use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class TestingMetadata method addColumn.
@Override
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) {
ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
SchemaTableName tableName = getTableName(tableHandle);
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
columns.addAll(tableMetadata.getColumns());
columns.add(column);
tables.put(tableName, new ConnectorTableMetadata(tableName, columns.build(), tableMetadata.getProperties(), tableMetadata.getComment()));
}
use of io.trino.spi.connector.SchemaTableName 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.SchemaTableName 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.SchemaTableName in project trino by trinodb.
the class TestPushProjectionIntoTableScan method mockApplyProjection.
private Optional<ProjectionApplicationResult<ConnectorTableHandle>> mockApplyProjection(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorExpression> projections, Map<String, ColumnHandle> assignments) {
// Prepare new table handle
SchemaTableName inputSchemaTableName = ((MockConnectorTableHandle) tableHandle).getTableName();
SchemaTableName projectedTableName = new SchemaTableName(inputSchemaTableName.getSchemaName(), "projected_" + inputSchemaTableName.getTableName());
// Prepare new column handles
ImmutableList.Builder<ConnectorExpression> outputExpressions = ImmutableList.builder();
ImmutableList.Builder<Assignment> outputAssignments = ImmutableList.builder();
ImmutableList.Builder<ColumnHandle> projectedColumnsBuilder = ImmutableList.builder();
for (ConnectorExpression projection : projections) {
String variablePrefix;
if (projection instanceof Variable) {
variablePrefix = "projected_variable_";
} else if (projection instanceof FieldDereference) {
variablePrefix = "projected_dereference_";
} else if (projection instanceof Constant) {
variablePrefix = "projected_constant_";
} else if (projection instanceof Call) {
variablePrefix = "projected_call_";
} else {
throw new UnsupportedOperationException();
}
String newVariableName = variablePrefix + projection.toString();
Variable newVariable = new Variable(newVariableName, projection.getType());
ColumnHandle newColumnHandle = new TpchColumnHandle(newVariableName, projection.getType());
outputExpressions.add(newVariable);
outputAssignments.add(new Assignment(newVariableName, newColumnHandle, projection.getType()));
projectedColumnsBuilder.add(newColumnHandle);
}
return Optional.of(new ProjectionApplicationResult<>(new MockConnectorTableHandle(projectedTableName, TupleDomain.all(), Optional.of(projectedColumnsBuilder.build())), outputExpressions.build(), outputAssignments.build(), false));
}
use of io.trino.spi.connector.SchemaTableName 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();
}
Aggregations