Search in sources :

Example 6 with ColumnSchema

use of org.apache.kudu.ColumnSchema 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.getLastName(), 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

ColumnSchema (org.apache.kudu.ColumnSchema)6 ArrayList (java.util.ArrayList)3 Schema (org.apache.kudu.Schema)3 TimeoutException (com.stumbleupon.async.TimeoutException)2 DBException (com.yahoo.ycsb.DBException)2 MaterializedField (org.apache.drill.exec.record.MaterializedField)2 CreateTableOptions (org.apache.kudu.client.CreateTableOptions)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 UserException (org.apache.drill.common.exceptions.UserException)1 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 BatchSchema (org.apache.drill.exec.record.BatchSchema)1 ValueVector (org.apache.drill.exec.vector.ValueVector)1 Type (org.apache.kudu.Type)1 Insert (org.apache.kudu.client.Insert)1 KuduClient (org.apache.kudu.client.KuduClient)1 KuduScanner (org.apache.kudu.client.KuduScanner)1 KuduSession (org.apache.kudu.client.KuduSession)1