Search in sources :

Example 46 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class MemoryLocalQueryRunner method execute.

public List<Page> execute(@Language("SQL") String query) {
    MemoryPool memoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(2, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(new DataSize(1, GIGABYTE));
    QueryContext queryContext = new QueryContext(new QueryId("test"), new DataSize(1, GIGABYTE), new DataSize(2, GIGABYTE), new DataSize(1, GIGABYTE), new DataSize(2, GIGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(4, GIGABYTE), spillSpaceTracker, listJsonCodec(TaskMemoryReservationSummary.class));
    TaskContext taskContext = queryContext.addTaskContext(new TaskStateMachine(new TaskId("query", 0, 0, 0), localQueryRunner.getExecutor()), localQueryRunner.getDefaultSession(), Optional.empty(), false, false, false, false, false);
    // Use NullOutputFactory to avoid coping out results to avoid affecting benchmark results
    ImmutableList.Builder<Page> output = ImmutableList.builder();
    List<Driver> drivers = localQueryRunner.createDrivers(query, new PageConsumerOperator.PageConsumerOutputFactory(types -> output::add), taskContext);
    boolean done = false;
    while (!done) {
        boolean processed = false;
        for (Driver driver : drivers) {
            if (!driver.isFinished()) {
                driver.process();
                processed = true;
            }
        }
        done = !processed;
    }
    return output.build();
}
Also used : TaskMemoryReservationSummary(com.facebook.presto.operator.TaskMemoryReservationSummary) Page(com.facebook.presto.common.Page) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) JsonCodec.listJsonCodec(com.facebook.airlift.json.JsonCodec.listJsonCodec) MemoryConnectorFactory(com.facebook.presto.plugin.memory.MemoryConnectorFactory) SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) QueryContext(com.facebook.presto.memory.QueryContext) TableHandle(com.facebook.presto.spi.TableHandle) MemoryPool(com.facebook.presto.memory.MemoryPool) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) TaskContext(com.facebook.presto.operator.TaskContext) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) Driver(com.facebook.presto.operator.Driver) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) Plugin(com.facebook.presto.spi.Plugin) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) DataSize(io.airlift.units.DataSize) List(java.util.List) TaskId(com.facebook.presto.execution.TaskId) QueryId(com.facebook.presto.spi.QueryId) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) TaskMemoryReservationSummary(com.facebook.presto.operator.TaskMemoryReservationSummary) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) Metadata(com.facebook.presto.metadata.Metadata) SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) TaskContext(com.facebook.presto.operator.TaskContext) TaskId(com.facebook.presto.execution.TaskId) ImmutableList(com.google.common.collect.ImmutableList) QueryId(com.facebook.presto.spi.QueryId) Driver(com.facebook.presto.operator.Driver) Page(com.facebook.presto.common.Page) QueryContext(com.facebook.presto.memory.QueryContext) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) DataSize(io.airlift.units.DataSize) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) MemoryPool(com.facebook.presto.memory.MemoryPool)

Example 47 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestHiveDistributedJoinQueriesWithDynamicFiltering method searchScanFilterAndProjectOperatorStats.

