bowenli86 commented on a change in pull request #8940: [FLINK-13047][table] Fix 
the Optional.orElse() usage issue in Databas…
URL: https://github.com/apache/flink/pull/8940#discussion_r299279990
 
 

 ##########
 File path: 
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/catalog/DatabaseCalciteSchema.java
 ##########
 @@ -104,9 +103,19 @@ private Table 
convertConnectorTable(ConnectorCatalogTable<?, ?> table) {
        }
 
        private Table convertCatalogTable(ObjectPath tablePath, CatalogTable 
table) {
+               TableSource<?> tableSource;
                Optional<TableFactory> tableFactory = catalog.getTableFactory();
-               TableSource<Row> tableSource = tableFactory.map(tf -> 
((TableSourceFactory) tf).createTableSource(tablePath, table))
-                       
.orElse(TableFactoryUtil.findAndCreateTableSource(table));
+               if (tableFactory.isPresent()) {
+                       TableFactory tf = tableFactory.get();
+                       if (tf instanceof TableSourceFactory) {
+                               tableSource = ((TableSourceFactory) 
tf).createTableSource(tablePath, table);
+                       } else {
+                               throw new 
TableException(String.format("TableFactory provided by catalog %s must 
implement TableSourceFactory",
 
 Review comment:
   minor: shall we use similar error message as that in 
`convertConnectorTable()`, something like "Cannot query a sink-only table. 
TableFactory provided by catalog %s must implement ....".
   
   Asking this because when I first saw this exception, I got a bit on confused 
why it cannot be `TableSinkFactory`. 

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

Reply via email to