From 3e131579948821820af73dd306f380f018686b9d Mon Sep 17 00:00:00 2001 From: chertus Date: Fri, 27 Dec 2019 15:41:55 +0300 Subject: [PATCH] better engine Join tests --- dbms/src/Storages/StorageJoin.cpp | 22 ++++---- .../01051_all_join_engine.reference | 32 +++++++++++ .../0_stateless/01051_all_join_engine.sql | 56 +++++++++++++++++++ .../01051_new_any_join_engine.reference | 1 - .../0_stateless/01051_new_any_join_engine.sql | 3 - 5 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/01051_all_join_engine.reference create mode 100644 dbms/tests/queries/0_stateless/01051_all_join_engine.sql diff --git a/dbms/src/Storages/StorageJoin.cpp b/dbms/src/Storages/StorageJoin.cpp index 954d096cbd7..232e2201536 100644 --- a/dbms/src/Storages/StorageJoin.cpp +++ b/dbms/src/Storages/StorageJoin.cpp @@ -140,35 +140,36 @@ void registerStorageJoin(StorageFactory & factory) { const String strictness_str = Poco::toLower(*opt_strictness_id); - if (strictness_str == "any" || strictness_str == "\'any\'") + if (strictness_str == "any") { if (old_any_join) strictness = ASTTableJoin::Strictness::RightAny; else strictness = ASTTableJoin::Strictness::Any; } - else if (strictness_str == "all" || strictness_str == "\'all\'") + else if (strictness_str == "all") strictness = ASTTableJoin::Strictness::All; - else if (strictness_str == "semi" || strictness_str == "\'semi\'") + else if (strictness_str == "semi") strictness = ASTTableJoin::Strictness::Semi; - else if (strictness_str == "anti" || strictness_str == "\'anti\'") + else if (strictness_str == "anti") strictness = ASTTableJoin::Strictness::Anti; } if (strictness == ASTTableJoin::Strictness::Unspecified) - throw Exception("First parameter of storage Join must be ANY or ALL or SEMI or ANTI.", ErrorCodes::BAD_ARGUMENTS); + throw Exception("First parameter of storage Join must be ANY or ALL or SEMI or ANTI (without quotes).", + ErrorCodes::BAD_ARGUMENTS); if (auto opt_kind_id = tryGetIdentifierName(engine_args[1])) { const String kind_str = Poco::toLower(*opt_kind_id); - if (kind_str == "left" || kind_str == "\'left\'") + if (kind_str == "left") kind = ASTTableJoin::Kind::Left; - else if (kind_str == "inner" || kind_str == "\'inner\'") + else if (kind_str == "inner") kind = ASTTableJoin::Kind::Inner; - else if (kind_str == "right" || kind_str == "\'right\'") + else if (kind_str == "right") kind = ASTTableJoin::Kind::Right; - else if (kind_str == "full" || kind_str == "\'full\'") + else if (kind_str == "full") { if (strictness == ASTTableJoin::Strictness::Any) strictness = ASTTableJoin::Strictness::RightAny; @@ -177,7 +178,8 @@ void registerStorageJoin(StorageFactory & factory) } if (kind == ASTTableJoin::Kind::Comma) - throw Exception("Second parameter of storage Join must be LEFT or INNER or RIGHT or FULL.", ErrorCodes::BAD_ARGUMENTS); + throw Exception("Second parameter of storage Join must be LEFT or INNER or RIGHT or FULL (without quotes).", + ErrorCodes::BAD_ARGUMENTS); Names key_names; key_names.reserve(engine_args.size() - 2); diff --git a/dbms/tests/queries/0_stateless/01051_all_join_engine.reference b/dbms/tests/queries/0_stateless/01051_all_join_engine.reference new file mode 100644 index 00000000000..3e73caac0c7 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01051_all_join_engine.reference @@ -0,0 +1,32 @@ +left +0 a1 +1 a2 +2 a3 b1 +2 a3 b2 +3 a4 +4 a5 b3 +4 a5 b4 +4 a5 b5 +inner +2 a3 b1 +2 a3 b2 +4 a5 b3 +4 a5 b4 +4 a5 b5 +right +2 a3 b1 +2 a3 b2 +4 a5 b3 +4 a5 b4 +4 a5 b5 +5 b6 +full +0 a1 +1 a2 +2 a3 b1 +2 a3 b2 +3 a4 +4 a5 b3 +4 a5 b4 +4 a5 b5 +5 b6 diff --git a/dbms/tests/queries/0_stateless/01051_all_join_engine.sql b/dbms/tests/queries/0_stateless/01051_all_join_engine.sql new file mode 100644 index 00000000000..fe5ac390884 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01051_all_join_engine.sql @@ -0,0 +1,56 @@ +DROP TABLE IF EXISTS t1; + +DROP TABLE IF EXISTS left_join; +DROP TABLE IF EXISTS inner_join; +DROP TABLE IF EXISTS right_join; +DROP TABLE IF EXISTS full_join; + +CREATE TABLE t1 (x UInt32, str String) engine = Memory; + +CREATE TABLE left_join (x UInt32, s String) engine = Join(ALL, LEFT, x); +CREATE TABLE inner_join (x UInt32, s String) engine = Join(ALL, INNER, x); +CREATE TABLE right_join (x UInt32, s String) engine = Join(ALL, RIGHT, x); +CREATE TABLE full_join (x UInt32, s String) engine = Join(ALL, FULL, x); + +INSERT INTO t1 (x, str) VALUES (0, 'a1'), (1, 'a2'), (2, 'a3'), (3, 'a4'), (4, 'a5'); + +INSERT INTO left_join (x, s) VALUES (2, 'b1'), (2, 'b2'), (4, 'b3'), (4, 'b4'), (4, 'b5'), (5, 'b6'); +INSERT INTO inner_join (x, s) VALUES (2, 'b1'), (2, 'b2'), (4, 'b3'), (4, 'b4'), (4, 'b5'), (5, 'b6'); +INSERT INTO right_join (x, s) VALUES (2, 'b1'), (2, 'b2'), (4, 'b3'), (4, 'b4'), (4, 'b5'), (5, 'b6'); +INSERT INTO full_join (x, s) VALUES (2, 'b1'), (2, 'b2'), (4, 'b3'), (4, 'b4'), (4, 'b5'), (5, 'b6'); + +SET join_use_nulls = 0; + +SELECT 'left'; +SELECT * FROM t1 LEFT JOIN left_join j USING(x) ORDER BY x, str, s; + +SELECT 'inner'; +SELECT * FROM t1 INNER JOIN inner_join j USING(x) ORDER BY x, str, s; + +SELECT 'right'; +SELECT * FROM t1 RIGHT JOIN right_join j USING(x) ORDER BY x, str, s; + +SELECT 'full'; +SELECT * FROM t1 FULL JOIN full_join j USING(x) ORDER BY x, str, s; + +-- TODO +-- SET join_use_nulls = 1; +-- +-- SELECT 'left (join_use_nulls)'; +-- SELECT * FROM t1 LEFT JOIN left_join j USING(x) ORDER BY x, str, s; +-- +-- SELECT 'inner (join_use_nulls)'; +-- SELECT * FROM t1 INNER JOIN inner_join j USING(x) ORDER BY x, str, s; +-- +-- SELECT 'right (join_use_nulls)'; +-- SELECT * FROM t1 RIGHT JOIN right_join j USING(x) ORDER BY x, str, s; +-- +-- SELECT 'full (join_use_nulls)'; +-- SELECT * FROM t1 FULL JOIN full_join j USING(x) ORDER BY x, str, s; + +DROP TABLE t1; + +DROP TABLE left_join; +DROP TABLE inner_join; +DROP TABLE right_join; +DROP TABLE full_join; diff --git a/dbms/tests/queries/0_stateless/01051_new_any_join_engine.reference b/dbms/tests/queries/0_stateless/01051_new_any_join_engine.reference index fe207c56ed1..635ae641a63 100644 --- a/dbms/tests/queries/0_stateless/01051_new_any_join_engine.reference +++ b/dbms/tests/queries/0_stateless/01051_new_any_join_engine.reference @@ -16,7 +16,6 @@ any right 5 b6 semi left 2 a3 b1 -2 a6 b1 4 a5 b3 semi right 2 a3 b1 diff --git a/dbms/tests/queries/0_stateless/01051_new_any_join_engine.sql b/dbms/tests/queries/0_stateless/01051_new_any_join_engine.sql index 5ca321135a3..8662d8532d4 100644 --- a/dbms/tests/queries/0_stateless/01051_new_any_join_engine.sql +++ b/dbms/tests/queries/0_stateless/01051_new_any_join_engine.sql @@ -45,9 +45,6 @@ SELECT * FROM t1 ANY INNER JOIN any_inner_join j USING(x) ORDER BY x, str, s; SELECT 'any right'; SELECT * FROM t1 ANY RIGHT JOIN any_right_join j USING(x) ORDER BY x, str, s; - -INSERT INTO t1 (x, str) VALUES (2, 'a6'); - SELECT 'semi left'; SELECT * FROM t1 SEMI LEFT JOIN semi_left_join j USING(x) ORDER BY x, str, s;