Search in sources :

Example 1 with TpchConnectorFactory

use of io.trino.plugin.tpch.TpchConnectorFactory in project trino by trinodb.

the class TestSpatialJoinPlanning method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    LocalQueryRunner queryRunner = LocalQueryRunner.create(testSessionBuilder().setCatalog("memory").setSchema("default").build());
    queryRunner.installPlugin(new GeoPlugin());
    queryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());
    queryRunner.createCatalog("memory", new MemoryConnectorFactory(), ImmutableMap.of());
    queryRunner.execute(format("CREATE TABLE kdb_tree AS SELECT '%s' AS v", KDB_TREE_JSON));
    queryRunner.execute("CREATE TABLE points (lng, lat, name) AS (VALUES (2.1e0, 2.1e0, 'x'))");
    queryRunner.execute("CREATE TABLE polygons (wkt, name) AS (VALUES ('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))', 'a'))");
    return queryRunner;
}
Also used : TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) MemoryConnectorFactory(io.trino.plugin.memory.MemoryConnectorFactory) LocalQueryRunner(io.trino.testing.LocalQueryRunner)

Example 2 with TpchConnectorFactory

use of io.trino.plugin.tpch.TpchConnectorFactory in project trino by trinodb.

the class TestPlannerWarnings method setUp.

@BeforeClass
public void setUp() {
    queryRunner = LocalQueryRunner.create(testSessionBuilder().setCatalog("local").setSchema("tiny").build());
    queryRunner.createCatalog(queryRunner.getDefaultSession().getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of());
}
Also used : TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with TpchConnectorFactory

use of io.trino.plugin.tpch.TpchConnectorFactory in project trino by trinodb.

the class TestTransactionManager method testAbortedTransactionWorkflow.

@Test
public void testAbortedTransactionWorkflow() {
    try (LocalQueryRunner queryRunner = LocalQueryRunner.create(TEST_SESSION)) {
        TransactionManager transactionManager = queryRunner.getTransactionManager();
        queryRunner.createCatalog(CATALOG, new TpchConnectorFactory(), ImmutableMap.of());
        TransactionId transactionId = transactionManager.beginTransaction(false);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getCatalogNames().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        ConnectorMetadata metadata = transactionManager.getOptionalCatalogMetadata(transactionId, CATALOG).get().getMetadata(TEST_SESSION);
        metadata.listSchemaNames(TEST_SESSION.toConnectorSession(CATALOG_NAME));
        transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertEquals(transactionInfo.getCatalogNames(), ImmutableList.of(CATALOG_NAME, INFORMATION_SCHEMA_ID, SYSTEM_TABLES_ID));
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        getFutureValue(transactionManager.asyncAbort(transactionId));
        assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    }
}
Also used : TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Test(org.testng.annotations.Test)

Example 4 with TpchConnectorFactory

use of io.trino.plugin.tpch.TpchConnectorFactory in project trino by trinodb.

the class TestTransactionManager method testFailedTransactionWorkflow.

@Test
public void testFailedTransactionWorkflow() {
    try (LocalQueryRunner queryRunner = LocalQueryRunner.create(TEST_SESSION)) {
        TransactionManager transactionManager = queryRunner.getTransactionManager();
        queryRunner.createCatalog(CATALOG, new TpchConnectorFactory(), ImmutableMap.of());
        TransactionId transactionId = transactionManager.beginTransaction(false);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getCatalogNames().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        ConnectorMetadata metadata = transactionManager.getOptionalCatalogMetadata(transactionId, CATALOG).get().getMetadata(TEST_SESSION);
        metadata.listSchemaNames(TEST_SESSION.toConnectorSession(CATALOG_NAME));
        transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertEquals(transactionInfo.getCatalogNames(), ImmutableList.of(CATALOG_NAME, INFORMATION_SCHEMA_ID, SYSTEM_TABLES_ID));
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        transactionManager.fail(transactionId);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        assertTrinoExceptionThrownBy(() -> transactionManager.getCatalogMetadata(transactionId, CATALOG_NAME)).hasErrorCode(TRANSACTION_ALREADY_ABORTED);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        getFutureValue(transactionManager.asyncAbort(transactionId));
        assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    }
}
Also used : TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Test(org.testng.annotations.Test)

Example 5 with TpchConnectorFactory

use of io.trino.plugin.tpch.TpchConnectorFactory in project trino by trinodb.

the class TestColumnMask method init.

