Search in sources :

Example 1 with ColumnNotFoundException

use of com.facebook.presto.spi.ColumnNotFoundException in project presto by prestodb.

the class AtopMetadata method getColumnMetadata.

@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    String columnName = ((AtopColumnHandle) columnHandle).getName();
    for (ColumnMetadata column : getTableMetadata(session, tableHandle).getColumns()) {
        if (column.getName().equals(columnName)) {
            return column;
        }
    }
    AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
    SchemaTableName tableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
    throw new ColumnNotFoundException(tableName, columnName);
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ColumnNotFoundException(com.facebook.presto.spi.ColumnNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 2 with ColumnNotFoundException

use of com.facebook.presto.spi.ColumnNotFoundException in project presto by prestodb.

the class TestingHiveMetastore method renameColumn.

@Override
public synchronized void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
    SchemaTableName name = new SchemaTableName(databaseName, tableName);
    Table oldTable = getRequiredTable(name);
    if (oldTable.getColumn(newColumnName).isPresent()) {
        throw new PrestoException(ALREADY_EXISTS, "Column already exists: " + newColumnName);
    }
    if (!oldTable.getColumn(oldColumnName).isPresent()) {
        throw new ColumnNotFoundException(name, oldColumnName);
    }
    for (Column column : oldTable.getPartitionColumns()) {
        if (column.getName().equals(oldColumnName)) {
            throw new PrestoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
        }
    }
    ImmutableList.Builder<Column> newDataColumns = ImmutableList.builder();
    for (Column fieldSchema : oldTable.getDataColumns()) {
        if (fieldSchema.getName().equals(oldColumnName)) {
            newDataColumns.add(new Column(newColumnName, fieldSchema.getType(), fieldSchema.getComment()));
        } else {
            newDataColumns.add(fieldSchema);
        }
    }
    Table newTable = Table.builder(oldTable).setDataColumns(newDataColumns.build()).build();
    relations.put(name, newTable);
}
Also used : ColumnNotFoundException(com.facebook.presto.spi.ColumnNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

ColumnNotFoundException (com.facebook.presto.spi.ColumnNotFoundException)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)1 ImmutableList (com.google.common.collect.ImmutableList)1