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

Example Script: Get table names used by data source #11

Merged
merged 25 commits into from
Feb 24, 2021
Merged

Conversation

susodapop
Copy link
Collaborator

@susodapop susodapop commented Apr 13, 2020

Type of PR

  • Feature

Description

Adds a script that shows which tables of a SQL data source are used in queries. It checks table names against the data source schema (if available). If schema is not available then CTE's and temporary tables are included in the output. No way around this AFAIK.

Example

$ python3 find-table-names.py URL APIKEY DS_ID

              table | number of queries
------------------- | -----------------
            queries |               213
      organizations |               201
             events |               157
              users |               106
       data_sources |                81
      query_results |                61
         dashboards |                56
     visualizations |                37

The --detail flag prints a CSV stream of query_id and table_name pairs to stdout. Like:

2168,queries
2168,organizations
1432,queries
1431,queries
1431,organizations

This is meant for writing to disk:

$ python3 find-table-names.py URL APIKEY DS_ID --detail yes > tables.csv

Can also be invoked as a console_script

$ find-tables URL APIKEY DS_ID

or from within the project directory:

$ poetry run find-tables URL APIKEY DS_ID

Related Issues

#10

@susodapop
Copy link
Collaborator Author

I ran black over this before committing. I don't care for the restyled changes.

@susodapop susodapop requested a review from rauchy April 13, 2020 19:09
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
redash_toolbelt/examples/find-table-names.py Outdated Show resolved Hide resolved
@susodapop susodapop marked this pull request as draft April 13, 2020 23:07
@susodapop susodapop marked this pull request as ready for review April 16, 2020 19:41
@susodapop susodapop requested a review from rauchy April 16, 2020 19:41
@susodapop susodapop merged commit 8b6bb49 into master Feb 24, 2021
@susodapop susodapop deleted the issue-10 branch February 24, 2021 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants