Search in sources :

Example 46 with DistributedQueryRunner

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");
    }
}
Also used : TestingAccessControlManager.privilege(com.facebook.presto.testing.TestingAccessControlManager.privilege) Arrays(java.util.Arrays) SELECT_COLUMN(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.SELECT_COLUMN) PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) PartitionWithStatistics(com.facebook.presto.hive.metastore.PartitionWithStatistics) PlanMatchPattern.anyTree(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) MatchResult(com.facebook.presto.sql.planner.assertions.MatchResult) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) TupleDomain.withColumnDomains(com.facebook.presto.common.predicate.TupleDomain.withColumnDomains) OPTIMIZE_METADATA_QUERIES_IGNORE_STATS(com.facebook.presto.SystemSessionProperties.OPTIMIZE_METADATA_QUERIES_IGNORE_STATS) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) Slices(io.airlift.slice.Slices) Map(java.util.Map) PlanMatchPattern.expression(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) CUSTOMER(io.airlift.tpch.TpchTable.CUSTOMER) Assert.assertFalse(org.testng.Assert.assertFalse) PrincipalPrivileges(com.facebook.presto.hive.metastore.PrincipalPrivileges) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SHUFFLE_PARTITIONED_COLUMNS_FOR_TABLE_WRITE(com.facebook.presto.hive.HiveSessionProperties.SHUFFLE_PARTITIONED_COLUMNS_FOR_TABLE_WRITE) Set(java.util.Set) PlanMatchPattern.anySymbol(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anySymbol) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) MATERIALIZED_VIEW_MISSING_PARTITIONS_THRESHOLD(com.facebook.presto.hive.HiveSessionProperties.MATERIALIZED_VIEW_MISSING_PARTITIONS_THRESHOLD) PlanMatchPattern.unnest(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.unnest) Collectors.joining(java.util.stream.Collectors.joining) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) FileHiveMetastore(com.facebook.presto.hive.metastore.file.FileHiveMetastore) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) PARTIAL_AGGREGATION_PUSHDOWN_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PARTIAL_AGGREGATION_PUSHDOWN_ENABLED) PlanMatchPattern.node(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Domain.notNull(com.facebook.presto.common.predicate.Domain.notNull) Table(com.facebook.presto.hive.metastore.Table) Slice(io.airlift.slice.Slice) GATHER(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.GATHER) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) ArrayList(java.util.ArrayList) ParquetTypeUtils.pushdownColumnNameForSubfield(com.facebook.presto.parquet.ParquetTypeUtils.pushdownColumnNameForSubfield) Identity(com.facebook.presto.spi.security.Identity) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ArrayType(com.facebook.presto.common.type.ArrayType) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) OPTIMIZE_METADATA_QUERIES(com.facebook.presto.SystemSessionProperties.OPTIMIZE_METADATA_QUERIES) Functions(com.google.common.base.Functions) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SymbolAliases(com.facebook.presto.sql.planner.assertions.SymbolAliases) AbstractTestQueryFramework(com.facebook.presto.tests.AbstractTestQueryFramework) HIVE_CATALOG(com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG) Session(com.facebook.presto.Session) ELIMINATE_CROSS_JOINS(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinReorderingStrategy.ELIMINATE_CROSS_JOINS) StatsProvider(com.facebook.presto.cost.StatsProvider) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) Domain(com.facebook.presto.common.predicate.Domain) COLLECT_COLUMN_STATISTICS_ON_WRITE(com.facebook.presto.hive.HiveSessionProperties.COLLECT_COLUMN_STATISTICS_ON_WRITE) ColumnHandle(com.facebook.presto.spi.ColumnHandle) PUSHDOWN_FILTER_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PUSHDOWN_FILTER_ENABLED) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) ValueSet(com.facebook.presto.common.predicate.ValueSet) Metadata(com.facebook.presto.metadata.Metadata) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) HiveColumnHandle.isPushedDownSubfield(com.facebook.presto.hive.HiveColumnHandle.isPushedDownSubfield) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) QUERY_OPTIMIZATION_WITH_MATERIALIZED_VIEW_ENABLED(com.facebook.presto.SystemSessionProperties.QUERY_OPTIMIZATION_WITH_MATERIALIZED_VIEW_ENABLED) LINE_ITEM(io.airlift.tpch.TpchTable.LINE_ITEM) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ValueSet.ofRanges(com.facebook.presto.common.predicate.ValueSet.ofRanges) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) PUSHDOWN_DEREFERENCE_ENABLED(com.facebook.presto.SystemSessionProperties.PUSHDOWN_DEREFERENCE_ENABLED) Path(org.apache.hadoop.fs.Path) CallExpression(com.facebook.presto.spi.relation.CallExpression) URI(java.net.URI) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) PlanMatchPattern.globalAggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.globalAggregation) ImmutableSet(com.google.common.collect.ImmutableSet) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Domain.singleValue(com.facebook.presto.common.predicate.Domain.singleValue) VarcharType(com.facebook.presto.common.type.VarcharType) Collectors(java.util.stream.Collectors) TRUE_CONSTANT(com.facebook.presto.expressions.LogicalRowExpressions.TRUE_CONSTANT) PARQUET_DEREFERENCE_PUSHDOWN_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PARQUET_DEREFERENCE_PUSHDOWN_ENABLED) String.format(java.lang.String.format) Range(com.facebook.presto.common.predicate.Range) REMOTE_STREAMING(com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.REMOTE_STREAMING) Objects(java.util.Objects) List(java.util.List) Range.greaterThan(com.facebook.presto.common.predicate.Range.greaterThan) JOIN_REORDERING_STRATEGY(com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY) Domain.create(com.facebook.presto.common.predicate.Domain.create) RANGE_FILTERS_ON_SUBSCRIPTS_ENABLED(com.facebook.presto.hive.HiveSessionProperties.RANGE_FILTERS_ON_SUBSCRIPTS_ENABLED) MetastoreUtil.toPartitionValues(com.facebook.presto.hive.metastore.MetastoreUtil.toPartitionValues) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) ExpectedValueProvider(com.facebook.presto.sql.planner.assertions.ExpectedValueProvider) OPTIMIZE_METADATA_QUERIES_CALL_THRESHOLD(com.facebook.presto.SystemSessionProperties.OPTIMIZE_METADATA_QUERIES_CALL_THRESHOLD) NoHdfsAuthentication(com.facebook.presto.hive.authentication.NoHdfsAuthentication) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) NATION(io.airlift.tpch.TpchTable.NATION) PARTIAL_AGGREGATION_PUSHDOWN_FOR_VARIABLE_LENGTH_DATATYPES_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PARTIAL_AGGREGATION_PUSHDOWN_FOR_VARIABLE_LENGTH_DATATYPES_ENABLED) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) ORDERS(io.airlift.tpch.TpchTable.ORDERS) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Partition(com.facebook.presto.hive.metastore.Partition) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) LOCAL(com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.LOCAL) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) Objects.requireNonNull(java.util.Objects.requireNonNull) PlanMatchPattern.any(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.any) PlanMatchPattern.strictTableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.strictTableScan) Plan(com.facebook.presto.sql.planner.Plan) Domain.multipleValues(com.facebook.presto.common.predicate.Domain.multipleValues) PlanNodeSearcher.searchFrom(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom) RowExpression(com.facebook.presto.spi.relation.RowExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) INSERT_TABLE(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.INSERT_TABLE) Matcher(com.facebook.presto.sql.planner.assertions.Matcher) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Consumer(java.util.function.Consumer) PlanNode(com.facebook.presto.spi.plan.PlanNode) MaterializedResult(com.facebook.presto.testing.MaterializedResult) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) SYNTHESIZED(com.facebook.presto.hive.HiveColumnHandle.ColumnType.SYNTHESIZED) Assert.assertTrue(org.testng.Assert.assertTrue) REFERENCED_MATERIALIZED_VIEWS(com.facebook.presto.hive.HiveMetadata.REFERENCED_MATERIALIZED_VIEWS) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) TestHiveIntegrationSmokeTest.assertRemoteExchangesCount(com.facebook.presto.hive.TestHiveIntegrationSmokeTest.assertRemoteExchangesCount) Identity(com.facebook.presto.spi.security.Identity) QueryRunner(com.facebook.presto.testing.QueryRunner) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 47 with DistributedQueryRunner

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);
    }
}
Also used : PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) MaterializedResult(com.facebook.presto.testing.MaterializedResult) QueryRunner(com.facebook.presto.testing.QueryRunner) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 48 with DistributedQueryRunner

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");
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) MaterializedResult(com.facebook.presto.testing.MaterializedResult) QueryInfo(com.facebook.presto.execution.QueryInfo) QueryRunner(com.facebook.presto.testing.QueryRunner) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ConnectorSession(com.facebook.presto.spi.ConnectorSession) HiveQueryRunner.createBucketedSession(com.facebook.presto.hive.HiveQueryRunner.createBucketedSession) Session(com.facebook.presto.Session) HiveQueryRunner.createMaterializeExchangesSession(com.facebook.presto.hive.HiveQueryRunner.createMaterializeExchangesSession) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 49 with DistributedQueryRunner

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");
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 50 with DistributedQueryRunner

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);
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) OperatorStats(com.facebook.presto.operator.OperatorStats) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)111 Test (org.testng.annotations.Test)36 TpchPlugin (com.facebook.presto.tpch.TpchPlugin)33 Session (com.facebook.presto.Session)26 QueryId (com.facebook.presto.spi.QueryId)19 Logger (com.facebook.airlift.log.Logger)15 TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)14 MaterializedResult (com.facebook.presto.testing.MaterializedResult)13 QueryRunner (com.facebook.presto.testing.QueryRunner)13 ImmutableMap (com.google.common.collect.ImmutableMap)10 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)9 ArrayList (java.util.ArrayList)8 File (java.io.File)7 BeforeClass (org.testng.annotations.BeforeClass)7 JettyHttpClient (com.facebook.airlift.http.client.jetty.JettyHttpClient)6 FileResourceGroupConfigurationManagerFactory (com.facebook.presto.resourceGroups.FileResourceGroupConfigurationManagerFactory)6 H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)6 Path (java.nio.file.Path)6 Future (java.util.concurrent.Future)6 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)5