private String generateEqualityString( List<Expression> equalities, List<List<FormulaVariable>> variables, boolean with) { StringBuilder localResult = new StringBuilder(); StringBuilder prefix = new StringBuilder(); if (useSaveFormat) { if (with) { prefix.append("\n").append(generateIndent()).append("with "); } else { prefix.append(",\n").append(generateIndent()); } } else { prefix.append(",\n").append(generateIndent()); } for (int i = 0; i < equalities.size(); i++) { Expression expression = equalities.get(i).clone(); if (utility.setVariableDescriptions(expression, variables)) { if (useSaveFormat) { String expressionString = expression.toSaveString(); if (with) { expressionString = expressionString.replaceAll("==", "="); } localResult.append(expressionString); } else { localResult.append(expression.toString()); } if (i != equalities.size() - 1) { localResult.append(", "); } } } if (!localResult.toString().isEmpty()) { localResult.insert(0, prefix.toString()); } return localResult.toString(); }
public String convertToPostgres(Expression transformationFunctionExpression, boolean withRel) { String functionExpression = transformationFunctionExpression.getJepExpression().toStringForSql(); // first fix attribute names for (VariablePathExpression vpe : transformationFunctionExpression.getAttributePaths()) { if (functionExpression.contains(vpe.toString())) { String expressionToCheckForSigns = transformationFunctionExpression.getJepExpression().toString(); int startIndex = expressionToCheckForSigns.indexOf(vpe.toString()); int endIndex = startIndex + vpe.toString().length(); boolean castToFloat = false; // check so that the String index will not get out of bounds if (startIndex - 2 >= 0) { if (math_sign.contains(expressionToCheckForSigns.charAt(startIndex - 2))) { castToFloat = true; } // to catch the '>=' or '<=' case else if (expressionToCheckForSigns.charAt(startIndex - 2) == '=' && startIndex - 3 >= 0) { if (expressionToCheckForSigns.charAt(startIndex - 3) == '<' || expressionToCheckForSigns.charAt(startIndex - 3) == '>') { castToFloat = true; } } } if (endIndex + 2 <= expressionToCheckForSigns.length()) { if (math_sign.contains(expressionToCheckForSigns.charAt(endIndex + 1))) { castToFloat = true; } } String newAttrName; // replace them with the corresponding attribute name if (withRel) { newAttrName = GenerateSQL.attributeNameWithVariable(vpe); } else { newAttrName = GenerateSQL.attributeNameInVariable(vpe); } // if previous or next character is one of {+,-,*,/,<,>} cast it to float if (castToFloat) { functionExpression = functionExpression.replaceAll(vpe.toString(), "cast(" + newAttrName + " as float)"); } else { functionExpression = functionExpression.replaceAll(vpe.toString(), newAttrName); } } } return replaceExpression(functionExpression); }
public VariableSelectionCondition clone() { try { VariableSelectionCondition clone = (VariableSelectionCondition) super.clone(); clone.condition = condition.clone(); return clone; } catch (CloneNotSupportedException ex) { return null; } }
private static String sqlString(Expression expression) { String result = ""; List<VariablePathExpression> attributePaths = expression.getAttributePaths(); if (expression.toString().startsWith("isNull(")) { String attributeName = extractAttributeNameFromExpression(attributePaths.get(0)); return attributeName + " IS NULL"; } if (expression.toString().startsWith("isNotNull(")) { String attributeName = extractAttributeNameFromExpression(attributePaths.get(0)); return attributeName + " IS NOT NULL"; } for (VariablePathExpression attributePath : attributePaths) { String attributeName = extractAttributeNameFromExpression(attributePaths.get(0)); result = expression.toString().replaceAll(attributePath.toString(), attributeName); } result = result.replaceAll("==", "="); result = result.replaceAll("\"", "\'"); return result.replaceAll("&&", "AND"); }
private String generateBuiltinsForSelections(ComplexConjunctiveQuery query) { StringBuilder localResult = new StringBuilder(); if (query.getAllSelections().size() > 0) { localResult.append(", "); } for (int i = 0; i < query.getAllSelections().size(); i++) { VariableSelectionCondition selection = query.getAllSelections().get(i); Expression expression = selection.getCondition().clone(); utility.setVariableDescriptions(expression, variables); if (useSaveFormat) { String expressionString = expression.toSaveString(); localResult.append(expressionString); } else { localResult.append(expression.toString()); } if (i != query.getAllSelections().size() - 1) { localResult.append(", "); } } return localResult.toString(); }