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

[SQL Lab] Add function names to autocomplete #9012

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Jan 24, 2020

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Adds a new function to db_engine_specs for getting function names available in a database. Also implements this function for Presto and Hive.

Then passes this result through the database API and adds it to the SQL Lab editor autocomplete

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Hive:
Screen Shot 2020-01-23 at 6 17 31 PM
Presto:
Screen Shot 2020-01-23 at 6 17 45 PM

TEST PLAN

Test with Hive and Presto and see function autocompletes. Test with mysql and ensure that autocompletes still work

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @dpgaspar @villebro @john-bodley @graceguo-supercat @betodealmeida

@@ -320,7 +324,7 @@ def get_quoter(self):
return self.get_dialect().identifier_preparer.quote

def get_df( # pylint: disable=too-many-locals
self, sql: str, schema: str, mutator: Optional[Callable] = None
self, sql: str, schema: Optional[str] = None, mutator: Optional[Callable] = None
Copy link
Member Author

@etr2460 etr2460 Jan 24, 2020

Choose a reason for hiding this comment

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

self.get_sla_engine (which is called on line 336) sets schema to None by default so I moved this up a level to make my db query easier (since it's not schema dependent)

:param database: The database to get functions for
:return: A list of function names useable in the database
"""
df = database.get_df("SHOW FUNCTIONS")
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove the interim df variable, i.e.,

return database.get_df("SHOW FUNCTIONS")["tab_name"].tolist()

@etr2460 etr2460 force-pushed the erik-ritter--add-function-names-sql-autocomplete branch from b7aa583 to 99a14c7 Compare January 24, 2020 17:19
@codecov-io
Copy link

Codecov Report

Merging #9012 into master will increase coverage by <.01%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9012      +/-   ##
==========================================
+ Coverage   59.15%   59.15%   +<.01%     
==========================================
  Files         367      367              
  Lines       11682    11686       +4     
  Branches     2864     2866       +2     
==========================================
+ Hits         6910     6913       +3     
- Misses       4593     4594       +1     
  Partials      179      179
Impacted Files Coverage Δ
...uperset/assets/src/SqlLab/components/SqlEditor.jsx 51.94% <100%> (+0.31%) ⬆️
superset/assets/src/SqlLab/constants.js 100% <100%> (ø) ⬆️
.../assets/src/SqlLab/components/AceEditorWrapper.jsx 54.21% <33.33%> (-0.11%) ⬇️

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 d0bc04f...99a14c7. Read the comment docs.

@etr2460 etr2460 force-pushed the erik-ritter--add-function-names-sql-autocomplete branch from 99a14c7 to 6d13b75 Compare January 24, 2020 17:45
@etr2460 etr2460 merged commit a4b8e0b into apache:master Jan 24, 2020
@villebro
Copy link
Member

villebro commented Jan 24, 2020

I seem to have just missed the train.. LGTM, but something worth considering: some dbs support defining UDFs per account/database/schema (e.g. Snowflake: SHOW USER FUNCTIONS IN SCHEMA 'my_schema'). While fetching global functions is most likely 99 % of use cases, adding the schema parameter to get_function_names could be used to add UDFs that are available in the chosen schema for the current user.

@etr2460
Copy link
Member Author

etr2460 commented Jan 24, 2020

eek, sorry about that @villebro! I didn't realize some dbs supported UDFs per schema. Do you think it's worth adding that functionality now, given that i've only implemented hive and presto, or should we wait for someone more familiar with Snowflake or other dbs to update the function signature for what they require?

@villebro
Copy link
Member

No panic, I'm pretty excited about getting these in for Snowflake, so can do the necessary changes in a separate PR 👍

@etr2460
Copy link
Member Author

etr2460 commented Jan 24, 2020

Sounds good! Feel free to tag me on your PR and i'll review

@villebro
Copy link
Member

Thanks, will do!

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.36.0 labels Feb 28, 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 🚢 0.36.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants