Java Code Examples for com.facebook.presto.spi.Page#getPositionCount()

The following examples show how to use com.facebook.presto.spi.Page#getPositionCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KuduPageSink.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ElasticsearchPageSink.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<?> appendPage(Page page)
{
    List<Document> batch = new ArrayList<>(page.getPositionCount());

    for (int position = 0; position < page.getPositionCount(); position++) {
        Document.DocumentBuilder builder = Document.newDocument().setIndex(schemaTableName.getTableName());
        Map<String, Object> source = new HashMap<>();
        for (int channel = 0; channel < page.getChannelCount(); channel++) {
            ElasticsearchColumnHandle column = columns.get(channel);
            Object value = getObjectValue(column.getType(), page.getBlock(channel), position);

            if ("_id".equals(column.getName())) {
                builder.setId((String) value);
            }
            else if ("_type".equals(column.getName())) {
                builder.setType((String) value);
            }
            else {
                source.put(column.getName(), value);
            }
        }
        batch.add(builder.setSource(source).get());
    }

    // push
    client.insertMany(batch);
    return NOT_BLOCKED;
}
 
Example 3
Source File: HbasePageSink.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<?> appendPage(Page page)
{
    // For each position within the page, i.e. row
    for (int position = 0; position < page.getPositionCount(); ++position) {
        Type rowkeyType = columns.get(rowIdOrdinal).getType();
        Object rowKey = TypeUtils.readNativeValue(rowkeyType, page.getBlock(rowIdOrdinal), position);
        if (rowKey == null) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Column mapped as the Hbase row ID cannot be null");
        }
        Put put = new Put(toHbaseBytes(rowkeyType, rowKey));

        // For each channel within the page, i.e. column
        for (HbaseColumnHandle column : columns) {
            // Skip the row ID ordinal
            if (column.getOrdinal() == rowIdOrdinal) {
                continue;
            }
            // Get the type for this channel
            int channel = column.getOrdinal();

            // Read the value from the page and append the field to the row
            Object value = TypeUtils.readNativeValue(column.getType(), page.getBlock(channel), position);
            put.addColumn(
                    Bytes.toBytes(column.getFamily().get()),
                    Bytes.toBytes(column.getQualifier().get()),
                    toHbaseBytes(column.getType(), value));
        }

        // Convert row to a Mutation, writing and indexing it
        puts.add(put);
        ++numRows;

        // TODO Fix arbitrary flush every 10k rows
        if (numRows % MAX_PUT_NUM == 0) {
            flush();
        }
    }

    return NOT_BLOCKED;
}