Search in sources :

Example 26 with TypeSignature

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();
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) ImmutableList(com.google.common.collect.ImmutableList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList)

Example 27 with TypeSignature

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();
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 28 with TypeSignature

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()));
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 29 with TypeSignature

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)));
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 30 with TypeSignature

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)));
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Aggregations

TypeSignature (com.facebook.presto.spi.type.TypeSignature)34 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)19 ImmutableList (com.google.common.collect.ImmutableList)14 NamedTypeSignature (com.facebook.presto.spi.type.NamedTypeSignature)10 Test (org.testng.annotations.Test)10 Signature (com.facebook.presto.metadata.Signature)9 PrestoException (com.facebook.presto.spi.PrestoException)8 Type (com.facebook.presto.spi.type.Type)6 TypeSignatureParameter (com.facebook.presto.spi.type.TypeSignatureParameter)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 Slice (io.airlift.slice.Slice)6 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)5 SCALAR (com.facebook.presto.metadata.FunctionKind.SCALAR)5 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)5 SqlScalarFunctionBuilder (com.facebook.presto.metadata.SqlScalarFunctionBuilder)5 SpecializeContext (com.facebook.presto.metadata.SqlScalarFunctionBuilder.SpecializeContext)5 SqlType (com.facebook.presto.spi.function.SqlType)5 DecimalType (com.facebook.presto.spi.type.DecimalType)5 Decimals (com.facebook.presto.spi.type.Decimals)5 Decimals.encodeUnscaledValue (com.facebook.presto.spi.type.Decimals.encodeUnscaledValue)5