org.apache.kudu.Type - java examples

Here are the examples of the java api org.apache.kudu.Type taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

39 Examples 7

19 View Complete Implementation : AbstractKuduOutputOperator.java
Copyright Apache License 2.0
Author : apache
/**
 * Used to build a getter for the given schema column from the POJO field definition
 * @param columnSchema The Kudu column definition
 * @param fieldDefinition The POJO field definition
 */
private void extractGetterForColumn(ColumnSchema columnSchema, Field fieldDefinition) {
    Type columnType = columnSchema.getType();
    Clreplaced pojoClreplaced = getTuplePayloadClreplaced();
    Object getter = null;
    switch(columnType) {
        case BINARY:
            getter = PojoUtils.createGetter(pojoClreplaced, fieldDefinition.getName(), ByteBuffer.clreplaced);
            break;
        case STRING:
            getter = PojoUtils.createGetter(pojoClreplaced, fieldDefinition.getName(), String.clreplaced);
            break;
        case BOOL:
            getter = PojoUtils.createGetterBoolean(pojoClreplaced, fieldDefinition.getName());
            break;
        case DOUBLE:
            getter = PojoUtils.createGetterDouble(pojoClreplaced, fieldDefinition.getName());
            break;
        case FLOAT:
            getter = PojoUtils.createGetterFloat(pojoClreplaced, fieldDefinition.getName());
            break;
        case INT8:
            getter = PojoUtils.createGetterByte(pojoClreplaced, fieldDefinition.getName());
            break;
        case INT16:
            getter = PojoUtils.createGetterShort(pojoClreplaced, fieldDefinition.getName());
            break;
        case INT32:
            getter = PojoUtils.createGetterInt(pojoClreplaced, fieldDefinition.getName());
            break;
        case INT64:
        case UNIXTIME_MICROS:
            getter = PojoUtils.createGetterLong(pojoClreplaced, fieldDefinition.getName());
            break;
        default:
            LOG.error(fieldDefinition.getName() + " has a data type that is not yet supported");
            throw new UnsupportedOperationException(fieldDefinition.getName() + " does not have a compatible data type");
    }
    if (getter != null) {
        kuduColumnBasedGetters.put(columnSchema.getName(), getter);
    }
}

19 View Complete Implementation : RegexpKuduOperationsProducer.java
Copyright Apache License 2.0
Author : apache
/**
 * Coerces the string `rawVal` to the type `type` and sets the resulting
 * value for column `colName` in `row`.
 *
 * @param rawVal the raw string column value
 * @param colName the name of the column
 * @param type the Kudu type to convert `rawVal` to
 * @param row the row to set the value in
 * @throws NumberFormatException if `rawVal` cannot be cast as `type`.
 */
private void coerceAndSet(String rawVal, String colName, Type type, PartialRow row) throws NumberFormatException {
    switch(type) {
        case BOOL:
            row.addBoolean(colName, Boolean.parseBoolean(rawVal));
            break;
        case INT8:
            row.addByte(colName, Byte.parseByte(rawVal));
            break;
        case INT16:
            row.addShort(colName, Short.parseShort(rawVal));
            break;
        case INT32:
            row.addInt(colName, Integer.parseInt(rawVal));
            break;
        // Fall through
        case INT64:
        case UNIXTIME_MICROS:
            row.addLong(colName, Long.parseLong(rawVal));
            break;
        case FLOAT:
            row.addFloat(colName, Float.parseFloat(rawVal));
            break;
        case DOUBLE:
            row.addDouble(colName, Double.parseDouble(rawVal));
            break;
        case BINARY:
            row.addBinary(colName, rawVal.getBytes(charset));
            break;
        case STRING:
            row.addString(colName, rawVal);
            break;
        default:
            logger.warn("got unknown type {} for column '{}'-- ignoring this column", type, colName);
    }
}

19 View Complete Implementation : KuduAllReqRow.java
Copyright Apache License 2.0
Author : DTStack
private void setMapValue(Type type, Map<String, Object> oneRow, String sideFieldName, RowResult result) {
    switch(type) {
        case STRING:
            oneRow.put(sideFieldName, result.getString(sideFieldName));
            break;
        case FLOAT:
            oneRow.put(sideFieldName, result.getFloat(sideFieldName));
            break;
        case INT8:
            oneRow.put(sideFieldName, result.getFloat(sideFieldName));
            break;
        case INT16:
            oneRow.put(sideFieldName, result.getShort(sideFieldName));
            break;
        case INT32:
            oneRow.put(sideFieldName, result.getInt(sideFieldName));
            break;
        case INT64:
            oneRow.put(sideFieldName, result.getLong(sideFieldName));
            break;
        case DOUBLE:
            oneRow.put(sideFieldName, result.getDouble(sideFieldName));
            break;
        case BOOL:
            oneRow.put(sideFieldName, result.getBoolean(sideFieldName));
            break;
        case UNIXTIME_MICROS:
            oneRow.put(sideFieldName, result.getTimestamp(sideFieldName));
            break;
        case BINARY:
            oneRow.put(sideFieldName, result.getBinary(sideFieldName));
            break;
        default:
            throw new IllegalArgumentException("Illegal var type: " + type);
    }
}

19 View Complete Implementation : KuduUtil.java
Copyright Apache License 2.0
Author : DTStack
public static ExpressResult parseExpress(String express, Map<String, Type> nameTypeMap) {
    Matcher matcher = EXPRESS_PATTERN.matcher(express.trim());
    if (matcher.find()) {
        String column = matcher.group("column");
        String op = matcher.group("op");
        String value = matcher.group("value");
        Type type = nameTypeMap.get(column.trim());
        if (type == null) {
            throw new IllegalArgumentException("Can not find column:" + column + " from column list");
        }
        ColumnSchema columnSchema = new ColumnSchema.ColumnSchemaBuilder(column, type).build();
        ExpressResult result = new ExpressResult();
        result.setColumnSchema(columnSchema);
        result.setOp(getOp(op));
        result.setValue(getValue(value, type));
        return result;
    } else {
        throw new IllegalArgumentException("Illegal filter express:" + express);
    }
}

19 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : MartinWeindel
private static Number toNumber(Object obj, Type type, String name) {
    if (Number.clreplaced.isreplacedignableFrom(obj.getClreplaced())) {
        return (Number) obj;
    } else if (obj instanceof String) {
        String s = (String) obj;
        BigDecimal d = new BigDecimal((String) obj);
        return d;
    } else {
        handleInvalidValue(name, type, obj);
        return 0;
    }
}

19 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : MartinWeindel
private static void handleInvalidValue(String name, Type type, Object obj) {
    throw new IllegalStateException("Invalid value " + obj + " for column " + name + " of type " + type);
}

19 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : MartinWeindel
private static byte[] toByteArray(Object obj, Type type, String name) {
    if (obj instanceof byte[]) {
        return (byte[]) obj;
    } else if (obj instanceof String) {
        return Base64.getDecoder().decode((String) obj);
    } else {
        handleInvalidValue(name, type, obj);
        return null;
    }
}

19 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : MartinWeindel
private static long toUnixTimeMicros(Object obj, Type type, String name) {
    if (Number.clreplaced.isreplacedignableFrom(obj.getClreplaced())) {
        return ((Number) obj).longValue();
    } else if (obj instanceof String) {
        String s = (String) obj;
        s = s.trim().replace(' ', 'T');
        long millis = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC).parseMillis(s);
        return millis * 1000;
    } else {
        handleInvalidValue(name, type, obj);
        return 0;
    }
}

19 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : MartinWeindel
private static void setColumnValue(PartialRow partialRow, int idx, Object obj, Type type, String name) {
    Number n;
    switch(type) {
        case STRING:
            if (obj instanceof String) {
                partialRow.addString(idx, (String) obj);
            } else {
                handleInvalidValue(name, type, obj);
            }
            break;
        case INT64:
            n = toNumber(obj, type, name);
            partialRow.addLong(idx, n.longValue());
            break;
        case INT32:
            n = toNumber(obj, type, name);
            partialRow.addInt(idx, n.intValue());
            break;
        case INT16:
            n = toNumber(obj, type, name);
            partialRow.addShort(idx, n.shortValue());
            break;
        case INT8:
            n = toNumber(obj, type, name);
            partialRow.addByte(idx, n.byteValue());
            break;
        case DOUBLE:
            n = toNumber(obj, type, name);
            partialRow.addDouble(idx, n.doubleValue());
            break;
        case FLOAT:
            n = toNumber(obj, type, name);
            partialRow.addFloat(idx, n.floatValue());
            break;
        case UNIXTIME_MICROS:
            long l = toUnixTimeMicros(obj, type, name);
            partialRow.addLong(idx, l);
            break;
        case BOOL:
            boolean b = toBoolean(obj, type, name);
            partialRow.addBoolean(idx, b);
            break;
        case BINARY:
            byte[] bytes = toByteArray(obj, type, name);
            partialRow.addBinary(idx, bytes);
            break;
        default:
            handleInvalidValue(name, type, obj);
            break;
    }
}

19 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : MartinWeindel
private static boolean toBoolean(Object obj, Type type, String name) {
    if (obj instanceof Boolean) {
        return (Boolean) obj;
    } else if (obj instanceof String) {
        return Boolean.valueOf((String) obj);
    } else {
        handleInvalidValue(name, type, obj);
        return false;
    }
}

19 View Complete Implementation : KuduColumnInfo.java
Copyright Apache License 2.0
Author : zhisheng17
/**
 * Desc:
 * Created by zhisheng on 2019-06-08
 * blog:http://www.54tianzhisheng.cn/
 * 微信公众号:zhisheng
 */
public clreplaced KuduColumnInfo implements Serializable {

    private String name;

    private Type type;

    private boolean key;

    private boolean rangeKey;

    private boolean hashKey;

    private boolean nullable;

    private Object defaultValue;

    private int blockSize;

    private Encoding encoding;

    private Compression compression;

    private KuduColumnInfo(String name, Type type) {
        this.name = name;
        this.type = type;
        this.blockSize = 0;
        this.key = false;
        this.rangeKey = false;
        this.hashKey = false;
        this.nullable = false;
        this.defaultValue = null;
        this.encoding = Encoding.AUTO;
        this.compression = Compression.DEFAULT;
    }

    protected String name() {
        return name;
    }

    protected boolean isRangeKey() {
        return rangeKey;
    }

    protected boolean isHashKey() {
        return hashKey;
    }

    protected ColumnSchema columnSchema() {
        return new ColumnSchema.ColumnSchemaBuilder(name, type).key(key).nullable(nullable).defaultValue(defaultValue).desiredBlockSize(blockSize).encoding(encoding.encode).compressionAlgorithm(compression.algorithm).build();
    }

    public static clreplaced Builder {

        private KuduColumnInfo column;

        private Builder(String name, Type type) {
            this.column = new KuduColumnInfo(name, type);
        }

        public static Builder create(String name, Type type) {
            return new Builder(name, type);
        }

        public static Builder createByte(String name) {
            return create(name, Type.INT8);
        }

        public static Builder createShort(String name) {
            return create(name, Type.INT16);
        }

        public static Builder createInteger(String name) {
            return create(name, Type.INT32);
        }

        public static Builder createLong(String name) {
            return create(name, Type.INT64);
        }

        public static Builder createDouble(String name) {
            return create(name, Type.DOUBLE);
        }

        public static Builder createFloat(String name) {
            return create(name, Type.FLOAT);
        }

        public static Builder createString(String name) {
            return create(name, Type.STRING);
        }

        public static Builder createBool(String name) {
            return create(name, Type.BOOL);
        }

        public static Builder createByteArray(String name) {
            return create(name, Type.BINARY);
        }

        public static Builder createUnixTime(String name) {
            return create(name, Type.UNIXTIME_MICROS);
        }

        public Builder asKey() {
            return key(true);
        }

        public Builder key(boolean key) {
            this.column.key = key;
            return this;
        }

        public Builder asRangeKey() {
            return rangeKey(true);
        }

        public Builder rangeKey(boolean rangeKey) {
            this.column.rangeKey = rangeKey;
            return this;
        }

        public Builder asHashKey() {
            return hashKey(true);
        }

        public Builder hashKey(boolean hashKey) {
            this.column.hashKey = hashKey;
            return this;
        }

        public Builder asNullable() {
            return nullable(true);
        }

        public Builder asNotNullable() {
            return nullable(false);
        }

        public Builder nullable(boolean nullable) {
            this.column.nullable = nullable;
            return this;
        }

        public Builder defaultValue(Object defaultValue) {
            this.column.defaultValue = defaultValue;
            return this;
        }

        public Builder desiredBlockSize(int blockSize) {
            this.column.blockSize = blockSize;
            return this;
        }

        public Builder encoding(Encoding encoding) {
            this.column.encoding = encoding;
            return this;
        }

        public Builder compressionAlgorithm(Compression compression) {
            this.column.compression = compression;
            return this;
        }

        public KuduColumnInfo build() {
            return column;
        }
    }

    public enum Compression {

        UNKNOWN(ColumnSchema.CompressionAlgorithm.UNKNOWN),
        DEFAULT(ColumnSchema.CompressionAlgorithm.DEFAULT_COMPRESSION),
        WITHOUT(ColumnSchema.CompressionAlgorithm.NO_COMPRESSION),
        SNAPPY(ColumnSchema.CompressionAlgorithm.SNAPPY),
        LZ4(ColumnSchema.CompressionAlgorithm.LZ4),
        ZLIB(ColumnSchema.CompressionAlgorithm.ZLIB);

        final ColumnSchema.CompressionAlgorithm algorithm;

        Compression(ColumnSchema.CompressionAlgorithm algorithm) {
            this.algorithm = algorithm;
        }
    }

    public enum Encoding {

        UNKNOWN(ColumnSchema.Encoding.UNKNOWN),
        AUTO(ColumnSchema.Encoding.AUTO_ENCODING),
        PLAIN(ColumnSchema.Encoding.PLAIN_ENCODING),
        PREFIX(ColumnSchema.Encoding.PREFIX_ENCODING),
        GROUP_VARINT(ColumnSchema.Encoding.GROUP_VARINT),
        RLE(ColumnSchema.Encoding.RLE),
        DICT(ColumnSchema.Encoding.DICT_ENCODING),
        BIT_SHUFFLE(ColumnSchema.Encoding.BIT_SHUFFLE);

        final ColumnSchema.Encoding encode;

        Encoding(ColumnSchema.Encoding encode) {
            this.encode = encode;
        }
    }
}

19 View Complete Implementation : KuduMapper.java
Copyright Apache License 2.0
Author : zhisheng17
static Operation toOperation(KuduTable table, KuduConnector.WriteMode writeMode, KuduRow row) {
    final Operation operation = toOperation(table, writeMode);
    final PartialRow partialRow = operation.getRow();
    table.getSchema().getColumns().forEach(column -> {
        String columnName = column.getName();
        Object value = row.getField(column.getName());
        if (value == null) {
            partialRow.setNull(columnName);
        } else {
            Type type = column.getType();
            switch(type) {
                case STRING:
                    partialRow.addString(columnName, (String) value);
                    break;
                case FLOAT:
                    partialRow.addFloat(columnName, (Float) value);
                    break;
                case INT8:
                    partialRow.addByte(columnName, (Byte) value);
                    break;
                case INT16:
                    partialRow.addShort(columnName, (Short) value);
                    break;
                case INT32:
                    partialRow.addInt(columnName, (Integer) value);
                    break;
                case INT64:
                    partialRow.addLong(columnName, (Long) value);
                    break;
                case DOUBLE:
                    partialRow.addDouble(columnName, (Double) value);
                    break;
                case BOOL:
                    partialRow.addBoolean(columnName, (Boolean) value);
                    break;
                case UNIXTIME_MICROS:
                    // *1000 to correctly create date on kudu
                    partialRow.addLong(columnName, ((Long) value) * 1000);
                    break;
                case BINARY:
                    partialRow.addBinary(columnName, (byte[]) value);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal var type: " + type);
            }
        }
    });
    return operation;
}

18 View Complete Implementation : AbstractKuduOutputOperator.java
Copyright Apache License 2.0
Author : apache
/**
 * Sets the values from the Pojo into the Kudu mutation object.
 * @param currentOperation The operation instance that represents the current mutation. This will be applied to the
 *                         current session
 * @param kuduExecutionContext The tuple that contains the payload as well as other information like mutation type etc
 */
