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: add Shillelagh DB engine spec #16416

Merged

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Aug 24, 2021

SUMMARY

Shillelagh is a library for querying APIs via SQL. It's currently used by Superset in order to connect to Google Sheets, but it offers more APIs:

Datasette

Datasette is an open-source tool for exploring and publishing data, developed by one of the creators of Django. "Datasettes" are self-hosted micro web apps that serve a few tables, with a friendly UI. For example, this list of trees in SF.

Shillelagh can query any Datasette table directly:

% shillelagh
sql> SELECT * FROM "https://san-francisco.datasettes.com/sf-trees/Street_Tree_List" LIMIT 5;
  TreeID    qLegalStatus    qSpecies  qAddress             SiteOrder    qSiteInfo    PlantType    qCaretaker  qCareAssistant    PlantDate                 DBH  PlotSize    PermitNotes                XCoord       YCoord    Latitude    Longitude  Location
--------  --------------  ----------  -----------------  -----------  -----------  -----------  ------------  ----------------  ----------------------  -----  ----------  --------------------  -----------  -----------  ----------  -----------  -------------------------------------
  141565               1           1  501X Baker St                1            1            1             1                    07/21/1988 12:00:00 AM     21  Width 0ft   Permit Number 25401   6.00061e+06  2.11083e+06     37.776      -122.441  (37.7759676911831, -122.441396661871)
  232565               2           2  940 Elizabeth St             1            2            1             1                    03/20/2017 12:00:00 AM      3  Width 4ft   Permit Number 779625  6.0004e+06   2.102e+06       37.7517     -122.441  (37.7517102172731, -122.441498017841)
  119263               3           3  495X Lakeshore Dr            1            3            1             2                                                   10x30
  207368               2           4  920 Kirkham St               1            1            1             1                                                6  Width 1ft                         5.99201e+06  2.10527e+06     37.7602     -122.471  (37.760210314285, -122.47073935813)
  188702               3           5  1501 Evans Ave               2            4            1             2                                               17  Width 4ft                         6.01599e+06  2.09822e+06     37.7422     -122.387  (37.7422086702947, -122.387293152263)
sql>

We can create a dataset in Superset and make a map of red maple trees in SF:

Screenshot 2021-08-23 at 21-12-41  DEV  Red maple trees in SF

Socrata

The Socrata Open Data API is a simple API used by many governments, non-profits, and NGOs around the world, including the CDC. Shillelagh can connect directly to any Socrata dataset by using its API URL. Here's an example showing the percentage of adults partially vaccinated for COVID-19 in the US:

Screen Shot 2021-08-24 at 8 13 40 AM

% shillelagh
sql> SELECT date, administered_dose1_recip_4 FROM "https://data.cdc.gov/resource/unsk-b7fc.json" WHERE location='US' LIMIT 5;
date          administered_dose1_recip_4
----------  ----------------------------
2021-08-23                          73.1
2021-08-22                          73
2021-08-21                          72.9
2021-08-20                          72.7
2021-08-19                          72.5
sql>

We can also create a dataset in Superset and make a time series:

Screenshot 2021-08-23 at 21-21-45  DEV  % adults partially vaccinated US

WeatherAPI

This adapter offers access to historical weather data from WeatherAPI. It requires signing up and an API key, but there's a free account.

Here's an example chart showing the perceived temperature in Fahrenheit in Bodega Bay:

% shillelagh
sql> SELECT AVG(feelslike_f) AS "AVG(feelslike_f)"
FROM "https://api.weatherapi.com/v1/history.json?q=94923"
LIMIT 10000
OFFSET 0;
  AVG(feelslike_f)
------------------
           57.6054
sql>

Screenshot 2021-08-24 at 08-40-19  DEV  Explore - https api weatherapi com v1 history json q=94923

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

Shillelagh supports two dialects, shillelagh:// and shillelagh+safe://. The former is disabled in Superset if PREVENT_UNSAFE_DB_CONNECTIONS is true, since it can read and write to disk. The latter allows only safe adapters to be loaded, and they have to be listed explicitly:

An API key is needed for WeatherAPI:

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

@pull-request-size pull-request-size bot added size/M and removed size/S labels Aug 24, 2021
@betodealmeida betodealmeida marked this pull request as ready for review August 24, 2021 16:14
@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #16416 (f330351) into master (50d896f) will increase coverage by 0.00%.
The diff coverage is 67.77%.

❗ Current head f330351 differs from pull request most recent head 424abf2. Consider uploading reports for the commit 424abf2 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16416   +/-   ##
=======================================
  Coverage   76.51%   76.51%           
=======================================
  Files        1000     1001    +1     
  Lines       53479    53506   +27     
  Branches     6815     6814    -1     
