fhueske commented on a change in pull request #6606: [FLINK-10163] [sql-client] 
Support views in SQL Client
URL: https://github.com/apache/flink/pull/6606#discussion_r212654542
 
 

 ##########
 File path: 
flink-libraries/flink-sql-client/src/main/java/org/apache/flink/table/client/config/Environment.java
 ##########
 @@ -67,24 +75,36 @@ public Environment() {
        public void setTables(List<Map<String, Object>> tables) {
                this.tables = new HashMap<>(tables.size());
                tables.forEach(config -> {
-                       if (!config.containsKey(TABLE_NAME)) {
-                               throw new SqlClientException("The 'name' 
attribute of a table is missing.");
-                       }
-                       final Object nameObject = config.get(TABLE_NAME);
-                       if (nameObject == null || !(nameObject instanceof 
String) || ((String) nameObject).length() <= 0) {
-                               throw new SqlClientException("Invalid table 
name '" + nameObject + "'.");
-                       }
-                       final String name = (String) nameObject;
+                       final String name = extractEarlyStringProperty(config, 
TABLE_NAME, "table");
                        final Map<String, Object> properties = new 
HashMap<>(config);
                        properties.remove(TABLE_NAME);
 
-                       if (this.tables.containsKey(name)) {
+                       if (this.tables.containsKey(name) || 
this.views.containsKey(name)) {
                                throw new SqlClientException("Duplicate table 
name '" + name + "'.");
                        }
                        this.tables.put(name, createTableDescriptor(name, 
properties));
                });
        }
 
+       public Map<String, String> getViews() {
+               return views;
+       }
+
+       public void setViews(List<Map<String, Object>> views) {
+               // the order of how views are registered matters because
+               // they might reference each other
+               this.views = new LinkedHashMap<>(views.size());
+               views.forEach(config -> {
+                       final String name = extractEarlyStringProperty(config, 
VIEW_NAME, "view");
+                       final String query = extractEarlyStringProperty(config, 
VIEW_QUERY, "view");
+
+                       if (this.tables.containsKey(name) || 
this.views.containsKey(name)) {
+                               throw new SqlClientException("Duplicate table 
name '" + name + "'.");
 
 Review comment:
   `table name` -> `view name` (or rewrite error message to sth like "Cannot 
create view XXX because another table or view with that name is already 
registered."

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