Search in sources :

Example 96 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class DistributedQueryRunner method createPlan.

@Override
public Plan createPlan(Session session, String sql, WarningCollector warningCollector) {
    QueryId queryId = executeWithQueryId(session, sql).getQueryId();
    Plan queryPlan = getQueryPlan(queryId);
    coordinator.getQueryManager().cancelQuery(queryId);
    return queryPlan;
}
Also used : QueryId(io.trino.spi.QueryId) Plan(io.trino.sql.planner.Plan)

Example 97 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class AbstractOperatorBenchmark method runOnce.

@Override
protected Map<String, Long> runOnce() {
    Session session = testSessionBuilder().setSystemProperty("optimizer.optimize-hash-generation", "true").setTransactionId(this.session.getRequiredTransactionId()).build();
    MemoryPool memoryPool = new MemoryPool(DataSize.of(1, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(DataSize.of(1, GIGABYTE));
    TaskContext taskContext = new QueryContext(new QueryId("test"), DataSize.of(256, MEGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), DataSize.of(256, MEGABYTE), spillSpaceTracker).addTaskContext(new TaskStateMachine(new TaskId(new StageId("query", 0), 0, 0), localQueryRunner.getExecutor()), session, () -> {
    }, false, false);
    CpuTimer cpuTimer = new CpuTimer();
    Map<String, Long> executionStats = execute(taskContext);
    CpuDuration executionTime = cpuTimer.elapsedTime();
    TaskStats taskStats = taskContext.getTaskStats();
    long inputRows = taskStats.getRawInputPositions();
    long inputBytes = taskStats.getRawInputDataSize().toBytes();
    long outputRows = taskStats.getOutputPositions();
    long outputBytes = taskStats.getOutputDataSize().toBytes();
    double inputMegaBytes = ((double) inputBytes) / MEGABYTE.inBytes();
    return ImmutableMap.<String, Long>builder().putAll(executionStats).put("elapsed_millis", executionTime.getWall().toMillis()).put("input_rows_per_second", (long) (inputRows / executionTime.getWall().getValue(SECONDS))).put("output_rows_per_second", (long) (outputRows / executionTime.getWall().getValue(SECONDS))).put("input_megabytes", (long) inputMegaBytes).put("input_megabytes_per_second", (long) (inputMegaBytes / executionTime.getWall().getValue(SECONDS))).put("wall_nanos", executionTime.getWall().roundTo(NANOSECONDS)).put("cpu_nanos", executionTime.getCpu().roundTo(NANOSECONDS)).put("user_nanos", executionTime.getUser().roundTo(NANOSECONDS)).put("input_rows", inputRows).put("input_bytes", inputBytes).put("output_rows", outputRows).put("output_bytes", outputBytes).buildOrThrow();
}
Also used : SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) TaskContext(io.trino.operator.TaskContext) TaskId(io.trino.execution.TaskId) QueryId(io.trino.spi.QueryId) StageId(io.trino.execution.StageId) QueryContext(io.trino.memory.QueryContext) TaskStats(io.trino.operator.TaskStats) TaskStateMachine(io.trino.execution.TaskStateMachine) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) CpuTimer(io.airlift.stats.CpuTimer) CpuDuration(io.airlift.stats.CpuTimer.CpuDuration) Session(io.trino.Session) MemoryPool(io.trino.memory.MemoryPool)

Example 98 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class MemoryLocalQueryRunner method execute.

public List<Page> execute(@Language("SQL") String query) {
    MemoryPool memoryPool = new MemoryPool(DataSize.of(2, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(DataSize.of(1, GIGABYTE));
    QueryContext queryContext = new QueryContext(new QueryId("test"), DataSize.of(1, GIGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), DataSize.of(4, GIGABYTE), spillSpaceTracker);
    TaskContext taskContext = queryContext.addTaskContext(new TaskStateMachine(new TaskId(new StageId("query", 0), 0, 0), localQueryRunner.getExecutor()), localQueryRunner.getDefaultSession(), () -> {
    }, 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 : QueryId(io.trino.spi.QueryId) SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) StageId(io.trino.execution.StageId) MemoryConnectorFactory(io.trino.plugin.memory.MemoryConnectorFactory) Page(io.trino.spi.Page) TaskStateMachine(io.trino.execution.TaskStateMachine) PageConsumerOperator(io.trino.testing.PageConsumerOperator) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) TaskContext(io.trino.operator.TaskContext) MemoryPool(io.trino.memory.MemoryPool) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) QueryContext(io.trino.memory.QueryContext) TaskId(io.trino.execution.TaskId) DataSize(io.airlift.units.DataSize) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) Driver(io.trino.operator.Driver) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) Session(io.trino.Session) SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) TaskContext(io.trino.operator.TaskContext) TaskId(io.trino.execution.TaskId) ImmutableList(com.google.common.collect.ImmutableList) QueryId(io.trino.spi.QueryId) StageId(io.trino.execution.StageId) Driver(io.trino.operator.Driver) Page(io.trino.spi.Page) QueryContext(io.trino.memory.QueryContext) TaskStateMachine(io.trino.execution.TaskStateMachine) PageConsumerOperator(io.trino.testing.PageConsumerOperator) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) MemoryPool(io.trino.memory.MemoryPool)

Example 99 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestServer method testQuery.

@Test
public void testQuery() {
    ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
    QueryResults queryResults = postQuery(request -> request.setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(TRINO_HEADERS.requestCatalog(), "catalog").setHeader(TRINO_HEADERS.requestSchema(), "schema").setHeader(TRINO_HEADERS.requestPath(), "path").setHeader(TRINO_HEADERS.requestClientInfo(), "{\"clientVersion\":\"testVersion\"}").addHeader(TRINO_HEADERS.requestSession(), QUERY_MAX_MEMORY + "=1GB").addHeader(TRINO_HEADERS.requestSession(), JOIN_DISTRIBUTION_TYPE + "=partitioned," + HASH_PARTITION_COUNT + " = 43").addHeader(TRINO_HEADERS.requestPreparedStatement(), "foo=select * from bar")).map(JsonResponse::getValue).peek(result -> assertNull(result.getError())).peek(results -> {
        if (results.getData() != null) {
            data.addAll(results.getData());
        }
    }).collect(last());
    // get the query info
    BasicQueryInfo queryInfo = server.getQueryManager().getQueryInfo(new QueryId(queryResults.getId()));
    // verify session properties
    assertEquals(queryInfo.getSession().getSystemProperties(), ImmutableMap.builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").buildOrThrow());
    // verify client info in session
    assertEquals(queryInfo.getSession().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
    // verify prepared statements
    assertEquals(queryInfo.getSession().getPreparedStatements(), ImmutableMap.builder().put("foo", "select * from bar").buildOrThrow());
    List<List<Object>> rows = data.build();
    assertEquals(rows, ImmutableList.of(ImmutableList.of("memory"), ImmutableList.of("system")));
}
Also used : QueryId(io.trino.spi.QueryId) QueryError(io.trino.client.QueryError) X_FORWARDED_PORT(com.google.common.net.HttpHeaders.X_FORWARDED_PORT) BasicQueryInfo(io.trino.server.BasicQueryInfo) FullJsonResponseHandler.createFullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) Closeables.closeAll(io.airlift.testing.Closeables.closeAll) QueryResults(io.trino.client.QueryResults) URI(java.net.URI) Collector(java.util.stream.Collector) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) Splitter(com.google.common.base.Splitter) X_FORWARDED_PROTO(com.google.common.net.HttpHeaders.X_FORWARDED_PROTO) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) SEE_OTHER(javax.ws.rs.core.Response.Status.SEE_OTHER) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Builder.prepareHead(io.airlift.http.client.Request.Builder.prepareHead) QUERY_MAX_MEMORY(io.trino.SystemSessionProperties.QUERY_MAX_MEMORY) ImmutableMap(com.google.common.collect.ImmutableMap) OK(javax.ws.rs.core.Response.Status.OK) MemoryPlugin(io.trino.plugin.memory.MemoryPlugin) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.assertNotNull(org.testng.Assert.assertNotNull) Streams(com.google.common.collect.Streams) TestingTrinoClient(io.trino.testing.TestingTrinoClient) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Stream(java.util.stream.Stream) Optional(java.util.Optional) StaticBodyGenerator.createStaticBodyGenerator(io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) JsonCodec(io.airlift.json.JsonCodec) HttpClient(io.airlift.http.client.HttpClient) IntStream(java.util.stream.IntStream) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(org.testng.Assert.assertEquals) Function(java.util.function.Function) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) AbstractSequentialIterator(com.google.common.collect.AbstractSequentialIterator) INCOMPATIBLE_CLIENT(io.trino.spi.StandardErrorCode.INCOMPATIBLE_CLIENT) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) X_FORWARDED_HOST(com.google.common.net.HttpHeaders.X_FORWARDED_HOST) AfterClass(org.testng.annotations.AfterClass) Builder.preparePost(io.airlift.http.client.Request.Builder.preparePost) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) Language(org.intellij.lang.annotations.Language) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.fail(org.testng.Assert.fail) HASH_PARTITION_COUNT(io.trino.SystemSessionProperties.HASH_PARTITION_COUNT) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) StatusResponseHandler.createStatusResponseHandler(io.airlift.http.client.StatusResponseHandler.createStatusResponseHandler) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) TimeZoneNotSupportedException(io.trino.spi.type.TimeZoneNotSupportedException) StatusResponse(io.airlift.http.client.StatusResponseHandler.StatusResponse) Collections(java.util.Collections) TRINO_HEADERS(io.trino.client.ProtocolHeaders.TRINO_HEADERS) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryId(io.trino.spi.QueryId) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) QueryResults(io.trino.client.QueryResults) Test(org.testng.annotations.Test)

