mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
fix distinct on single string field [#CLICKHOUSE-28]
This commit is contained in:
parent
eb2c8196fd
commit
3292ca81cb
@ -37,7 +37,8 @@ private:
|
||||
Method & method,
|
||||
const ConstColumnPlainPtrs & key_columns,
|
||||
IColumn::Filter & filter,
|
||||
size_t rows) const;
|
||||
size_t rows,
|
||||
SetVariants & variants) const;
|
||||
|
||||
|
||||
Names columns_names;
|
||||
|
@ -56,7 +56,7 @@ Block DistinctBlockInputStream::readImpl()
|
||||
break;
|
||||
#define M(NAME) \
|
||||
case SetVariants::Type::NAME: \
|
||||
buildFilter(*data.NAME, column_ptrs, filter, rows); \
|
||||
buildFilter(*data.NAME, column_ptrs, filter, rows, data); \
|
||||
break;
|
||||
APPLY_FOR_SET_VARIANTS(M)
|
||||
#undef M
|
||||
@ -104,7 +104,8 @@ void DistinctBlockInputStream::buildFilter(
|
||||
Method & method,
|
||||
const ConstColumnPlainPtrs & columns,
|
||||
IColumn::Filter & filter,
|
||||
size_t rows) const
|
||||
size_t rows,
|
||||
SetVariants & variants) const
|
||||
{
|
||||
typename Method::State state;
|
||||
state.init(columns);
|
||||
@ -114,9 +115,16 @@ void DistinctBlockInputStream::buildFilter(
|
||||
/// Make a key.
|
||||
typename Method::Key key = state.getKey(columns, columns.size(), i, key_sizes);
|
||||
|
||||
typename Method::Data::iterator it = method.data.find(key);
|
||||
bool inserted;
|
||||
method.data.emplace(key, it, inserted);
|
||||
|
||||
if (inserted)
|
||||
method.onNewKey(*it, columns.size(), i, variants.string_pool);
|
||||
|
||||
/// Emit the record if there is no such key in the current set yet.
|
||||
/// Skip it otherwise.
|
||||
filter[i] = method.data.insert(key).second;
|
||||
filter[i] = inserted;
|
||||
}
|
||||
}
|
||||
|
||||
|
8
dbms/tests/queries/0_stateless/00413_distinct.reference
Normal file
8
dbms/tests/queries/0_stateless/00413_distinct.reference
Normal file
@ -0,0 +1,8 @@
|
||||
Bill
|
||||
John
|
||||
Mary
|
||||
1
|
||||
3
|
||||
4
|
||||
5
|
||||
7
|
22
dbms/tests/queries/0_stateless/00413_distinct.sql
Normal file
22
dbms/tests/queries/0_stateless/00413_distinct.sql
Normal file
@ -0,0 +1,22 @@
|
||||
DROP TABLE IF EXISTS test.distinct;
|
||||
CREATE TABLE test.distinct (Num UInt32, Name String) ENGINE = Memory;
|
||||
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (1, 'John');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (1, 'John');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (3, 'Mary');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (3, 'Mary');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (3, 'Mary');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (4, 'Mary');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (4, 'Mary');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (5, 'Bill');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (7, 'Bill');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (7, 'Bill');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (7, 'Mary');
|
||||
INSERT INTO test.distinct (Num, Name) VALUES (7, 'John');
|
||||
|
||||
-- String field
|
||||
SELECT Name FROM (SELECT DISTINCT Name FROM test.distinct) ORDER BY Name;
|
||||
-- Num field
|
||||
SELECT Num FROM (SELECT DISTINCT Num FROM test.distinct) ORDER BY Num;
|
||||
|
||||
DROP TABLE IF EXISTS test.distinct;
|
Loading…
Reference in New Issue
Block a user