private static Function get_CONCAT(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { return (Function) terms.stream() // left recursion to match || in JSQLParser .reduce(null, (a, b) -> (a == null) ? b : TERM_FACTORY.getFunction(ExpressionOperation.CONCAT, a, b)); }
private Function get_CONCAT(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { return (Function) terms.stream() // left recursion to match || in JSQLParser .reduce(null, (a, b) -> (a == null) ? b : termFactory.getFunction(ExpressionOperation.CONCAT, a, b)); }
private static Function get_SUBSTR(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { switch (terms.size()) { case 2: return TERM_FACTORY.getFunction(ExpressionOperation.SUBSTR2, terms.get(0), terms.get(1)); case 3: return TERM_FACTORY.getFunction(ExpressionOperation.SUBSTR3, terms.get(0), terms.get(1), terms.get(2)); } // DB2 has 4 throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private Term getNestedConcat(String str) { ArrayList<Term> terms; terms = addToTermsList(str); if (terms.size() == 1) { return terms.get(0); } Function f = TERM_FACTORY.getFunction(ExpressionOperation.CONCAT, terms.get(0), terms.get(1)); for (int j = 2; j < terms.size(); j++) { f = TERM_FACTORY.getFunction(ExpressionOperation.CONCAT, f, terms.get(j)); } return f; }
private Function get_SUBSTR(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { switch (terms.size()) { case 2: return termFactory.getFunction(ExpressionOperation.SUBSTR2, terms.get(0), terms.get(1)); case 3: return termFactory.getFunction(ExpressionOperation.SUBSTR3, terms.get(0), terms.get(1), terms.get(2)); } // DB2 has 4 throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private Function get_STRLEN(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { if (terms.size() == 1) return termFactory.getFunction(ExpressionOperation.STRLEN, terms.get(0)); throw new InvalidSelectQueryRuntimeException("Wrong number of arguments in SQL function", expression); }
private Function get_LCASE(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { if (terms.size() == 1) return termFactory.getFunction(ExpressionOperation.LCASE, terms.get(0)); // DB2 has 3 throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private static Function get_RAND(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { switch (terms.size()) { case 0: return TERM_FACTORY.getFunction(ExpressionOperation.RAND); } throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private static Function get_LCASE(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { if (terms.size() == 1) return TERM_FACTORY.getFunction(ExpressionOperation.LCASE, terms.get(0)); // DB2 has 3 throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private static Function get_STRLEN(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { if (terms.size() == 1) return TERM_FACTORY.getFunction(ExpressionOperation.STRLEN, terms.get(0)); throw new InvalidSelectQueryRuntimeException("Wrong number of arguments in SQL function", expression); }
private Function get_UCASE(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { if (terms.size() == 1) return termFactory.getFunction(ExpressionOperation.UCASE, terms.get(0)); // DB2 has 3 throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private Function get_RAND(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { switch (terms.size()) { case 0: return termFactory.getFunction(ExpressionOperation.RAND); } throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private static Function get_UCASE(ImmutableList<Term> terms, net.sf.jsqlparser.expression.Function expression) { if (terms.size() == 1) return TERM_FACTORY.getFunction(ExpressionOperation.UCASE, terms.get(0)); // DB2 has 3 throw new UnsupportedSelectQueryRuntimeException("Unsupported SQL function", expression); }
private Function getFreshHead(List<Term> terms) { Predicate pred = datalogFactory.getSubqueryPredicate("" + predicateIdx, terms.size()); predicateIdx++; return termFactory.getFunction(pred, terms); }
public static Function getAtom(RelationDefinition r, List<Term> terms) { if (r.getAttributes().size() != terms.size()) throw new IllegalArgumentException("The number of terms does not match the arity of relation"); Predicate pred = createPredicateFromRelation(r); return TERM_FACTORY.getFunction(pred, terms); }
public TMappingIndexEntry copyOf(Predicate newPredicate) { TMappingIndexEntry copy = new TMappingIndexEntry(); for (TMappingRule rule : rules) { Function newHead = TERM_FACTORY.getFunction(newPredicate, rule.getHeadTerms()); TMappingRule newRule = new TMappingRule(newHead, rule); copy.rules.add(newRule); } return copy; }
private CQIE createRule(DatalogProgram pr, String headName, List<Term> headParameters, Function... body) { Predicate pred = datalogFactory.getSubqueryPredicate(headName, headParameters.size()); Function head = termFactory.getFunction(pred, headParameters); CQIE rule = datalogFactory.getCQIE(head, body); pr.appendRule(rule); return rule; }
private Term evalIfElseNull(Function term) { Term formerCondition = term.getTerm(0); Term newCondition = eval(formerCondition); if (newCondition.equals(formerCondition)) return term; else if (newCondition.equals(TermConstants.FALSE)) return TermConstants.NULL; else if (newCondition.equals(TermConstants.TRUE)) return term.getTerm(1); else return TERM_FACTORY.getFunction(term.getFunctionSymbol(), newCondition, term.getTerm(1)); }
private Term evalIfElseNull(Function term) { Term formerCondition = term.getTerm(0); Term newCondition = eval(formerCondition); if (newCondition.equals(formerCondition)) return term; else if (newCondition.equals(valueFalse)) return valueNull; else if (newCondition.equals(valueTrue)) return term.getTerm(1); else return termFactory.getFunction(term.getFunctionSymbol(), newCondition, term.getTerm(1)); }
private Function getFreshAtom(Function a, String suffix) { List<Term> termscopy = new ArrayList<>(a.getArity()); for (Term t : a.getTerms()) { if (t instanceof Variable) { Variable v = (Variable)t; termscopy.add(termFactory.getVariable(v.getName() + suffix)); } else termscopy.add(t.clone()); } return termFactory.getFunction(a.getFunctionSymbol(), termscopy); }