String variableName = typeSignatureParameter.getVariable(); if (!bindings.containsLongVariable(variableName) || !bindings.getLongVariable(variableName).equals(commonSuperLongLiteral)) { bindings.setLongVariable(variableName, commonSuperLongLiteral); result = SolverReturnStatus.CHANGED;
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); } }
String variableName = typeSignatureParameter.getVariable(); if (!bindings.containsLongVariable(variableName) || !bindings.getLongVariable(variableName).equals(commonSuperLongLiteral)) { bindings.setLongVariable(variableName, commonSuperLongLiteral); result = SolverReturnStatus.CHANGED;
InternalAggregationFunction specialized = aggregation.specialize( BoundVariables.builder() .setLongVariable("x", 17L) .setLongVariable("y", 13L) .setLongVariable("z", 30L) .build(), 2, typeRegistry, functionRegistry); assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(30));
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setLongVariable("x", 17L).build(), 1, typeRegistry, functionRegistry); assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(17)); assertTrue(specialized.isDecomposable());
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setLongVariable("x", 17L).build(), 1, typeRegistry, functionRegistry); assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(17)); assertTrue(specialized.isDecomposable());
InternalAggregationFunction specialized = aggregation.specialize( BoundVariables.builder() .setLongVariable("x", 17L) .setLongVariable("y", 13L) .setLongVariable("z", 30L) .build(), 2, typeRegistry, functionRegistry); assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(30));
@Test public void testBindParameters() { BoundVariables boundVariables = BoundVariables.builder() .setTypeVariable("T1", DOUBLE) .setTypeVariable("T2", BIGINT) .setTypeVariable("T3", DecimalType.createDecimalType(5, 3)) .setLongVariable("p", 1L) .setLongVariable("s", 2L) .build(); assertThat("bigint", boundVariables, "bigint"); assertThat("T1", boundVariables, "double"); assertThat("T2", boundVariables, "bigint"); assertThat("array(T1)", boundVariables, "array(double)"); assertThat("array(T3)", boundVariables, "array(decimal(5,3))"); assertThat("array<T1>", boundVariables, "array(double)"); assertThat("map(T1,T2)", boundVariables, "map(double,bigint)"); assertThat("map<T1,T2>", boundVariables, "map(double,bigint)"); assertThat("bla(T1,42,T2)", boundVariables, "bla(double,42,bigint)"); assertThat("varchar(p)", boundVariables, "varchar(1)"); assertThat("char(p)", boundVariables, "char(1)"); assertThat("decimal(p,s)", boundVariables, "decimal(1,2)"); assertThat("array(decimal(p,s))", boundVariables, "array(decimal(1,2))"); assertBindVariablesFails("T1(bigint)", boundVariables, "Unbounded parameters can not have parameters"); }
@Test public void testBindParameters() { BoundVariables boundVariables = BoundVariables.builder() .setTypeVariable("T1", DOUBLE) .setTypeVariable("T2", BIGINT) .setTypeVariable("T3", DecimalType.createDecimalType(5, 3)) .setLongVariable("p", 1L) .setLongVariable("s", 2L) .build(); assertThat("bigint", boundVariables, "bigint"); assertThat("T1", boundVariables, "double"); assertThat("T2", boundVariables, "bigint"); assertThat("array(T1)", boundVariables, "array(double)"); assertThat("array(T3)", boundVariables, "array(decimal(5,3))"); assertThat("array<T1>", boundVariables, "array(double)"); assertThat("map(T1,T2)", boundVariables, "map(double,bigint)"); assertThat("map<T1,T2>", boundVariables, "map(double,bigint)"); assertThat("bla(T1,42,T2)", boundVariables, "bla(double,42,bigint)"); assertThat("varchar(p)", boundVariables, "varchar(1)"); assertThat("char(p)", boundVariables, "char(1)"); assertThat("decimal(p,s)", boundVariables, "decimal(1,2)"); assertThat("array(decimal(p,s))", boundVariables, "array(decimal(1,2))"); assertBindVariablesFails("T1(bigint)", boundVariables, "Unbounded parameters can not have parameters"); }
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); } }
@Test public void testLearnLibSvm() { Type mapType = typeManager.getParameterizedType("map", ImmutableList.of(TypeSignatureParameter.of(parseTypeSignature(StandardTypes.BIGINT)), TypeSignatureParameter.of(parseTypeSignature(StandardTypes.DOUBLE)))); InternalAggregationFunction aggregation = AggregationFromAnnotationsParser.parseFunctionDefinitionWithTypesConstraint( LearnLibSvmClassifierAggregation.class, ClassifierType.BIGINT_CLASSIFIER.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature(), mapType.getTypeSignature(), VarcharType.getParametrizedVarcharSignature("x")) ).specialize(BoundVariables.builder().setLongVariable("x", (long) Integer.MAX_VALUE).build(), 3, typeManager); assertLearnClassifer(aggregation.bind(ImmutableList.of(0, 1, 2), Optional.empty()).createAccumulator()); }