Java Code Examples for org.apache.kudu.ColumnSchema#getType()
The following examples show how to use
org.apache.kudu.ColumnSchema#getType() .
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: KuduFilterInfo.java From flink-learning with Apache License 2.0 | 4 votes |
private KuduPredicate predicateComparator(ColumnSchema column) { KuduPredicate.ComparisonOp comparison = this.type.comparator; KuduPredicate predicate; switch (column.getType()) { case STRING: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (String)this.value); break; case FLOAT: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Float)this.value); break; case INT8: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Byte)this.value); break; case INT16: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Short)this.value); break; case INT32: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Integer)this.value); break; case INT64: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Long)this.value); break; case DOUBLE: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Double)this.value); break; case BOOL: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Boolean)this.value); break; case UNIXTIME_MICROS: Long time = (Long)this.value; predicate = KuduPredicate.newComparisonPredicate(column, comparison, time*1000); break; case BINARY: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (byte[])this.value); break; default: throw new IllegalArgumentException("Illegal var type: " + column.getType()); } return predicate; }
Example 2
Source File: KuduFilterInfo.java From flink-learning with Apache License 2.0 | 4 votes |
private KuduPredicate predicateComparator(ColumnSchema column) { KuduPredicate.ComparisonOp comparison = this.type.comparator; KuduPredicate predicate; switch (column.getType()) { case STRING: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (String)this.value); break; case FLOAT: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Float)this.value); break; case INT8: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Byte)this.value); break; case INT16: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Short)this.value); break; case INT32: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Integer)this.value); break; case INT64: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Long)this.value); break; case DOUBLE: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Double)this.value); break; case BOOL: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (Boolean)this.value); break; case UNIXTIME_MICROS: Long time = (Long)this.value; predicate = KuduPredicate.newComparisonPredicate(column, comparison, time*1000); break; case BINARY: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (byte[])this.value); break; default: throw new IllegalArgumentException("Illegal var type: " + column.getType()); } return predicate; }
Example 3
Source File: KuduSink.java From sylph with Apache License 2.0 | 4 votes |
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); } }
Example 4
Source File: KuduFilterInfo.java From bahir-flink with Apache License 2.0 | 4 votes |
private KuduPredicate predicateComparator(ColumnSchema column) { KuduPredicate.ComparisonOp comparison = this.type.comparator; KuduPredicate predicate; switch (column.getType()) { case STRING: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (String) this.value); break; case FLOAT: predicate = KuduPredicate.newComparisonPredicate(column, comparison, this.value); break; case INT8: predicate = KuduPredicate.newComparisonPredicate(column, comparison, this.value); break; case INT16: predicate = KuduPredicate.newComparisonPredicate(column, comparison, this.value); break; case INT32: predicate = KuduPredicate.newComparisonPredicate(column, comparison, this.value); break; case INT64: predicate = KuduPredicate.newComparisonPredicate(column, comparison, this.value); break; case DOUBLE: predicate = KuduPredicate.newComparisonPredicate(column, comparison, this.value); break; case BOOL: predicate = KuduPredicate.newComparisonPredicate(column, comparison, this.value); break; case UNIXTIME_MICROS: Long time = (Long) this.value; predicate = KuduPredicate.newComparisonPredicate(column, comparison, time * 1000); break; case BINARY: predicate = KuduPredicate.newComparisonPredicate(column, comparison, (byte[]) this.value); break; default: throw new IllegalArgumentException("Illegal var type: " + column.getType()); } return predicate; }
Example 5
Source File: KuduOutput.java From envelope with Apache License 2.0 | 4 votes |
private Row resultAsRow(RowResult result, KuduTable table) throws KuduException { List<Object> values = Lists.newArrayList(); for (ColumnSchema columnSchema : table.getSchema().getColumns()) { String columnName = columnSchema.getName(); if (result.isNull(columnName)) { values.add(null); continue; } switch (columnSchema.getType()) { case DOUBLE: values.add(result.getDouble(columnName)); break; case FLOAT: values.add(result.getFloat(columnName)); break; case INT8: values.add(result.getByte(columnName)); break; case INT16: values.add(result.getShort(columnName)); break; case INT32: values.add(result.getInt(columnName)); break; case INT64: values.add(result.getLong(columnName)); break; case STRING: values.add(result.getString(columnName)); break; case BOOL: values.add(result.getBoolean(columnName)); break; case BINARY: values.add(result.getBinaryCopy(columnName)); break; case UNIXTIME_MICROS: values.add(result.getTimestamp(columnName)); break; case DECIMAL: values.add(result.getDecimal(columnName)); break; default: throw new RuntimeException("Unsupported Kudu column type: " + columnSchema.getType()); } } Row row = new RowWithSchema(getTableSchema(table), values.toArray()); return row; }
Example 6
Source File: KuduOutput.java From envelope with Apache License 2.0 | 4 votes |
private StructType schemaFor(KuduTable table) { List<StructField> fields = Lists.newArrayList(); for (ColumnSchema columnSchema : table.getSchema().getColumns()) { DataType fieldType; switch (columnSchema.getType()) { case DOUBLE: fieldType = DataTypes.DoubleType; break; case FLOAT: fieldType = DataTypes.FloatType; break; case INT8: fieldType = DataTypes.ByteType; break; case INT16: fieldType = DataTypes.ShortType; break; case INT32: fieldType = DataTypes.IntegerType; break; case INT64: fieldType = DataTypes.LongType; break; case STRING: fieldType = DataTypes.StringType; break; case BOOL: fieldType = DataTypes.BooleanType; break; case BINARY: fieldType = DataTypes.BinaryType; break; case UNIXTIME_MICROS: fieldType = DataTypes.TimestampType; break; case DECIMAL: int precision = columnSchema.getTypeAttributes().getPrecision(); int scale = columnSchema.getTypeAttributes().getScale(); fieldType = DataTypes.createDecimalType(precision, scale); break; default: throw new RuntimeException("Unsupported Kudu column type: " + columnSchema.getType()); } fields.add(DataTypes.createStructField(columnSchema.getName(), fieldType, true)); } return DataTypes.createStructType(fields); }
Example 7
Source File: AbstractKuduOutputOperator.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
/*** * 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(); Class pojoClass = getTuplePayloadClass(); Object getter = null; switch ( columnType ) { case BINARY: getter = PojoUtils.createGetter(pojoClass, fieldDefinition.getName(), ByteBuffer.class); break; case STRING: getter = PojoUtils.createGetter(pojoClass, fieldDefinition.getName(), String.class); break; case BOOL: getter = PojoUtils.createGetterBoolean(pojoClass, fieldDefinition.getName()); break; case DOUBLE: getter = PojoUtils.createGetterDouble(pojoClass, fieldDefinition.getName()); break; case FLOAT: getter = PojoUtils.createGetterFloat(pojoClass, fieldDefinition.getName()); break; case INT8: getter = PojoUtils.createGetterByte(pojoClass, fieldDefinition.getName()); break; case INT16: getter = PojoUtils.createGetterShort(pojoClass, fieldDefinition.getName()); break; case INT32: getter = PojoUtils.createGetterInt(pojoClass, fieldDefinition.getName()); break; case INT64: case UNIXTIME_MICROS: getter = PojoUtils.createGetterLong(pojoClass, 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); } }
Example 8
Source File: KuduRecordConverter.java From datacollector with Apache License 2.0 | 4 votes |
private void recordToRow(Record record, PartialRow row, String fieldName, String column, int operation) throws OnRecordErrorException { Field.Type type = columnsToFieldTypes.get(column); ColumnSchema columnSchema = schema.getColumn(column); if (record.has(fieldName)) { Field field = record.get(fieldName); if (field.getValue() == null) { if (!columnSchema.isNullable()) { throw new OnRecordErrorException(record, Errors.KUDU_06, column, fieldName); } row.setNull(column); } else { try { switch (type) { case BOOLEAN: row.addBoolean(column, field.getValueAsBoolean()); break; case BYTE: row.addByte(column, field.getValueAsByte()); break; case SHORT: row.addShort(column, field.getValueAsShort()); break; case INTEGER: row.addInt(column, field.getValueAsInteger()); break; case LONG: if (columnSchema.getType() == Type.UNIXTIME_MICROS) { // Convert millisecond to microsecond row.addLong(column, field.getValueAsLong() * 1000); } else { row.addLong(column, field.getValueAsLong()); } break; case FLOAT: row.addFloat(column, field.getValueAsFloat()); break; case DOUBLE: row.addDouble(column, field.getValueAsDouble()); break; case STRING: row.addString(column, field.getValueAsString()); break; case BYTE_ARRAY: row.addBinary(column, field.getValueAsByteArray()); break; case DECIMAL: row.addDecimal(column, field.getValueAsDecimal()); break; default: throw new OnRecordErrorException(record, Errors.KUDU_04, fieldName, type.name()); } } catch (IllegalArgumentException e) { throw new OnRecordErrorException(record, Errors.KUDU_09, fieldName, type.name(), e.toString(), e); } } } else { // SDC-5816. do not null out columns in UPDATE or UPSERT mode. // if the columns are not specified - they should not be changed. if (operation == KuduOperationType.INSERT.code) { if (!columnSchema.isNullable()) { throw new OnRecordErrorException(record, Errors.KUDU_06, column, fieldName); } row.setNull(column); } } }
Example 9
Source File: KuduLookupService.java From nifi with Apache License 2.0 | 4 votes |
private RecordSchema kuduSchemaToNiFiSchema(Schema kuduTableSchema, List<String> columnNames){ final List<RecordField> fields = new ArrayList<>(); for(String columnName : columnNames) { if(!kuduTableSchema.hasColumn(columnName)){ throw new IllegalArgumentException("Column not found in Kudu table schema " + columnName); } ColumnSchema cs = kuduTableSchema.getColumn(columnName); switch (cs.getType()) { case INT8: fields.add(new RecordField(cs.getName(), RecordFieldType.BYTE.getDataType())); break; case INT16: fields.add(new RecordField(cs.getName(), RecordFieldType.SHORT.getDataType())); break; case INT32: fields.add(new RecordField(cs.getName(), RecordFieldType.INT.getDataType())); break; case INT64: fields.add(new RecordField(cs.getName(), RecordFieldType.LONG.getDataType())); break; case DECIMAL: final ColumnTypeAttributes attributes = cs.getTypeAttributes(); fields.add(new RecordField(cs.getName(), RecordFieldType.DECIMAL.getDecimalDataType(attributes.getPrecision(), attributes.getScale()))); break; case UNIXTIME_MICROS: fields.add(new RecordField(cs.getName(), RecordFieldType.TIMESTAMP.getDataType())); break; case BINARY: case STRING: case VARCHAR: fields.add(new RecordField(cs.getName(), RecordFieldType.STRING.getDataType())); break; case DOUBLE: fields.add(new RecordField(cs.getName(), RecordFieldType.DOUBLE.getDataType())); break; case BOOL: fields.add(new RecordField(cs.getName(), RecordFieldType.BOOLEAN.getDataType())); break; case FLOAT: fields.add(new RecordField(cs.getName(), RecordFieldType.FLOAT.getDataType())); break; } } return new SimpleRecordSchema(fields); }
Example 10
Source File: AbstractKuduProcessor.java From nifi with Apache License 2.0 | 4 votes |
@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 column %s to null ", colName)); } if (!ignoreNull) { row.setNull(colName); } } else { Object value = record.getValue(recordFieldName); switch (colType) { case BOOL: row.addBoolean(colIdx, DataTypeUtils.toBoolean(value, recordFieldName)); break; case INT8: row.addByte(colIdx, DataTypeUtils.toByte(value, recordFieldName)); break; case INT16: row.addShort(colIdx, DataTypeUtils.toShort(value, recordFieldName)); break; case INT32: row.addInt(colIdx, DataTypeUtils.toInteger(value, recordFieldName)); break; case INT64: row.addLong(colIdx, DataTypeUtils.toLong(value, recordFieldName)); break; case UNIXTIME_MICROS: DataType fieldType = record.getSchema().getDataType(recordFieldName).get(); Timestamp timestamp = DataTypeUtils.toTimestamp(record.getValue(recordFieldName), () -> DataTypeUtils.getDateFormat(fieldType.getFormat()), recordFieldName); row.addTimestamp(colIdx, timestamp); break; case STRING: row.addString(colIdx, DataTypeUtils.toString(value, recordFieldName)); break; case BINARY: row.addBinary(colIdx, DataTypeUtils.toString(value, recordFieldName).getBytes()); break; case FLOAT: row.addFloat(colIdx, DataTypeUtils.toFloat(value, recordFieldName)); break; case DOUBLE: row.addDouble(colIdx, DataTypeUtils.toDouble(value, recordFieldName)); break; case DECIMAL: row.addDecimal(colIdx, new BigDecimal(DataTypeUtils.toString(value, recordFieldName))); break; case VARCHAR: row.addVarchar(colIdx, DataTypeUtils.toString(value, recordFieldName)); break; default: throw new IllegalStateException(String.format("unknown column type %s", colType)); } } } } }