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);
}
}
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");
}
Aggregations