Search in sources :

Example 56 with RowType

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());
}
Also used : TimestampWithTimeZoneType(io.trino.spi.type.TimestampWithTimeZoneType) OrcType(io.trino.orc.metadata.OrcType) MapType(io.trino.spi.type.MapType) VarbinaryType(io.trino.spi.type.VarbinaryType) CharType(io.trino.spi.type.CharType) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) VarcharType(io.trino.spi.type.VarcharType) TypeSignatureParameter(io.trino.spi.type.TypeSignatureParameter) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RowFieldName(io.trino.spi.type.RowFieldName) NamedTypeSignature(io.trino.spi.type.NamedTypeSignature)

Example 57 with RowType

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));
}
Also used : RowType(io.trino.spi.type.RowType)

Example 58 with RowType

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();
}
Also used : DeltaLakeParquetFileStatistics(io.trino.plugin.deltalake.transactionlog.statistics.DeltaLakeParquetFileStatistics) RowType(io.trino.spi.type.RowType) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 59 with RowType

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();
}
Also used : RowType(io.trino.spi.type.RowType) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) MapType(io.trino.spi.type.MapType) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 60 with RowType

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()));
    }
}
Also used : ArrayType(io.trino.spi.type.ArrayType) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType)

Aggregations

RowType (io.trino.spi.type.RowType)90 ArrayType (io.trino.spi.type.ArrayType)51 MapType (io.trino.spi.type.MapType)42 Type (io.trino.spi.type.Type)42 ImmutableList (com.google.common.collect.ImmutableList)30 VarcharType (io.trino.spi.type.VarcharType)28 BlockBuilder (io.trino.spi.block.BlockBuilder)26 DecimalType (io.trino.spi.type.DecimalType)21 Test (org.testng.annotations.Test)21 ImmutableMap (com.google.common.collect.ImmutableMap)20 Block (io.trino.spi.block.Block)20 List (java.util.List)20 Map (java.util.Map)18 ArrayList (java.util.ArrayList)17 Optional (java.util.Optional)17 CharType (io.trino.spi.type.CharType)16 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)15 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)12 TimestampWithTimeZoneType (io.trino.spi.type.TimestampWithTimeZoneType)12 HashMap (java.util.HashMap)12