Skip to content

Commit cd5eec5

Browse files
branch-4.0: [fix](substring) Fix substring_index #60346 (#60373)
Cherry-picked from #60346 Co-authored-by: Gabriel <liwenqiang@selectdb.com>
1 parent 9339ad7 commit cd5eec5

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

be/src/vec/functions/function_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ class FunctionSubstringIndex : public IFunction {
18971897
}
18981898

18991899
for (size_t i = 0; i < input_rows_count; ++i) {
1900-
auto str = str_col->get_data_at(i);
1900+
auto str = str_col->get_data_at(content_const ? 0 : i);
19011901
auto delimiter = delimiter_col->get_data_at(delimiter_const ? 0 : i);
19021902
int32_t delimiter_size = delimiter.size;
19031903

regression-test/data/function_p0/test_substring_index.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@
4646
-- !sql --
4747
test|test test|test
4848

49+
-- !sql --
50+
51+
52+

regression-test/suites/function_p0/test_substring_index.groovy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,26 @@ suite("test_substring_index") {
134134
"""
135135

136136
sql "DROP TABLE IF EXISTS test_substring_index"
137+
138+
sql "DROP TABLE IF EXISTS test_substring_index2"
139+
sql """
140+
CREATE TABLE test_substring_index2 (
141+
id INT,
142+
str VARCHAR(100),
143+
delimiter VARCHAR(10)
144+
) ENGINE=OLAP
145+
DUPLICATE KEY(id)
146+
DISTRIBUTED BY HASH(id) BUCKETS 1
147+
PROPERTIES (
148+
"replication_allocation" = "tag.location.default: 1"
149+
)
150+
"""
151+
152+
sql """
153+
INSERT INTO test_substring_index2 VALUES
154+
(1, NULL, NULL),
155+
(2, NULL, NULL)
156+
"""
157+
qt_sql """ SELECT SUBSTRING_INDEX(IFNULL(a.str, ''), ',', a.id) from test_substring_index2 a """
158+
sql "DROP TABLE IF EXISTS test_substring_index2"
137159
}

0 commit comments

Comments
 (0)