Package org.teiid.query.sql.symbol

Examples of org.teiid.query.sql.symbol.Expression


        }
        return actual;
   
   
    private Expression helpTestRewriteExpression(String original, String expected, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException {
      Expression actualExp = QueryParser.getQueryParser().parseExpression(original);
      ResolverVisitor.resolveLanguageObject(actualExp, metadata);
      CommandContext context = new CommandContext();
      context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
      actualExp = QueryRewriter.rewriteExpression(actualExp, null, context, metadata);
      if (expected != null) {
        Expression expectedExp = QueryParser.getQueryParser().parseExpression(expected);
        ResolverVisitor.resolveLanguageObject(expectedExp, metadata);
        assertEquals(expectedExp, actualExp);
      }
      return actualExp;
    }
View Full Code Here


    /*
     * Test for Object clone()
     */
    public void testClone() {
        ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
        Expression e1 = new Constant("abc"); //$NON-NLS-1$
        Expression e2 = new Constant("xyz"); //$NON-NLS-1$
        ArrayList whens = new ArrayList();
        whens.add(e1);
        whens.add(e2);
        Constant const1 = new Constant("a"); //$NON-NLS-1$
        Constant const2 = new Constant("b"); //$NON-NLS-1$
        ArrayList thens = new ArrayList();
        thens.add(const1);
        thens.add(const2);
        Expression elseExpression = new Constant("c"); //$NON-NLS-1$
        CaseExpression expr = new CaseExpression(x, whens, thens);
        expr.setElseExpression(elseExpression);
        expr.setType(DataTypeManager.DefaultDataClasses.STRING);
       
        CaseExpression clone = (CaseExpression)expr.clone();
View Full Code Here

        List<PlanNode> result = new LinkedList<PlanNode>();
       
        Float cardinality = null;
       
        for (int i = 0; i < dependentExpressions.size(); i++) {
            Expression depExpr = (Expression) dependentExpressions.get(i);
            Expression indepExpr = (Expression) independentExpressions.get(i);
            DependentSetCriteria crit = new DependentSetCriteria(SymbolMap.getExpression(depExpr), id);
            float ndv = NewCalculateCostUtil.UNKNOWN_VALUE;
            if (dca != null && dca.expectedNdv[i] != null) {
              if (dca.expectedNdv[i] > 4*dca.maxNdv[i]) {
                continue; //not necessary to use
View Full Code Here

            //List preExecNodes = new LinkedList();
                       
            for (Iterator params = proc.getInputParameters().iterator(); params.hasNext();) {
                SPParameter param = (SPParameter)params.next();
                ElementSymbol symbol = param.getParameterSymbol();
                Expression input = param.getExpression();
                inputReferences.add(input);
                inputSymbols.add(symbol);
            }
           
            findInputNodes(inputSymbols, critNode, conjuncts, coveredParams);
           
            List defaults = new LinkedList();
           
            for (Iterator params = inputReferences.iterator(); params.hasNext();) {
                Reference ref = (Reference)params.next();
                ElementSymbol symbol = ref.getExpression();
               
                Expression defaultValue = null;
               
                /*try {
                    defaultValue = ResolverUtil.getDefault(symbol, metadata);
                } catch (QueryResolverException qre) {
                    //Just ignore
View Full Code Here

            case NodeConstants.Types.TUPLE_LIMIT:
            {
                PlanNode child = node.getFirstChild();
                float childCost = child.getCardinality();
               
                Expression offset = (Expression)node.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT);
                Float cost = childCost;
               
                if (childCost != UNKNOWN_VALUE && offset instanceof Constant) {
                    float offsetCost = childCost - ((Number)((Constant)offset).getValue()).floatValue();
                    cost = new Float((offsetCost < 0) ? 0 : offsetCost);
                }
               
                Expression limit = (Expression)node.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
                if (limit instanceof Constant) {
                    float limitCost = ((Number)((Constant)limit).getValue()).floatValue();
                    if (cost.floatValue() != UNKNOWN_VALUE) {
                        cost = new Float(Math.min(limitCost, cost.floatValue()));
                    } else {
View Full Code Here

      }
      SetQuery.Operation setOp = (Operation) node.getProperty(Info.SET_OPERATION);
      List<? extends Expression> outputCols = getOutputCols(node, metadata);
      ColStats newColStats = new ColStats();
      for (int i = 0; i < outputCols.size(); i++) {
        Expression expr = outputCols.get(i);
        float[] newStats = new float[2];
        Arrays.fill(newStats, UNKNOWN_VALUE);
        if (childCardinality == UNKNOWN_VALUE || (setOp != null && (colStats == null || colStatsOther == null))) {
          //base case - cannot determine, just assume unique rows
            newStats[Stat.NDV.ordinal()] = cardinality;
View Full Code Here

                  for (Expression expr : outputCols) {
                    if (!(expr instanceof ElementSymbol)) {
                      continue;
                    }
                    ElementSymbol es = (ElementSymbol)expr;
                    Expression ex = symbolMap.getMappedExpression(es);
              newColStats.put(es, colStats.get(ex));
            }
                node.setProperty(Info.EST_COL_STATS, newColStats);
                } else {
                  colStats = createColStats(node, metadata, cost);
View Full Code Here

     * or if it will contain single match chars
     */
    private static float estimateMatchCost(float childCost,
                                           float ndv,
                                           MatchCriteria criteria) {
        Expression matchExpression = criteria.getRightExpression();
        if(matchExpression instanceof Constant && ((Constant)matchExpression).getType().equals(DataTypeManager.DefaultDataClasses.STRING)) {
            String compareValue = (String) ((Constant)matchExpression).getValue();
            if(compareValue != null && compareValue.indexOf('%') < 0) {
              return (childCost / 2) * (1 / 3f  + 1 / ndv); //without knowing length constraints we'll make an average guess
            }
View Full Code Here

        }   
    
        // Sort elements into groups
        Map<GroupSymbol, List<Object>> groupMap = new HashMap<GroupSymbol, List<Object>>();
        for (SingleElementSymbol ses : allElements) {
          Expression ex = SymbolMap.getExpression(ses);
          if (!(ex instanceof ElementSymbol)) {
            continue; //TODO: function based indexes are possible, but we don't have the metadata
          }
          ElementSymbol element = (ElementSymbol)ex;
            GroupSymbol group = element.getGroupSymbol();
View Full Code Here

                if (index != -1) {
                  if (insert.isBulk()) {
                    Constant multiValue = (Constant)insert.getValues().get(index);
                value = ((List<?>)multiValue.getValue()).get(row);
                  } else {
                    Expression expr = (Expression)insert.getValues().get(index);
                        value = Evaluator.evaluate(expr);
                  }
                }
                currentRow.add(value);
            }
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.symbol.Expression

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.