Search in sources :

Example 76 with ArrayType

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

the class TestAnnotationEngineForAggregates method testSimpleExplicitSpecializedAggregationParse.

// TODO this is not yet supported
@Test(enabled = false)
public void testSimpleExplicitSpecializedAggregationParse() {
    Signature expectedSignature = new Signature("explicit_specialized_aggregate", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.typeParameter(new TypeSignature("T")))), false);
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(ExplicitSpecializedAggregationFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple explicit specialized aggregate");
    assertTrue(aggregation.getFunctionMetadata().isDeterministic());
    assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 1, 1);
    AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
    assertTrue(implementation1.hasSpecializedTypeParameters());
    assertFalse(implementation1.hasSpecializedTypeParameters());
    assertEquals(implementation1.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
    assertTrue(implementation2.hasSpecializedTypeParameters());
    assertFalse(implementation2.hasSpecializedTypeParameters());
    assertEquals(implementation2.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(new ArrayType(DoubleType.DOUBLE)));
    AggregationFunctionMetadata aggregationMetadata = aggregation.getAggregationMetadata();
    assertFalse(aggregationMetadata.isOrderSensitive());
    assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
    aggregation.specialize(boundSignature, NO_FUNCTION_DEPENDENCIES);
}
Also used : AggregationImplementation(io.trino.operator.aggregation.AggregationImplementation) ArrayType(io.trino.spi.type.ArrayType) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Signature(io.trino.metadata.Signature) BoundSignature(io.trino.metadata.BoundSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricAggregation(io.trino.operator.aggregation.ParametricAggregation) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) Test(org.testng.annotations.Test)

Example 77 with ArrayType

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

the class TestAnnotationEngineForAggregates method testSimpleImplicitSpecializedAggregationParse.

// TODO this is not yet supported
@Test(enabled = false)
public void testSimpleImplicitSpecializedAggregationParse() {
    Signature expectedSignature = new Signature("implicit_specialized_aggregate", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.typeParameter(new TypeSignature("T"))), new TypeSignature("T")), false);
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(ImplicitSpecializedAggregationFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple implicit specialized aggregate");
    assertTrue(aggregation.getFunctionMetadata().isDeterministic());
    assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 0, 2);
    AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
    assertTrue(implementation1.hasSpecializedTypeParameters());
    assertFalse(implementation1.hasSpecializedTypeParameters());
    assertEquals(implementation1.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL, INPUT_CHANNEL));
    AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
    assertTrue(implementation2.hasSpecializedTypeParameters());
    assertFalse(implementation2.hasSpecializedTypeParameters());
    assertEquals(implementation2.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(new ArrayType(DoubleType.DOUBLE)));
    AggregationFunctionMetadata aggregationMetadata = aggregation.getAggregationMetadata();
    assertFalse(aggregationMetadata.isOrderSensitive());
    assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
    aggregation.specialize(boundSignature, NO_FUNCTION_DEPENDENCIES);
}
Also used : AggregationImplementation(io.trino.operator.aggregation.AggregationImplementation) ArrayType(io.trino.spi.type.ArrayType) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Signature(io.trino.metadata.Signature) BoundSignature(io.trino.metadata.BoundSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricAggregation(io.trino.operator.aggregation.ParametricAggregation) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) Test(org.testng.annotations.Test)

Example 78 with ArrayType

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

the class TestSignatureBinder method testCanCoerceTo.

@Test
public void testCanCoerceTo() {
    Signature arrayJoin = functionSignature().returnType(VARCHAR.getTypeSignature()).argumentTypes(arrayType(new TypeSignature("E"))).typeVariableConstraints(castableToTypeParameter("E", VARCHAR.getTypeSignature())).build();
    assertThat(arrayJoin).boundTo(new ArrayType(INTEGER)).produces(new BoundVariables().setTypeVariable("E", INTEGER));
    assertThat(arrayJoin).boundTo(new ArrayType(VARBINARY)).fails();
    Signature castArray = functionSignature().returnType(arrayType(new TypeSignature("T"))).argumentTypes(arrayType(new TypeSignature("F"))).typeVariableConstraints(typeVariable("T"), castableToTypeParameter("F", new TypeSignature("T"))).build();
    assertThat(castArray).boundTo(ImmutableList.of(new ArrayType(INTEGER)), new ArrayType(VARCHAR)).produces(new BoundVariables().setTypeVariable("F", INTEGER).setTypeVariable("T", VARCHAR));
    assertThat(castArray).boundTo(new ArrayType(INTEGER), new ArrayType(TIMESTAMP_MILLIS)).fails();
    Signature multiCast = functionSignature().returnType(VARCHAR.getTypeSignature()).argumentTypes(arrayType(new TypeSignature("E"))).typeVariableConstraints(castableToTypeParameter("E", VARCHAR.getTypeSignature(), INTEGER.getTypeSignature())).build();
    assertThat(multiCast).boundTo(new ArrayType(TINYINT)).produces(new BoundVariables().setTypeVariable("E", TINYINT));
    assertThat(multiCast).boundTo(new ArrayType(TIMESTAMP_MILLIS)).fails();
}
Also used : ArrayType(io.trino.spi.type.ArrayType) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 79 with ArrayType

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

the class TestSignatureBinder method testBindMixedLiteralAndTypeVariables.

@Test
public void testBindMixedLiteralAndTypeVariables() {
    Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).argumentTypes(arrayType(new TypeSignature("T")), arrayType(new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p"), TypeSignatureParameter.typeVariable("s")))).build();
    assertThat(function).boundTo(new ArrayType(createDecimalType(2, 1)), new ArrayType(createDecimalType(3, 1))).withCoercion().produces(new BoundVariables().setTypeVariable("T", createDecimalType(2, 1)).setLongVariable("p", 3L).setLongVariable("s", 1L));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 80 with ArrayType

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

the class TestSignatureBinder method testBasic.

@Test
public void testBasic() {
    Signature function = functionSignature().typeVariableConstraints(ImmutableList.of(typeVariable("T"))).returnType(new TypeSignature("T")).argumentTypes(new TypeSignature("T")).build();
    assertThat(function).boundTo(BIGINT).produces(new BoundVariables().setTypeVariable("T", BIGINT));
    assertThat(function).boundTo(VARCHAR).produces(new BoundVariables().setTypeVariable("T", VARCHAR));
    assertThat(function).boundTo(VARCHAR, BIGINT).fails();
    assertThat(function).boundTo(new ArrayType(BIGINT)).produces(new BoundVariables().setTypeVariable("T", new ArrayType(BIGINT)));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Aggregations

ArrayType (io.trino.spi.type.ArrayType)289 Test (org.testng.annotations.Test)205 Type (io.trino.spi.type.Type)92 RowType (io.trino.spi.type.RowType)86 ImmutableList (com.google.common.collect.ImmutableList)66 List (java.util.List)62 ArrayList (java.util.ArrayList)59 MapType (io.trino.spi.type.MapType)43 Arrays.asList (java.util.Arrays.asList)36 Collections.singletonList (java.util.Collections.singletonList)34 VarcharType (io.trino.spi.type.VarcharType)32 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)32 BlockBuilder (io.trino.spi.block.BlockBuilder)31 MessageType (org.apache.parquet.schema.MessageType)31 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)30 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)27 DecimalType (io.trino.spi.type.DecimalType)26 StructuralTestUtil.mapType (io.trino.testing.StructuralTestUtil.mapType)24 Block (io.trino.spi.block.Block)23 Map (java.util.Map)23