Search in sources :

Example 1 with LongVariableConstraint

use of io.prestosql.spi.function.LongVariableConstraint in project hetu-core by openlookeng.

the class SignatureBinder method calculateVariableValuesForLongConstraints.

private void calculateVariableValuesForLongConstraints(BoundVariables.Builder variableBinder) {
    for (LongVariableConstraint longVariableConstraint : declaredSignature.getLongVariableConstraints()) {
        String calculation = longVariableConstraint.getExpression();
        String variableName = longVariableConstraint.getName();
        Long calculatedValue = calculateLiteralValue(calculation, variableBinder.getLongVariables());
        if (variableBinder.containsLongVariable(variableName)) {
            Long currentValue = variableBinder.getLongVariable(variableName);
            checkState(Objects.equals(currentValue, calculatedValue), "variable '%s' is already set to %s when trying to set %s", variableName, currentValue, calculatedValue);
        }
        variableBinder.setLongVariable(variableName, calculatedValue);
    }
}
Also used : LongVariableConstraint(io.prestosql.spi.function.LongVariableConstraint)

Example 2 with LongVariableConstraint

use of io.prestosql.spi.function.LongVariableConstraint in project hetu-core by openlookeng.

the class TestAnnotationEngineForAggregates method testLongConstraintAggregateFunctionParse.

@Test
public void testLongConstraintAggregateFunctionParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_aggregate_long_constraint"), FunctionKind.AGGREGATE, ImmutableList.of(), ImmutableList.of(new LongVariableConstraint("z", "x + y")), parseTypeSignature("varchar(z)", ImmutableSet.of("z")), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x")), parseTypeSignature("varchar(y)", ImmutableSet.of("y"))), false);
    ParametricAggregation aggregation = parseFunctionDefinition(LongConstraintAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Parametric aggregate with parametric type returned");
    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(), LongConstraintAggregateFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setLongVariable("x", 17L).setLongVariable("y", 13L).setLongVariable("z", 30L).build(), 2, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(30));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "parametric_aggregate_long_constraint");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) LongVariableConstraint(io.prestosql.spi.function.LongVariableConstraint) 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

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