From b1c1cd2bb354afc8566774c6b002d511c4a99f65 Mon Sep 17 00:00:00 2001 From: Indhumathi27 Date: Wed, 21 Nov 2018 17:23:25 +0530 Subject: [PATCH] [CARBONDATA-3115]Fix Codegen issue --- .../TestPreAggCreateCommand.scala | 23 +++++++++++++++++++ .../spark/sql/CarbonDictionaryDecoder.scala | 12 +++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggCreateCommand.scala b/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggCreateCommand.scala index 9fbdff720f4..7851bd1270a 100644 --- a/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggCreateCommand.scala +++ b/integration/spark-common-test/src/test/scala/org/apache/carbondata/integration/spark/testsuite/preaggregate/TestPreAggCreateCommand.scala @@ -438,6 +438,29 @@ class TestPreAggCreateCommand extends QueryTest with BeforeAndAfterAll { } } + test("test codegen issue with preaggregate") { + sql("DROP TABLE IF EXISTS PreAggMain") + sql("CREATE TABLE PreAggMain (id Int, date date, country string, phonetype string, " + + "serialname String,salary int ) STORED BY 'org.apache.carbondata.format' " + + "tblproperties('dictionary_include'='country')") + sql("create datamap PreAggSum on table PreAggMain using 'preaggregate' as " + + "select country,sum(salary) as sum from PreAggMain group by country") + sql("create datamap PreAggAvg on table PreAggMain using 'preaggregate' as " + + "select country,avg(salary) as avg from PreAggMain group by country") + sql("create datamap PreAggCount on table PreAggMain using 'preaggregate' as " + + "select country,count(salary) as count from PreAggMain group by country") + sql("create datamap PreAggMin on table PreAggMain using 'preaggregate' as " + + "select country,min(salary) as min from PreAggMain group by country") + sql("create datamap PreAggMax on table PreAggMain using 'preaggregate' as " + + "select country,max(salary) as max from PreAggMain group by country") + sql(s"LOAD DATA INPATH '$integrationPath/spark-common-test/src/test/resources/source.csv' " + + s"into table PreAggMain") + checkExistence(sql("select t1.country,sum(id) from PreAggMain t1 join (select " + + "country as newcountry,sum(salary) as sum from PreAggMain group by country)" + + "t2 on t1.country=t2.newcountry group by country"), true, "france") + sql("DROP TABLE IF EXISTS PreAggMain") + } + // TODO: Need to Fix ignore("test creation of multiple preaggregate of same name concurrently") { sql("DROP TABLE IF EXISTS tbl_concurr") diff --git a/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonDictionaryDecoder.scala b/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonDictionaryDecoder.scala index 95ab29d7b34..3b20c2f1ae2 100644 --- a/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonDictionaryDecoder.scala +++ b/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonDictionaryDecoder.scala @@ -248,34 +248,34 @@ case class CarbonDictionaryDecoder( |org.apache.spark.sql.DictTuple $value = $decodeDecimal($dictRef, ${ev.value}); """.stripMargin ExprCode(code, s"$value.getIsNull()", - s"(org.apache.spark.sql.types.Decimal)$value.getValue()") + s"((org.apache.spark.sql.types.Decimal)$value.getValue())") } else { getDictionaryColumnIds(index)._3.getDataType match { case CarbonDataTypes.INT => code += s""" |org.apache.spark.sql.DictTuple $value = $decodeInt($dictRef, ${ ev.value }); """.stripMargin - ExprCode(code, s"$value.getIsNull()", s"(Integer)$value.getValue()") + ExprCode(code, s"$value.getIsNull()", s"((Integer)$value.getValue())") case CarbonDataTypes.SHORT => code += s""" |org.apache.spark.sql.DictTuple $value = $decodeShort($dictRef, ${ ev.value }); """.stripMargin - ExprCode(code, s"$value.getIsNull()", s"(Short)$value.getValue()") + ExprCode(code, s"$value.getIsNull()", s"((Short)$value.getValue())") case CarbonDataTypes.DOUBLE => code += s""" |org.apache.spark.sql.DictTuple $value = $decodeDouble($dictRef, ${ ev.value }); """.stripMargin - ExprCode(code, s"$value.getIsNull()", s"(Double)$value.getValue()") + ExprCode(code, s"$value.getIsNull()", s"((Double)$value.getValue())") case CarbonDataTypes.LONG => code += s""" |org.apache.spark.sql.DictTuple $value = $decodeLong($dictRef, ${ ev.value }); """.stripMargin - ExprCode(code, s"$value.getIsNull()", s"(Long)$value.getValue()") + ExprCode(code, s"$value.getIsNull()", s"((Long)$value.getValue())") case _ => code += s""" |org.apache.spark.sql.DictTuple $value = $decodeStr($dictRef, ${ev.value}); """.stripMargin - ExprCode(code, s"$value.getIsNull()", s"(UTF8String)$value.getValue()") + ExprCode(code, s"$value.getIsNull()", s"((UTF8String)$value.getValue())") } }