protected void appendSetQuery( SetQuery parent, QueryCommand obj, boolean right ) { if (obj.getLimit() != null || obj.getOrderBy() != null || (obj instanceof SetQuery && ((right && parent.isAll() && !((SetQuery)obj).isAll()) || ((parent.getOperation() == Operation.INTERSECT || right) && parent.getOperation() != ((SetQuery)obj).getOperation())))) { append(Tokens.LPAREN); visitNode(obj); append(Tokens.RPAREN); } else { visitNode(obj); } }
protected void appendSetQuery( SetQuery parent, QueryCommand obj, boolean right ) { if (obj.getLimit() != null || obj.getOrderBy() != null || (obj instanceof SetQuery && ((right && parent.isAll() && !((SetQuery)obj).isAll()) || ((parent.getOperation() == Operation.INTERSECT || right) && parent.getOperation() != ((SetQuery)obj).getOperation())))) { append(Tokens.LPAREN); visitNode(obj); append(Tokens.RPAREN); } else { visitNode(obj); } }
protected void appendSetQuery( SetQuery parent, QueryCommand obj, boolean right ) { if (obj.getLimit() != null || obj.getOrderBy() != null || (obj instanceof SetQuery && ((right && parent.isAll() && !((SetQuery)obj).isAll()) || ((parent.getOperation() == Operation.INTERSECT || right) && parent.getOperation() != ((SetQuery)obj).getOperation())))) { append(Tokens.LPAREN); visitNode(obj); append(Tokens.RPAREN); } else { visitNode(obj); } }
protected void validateSetQuery(SetQuery query) { // Walk through sub queries - validate each one separately and // also check the columns of each for comparability for (QueryCommand subQuery : query.getQueryCommands()) { if (subQuery instanceof Query && ((Query)subQuery).getInto() != null) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.union_insert"), query); //$NON-NLS-1$ } } if (!query.isAll() || query.getOperation() == Operation.EXCEPT || query.getOperation() == Operation.INTERSECT) { validateSortable(query.getProjectedSymbols()); } if (query.isAll() && (query.getOperation() == Operation.EXCEPT || query.getOperation() == Operation.INTERSECT)) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.excpet_intersect_all"), query); //$NON-NLS-1$ } }
public static boolean extractQueries(QueryCommand queryCommand, List<Query> result) { if (queryCommand instanceof SetQuery) { SetQuery sq = (SetQuery)queryCommand; if (sq.isAll() && sq.getOperation() == Operation.UNION && sq.getOrderBy() == null && sq.getLimit() == null && sq.getWith() == null) { if (!extractQueries(sq.getLeftQuery(), result)) { return false; } if (!extractQueries(sq.getRightQuery(), result)) { return false; } return true; } return false; } result.add((Query)queryCommand); return true; }
protected void validateSetQuery(SetQuery query) { // Walk through sub queries - validate each one separately and // also check the columns of each for comparability for (QueryCommand subQuery : query.getQueryCommands()) { if (subQuery instanceof Query && ((Query)subQuery).getInto() != null) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.union_insert"), query); //$NON-NLS-1$ } } if (!query.isAll() || query.getOperation() == Operation.EXCEPT || query.getOperation() == Operation.INTERSECT) { validateSortable(query.getProjectedSymbols()); } if (query.isAll() && (query.getOperation() == Operation.EXCEPT || query.getOperation() == Operation.INTERSECT)) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.excpet_intersect_all"), query); //$NON-NLS-1$ } }
public static boolean extractQueries(QueryCommand queryCommand, List<Query> result) { if (queryCommand instanceof SetQuery) { SetQuery sq = (SetQuery)queryCommand; if (sq.isAll() && sq.getOperation() == Operation.UNION && sq.getOrderBy() == null && sq.getLimit() == null && sq.getWith() == null) { if (!extractQueries(sq.getLeftQuery(), result)) { return false; } if (!extractQueries(sq.getRightQuery(), result)) { return false; } return true; } return false; } result.add((Query)queryCommand); return true; }
public static boolean extractQueries(QueryCommand queryCommand, List<Query> result) { if (queryCommand instanceof SetQuery) { SetQuery sq = (SetQuery)queryCommand; if (sq.isAll() && sq.getOperation() == Operation.UNION && sq.getOrderBy() == null && sq.getLimit() == null && sq.getWith() == null) { if (!extractQueries(sq.getLeftQuery(), result)) { return false; } if (!extractQueries(sq.getRightQuery(), result)) { return false; } return true; } return false; } result.add((Query)queryCommand); return true; }
protected void validateSetQuery(SetQuery query) { // Walk through sub queries - validate each one separately and // also check the columns of each for comparability for (QueryCommand subQuery : query.getQueryCommands()) { if(isXMLCommand(subQuery)) { handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0034"), query); //$NON-NLS-1$ } if (subQuery instanceof Query && ((Query)subQuery).getInto() != null) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.union_insert"), query); //$NON-NLS-1$ } } if (!query.isAll() || query.getOperation() == Operation.EXCEPT || query.getOperation() == Operation.INTERSECT) { validateSortable(query.getProjectedSymbols()); } if (query.isAll() && (query.getOperation() == Operation.EXCEPT || query.getOperation() == Operation.INTERSECT)) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.excpet_intersect_all"), query); //$NON-NLS-1$ } }
private boolean isPushdownValid(WithQueryCommand with, SetQuery setQuery, Object modelID, QueryCommand withCommand, RelationalPlan subPlan1) throws QueryMetadataException, TeiidComponentException { AccessNode aNode1 = CriteriaCapabilityValidatorVisitor.getAccessNode(subPlan1); if (aNode1 == null) { return false; } Object modelID1 = CriteriaCapabilityValidatorVisitor.validateCommandPushdown(null, metadata, capFinder, aNode1, false); QueryCommand withCommand1 = CriteriaCapabilityValidatorVisitor.getQueryCommand(aNode1); if (modelID1 == null || withCommand1 == null) { return false; } //if we are the same connector for each, then we should be good to proceed if (CapabilitiesUtil.isSameConnector(modelID, modelID1, metadata, capFinder)) { SetQuery pushdownSetQuery = new SetQuery(Operation.UNION, setQuery.isAll(), withCommand, withCommand1); WithQueryCommand wqc = new WithQueryCommand(with.getGroupSymbol(), with.getColumns(), pushdownSetQuery); wqc.setRecursive(true); this.withPlanningState.pushdownWith.put(with.getGroupSymbol().getName(), wqc); return true; } return false; }
/** * Compare two queries for equality. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof SetQuery)) { return false; } SetQuery other = (SetQuery) obj; return getOperation() == other.getOperation() && EquivalenceUtil.areEqual(this.isAll(), other.isAll()) && EquivalenceUtil.areEqual(this.leftQuery, other.leftQuery) && EquivalenceUtil.areEqual(this.rightQuery, other.rightQuery) && EquivalenceUtil.areEqual(getOrderBy(), other.getOrderBy()) && EquivalenceUtil.areEqual(getLimit(), other.getLimit()) && EquivalenceUtil.areEqual(getWith(), other.getWith()) && sameOptionAndHint(other); }
private boolean isPushdownValid(WithQueryCommand with, SetQuery setQuery, Object modelID, QueryCommand withCommand, RelationalPlan subPlan1) throws QueryMetadataException, TeiidComponentException { AccessNode aNode1 = CriteriaCapabilityValidatorVisitor.getAccessNode(subPlan1); if (aNode1 == null) { return false; } Object modelID1 = CriteriaCapabilityValidatorVisitor.validateCommandPushdown(null, metadata, capFinder, aNode1, false); QueryCommand withCommand1 = CriteriaCapabilityValidatorVisitor.getQueryCommand(aNode1); if (modelID1 == null || withCommand1 == null) { return false; } //if we are the same connector for each, then we should be good to proceed if (CapabilitiesUtil.isSameConnector(modelID, modelID1, metadata, capFinder)) { SetQuery pushdownSetQuery = new SetQuery(Operation.UNION, setQuery.isAll(), withCommand, withCommand1); WithQueryCommand wqc = new WithQueryCommand(with.getGroupSymbol(), with.getColumns(), pushdownSetQuery); wqc.setRecursive(true); this.withPlanningState.pushdownWith.put(with.getGroupSymbol().getName(), wqc); return true; } return false; }
private boolean isPushdownValid(WithQueryCommand with, SetQuery setQuery, Object modelID, QueryCommand withCommand, RelationalPlan subPlan1) throws QueryMetadataException, TeiidComponentException { AccessNode aNode1 = CriteriaCapabilityValidatorVisitor.getAccessNode(subPlan1); if (aNode1 == null) { return false; } Object modelID1 = CriteriaCapabilityValidatorVisitor.validateCommandPushdown(null, metadata, capFinder, aNode1, false); QueryCommand withCommand1 = CriteriaCapabilityValidatorVisitor.getQueryCommand(aNode1); if (modelID1 == null || withCommand1 == null) { return false; } //if we are the same connector for each, then we should be good to proceed if (CapabilitiesUtil.isSameConnector(modelID, modelID1, metadata, capFinder)) { SetQuery pushdownSetQuery = new SetQuery(Operation.UNION, setQuery.isAll(), withCommand, withCommand1); WithQueryCommand wqc = new WithQueryCommand(with.getGroupSymbol(), with.getColumns(), pushdownSetQuery); wqc.setRecursive(true); this.withPlanningState.pushdownWith.put(with.getGroupSymbol().getName(), wqc); return true; } return false; }
@Override public void open() throws TeiidComponentException, TeiidProcessingException { if (with != null && tempTableStore.getProcessors() == null) { HashMap<String, TableProcessor> processors = new HashMap<String, TableProcessor>(); tempTableStore.setProcessors(processors); for (WithQueryCommand withCommand : this.with) { if (withCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withCommand.getCommand(); ProcessorPlan initial = setQuery.getLeftQuery().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(initial, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new RecursiveTableProcessor(withProcessor, withCommand.getColumns(), setQuery.getRightQuery().getProcessorPlan(), setQuery.isAll())); continue; } ProcessorPlan plan = withCommand.getCommand().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(plan, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new TableProcessor(withProcessor, withCommand.getColumns())); } } this.root.open(); }
@Override public void open() throws TeiidComponentException, TeiidProcessingException { if (with != null && tempTableStore.getProcessors() == null) { HashMap<String, TableProcessor> processors = new HashMap<String, TableProcessor>(); tempTableStore.setProcessors(processors); for (WithQueryCommand withCommand : this.with) { if (withCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withCommand.getCommand(); ProcessorPlan initial = setQuery.getLeftQuery().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(initial, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new RecursiveTableProcessor(withProcessor, withCommand.getColumns(), setQuery.getRightQuery().getProcessorPlan(), setQuery.isAll())); continue; } ProcessorPlan plan = withCommand.getCommand().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(plan, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new TableProcessor(withProcessor, withCommand.getColumns())); } } this.root.open(); }
@Override public void open() throws TeiidComponentException, TeiidProcessingException { if (with != null && tempTableStore.getProcessors() == null) { HashMap<String, TableProcessor> processors = new HashMap<String, TableProcessor>(); tempTableStore.setProcessors(processors); for (WithQueryCommand withCommand : this.with) { if (withCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withCommand.getCommand(); ProcessorPlan initial = setQuery.getLeftQuery().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(initial, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new RecursiveTableProcessor(withProcessor, withCommand.getColumns(), setQuery.getRightQuery().getProcessorPlan(), setQuery.isAll())); continue; } ProcessorPlan plan = withCommand.getCommand().getProcessorPlan(); QueryProcessor withProcessor = new QueryProcessor(plan, getContext().clone(), root.getBufferManager(), root.getDataManager()); processors.put(withCommand.getGroupSymbol().getName(), new TableProcessor(withProcessor, withCommand.getColumns())); } } this.root.open(); }
org.teiid.language.SetQuery translate(SetQuery union) { org.teiid.language.SetQuery result = new org.teiid.language.SetQuery(); result.setWith(translate(union.getWith())); result.setAll(union.isAll()); switch (union.getOperation()) { case UNION: result.setOperation(org.teiid.language.SetQuery.Operation.UNION); break; case INTERSECT: result.setOperation(org.teiid.language.SetQuery.Operation.INTERSECT); break; case EXCEPT: result.setOperation(org.teiid.language.SetQuery.Operation.EXCEPT); break; } result.setLeftQuery(translate(union.getLeftQuery())); result.setRightQuery(translate(union.getRightQuery())); result.setOrderBy(translate(union.getOrderBy(), true)); result.setLimit(translate(union.getLimit())); return result; }
org.teiid.language.SetQuery translate(SetQuery union) { org.teiid.language.SetQuery result = new org.teiid.language.SetQuery(); result.setWith(translate(union.getWith())); result.setAll(union.isAll()); switch (union.getOperation()) { case UNION: result.setOperation(org.teiid.language.SetQuery.Operation.UNION); break; case INTERSECT: result.setOperation(org.teiid.language.SetQuery.Operation.INTERSECT); break; case EXCEPT: result.setOperation(org.teiid.language.SetQuery.Operation.EXCEPT); break; } result.setLeftQuery(translate(union.getLeftQuery())); result.setRightQuery(translate(union.getRightQuery())); result.setOrderBy(translate(union.getOrderBy(), true)); result.setLimit(translate(union.getLimit())); return result; }
org.teiid.language.SetQuery translate(SetQuery union) { org.teiid.language.SetQuery result = new org.teiid.language.SetQuery(); result.setWith(translate(union.getWith())); result.setAll(union.isAll()); switch (union.getOperation()) { case UNION: result.setOperation(org.teiid.language.SetQuery.Operation.UNION); break; case INTERSECT: result.setOperation(org.teiid.language.SetQuery.Operation.INTERSECT); break; case EXCEPT: result.setOperation(org.teiid.language.SetQuery.Operation.EXCEPT); break; } result.setLeftQuery(translate(union.getLeftQuery())); result.setRightQuery(translate(union.getRightQuery())); result.setOrderBy(translate(union.getOrderBy(), true)); result.setLimit(translate(union.getLimit())); return result; }
@Override public void visit( SetQuery obj ) { addCacheHint(obj.getCacheHint()); addWithClause(obj); QueryCommand query = obj.getLeftQuery(); appendSetQuery(obj, query, false); beginClause(0); append(obj.getOperation()); if (obj.isAll()) { append(SPACE); append(ALL); } beginClause(0); query = obj.getRightQuery(); appendSetQuery(obj, query, true); if (obj.getOrderBy() != null) { beginClause(0); visitNode(obj.getOrderBy()); } if (obj.getLimit() != null) { beginClause(0); visitNode(obj.getLimit()); } if (obj.getOption() != null) { beginClause(0); visitNode(obj.getOption()); } }