@SuppressWarnings(value = "unchecked")
private void performCommonProcessing(Operation currentOperation, KuduExecutionContext kuduExecutionContext) {
    currentOperation.setExternalConsistencyMode(kuduExecutionContext.getExternalConsistencyMode());
    Long propagatedTimeStamp = kuduExecutionContext.getPropagatedTimestamp();
    if (propagatedTimeStamp != null) {
        // set propagation timestamp only if enabled
        currentOperation.setPropagatedTimestamp(propagatedTimeStamp);
    }
    PartialRow partialRow = currentOperation.getRow();
    Object payload = kuduExecutionContext.getPayload();
    Set<String> doNotWriteColumns = kuduExecutionContext.getDoNotWriteColumns();
    if (doNotWriteColumns == null) {
        doNotWriteColumns = new HashSet<>();
    }
    for (String columnName : kuduColumnBasedGetters.keySet()) {
        if (doNotWriteColumns.contains(columnName)) {
            continue;
        }
        ColumnSchema columnSchema = allColumnDefs.get(columnName);
        Type dataType = columnSchema.getType();
        try {
            switch(dataType) {
                case STRING:
                    PojoUtils.Getter<Object, String> stringGetter = ((PojoUtils.Getter<Object, String>) kuduColumnBasedGetters.get(columnName));
                    if (stringGetter != null) {
                        final String stringValue = stringGetter.get(payload);
                        if (stringValue != null) {
                            partialRow.addString(columnName, stringValue);
                        }
                    }
                    break;
                case BINARY:
                    PojoUtils.Getter<Object, ByteBuffer> byteBufferGetter = ((PojoUtils.Getter<Object, ByteBuffer>) kuduColumnBasedGetters.get(columnName));
                    if (byteBufferGetter != null) {
                        final ByteBuffer byteBufferValue = byteBufferGetter.get(payload);
                        if (byteBufferValue != null) {
                            partialRow.addBinary(columnName, byteBufferValue);
                        }
                    }
                    break;
                case BOOL:
                    PojoUtils.GetterBoolean<Object> boolGetter = ((PojoUtils.GetterBoolean<Object>) kuduColumnBasedGetters.get(columnName));
                    if (boolGetter != null) {
                        final boolean boolValue = boolGetter.get(payload);
                        partialRow.addBoolean(columnName, boolValue);
                    }
                    break;
                case DOUBLE:
                    PojoUtils.GetterDouble<Object> doubleGetter = ((PojoUtils.GetterDouble<Object>) kuduColumnBasedGetters.get(columnName));
                    if (doubleGetter != null) {
                        final double doubleValue = doubleGetter.get(payload);
                        partialRow.addDouble(columnName, doubleValue);
                    }
                    break;
                case FLOAT:
                    PojoUtils.GetterFloat<Object> floatGetter = ((PojoUtils.GetterFloat<Object>) kuduColumnBasedGetters.get(columnName));
                    if (floatGetter != null) {
                        final float floatValue = floatGetter.get(payload);
                        partialRow.addFloat(columnName, floatValue);
                    }
                    break;
                case INT8:
                    PojoUtils.GetterByte<Object> byteGetter = ((PojoUtils.GetterByte<Object>) kuduColumnBasedGetters.get(columnName));
                    if (byteGetter != null) {
                        final byte byteValue = byteGetter.get(payload);
                        partialRow.addByte(columnName, byteValue);
                    }
                    break;
                case INT16:
                    PojoUtils.GetterShort<Object> shortGetter = ((PojoUtils.GetterShort<Object>) kuduColumnBasedGetters.get(columnName));
                    if (shortGetter != null) {
                        final short shortValue = shortGetter.get(payload);
                        partialRow.addShort(columnName, shortValue);
                    }
                    break;
                case INT32:
                    PojoUtils.GetterInt<Object> intGetter = ((PojoUtils.GetterInt<Object>) kuduColumnBasedGetters.get(columnName));
                    if (intGetter != null) {
                        final int intValue = intGetter.get(payload);
                        partialRow.addInt(columnName, intValue);
                    }
                    break;
                case INT64:
                case UNIXTIME_MICROS:
                    PojoUtils.GetterLong<Object> longGetter = ((PojoUtils.GetterLong<Object>) kuduColumnBasedGetters.get(columnName));
                    if (longGetter != null) {
                        final long longValue = longGetter.get(payload);
                        partialRow.addLong(columnName, longValue);
                    }
                    break;
                default:
                    LOG.error(columnName + " is not of the supported data type");
                    throw new UnsupportedOperationException("Kudu does not support data type for column " + columnName);
            }
        } catch (Exception ex) {
            LOG.error(" Exception while fetching the value of " + columnName + " because " + ex.getMessage());
            partialRow.setNull(columnName);
        }
    }
    try {
        kuduSession.apply(currentOperation);
    } catch (KuduException e) {
        throw new RuntimeException("Could not execute operation because " + e.getMessage(), e);
    }
}

18 View Complete Implementation : KuduColumnInfo.java
Copyright Apache License 2.0
Author : apache
@PublicEvolving
public clreplaced KuduColumnInfo implements Serializable {

    private String name;

    private Type type;

    private boolean key;

    private boolean rangeKey;

    private boolean hashKey;

    private boolean nullable;

    private Object defaultValue;

    private int blockSize;

    private Encoding encoding;

    private Compression compression;

    private KuduColumnInfo(String name, Type type) {
        this.name = name;
        this.type = type;
        this.blockSize = 0;
        this.key = false;
        this.rangeKey = false;
        this.hashKey = false;
        this.nullable = false;
        this.defaultValue = null;
        this.encoding = Encoding.AUTO;
        this.compression = Compression.DEFAULT;
    }

    protected String name() {
        return name;
    }

    protected boolean isRangeKey() {
        return rangeKey;
    }

    protected boolean isHashKey() {
        return hashKey;
    }

    protected ColumnSchema columnSchema() {
        return new ColumnSchema.ColumnSchemaBuilder(name, type).key(key).nullable(nullable).defaultValue(defaultValue).desiredBlockSize(blockSize).encoding(encoding.encode).compressionAlgorithm(compression.algorithm).build();
    }

    public static clreplaced Builder {

        private KuduColumnInfo column;

        private Builder(String name, Type type) {
            this.column = new KuduColumnInfo(name, type);
        }

        public static Builder create(String name, Type type) {
            return new Builder(name, type);
        }

        public static Builder createByte(String name) {
            return create(name, Type.INT8);
        }

        public static Builder createShort(String name) {
            return create(name, Type.INT16);
        }

        public static Builder createInteger(String name) {
            return create(name, Type.INT32);
        }

        public static Builder createLong(String name) {
            return create(name, Type.INT64);
        }

        public static Builder createDouble(String name) {
            return create(name, Type.DOUBLE);
        }

        public static Builder createFloat(String name) {
            return create(name, Type.FLOAT);
        }

        public static Builder createString(String name) {
            return create(name, Type.STRING);
        }

        public static Builder createBool(String name) {
            return create(name, Type.BOOL);
        }

        public static Builder createByteArray(String name) {
            return create(name, Type.BINARY);
        }

        public static Builder createUnixTime(String name) {
            return create(name, Type.UNIXTIME_MICROS);
        }

        public Builder asKey() {
            return key(true);
        }

        public Builder key(boolean key) {
            this.column.key = key;
            return this;
        }

        public Builder asRangeKey() {
            return rangeKey(true);
        }

        public Builder rangeKey(boolean rangeKey) {
            this.column.rangeKey = rangeKey;
            return this;
        }

        public Builder asHashKey() {
            return hashKey(true);
        }

        public Builder hashKey(boolean hashKey) {
            this.column.hashKey = hashKey;
            return this;
        }

        public Builder asNullable() {
            return nullable(true);
        }

        public Builder asNotNullable() {
            return nullable(false);
        }

        public Builder nullable(boolean nullable) {
            this.column.nullable = nullable;
            return this;
        }

        public Builder defaultValue(Object defaultValue) {
            this.column.defaultValue = defaultValue;
            return this;
        }

        public Builder desiredBlockSize(int blockSize) {
            this.column.blockSize = blockSize;
            return this;
        }

        public Builder encoding(Encoding encoding) {
            this.column.encoding = encoding;
            return this;
        }

        public Builder compressionAlgorithm(Compression compression) {
            this.column.compression = compression;
            return this;
        }

        public KuduColumnInfo build() {
            return column;
        }
    }

    public enum Compression {

        UNKNOWN(ColumnSchema.CompressionAlgorithm.UNKNOWN),
        DEFAULT(ColumnSchema.CompressionAlgorithm.DEFAULT_COMPRESSION),
        WITHOUT(ColumnSchema.CompressionAlgorithm.NO_COMPRESSION),
        SNAPPY(ColumnSchema.CompressionAlgorithm.SNAPPY),
        LZ4(ColumnSchema.CompressionAlgorithm.LZ4),
        ZLIB(ColumnSchema.CompressionAlgorithm.ZLIB);

        final ColumnSchema.CompressionAlgorithm algorithm;

        Compression(ColumnSchema.CompressionAlgorithm algorithm) {
            this.algorithm = algorithm;
        }
    }

    public enum Encoding {

        UNKNOWN(ColumnSchema.Encoding.UNKNOWN),
        AUTO(ColumnSchema.Encoding.AUTO_ENCODING),
        PLAIN(ColumnSchema.Encoding.PLAIN_ENCODING),
        PREFIX(ColumnSchema.Encoding.PREFIX_ENCODING),
        GROUP_VARINT(ColumnSchema.Encoding.GROUP_VARINT),
        RLE(ColumnSchema.Encoding.RLE),
        DICT(ColumnSchema.Encoding.DICT_ENCODING),
        BIT_SHUFFLE(ColumnSchema.Encoding.BIT_SHUFFLE);

        final ColumnSchema.Encoding encode;

        Encoding(ColumnSchema.Encoding encode) {
            this.encode = encode;
        }
    }
}

18 View Complete Implementation : KuduWriter.java
Copyright Apache License 2.0
Author : apache
private Operation mapToOperation(KuduRow row) {
    final Operation operation = obtainOperation();
    final PartialRow partialRow = operation.getRow();
    table.getSchema().getColumns().forEach(column -> {
        String columnName = column.getName();
        if (!row.hasField(columnName)) {
            return;
        }
        Object value = row.getField(columnName);
        if (value == null) {
            partialRow.setNull(columnName);
        } else {
            Type type = column.getType();
            switch(type) {
                case STRING:
                    partialRow.addString(columnName, (String) value);
                    break;
                case FLOAT:
                    partialRow.addFloat(columnName, (Float) value);
                    break;
                case INT8:
                    partialRow.addByte(columnName, (Byte) value);
                    break;
                case INT16:
                    partialRow.addShort(columnName, (Short) value);
                    break;
                case INT32:
                    partialRow.addInt(columnName, (Integer) value);
                    break;
                case INT64:
                    partialRow.addLong(columnName, (Long) value);
                    break;
                case DOUBLE:
                    partialRow.addDouble(columnName, (Double) value);
                    break;
                case BOOL:
                    partialRow.addBoolean(columnName, (Boolean) value);
                    break;
                case UNIXTIME_MICROS:
                    // *1000 to correctly create date on kudu
                    partialRow.addLong(columnName, ((Long) value) * 1000);
                    break;
                case BINARY:
                    partialRow.addBinary(columnName, (byte[]) value);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal var type: " + type);
            }
        }
    });
    return operation;
}

18 View Complete Implementation : KuduClientUtils.java
Copyright Apache License 2.0
Author : apache
public static Object getObjectRow(RowResult row, Column column) {
    Type type = column.getDataType().getType();
    Object res;
    switch(type) {
        case INT8:
            res = row.getByte(column.getName());
            break;
        case INT16:
            res = row.getShort(column.getName());
            break;
        case INT32:
            res = row.getInt(column.getName());
            break;
        case INT64:
            res = row.getLong(column.getName());
            break;
        case BINARY:
            res = row.getBinaryCopy(column.getName());
            break;
        case STRING:
            res = row.getString(column.getName());
            break;
        case BOOL:
            res = row.getBoolean(column.getName());
            break;
        case FLOAT:
            res = row.getFloat(column.getName());
            break;
        case DOUBLE:
            res = row.getDouble(column.getName());
            break;
        case UNIXTIME_MICROS:
            res = row.getTimestamp(column.getName());
            break;
        case DECIMAL:
            res = row.getDecimal(column.getName());
            break;
        default:
            throw new replacedertionError(type.name());
    }
    return res;
}

18 View Complete Implementation : KuduClientUtils.java
Copyright Apache License 2.0
Author : apache
public static void addObjectRow(PartialRow row, Column column, Object key) {
    Type type = column.getDataType().getType();
    switch(type) {
        case INT8:
            row.addByte(column.getName(), (byte) key);
            break;
        case INT16:
            row.addShort(column.getName(), (short) key);
            break;
        case INT32:
            row.addInt(column.getName(), (int) key);
            break;
        case INT64:
            row.addLong(column.getName(), (long) key);
            break;
        case BINARY:
            row.addBinary(column.getName(), (byte[]) key);
            break;
        case STRING:
            row.addString(column.getName(), (String) key);
            break;
        case BOOL:
            row.addBoolean(column.getName(), (boolean) key);
            break;
        case FLOAT:
            row.addFloat(column.getName(), (float) key);
            break;
        case DOUBLE:
            row.addDouble(column.getName(), (double) key);
            break;
        case UNIXTIME_MICROS:
            if (key instanceof Timestamp) {
                row.addTimestamp(column.getName(), (Timestamp) key);
            } else if (key instanceof Long) {
                row.addTimestamp(column.getName(), new Timestamp((Long) key));
            }
            break;
        case DECIMAL:
            row.addDecimal(column.getName(), (BigDecimal) key);
            break;
        default:
            throw new replacedertionError(type.name());
    }
}

18 View Complete Implementation : AbstractKuduProcessor.java
Copyright Apache License 2.0
Author : apache
@VisibleForTesting
protected void buildPartialRow(Schema schema, PartialRow row, Record record, List<String> fieldNames, Boolean ignoreNull, Boolean lowercaseFields) {
    for (String recordFieldName : fieldNames) {
        String colName = recordFieldName;
        if (lowercaseFields) {
            colName = colName.toLowerCase();
        }
        int colIdx = this.getColumnIndex(schema, colName);
        if (colIdx != -1) {
            ColumnSchema colSchema = schema.getColumnByIndex(colIdx);
            Type colType = colSchema.getType();
            if (record.getValue(recordFieldName) == null) {
                if (schema.getColumnByIndex(colIdx).isKey()) {
                    throw new IllegalArgumentException(String.format("Can't set primary key column %s to null ", colName));
                } else if (!schema.getColumnByIndex(colIdx).isNullable()) {
                    throw new IllegalArgumentException(String.format("Can't set primary key column %s to null ", colName));
                }
                if (!ignoreNull) {
                    row.setNull(colName);
                    continue;
                }
            } else {
                switch(colType.getDataType(colSchema.getTypeAttributes())) {
                    case BOOL:
                        row.addBoolean(colIdx, record.getAsBoolean(recordFieldName));
                        break;
                    case FLOAT:
                        row.addFloat(colIdx, record.getAsFloat(recordFieldName));
                        break;
                    case DOUBLE:
                        row.addDouble(colIdx, record.getAsDouble(recordFieldName));
                        break;
                    case BINARY:
                        row.addBinary(colIdx, record.getreplacedtring(recordFieldName).getBytes());
                        break;
                    case INT8:
                        row.addByte(colIdx, record.getAsInt(recordFieldName).byteValue());
                        break;
                    case INT16:
                        row.addShort(colIdx, record.getAsInt(recordFieldName).shortValue());
                        break;
                    case INT32:
                        row.addInt(colIdx, record.getAsInt(recordFieldName));
                        break;
                    case INT64:
                    case UNIXTIME_MICROS:
                        row.addLong(colIdx, record.getAsLong(recordFieldName));
                        break;
                    case STRING:
                        row.addString(colIdx, record.getreplacedtring(recordFieldName));
                        break;
                    case DECIMAL32:
                    case DECIMAL64:
                    case DECIMAL128:
                        row.addDecimal(colIdx, new BigDecimal(record.getreplacedtring(recordFieldName)));
                        break;
                    default:
                        throw new IllegalStateException(String.format("unknown column type %s", colType));
                }
            }
        }
    }
}

18 View Complete Implementation : KuduAllReqRow.java
Copyright Apache License 2.0
Author : DTStack
private void primaryKeyRange(PartialRow partialRow, Type type, String primaryKey, String value) {
    switch(type) {
        case STRING:
            partialRow.addString(primaryKey, value);
            break;
        case FLOAT:
            partialRow.addFloat(primaryKey, Float.valueOf(value));
            break;
        case INT8:
            partialRow.addByte(primaryKey, Byte.valueOf(value));
            break;
        case INT16:
            partialRow.addShort(primaryKey, Short.valueOf(value));
            break;
        case INT32:
            partialRow.addInt(primaryKey, Integer.valueOf(value));
            break;
        case INT64:
            partialRow.addLong(primaryKey, Long.valueOf(value));
            break;
        case DOUBLE:
            partialRow.addDouble(primaryKey, Double.valueOf(value));
            break;
        case BOOL:
            partialRow.addBoolean(primaryKey, Boolean.valueOf(value));
            break;
        case UNIXTIME_MICROS:
            partialRow.addTimestamp(primaryKey, Timestamp.valueOf(value));
            break;
        case BINARY:
            partialRow.addBinary(primaryKey, value.getBytes());
            break;
        default:
            throw new IllegalArgumentException("Illegal var type: " + type);
    }
}

18 View Complete Implementation : KuduSink.java
Copyright Apache License 2.0
Author : harbby
private void appendColumn(Operation operation, String name, Object value) {
    ColumnSchema columnSchema = kuduTable.getSchema().getColumn(name);
    if (value == null) {
        operation.getRow().setNull(name);
        return;
    }
    Type kuduType = columnSchema.getType();
    switch(kuduType) {
        case BINARY:
            operation.getRow().addBinary(name, (byte[]) value);
            break;
        case STRING:
            operation.getRow().addString(name, String.valueOf(value));
            break;
        case BOOL:
            operation.getRow().addBoolean(name, (Boolean) value);
            break;
        case INT8:
        case INT16:
            operation.getRow().addShort(name, (Short) value);
            break;
        case INT32:
            operation.getRow().addInt(name, (Integer) value);
            break;
        case INT64:
            {
                if (value instanceof Date) {
                    operation.getRow().addLong(name, ((Date) value).getTime());
                } else if (value instanceof Time) {
                    operation.getRow().addLong(name, ((Time) value).getTime());
                } else if (value instanceof Timestamp) {
                    operation.getRow().addLong(name, ((Timestamp) value).getTime());
                } else {
                    operation.getRow().addLong(name, (Long) value);
                }
                break;
            }
        case DOUBLE:
            operation.getRow().addDouble(name, (Double) value);
            break;
        case FLOAT:
            operation.getRow().addFloat(name, (Float) value);
            break;
        case DECIMAL:
            operation.getRow().addDecimal(name, (BigDecimal) value);
            break;
        default:
            throw new IllegalStateException("不受支持的kudu类型:" + kuduType);
    }
}

18 View Complete Implementation : KuduClientSession.java
Copyright Apache License 2.0
Author : prestosql
public void addColumn(SchemaTableName schemaTableName, ColumnMetadata column) {
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        AlterTableOptions alterOptions = new AlterTableOptions();
        Type type = TypeHelper.toKuduClientType(column.getType());
        alterOptions.addNullableColumn(column.getName(), type);
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}

18 View Complete Implementation : AbstractKuduTest.java
Copyright Apache License 2.0
Author : syndesisio
protected void createTestTable(final String tableName, final String connection) throws KuduException {
    try (KuduClient client = new KuduClient.KuduClientBuilder(connection).build()) {
        final List<ColumnSchema> columns = new ArrayList<>(5);
        final List<String> columnNames = Arrays.asList("id", "replacedle", "name", "lastname", "address");
        for (int i = 0; i < columnNames.size(); i++) {
            final Type type = i == 0 ? Type.INT32 : Type.STRING;
            columns.add(new ColumnSchema.ColumnSchemaBuilder(columnNames.get(i), type).key(i == 0).build());
        }
        final List<String> rangeKeys = new ArrayList<>();
        rangeKeys.add("id");
        client.createTable(tableName, new Schema(columns), new CreateTableOptions().setRangeParreplacedionColumns(rangeKeys));
    }
}

17 View Complete Implementation : DrillKuduTable.java
Copyright Apache License 2.0
Author : apache
private RelDataType getSqlTypeFromKuduType(RelDataTypeFactory typeFactory, Type type) {
    switch(type) {
        case BOOL:
            return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
        case DOUBLE:
            return typeFactory.createSqlType(SqlTypeName.DOUBLE);
        case FLOAT:
            return typeFactory.createSqlType(SqlTypeName.FLOAT);
        case INT16:
        case INT32:
        case INT64:
        case INT8:
            return typeFactory.createSqlType(SqlTypeName.INTEGER);
        case STRING:
            return typeFactory.createSqlType(SqlTypeName.VARCHAR);
        case UNIXTIME_MICROS:
            return typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
        case BINARY:
            return typeFactory.createSqlType(SqlTypeName.VARBINARY, Integer.MAX_VALUE);
        default:
            throw new UnsupportedOperationException("Unsupported type.");
    }
}

17 View Complete Implementation : KuduInputFormat.java
Copyright Apache License 2.0
Author : DTStack
@Override
protected Row nextRecordInternal(Row row) throws IOException {
    row = new Row(columns.size());
    RowResult rowResult = iterator.next();
    for (int i = 0; i < columns.size(); i++) {
        MetaColumn column = columns.get(i);
        Type type = KuduUtil.getType(column.getType());
        if (column.getValue() != null) {
            row.setField(i, KuduUtil.getValue(column.getValue(), type));
        } else {
            row.setField(i, getValue(type, rowResult, column.getName()));
        }
    }
    LOG.info("nextRecordInternal, numReadCounter = {}", numReadCounter.getLocalValue());
    return row;
}

17 View Complete Implementation : DafPutKudu.java
Copyright GNU Affero General Public License v3.0
Author : italia
private void insert(KuduTable kuduTable, Operation operation, Record record, List<String> fieldNames) {
    PartialRow row = operation.getRow();
    Schema colSchema = kuduTable.getSchema();
    for (String colName : fieldNames) {
        int colIdx = this.getColumnIndex(colSchema, colName);
        if (colIdx != -1) {
            Type colType = colSchema.getColumnByIndex(colIdx).getType();
            switch(colType.getDataType()) {
                case BOOL:
                    row.addBoolean(colIdx, record.getAsBoolean(colName));
                    break;
                case FLOAT:
                    row.addFloat(colIdx, record.getAsFloat(colName));
                    break;
                case DOUBLE:
                    row.addDouble(colIdx, record.getAsDouble(colName));
                    break;
                case BINARY:
                    row.addBinary(colIdx, record.getreplacedtring(colName).getBytes());
                    break;
                case INT8:
                case INT16:
                    short temp = (short) record.getAsInt(colName).intValue();
                    row.addShort(colIdx, temp);
                case INT32:
                    row.addInt(colIdx, record.getAsInt(colName));
                    break;
                case INT64:
                    row.addLong(colIdx, record.getAsLong(colName));
                    break;
                case STRING:
                    row.addString(colIdx, record.getreplacedtring(colName));
                    break;
                default:
                    throw new IllegalStateException(String.format("unknown column type %s", colType));
            }
        }
    }
}

17 View Complete Implementation : NativeKuduClientSession.java
Copyright Apache License 2.0
Author : MartinWeindel
@Override
public void addColumn(SchemaTableName schemaTableName, ColumnMetadata column) {
    try {
        String rawName = toRawName(schemaTableName);
        AlterTableOptions alterOptions = new AlterTableOptions();
        Type type = TypeHelper.toKuduClientType(column.getType());
        alterOptions.addNullableColumn(column.getName(), type);
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}

17 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : MartinWeindel
private static Object toValue(Schema schema, PartialRow bound, Integer idx) {
    Type type = schema.getColumnByIndex(idx).getType();
    switch(type) {
        case UNIXTIME_MICROS:
            long millis = bound.getLong(idx) / 1000;
            return ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).print(millis);
        case STRING:
            return bound.getString(idx);
        case INT64:
            return bound.getLong(idx);
        case INT32:
            return bound.getInt(idx);
        case INT16:
            return bound.getShort(idx);
        case INT8:
            short s = bound.getByte(idx);
            return s;
        case BOOL:
            return bound.getBoolean(idx);
        case BINARY:
            return bound.getBinaryCopy(idx);
        default:
            throw new IllegalStateException("Unhandled type " + type + " for range parreplacedion");
    }
}

17 View Complete Implementation : KuduTableProperties.java
Copyright Apache License 2.0
Author : prestodb
private static Object toValue(Schema schema, PartialRow bound, Integer idx) {
    Type type = schema.getColumnByIndex(idx).getType();
    switch(type) {
        case UNIXTIME_MICROS:
            long millis = bound.getLong(idx) / 1000;
            return ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).print(millis);
        case STRING:
            return bound.getString(idx);
        case INT64:
            return bound.getLong(idx);
        case INT32:
            return bound.getInt(idx);
        case INT16:
            return bound.getShort(idx);
        case INT8:
            return (short) bound.getByte(idx);
        case BOOL:
            return bound.getBoolean(idx);
        case BINARY:
            return bound.getBinaryCopy(idx);
        default:
            throw new IllegalStateException("Unhandled type " + type + " for range parreplacedion");
    }
}

17 View Complete Implementation : KuduMapper.java
Copyright Apache License 2.0
Author : zhisheng17
static KuduRow toKuduRow(RowResult row) {
    Schema schema = row.getColumnProjection();
    KuduRow values = new KuduRow(schema.getColumnCount());
    schema.getColumns().forEach(column -> {
        String name = column.getName();
        int pos = schema.getColumnIndex(name);
        if (row.isNull(name)) {
            values.setField(pos, name, null);
        } else {
            Type type = column.getType();
            switch(type) {
                case BINARY:
                    values.setField(pos, name, row.getBinary(name));
                    break;
                case STRING:
                    values.setField(pos, name, row.getString(name));
                    break;
                case BOOL:
                    values.setField(pos, name, row.getBoolean(name));
                    break;
                case DOUBLE:
                    values.setField(pos, name, row.getDouble(name));
                    break;
                case FLOAT:
                    values.setField(pos, name, row.getFloat(name));
                    break;
                case INT8:
                    values.setField(pos, name, row.getByte(name));
                    break;
                case INT16:
                    values.setField(pos, name, row.getShort(name));
                    break;
                case INT32:
                    values.setField(pos, name, row.getInt(name));
                    break;
                case INT64:
                    values.setField(pos, name, row.getLong(name));
                    break;
                case UNIXTIME_MICROS:
                    values.setField(pos, name, row.getLong(name) / 1000);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal var type: " + type);
            }
        }
    });
    return values;
}

16 View Complete Implementation : KuduRecordReader.java
Copyright Apache License 2.0
Author : apache
private void initCols(Schema schema) throws SchemaChangeException {
    ImmutableList.Builder<ProjectedColumnInfo> pciBuilder = ImmutableList.builder();
    for (int i = 0; i < schema.getColumnCount(); i++) {
        ColumnSchema col = schema.getColumnByIndex(i);
        final String name = col.getName();
        final Type kuduType = col.getType();
        lastColumnName = name;
        lastColumnType = kuduType;
        MinorType minorType = TYPES.get(kuduType);
        if (minorType == null) {
            logger.warn("Ignoring column that is unsupported.", UserException.unsupportedError().message("A column you queried has a data type that is not currently supported by the Kudu storage plugin. " + "The column's name was %s and its Kudu data type was %s. ", name, kuduType.toString()).addContext("column Name", name).addContext("plugin", "kudu").build(logger));
            continue;
        }
        MajorType majorType;
        if (col.isNullable()) {
            majorType = Types.optional(minorType);
        } else {
            majorType = Types.required(minorType);
        }
        MaterializedField field = MaterializedField.create(name, majorType);
        final Clreplaced<? extends ValueVector> clazz = TypeHelper.getValueVectorClreplaced(minorType, majorType.getMode());
        ValueVector vector = output.addField(field, clazz);
        vector.allocateNew();
        ProjectedColumnInfo pci = new ProjectedColumnInfo();
        pci.vv = vector;
        pci.kuduColumn = col;
        pci.index = i;
        pciBuilder.add(pci);
    }
    projectedCols = pciBuilder.build();
}

16 View Complete Implementation : KuduUtil.java
Copyright Apache License 2.0
Author : DTStack
public static Object getValue(String value, Type type) {
    if (value == null) {
        return null;
    }
    if (value.startsWith("\"") || value.endsWith("'")) {
        value = value.substring(1, value.length() - 1);
    }
    Object objValue;
    if (Type.BOOL.equals(type)) {
        objValue = Boolean.valueOf(value);
    } else if (Type.INT8.equals(type)) {
        objValue = Byte.valueOf(value);
    } else if (Type.INT16.equals(type)) {
        objValue = Short.valueOf(value);
    } else if (Type.INT32.equals(type)) {
        objValue = Integer.valueOf(value);
    } else if (Type.INT64.equals(type)) {
        objValue = Long.valueOf(value);
    } else if (Type.FLOAT.equals(type)) {
        objValue = Float.valueOf(value);
    } else if (Type.DOUBLE.equals(type)) {
        objValue = Double.valueOf(value);
    } else if (Type.DECIMAL.equals(type)) {
        objValue = new BigDecimal(value);
    } else if (Type.UNIXTIME_MICROS.equals(type)) {
        if (NumberUtils.isNumber(value)) {
            objValue = Long.valueOf(value);
        } else {
            objValue = Timestamp.valueOf(value);
        }
    } else {
        objValue = value;
    }
    return objValue;
}

16 View Complete Implementation : KuduInputFormat.java
Copyright Apache License 2.0
Author : DTStack
private Object getValue(Type type, RowResult rowResult, String name) {
    Object objValue;
    if (Type.BOOL.equals(type)) {
        objValue = rowResult.getBoolean(name);
    } else if (Type.INT8.equals(type)) {
        objValue = rowResult.getByte(name);
    } else if (Type.INT16.equals(type)) {
        objValue = rowResult.getShort(name);
    } else if (Type.INT32.equals(type)) {
        objValue = rowResult.getInt(name);
    } else if (Type.INT64.equals(type)) {
        objValue = rowResult.getLong(name);
    } else if (Type.FLOAT.equals(type)) {
        objValue = rowResult.getFloat(name);
    } else if (Type.DOUBLE.equals(type)) {
        objValue = rowResult.getDouble(name);
    } else if (Type.DECIMAL.equals(type)) {
        objValue = rowResult.getDecimal(name);
    } else if (Type.BINARY.equals(type)) {
        objValue = rowResult.getBinary(name);
    } else if (Type.UNIXTIME_MICROS.equals(type)) {
        objValue = rowResult.getTimestamp(name);
    } else {
        objValue = rowResult.getString(name);
    }
    return objValue;
}

16 View Complete Implementation : KuduClientSession.java
Copyright Apache License 2.0
Author : prestosql
private ColumnSchema toColumnSchema(ColumnMetadata columnMetadata) {
    String name = columnMetadata.getName();
    ColumnDesign design = KuduTableProperties.getColumnDesign(columnMetadata.getProperties());
    Type ktype = TypeHelper.toKuduClientType(columnMetadata.getType());
    ColumnSchema.ColumnSchemaBuilder builder = new ColumnSchema.ColumnSchemaBuilder(name, ktype);
    builder.key(design.isPrimaryKey()).nullable(design.isNullable());
    setEncoding(name, builder, design);
    setCompression(name, builder, design);
    setTypeAttributes(columnMetadata, builder);
    return builder.build();
}

15 View Complete Implementation : KuduReaderIterator.java
Copyright Apache License 2.0
Author : apache
private KuduRow toKuduRow(RowResult row) {
    Schema schema = row.getColumnProjection();
    KuduRow values = new KuduRow(schema.getColumnCount());
    schema.getColumns().forEach(column -> {
        String name = column.getName();
        int pos = schema.getColumnIndex(name);
        if (row.isNull(name)) {
            values.setField(pos, name, null);
        } else {
            Type type = column.getType();
            switch(type) {
                case BINARY:
                    values.setField(pos, name, row.getBinary(name));
                    break;
                case STRING:
                    values.setField(pos, name, row.getString(name));
                    break;
                case BOOL:
                    values.setField(pos, name, row.getBoolean(name));
                    break;
                case DOUBLE:
                    values.setField(pos, name, row.getDouble(name));
                    break;
                case FLOAT:
                    values.setField(pos, name, row.getFloat(name));
                    break;
                case INT8:
                    values.setField(pos, name, row.getByte(name));
                    break;
                case INT16:
                    values.setField(pos, name, row.getShort(name));
                    break;
                case INT32:
                    values.setField(pos, name, row.getInt(name));
                    break;
                case INT64:
                    values.setField(pos, name, row.getLong(name));
                    break;
                case UNIXTIME_MICROS:
                    values.setField(pos, name, row.getLong(name) / 1000);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal var type: " + type);
            }
        }
    });
    return values;
}

