Skip to content

Commit 3bb3748

Browse files
author
Mars Wang
committed
support list query options for sql-like
1 parent 7576f98 commit 3bb3748

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ with VisierSession(auth) as s:
247247
You can write SQL-like queries to define both list and aggregate queries.
248248

249249
#### SQL-Like List Query
250-
In this example, we define a snippet to get the `EmployeeID`, `Union_Status`, `Direct_Manager.Gender`, `Direct_Manager.Vaccination_Status` where `isFemale` = `TRUE` and `isHighPerformer` = `TRUE` between January 1, 2020 and December 31, 2021.
250+
In this example, we define a snippet to get the `EmployeeID`, `Union_Status`, `Direct_Manager.Gender`, `Direct_Manager.Vaccination_Status` where `isFemale` = `TRUE` and `isHighPerformer` = `TRUE` between January 1, 2020 and December 31, 2021. In list SQL-like queries, you can use `list_query_options`, see [Visier documentation](https://docs.visier.com/developer/apis/references/api-reference.htm#tag/DataQuery/operation/DataQuery_SqlLike) for all available list options.
251251
```python
252252
with VisierSession(auth) as s:
253253
client = QueryApiClient(s)
@@ -261,7 +261,7 @@ with VisierSession(auth) as s:
261261
```
262262

263263
#### SQL-Like Aggregate Query
264-
In this example, we define a snippet to aggregate `employeeCount` by `Location_0`, `Gender`, `Union_Status`, and `Location_1` for 4 periods of 3 months each starting from April 1, 2020. In aggregate SQL-like queries, you can use `aggregateQueryOptions` to eliminate cells with zero and null values. This reduces the size of the overall result set to only include rows whose metric value is more than 0.
264+
In this example, we define a snippet to aggregate `employeeCount` by `Location_0`, `Gender`, `Union_Status`, and `Location_1` for 4 periods of 3 months each starting from April 1, 2020. In aggregate SQL-like queries, you can use `aggregate_query_options` to eliminate cells with zero and null values. This reduces the size of the overall result set to only include rows whose metric value is more than 0. See [Visier documentation](https://docs.visier.com/developer/apis/references/api-reference.htm#tag/DataQuery/operation/DataQuery_SqlLike) for all available aggregate options.
265265
```python
266266
with VisierSession(auth) as s:
267267
client = QueryApiClient(s)

‎visier/api/query.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ def snapshot(self, query_def: object):
3636
"""Execute a Visier snapshot query and return a tabular result."""
3737
return self._execute_query_api("/v1/data/query/snapshot", query_def)
3838

39-
def sqllike(self, sql_query: str, options = None):
39+
def sqllike(self, sql_query: str, aggregate_query_options = None, list_query_options = None):
4040
"""Execute a Visier SQL-like query statement and return a tabular result."""
4141
body = {"query" : sql_query}
42-
if options:
43-
body["aggregateQueryOptions"] = options
42+
if aggregate_query_options:
43+
body["aggregateQueryOptions"] = aggregate_query_options
44+
if list_query_options:
45+
body["listQueryOptions"] = list_query_options
4446
return self._execute_query_api("/v1/data/query/sql", body)
4547

4648
def _execute_query_api(self, path: str, body: object):

‎visier/connector/sessions.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ def execute_list(self, query_def: object):
116116
return self._execute_query_api("/v1/data/query/list", query_def)
117117

118118
@deprecated(version="0.9.5", reason="Use visier.api.QueryApiClient instead")
119-
def execute_sqllike(self, sql_query: str, options = None):
119+
def execute_sqllike(self, sql_query: str, aggregate_query_options = None, list_query_options = None):
120120
"""Execute a Visier SQL-like query statement and return a tabular result."""
121121
body = {"query" : sql_query}
122-
if options:
123-
body["aggregateQueryOptions"] = options
122+
if aggregate_query_options:
123+
body["aggregateQueryOptions"] = aggregate_query_options
124+
if list_query_options:
125+
body["listQueryOptions"] = list_query_options
124126
return self._execute_query_api("/v1/data/query/sql", body)
125127

126128
def execute(self, call_function: Callable[[SessionContext], Response]) -> Response:

0 commit comments

Comments
 (0)