use of com.facebook.presto.tests.DistributedQueryRunner in project presto by prestodb.
the class TestHiveLogicalPlanner method testMaterializedViewQueryAccessControl.
@Test
public void testMaterializedViewQueryAccessControl() {
QueryRunner queryRunner = getQueryRunner();
Session invokerSession = Session.builder(getSession()).setIdentity(new Identity("test_view_invoker", Optional.empty())).setCatalog(getSession().getCatalog().get()).setSchema(getSession().getSchema().get()).setSystemProperty(QUERY_OPTIMIZATION_WITH_MATERIALIZED_VIEW_ENABLED, "true").build();
Session ownerSession = getSession();
queryRunner.execute(ownerSession, "CREATE TABLE test_orders_base WITH (partitioned_by = ARRAY['orderstatus']) " + "AS SELECT orderkey, custkey, totalprice, orderstatus FROM orders LIMIT 10");
queryRunner.execute(ownerSession, "CREATE MATERIALIZED VIEW test_orders_view " + "WITH (partitioned_by = ARRAY['orderstatus']) " + "AS SELECT SUM(totalprice) AS totalprice, orderstatus FROM test_orders_base GROUP BY orderstatus");
setReferencedMaterializedViews((DistributedQueryRunner) getQueryRunner(), "test_orders_base", ImmutableList.of("test_orders_view"));
Consumer<String> testQueryWithDeniedPrivilege = query -> {
// Verify checking the base table instead of the materialized view for SELECT permission
assertAccessDenied(invokerSession, query, "Cannot select from columns \\[.*\\] in table .*test_orders_base.*", privilege(invokerSession.getUser(), "test_orders_base", SELECT_COLUMN));
assertAccessAllowed(invokerSession, query, privilege(invokerSession.getUser(), "test_orders_view", SELECT_COLUMN));
};
try {
// Check for both the direct materialized view query and the base table query optimization with materialized view
String directMaterializedViewQuery = "SELECT totalprice, orderstatus FROM test_orders_view";
String queryWithMaterializedViewOptimization = "SELECT SUM(totalprice) AS totalprice, orderstatus FROM test_orders_base GROUP BY orderstatus";
// Test when the materialized view is not materialized yet
testQueryWithDeniedPrivilege.accept(directMaterializedViewQuery);
testQueryWithDeniedPrivilege.accept(queryWithMaterializedViewOptimization);
// Test when the materialized view is partially materialized
queryRunner.execute(ownerSession, "REFRESH MATERIALIZED VIEW test_orders_view WHERE orderstatus = 'F'");
testQueryWithDeniedPrivilege.accept(directMaterializedViewQuery);
testQueryWithDeniedPrivilege.accept(queryWithMaterializedViewOptimization);
// Test when the materialized view is fully materialized
queryRunner.execute(ownerSession, "REFRESH MATERIALIZED VIEW test_orders_view WHERE orderstatus <> 'F'");
testQueryWithDeniedPrivilege.accept(directMaterializedViewQuery);
testQueryWithDeniedPrivilege.accept(queryWithMaterializedViewOptimization);
} finally {
queryRunner.execute(ownerSession, "DROP MATERIALIZED VIEW test_orders_view");
queryRunner.execute(ownerSession, "DROP TABLE test_orders_base");
}
}
use of com.facebook.presto.tests.DistributedQueryRunner in project presto by prestodb.
the class TestHiveLogicalPlanner method testBaseToViewConversionWithMultipleCandidates.
@Test
public void testBaseToViewConversionWithMultipleCandidates() {
Session queryOptimizationWithMaterializedView = Session.builder(getSession()).setSystemProperty(QUERY_OPTIMIZATION_WITH_MATERIALIZED_VIEW_ENABLED, "true").build();
QueryRunner queryRunner = getQueryRunner();
String table = "orders_partitioned";
String view1 = "test_orders_view1";
String view2 = "test_orders_view2";
String view3 = "test_orders_view3";
try {
queryRunner.execute(format("CREATE TABLE %s WITH (partitioned_by = ARRAY['ds']) AS " + "SELECT orderkey, orderpriority, orderdate, totalprice, '2020-01-01' as ds FROM orders WHERE orderkey < 1000 " + "UNION ALL " + "SELECT orderkey, orderpriority, orderdate, totalprice, '2020-01-02' as ds FROM orders WHERE orderkey > 1000", table));
assertUpdate(format("CREATE MATERIALIZED VIEW %s WITH (partitioned_by = ARRAY['ds']) " + "AS SELECT orderkey, orderpriority, ds FROM %s", view1, table));
assertUpdate(format("CREATE MATERIALIZED VIEW %s WITH (partitioned_by = ARRAY['ds']) " + "AS SELECT orderkey, orderdate, ds FROM %s", view2, table));
assertUpdate(format("CREATE MATERIALIZED VIEW %s WITH (partitioned_by = ARRAY['ds']) " + "AS SELECT orderkey, totalprice, ds FROM %s", view3, table));
assertTrue(queryRunner.tableExists(getSession(), view1));
assertTrue(queryRunner.tableExists(getSession(), view2));
assertTrue(queryRunner.tableExists(getSession(), view3));
setReferencedMaterializedViews((DistributedQueryRunner) queryRunner, table, ImmutableList.of(view1, view2, view3));
assertUpdate(format("REFRESH MATERIALIZED VIEW %s WHERE ds='2020-01-01'", view1), 255);
assertUpdate(format("REFRESH MATERIALIZED VIEW %s WHERE ds='2020-01-02'", view1), 14745);
assertUpdate(format("REFRESH MATERIALIZED VIEW %s WHERE ds='2020-01-01'", view2), 255);
assertUpdate(format("REFRESH MATERIALIZED VIEW %s WHERE ds='2020-01-02'", view2), 14745);
assertUpdate(format("REFRESH MATERIALIZED VIEW %s WHERE ds='2020-01-01'", view3), 255);
assertUpdate(format("REFRESH MATERIALIZED VIEW %s WHERE ds='2020-01-02'", view3), 14745);
String baseQuery = format("SELECT orderkey, orderdate from %s where orderkey < 1000 ORDER BY orderkey", table);
String viewQuery = format("SELECT orderkey, orderdate from %s where orderkey < 1000 ORDER BY orderkey", view2);
// Try optimizing the base query when there is one compatible candidate from the referenced materialized views
MaterializedResult optimizedQueryResult = computeActual(queryOptimizationWithMaterializedView, baseQuery);
MaterializedResult baseQueryResult = computeActual(baseQuery);
assertEquals(optimizedQueryResult, baseQueryResult);
PlanMatchPattern expectedPattern = anyTree(anyTree(values("orderkey", "orderdate")), anyTree(filter("orderkey_25 < BIGINT'1000'", PlanMatchPattern.constrainedTableScan(view2, ImmutableMap.of(), ImmutableMap.of("orderkey_25", "orderkey")))));
assertPlan(queryOptimizationWithMaterializedView, baseQuery, expectedPattern);
assertPlan(getSession(), viewQuery, expectedPattern);
// Try optimizing the base query when all candidates are incompatible
setReferencedMaterializedViews((DistributedQueryRunner) queryRunner, table, ImmutableList.of(view1, view3));
assertPlan(queryOptimizationWithMaterializedView, baseQuery, anyTree(filter("orderkey < BIGINT'1000'", PlanMatchPattern.constrainedTableScan(table, ImmutableMap.of(), ImmutableMap.of("orderkey", "orderkey")))));
} finally {
queryRunner.execute("DROP MATERIALIZED VIEW IF EXISTS " + view1);
queryRunner.execute("DROP MATERIALIZED VIEW IF EXISTS " + view2);
queryRunner.execute("DROP MATERIALIZED VIEW IF EXISTS " + view3);
queryRunner.execute("DROP TABLE IF EXISTS " + table);
}
}
use of com.facebook.presto.tests.DistributedQueryRunner in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testRefreshMaterializedViewSimple.
@Test
public void testRefreshMaterializedViewSimple() {
Session session = getSession();
QueryRunner queryRunner = getQueryRunner();
computeActual("CREATE TABLE orders_partitioned WITH (partitioned_by = ARRAY['ds']) " + "AS SELECT orderkey, orderpriority, '2020-01-01' as ds FROM orders WHERE orderkey < 1000 " + "UNION ALL " + "SELECT orderkey, orderpriority, '2019-01-02' as ds FROM orders WHERE orderkey > 1000");
computeActual("CREATE MATERIALIZED VIEW test_orders_view WITH (partitioned_by = ARRAY['ds']) " + "AS SELECT orderkey, orderpriority, ds FROM orders_partitioned");
String refreshSql = "REFRESH MATERIALIZED VIEW test_orders_view WHERE ds='2020-01-01'";
String expectedInsertQuery = "SELECT orderkey, orderpriority, ds " + "FROM (" + " SELECT * FROM orders_partitioned WHERE ds='2020-01-01'" + ") orders_partitioned";
QueryAssertions.assertQuery(queryRunner, session, refreshSql, queryRunner, "SELECT COUNT(*) FROM ( " + expectedInsertQuery + " )", false, true);
ResultWithQueryId<MaterializedResult> resultWithQueryId = ((DistributedQueryRunner) queryRunner).executeWithQueryId(session, refreshSql);
QueryInfo queryInfo = ((DistributedQueryRunner) queryRunner).getQueryInfo(resultWithQueryId.getQueryId());
assertEquals(queryInfo.getExpandedQuery().get(), "-- Expanded Query: REFRESH MATERIALIZED VIEW test_orders_view WHERE (ds = '2020-01-01')\n" + "INSERT INTO test_orders_view SELECT\n" + " orderkey\n" + ", orderpriority\n" + ", ds\n" + "FROM\n" + " orders_partitioned\n");
}
use of com.facebook.presto.tests.DistributedQueryRunner in project presto by prestodb.
the class TestHiveLogicalPlanner method testVirtualBucketing.
@Test
public void testVirtualBucketing() {
try {
assertUpdate("CREATE TABLE test_virtual_bucket(a bigint, b bigint)");
Session virtualBucketEnabled = Session.builder(getSession()).setCatalogSessionProperty(HIVE_CATALOG, "virtual_bucket_count", "2").build();
assertPlan(virtualBucketEnabled, "SELECT COUNT(DISTINCT(\"$path\")) FROM test_virtual_bucket", anyTree(exchange(REMOTE_STREAMING, GATHER, anyTree(tableScan("test_virtual_bucket", ImmutableMap.of())))), assertRemoteExchangesCount(1, getSession(), (DistributedQueryRunner) getQueryRunner()));
} finally {
assertUpdate("DROP TABLE IF EXISTS test_virtual_bucket");
}
}
use of com.facebook.presto.tests.DistributedQueryRunner in project presto by prestodb.
the class TestHiveDistributedJoinQueriesWithDynamicFiltering method testJoinWithEmptyBuildSide.
@Test
public void testJoinWithEmptyBuildSide() {
Session session = Session.builder(getSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, FeaturesConfig.JoinDistributionType.BROADCAST.name()).setSystemProperty(PUSHDOWN_SUBFIELDS_ENABLED, "false").setCatalogSessionProperty(HIVE_CATALOG, PUSHDOWN_FILTER_ENABLED, "false").build();
DistributedQueryRunner runner = (DistributedQueryRunner) getQueryRunner();
ResultWithQueryId<MaterializedResult> result = runner.executeWithQueryId(session, "SELECT * FROM lineitem JOIN orders ON lineitem.orderkey = orders.orderkey AND orders.totalprice = 123.4567");
assertEquals(result.getResult().getRowCount(), 0);
OperatorStats probeStats = searchScanFilterAndProjectOperatorStats(result.getQueryId(), "lineitem");
// Probe-side is not scanned at all, due to dynamic filtering:
assertEquals(probeStats.getInputPositions(), 0L);
}
Aggregations