Search in sources :

Example 1 with AlterTableOptions

use of org.apache.kudu.client.AlterTableOptions in project presto by prestodb.

the class KuduClientSession method renameColumn.

public void renameColumn(SchemaTableName schemaTableName, String oldName, String newName) {
    reTryKerberos(kerberosAuthEnabled);
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        AlterTableOptions alterOptions = new AlterTableOptions();
        alterOptions.renameColumn(oldName, newName);
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
Also used : AlterTableOptions(org.apache.kudu.client.AlterTableOptions) PrestoException(com.facebook.presto.spi.PrestoException) KuduException(org.apache.kudu.client.KuduException)

Example 2 with AlterTableOptions

use of org.apache.kudu.client.AlterTableOptions in project presto by prestodb.

the class KuduClientSession method addColumn.

public void addColumn(SchemaTableName schemaTableName, ColumnMetadata column) {
    reTryKerberos(kerberosAuthEnabled);
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        AlterTableOptions alterOptions = new AlterTableOptions();
        Type type = TypeHelper.toKuduClientType(column.getType());
        alterOptions.addNullableColumn(column.getName(), type);
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
Also used : AlterTableOptions(org.apache.kudu.client.AlterTableOptions) Type(org.apache.kudu.Type) DecimalType(com.facebook.presto.common.type.DecimalType) PrestoException(com.facebook.presto.spi.PrestoException) KuduException(org.apache.kudu.client.KuduException)

Example 3 with AlterTableOptions

use of org.apache.kudu.client.AlterTableOptions in project presto by prestodb.

the class KuduClientSession method dropColumn.

public void dropColumn(SchemaTableName schemaTableName, String name) {
    reTryKerberos(kerberosAuthEnabled);
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        AlterTableOptions alterOptions = new AlterTableOptions();
        alterOptions.dropColumn(name);
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
Also used : AlterTableOptions(org.apache.kudu.client.AlterTableOptions) PrestoException(com.facebook.presto.spi.PrestoException) KuduException(org.apache.kudu.client.KuduException)

Example 4 with AlterTableOptions

use of org.apache.kudu.client.AlterTableOptions in project presto by prestodb.

the class KuduClientSession method renameTable.

public void renameTable(SchemaTableName schemaTableName, SchemaTableName newSchemaTableName) {
    reTryKerberos(kerberosAuthEnabled);
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        String newRawName = schemaEmulation.toRawName(newSchemaTableName);
        AlterTableOptions alterOptions = new AlterTableOptions();
        alterOptions.renameTable(newRawName);
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
Also used : AlterTableOptions(org.apache.kudu.client.AlterTableOptions) PrestoException(com.facebook.presto.spi.PrestoException) KuduException(org.apache.kudu.client.KuduException)

Example 5 with AlterTableOptions

use of org.apache.kudu.client.AlterTableOptions in project presto by prestodb.

the class KuduClientSession method changeRangePartition.

private void changeRangePartition(SchemaTableName schemaTableName, RangePartition rangePartition, RangePartitionChange change) {
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        KuduTable table = client.openTable(rawName);
        Schema schema = table.getSchema();
        PartitionDesign design = KuduTableProperties.getPartitionDesign(table);
        RangePartitionDefinition definition = design.getRange();
        if (definition == null) {
            throw new PrestoException(QUERY_REJECTED, "Table " + schemaTableName + " has no range partition");
        }
        PartialRow lowerBound = KuduTableProperties.toRangeBoundToPartialRow(schema, definition, rangePartition.getLower());
        PartialRow upperBound = KuduTableProperties.toRangeBoundToPartialRow(schema, definition, rangePartition.getUpper());
        AlterTableOptions alterOptions = new AlterTableOptions();
        switch(change) {
            case ADD:
                alterOptions.addRangePartition(lowerBound, upperBound);
                break;
            case DROP:
                alterOptions.dropRangePartition(lowerBound, upperBound);
                break;
        }
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
Also used : AlterTableOptions(org.apache.kudu.client.AlterTableOptions) Schema(org.apache.kudu.Schema) ColumnSchema(org.apache.kudu.ColumnSchema) PartialRow(org.apache.kudu.client.PartialRow) KuduTable(org.apache.kudu.client.KuduTable) RangePartitionDefinition(com.facebook.presto.kudu.properties.RangePartitionDefinition) PrestoException(com.facebook.presto.spi.PrestoException) PartitionDesign(com.facebook.presto.kudu.properties.PartitionDesign) KuduException(org.apache.kudu.client.KuduException)

Aggregations

PrestoException (com.facebook.presto.spi.PrestoException)5 AlterTableOptions (org.apache.kudu.client.AlterTableOptions)5 KuduException (org.apache.kudu.client.KuduException)5 DecimalType (com.facebook.presto.common.type.DecimalType)1 PartitionDesign (com.facebook.presto.kudu.properties.PartitionDesign)1 RangePartitionDefinition (com.facebook.presto.kudu.properties.RangePartitionDefinition)1 ColumnSchema (org.apache.kudu.ColumnSchema)1 Schema (org.apache.kudu.Schema)1 Type (org.apache.kudu.Type)1 KuduTable (org.apache.kudu.client.KuduTable)1 PartialRow (org.apache.kudu.client.PartialRow)1