diff --git a/.changes/unreleased/Fixes-20250721-115455.yaml b/.changes/unreleased/Fixes-20250721-115455.yaml new file mode 100644 index 0000000..6a5b752 --- /dev/null +++ b/.changes/unreleased/Fixes-20250721-115455.yaml @@ -0,0 +1,3 @@ +kind: Fixes +body: Remove unneeded subquery, which creates invalid SQL for some dialects. +time: 2025-07-21T11:54:55.027236-07:00 diff --git a/.gitignore b/.gitignore index e2b72f5..c561d95 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ dist/ .ruff_cache .pytest_cache +venv/ +uv.lock # ignore gql schema files **/*.gql diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed031ea..23d8de7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ If you want to contribute by submitting code, this section will explain how to s ### Setting up your environment 1. We use [hatch](https://hatch.pypa.io/) as the dependency and environment manager. Make sure you install it via one of the methods described [here](https://hatch.pypa.io/latest/install/). -2. We use [lefthook](https://github.com/evilmartians/lefthook/) for Git hooks management. The first time you clone the repo, run `lefthook install` to setup the git hooks. +2. We use [lefthook](https://github.com/evilmartians/lefthook/) for Git hooks management. The first time you clone the repo, run `pip install lefthook && lefthook install` to setup the git hooks. Hatch will manage your environments for you. Check out the list of available environments in [`pyproject.toml`](./pyproject.toml). Here follows a brief explanation of what they are for: - `default`: run only basic scripts, no dependencies installed diff --git a/dbtsl/api/adbc/protocol.py b/dbtsl/api/adbc/protocol.py index cb26b5a..228b21e 100644 --- a/dbtsl/api/adbc/protocol.py +++ b/dbtsl/api/adbc/protocol.py @@ -83,10 +83,10 @@ def get_query_sql(cls, params: QueryParameters) -> str: strict_params_dict = {field: getattr(strict_params, field) for field in params_fields} serialized_params = cls._serialize_params_dict(strict_params_dict, params_fields) - return f"SELECT * FROM {{{{ semantic_layer.query({serialized_params}) }}}}" + return f"{{{{ semantic_layer.query({serialized_params}) }}}}" @classmethod def get_dimension_values_sql(cls, params: DimensionValuesQueryParameters) -> str: """Get the SQL that will be sent via Arrow Flight to the server based on dimension values query parameters.""" serialized_params = cls._serialize_params_dict(params, list(DimensionValuesQueryParameters.__optional_keys__)) - return f"SELECT * FROM {{{{ semantic_layer.dimension_values({serialized_params}) }}}}" + return f"{{{{ semantic_layer.dimension_values({serialized_params}) }}}}" diff --git a/tests/api/adbc/test_protocol.py b/tests/api/adbc/test_protocol.py index 83e349a..4427e83 100644 --- a/tests/api/adbc/test_protocol.py +++ b/tests/api/adbc/test_protocol.py @@ -82,10 +82,7 @@ def test_serialize_query_params_complete_query() -> None: def test_get_query_sql_simple_query() -> None: sql = ADBCProtocol.get_query_sql(params={"metrics": ["a", "b"], "order_by": ["-a"]}) - expected = ( - 'SELECT * FROM {{ semantic_layer.query(metrics=["a","b"],' - 'order_by=[Metric("a").descending(True)],read_cache=True) }}' - ) + expected = '{{ semantic_layer.query(metrics=["a","b"],order_by=[Metric("a").descending(True)],read_cache=True) }}' assert sql == expected @@ -100,7 +97,7 @@ def test_get_query_sql_group_by_param() -> None: } ) expected = ( - "SELECT * FROM {{ semantic_layer.query(" + "{{ semantic_layer.query(" 'group_by=[Dimension("c").grain("day"),Entity("d").grain("week")],metrics=["a","b"],read_cache=True) }}' ) assert sql == expected @@ -108,5 +105,5 @@ def test_get_query_sql_group_by_param() -> None: def test_get_query_sql_dimension_values_query() -> None: sql = ADBCProtocol.get_dimension_values_sql(params={"metrics": ["a", "b"]}) - expected = 'SELECT * FROM {{ semantic_layer.dimension_values(metrics=["a","b"]) }}' + expected = '{{ semantic_layer.dimension_values(metrics=["a","b"]) }}' assert sql == expected