Skip to content

Commit

Permalink
Merge pull request #61572 from ClickHouse/backport/23.8/61547
Browse files Browse the repository at this point in the history
Backport #61547 to 23.8: Fix string search with const position
  • Loading branch information
antonio2368 committed Mar 20, 2024
2 parents 9bba341 + fb0b0f2 commit 472c203
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Functions/FunctionsStringSearch.h
Expand Up @@ -161,14 +161,26 @@ class FunctionsStringSearch : public IFunction
{
if (col_haystack_const && col_needle_const)
{
const auto is_col_start_pos_const = !column_start_pos || isColumnConst(*column_start_pos);
auto column_start_position_arg = column_start_pos;
bool is_col_start_pos_const = false;
if (column_start_pos)
{
if (const ColumnConst * const_column_start_pos = typeid_cast<const ColumnConst *>(&*column_start_pos))
{
is_col_start_pos_const = true;
column_start_position_arg = const_column_start_pos->getDataColumnPtr();
}
}
else
is_col_start_pos_const = true;

vec_res.resize(is_col_start_pos_const ? 1 : column_start_pos->size());
const auto null_map = create_null_map();

Impl::constantConstant(
col_haystack_const->getValue<String>(),
col_needle_const->getValue<String>(),
column_start_pos,
column_start_position_arg,
vec_res,
null_map.get());

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions tests/queries/0_stateless/03013_position_const_start_pos.sql
@@ -0,0 +1,3 @@
CREATE TABLE 03013_position_const_start_pos (n Int16) ENGINE = Memory;
INSERT INTO 03013_position_const_start_pos SELECT * FROM generateRandom() LIMIT 1000;
SELECT position('test', 'ca', 2) FROM 03013_position_const_start_pos FORMAT Null;

0 comments on commit 472c203

Please sign in to comment.