private OperatorStats searchScanFilterAndProjectOperatorStats(QueryId queryId, String tableName) {
    DistributedQueryRunner runner = (DistributedQueryRunner) getQueryRunner();
    Plan plan = runner.getQueryPlan(queryId);
    PlanNodeId nodeId = PlanNodeSearcher.searchFrom(plan.getRoot()).where(node -> {
        if (!(node instanceof ProjectNode)) {
            return false;
        }
        ProjectNode projectNode = (ProjectNode) node;
        FilterNode filterNode = (FilterNode) projectNode.getSource();
        TableScanNode tableScanNode = (TableScanNode) filterNode.getSource();
        return tableName.equals(((HiveTableHandle) (tableScanNode.getTable().getConnectorHandle())).getTableName());
    }).findOnlyElement().getId();
    return runner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getQueryStats().getOperatorSummaries().stream().filter(summary -> nodeId.equals(summary.getPlanNodeId())).collect(MoreCollectors.onlyElement());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) AbstractTestJoinQueries(com.facebook.presto.tests.AbstractTestJoinQueries) Assert.assertEquals(org.testng.Assert.assertEquals) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) OperatorStats(com.facebook.presto.operator.OperatorStats) ENABLE_DYNAMIC_FILTERING(com.facebook.presto.SystemSessionProperties.ENABLE_DYNAMIC_FILTERING) FilterNode(com.facebook.presto.spi.plan.FilterNode) ResultWithQueryId(com.facebook.presto.tests.ResultWithQueryId) Plan(com.facebook.presto.sql.planner.Plan) PUSHDOWN_SUBFIELDS_ENABLED(com.facebook.presto.SystemSessionProperties.PUSHDOWN_SUBFIELDS_ENABLED) HIVE_CATALOG(com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG) Session(com.facebook.presto.Session) MoreCollectors(com.google.common.collect.MoreCollectors) PlanNodeSearcher(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TpchTable.getTables(io.airlift.tpch.TpchTable.getTables) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) JOIN_REORDERING_STRATEGY(com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY) PUSHDOWN_FILTER_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PUSHDOWN_FILTER_ENABLED) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) Assertions.assertLessThanOrEqual(com.facebook.airlift.testing.Assertions.assertLessThanOrEqual) QueryId(com.facebook.presto.spi.QueryId) Assertions.assertGreaterThan(com.facebook.airlift.testing.Assertions.assertGreaterThan) BROADCAST(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType.BROADCAST) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) Plan(com.facebook.presto.sql.planner.Plan)

Example 48 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestEventListenerWithExchangeMaterialization method testRuntimeOptimizedStagesCorrectness.

@Test
public void testRuntimeOptimizedStagesCorrectness() throws Exception {
    // We expect one runtime optimized stage: 1.
    int expectedEvents = 2;
    QueryId queryId = runQueryAndWaitForEvents("SELECT phone, regionkey FROM nation INNER JOIN supplier ON supplier.nationkey=nation.nationkey", expectedEvents);
    QueryCreatedEvent queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    QueryCompletedEvent queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    QueryMetadata queryMetadata = queryCompletedEvent.getMetadata();
    Optional<List<StageId>> runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertEquals(queryMetadata.getQueryId(), queryId.toString());
    assertEquals(queryMetadata.getRuntimeOptimizedStages().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages().get(0), "1");
    assertTrue(runtimeOptimizedStages.isPresent());
    assertEquals(runtimeOptimizedStages.get().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages(), runtimeOptimizedStages.get().stream().map(stageId -> String.valueOf(stageId.getId())).collect(toImmutableList()));
    // Now, the following query should not trigger runtime optimizations, so should have empty list of runtime optimized stages.
    runQueryAndWaitForEvents("SELECT phone, regionkey FROM supplier INNER JOIN nation ON supplier.nationkey=nation.nationkey", expectedEvents);
    queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertTrue(queryCompletedEvent.getMetadata().getRuntimeOptimizedStages().isEmpty());
    assertFalse(runtimeOptimizedStages.isPresent());
    // Now, the following query should have two optimized joins in a single stage (both on the same nationkey), therefore expect only one optimized stage: 1.
    runQueryAndWaitForEvents("SELECT supplier.phone, regionkey, custkey FROM nation INNER JOIN supplier ON supplier.nationkey=nation.nationkey INNER JOIN customer ON nation.nationkey=customer.nationkey", expectedEvents);
    queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    queryMetadata = queryCompletedEvent.getMetadata();
    runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertEquals(queryMetadata.getRuntimeOptimizedStages().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages().get(0), "1");
    assertTrue(runtimeOptimizedStages.isPresent());
    assertEquals(runtimeOptimizedStages.get().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages(), runtimeOptimizedStages.get().stream().map(stageId -> String.valueOf(stageId.getId())).collect(toImmutableList()));
    // Now, the following query should have two runtime optimized stages: 1 and 4, corresponding to the two join operations (on regionkey and nationkey respectively).
    runQueryAndWaitForEvents("WITH natreg AS (SELECT nation.regionkey, nationkey, region.name FROM region INNER JOIN nation ON nation.regionkey=region.regionkey) SELECT phone, regionkey FROM natreg INNER JOIN supplier ON supplier.nationkey=natreg.nationkey", expectedEvents);
    queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    queryMetadata = queryCompletedEvent.getMetadata();
    runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertEquals(queryMetadata.getRuntimeOptimizedStages().size(), 2);
    assertEquals(ImmutableSet.copyOf(queryMetadata.getRuntimeOptimizedStages()), ImmutableSet.of("1", "4"));
    assertTrue(runtimeOptimizedStages.isPresent());
    assertEquals(runtimeOptimizedStages.get().size(), 2);
    assertEquals(queryMetadata.getRuntimeOptimizedStages(), runtimeOptimizedStages.get().stream().map(stageId -> String.valueOf(stageId.getId())).collect(toImmutableList()));
}
Also used : QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) QueryId(com.facebook.presto.spi.QueryId) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 49 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestEventListenerWithExchangeMaterialization method runQueryAndWaitForEvents.

