private QueryCommand minimizeWithProjection(WithQueryCommand with, QueryCommand subCommand, TempMetadataID tid, Collection<TempMetadataID> accessed) throws QueryMetadataException, QueryResolverException, TeiidComponentException { List<TempMetadataID> elements = tid.getElements(); List<Integer> toRemove = new ArrayList<Integer>(); for (int i = elements.size()-1; i >= 0; i--) { TempMetadataID elem = elements.get(i); if (!accessed.contains(elem)) { toRemove.add(i); } } //the strategy here is to replace the actual projections with null. this keeps //the definition of the with clause consistent if (!toRemove.isEmpty()) { if (with.isRecursive()) { SetQuery setQuery = (SetQuery) subCommand; setQuery.setLeftQuery(removeUnusedProjection(with, setQuery.getLeftQuery(), elements, toRemove)); setQuery.setRightQuery(removeUnusedProjection(with, setQuery.getRightQuery(), elements, toRemove)); } else { subCommand = removeUnusedProjection(with, subCommand, elements, toRemove); with.setCommand(subCommand); } } return subCommand; }
private QueryCommand minimizeWithProjection(WithQueryCommand with, QueryCommand subCommand, TempMetadataID tid, Collection<TempMetadataID> accessed) throws QueryMetadataException, QueryResolverException, TeiidComponentException { List<TempMetadataID> elements = tid.getElements(); List<Integer> toRemove = new ArrayList<Integer>(); for (int i = elements.size()-1; i >= 0; i--) { TempMetadataID elem = elements.get(i); if (!accessed.contains(elem)) { toRemove.add(i); } } //the strategy here is to replace the actual projections with null. this keeps //the definition of the with clause consistent if (!toRemove.isEmpty()) { if (with.isRecursive()) { SetQuery setQuery = (SetQuery) subCommand; setQuery.setLeftQuery(removeUnusedProjection(with, setQuery.getLeftQuery(), elements, toRemove)); setQuery.setRightQuery(removeUnusedProjection(with, setQuery.getRightQuery(), elements, toRemove)); } else { subCommand = removeUnusedProjection(with, subCommand, elements, toRemove); with.setCommand(subCommand); } } return subCommand; }
with.setCommand(subCommand);