diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveIntegrationSmokeTest.java b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveIntegrationSmokeTest.java index d7e06a1f926db..a6787c0d74d74 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveIntegrationSmokeTest.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveIntegrationSmokeTest.java @@ -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."); } diff --git a/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/RefreshMaterializedViewPredicateAnalyzer.java b/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/RefreshMaterializedViewPredicateAnalyzer.java index 4e6c3fb6cd3e4..37b023ddbe9d5 100644 --- a/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/RefreshMaterializedViewPredicateAnalyzer.java +++ b/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/RefreshMaterializedViewPredicateAnalyzer.java @@ -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 @@ -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."); }