Search in sources :

Example 81 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestRaptorMetadata method assertTableEqual.

private static void assertTableEqual(ConnectorTableMetadata actual, ConnectorTableMetadata expected) {
    assertEquals(actual.getTable(), expected.getTable());
    List<ColumnMetadata> actualColumns = actual.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(Collectors.toList());
    List<ColumnMetadata> expectedColumns = expected.getColumns();
    assertEquals(actualColumns.size(), expectedColumns.size());
    for (int i = 0; i < actualColumns.size(); i++) {
        ColumnMetadata actualColumn = actualColumns.get(i);
        ColumnMetadata expectedColumn = expectedColumns.get(i);
        assertEquals(actualColumn.getName(), expectedColumn.getName());
        assertEquals(actualColumn.getType(), expectedColumn.getType());
    }
    assertEquals(actual.getProperties(), expected.getProperties());
}
Also used : TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Assertions.assertInstanceOf(io.airlift.testing.Assertions.assertInstanceOf) NodeManager(io.trino.spi.NodeManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) ORGANIZED_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.ORGANIZED_PROPERTY) AfterMethod(org.testng.annotations.AfterMethod) TrinoExceptionAssert.assertTrinoExceptionThrownBy(io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy) Ticker.systemTicker(com.google.common.base.Ticker.systemTicker) QueryAssertions.assertEqualsIgnoreOrder(io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder) RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Handle(org.jdbi.v3.core.Handle) Map(java.util.Map) ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) RaptorPartitioningHandle(io.trino.plugin.raptor.legacy.RaptorPartitioningHandle) DatabaseTesting.createTestingJdbi(io.trino.plugin.raptor.legacy.DatabaseTesting.createTestingJdbi) Assert.assertFalse(org.testng.Assert.assertFalse) RaptorSessionProperties(io.trino.plugin.raptor.legacy.RaptorSessionProperties) ImmutableSet(com.google.common.collect.ImmutableSet) TestingNodeManager(io.trino.testing.TestingNodeManager) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeMethod(org.testng.annotations.BeforeMethod) TrinoException(io.trino.spi.TrinoException) TableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder) Assert.assertNotNull(org.testng.Assert.assertNotNull) RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) RaptorMetadata(io.trino.plugin.raptor.legacy.RaptorMetadata) Collectors(java.util.stream.Collectors) NodeSupplier(io.trino.plugin.raptor.legacy.NodeSupplier) SchemaTableName(io.trino.spi.connector.SchemaTableName) DISTRIBUTION_NAME_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.DISTRIBUTION_NAME_PROPERTY) List(java.util.List) BIGINT(io.trino.spi.type.BigintType.BIGINT) SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) BUCKET_COUNT_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.BUCKET_COUNT_PROPERTY) Optional(java.util.Optional) DATE(io.trino.spi.type.DateType.DATE) TestDatabaseShardManager.createShardManager(io.trino.plugin.raptor.legacy.metadata.TestDatabaseShardManager.createShardManager) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) Assert.assertNull(org.testng.Assert.assertNull) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assert.assertEquals(org.testng.Assert.assertEquals) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) BUCKETED_ON_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.BUCKETED_ON_PROPERTY) OptionalInt(java.util.OptionalInt) OptionalLong(java.util.OptionalLong) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ColumnHandle(io.trino.spi.connector.ColumnHandle) ORDERING_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.ORDERING_PROPERTY) Jdbi(org.jdbi.v3.core.Jdbi) StorageManagerConfig(io.trino.plugin.raptor.legacy.storage.StorageManagerConfig) TRANSACTION_CONFLICT(io.trino.spi.StandardErrorCode.TRANSACTION_CONFLICT) Assert.fail(org.testng.Assert.fail) ConnectorSession(io.trino.spi.connector.ConnectorSession) SchemaDaoUtil.createTablesWithRetry(io.trino.plugin.raptor.legacy.metadata.SchemaDaoUtil.createTablesWithRetry) TEMPORAL_COLUMN_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.TEMPORAL_COLUMN_PROPERTY) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Assert.assertTrue(org.testng.Assert.assertTrue) ColumnMetadata(io.trino.spi.connector.ColumnMetadata)

Example 82 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestQueryTracker method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session defaultSession = testSessionBuilder().setCatalog("mock").setSchema("default").setSystemProperty(QUERY_MAX_PLANNING_TIME, "2s").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(defaultSession).build();
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            return ImmutableList.of(MockConnectorFactory.builder().withGetColumns(ignored -> ImmutableList.of(new ColumnMetadata("col", VARCHAR))).withApplyFilter((ignored1, ignored2, ignored3) -> freeze()).build());
        }
    });
    queryRunner.createCatalog("mock", "mock");
    return queryRunner;
}
Also used : AfterClass(org.testng.annotations.AfterClass) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Test(org.testng.annotations.Test) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) Plugin(io.trino.spi.Plugin) CountDownLatch(java.util.concurrent.CountDownLatch) QUERY_MAX_PLANNING_TIME(io.trino.SystemSessionProperties.QUERY_MAX_PLANNING_TIME) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) QueryRunner(io.trino.testing.QueryRunner) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Session(io.trino.Session) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Session(io.trino.Session) Plugin(io.trino.spi.Plugin)

Example 83 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestRefreshMaterializedView method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setCatalog("mock").setSchema("default").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build();
    queryRunner.installPlugin(new MockConnectorPlugin(MockConnectorFactory.builder().withListSchemaNames(connectionSession -> ImmutableList.of("default")).withGetColumns(schemaTableName -> ImmutableList.of(new ColumnMetadata("nationkey", BIGINT))).withGetTableHandle((connectorSession, tableName) -> new MockConnectorTableHandle(tableName)).withGetMaterializedViews((connectorSession, schemaTablePrefix) -> ImmutableMap.of(new SchemaTableName("default", "delegate_refresh_to_connector"), new ConnectorMaterializedViewDefinition("SELECT nationkey FROM mock.default.test_table", Optional.of(new CatalogSchemaTableName("mock", "default", "test_storage")), Optional.of("mock"), Optional.of("default"), ImmutableList.of(new ConnectorMaterializedViewDefinition.Column("nationkey", BIGINT.getTypeId())), Optional.empty(), Optional.of("alice"), ImmutableMap.of()))).withDelegateMaterializedViewRefreshToConnector((connectorSession, schemaTableName) -> true).withRefreshMaterializedView(((connectorSession, schemaTableName) -> {
        startRefreshMaterializedView.set(null);
        SettableFuture<Void> refreshMaterializedView = SettableFuture.create();
        finishRefreshMaterializedView.addListener(() -> refreshMaterializedView.set(null), directExecutor());
        addExceptionCallback(refreshMaterializedView, () -> refreshInterrupted.set(null));
        return toCompletableFuture(refreshMaterializedView);
    })).build()));
    queryRunner.createCatalog("mock", "mock");
    return queryRunner;
}
Also used : MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RUNNING(io.trino.execution.QueryState.RUNNING) Test(org.testng.annotations.Test) SettableFuture(com.google.common.util.concurrent.SettableFuture) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) MockConnectorPlugin(io.trino.connector.MockConnectorPlugin) MoreFutures.toCompletableFuture(io.airlift.concurrent.MoreFutures.toCompletableFuture) AfterClass(org.testng.annotations.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) MoreFutures.addExceptionCallback(io.airlift.concurrent.MoreFutures.addExceptionCallback) SchemaTableName(io.trino.spi.connector.SchemaTableName) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Futures(com.google.common.util.concurrent.Futures) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) BIGINT(io.trino.spi.type.BigintType.BIGINT) Assert.assertEventually(io.trino.testing.assertions.Assert.assertEventually) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) QueryRunner(io.trino.testing.QueryRunner) Optional(java.util.Optional) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Session(io.trino.Session) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) MockConnectorPlugin(io.trino.connector.MockConnectorPlugin) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) Session(io.trino.Session)

Example 84 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.

the class TestErrorThrowableInQuery method createQueryRunner.

@Override
protected DistributedQueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setSystemProperty("task_concurrency", "1").setCatalog("mock").setSchema("default").setClientInfo("{\"clientVersion\":\"testVersion\"}").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    try {
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.installPlugin(new Plugin() {

            @Override
            public Iterable<ConnectorFactory> getConnectorFactories() {
                SchemaTableName stackOverflowErrorTableName = new SchemaTableName("default", "stack_overflow_during_planning");
                SchemaTableName classFormatErrorTableName = new SchemaTableName("default", "class_format_error_during_planning");
                MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListTables((session, s) -> ImmutableList.of(stackOverflowErrorTableName)).withGetColumns(schemaTableName -> ImmutableList.of(new ColumnMetadata("test_varchar", createUnboundedVarcharType()), new ColumnMetadata("test_bigint", BIGINT))).withGetTableHandle((session, schemaTableName) -> new MockConnectorTableHandle(schemaTableName)).withApplyProjection((session, handle, projections, assignments) -> {
                    MockConnectorTableHandle mockTableHandle = (MockConnectorTableHandle) handle;
                    if (stackOverflowErrorTableName.equals(mockTableHandle.getTableName())) {
                        throw new StackOverflowError("We run out of stack!!!!!!!!!!!");
                    }
                    if (classFormatErrorTableName.equals(mockTableHandle.getTableName())) {
                        throw new ClassFormatError("Bad class format!!!!!!!!!!");
                    }
                    throw new TrinoException(NOT_FOUND, "Unknown table: " + mockTableHandle.getTableName());
                }).build();
                return ImmutableList.of(connectorFactory);
            }
        });
        queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
    } catch (Exception e) {
        queryRunner.close();
        throw e;
    }
    return queryRunner;
}
Also used : NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) ImmutableMap(com.google.common.collect.ImmutableMap) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) TrinoException(io.trino.spi.TrinoException) Test(org.testng.annotations.Test) SchemaTableName(io.trino.spi.connector.SchemaTableName) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) Plugin(io.trino.spi.Plugin) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) 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) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Session(io.trino.Session) MockConnectorFactory(io.trino.connector.MockConnectorFactory) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoException(io.trino.spi.TrinoException) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) TrinoException(io.trino.spi.TrinoException) Session(io.trino.Session) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Plugin(io.trino.spi.Plugin) TpchPlugin(io.trino.plugin.tpch.TpchPlugin)

Example 85 with ColumnMetadata

use of io.trino.spi.connector.ColumnMetadata in project TiBigData by tidb-incubator.

the class TiDBMetadata method createTable.

@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
    List<ColumnMetadata> columns = tableMetadata.getColumns();
    SchemaTableName table = tableMetadata.getTable();
    String schemaName = table.getSchemaName();
    String tableName = table.getTableName();
    List<String> columnNames = columns.stream().map(ColumnMetadata::getName).collect(toImmutableList());
    List<String> columnTypes = columns.stream().map(column -> TypeHelpers.toSqlString(column.getType())).collect(toImmutableList());
    List<String> primaryKeyColumns = Arrays.stream(tableMetadata.getProperties().get(PRIMARY_KEY).toString().split(",")).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    checkArgument(columnNames.containsAll(primaryKeyColumns), "invalid primary key columns: " + primaryKeyColumns);
    List<String> uniqueKeyColumns = Arrays.stream(tableMetadata.getProperties().get(UNIQUE_KEY).toString().split(",")).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    checkArgument(columnNames.containsAll(uniqueKeyColumns), "invalid unique key columns: " + uniqueKeyColumns);
    getInternal().createTable(schemaName, tableName, columnNames, columnTypes, primaryKeyColumns, uniqueKeyColumns, ignoreExisting);
}
Also used : Arrays(java.util.Arrays) TypeHelpers.getHelper(io.tidb.bigdata.trino.tidb.TypeHelpers.getHelper) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) Slice(io.airlift.slice.Slice) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) UNIQUE_KEY(io.tidb.bigdata.trino.tidb.TiDBConfig.UNIQUE_KEY) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) String.join(java.lang.String.join) MetadataInternal(io.tidb.bigdata.tidb.MetadataInternal) Objects.requireNonNull(java.util.Objects.requireNonNull) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) ColumnHandle(io.trino.spi.connector.ColumnHandle) ColumnHandleInternal(io.tidb.bigdata.tidb.ColumnHandleInternal) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) PRIMARY_KEY(io.tidb.bigdata.trino.tidb.TiDBConfig.PRIMARY_KEY) ComputedStatistics(io.trino.spi.statistics.ComputedStatistics) ConnectorSession(io.trino.spi.connector.ConnectorSession) Wrapper(io.tidb.bigdata.tidb.Wrapper) ConnectorOutputMetadata(io.trino.spi.connector.ConnectorOutputMetadata) Collectors(java.util.stream.Collectors) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) List(java.util.List) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) Stream(java.util.stream.Stream) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Aggregations

ColumnMetadata (io.trino.spi.connector.ColumnMetadata)154 SchemaTableName (io.trino.spi.connector.SchemaTableName)75 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)73 Test (org.testng.annotations.Test)64 ImmutableList (com.google.common.collect.ImmutableList)63 ImmutableMap (com.google.common.collect.ImmutableMap)55 List (java.util.List)45 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)43 Optional (java.util.Optional)43 ConnectorSession (io.trino.spi.connector.ConnectorSession)41 TrinoException (io.trino.spi.TrinoException)38 ColumnHandle (io.trino.spi.connector.ColumnHandle)38 Map (java.util.Map)38 Type (io.trino.spi.type.Type)35 Constraint (io.trino.spi.connector.Constraint)32 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)31 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)30 BIGINT (io.trino.spi.type.BigintType.BIGINT)30 HashMap (java.util.HashMap)27 Set (java.util.Set)27