Package org.teiid.query.sql.symbol

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


      boolean convertLeft = false;
      Class setType = null;
 
      Iterator valIter = scrit.getValues().iterator();
      while(valIter.hasNext()) {
          Expression value = (Expression) valIter.next();
          setDesiredType(value, exprType, scrit);
          if(! value.getType().equals(exprType)) {
              // try to apply cast
              String valTypeName = DataTypeManager.getDataTypeName(value.getType());
              if(ResolverUtil.canImplicitlyConvert(valTypeName, exprTypeName)) {
                  // Apply cast and replace current value
                  newVals.add(ResolverUtil.convertExpression(value, valTypeName, exprTypeName, metadata) );
                  changed = true;
              } else {
                  convertLeft = true;
                  setType = value.getType();
                  break;
              }
          } else {
              newVals.add(value);
          }
      }
 
      // If no convert found for first element, check whether everything in the
      // set is the same and the convert can be placed on the left side
      if(convertLeft) {
          // Is there a possible conversion from left to right?
          String setTypeName = DataTypeManager.getDataTypeName(setType);
          if(ResolverUtil.canImplicitlyConvert(exprTypeName, setTypeName)) {
              valIter = scrit.getValues().iterator();
              while(valIter.hasNext()) {
                  Expression value = (Expression) valIter.next();
                  if(value.getType() == null) {
                      throw new QueryResolverException("ERR.015.008.0030", QueryPlugin.Util.getString("ERR.015.008.0030", value)); //$NON-NLS-1$ //$NON-NLS-2$
                  } else if(! value.getType().equals(setType)) {
                      throw new QueryResolverException("ERR.015.008.0031", QueryPlugin.Util.getString("ERR.015.008.0031", scrit)); //$NON-NLS-1$ //$NON-NLS-2$
                  }
              }
 
              // Convert left expression to type of values in the set
View Full Code Here


      // If already resolved, do nothing
      if (obj.getType() != null) {
          return;
      }
      final int whenCount = obj.getWhenCount();
      Expression expr = obj.getExpression();
 
      Class whenType = null;
      Class thenType = null;
      // Get the WHEN and THEN types, and get a candidate type for each (for the next step)
      for (int i = 0; i < whenCount; i++) {
          if (whenType == null) {
              whenType = obj.getWhenExpression(i).getType();
          }
          if (thenType == null) {
              thenType = obj.getThenExpression(i).getType();
          }
      }
 
      Expression elseExpr = obj.getElseExpression();
      if (elseExpr != null) {
          if (thenType == null) {
              thenType = elseExpr.getType();
          }
      }
      // Invariant: All the expressions contained in the obj are resolved (except References)
 
      // 2. Attempt to set the target types of all contained expressions,
      //    and collect their type names for the next step
      ArrayList whenTypeNames = new ArrayList(whenCount + 1);
      ArrayList thenTypeNames = new ArrayList(whenCount + 1);
      setDesiredType(expr, whenType, obj);
      // Add the expression's type to the WHEN types
      whenTypeNames.add(DataTypeManager.getDataTypeName(expr.getType()));
      Expression when = null;
      Expression then = null;
      // Set the types of the WHEN and THEN parts
      for (int i = 0; i < whenCount; i++) {
          when = obj.getWhenExpression(i);
          then = obj.getThenExpression(i);
 
          setDesiredType(when, expr.getType(), obj);
          setDesiredType(then, thenType, obj);
 
          if (!whenTypeNames.contains(DataTypeManager.getDataTypeName(when.getType()))) {
              whenTypeNames.add(DataTypeManager.getDataTypeName(when.getType()));
          }
          if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(then.getType()))) {
              thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
          }
      }
      // Set the type of the else expression
      if (elseExpr != null) {
          setDesiredType(elseExpr, thenType, obj);
View Full Code Here

          if (thenType == null) {
              thenType = obj.getThenExpression(i).getType();
          }
      }
 
      Expression elseExpr = obj.getElseExpression();
      if (elseExpr != null) {
          if (thenType == null) {
              thenType = elseExpr.getType();
          }
      }
      // Invariant: All the expressions contained in the obj are resolved (except References)
 
      // 2. Attempt to set the target types of all contained expressions,
      //    and collect their type names for the next step
      ArrayList thenTypeNames = new ArrayList(whenCount + 1);
      Expression then = null;
      // Set the types of the WHEN and THEN parts
      for (int i = 0; i < whenCount; i++) {
          then = obj.getThenExpression(i);
          setDesiredType(then, thenType, obj);
          if (!thenTypeNames.contains(DataTypeManager.getDataTypeName(then.getType()))) {
              thenTypeNames.add(DataTypeManager.getDataTypeName(then.getType()));
          }
      }
      // Set the type of the else expression
      if (elseExpr != null) {
          setDesiredType(elseExpr, thenType, obj);
View Full Code Here

            throw new IllegalArgumentException(QueryPlugin.Util.getString("QueryParser.nullSqlExpr")); //$NON-NLS-1$
        }

        ParseInfo dummyInfo = new ParseInfo();

        Expression result = null;
        try{
            result = getSqlParser(sql).expression(dummyInfo);

        } catch(ParseException pe) {
            throw convertParserException(pe);
View Full Code Here

    @Test(expected=ExpressionEvaluationException.class) public void testCommandPayloadArgWithBadPayload() throws Exception {
        helpTestCommandPayload(Boolean.TRUE, "BOGUS", null); //$NON-NLS-1$
    }
   
    @Test public void testBigDecimalFromDoubleDivision() throws Exception {
      Expression ex = TestFunctionResolving.getExpression("convert(1.0, bigdecimal)/3");
      assertEquals(new BigDecimal("0.3333333333333333"), Evaluator.evaluate(ex));
    }
View Full Code Here

      Expression ex = TestFunctionResolving.getExpression("convert(1.0, bigdecimal)/3");
      assertEquals(new BigDecimal("0.3333333333333333"), Evaluator.evaluate(ex));
    }
   
    @Test public void testBigDecimalDivision() throws Exception {
      Expression ex = TestFunctionResolving.getExpression("1/convert('3.0', bigdecimal)");
      assertEquals(new BigDecimal("0.3333333333333333"), Evaluator.evaluate(ex));
    }
