hello-stephen commented on code in PR #71231: URL: https://github.com/apache/doris/pull/71231#discussion_r4764413201
########## regression-test/suites/variant_p0/test_variant_search_sparse_stats_and_score.groovy: ########## @@ -0,0 +1,91 @@ +// 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. + +suite("test_variant_search_sparse_stats_and_score", "p0") { + if (getFeConfig("enable_debug_points").toBoolean()) { + sql "SET debug_variant_enable_doc_mode = false" + } + def tbl = "test_variant_search_sparse_stats_and_score" + sql "DROP TABLE IF EXISTS ${tbl}" + sql """CREATE TABLE ${tbl} ( + id INT NOT NULL, + mixedRoot VARIANT<'string_*':TEXT, PROPERTIES( + "variant_max_subcolumns_count"="1", "variant_max_sparse_column_statistics_size"="1", + "variant_enable_typed_paths_to_sparse"="false", "variant_sparse_hash_shard_count"="1")>, + INDEX idx(mixedRoot) USING INVERTED PROPERTIES( + "field_pattern"="string_*", "parser"="english", "norms"="true") + ) UNIQUE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES("replication_num"="1", "inverted_index_storage_format"="V3", + "disable_auto_compaction"="true")""" + sql """INSERT INTO ${tbl} VALUES + (1, parse_to_variant('{"string_Key":"hit","string_key":"other"}')), + (2, parse_to_variant('{"string_Key":"other","string_key":"hit"}'))""" + ["string_Key": 1, "string_key": 2].each { key, id -> + def pred = """SEARCH('mixedRoot.${key}:hit', '{"mode":"lucene"}')""" + assertEquals([[id]], sql("SELECT id FROM ${tbl} WHERE ${pred}")) + def rows = sql("SELECT id, score() AS s FROM ${tbl} WHERE ${pred} ORDER BY s LIMIT 10") + assertEquals([id], rows.collect { it[0] }) + assertTrue(rows[0][1].toDouble() > 0) + } + + // Incomplete metadata cannot prove absence. An unrelated segment still raises E-6001 + // rather than scanning every sparse key for each missing SEARCH field. + sql """INSERT INTO ${tbl} VALUES (3, parse_to_variant('{"noise_a":1,"noise_b":2,"noise_c":3}'))""" + ["mixedRoot.string_Key:hit", "NOT mixedRoot.string_Key:hit"].each { dsl -> + test { + sql """SELECT id FROM ${tbl} WHERE SEARCH('${dsl}', '{"mode":"lucene"}')""" + exception "SEARCH index unavailable for Variant field 'mixedRoot.string_Key'" + } + } + + // Isolate the hidden-descendant case from the unrelated truncated segment. + sql "TRUNCATE TABLE ${tbl}" + // The exact scalar path matches the template, but fnmatch(FNM_PATHNAME) lets a + // descendant containing '/' fall outside string_*. Truncated sparse statistics + // can omit that descendant. Keep the unavailable-index error, including under NOT. + sql """INSERT INTO ${tbl} VALUES + (4, parse_to_variant('{"hot":2,"aaa_noise":1}')), + (5, parse_to_variant('{"hot":2,"string_Key":{"leaf/slash":"hit"}}')), + (6, parse_to_variant('{"hot":2}'))""" + assertEquals([['{"leaf/slash":"hit"}']], sql(""" + SELECT CAST(mixedRoot['string_Key'] AS STRING) FROM ${tbl} WHERE id = 5 + """)) + ["mixedRoot.string_Key:hit", "NOT mixedRoot.string_Key:hit"].each { dsl -> + test { + sql """SELECT id FROM ${tbl} WHERE SEARCH('${dsl}', '{"mode":"lucene"}')""" + exception "SEARCH index unavailable for Variant field 'mixedRoot.string_Key'" + } + } + + // An inherited parent index also needs the physical suffix when collecting BM25 statistics. + def plain = "${tbl}_plain" + sql "DROP TABLE IF EXISTS ${plain}" + sql """CREATE TABLE ${plain} ( + id INT NOT NULL, mixedRoot VARIANT, `mixedroot.string_Key` INT, Review Comment: [P2] Pin the materialization budget for the plain scoring fixture The standard p0/cloud_p0 configs enable fuzzy session variables and debug points, so `initFuzzyModeVariables()` can leave `debug_variant_max_subcolumns_count=1` with doc mode false. This bare `VARIANT` inherits that budget even after the doc-mode reset above. Its two untyped keys then compete for one materialized path: `string_Key` stays sparse without a leaf index, and the first scored query raises E-6001 instead of passing. Please set `variant_max_subcolumns_count` explicitly to at least two for this fixture so the suite does not fail intermittently in CI. -- 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]
