use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindUnknownToDecimal.
@Test
public void testBindUnknownToDecimal() {
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p"), TypeSignatureParameter.typeVariable("s"))).build();
assertThat(function).boundTo(UNKNOWN).withCoercion().produces(new BoundVariables().setLongVariable("p", 1L).setLongVariable("s", 0L));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindLiteralForRepeatedVarchar.
@Test
public void testBindLiteralForRepeatedVarchar() {
TypeSignature leftType = new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x"));
TypeSignature rightType = new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x"));
TypeSignature returnType = new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x"));
Signature function = functionSignature().returnType(returnType).argumentTypes(leftType, rightType).build();
assertThat(function).withCoercion().boundTo(ImmutableList.of(createVarcharType(3), createVarcharType(5)), createVarcharType(5)).produces(new BoundVariables().setLongVariable("x", 5L));
assertThat(function).withCoercion().boundTo(ImmutableList.of(createVarcharType(3), createVarcharType(5)), createVarcharType(6)).produces(new BoundVariables().setLongVariable("x", 6L));
}
use of io.trino.spi.type.TypeSignature 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.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testMap.
@Test
public void testMap() {
Signature getValueFunction = functionSignature().returnType(new TypeSignature("V")).argumentTypes(mapType(new TypeSignature("K"), new TypeSignature("V")), new TypeSignature("K")).typeVariableConstraints(ImmutableList.of(typeVariable("K"), typeVariable("V"))).build();
assertThat(getValueFunction).boundTo(type(mapType(BIGINT.getTypeSignature(), VARCHAR.getTypeSignature())), BIGINT).produces(new BoundVariables().setTypeVariable("K", BIGINT).setTypeVariable("V", VARCHAR));
assertThat(getValueFunction).boundTo(type(mapType(BIGINT.getTypeSignature(), VARCHAR.getTypeSignature())), VARCHAR).withCoercion().fails();
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testNoVariableReuseAcrossTypes.
@Test
public void testNoVariableReuseAcrossTypes() {
TypeSignature leftType = new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p1"), TypeSignatureParameter.typeVariable("s"));
TypeSignature rightType = new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p2"), TypeSignatureParameter.typeVariable("s"));
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(leftType, rightType).build();
assertThatThrownBy(() -> assertThat(function).boundTo(createDecimalType(2, 1), createDecimalType(3, 1)).produces(NO_BOUND_VARIABLES)).isInstanceOf(UnsupportedOperationException.class).hasMessage("Literal parameters may not be shared across different types");
}
Aggregations