Package org.teiid.query.sql.symbol

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


    private void helpTestMatch(String value, String pattern, char escape, boolean expectedMatch) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
        helpTestMatch(value, pattern, escape, false, expectedMatch);
    }
 
    private void helpTestIsNull(String value, boolean negated, boolean expectedMatch) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
        IsNullCriteria criteria = new IsNullCriteria(new Constant(value));
        criteria.setNegated(negated);
       
        boolean result = Evaluator.evaluate(criteria);
        assertEquals("Result did not match expected value", expectedMatch, result); //$NON-NLS-1$
    }
View Full Code Here


        helpTestSetCriteria(new Integer(value), negated, expectedMatch);
    }
   
    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

   
    /**
     * Big decimal comparisons should ignore precision.
     */
    @Test public void testBigDecimalEquality() throws Exception {
      CompareCriteria crit = new CompareCriteria(new Constant(new BigDecimal("3.10")), CompareCriteria.EQ, new Constant(new BigDecimal("3.1"))); //$NON-NLS-1$ //$NON-NLS-2$
      assertTrue(Evaluator.evaluate(crit));
    }
View Full Code Here

        if (rsInfo.getUserRowLimit() != -1) {
            int limit = rsInfo.getUserRowLimit();
            if (rsInfo.exceptionOnRowlimit()) {
                limit++;
            }
            rsQuery.setLimit(new Limit(null, new Constant(new Integer(limit))));
        }
       
        //prepareQuery(sourceNode, planEnv, rsQuery);
       
        // this query is not eligible for staging; proceed normally.
View Full Code Here

          return null;
        }

        try {
          //try to get the converted constant, if this fails then it is not in a valid format
          Constant result = getProperlyTypedConstant(constant.getValue(), DataTypeManager.getDataTypeClass(targetTypeName));
         
          if (DataTypeManager.DefaultDataTypes.STRING.equals(sourceTypeName)) {
            if (DataTypeManager.DefaultDataTypes.CHAR.equals(targetTypeName)) {
              String value = (String)constant.getValue();
              if (value != null && value.length() != 1) {
                return null;
              }
            }
            return result;
          }
         
          //for non-strings, ensure that the conversion is consistent
          if (!DataTypeManager.isTransformable(targetTypeName, sourceTypeName)) {
            return null;
          }
       
          if (!(constant.getValue() instanceof Comparable)) {
            return null; //this is the case for xml constants
          }
         
          Constant reverse = getProperlyTypedConstant(result.getValue(), constant.getType());
         
          if (((Comparable)constant.getValue()).compareTo(reverse.getValue()) == 0) {
              return result;
          }
        } catch (QueryResolverException e) {
         
        }
View Full Code Here

      }
      TempTable tempTable = globalStore.getOrCreateTempTable(matTableName, new Query(), bufferManager, false);
      if (!tempTable.isUpdatable()) {
        throw new QueryProcessingException(QueryPlugin.Util.getString("TempTableDataManager.row_refresh_updatable", matViewName)); //$NON-NLS-1$
      }
      Constant key = (Constant)proc.getParameter(2).getExpression();
      LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.getString("TempTableDataManager.row_refresh", matViewName, key)); //$NON-NLS-1$
      String queryString = Reserved.SELECT + " * " + Reserved.FROM + ' ' + matViewName + ' ' + Reserved.WHERE + ' ' + //$NON-NLS-1$
        metadata.getFullName(ids.iterator().next()) + " = ?" + ' ' + Reserved.OPTION + ' ' + Reserved.NOCACHE; //$NON-NLS-1$
      QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(queryString, matViewName.toUpperCase(), context, key.getValue());
      qp.setNonBlocking(true);
      qp.getContext().setDataObjects(null);
      TupleSource ts = new BatchCollector.BatchProducerTupleSource(qp);
      List<?> tuple = ts.nextTuple();
      boolean delete = false;
      if (tuple == null) {
        delete = true;
        tuple = Arrays.asList(key.getValue());
      }
      List<?> result = updateMatViewRow(globalStore, matTableName, tuple, delete);
      if (result != null && eventDistributor != null) {
        this.eventDistributor.updateMatViewRow(context.getVdbName(), context.getVdbVersion(), metadata.getName(metadata.getModelID(groupID)), metadata.getName(groupID), tuple, delete);
      }
View Full Code Here

                                            boolean implicit, FunctionLibrary library) {
        Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName);

        FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName));

        Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) });
        conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName));
        conversion.setFunctionDescriptor(fd);
        if (implicit) {
          conversion.makeImplicit();
        }
View Full Code Here

            }
          } else if (sortKey instanceof ExpressionSymbol) {
            // check for legacy positional
          ExpressionSymbol es = (ExpressionSymbol)sortKey;
            if (es.getExpression() instanceof Constant) {
                Constant c = (Constant)es.getExpression();
                int elementOrder = Integer.valueOf(c.getValue().toString()).intValue();
                // adjust for the 1 based index.
                if (elementOrder > knownElements.size() || elementOrder < 1) {
                    throw new QueryResolverException(QueryPlugin.Util.getString("SQLParser.non_position_constant", c)); //$NON-NLS-1$
                }
                orderBy.setExpressionPosition(i, elementOrder - 1);
View Full Code Here

    private static Constant getProperlyTypedConstant(Object defaultValue,
                                                Class parameterType)
    throws QueryResolverException{
        try {
            Object newValue = DataTypeManager.transformValue(defaultValue, parameterType);
            return new Constant(newValue, parameterType);
        } catch (TransformationException e) {
            throw new QueryResolverException(e, QueryPlugin.Util.getString("ResolverUtil.error_converting_value_type", defaultValue, defaultValue.getClass(), parameterType)); //$NON-NLS-1$
        }
    }
View Full Code Here

    if(symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
        ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
        Expression expr = exprSymbol.getExpression();
        
        if(expr instanceof Constant) {                 
            exprSymbol.setExpression(new Constant(null, replacement));
        } else if (expr instanceof AbstractCaseExpression) {
            ((AbstractCaseExpression)expr).setType(replacement);
        } else if (expr instanceof ScalarSubquery) {
            ((ScalarSubquery)expr).setType(replacement);                                       
        } else {
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.