|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +suite("test_empty_string_match", "p0") { |
| 19 | + def tableName = "test_empty_string_match" |
| 20 | + |
| 21 | + sql "DROP TABLE IF EXISTS ${tableName}" |
| 22 | + sql """ |
| 23 | + CREATE TABLE ${tableName} ( |
| 24 | + id INT, |
| 25 | + keyword_col TEXT DEFAULT '', |
| 26 | + english_col TEXT DEFAULT '', |
| 27 | + INDEX keyword_idx(keyword_col) USING INVERTED COMMENT 'keyword index', |
| 28 | + INDEX english_idx(english_col) USING INVERTED PROPERTIES("parser" = "english") COMMENT 'english parser' |
| 29 | + ) ENGINE=OLAP |
| 30 | + DUPLICATE KEY(id) |
| 31 | + DISTRIBUTED BY HASH(id) BUCKETS 1 |
| 32 | + PROPERTIES("replication_allocation" = "tag.location.default: 1"); |
| 33 | + """ |
| 34 | + |
| 35 | + sql """ |
| 36 | + INSERT INTO ${tableName} VALUES |
| 37 | + (1, '', 'hello world'), |
| 38 | + (2, 'test', ''), |
| 39 | + (3, '', ''), |
| 40 | + (4, 'data', 'some text'); |
| 41 | + """ |
| 42 | + |
| 43 | + sql "SET enable_common_expr_pushdown = true" |
| 44 | + |
| 45 | + // Test 1: Empty string match on keyword index (index path) |
| 46 | + // Should match rows where keyword_col is empty string (rows 1 and 3) |
| 47 | + sql "SET enable_inverted_index_query = true" |
| 48 | + qt_keyword_index_path """SELECT id FROM ${tableName} WHERE keyword_col match '' ORDER BY id""" |
| 49 | + |
| 50 | + // Test 2: Empty string match on keyword index (slow path) |
| 51 | + // Should also match rows where keyword_col is empty string |
| 52 | + sql "SET enable_inverted_index_query = false" |
| 53 | + sql "SET enable_match_without_inverted_index = true" |
| 54 | + qt_keyword_slow_path """SELECT id FROM ${tableName} WHERE keyword_col match '' ORDER BY id""" |
| 55 | + |
| 56 | + // Test 3: Empty string match on tokenized index (index path) |
| 57 | + // Should return no rows because empty string tokenizes to nothing |
| 58 | + sql "SET enable_inverted_index_query = true" |
| 59 | + qt_english_index_path """SELECT count() FROM ${tableName} WHERE english_col match ''""" |
| 60 | + |
| 61 | + // Test 4: Empty string match on tokenized index (slow path) |
| 62 | + // Should also return no rows |
| 63 | + sql "SET enable_inverted_index_query = false" |
| 64 | + qt_english_slow_path """SELECT count() FROM ${tableName} WHERE english_col match ''""" |
| 65 | + |
| 66 | + // Test 5: Non-empty string match on keyword index should work as before |
| 67 | + sql "SET enable_inverted_index_query = true" |
| 68 | + qt_keyword_nonempty """SELECT id FROM ${tableName} WHERE keyword_col match 'test' ORDER BY id""" |
| 69 | + |
| 70 | + // Test 6: Verify match_any with empty string on keyword index |
| 71 | + sql "SET enable_inverted_index_query = false" |
| 72 | + qt_match_any_empty """SELECT id FROM ${tableName} WHERE keyword_col match_any '' ORDER BY id""" |
| 73 | + |
| 74 | + // Test 7: Verify match_all with empty string on keyword index |
| 75 | + qt_match_all_empty """SELECT id FROM ${tableName} WHERE keyword_col match_all '' ORDER BY id""" |
| 76 | + |
| 77 | + sql "DROP TABLE IF EXISTS ${tableName}" |
| 78 | +} |
0 commit comments