airborne12 commented on code in PR #67918: URL: https://github.com/apache/doris/pull/67918#discussion_r4081904235
########## regression-test/suites/inverted_index_p0/analyzer/test_analyzer_malformed_utf8_write.groovy: ########## @@ -0,0 +1,110 @@ +// 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. + +// A string column may hold bytes that are not valid UTF-8. Indexing them must keep working: +// the malformed bytes are skipped and the valid text around them stays searchable. +suite("test_analyzer_malformed_utf8_write", "p0") { + def ngramTable = "test_malformed_utf8_ngram" + def icuTable = "test_malformed_utf8_icu" + + sql "DROP TABLE IF EXISTS ${ngramTable}" + sql "DROP TABLE IF EXISTS ${icuTable}" + + sql """ + CREATE INVERTED INDEX TOKENIZER IF NOT EXISTS malformed_utf8_ngram_tokenizer + PROPERTIES + ( + "type" = "ngram", + "min_gram" = "2", + "max_gram" = "2" + ); + """ + + sql """ + CREATE INVERTED INDEX ANALYZER IF NOT EXISTS malformed_utf8_ngram_analyzer + PROPERTIES + ( + "tokenizer" = "malformed_utf8_ngram_tokenizer" + ); + """ + + sql """ + CREATE INVERTED INDEX ANALYZER IF NOT EXISTS malformed_utf8_icu_analyzer + PROPERTIES + ( + "tokenizer" = "icu" + ); + """ + + for (String analyzer : ["malformed_utf8_ngram_analyzer", "malformed_utf8_icu_analyzer"]) { + Exception lastException = null + boolean ready = false + for (int attempt = 0; attempt < 30; attempt++) { + try { + sql """SELECT TOKENIZE('probe', '"analyzer"="${analyzer}"')""" + ready = true + break + } catch (Exception e) { + lastException = e + sleep(1000) + } + } + assertTrue(ready, "Analyzer ${analyzer} was not ready: ${lastException?.message}") + } + + sql """ + CREATE TABLE ${ngramTable} ( + `id` int NOT NULL, + `ch` text NULL, + INDEX idx_ch (`ch`) USING INVERTED PROPERTIES("analyzer" = "malformed_utf8_ngram_analyzer") + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ("replication_allocation" = "tag.location.default: 1"); + """ + + sql """ + CREATE TABLE ${icuTable} ( + `id` int NOT NULL, + `ch` text NULL, + INDEX idx_ch (`ch`) USING INVERTED PROPERTIES("analyzer" = "malformed_utf8_icu_analyzer") + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ("replication_allocation" = "tag.location.default: 1"); + """ + + // An overlong encoding and a byte that can never start a sequence. + sql """ INSERT INTO ${ngramTable} VALUES (1, CONCAT('abcd', UNHEX('C0AF'), 'efgh')) """ + sql """ INSERT INTO ${ngramTable} VALUES (2, CONCAT('wxyz', UNHEX('FF'))) """ + sql """ INSERT INTO ${ngramTable} VALUES (3, 'plain') """ + sql """ INSERT INTO ${icuTable} VALUES (1, CONCAT('alpha ', UNHEX('FF'), ' beta')) """ + sql """ INSERT INTO ${icuTable} VALUES (2, 'gamma delta') """ + + sql "sync" + + // Every row was written, so the malformed bytes did not fail the index write. + assertEquals(3, sql("SELECT COUNT(*) FROM ${ngramTable}")[0][0]) Review Comment: We looked for the contract this rests on and could not find it, so we would rather keep `assertEquals` here and explain why than convert on an assumption. `regression-test/README.md` is the guide for test cases in this repository, and across its 119 lines it says nothing about `qt_sql`, `order_qt_sql` or `.out` files; its rules are about variable scoping and similar hazards. In `regression-test/suites/inverted_index_p0` itself, 47 of 219 suites use no `qt_` variant at all, and several of those assert deterministic results with `assertEquals` - for example `test_inverted_is_null`, `test_bm25_score_variant` and `test_add_drop_index_ignore_case_column`. So both styles are in use here rather than one being required. For this particular suite the explicit form also reads better. The point of the case is an invariant - every row survives the index write and the text on both sides of a malformed byte is still matchable - and `assertEquals(3, ...)` states that invariant next to the query instead of moving it into a separate golden blob. There is also a practical reason not to convert it the way we would have to. A `.out` begins with `This file is automatically generated`, and we have no cluster here to run the suite with the generator, so the file would be hand-written. This suite has already cost one P0 run when it raced analyzer propagation, and a hand-made golden is another way to break it for a reason unrelated to what it tests. If a maintainer would rather have golden output for it, we are happy to convert - we would just want the `.out` produced by the runner rather than written by hand. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
