Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(groupby): support group by constant string #6095

Merged
merged 3 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions common/datablocks/src/kernels/data_block_group_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ impl HashMethod for HashMethodSingleString {
) -> Result<Vec<&'a [u8]>> {
debug_assert!(group_columns.len() == 1);
let column = group_columns[0];
let str_column: &StringColumn = Series::check_get(column)?;

// may have constant case
let str_column = Vu8::try_create_viewer(column)?;
let mut values = Vec::with_capacity(rows);
for row in 0..rows {
values.push(str_column.get_data(row));
values.push(str_column.value_at(row));
}
Ok(values)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ NULL 2 3
2 1 []
4 3 [1, 2, 3]
6 5 [4, 5, 6]
10
10
4 changes: 4 additions & 0 deletions tests/suites/0_stateless/03_dml/03_0003_select_group_by.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ INSERT INTO t_array VALUES(1, []),

SELECT max(id), min(id), arr FROM t_array GROUP BY arr ORDER BY arr ASC;

-- group by constant string
select count() from numbers(10) group by 'ab';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add test for nullable string column as well?

select count() from numbers(10) group by to_nullable('ab');

DROP TABLE t_array;