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(uploads): respect db engine spec's supports_multivalues_insert value for file uploads & enable multi-insert for MSSQL #30222

Merged
merged 9 commits into from
Sep 12, 2024

Conversation

sfirke
Copy link
Member

@sfirke sfirke commented Sep 10, 2024

SUMMARY

This PR makes two changes to enable the setting of method = 'multi' when the Pandas function .to_sql is called to write a file upload to a data warehouse. This speeds up file uploads by 15x. See discussion #30152 for background and discussion.

Changes:

  1. The base method df_to_sql does not currently access the supports_multivalues_insert attribute when it is set in a Superset EngineSpec. Instead it relies on this attribute being set in the SQLAlchemy implementation for that dialect. After this PR, Superset will check both of these places for the attribute.
  2. Sets the attribute supports_multivalues_insert to True for Microsoft SQL Server (MSSQL), which has supported this behavior since SQL Server 2008.

Thanks to @nytai for advising.

TESTING INSTRUCTIONS

Check that uploading a flat file to a data warehouse succeeds. I tested it for MSSQL. This PR was written to not reduce any existing functionality (there's an or with the previous condition) but someone could check on another data warehouse too.

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

@sfirke sfirke requested a review from nytai September 10, 2024 18:02
@dosubot dosubot bot added change:backend Requires changing the backend data:connect:mssql Related to MSSSQL labels Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.69%. Comparing base (76d897e) to head (94550af).
Report is 724 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #30222       +/-   ##
===========================================
+ Coverage   60.48%   83.69%   +23.20%     
===========================================
  Files        1931      529     -1402     
  Lines       76236    38420    -37816     
  Branches     8568        0     -8568     
===========================================
- Hits        46114    32155    -13959     
+ Misses      28017     6265    -21752     
+ Partials     2105        0     -2105     
Flag Coverage Δ
hive 48.87% <66.66%> (-0.29%) ⬇️
javascript ?
mysql 76.63% <100.00%> (?)
postgres 76.73% <100.00%> (?)
presto 53.38% <66.66%> (-0.42%) ⬇️
python 83.69% <100.00%> (+20.20%) ⬆️
sqlite 76.18% <100.00%> (?)
unit 60.44% <66.66%> (+2.82%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

LGTM, but all db engine spec class properites need to be also added to BaseEngineSpec with conservative defaults.

superset/db_engine_specs/mssql.py Show resolved Hide resolved
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.

Generally LGTM but could be simplified more

superset/db_engine_specs/base.py Outdated Show resolved Hide resolved
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.

Nice, really stoked about this PR, LGTM! 🚀

@sfirke sfirke merged commit f8a7753 into apache:master Sep 12, 2024
37 checks passed
@sfirke sfirke deleted the fix-multivalues-insert branch September 12, 2024 00:17
@sfirke sfirke removed the request for review from nytai September 12, 2024 00:19
sadpandajoe pushed a commit that referenced this pull request Sep 12, 2024
…lue for file uploads & enable multi-insert for MSSQL (#30222)

Co-authored-by: Ville Brofeldt <[email protected]>
(cherry picked from commit f8a7753)
@sadpandajoe sadpandajoe added the v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:backend Requires changing the backend data:connect:mssql Related to MSSSQL size/XS v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants