Search in sources :

Example 16 with LocalQueryRunner

use of io.trino.testing.LocalQueryRunner in project trino by trinodb.

the class TestShowQueries method init.

@BeforeAll
public void init() {
    LocalQueryRunner queryRunner = LocalQueryRunner.create(testSessionBuilder().setCatalog("local").setSchema("default").build());
    queryRunner.createCatalog("mock", MockConnectorFactory.builder().withGetColumns(schemaTableName -> ImmutableList.of(ColumnMetadata.builder().setName("colaa").setType(BIGINT).build(), ColumnMetadata.builder().setName("cola_").setType(BIGINT).build(), ColumnMetadata.builder().setName("colabc").setType(BIGINT).build())).withListSchemaNames(session -> ImmutableList.of("mockschema")).withListTables((session, schemaName) -> ImmutableList.of(new SchemaTableName("mockSchema", "mockTable"))).build(), ImmutableMap.of());
    queryRunner.createCatalog("testing_catalog", "mock", ImmutableMap.of());
    assertions = new QueryAssertions(queryRunner);
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PER_CLASS(org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS) SchemaTableName(io.trino.spi.connector.SchemaTableName) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TestInstance(org.junit.jupiter.api.TestInstance) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) BIGINT(io.trino.spi.type.BigintType.BIGINT) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SchemaTableName(io.trino.spi.connector.SchemaTableName) LocalQueryRunner(io.trino.testing.LocalQueryRunner) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 17 with LocalQueryRunner

use of io.trino.testing.LocalQueryRunner in project trino by trinodb.

the class TestSubqueries method init.

@BeforeAll
public void init() {
    Session session = testSessionBuilder().setCatalog(CATALOG).setSchema(TINY_SCHEMA_NAME).build();
    LocalQueryRunner runner = LocalQueryRunner.builder(session).build();
    runner.createCatalog(CATALOG, new TpchConnectorFactory(1), ImmutableMap.of());
    assertions = new QueryAssertions(runner);
}
Also used : TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 18 with LocalQueryRunner

use of io.trino.testing.LocalQueryRunner in project trino by trinodb.

the class TestPushDistinctLimitIntoTableScan method createLocalQueryRunner.

@Override
protected Optional<LocalQueryRunner> createLocalQueryRunner() {
    Session defaultSession = TestingSession.testSessionBuilder().setCatalog(TEST_CATALOG.getCatalogName()).setSchema("tiny").build();
    LocalQueryRunner queryRunner = LocalQueryRunner.create(defaultSession);
    queryRunner.createCatalog(TEST_CATALOG.getCatalogName(), MockConnectorFactory.builder().withApplyAggregation((session, handle, aggregates, assignments, groupingSets) -> {
        if (testApplyAggregation != null) {
            return testApplyAggregation.apply(session, handle, aggregates, assignments, groupingSets);
        }
        return Optional.empty();
    }).build(), Map.of());
    return Optional.of(queryRunner);
}
Also used : LocalQueryRunner(io.trino.testing.LocalQueryRunner) TestingSession(io.trino.testing.TestingSession) Session(io.trino.Session)

Example 19 with LocalQueryRunner

use of io.trino.testing.LocalQueryRunner in project trino by trinodb.

