Package org.teiid.query.sql.symbol

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


        func.setArgs(new Expression[] {new Constant("http_port")}); //$NON-NLS-1$
        assertEquals("8000", new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(func, Collections.emptyList())); //$NON-NLS-1$
    }
   
    public void helpTestCommandPayload(Serializable payload, String property, String expectedValue) throws Exception {
        Function func = new Function("commandpayload", new Expression[] {}); //$NON-NLS-1$
       
        Class[] parameterSignature = null;
        if(property == null) {
            parameterSignature = new Class[] {};
        } else {
            parameterSignature = new Class[] { String.class };
        }       
        FunctionDescriptor desc = FakeMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("commandpayload", parameterSignature );         //$NON-NLS-1$
        func.setFunctionDescriptor(desc);
       
        FakeDataManager dataMgr = new FakeDataManager();      
        CommandContext context = new CommandContext(new Long(-1), null, "user", payload, "vdb", 1, null, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

        if(property != null) {
            func.setArgs(new Expression[] {new Constant(property)});
        }
        String actual = (String) new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(func, Collections.emptyList());
        assertEquals(expectedValue, actual);
    }
View Full Code Here


           
            Collection contextFunctions = ContextReplacerVisitor.replaceContextFunctions(conjunct);
            if (!contextFunctions.isEmpty()) {
                //ensure that every part of the conjunct is to the same context
                for (Iterator i = contextFunctions.iterator(); i.hasNext();) {
                    Function contextFunction = (Function)i.next();
                    MappingNode otherContext = getContext(planEnv, contextFunction);
                    if (context == null) {
                        context = otherContext;
                    } else if (context != otherContext){
                        throw new QueryPlannerException("ERR.015.004.0068", QueryPlugin.Util.getString("ERR.015.004.0068", criteria)); //$NON-NLS-1$ //$NON-NLS-2$
View Full Code Here

        // Restrictions
        //  -Single arg must be any xml doc node that is within the scope of a mapping class
        //  -Can't have conflicting row limits on the same mapping class
        // (Query Validator enforces additional restrictions.)

        Function rowLimitFunction = null;
        Constant rowLimitConstant = null;
        boolean exceptionOnRowLimit = false;
       
        if (conjunct instanceof CompareCriteria) {
            CompareCriteria crit = (CompareCriteria)conjunct;
            if (crit.getLeftExpression() instanceof Function) {
                Function function = (Function)crit.getLeftExpression();
                if (function.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT)) {
                    rowLimitFunction = function;
                    rowLimitConstant = (Constant)crit.getRightExpression();
                } else if (function.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
                    rowLimitFunction = function;
                    rowLimitConstant = (Constant)crit.getRightExpression();
                    exceptionOnRowLimit = true;
                }
            }
            if (rowLimitFunction == null && crit.getRightExpression() instanceof Function) {
                Function function = (Function)crit.getRightExpression();
                if (function.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT)) {
                    rowLimitFunction = function;
                    rowLimitConstant = (Constant)crit.getLeftExpression();
                } else if (function.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
                    rowLimitFunction = function;
                    rowLimitConstant = (Constant)crit.getLeftExpression();
                    exceptionOnRowLimit = true;
                }
            }
View Full Code Here

    /**
     * @see org.teiid.query.sql.visitor.ExpressionMappingVisitor#replaceExpression(org.teiid.query.sql.symbol.Expression)
     */
    public Expression replaceExpression(Expression exp) {
        if (exp instanceof Function){
            Function function = (Function)exp;
            if (function.getName().equalsIgnoreCase(FunctionLibrary.CONTEXT)){
                this.contextFunctions.add(function);
                //return 2nd argument to 'context'
                return function.getArg(1);
            }
        }
        return exp;
    }
View Full Code Here

        GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
        ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null, gs1); //$NON-NLS-1$
        ElementSymbol es2 = new ElementSymbol("root.node1", null, gs1); //$NON-NLS-1$
        Expression[] exprs = new Expression[]{es1, es2};
       
        Function context = new Function("context", exprs); //$NON-NLS-1$
       
        CompareCriteria expected = new CompareCriteria();
        expected.setLeftExpression(context);
        expected.setOperator(CompareCriteria.EQ);
        expected.setRightExpression(new Constant("yyz")); //$NON-NLS-1$
View Full Code Here

      GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
        ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null, gs1); //$NON-NLS-1$
        es1.setGroupSymbol(gs1);
        Expression[] exprs = new Expression[]{es1};
       
        Function context = new Function("rowlimit", exprs); //$NON-NLS-1$
       
        CompareCriteria expected = new CompareCriteria();
        expected.setLeftExpression(context);
        expected.setOperator(CompareCriteria.EQ);
        expected.setRightExpression(new Constant(new Integer(2)));
View Full Code Here

    public void testRowLimitException() {                 
      GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
        ElementSymbol es1 = new ElementSymbol("root.node1.node2.node3", null, gs1); //$NON-NLS-1$
        Expression[] exprs = new Expression[]{es1};
       
        Function context = new Function("rowlimitexception", exprs); //$NON-NLS-1$
       
        CompareCriteria expected = new CompareCriteria();
        expected.setLeftExpression(context);
        expected.setOperator(CompareCriteria.EQ);
        expected.setRightExpression(new Constant(new Integer(2)));
View Full Code Here

        // Expected left expression
      GroupSymbol gs1 = new GroupSymbol("xmltest.doc1"); //$NON-NLS-1$
        ElementSymbol es1 = new ElementSymbol("root.node1", null, gs1); //$NON-NLS-1$

        // Expected right expression
        Function convert = new Function("convert", new Expression[] { new Constant(new Integer(5)), new Constant("string") }); //$NON-NLS-1$ //$NON-NLS-2$

        // Expected criteria
        CompareCriteria expected = new CompareCriteria();
        expected.setLeftExpression(es1);
        expected.setOperator(CompareCriteria.EQ);
        expected.setRightExpression(convert);

        // Resolve the query and check against expected objects
        Query query = (Query) helpResolve("select * from xmltest.doc1 where node1 = convert(5, string)"); //$NON-NLS-1$
        Criteria actual = query.getCriteria();
        assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$
        Function actualRightExpr = (Function) ((CompareCriteria)actual).getRightExpression();
        assertNotNull("Failed to resolve function", actualRightExpr.getFunctionDescriptor()); //$NON-NLS-1$
    }
View Full Code Here

       
        Expression leftExpr = criteria.getLeftExpression();
        Expression rightExpr = criteria.getRightExpression();
       
        // Allow for concat and string literal to be on either side
        Function tsCreateFunction = null;
        Constant timestampConstant = null;       
        if(leftExpr instanceof Function && rightExpr instanceof Constant) {
            tsCreateFunction = (Function) leftExpr;
            timestampConstant = (Constant) rightExpr;           
        } else {
            return criteria;
        }

        // Verify data type of constant and that constant has a value
        if(! timestampConstant.getType().equals(DataTypeManager.DefaultDataClasses.TIMESTAMP)) {
            return criteria;       
        }
       
        // Verify function is timestampCreate function
        if(! (tsCreateFunction.getName().equalsIgnoreCase("timestampCreate"))) { //$NON-NLS-1$
            return criteria;
        }
       
        // Get timestamp literal and break into pieces
        Timestamp ts = (Timestamp) timestampConstant.getValue();
        String tsStr = ts.toString();
        Date date = Date.valueOf(tsStr.substring(0, 10));
        Time time = Time.valueOf(tsStr.substring(11, 19));
       
        // Get timestampCreate args
        Expression[] args = tsCreateFunction.getArgs();
       
        // Rebuild the function
        CompareCriteria dateCrit = new CompareCriteria(args[0], CompareCriteria.EQ, new Constant(date, DataTypeManager.DefaultDataClasses.DATE));
        CompareCriteria timeCrit = new CompareCriteria(args[1], CompareCriteria.EQ, new Constant(time, DataTypeManager.DefaultDataClasses.TIME));       
        CompoundCriteria compCrit = new CompoundCriteria(CompoundCriteria.AND, dateCrit, timeCrit);
View Full Code Here

      
       Expression leftExpr = criteria.getLeftExpression();
       Expression rightExpr = criteria.getRightExpression();
      
       // Allow for concat and string literal to be on either side
       Function concatFunction = null;
       Constant timestampConstant = null;       
       if(leftExpr instanceof Function && rightExpr instanceof Constant) {
           concatFunction = (Function) leftExpr;
           timestampConstant = (Constant) rightExpr;           
       } else {
           return criteria;
       }

       // Verify data type of string constant and that constant has a value
       if(! timestampConstant.getType().equals(DataTypeManager.DefaultDataClasses.STRING)) {
           return criteria;       
       }
      
       // Verify function is concat function
       if(! (concatFunction.getName().equalsIgnoreCase("concat") || concatFunction.getName().equals("||"))) { //$NON-NLS-1$ //$NON-NLS-2$
           return criteria;
       }
      
       // Verify concat has formatdate and formattime functions
       Expression[] args = concatFunction.getArgs();
       if(! (args[0] instanceof Function && args[1] instanceof Function)) {
           return criteria;
       }
       Function formatDateFunction = (Function) args[0];
       Function formatTimeFunction = (Function) args[1];
       if(! (formatDateFunction.getName().equalsIgnoreCase("formatdate") && formatTimeFunction.getName().equalsIgnoreCase("formattime"))) { //$NON-NLS-1$ //$NON-NLS-2$
           return criteria;
       }
      
       // Verify format functions have constants
       if(! (formatDateFunction.getArgs()[1] instanceof Constant && formatTimeFunction.getArgs()[1] instanceof Constant)) {
           return criteria;
       }
      
       // Verify length of combined date/time constants == timestamp constant
       String dateFormat = (String) ((Constant)formatDateFunction.getArgs()[1]).getValue();       
       String timeFormat = (String) ((Constant)formatTimeFunction.getArgs()[1]).getValue();       
       String timestampValue = (String) timestampConstant.getValue();
      
       // Passed all the checks, so build the optimized version
       try {
         Timestamp ts = FunctionMethods.parseTimestamp(timestampValue, dateFormat + timeFormat);
           Constant dateConstant = new Constant(TimestampWithTimezone.createDate(ts));
           CompareCriteria dateCompare = new CompareCriteria(formatDateFunction.getArgs()[0], CompareCriteria.EQ, dateConstant);

           Constant timeConstant = new Constant(TimestampWithTimezone.createTime(ts));
           CompareCriteria timeCompare = new CompareCriteria(formatTimeFunction.getArgs()[0], CompareCriteria.EQ, timeConstant);
          
           CompoundCriteria compCrit = new CompoundCriteria(CompoundCriteria.AND, dateCompare, timeCompare);
           return compCrit;
          
       } catch(FunctionExecutionException e) {
View Full Code Here

TOP

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

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.