Search in sources :

Example 81 with Signature

use of com.facebook.presto.spi.function.Signature in project presto by prestodb.

the class TestSignatureBinder method testBindPartialDecimal.

@Test
public void testBindPartialDecimal() {
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("decimal(4,s)", ImmutableSet.of("s"))).build();
    assertThat(function).boundTo("decimal(2,1)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("s", 1L)));
    function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("decimal(p,1)", ImmutableSet.of("p"))).build();
    assertThat(function).boundTo("decimal(2,0)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 3L)));
    assertThat(function).boundTo("decimal(2,1)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 2L)));
    assertThat(function).boundTo("bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 20L)));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) Test(org.testng.annotations.Test)

Example 82 with Signature

use of com.facebook.presto.spi.function.Signature in project presto by prestodb.

the class TestSignatureBinder method testBindUnknownToConcreteArray.

@Test
public void testBindUnknownToConcreteArray() {
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("array(boolean)")).build();
    assertThat(function).boundTo("unknown").withCoercion().succeeds();
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) Test(org.testng.annotations.Test)

Example 83 with Signature

use of com.facebook.presto.spi.function.Signature in project presto by prestodb.

the class TestSignatureBinder method testBindVarchar.

@Test
public void testBindVarchar() {
    Signature function = functionSignature().returnType(parseTypeSignature("varchar(42)")).argumentTypes(parseTypeSignature("varchar(42)")).build();
    assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(1)").fails();
    assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(1)").withCoercion().fails();
    assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(42)").withCoercion().succeeds();
    assertThat(function).boundTo(ImmutableList.of("varchar(44)"), "varchar(44)").withCoercion().fails();
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) Test(org.testng.annotations.Test)

Example 84 with Signature

use of com.facebook.presto.spi.function.Signature in project presto by prestodb.

the class TestSignatureBinder method testRow.

@Test
public void testRow() {
    Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(parseTypeSignature("row(integer)")).build();
    assertThat(function).boundTo("row(tinyint)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of()));
    assertThat(function).boundTo("row(integer)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of()));
    assertThat(function).boundTo("row(bigint)").withCoercion().fails();
    Signature biFunction = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(parseTypeSignature("row(T)"), parseTypeSignature("row(T)")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
    assertThat(biFunction).boundTo("row(bigint)", "row(bigint)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
    assertThat(biFunction).boundTo("row(integer)", "row(bigint)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) Test(org.testng.annotations.Test)

Example 85 with Signature

use of com.facebook.presto.spi.function.Signature in project presto by prestodb.

the class TestSignatureBinder method testBasic.

@Test
public void testBasic() {
    Signature function = functionSignature().typeVariableConstraints(ImmutableList.of(typeVariable("T"))).returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("T")).build();
    assertThat(function).boundTo("bigint").produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
    assertThat(function).boundTo("varchar").produces(new BoundVariables(ImmutableMap.of("T", type("varchar")), ImmutableMap.of()));
    assertThat(function).boundTo("varchar", "bigint").fails();
    assertThat(function).boundTo("array(bigint)").produces(new BoundVariables(ImmutableMap.of("T", type("array(bigint)")), ImmutableMap.of()));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) Test(org.testng.annotations.Test)

Aggregations

Signature (com.facebook.presto.spi.function.Signature)90 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)79 TypeSignature (com.facebook.presto.common.type.TypeSignature)73 Test (org.testng.annotations.Test)64 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)16 ParametricAggregation (com.facebook.presto.operator.aggregation.ParametricAggregation)14 ImmutableList (com.google.common.collect.ImmutableList)14 AggregationImplementation (com.facebook.presto.operator.aggregation.AggregationImplementation)13 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)13 StandardTypes (com.facebook.presto.common.type.StandardTypes)12 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)12 ParametricScalar (com.facebook.presto.operator.scalar.ParametricScalar)12 PrestoException (com.facebook.presto.spi.PrestoException)12 SCALAR (com.facebook.presto.spi.function.FunctionKind.SCALAR)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 Slice (io.airlift.slice.Slice)12 BuiltInScalarFunctionImplementation (com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation)11 ADD (com.facebook.presto.common.function.OperatorType.ADD)10 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)10 Math.toIntExact (java.lang.Math.toIntExact)10