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

Can Kedro handle templated queries? #214

Closed
atercygnus opened this issue Feb 5, 2020 · 3 comments
Closed

Can Kedro handle templated queries? #214

atercygnus opened this issue Feb 5, 2020 · 3 comments

Comments

@atercygnus
Copy link

atercygnus commented Feb 5, 2020

I apologize if this feature is already implemented, but I can't find one.

Need to have SQLQueryDataSet with parameters.
Something like:

**catalog.yml:**

foo_dataset:
    type: SQLQueryDataSet
    credentials: foo_cred
    sql:
        select id, ... from foo_table where id in ({%ids})

**notebook or .py file:**

ids_tofetch = [...]
df = context.catalog.load('foo_dataset', {'ids':ids_tofetch})

Can this be done for now?

@atercygnus atercygnus added the Issue: Feature Request New feature or improvement to existing feature label Feb 5, 2020
@yetudada
Copy link
Contributor

yetudada commented Feb 5, 2020

Hi @atercygnus! Thanks for raising this query. A templated query, or in your case, a templated catalog.yml is possible. Here are the docs for this: https://kedro.readthedocs.io/en/latest/04_user_guide/03_configuration.html#templating-configuration. However, this would still require you to create a globals.yml in conf/ to host your ids_tofetch. Is this possible in your use case?

We actually find that Stack Overflow might be better suited to these kind of questions, so please do post there next, tag your questions with kedro and we'll find them.

@atercygnus
Copy link
Author

atercygnus commented Feb 6, 2020

Hi @yetudada! Thanks for answering!

This is nice, and solves a part of my problem, but in many cases sql queries are too complicated to be a single query, and it's convenient to fetch parts of the data separately, and then merge them in python. In this case it is essential to have templated queries without using additional file globals.yml.

@yetudada yetudada changed the title Can Kedro handle templated queryes? Can Kedro handle templated queries? Feb 13, 2020
@lorenabalan lorenabalan added Issue: Question and removed Issue: Feature Request New feature or improvement to existing feature labels May 27, 2020
@lorenabalan
Copy link
Contributor

Closing this issue as stale, but please feel free to raise a new one if you encounter other problems. As Yetu noted, TemplatedConfigLoader could be helpful here. Otherwise maybe a local customisation for the SQLDataSet is the best guess.

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

No branches or pull requests

3 participants