Skip to content

Commit

Permalink
[CARBONDATA-2534][MV] Fix substring expression not working in MV crea…
Browse files Browse the repository at this point in the history
…tion

Problem: The column generated when subquery expression column present is wrong while creating of MV table.
Solution: Corrected the column name by removing special characters.

This closes #2476
  • Loading branch information
ravipesala authored and jackylk committed Jul 24, 2018
1 parent 4014b0f commit 2c291d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -119,7 +119,12 @@ object MVHelper {
}

def updateColumnName(attr: Attribute): String = {
val name = attr.name.replace("(", "_").replace(")", "").replace(" ", "_").replace("=", "")
val name =
attr.name.replace("(", "_")
.replace(")", "")
.replace(" ", "_")
.replace("=", "")
.replace(",", "")
attr.qualifier.map(qualifier => qualifier + "_" + name).getOrElse(name)
}

Expand Down
Expand Up @@ -750,6 +750,18 @@ class MVCreateTestCase extends QueryTest with BeforeAndAfterAll {
sql("drop table if exists test1")
}

test("jira carbondata-2534") {

sql("drop datamap if exists MV_exp")
sql("create datamap MV_exp using 'mv' as select sum(salary),substring(empname,2,5),designation from fact_table1 group by substring(empname,2,5),designation")
sql("rebuild datamap MV_exp")
val frame = sql(
"select sum(salary),substring(empname,2,5),designation from fact_table1 group by substring(empname,2,5),designation")
val analyzed = frame.queryExecution.analyzed
assert(verifyMVDataMap(analyzed, "MV_exp"))
sql("drop datamap if exists MV_exp")
}

def verifyMVDataMap(logicalPlan: LogicalPlan, dataMapName: String): Boolean = {
val tables = logicalPlan collect {
case l: LogicalRelation => l.catalogTable.get
Expand Down

0 comments on commit 2c291d6

Please sign in to comment.