From 373fca6a746b3ff13463f377854be5f14eca991d Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Thu, 15 Feb 2024 12:37:55 +0100 Subject: [PATCH] clickhouse_client: add testing for querying more data types --- .../clickhouse_client/tasks/data_types.yml | 76 +++++++++++++++++++ .../clickhouse_client/tasks/initial.yml | 68 ----------------- .../targets/clickhouse_client/tasks/main.yml | 3 + 3 files changed, 79 insertions(+), 68 deletions(-) create mode 100644 tests/integration/targets/clickhouse_client/tasks/data_types.yml diff --git a/tests/integration/targets/clickhouse_client/tasks/data_types.yml b/tests/integration/targets/clickhouse_client/tasks/data_types.yml new file mode 100644 index 0000000..a17f20d --- /dev/null +++ b/tests/integration/targets/clickhouse_client/tasks/data_types.yml @@ -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]]] diff --git a/tests/integration/targets/clickhouse_client/tasks/initial.yml b/tests/integration/targets/clickhouse_client/tasks/initial.yml index 0861f52..aee4110 100644 --- a/tests/integration/targets/clickhouse_client/tasks/initial.yml +++ b/tests/integration/targets/clickhouse_client/tasks/initial.yml @@ -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"]] diff --git a/tests/integration/targets/clickhouse_client/tasks/main.yml b/tests/integration/targets/clickhouse_client/tasks/main.yml index d319da8..b1b8b9b 100644 --- a/tests/integration/targets/clickhouse_client/tasks/main.yml +++ b/tests/integration/targets/clickhouse_client/tasks/main.yml @@ -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