Github user xubo245 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/1856#discussion_r165051297
--- Diff:
integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/timeseries/TestTimeSeriesMatchStrategySuite.scala
---
@@ -0,0 +1,294 @@
+/*
+ * 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.integration.spark.testsuite.timeseries
+
+import java.sql.Timestamp
+
+import org.apache.spark.sql.{CarbonDatasourceHadoopRelation, Row}
+import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
+import org.apache.spark.sql.execution.datasources.LogicalRelation
+import org.apache.spark.sql.hive.CarbonRelation
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.util.SparkUtil4Test
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.util.CarbonProperties
+
+class TestTimeSeriesMatchStrategySuite extends QueryTest with
BeforeAndAfterAll with BeforeAndAfterEach {
+
+ override def beforeAll: Unit = {
+ SparkUtil4Test.createTaskMockUp(sqlContext)
+ CarbonProperties.getInstance()
+ .addProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT,
+ CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT)
+
+ }
+
+ override protected def beforeEach(): Unit = {
+ sql("drop table if exists mainTable")
+ sql(
+ """
+ | CREATE TABLE mainTable(
+ | mytime timestamp,
+ | name string,
+ | age int)
+ | STORED BY 'org.apache.carbondata.format'
+ """.stripMargin)
+ sql(s"LOAD DATA LOCAL INPATH '$resourcesPath/timeseriestest.csv' into
table mainTable")
+ }
+
+ val timeSeries = "preaggregate"
+
+ test("test timeseries match 1: select small size when there are >1
timeseries match") {
+
+ dropDataMaps("maintable", "agg1_minute", "agg2_minute")
+ sql(
+ s"""
+ | create datamap agg1 on table mainTable
+ | using '$timeSeries'
+ | DMPROPERTIES (
+ | 'timeseries.eventTime'='mytime',
+ | 'timeseries.hierarchy'='minute=1')
+ | as select mytime, sum(age), count(age), max(age), min(age)
+ | from mainTable
+ | group by mytime
+ """.stripMargin)
+
+ val df1 = sql(
+ """
+ | select
+ | timeseries(mytime,'minute') as minuteLevel,
+ | sum(age) as sum
+ | from mainTable
+ | where
+ | timeseries(mytime,'minute')<'2016-02-23 01:02:00' and
+ | timeseries(mytime,'minute')>='2016-02-23 01:01:00'
+ | group by
+ | timeseries(mytime,'minute')
+ | order by
+ | timeseries(mytime,'minute')
+ """.stripMargin)
+
+ checkAnswer(df1, Seq(Row(Timestamp.valueOf("2016-02-23 01:01:00"),
60)))
+
+ preAggTableValidator(df1.queryExecution.analyzed,
"maintable_agg1_minute")
+
+ sql(
+ s"""
+ | create datamap agg2 on table mainTable
+ | using '$timeSeries'
+ | DMPROPERTIES (
+ | 'timeseries.eventTime'='mytime',
+ | 'timeseries.hierarchy'='minute=1')
+ | as select mytime, sum(age)
+ | from mainTable
+ | group by mytime
+ """.stripMargin)
+
+ val df2 = sql(
+ """
+ | select
+ | timeseries(mytime,'minute') as minuteLevel,
+ | sum(age) as sum
+ | from mainTable
+ | where
+ | timeseries(mytime,'minute')<'2016-02-23 01:02:00' and
+ | timeseries(mytime,'minute')>='2016-02-23 01:01:00'
+ | group by
+ | timeseries(mytime,'minute')
+ | order by
+ | timeseries(mytime,'minute')
+ """.stripMargin)
+
+ checkAnswer(df2, Seq(Row(Timestamp.valueOf("2016-02-23 01:01:00"),
60)))
+
+ preAggTableValidator(df2.queryExecution.analyzed,
"maintable_agg2_minute")
+ }
+
+ test("test timeseries match 2: select small size when there are >1
timeseries match") {
+ dropDataMaps("maintable", "agg1_minute", "agg2_minute")
+ sql(
+ s"""
+ | create datamap agg1 on table mainTable
+ | using '$timeSeries'
+ | DMPROPERTIES (
+ | 'timeseries.eventTime'='mytime',
+ | 'timeseries.hierarchy'='minute=1')
+ | as select mytime, sum(age), count(age), max(age), min(age)
+ | from mainTable
+ | group by mytime
+ """.stripMargin)
+
+ sql(
+ s"""
+ | create datamap agg2 on table mainTable
+ | using '$timeSeries'
+ | DMPROPERTIES (
+ | 'timeseries.eventTime'='mytime',
+ | 'timeseries.hierarchy'='minute=1')
+ | as select mytime, sum(age)
--- End diff --
ok, done
---