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: error around latest partition in BigQuery #11274

Merged
merged 5 commits into from
Oct 21, 2020

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Oct 14, 2020

Hit this bug while using BigQ. The SQLAlchemy inspector's get_indexes returns a list of columns that is wrong and get the SQL Lab frontend to hard crash.

Here's the exact payload I was getting off of get_indexes for a particular table:
[{'name': 'partition', 'column_names': [None], 'unique': False}]

Here I'm adding a BigQuery specific mutation for the indexes that makes sure this doesn't happen. We're assuming that pybigquery will fix the root cause in a future version.

Screen Shot 2020-10-18 at 10 27 37 PM

@codecov-io
Copy link

codecov-io commented Oct 16, 2020

Codecov Report

Merging #11274 into master will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11274      +/-   ##
==========================================
- Coverage   65.63%   65.62%   -0.02%     
==========================================
  Files         838      839       +1     
  Lines       39714    39841     +127     
  Branches     3613     3653      +40     
==========================================
+ Hits        26068    26145      +77     
- Misses      13538    13595      +57     
+ Partials      108      101       -7     
Flag Coverage Δ
#cypress 56.23% <0.00%> (+0.39%) ⬆️
#javascript 62.66% <100.00%> (+0.05%) ⬆️
#python 60.60% <100.00%> (-0.31%) ⬇️

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

Impacted Files Coverage Δ
...et-frontend/src/SqlLab/components/TableElement.jsx 82.55% <100.00%> (ø)
superset/db_engine_specs/base.py 85.60% <100.00%> (-1.77%) ⬇️
superset/db_engine_specs/bigquery.py 95.69% <100.00%> (+0.46%) ⬆️
superset/models/core.py 86.07% <100.00%> (-3.04%) ⬇️
...d/src/views/CRUD/csstemplates/CssTemplatesList.tsx 80.39% <0.00%> (-16.91%) ⬇️
superset/db_engine_specs/mysql.py 79.59% <0.00%> (-12.25%) ⬇️
superset/db_engine_specs/sqlite.py 65.62% <0.00%> (-9.38%) ⬇️
superset/databases/commands/create.py 82.97% <0.00%> (-8.52%) ⬇️
superset/databases/commands/update.py 85.71% <0.00%> (-8.17%) ⬇️
superset/utils/celery.py 82.14% <0.00%> (-3.58%) ⬇️
... and 35 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 9266f0a...2905eb7. Read the comment docs.

@mistercrunch mistercrunch force-pushed the fix_partition_bug_bigq branch 2 times, most recently from b852a3d to f099e0e Compare October 19, 2020 00:56
@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 19, 2020
@@ -110,7 +110,7 @@ class TableElement extends React.PureComponent {
/>
);
}
let latest = Object.entries(table.partitions.latest).map(
let latest = Object.entries(table.partitions?.latest || []).map(
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't necessary anymore given the issue being addressed in the backend, but is a tiny bit of defensive programming.

@mistercrunch mistercrunch force-pushed the fix_partition_bug_bigq branch from 4edbc56 to 816d467 Compare October 19, 2020 05:18
@mistercrunch mistercrunch force-pushed the fix_partition_bug_bigq branch from 816d467 to f8dbcae Compare October 20, 2020 04:12
Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

LGTM

# the index's `column_names` == [None]
# Here we're returning only non-None indexes
for ix in indexes:
column_names = ix.get("column_names") or []
Copy link
Member

Choose a reason for hiding this comment

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

nit:

        for index in indexes:
            column_names = index.get("column_names", [])

Copy link
Member Author

Choose a reason for hiding this comment

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

the or is a bit safer in case the key exists with a None value, will stick to it

normalized_idx = BigQueryEngineSpec.normalize_indexes(indexes)
self.assertEqual(normalized_idx, [])

indexes = [{"name": "partition", "column_names": ["dttm"], "unique": False}]
Copy link
Member

Choose a reason for hiding this comment

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

we could add another small test with indexes = [{"name": "partition", "column_names": ["dttm", None], "unique": False}]

@mistercrunch mistercrunch force-pushed the fix_partition_bug_bigq branch from 7fa9092 to 2905eb7 Compare October 20, 2020 21:49
@mistercrunch
Copy link
Member Author

addressed the comments, mergin'!

@mistercrunch mistercrunch merged commit 796a2a6 into apache:master Oct 21, 2020
@mistercrunch mistercrunch deleted the fix_partition_bug_bigq branch October 21, 2020 04:34
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
* fix: error around latest partition in BigQuery

* lint

* Going with a backend-first approach

* fix test

* add an extra test
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 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 size/M 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants