-
Notifications
You must be signed in to change notification settings - Fork 11
Fix workbench demo launch #142
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| """Example semantic SQL queries for the workbench.""" | ||
|
|
||
| EXAMPLE_QUERIES = { | ||
| "Timeseries": """-- Timeseries revenue by month and region | ||
| SELECT | ||
| orders.created_month, | ||
| customers.region, | ||
| orders.total_revenue, | ||
| orders.order_count | ||
| FROM orders | ||
| ORDER BY created_month DESC, region""", | ||
| "Top Customers": """-- Top customers by revenue | ||
| SELECT | ||
| customers.name, | ||
| customers.region, | ||
| orders.total_revenue, | ||
| orders.order_count | ||
| FROM orders | ||
| ORDER BY orders.total_revenue DESC | ||
| LIMIT 10""", | ||
| "Aggregates": """-- Revenue metrics by region | ||
| SELECT | ||
| customers.region, | ||
| orders.total_revenue, | ||
| orders.avg_order_value, | ||
| orders.order_count | ||
| FROM orders | ||
| GROUP BY customers.region | ||
| ORDER BY orders.total_revenue DESC""", | ||
| "Custom": """-- Write your custom query here | ||
| SELECT | ||
|
|
||
| FROM """, | ||
| } |
This file contains hidden or 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 hidden or 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,54 @@ | ||
| """Tests for bundled workbench demo behavior.""" | ||
|
|
||
| import importlib.util | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from sidemantic import SemanticLayer, load_from_directory | ||
| from sidemantic.sql.query_rewriter import QueryRewriter | ||
| from sidemantic.workbench.examples import EXAMPLE_QUERIES | ||
|
|
||
|
|
||
| def _load_demo_data_module(): | ||
| demo_data_path = Path(__file__).resolve().parent.parent / "examples" / "multi_format_demo" / "demo_data.py" | ||
| spec = importlib.util.spec_from_file_location("demo_data", demo_data_path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| sys.modules["demo_data"] = module | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| def _load_demo_layer(): | ||
| demo_dir = Path(__file__).resolve().parent.parent / "examples" / "multi_format_demo" | ||
| demo_data = _load_demo_data_module() | ||
|
|
||
| layer = SemanticLayer(connection="duckdb:///:memory:") | ||
| demo_conn = demo_data.create_demo_database() | ||
|
|
||
| for table in ["customers", "products", "orders"]: | ||
| rows = demo_conn.execute(f"SELECT * FROM {table}").fetchall() | ||
| columns = [desc[0] for desc in demo_conn.execute(f"SELECT * FROM {table} LIMIT 0").description] | ||
| create_sql = demo_conn.execute(f"SELECT sql FROM duckdb_tables() WHERE table_name = '{table}'").fetchone()[0] | ||
| layer.adapter.execute(create_sql) | ||
|
|
||
| if rows: | ||
| placeholders = ", ".join(["?" for _ in columns]) | ||
| layer.adapter.executemany(f"INSERT INTO {table} VALUES ({placeholders})", rows) | ||
|
|
||
| load_from_directory(layer, str(demo_dir)) | ||
| return layer | ||
|
|
||
|
|
||
| def test_workbench_demo_starter_queries_execute(): | ||
| layer = _load_demo_layer() | ||
| rewriter = QueryRewriter(layer.graph, dialect=layer.dialect) | ||
|
|
||
| for name, sql in EXAMPLE_QUERIES.items(): | ||
| if name == "Custom": | ||
| continue | ||
|
|
||
| rendered_sql = rewriter.rewrite(sql) | ||
| result = layer.adapter.execute(rendered_sql) | ||
|
|
||
| assert result.description, name | ||
| assert result.fetchall(), name |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When users follow this new hint outside the dev environment,
sidemantic[workbench]installs Textual/plotting only; it does not installlkml(seepyproject.tomlworkbench vs lookml extras). The packaged demo includesexamples/multi_format_demo/lookml/orders.lkml, andload_from_directory()parses.lkmlfiles throughLookMLAdapter, which requireslkml; without it the orders model is skipped while the starter queries insidemantic/workbench/examples.pyall referenceorders.*. The demo therefore launches with the suggested command but the bundled queries fail, so the hint/README command should include the lookml extra as well, e.g.sidemantic[workbench,lookml].Useful? React with 👍 / 👎.