Search in sources :

Example 61 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testSortOrderProperty.

@Test
public void testSortOrderProperty() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdate", "custkey")));
    metadata.createTable(SESSION, ordersTable, false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    // verify sort columns
    List<TableColumn> sortColumns = metadataDao.listSortColumns(tableId);
    assertTableColumnsEqual(sortColumns, ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderdate", DATE, 4, 3, OptionalInt.empty(), OptionalInt.of(0), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, 1, OptionalInt.empty(), OptionalInt.of(1), false)));
    // verify temporal column is not set
    assertEquals(metadataDao.getTemporalColumnId(tableId), null);
    metadata.dropTable(SESSION, tableHandle);
}
Also used : RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 62 with ConnectorTableMetadata

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

the class RedisMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
    SchemaTableName schemaTableName = ((RedisTableHandle) tableHandle).toSchemaTableName();
    ConnectorTableMetadata tableMetadata = getTableMetadata(schemaTableName);
    if (tableMetadata == null) {
        throw new TableNotFoundException(schemaTableName);
    }
    return tableMetadata;
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Example 63 with ConnectorTableMetadata

use of io.trino.spi.connector.ConnectorTableMetadata 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)

Example 64 with ConnectorTableMetadata

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

the class BigQueryMetadata method createTable.

private void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
    SchemaTableName schemaTableName = tableMetadata.getTable();
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    List<Field> fields = tableMetadata.getColumns().stream().map(column -> toField(column.getName(), column.getType())).collect(toImmutableList());
    TableId tableId = TableId.of(schemaName, tableName);
    TableDefinition tableDefinition = StandardTableDefinition.of(Schema.of(fields));
    TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
    bigQueryClientFactory.create(session).createTable(tableInfo);
}
Also used : ViewDefinition(com.google.cloud.bigquery.ViewDefinition) StandardTableDefinition(com.google.cloud.bigquery.StandardTableDefinition) TableId(com.google.cloud.bigquery.TableId) SchemaNotFoundException(io.trino.spi.connector.SchemaNotFoundException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) VIEW(com.google.cloud.bigquery.TableDefinition.Type.VIEW) Schema(com.google.cloud.bigquery.Schema) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) ProjectionApplicationResult(io.trino.spi.connector.ProjectionApplicationResult) RemoteDatabaseObject(io.trino.plugin.bigquery.BigQueryClient.RemoteDatabaseObject) ENGLISH(java.util.Locale.ENGLISH) TABLE(com.google.cloud.bigquery.TableDefinition.Type.TABLE) Field(com.google.cloud.bigquery.Field) TableDefinition(com.google.cloud.bigquery.TableDefinition) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) Streams(com.google.common.collect.Streams) SchemaTableName(io.trino.spi.connector.SchemaTableName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) BIGQUERY_LISTING_DATASET_ERROR(io.trino.plugin.bigquery.BigQueryErrorCode.BIGQUERY_LISTING_DATASET_ERROR) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) Assignment(io.trino.spi.connector.Assignment) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) SystemTable(io.trino.spi.connector.SystemTable) Constraint(io.trino.spi.connector.Constraint) Logger(io.airlift.log.Logger) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Type(io.trino.spi.type.Type) BigQueryException(com.google.cloud.bigquery.BigQueryException) BigQueryType.toField(io.trino.plugin.bigquery.BigQueryType.toField) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) DatasetId(com.google.cloud.bigquery.DatasetId) Function(java.util.function.Function) Inject(javax.inject.Inject) VarcharType(io.trino.spi.type.VarcharType) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) Table(com.google.cloud.bigquery.Table) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) RecordCursor(io.trino.spi.connector.RecordCursor) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) InMemoryRecordSet(io.trino.spi.connector.InMemoryRecordSet) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) ConnectorExpression(io.trino.spi.expression.ConnectorExpression) DatasetInfo(com.google.cloud.bigquery.DatasetInfo) TableInfo(com.google.cloud.bigquery.TableInfo) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) TableId(com.google.cloud.bigquery.TableId) Field(com.google.cloud.bigquery.Field) BigQueryType.toField(io.trino.plugin.bigquery.BigQueryType.toField) StandardTableDefinition(com.google.cloud.bigquery.StandardTableDefinition) TableDefinition(com.google.cloud.bigquery.TableDefinition) TableInfo(com.google.cloud.bigquery.TableInfo) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 65 with ConnectorTableMetadata

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

the class SheetsMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName tableName : listTables(session, prefix.getSchema())) {
        Optional<ConnectorTableMetadata> tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata.isPresent()) {
            columns.put(tableName, tableMetadata.get().getColumns());
        }
    }
    return columns.buildOrThrow();
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Aggregations

ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)113 SchemaTableName (io.trino.spi.connector.SchemaTableName)69 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)62 Test (org.testng.annotations.Test)48 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)39 ConnectorSession (io.trino.spi.connector.ConnectorSession)35 ImmutableList (com.google.common.collect.ImmutableList)34 List (java.util.List)32 ImmutableMap (com.google.common.collect.ImmutableMap)31 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)30 ColumnHandle (io.trino.spi.connector.ColumnHandle)25 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)20 Optional (java.util.Optional)20 TrinoException (io.trino.spi.TrinoException)19 Map (java.util.Map)19 Type (io.trino.spi.type.Type)18 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)17 Constraint (io.trino.spi.connector.Constraint)17 ImmutableSet (com.google.common.collect.ImmutableSet)16