Search in sources :

Example 6 with Upsert

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

the class SchemaEmulationByTableNameConvention method createSchema.

@Override
public void createSchema(KuduClient client, String schemaName) {
    if (DEFAULT_SCHEMA.equals(schemaName)) {
        throw new SchemaAlreadyExistsException(schemaName);
    } else {
        try {
            KuduTable schemasTable = getSchemasTable(client);
            KuduSession session = client.newSession();
            try {
                Upsert upsert = schemasTable.newUpsert();
                upsert.getRow().addString(0, schemaName);
                session.apply(upsert);
            } finally {
                session.close();
            }
        } catch (KuduException e) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
        }
    }
}
Also used : Upsert(org.apache.kudu.client.Upsert) KuduSession(org.apache.kudu.client.KuduSession) KuduTable(org.apache.kudu.client.KuduTable) PrestoException(com.facebook.presto.spi.PrestoException) KuduException(org.apache.kudu.client.KuduException)

Example 7 with Upsert

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

the class KuduPageSink method appendPage.

@Override
public CompletableFuture<?> appendPage(Page page) {
    for (int position = 0; position < page.getPositionCount(); position++) {
        Upsert upsert = table.newUpsert();
        PartialRow row = upsert.getRow();
        int start = 0;
        if (generateUUID) {
            String id = String.format("%s-%08x", uuid, nextSubId++);
            row.addString(0, id);
            start = 1;
        }
        for (int channel = 0; channel < page.getChannelCount(); channel++) {
            appendColumn(row, page, position, channel, channel + start);
        }
        try {
            session.apply(upsert);
        } catch (KuduException e) {
            throw new RuntimeException(e);
        }
    }
    return NOT_BLOCKED;
}
Also used : Upsert(org.apache.kudu.client.Upsert) PartialRow(org.apache.kudu.client.PartialRow) KuduException(org.apache.kudu.client.KuduException)

Aggregations

Upsert (org.apache.kudu.client.Upsert)7 KuduException (org.apache.kudu.client.KuduException)4 PartialRow (org.apache.kudu.client.PartialRow)4 KuduSession (org.apache.kudu.client.KuduSession)3 KuduTable (org.apache.kudu.client.KuduTable)3 ColumnSchema (org.apache.kudu.ColumnSchema)2 OperationResponse (org.apache.kudu.client.OperationResponse)2 PrestoException (com.facebook.presto.spi.PrestoException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Schema (org.apache.avro.Schema)1 Column (org.apache.gora.kudu.mapping.Column)1 GoraException (org.apache.gora.util.GoraException)1 Schema (org.apache.kudu.Schema)1 Type (org.apache.kudu.Type)1