use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestValidateLimitWithPresortedInput 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(MOCK_TABLE_NAME)) {
return new ConnectorTableProperties(TupleDomain.all(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(new SortingProperty<>(COLUMN_HANDLE_A, ASC_NULLS_FIRST), new SortingProperty<>(COLUMN_HANDLE_C, ASC_NULLS_FIRST)));
}
throw new IllegalArgumentException();
}).withGetColumns(schemaTableName -> {
if (schemaTableName.equals(MOCK_TABLE_NAME)) {
return ImmutableList.of(new ColumnMetadata(COLUMN_NAME_A, VARCHAR), new ColumnMetadata(COLUMN_NAME_B, VARCHAR), new ColumnMetadata(COLUMN_NAME_C, VARCHAR));
}
throw new IllegalArgumentException();
}).build();
queryRunner.createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
return queryRunner;
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class BaseJdbcClient method createTable.
protected JdbcOutputTableHandle createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, String targetTableName) throws SQLException {
SchemaTableName schemaTableName = tableMetadata.getTable();
ConnectorIdentity identity = session.getIdentity();
if (!getSchemaNames(session).contains(schemaTableName.getSchemaName())) {
throw new TrinoException(NOT_FOUND, "Schema not found: " + schemaTableName.getSchemaName());
}
try (Connection connection = connectionFactory.openConnection(session)) {
String remoteSchema = identifierMapping.toRemoteSchemaName(identity, connection, schemaTableName.getSchemaName());
String remoteTable = identifierMapping.toRemoteTableName(identity, connection, remoteSchema, schemaTableName.getTableName());
String remoteTargetTableName = identifierMapping.toRemoteTableName(identity, connection, remoteSchema, targetTableName);
String catalog = connection.getCatalog();
ImmutableList.Builder<String> columnNames = ImmutableList.builder();
ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();
ImmutableList.Builder<String> columnList = ImmutableList.builder();
for (ColumnMetadata column : tableMetadata.getColumns()) {
String columnName = identifierMapping.toRemoteColumnName(connection, column.getName());
columnNames.add(columnName);
columnTypes.add(column.getType());
columnList.add(getColumnDefinitionSql(session, column, columnName));
}
RemoteTableName remoteTableName = new RemoteTableName(Optional.ofNullable(catalog), Optional.ofNullable(remoteSchema), remoteTargetTableName);
String sql = createTableSql(remoteTableName, columnList.build(), tableMetadata);
execute(connection, sql);
return new JdbcOutputTableHandle(catalog, remoteSchema, remoteTable, columnNames.build(), columnTypes.build(), Optional.empty(), remoteTargetTableName);
}
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestAccumuloClient method testCreateTableEmptyAccumuloColumn.
@Test
public void testCreateTableEmptyAccumuloColumn() {
SchemaTableName tableName = new SchemaTableName("default", "test_create_table_empty_accumulo_column");
try {
List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("id", BIGINT), new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT));
Map<String, Object> properties = new HashMap<>();
new AccumuloTableProperties().getTableProperties().forEach(meta -> properties.put(meta.getName(), meta.getDefaultValue()));
properties.put("external", true);
properties.put("column_mapping", "a:a:a,b::b,c:c:,d::");
client.createTable(new ConnectorTableMetadata(tableName, columns, properties));
assertNotNull(client.getTable(tableName));
} finally {
AccumuloTable table = zooKeeperMetadataManager.getTable(tableName);
if (table != null) {
client.dropTable(table);
}
}
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class BigQueryMetadata method getViewDefinitionSystemTable.
private Optional<SystemTable> getViewDefinitionSystemTable(ConnectorSession session, SchemaTableName viewDefinitionTableName, SchemaTableName sourceTableName) {
BigQueryClient client = bigQueryClientFactory.create(session);
String projectId = getProjectId(client);
String remoteSchemaName = client.toRemoteDataset(projectId, sourceTableName.getSchemaName()).map(RemoteDatabaseObject::getOnlyRemoteName).orElseThrow(() -> new TableNotFoundException(viewDefinitionTableName));
String remoteTableName = client.toRemoteTable(projectId, remoteSchemaName, sourceTableName.getTableName()).map(RemoteDatabaseObject::getOnlyRemoteName).orElseThrow(() -> new TableNotFoundException(viewDefinitionTableName));
TableInfo tableInfo = client.getTable(TableId.of(projectId, remoteSchemaName, remoteTableName)).orElseThrow(() -> new TableNotFoundException(viewDefinitionTableName));
if (!(tableInfo.getDefinition() instanceof ViewDefinition)) {
throw new TableNotFoundException(viewDefinitionTableName);
}
List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("query", VarcharType.VARCHAR));
List<Type> types = columns.stream().map(ColumnMetadata::getType).collect(toImmutableList());
Optional<String> query = Optional.ofNullable(((ViewDefinition) tableInfo.getDefinition()).getQuery());
Iterable<List<Object>> propertyValues = ImmutableList.of(ImmutableList.of(query.orElse("NULL")));
return Optional.of(createSystemTable(new ConnectorTableMetadata(sourceTableName, columns), constraint -> new InMemoryRecordSet(types, propertyValues).cursor()));
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestTypeConversions method testConvertOneLevelRecordColumn.
@Test
public void testConvertOneLevelRecordColumn() {
BigQueryColumnHandle column = new BigQueryColumnHandle("rec", BigQueryType.RECORD, Field.Mode.NULLABLE, null, null, ImmutableList.of(new BigQueryColumnHandle("sub_s", BigQueryType.STRING, Field.Mode.NULLABLE, null, null, ImmutableList.of(), null), new BigQueryColumnHandle("sub_i", BigQueryType.INTEGER, Field.Mode.NULLABLE, null, null, ImmutableList.of(), null)), null);
ColumnMetadata metadata = column.getColumnMetadata();
RowType targetType = RowType.rowType(RowType.field("sub_s", VarcharType.VARCHAR), RowType.field("sub_i", BigintType.BIGINT));
assertThat(metadata.getType()).isEqualTo(targetType);
}
Aggregations