-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
compile_sql
via GraphQL (#44)
* feat: add `compile_sql` via GraphQL This commit adds a new `compile_sql` method to the SDK, which uses the GraphQL API to generate the compiled SQL given a set of query parameters. * test: add integration test for `compile_sql` Added an integration test for `compile_sql` that ensures we get data back from the API for a valid query which contains a `SELECT` statement. * docs: add example for `compile_sql` This commit adds a usage example for `compile_sql`. * docs: add changelog entry
- Loading branch information
1 parent
13ebfe5
commit 39b6f91
Showing
9 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kind: Features | ||
body: '`compile_sql` method for getting the compiled SQL of a query' | ||
time: 2024-09-20T18:05:50.976574+02:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Compile a query and display the SQL.""" | ||
|
||
from argparse import ArgumentParser | ||
|
||
from dbtsl import SemanticLayerClient | ||
|
||
|
||
def get_arg_parser() -> ArgumentParser: | ||
p = ArgumentParser() | ||
|
||
p.add_argument("metric", help="The metric to fetch") | ||
p.add_argument("group_by", help="A dimension to group by") | ||
p.add_argument("--env-id", required=True, help="The dbt environment ID", type=int) | ||
p.add_argument("--token", required=True, help="The API auth token") | ||
p.add_argument("--host", required=True, help="The API host") | ||
|
||
return p | ||
|
||
|
||
def main() -> None: | ||
arg_parser = get_arg_parser() | ||
args = arg_parser.parse_args() | ||
|
||
client = SemanticLayerClient( | ||
environment_id=args.env_id, | ||
auth_token=args.token, | ||
host=args.host, | ||
) | ||
|
||
with client.session(): | ||
sql = client.compile_sql( | ||
metrics=[args.metric], | ||
group_by=[args.group_by], | ||
limit=15, | ||
) | ||
print(f"Compiled SQL for {args.metric} grouped by {args.group_by}, limit 15:") | ||
print(sql) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters