Search in sources :

Example 1 with DependentSetCriteria

use of org.teiid.query.sql.lang.DependentSetCriteria in project teiid by teiid.

the class DependentCriteriaProcessor method replaceDependentCriteria.

public Criteria replaceDependentCriteria(AbstractSetCriteria crit, SetState state) throws TeiidComponentException {
    if (state.overMax) {
        DependentValueSource originalVs = (DependentValueSource) dependentNode.getContext().getVariableContext().getGlobalValue(((DependentSetCriteria) crit).getContextSymbol());
        originalVs.setUnused(true);
        return QueryRewriter.TRUE_CRITERIA;
    }
    if (state.replacement.isEmpty()) {
        // No values - return criteria that is always false
        return QueryRewriter.FALSE_CRITERIA;
    }
    int numberOfSets = 1;
    int setSize = Integer.MAX_VALUE;
    if (this.maxSetSize > 0) {
        setSize = (int) Math.max(1, this.maxSetSize / state.valueCount);
        numberOfSets = state.replacement.size() / setSize + (state.replacement.size() % setSize != 0 ? 1 : 0);
    }
    Iterator<Constant> iter = state.replacement.iterator();
    ArrayList<Criteria> orCrits = new ArrayList<Criteria>(numberOfSets);
    for (int i = 0; i < numberOfSets; i++) {
        if (setSize == 1 || i + 1 == state.replacement.size()) {
            orCrits.add(new CompareCriteria(crit.getExpression(), CompareCriteria.EQ, iter.next()));
        } else {
            List<Constant> vals = new ArrayList<Constant>(Math.min(state.replacement.size(), setSize));
            for (int j = 0; j < setSize && iter.hasNext(); j++) {
                Constant val = iter.next();
                vals.add(val);
            }
            SetCriteria sc = new SetCriteria();
            sc.setExpression(crit.getExpression());
            sc.setValues(vals);
            orCrits.add(sc);
        }
    }
    if (orCrits.size() == 1) {
        return orCrits.get(0);
    }
    return new CompoundCriteria(CompoundCriteria.OR, orCrits);
}
Also used : DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) Constant(org.teiid.query.sql.symbol.Constant) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) AbstractSetCriteria(org.teiid.query.sql.lang.AbstractSetCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) Criteria(org.teiid.query.sql.lang.Criteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) AbstractSetCriteria(org.teiid.query.sql.lang.AbstractSetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 2 with DependentSetCriteria

use of org.teiid.query.sql.lang.DependentSetCriteria in project teiid by teiid.

the class TestDependentSetCriteria method testEquivalence.

public void testEquivalence() {
    DependentSetCriteria dsc = example();
    UnitTestUtil.helpTestEquivalence(0, dsc, dsc);
    UnitTestUtil.helpTestEquivalence(0, dsc, dsc.clone());
}
Also used : DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria)

Example 3 with DependentSetCriteria

use of org.teiid.query.sql.lang.DependentSetCriteria in project teiid by teiid.

the class RulePushSelectCriteria method moveNodeAcrossFrame.

Boolean moveNodeAcrossFrame(PlanNode critNode, PlanNode sourceNode, final QueryMetadataInterface metadata) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
    // Check that sourceNode has a child to push across
    if (sourceNode.getChildCount() == 0) {
        return false;
    }
    final PlanNode projectNode = NodeEditor.findNodePreOrder(sourceNode.getFirstChild(), NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE);
    if (FrameUtil.isProcedure(projectNode)) {
        return false;
    }
    final SymbolMap symbolMap = (SymbolMap) sourceNode.getProperty(NodeConstants.Info.SYMBOL_MAP);
    final GroupSymbol sourceGroup = sourceNode.getGroups().iterator().next();
    if (!placeConvertedSelectNode(critNode, sourceGroup, projectNode, symbolMap, metadata)) {
        if (createdNodes == null) {
            Criteria crit = (Criteria) critNode.getProperty(NodeConstants.Info.SELECT_CRITERIA);
            if (isMultiAttributeDependentSet(crit) && splitSet(critNode, new DependentNodeTest() {

                @Override
                public boolean isValid(PlanNode copyNode) throws QueryMetadataException, QueryPlannerException, TeiidComponentException {
                    return createConvertedSelectNode(copyNode, sourceGroup, projectNode, symbolMap, metadata) != null;
                }
            }, (DependentSetCriteria) crit, sourceNode)) {
                return null;
            }
        }
        return false;
    }
    if (createdNodes == null) {
        satisfyConditions(critNode, sourceNode, metadata);
    }
    // Mark critNode as a "phantom"
    critNode.setProperty(NodeConstants.Info.IS_PHANTOM, Boolean.TRUE);
    return true;
}
Also used : DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) SymbolMap(org.teiid.query.sql.util.SymbolMap) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

Example 4 with DependentSetCriteria

use of org.teiid.query.sql.lang.DependentSetCriteria in project teiid by teiid.

