use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.
the class TpchMetadata method getTableMetadata.
private static ConnectorTableMetadata getTableMetadata(String schemaName, TpchTable<?> tpchTable, ColumnNaming columnNaming) {
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (TpchColumn<? extends TpchEntity> column : tpchTable.getColumns()) {
columns.add(new ColumnMetadata(columnNaming.getName(column), getPrestoType(column), false, null, null, false, emptyMap()));
}
columns.add(new ColumnMetadata(ROW_NUMBER_COLUMN_NAME, BIGINT, null, true));
SchemaTableName tableName = new SchemaTableName(schemaName, tpchTable.getTableName());
return new ConnectorTableMetadata(tableName, columns.build());
}
use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.
the class TpcdsMetadata method listTableColumns.
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
for (String schemaName : getSchemaNames(session, prefix.getSchema())) {
for (Table tpcdsTable : Table.getBaseTables()) {
if (prefix.getTable().map(tpcdsTable.getName()::equals).orElse(true)) {
ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpcdsTable);
tableColumns.put(new SchemaTableName(schemaName, tpcdsTable.getName()), tableMetadata.getColumns());
}
}
}
return tableColumns.build();
}
use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.
the class TestMemoryMetadata method tableAlreadyExists.
@Test
public void tableAlreadyExists() {
assertNoTables();
SchemaTableName test1Table = new SchemaTableName("default", "test1");
SchemaTableName test2Table = new SchemaTableName("default", "test2");
metadata.createTable(SESSION, new ConnectorTableMetadata(test1Table, ImmutableList.of()), false);
try {
metadata.createTable(SESSION, new ConnectorTableMetadata(test1Table, ImmutableList.of()), false);
fail("Should fail because table already exists");
} catch (PrestoException ex) {
assertEquals(ex.getErrorCode(), ALREADY_EXISTS.toErrorCode());
assertEquals(ex.getMessage(), "Table [default.test1] already exists");
}
ConnectorTableHandle test1TableHandle = metadata.getTableHandle(SESSION, test1Table);
metadata.createTable(SESSION, new ConnectorTableMetadata(test2Table, ImmutableList.of()), false);
try {
metadata.renameTable(SESSION, test1TableHandle, test2Table);
fail("Should fail because table already exists");
} catch (PrestoException ex) {
assertEquals(ex.getErrorCode(), ALREADY_EXISTS.toErrorCode());
assertEquals(ex.getMessage(), "Table [default.test2] already exists");
}
}
use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.
the class TestMemoryMetadata method testRenameTable.
@Test
public void testRenameTable() {
SchemaTableName tableName = new SchemaTableName("test_schema", "test_table_to_be_renamed");
metadata.createSchema(SESSION, "test_schema", ImmutableMap.of());
ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(tableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty());
metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
// rename table to schema which does not exist
SchemaTableName invalidSchemaTableName = new SchemaTableName("test_schema_not_exist", "test_table_renamed");
ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, tableName);
Throwable throwable = expectThrows(SchemaNotFoundException.class, () -> metadata.renameTable(SESSION, tableHandle, invalidSchemaTableName));
assertTrue(throwable.getMessage().equals("Schema test_schema_not_exist not found"));
// rename table to same schema
SchemaTableName sameSchemaTableName = new SchemaTableName("test_schema", "test_renamed");
metadata.renameTable(SESSION, metadata.getTableHandle(SESSION, tableName), sameSchemaTableName);
assertEquals(metadata.listTables(SESSION, Optional.of("test_schema")), ImmutableList.of(sameSchemaTableName));
}
use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.
the class TestMemoryMetadata method tableIsCreatedAfterCommits.
@Test
public void tableIsCreatedAfterCommits() {
assertNoTables();
SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table");
ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty());
metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty());
assertEquals(tables.size(), 1, "Expected only one table");
assertEquals(tables.get(0).getTableName(), "temp_table", "Expected table with name 'temp_table'");
}
Aggregations