Skip to content

Commit

Permalink
clickhouse_client: add testing for querying more data types
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersson007 committed Feb 15, 2024
1 parent 71d49e2 commit 373fca6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 68 deletions.
76 changes: 76 additions & 0 deletions tests/integration/targets/clickhouse_client/tasks/data_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
- name: The system.users table contain UUID value
register: result
community.clickhouse.clickhouse_client:
execute: SELECT id FROM system.users LIMIT 1

- name: Check the result
ansible.builtin.assert:
that:
- result.result[0] != []


- name: Create table with Decimal and DateTime columns
community.clickhouse.clickhouse_client:
execute: CREATE TABLE decimal_datetime (x Decimal(12,4), y DateTime) ENGINE = Memory

- name: Insert Decimal and DateTime
community.clickhouse.clickhouse_client:
execute: "INSERT INTO decimal_datetime VALUES ('4.01', '2019-01-01 00:00:00')"

- name: Select Decimal and DateTime
register: result
community.clickhouse.clickhouse_client:
execute: "SELECT * FROM decimal_datetime"

- name: Check the ret vals
ansible.builtin.assert:
that:
- result.result == [[4.01, '2019-01-01T00:00:00']]


- name: Create table with Map column
community.clickhouse.clickhouse_client:
execute: CREATE TABLE map (x Map(String, UInt64)) ENGINE = Memory

- name: Insert Map
community.clickhouse.clickhouse_client:
execute: "INSERT INTO map VALUES ({'a': 1, 'b': 2})"

- name: Select Map
register: result
community.clickhouse.clickhouse_client:
execute: "SELECT * FROM map"

- name: Check the ret vals
ansible.builtin.assert:
that:
- result.result[0][0]['a'] == 1

# Test version dependent features
- name: Get server version
register: srv
community.clickhouse.clickhouse_info:
limit: version


- name: Test Point column
when: srv['version']['year'] >= 23
block:

- name: Create table with Point column
community.clickhouse.clickhouse_client:
execute: CREATE TABLE geo_point (p Point) ENGINE = Memory

- name: Insert Point
community.clickhouse.clickhouse_client:
execute: "INSERT INTO geo_point VALUES ((10, 10))"

- name: Select Point
register: result
community.clickhouse.clickhouse_client:
execute: "SELECT * FROM geo_point"

- name: Check the ret vals
ansible.builtin.assert:
that:
- result.result == [[[10, 10]]]
68 changes: 0 additions & 68 deletions tests/integration/targets/clickhouse_client/tasks/initial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,71 +71,3 @@
ansible.builtin.assert:
that:
- result.result == [["one"], ["two"], ["three"]]


- name: The system.users table contain UUID value
register: result
community.clickhouse.clickhouse_client:
execute: SELECT id FROM system.users LIMIT 1

- name: Check the result
ansible.builtin.assert:
that:
- result.result[0] != []


- name: Create table with Decimal and DateTime columns
community.clickhouse.clickhouse_client:
execute: CREATE TABLE decimal_datetime (x Decimal(12,4), y DateTime) ENGINE = Memory

- name: Insert Decimal and DateTime
community.clickhouse.clickhouse_client:
execute: "INSERT INTO decimal_datetime VALUES ('4.01', '2019-01-01 00:00:00')"

- name: Select Decimal and DateTime
register: result
community.clickhouse.clickhouse_client:
execute: "SELECT * FROM decimal_datetime"

- name: Check the ret vals
ansible.builtin.assert:
that:
- result.result == [[4.01, '2019-01-01T00:00:00']]


- name: Create table with Map column
community.clickhouse.clickhouse_client:
execute: CREATE TABLE map (x Map(String, UInt64)) ENGINE = Memory

- name: Insert Map
community.clickhouse.clickhouse_client:
execute: "INSERT INTO map VALUES ({'a': 1, 'b': 2})"

- name: Select Map
register: result
community.clickhouse.clickhouse_client:
execute: "SELECT * FROM map"

- name: Check the ret vals
ansible.builtin.assert:
that:
- result.result[0][0]['a'] == 1


- name: Create table with IPv4 and IPv6 columns
community.clickhouse.clickhouse_client:
execute: CREATE TABLE ip (v4 IPv4, v6 IPv6) ENGINE = Memory

- name: Insert IPv4 and IPv6
community.clickhouse.clickhouse_client:
execute: "INSERT INTO ip VALUES ('192.168.0.1', '001:44c8:129:2632:33:0:252:2')"

- name: Select IPv4 and IPv6
register: result
community.clickhouse.clickhouse_client:
execute: "SELECT * FROM ip"

- name: Check the ret vals
ansible.builtin.assert:
that:
- result.result == [["192.168.0.1", "1:44c8:129:2632:33:0:252:2"]]
3 changes: 3 additions & 0 deletions tests/integration/targets/clickhouse_client/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

# Initial CI tests of clickhouse_client module
- import_tasks: initial.yml

# File to test querying tables storing different data types
- import_tasks: data_types.yml

0 comments on commit 373fca6

Please sign in to comment.