public static Type fromKuduColumn(ColumnSchema column) { return fromKuduClientType(column.getType(), column.getTypeAttributes()); }
switch (colType.getDataType(colSchema.getTypeAttributes())) { case BOOL: row.addBoolean(colIdx, record.getAsBoolean(colName));
public static Type fromKuduColumn(ColumnSchema column) { return fromKuduClientType(column.getType(), column.getTypeAttributes()); }
public static Type fromKuduColumn(ColumnSchema column) { return fromKuduClientType(column.getType(), column.getTypeAttributes()); }
/** {@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(); }
/** * Set a BigDecimal for the upper bound * @param upperBound value for the upper bound */ public void setUpperBound(BigDecimal upperBound) { checkColumn(Type.DECIMAL); int precision = column.getTypeAttributes().getPrecision(); int scale = column.getTypeAttributes().getScale(); BigDecimal coercedVal = DecimalUtil.coerce(upperBound, precision, scale); setUpperBoundInternal(Bytes.fromBigDecimal(coercedVal, precision)); }
/** * Set a BigDecimal for the lower bound * @param lowerBound value for the lower bound */ public void setLowerBound(BigDecimal lowerBound) { checkColumn(Type.DECIMAL); int precision = column.getTypeAttributes().getPrecision(); int scale = column.getTypeAttributes().getScale(); BigDecimal coercedVal = DecimalUtil.coerce(lowerBound, precision, scale); setLowerBoundInternal(Bytes.fromBigDecimal(coercedVal, precision)); }
/** * 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()][])); } }
switch (column.getType().getDataType(column.getTypeAttributes())) { case BOOL: return Boolean.toString(Bytes.getBoolean(value)); case INT8: return Byte.toString(Bytes.getByte(value)); case DECIMAL64: case DECIMAL128: ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return Bytes.getDecimal(value, typeAttributes.getPrecision(), typeAttributes.getScale()).toString();
/** * Clone the given column schema instance. The new instance will include only the name, type, and * nullability of the passed one. * @return a new column schema */ private static ColumnSchema getStrippedColumnSchema(ColumnSchema columnToClone) { return new ColumnSchema.ColumnSchemaBuilder(columnToClone.getName(), columnToClone.getType()) .nullable(columnToClone.isNullable()) .typeAttributes(columnToClone.getTypeAttributes()) .build(); }
public static Common.ColumnTypeAttributesPB columnTypeAttributesToPb( Common.ColumnTypeAttributesPB.Builder builder, ColumnSchema column) { ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); if (typeAttributes.hasPrecision()) { builder.setPrecision(typeAttributes.getPrecision()); } if (typeAttributes.hasScale()) { builder.setScale(typeAttributes.getScale()); } return builder.build(); }
private static byte[] objectToWireFormat(ColumnSchema col, Object value) { switch (col.getType()) { case BOOL: return Bytes.fromBoolean((Boolean) value); case INT8: return new byte[] {(Byte) value}; case INT16: return Bytes.fromShort((Short) value); case INT32: return Bytes.fromInt((Integer) value); case INT64: case UNIXTIME_MICROS: return Bytes.fromLong((Long) value); case STRING: return ((String) value).getBytes(UTF_8); case BINARY: return (byte[]) value; case FLOAT: return Bytes.fromFloat((Float) value); case DOUBLE: return Bytes.fromDouble((Double) value); case DECIMAL: return Bytes.fromBigDecimal((BigDecimal) value, col.getTypeAttributes().getPrecision()); default: throw new IllegalArgumentException("The column " + col.getName() + " is of type " + col .getType() + " which is unknown"); } }
switch (column.getType().getDataType(column.getTypeAttributes())) { case BOOL: return Boolean.compare(Bytes.getBoolean(a), Bytes.getBoolean(b));
/** * Add a Decimal for the specified column. * @param columnIndex the column's index in the schema * @param val value to add * @throws IllegalArgumentException if the value doesn't match the column's type * @throws IllegalStateException if the row was already applied * @throws IndexOutOfBoundsException if the column doesn't exist */ public void addDecimal(int columnIndex, BigDecimal val) { checkNotFrozen(); ColumnSchema column = schema.getColumnByIndex(columnIndex); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); checkColumn(column, Type.DECIMAL); BigDecimal coercedVal = DecimalUtil.coerce(val,typeAttributes.getPrecision(), typeAttributes.getScale()); Bytes.setBigDecimal(rowAlloc, coercedVal, typeAttributes.getPrecision(), getPositionInRowAllocAndSetBitSet(columnIndex)); }
/** * Get the specified column's Decimal. * * @param columnIndex Column index in the schema * @return a BigDecimal * @throws IllegalArgumentException if the column is null, is unset, * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public BigDecimal getDecimal(int columnIndex) { checkColumn(schema.getColumnByIndex(columnIndex), Type.DECIMAL); checkColumnExists(schema.getColumnByIndex(columnIndex)); checkValue(columnIndex); ColumnSchema column = schema.getColumnByIndex(columnIndex); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return Bytes.getDecimal(rowAlloc, schema.getColumnOffset(columnIndex), typeAttributes.getPrecision(), typeAttributes.getScale()); }
table.getSchema().getColumn("c1").getTypeAttributes().getPrecision());
/** * Get the specified column's Decimal. * * @param columnIndex Column index in the schema * @return a BigDecimal. * @throws IllegalArgumentException if the column is null * @throws IndexOutOfBoundsException if the column doesn't exist */ public BigDecimal getDecimal(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.DECIMAL); ColumnSchema column = schema.getColumnByIndex(columnIndex); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return Bytes.getDecimal(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex), typeAttributes.getPrecision(), typeAttributes.getScale()); }
return null; switch (column.getType().getDataType(column.getTypeAttributes())) { case BOOL: return KuduPredicate.newComparisonPredicate(column, op, Bytes.getBoolean(bound)); case DECIMAL64: case DECIMAL128: ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return KuduPredicate.newComparisonPredicate(column, op, Bytes.getDecimal(bound, typeAttributes.getPrecision(), typeAttributes.getScale()));
break; case DECIMAL: ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); addDecimal(index, DecimalUtil.minValue(typeAttributes.getPrecision(), typeAttributes.getScale()));
public static Common.ColumnSchemaPB columnToPb(Common.ColumnSchemaPB.Builder schemaBuilder, ColumnSchema column) { schemaBuilder .setName(column.getName()) .setType(column.getType().getDataType(column.getTypeAttributes())) .setIsKey(column.isKey()) .setIsNullable(column.isNullable()) .setCfileBlockSize(column.getDesiredBlockSize()); if (column.getEncoding() != null) { schemaBuilder.setEncoding(column.getEncoding().getInternalPbType()); } if (column.getCompressionAlgorithm() != null) { schemaBuilder.setCompression(column.getCompressionAlgorithm().getInternalPbType()); } if (column.getDefaultValue() != null) { schemaBuilder.setReadDefaultValue(UnsafeByteOperations.unsafeWrap( objectToWireFormat(column, column.getDefaultValue()))); } if(column.getTypeAttributes() != null) { schemaBuilder.setTypeAttributes( columnTypeAttributesToPb(Common.ColumnTypeAttributesPB.newBuilder(), column)); } return schemaBuilder.build(); }