Package org.teiid.query.sql.symbol

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


        Constant c = helpExample(val);
        return new Literal(c.getValue(), c.getType());
    }

    public static Literal example(Object val) {
        Constant c = helpExample(val);
        return new Literal(c.getValue(), c.getType());
    }
View Full Code Here


        ElementSymbol col1 = new ElementSymbol("col1"); //$NON-NLS-1$
        col1.setType(Integer.class);
        ElementSymbol col2 = new ElementSymbol("col2"); //$NON-NLS-1$
        col2.setType(Integer.class);
       
        Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), col2 }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        FunctionDescriptor desc = FakeMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class } ); //$NON-NLS-1$
        func.setFunctionDescriptor(desc);
        func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
       
        outputElements.add(col1);
View Full Code Here

        float cost = childCost;
        try{
            float maxValue = 0;
            float minValue = 0;

            Constant value = (Constant)compCrit.getRightExpression();
            float compareValue = 0;
          // Case 6257 - handling added for time and date.  If the max/min values are not
            // in the expected format, NumberFormatException is thrown and reverts to default costing.
            if(dataType.equals(DataTypeManager.DefaultDataClasses.TIMESTAMP)) {
                compareValue = ((Timestamp)value.getValue()).getTime();
                maxValue = Timestamp.valueOf(max).getTime();
                minValue = Timestamp.valueOf(min).getTime();
            } else if(dataType.equals(DataTypeManager.DefaultDataClasses.TIME)) {
                compareValue = ((Time)value.getValue()).getTime();
                maxValue = Time.valueOf(max).getTime();
                minValue = Time.valueOf(min).getTime();
            // (For date, our costing sets the max and min values using timestamp format)
            } else if(dataType.equals(DataTypeManager.DefaultDataClasses.DATE)) {
                compareValue = ((Date)value.getValue()).getTime();
                maxValue = Timestamp.valueOf(max).getTime();
                minValue = Timestamp.valueOf(min).getTime();
            } else {
              if(!Number.class.isAssignableFrom(dataType)) {
                    if (unknownChildCost) {
                        return UNKNOWN_VALUE;
                    }
                    return childCost/3;
                }
                compareValue = ((Number)value.getValue()).floatValue();
                maxValue = Integer.parseInt(max);
                minValue = Integer.parseInt(min);
            }
            float range = Math.max(maxValue - minValue, 1);
           
View Full Code Here

    }
   
  public static List<List<Object>> getBulkRows(Insert insert, List<ElementSymbol> elements) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    int bulkRowCount = 1;
    if (insert.isBulk()) {
      Constant c = (Constant)insert.getValues().get(0);
      bulkRowCount = ((List<?>)c.getValue()).size();
    }
   
    List<List<Object>> tuples = new ArrayList<List<Object>>(bulkRowCount);
   
    for (int row = 0; row < bulkRowCount; row++) {
      List<Object> currentRow = new ArrayList<Object>(insert.getValues().size());
      for (ElementSymbol symbol : elements) {
                int index = insert.getVariables().indexOf(symbol);
                Object value = null;
                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);
                  }
                }
View Full Code Here

            {
                if (RelationalNodeUtil.isUpdate(accessNode.getCommand())) {
                  //should return a 0 update count
                  ProjectNode pnode = new ProjectNode(getID());
                  pnode.setElements(accessNode.getElements());
                  pnode.setSelectSymbols(Arrays.asList(new ExpressionSymbol("x", new Constant(0)))); //$NON-NLS-1$
                  return pnode;
                }
                // Replace existing access node with a NullNode
                NullNode nullNode = new NullNode(getID());
                nullNode.setElements(accessNode.getElements());
View Full Code Here

        if (param.getParameterType() != SPParameter.IN) {
          continue;
        }
        String shortName = SingleElementSymbol.getShortName(param.getName());       
          if(shortName.equalsIgnoreCase(MultiSourceElement.MULTI_SOURCE_ELEMENT_NAME)) {
              Constant source = (Constant)param.getExpression();
            params.remove();
            if (param.isUsingDefault() && source.isNull()) {
              continue;
            }
              if (!source.getValue().equals(sourceName)) {
                return null;
              }
            }
      }
    } if (command instanceof Insert) {
      Insert obj = (Insert)command;
      for (int i = 0; i < obj.getVariables().size(); i++) {
        ElementSymbol elem = obj.getVariables().get(i);
            Object metadataID = elem.getMetadataID();           
            if(metadataID instanceof MultiSourceElement) {
              Constant source = (Constant)obj.getValues().get(i);
            obj.getVariables().remove(i);
            obj.getValues().remove(i);
              if (!source.getValue().equals(sourceName)) {
                return null;
              }
            }
      }
    } else {
View Full Code Here

    public static List getWhenCriteria(int criteria) {
        ArrayList list = new ArrayList();
        ElementSymbol x = TestElementImpl.helpExample("vm1.g1", "e1"); //$NON-NLS-1$ //$NON-NLS-2$
        for (int i = 0; i < criteria; i++) {
            list.add(new CompareCriteria(x, CompareCriteria.EQ, new Constant(new Integer(i))));
        }
        return list;
    }
View Full Code Here

        return list;
    }
   
    public static SearchedCaseExpression helpExample() {
        SearchedCaseExpression caseExpr = new SearchedCaseExpression(getWhenCriteria(3), TestCaseExpression.getThenExpressions(3));
        caseExpr.setElseExpression(new Constant(new Integer(9999)));
        return caseExpr;
    }
View Full Code Here

        super(name);
    }

    public static MatchCriteria helpExample(String right, char escape, boolean negated) {
        ElementSymbol e1 = TestElementImpl.helpExample("vm1.g1", "e1"); //$NON-NLS-1$ //$NON-NLS-2$
        MatchCriteria match = new MatchCriteria(e1, new Constant(right), escape);
        match.setNegated(negated);
        return match;
    }
View Full Code Here

                joinStrategy = new MergeJoinStrategy(SortOption.SORT, SortOption.SORT, false);
                join.setJoinStrategy(joinStrategy);
                break;

            case FUNCTION_CRITERIA :
                Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                FunctionDescriptor desc = FakeMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class }); //$NON-NLS-1$
                func.setFunctionDescriptor(desc);
                func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
                CompareCriteria joinCriteria = new CompareCriteria(es2, CompareCriteria.EQ, func);
                join.setJoinCriteria(joinCriteria);
View Full Code Here

TOP

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

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.