From 3f9ffbb451bbdc2897cb0d72c414f195eafebb44 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 22 Oct 2023 12:25:09 +0530 Subject: [PATCH] Add functional tests for create_table_empty_primary_key_by_default 1. 02902_empty_order_by_throws_error - setting disabled and no order by or primary key - expect error - setting disabled and primary key in the table definition - no error and expect order by as primary key 2. 02903_empty_order_by_with_setting_enabled - setting enabled and no order by or primary key - expect the order by as empty - setting enabled and per-column primary key - expect the order by as column order - setting enabled and primary key in table definition (not per-column or order by) - expect order as primary key - setting enabled and order by in table definition (no primary key) - expect same order by --- ...2902_empty_order_by_throws_error.reference | 2 + .../02902_empty_order_by_throws_error.sh | 18 +++++++++ ...ty_order_by_with_setting_enabled.reference | 4 ++ ...903_empty_order_by_with_setting_enabled.sh | 37 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 tests/queries/0_stateless/02902_empty_order_by_throws_error.reference create mode 100755 tests/queries/0_stateless/02902_empty_order_by_throws_error.sh create mode 100644 tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.reference create mode 100755 tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.sh diff --git a/tests/queries/0_stateless/02902_empty_order_by_throws_error.reference b/tests/queries/0_stateless/02902_empty_order_by_throws_error.reference new file mode 100644 index 00000000000..2c94e483710 --- /dev/null +++ b/tests/queries/0_stateless/02902_empty_order_by_throws_error.reference @@ -0,0 +1,2 @@ +OK +OK diff --git a/tests/queries/0_stateless/02902_empty_order_by_throws_error.sh b/tests/queries/0_stateless/02902_empty_order_by_throws_error.sh new file mode 100755 index 00000000000..64f5dd1a987 --- /dev/null +++ b/tests/queries/0_stateless/02902_empty_order_by_throws_error.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh + +# setting disabled and no order by or primary key; expect error +$CLICKHOUSE_CLIENT -n --query=" + DROP TABLE IF EXISTS test_empty_order_by; + CREATE TABLE test_empty_order_by(a UInt8) ENGINE = MergeTree() SETTINGS index_granularity = 8192; +" 2>&1 \ | grep -F -q "You must provide an ORDER BY or PRIMARY KEY expression in the table definition." && echo 'OK' || echo 'FAIL' + +# setting disabled and primary key in table definition +$CLICKHOUSE_CLIENT -n --query=" + DROP TABLE IF EXISTS test_empty_order_by; + CREATE TABLE test_empty_order_by(a UInt8) ENGINE = MergeTree() PRIMARY KEY a SETTINGS index_granularity = 8192; + SHOW CREATE TABLE test_empty_order_by; +" 2>&1 \ | grep -F -q "ORDER BY a" && echo 'OK' || echo 'FAIL' diff --git a/tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.reference b/tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.reference new file mode 100644 index 00000000000..b462a5a7baa --- /dev/null +++ b/tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.reference @@ -0,0 +1,4 @@ +OK +OK +OK +OK diff --git a/tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.sh b/tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.sh new file mode 100755 index 00000000000..7ac9b488be5 --- /dev/null +++ b/tests/queries/0_stateless/02903_empty_order_by_with_setting_enabled.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh + +# setting enabled and no order by or primary key +${CLICKHOUSE_CLIENT} -n --query=" + SET create_table_empty_primary_key_by_default = true; + DROP TABLE IF EXISTS test_empty_order_by; + CREATE TABLE test_empty_order_by(a UInt8) ENGINE = MergeTree() SETTINGS index_granularity = 8192; + SHOW CREATE TABLE test_empty_order_by; +" 2>&1 \ | grep -F -q "ORDER BY tuple()" && echo 'OK' || echo 'FAIL' + +# setting enabled and per-column primary key +${CLICKHOUSE_CLIENT} -n --query=" + SET create_table_empty_primary_key_by_default = true; + DROP TABLE IF EXISTS test_empty_order_by; + CREATE TABLE test_empty_order_by(a UInt8 PRIMARY KEY, b String PRIMARY KEY) ENGINE = MergeTree() SETTINGS index_granularity = 8192; + SHOW CREATE TABLE test_empty_order_by; +" 2>&1 \ | grep -F -q "ORDER BY (a, b)" && echo 'OK' || echo 'FAIL' + +# setting enabled and primary key in table definition (not per-column or order by) +${CLICKHOUSE_CLIENT} -n --query=" + SET create_table_empty_primary_key_by_default = true; + DROP TABLE IF EXISTS test_empty_order_by; + CREATE TABLE test_empty_order_by(a UInt8, b String) ENGINE = MergeTree() PRIMARY KEY (a) SETTINGS index_granularity = 8192; + SHOW CREATE TABLE test_empty_order_by; +" 2>&1 \ | grep -F -q "ORDER BY a" && echo 'OK' || echo 'FAIL' + +# setting enabled and order by in table definition (no primary key) +${CLICKHOUSE_CLIENT} -n --query=" + SET create_table_empty_primary_key_by_default = true; + DROP TABLE IF EXISTS test_empty_order_by; + CREATE TABLE test_empty_order_by(a UInt8, b String) ENGINE = MergeTree() ORDER BY (a, b) SETTINGS index_granularity = 8192; + SHOW CREATE TABLE test_empty_order_by; +" 2>&1 \ | grep -F -q "ORDER BY (a, b)" && echo 'OK' || echo 'FAIL'