15 View Complete Implementation : KuduRecordReader.java
Copyright Apache License 2.0
Author : apache
public clreplaced KuduRecordReader extends AbstractRecordReader {

    private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(KuduRecordReader.clreplaced);

    private static final int TARGET_RECORD_COUNT = 4000;

    private final KuduClient client;

    private final KuduSubScanSpec scanSpec;

    private KuduScanner scanner;

    private RowResulreplacederator iterator;

    private OutputMutator output;

    private OperatorContext context;

    private String lastColumnName;

    private Type lastColumnType;

    private static clreplaced ProjectedColumnInfo {

        int index;

        ValueVector vv;

        ColumnSchema kuduColumn;
    }

    private ImmutableList<ProjectedColumnInfo> projectedCols;

    public KuduRecordReader(KuduClient client, KuduSubScan.KuduSubScanSpec subScanSpec, List<SchemaPath> projectedColumns) {
        setColumns(projectedColumns);
        this.client = client;
        scanSpec = subScanSpec;
        logger.debug("Scan spec: {}", subScanSpec);
    }

    @Override
    public void setup(OperatorContext context, OutputMutator output) throws ExecutionSetupException {
        this.output = output;
        this.context = context;
        try {
            KuduTable table = client.openTable(scanSpec.getTableName());
            KuduScannerBuilder builder = client.newScannerBuilder(table);
            if (!isStarQuery()) {
                List<String> colNames = Lists.newArrayList();
                for (SchemaPath p : this.getColumns()) {
                    colNames.add(p.getRootSegmentPath());
                }
                builder.setProjectedColumnNames(colNames);
            }
            context.getStats().startWait();
            try {
                scanner = builder.lowerBoundRaw(scanSpec.getStartKey()).exclusiveUpperBoundRaw(scanSpec.getEndKey()).build();
            } finally {
                context.getStats().stopWait();
            }
        } catch (Exception e) {
            throw new ExecutionSetupException(e);
        }
    }

    static final Map<Type, MinorType> TYPES;

    static {
        TYPES = ImmutableMap.<Type, MinorType>builder().put(Type.BINARY, MinorType.VARBINARY).put(Type.BOOL, MinorType.BIT).put(Type.DOUBLE, MinorType.FLOAT8).put(Type.FLOAT, MinorType.FLOAT4).put(Type.INT8, MinorType.INT).put(Type.INT16, MinorType.INT).put(Type.INT32, MinorType.INT).put(Type.INT64, MinorType.BIGINT).put(Type.STRING, MinorType.VARCHAR).put(Type.UNIXTIME_MICROS, MinorType.TIMESTAMP).build();
    }

    @Override
    public int next() {
        int rowCount = 0;
        try {
            while (iterator == null || !iterator.hasNext()) {
                if (!scanner.hasMoreRows()) {
                    iterator = null;
                    return 0;
                }
                context.getStats().startWait();
                try {
                    iterator = scanner.nextRows();
                } finally {
                    context.getStats().stopWait();
                }
            }
            for (; rowCount < TARGET_RECORD_COUNT && iterator.hasNext(); rowCount++) {
                addRowResult(iterator.next(), rowCount);
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        for (ProjectedColumnInfo pci : projectedCols) {
            pci.vv.getMutator().setValueCount(rowCount);
        }
        return rowCount;
    }

    private void initCols(Schema schema) throws SchemaChangeException {
        ImmutableList.Builder<ProjectedColumnInfo> pciBuilder = ImmutableList.builder();
        for (int i = 0; i < schema.getColumnCount(); i++) {
            ColumnSchema col = schema.getColumnByIndex(i);
            final String name = col.getName();
            final Type kuduType = col.getType();
            lastColumnName = name;
            lastColumnType = kuduType;
            MinorType minorType = TYPES.get(kuduType);
            if (minorType == null) {
                logger.warn("Ignoring column that is unsupported.", UserException.unsupportedError().message("A column you queried has a data type that is not currently supported by the Kudu storage plugin. " + "The column's name was %s and its Kudu data type was %s. ", name, kuduType.toString()).addContext("column Name", name).addContext("plugin", "kudu").build(logger));
                continue;
            }
            MajorType majorType;
            if (col.isNullable()) {
                majorType = Types.optional(minorType);
            } else {
                majorType = Types.required(minorType);
            }
            MaterializedField field = MaterializedField.create(name, majorType);
            final Clreplaced<? extends ValueVector> clazz = TypeHelper.getValueVectorClreplaced(minorType, majorType.getMode());
            ValueVector vector = output.addField(field, clazz);
            vector.allocateNew();
            ProjectedColumnInfo pci = new ProjectedColumnInfo();
            pci.vv = vector;
            pci.kuduColumn = col;
            pci.index = i;
            pciBuilder.add(pci);
        }
        projectedCols = pciBuilder.build();
    }

    private void addRowResult(RowResult result, int rowIndex) throws SchemaChangeException {
        if (projectedCols == null) {
            initCols(result.getColumnProjection());
        }
        for (ProjectedColumnInfo pci : projectedCols) {
            if (result.isNull(pci.index)) {
                continue;
            }
            switch(pci.kuduColumn.getType()) {
                case BINARY:
                    {
                        ByteBuffer value = result.getBinary(pci.index);
                        if (pci.kuduColumn.isNullable()) {
                            ((NullableVarBinaryVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, value, 0, value.remaining());
                        } else {
                            ((VarBinaryVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, value, 0, value.remaining());
                        }
                        break;
                    }
                case STRING:
                    {
                        ByteBuffer value = ByteBuffer.wrap(result.getString(pci.index).getBytes());
                        if (pci.kuduColumn.isNullable()) {
                            ((NullableVarCharVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, value, 0, value.remaining());
                        } else {
                            ((VarCharVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, value, 0, value.remaining());
                        }
                        break;
                    }
                case BOOL:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableBitVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getBoolean(pci.index) ? 1 : 0);
                    } else {
                        ((BitVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getBoolean(pci.index) ? 1 : 0);
                    }
                    break;
                case DOUBLE:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableFloat8Vector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getDouble(pci.index));
                    } else {
                        ((Float8Vector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getDouble(pci.index));
                    }
                    break;
                case FLOAT:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableFloat4Vector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getFloat(pci.index));
                    } else {
                        ((Float4Vector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getFloat(pci.index));
                    }
                    break;
                case INT16:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableIntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getShort(pci.index));
                    } else {
                        ((IntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getShort(pci.index));
                    }
                    break;
                case INT32:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableIntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getInt(pci.index));
                    } else {
                        ((IntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getInt(pci.index));
                    }
                    break;
                case INT8:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableIntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getByte(pci.index));
                    } else {
                        ((IntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getByte(pci.index));
                    }
                    break;
                case INT64:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableBigIntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getLong(pci.index));
                    } else {
                        ((BigIntVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getLong(pci.index));
                    }
                    break;
                case UNIXTIME_MICROS:
                    if (pci.kuduColumn.isNullable()) {
                        ((NullableTimeStampVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getLong(pci.index) / 1000);
                    } else {
                        ((TimeStampVector.Mutator) pci.vv.getMutator()).setSafe(rowIndex, result.getLong(pci.index) / 1000);
                    }
                    break;
                default:
                    // TODO make better
                    throw new SchemaChangeException("unknown type");
            }
        }
    }

    @Override
    public void close() {
    }

    @Override
    public String toString() {
        return "KuduRecordReader[Column=" + lastColumnName + ", Type=" + lastColumnType + "]";
    }
}

15 View Complete Implementation : KuduMappingBuilder.java
Copyright Apache License 2.0
Author : apache
/**
 * Reads Kudu mappings from file
 *
 * @param inputStream Mapping input stream
 * @throws org.apache.gora.util.GoraException Error reading mapping file
 */
