Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6053,9 +6053,20 @@ public void testRefreshMaterializedView()
"SELECT COUNT(*) FROM ( " + expectedInsertQuery + " )",
false, true);

refreshSql = "REFRESH MATERIALIZED VIEW test_customer_view_5 WHERE regionkey = 1 OR nationkey = 24";
expectedInsertQuery = "SELECT nation.name AS nationname, customer.custkey, customer.name AS customername, UPPER(customer.mktsegment) AS marketsegment, customer.nationkey, regionkey " +
"FROM test_nation_base_5 nation JOIN test_customer_base_5 customer ON (nation.nationkey = customer.nationkey) " +
"WHERE regionkey = 1 OR customer.nationkey = 24";
QueryAssertions.assertQuery(
queryRunner,
session,
refreshSql,
queryRunner,
"SELECT COUNT(*) FROM ( " + expectedInsertQuery + " )",
false, true);

// Test invalid predicates
assertQueryFails("REFRESH MATERIALIZED VIEW test_customer_view_5 WHERE nationname = 'UNITED STATES'", ".*Refresh materialized view by column nationname is not supported.*");
assertQueryFails("REFRESH MATERIALIZED VIEW test_customer_view_5 WHERE regionkey = 1 OR nationkey = 24", ".*Only logical AND is supported in WHERE clause.*");
assertQueryFails("REFRESH MATERIALIZED VIEW test_customer_view_5 WHERE regionkey + nationkey = 25", ".*Only columns specified on literals are supported in WHERE clause.*");
assertQueryFails("REFRESH MATERIALIZED VIEW test_customer_view_5", ".*Refresh Materialized View without predicates is not supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

/**
* Map predicates on view columns in the RefreshMaterializedView where clause to predicates on base table columns,
* which could be used for predicate push-down afterwards. Mapped predicates are connected by AND.
* which could be used for predicate push-down afterwards. Mapped predicates are connected by AND or OR.
* For view columns that do not have a direct mapping to a base table column, keep the predicate with the view.
*/
public class RefreshMaterializedViewPredicateAnalyzer
Expand Down Expand Up @@ -120,9 +120,12 @@ protected Void visitExpression(Expression node, Void context)
@Override
protected Void visitLogicalBinaryExpression(LogicalBinaryExpression node, Void context)
{
if (!LogicalBinaryExpression.Operator.AND.equals(node.getOperator())) {
throw new SemanticException(NOT_SUPPORTED, node, "Only logical AND is supported in WHERE clause.");
if (LogicalBinaryExpression.Operator.OR.equals(node.getOperator())) {
SchemaTableName viewName = new SchemaTableName(viewDefinition.getSchema(), viewDefinition.getTable());
tablePredicatesBuilder.put(viewName, node);
return null;
}

if (!(node.getLeft() instanceof ComparisonExpression || node.getLeft() instanceof LogicalBinaryExpression)) {
throw new SemanticException(NOT_SUPPORTED, node.getLeft(), "Only column specifications connected by logical AND are supported in WHERE clause.");
}
Expand Down
Loading