Search in sources :

Example 1 with UnionAllOp

use of herddb.model.planner.UnionAllOp 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)

Example 2 with UnionAllOp

use of herddb.model.planner.UnionAllOp in project herddb by diennea.

the class CalcitePlanner method planEnumerableUnion.

private PlannerOp planEnumerableUnion(EnumerableUnion op, RelDataType rowType, boolean returnValues) {
    if (!op.all) {
        throw new StatementExecutionException("not suppoer UNION, all=false");
    }
    List<PlannerOp> inputs = new ArrayList<>(op.getInputs().size());
    for (RelNode input : op.getInputs()) {
        PlannerOp inputOp = convertRelNode(input, rowType, false, false).optimize();
        inputs.add(inputOp);
    }
    return new UnionAllOp(inputs);
}
Also used : PlannerOp(herddb.model.planner.PlannerOp) RelNode(org.apache.calcite.rel.RelNode) UnionAllOp(herddb.model.planner.UnionAllOp) ArrayList(java.util.ArrayList) StatementExecutionException(herddb.model.StatementExecutionException)

Aggregations

PlannerOp (herddb.model.planner.PlannerOp)2 UnionAllOp (herddb.model.planner.UnionAllOp)2 ArrayList (java.util.ArrayList)2 StatementExecutionException (herddb.model.StatementExecutionException)1 LimitOp (herddb.model.planner.LimitOp)1 ConstantExpression (herddb.sql.expressions.ConstantExpression)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 RelNode (org.apache.calcite.rel.RelNode)1