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/03 09:12:32 UTC

[GitHub] [superset] villebro commented on a change in pull request #14768: feat(sqllab) Add a configuration option to disable data preview

villebro commented on a change in pull request #14768:
URL: https://github.com/apache/superset/pull/14768#discussion_r818440960



##########
File path: superset-frontend/src/SqlLab/actions/sqlLab.test.js
##########
@@ -727,37 +727,64 @@ describe('async actions', () => {
       it('updates the table schema state in the backend', () => {
         expect.assertions(5);
 
+        const database = { allows_preview_data: false };
+        const tableName = 'table';
+        const schemaName = 'schema';
+        const store = mockStore({});
+        const expectedActionTypes = [
+          actions.MERGE_TABLE, // addTable
+          actions.MERGE_TABLE, // getTableMetadata
+          actions.MERGE_TABLE, // getTableExtendedMetadata
+          actions.MERGE_TABLE, // addTable
+        ];
+        return store
+          .dispatch(actions.addTable(query, database, tableName, schemaName))
+          .then(() => {
+            expect(store.getActions().map(a => a.type)).toEqual(
+              expectedActionTypes,
+            );
+            expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(1);
+            expect(fetchMock.calls(getTableMetadataEndpoint)).toHaveLength(1);
+            expect(fetchMock.calls(getExtraTableMetadataEndpoint)).toHaveLength(
+              1,
+            );
+
+            // tab state is not updated, since no query was run
+            expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
+          });
+      });
+
+      it('updates and runs data preview query when configured', () => {
+        expect.assertions(2);

Review comment:
       I think this should be 
   ```suggestion
           expect.assertions(5);
   ```

##########
File path: superset-frontend/src/SqlLab/actions/sqlLab.test.js
##########
@@ -727,37 +727,64 @@ describe('async actions', () => {
       it('updates the table schema state in the backend', () => {
         expect.assertions(5);
 
+        const database = { allows_preview_data: false };
+        const tableName = 'table';
+        const schemaName = 'schema';
+        const store = mockStore({});
+        const expectedActionTypes = [
+          actions.MERGE_TABLE, // addTable
+          actions.MERGE_TABLE, // getTableMetadata
+          actions.MERGE_TABLE, // getTableExtendedMetadata
+          actions.MERGE_TABLE, // addTable
+        ];
+        return store
+          .dispatch(actions.addTable(query, database, tableName, schemaName))
+          .then(() => {
+            expect(store.getActions().map(a => a.type)).toEqual(
+              expectedActionTypes,
+            );
+            expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(1);
+            expect(fetchMock.calls(getTableMetadataEndpoint)).toHaveLength(1);
+            expect(fetchMock.calls(getExtraTableMetadataEndpoint)).toHaveLength(
+              1,
+            );
+
+            // tab state is not updated, since no query was run
+            expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
+          });
+      });
+
+      it('updates and runs data preview query when configured', () => {
+        expect.assertions(2);
+
         const results = {
           data: mockBigNumber,
-          query: { sqlEditorId: 'null' },
+          query: { sqlEditorId: 'null', dbId: 1 },
           query_id: 'efgh',
         };
         fetchMock.post(runQueryEndpoint, JSON.stringify(results), {
           overwriteRoutes: true,
         });
 
+        const database = { allows_preview_data: true, id: 1 };
         const tableName = 'table';
         const schemaName = 'schema';
         const store = mockStore({});
         const expectedActionTypes = [
           actions.MERGE_TABLE, // addTable
           actions.MERGE_TABLE, // getTableMetadata
-          actions.START_QUERY, // runQuery (data preview)
           actions.MERGE_TABLE, // getTableExtendedMetadata
-          actions.QUERY_SUCCESS, // querySuccess
+          actions.MERGE_TABLE, // addTable (data preview)
+          actions.START_QUERY, // runQuery (data preview)
           actions.MERGE_TABLE, // addTable
+          actions.QUERY_SUCCESS, // querySuccess
         ];
         return store
-          .dispatch(actions.addTable(query, tableName, schemaName))
+          .dispatch(actions.addTable(query, database, tableName, schemaName))
           .then(() => {
             expect(store.getActions().map(a => a.type)).toEqual(
               expectedActionTypes,
             );
-            expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(1);
-            expect(fetchMock.calls(getTableMetadataEndpoint)).toHaveLength(1);
-            expect(fetchMock.calls(getExtraTableMetadataEndpoint)).toHaveLength(
-              1,
-            );

Review comment:
       ..and these lines should not be removed (I tested locally, and the test passes with these changes)

##########
File path: superset-frontend/src/views/CRUD/data/database/DatabaseModal/ExtraOptions.tsx
##########
@@ -198,6 +198,23 @@ const ExtraOptions = ({
                 />
               </div>
             </StyledInputContainer>
+            <StyledInputContainer>
+              <div className="input-container">
+                <IndeterminateCheckbox
+                  id="allows_preview_data"
+                  indeterminate={false}
+                  checked={!!db?.extra_json?.allows_preview_data}
+                  onChange={onExtraInputChange}
+                  labelText={t('Allow SQL Lab data preview queries')}
+                />
+                <InfoTooltip
+                  tooltip={t(
+                    'The allows_preview_data field is a boolean specifying whether or not data ' +
+                      'preview queries will be run when fetching table metadata in SQL Lab.',
+                  )}
+                />
+              </div>
+            </StyledInputContainer>

Review comment:
       I believe we may need to reverse this flag to `disable_preview_data`, as otherwise this will disable data preview for existing databases (breaking change)




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