diff --git a/.changes/unreleased/Features-20240709-121955.yaml b/.changes/unreleased/Features-20240709-121955.yaml new file mode 100644 index 0000000..e2269e7 --- /dev/null +++ b/.changes/unreleased/Features-20240709-121955.yaml @@ -0,0 +1,3 @@ +kind: Features +body: Full support for all query parameters +time: 2024-07-09T12:19:55.649315+02:00 diff --git a/dbtsl/api/adbc/protocol.py b/dbtsl/api/adbc/protocol.py index 0077aab..5a08209 100644 --- a/dbtsl/api/adbc/protocol.py +++ b/dbtsl/api/adbc/protocol.py @@ -13,7 +13,11 @@ def _serialize_query_params(params: QueryParameters) -> str: def append_param_if_exists(p_str: str, p_name: str) -> str: p_value = params.get(p_name) if p_value is not None: - p_str += f"{p_name}={json.dumps(p_value)}," + if isinstance(p_value, bool): + dumped = str(p_value) + else: + dumped = json.dumps(p_value) + p_str += f"{p_name}={dumped}," return p_str serialized_params = append_param_if_exists(serialized_params, "metrics") @@ -21,6 +25,7 @@ def append_param_if_exists(p_str: str, p_name: str) -> str: serialized_params = append_param_if_exists(serialized_params, "limit") serialized_params = append_param_if_exists(serialized_params, "order_by") serialized_params = append_param_if_exists(serialized_params, "where") + serialized_params = append_param_if_exists(serialized_params, "read_cache") serialized_params = serialized_params.strip(",") diff --git a/dbtsl/api/graphql/protocol.py b/dbtsl/api/graphql/protocol.py index 08c665b..2a56408 100644 --- a/dbtsl/api/graphql/protocol.py +++ b/dbtsl/api/graphql/protocol.py @@ -200,11 +200,21 @@ def get_request_text(self) -> str: query = """ mutation createQuery( $environmentId: BigInt!, - $metrics: [MetricInput!]! + $metrics: [MetricInput!]!, + $groupBy: [GroupByInput!]!, + $where: [WhereInput!]!, + $orderBy: [OrderByInput!]!, + $limit: Int, + $readCache: Boolean, ) { createQuery( environmentId: $environmentId, - metrics: $metrics + metrics: $metrics, + groupBy: $groupBy, + where: $where, + orderBy: $orderBy, + limit: $limit, + readCache: $readCache, ) { queryId } @@ -221,6 +231,7 @@ def get_request_variables(self, environment_id: int, **kwargs: QueryParameters) "where": [{"sql": sql} for sql in kwargs.get("where", [])], "orderBy": [{"name": o} for o in kwargs.get("order_by", [])], "limit": kwargs.get("limit", None), + "readCache": kwargs.get("read_cache", True), } @override diff --git a/dbtsl/api/shared/query_params.py b/dbtsl/api/shared/query_params.py index 5b38bed..eada181 100644 --- a/dbtsl/api/shared/query_params.py +++ b/dbtsl/api/shared/query_params.py @@ -18,3 +18,4 @@ class QueryParameters(TypedDict): limit: NotRequired[int] order_by: NotRequired[List[str]] where: NotRequired[List[str]] + read_cache: NotRequired[bool] diff --git a/tests/api/adbc/test_protocol.py b/tests/api/adbc/test_protocol.py index a282a85..1789243 100644 --- a/tests/api/adbc/test_protocol.py +++ b/tests/api/adbc/test_protocol.py @@ -16,12 +16,14 @@ def test_serialize_query_params_complete_query() -> None: "limit": 1, "order_by": ["dim_c"], "where": ['{{ Dimension("metric_time").grain("month") }} >= \'2017-03-09\''], + "read_cache": False, } ) expected = ( 'metrics=["a", "b"],group_by=["dim_c"],limit=1,order_by=["dim_c"],' - 'where=["{{ Dimension(\\"metric_time\\").grain(\\"month\\") }} >= \'2017-03-09\'"]' + 'where=["{{ Dimension(\\"metric_time\\").grain(\\"month\\") }} >= \'2017-03-09\'"],' + "read_cache=False" ) assert params == expected