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)));
}
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();
}
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();
}
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();
}
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();
}
Aggregations