Package org.teiid.language

Examples of org.teiid.language.Literal


        if (limit == null) {
            return null;
        }
        int rowOffset = 0;
        if (limit.getOffset() != null) {
            Literal c1 = (Literal)translate(limit.getOffset());
            rowOffset = ((Integer)c1.getValue()).intValue();
        }
        Literal c2 = (Literal)translate(limit.getRowLimit());
        int rowLimit = ((Integer)c2.getValue()).intValue();
        return new org.teiid.language.Limit(rowOffset, rowLimit);
    }
View Full Code Here


    convertCrossJoinToInner(obj, getLanguageFactory());
    //DB2 needs projected nulls wrapped in casts
    if (obj instanceof DerivedColumn) {
      DerivedColumn selectSymbol = (DerivedColumn)obj;
      if (selectSymbol.getExpression() instanceof Literal) {
        Literal literal = (Literal)selectSymbol.getExpression();
        if (literal.getValue() == null) {
          String type = TypeFacility.RUNTIME_NAMES.INTEGER;
          if (literal.getType() != TypeFacility.RUNTIME_TYPES.NULL) {
            type = TypeFacility.getDataTypeName(literal.getType());
          }
          selectSymbol.setExpression(ConvertModifier.createConvertFunction(getLanguageFactory(), literal, type));
        }
      }
    }
View Full Code Here

  public static void convertCrossJoinToInner(LanguageObject obj, LanguageFactory lf) {
    if (obj instanceof Join) {
      Join join = (Join)obj;
      if (join.getJoinType() == JoinType.CROSS_JOIN) {
        Literal one = lf.createLiteral(1, TypeFacility.RUNTIME_TYPES.INTEGER);
        join.setCondition(lf.createCompareCriteria(Operator.EQ, one, one));
        join.setJoinType(JoinType.INNER_JOIN);
      }
    }
  }
View Full Code Here

        registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()));
        registerFunctionModifier(SourceSystemFunctions.COT, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        function.setName(SourceSystemFunctions.TAN);
        return Arrays.asList(getLanguageFactory().createFunction(SourceSystemFunctions.DIVIDE_OP, new Expression[] {new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER), function}, TypeFacility.RUNTIME_TYPES.DOUBLE));
      }
    });
       
        //spatial functions
        registerFunctionModifier(OracleSpatialFunctions.RELATE, new OracleSpatialFunctionModifier());
View Full Code Here

    //case when length > LENGTH(string) - start + 1 then LENGTH(string) - start + 1 case when length > 0 then length end
    Expression length = function.getParameters().get(2);
    List<SearchedWhenClause> clauses = new ArrayList<SearchedWhenClause>(2);
    Boolean isNegative = null;
    if (length instanceof Literal) {
      Literal l = (Literal)length;
      if (!l.isMultiValued()) {
        int value = (Integer)l.getValue();
        isNegative = value < 0;
      }
    }
    Expression maxLength = new Function(
        SourceSystemFunctions.SUBTRACT_OP,
        Arrays.asList(new Function(
                SourceSystemFunctions.LENGTH,
                Arrays.asList(function.getParameters().get(0)),
                TypeFacility.RUNTIME_TYPES.INTEGER),
              new Function(
                SourceSystemFunctions.SUBTRACT_OP,
                Arrays.asList(
                    function.getParameters().get(1),
                    new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)),
                  TypeFacility.RUNTIME_TYPES.INTEGER)),
        TypeFacility.RUNTIME_TYPES.INTEGER);
    clauses.add(new SearchedWhenClause(new Comparison(length, maxLength, Operator.GT), maxLength));
    Expression defaultExpr = null;
    if (isNegative == null) {
      clauses.add(new SearchedWhenClause(new Comparison(length, new Literal(0, TypeFacility.RUNTIME_TYPES.INTEGER), Operator.GT), length));
    } else if (isNegative) {
      //TODO: could be done in the rewriter
      function.getParameters().set(2, null);
      return null;
    } else {
View Full Code Here

    if (add) {
      function.setName("dateadd"); //$NON-NLS-1$
    } else {
      function.setName("datediff"); //$NON-NLS-1$
    }
    Literal intervalType = (Literal)function.getParameters().get(0);
    String interval = ((String)intervalType.getValue()).toUpperCase();
    String newInterval = INTERVAL_MAP.get(interval);
    if (newInterval != null) {
      intervalType.setValue(newInterval);
      return null;
    }
    if (add) {
      if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
        intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
        Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(1000000, TypeFacility.RUNTIME_TYPES.INTEGER)};
        function.getParameters().set(1, factory.createFunction("/", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
      } else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
        intervalType.setValue(ExtractFunctionModifier.DAY);
        Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(91, TypeFacility.RUNTIME_TYPES.INTEGER)};
        function.getParameters().set(1, factory.createFunction("*", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
      } else {
        intervalType.setValue(ExtractFunctionModifier.DAY);
        Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(7, TypeFacility.RUNTIME_TYPES.INTEGER)};
        function.getParameters().set(1, factory.createFunction("*", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
      }
      return null;
    }
    if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
      intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
      return Arrays.asList(function, " * 1000000"); //$NON-NLS-1$
    } else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
      intervalType.setValue(ExtractFunctionModifier.DAY);
      return Arrays.asList(function, " / 91"); //$NON-NLS-1$ 
    }
    intervalType.setValue(ExtractFunctionModifier.DAY);
    return Arrays.asList(function, " / 7"); //$NON-NLS-1$ 
  }
View Full Code Here

  @Test public void testGetTextFiles() throws Exception {
    FileExecutionFactory fef = new FileExecutionFactory();
    FileConnection fc = Mockito.mock(FileConnection.class);
    Mockito.stub(fc.getFile("*.txt")).toReturn(new File(UnitTestUtil.getTestDataPath(), "*.txt"));
    Call call = fef.getLanguageFactory().createCall("getTextFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*.txt", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), null);
    ProcedureExecution pe = fef.createProcedureExecution(call, null, null, fc);
    pe.execute();
    int count = 0;
    while (true) {
      if (pe.next() == null) {
View Full Code Here

TOP

Related Classes of org.teiid.language.Literal

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.