Package org.teiid.query.sql.lang

Examples of org.teiid.query.sql.lang.SetQuery


                 "SELECT a FROM g EXCEPT SELECT b FROM h"//$NON-NLS-1$
                 setQuery);
    }

    public void testIntersect(){
        SetQuery setQuery = exampleSetQuery(Operation.INTERSECT);

        TestParser.helpTest("SELECT a FROM g intersect select b from h"//$NON-NLS-1$
                 "SELECT a FROM g INTERSECT SELECT b FROM h"//$NON-NLS-1$
                 setQuery);
    }
View Full Code Here


                 setQuery);
    }

    public void testIntersectPresedence(){
       
        SetQuery setQuery = new SetQuery(Operation.INTERSECT, false, createTestQuery("t2"), createTestQuery("t3")); //$NON-NLS-1$  //$NON-NLS-2$
       
        setQuery = new SetQuery(Operation.EXCEPT, false, createTestQuery("t1"), setQuery); //$NON-NLS-1$
       
        TestParser.helpTest("select * from t1 EXCEPT select * from t2 INTERSECT select * from t3"//$NON-NLS-1$
                 "SELECT * FROM t1 EXCEPT (SELECT * FROM t2 INTERSECT SELECT * FROM t3)"//$NON-NLS-1$
                 setQuery);
    }
View Full Code Here

       
        Query query2 = new Query();
        query2.setSelect(select);
        query2.setFrom(from);
       
        SetQuery setQuery = new SetQuery(op);
        setQuery.setAll(false);
        setQuery.setLeftQuery(query1);
        setQuery.setRightQuery(query2);
        return setQuery;
    }
View Full Code Here

       
        Query query2 = new Query();
        query2.setSelect(select);
        query2.setFrom(from);
       
        SetQuery setQuery = new SetQuery(Operation.UNION);
        setQuery.setAll(true);
        setQuery.setLeftQuery(query1);
        setQuery.setRightQuery(query2);

        TestParser.helpTest("SELECT a FROM g UNION ALL select b from h"//$NON-NLS-1$
                 "SELECT a FROM g UNION ALL SELECT b FROM h"//$NON-NLS-1$
                 setQuery);
    }
View Full Code Here

                 setQuery);
    }
   
    /** select c1 from g1 union select c2 from g2 union select c3 from g3*/
    public void testTwoUnions(){
        SetQuery setQuery = new SetQuery(Operation.UNION);
        setQuery.setAll(false);
        GroupSymbol g = new GroupSymbol("g1"); //$NON-NLS-1$
        From from = new From();
        from.addGroup(g);

        Select select = new Select();
        select.addSymbol(new ElementSymbol("c1")); //$NON-NLS-1$
       
        Query query = new Query();
        query.setSelect(select);
        query.setFrom(from);

        setQuery.setLeftQuery(query);
       
        g = new GroupSymbol("g2"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c2")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery.setRightQuery(query);

        g = new GroupSymbol("g3"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c3")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery = new SetQuery(Operation.UNION, false, setQuery, query);

        TestParser.helpTest("select c1 from g1 union select c2 from g2 union select c3 from g3"//$NON-NLS-1$
                 "SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION SELECT c3 FROM g3"//$NON-NLS-1$
                 setQuery);
    }
View Full Code Here

                 setQuery);
    }
   
    /** select c1 from g1 union select c2 from g2 union all select c3 from g3 union select c4 from g4 */
    public void testThreeUnions(){
        SetQuery setQuery = new SetQuery(Operation.UNION);
        setQuery.setAll(false);
        GroupSymbol g = new GroupSymbol("g1"); //$NON-NLS-1$
        From from = new From();
        from.addGroup(g);

        Select select = new Select();
        select.addSymbol(new ElementSymbol("c1")); //$NON-NLS-1$
       
        Query query = new Query();
        query.setSelect(select);
        query.setFrom(from);

        setQuery.setLeftQuery(query);
       
        g = new GroupSymbol("g2"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c2")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery.setRightQuery(query);

        g = new GroupSymbol("g3"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c3")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery = new SetQuery(SetQuery.Operation.UNION, true, setQuery, query);

        g = new GroupSymbol("g4"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c4")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery = new SetQuery(SetQuery.Operation.UNION, false, setQuery, query);

        TestParser.helpTest("select c1 from g1 union select c2 from g2 union all select c3 from g3 union select c4 from g4"//$NON-NLS-1$
                 "SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION ALL SELECT c3 FROM g3 UNION SELECT c4 FROM g4"//$NON-NLS-1$
                 setQuery);
    }  
View Full Code Here

                 "SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION ALL SELECT c3 FROM g3 UNION SELECT c4 FROM g4"//$NON-NLS-1$
                 setQuery);
    }  
   
    public void testUnionWithLimit(){
        SetQuery setQuery = exampleSetQuery(Operation.UNION);
        setQuery.setLimit(new Limit(null, new Constant(1)));

        TestParser.helpTest("SELECT a FROM g UNION select b from h LIMIT 1"//$NON-NLS-1$
                 "SELECT a FROM g UNION SELECT b FROM h LIMIT 1"//$NON-NLS-1$
                 setQuery);
    }
View Full Code Here

                                   List<Class<?>> firstProjectTypes, QueryMetadataInterface metadata) throws QueryResolverException {
        for (QueryCommand subCommand : setQuery.getQueryCommands()) {
            if (!(subCommand instanceof SetQuery)) {
                continue;
            }
            SetQuery child = (SetQuery)subCommand;
            List projectedSymbols = child.getProjectedSymbols();
            if (child.getOrderBy() != null) {
                for (int j = 0; j < projectedSymbols.size(); j++) {
                    SingleElementSymbol ses = (SingleElementSymbol)projectedSymbols.get(j);
                    Class<?> targetType = firstProjectTypes.get(j);
                    if (ses.getType() != targetType && orderByContainsVariable(child.getOrderBy(), ses, j)) {
                        String sourceTypeName = DataTypeManager.getDataTypeName(ses.getType());
                        String targetTypeName = DataTypeManager.getDataTypeName(targetType);
                        throw new QueryResolverException(QueryPlugin.Util.getString("UnionQueryResolver.type_conversion", //$NON-NLS-1$
                                                                                    new Object[] {ses, sourceTypeName, targetTypeName}));
                    }
                }
            }
            child.setProjectedTypes(firstProjectTypes, metadata);
            setProjectedTypes(child, firstProjectTypes, metadata);
        }
    }
View Full Code Here

        Assertion.failed("unknown operator"); //$NON-NLS-1$
        return 0;
    }
   
    SetQuery addQueryToSetOperation(QueryCommand query, QueryCommand rightQuery, SetQuery.Operation type, boolean all) {
        SetQuery setQuery = new SetQuery(type, all, query, rightQuery);
        return setQuery;
    }
View Full Code Here

      PlanNode node = null;
        if(command instanceof Query) {
            node = createQueryPlan((Query) command);
        } else {
            hints.hasSetQuery = true;
            SetQuery query = (SetQuery)command;
            PlanNode leftPlan = createQueryPlan( query.getLeftQuery());
            PlanNode rightPlan = createQueryPlan( query.getRightQuery());

            node = NodeFactory.getNewNode(NodeConstants.Types.SET_OP);
            node.setProperty(NodeConstants.Info.SET_OPERATION, query.getOperation());
            node.setProperty(NodeConstants.Info.USE_ALL, query.isAll());
           
            attachLast(node, leftPlan);
            attachLast(node, rightPlan);
        }
       
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.lang.SetQuery

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.