private QueryId runQueryAndWaitForEvents(@Language("SQL") String sql, int numEventsExpected) throws Exception {
    generatedEvents.initialize(numEventsExpected);
    QueryId resultId = queryRunner.executeWithQueryId(session, sql).getQueryId();
    generatedEvents.waitForEvents(600);
    return resultId;
}
Also used : QueryId(com.facebook.presto.spi.QueryId)

Example 50 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class ClusterMemoryManager method findLargestMemoryQuery.

private QueryExecution findLargestMemoryQuery(ClusterMemoryPoolInfo generalPool, Iterable<QueryExecution> queries) {
    QueryExecution biggestQuery = null;
    long maxMemory = -1;
    Optional<QueryId> largestMemoryQuery = generalPool.getLargestMemoryQuery();
    // If present, this means the resource manager is determining the largest query, so do not make this determination locally
    if (memoryManagerService.isPresent()) {
        return largestMemoryQuery.flatMap(largestMemoryQueryId -> Streams.stream(queries).filter(query -> query.getQueryId().equals(largestMemoryQueryId)).findFirst()).orElse(null);
    }
    for (QueryExecution queryExecution : queries) {
        if (resourceOvercommit(queryExecution.getSession())) {
            // since their memory usage is unbounded.
            continue;
        }
        long bytesUsed = getQueryMemoryReservation(queryExecution);
        if (bytesUsed > maxMemory) {
            biggestQuery = queryExecution;
            maxMemory = bytesUsed;
        }
    }
    return biggestQuery;
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) SYSTEM(com.facebook.presto.execution.QueryLimit.Source.SYSTEM) QUERY(com.facebook.presto.execution.QueryLimit.Source.QUERY) Duration(io.airlift.units.Duration) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) QueryMemoryInfo(com.facebook.presto.memory.LowMemoryKiller.QueryMemoryInfo) QueryLimit.getMinimum(com.facebook.presto.execution.QueryLimit.getMinimum) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Map(java.util.Map) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) ServerConfig(com.facebook.presto.server.ServerConfig) QueryLimit(com.facebook.presto.execution.QueryLimit) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ExceededMemoryLimitException.exceededGlobalUserLimit(com.facebook.presto.ExceededMemoryLimitException.exceededGlobalUserLimit) Math.min(java.lang.Math.min) Streams(com.google.common.collect.Streams) GuardedBy(javax.annotation.concurrent.GuardedBy) Codec(com.facebook.airlift.json.Codec) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) QueryIdGenerator(com.facebook.presto.execution.QueryIdGenerator) QueryExecution(com.facebook.presto.execution.QueryExecution) DataSize(io.airlift.units.DataSize) List(java.util.List) Stream(java.util.stream.Stream) Comparator.comparingLong(java.util.Comparator.comparingLong) Entry(java.util.Map.Entry) Optional(java.util.Optional) JmxException(org.weakref.jmx.JmxException) RESOURCE_GROUP(com.facebook.presto.execution.QueryLimit.Source.RESOURCE_GROUP) SystemSessionProperties.resourceOvercommit(com.facebook.presto.SystemSessionProperties.resourceOvercommit) Joiner(com.google.common.base.Joiner) QueryLimit.createDataSizeLimit(com.facebook.presto.execution.QueryLimit.createDataSizeLimit) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) RESOURCE_OVERCOMMIT(com.facebook.presto.SystemSessionProperties.RESOURCE_OVERCOMMIT) Logger(com.facebook.airlift.log.Logger) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) CLUSTER_OUT_OF_MEMORY(com.facebook.presto.spi.StandardErrorCode.CLUSTER_OUT_OF_MEMORY) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ResourceGroupQueryLimits(com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits) SystemSessionProperties.getQueryMaxTotalMemory(com.facebook.presto.SystemSessionProperties.getQueryMaxTotalMemory) ImmutableList(com.google.common.collect.ImmutableList) Managed(org.weakref.jmx.Managed) Closer(com.google.common.io.Closer) Verify.verify(com.google.common.base.Verify.verify) SmileCodec(com.facebook.airlift.json.smile.SmileCodec) Objects.requireNonNull(java.util.Objects.requireNonNull) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SystemSessionProperties.getQueryMaxMemory(com.facebook.presto.SystemSessionProperties.getQueryMaxMemory) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SimpleEntry(java.util.AbstractMap.SimpleEntry) ExecutorService(java.util.concurrent.ExecutorService) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) ClusterMemoryPoolManager(com.facebook.presto.spi.memory.ClusterMemoryPoolManager) ObjectNames.generatedNameOf(org.weakref.jmx.ObjectNames.generatedNameOf) SHUTTING_DOWN(com.facebook.presto.spi.NodeState.SHUTTING_DOWN) InternalCommunicationConfig(com.facebook.presto.server.InternalCommunicationConfig) IOException(java.io.IOException) LocationFactory(com.facebook.presto.execution.LocationFactory) HttpClient(com.facebook.airlift.http.client.HttpClient) ExceededMemoryLimitException.exceededGlobalTotalLimit(com.facebook.presto.ExceededMemoryLimitException.exceededGlobalTotalLimit) InternalNode(com.facebook.presto.metadata.InternalNode) Consumer(java.util.function.Consumer) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MBeanExporter(org.weakref.jmx.MBeanExporter) Comparator(java.util.Comparator) ClusterMemoryManagerService(com.facebook.presto.resourcemanager.ClusterMemoryManagerService) QueryId(com.facebook.presto.spi.QueryId) QueryExecution(com.facebook.presto.execution.QueryExecution)

Aggregations

QueryId (com.facebook.presto.spi.QueryId)121 Test (org.testng.annotations.Test)79 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)19 DataSize (io.airlift.units.DataSize)18 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)17 Session (com.facebook.presto.Session)16 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)16 QueryManager (com.facebook.presto.execution.QueryManager)15 Identity (com.facebook.presto.spi.security.Identity)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ArrayList (java.util.ArrayList)11 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)10 PrestoException (com.facebook.presto.spi.PrestoException)10 ConnectorIdentity (com.facebook.presto.spi.security.ConnectorIdentity)10 List (java.util.List)10 SqlTask.createSqlTask (com.facebook.presto.execution.SqlTask.createSqlTask)9 MemoryPool (com.facebook.presto.memory.MemoryPool)9 ImmutableList (com.google.common.collect.ImmutableList)9 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)8 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)7