Example 100 with QueryId

use of io.trino.spi.QueryId in project trino by trinodb.

the class TestQueryManager method testFailQuery.

@Test(timeOut = 60_000L)
public void testFailQuery() throws Exception {
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    QueryId queryId = dispatchManager.createQueryId();
    dispatchManager.createQuery(queryId, Slug.createNew(), TestingSessionContext.fromSession(TEST_SESSION), "SELECT * FROM lineitem").get();
    // wait until query starts running
    while (true) {
        QueryState state = dispatchManager.getQueryInfo(queryId).getState();
        if (state.isDone()) {
            fail("unexpected query state: " + state);
        }
        if (state == RUNNING) {
            break;
        }
        Thread.sleep(100);
    }
    // cancel query
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    queryManager.failQuery(queryId, new TrinoException(GENERIC_INTERNAL_ERROR, "mock exception"));
    QueryInfo queryInfo = queryManager.getFullQueryInfo(queryId);
    assertEquals(queryInfo.getState(), FAILED);
    assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
    assertNotNull(queryInfo.getFailureInfo());
    assertEquals(queryInfo.getFailureInfo().getMessage(), "mock exception");
}
Also used : DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) QueryManager(io.trino.execution.QueryManager) TrinoException(io.trino.spi.TrinoException) QueryState(io.trino.execution.QueryState) TestQueryRunnerUtil.waitForQueryState(io.trino.execution.TestQueryRunnerUtil.waitForQueryState) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo) Test(org.testng.annotations.Test)

Aggregations

QueryId (io.trino.spi.QueryId)103 Test (org.testng.annotations.Test)70 TaskId (io.trino.execution.TaskId)26 StageId (io.trino.execution.StageId)24 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)16 DynamicFilterId (io.trino.sql.planner.plan.DynamicFilterId)15 DistributedQueryRunner (io.trino.testing.DistributedQueryRunner)14 Optional (java.util.Optional)13 Duration (io.airlift.units.Duration)12 Session (io.trino.Session)12 DynamicFilter (io.trino.spi.connector.DynamicFilter)12 Symbol (io.trino.sql.planner.Symbol)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 TestingColumnHandle (io.trino.spi.connector.TestingColumnHandle)11 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)11 Set (java.util.Set)10 AccessDeniedException (io.trino.spi.security.AccessDeniedException)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)8