Search in sources :

Example 51 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class TestFunctionAndTypeManager method testExactMatchBeforeCoercion.

@Test
public void testExactMatchBeforeCoercion() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    boolean foundOperator = false;
    for (SqlFunction function : functionAndTypeManager.listOperators()) {
        OperatorType operatorType = tryGetOperatorType(function.getSignature().getName()).get();
        if (operatorType == CAST || operatorType == SATURATED_FLOOR_CAST) {
            continue;
        }
        if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
            continue;
        }
        if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
            continue;
        }
        BuiltInFunctionHandle exactOperator = (BuiltInFunctionHandle) functionAndTypeManager.resolveOperatorFunctionHandle(operatorType, fromTypeSignatures(function.getSignature().getArgumentTypes()));
        assertEquals(exactOperator.getSignature(), function.getSignature());
        foundOperator = true;
    }
    assertTrue(foundOperator);
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) FunctionAndTypeManager.createTestFunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) OperatorType(io.prestosql.spi.function.OperatorType) OperatorType.tryGetOperatorType(io.prestosql.spi.function.OperatorType.tryGetOperatorType) SqlFunction(io.prestosql.spi.function.SqlFunction) Test(org.testng.annotations.Test)

Example 52 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class TestFunctionRegistry method testExactMatchBeforeCoercion.

@Test
public void testExactMatchBeforeCoercion() {
    Metadata metadata = createTestMetadataManager();
    boolean foundOperator = false;
    for (SqlFunction function : listOperators(metadata)) {
        OperatorType operatorType = unmangleOperator(function.getSignature().getName().getObjectName());
        if (operatorType == OperatorType.CAST || operatorType == OperatorType.SATURATED_FLOOR_CAST) {
            continue;
        }
        if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
            continue;
        }
        if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
            continue;
        }
        List<Type> argumentTypes = function.getSignature().getArgumentTypes().stream().map(metadata::getType).collect(toImmutableList());
        Signature exactOperator = metadata.getFunctionAndTypeManager().resolveBuiltInFunction(QualifiedName.of(mangleOperatorName(operatorType)), fromTypes(argumentTypes));
        assertEquals(exactOperator, function.getSignature());
        foundOperator = true;
    }
    assertTrue(foundOperator);
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) SqlType(io.prestosql.spi.function.SqlType) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) OperatorType(io.prestosql.spi.function.OperatorType) SqlFunction(io.prestosql.spi.function.SqlFunction) Test(org.testng.annotations.Test)

Example 53 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

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.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 54 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class TestAnnotationEngineForAggregates method testSimpleExplicitSpecializedAggregationParse.

// TODO this is not yet supported
@Test(enabled = false)
public void testSimpleExplicitSpecializedAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("explicit_specialized_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.of(parseTypeSignature("T")))), false);
    ParametricAggregation aggregation = parseFunctionDefinition(ExplicitSpecializedAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple explicit specialized aggregate");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 1, 1);
    AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
    assertTrue(implementation1.hasSpecializedTypeParameters());
    assertFalse(implementation1.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation1.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
    assertTrue(implementation2.hasSpecializedTypeParameters());
    assertFalse(implementation2.hasSpecializedTypeParameters());
    assertTrue(implementation2.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "implicit_specialized_aggregate");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) ParametricAggregation(io.prestosql.operator.aggregation.ParametricAggregation) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 55 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class TestAnnotationEngineForAggregates method testSimpleImplicitSpecializedAggregationParse.

// TODO this is not yet supported
@Test(enabled = false)
public void testSimpleImplicitSpecializedAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("implicit_specialized_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.of(parseTypeSignature("T"))), parseTypeSignature("T")), false);
    ParametricAggregation aggregation = parseFunctionDefinition(ImplicitSpecializedAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple implicit specialized aggregate");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 0, 2);
    AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
    assertTrue(implementation1.hasSpecializedTypeParameters());
    assertFalse(implementation1.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation1.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
    assertTrue(implementation2.hasSpecializedTypeParameters());
    assertFalse(implementation2.hasSpecializedTypeParameters());
    assertTrue(implementation2.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "implicit_specialized_aggregate");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) ParametricAggregation(io.prestosql.operator.aggregation.ParametricAggregation) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Aggregations

TypeSignature (io.prestosql.spi.type.TypeSignature)79 Signature (io.prestosql.spi.function.Signature)36 Type (io.prestosql.spi.type.Type)27 Test (org.testng.annotations.Test)24 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)22 ImmutableList (com.google.common.collect.ImmutableList)18 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)18 CallExpression (io.prestosql.spi.relation.CallExpression)18 PrestoException (io.prestosql.spi.PrestoException)17 List (java.util.List)14 RowExpression (io.prestosql.spi.relation.RowExpression)12 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)11 RowType (io.prestosql.spi.type.RowType)11 ArrayList (java.util.ArrayList)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)10 ArrayType (io.prestosql.spi.type.ArrayType)10 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)10 HashSet (java.util.HashSet)10 Domain (io.prestosql.spi.predicate.Domain)9