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

fix(sql lab): add quotes when autocompleting table names with spaces in the editor #19311

Conversation

diegomedina248
Copy link
Contributor

SUMMARY

The SQL autocomplete in the SQL Lab editor work with the tables loaded from the schema.
The autocomplete works, but if the table has spaces, the query won't work as it's not properly escaped.

This PR adds quotes around the table name if it has spaces in it.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

Screen.Recording.2022-03-22.at.14.21.21.mov

After:

Screen.Recording.2022-03-22.at.14.22.40.mov

TESTING INSTRUCTIONS

  1. Open SQL lab
  2. Select a database & schema that contain table with spaces
  3. Attempt to add that table with autocomplete

Ensure the autocompleted table has quotes if the name has spaces in it.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Mar 22, 2022

Codecov Report

Merging #19311 (420973f) into master (7ca10fb) will decrease coverage by 0.00%.
The diff coverage is 80.88%.

❗ Current head 420973f differs from pull request most recent head 74d1b86. Consider uploading reports for the commit 74d1b86 to get more accurate results

@@            Coverage Diff             @@
##           master   #19311      +/-   ##
==========================================
- Coverage   66.65%   66.64%   -0.01%     
==========================================
  Files        1672     1674       +2     
  Lines       64611    64606       -5     
  Branches     6505     6501       -4     
==========================================
- Hits        43066    43058       -8     
- Misses      19862    19865       +3     
  Partials     1683     1683              
Flag Coverage Δ
javascript 51.31% <80.00%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
...superset-ui-core/src/query/types/PostProcessing.ts 100.00% <ø> (ø)
.../superset-ui-core/src/query/types/QueryFormData.ts 100.00% <ø> (ø)
...src/BigNumber/BigNumberWithTrendline/buildQuery.ts 11.11% <ø> (+2.02%) ⬆️
...in-chart-echarts/src/MixedTimeseries/buildQuery.ts 0.00% <ø> (ø)
.../plugin-chart-echarts/src/Timeseries/buildQuery.ts 66.66% <0.00%> (ø)
...d/src/SqlLab/components/AceEditorWrapper/index.tsx 42.62% <0.00%> (-2.21%) ⬇️
...-frontend/src/components/UiConfigContext/index.tsx 50.00% <0.00%> (ø)
superset-frontend/src/utils/urlUtils.ts 36.73% <ø> (ø)
...perset-frontend/src/views/CRUD/welcome/Welcome.tsx 75.00% <0.00%> (ø)
superset-frontend/src/views/components/Menu.tsx 60.00% <ø> (ø)
... and 32 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 7ca10fb...74d1b86. Read the comment docs.

@@ -221,11 +221,15 @@ class AceEditorWrapper extends React.PureComponent<Props, State> {
this.props.queryEditor.schema,
);
}

let { caption } = data;
if (data.meta === 'table' && caption.includes(' ')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, we don't need to check if the caption contains space or not, because adding quotes to table name will always work fine. So you don't need this condition again, just add your expression into above condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works fine, but it doesn't look good. We should only add it when needed

Copy link
Member

Choose a reason for hiding this comment

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

@codemaster08240328 any updates here?

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM!

@rusackas rusackas merged commit 8d4a52c into apache:master Apr 15, 2022
philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels Preset-Patch size/S 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants