carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akash...@apache.org
Subject [carbondata] branch master updated: [CARBONDATA-3768] Fix query not hitting mv without alias, with mv having Alias
Date Tue, 14 Apr 2020 05:13:27 GMT
This is an automated email from the ASF dual-hosted git repository.

akashrn5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/carbondata.git


The following commit(s) were added to refs/heads/master by this push:
     new e234ce7  [CARBONDATA-3768] Fix query not hitting mv without alias, with mv having
Alias
e234ce7 is described below

commit e234ce7f0b6c1ee702ecf80603944c432c5c4a8b
Author: Indhumathi27 <indhumathim27@gmail.com>
AuthorDate: Wed Apr 8 15:20:24 2020 +0530

    [CARBONDATA-3768] Fix query not hitting mv without alias, with mv having Alias
    
    Why is this PR needed?
    create MV with select query having alias. Query without alias is not hitting mv.
    
    What changes were proposed in this PR?
    While query matching, check if outputlist with alias contains all user outputlist.
    
    This closes #3699
---
 .../org/apache/spark/sql/optimizer/MVMatcher.scala      | 17 +++++++++++++----
 .../apache/carbondata/mv/rewrite/MVCreateTestCase.scala |  3 +++
 .../carbondata/mv/rewrite/TestAllOperationsOnMV.scala   |  6 ++++++
 .../mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala    |  9 ++++++---
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/optimizer/MVMatcher.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/optimizer/MVMatcher.scala
index 9003627..8cb97b0 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/optimizer/MVMatcher.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/optimizer/MVMatcher.scala
@@ -863,11 +863,15 @@ private object GroupbyGroupbyNoChildDelta extends MVMatchPattern {
           isExpressionMatches(expr, gb_2q.predicateList))
         val isOutputEmR = gb_2q.outputList.forall {
           case a @ Alias(_, _) =>
-            gb_2a.outputList.exists{
-              case a1: Alias => a1.child.semanticEquals(a.child)
+            gb_2a.outputList.exists {
+              case alias: Alias => alias.child.semanticEquals(a.child)
               case exp => exp.semanticEquals(a.child)
             }
-          case exp => gb_2a.outputList.exists(_.semanticEquals(exp))
+          case exp =>
+            gb_2a.outputList.exists {
+              case alias: Alias => alias.child.semanticEquals(exp)
+              case expr => expr.semanticEquals(exp)
+            }
         }
         if (isGroupingEmR && isGroupingRmE) {
           if (isOutputEmR) {
@@ -878,7 +882,12 @@ private object GroupbyGroupbyNoChildDelta extends MVMatchPattern {
                   a.child.semanticEquals(exp.children.head) ||
                     isExpressionMatches(a.child, exp.children.head)
                 case a: Alias => a.child.semanticEquals(exp)
-                case other => other.semanticEquals(exp)
+                case other => exp match {
+                  case alias: Alias =>
+                    other.semanticEquals(alias.child)
+                  case _ =>
+                    other.semanticEquals(exp)
+                }
               }.getOrElse(gb_2a.outputList(index)))
             }
 
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCreateTestCase.scala
b/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCreateTestCase.scala
index 8f9489a..3b14b48 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCreateTestCase.scala
+++ b/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCreateTestCase.scala
@@ -1242,6 +1242,7 @@ class MVCreateTestCase extends QueryTest with BeforeAndAfterAll {
     val df2 = sql(
       " select cast(floor((m_month +1000) / 900) * 900 - 2000 AS INT),c_code as abc  from
maintable")
     assert(TestUtil.verifyMVDataMap(df1.queryExecution.optimizedPlan, "da_cast"))
+    assert(TestUtil.verifyMVDataMap(df2.queryExecution.optimizedPlan, "da_cast"))
   }
 
   test("test cast of expression with mv") {
@@ -1271,6 +1272,8 @@ class MVCreateTestCase extends QueryTest with BeforeAndAfterAll {
     checkAnswer(sql("select cast(m_month + 1000 AS INT) as a, c_code as abc from maintable"),
Seq(Row(1010, "xxx")))
     var df1 = sql("select cast(m_month + 1000 AS INT) as a, c_code as abc from maintable")
     assert(TestUtil.verifyMVDataMap(df1.queryExecution.optimizedPlan, "da_cast"))
+    df1 = sql("select cast(m_month + 1000 AS INT), c_code from maintable")
+    assert(TestUtil.verifyMVDataMap(df1.queryExecution.optimizedPlan, "da_cast"))
     sql("drop materialized view if exists da_cast")
     sql(
       "create materialized view da_cast as select cast(m_month + 1000 AS INT), c_code from
maintable")
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestAllOperationsOnMV.scala
b/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestAllOperationsOnMV.scala
index 3ed7d43..d1377b3 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestAllOperationsOnMV.scala
+++ b/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/TestAllOperationsOnMV.scala
@@ -564,11 +564,17 @@ class TestAllOperationsOnMV extends QueryTest with BeforeAndAfterEach
{
     sql("create table maintable(name string, age int, add string) STORED AS carbondata")
     sql("insert into maintable values('abc',1,'a'),('def',2,'b'),('ghi',3,'c')")
     val res = sql("select sum(age) from maintable")
+    val res1 = sql("select age,sum(age) from maintable group by age")
     sql("drop materialized view if exists mv3")
     sql("create materialized view mv3 as select age,sum(age) from maintable group by age")
     val df = sql("select sum(age) from maintable")
     TestUtil.verifyMVDataMap(df.queryExecution.optimizedPlan, "mv3")
     checkAnswer(res, df)
+    sql("drop materialized view if exists mv3")
+    sql("create materialized view mv3 as select age as a,sum(age) as b from maintable group
by age")
+    val df1 = sql("select age,sum(age) from maintable group by age")
+    TestUtil.verifyMVDataMap(df1.queryExecution.optimizedPlan, "mv3")
+    checkAnswer(res1, df1)
     sql("drop table if exists maintable")
   }
 
diff --git a/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala
b/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala
index fa05268..c0a7362 100644
--- a/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala
+++ b/mv/core/src/test/scala/org/apache/carbondata/mv/timeseries/TestMVTimeSeriesLoadAndQuery.scala
@@ -240,6 +240,7 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll
{
   }
 
   test("test mvtimeseries with alias") {
+    val result = sql("select timeseries(projectjoindate,'month'),projectcode from maintable
group by timeseries(projectjoindate,'month'),projectcode")
     dropDataMap("datamap1")
     sql(
       "create materialized view datamap1 as " +
@@ -247,9 +248,11 @@ class TestMVTimeSeriesLoadAndQuery extends QueryTest with BeforeAndAfterAll
{
     loadData("maintable")
     val df1 = sql("select timeseries(projectjoindate,'month') as t,projectcode as y from
maintable group by timeseries(projectjoindate,'month'),projectcode")
     checkPlan("datamap1", df1)
-    // TODO: fix the base issue of alias with group by
-    //   val df2 = sql("select timeseries(projectjoindate,'month'),projectcode from maintable
group by timeseries(projectjoindate,'month'),projectcode")
-    //   checkPlan("datamap1", df2)
+    val df2 = sql("select timeseries(projectjoindate,'month'),projectcode from maintable
group by timeseries(projectjoindate,'month'),projectcode")
+    checkPlan("datamap1", df2)
+    checkAnswer(result, df2)
+    val df4 = sql("select timeseries(projectjoindate,'month'),projectcode as y from maintable
group by timeseries(projectjoindate,'month'),projectcode")
+    checkPlan("datamap1", df4)
     dropDataMap("datamap1")
     sql(
       "create materialized view datamap1 as " +


Mime
View raw message