From 58db4b7be4f326f5c30dccf3372172d83912f282 Mon Sep 17 00:00:00 2001 From: Vitaliy Lyudvichenko Date: Thu, 8 Jun 2017 19:36:45 +0300 Subject: [PATCH 1/3] Fix HTTP session test again. [#CLICKHOUSE-2] --- .../0_stateless/00463_sessions_in_http_interface.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dbms/tests/queries/0_stateless/00463_sessions_in_http_interface.sh b/dbms/tests/queries/0_stateless/00463_sessions_in_http_interface.sh index c7fd1109a9c..2a8abe55029 100755 --- a/dbms/tests/queries/0_stateless/00463_sessions_in_http_interface.sh +++ b/dbms/tests/queries/0_stateless/00463_sessions_in_http_interface.sh @@ -51,7 +51,14 @@ check "$url$session&session_timeout=3600" "$select" "Exception" 0 "3600 second t check "$url$session&session_timeout=60" "$select" "Exception" 0 "60 second timeout not accepted." check $url$session "$select" "7777777" 1 "Failed to reuse session." -check "$url$session&user=readonly&session_check=1" "$select" "Exception.*Session not found" 1 "Session is accessable for another user." +# Workaround here +# TODO: move the test to integration test or add readonly user to test environment +if [[ -z `request "$url?user=readonly" "SELECT ''"` ]]; then + # We have readonly user + check "$url$session&user=readonly&session_check=1" "$select" "Exception.*Session not found" 1 "Session is accessable for another user." +else + check "$url$session&user=readonly&session_check=1" "$select" "Exception.*Unknown user*" 1 "Session is accessable for unknown user." +fi create_temporary_table $url$session check $url$session "$select_from_temporary_table" "Hello" 1 "Failed to reuse a temporary table for session." From b03c87be39e2be57305369689e7980139fe4161d Mon Sep 17 00:00:00 2001 From: Alexey Zatelepin Date: Thu, 8 Jun 2017 15:15:57 +0300 Subject: [PATCH 2/3] fix nulls sorting when limit is greater than rows count [#CLICKHOUSE-3061] --- dbms/src/Columns/ColumnNullable.cpp | 4 +++- dbms/tests/queries/0_stateless/00426_nulls_sorting.reference | 3 +++ dbms/tests/queries/0_stateless/00426_nulls_sorting.sql | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dbms/src/Columns/ColumnNullable.cpp b/dbms/src/Columns/ColumnNullable.cpp index 54587b8f26f..a155b382176 100644 --- a/dbms/src/Columns/ColumnNullable.cpp +++ b/dbms/src/Columns/ColumnNullable.cpp @@ -240,6 +240,8 @@ void ColumnNullable::getPermutation(bool reverse, size_t limit, int null_directi if (!limit) limit = end_idx; + else + limit = std::min(end_idx, limit); while (read_idx < limit && !isNullAt(res[read_idx])) { @@ -271,7 +273,7 @@ void ColumnNullable::getPermutation(bool reverse, size_t limit, int null_directi } else { - /// Shift all NULL values to the begin. + /// Shift all NULL values to the beginning. ssize_t read_idx = res.size() - 1; ssize_t write_idx = res.size() - 1; diff --git a/dbms/tests/queries/0_stateless/00426_nulls_sorting.reference b/dbms/tests/queries/0_stateless/00426_nulls_sorting.reference index 0b844108516..1e33b9ec60c 100644 --- a/dbms/tests/queries/0_stateless/00426_nulls_sorting.reference +++ b/dbms/tests/queries/0_stateless/00426_nulls_sorting.reference @@ -114,3 +114,6 @@ \N 3 \N 6 \N 9 +2 +1 +0 diff --git a/dbms/tests/queries/0_stateless/00426_nulls_sorting.sql b/dbms/tests/queries/0_stateless/00426_nulls_sorting.sql index 4f3561479bb..f670792ff3c 100644 --- a/dbms/tests/queries/0_stateless/00426_nulls_sorting.sql +++ b/dbms/tests/queries/0_stateless/00426_nulls_sorting.sql @@ -20,3 +20,5 @@ SET max_block_size = 5; SELECT nullIf(number, number % 3 = 0 ? number : 0) AS x, number AS y FROM (SELECT * FROM system.numbers LIMIT 10) ORDER BY x, y; SELECT nullIf(number, number % 3 = 0 ? number : 0) AS x, number AS y FROM (SELECT * FROM system.numbers LIMIT 10) ORDER BY x DESC, y; + +SELECT x FROM (SELECT toNullable(number) AS x FROM system.numbers LIMIT 3) ORDER BY x DESC LIMIT 10 From 877283b589965f2dc2a941e1d9f6031be2c5bd74 Mon Sep 17 00:00:00 2001 From: Alexey Zatelepin Date: Thu, 8 Jun 2017 15:50:58 +0300 Subject: [PATCH 3/3] fix sorting when all columns are const [#CLICKHOUSE-3062] --- dbms/src/DataStreams/MergeSortingBlockInputStream.cpp | 5 +++++ .../0_stateless/00464_sort_all_constant_columns.reference | 4 ++++ .../queries/0_stateless/00464_sort_all_constant_columns.sql | 3 +++ 3 files changed, 12 insertions(+) create mode 100644 dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.reference create mode 100644 dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.sql diff --git a/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp b/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp index a2bcc7ac849..a12ad8411dd 100644 --- a/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp +++ b/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp @@ -83,6 +83,11 @@ Block MergeSortingBlockInputStream::readImpl() removeConstantsFromSortDescription(sample_block, description); } + /// If there were only const columns in sort description, then there is no need to sort. + /// Return the blocks as is. + if (description.empty()) + return block; + removeConstantsFromBlock(block); blocks.push_back(block); diff --git a/dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.reference b/dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.reference new file mode 100644 index 00000000000..4f8102040fd --- /dev/null +++ b/dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.reference @@ -0,0 +1,4 @@ +1 2 +2 +2 +2 diff --git a/dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.sql b/dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.sql new file mode 100644 index 00000000000..6c89e14a88f --- /dev/null +++ b/dbms/tests/queries/0_stateless/00464_sort_all_constant_columns.sql @@ -0,0 +1,3 @@ +SELECT * FROM (SELECT 1 AS x, 2 AS y) ORDER BY x; + +SELECT * FROM (SELECT x FROM (SELECT 2 AS x, arrayJoin([1,2,3]))) ORDER BY x;