wuchong commented on a change in pull request #10989:
[FLINK-15840][table-planner-blink] ClassCastException is thrown when use
tEnv.from for temp/catalog table
URL: https://github.com/apache/flink/pull/10989#discussion_r373848300
##########
File path:
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/delegation/PlannerContext.java
##########
@@ -109,6 +109,9 @@ public PlannerContext(
planner.addRelTraitDef(traitDef);
}
this.cluster = FlinkRelOptClusterFactory.create(planner, new
RexBuilder(typeFactory));
+
+ this.context.toRexConverterFactory_$eq(t -> new
SqlExprToRexConverterImpl(
Review comment:
Mutable member field and lazy assignement is not a good practice. I would
suggest to make `FlinkContextImpl` constructor accepts a supplier function to
create the SqlExprToRexConverterFactory.
```scala
class FlinkContextImpl(
tableConfig: TableConfig,
functionCatalog: FunctionCatalog,
catalogManager: CatalogManager,
factorySupplier: Supplier[ToRexConverterFactory])
extends FlinkContext {
...
override def getToRexConverterFactory: ToRexConverterFactory =
factorySupplier.get()
}
```
Then in the `PlannerContext`, we can instantiate the context early.
```java
public PlannerContext(...) {
...
this.context = new FlinkContextImpl(
tableConfig,
functionCatalog,
catalogManager,
this::createToRexConverterFactory);
...
}
private ToRexConverterFactory createToRexConverterFactory() {
return t -> new
SqlExprToRexConverterImpl(createFrameworkConfig(), typeFactory, cluster, t);
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services