the class TestPartialTopNWithPresortedInput method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    Session session = testSessionBuilder().setCatalog(MOCK_CATALOG).setSchema(TEST_SCHEMA).build();
    LocalQueryRunner queryRunner = LocalQueryRunner.builder(session).build();
    MockConnectorFactory mockFactory = MockConnectorFactory.builder().withGetTableProperties((connectorSession, handle) -> {
        MockConnectorTableHandle tableHandle = (MockConnectorTableHandle) handle;
        if (tableHandle.getTableName().equals(tableA)) {
            return new ConnectorTableProperties(TupleDomain.all(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(new SortingProperty<>(columnHandleA, ASC_NULLS_FIRST)));
        }
        throw new IllegalArgumentException();
    }).withGetColumns(schemaTableName -> {
        if (schemaTableName.equals(tableA)) {
            return ImmutableList.of(new ColumnMetadata(columnNameA, VARCHAR), new ColumnMetadata(columnNameB, VARCHAR));
        }
        throw new IllegalArgumentException();
    }).build();
    queryRunner.createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
    return queryRunner;
}
Also used : OPTIMIZED_AND_VALIDATED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) PARTIAL(io.trino.sql.planner.plan.TopNNode.Step.PARTIAL) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) MockConnectorFactory(io.trino.connector.MockConnectorFactory) LongLiteral(io.trino.sql.tree.LongLiteral) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) SchemaTableName(io.trino.spi.connector.SchemaTableName) SortingProperty(io.trino.spi.connector.SortingProperty) ASC_NULLS_FIRST(io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) List(java.util.List) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) Optional(java.util.Optional) PlanMatchPattern.output(io.trino.sql.planner.assertions.PlanMatchPattern.output) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) ValidateLimitWithPresortedInput(io.trino.sql.planner.sanity.ValidateLimitWithPresortedInput) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) PlanMatchPattern.window(io.trino.sql.planner.assertions.PlanMatchPattern.window) PlanAssert(io.trino.sql.planner.assertions.PlanAssert) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) LocalQueryRunner(io.trino.testing.LocalQueryRunner) ColumnHandle(io.trino.spi.connector.ColumnHandle) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) LAST(io.trino.sql.tree.SortItem.NullOrdering.LAST) Language(org.intellij.lang.annotations.Language) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) FINAL(io.trino.sql.planner.plan.TopNNode.Step.FINAL) PlanMatchPattern.topN(io.trino.sql.planner.assertions.PlanMatchPattern.topN) TupleDomain(io.trino.spi.predicate.TupleDomain) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) WarningCollector(io.trino.execution.warnings.WarningCollector) Plan(io.trino.sql.planner.Plan) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) MockConnectorFactory(io.trino.connector.MockConnectorFactory) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) SortingProperty(io.trino.spi.connector.SortingProperty) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session)

Example 20 with LocalQueryRunner

use of io.trino.testing.LocalQueryRunner in project trino by trinodb.

the class TestPartialTopNWithPresortedInput method assertPlanWithValidation.

private void assertPlanWithValidation(@Language("SQL") String sql, PlanMatchPattern pattern) {
    LocalQueryRunner queryRunner = getQueryRunner();
    queryRunner.inTransaction(queryRunner.getDefaultSession(), transactionSession -> {
        Plan actualPlan = queryRunner.createPlan(transactionSession, sql, OPTIMIZED_AND_VALIDATED, false, WarningCollector.NOOP);
        PlanAssert.assertPlan(transactionSession, queryRunner.getMetadata(), queryRunner.getFunctionManager(), queryRunner.getStatsCalculator(), actualPlan, pattern);
        PlannerContext plannerContext = queryRunner.getPlannerContext();
        new ValidateLimitWithPresortedInput().validate(actualPlan.getRoot(), transactionSession, plannerContext, createTestingTypeAnalyzer(plannerContext), actualPlan.getTypes(), WarningCollector.NOOP);
        return null;
    });
}
Also used : PlannerContext(io.trino.sql.PlannerContext) ValidateLimitWithPresortedInput(io.trino.sql.planner.sanity.ValidateLimitWithPresortedInput) Plan(io.trino.sql.planner.Plan) LocalQueryRunner(io.trino.testing.LocalQueryRunner)

Aggregations

LocalQueryRunner (io.trino.testing.LocalQueryRunner)66 Session (io.trino.Session)28 TpchConnectorFactory (io.trino.plugin.tpch.TpchConnectorFactory)25 Test (org.testng.annotations.Test)22 ImmutableMap (com.google.common.collect.ImmutableMap)12 SchemaTableName (io.trino.spi.connector.SchemaTableName)12 ImmutableList (com.google.common.collect.ImmutableList)11 MockConnectorFactory (io.trino.connector.MockConnectorFactory)11 Optional (java.util.Optional)11 CatalogName (io.trino.connector.CatalogName)9 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)9 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)8 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)8 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)7 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)7 TrinoException (io.trino.spi.TrinoException)6 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 ColumnHandle (io.trino.spi.connector.ColumnHandle)5 List (java.util.List)5