[cherry-pick] (branch-2.1) fix query errors caused by ignore_above (#37685)

## Proposed changes
pick from master #37679
This commit is contained in:
Sun Chenyang
2024-07-12 09:31:45 +08:00
committed by GitHub
parent 87912de93f
commit 4dc933bb28
3 changed files with 57 additions and 1 deletions

View File

@ -405,8 +405,18 @@ Status StringTypeInvertedIndexReader::query(OlapReaderStatistics* stats,
const auto* search_query = reinterpret_cast<const StringRef*>(query_value);
auto act_len = strnlen(search_query->data, search_query->size);
// If the written value exceeds ignore_above, it will be written as null.
// The queried value exceeds ignore_above means the written value cannot be found.
// The query needs to be downgraded to read from the segment file.
if (int ignore_above =
std::stoi(get_parser_ignore_above_value_from_properties(_index_meta.properties()));
act_len > ignore_above) {
return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>(
"query value is too long, evaluate skipped.");
}
std::string search_str(search_query->data, act_len);
// std::string search_str = reinterpret_cast<const StringRef*>(query_value)->to_string();
VLOG_DEBUG << "begin to query the inverted index from clucene"
<< ", column_name: " << column_name << ", search_str: " << search_str;
std::wstring column_name_ws = StringUtil::string_to_wstring(column_name);

View File

@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
3

View File

@ -0,0 +1,42 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import org.codehaus.groovy.runtime.IOGroovyMethods
suite("test_ignore_above_in_index", "p0") {
def tableName = "test_ignore_above_in_index"
sql "DROP TABLE IF EXISTS ${tableName}"
sql """
CREATE TABLE IF NOT EXISTS ${tableName}(
`id`int(11)NULL,
`c` text NULL,
INDEX c_idx(`c`) USING INVERTED PROPERTIES("ignore_above"="9") COMMENT ''
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES(
"replication_allocation" = "tag.location.default: 1"
);
"""
// ignore_above = 9, insert string length = 10
sql "insert into ${tableName} values (20, '1234567890');"
sql "insert into ${tableName} values (20, '1234567890');"
sql "insert into ${tableName} values (20, '1234567890');"
qt_sql "select count() from ${tableName} where c = '1234567890';"
}