Search in sources :

Example 76 with Signature

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

the class TestSignatureBinder method testBindUnknown.

@Test
public void testBindUnknown() {
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).build();
    assertThat(function).boundTo("unknown").fails();
    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 77 with Signature

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

the class TestSignatureBinder method testNoVariableReuseAcrossTypes.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testNoVariableReuseAcrossTypes() {
    Set<String> literalParameters = ImmutableSet.of("p1", "p2", "s");
    TypeSignature leftType = parseTypeSignature("decimal(p1,s)", literalParameters);
    TypeSignature rightType = parseTypeSignature("decimal(p2,s)", literalParameters);
    Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(leftType, rightType).build();
    assertThat(function).boundTo("decimal(2,1)", "decimal(3,1)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of()));
}
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)

Example 78 with Signature

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

the class TestSignatureBinder method testVarArgs.

@Test
public void testVarArgs() {
    Signature variableArityFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).setVariableArity(true).build();
    assertThat(variableArityFunction).boundTo("bigint").produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
    assertThat(variableArityFunction).boundTo("varchar").produces(new BoundVariables(ImmutableMap.of("T", type("varchar")), ImmutableMap.of()));
    assertThat(variableArityFunction).boundTo("bigint", "bigint").produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
    assertThat(variableArityFunction).boundTo("bigint", "varchar").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 79 with Signature

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

the class TestSignatureBinder method testBindLiteralForRepeatedVarcharWithReturn.

@Test
public void testBindLiteralForRepeatedVarcharWithReturn() {
    TypeSignature leftType = parseTypeSignature("varchar(x)", ImmutableSet.of("x"));
    TypeSignature rightType = parseTypeSignature("varchar(x)", ImmutableSet.of("x"));
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(leftType, rightType).build();
    assertThat(function).boundTo("varchar(44)", "varchar(44)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 44L)));
    assertThat(function).boundTo("varchar(44)", "varchar(42)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 44L)));
    assertThat(function).boundTo("varchar(42)", "varchar(44)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 44L)));
    assertThat(function).boundTo("unknown", "varchar(44)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 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)

Example 80 with Signature

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

the class TestSignatureBinder method testUnknownCoercion.

@Test
public void testUnknownCoercion() {
    Signature foo = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
    assertThat(foo).boundTo("unknown", "unknown").produces(new BoundVariables(ImmutableMap.of("T", type("unknown")), ImmutableMap.of()));
    assertThat(foo).boundTo("unknown", "bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
    assertThat(foo).boundTo("varchar", "bigint").withCoercion().fails();
    Signature bar = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(comparableTypeParameter("T"))).build();
    assertThat(bar).boundTo("unknown", "bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
    assertThat(bar).boundTo("varchar", "bigint").withCoercion().fails();
    assertThat(bar).boundTo("HyperLogLog", "HyperLogLog").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)

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