ajantha-bhat commented on a change in pull request #3438: [CARBONDATA-3531]Support load and query for MV timeseries and support multiple granularity.
URL: https://github.com/apache/carbondata/pull/3438#discussion_r346250919 ########## File path: datamap/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala ########## @@ -0,0 +1,360 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.apache.carbondata.mv.timeseries + +import org.apache.spark.sql.DataFrame +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.mv.rewrite.TestUtil + +class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll { + + override def beforeAll(): Unit = { + drop() + createTable() + } + + test("create MV timeseries datamap with simple projection and aggregation and filter") { + sql("drop datamap if exists datamap1") + sql("drop datamap if exists datamap2") + sql( + "create datamap datamap1 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'minute'), sum(projectcode) from maintable group by timeseries(projectjoindate,'minute')") + loadData("maintable") + val df = sql("select timeseries(projectjoindate,'minute'), sum(projectcode) from maintable group by timeseries(projectjoindate,'minute')") + val analyzed = df.queryExecution.analyzed + assert(TestUtil.verifyMVDataMap(analyzed, "datamap1")) + dropDataMap("datamap1") + sql( + "create datamap datamap1 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'minute'), sum(projectcode) from maintable where timeseries(projectjoindate,'minute') = '2016-02-23 09:17:00' group by timeseries(projectjoindate,'minute')") + + sql("select * from datamap1_table").show(false) + val df1 = sql("select timeseries(projectjoindate,'minute'),sum(projectcode) from maintable where timeseries(projectjoindate,'minute') = '2016-02-23 09:17:00'" + + "group by timeseries(projectjoindate,'minute')") + val analyzed1 = df1.queryExecution.analyzed + assert(TestUtil.verifyMVDataMap(analyzed1, "datamap1")) + dropDataMap("datamap1") + } + + test("test mv timeseries with ctas and filter in actual query") { + dropDataMap("datamap1") + sql( + "create datamap datamap1 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'hour'), sum(projectcode) from maintable group by timeseries(projectjoindate,'hour')") + loadData("maintable") + val df = sql("select timeseries(projectjoindate,'hour'), sum(projectcode) from maintable where timeseries(projectjoindate,'hour') = '2016-02-23 09:00:00' " + + "group by timeseries(projectjoindate,'hour')") + val analyzed = df.queryExecution.analyzed + assert(TestUtil.verifyMVDataMap(analyzed, "datamap1")) + dropDataMap("datamap1") + } + + test("test mv timeseries with multiple granularity datamaps") { + dropDataMap("datamap1") + dropDataMap("datamap2") + dropDataMap("datamap3") + dropDataMap("datamap4") + dropDataMap("datamap5") + dropDataMap("datamap6") + loadData("maintable") + sql( + "create datamap datamap1 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'minute'), sum(salary) from maintable group by timeseries(projectjoindate,'minute')") + sql( + "create datamap datamap2 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'hour'), sum(salary) from maintable group by timeseries(projectjoindate,'hour')") + sql( + "create datamap datamap3 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'fifteen_minute'), sum(salary) from maintable group by timeseries(projectjoindate,'fifteen_minute')") + sql( + "create datamap datamap4 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'five_minute'), sum(salary) from maintable group by timeseries(projectjoindate,'five_minute')") + sql( + "create datamap datamap5 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'week'), sum(salary) from maintable group by timeseries(projectjoindate,'week')") + sql( + "create datamap datamap6 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'year'), sum(salary) from maintable group by timeseries(projectjoindate,'year')") + val df1 = sql("select timeseries(projectjoindate,'minute'), sum(salary) from maintable group by timeseries(projectjoindate,'minute')") + checkPlan("datamap1", df1) + val df2 = sql("select timeseries(projectjoindate,'hour'), sum(salary) from maintable group by timeseries(projectjoindate,'hour')") + checkPlan("datamap2", df2) + val df3 = sql("select timeseries(projectjoindate,'fifteen_minute'), sum(salary) from maintable group by timeseries(projectjoindate,'fifteen_minute')") + checkPlan("datamap3", df3) + val df4 = sql("select timeseries(projectjoindate,'five_minute'), sum(salary) from maintable group by timeseries(projectjoindate,'five_minute')") + checkPlan("datamap4", df4) + val df5 = sql("select timeseries(projectjoindate,'week'), sum(salary) from maintable group by timeseries(projectjoindate,'week')") + checkPlan("datamap5", df5) + val df6 = sql("select timeseries(projectjoindate,'year'), sum(salary) from maintable group by timeseries(projectjoindate,'year')") + checkPlan("datamap6", df6) + val result = sql("show datamap on table maintable").collect() + result.find(_.get(0).toString.contains("datamap1")) match { + case Some(row) => assert(row.get(4).toString.contains("ENABLED")) + case None => assert(false) + } + result.find(_.get(0).toString.contains("datamap2")) match { + case Some(row) => assert(row.get(4).toString.contains("ENABLED")) + case None => assert(false) + } + result.find(_.get(0).toString.contains("datamap3")) match { + case Some(row) => assert(row.get(4).toString.contains("ENABLED")) + case None => assert(false) + } + result.find(_.get(0).toString.contains("datamap4")) match { + case Some(row) => assert(row.get(4).toString.contains("ENABLED")) + case None => assert(false) + } + result.find(_.get(0).toString.contains("datamap5")) match { + case Some(row) => assert(row.get(4).toString.contains("ENABLED")) + case None => assert(false) + } + result.find(_.get(0).toString.contains("datamap6")) match { + case Some(row) => assert(row.get(4).toString.contains("ENABLED")) + case None => assert(false) + } + dropDataMap("datamap1") + dropDataMap("datamap2") + dropDataMap("datamap3") + dropDataMap("datamap4") + dropDataMap("datamap5") + dropDataMap("datamap6") + } + + test("test mv timeseries with week granular select data") { + dropDataMap("datamap1") + loadData("maintable") + sql( + "create datamap datamap1 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'week'), sum(salary) from maintable group by timeseries(projectjoindate,'week')") +/* + +-----------------------------------+----------+ + |UDF:timeseries_projectjoindate_week|sum_salary| + +-----------------------------------+----------+ + |2016-02-21 00:00:00 |3801 | + |2016-03-20 00:00:00 |400.2 | + |2016-04-17 00:00:00 |350.0 | + |2016-03-27 00:00:00 |150.6 | + +-----------------------------------+----------+*/ + val df1 = sql("select timeseries(projectjoindate,'week'), sum(salary) from maintable group by timeseries(projectjoindate,'week')") + checkPlan("datamap1", df1) + checkExistence(df1, true, "2016-02-21 00:00:00.0" ) + dropDataMap("datamap1") + } + + test("test timeseries with different aggregations") { + dropDataMap("datamap1") + dropDataMap("datamap2") + loadData("maintable") + sql( + "create datamap datamap1 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'hour'), avg(salary), max(salary) from maintable group by timeseries(projectjoindate,'hour')") + sql( + "create datamap datamap2 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'day'), count(projectcode), min(salary) from maintable group by timeseries(projectjoindate,'day')") + val df1 = sql("select timeseries(projectjoindate,'hour'), avg(salary), max(salary) from maintable group by timeseries(projectjoindate,'hour')") + checkPlan("datamap1", df1) + val df2 = sql("select timeseries(projectjoindate,'day'), count(projectcode), min(salary) from maintable group by timeseries(projectjoindate,'day')") + checkPlan("datamap2", df2) + dropDataMap("datamap1") + dropDataMap("datamap2") + } + + test("test timeseries with and and or filters") { + dropDataMap("datamap1") + dropDataMap("datamap2") + dropDataMap("datamap3") + sql( + "create datamap datamap1 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'month'), max(salary) from maintable where timeseries(projectjoindate,'month') = '2016-03-01 00:00:00' or timeseries(projectjoindate,'month') = '2016-02-01 00:00:00' group by timeseries(projectjoindate,'month')") + loadData("maintable") + val df1 = sql("select timeseries(projectjoindate,'month'), max(salary) from maintable where timeseries(projectjoindate,'month') = '2016-03-01 00:00:00' or timeseries(projectjoindate,'month') = '2016-02-01 00:00:00' group by timeseries(projectjoindate,'month')") + checkPlan("datamap1", df1) + df1.show() + sql( + "create datamap datamap2 on table maintable using 'mv_timeseries' as " + + "select timeseries(projectjoindate,'month'), max(salary) from maintable where timeseries(projectjoindate,'month') = '2016-03-01 00:00:00' and timeseries(projectjoindate,'month') = '2016-02-01 00:00:00' group by timeseries(projectjoindate,'month')") + val df2 = sql("select timeseries(projectjoindate,'month'), max(salary) from maintable where timeseries(projectjoindate,'month') = '2016-03-01 00:00:00' and timeseries(projectjoindate,'month') = '2016-02-01 00:00:00' group by timeseries(projectjoindate,'month')") + checkPlan("datamap2", df2) + df2.show() Review comment: can remove .show() have validations instead ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |