Search in sources :

Example 56 with TypeSignature

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));
}
Also used : 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 57 with TypeSignature

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();
}
Also used : 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 58 with TypeSignature

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));
}
Also used : 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 59 with TypeSignature

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)))));
}
Also used : 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 60 with TypeSignature

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();
}
Also used : 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

TypeSignature (io.trino.spi.type.TypeSignature)78 Test (org.testng.annotations.Test)49 TypeSignatureTranslator.parseTypeSignature (io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature)35 ImmutableList (com.google.common.collect.ImmutableList)19 Signature (io.trino.metadata.Signature)17 NamedTypeSignature (io.trino.spi.type.NamedTypeSignature)17 Type (io.trino.spi.type.Type)15 ArrayType (io.trino.spi.type.ArrayType)14 List (java.util.List)13 BoundSignature (io.trino.metadata.BoundSignature)11 Optional (java.util.Optional)10 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableSet (com.google.common.collect.ImmutableSet)9 TrinoException (io.trino.spi.TrinoException)9 DecimalType (io.trino.spi.type.DecimalType)9 TypeSignatureParameter (io.trino.spi.type.TypeSignatureParameter)9 Objects.requireNonNull (java.util.Objects.requireNonNull)9 BIGINT (io.trino.spi.type.BigintType.BIGINT)8 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)7 ADD (io.trino.spi.function.OperatorType.ADD)7