public class HiveJoinInsertDeleteIncrementalRewritingRule
extends org.apache.calcite.plan.RelOptRule
This rule will perform a rewriting to prepare the plan for incremental
view maintenance in case there is no aggregation operator but some of the
source tables has delete operations, so we can avoid the INSERT OVERWRITE and use a
MULTI INSERT statement instead: one insert branch for inserted rows
and another for inserting deleted rows to delete delta.
Since CBO plan does not contain the INSERT branches we focus on the SELECT part of the plan in this rule.
See also CalcitePlanner#fixUpASTJoinInsertDeleteIncrementalRebuild(ASTNode)
FROM (select mv.ROW__ID, mv.a, mv.b from mv) mv
RIGHT OUTER JOIN (SELECT _source_.ROW__IS_DELETED,_source_.a, _source_.b FROM _source_) source
ON (mv.a <=> source.a AND mv.b <=> source.b)
INSERT INTO TABLE mv_delete_delta
SELECT mv.ROW__ID
WHERE source.ROW__IS__DELETED
INSERT INTO TABLE mv
SELECT source.a, source.b
WHERE NOT source.ROW__IS__DELETED
SORT BY mv.ROW__ID;