1616 */
1717package org .apache .calcite .schema .impl ;
1818
19- import java .util .Optional ;
19+ import java .util .HashSet ;
2020
2121import org .apache .calcite .adapter .java .AbstractQueryableTable ;
2222import org .apache .calcite .jdbc .CalciteSchema ;
4343
4444import java .lang .reflect .Type ;
4545import 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