Merge pull request #40020 from canhld94/ch_canh_fix_hash

fix HashMethodOneNumber with const column
This commit is contained in:
Kruglov Pavel 2022-08-12 14:40:24 +02:00 committed by GitHub
commit 4c7222d938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 8 deletions

View File

@ -6,11 +6,9 @@
#include <Common/Arena.h>
#include <Common/LRUCache.h>
#include <Common/assert_cast.h>
#include "Columns/IColumn.h"
#include <base/unaligned.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnConst.h>
#include <Columns/ColumnFixedString.h>
#include <Columns/ColumnLowCardinality.h>
@ -85,11 +83,8 @@ struct HashMethodString
HashMethodString(const ColumnRawPtrs & key_columns, const Sizes & /*key_sizes*/, const HashMethodContextPtr &)
{
const IColumn * column = key_columns[0];
if (isColumnConst(*column))
column = &assert_cast<const ColumnConst &>(*column).getDataColumn();
const ColumnString & column_string = assert_cast<const ColumnString &>(*column);
const IColumn & column = *key_columns[0];
const ColumnString & column_string = assert_cast<const ColumnString &>(column);
offsets = column_string.getOffsets().data();
chars = column_string.getChars().data();
}

View File

@ -128,7 +128,11 @@ void IntersectOrExceptTransform::accumulate(Chunk chunk)
column_ptrs.reserve(key_columns_pos.size());
for (auto pos : key_columns_pos)
{
/// Hash methods expect non-const column
columns[pos] = columns[pos]->convertToFullColumnIfConst();
column_ptrs.emplace_back(columns[pos].get());
}
if (!data)
data.emplace();
@ -160,8 +164,11 @@ void IntersectOrExceptTransform::filter(Chunk & chunk)
column_ptrs.reserve(key_columns_pos.size());
for (auto pos : key_columns_pos)
{
/// Hash methods expect non-const column
columns[pos] = columns[pos]->convertToFullColumnIfConst();
column_ptrs.emplace_back(columns[pos].get());
}
if (!data)
data.emplace();

View File

@ -0,0 +1,61 @@
fooooo
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

View File

@ -0,0 +1,13 @@
-- Test: crash the server
SELECT 'fooooo' INTERSECT SELECT 'fooooo';
SELECT 'fooooo' EXCEPT SELECT 'fooooo';
-- Test: intersect return incorrect result for const column
SELECT 1 FROM numbers(10) INTERSECT SELECT 1 FROM numbers(10);
SELECT toString(1) FROM numbers(10) INTERSECT SELECT toString(1) FROM numbers(10);
SELECT '1' FROM numbers(10) INTERSECT SELECT '1' FROM numbers(10);
-- Test: except return incorrect result for const column
SELECT 2 FROM numbers(10) EXCEPT SELECT 1 FROM numbers(5);
SELECT toString(2) FROM numbers(10) EXCEPT SELECT toString(1) FROM numbers(5);
SELECT '2' FROM numbers(10) EXCEPT SELECT '1' FROM numbers(5);