Search in sources :

Example 1 with Row

use of com.facebook.presto.accumulo.model.Row in project presto by prestodb.

the class AccumuloPageSink method appendPage.

@Override
public CompletableFuture<?> appendPage(Page page) {
    // For each position within the page, i.e. row
    for (int position = 0; position < page.getPositionCount(); ++position) {
        Row row = new Row();
        // For each channel within the page, i.e. column
        for (int channel = 0; channel < page.getChannelCount(); ++channel) {
            // Get the type for this channel
            Type type = columns.get(channel).getType();
            // Read the value from the page and append the field to the row
            row.addField(TypeUtils.readNativeValue(type, page.getBlock(channel), position), type);
        }
        try {
            // Convert row to a Mutation, writing and indexing it
            Mutation mutation = toMutation(row, rowIdOrdinal, columns, serializer);
            writer.addMutation(mutation);
            if (indexer.isPresent()) {
                indexer.get().index(mutation);
            }
            ++numRows;
        } catch (MutationsRejectedException e) {
            throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Mutation rejected by server", e);
        }
        // TODO Fix arbitrary flush every 100k rows
        if (numRows % 100_000 == 0) {
            flush();
        }
    }
    return NOT_BLOCKED;
}
Also used : Type(com.facebook.presto.spi.type.Type) VarcharType(com.facebook.presto.spi.type.VarcharType) PrestoException(com.facebook.presto.spi.PrestoException) Row(com.facebook.presto.accumulo.model.Row) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Aggregations

Row (com.facebook.presto.accumulo.model.Row)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Type (com.facebook.presto.spi.type.Type)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 Mutation (org.apache.accumulo.core.data.Mutation)1