Search in sources :

Example 1 with LiteralImplementationDependency

use of io.prestosql.operator.annotations.LiteralImplementationDependency in project hetu-core by openlookeng.

the class TestAnnotationEngineForAggregates method testInjectLiteralAggregateParse.

@Test
public void testInjectLiteralAggregateParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("inject_literal_aggregate"), FunctionKind.AGGREGATE, parseTypeSignature("varchar(x)", ImmutableSet.of("x")), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))));
    ParametricAggregation aggregation = parseFunctionDefinition(InjectLiteralAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with type literal");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertEquals(implementations.getGenericImplementations().size(), 1);
    AggregationImplementation implementation = implementations.getGenericImplementations().get(0);
    assertTrue(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), InjectLiteralAggregateFunction.class);
    assertDependencyCount(implementation, 1, 1, 1);
    assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
    assertTrue(implementation.getInputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getCombineDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getOutputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof LiteralImplementationDependency);
    assertFalse(implementation.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setLongVariable("x", 17L).build(), 1, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(17));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "inject_literal_aggregate");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) 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 2 with LiteralImplementationDependency

use of io.prestosql.operator.annotations.LiteralImplementationDependency in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testSimpleInjectionScalarParse.

@Test
public void testSimpleInjectionScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_scalar_inject"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SimpleInjectionScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 0, 1);
    List<ParametricScalarImplementationChoice> parametricScalarImplementationChoices = scalar.getImplementations().getGenericImplementations().get(0).getChoices();
    assertEquals(parametricScalarImplementationChoices.size(), 1);
    List<ImplementationDependency> dependencies = parametricScalarImplementationChoices.get(0).getDependencies();
    assertEquals(dependencies.size(), 1);
    assertTrue(dependencies.get(0) instanceof LiteralImplementationDependency);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar with literal injected");
}
Also used : TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Aggregations

LiteralImplementationDependency (io.prestosql.operator.annotations.LiteralImplementationDependency)2 Signature (io.prestosql.spi.function.Signature)2 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)2 Test (org.testng.annotations.Test)2 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)1 AggregationImplementation (io.prestosql.operator.aggregation.AggregationImplementation)1 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)1 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)1 ParametricAggregation (io.prestosql.operator.aggregation.ParametricAggregation)1 ImplementationDependency (io.prestosql.operator.annotations.ImplementationDependency)1 TypeImplementationDependency (io.prestosql.operator.annotations.TypeImplementationDependency)1 ParametricScalar (io.prestosql.operator.scalar.ParametricScalar)1 ParametricScalarImplementationChoice (io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)1 TypeSignature (io.prestosql.spi.type.TypeSignature)1