@BeforeAll
public void init() {
    LocalQueryRunner runner = LocalQueryRunner.builder(SESSION).build();
    runner.createCatalog(CATALOG, new TpchConnectorFactory(1), ImmutableMap.of());
    ConnectorViewDefinition view = new ConnectorViewDefinition("SELECT nationkey, name FROM local.tiny.nation", Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorViewDefinition.ViewColumn("nationkey", BigintType.BIGINT.getTypeId()), new ConnectorViewDefinition.ViewColumn("name", VarcharType.createVarcharType(25).getTypeId())), Optional.empty(), Optional.of(VIEW_OWNER), false);
    ConnectorMaterializedViewDefinition materializedView = new ConnectorMaterializedViewDefinition("SELECT * FROM local.tiny.nation", Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorMaterializedViewDefinition.Column("nationkey", BigintType.BIGINT.getTypeId()), new ConnectorMaterializedViewDefinition.Column("name", VarcharType.createVarcharType(25).getTypeId()), new ConnectorMaterializedViewDefinition.Column("regionkey", BigintType.BIGINT.getTypeId()), new ConnectorMaterializedViewDefinition.Column("comment", VarcharType.createVarcharType(152).getTypeId())), Optional.empty(), Optional.of(VIEW_OWNER), ImmutableMap.of());
    ConnectorMaterializedViewDefinition freshMaterializedView = new ConnectorMaterializedViewDefinition("SELECT * FROM local.tiny.nation", Optional.of(new CatalogSchemaTableName("local", "tiny", "nation")), Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorMaterializedViewDefinition.Column("nationkey", BigintType.BIGINT.getTypeId()), new ConnectorMaterializedViewDefinition.Column("name", VarcharType.createVarcharType(25).getTypeId()), new ConnectorMaterializedViewDefinition.Column("regionkey", BigintType.BIGINT.getTypeId()), new ConnectorMaterializedViewDefinition.Column("comment", VarcharType.createVarcharType(152).getTypeId())), Optional.empty(), Optional.of(VIEW_OWNER), ImmutableMap.of());
    ConnectorMaterializedViewDefinition materializedViewWithCasts = new ConnectorMaterializedViewDefinition("SELECT nationkey, cast(name as varchar(1)) as name, regionkey, comment FROM local.tiny.nation", Optional.of(new CatalogSchemaTableName("local", "tiny", "nation")), Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorMaterializedViewDefinition.Column("nationkey", BigintType.BIGINT.getTypeId()), new ConnectorMaterializedViewDefinition.Column("name", VarcharType.createVarcharType(2).getTypeId()), new ConnectorMaterializedViewDefinition.Column("regionkey", BigintType.BIGINT.getTypeId()), new ConnectorMaterializedViewDefinition.Column("comment", VarcharType.createVarcharType(152).getTypeId())), Optional.empty(), Optional.of(VIEW_OWNER), ImmutableMap.of());
    MockConnectorFactory mock = MockConnectorFactory.builder().withGetColumns(schemaTableName -> {
        if (schemaTableName.equals(new SchemaTableName("tiny", "nation_with_hidden_column"))) {
            return TPCH_NATION_WITH_HIDDEN_COLUMN;
        }
        throw new UnsupportedOperationException();
    }).withData(schemaTableName -> {
        if (schemaTableName.equals(new SchemaTableName("tiny", "nation_with_hidden_column"))) {
            return TPCH_WITH_HIDDEN_COLUMN_DATA;
        }
        throw new UnsupportedOperationException();
    }).withGetViews((s, prefix) -> ImmutableMap.of(new SchemaTableName("default", "nation_view"), view)).withGetMaterializedViews((s, prefix) -> ImmutableMap.of(new SchemaTableName("default", "nation_materialized_view"), materializedView, new SchemaTableName("default", "nation_fresh_materialized_view"), freshMaterializedView, new SchemaTableName("default", "materialized_view_with_casts"), materializedViewWithCasts)).build();
    runner.createCatalog(MOCK_CATALOG, mock, ImmutableMap.of());
    assertions = new QueryAssertions(runner);
    accessControl = assertions.getQueryRunner().getAccessControl();
}
Also used : SELECT_COLUMN(io.trino.testing.TestingAccessControlManager.TestingPrivilegeType.SELECT_COLUMN) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) AfterAll(org.junit.jupiter.api.AfterAll) BigintType(io.trino.spi.type.BigintType) VarcharType(io.trino.spi.type.VarcharType) TestInstance(org.junit.jupiter.api.TestInstance) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) Identity(io.trino.spi.security.Identity) LocalQueryRunner(io.trino.testing.LocalQueryRunner) TestingAccessControlManager(io.trino.testing.TestingAccessControlManager) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) TINY_SCHEMA_NAME(io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) ViewExpression(io.trino.spi.security.ViewExpression) PER_CLASS(org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS) TPCH_WITH_HIDDEN_COLUMN_DATA(io.trino.connector.MockConnectorEntities.TPCH_WITH_HIDDEN_COLUMN_DATA) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.junit.jupiter.api.Test) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TestingAccessControlManager.privilege(io.trino.testing.TestingAccessControlManager.privilege) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) Optional(java.util.Optional) Execution(org.junit.jupiter.api.parallel.Execution) TPCH_NATION_WITH_HIDDEN_COLUMN(io.trino.connector.MockConnectorEntities.TPCH_NATION_WITH_HIDDEN_COLUMN) Session(io.trino.Session) TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) MockConnectorFactory(io.trino.connector.MockConnectorFactory) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) LocalQueryRunner(io.trino.testing.LocalQueryRunner) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

TpchConnectorFactory (io.trino.plugin.tpch.TpchConnectorFactory)31 LocalQueryRunner (io.trino.testing.LocalQueryRunner)25 Session (io.trino.Session)17 BeforeClass (org.testng.annotations.BeforeClass)7 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 FeaturesConfig (io.trino.FeaturesConfig)3 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)3 Optional (java.util.Optional)3 Test (org.testng.annotations.Test)3 SessionBuilder (io.trino.Session.SessionBuilder)2 TPCH_NATION_WITH_HIDDEN_COLUMN (io.trino.connector.MockConnectorEntities.TPCH_NATION_WITH_HIDDEN_COLUMN)2 TPCH_WITH_HIDDEN_COLUMN_DATA (io.trino.connector.MockConnectorEntities.TPCH_WITH_HIDDEN_COLUMN_DATA)2 MockConnectorFactory (io.trino.connector.MockConnectorFactory)2 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)2 MemoryConnectorFactory (io.trino.plugin.memory.MemoryConnectorFactory)2 TINY_SCHEMA_NAME (io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME)2 ConnectorViewDefinition (io.trino.spi.connector.ConnectorViewDefinition)2