Skip to content

Commit

Permalink
Merge pull request #61569 from ClickHouse/cherrypick/23.3/ef7395a81d4…
Browse files Browse the repository at this point in the history
…40880f74be0667aef6670bc39c2bb

Cherry pick #61547 to 23.3: Fix string search with const position
  • Loading branch information
robot-ch-test-poll committed Mar 19, 2024
2 parents 2c65d5d + ef7395a commit fbabaa0
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 fbabaa0

Please sign in to comment.