/** * because of the way constraints are enforced, we cannot allow correlated references * the issues are: * - the insert may be partially specified and relevant default values may not be known * - to know the full update row, we have to use row processing * @param object * @param gs * @param planner * @throws QueryValidatorException * @throws TeiidComponentException * @throws QueryMetadataException * @throws QueryPlannerException */ private static void validateAndPlanSubqueries(LanguageObject object, GroupSymbol gs, RelationalPlanner planner) throws QueryValidatorException, QueryPlannerException, QueryMetadataException, TeiidComponentException { List<SubqueryContainer<?>> subqueries = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(object); if (subqueries.isEmpty()) { return; } Set<GroupSymbol> groups = Collections.singleton(gs); planner.planSubqueries(groups, null, subqueries, true, false); List<Reference> refs = new LinkedList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(object, groups, refs, planner.metadata); if (!refs.isEmpty()) { throw new QueryValidatorException(QueryPlugin.Event.TEIID31142, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31142, object, gs)); } }
final CorrelatedReferenceCollectorVisitor visitor = new CorrelatedReferenceCollectorVisitor(groups, correlatedReferences); visitor.metadata = metadata; visitor.queryRoot = obj instanceof Command;
/** * because of the way constraints are enforced, we cannot allow correlated references * the issues are: * - the insert may be partially specified and relevant default values may not be known * - to know the full update row, we have to use row processing * @param object * @param gs * @param planner * @throws QueryValidatorException * @throws TeiidComponentException * @throws QueryMetadataException * @throws QueryPlannerException */ private static void validateAndPlanSubqueries(LanguageObject object, GroupSymbol gs, RelationalPlanner planner) throws QueryValidatorException, QueryPlannerException, QueryMetadataException, TeiidComponentException { List<SubqueryContainer<?>> subqueries = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(object); if (subqueries.isEmpty()) { return; } Set<GroupSymbol> groups = Collections.singleton(gs); planner.planSubqueries(groups, null, subqueries, true, false); List<Reference> refs = new LinkedList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(object, groups, refs, planner.metadata); if (!refs.isEmpty()) { throw new QueryValidatorException(QueryPlugin.Event.TEIID31142, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31142, object, gs)); } }
final CorrelatedReferenceCollectorVisitor visitor = new CorrelatedReferenceCollectorVisitor(groups, correlatedReferences); visitor.metadata = metadata; visitor.queryRoot = obj instanceof Command;
/** * because of the way constraints are enforced, we cannot allow correlated references * the issues are: * - the insert may be partially specified and relevant default values may not be known * - to know the full update row, we have to use row processing * @param object * @param gs * @param planner * @throws QueryValidatorException * @throws TeiidComponentException * @throws QueryMetadataException * @throws QueryPlannerException */ private static void validateAndPlanSubqueries(LanguageObject object, GroupSymbol gs, RelationalPlanner planner) throws QueryValidatorException, QueryPlannerException, QueryMetadataException, TeiidComponentException { List<SubqueryContainer<?>> subqueries = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(object); if (subqueries.isEmpty()) { return; } Set<GroupSymbol> groups = Collections.singleton(gs); planner.planSubqueries(groups, null, subqueries, true); List<Reference> refs = new LinkedList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(object, groups, refs, planner.metadata); if (!refs.isEmpty()) { throw new QueryValidatorException(QueryPlugin.Event.TEIID31142, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31142, object, gs)); } }
final CorrelatedReferenceCollectorVisitor visitor = new CorrelatedReferenceCollectorVisitor(groups, correlatedReferences); visitor.metadata = metadata; visitor.queryRoot = obj instanceof Command;
private void determineCorrelatedReferences(List<GroupSymbol> groups, PlannedResult plannedResult) { if (plannedResult.query.getCorrelatedReferences() == null) { //create the correlated refs if they exist //there is a little bit of a design problem here that null usually means no refs. ArrayList<Reference> correlatedReferences = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(plannedResult.query, groups, correlatedReferences, metadata); if (!correlatedReferences.isEmpty()) { SymbolMap map = new SymbolMap(); for (Reference reference : correlatedReferences) { map.addMapping(reference.getExpression(), reference.getExpression()); } plannedResult.query.setCorrelatedReferences(map); } } }
private void determineCorrelatedReferences(List<GroupSymbol> groups, PlannedResult plannedResult) { if (plannedResult.query.getCorrelatedReferences() == null) { //create the correlated refs if they exist //there is a little bit of a design problem here that null usually means no refs. ArrayList<Reference> correlatedReferences = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(plannedResult.query, groups, correlatedReferences, metadata); if (!correlatedReferences.isEmpty()) { SymbolMap map = new SymbolMap(); for (Reference reference : correlatedReferences) { map.addMapping(reference.getExpression(), reference.getExpression()); } plannedResult.query.setCorrelatedReferences(map); } } }
private void determineCorrelatedReferences(List<GroupSymbol> groups, PlannedResult plannedResult) { if (plannedResult.query.getCorrelatedReferences() == null) { //create the correlated refs if they exist //there is a little bit of a design problem here that null usually means no refs. ArrayList<Reference> correlatedReferences = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(plannedResult.query, groups, correlatedReferences, metadata); if (!correlatedReferences.isEmpty()) { SymbolMap map = new SymbolMap(); for (Reference reference : correlatedReferences) { map.addMapping(reference.getExpression(), reference.getExpression()); } plannedResult.query.setCorrelatedReferences(map); } } }
private SymbolMap getCorrelatedReferences(PlanNode parent, PlanNode node, LanguageObject lo) { PlanNode rootJoin = parent; Set<GroupSymbol> groups = new HashSet<GroupSymbol>(rootJoin.getGroups()); while (rootJoin.getParent() != null && rootJoin.getParent().getType() == NodeConstants.Types.JOIN) { rootJoin = rootJoin.getParent(); //accumulate groups as we go, as intermediate joins may not contribute groups to the final join groups.addAll(rootJoin.getGroups()); } List<Reference> correlatedReferences = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(lo, groups, correlatedReferences, metadata); if (correlatedReferences.isEmpty()) { return null; } SymbolMap map = new SymbolMap(); for (Reference reference : correlatedReferences) { map.addMapping(reference.getExpression(), reference.getExpression()); } node.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, map); return map; }
private SymbolMap getCorrelatedReferences(PlanNode parent, PlanNode node, LanguageObject lo) { PlanNode rootJoin = parent; Set<GroupSymbol> groups = new HashSet<GroupSymbol>(rootJoin.getGroups()); while (rootJoin.getParent() != null && rootJoin.getParent().getType() == NodeConstants.Types.JOIN) { rootJoin = rootJoin.getParent(); //accumulate groups as we go, as intermediate joins may not contribute groups to the final join groups.addAll(rootJoin.getGroups()); } List<Reference> correlatedReferences = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(lo, groups, correlatedReferences, metadata); if (correlatedReferences.isEmpty()) { return null; } SymbolMap map = new SymbolMap(); for (Reference reference : correlatedReferences) { map.addMapping(reference.getExpression(), reference.getExpression()); } node.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, map); return map; }
private SymbolMap getCorrelatedReferences(PlanNode parent, PlanNode node, LanguageObject lo) { PlanNode rootJoin = parent; while (rootJoin.getParent() != null && rootJoin.getParent().getType() == NodeConstants.Types.JOIN && !rootJoin.getParent().getGroups().isEmpty()) { rootJoin = rootJoin.getParent(); } List<Reference> correlatedReferences = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(lo, rootJoin.getGroups(), correlatedReferences, metadata); if (correlatedReferences.isEmpty()) { return null; } SymbolMap map = new SymbolMap(); for (Reference reference : correlatedReferences) { map.addMapping(reference.getExpression(), reference.getExpression()); } node.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, map); return map; }
CorrelatedReferenceCollectorVisitor.collectReferences(subCommand, localGroupSymbols, correlatedReferences, metadata); ProcessorPlan procPlan = QueryOptimizer.optimizePlan(subCommand, metadata, idGenerator, capFinder, analysisRecord, context); container.getCommand().setProcessorPlan(procPlan); List<Reference> refs = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(c, localGroupSymbols, refs, metadata); setCorrelatedReferences(containers.get(i), refs); c.setProcessorPlan(clone.getProcessorPlan());
@Test public void testRewriteCorrelatedSubqueryInHaving() throws Exception { String sql = "select pm1.g1.e1 from pm1.g1 group by pm1.g1.e1 having pm1.g1.e1 in (select pm1.g1.e1 from pm1.g2)"; //$NON-NLS-1$ String expected = "SELECT pm1.g1.e1 FROM pm1.g1 GROUP BY pm1.g1.e1 HAVING pm1.g1.e1 IN (SELECT pm1.g1.e1 FROM pm1.g2)"; //$NON-NLS-1$ Query query = (Query)helpTestRewriteCommand(sql, expected); List<Reference> refs = new LinkedList<Reference>(); GroupSymbol gs = new GroupSymbol("pm1.g1"); ResolverUtil.resolveGroup(gs, RealMetadataFactory.example1Cached()); CorrelatedReferenceCollectorVisitor.collectReferences(query.getHaving(), Arrays.asList(gs), refs, RealMetadataFactory.example1Cached());//$NON-NLS-1$ assertEquals(1, refs.size()); }
CorrelatedReferenceCollectorVisitor.collectReferences(subCommand, localGroupSymbols, correlatedReferences, metadata); setCorrelatedReferences(container, correlatedReferences); List<Reference> refs = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(c, localGroupSymbols, refs, metadata); setCorrelatedReferences(containers.get(i), refs);
CorrelatedReferenceCollectorVisitor.collectReferences(subCommand, localGroupSymbols, correlatedReferences, metadata); setCorrelatedReferences(container, correlatedReferences); List<Reference> refs = new ArrayList<Reference>(); CorrelatedReferenceCollectorVisitor.collectReferences(c, localGroupSymbols, refs, metadata); setCorrelatedReferences(containers.get(i), refs);
@Test public void testDeepNesting() throws Exception { String sql = "select * from bqt1.smalla where exists (select intnum from bqt1.smalla x where smalla.intnum = x.intnum and exists (select intnum from bqt1.smalla where exists (select intnum from bqt1.smalla x where smalla.intnum = x.intnum)))"; Command command = TestResolver.helpResolve(sql, RealMetadataFactory.exampleBQTCached()); command = QueryRewriter.rewrite(command, RealMetadataFactory.exampleBQTCached(), null); command = ((ExistsCriteria)((Query)command).getCriteria()).getCommand(); LinkedList<Reference> correlatedReferences = new LinkedList<Reference>(); GroupSymbol gs = new GroupSymbol("bqt1.smalla"); ResolverUtil.resolveGroup(gs, RealMetadataFactory.exampleBQTCached()); CorrelatedReferenceCollectorVisitor.collectReferences(command, Arrays.asList(gs), correlatedReferences, RealMetadataFactory.exampleBQTCached()); assertEquals(1, correlatedReferences.size()); }
CorrelatedReferenceCollectorVisitor.collectReferences(subqueryContainer.getCommand(), Arrays.asList(container.getGroup()), correlatedReferences, metadata); setCorrelatedReferences(subqueryContainer, correlatedReferences);
CorrelatedReferenceCollectorVisitor.collectReferences(subqueryContainer.getCommand(), Arrays.asList(container.getGroup()), correlatedReferences, metadata); setCorrelatedReferences(subqueryContainer, correlatedReferences);
CorrelatedReferenceCollectorVisitor.collectReferences(subqueryContainer.getCommand(), Arrays.asList(container.getGroup()), correlatedReferences, metadata); setCorrelatedReferences(subqueryContainer, correlatedReferences);