Skip to content

Commit

Permalink
add to_json back into sql query (#821)
Browse files Browse the repository at this point in the history
Signed-off-by: Chloe Ching <[email protected]>
  • Loading branch information
cching95 authored Sep 2, 2024
1 parent 79838dc commit 53f78a8
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 53f78a8

Please sign in to comment.