Skip to content

Commit

Permalink
Backport #61547 to 24.1: Fix string search with const position
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-clickhouse committed Mar 19, 2024
1 parent 9518c25 commit 339c28f
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(concat(NULLIF(1, 1), materialize(3)), 'ca', 2) FROM 03013_position_const_start_pos FORMAT Null;

0 comments on commit 339c28f

Please sign in to comment.