private void buildAggregateQuery(DocumentNode node, Query outerQuery, ExpandDocumentNode expandResource, OrderBy expandOrder, Query query, EdmNavigationProperty navigationProperty) throws TeiidException { Select select = query.getSelect(); Array array = new Array(Object.class, new ArrayList<Expression>(select.getSymbols())); select.getSymbols().clear(); AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, array); select.addSymbol(symbol); symbol.setOrderBy(expandOrder); Criteria crit = node.buildJoinCriteria(expandResource, navigationProperty); if (crit != null) { query.setCriteria(Criteria.combineCriteria(crit, query.getCriteria())); } // else assertion error? expandResource.setColumnIndex(outerQuery.getSelect().getCount() + 1); ScalarSubquery agg = new ScalarSubquery(query); SubqueryHint subqueryHint = new SubqueryHint(); subqueryHint.setMergeJoin(true); agg.setSubqueryHint(subqueryHint); outerQuery.getSelect().addSymbol(agg); }
public PlannedResult findSubquery(Expression expr, boolean unnest, PlannedResult result) { if (expr instanceof ScalarSubquery) { ScalarSubquery scc = (ScalarSubquery)expr; if (scc.getSubqueryHint().isNoUnnest()) { return result; } Query query = (Query)scc.getCommand(); if (!isSingleRow(query)) { return result; } result.type = scc.getClass(); result.mergeJoin = scc.getSubqueryHint().isMergeJoin(); if (!unnest && !result.mergeJoin) { return result; } result.makeInd = scc.getSubqueryHint().isDepJoin(); result.query = query; } return result; }
SubqueryHint getSubqueryHint(Token t) { SubqueryHint hint = new SubqueryHint(); String[] parts = getComment(t).split("\\s"); //$NON-NLS-1$ for (int i = 0; i < parts.length; i++) { if (parts[i].equalsIgnoreCase(SubqueryHint.MJ)) { hint.setMergeJoin(true); } else if (parts[i].equalsIgnoreCase(SubqueryHint.NOUNNEST)) { hint.setNoUnnest(true); } else if (parts[i].equalsIgnoreCase(SubqueryHint.DJ)) { hint.setDepJoin(); } } return hint; }
ec.setSubqueryHint(new ExistsCriteria.SubqueryHint()); ec.getSubqueryHint().setDepJoin(); ec.setCommand(query); Criteria existing = stagableQuery.getCriteria();
if (ssc.getSubqueryHint().isNoUnnest()) { return result; if (cc.getRightExpression() instanceof ScalarSubquery) { ScalarSubquery ss = (ScalarSubquery)cc.getRightExpression(); if (ss.getSubqueryHint().isNoUnnest()) { return result; if (ss.getSubqueryHint().isNoUnnest()) { return result; if (scc.getSubqueryHint().isNoUnnest()) { return result; result.mergeJoin = scc.getSubqueryHint().isMergeJoin(); if (!unnest && !result.mergeJoin) { return result; result.makeInd = scc.getSubqueryHint().isDepJoin(); result.query = query; result.additionalCritieria = (CompareCriteria)new CompareCriteria(scc.getLeftExpression(), scc.getOperator(), rightExpr).clone(); if (exists.getSubqueryHint().isNoUnnest()) { return result; result.mergeJoin = exists.getSubqueryHint().isMergeJoin(); result.makeInd = exists.getSubqueryHint().isDepJoin(); if (!unnest && !result.mergeJoin) { return result;
if (ssc.getSubqueryHint().isNoUnnest()) { return result; if (cc.getRightExpression() instanceof ScalarSubquery) { ScalarSubquery ss = (ScalarSubquery)cc.getRightExpression(); if (ss.getSubqueryHint().isNoUnnest()) { return result; if (ss.getSubqueryHint().isNoUnnest()) { return result; if (scc.getSubqueryHint().isNoUnnest()) { return result; result.mergeJoin = scc.getSubqueryHint().isMergeJoin(); if (!unnest && !result.mergeJoin) { return result; result.makeInd = scc.getSubqueryHint().isDepJoin(); result.query = query; result.additionalCritieria = (CompareCriteria)new CompareCriteria(scc.getLeftExpression(), scc.getOperator(), rightExpr).clone(); if (exists.getSubqueryHint().isNoUnnest()) { return result; result.mergeJoin = exists.getSubqueryHint().isMergeJoin(); result.makeInd = exists.getSubqueryHint().isDepJoin(); if (!unnest && !result.mergeJoin) { return result;
if (ssc.getSubqueryHint().isNoUnnest()) { return result; if (cc.getRightExpression() instanceof ScalarSubquery) { ScalarSubquery ss = (ScalarSubquery)cc.getRightExpression(); if (ss.getSubqueryHint().isNoUnnest()) { return result; if (scc.getSubqueryHint().isNoUnnest()) { return result; result.type = scc.getClass(); result.mergeJoin = scc.getSubqueryHint().isMergeJoin(); if (!unnest && !result.mergeJoin) { return result; result.makeInd = scc.getSubqueryHint().isDepJoin(); result.query = query; result.additionalCritieria = (Criteria)new CompareCriteria(scc.getLeftExpression(), scc.getOperator(), rightExpr).clone(); if (exists.getSubqueryHint().isNoUnnest()) { return result; result.mergeJoin = exists.getSubqueryHint().isMergeJoin(); result.makeInd = exists.getSubqueryHint().isDepJoin(); if (!unnest && !result.mergeJoin) { return result;
/** * Deep copy of object. The values Iterator of this object * will not be cloned - it will be null in the new object * (see #setValueIterator setValueIterator}). * @return Deep copy of object * @see java.lang.Object#clone() */ public Object clone() { Expression leftCopy = null; if(getLeftExpression() != null) { leftCopy = (Expression) getLeftExpression().clone(); } QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } SubqueryCompareCriteria copy = new SubqueryCompareCriteria(leftCopy, copyCommand, this.getOperator(), this.getPredicateQuantifier()); if (this.subqueryHint != null) { copy.subqueryHint = this.subqueryHint.clone(); } if (this.arrayExpression != null) { copy.arrayExpression = (Expression) this.arrayExpression.clone(); } return copy; }
/** * Deep copy of object. The values Iterator of this object * will not be cloned - it will be null in the new object * (see #setValueIterator setValueIterator}). * @return Deep copy of object * @see java.lang.Object#clone() */ public Object clone() { Expression leftCopy = null; if(getLeftExpression() != null) { leftCopy = (Expression) getLeftExpression().clone(); } QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } SubqueryCompareCriteria copy = new SubqueryCompareCriteria(leftCopy, copyCommand, this.getOperator(), this.getPredicateQuantifier()); if (this.subqueryHint != null) { copy.subqueryHint = this.subqueryHint.clone(); } if (this.arrayExpression != null) { copy.arrayExpression = (Expression) this.arrayExpression.clone(); } return copy; }
public void addSubqueryHint(SubqueryHint hint) { if (hint.isNoUnnest()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.NOUNNEST); append(SPACE); append(END_HINT); } else if (hint.isDepJoin()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.DJ); append(SPACE); append(END_HINT); } else if (hint.isMergeJoin()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.MJ); append(SPACE); append(END_HINT); } }
/** * Deep copy of object. The values Iterator of this object * will not be cloned - it will be null in the new object * (see #setValueIterator setValueIterator}). * @return Deep copy of object * @see java.lang.Object#clone() */ public Object clone() { Expression leftCopy = null; if(getLeftExpression() != null) { leftCopy = (Expression) getLeftExpression().clone(); } QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } SubqueryCompareCriteria copy = new SubqueryCompareCriteria(leftCopy, copyCommand, this.getOperator(), this.getPredicateQuantifier()); if (this.subqueryHint != null) { copy.subqueryHint = this.subqueryHint.clone(); } if (this.arrayExpression != null) { copy.arrayExpression = (Expression) this.arrayExpression.clone(); } return copy; }
public void addSubqueryHint(SubqueryHint hint) { if (hint.isNoUnnest()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.NOUNNEST); append(SPACE); append(END_HINT); } else if (hint.isDepJoin()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.DJ); append(SPACE); append(END_HINT); } else if (hint.isMergeJoin()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.MJ); append(SPACE); append(END_HINT); } }
public void addSubqueryHint(SubqueryHint hint) { if (hint.isNoUnnest()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.NOUNNEST); append(SPACE); append(END_HINT); } else if (hint.isDepJoin()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.DJ); append(SPACE); append(END_HINT); } else if (hint.isMergeJoin()) { append(SPACE); append(BEGIN_HINT); append(SPACE); append(SubqueryHint.MJ); append(SPACE); append(END_HINT); } }
/** * Deep copy of object. The values Iterator of this object * will not be cloned - it will be null in the new object * (see #setValueIterator setValueIterator}). * @return Deep copy of object */ public SubquerySetCriteria clone() { Expression copy = null; if(getExpression() != null) { copy = (Expression) getExpression().clone(); } QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } SubquerySetCriteria criteriaCopy = new SubquerySetCriteria(copy, copyCommand); criteriaCopy.setNegated(isNegated()); criteriaCopy.subqueryHint = this.subqueryHint.clone(); return criteriaCopy; }
/** * Deep copy of object. The values Iterator of this object * will not be cloned - it will be null in the new object * (see #setValueIterator setValueIterator}). * @return Deep copy of object */ public SubquerySetCriteria clone() { Expression copy = null; if(getExpression() != null) { copy = (Expression) getExpression().clone(); } QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } SubquerySetCriteria criteriaCopy = new SubquerySetCriteria(copy, copyCommand); criteriaCopy.setNegated(isNegated()); criteriaCopy.subqueryHint = this.subqueryHint.clone(); return criteriaCopy; }
static Query exampleExists(boolean semiJoin) { Select s1 = new Select(); s1.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$ From f1 = new From(); f1.addGroup(new GroupSymbol("m.g1")); //$NON-NLS-1$ Query q1 = new Query(); q1.setSelect(s1); q1.setFrom(f1); Select s2 = new Select(); s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$ From f2 = new From(); f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$ ExistsCriteria existsCrit = new ExistsCriteria(q1); existsCrit.getSubqueryHint().setMergeJoin(semiJoin); Query q2 = new Query(); q2.setSelect(s2); q2.setFrom(f2); q2.setCriteria(existsCrit); return q2; }
static Query exampleIn(boolean semiJoin) { GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$ From from = new From(); from.addGroup(g); Select select = new Select(); select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$ Expression expr = new ElementSymbol("b"); //$NON-NLS-1$ Criteria criteria = new CompareCriteria(new ElementSymbol("a2"), CompareCriteria.EQ, //$NON-NLS-1$ new Constant(new Integer(5))); Query query = new Query(); query.setSelect(select); query.setFrom(from); query.setCriteria(criteria); SubquerySetCriteria subCrit = new SubquerySetCriteria(expr, query); subCrit.getSubqueryHint().setMergeJoin(semiJoin); Query outer = new Query(); outer.setSelect(select); outer.setFrom(from); outer.setCriteria(subCrit); return outer; }
/** * Override equals() method. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Use super.equals() to check obvious stuff and variable if(obj == this) { return true; } if(! (obj instanceof SubquerySetCriteria)) { return false; } SubquerySetCriteria sc = (SubquerySetCriteria)obj; return this.isNegated() == sc.isNegated() && EquivalenceUtil.areEqual(getExpression(), sc.getExpression()) && EquivalenceUtil.areEqual(getCommand(), sc.getCommand()) && this.subqueryHint.equals(sc.getSubqueryHint()); }
/** * Override equals() method. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Use super.equals() to check obvious stuff and variable if(obj == this) { return true; } if(! (obj instanceof SubquerySetCriteria)) { return false; } SubquerySetCriteria sc = (SubquerySetCriteria)obj; return this.isNegated() == sc.isNegated() && EquivalenceUtil.areEqual(getExpression(), sc.getExpression()) && EquivalenceUtil.areEqual(getCommand(), sc.getCommand()) && this.subqueryHint.equals(sc.getSubqueryHint()); }
/** * Deep copy of object. The values Iterator of this object * will not be cloned - it will be null in the new object * (see #setValueIterator setValueIterator}). * @return Deep copy of object */ public SubquerySetCriteria clone() { Expression copy = null; if(getExpression() != null) { copy = (Expression) getExpression().clone(); } QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } SubquerySetCriteria criteriaCopy = new SubquerySetCriteria(copy, copyCommand); criteriaCopy.setNegated(isNegated()); criteriaCopy.subqueryHint = this.subqueryHint.clone(); return criteriaCopy; }