/** Drops the CREATE VIRTUAL PROCEDURE prefix */
  @Override
  @Test
  public void testVirtualProcedure() {
    ElementSymbolImpl x = getFactory().newElementSymbol("x");
    String intType = new String("integer");
    StatementImpl dStmt = getFactory().newDeclareStatement(x, intType);

    GroupSymbolImpl g = getFactory().newGroupSymbol("m.g");
    FromImpl from = getFactory().newFrom();
    from.addGroup(g);

    SelectImpl select = getFactory().newSelect();
    ElementSymbolImpl c1 = getFactory().newElementSymbol("c1");
    select.addSymbol(c1);
    select.addSymbol(getFactory().newElementSymbol("c2"));

    QueryImpl query = getFactory().newQuery(select, from);

    x = getFactory().newElementSymbol("x");
    c1 = getFactory().newElementSymbol("mycursor.c1");
    StatementImpl assignmentStmt = getFactory().newAssignmentStatement(x, c1);
    BlockImpl block = getFactory().newBlock();
    block.addStatement(assignmentStmt);

    BlockImpl ifBlock = getFactory().newBlock();
    StatementImpl continueStmt = getFactory().newBranchingStatement(BranchingMode.CONTINUE);
    ifBlock.addStatement(continueStmt);
    CriteriaImpl crit =
        getFactory().newCompareCriteria(x, Operator.GT, getFactory().newConstant(new Integer(5)));
    IfStatementImpl ifStmt = getFactory().newIfStatement(crit, ifBlock);
    block.addStatement(ifStmt);

    String cursor = "mycursor";
    LoopStatementImpl loopStmt = getFactory().newLoopStatement(block, query, cursor);

    block = getFactory().newBlock();
    block.addStatement(dStmt);
    block.addStatement(loopStmt);
    CommandStatementImpl cmdStmt = getFactory().newCommandStatement(query);
    block.addStatement(cmdStmt);

    CreateProcedureCommandImpl virtualProcedureCommand = getFactory().newCreateProcedureCommand();
    virtualProcedureCommand.setBlock(block);

    helpTest(
        "BEGIN DECLARE integer x; LOOP ON (SELECT c1, c2 FROM m.g) AS mycursor BEGIN x=mycursor.c1; IF(x > 5) BEGIN CONTINUE; END END SELECT c1, c2 FROM m.g; END",
        "BEGIN\nDECLARE integer x;\n"
            + "LOOP ON (SELECT c1, c2 FROM m.g) AS mycursor\nBEGIN\n"
            + "x = mycursor.c1;\nIF(x > 5)\nBEGIN\nCONTINUE;\nEND\nEND\n"
            + "SELECT c1, c2 FROM m.g;\nEND",
        virtualProcedureCommand);
  }
  @Test
  public void testGroupByRollup() {
    GroupSymbolImpl g = getFactory().newGroupSymbol("m.g"); // $NON-NLS-1$
    FromImpl from = getFactory().newFrom();
    from.addGroup(g);

    SelectImpl select = getFactory().newSelect();
    select.addSymbol(getFactory().newElementSymbol("a")); // $NON-NLS-1$

    GroupByImpl groupBy = getFactory().newGroupBy();
    groupBy.setRollup(true);
    groupBy.addSymbol(getFactory().newElementSymbol("b")); // $NON-NLS-1$
    groupBy.addSymbol(getFactory().newElementSymbol("c")); // $NON-NLS-1$

    QueryImpl query = getFactory().newQuery();
    query.setSelect(select);
    query.setFrom(from);
    query.setGroupBy(groupBy);
    helpTest(
        "SELECT a FROM m.g GROUP BY rollup(b, c)", //$NON-NLS-1$
        "SELECT a FROM m.g GROUP BY ROLLUP(b, c)", //$NON-NLS-1$
        query);
  }