Java Code Examples for org.apache.kudu.client.PartialRow#addStringUtf8()

The following examples show how to use org.apache.kudu.client.PartialRow#addStringUtf8() . 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: RowHelper.java    From presto with Apache License 2.0 5 votes vote down vote up
public static void copyPrimaryKey(Schema schema, RowResult from, PartialRow to)
{
    for (int i = 0; i < schema.getPrimaryKeyColumnCount(); i++) {
        switch (schema.getColumnByIndex(i).getType()) {
            case STRING:
                to.addStringUtf8(i, from.getString(i).getBytes(StandardCharsets.UTF_8));
                break;
            case INT64:
            case UNIXTIME_MICROS:
                to.addLong(i, from.getLong(i));
                break;
            case INT32:
                to.addInt(i, from.getInt(i));
                break;
            case INT16:
                to.addShort(i, from.getShort(i));
                break;
            case INT8:
                to.addByte(i, from.getByte(i));
                break;
            case DOUBLE:
                to.addDouble(i, from.getDouble(i));
                break;
            case FLOAT:
                to.addFloat(i, from.getFloat(i));
                break;
            case BOOL:
                to.addBoolean(i, from.getBoolean(i));
                break;
            case BINARY:
                to.addBinary(i, from.getBinary(i));
                break;
            default:
                throw new IllegalStateException("Unknown type " + schema.getColumnByIndex(i).getType()
                        + " for column " + schema.getColumnByIndex(i).getName());
        }
    }
}
 
Example 2
Source File: RowHelper.java    From presto with Apache License 2.0 5 votes vote down vote up
public static void copyPrimaryKey(Schema schema, PartialRow from, PartialRow to)
{
    for (int i = 0; i < schema.getPrimaryKeyColumnCount(); i++) {
        switch (schema.getColumnByIndex(i).getType()) {
            case STRING:
                to.addStringUtf8(i, from.getString(i).getBytes(StandardCharsets.UTF_8));
                break;
            case INT64:
            case UNIXTIME_MICROS:
                to.addLong(i, from.getLong(i));
                break;
            case INT32:
                to.addInt(i, from.getInt(i));
                break;
            case INT16:
                to.addShort(i, from.getShort(i));
                break;
            case INT8:
                to.addByte(i, from.getByte(i));
                break;
            case DOUBLE:
                to.addDouble(i, from.getDouble(i));
                break;
            case FLOAT:
                to.addFloat(i, from.getFloat(i));
                break;
            case BOOL:
                to.addBoolean(i, from.getBoolean(i));
                break;
            case BINARY:
                to.addBinary(i, from.getBinary(i));
                break;
            default:
                throw new IllegalStateException("Unknown type " + schema.getColumnByIndex(i).getType()
                        + " for column " + schema.getColumnByIndex(i).getName());
        }
    }
}
 
Example 3
Source File: KuduPageSink.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
private void appendColumn(PartialRow row, Page page, int position, int channel, int destChannel) {
    Block block = page.getBlock(channel);
    Type type = columnTypes.get(destChannel);
    if (block.isNull(position)) {
        row.setNull(destChannel);
    } else if (TIMESTAMP.equals(type)) {
        row.addLong(destChannel, type.getLong(block, position) * 1000);
    } else if (REAL.equals(type)) {
        row.addFloat(destChannel, intBitsToFloat((int) type.getLong(block, position)));
    } else if (BIGINT.equals(type)) {
        row.addLong(destChannel, type.getLong(block, position));
    } else if (INTEGER.equals(type)) {
        row.addInt(destChannel, (int) type.getLong(block, position));
    } else if (SMALLINT.equals(type)) {
        row.addShort(destChannel, (short) type.getLong(block, position));
    } else if (TINYINT.equals(type)) {
        row.addByte(destChannel, (byte) type.getLong(block, position));
    } else if (BOOLEAN.equals(type)) {
        row.addBoolean(destChannel, type.getBoolean(block, position));
    } else if (DOUBLE.equals(type)) {
        row.addDouble(destChannel, type.getDouble(block, position));
    } else if (isVarcharType(type)) {
        Type originalType = originalColumnTypes.get(destChannel);
        if (DATE.equals(originalType)) {
            SqlDate date = (SqlDate) originalType.getObjectValue(connectorSession, block, position);
            LocalDateTime ldt = LocalDateTime.ofEpochSecond(TimeUnit.DAYS.toSeconds(date.getDays()), 0, ZoneOffset.UTC);
            byte[] bytes = ldt.format(DateTimeFormatter.ISO_LOCAL_DATE).getBytes(Charsets.UTF_8);
            row.addStringUtf8(destChannel, bytes);
        } else {
            row.addString(destChannel, type.getSlice(block, position).toStringUtf8());
        }
    } else if (VARBINARY.equals(type)) {
        row.addBinary(destChannel, type.getSlice(block, position).toByteBuffer());
    } else if (type instanceof DecimalType) {
        SqlDecimal sqlDecimal = (SqlDecimal) type.getObjectValue(connectorSession, block, position);
        row.addDecimal(destChannel, sqlDecimal.toBigDecimal());
    } else {
        throw new UnsupportedOperationException("Type is not supported: " + type);
    }
}
 
Example 4
Source File: RowHelper.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
public static void copyPrimaryKey(Schema schema, RowResult from, PartialRow to) {
    for (int i = 0; i < schema.getPrimaryKeyColumnCount(); i++) {
        switch (schema.getColumnByIndex(i).getType()) {
            case STRING:
                to.addStringUtf8(i, from.getString(i).getBytes(Charsets.UTF_8));
                break;
            case INT64:
            case UNIXTIME_MICROS:
                to.addLong(i, from.getLong(i));
                break;
            case INT32:
                to.addInt(i, from.getInt(i));
                break;
            case INT16:
                to.addShort(i, from.getShort(i));
                break;
            case INT8:
                to.addByte(i, from.getByte(i));
                break;
            case DOUBLE:
                to.addDouble(i, from.getDouble(i));
                break;
            case FLOAT:
                to.addFloat(i, from.getFloat(i));
                break;
            case BOOL:
                to.addBoolean(i, from.getBoolean(i));
                break;
            case BINARY:
                to.addBinary(i, from.getBinary(i));
                break;
            default:
                throw new IllegalStateException("Unknown type " + schema.getColumnByIndex(i).getType()
                        + " for column " + schema.getColumnByIndex(i).getName());
        }
    }
}
 
Example 5
Source File: RowHelper.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
public static void copyPrimaryKey(Schema schema, PartialRow from, PartialRow to) {
    for (int i = 0; i < schema.getPrimaryKeyColumnCount(); i++) {
        switch (schema.getColumnByIndex(i).getType()) {
            case STRING:
                to.addStringUtf8(i, from.getString(i).getBytes(Charsets.UTF_8));
                break;
            case INT64:
            case UNIXTIME_MICROS:
                to.addLong(i, from.getLong(i));
                break;
            case INT32:
                to.addInt(i, from.getInt(i));
                break;
            case INT16:
                to.addShort(i, from.getShort(i));
                break;
            case INT8:
                to.addByte(i, from.getByte(i));
                break;
            case DOUBLE:
                to.addDouble(i, from.getDouble(i));
                break;
            case FLOAT:
                to.addFloat(i, from.getFloat(i));
                break;
            case BOOL:
                to.addBoolean(i, from.getBoolean(i));
                break;
            case BINARY:
                to.addBinary(i, from.getBinary(i));
                break;
            default:
                throw new IllegalStateException("Unknown type " + schema.getColumnByIndex(i).getType()
                        + " for column " + schema.getColumnByIndex(i).getName());
        }
    }
}
 
Example 6
Source File: KuduPageSink.java    From presto with Apache License 2.0 4 votes vote down vote up
private void appendColumn(PartialRow row, Page page, int position, int channel, int destChannel)
{
    Block block = page.getBlock(channel);
    Type type = columnTypes.get(destChannel);
    if (block.isNull(position)) {
        row.setNull(destChannel);
    }
    else if (TIMESTAMP.equals(type)) {
        row.addLong(destChannel, type.getLong(block, position) * 1000);
    }
    else if (REAL.equals(type)) {
        row.addFloat(destChannel, intBitsToFloat(toIntExact(type.getLong(block, position))));
    }
    else if (BIGINT.equals(type)) {
        row.addLong(destChannel, type.getLong(block, position));
    }
    else if (INTEGER.equals(type)) {
        row.addInt(destChannel, toIntExact(type.getLong(block, position)));
    }
    else if (SMALLINT.equals(type)) {
        row.addShort(destChannel, Shorts.checkedCast(type.getLong(block, position)));
    }
    else if (TINYINT.equals(type)) {
        row.addByte(destChannel, SignedBytes.checkedCast(type.getLong(block, position)));
    }
    else if (BOOLEAN.equals(type)) {
        row.addBoolean(destChannel, type.getBoolean(block, position));
    }
    else if (DOUBLE.equals(type)) {
        row.addDouble(destChannel, type.getDouble(block, position));
    }
    else if (isVarcharType(type)) {
        Type originalType = originalColumnTypes.get(destChannel);
        if (DATE.equals(originalType)) {
            SqlDate date = (SqlDate) originalType.getObjectValue(connectorSession, block, position);
            LocalDateTime ldt = LocalDateTime.ofEpochSecond(TimeUnit.DAYS.toSeconds(date.getDays()), 0, ZoneOffset.UTC);
            byte[] bytes = ldt.format(DateTimeFormatter.ISO_LOCAL_DATE).getBytes(StandardCharsets.UTF_8);
            row.addStringUtf8(destChannel, bytes);
        }
        else {
            row.addString(destChannel, type.getSlice(block, position).toStringUtf8());
        }
    }
    else if (VARBINARY.equals(type)) {
        row.addBinary(destChannel, type.getSlice(block, position).toByteBuffer());
    }
    else if (type instanceof DecimalType) {
        SqlDecimal sqlDecimal = (SqlDecimal) type.getObjectValue(connectorSession, block, position);
        row.addDecimal(destChannel, sqlDecimal.toBigDecimal());
    }
    else {
        throw new UnsupportedOperationException("Type is not supported: " + type);
    }
}