Search in sources :

Example 1 with SimpleDeleteOp

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

the class CalcitePlanner method planDelete.

private PlannerOp planDelete(EnumerableTableModify dml) {
    PlannerOp input = convertRelNode(dml.getInput(), null, false);
    final String tableSpace = dml.getTable().getQualifiedName().get(0);
    final String tableName = dml.getTable().getQualifiedName().get(1);
    final TableImpl tableImpl = (TableImpl) dml.getTable().unwrap(org.apache.calcite.schema.Table.class);
    Table table = tableImpl.tableManager.getTable();
    DeleteStatement delete = null;
    if (input instanceof TableScanOp) {
        delete = new DeleteStatement(tableSpace, tableName, null, null);
    } else if (input instanceof FilterOp) {
        FilterOp filter = (FilterOp) input;
        if (filter.getInput() instanceof TableScanOp) {
            SQLRecordPredicate pred = new SQLRecordPredicate(table, null, filter.getCondition());
            delete = new DeleteStatement(tableSpace, tableName, null, pred);
        }
    } else if (input instanceof BindableTableScanOp) {
        BindableTableScanOp filter = (BindableTableScanOp) input;
        Predicate pred = filter.getStatement().getPredicate();
        delete = new DeleteStatement(tableSpace, tableName, null, pred);
    }
    if (delete != null) {
        return new SimpleDeleteOp(delete);
    } else {
        return new DeleteOp(tableSpace, tableName, input);
    }
}
Also used : PlannerOp(herddb.model.planner.PlannerOp) Table(herddb.model.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) ScannableTable(org.apache.calcite.schema.ScannableTable) AbstractTable(org.apache.calcite.schema.impl.AbstractTable) ModifiableTable(org.apache.calcite.schema.ModifiableTable) FilteredTableScanOp(herddb.model.planner.FilteredTableScanOp) BindableTableScanOp(herddb.model.planner.BindableTableScanOp) TableScanOp(herddb.model.planner.TableScanOp) FilterOp(herddb.model.planner.FilterOp) DeleteStatement(herddb.model.commands.DeleteStatement) Predicate(herddb.model.Predicate) SimpleDeleteOp(herddb.model.planner.SimpleDeleteOp) DeleteOp(herddb.model.planner.DeleteOp) SimpleDeleteOp(herddb.model.planner.SimpleDeleteOp) BindableTableScanOp(herddb.model.planner.BindableTableScanOp)

Aggregations

Predicate (herddb.model.Predicate)1 Table (herddb.model.Table)1 DeleteStatement (herddb.model.commands.DeleteStatement)1 BindableTableScanOp (herddb.model.planner.BindableTableScanOp)1 DeleteOp (herddb.model.planner.DeleteOp)1 FilterOp (herddb.model.planner.FilterOp)1 FilteredTableScanOp (herddb.model.planner.FilteredTableScanOp)1 PlannerOp (herddb.model.planner.PlannerOp)1 SimpleDeleteOp (herddb.model.planner.SimpleDeleteOp)1 TableScanOp (herddb.model.planner.TableScanOp)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 ModifiableTable (org.apache.calcite.schema.ModifiableTable)1 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)1 ScannableTable (org.apache.calcite.schema.ScannableTable)1 AbstractTable (org.apache.calcite.schema.impl.AbstractTable)1