fhueske commented on a change in pull request #6508: [Flink-10079] [table] 
Support external sink table in the INSERT INTO clause 
URL: https://github.com/apache/flink/pull/6508#discussion_r218205508
 
 

 ##########
 File path: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/TableEnvironment.scala
 ##########
 @@ -828,12 +831,28 @@ abstract class TableEnvironment(val config: TableConfig) 
{
     rootSchema.getTableNames.contains(name)
   }
 
-  protected def getTable(name: String): org.apache.calcite.schema.Table = {
-    rootSchema.getTable(name)
-  }
+  /**
+    * Get a table from either internal or external catalogs.
+    *
+    * @param name The name of the table.
+    * @return The table registered either internally or externally, None 
otherwise.
+    */
+  protected def getTable(name: String): 
Option[org.apache.calcite.schema.Table] = {
+    val internalTable = rootSchema.getTable(name)
 
-  protected def getRowType(name: String): RelDataType = {
-    rootSchema.getTable(name).getRowType(typeFactory)
+    if (internalTable != null) {
+      Some(internalTable)
+    } else {
+      // search external catalogs
+      var (subSchema, tableName) = (rootSchema, name)
+      while (tableName.contains(".")) {
+        val Array(subcatalog, table) = tableName.split("\\.", 2)
+        subSchema = subSchema.getSubSchema(subcatalog)
 
 Review comment:
   We need to check for `subSchema != null` to prevent an NPE if a subschema 
does not exist.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to