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 @@ -72,6 +72,7 @@
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.singleGroupingSet;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.unnest;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values;
import static com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.INSERT_TABLE;
Expand Down Expand Up @@ -2921,6 +2922,46 @@ public void testAutoRefreshMaterializedViewAfterInsertion()
}
}

public void testMaterializedViewNotRefreshedInNonLegacyMode()
{
Session nonLegacySession = Session.builder(getSession())
.setSystemProperty("legacy_materialized_views", "false")
.build();
try {
assertUpdate("CREATE TABLE base_table (id BIGINT, name VARCHAR, part_key BIGINT) WITH (partitioned_by = ARRAY['part_key'])");
assertUpdate("INSERT INTO base_table VALUES (1, 'Alice', 100), (2, 'Bob', 200)", 2);
assertUpdate("CREATE MATERIALIZED VIEW simple_mv WITH (partitioned_by = ARRAY['part_key']) AS SELECT id, name, part_key FROM base_table");

assertPlan(nonLegacySession, "SELECT * FROM simple_mv",
anyTree(tableScan("base_table")));
}
finally {
assertUpdate("DROP TABLE base_table");
assertUpdate("DROP MATERIALIZED VIEW simple_mv");
Comment thread
hantangwangd marked this conversation as resolved.
}
}

@Test
public void testMaterializedViewRefreshedInNonLegacyMode()
{
Session nonLegacySession = Session.builder(getSession())
.setSystemProperty("legacy_materialized_views", "false")
.build();
try {
assertUpdate("CREATE TABLE base_table (id BIGINT, name VARCHAR, part_key BIGINT) WITH (partitioned_by = ARRAY['part_key'])");
assertUpdate("INSERT INTO base_table VALUES (1, 'Alice', 100), (2, 'Bob', 200)", 2);
assertUpdate("CREATE MATERIALIZED VIEW simple_mv WITH (partitioned_by = ARRAY['part_key']) AS SELECT id, name, part_key FROM base_table");
assertUpdate("REFRESH MATERIALIZED VIEW simple_mv where part_key > 0", 2);

assertPlan(nonLegacySession, "SELECT * FROM simple_mv",
anyTree(tableScan("simple_mv")));
}
finally {
assertUpdate("DROP TABLE base_table");
assertUpdate("DROP MATERIALIZED VIEW simple_mv");
}
}

private void setReferencedMaterializedViews(DistributedQueryRunner queryRunner, String tableName, List<String> referencedMaterializedViews)
{
appendTableParameter(replicateHiveMetastore(queryRunner),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ private RelationPlan planMaterializedView(Table node, Analysis.MaterializedViewI
List<VariableReferenceExpression> viewQueryVariables = viewQueryPlan.getFieldMappings();

checkArgument(
dataTableVariables.size() == viewQueryVariables.size(),
"Materialized view %s has mismatched field counts: data table has %s fields but view query has %s fields",
dataTableDescriptor.getVisibleFieldCount() == viewQueryVariables.size(),
"Materialized view %s has mismatched field counts: data table has %s visible fields but view query has %s fields",
materializedViewName,
dataTableVariables.size(),
dataTableDescriptor.getVisibleFieldCount(),
viewQueryVariables.size());

ImmutableList.Builder<VariableReferenceExpression> outputVariablesBuilder = ImmutableList.builder();
Expand Down
Loading