Search in sources :

Example 36 with TypeSignature

use of io.trino.spi.type.TypeSignature in project trino by trinodb.

the class TestMergeQuantileDigestFunction method getSequenceBlocks.

@Override
protected Block[] getSequenceBlocks(int start, int length) {
    Type type = functionResolution.getPlannerContext().getTypeManager().getType(new TypeSignature(QDIGEST.getName(), TypeSignatureParameter.typeParameter(DOUBLE.getTypeSignature())));
    BlockBuilder blockBuilder = type.createBlockBuilder(null, length);
    for (int i = start; i < start + length; i++) {
        QuantileDigest qdigest = new QuantileDigest(0.0);
        qdigest.add(i);
        type.writeSlice(blockBuilder, qdigest.serialize());
    }
    return new Block[] { blockBuilder.build() };
}
Also used : QuantileDigestType(io.trino.spi.type.QuantileDigestType) Type(io.trino.spi.type.Type) TypeSignature(io.trino.spi.type.TypeSignature) QuantileDigest(io.airlift.stats.QuantileDigest) Block(io.trino.spi.block.Block) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 37 with TypeSignature

use of io.trino.spi.type.TypeSignature in project trino by trinodb.

the class TestOrcReaderMemoryUsage method testMapTypeWithNulls.

@Test
public void testMapTypeWithNulls() throws Exception {
    Type mapType = TESTING_TYPE_MANAGER.getType(new TypeSignature(StandardTypes.MAP, TypeSignatureParameter.typeParameter(BIGINT.getTypeSignature()), TypeSignatureParameter.typeParameter(BIGINT.getTypeSignature())));
    int rows = 10000;
    OrcRecordReader reader = null;
    try (TempFile tempFile = createSingleColumnMapFileWithNullValues(mapType, rows)) {
        reader = createCustomOrcRecordReader(tempFile, OrcPredicate.TRUE, mapType, INITIAL_BATCH_SIZE);
        assertInitialRetainedSizes(reader, rows);
        long stripeReaderRetainedSize = reader.getCurrentStripeRetainedSizeInBytes();
        long streamReaderRetainedSize = reader.getStreamReaderRetainedSizeInBytes();
        long readerRetainedSize = reader.getRetainedSizeInBytes();
        long readerMemoryUsage = reader.getMemoryUsage();
        while (true) {
            Page page = reader.nextPage();
            if (page == null) {
                break;
            }
            page = page.getLoadedPage();
            // increasing during the test, which will cause the StreamReader buffer sizes to increase too.
            if (page.getPositionCount() < MAX_BATCH_SIZE) {
                continue;
            }
            // StripeReader memory should increase after reading a block.
            assertGreaterThan(reader.getCurrentStripeRetainedSizeInBytes(), stripeReaderRetainedSize);
            // There are no local buffers needed.
            assertEquals(reader.getStreamReaderRetainedSizeInBytes() - streamReaderRetainedSize, 0L);
            // The total retained size and memory usage should be strictly larger than 0L because of the instance sizes.
            assertGreaterThan(reader.getRetainedSizeInBytes() - readerRetainedSize, 0L);
            assertGreaterThan(reader.getMemoryUsage() - readerMemoryUsage, 0L);
        }
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
    assertClosedRetainedSizes(reader);
}
Also used : Type(io.trino.spi.type.Type) TypeSignature(io.trino.spi.type.TypeSignature) Page(io.trino.spi.Page) OrcTester.createCustomOrcRecordReader(io.trino.orc.OrcTester.createCustomOrcRecordReader) Test(org.testng.annotations.Test)

Example 38 with TypeSignature

use of io.trino.spi.type.TypeSignature in project trino by trinodb.

the class TestTypeSignature method testIsCalculated.

@Test
public void testIsCalculated() {
    assertFalse(BIGINT.getTypeSignature().isCalculated());
    assertTrue(new TypeSignature("decimal", typeVariable("p"), typeVariable("s")).isCalculated());
    assertFalse(createDecimalType(2, 1).getTypeSignature().isCalculated());
    assertTrue(arrayType(new TypeSignature("decimal", typeVariable("p"), typeVariable("s"))).isCalculated());
    assertFalse(arrayType(createDecimalType(2, 1).getTypeSignature()).isCalculated());
    assertTrue(mapType(new TypeSignature("decimal", typeVariable("p1"), typeVariable("s1")), new TypeSignature("decimal", typeVariable("p2"), typeVariable("s2"))).isCalculated());
    assertFalse(mapType(createDecimalType(2, 1).getTypeSignature(), createDecimalType(3, 1).getTypeSignature()).isCalculated());
    assertTrue(rowType(namedField("a", new TypeSignature("decimal", typeVariable("p1"), typeVariable("s1"))), namedField("b", new TypeSignature("decimal", typeVariable("p2"), typeVariable("s2")))).isCalculated());
}
Also used : NamedTypeSignature(io.trino.spi.type.NamedTypeSignature) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 39 with TypeSignature

use of io.trino.spi.type.TypeSignature in project trino by trinodb.

the class TestTypeSignature method assertSignature.

private static void assertSignature(String typeName, String base, List<String> parameters, String expectedTypeName) {
    TypeSignature signature = parseTypeSignature(typeName, ImmutableSet.of());
    assertEquals(signature.getBase(), base);
    assertEquals(signature.getParameters().size(), parameters.size());
    for (int i = 0; i < signature.getParameters().size(); i++) {
        assertEquals(signature.getParameters().get(i).toString(), parameters.get(i));
    }
    assertEquals(signature.toString(), expectedTypeName);
}
Also used : NamedTypeSignature(io.trino.spi.type.NamedTypeSignature) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature)

Example 40 with TypeSignature

use of io.trino.spi.type.TypeSignature in project trino by trinodb.

the class TypeConverter method toTrinoType.

public static Type toTrinoType(org.apache.iceberg.types.Type type, TypeManager typeManager) {
    switch(type.typeId()) {
        case BOOLEAN:
            return BooleanType.BOOLEAN;
        case BINARY:
        case FIXED:
            return VarbinaryType.VARBINARY;
        case DATE:
            return DateType.DATE;
        case DECIMAL:
            Types.DecimalType decimalType = (Types.DecimalType) type;
            return DecimalType.createDecimalType(decimalType.precision(), decimalType.scale());
        case DOUBLE:
            return DoubleType.DOUBLE;
        case LONG:
            return BigintType.BIGINT;
        case FLOAT:
            return RealType.REAL;
        case INTEGER:
            return IntegerType.INTEGER;
        case TIME:
            return TIME_MICROS;
        case TIMESTAMP:
            return ((Types.TimestampType) type).shouldAdjustToUTC() ? TIMESTAMP_TZ_MICROS : TIMESTAMP_MICROS;
        case STRING:
            return VarcharType.createUnboundedVarcharType();
        case UUID:
            return UuidType.UUID;
        case LIST:
            Types.ListType listType = (Types.ListType) type;
            return new ArrayType(toTrinoType(listType.elementType(), typeManager));
        case MAP:
            Types.MapType mapType = (Types.MapType) type;
            TypeSignature keyType = toTrinoType(mapType.keyType(), typeManager).getTypeSignature();
            TypeSignature valueType = toTrinoType(mapType.valueType(), typeManager).getTypeSignature();
            return typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(keyType), TypeSignatureParameter.typeParameter(valueType)));
        case STRUCT:
            List<Types.NestedField> fields = ((Types.StructType) type).fields();
            return RowType.from(fields.stream().map(field -> new RowType.Field(Optional.of(field.name()), toTrinoType(field.type(), typeManager))).collect(toImmutableList()));
    }
    throw new UnsupportedOperationException(format("Cannot convert from Iceberg type '%s' (%s) to Trino type", type, type.typeId()));
}
Also used : Types(org.apache.iceberg.types.Types) StandardTypes(io.trino.spi.type.StandardTypes) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature(io.trino.spi.type.TypeSignature) DecimalType(io.trino.spi.type.DecimalType)

Aggregations

TypeSignature (io.trino.spi.type.TypeSignature)78 Test (org.testng.annotations.Test)49 TypeSignatureTranslator.parseTypeSignature (io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature)35 ImmutableList (com.google.common.collect.ImmutableList)19 Signature (io.trino.metadata.Signature)17 NamedTypeSignature (io.trino.spi.type.NamedTypeSignature)17 Type (io.trino.spi.type.Type)15 ArrayType (io.trino.spi.type.ArrayType)14 List (java.util.List)13 BoundSignature (io.trino.metadata.BoundSignature)11 Optional (java.util.Optional)10 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableSet (com.google.common.collect.ImmutableSet)9 TrinoException (io.trino.spi.TrinoException)9 DecimalType (io.trino.spi.type.DecimalType)9 TypeSignatureParameter (io.trino.spi.type.TypeSignatureParameter)9 Objects.requireNonNull (java.util.Objects.requireNonNull)9 BIGINT (io.trino.spi.type.BigintType.BIGINT)8 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)7 ADD (io.trino.spi.function.OperatorType.ADD)7