use of com.facebook.presto.spi.type.TypeSignature in project presto by prestodb.
the class SignatureBinder method expandVarargFormalTypeSignature.
private static List<TypeSignature> expandVarargFormalTypeSignature(List<TypeSignature> formalTypeSignatures, int actualArity) {
int variableArityArgumentsCount = actualArity - formalTypeSignatures.size() + 1;
if (variableArityArgumentsCount == 0) {
return formalTypeSignatures.subList(0, formalTypeSignatures.size() - 1);
}
if (variableArityArgumentsCount == 1) {
return formalTypeSignatures;
}
checkArgument(variableArityArgumentsCount > 1 && !formalTypeSignatures.isEmpty());
ImmutableList.Builder<TypeSignature> builder = ImmutableList.builder();
builder.addAll(formalTypeSignatures);
TypeSignature lastTypeSignature = formalTypeSignatures.get(formalTypeSignatures.size() - 1);
for (int i = 1; i < variableArityArgumentsCount; i++) {
builder.add(lastTypeSignature);
}
return builder.build();
}
use of com.facebook.presto.spi.type.TypeSignature in project presto by prestodb.
the class TestSignatureBinder method testBindDifferentLiteralParameters.
@Test
public void testBindDifferentLiteralParameters() throws Exception {
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.type.TypeSignature in project presto by prestodb.
the class TestSignatureBinder method testNoVariableReuseAcrossTypes.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testNoVariableReuseAcrossTypes() throws Exception {
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()));
}
use of com.facebook.presto.spi.type.TypeSignature 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.type.TypeSignature 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)));
}
Aggregations