Search in sources :

Example 1 with SetOperation

use of net.sf.jsqlparser.statement.select.SetOperation in project herddb by diennea.

the class JSQLParserPlanner method buildSetOperationList.

private PlannerOp buildSetOperationList(String defaultTableSpace, int maxRows, SetOperationList list, boolean forceScan) {
    checkSupported(list.getFetch() == null);
    checkSupported(list.getLimit() == null);
    checkSupported(list.getOffset() == null);
    checkSupported(list.getOrderByElements() == null);
    checkSupported(list.getOperations().size() == 1);
    checkSupported(list.getSelects().size() == 2);
    final SetOperation operation = list.getOperations().get(0);
    checkSupported(operation instanceof UnionOp);
    UnionOp unionOp = (UnionOp) operation;
    // only "UNION ALL"
    checkSupported(unionOp.isAll());
    checkSupported(!unionOp.isDistinct());
    List<PlannerOp> inputs = new ArrayList<>();
    for (SelectBody body : list.getSelects()) {
        inputs.add(buildSelectBody(defaultTableSpace, -1, body, forceScan));
    }
    PlannerOp op = new UnionAllOp(inputs);
    if (maxRows > 0) {
        op = new LimitOp(op, new ConstantExpression(maxRows, ColumnTypes.NOTNULL_LONG), null);
    }
    return op;
}
Also used : SetOperation(net.sf.jsqlparser.statement.select.SetOperation) UnionOp(net.sf.jsqlparser.statement.select.UnionOp) PlannerOp(herddb.model.planner.PlannerOp) UnionAllOp(herddb.model.planner.UnionAllOp) ConstantExpression(herddb.sql.expressions.ConstantExpression) ArrayList(java.util.ArrayList) SelectBody(net.sf.jsqlparser.statement.select.SelectBody) LimitOp(herddb.model.planner.LimitOp)

Aggregations

LimitOp (herddb.model.planner.LimitOp)1 PlannerOp (herddb.model.planner.PlannerOp)1 UnionAllOp (herddb.model.planner.UnionAllOp)1 ConstantExpression (herddb.sql.expressions.ConstantExpression)1 ArrayList (java.util.ArrayList)1 SelectBody (net.sf.jsqlparser.statement.select.SelectBody)1 SetOperation (net.sf.jsqlparser.statement.select.SetOperation)1 UnionOp (net.sf.jsqlparser.statement.select.UnionOp)1