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);
}
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);
}
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();
}
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));
}
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)));
}
Aggregations