diff --git a/.github/actions/test_sqllogic_standalone/action.yml b/.github/actions/test_sqllogic_standalone/action.yml index c653bde8ba5a..79907e722052 100644 --- a/.github/actions/test_sqllogic_standalone/action.yml +++ b/.github/actions/test_sqllogic_standalone/action.yml @@ -31,7 +31,7 @@ runs: - name: Install python dependences shell: bash run: | - pip3 install --user boto3 "moto[all]" yapf shfmt-py mysql-connector pymysql six PyHamcrest requests + pip3 install --user boto3 "moto[all]" yapf shfmt-py mysql-connector pymysql six PyHamcrest requests environs - name: Run sqllogic Tests with Standalone mode, with embedded meta-store shell: bash diff --git a/tests/logictest/Dockerfile b/tests/logictest/Dockerfile index b1f279198d4e..07b8622a40d2 100644 --- a/tests/logictest/Dockerfile +++ b/tests/logictest/Dockerfile @@ -1,6 +1,6 @@ From python:3.10.4-alpine3.15 -RUN /usr/local/bin/python -m pip install --upgrade pip && pip install --user mysql-connector six PyHamcrest requests +RUN /usr/local/bin/python -m pip install --upgrade pip && pip install --user mysql-connector six PyHamcrest requests environs COPY *.py / COPY suites/* /suites/ WORKDIR / diff --git a/tests/logictest/README.md b/tests/logictest/README.md index 03227d82cebc..6cd93686a7cc 100644 --- a/tests/logictest/README.md +++ b/tests/logictest/README.md @@ -1,7 +1,7 @@ # Targets -The database return right with diffrent handlers, for example mysql and http +The database return right with different handlers, for example mysql and http # Usage @@ -9,8 +9,9 @@ The database return right with diffrent handlers, for example mysql and http 1. Change to the scripts dir, cd tests/logictest/ 2. Make sure python3 is installed 3. Using [Poetry](https://github.com/python-poetry/poetry) to install dependency, dependency see tests/pyproject.toml +4. (Optional)If use pip, you can find dependency in Dockerfile -## Need to Known +## Need to known 1. Cases from **tests/suites/0_stateless/** to **tests/logictest/suites/gen/** 2. If a case file already exists in gen/, gen_suites will ignore it. 3. Regenerateļ¼šdelete case file in gen/ and run gen_suites.py @@ -21,6 +22,27 @@ The database return right with diffrent handlers, for example mysql and http ## Run logic test 1. python3 main.py +## Docker + +### Build image + +docker build -t sqllogic/test:latest . + +### Run with docker + +1. Image release: public.ecr.aws/k3y0u5f2/sqllogic/test:latest +2. Set envs +- DISABLE_MYSQL_LOGIC_TEST (if anything set, will skip mysql handler) +- DISABLE_HTTP_LOGIC_TEST (if anything set, will skip http handler) +- QUERY_MYSQL_HANDLER_HOST +- QUERY_MYSQL_HANDLER_PORT +- QUERY_HTTP_HANDLER_HOST +- QUERY_HTTP_HANDLER_PORT +- MYSQL_DATABASE +- MYSQL_USER +- ADDITIONAL_HEADERS (for security scenario) +3. docker run --name logictest --rm --network host public.ecr.aws/k3y0u5f2/sqllogic/test:latest + # Learn More -See pr: https://github.com/datafuselabs/databend/pull/5048 +Ref pr: https://github.com/datafuselabs/databend/pull/5048 diff --git a/tests/logictest/http_connector.py b/tests/logictest/http_connector.py index 6c861c503a49..6dfd6c8d2f3a 100644 --- a/tests/logictest/http_connector.py +++ b/tests/logictest/http_connector.py @@ -1,4 +1,5 @@ import json +import os import environs import requests @@ -97,8 +98,10 @@ def connect(self, host, port, user="root", database=default_database): self._database = database self._session_max_idle_time = 300 self._session = None + self._additonal_headers = dict() e = environs.Env() - self._additonal_headers = e.dict("ADDITIONAL_HEADERS") + if os.getenv("ADDITIONAL_HEADERS") is not None: + self._additonal_headers = e.dict("ADDITIONAL_HEADERS") def query(self, statement, session=None): url = "http://{}:{}/v1/query/".format(self._host, self._port) diff --git a/tests/logictest/logictest.py b/tests/logictest/logictest.py index 00e8a6639ccc..71fe971bc5ea 100644 --- a/tests/logictest/logictest.py +++ b/tests/logictest/logictest.py @@ -293,7 +293,11 @@ def assert_query_equal(self, f, resultset, statement): def assert_execute_query(self, statement): actual = safe_execute(lambda: self.execute_query(statement), statement) - f = format_value(actual, len(statement.s_type.query_type)) + try: + f = format_value(actual, len(statement.s_type.query_type)) + except Exception: + log.warning("{} statement type is query but return nothing".format(statement)) + raise assert statement.results is not None and len( statement.results) > 0, "No result found {}".format(statement) hasResult = False diff --git a/tests/logictest/suites/gen/02_function/02_0048_function_semi_structureds_object_keys b/tests/logictest/suites/gen/02_function/02_0048_function_semi_structureds_object_keys new file mode 100644 index 000000000000..7ac9ccb9d4bc --- /dev/null +++ b/tests/logictest/suites/gen/02_function/02_0048_function_semi_structureds_object_keys @@ -0,0 +1,19 @@ +statement ok +CREATE TABLE IF NOT EXISTS objects_test1(id TINYINT, obj OBJECT, var VARIANT) Engine=Memory; + +statement ok +insert into objects_test1 values (1, parse_json('{"a": 1, "b": [1,2,3]}'), parse_json('{"1": 2}')); + +-- TODO: Bug here, http handler return state running +-- statement ok +-- select id, object_keys(obj), object_keys(var) from objects_test1; + +statement ok +drop table objects_test1; + +statement error 1010 +select object_keys(parse_json('[1,2,3]')); + +statement error 1010 +select object_keys(1); + diff --git a/tests/logictest/suites/gen/03_dml/03_0023_insert_into_array b/tests/logictest/suites/gen/03_dml/03_0023_insert_into_array new file mode 100644 index 000000000000..29ebfe272a10 --- /dev/null +++ b/tests/logictest/suites/gen/03_dml/03_0023_insert_into_array @@ -0,0 +1,306 @@ +statement ok +DROP DATABASE IF EXISTS db1; + +statement ok +CREATE DATABASE db1; + +statement ok +USE db1; + +statement query T +select '==Array(UInt8)=='; + +---- +==Array(UInt8)== + +statement ok +CREATE TABLE IF NOT EXISTS t1(id Int, arr Array(UInt8)) Engine = Memory; + +statement ok +INSERT INTO t1 (id, arr) VALUES(1, [1,2,3]), (2, [254,255]); + +statement ok +select * from t1; + +statement ok +select arr[0], arr[1] from t1; + +statement query T +select '==Array(UInt16)=='; + +---- +==Array(UInt16)== + +statement ok +CREATE TABLE IF NOT EXISTS t2(id Int, arr Array(UInt16)) Engine = Memory; + +statement ok +INSERT INTO t2 (id, arr) VALUES(1, [1,2,3]), (2, [65534,65535]); + +statement ok +select * from t2; + +statement ok +select arr[0], arr[1] from t2; + +statement query T +select '==Array(UInt32)=='; + +---- +==Array(UInt32)== + +statement ok +CREATE TABLE IF NOT EXISTS t3(id Int, arr Array(UInt32)) Engine = Memory; + +statement ok +INSERT INTO t3 (id, arr) VALUES(1, [1,2,3]), (2, [4294967294,4294967295]); + +statement ok +select * from t3; + +statement ok +select arr[0], arr[1] from t3; + +statement query T +select '==Array(UInt64)=='; + +---- +==Array(UInt64)== + +statement ok +CREATE TABLE IF NOT EXISTS t4(id Int, arr Array(UInt64)) Engine = Memory; + +statement ok +INSERT INTO t4 (id, arr) VALUES(1, [1,2,3]), (2, [18446744073709551614,18446744073709551615]); + +statement ok +select * from t4; + +statement ok +select arr[0], arr[1] from t4; + +statement query T +select '==Array(Int8)=='; + +---- +==Array(Int8)== + +statement ok +CREATE TABLE IF NOT EXISTS t5(id Int, arr Array(Int8)) Engine = Memory; + +statement ok +INSERT INTO t5 (id, arr) VALUES(1, [1,2,3]), (2, [-128,127]); + +statement ok +select * from t5; + +statement ok +select arr[0], arr[1] from t5; + +statement query T +select '==Array(Int16)=='; + +---- +==Array(Int16)== + +statement ok +CREATE TABLE IF NOT EXISTS t6(id Int, arr Array(Int16)) Engine = Memory; + +statement ok +INSERT INTO t6 (id, arr) VALUES(1, [1,2,3]), (2, [-32768,32767]); + +statement ok +select * from t6; + +statement ok +select arr[0], arr[1] from t6; + +statement query T +select '==Array(Int32)=='; + +---- +==Array(Int32)== + +statement ok +CREATE TABLE IF NOT EXISTS t7(id Int, arr Array(Int32)) Engine = Memory; + +statement ok +INSERT INTO t7 (id, arr) VALUES(1, [1,2,3]), (2, [-2147483648,2147483647]); + +statement ok +select * from t7; + +statement ok +select arr[0], arr[1] from t7; + +statement query T +select '==Array(Int64)=='; + +---- +==Array(Int64)== + +statement ok +CREATE TABLE IF NOT EXISTS t8(id Int, arr Array(Int64)) Engine = Memory; + +statement ok +INSERT INTO t8 (id, arr) VALUES(1, [1,2,3]), (2, [-9223372036854775808,9223372036854775807]); + +statement ok +select * from t8; + +statement ok +select arr[0], arr[1] from t8; + +statement query T +select '==Array(Float32)=='; + +---- +==Array(Float32)== + +statement ok +CREATE TABLE IF NOT EXISTS t9(id Int, arr Array(Float32)) Engine = Memory; + +statement ok +INSERT INTO t9 (id, arr) VALUES(1, [1.1,1.2,1.3]), (2, [-1.1,-1.2,-1.3]); + +statement ok +select * from t9; + +statement ok +select arr[0], arr[1] from t9; + +statement query T +select '==Array(Float64)=='; + +---- +==Array(Float64)== + +statement ok +CREATE TABLE IF NOT EXISTS t10(id Int, arr Array(Float64)) Engine = Memory; + +statement ok +INSERT INTO t10 (id, arr) VALUES(1, [1.1,1.2,1.3]), (2, [-1.1,-1.2,-1.3]); + +statement ok +select * from t10; + +statement ok +select arr[0], arr[1] from t10; + +statement query T +select '==Array(Boolean)=='; + +---- +==Array(Boolean)== + +statement ok +CREATE TABLE IF NOT EXISTS t11(id Int, arr Array(Bool)) Engine = Memory; + +statement ok +INSERT INTO t11 (id, arr) VALUES(1, [true, true]), (2, [false, false]), (3, [true, false]), (4, [false, true]); + +statement ok +select * from t11; + +statement ok +select arr[0], arr[1] from t11; + +statement query T +select '==Array(Date)=='; + +---- +==Array(Date)== + +statement ok +CREATE TABLE IF NOT EXISTS t12(id Int, arr Array(Date)) Engine = Memory; + +statement ok +INSERT INTO t12 (id, arr) VALUES(1, ['2021-01-01', '2022-01-01']), (2, ['1990-12-01', '2030-01-12']); + +statement error 1010 +INSERT INTO t12 (id, arr) VALUES(3, ['1000000-01-01', '2000000-01-01']); + +statement ok +select * from t12; + +statement ok +select arr[0], arr[1] from t12; + +statement query T +select '==Array(Timestamp)=='; + +---- +==Array(Timestamp)== + +statement ok +CREATE TABLE IF NOT EXISTS t13(id Int, arr Array(Timestamp)) Engine = Memory; + +statement ok +INSERT INTO t13 (id, arr) VALUES(1, ['2021-01-01 01:01:01', '2022-01-01 01:01:01']), (2, ['1990-12-01 10:11:12', '2030-01-12 22:00:00']); + +statement error 1010 +INSERT INTO t13 (id, arr) VALUES(3, ['1000000-01-01 01:01:01', '2000000-01-01 01:01:01']); + +statement ok +select * from t13; + +statement ok +select arr[0], arr[1] from t13; + +statement query T +select '==Array(String)=='; + +---- +==Array(String)== + +statement ok +CREATE TABLE IF NOT EXISTS t14(id Int, arr Array(String)) Engine = Memory; + +statement ok +INSERT INTO t14 (id, arr) VALUES(1, ['aa', 'bb']), (2, ['cc', 'dd']); + +statement ok +select * from t14; + +statement ok +select arr[0], arr[1] from t14; + +statement query T +select '==Array(String) Nullable=='; + +---- +==Array(String) Nullable== + +statement ok +CREATE TABLE IF NOT EXISTS t15(id Int, arr Array(String) Null) Engine = Memory; + +statement ok +INSERT INTO t15 (id, arr) VALUES(1, ['aa', 'bb']), (2, ['cc', 'dd']), (3, null), (4, ['ee', 'ff']); + +statement ok +select * from t15; + +statement ok +select arr[0], arr[1] from t15; + +statement query T +select '==Array(Int64) Nullable=='; + +---- +==Array(Int64) Nullable== + +statement ok +CREATE TABLE IF NOT EXISTS t16(id Int, arr Array(Int64) Null) Engine = fuse; + +statement ok +INSERT INTO t16 (id, arr) VALUES(1, [1,2,3,4]), (2, [5,6,7,8]), (3, null); + +statement ok +select * from t16; + +statement ok +select arr[0], arr[1] from t16; + +statement ok +DROP DATABASE db1; + diff --git a/tests/logictest/suites/gen/06_show/06_0008_show_table_status b/tests/logictest/suites/gen/06_show/06_0008_show_table_status index e56f25b81742..3271e2bc6210 100644 --- a/tests/logictest/suites/gen/06_show/06_0008_show_table_status +++ b/tests/logictest/suites/gen/06_show/06_0008_show_table_status @@ -75,7 +75,7 @@ statement query TTITITITTTTTTTTTT SHOW TABLE STATUS FROM showtabstat WHERE Name = 't4'; ---- -t4 FUSE 0 None None None None None None None None 1970-01-01 00:00:00.000 +0000 None None None None +t4 FUSE 0 None 0 None 0 None None None None 1970-01-01 00:00:00.000 +0000 None None None None statement ok insert into showtabstat.t4 values(1); diff --git a/tests/logictest/suites/gen/09_fuse_engine/09_0000_remote_create_table b/tests/logictest/suites/gen/09_fuse_engine/09_0000_remote_create_table index 5cec566d17ab..6b02420ccb25 100644 --- a/tests/logictest/suites/gen/09_fuse_engine/09_0000_remote_create_table +++ b/tests/logictest/suites/gen/09_fuse_engine/09_0000_remote_create_table @@ -14,7 +14,7 @@ statement query TTTTIIII SELECT * FROM system.tables WHERE database='db1'; ---- -db1 t1 fuse 1970-01-01 00:00:00.000 +0000 None None None None +db1 t1 fuse 1970-01-01 00:00:00.000 +0000 0 0 0 None statement ok DROP TABLE t1; diff --git a/tests/logictest/suites/gen/09_fuse_engine/09_0014_func_clustering_information_function b/tests/logictest/suites/gen/09_fuse_engine/09_0014_func_clustering_information_function new file mode 100644 index 000000000000..0e7ce16a7a3e --- /dev/null +++ b/tests/logictest/suites/gen/09_fuse_engine/09_0014_func_clustering_information_function @@ -0,0 +1,25 @@ +statement ok +create table t09_0014(a int, b int) cluster by(b,a); + +statement ok +insert into t09_0014 values(0,3),(1,1); + +statement ok +insert into t09_0014 values(1,3),(2,1); + +statement ok +insert into t09_0014 values(4,4); + +statement query II +select * from t09_0014 order by b, a; + +---- +1 1 +2 1 +0 3 +1 3 +4 4 + +statement ok +drop table t09_0014; + diff --git a/tests/logictest/suites/gen/20+_others/20_0003_async_crash_me_table b/tests/logictest/suites/gen/20+_others/20_0003_async_crash_me_table new file mode 100644 index 000000000000..7744a15164bc --- /dev/null +++ b/tests/logictest/suites/gen/20+_others/20_0003_async_crash_me_table @@ -0,0 +1,3 @@ +statement error 1104 +SELECT * FROM async_crash_me('async crash me'); + diff --git a/tests/pyproject.toml b/tests/pyproject.toml index 76fcafa790ed..7d1d81711b14 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -19,6 +19,7 @@ PyMySQL = "^1.0.2" six = "^1.16.0" PyHamcrest = "^2.0.2" requests = "^2.27.1" +environs = "^9.5.0" toml = "^0.10.2" [tool.poetry.dev-dependencies]