use of io.trino.spi.connector.ConnectorTableLayout in project trino by trinodb.
the class AbstractTestHive method testCreateBucketedTableLayout.
@Test
public void testCreateBucketedTableLayout() {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
Optional<ConnectorTableLayout> newTableLayout = metadata.getNewTableLayout(session, new ConnectorTableMetadata(new SchemaTableName("schema", "table"), ImmutableList.of(new ColumnMetadata("column1", BIGINT), new ColumnMetadata("column2", BIGINT)), ImmutableMap.of(PARTITIONED_BY_PROPERTY, ImmutableList.of(), BUCKETED_BY_PROPERTY, ImmutableList.of("column1"), BUCKET_COUNT_PROPERTY, 10, SORTED_BY_PROPERTY, ImmutableList.of())));
assertTrue(newTableLayout.isPresent());
ConnectorPartitioningHandle partitioningHandle = new HivePartitioningHandle(BUCKETING_V1, 10, ImmutableList.of(HIVE_LONG), OptionalInt.empty(), false);
assertEquals(newTableLayout.get().getPartitioning(), Optional.of(partitioningHandle));
assertEquals(newTableLayout.get().getPartitionColumns(), ImmutableList.of("column1"));
ConnectorBucketNodeMap connectorBucketNodeMap = nodePartitioningProvider.getBucketNodeMap(transaction.getTransactionHandle(), session, partitioningHandle);
assertEquals(connectorBucketNodeMap.getBucketCount(), 10);
assertFalse(connectorBucketNodeMap.hasFixedMapping());
}
}
use of io.trino.spi.connector.ConnectorTableLayout in project trino by trinodb.
the class AbstractTestHive method insertBucketedTableLayout.
protected void insertBucketedTableLayout(boolean transactional) throws Exception {
SchemaTableName tableName = temporaryTable("empty_bucketed_table");
try {
List<Column> columns = ImmutableList.of(new Column("column1", HIVE_STRING, Optional.empty()), new Column("column2", HIVE_LONG, Optional.empty()));
HiveBucketProperty bucketProperty = new HiveBucketProperty(ImmutableList.of("column1"), BUCKETING_V1, 4, ImmutableList.of());
createEmptyTable(tableName, ORC, columns, ImmutableList.of(), Optional.of(bucketProperty), transactional);
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName);
Optional<ConnectorTableLayout> insertLayout = metadata.getInsertLayout(session, tableHandle);
assertTrue(insertLayout.isPresent());
ConnectorPartitioningHandle partitioningHandle = new HivePartitioningHandle(bucketProperty.getBucketingVersion(), bucketProperty.getBucketCount(), ImmutableList.of(HIVE_STRING), OptionalInt.empty(), false);
assertEquals(insertLayout.get().getPartitioning(), Optional.of(partitioningHandle));
assertEquals(insertLayout.get().getPartitionColumns(), ImmutableList.of("column1"));
ConnectorBucketNodeMap connectorBucketNodeMap = nodePartitioningProvider.getBucketNodeMap(transaction.getTransactionHandle(), session, partitioningHandle);
assertEquals(connectorBucketNodeMap.getBucketCount(), 4);
assertFalse(connectorBucketNodeMap.hasFixedMapping());
}
} finally {
dropTable(tableName);
}
}
use of io.trino.spi.connector.ConnectorTableLayout in project trino by trinodb.
the class DeltaLakeMetadata method getLayoutForOptimize.
private Optional<ConnectorTableLayout> getLayoutForOptimize(DeltaLakeTableExecuteHandle executeHandle) {
DeltaTableOptimizeHandle optimizeHandle = (DeltaTableOptimizeHandle) executeHandle.getProcedureHandle();
List<String> partitionColumnNames = optimizeHandle.getMetadataEntry().getCanonicalPartitionColumns();
if (partitionColumnNames.isEmpty()) {
return Optional.empty();
}
Map<String, DeltaLakeColumnHandle> columnsByName = optimizeHandle.getTableColumns().stream().collect(toImmutableMap(columnHandle -> columnHandle.getName().toLowerCase(Locale.ENGLISH), identity()));
ImmutableList.Builder<DeltaLakeColumnHandle> partitioningColumns = ImmutableList.builder();
for (String columnName : partitionColumnNames) {
partitioningColumns.add(columnsByName.get(columnName));
}
DeltaLakePartitioningHandle partitioningHandle = new DeltaLakePartitioningHandle(partitioningColumns.build());
return Optional.of(new ConnectorTableLayout(partitioningHandle, partitionColumnNames));
}
use of io.trino.spi.connector.ConnectorTableLayout in project trino by trinodb.
the class TestInsert method createLocalQueryRunner.
@Override
protected LocalQueryRunner createLocalQueryRunner() {
Session.SessionBuilder sessionBuilder = testSessionBuilder().setCatalog("mock").setSchema("schema");
LocalQueryRunner queryRunner = LocalQueryRunner.create(sessionBuilder.build());
queryRunner.createCatalog("mock", MockConnectorFactory.builder().withGetTableHandle((session, schemaTableName) -> {
if (schemaTableName.getTableName().equals("test_table_preferred_partitioning")) {
return new MockConnectorTableHandle(schemaTableName);
}
if (schemaTableName.getTableName().equals("test_table_required_partitioning")) {
return new MockConnectorTableHandle(schemaTableName);
}
return null;
}).withGetColumns(name -> ImmutableList.of(new ColumnMetadata("column1", INTEGER), new ColumnMetadata("column2", INTEGER))).withGetInsertLayout((session, tableName) -> {
if (tableName.getTableName().equals("test_table_preferred_partitioning")) {
return Optional.of(new ConnectorTableLayout(ImmutableList.of("column1")));
}
if (tableName.getTableName().equals("test_table_required_partitioning")) {
return Optional.of(new ConnectorTableLayout(new TpchPartitioningHandle("orders", 10), ImmutableList.of("column1")));
}
return Optional.empty();
}).withGetNewTableLayout((session, tableMetadata) -> {
if (tableMetadata.getTable().getTableName().equals("new_test_table_preferred_partitioning")) {
return Optional.of(new ConnectorTableLayout(ImmutableList.of("column1")));
}
if (tableMetadata.getTable().getTableName().equals("new_test_table_required_partitioning")) {
return Optional.of(new ConnectorTableLayout(new TpchPartitioningHandle("orders", 10), ImmutableList.of("column1")));
}
if (tableMetadata.getTable().getTableName().equals("new_test_table_unpartitioned")) {
return Optional.empty();
}
return Optional.empty();
}).build(), ImmutableMap.of());
return queryRunner;
}
use of io.trino.spi.connector.ConnectorTableLayout in project trino by trinodb.
the class TestDeltaLakeMetadata method testGetInsertLayout.
@Test
public void testGetInsertLayout() {
DeltaLakeMetadata deltaLakeMetadata = deltaLakeMetadataFactory.create(SESSION.getIdentity());
ConnectorTableMetadata tableMetadata = newTableMetadata(ImmutableList.of(BIGINT_COLUMN_1, BIGINT_COLUMN_2), ImmutableList.of(BIGINT_COLUMN_1));
deltaLakeMetadata.createTable(SESSION, tableMetadata, false);
Optional<ConnectorTableLayout> insertLayout = deltaLakeMetadata.getInsertLayout(SESSION, deltaLakeMetadata.getTableHandle(SESSION, tableMetadata.getTable()));
assertThat(insertLayout).isPresent();
assertThat(insertLayout.get().getPartitioning()).isNotPresent();
assertThat(insertLayout.get().getPartitionColumns()).isEqualTo(getPartitionColumnNames(ImmutableList.of(BIGINT_COLUMN_1)));
}
Aggregations