use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class TestingDatabase method getColumnHandles.
public Map<String, JdbcColumnHandle> getColumnHandles(String schemaName, String tableName) {
JdbcTableHandle tableHandle = jdbcClient.getTableHandle(new SchemaTableName(schemaName, tableName));
List<JdbcColumnHandle> columns = jdbcClient.getColumns(tableHandle);
checkArgument(columns != null, "table not found: %s.%s", schemaName, tableName);
ImmutableMap.Builder<String, JdbcColumnHandle> columnHandles = ImmutableMap.builder();
for (JdbcColumnHandle column : columns) {
columnHandles.put(column.getColumnMetadata().getName(), column);
}
return columnHandles.build();
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class TestJdbcClient method testMetadataWithFloatAndDoubleCol.
@Test
public void testMetadataWithFloatAndDoubleCol() throws Exception {
SchemaTableName schemaTableName = new SchemaTableName("exa_ple", "table_with_float_col");
JdbcTableHandle table = jdbcClient.getTableHandle(schemaTableName);
assertNotNull(table, "table is null");
assertEquals(jdbcClient.getColumns(table), ImmutableList.of(new JdbcColumnHandle(CONNECTOR_ID, "COL1", BIGINT), new JdbcColumnHandle(CONNECTOR_ID, "COL2", DOUBLE), new JdbcColumnHandle(CONNECTOR_ID, "COL3", DOUBLE), new JdbcColumnHandle(CONNECTOR_ID, "COL4", REAL)));
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class BridgingHiveMetastore method renameColumn.
@Override
public void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(databaseName, tableName);
if (!source.isPresent()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
for (FieldSchema fieldSchema : table.getPartitionKeys()) {
if (fieldSchema.getName().equals(oldColumnName)) {
throw new PrestoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
}
}
for (FieldSchema fieldSchema : table.getSd().getCols()) {
if (fieldSchema.getName().equals(oldColumnName)) {
fieldSchema.setName(newColumnName);
}
}
alterTable(databaseName, tableName, table);
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class SemiTransactionalHiveMetastore method finishInsertIntoExistingPartition.
public synchronized void finishInsertIntoExistingPartition(ConnectorSession session, String databaseName, String tableName, List<String> partitionValues, Path currentLocation, List<String> fileNames) {
setShared();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(schemaTableName, k -> new HashMap<>());
Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partitionValues);
if (oldPartitionAction == null) {
Optional<Partition> partition = delegate.getPartition(databaseName, tableName, partitionValues);
if (!partition.isPresent()) {
throw new PartitionNotFoundException(schemaTableName, partitionValues);
}
partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.INSERT_EXISTING, new PartitionAndMore(partition.get(), currentLocation, Optional.of(fileNames)), session.getUser(), session.getQueryId()));
return;
}
switch(oldPartitionAction.getType()) {
case DROP:
throw new PartitionNotFoundException(schemaTableName, partitionValues);
case ADD:
case ALTER:
case INSERT_EXISTING:
throw new UnsupportedOperationException("Inserting into a partition that were added, altered, or inserted into in the same transaction is not supported");
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class BridgingHiveMetastore method renameTable.
@Override
public void renameTable(String databaseName, String tableName, String newDatabaseName, String newTableName) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(databaseName, tableName);
if (!source.isPresent()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
table.setDbName(newDatabaseName);
table.setTableName(newTableName);
alterTable(databaseName, tableName, table);
}
Aggregations