use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindLiteralForRepeatedDecimal.
@Test
public void testBindLiteralForRepeatedDecimal() {
TypeSignature leftType = new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p"), TypeSignatureParameter.typeVariable("s"));
TypeSignature rightType = new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p"), TypeSignatureParameter.typeVariable("s"));
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo(createDecimalType(10, 5), createDecimalType(10, 5)).produces(new BoundVariables().setLongVariable("p", 10L).setLongVariable("s", 5L));
assertThat(function).boundTo(createDecimalType(10, 8), createDecimalType(9, 8)).withCoercion().produces(new BoundVariables().setLongVariable("p", 10L).setLongVariable("s", 8L));
assertThat(function).boundTo(createDecimalType(10, 2), createDecimalType(10, 8)).withCoercion().produces(new BoundVariables().setLongVariable("p", 16L).setLongVariable("s", 8L));
assertThat(function).boundTo(UNKNOWN, createDecimalType(10, 5)).withCoercion().produces(new BoundVariables().setLongVariable("p", 10L).setLongVariable("s", 5L));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindDifferentLiteralParameters.
@Test
public void testBindDifferentLiteralParameters() {
TypeSignature argType = new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p"), TypeSignatureParameter.typeVariable("s"));
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(argType, argType).build();
assertThat(function).boundTo(createDecimalType(2, 1), createDecimalType(3, 1)).fails();
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindUnknownToTypeParameter.
@Test
public void testBindUnknownToTypeParameter() {
Signature function = functionSignature().returnType(new TypeSignature("T")).argumentTypes(new TypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(function).boundTo(UNKNOWN).withCoercion().produces(new BoundVariables().setTypeVariable("T", UNKNOWN));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindUnknownToVariadic.
@Test
public void testBindUnknownToVariadic() {
Signature rowFunction = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(new TypeSignature("T"), new TypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "row"))).build();
assertThat(rowFunction).boundTo(UNKNOWN, RowType.from(ImmutableList.of(RowType.field("a", BIGINT)))).withCoercion().produces(new BoundVariables().setTypeVariable("T", RowType.from(ImmutableList.of(RowType.field("a", BIGINT)))));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testCoercion.
@Test
public void testCoercion() {
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(new TypeSignature("T"), DOUBLE.getTypeSignature()).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(function).boundTo(DOUBLE, DOUBLE).withCoercion().produces(new BoundVariables().setTypeVariable("T", DOUBLE));
assertThat(function).boundTo(BIGINT, BIGINT).withCoercion().produces(new BoundVariables().setTypeVariable("T", BIGINT));
assertThat(function).boundTo(VARCHAR, BIGINT).withCoercion().produces(new BoundVariables().setTypeVariable("T", VARCHAR));
assertThat(function).boundTo(BIGINT, VARCHAR).withCoercion().fails();
}
Aggregations