Skip to content

Commit

Permalink
Fix validate mvQuery having filter expression and correct error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Indhumathi27 committed Jul 19, 2019
1 parent 0902d45 commit 101df73
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ object MVHelper {
if (attr.dataType.isInstanceOf[ArrayType] || attr.dataType.isInstanceOf[StructType] ||
attr.dataType.isInstanceOf[MapType]) {
throw new UnsupportedOperationException(
s"MV datamap is unsupported for ComplexData type column: " + attr.name)
s"MV datamap is not supported for complex datatype columns and complex datatype return " +
s"types of function :" + attr.name)
}
val name = updateColumnName(attr, counter)
counter += 1
Expand Down Expand Up @@ -260,13 +261,21 @@ object MVHelper {
f.children.collect {
case p: AttributeReference =>
predicateList = predicateList.+:(p)
case e: Expression =>
e.collect {
case attr: AttributeReference =>
predicateList = predicateList.+:(attr)
}
}
}
if (predicateList.nonEmpty) {
predicateList.forall { p =>
s.outputList.exists {
case a: Alias =>
a.semanticEquals(p) || a.child.semanticEquals(p)
a.semanticEquals(p) || a.child.semanticEquals(p) || a.collect {
case attr: AttributeReference =>
attr.semanticEquals(p)
}.exists(p => p.equals(true))
case other => other.semanticEquals(p)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ class MVUtil {
if (a.child.isInstanceOf[GetMapValue] || a.child.isInstanceOf[GetStructField] ||
a.child.isInstanceOf[GetArrayItem]) {
throw new UnsupportedOperationException(
s"MV datamap is unsupported for ComplexData type child column: " + a.child.simpleString)
s"MV datamap is not supported for complex datatype child columns and complex datatype " +
s"return types of function :" + a.child.simpleString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ class MVCreateTestCase extends QueryTest with BeforeAndAfterAll {
sql(
"create table mv_like(name string, age int, address string, Country string, id int) stored by 'carbondata'")
sql(
"create datamap mvlikedm1 using 'mv' as select name,address from mv_like where Country NOT LIKE 'US' group by name,address")
"create datamap mvlikedm1 using 'mv' as select name,address,sum(Country) from mv_like where Country NOT LIKE 'US' group by name,address")
sql(
"create datamap mvlikedm2 using 'mv' as select name,address,Country from mv_like where Country = 'US' or Country = 'China' group by name,address,Country")
sql("insert into mv_like select 'chandler', 32, 'newYork', 'US', 5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,16 @@ class TestAllOperationsOnMV extends QueryTest with BeforeAndAfterEach {
sql("drop datamap if exists dm ")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select c_code from maintable")
}.getMessage.contains("MV datamap is unsupported for ComplexData type column: c_code")
}.getMessage.contains("MV datamap is not supported for complex datatype columns and complex datatype return types of function : c_code")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select price from maintable")
}.getMessage.contains("MV datamap is unsupported for ComplexData type column: price")
}.getMessage.contains("MV datamap is not supported for complex datatype columns and complex datatype return types of function : price")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select type from maintable")
}.getMessage.contains("MV datamap is unsupported for ComplexData type column: type")
}.getMessage.contains("MV datamap is not supported for complex datatype columns and complex datatype return types of function : type")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select price.b from maintable")
}.getMessage.contains("MV datamap is unsupported for ComplexData type child column: price")
}.getMessage.contains("MV datamap is not supported for complex datatype child columns and complex datatype return types of function : price")
sql("drop table IF EXISTS maintable")
}

Expand Down Expand Up @@ -551,6 +551,34 @@ class TestAllOperationsOnMV extends QueryTest with BeforeAndAfterEach {
sql("drop table if exists maintable")
}

test("test mv with filter instance of expression") {
sql("drop table IF EXISTS maintable")
sql("CREATE TABLE maintable (CUST_ID int,CUST_NAME String,ACTIVE_EMUI_VERSION string, DOB date, DOJ timestamp, BIGINT_COLUMN1 bigint,BIGINT_COLUMN2 bigint,DECIMAL_COLUMN1 decimal(30,10), DECIMAL_COLUMN2 decimal(36,10),Double_COLUMN1 double, Double_COLUMN2 double,INTEGER_COLUMN1 int) STORED BY 'org.apache.carbondata.format'")
sql("insert into maintable values(1, 'abc', 'abc001', '1975-06-11','1975-06-11 02:00:03.0', 120, 1234,4.34,24.56,12345, 2464, 45)")
sql("drop datamap if exists dm ")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select dob from maintable where (dob='1975-06-11' or cust_id=2)")
}.getMessage.contains("Group by/Filter columns must be present in project columns")
sql("drop table IF EXISTS maintable")
}

test("test histogram_numeric, collect_set & collect_list functions") {
sql("drop table IF EXISTS maintable")
sql("CREATE TABLE maintable (CUST_ID int,CUST_NAME String,ACTIVE_EMUI_VERSION string, DOB timestamp, DOJ timestamp, BIGINT_COLUMN1 bigint,BIGINT_COLUMN2 bigint,DECIMAL_COLUMN1 decimal(30,10), DECIMAL_COLUMN2 decimal(36,10),Double_COLUMN1 double, Double_COLUMN2 double,INTEGER_COLUMN1 int) STORED BY 'org.apache.carbondata.format'")
sql("insert into maintable values(1, 'abc', 'abc001', '1975-06-11 01:00:03.0','1975-06-11 02:00:03.0', 120, 1234,4.34,24.56,12345, 2464, 45)")
sql("drop datamap if exists dm ")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select histogram_numeric(1,2) from maintable")
}.getMessage.contains("MV datamap is not supported for complex datatype columns and complex datatype return types of function : histogram_numeric( 1, 2)")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select collect_set(cust_id) from maintable")
}.getMessage.contains("MV datamap is not supported for complex datatype columns and complex datatype return types of function : collect_set(cust_id)")
intercept[UnsupportedOperationException] {
sql("create datamap dm using 'mv' as select collect_list(cust_id) from maintable")
}.getMessage.contains("MV datamap is not supported for complex datatype columns and complex datatype return types of function : collect_list(cust_id)")
sql("drop table IF EXISTS maintable")
}

test("drop meta cache on mv datamap table") {
sql("drop table IF EXISTS maintable")
sql("create table maintable(name string, c_code int, price int) stored by 'carbondata'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object DataMapUtil {
parentOrder.foreach(parentcol =>
fields.filter(col => fieldRelationMap(col).aggregateFunction.isEmpty &&
fieldRelationMap(col).columnTableRelationList.size == 1 &&
parentcol.equals(fieldRelationMap(col).
parentcol.equalsIgnoreCase(fieldRelationMap(col).
columnTableRelationList.get(0).parentColumnName))
.map(cols => neworder :+= cols.column))
if (neworder.nonEmpty) {
Expand Down

0 comments on commit 101df73

Please sign in to comment.