Search in sources :

Example 71 with Signature

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

the class TestSignatureBinder method testBindLiteralForDecimal.

@Test
public void testBindLiteralForDecimal() {
    TypeSignature leftType = parseTypeSignature("decimal(p1,s1)", ImmutableSet.of("p1", "s1"));
    TypeSignature rightType = parseTypeSignature("decimal(p2,s2)", ImmutableSet.of("p2", "s2"));
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(leftType, rightType).build();
    assertThat(function).boundTo("decimal(2,1)", "decimal(1,0)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p1", 2L, "s1", 1L, "p2", 1L, "s2", 0L)));
}
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 72 with Signature

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

the class TestSignatureBinder method testBindDifferentLiteralParameters.

@Test
public void testBindDifferentLiteralParameters() {
    TypeSignature argType = parseTypeSignature("decimal(p,s)", ImmutableSet.of("p", "s"));
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(argType, argType).build();
    assertThat(function).boundTo("decimal(2,1)", "decimal(3,1)").fails();
}
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 73 with Signature

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

the class TestSignatureBinder method testCoercion.

@Test
public void testCoercion() {
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("T"), parseTypeSignature(StandardTypes.DOUBLE)).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
    assertThat(function).boundTo("double", "double").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("double")), ImmutableMap.of()));
    assertThat(function).boundTo("bigint", "bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
    assertThat(function).boundTo("varchar", "bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("varchar")), ImmutableMap.of()));
    assertThat(function).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 74 with Signature

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

the class TestSignatureBinder method testMismatchedArgumentCount.

@Test
public void testMismatchedArgumentCount() {
    Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT)).build();
    assertThat(function).boundTo("bigint", "bigint", "bigint").fails();
    assertThat(function).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 75 with Signature

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

the class TestSignatureBinder method testMap.

@Test
public void testMap() {
    Signature getValueFunction = functionSignature().returnType(parseTypeSignature("V")).argumentTypes(parseTypeSignature("map(K,V)"), parseTypeSignature("K")).typeVariableConstraints(ImmutableList.of(typeVariable("K"), typeVariable("V"))).build();
    assertThat(getValueFunction).boundTo("map(bigint,varchar)", "bigint").produces(new BoundVariables(ImmutableMap.of("K", type("bigint"), "V", type("varchar")), ImmutableMap.of()));
    assertThat(getValueFunction).boundTo("map(bigint,varchar)", "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)

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