Package org.teiid.query.sql.lang

Examples of org.teiid.query.sql.lang.SetCriteria


public class TestDependentCriteriaProcessor {

  @Test public void testNegatedSetCriteria() throws Exception {
    DependentAccessNode dan = new DependentAccessNode(0);
    SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), Arrays.asList(new Constant(1), new Constant(2))); //$NON-NLS-1$
    DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc);
    Criteria result = dcp.prepareCriteria();
    assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result); //$NON-NLS-1$
    assertTrue(dcp.hasNextCommand());
  }
View Full Code Here


    dan.setContext(cc);
    List<Reference> references = Arrays.asList(new Reference(1), new Reference(2));
    for (Reference reference : references) {
      cc.getVariableContext().setGlobalValue(reference.getContextSymbol(), 1);
    }
    SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), references); //$NON-NLS-1$
    DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc);
    Criteria result = dcp.prepareCriteria();
    assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result); //$NON-NLS-1$
    assertFalse(dcp.hasNextCommand());
  }
View Full Code Here

    }
   
    @Test public void testRewriteInCriteriaWithNoValues() throws Exception {
      ElementSymbol e1 = new ElementSymbol("e1");
      e1.setGroupSymbol(new GroupSymbol("g1"));
        Criteria crit = new SetCriteria(e1, Collections.EMPTY_LIST); //$NON-NLS-1$
       
        Criteria actual = QueryRewriter.rewriteCriteria(crit, null, null, null);
       
        IsNullCriteria inc = new IsNullCriteria(e1);
        inc.setNegated(true);
View Full Code Here

        ArrayList values = new ArrayList();
        values.add(TestLiteralImpl.helpExample(100));
        values.add(TestLiteralImpl.helpExample(200));
        values.add(TestLiteralImpl.helpExample(300));
        values.add(TestLiteralImpl.helpExample(400));
        SetCriteria crit = new SetCriteria(TestLiteralImpl.helpExample(300), values);
        crit.setNegated(negated);
        return crit;
    }
View Full Code Here

            cost = estimateMatchCost(childCost, ndv, matchCriteria);
           
            isNegatedPredicateCriteria = matchCriteria.isNegated();

        } else if(predicateCriteria instanceof SetCriteria) {
            SetCriteria setCriteria = (SetCriteria) predicateCriteria;
            if (unknownChildCost) {
                return UNKNOWN_VALUE;
            }
            cost = childCost * setCriteria.getNumberOfValues() / ndv;
           
            isNegatedPredicateCriteria = setCriteria.isNegated();
           
        } else if(predicateCriteria instanceof SubquerySetCriteria) {
            SubquerySetCriteria setCriteria = (SubquerySetCriteria) predicateCriteria;
           
            // TODO - use inner ProcessorPlan cardinality estimates
            // to determine the estimated number of values
            if (unknownChildCost) {
                return UNKNOWN_VALUE;
            }
            cost = childCost / 3;
           
            isNegatedPredicateCriteria = setCriteria.isNegated();

        } else if(predicateCriteria instanceof IsNullCriteria) {
            IsNullCriteria isNullCriteria = (IsNullCriteria)predicateCriteria;

            float nnv = getStat(Stat.NNV, elements, currentNode, childCost, metadata);
View Full Code Here

                       return converted;
                     }
                    } else {
                      //or
                      if (converted instanceof SetCriteria) {
                        SetCriteria sc = (SetCriteria)converted;
                        if (!sc.isNegated() && sc.isAllConstants()) {
                        Criteria crit = exprMap.get(sc.getExpression());
                        if (crit == null) {
                          exprMap.put(sc.getExpression(), sc);
                        } else if (crit instanceof SetCriteria) {
                          SetCriteria other = (SetCriteria)crit;
                          other.getValues().addAll(sc.getValues());
                          continue;
                        } else {
                          newCrits.remove(crit);
                          CompareCriteria cc = (CompareCriteria)crit;
                          sc.getValues().add(cc.getRightExpression());
                        }
                      }
                      } else if (converted instanceof CompareCriteria) {
                        CompareCriteria cc = (CompareCriteria)converted;
                        if (cc.getOperator() == CompareCriteria.EQ && cc.getRightExpression() instanceof Constant) {
                        Criteria crit = exprMap.get(cc.getLeftExpression());
                        if (crit == null) {
                          exprMap.put(cc.getLeftExpression(), cc);
                        } else if (crit instanceof SetCriteria) {
                          SetCriteria other = (SetCriteria)crit;
                          other.getValues().add(cc.getRightExpression());
                          continue;
                        } else {
                          newCrits.remove(crit);
                          CompareCriteria other = (CompareCriteria)crit;
                          SetCriteria sc = new SetCriteria(cc.getLeftExpression(), new LinkedHashSet<Expression>());
                          sc.setAllConstants(true);
                          sc.getValues().add(cc.getRightExpression());
                          sc.getValues().add(other.getRightExpression());
                          exprMap.put(sc.getExpression(), sc);
                          converted = sc;
                        }
                        }
                      }
                        newCrits.add(converted);
View Full Code Here

              } else if (!(crit instanceof IsNullCriteria)) {
                return FALSE_CRITERIA;
              }
          }
        } else if (converted instanceof SetCriteria) {
          SetCriteria sc = (SetCriteria)converted;
          Criteria crit = exprMap.get(sc.getExpression());
          if (crit instanceof IsNullCriteria) {
            return FALSE_CRITERIA;
          }
          if (!sc.isNegated() && sc.isAllConstants()) {
              if (crit == null) {
                exprMap.put(sc.getExpression(), converted);
              } else if (crit instanceof SetCriteria) {
                SetCriteria sc1 = (SetCriteria)crit;
                newCrits.remove(sc1);
                sc1.getValues().retainAll(sc.getValues());
                if (sc1.getValues().isEmpty()) {
                  return FALSE_CRITERIA;
                }
                //TODO: single value as compare criteria
                newCrits.add(sc1);
                exprMap.put(sc1.getExpression(), sc1);
                return null;
              } else {
                CompareCriteria cc = (CompareCriteria)crit;
                for (Iterator<Constant> exprIter = sc.getValues().iterator(); exprIter.hasNext();) {
            if (!Evaluator.compare(cc, exprIter.next().getValue(), ((Constant)cc.getRightExpression()).getValue())) {
              exprIter.remove();
            }
          }
                if (sc.getValues().isEmpty()) {
                  return FALSE_CRITERIA;
                }
                if (cc.getOperator() != CompareCriteria.EQ) {
                    newCrits.remove(cc);
                    //TODO: single value as compare criteria
                    exprMap.put(sc.getExpression(), sc);
                } else {
                  return null;
                }
              }
          }
        } else if (converted instanceof CompareCriteria) {
          CompareCriteria cc = (CompareCriteria)converted;
          Criteria crit = exprMap.get(cc.getLeftExpression());
          if (crit instanceof IsNullCriteria) {
            return FALSE_CRITERIA;
          }
          if (cc.getRightExpression() instanceof Constant) {
              if (crit == null) {
                exprMap.put(cc.getLeftExpression(), cc);
              } else if (crit instanceof SetCriteria) {
                SetCriteria sc = (SetCriteria)crit;
                boolean modified = false;
                for (Iterator<Constant> exprIter = sc.getValues().iterator(); exprIter.hasNext();) {
            if (!Evaluator.compare(cc, exprIter.next().getValue(), ((Constant)cc.getRightExpression()).getValue())) {
              if (!modified) {
                modified = true;
                newCrits.remove(sc);
              }
              exprIter.remove();
            }
          }
                //TODO: single value as compare criteria
                if (sc.getValues().isEmpty()) {
                  return FALSE_CRITERIA;
                }
                if (cc.getOperator() == CompareCriteria.EQ) {
                    exprMap.put(cc.getLeftExpression(), cc);
                } else if (modified) {
                  newCrits.add(sc);
                  exprMap.put(sc.getExpression(), sc);
                    return null;
                }
              } else {
                CompareCriteria cc1 = (CompareCriteria)crit;
                if (cc1.getOperator() == CompareCriteria.NE) {
View Full Code Here

   
    private void helpTestSetCriteria(Integer value, boolean negated, boolean expectedMatch) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
        Collection constants = new ArrayList(2);
        constants.add(new Constant(new Integer(1000)));
        constants.add(new Constant(new Integer(5000)));
        SetCriteria crit = new SetCriteria(new Constant(value), constants);
        crit.setNegated(negated);
        boolean result = Evaluator.evaluate(crit);
        assertEquals("Result did not match expected value", expectedMatch, result); //$NON-NLS-1$
    }
View Full Code Here

            }
            if (prefix.length() > 0) {
              this.addCondition(i, new Constant(prefix.toString()), CompareCriteria.GE);
            }
          } else if (criteria instanceof SetCriteria) {
            SetCriteria setCriteria = (SetCriteria)criteria;
            if (!setCriteria.getExpression().equals(keyColumn) || !setCriteria.isAllConstants()) {
              continue;
            }
            Collection<Constant> values = (Collection<Constant>) setCriteria.getValues();
            this.addSet(i, values);
          }
        }
      }
    }
View Full Code Here

        continue;
      }
      if (!(criteria instanceof SetCriteria)) {
        continue;
      }
      SetCriteria sc = (SetCriteria)criteria;
      HashSet<Constant> values = new HashSet<Constant>();
      boolean allConstants = true;
      for (Expression exp : (Collection<Expression>)sc.getValues()) {
        if (exp instanceof Constant) {
          values.add((Constant)exp);
        } else {
          allConstants = false;
          break;
        }
      }
      if (allConstants) {
        inMap.put(sc.getExpression(), values);
      }
    }
    Map<ElementSymbol, Set<Constant>> result = new HashMap<ElementSymbol, Set<Constant>>();
    for (int i = 0; i < projected.size(); i++) {
      Expression ex = SymbolMap.getExpression(projected.get(i));
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.lang.SetCriteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.