=======================================
+ Hits        40917    40938   +21     
- Misses      12326    12330    +4     
- Partials      236      238    +2     
Flag Coverage Δ
hive 81.26% <80.88%> (+0.03%) ⬆️
mysql ?
postgres 81.52% <86.02%> (-0.03%) ⬇️
presto 81.33% <80.14%> (?)
python 82.02% <86.76%> (+0.11%) ⬆️
sqlite 81.20% <85.92%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
superset-frontend/src/components/Modal/Modal.tsx 100.00% <ø> (ø)
...-frontend/src/components/OmniContainer/Omnibar.tsx 100.00% <ø> (ø)
...rset-frontend/src/components/ReportModal/index.tsx 93.75% <ø> (+20.83%) ⬆️
...et-frontend/src/dashboard/components/Dashboard.jsx 78.84% <ø> (ø)
...rontend/src/dashboard/containers/DashboardPage.tsx 0.00% <0.00%> (ø)
...c/views/CRUD/data/database/DatabaseModal/index.tsx 44.24% <0.00%> (-0.12%) ⬇️
superset/charts/commands/importers/dispatcher.py 80.64% <ø> (ø)
superset/cli.py 52.85% <0.00%> (ø)
superset/commands/importers/v1/__init__.py 94.73% <ø> (ø)
superset/commands/importers/v1/examples.py 39.53% <ø> (ø)
... and 102 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 50d896f...424abf2. Read the comment docs.

@betodealmeida betodealmeida force-pushed the shillelagh_db_engine_spec branch 2 times, most recently from b50278b to b8ef2b7 Compare August 24, 2021 17:38
@pull-request-size pull-request-size bot added size/S and removed size/M labels Aug 24, 2021
@betodealmeida betodealmeida added v1.3 and removed v1.3 labels Aug 24, 2021
@pull-request-size pull-request-size bot added size/M and removed size/S labels Aug 24, 2021
@betodealmeida betodealmeida added the need:review Requires a code review label Aug 24, 2021
@@ -133,7 +133,7 @@ def get_git_sha() -> str:
"exasol": ["sqlalchemy-exasol>=2.1.0, <2.2"],
"excel": ["xlrd>=1.2.0, <1.3"],
"firebird": ["sqlalchemy-firebird>=0.7.0, <0.8"],
"gsheets": ["shillelagh[gsheetsapi]>=0.7.1, <0.8"],
"gsheets": ["shillelagh[gsheetsapi]>=1.0.3, <2"],
Copy link
Member

Choose a reason for hiding this comment

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

any breaking changes here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No breaking changes, just fixes and features.

@@ -133,7 +133,7 @@ def get_git_sha() -> str:
"exasol": ["sqlalchemy-exasol>=2.1.0, <2.2"],
"excel": ["xlrd>=1.2.0, <1.3"],
"firebird": ["sqlalchemy-firebird>=0.7.0, <0.8"],
"gsheets": ["shillelagh[gsheetsapi]>=0.7.1, <0.8"],
"gsheets": ["shillelagh[gsheetsapi]>=1.0.3, <2"],
Copy link
Member

Choose a reason for hiding this comment

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

any breaking changes here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No breaking changes, just fixes and features.

@betodealmeida betodealmeida added the need:merge The PR is ready to be merged label Aug 24, 2021
@betodealmeida betodealmeida merged commit 5e47298 into apache:master Aug 25, 2021
amitmiran137 pushed a commit to nielsen-oss/superset that referenced this pull request Aug 26, 2021
* upstream/master: (25 commits)
  chore(ci): bump pylint to 2.10.2 (apache#16463)
  fix: prevent page crash when chart can't render (apache#16464)
  chore: fixed slack invite link (apache#16466)
  fix(native-filters): handle null values in value filter (apache#16460)
  feat: add function list to auto-complete to Clickhouse datasource (apache#16234)
  refactor(explore): improve typing for Dnd controls (apache#16362)
  fix(explore): update overwrite button on perm change (apache#16437)
  feat: Draggable and Resizable Modal (apache#16394)
  refactor: sql_json view endpoint (apache#16441)
  fix(dashboard): undo and redo buttons weird alignment  (apache#16417)
  fix: setupPlugin in chart list page (apache#16413)
  fix: Disable Slack notification method if no api token (apache#16367)
  feat: add Shillelagh DB engine spec (apache#16416)
  fix: copy to Clipboard order (apache#16299)
  docs: make FEATURE_FLAGS.md reference a link (apache#16415)
  chore(viz): bump superset-ui to 0.17.87 (apache#16420)
  feat: add activate command (apache#16404)
  Revert "fix(explore): let admin overwrite slice (apache#16290)" (apache#16408)
  fix(explore): retain chart ownership on query context update (apache#16419)
  chore: Removes the TODOs and uses the default page size (apache#16422)
  ...
@villebro villebro added the v1.3 label Sep 6, 2021
villebro pushed a commit that referenced this pull request Sep 6, 2021
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
@mistercrunch mistercrunch added 🍒 1.3.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.4.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 need:merge The PR is ready to be merged need:review Requires a code review size/M v1.3 🍒 1.3.1 🍒 1.3.2 🚢 1.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants