use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestingMetadata method listTableColumns.
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
for (SchemaTableName tableName : listTables(session, prefix.getSchema())) {
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (ColumnMetadata column : tables.get(tableName).getColumns()) {
columns.add(new ColumnMetadata(column.getName(), column.getType()));
}
tableColumns.put(tableName, columns.build());
}
return tableColumns.buildOrThrow();
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestTableScanRedirectionWithPushdown method createLocalQueryRunner.
private LocalQueryRunner createLocalQueryRunner(ApplyTableScanRedirect applyTableScanRedirect, Optional<ApplyProjection> applyProjection, Optional<ApplyFilter> applyFilter) {
LocalQueryRunner queryRunner = LocalQueryRunner.create(MOCK_SESSION);
MockConnectorFactory.Builder builder = MockConnectorFactory.builder().withGetTableHandle((session, schemaTableName) -> new MockConnectorTableHandle(schemaTableName)).withGetColumns(name -> {
if (name.equals(SOURCE_TABLE)) {
return ImmutableList.of(new ColumnMetadata(SOURCE_COLUMN_NAME_A, INTEGER), new ColumnMetadata(SOURCE_COLUMN_NAME_B, INTEGER), new ColumnMetadata(SOURCE_COLUMN_NAME_C, VARCHAR), new ColumnMetadata(SOURCE_COLUMN_NAME_D, ROW_TYPE));
} else if (name.equals(DESTINATION_TABLE)) {
return ImmutableList.of(new ColumnMetadata(DESTINATION_COLUMN_NAME_A, INTEGER), new ColumnMetadata(DESTINATION_COLUMN_NAME_B, INTEGER), new ColumnMetadata(DESTINATION_COLUMN_NAME_C, ROW_TYPE), new ColumnMetadata(DESTINATION_COLUMN_NAME_D, BOGUS));
}
throw new IllegalArgumentException();
}).withApplyTableScanRedirect(applyTableScanRedirect);
applyProjection.ifPresent(builder::withApplyProjection);
applyFilter.ifPresent(builder::withApplyFilter);
queryRunner.createCatalog(MOCK_CATALOG, builder.build(), ImmutableMap.of());
return queryRunner;
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestPushProjectionIntoTableScan method createMockFactory.
private MockConnectorFactory createMockFactory(Map<String, ColumnHandle> assignments, Optional<MockConnectorFactory.ApplyProjection> applyProjection) {
List<ColumnMetadata> metadata = assignments.entrySet().stream().map(entry -> new ColumnMetadata(entry.getKey(), ((TpchColumnHandle) entry.getValue()).getType())).collect(toImmutableList());
MockConnectorFactory.Builder builder = MockConnectorFactory.builder().withListSchemaNames(connectorSession -> ImmutableList.of(TEST_SCHEMA)).withListTables((connectorSession, schema) -> TEST_SCHEMA.equals(schema) ? ImmutableList.of(TEST_SCHEMA_TABLE) : ImmutableList.of()).withGetColumns(schemaTableName -> metadata).withGetTableProperties((session, tableHandle) -> {
MockConnectorTableHandle mockTableHandle = (MockConnectorTableHandle) tableHandle;
if (mockTableHandle.getTableName().getTableName().equals(TEST_TABLE)) {
return new ConnectorTableProperties(TupleDomain.all(), Optional.of(new ConnectorTablePartitioning(PARTITIONING_HANDLE, ImmutableList.of(column("col", VARCHAR)))), Optional.empty(), Optional.empty(), ImmutableList.of());
}
return new ConnectorTableProperties();
});
if (applyProjection.isPresent()) {
builder = builder.withApplyProjection(applyProjection.get());
}
return builder.build();
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestDeltaLakeSchemaSupport method testComplexSchema.
// |-- a: integer (nullable = false)
// |-- b: struct (nullable = true)
// | |-- b1: integer (nullable = false)
// | |-- b2: struct (nullable = true)
// | |-- b21: string (nullable = true)
// | |-- b22: boolean (nullable = false)
// |-- c: array (nullable = true)
// | |-- element: integer (containsNull = false)
// |-- d: array (nullable = true)
// | |-- element: struct (containsNull = true)
// | | |-- d1: integer (nullable = false)
// |-- e: map (nullable = true)
// | |-- key: string
// | |-- value: struct (valueContainsNull = true)
// | |-- e1: date (nullable = true)
// | |-- e2: timestamp (nullable = false)
@Test
public void testComplexSchema() throws IOException, URISyntaxException {
URL expected = getResource("io/trino/plugin/deltalake/transactionlog/schema/complex_schema.json");
String json = Files.readString(Path.of(expected.toURI()));
List<ColumnMetadata> schema = DeltaLakeSchemaSupport.getColumnMetadata(json, typeManager);
assertEquals(schema.size(), 5);
// asserting on the string representations, since they're more readable
assertEquals(schema.get(0).toString(), "ColumnMetadata{name='a', type=integer, nullable}");
assertEquals(schema.get(1).toString(), "ColumnMetadata{name='b', type=row(b1 integer, b2 row(b21 varchar, b22 boolean)), nullable}");
assertEquals(schema.get(2).toString(), "ColumnMetadata{name='c', type=array(integer), nullable}");
assertEquals(schema.get(3).toString(), "ColumnMetadata{name='d', type=array(row(d1 integer)), nullable}");
assertEquals(schema.get(4).toString(), "ColumnMetadata{name='e', type=map(varchar, row(e1 date, e2 timestamp(3) with time zone)), nullable}");
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestDeltaLakeSchemaSupport method testRoundTripComplexSchema.
@Test
public void testRoundTripComplexSchema() throws IOException, URISyntaxException {
URL expected = getResource("io/trino/plugin/deltalake/transactionlog/schema/complex_schema.json");
String json = Files.readString(Path.of(expected.toURI()));
List<ColumnMetadata> schema = DeltaLakeSchemaSupport.getColumnMetadata(json, typeManager);
List<DeltaLakeColumnHandle> columnHandles = schema.stream().map(metadata -> new DeltaLakeColumnHandle(metadata.getName(), metadata.getType(), REGULAR)).collect(toImmutableList());
ObjectMapper objectMapper = new ObjectMapper();
assertEquals(objectMapper.readTree(serializeSchemaAsJson(columnHandles)), objectMapper.readTree(json));
}
Aggregations