switch (colType.getDataType(colSchema.getTypeAttributes())) { case BOOL: row.addBoolean(colIdx, record.getAsBoolean(colName));
.equals(KuduDBValidationClassMapper.getValidTypeForClass(columnInfo.getType())))
private void checkType(int columnIndex, Type expectedType) { ColumnSchema columnSchema = schema.getColumnByIndex(columnIndex); Type columnType = columnSchema.getType(); if (!columnType.equals(expectedType)) { throw new IllegalArgumentException("Column (name: " + columnSchema.getName() + ", index: " + columnIndex + ") is of type " + columnType.getName() + " but was requested as a type " + expectedType.getName()); } }
int columnIdx = table.getSchema().getColumnIndex(column.getName()); ColumnSchema schema = table.getSchema().getColumnByIndex(columnIdx); if (column.getType() != schema.getType().getDataType(schema.getTypeAttributes())) { throw new IllegalStateException(String.format( "invalid type %s for column '%s' in scan token, expected: %s", column.getType().name(), column.getName(), schema.getType().name()));
private static PrimitiveType.PrimitiveTypeName getTypeName(Type type) { switch (type) { case BOOL: return PrimitiveType.PrimitiveTypeName.BOOLEAN; case INT8: return PrimitiveType.PrimitiveTypeName.INT32; case INT16: return PrimitiveType.PrimitiveTypeName.INT64; case INT32: return PrimitiveType.PrimitiveTypeName.INT32; case INT64: return PrimitiveType.PrimitiveTypeName.INT64; case STRING: return PrimitiveType.PrimitiveTypeName.BINARY; case FLOAT: return PrimitiveType.PrimitiveTypeName.FLOAT; case DOUBLE: return PrimitiveType.PrimitiveTypeName.DOUBLE; default: throw new IllegalArgumentException("Type " + type.getName() + " not recognized"); } }
private ColumnSchema(String name, Type type, boolean key, boolean nullable, Object defaultValue, int desiredBlockSize, Encoding encoding, CompressionAlgorithm compressionAlgorithm, ColumnTypeAttributes typeAttributes) { this.name = name; this.type = type; this.key = key; this.nullable = nullable; this.defaultValue = defaultValue; this.desiredBlockSize = desiredBlockSize; this.encoding = encoding; this.compressionAlgorithm = compressionAlgorithm; this.typeAttributes = typeAttributes; this.typeSize = type.getSize(typeAttributes); }
/** * Private constructor used to pre-create the types * @param dataType DataType from the common's pb * @param name string representation of the type */ private Type(DataType dataType, String name) { this.dataTypes = ImmutableList.of(dataType); this.name = name; this.size = getTypeSize(dataType); }
buf.append(type.name()); buf.append(" ").append(col.getName()); if (col.getTypeAttributes() != null) {
public static ColumnSchema pbToColumnSchema(Common.ColumnSchemaPB pb) { Type type = Type.getTypeForDataType(pb.getType()); ColumnTypeAttributes typeAttributes = pb.hasTypeAttributes() ? pbToColumnTypeAttributes(pb.getTypeAttributes()) : null; Object defaultValue = pb.hasWriteDefaultValue() ? byteStringToObject(type, typeAttributes, pb.getWriteDefaultValue()) : null; ColumnSchema.Encoding encoding = ColumnSchema.Encoding.valueOf(pb.getEncoding().name()); ColumnSchema.CompressionAlgorithm compressionAlgorithm = ColumnSchema.CompressionAlgorithm.valueOf(pb.getCompression().name()); int desiredBlockSize = pb.getCfileBlockSize(); return new ColumnSchema.ColumnSchemaBuilder(pb.getName(), type) .key(pb.getIsKey()) .nullable(pb.getIsNullable()) .defaultValue(defaultValue) .encoding(encoding) .compressionAlgorithm(compressionAlgorithm) .desiredBlockSize(desiredBlockSize) .typeAttributes(typeAttributes) .build(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Column name: "); sb.append(name); sb.append(", type: "); sb.append(type.getName()); if (typeAttributes != null) { sb.append(typeAttributes.toStringForType(type)); } return sb.toString(); }
/** * Builds an IN list predicate from a collection of raw values. The collection * must be sorted and deduplicated. * * @param column the column * @param values the IN list values * @return an IN list predicate */ private static KuduPredicate buildInList(ColumnSchema column, Collection<byte[]> values) { // IN (true, false) predicates can be simplified to IS NOT NULL. if (column.getType().getDataType(column.getTypeAttributes()) == Common.DataType.BOOL && values.size() > 1) { return newIsNotNullPredicate(column); } switch (values.size()) { case 0: return KuduPredicate.none(column); case 1: return new KuduPredicate(PredicateType.EQUALITY, column, values.iterator().next(), null); default: return new KuduPredicate(column, values.toArray(new byte[values.size()][])); } }
/** * Checks that the column is one of the expected types. * @param column the column being checked * @param passedTypes the expected types (logical OR) */ private static void checkColumn(ColumnSchema column, Type... passedTypes) { for (Type type : passedTypes) { if (column.getType().equals(type)) { return; } } throw new IllegalArgumentException(String.format("%s's type isn't %s, it's %s", column.getName(), Arrays.toString(passedTypes), column.getType().getName())); }
/** * Appends a debug string for the provided columns in the row. * * @param idxs the column indexes * @param sb the string builder to append to */ void appendDebugString(List<Integer> idxs, StringBuilder sb) { boolean first = true; for (int idx : idxs) { if (first) { first = false; } else { sb.append(", "); } ColumnSchema col = schema.getColumnByIndex(idx); sb.append(col.getType().getName()); sb.append(' '); sb.append(col.getName()); sb.append('='); appendCellValueDebugString(idx, sb); } }
switch ( aKuduTableColumn.getType().getDataType().getNumber()) { case Common.DataType.BINARY_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetter(clazzForResultObject,
/** * Verifies if the column exists and belongs to one of the specified types * @param column column the user wants to set * @param types types we expect * @throws IllegalArgumentException if the column or type was invalid */ private void checkColumn(ColumnSchema column, Type... types) { checkColumnExists(column); for (Type type : types) { if (column.getType().equals(type)) { return; } } throw new IllegalArgumentException(String.format("%s isn't %s, it's %s", column.getName(), Arrays.toString(types), column.getType().getName())); }
/** {@inheritDoc} */ @Override public String toString() { int numCols = schema.getColumnCount(); StringBuilder sb = new StringBuilder(); sb.append('('); boolean first = true; for (int idx = 0; idx < numCols; ++idx) { if (!columnsBitSet.get(idx)) { continue; } if (first) { first = false; } else { sb.append(", "); } ColumnSchema col = schema.getColumnByIndex(idx); sb.append(col.getType().getName()); if (col.getTypeAttributes() != null) { sb.append(col.getTypeAttributes().toStringForType(col.getType())); } sb.append(' '); sb.append(col.getName()); sb.append('='); appendCellValueDebugString(idx, sb); } sb.append(')'); return sb.toString(); }
switch (column.getType().getDataType(column.getTypeAttributes())) { case BOOL: return Boolean.toString(Bytes.getBoolean(value)); case INT8: return Byte.toString(Bytes.getByte(value));