ravipesala commented on a change in pull request #3135: [CARBONDATA-3303] Fix 
that MV datamap return wrong results when using coalesce and less groupby 
columns
URL: https://github.com/apache/carbondata/pull/3135#discussion_r282852576
 
 

 ##########
 File path: 
datamap/mv/core/src/test/scala/org/apache/carbondata/mv/rewrite/MVCoalesceTestCase.scala
 ##########
 @@ -0,0 +1,62 @@
+/*
+        * 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.rewrite
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
+import org.apache.spark.sql.execution.datasources.LogicalRelation
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
+
+class MVCoalesceTestCase  extends QueryTest with BeforeAndAfterAll  {
+  override def beforeAll(): Unit = {
+    drop()
+    sql("create table coalesce_test_main(id int,name string,height int,weight 
int) " +
+      "using carbondata")
+    sql("insert into coalesce_test_main select 1,'tom',170,130")
+    sql("insert into coalesce_test_main select 2,'tom',170,120")
+    sql("insert into coalesce_test_main select 3,'lily',160,100")
+  }
+
+  def drop(): Unit = {
+    sql("drop table if exists coalesce_test_main")
+  }
+
+  test("test mv table with coalesce expression less groupby cols") {
+    sql("drop datamap if exists coalesce_test_main_mv")
+    sql("create datamap coalesce_test_main_mv using 'mv' as " +
+      "select coalesce(sum(id),0) as sum_id,name as myname,weight from 
coalesce_test_main group by name,weight")
+    sql("rebuild datamap coalesce_test_main_mv")
+
+    val frame = sql("select coalesce(sum(id),0) as sumid,name from 
coalesce_test_main group by name")
+    assert(!verifyMVDataMap(frame.queryExecution.analyzed, 
"coalesce_test_main_mv"))
+    checkAnswer(frame, Seq(Row(3, "tom"), Row(3, "lily")))
+
+    sql("drop datamap if exists coalesce_test_main_mv")
+  }
+
 
 Review comment:
   Add another test case which has coalesce only in query not on MV like below. 
The below testcase should work but fails because of this fix.
   
   ```
   test("test mv table with coalesce expression on sql not on mv and less 
groupby cols") {
       sql("drop datamap if exists coalesce_test_main_mv")
       sql("create datamap coalesce_test_main_mv using 'mv' as " +
         "select sum(id) as sum_id,name as myname,weight from 
coalesce_test_main group by name,weight")
       sql("rebuild datamap coalesce_test_main_mv")
   
       val frame = sql("select coalesce(sum(id),0) as sumid,name from 
coalesce_test_main group by name")
       assert(verifyMVDataMap(frame.queryExecution.analyzed, 
"coalesce_test_main_mv"))
       checkAnswer(frame, Seq(Row(3, "tom"), Row(3, "lily")))
   
       sql("drop datamap if exists coalesce_test_main_mv")
     }
   ```
   
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to