the class RulePushSelectCriteria method markDependent.

private void markDependent(PlanNode critNode, PlanNode accessNode, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws QueryMetadataException, TeiidComponentException {
    // once a dependent crit node is pushed, don't bother pushing it further into the command
    // dependent access node will use this as an assumption for where dependent sets can appear in the command
    critNode.setProperty(NodeConstants.Info.IS_PUSHED, Boolean.TRUE);
    if (createdNodes != null) {
        // this is during a planning run and should not cause additional side-effects
        return;
    }
    accessNode.setProperty(NodeConstants.Info.IS_DEPENDENT_SET, Boolean.TRUE);
    Criteria crit = (Criteria) critNode.getProperty(NodeConstants.Info.SELECT_CRITERIA);
    if (isMultiAttributeDependentSet(crit)) {
        // split the criteria as needed
        List<DependentSetCriteria> crits = splitDependentSetCriteria((DependentSetCriteria) crit, CapabilitiesUtil.supports(Capability.ARRAY_TYPE, RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder), metadata);
        critNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, new CompoundCriteria(crits));
    }
    Collection<ElementSymbol> elements = null;
    for (PlanNode joinNode : NodeEditor.findAllNodes(accessNode, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE)) {
        List<Criteria> joinCriteria = (List<Criteria>) joinNode.getProperty(Info.JOIN_CRITERIA);
        if (joinCriteria == null) {
            continue;
        }
        for (Criteria joinPredicate : joinCriteria) {
            if (!(joinPredicate instanceof CompareCriteria)) {
                continue;
            }
            CompareCriteria cc = (CompareCriteria) joinPredicate;
            if (!cc.isOptional()) {
                continue;
            }
            if (elements == null) {
                elements = ElementCollectorVisitor.getElements((LanguageObject) critNode.getProperty(Info.SELECT_CRITERIA), true);
            }
            if (!Collections.disjoint(elements, ElementCollectorVisitor.getElements(cc, false))) {
                cc.setOptional(false);
            }
        }
    }
}
Also used : DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 5 with DependentSetCriteria

use of org.teiid.query.sql.lang.DependentSetCriteria in project teiid by teiid.

the class RulePushSelectCriteria method splitSet.

private boolean splitSet(PlanNode critNode, DependentNodeTest test, DependentSetCriteria dscOrig, PlanNode destination) throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
    boolean result = false;
    List<DependentSetCriteria> dscList = splitDependentSetCriteria(dscOrig, false, null);
    List<DependentSetCriteria.AttributeComparison> pushable = new ArrayList<AttributeComparison>();
    List<DependentSetCriteria.AttributeComparison> nonPushable = new ArrayList<AttributeComparison>();
    for (DependentSetCriteria dsc : dscList) {
        PlanNode copyNode = copyNode(critNode);
        setCriteria(dsc, copyNode);
        if (test.isValid(copyNode)) {
            pushable.add(dsc.getAttributes().get(0));
        } else {
            nonPushable.add(dsc.getAttributes().get(0));
        }
    }
    if (!pushable.isEmpty()) {
        // signal that we should run again
        result = true;
        if (nonPushable.isEmpty()) {
            // $NON-NLS-1$
            throw new AssertionError("should not be completely pushed");
        }
        setCriteria(RuleChooseDependent.createDependentSetCriteria(dscOrig.getContextSymbol(), nonPushable), critNode);
        PlanNode copyNode = copyNode(critNode);
        setCriteria(RuleChooseDependent.createDependentSetCriteria(dscOrig.getContextSymbol(), pushable), copyNode);
        // it should be pushed in the next run
        destination.addAsParent(copyNode);
    }
    return result;
}
Also used : DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) AttributeComparison(org.teiid.query.sql.lang.DependentSetCriteria.AttributeComparison)

Aggregations

DependentSetCriteria (org.teiid.query.sql.lang.DependentSetCriteria)15 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)8 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)7 Criteria (org.teiid.query.sql.lang.Criteria)7 CompoundCriteria (org.teiid.query.sql.lang.CompoundCriteria)6 AttributeComparison (org.teiid.query.sql.lang.DependentSetCriteria.AttributeComparison)6 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)5 LanguageObject (org.teiid.query.sql.LanguageObject)3 SetCriteria (org.teiid.query.sql.lang.SetCriteria)3 Expression (org.teiid.query.sql.symbol.Expression)3 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)3 ArrayList (java.util.ArrayList)2 AbstractSetCriteria (org.teiid.query.sql.lang.AbstractSetCriteria)2 Array (org.teiid.query.sql.symbol.Array)2 Collection (java.util.Collection)1 LanguageVisitor (org.teiid.query.sql.LanguageVisitor)1 IsNullCriteria (org.teiid.query.sql.lang.IsNullCriteria)1 Constant (org.teiid.query.sql.symbol.Constant)1 Reference (org.teiid.query.sql.symbol.Reference)1 SymbolMap (org.teiid.query.sql.util.SymbolMap)1