Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sqllab) Add a configuration option to disable data preview #14768

Closed
wants to merge 9 commits into from

Conversation

akedrou
Copy link

@akedrou akedrou commented May 22, 2021

SUMMARY

This PR adds a new per-database configuration option to disable data preview queries in SQL Lab. This setting is exposed in the database API as preview_data. I decided to add the feature to the database API and pass the database as a parameter to addTable rather than adding a database setting into a table API response (the proposed solution in #14726). As a result the data preview query was moved up to addTable as well. To my eye that looks cleaner since I don't think that previewing data should be a part of "table metadata" anyway.

There is no UI change, though the UX changes when data preview is disabled to not show the data preview pane (or results) when getting table metadata.

TESTING INSTRUCTIONS

  1. In the database configuration settings, add "preview_data": false to the "Extra" JSON object.
  2. In SQL Editor, select the database you have configured, and then any schema or table.
    • Alternately, trigger metadata to load from the editor textbox itself.
  3. Table metadata should load as normal, but no data preview query should run.
  4. When preview_data is true (or the key does not exist), a data preview query should run when selecting a table from the dropdown or triggering metadata to be loaded from the editor.

ADDITIONAL INFORMATION

This setting is per-database in the "extra" JSON data.
@akedrou akedrou changed the title [WIP] feat(sqllab) Add a configuration option to disable data preview feat(sqllab) Add a configuration option to disable data preview May 24, 2021
@eschutho
Copy link
Member

Thanks for the enhancement @akedrou.. I'm running tests now and added some reviewers.

@eschutho
Copy link
Member

@yousoph

@cccs-rc
Copy link
Contributor

cccs-rc commented Feb 10, 2022

@villebro This is the PR I was hoping we could get merged! :)

@villebro
Copy link
Member

@akedrou sorry about this PR falling through the cracks 🙁 This PR would need to be rebased. Is there any chance you could go through the trouble of doing that? I'd be happy to review, test and do my best to push this through (FYI @cccs-rc)

@akedrou
Copy link
Author

akedrou commented Feb 15, 2022

@villebro No problem! I figured it just slipped by and I didn't have the dedication to keep nagging - I should have some time to rebase within the next few days.

Thanks for coming back to the PR!

@codecov
Copy link

codecov bot commented Mar 3, 2022

Codecov Report

Merging #14768 (8459ad6) into master (00c99c9) will decrease coverage by 0.30%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14768      +/-   ##
==========================================
- Coverage   66.35%   66.04%   -0.31%     
==========================================
  Files        1640     1643       +3     
  Lines       63486    65575    +2089     
  Branches     6409     6503      +94     
==========================================
+ Hits        42124    43309    +1185     
- Misses      19702    20574     +872     
- Partials     1660     1692      +32     
Flag Coverage Δ
hive 52.65% <100.00%> (+0.17%) ⬆️
javascript 51.51% <80.00%> (+0.49%) ⬆️
mysql ?
postgres 81.88% <100.00%> (+0.12%) ⬆️
presto 52.50% <100.00%> (+0.18%) ⬆️
python 80.33% <100.00%> (-1.85%) ⬇️
sqlite ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...d/src/SqlLab/components/AceEditorWrapper/index.tsx 43.85% <ø> (ø)
...frontend/src/SqlLab/components/SqlEditor/index.jsx 51.44% <ø> (+0.29%) ⬆️
...d/src/SqlLab/components/SqlEditorLeftBar/index.tsx 58.82% <0.00%> (+1.68%) ⬆️
.../CRUD/data/database/DatabaseModal/ExtraOptions.tsx 83.33% <ø> (ø)
superset/databases/api.py 93.99% <ø> (ø)
superset/databases/schemas.py 98.47% <ø> (ø)
superset/views/core.py 65.81% <ø> (-11.70%) ⬇️
superset/views/database/mixins.py 81.03% <ø> (ø)
superset-frontend/src/SqlLab/actions/sqlLab.js 60.73% <100.00%> (+0.22%) ⬆️
superset/dashboards/schemas.py 99.41% <100.00%> (+<0.01%) ⬆️
... and 94 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00c99c9...8459ad6. Read the comment docs.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement! Something I've often been annoyed by. Some comments. Also, it seems there's currently a regression on master that breaks fetching table names (see #19008), so that probably needs to be fixed before we can properly test this

});

it('updates and runs data preview query when configured', () => {
expect.assertions(2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be

Suggested change
expect.assertions(2);
expect.assertions(5);

Comment on lines -756 to -760
expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(1);
expect(fetchMock.calls(getTableMetadataEndpoint)).toHaveLength(1);
expect(fetchMock.calls(getExtraTableMetadataEndpoint)).toHaveLength(
1,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +201 to +217
<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@villebro
Copy link
Member

villebro commented Mar 3, 2022

FYI @akedrou - @cccs-Dustin was kind enough to rebase this PR (I pushed the changes here). It still appears to need some lint cleanup + I added a few review comments. Let me know if you need help finishing this PR!

@villebro
Copy link
Member

Closing in favor of #19104 which finished this work

@villebro villebro closed this Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[sqllab] Add configuration option to disable data preview query in SQL editor
5 participants