Skip to content

Commit

Permalink
Fix unit tests, add a changelog fragment, make formatting consistent (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersson007 authored Jul 4, 2024
1 parent d84a69d commit 543a995
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- clickhouse_client - added the ``flatten_tested`` argument (https://github.com/ansible-collections/community.clickhouse/pull/63).
4 changes: 3 additions & 1 deletion plugins/doc_fragments/client_inst_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class ModuleDocFragment(object):
flatten_nested:
description:
- Sets the C(flatten_nested) setting on session before running the query.
- Sets the C(flatten_nested) setting on session before
running the query.
type: int
choices: [0, 1]
version_added: '0.5.0'
requirements: [ 'clickhouse-driver' ]
notes:
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/clickhouse_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,11 @@ def main():
# Substitute query params if needed for future return
substituted_query = get_substituted_query(module, client, query, execute_kwargs)

# Execute query
# If support of arbitrary levels of nesting is needed when executing the main query
if flatten_nested == 0:
execute_query(module, client, "SET flatten_nested = 0", execute_kwargs)

# Execute query
result = execute_query(module, client, query, execute_kwargs)

# Convert values not supported by ansible-core
Expand Down
13 changes: 7 additions & 6 deletions tests/integration/targets/clickhouse_client/tasks/initial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,22 @@
that:
- result.result == [["one"], ["two"], ["three"]]

- name: Load a Schema with Nested Fields
# https://github.com/ansible-collections/community.clickhouse/pull/63/
- name: Load a schema with nested fields
community.clickhouse.clickhouse_client:
flatten_nested: 0
execute: "CREATE TABLE foo.nested ( `coordinates` Nested(x int, y int )) ENGINE = Memory;"
execute: "CREATE TABLE foo.nested (`coordinates` Nested(x int, y int )) ENGINE = Memory"

- name: Load Nested Data
- name: Load nested data
community.clickhouse.clickhouse_client:
execute: 'insert into foo.nested (coordinates) VALUES (([(10,20), (11,21)]));'
execute: "INSERT INTO foo.nested (coordinates) VALUES (([(10,20), (11,21)]))"

- name: Read Nested data
- name: Read nested data
register: nested_result
community.clickhouse.clickhouse_client:
execute: 'select * from foo.nested;'

- name: Check Nested Data exists
- name: Check nested data exists
ansible.builtin.assert:
that:
- nested_result.result[0][0][0][0] == 10
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/plugins/module_utils/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def test_client_common_argument_spec():
'login_user': {'type': 'str', 'default': None},
'login_host': {'type': 'str', 'default': 'localhost'},
'login_password': {'type': 'str', 'default': None, 'no_log': True},
'client_kwargs': {'type': 'dict', 'default': {}}
'client_kwargs': {'type': 'dict', 'default': {}},
'flatten_nested': {'type': 'int', 'choices': [0, 1]},
}

assert client_common_argument_spec() == EXPECTED
Expand Down

0 comments on commit 543a995

Please sign in to comment.