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(sqla): convert prequery results to native python types #17195

Merged
merged 1 commit into from
Oct 22, 2021

Conversation

villebro
Copy link
Member

@villebro villebro commented Oct 22, 2021

SUMMARY

When limiting a query with top n series on a db that doesn't support subqueries (e.g. Druid), numeric values are sometimes returned as numpy types. For instance, integer values are returned as numpy.int64 instead of int. If the groupby column type is set to String type, despite the expression returning a numeric value, this causes the following SQLAlchemy compilation error:
image
image

This is due to SQLAlchemy attempting to perform a string replacement operation on the numeric value to escape hyphens during query compilation. However, by ensuring that the value is first converted into its native Python equivalent (np.inp64 to int), SQLAlchemy is able to ignore the incorrect target type (in this case String), and is able to successfully compile the query:
image

TESTING INSTRUCTIONS

  1. Use a database that doesn't support subqueries, e.g. Druid
  2. Create a dataset with a calculated column that returns a numeric value but set it to "STRING" type
  3. Create a chart with a limit on the series count
  4. Notice how the query raises a 500 when fetching data

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

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #17195 (e2ea5db) into master (4c708af) will decrease coverage by 0.07%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17195      +/-   ##
==========================================
- Coverage   76.91%   76.84%   -0.08%     
==========================================
  Files        1039     1039              
  Lines       55568    55571       +3     
  Branches     7570     7570              
==========================================
- Hits        42742    42702      -40     
- Misses      12576    12619      +43     
  Partials      250      250              
Flag Coverage Δ
hive 81.46% <66.66%> (+<0.01%) ⬆️
mysql 81.92% <66.66%> (+<0.01%) ⬆️
postgres 81.93% <66.66%> (+<0.01%) ⬆️
presto ?
python 82.28% <66.66%> (-0.15%) ⬇️
sqlite 81.60% <66.66%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
superset/connectors/sqla/models.py 86.04% <0.00%> (-1.31%) ⬇️
superset/utils/core.py 90.14% <100.00%> (+0.04%) ⬆️
superset/db_engine_specs/presto.py 84.30% <0.00%> (-6.07%) ⬇️
superset/models/core.py 89.26% <0.00%> (-0.74%) ⬇️

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 4c708af...e2ea5db. Read the comment docs.

@villebro villebro merged commit 2ba046f into apache:master Oct 22, 2021
@villebro villebro deleted the villebro/fix-numpy-prequery branch October 22, 2021 09:33
@sadpandajoe
Copy link
Member

🏷️ 2021.42

sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Oct 25, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.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:2021.42 preset-io size/M 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants