You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "luoyuxia (via GitHub)" <gi...@apache.org> on 2023/03/20 09:20:06 UTC

[GitHub] [flink] luoyuxia commented on a diff in pull request #22166: [FLINK-31409][hive] Hive dialect should use public interfaces

luoyuxia commented on code in PR #22166:
URL: https://github.com/apache/flink/pull/22166#discussion_r1141824286


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/delegation/PlannerBase.scala:
##########
@@ -169,17 +171,46 @@ abstract class PlannerBase(
   override def getParser: Parser = {
     if (parser == null || getTableConfig.getSqlDialect != currentDialect) {
       dialectFactory = getDialectFactory
-      parser =
-        dialectFactory.create(new DefaultParserContext(catalogManager, plannerContext, executor))
+      parser = dialectFactory.create(
+        new DefaultCalciteContext(catalogManager, getOperationTreeBuilder, plannerContext))
     }
     parser
   }
 
+  def getOperationTreeBuilder: OperationTreeBuilder = {
+    OperationTreeBuilderImpl.create(
+      tableConfig,
+      classLoader,
+      functionCatalog.asLookup(f => getParser.parseIdentifier(f)),
+      catalogManager.getDataTypeFactory,
+      (path: String) => getTableReferenceExpression(path),
+      (s: String, inputRowType: RowType, outputType) =>
+        getParser.parseSqlExpression(s, inputRowType, outputType),
+      isStreamingMode
+    )
+  }
+
+  def getTableReferenceExpression(path: String): Optional[TableReferenceExpression] = {
+    try {
+      val unresolvedIdentifier = getParser.parseIdentifier(path)
+      val tableIdentifier = catalogManager.qualifyIdentifier(unresolvedIdentifier)
+      val optionalTable = catalogManager.getTable(tableIdentifier)
+      if (!optionalTable.isPresent) {
+        Optional.empty()
+      } else {
+        val queryOperation = new SourceQueryOperation(optionalTable.get())
+        Optional.of(ApiExpressionUtils.tableRef(path, queryOperation))
+      }
+    } catch {
+      case _: SqlParserException => Optional.empty()

Review Comment:
   It's copied from `TableEnvironmentImpl`, I think we can also copy comment to here.
   Haven't find any test cases related to this exception path. Considering it's copied from existing codebase , may be we can add test in a dedicated pr if need.



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org