public String toString() { StringBuilder sb = new StringBuilder(); if (this.with != null) { sb.append(SQLConstants.Reserved.WITH); for (WithQueryCommand withCommand : this.with) { sb.append("\n"); //$NON-NLS-1$ sb.append(withCommand.getGroupSymbol()); if (withCommand.isRecursive()) { sb.append(" anchor\n").append(((SetQuery)withCommand.getCommand()).getLeftQuery().getProcessorPlan()); //$NON-NLS-1$ sb.append("recursive\n").append(((SetQuery)withCommand.getCommand()).getRightQuery().getProcessorPlan()); //$NON-NLS-1$ } else { sb.append("\n"); //$NON-NLS-1$ sb.append(withCommand.getCommand().getProcessorPlan()); } } sb.append("body\n"); //$NON-NLS-1$ } sb.append(this.root.toString()); return sb.toString(); }
public String toString() { StringBuilder sb = new StringBuilder(); if (this.with != null) { sb.append(SQLConstants.Reserved.WITH); for (WithQueryCommand withCommand : this.with) { sb.append("\n"); //$NON-NLS-1$ sb.append(withCommand.getGroupSymbol()); if (withCommand.isRecursive()) { sb.append(" anchor\n").append(((SetQuery)withCommand.getCommand()).getLeftQuery().getProcessorPlan()); //$NON-NLS-1$ sb.append("recursive\n").append(((SetQuery)withCommand.getCommand()).getRightQuery().getProcessorPlan()); //$NON-NLS-1$ } else { sb.append("\n"); //$NON-NLS-1$ sb.append(withCommand.getCommand().getProcessorPlan()); } } sb.append("body\n"); //$NON-NLS-1$ } sb.append(this.root.toString()); return sb.toString(); }
private static void determineDependencies(Command command, Column c, int index, LinkedHashSet<AbstractMetadataRecord> columnValues) { if (command instanceof Query || command instanceof StoredProcedure) { Expression ex = command.getProjectedSymbols().get(index); collectDependencies(ex, columnValues); } else if (command instanceof SetQuery) { determineDependencies(((SetQuery)command).getLeftQuery(), c, index, columnValues); determineDependencies(((SetQuery)command).getRightQuery(), c, index, columnValues); } }
private static void determineDependencies(Command command, Column c, int index, LinkedHashSet<AbstractMetadataRecord> columnValues) { if (command instanceof Query || command instanceof StoredProcedure) { Expression ex = command.getProjectedSymbols().get(index); collectDependencies(ex, columnValues); } else if (command instanceof SetQuery) { determineDependencies(((SetQuery)command).getLeftQuery(), c, index, columnValues); determineDependencies(((SetQuery)command).getRightQuery(), c, index, columnValues); } }
private static void determineDependencies(Command command, Column c, int index, LinkedHashSet<AbstractMetadataRecord> columnValues) { if (command instanceof Query) { Expression ex = command.getProjectedSymbols().get(index); collectDependencies(ex, columnValues); } else if (command instanceof SetQuery) { determineDependencies(((SetQuery)command).getLeftQuery(), c, index, columnValues); determineDependencies(((SetQuery)command).getRightQuery(), c, index, columnValues); } }
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; }
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; }
/** * visit the branches other than the first with individual naming contexts * Aliases are being added in all cases, even though they may only be needed in the order by case. * Adding the same alias to all branches ensures cross db support (db2 in particular) */ public void visit(SetQuery obj) { visitor.createChildNamingContext(true); visitNode(obj.getRightQuery()); visitor.removeChildNamingContext(); visitor.namingContext.aliasColumns = true; visitNode(obj.getLeftQuery()); visitNode(obj.getOrderBy()); }
/** * visit the branches other than the first with individual naming contexts * Aliases are being added in all cases, even though they may only be needed in the order by case. * Adding the same alias to all branches ensures cross db support (db2 in particular) */ public void visit(SetQuery obj) { visitor.createChildNamingContext(true); visitNode(obj.getRightQuery()); visitor.removeChildNamingContext(); visitor.namingContext.aliasColumns = true; visitNode(obj.getLeftQuery()); visitNode(obj.getOrderBy()); }
/** * visit the branches other than the first with individual naming contexts * Aliases are being added in all cases, even though they may only be needed in the order by case. * Adding the same alias to all branches ensures cross db support (db2 in particular) */ public void visit(SetQuery obj) { visitor.createChildNamingContext(true); visitNode(obj.getRightQuery()); visitor.removeChildNamingContext(); visitor.namingContext.aliasColumns = true; visitNode(obj.getLeftQuery()); visitNode(obj.getOrderBy()); }
/** * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean) */ public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException { SetQuery setQuery = (SetQuery) command; SimpleQueryResolver.resolveWith(metadata, setQuery); QueryCommand firstCommand = setQuery.getLeftQuery(); QueryResolver.setChildMetadata(firstCommand, setQuery); QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false); QueryCommand rightCommand = setQuery.getRightQuery(); QueryResolver.setChildMetadata(rightCommand, setQuery); QueryResolver.resolveCommand(rightCommand, metadata.getMetadata(), false); resolveSetQuery(metadata, resolveNullLiterals, setQuery, firstCommand, rightCommand); }
/** * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean) */ public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException { SetQuery setQuery = (SetQuery) command; SimpleQueryResolver.resolveWith(metadata, setQuery); QueryCommand firstCommand = setQuery.getLeftQuery(); QueryResolver.setChildMetadata(firstCommand, setQuery); QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false); QueryCommand rightCommand = setQuery.getRightQuery(); QueryResolver.setChildMetadata(rightCommand, setQuery); QueryResolver.resolveCommand(rightCommand, metadata.getMetadata(), false); resolveSetQuery(metadata, resolveNullLiterals, setQuery, firstCommand, rightCommand); }
/** * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean) */ public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException { SetQuery setQuery = (SetQuery) command; SimpleQueryResolver.resolveWith(metadata, setQuery); QueryCommand firstCommand = setQuery.getLeftQuery(); QueryResolver.setChildMetadata(firstCommand, setQuery); QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false); QueryCommand rightCommand = setQuery.getRightQuery(); QueryResolver.setChildMetadata(rightCommand, setQuery); QueryResolver.resolveCommand(rightCommand, metadata.getMetadata(), false); resolveSetQuery(metadata, resolveNullLiterals, setQuery, firstCommand, rightCommand); }
public RelationalPlan clone(){ RelationalPlan plan = new RelationalPlan((RelationalNode)root.clone()); plan.setOutputElements(outputCols); if (with != null) { List<WithQueryCommand> newWith = LanguageObject.Util.deepClone(this.with, WithQueryCommand.class); for (WithQueryCommand withQueryCommand : newWith) { if (withQueryCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withQueryCommand.getCommand(); setQuery.getLeftQuery().setProcessorPlan(setQuery.getLeftQuery().getProcessorPlan().clone()); setQuery.getRightQuery().setProcessorPlan(setQuery.getRightQuery().getProcessorPlan().clone()); } else { withQueryCommand.getCommand().setProcessorPlan(withQueryCommand.getCommand().getProcessorPlan().clone()); } } plan.setWith(newWith); } return plan; }
public RelationalPlan clone(){ RelationalPlan plan = new RelationalPlan((RelationalNode)root.clone()); plan.setOutputElements(outputCols); if (with != null) { List<WithQueryCommand> newWith = LanguageObject.Util.deepClone(this.with, WithQueryCommand.class); for (WithQueryCommand withQueryCommand : newWith) { if (withQueryCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withQueryCommand.getCommand(); setQuery.getLeftQuery().setProcessorPlan(setQuery.getLeftQuery().getProcessorPlan().clone()); setQuery.getRightQuery().setProcessorPlan(setQuery.getRightQuery().getProcessorPlan().clone()); } else { withQueryCommand.getCommand().setProcessorPlan(withQueryCommand.getCommand().getProcessorPlan().clone()); } } plan.setWith(newWith); } return plan; }
public RelationalPlan clone(){ RelationalPlan plan = new RelationalPlan((RelationalNode)root.clone()); plan.setOutputElements(outputCols); if (with != null) { List<WithQueryCommand> newWith = LanguageObject.Util.deepClone(this.with, WithQueryCommand.class); for (WithQueryCommand withQueryCommand : newWith) { if (withQueryCommand.isRecursive()) { SetQuery setQuery = (SetQuery)withQueryCommand.getCommand(); setQuery.getLeftQuery().setProcessorPlan(setQuery.getLeftQuery().getProcessorPlan().clone()); setQuery.getRightQuery().setProcessorPlan(setQuery.getRightQuery().getProcessorPlan().clone()); } else { withQueryCommand.getCommand().setProcessorPlan(withQueryCommand.getCommand().getProcessorPlan().clone()); } } plan.setWith(newWith); } return plan; }
@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(); }
private SetQuery rewriteSetQuery(SetQuery setQuery) throws TeiidComponentException, TeiidProcessingException{ if (setQuery.getProjectedTypes() != null) { for (QueryCommand command : setQuery.getQueryCommands()) { if (!(command instanceof Query)) { continue; } correctProjectedTypes(setQuery.getProjectedTypes(), (Query)command); } setQuery.setProjectedTypes(null, null); } setQuery.setLeftQuery((QueryCommand)rewriteCommand(setQuery.getLeftQuery(), true)); setQuery.setRightQuery((QueryCommand)rewriteCommand(setQuery.getRightQuery(), true)); rewriteOrderBy(setQuery); if (setQuery.getLimit() != null) { setQuery.setLimit(rewriteLimitClause(setQuery.getLimit())); } return setQuery; }