Star Tree Create Cube - Filter property predicate must evaluate boolean type.

This commit is contained in:
Sundar Annamalai 2021-06-22 19:34:40 -04:00
parent 11b2a13302
commit ee3728f3f4
3 changed files with 43 additions and 3 deletions

View File

@ -820,7 +820,11 @@ class StatementAnalyzer
throw new SemanticException(NOT_SUPPORTED, node, "Column '%s' not allowed in source filter predicate. Source filter predicate cannot contain any of the columns defined in Group property", identifier);
});
//analyze expression to identify if coercions required
analyzeExpression(predicate, queryScope);
ExpressionAnalysis filterAnalysis = analyzeExpression(predicate, queryScope);
Type predicateType = filterAnalysis.getType(predicate);
if (!predicateType.equals(BOOLEAN) && !predicateType.equals(UNKNOWN)) {
throw new SemanticException(TYPE_MISMATCH, predicate, "Filter property must evaluate to a boolean: actual type '%s'", predicateType);
}
});
return createAndAssignScope(node, scope, outputFields.build());
}

View File

@ -366,8 +366,10 @@ public class StarTreeAggregationRule
//Cube has no additional predicates to compare with
return true;
}
if (splitPredicate.getRight() == null) {
//No remaining predicate in Query. Can't compare with Cube predicate
if (splitPredicate.getRight() == null || !doesCubeContainQueryPredicateColumns(splitPredicate.getRight(), cubeMetadata)) {
// Cube has more predicate to match but query does not
// OR
// Cube does not contain all columns in the remaining predicate
return false;
}
Expression cubePredicate = ExpressionUtils.rewriteIdentifiersToSymbolReferences(sqlParser.createExpression(cubeFilter.getCubePredicate(), new ParsingOptions()));

View File

@ -653,6 +653,40 @@ public abstract class AbstractTestStarTreeQueries
assertUpdate("DROP TABLE orders_table_predicate_unsupported_predicate");
}
@Test
public void testCreateCubeWithIncorrectFilterPredicate()
{
assertQueryFails(sessionStarTree,
"CREATE CUBE orders_cube_unsuported_filter_predicate ON orders WITH (AGGREGATIONS=(sum(totalprice)), GROUP=(custkey), FILTER = (orderdate))",
".*Filter property must evaluate to a boolean: actual type 'date'.*");
assertQueryFails(sessionStarTree,
"CREATE CUBE orders_cube_unsuported_filter_predicate ON orders WITH (AGGREGATIONS=(sum(totalprice)), GROUP=(orderdate), FILTER = (custkey))",
".*Filter property must evaluate to a boolean: actual type 'bigint'.*");
}
@Test
public void testCubeInsertWithMultipleCube()
{
computeActual("CREATE TABLE orders_table_multiple_cube_insert AS SELECT * FROM orders");
computeActual("CREATE CUBE orders_cube_mutiple_cube_insert_1 ON orders_table_multiple_cube_insert WITH (AGGREGATIONS = (max(totalprice)), GROUP = (orderdate,custkey))");
assertQuerySucceeds("INSERT INTO CUBE orders_cube_mutiple_cube_insert_1 WHERE custkey >= 100");
assertQuery(sessionStarTree,
"SELECT custkey, max(totalprice) FROM orders_table_multiple_cube_insert WHERE custkey >= 101 GROUP BY custkey",
"SELECT custkey, max(totalprice) FROM orders WHERE custkey >= 101 GROUP BY custkey",
assertTableScan("orders_cube_mutiple_cube_insert_1"));
computeActual("CREATE CUBE orders_cube_mutiple_cube_insert_2 ON orders_table_multiple_cube_insert WITH (AGGREGATIONS = (max(totalprice)), GROUP = (orderdate,custkey), FILTER = (orderkey > 1))");
assertQuerySucceeds(sessionStarTree, "INSERT INTO CUBE orders_cube_mutiple_cube_insert_2 WHERE custkey >= 100");
assertQuery(sessionStarTree,
"SELECT custkey, max(totalprice) FROM orders_table_multiple_cube_insert WHERE custkey >= 101 GROUP BY custkey",
"SELECT custkey, max(totalprice) FROM orders WHERE custkey >= 101 GROUP BY custkey",
assertTableScan("orders_cube_mutiple_cube_insert_1"));
assertQuery(sessionStarTree,
"SELECT custkey, max(totalprice) FROM orders_table_multiple_cube_insert WHERE orderkey > 1 AND custkey >= 101 GROUP BY custkey",
"SELECT custkey, max(totalprice) FROM orders WHERE orderkey > 1 AND custkey >= 101 GROUP BY custkey",
assertTableScan("orders_cube_mutiple_cube_insert_2"));
assertUpdate("DROP TABLE orders_table_multiple_cube_insert");
}
private Consumer<Plan> assertInTableScans(String tableName)
{
return plan ->