use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindLiteralForVarchar.
@Test
public void testBindLiteralForVarchar() {
TypeSignature leftType = new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x"));
TypeSignature rightType = new TypeSignature("varchar", TypeSignatureParameter.typeVariable("y"));
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo(createVarcharType(42), createVarcharType(44)).produces(new BoundVariables().setLongVariable("x", 42L).setLongVariable("y", 44L));
assertThat(function).boundTo(UNKNOWN, createVarcharType(44)).withCoercion().produces(new BoundVariables().setLongVariable("x", 0L).setLongVariable("y", 44L));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testRow.
@Test
public void testRow() {
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(rowType(anonymousField(INTEGER.getTypeSignature()))).build();
assertThat(function).boundTo(RowType.anonymous(ImmutableList.of(TINYINT))).withCoercion().produces(NO_BOUND_VARIABLES);
assertThat(function).boundTo(RowType.anonymous(ImmutableList.of(INTEGER))).withCoercion().produces(NO_BOUND_VARIABLES);
assertThat(function).boundTo(RowType.anonymous(ImmutableList.of(BIGINT))).withCoercion().fails();
Signature biFunction = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(rowType(anonymousField(new TypeSignature("T"))), rowType(anonymousField(new TypeSignature("T")))).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(biFunction).boundTo(RowType.anonymous(ImmutableList.of(INTEGER)), RowType.anonymous(ImmutableList.of(BIGINT))).withCoercion().produces(new BoundVariables().setTypeVariable("T", BIGINT));
assertThat(biFunction).boundTo(RowType.anonymous(ImmutableList.of(INTEGER)), RowType.anonymous(ImmutableList.of(BIGINT))).withCoercion().produces(new BoundVariables().setTypeVariable("T", BIGINT));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindVarcharTemplateStyle.
@Test
public void testBindVarcharTemplateStyle() {
Signature function = functionSignature().returnType(new TypeSignature("T2")).argumentTypes(new TypeSignature("T1")).typeVariableConstraints(ImmutableList.of(new TypeVariableConstraint("T1", true, false, null, ImmutableSet.of(), ImmutableSet.of()), new TypeVariableConstraint("T2", true, false, null, ImmutableSet.of(), ImmutableSet.of()))).build();
assertThat(function).boundTo(ImmutableList.of(createVarcharType(42)), createVarcharType(1)).produces(new BoundVariables().setTypeVariable("T1", createVarcharType(42)).setTypeVariable("T2", createVarcharType(1)));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testCanCoerceFrom.
@Test
public void testCanCoerceFrom() {
Signature arrayJoin = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(arrayType(new TypeSignature("E")), JSON.getTypeSignature()).typeVariableConstraints(castableFromTypeParameter("E", JSON.getTypeSignature())).build();
assertThat(arrayJoin).boundTo(new ArrayType(INTEGER), JSON).produces(new BoundVariables().setTypeVariable("E", INTEGER));
assertThat(arrayJoin).boundTo(new ArrayType(VARBINARY)).fails();
Signature multiCast = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(arrayType(new TypeSignature("E")), JSON.getTypeSignature()).typeVariableConstraints(castableFromTypeParameter("E", VARCHAR.getTypeSignature(), JSON.getTypeSignature())).build();
assertThat(multiCast).boundTo(new ArrayType(TINYINT), JSON).produces(new BoundVariables().setTypeVariable("E", TINYINT));
assertThat(multiCast).boundTo(new ArrayType(TIMESTAMP_MILLIS), JSON).fails();
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testVarArgs.
@Test
public void testVarArgs() {
Signature variableArityFunction = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(new TypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).setVariableArity(true).build();
assertThat(variableArityFunction).boundTo(BIGINT).produces(new BoundVariables().setTypeVariable("T", BIGINT));
assertThat(variableArityFunction).boundTo(VARCHAR).produces(new BoundVariables().setTypeVariable("T", VARCHAR));
assertThat(variableArityFunction).boundTo(BIGINT, BIGINT).produces(new BoundVariables().setTypeVariable("T", BIGINT));
assertThat(variableArityFunction).boundTo(BIGINT, VARCHAR).withCoercion().fails();
}
Aggregations