use of io.trino.spi.type.RowType in project trino by trinodb.
the class OrcTester method rowType.
private static Type rowType(Type... fieldTypes) {
ImmutableList.Builder<TypeSignatureParameter> typeSignatureParameters = ImmutableList.builder();
for (int i = 0; i < fieldTypes.length; i++) {
String filedName = "field_" + i;
Type fieldType = fieldTypes[i];
typeSignatureParameters.add(TypeSignatureParameter.namedTypeParameter(new NamedTypeSignature(Optional.of(new RowFieldName(filedName)), fieldType.getTypeSignature())));
}
return TESTING_TYPE_MANAGER.getParameterizedType(StandardTypes.ROW, typeSignatureParameters.build());
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class CheckpointWriter method writeMinMaxMapAsFields.
private void writeMinMaxMapAsFields(BlockBuilder blockBuilder, RowType type, int fieldId, String fieldName, Optional<Map<String, Object>> values) {
RowType.Field valuesField = validateAndGetField(type, fieldId, fieldName);
RowType valuesFieldType = (RowType) valuesField.getType();
writeObjectMapAsFields(blockBuilder, type, fieldId, fieldName, preprocessMinMaxValues(valuesFieldType, values));
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class CheckpointWriter method writeParsedStats.
private void writeParsedStats(BlockBuilder entryBlockBuilder, RowType entryType, AddFileEntry addFileEntry) {
RowType statsType = getInternalRowType(entryType, 6, "stats_parsed");
if (addFileEntry.getStats().isEmpty() || !(addFileEntry.getStats().get() instanceof DeltaLakeParquetFileStatistics)) {
entryBlockBuilder.appendNull();
return;
}
DeltaLakeParquetFileStatistics stats = (DeltaLakeParquetFileStatistics) addFileEntry.getStats().get();
BlockBuilder statsBlockBuilder = entryBlockBuilder.beginBlockEntry();
writeLong(statsBlockBuilder, statsType, 0, "numRecords", stats.getNumRecords().orElse(null));
writeMinMaxMapAsFields(statsBlockBuilder, statsType, 1, "minValues", stats.getMinValues());
writeMinMaxMapAsFields(statsBlockBuilder, statsType, 2, "maxValues", stats.getMaxValues());
writeObjectMapAsFields(statsBlockBuilder, statsType, 3, "nullCount", stats.getNullCount());
entryBlockBuilder.closeEntry();
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class CheckpointWriter method writeStringMap.
private void writeStringMap(BlockBuilder blockBuilder, RowType type, int fieldId, String fieldName, @Nullable Map<String, String> values) {
RowType.Field field = validateAndGetField(type, fieldId, fieldName);
checkArgument(field.getType() instanceof MapType, "Expected field %s/%s to by of MapType but got %s", fieldId, fieldName, field.getType());
if (values == null) {
blockBuilder.appendNull();
return;
}
MapType mapType = (MapType) field.getType();
BlockBuilder mapBuilder = blockBuilder.beginBlockEntry();
for (Map.Entry<String, String> entry : values.entrySet()) {
mapType.getKeyType().writeSlice(mapBuilder, utf8Slice(entry.getKey()));
if (entry.getValue() == null) {
mapBuilder.appendNull();
} else {
mapType.getKeyType().writeSlice(mapBuilder, utf8Slice(entry.getValue()));
}
}
blockBuilder.closeEntry();
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class DeltaLakeSchemaSupport method validateStructuralType.
private static void validateStructuralType(Optional<Type> rootType, Type type) {
if (type instanceof ArrayType) {
validateType(rootType, ((ArrayType) type).getElementType());
}
if (type instanceof MapType) {
MapType mapType = (MapType) type;
validateType(rootType, mapType.getKeyType());
validateType(rootType, mapType.getValueType());
}
if (type instanceof RowType) {
RowType rowType = (RowType) type;
rowType.getFields().forEach(field -> validateType(rootType, field.getType()));
}
}
Aggregations