Search in sources :

Example 21 with SchemaTableName

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();
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 22 with SchemaTableName

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)));
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Example 23 with SchemaTableName

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);
}
Also used : MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException)

Example 24 with SchemaTableName

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");
    }
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 25 with SchemaTableName

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);
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

SchemaTableName (com.facebook.presto.spi.SchemaTableName)159 ImmutableList (com.google.common.collect.ImmutableList)49 List (java.util.List)42 Test (org.testng.annotations.Test)40 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)35 ImmutableMap (com.google.common.collect.ImmutableMap)35 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)31 PrestoException (com.facebook.presto.spi.PrestoException)31 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)25 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)19 ArrayList (java.util.ArrayList)19 Collectors.toList (java.util.stream.Collectors.toList)17 ConnectorSession (com.facebook.presto.spi.ConnectorSession)16 Map (java.util.Map)16 ColumnHandle (com.facebook.presto.spi.ColumnHandle)15 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)14 SchemaTablePrefix (com.facebook.presto.spi.SchemaTablePrefix)14 Optional (java.util.Optional)14 Table (com.facebook.presto.hive.metastore.Table)13 Path (org.apache.hadoop.fs.Path)12