This is an automated email from the ASF dual-hosted git repository.
indhumuthumurugesh 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 4826161 [CARBONDATA-4035]Fix MV query issue with aggregation on
decimal column
4826161 is described below
commit 482616123610867a46f6c5ebcda4b5e38cfe9537
Author: akashrn5 <[email protected]>
AuthorDate: Wed Oct 14 15:16:35 2020 +0530
[CARBONDATA-4035]Fix MV query issue with aggregation on decimal column
Why is this PR needed?
When the aggregation like sum is performed on decimal column similar to MV
schema query,
the user query is not getting results from MV. Since in MV schema during MV
created we
prepare the plan on the query string of modular
plan(modularPlan.asCompactSQL) which adds
multiple cast expression, because of which the semantic equals fails
What changes were proposed in this PR?
During MV creation, to set the query to MV schema, just use the direct
query string,
instead of compactSQL.
Does this PR introduce any user interface change?
No
Is any new testcase added?
Yes
This closes #3984
---
.../sql/execution/command/view/CarbonCreateMVCommand.scala | 4 +---
.../org/apache/carbondata/view/rewrite/MVCreateTestCase.scala | 10 ++++++++++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonCreateMVCommand.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonCreateMVCommand.scala
index ac6c90a..98b7179 100644
---
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonCreateMVCommand.scala
+++
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/view/CarbonCreateMVCommand.scala
@@ -327,11 +327,9 @@ case class CarbonCreateMVCommand(
schema.getProperties.put(MVProperty.REFRESH_MODE, viewRefreshMode)
schema.getProperties.put(MVProperty.REFRESH_TRIGGER_MODE,
viewRefreshTriggerMode)
if (null != granularity && null != timeSeriesColumn) {
- schema.setQuery(queryString)
schema.setTimeSeries(true)
- } else {
- schema.setQuery(modularPlan.asCompactSQL)
}
+ schema.setQuery(queryString)
try {
viewManager.createSchema(schema.getIdentifier.getDatabaseName, schema)
} catch {
diff --git
a/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCreateTestCase.scala
b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCreateTestCase.scala
index 1c036dd..891e36d 100644
---
a/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCreateTestCase.scala
+++
b/integration/spark/src/test/scala/org/apache/carbondata/view/rewrite/MVCreateTestCase.scala
@@ -1356,6 +1356,7 @@ class MVCreateTestCase extends QueryTest with
BeforeAndAfterAll {
sql("drop table if exists limit_fail")
sql("drop table IF EXISTS mv_like")
sql("drop table IF EXISTS maintable")
+ sql("drop table if exists sum_agg_decimal")
}
test("test create materialized view with add segment") {
@@ -1473,6 +1474,15 @@ class MVCreateTestCase extends QueryTest with
BeforeAndAfterAll {
sql("drop table if exists t2")
}
+ test("test sum aggregations on decimal columns") {
+ sql("drop table if exists sum_agg_decimal")
+ sql("create table sum_agg_decimal(salary1 decimal(7,2),salary2
decimal(7,2),salary3 decimal(7,2),salary4 decimal(7,2),empname string) stored
as carbondata")
+ sql("drop materialized view if exists decimal_mv")
+ sql("create materialized view decimal_mv as select empname, sum(salary1 -
salary2) from sum_agg_decimal group by empname")
+ val df = sql("select empname, sum( salary1 - salary2) from sum_agg_decimal
group by empname")
+ assert(TestUtil.verifyMVHit(df.queryExecution.optimizedPlan, "decimal_mv"))
+ }
+
def copy(oldLoc: String, newLoc: String): Unit = {
val oldFolder = FileFactory.getCarbonFile(oldLoc)
FileFactory.mkdirs(newLoc, FileFactory.getConfiguration)