From 53f78a8039c6e3161e5ef6ae6035157f8e95a7e2 Mon Sep 17 00:00:00 2001 From: cching95 <73163191+cching95@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:58:46 +0100 Subject: [PATCH] add to_json back into sql query (#821) Signed-off-by: Chloe Ching --- .../queries/time_series/_time_series_query_builder.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sdk/python/rtdip_sdk/queries/time_series/_time_series_query_builder.py b/src/sdk/python/rtdip_sdk/queries/time_series/_time_series_query_builder.py index 0063a1c22..dad49a2c4 100644 --- a/src/sdk/python/rtdip_sdk/queries/time_series/_time_series_query_builder.py +++ b/src/sdk/python/rtdip_sdk/queries/time_series/_time_series_query_builder.py @@ -101,19 +101,26 @@ def _raw_query(parameters_dict: dict) -> str: def _sql_query(parameters_dict: dict) -> str: sql_query = ( - "{{ sql_statement }}" + "{% if to_json is defined and to_json == true %}" + 'SELECT to_json(struct(*), map("timestampFormat", "yyyy-MM-dd\'T\'HH:mm:ss.SSSSSSSSSXXX")) as Value FROM (' + "{% endif %}" + "{{ sql_statement }} " "{% if limit is defined and limit is not none %}" "LIMIT {{ limit }} " "{% endif %}" "{% if offset is defined and offset is not none %}" "OFFSET {{ offset }} " "{% endif %}" + "{% if to_json is defined and to_json == true %}" + ")" + "{% endif %}" ) sql_parameters = { "sql_statement": parameters_dict.get("sql_statement"), "limit": parameters_dict.get("limit", None), "offset": parameters_dict.get("offset", None), + "to_json": parameters_dict.get("to_json", False), } sql_template = Template(sql_query)