[CARBONDATA-2028] Select Query failed with preagg having timeseries and normal 
agg table together

Select Query failed with preagg having timeseries and normal agg table together 
Root Cause:- hasTimeSeriesDataMap(CarbonTable carbonTable) in CarbonUtil 
returns result based on 1st DataMap. Solution:it should iterators all the 
DataMap and when finds timeseries datamap , then should returns the true.

This closes #1804


Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/29c98558
Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/29c98558
Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/29c98558

Branch: refs/heads/carbonstore
Commit: 29c985587952945c9f2f5c3082a733ef32df4686
Parents: 383b2ed
Author: BJangir <[email protected]>
Authored: Mon Jan 15 17:31:44 2018 +0530
Committer: kumarvishal <[email protected]>
Committed: Wed Jan 17 21:41:35 2018 +0530

----------------------------------------------------------------------
 .../apache/carbondata/core/util/CarbonUtil.java |  4 +++-
 .../TestPreAggregateTableSelection.scala        | 20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/29c98558/core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java 
b/core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java
index e272932..f1d474a 100644
--- a/core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java
+++ b/core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java
@@ -2305,7 +2305,9 @@ public final class CarbonUtil {
     List<DataMapSchema> dataMapSchemaList = 
carbonTable.getTableInfo().getDataMapSchemaList();
     for (DataMapSchema dataMapSchema : dataMapSchemaList) {
       if (dataMapSchema instanceof AggregationDataMapSchema) {
-        return ((AggregationDataMapSchema) 
dataMapSchema).isTimeseriesDataMap();
+        if (((AggregationDataMapSchema) dataMapSchema).isTimeseriesDataMap()) {
+          return true;
+        }
       }
     }
     return false;

http://git-wip-us.apache.org/repos/asf/carbondata/blob/29c98558/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggregateTableSelection.scala
----------------------------------------------------------------------
diff --git 
a/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggregateTableSelection.scala
 
b/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggregateTableSelection.scala
index 559e91f..3fefbaf 100644
--- 
a/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggregateTableSelection.scala
+++ 
b/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggregateTableSelection.scala
@@ -262,11 +262,29 @@ class TestPreAggregateTableSelection extends QueryTest 
with BeforeAndAfterAll {
     preAggTableValidator(df.queryExecution.analyzed, "maintable_agg0")
   }
 
-  test("Test query with math operation hitting fact table") {
+ test("Test query with math operation hitting fact table") {
     val df =  sql("select sum(id)+count(id) from maintable")
     preAggTableValidator(df.queryExecution.analyzed, "maintable")
   }
 
+test("test PreAggregate table selection with timeseries and normal together") {
+    sql("drop table if exists maintabletime")
+    sql(
+      "create table maintabletime(year int,month int,name string,salary 
int,dob timestamp) stored" +
+      " by 'carbondata' 
tblproperties('sort_scope'='Global_sort','table_blocksize'='23'," +
+      "'sort_columns'='month,year,name')")
+    sql("insert into maintabletime select 10,11,'babu',12,'2014-01-01 
00:00:00'")
+    sql(
+      "create datamap agg0 on table maintabletime using 'preaggregate' as 
select dob,name from " +
+      "maintabletime group by dob,name")
+    sql(
+      "create datamap agg1 on table maintabletime using 'preaggregate' 
DMPROPERTIES ('timeseries" +
+      ".eventTime'='dob', 
'timeseries.hierarchy'='hour=1,day=1,month=1,year=1') as select dob," +
+      "name from maintabletime group by dob,name")
+    val df = sql("select timeseries(dob,'year') from maintabletime group by 
timeseries(dob,'year')")
+    preAggTableValidator(df.queryExecution.analyzed, "maintabletime_agg1_year")
+
+  }
   override def afterAll: Unit = {
     sql("drop table if exists mainTable")
     sql("drop table if exists lineitem")

Reply via email to