Skip to content

Commit e297a55

Browse files
committed
fix(EXPB-7545): CALCULATIONVIEW hint is not considered in Views
1 parent d51caac commit e297a55

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

core/src/main/java/org/apache/calcite/plan/Hints.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ private Hints() {
2222

2323
}
2424
public static final String CALCULATION_VIEW = "CALCULATIONVIEW";
25+
public static final String PROPAGATE_HINTS = "PROPAGATE_HINTS";
2526
}

core/src/main/java/org/apache/calcite/schema/impl/ViewTable.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.apache.calcite.schema.impl;
1818

19-
import java.util.Optional;
19+
import java.util.HashSet;
2020

2121
import org.apache.calcite.adapter.java.AbstractQueryableTable;
2222
import org.apache.calcite.jdbc.CalciteSchema;
@@ -43,6 +43,10 @@
4343

4444
import java.lang.reflect.Type;
4545
import java.util.List;
46+
import java.util.function.Predicate;
47+
import java.util.stream.Collectors;
48+
49+
import static org.apache.calcite.plan.Hints.PROPAGATE_HINTS;
4650

4751
/**
4852
* Table whose contents are defined using an SQL statement.
@@ -133,6 +137,24 @@ private RelRoot expandView(RelOptTable.ToRelContext context,
133137
final RelRoot root =
134138
context.expandView(rowType, queryString, schemaPath, viewPath);
135139
final RelNode rel = RelOptUtil.createCastRel(root.rel, rowType, true);
140+
Predicate<RelHint> hintFilter = rel instanceof Hintable
141+
? ((Hintable)rel).getHints().stream()
142+
.filter(hint -> hint.hintName.equals(PROPAGATE_HINTS))
143+
.findAny()
144+
.map(it -> new HashSet<>(it.listOptions))
145+
.map(it -> (Predicate<RelHint>) hint -> {
146+
switch(hint.hintName) {
147+
case "PARAMETERS":
148+
return true;
149+
case "ANONYMIZE":
150+
return true;
151+
default:
152+
return it.contains(hint.hintName);
153+
}
154+
})
155+
.orElse(hint -> true)
156+
: hint -> true;
157+
136158
// Expand any views
137159
final RelNode rel2 =
138160
rel.accept(new RelShuttleImpl() {
@@ -143,12 +165,9 @@ private RelRoot expandView(RelOptTable.ToRelContext context,
143165
if (translatableTable != null) {
144166
RelNode result = translatableTable.toRel(context, table);
145167
if ( result instanceof Hintable) {
146-
Optional<RelHint> parameter = scan.getHints().stream()
147-
.filter(hint -> hint.hintName.equals("PARAMETERS") || hint.hintName.equals("ANONYMIZE"))
148-
.findAny();
149-
if ( parameter.isPresent()) {
150-
result = ((Hintable)result).attachHints(ImmutableList.of(parameter.get()));
151-
}
168+
result = ((Hintable)result).attachHints(scan.getHints().stream()
169+
.filter(hintFilter)
170+
.collect(Collectors.toList()));
152171
}
153172
return result;
154173
}

0 commit comments

Comments
 (0)