View Full Code Here

        for (XMLTable.XMLColumn column : obj.getColumns()) {
          if (column.getDefaultExpression() == null) {
            continue;
          }
          ResolverVisitor.resolveLanguageObject(column.getDefaultExpression(), metadata);
          Expression ex = ResolverUtil.convertExpression(column.getDefaultExpression(), DataTypeManager.getDataTypeName(column.getSymbol().getType()), metadata);
          column.setDefaultExpression(ex);
        }
      } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
      }
View Full Code Here

            if (symbol.getType() != type) {
                if (symbol instanceof AliasSymbol) {
                    symbol = ((AliasSymbol)symbol).getSymbol();
                }

                Expression expr = symbol;
                if (symbol instanceof ExpressionSymbol) {
                    expr = ((ExpressionSymbol)symbol).getExpression();
                }
               
                try {
View Full Code Here

               
                AssignmentStatement assignStmt = (AssignmentStatement)statement;
               
                assignInstr.setVariable(assignStmt.getVariable());
               
        Expression asigExpr = assignStmt.getExpression();
                assignInstr.setExpression(asigExpr);
                if(debug) {
                  analysisRecord.println("\tASSIGNMENT\n" + statement); //$NON-NLS-1$
                }
        break;
            }
            case Statement.TYPE_ERROR:
            {
              ErrorInstruction error = new ErrorInstruction();
              instruction = error;
              RaiseErrorStatement res = (RaiseErrorStatement)statement;
               
        Expression asigExpr = res.getExpression();
        error.setExpression(asigExpr);
                if(debug) {
                  analysisRecord.println("\tERROR STATEMENT:\n" + statement); //$NON-NLS-1$
                }
              break;
            }
      case Statement.TYPE_COMMAND:
            {
        CommandStatement cmdStmt = (CommandStatement) statement;
                Command command = cmdStmt.getCommand();
        ProcessorPlan commandPlan = cmdStmt.getCommand().getProcessorPlan();               
               
        if (command.getType() == Command.TYPE_DYNAMIC){
          instruction = new ExecDynamicSqlInstruction(parentProcCommand,((DynamicCommand)command), metadata, idGenerator, capFinder );
        }else{
          instruction = new CreateCursorResultSetInstruction(CreateCursorResultSetInstruction.RS_NAME, commandPlan,
              command.getType() == Command.TYPE_INSERT
              || command.getType() == Command.TYPE_UPDATE
              || command.getType() == Command.TYPE_DELETE);
          //handle stored procedure calls
          if (command.getType() == Command.TYPE_STORED_PROCEDURE) {
            StoredProcedure sp = (StoredProcedure)command;
            if (sp.isCallableStatement()) {
              Map<ElementSymbol, ElementSymbol> assignments = new LinkedHashMap<ElementSymbol, ElementSymbol>();
              for (SPParameter param : sp.getParameters()) {
                if (param.getParameterType() == SPParameter.RESULT_SET
                    || param.getParameterType() == SPParameter.IN) {
                  continue;
                }
                Expression expr = param.getExpression();
                if (expr instanceof Reference) {
                  expr = ((Reference)expr).getExpression();
                }
                ElementSymbol symbol = null;
                if (expr instanceof ElementSymbol) {
View Full Code Here

        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));
      if (DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(ex.getType()))) {
        continue;
      }
      if (ex instanceof Constant) {
        result.put(projectedSymbols.get(i), Collections.singleton((Constant)ex));
      } else {
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.