Search in sources :

Example 86 with Signature

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

the class TestSignatureBinder method testBindUnknownToVariadic.

@Test
public void testBindUnknownToVariadic() {
    Signature rowFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "row"))).build();
    assertThat(rowFunction).boundTo("unknown", "row(a bigint)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("row(a bigint)")), ImmutableMap.of()));
    Signature arrayFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "array"))).build();
    assertThat(arrayFunction).boundTo("unknown", "array(bigint)").withCoercion().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)

Example 87 with Signature

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

the class TestSignatureBinder method testBindTypeVariablesBasedOnTheSecondArgument.

@Test
public void testBindTypeVariablesBasedOnTheSecondArgument() {
    Signature function = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
    assertThat(function).boundTo("unknown", "decimal(2,1)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("decimal(2,1)")), 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 88 with Signature

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

the class TestSignatureBinder method testBindUnknownToDecimal.

@Test
public void testBindUnknownToDecimal() {
    Signature function = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("decimal(p,s)", ImmutableSet.of("p", "s"))).build();
    assertThat(function).boundTo("unknown").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 1L, "s", 0L)));
}
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 89 with Signature

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

the class TestSignatureBinder method testVariadic.

@Test
public void testVariadic() {
    Signature mapVariadicBoundFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BIGINT)).argumentTypes(parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "map"))).build();
    assertThat(mapVariadicBoundFunction).boundTo("map(bigint,bigint)").produces(new BoundVariables(ImmutableMap.of("T", type("map(bigint,bigint)")), ImmutableMap.of()));
    assertThat(mapVariadicBoundFunction).boundTo("array(bigint)").fails();
    assertThat(mapVariadicBoundFunction).boundTo("array(bigint)").withCoercion().fails();
    Signature decimalVariadicBoundFunction = functionSignature().returnType(parseTypeSignature("bigint")).argumentTypes(parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "decimal"))).build();
    assertThat(decimalVariadicBoundFunction).boundTo("decimal(2,1)").produces(new BoundVariables(ImmutableMap.of("T", type("decimal(2,1)")), ImmutableMap.of()));
    assertThat(decimalVariadicBoundFunction).boundTo("bigint").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 90 with Signature

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

the class TestSignatureBinder method testBindLiteralForVarchar.

@Test
public void testBindLiteralForVarchar() {
    TypeSignature leftType = parseTypeSignature("varchar(x)", ImmutableSet.of("x"));
    TypeSignature rightType = parseTypeSignature("varchar(y)", ImmutableSet.of("y"));
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(leftType, rightType).build();
    assertThat(function).boundTo("varchar(42)", "varchar(44)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 42L, "y", 44L)));
    assertThat(function).boundTo("unknown", "varchar(44)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 0L, "y", 44L)));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) 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