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);
}
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());
}
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;
}
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);
}
}
}
}
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;
}
Aggregations