Search in sources :

Example 16 with CreateTableOptions

use of org.apache.kudu.client.CreateTableOptions in project drill by apache.

the class KuduRecordWriterImpl method updateSchema.

@Override
public void updateSchema(VectorAccessible batch) throws IOException {
    BatchSchema schema = batch.getSchema();
    int i = 0;
    try {
        if (!checkForTable(name)) {
            List<ColumnSchema> columns = new ArrayList<>();
            for (MaterializedField f : schema) {
                columns.add(new ColumnSchema.ColumnSchemaBuilder(f.getName(), getType(f.getType())).nullable(f.getType().getMode() == DataMode.OPTIONAL).key(i == 0).build());
                i++;
            }
            Schema kuduSchema = new Schema(columns);
            table = client.createTable(name, kuduSchema, new CreateTableOptions());
        }
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) Schema(org.apache.kudu.Schema) BatchSchema(org.apache.drill.exec.record.BatchSchema) ColumnSchema(org.apache.kudu.ColumnSchema) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.kudu.ColumnSchema) MaterializedField(org.apache.drill.exec.record.MaterializedField) CreateTableOptions(org.apache.kudu.client.CreateTableOptions) IOException(java.io.IOException) UserException(org.apache.drill.common.exceptions.UserException) IOException(java.io.IOException)

Aggregations

CreateTableOptions (org.apache.kudu.client.CreateTableOptions)16 ColumnSchema (org.apache.kudu.ColumnSchema)9 Schema (org.apache.kudu.Schema)8 PartialRow (org.apache.kudu.client.PartialRow)7 ArrayList (java.util.ArrayList)6 Insert (org.apache.kudu.client.Insert)5 KuduSession (org.apache.kudu.client.KuduSession)5 KuduTable (org.apache.kudu.client.KuduTable)5 Before (org.junit.Before)4 KuduException (org.apache.kudu.client.KuduException)3 IOException (java.io.IOException)2 UserException (org.apache.drill.common.exceptions.UserException)2 BatchSchema (org.apache.drill.exec.record.BatchSchema)2 MaterializedField (org.apache.drill.exec.record.MaterializedField)2 KuduClient (org.apache.kudu.client.KuduClient)2 KuduScanner (org.apache.kudu.client.KuduScanner)2 ListTablesResponse (org.apache.kudu.client.ListTablesResponse)2 RowResultIterator (org.apache.kudu.client.RowResultIterator)2 HashPartitionDefinition (com.facebook.presto.kudu.properties.HashPartitionDefinition)1 PartitionDesign (com.facebook.presto.kudu.properties.PartitionDesign)1