Skip to content

Commit

Permalink
syntax error & other fixes (#69)
Browse files Browse the repository at this point in the history
* syntax error

* syntax error

* text instead of json

* commit

* rollback

Co-authored-by: ncgl-syngenta <[email protected]>
  • Loading branch information
ncgl-syngenta and ncgl-syngenta authored Sep 7, 2021
1 parent 26b7aff commit 62c45fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion syngenta_digital_dta/postgres/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def bulk_insert_json(
function_map=function_map or {}
)

self.__execute(query=statement, params={})
self.__execute(query=statement, params={}, commit=True, rollback=True)

def create_index(self, table_name, index_columns):
index_name = f"index_{'_'.join(index_columns)}"
Expand Down
4 changes: 2 additions & 2 deletions syngenta_digital_dta/postgres/json_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def insert_json_into_table(
f"""{_build_json_cte(json)}
{_build_insert_statement(table_name, column_map, json_column_map)}
{_build_select_statement(column_map, json_column_map, function_map or {})}
FROM ({_build_json_array_subquery(target_key)}
FROM ({_build_json_array_subquery(target_key)})x
"""
)

Expand Down Expand Up @@ -63,7 +63,7 @@ def _parse_json_line(k, v):
parts = v.split('.')

if len(parts) == 2:
statement = f"_jsondict -> '{parts[1]}' AS {k}"
statement = f"_jsondict ->> '{parts[1]}' AS {k}"

elif len(parts) == 3:
statement = f"_jsondict -> '{parts[1]}' ->> '{parts[2]}' AS {k}"
Expand Down
4 changes: 2 additions & 2 deletions tests/syngenta_digital_dta/postgres/test_json_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_insert_json_into_table(self):
expected = """WITH _json_cte AS (SELECT '{}'::json AS _json)
INSERT INTO my_table (guuid, created_at, updated_at, time, machine, secID)
SELECT generate_uuid_v4() AS guuid, now() AS created_at, now() AS updated_at, _jsondict -> 'properties' ->> 'Time' AS time, _jsondict -> 'properties' ->> 'Machine' AS machine, _jsondict -> 'properties' ->> 'SecID' AS secID
FROM (SELECT json_array_elements(_json->'feature') AS _jsondict FROM _json_cte
FROM (SELECT json_array_elements(_json->'feature') AS _jsondict FROM _json_cte)x
"""

self.assertEqual(expected, actual)
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_insert_json_into_table_function_map(self):
expected = """WITH _json_cte AS (SELECT '{}'::json AS _json)
INSERT INTO my_table (guuid, created_at, updated_at, time, machine, secID)
SELECT generate_uuid_v4() AS guuid, now() AS created_at, now() AS updated_at, _jsondict -> 'properties' ->> 'Time' AS time, _jsondict -> 'properties' ->> 'Machine' AS machine, cast(_jsondict -> 'properties' ->> 'SecID' as varchar) as secID
FROM (SELECT json_array_elements(_json->'feature') AS _jsondict FROM _json_cte
FROM (SELECT json_array_elements(_json->'feature') AS _jsondict FROM _json_cte)x
"""

self.assertEqual(expected, actual)

0 comments on commit 62c45fb

Please sign in to comment.