public void readMappingFile(InputStream inputStream) throws GoraException {
    try {
        SAXBuilder saxBuilder = new SAXBuilder();
        if (inputStream == null) {
            LOG.error("The mapping input stream is null!");
            throw new GoraException("The mapping input stream is null!");
        }
        Doreplacedent doreplacedent = saxBuilder.build(inputStream);
        if (doreplacedent == null) {
            LOG.error("The mapping doreplacedent is null!");
            throw new GoraException("The mapping doreplacedent is null!");
        }
        @SuppressWarnings("unchecked")
        List<Element> clreplacedes = doreplacedent.getRootElement().getChildren("clreplaced");
        boolean keyClreplacedMatches = false;
        for (Element clreplacedElement : clreplacedes) {
            if (clreplacedElement.getAttributeValue("keyClreplaced").equals(dataStore.getKeyClreplaced().getCanonicalName()) && clreplacedElement.getAttributeValue("name").equals(dataStore.getPersistentClreplaced().getCanonicalName())) {
                keyClreplacedMatches = true;
                LOG.debug("Keyclreplaced and nameclreplaced match.");
                final String tableNameFromMapping = clreplacedElement.getAttributeValue("table");
                final String tablenumReplicasMapping = clreplacedElement.getAttributeValue("numReplicas");
                String tableName = dataStore.getSchemaName(tableNameFromMapping, dataStore.getPersistentClreplaced());
                kuduMapping.setTableName(tableName);
                kuduMapping.setNumReplicas(Integer.parseInt(tablenumReplicasMapping));
                @SuppressWarnings("unchecked")
                List<Element> tables = doreplacedent.getRootElement().getChildren("table");
                for (Element tableElement : tables) {
                    if (tableElement.getAttributeValue("name").equals(tableNameFromMapping)) {
                        @SuppressWarnings("unchecked")
                        List<Element> pkColumns = tableElement.getChildren("primaryKey");
                        List<Column> pkFields = new ArrayList<>();
                        for (Element aPrimaryKey : pkColumns) {
                            String columnName = aPrimaryKey.getAttributeValue("column");
                            String columnType = aPrimaryKey.getAttributeValue("type");
                            Type aDataType = Type.valueOf(columnType);
                            if (aDataType == Type.DECIMAL) {
                                int precision = Integer.parseInt(aPrimaryKey.getAttributeValue("precision"));
                                int scale = Integer.parseInt(aPrimaryKey.getAttributeValue("scale"));
                                pkFields.add(new Column(columnName, new Column.FieldType(precision, scale)));
                            } else {
                                pkFields.add(new Column(columnName, new Column.FieldType(aDataType)));
                            }
                        }
                        kuduMapping.setPrimaryKey(pkFields);
                        Element hashParreplacedion = tableElement.getChild("hashParreplacedion");
                        if (hashParreplacedion != null) {
                            int numBuckets = Integer.parseInt(hashParreplacedion.getAttributeValue("numBuckets"));
                            kuduMapping.setHashBuckets(numBuckets);
                        }
                        List<Map.Entry<String, String>> ranges = new ArrayList<>();
                        @SuppressWarnings("unchecked")
                        List<Element> rangeParreplacedions = tableElement.getChildren("rangeParreplacedion");
                        for (Element rangeParreplacedion : rangeParreplacedions) {
                            String lower = rangeParreplacedion.getAttributeValue("lower");
                            String upper = rangeParreplacedion.getAttributeValue("upper");
                            ranges.add(new AbstractMap.SimpleEntry<>(lower, upper));
                        }
                        kuduMapping.setRangeParreplacedions(ranges);
                    }
                }
                @SuppressWarnings("unchecked")
                List<Element> fields = clreplacedElement.getChildren("field");
                Map<String, Column> fieldsMappings = new HashMap<>();
                for (Element field : fields) {
                    String fieldName = field.getAttributeValue("name");
                    String columnName = field.getAttributeValue("column");
                    String columnType = field.getAttributeValue("type");
                    Type aDataType = Type.valueOf(columnType);
                    if (aDataType == Type.DECIMAL) {
                        int precision = Integer.parseInt(field.getAttributeValue("precision"));
                        int scale = Integer.parseInt(field.getAttributeValue("scale"));
                        fieldsMappings.put(fieldName, new Column(columnName, new Column.FieldType(precision, scale)));
                    } else {
                        fieldsMappings.put(fieldName, new Column(columnName, new Column.FieldType(aDataType)));
                    }
                }
                kuduMapping.setFields(fieldsMappings);
                break;
            }
        }
        if (!keyClreplacedMatches) {
            throw new GoraException("gora-kudu-mapping does not include the name and keyClreplaced in the databean.");
        }
    } catch (IOException | JDOMException e) {
        throw new GoraException(e);
    }
    LOG.info("Gora Kudu mapping file was read successfully.");
}

15 View Complete Implementation : NativeKuduClientSession.java
Copyright Apache License 2.0
Author : MartinWeindel
private ColumnSchema toColumnSchema(ColumnMetadata columnMetadata, Map<String, ColumnDesign> columnDesignMap) {
    String name = columnMetadata.getName();
    ColumnDesign design = columnDesignMap.getOrDefault(name, ColumnDesign.DEFAULT);
    Type ktype = TypeHelper.toKuduClientType(columnMetadata.getType());
    ColumnSchema.ColumnSchemaBuilder builder = new ColumnSchema.ColumnSchemaBuilder(name, ktype);
    builder.key(design.isKey()).nullable(design.isNullable());
    setEncoding(name, builder, design);
    setCompression(name, builder, design);
    setTypeAttributes(columnMetadata, builder);
    return builder.build();
}

14 View Complete Implementation : KuduScanCustomizer.java
Copyright Apache License 2.0
Author : syndesisio
private static void processBody(Exchange exchange) throws KuduException, JsonProcessingException {
    final Message in = exchange.getIn();
    final KuduScanner scanner = in.getBody(KuduScanner.clreplaced);
    final List<String> answer = new ArrayList<>();
    while (scanner.hasMoreRows()) {
        RowResulreplacederator results = scanner.nextRows();
        while (results.hasNext()) {
            Map<String, Object> row = new HashMap<String, Object>();
            RowResult result = results.next();
            for (int i = 0; i < result.getSchema().getColumnCount(); i++) {
                String key = result.getSchema().getColumnByIndex(i).getName();
                Type type = result.getColumnType(i);
                switch(type.getName()) {
                    case "string":
                        row.put(key, result.getString(i));
                        break;
                    case "bool":
                        row.put(key, result.getBoolean(i));
                        break;
                    case "int8":
                    case "int16":
                    case "int32":
                        row.put(key, result.getInt(i));
                        break;
                    case "int64":
                        row.put(key, result.getLong(i));
                        break;
                    case "double":
                        row.put(key, result.getDouble(i));
                        break;
                    case "float":
                        row.put(key, result.getFloat(i));
                        break;
                    default:
                        throw new SyndesisServerException("The column schema type " + type.getName() + " for column " + key + " is not supported at the moment");
                }
            }
            answer.add(KuduSupport.toJSONBean(row));
        }
    }
    in.setBody(answer);
}

13 View Complete Implementation : KuduRowUtils.java
Copyright Apache License 2.0
Author : ucarGroup
public static void setValue(PartialRow partialRow, Object value, ColumnSchema columnSchema) throws Exception {
    Object writeValue;
    String columnName = columnSchema.getName();
    Type type = columnSchema.getType();
    if (type == Type.STRING) {
        writeValue = value == null ? "" : value;
        partialRow.addString(columnName, writeValue.toString());
        return;
    } else if (type == Type.BINARY) {
        writeValue = value == null ? "" : value;
        partialRow.addBinary(columnName, writeValue.toString().getBytes());
        return;
    }
    writeValue = (value == null || value.toString().trim().equals("") || value.toString().equalsIgnoreCase("null")) ? 0 : value;
    try {
        if (type == Type.INT16) {
            partialRow.addShort(columnName, Short.parseShort(writeValue.toString()));
            return;
        } else if (type == Type.INT8) {
            partialRow.addByte(columnName, Byte.parseByte(writeValue.toString()));
            return;
        } else if (type == Type.INT32) {
            partialRow.addInt(columnName, Integer.parseInt(writeValue.toString()));
            return;
        } else if (type == Type.INT64) {
            partialRow.addLong(columnName, Long.parseLong(writeValue.toString()));
            return;
        } else if (type == Type.BOOL) {
            partialRow.addBoolean(columnName, Boolean.parseBoolean(writeValue.toString()));
            return;
        } else if (type == Type.FLOAT) {
            partialRow.addFloat(columnName, Float.parseFloat(writeValue.toString()));
            return;
        } else if (type == Type.DOUBLE) {
            partialRow.addDouble(columnName, Double.parseDouble(writeValue.toString()));
            return;
        }
    } catch (NumberFormatException e) {
        String msg = String.format("column[%s] value[%s] convert type[%s]  errror!", columnName, value, type.toString());
        LOG.error(msg, e);
        throw new DatalinkException(msg, e);
    }
    if (type == Type.DECIMAL) {
        int scale = columnSchema.getTypeAttributes().getScale();
        BigDecimal formatValue = null;
        try {
            formatValue = new BigDecimal(String.valueOf(writeValue)).setScale(scale, BigDecimal.ROUND_HALF_UP);
            partialRow.addDecimal(columnName, formatValue);
            return;
        } catch (Exception e) {
            String msg = String.format("column[%s] value[%s] convert type[%s]  value[%s] errror!", columnName, writeValue, type.toString(), formatValue == null ? "" : formatValue.toString());
            LOG.error(msg, e);
            throw new DatalinkException(msg, e);
        }
    }
    throw new Exception(String.format("column[%s] type[%s] not support!", columnName, type.toString()));
}