Java Code Examples for org.apache.kudu.Schema#getColumnByIndex()
The following examples show how to use
org.apache.kudu.Schema#getColumnByIndex() .
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: KuduMetadata.java From presto with Apache License 2.0 | 6 votes |
@Override public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle connectorTableHandle) { KuduTableHandle tableHandle = (KuduTableHandle) connectorTableHandle; Schema schema = clientSession.getTableSchema(tableHandle); ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder(); for (int ordinal = 0; ordinal < schema.getColumnCount(); ordinal++) { ColumnSchema col = schema.getColumnByIndex(ordinal); String name = col.getName(); Type type = TypeHelper.fromKuduColumn(col); KuduColumnHandle columnHandle = new KuduColumnHandle(name, ordinal, type); columnHandles.put(name, columnHandle); } return columnHandles.build(); }
Example 2
Source File: KuduTableProperties.java From presto with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: KuduMetadata.java From presto-kudu with Apache License 2.0 | 6 votes |
@Override public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle connectorTableHandle) { KuduTableHandle tableHandle = fromConnectorTableHandle(session, connectorTableHandle); Schema schema = clientSession.getTableSchema(tableHandle); ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder(); for (int i = 0; i < schema.getColumnCount(); i++) { ColumnSchema col = schema.getColumnByIndex(i); String name = col.getName(); Type type = TypeHelper.fromKuduColumn(col); KuduColumnHandle columnHandle = new KuduColumnHandle(name, i, type); columnHandles.put(name, columnHandle); } return columnHandles.build(); }
Example 4
Source File: KuduTableProperties.java From presto-kudu with Apache License 2.0 | 6 votes |
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(name -> schema.getColumnIndex(name)).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; }
Example 5
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)); } } } } }