You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/03/23 06:00:53 UTC

[GitHub] [superset] RahulRaj97 opened a new pull request #19319: feat: Catalogs functionality (Presto)

RahulRaj97 opened a new pull request #19319:
URL: https://github.com/apache/superset/pull/19319


   <!---
   Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   Functionality added to fetch catalogs and shortlist schemas based on catalogs for presto databases.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   ![feat-catalogs](https://user-images.githubusercontent.com/29128399/159472165-5fdd71e3-e728-45ee-8880-a0471dc150b4.gif)
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   TBD, working on it.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [x] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscribe@superset.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie edited a comment on pull request #19319: feat: Catalogs functionality (Presto)

Posted by GitBox <gi...@apache.org>.
zhaoyongjie edited a comment on pull request #19319:
URL: https://github.com/apache/superset/pull/19319#issuecomment-1076064369


   Hey @RahulRaj97, thanks for your contribution! Could you post a screenshot for the dataset Modal if the Database(such as MySQL) doesn't have `catalog`?
   
   BTW, although there are multiple layers of namespaces in database systems, many databases do not fully implement them. Currently, Superset just uses Database/Schema/Table in both SQLLab and Explore. If we add `Catalog` in the dataset model, we should append this level into SQLLab.


-- 
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: notifications-unsubscribe@superset.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on pull request #19319: feat: Catalogs functionality (Presto)

Posted by GitBox <gi...@apache.org>.
zhaoyongjie commented on pull request #19319:
URL: https://github.com/apache/superset/pull/19319#issuecomment-1076064369


   Hey @RahulRaj97, thanks for your contribution! Could you post a screenshot for the dataset Modal if the Database(such as MySQL) doesn't have `catalog`?
   
   BTW, although there are multiple layers of namespaces in database systems, many databases do not fully implement them. currently, Superset just uses Database/Schema/Table in both SQLLab and Explore. If we add `Catalog` in the dataset model, we should append this level into SQLLab.


-- 
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: notifications-unsubscribe@superset.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a change in pull request #19319: feat: catalogs functionality (presto)

Posted by GitBox <gi...@apache.org>.
villebro commented on a change in pull request #19319:
URL: https://github.com/apache/superset/pull/19319#discussion_r834203967



##########
File path: superset-frontend/src/components/DatabaseSelector/utils.ts
##########
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import _ from 'lodash';
+import { DatabaseObject } from '.';
+
+export function isPrestoDatabase(database: DatabaseObject | undefined) {
+  return _.isEqual(database?.backend, 'presto');

Review comment:
       this seems unnecessarily heavy duty - something like this should be enough IMO:
   ```suggestion
     return database?.backend === 'presto';
   ```

##########
File path: superset-frontend/src/components/DatabaseSelector/utils.ts
##########
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import _ from 'lodash';
+import { DatabaseObject } from '.';
+
+export function isPrestoDatabase(database: DatabaseObject | undefined) {

Review comment:
       This needs to be made more generic. I would propose adding a property to `BaseEngineSpec` that defines whether or not catalogs are supported (defaults to `False`), add it to the `Database` schema and then set that to `True` for Presto, Trino and others that support it.

##########
File path: superset-frontend/src/components/TableSelector/index.tsx
##########
@@ -174,56 +185,73 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
     // reset selections
     if (database === undefined) {
       setCurrentDatabase(undefined);
+      setCurrentCatalog(undefined);
       setCurrentSchema(undefined);
       setCurrentTable(undefined);
     }
   }, [database]);
 
   useEffect(() => {
-    if (currentDatabase && currentSchema) {
+    if (shouldLoadTables(currentDatabase)) {
       setLoadingTables(true);
-      const encodedSchema = encodeURIComponent(currentSchema);
       const forceRefresh = refresh !== previousRefresh;
-      // TODO: Would be nice to add pagination in a follow-up. Needs endpoint changes.

Review comment:
       Would be nice to retain the TODO my moving it into the `getEndpoint` callback

##########
File path: superset-frontend/src/components/TableSelector/index.tsx
##########
@@ -174,56 +185,73 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
     // reset selections
     if (database === undefined) {
       setCurrentDatabase(undefined);
+      setCurrentCatalog(undefined);
       setCurrentSchema(undefined);
       setCurrentTable(undefined);
     }
   }, [database]);
 
   useEffect(() => {
-    if (currentDatabase && currentSchema) {
+    if (shouldLoadTables(currentDatabase)) {
       setLoadingTables(true);
-      const encodedSchema = encodeURIComponent(currentSchema);
       const forceRefresh = refresh !== previousRefresh;
-      // TODO: Would be nice to add pagination in a follow-up. Needs endpoint changes.
-      const endpoint = encodeURI(
-        `/superset/tables/${currentDatabase.id}/${encodedSchema}/undefined/${forceRefresh}/`,
-      );
-
-      if (previousRefresh !== refresh) {
-        setPreviousRefresh(refresh);
-      }
-
-      SupersetClient.get({ endpoint })
-        .then(({ json }) => {
-          const options: TableOption[] = [];
-          let currentTable;
-          json.options.forEach((table: Table) => {
-            const option = {
-              value: table.value,
-              label: <TableOption table={table} />,
-              text: table.label,
-            };
-            options.push(option);
-            if (table.label === tableName) {
-              currentTable = option;
-            }
-          });
-
-          onTablesLoad?.(json.options);
-          setTableOptions(options);
-          setCurrentTable(currentTable);
-          setLoadingTables(false);
-          if (forceRefresh) addSuccessToast('List updated');
-        })
-        .catch(() => {
-          setLoadingTables(false);
-          handleError(t('There was an error loading the tables'));
-        });
+      const endpoint = getEndpoint({
+        forceRefresh,
+        schema: currentSchema || '',
+        databaseId: currentDatabase?.id || 0,
+      });
+      const encodedEndpoint = encodeURI(endpoint);
+      if (previousRefresh !== refresh) setPreviousRefresh(refresh);
+      fetchTables(encodedEndpoint, forceRefresh);
     }
-    // We are using the refresh state to re-trigger the query
-    // previousRefresh should be out of dependencies array
-    // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, [currentDatabase, currentSchema, onTablesLoad, refresh]);
+  }, [refresh, currentDatabase, currentCatalog, currentSchema, onTablesLoad]);
+
+  function getEndpoint({
+    schema,
+    databaseId,
+    forceRefresh,
+  }: {
+    schema: string;
+    databaseId: number;
+    forceRefresh: boolean;
+  }) {
+    const encodedSchema = encodeURIComponent(schema);
+    return `/superset/tables/${databaseId}/${encodedSchema}/undefined/${forceRefresh}/`;
+  }

Review comment:
       While we're at it, it would be nice to wrap these in `useCallback`. Also, you should always use arrow functions in React components (applies to `shouldLoadTables` and other functions below).




-- 
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: notifications-unsubscribe@superset.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org