Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.calcite.rel.logical.LogicalMinus;
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rel.logical.LogicalRepeatUnion;
import org.apache.calcite.rel.logical.LogicalSnapshot;
import org.apache.calcite.rel.logical.LogicalSort;
import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.rel.logical.LogicalUnion;
Expand Down Expand Up @@ -91,6 +92,10 @@ public class RelHomogeneousShuttle extends RelShuttleImpl {
return visit((RelNode) sort);
}

@Override public RelNode visit(LogicalSnapshot snapshot) {
return visit((RelNode) snapshot);
}

@Override public RelNode visit(LogicalExchange exchange) {
return visit((RelNode) exchange);
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/apache/calcite/rel/RelShuttle.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.calcite.rel.logical.LogicalMinus;
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rel.logical.LogicalRepeatUnion;
import org.apache.calcite.rel.logical.LogicalSnapshot;
import org.apache.calcite.rel.logical.LogicalSort;
import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.rel.logical.LogicalUnion;
Expand Down Expand Up @@ -67,6 +68,8 @@ public interface RelShuttle {

RelNode visit(LogicalSort sort);

RelNode visit(LogicalSnapshot snapshot);

RelNode visit(LogicalExchange exchange);

RelNode visit(LogicalTableModify modify);
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/apache/calcite/rel/RelShuttleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.calcite.rel.logical.LogicalMinus;
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rel.logical.LogicalRepeatUnion;
import org.apache.calcite.rel.logical.LogicalSnapshot;
import org.apache.calcite.rel.logical.LogicalSort;
import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.rel.logical.LogicalUnion;
Expand Down Expand Up @@ -131,6 +132,10 @@ protected RelNode visitChildren(RelNode rel) {
return visitChildren(sort);
}

@Override public RelNode visit(LogicalSnapshot snapshot) {
return visitChildren(snapshot);
}

@Override public RelNode visit(LogicalExchange exchange) {
return visitChildren(exchange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.calcite.rel.RelDistributionTraitDef;
import org.apache.calcite.rel.RelInput;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.RelShuttle;
import org.apache.calcite.rel.core.Snapshot;
import org.apache.calcite.rel.hint.RelHint;
import org.apache.calcite.rel.metadata.RelMdCollation;
Expand Down Expand Up @@ -103,4 +104,9 @@ public static LogicalSnapshot create(RelNode input, RexNode period) {
@Override public RelNode withHints(final List<RelHint> hintList) {
return new LogicalSnapshot(getCluster(), traitSet, hintList, input, getPeriod());
}

@Override public RelNode accept(RelShuttle shuttle) {
return shuttle.visit(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.calcite.rel.logical.LogicalJoin;
import org.apache.calcite.rel.logical.LogicalMinus;
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rel.logical.LogicalSnapshot;
import org.apache.calcite.rel.logical.LogicalSort;
import org.apache.calcite.rel.logical.LogicalUnion;
import org.apache.calcite.rel.logical.LogicalValues;
Expand Down Expand Up @@ -919,6 +920,13 @@ private static class HintCollector extends RelShuttleImpl {
return super.visit(sort);
}

@Override public RelNode visit(LogicalSnapshot snapshot) {
if (!snapshot.getHints().isEmpty()) {
this.hintsCollect.add("Snapshot:" + snapshot.getHints());
}
return super.visit(snapshot);
}

@Override public RelNode visit(LogicalValues values) {
if (!values.getHints().isEmpty()) {
this.hintsCollect.add("Values:" + values.getHints());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.calcite.rel.logical.LogicalCalc;
import org.apache.calcite.rel.logical.LogicalFilter;
import org.apache.calcite.rel.logical.LogicalRepeatUnion;
import org.apache.calcite.rel.logical.LogicalSnapshot;
import org.apache.calcite.rel.logical.LogicalSort;
import org.apache.calcite.rel.logical.LogicalTableModify;
import org.apache.calcite.rel.rules.CoreRules;
Expand Down Expand Up @@ -3086,6 +3087,36 @@ void checkCorrelatedMapSubQuery(boolean expand) {
assertThat(rels.get(0), instanceOf(LogicalCalc.class));
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6947">[CALCITE-6947]
* Support LogicalSnapshot in RelShuttle</a>. */
@Test void testRelShuttleForLogicalSnapshot() {
final String sql = "select * from products_temporal "
+ "for system_time as of TIMESTAMP '2011-01-02 00:00:00'";
final RelNode rel = sql(sql).toRel();
final List<RelNode> rels = new ArrayList<>();
final List<RelNode> otherRels = new ArrayList<>();
final RelShuttleImpl visitor = new RelShuttleImpl() {
@Override public RelNode visit(LogicalSnapshot modify) {
RelNode visitedRel = super.visit(modify);
rels.add(visitedRel);
return visitedRel;
}

@Override public RelNode visit(RelNode other) {
if (other instanceof LogicalSnapshot) {
otherRels.add(other);
}
RelNode visitedRel = super.visit(other);
return visitedRel;
}
};
rel.accept(visitor);
assertThat(otherRels, hasSize(0));
assertThat(rels, hasSize(1));
assertThat(rels.get(0), instanceOf(LogicalSnapshot.class));
}

@Test void testRelShuttleForLogicalTableModify() {
final String sql = "insert into emp select * from emp";
final RelNode rel = sql(sql).toRel();
Expand Down
5 changes: 5 additions & 0 deletions site/_docs/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ other software versions as specified in gradle.properties.
#### Breaking Changes
{: #breaking-1-42-0}

* [<a href="https://issues.apache.org/jira/browse/CALCITE-6947">CALCITE-6947</a>]
The feature support LogicalSnapshot in RelShuttle. please note that If there’s a class X that extends LogicalSnapshot
and a class Y extends Snapshot, but not LogicalSnapshot, then X will call RelShuttle.visit(LogicalSnapshot)
and Y will call RelShuttle.visit(RelNode other)

#### New features
{: #new-features-1-42-0}

Expand Down
Loading