public static Type fromKuduColumn(ColumnSchema column) { return fromKuduClientType(column.getType(), column.getTypeAttributes()); }
public static PartialRow toRangeBoundToPartialRow(Schema schema, RangePartitionDefinition definition, RangeBoundValue boundValue) { PartialRow partialRow = new PartialRow(schema); if (boundValue != null) { List<Integer> rangeColumns = definition.getColumns().stream() .map(schema::getColumnIndex).collect(toImmutableList()); if (rangeColumns.size() != boundValue.getValues().size()) { throw new IllegalStateException("Expected " + rangeColumns.size() + " range columns, but got " + boundValue.getValues().size()); } for (int i = 0; i < rangeColumns.size(); i++) { Object obj = boundValue.getValues().get(i); int idx = rangeColumns.get(i); ColumnSchema columnSchema = schema.getColumnByIndex(idx); setColumnValue(partialRow, idx, obj, columnSchema.getType(), columnSchema.getName()); } } return partialRow; }
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 partition"); } }
if (colIdx != -1) { ColumnSchema colSchema = schema.getColumnByIndex(colIdx); Type colType = colSchema.getType();
@Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { List<String> names = Lists.newArrayList(); List<RelDataType> types = Lists.newArrayList(); for (ColumnSchema column : schema.getColumns()) { names.add(column.getName()); RelDataType type = getSqlTypeFromKuduType(typeFactory, column.getType()); type = typeFactory.createTypeWithNullability(type, column.isNullable()); types.add(type); } return typeFactory.createStructType(types, names); }
/** * 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 void copyPrimaryKey(Schema schema, RowResult from, PartialRow to) switch (schema.getColumnByIndex(i).getType()) { case STRING: to.addStringUtf8(i, from.getString(i).getBytes(StandardCharsets.UTF_8)); break; default: throw new IllegalStateException("Unknown type " + schema.getColumnByIndex(i).getType() + " for column " + schema.getColumnByIndex(i).getName());
public static void copyPrimaryKey(Schema schema, PartialRow from, PartialRow to) switch (schema.getColumnByIndex(i).getType()) { case STRING: to.addStringUtf8(i, from.getString(i).getBytes(StandardCharsets.UTF_8)); break; default: throw new IllegalStateException("Unknown type " + schema.getColumnByIndex(i).getType() + " for column " + schema.getColumnByIndex(i).getName());
final Type kuduType = col.getType(); lastColumnName = name; lastColumnType = kuduType;
continue; switch (pci.kuduColumn.getType()) { case BINARY: { ByteBuffer value = result.getBinary(pci.index);
if (!schema.getColumn(columnInfo.getColumnName()).getType() .equals(KuduDBValidationClassMapper.getValidTypeForClass(columnInfo.getType())))
/** * Get the type of a column in this result. * @param columnName name of the column * @return a type */ public Type getColumnType(String columnName) { return this.schema.getColumn(columnName).getType(); }
/** * Get the type of a column in this result. * @param columnIndex column index in the schema * @return a type * @throws IndexOutOfBoundsException if the column doesn't exist */ public Type getColumnType(int columnIndex) { return this.schema.getColumnByIndex(columnIndex).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()); } }
@Test public void testGetMissingColumnIndex() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callGetByIndex(partialRow, 999, columnSchema.getType()); fail("Expected IndexOutOfBoundsException for type: " + columnSchema.getType()); } catch (IndexOutOfBoundsException ex) { // This is the expected exception. } } }
@Test public void testGetMissingColumnName() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callGetByName(partialRow, "not-a-column", columnSchema.getType()); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }
@Test public void testAddMissingColumnIndex() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callAddByIndex(partialRow, 999, columnSchema.getType()); fail("Expected IndexOutOfBoundsException for type: " + columnSchema.getType()); } catch (IndexOutOfBoundsException ex) { // This is the expected exception. } } }
@Test public void testGetWrongTypeColumn() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callGetByName(partialRow, columnSchema.getName(), getShiftedType(columnSchema.getType())); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }
@Test public void testAddWrongTypeColumn() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callAddByName(partialRow, columnSchema.getName(), getShiftedType(columnSchema.getType())); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }