private ColumnMetadata getColumnMetadata(ColumnSchema column) { Map<String, Object> properties = new LinkedHashMap<>(); StringBuilder extra = new StringBuilder(); if (column.isKey()) { properties.put(KuduTableProperties.PRIMARY_KEY, true); extra.append("primary_key, "); } if (column.isNullable()) { properties.put(KuduTableProperties.NULLABLE, true); extra.append("nullable, "); } String encoding = KuduTableProperties.lookupEncodingString(column.getEncoding()); if (!column.getEncoding().equals(ColumnSchema.Encoding.AUTO_ENCODING)) { properties.put(KuduTableProperties.ENCODING, encoding); } extra.append("encoding=").append(encoding).append(", "); String compression = KuduTableProperties.lookupCompressionString(column.getCompressionAlgorithm()); if (!column.getCompressionAlgorithm().equals(ColumnSchema.CompressionAlgorithm.DEFAULT_COMPRESSION)) { properties.put(KuduTableProperties.COMPRESSION, compression); } extra.append("compression=").append(compression); Type prestoType = TypeHelper.fromKuduColumn(column); return new ColumnMetadata(column.getName(), prestoType, null, extra.toString(), false, properties); }
@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); }
private static LinkedHashMap<String, ColumnDesign> getColumns(KuduTable table) { Schema schema = table.getSchema(); LinkedHashMap<String, ColumnDesign> columns = new LinkedHashMap<>(); for (ColumnSchema columnSchema : schema.getColumns()) { ColumnDesign design = new ColumnDesign(); design.setNullable(columnSchema.isNullable()); design.setPrimaryKey(columnSchema.isKey()); design.setCompression(lookupCompressionString(columnSchema.getCompressionAlgorithm())); design.setEncoding(lookupEncodingString(columnSchema.getEncoding())); columns.put(columnSchema.getName(), design); } return columns; }
case BINARY: { ByteBuffer value = result.getBinary(pci.index); if (pci.kuduColumn.isNullable()) { ((NullableVarBinaryVector.Mutator) pci.vv.getMutator()) .setSafe(rowIndex, value, 0, value.remaining()); if (pci.kuduColumn.isNullable()) { ((NullableVarCharVector.Mutator) pci.vv.getMutator()) .setSafe(rowIndex, value, 0, value.remaining()); if (pci.kuduColumn.isNullable()) { ((NullableBitVector.Mutator) pci.vv.getMutator()) .setSafe(rowIndex, result.getBoolean(pci.index) ? 1 : 0); if (pci.kuduColumn.isNullable()) { ((NullableFloat8Vector.Mutator) pci.vv.getMutator()) .setSafe(rowIndex, result.getDouble(pci.index)); if (pci.kuduColumn.isNullable()) { ((NullableFloat4Vector.Mutator) pci.vv.getMutator()) .setSafe(rowIndex, result.getFloat(pci.index)); if (pci.kuduColumn.isNullable()) { ((NullableIntVector.Mutator) pci.vv.getMutator()) .setSafe(rowIndex, result.getShort(pci.index)); if (pci.kuduColumn.isNullable()) { ((NullableIntVector.Mutator) pci.vv.getMutator()) .setSafe(rowIndex, result.getInt(pci.index));
if (col.isNullable()) { majorType = Types.optional(minorType); } else {
/** * Creates a new {@code IS NULL} predicate. * * @param column the column that the predicate applies to * @return an {@code IS NULL} predicate */ public static KuduPredicate newIsNullPredicate(ColumnSchema column) { if (!column.isNullable()) { return none(column); } return new KuduPredicate(PredicateType.IS_NULL, column, null, null); }
/** * Get if the specified column is NULL * @param columnIndex Column index in the schema * @return true if the column cell is null and the column is nullable, * false otherwise * @throws IndexOutOfBoundsException if the column doesn't exist */ public boolean isNull(int columnIndex) { checkValidColumn(columnIndex); if (nullsBitSet == null) { return false; } return schema.getColumnByIndex(columnIndex).isNullable() && nullsBitSet.get(columnIndex); }
private void setNull(ColumnSchema column) { assert nullsBitSet != null; checkNotFrozen(); checkColumnExists(column); if (!column.isNullable()) { throw new IllegalArgumentException(column.getName() + " cannot be set to null"); } int idx = schema.getColumns().indexOf(column); columnsBitSet.set(idx); nullsBitSet.set(idx); }
/** * Gives the size in bytes for a single row given the specified schema * @param columns the row's columns * @return row size in bytes */ private static int getRowSize(List<ColumnSchema> columns) { int totalSize = 0; boolean hasNullables = false; for (ColumnSchema column : columns) { totalSize += column.getTypeSize(); hasNullables |= column.isNullable(); } if (hasNullables) { totalSize += Bytes.getBitSetSize(columns.size()); } return totalSize; }
hasNulls |= column.isNullable(); columnOffsets[index] = offset; offset += column.getTypeSize();
private ColumnMetadata getColumnMetadata(ColumnSchema column) { Map<String, Object> properties = new LinkedHashMap<>(); StringBuilder extra = new StringBuilder(); if (column.isKey()) { properties.put(KuduTableProperties.PRIMARY_KEY, true); extra.append("primary_key, "); } if (column.isNullable()) { properties.put(KuduTableProperties.NULLABLE, true); extra.append("nullable, "); } String encoding = KuduTableProperties.lookupEncodingString(column.getEncoding()); if (!column.getEncoding().equals(ColumnSchema.Encoding.AUTO_ENCODING)) { properties.put(KuduTableProperties.ENCODING, encoding); } extra.append("encoding=").append(encoding).append(", "); String compression = KuduTableProperties.lookupCompressionString(column.getCompressionAlgorithm()); if (!column.getCompressionAlgorithm().equals(ColumnSchema.CompressionAlgorithm.DEFAULT_COMPRESSION)) { properties.put(KuduTableProperties.COMPRESSION, compression); } extra.append("compression=").append(compression); Type prestoType = TypeHelper.fromKuduColumn(column); return new ColumnMetadata(column.getName(), prestoType, null, extra.toString(), false, properties); }
/** * Adds a predicate to the scan. * @param predicate predicate to add * @return this instance */ public S addPredicate(KuduPredicate predicate) { String columnName = predicate.getColumn().getName(); KuduPredicate existing = predicates.get(columnName); if (existing != null) { predicate = existing.merge(predicate); } // KUDU-1652: Do not send an IS NOT NULL predicate to the server for a non-nullable column. if (!predicate.getColumn().isNullable() && predicate.getType() == KuduPredicate.PredicateType.IS_NOT_NULL) { return (S) this; } predicates.put(columnName, predicate); return (S) this; }
/** * Get if the specified column is NULL * @param columnIndex Column index in the schema * @return true if the column cell is null and the column is nullable, * false otherwise * @throws IndexOutOfBoundsException if the column doesn't exist */ public boolean isNull(int columnIndex) { checkColumnExists(schema.getColumnByIndex(columnIndex)); return schema.getColumnByIndex(columnIndex).isNullable() && isSetToNull(columnIndex); }
private ConnectorTableMetadata getTableMetadata(KuduTableHandle tableHandle) { KuduTable table = tableHandle.getTable(clientSession); Schema schema = table.getSchema(); List<ColumnMetadata> columnsMetaList = schema.getColumns().stream() .filter(col -> !col.isKey() || !col.getName().equals(KuduColumnHandle.ROW_ID)) .map(col -> { StringBuilder extra = new StringBuilder(); if (col.isKey()) { extra.append("key, "); } else if (col.isNullable()) { extra.append("nullable, "); } if (col.getEncoding() != null) { extra.append("encoding=").append(col.getEncoding().name()).append(", "); } if (col.getCompressionAlgorithm() != null) { extra.append("compression=").append(col.getCompressionAlgorithm().name()).append(", "); } if (extra.length() > 2) { extra.setLength(extra.length() - 2); } Type prestoType = TypeHelper.fromKuduColumn(col); return new ColumnMetadata(col.getName(), prestoType, null, extra.toString(), false); }).collect(toImmutableList()); Map<String, Object> properties = clientSession.getTableProperties(tableHandle); return new ConnectorTableMetadata(tableHandle.getSchemaTableName(), columnsMetaList, properties); }
/** * Add a new column. * @param colSchema the schema of the new column * @return this instance */ public AlterTableOptions addColumn(ColumnSchema colSchema) { if (!colSchema.isNullable() && colSchema.getDefaultValue() == null) { throw new IllegalArgumentException("A new non-null column must have a default value"); } if (colSchema.isKey()) { throw new IllegalArgumentException("Key columns cannot be added"); } AlterTableRequestPB.Step.Builder step = pb.addAlterSchemaStepsBuilder(); step.setType(AlterTableRequestPB.StepType.ADD_COLUMN); step.setAddColumn(AlterTableRequestPB.AddColumn.newBuilder() .setSchema(ProtobufHelper.columnToPb(colSchema))); return this; }
/** * 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(); }
private static LinkedHashMap<String, ColumnDesign> getColumns(KuduTable table) { Schema schema = table.getSchema(); LinkedHashMap<String, ColumnDesign> columns = new LinkedHashMap<>(); for (ColumnSchema columnSchema : schema.getColumns()) { ColumnDesign design = new ColumnDesign(); design.setNullable(columnSchema.isNullable()); design.setPrimaryKey(columnSchema.isKey()); design.setCompression(lookupCompressionString(columnSchema.getCompressionAlgorithm())); design.setEncoding(lookupEncodingString(columnSchema.getEncoding())); columns.put(columnSchema.getName(), design); } return columns; }
private static LinkedHashMap<String, ColumnDesign> getColumns(KuduTable table) { Schema schema = table.getSchema(); LinkedHashMap<String, ColumnDesign> columns = new LinkedHashMap<>(); for (ColumnSchema columnSchema : schema.getColumns()) { ColumnDesign design = new ColumnDesign(); design.setNullable(columnSchema.isNullable()); design.setKey(columnSchema.isKey()); if (columnSchema.getCompressionAlgorithm() != null) { design.setCompression(columnSchema.getCompressionAlgorithm().name()); } if (columnSchema.getEncoding() != null) { design.setEncoding(columnSchema.getEncoding().name()); } columns.put(columnSchema.getName(), design); } return columns; }
column.getType().name(), column.getName(), schema.getType().name())); if (column.getIsNullable() != schema.isNullable()) { throw new IllegalStateException(String.format( "invalid nullability for column '%s' in scan token, expected: %s",
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(); }