This is an automated email from the ASF dual-hosted git repository.

airborne12 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new fab6ef907f4 [refactor](be) Remove the temporary CLucene facilities of 
the analysis migration (#70273)
fab6ef907f4 is described below

commit fab6ef907f45e8ef4a62b85588b2be82395ca074
Author: Jack <[email protected]>
AuthorDate: Tue Nov 24 15:51:38 2026 +0800

    [refactor](be) Remove the temporary CLucene facilities of the analysis 
migration (#70273)
    
    ### What problem does this PR solve?
    
    Issue Number: None
    
    Related PR: #70269, #70272 (depends on)
    
    Problem Summary: Remove what only served the migration: the
    `LuceneBackedTextAnalyzer` adapter, CLucene's contribs-lib in doris_be
    and the exception tables of the CLucene header gate.
---
 be/CMakeLists.txt                                  |   9 +-
 be/src/pch/pch.h                                   |   1 -
 .../clucene/lucene_backed_text_analyzer.cpp        | 114 ---------------------
 .../inverted/clucene/lucene_backed_text_analyzer.h |  50 ---------
 be/test/CMakeLists.txt                             |   4 +
 .../index/inverted/clucene/lucene_adapter_test.cpp | 109 +-------------------
 build-support/check-header-deps.py                 |  65 +++---------
 .../tests/test-build-hygiene-header-deps.sh        |  56 +++++-----
 8 files changed, 49 insertions(+), 359 deletions(-)

diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt
index dd43c6ecb14..7dbe60b6594 100644
--- a/be/CMakeLists.txt
+++ b/be/CMakeLists.txt
@@ -613,11 +613,12 @@ include_directories(
     ${CMAKE_CURRENT_BINARY_DIR}/apache-orc/c++/include
 )
 
+# Not contribs-lib: only the BE UT links clucene-contribs-lib 
(TEST_LINK_LIBS), so its headers are
+# on doris_be_test's include path alone (be/test/CMakeLists.txt).
 include_directories(
     ${CMAKE_CURRENT_BINARY_DIR}/clucene/src/shared
     ${CONTRIB_PATH}/clucene/src/core
     ${CONTRIB_PATH}/clucene/src/shared
-    ${CONTRIB_PATH}/clucene/src/contribs-lib
 )
 
 include_directories(
@@ -777,7 +778,6 @@ set(DORIS_DEPENDENCIES ${DORIS_DEPENDENCIES} orc)
 set(DORIS_DEPENDENCIES ${DORIS_DEPENDENCIES} ic)
 set(DORIS_DEPENDENCIES ${DORIS_DEPENDENCIES} clucene-core-static)
 set(DORIS_DEPENDENCIES ${DORIS_DEPENDENCIES} clucene-shared-static)
-set(DORIS_DEPENDENCIES ${DORIS_DEPENDENCIES} clucene-contribs-lib)
 set(DORIS_DEPENDENCIES ${DORIS_DEPENDENCIES} h3)
 
 set(DORIS_DEPENDENCIES ${DORIS_DEPENDENCIES} ${WL_END_GROUP})
@@ -913,9 +913,12 @@ else()
     endif()
 endif()
 
-# Set libraries for test
+# Set libraries for test. clucene-contribs-lib holds CLucene's 
LanguageBasedAnalyzer, the oracle
+# the jieba live differential (JiebaTokenizerTest, AnalysisDifferential) 
compares JiebaTokenizer
+# with; doris_be does not link it.
 set (TEST_LINK_LIBS ${DORIS_LINK_LIBS}
     ${WL_START_GROUP}
+    clucene-contribs-lib
     gmock
     gtest
     ${WL_END_GROUP}
diff --git a/be/src/pch/pch.h b/be/src/pch/pch.h
index 56d3c735fc0..e20aa9e2639 100644
--- a/be/src/pch/pch.h
+++ b/be/src/pch/pch.h
@@ -28,7 +28,6 @@
 
 // CLucene headers
 #include <CLucene.h>
-#include <CLucene/analysis/LanguageBasedAnalyzer.h>
 #include <CLucene/clucene-config.h>
 #include <CLucene/debug/error.h>
 #include <CLucene/debug/mem.h>
diff --git 
a/be/src/storage/index/inverted/clucene/lucene_backed_text_analyzer.cpp 
b/be/src/storage/index/inverted/clucene/lucene_backed_text_analyzer.cpp
deleted file mode 100644
index 52aa4b9110e..00000000000
--- a/be/src/storage/index/inverted/clucene/lucene_backed_text_analyzer.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-// 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.
-
-#include "storage/index/inverted/clucene/lucene_backed_text_analyzer.h"
-
-#include <CLucene.h>
-
-#include <string_view>
-#include <utility>
-
-#include "common/cast_set.h"
-#include "common/check.h"
-#include "common/exception.h"
-#include "storage/index/inverted/clucene/lucene_reader.h"
-
-namespace doris::segment_v2::inverted_index {
-
-namespace {
-
-// One value at a time through a CLucene analyzer. The reader, the token and 
the CLucene stream are
-// made by reset() and released once the value is exhausted, so nothing 
outlives a value.
-class LuceneBackedTokenStream final : public TextTokenizer {
-public:
-    // The analyzer outlives the stream, because a stream does not outlive its 
TextAnalyzer.
-    explicit LuceneBackedTokenStream(lucene::analysis::Analyzer* analyzer) : 
_analyzer(analyzer) {}
-
-    void reset(std::string_view text) override {
-        release();
-        try {
-            _reader = std::make_shared<lucene::util::SStringReader<char>>();
-            _reader->init(text.data(), cast_set<int32_t>(text.size()), false);
-            _token = std::make_unique<lucene::analysis::Token>();
-            _stream.reset(_analyzer->tokenStream(L"", _reader));
-        } catch (const CLuceneError& e) {
-            release();
-            throw Exception(ErrorCode::INVERTED_INDEX_ANALYZER_ERROR,
-                            "the CLucene analyzer failed to start a value: 
{}", e.what());
-        }
-    }
-
-    bool next_batch(TokenBatch& batch) override {
-        batch.clear();
-        while (_stream != nullptr && batch.size() < kBatchTokens) {
-            lucene::analysis::Token* token = next_lucene_token();
-            if (token == nullptr) {
-                release();
-                break;
-            }
-            batch.push_copy({token->termBuffer<char>(), 
token->termLength<char>()},
-                            token->getPositionIncrement());
-        }
-        return batch.size() != 0;
-    }
-
-    // Nothing survives a value.
-    size_t reserved_bytes() const override { return 0; }
-
-private:
-    // The next CLucene token, or nullptr once the value is exhausted.
-    lucene::analysis::Token* next_lucene_token() {
-        try {
-            lucene::analysis::Token* token = _stream->next(_token.get());
-            if (token == nullptr) {
-                _stream->close();
-            }
-            return token;
-        } catch (const CLuceneError& e) {
-            release();
-            throw Exception(ErrorCode::INVERTED_INDEX_ANALYZER_ERROR,
-                            "the CLucene analyzer failed on a value: {}", 
e.what());
-        }
-    }
-
-    void release() {
-        _stream.reset();
-        _token.reset();
-        _reader.reset();
-    }
-
-    lucene::analysis::Analyzer* const _analyzer;
-    ReaderPtr _reader;
-    std::unique_ptr<lucene::analysis::Token> _token;
-    std::unique_ptr<lucene::analysis::TokenStream> _stream;
-};
-
-} // namespace
-
-LuceneBackedTextAnalyzer::LuceneBackedTextAnalyzer(
-        std::shared_ptr<lucene::analysis::Analyzer> analyzer)
-        : _analyzer(std::move(analyzer)) {
-    DORIS_CHECK(_analyzer != nullptr);
-}
-
-LuceneBackedTextAnalyzer::~LuceneBackedTextAnalyzer() = default;
-
-std::unique_ptr<TextTokenStream> LuceneBackedTextAnalyzer::create_stream() 
const {
-    return std::make_unique<LuceneBackedTokenStream>(_analyzer.get());
-}
-
-} // namespace doris::segment_v2::inverted_index
diff --git 
a/be/src/storage/index/inverted/clucene/lucene_backed_text_analyzer.h 
b/be/src/storage/index/inverted/clucene/lucene_backed_text_analyzer.h
deleted file mode 100644
index 8880f1c44a2..00000000000
--- a/be/src/storage/index/inverted/clucene/lucene_backed_text_analyzer.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// 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.
-
-#pragma once
-
-#include <memory>
-
-#include "storage/index/inverted/analysis/text_analyzer.h"
-
-namespace lucene::analysis {
-class Analyzer;
-} // namespace lucene::analysis
-
-namespace doris::segment_v2::inverted_index {
-
-// A CLucene analyzer behind the TextAnalyzer interface, for the consumers 
that move to the
-// interface before the analyzers do. It goes once every analyzer is native.
-//
-// Every value gets a new reader and a new CLucene stream from 
Analyzer::tokenStream(), as queries
-// and the SNII writer read a value before the TextAnalyzer interface. The 
index's char filter is
-// not applied here but in front of the analyzer 
(InvertedIndexAnalyzer::create_analyzer). Sharing
-// the analyzer between threads is as safe as sharing the CLucene analyzer for 
tokenStream()
-// calls. Terms are copied into the batch, because a CLucene token is 
overwritten by the next one;
-// a CLuceneError comes out as a doris::Exception.
-class LuceneBackedTextAnalyzer final : public TextAnalyzer {
-public:
-    explicit 
LuceneBackedTextAnalyzer(std::shared_ptr<lucene::analysis::Analyzer> analyzer);
-    ~LuceneBackedTextAnalyzer() override;
-
-    std::unique_ptr<TextTokenStream> create_stream() const override;
-
-private:
-    const std::shared_ptr<lucene::analysis::Analyzer> _analyzer;
-};
-
-} // namespace doris::segment_v2::inverted_index
diff --git a/be/test/CMakeLists.txt b/be/test/CMakeLists.txt
index b891d984591..6fcc3cbaf67 100644
--- a/be/test/CMakeLists.txt
+++ b/be/test/CMakeLists.txt
@@ -141,6 +141,10 @@ if (TARGET phdr_cache_test_dso)
     add_dependencies(doris_be_test phdr_cache_test_dso)
 endif()
 
+# The headers of clucene-contribs-lib, which TEST_LINK_LIBS links for the 
jieba live differential
+# alone: the main library's include path leaves them out, so no be/src source 
can use them.
+target_include_directories(doris_be_test PRIVATE 
${CONTRIB_PATH}/clucene/src/contribs-lib)
+
 # run-be-ut.sh resets DORIS_HOME to the test binary dir before launching the
 # tests, so the real-IPADIC dictionary test can't find the repo dictionary via
 # DORIS_HOME.
diff --git a/be/test/storage/index/inverted/clucene/lucene_adapter_test.cpp 
b/be/test/storage/index/inverted/clucene/lucene_adapter_test.cpp
index d993f362e45..9532c230088 100644
--- a/be/test/storage/index/inverted/clucene/lucene_adapter_test.cpp
+++ b/be/test/storage/index/inverted/clucene/lucene_adapter_test.cpp
@@ -15,9 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
-// The two adapters between the CLucene analysis interfaces and the 
TextAnalyzer interface:
-// LuceneBackedTextAnalyzer, a CLucene analyzer for the new consumers, and 
LuceneAnalyzerBridge, a
-// TextAnalyzer for the V1 and V2 writers.
+// LuceneAnalyzerBridge, the adapter that puts a TextAnalyzer behind the 
CLucene analysis interfaces
+// for the V1 and V2 writers.
 
 #include <CLucene.h>
 #include <fmt/format.h>
@@ -32,7 +31,6 @@
 #include <utility>
 #include <vector>
 
-#include "CLucene/analysis/standard95/StandardAnalyzer.h"
 #include "common/exception.h"
 #include "common/status.h"
 #include "io/fs/local_file_system.h"
@@ -43,7 +41,6 @@
 #include "storage/index/inverted/analysis/token_batch.h"
 #include "storage/index/inverted/clucene/inverted_index_writer.h"
 #include "storage/index/inverted/clucene/lucene_analyzer_bridge.h"
-#include "storage/index/inverted/clucene/lucene_backed_text_analyzer.h"
 #include "storage/index/inverted/common/inverted_index_desc.h"
 #include "storage/tablet/tablet_schema.h"
 #include "testutil/tmp_file_dirs_util.h"
@@ -65,13 +62,6 @@ std::string words(size_t count) {
     return text;
 }
 
-std::string read_all(lucene::util::Reader* reader) {
-    const char* start = nullptr;
-    const int32_t length = reader->read(reinterpret_cast<const 
void**>(&start), 0,
-                                        static_cast<int32_t>(reader->size()));
-    return length > 0 ? std::string(start, length) : std::string();
-}
-
 // A word of a script value: words are separated by spaces, "_" is an empty 
term, a leading '^'
 // puts the word at the position of the one before, and "!" is a failure where 
it stands.
 struct ScriptWord {
@@ -104,58 +94,6 @@ bool next_script_word(std::string_view text, size_t* 
position, ScriptWord* word)
     return true;
 }
 
-// A CLucene stream over a script value; "!" throws a CLuceneError.
-class ScriptedLuceneStream final : public lucene::analysis::TokenStream {
-public:
-    explicit ScriptedLuceneStream(std::string text) : _text(std::move(text)) {}
-
-    lucene::analysis::Token* next(lucene::analysis::Token* token) override {
-        ScriptWord word;
-        if (!next_script_word(_text, &_position, &word)) {
-            return nullptr;
-        }
-        if (word.fails) {
-            _CLTHROWA(CL_ERR_IO, "scripted CLucene failure");
-        }
-        token->setTextNoCopy(word.term.data(), 
static_cast<int32_t>(word.term.size()));
-        token->setPositionIncrement(word.position_increment);
-        return token;
-    }
-
-    void close() override {}
-
-private:
-    const std::string _text;
-    size_t _position = 0;
-};
-
-// A CLucene analyzer of script values; the value "!!" makes tokenStream() 
itself throw.
-class ScriptedLuceneAnalyzer final : public lucene::analysis::Analyzer {
-public:
-    bool isSDocOpt() override { return true; }
-
-    lucene::analysis::TokenStream* tokenStream(const TCHAR*, const ReaderPtr& 
reader) override {
-        std::string text = read_all(reader.get());
-        if (text == "!!") {
-            _CLTHROWA(CL_ERR_IO, "scripted CLucene failure in tokenStream");
-        }
-        return new ScriptedLuceneStream(std::move(text));
-    }
-
-    lucene::analysis::TokenStream* tokenStream(const TCHAR*, 
lucene::util::Reader*) override {
-        throw Exception(ErrorCode::INVERTED_INDEX_NOT_SUPPORTED, "not used");
-    }
-
-    lucene::analysis::TokenStream* reusableTokenStream(const TCHAR*,
-                                                       lucene::util::Reader*) 
override {
-        throw Exception(ErrorCode::INVERTED_INDEX_NOT_SUPPORTED, "not used");
-    }
-
-    lucene::analysis::TokenStream* reusableTokenStream(const TCHAR*, const 
ReaderPtr&) override {
-        throw Exception(ErrorCode::INVERTED_INDEX_NOT_SUPPORTED, "not used");
-    }
-};
-
 // A native stream over a script value, handing out views of it; "!" throws a 
doris::Exception
 // from next_batch(), and a value starting with "!reset" throws from reset().
 class ScriptedTextStream final : public TextTokenizer {
@@ -263,49 +201,6 @@ int thrown_code(const std::function<void()>& body) {
 
 } // namespace
 
-TEST(LuceneBackedTextAnalyzerTest, HandsOutTheCLuceneTokens) {
-    const LuceneBackedTextAnalyzer 
analyzer(std::make_shared<ScriptedLuceneAnalyzer>());
-    const auto stream = analyzer.create_stream();
-    EXPECT_EQ(collect_checked(*stream, "a ^b _ c"), kScriptTokens);
-    EXPECT_EQ(stream->reserved_bytes(), 0);
-
-    TokenBatch batch;
-    std::vector<size_t> sizes;
-    const std::string long_text = words(1000);
-    stream->reset(long_text);
-    while (stream->next_batch(batch)) {
-        sizes.push_back(batch.size());
-    }
-    EXPECT_EQ(sizes, (std::vector<size_t> {256, 256, 256, 232}));
-}
-
-TEST(LuceneBackedTextAnalyzerTest, CLuceneErrorsComeOutAsDorisExceptions) {
-    const LuceneBackedTextAnalyzer 
analyzer(std::make_shared<ScriptedLuceneAnalyzer>());
-    const auto stream = analyzer.create_stream();
-    TokenBatch batch;
-    EXPECT_EQ(thrown_code([&] {
-                  stream->reset("a b !");
-                  while (stream->next_batch(batch)) {
-                  }
-              }),
-              ErrorCode::INVERTED_INDEX_ANALYZER_ERROR);
-    EXPECT_EQ(thrown_code([&] { stream->reset("!!"); }), 
ErrorCode::INVERTED_INDEX_ANALYZER_ERROR);
-    // The next value starts over.
-    EXPECT_EQ(collect_checked(*stream, "c"), (Tokens {{.term = "c", 
.position_increment = 1}}));
-}
-
-TEST(LuceneBackedTextAnalyzerTest, KeepsTheTextStreamContract) {
-    const LuceneBackedTextAnalyzer 
scripted(std::make_shared<ScriptedLuceneAnalyzer>());
-    expect_text_stream_contract([&] { return scripted.create_stream(); },
-                                {"a ^b _ c", words(1000), words(256), "x"});
-    // A real CLucene analyzer behind the adapter: the standard one, which the 
builtin standard
-    // parser used before it had a tokenizer of its own.
-    const LuceneBackedTextAnalyzer standard(
-            
std::make_shared<lucene::analysis::standard95::StandardAnalyzer>());
-    expect_text_stream_contract([&] { return standard.create_stream(); },
-                                {"The Quick brown fox", words(1000), "中文 mixed 
文本", "x"});
-}
-
 TEST(LuceneAnalyzerBridgeTest, HandsOutTheTokensOfTheTextAnalyzer) {
     LuceneAnalyzerBridge bridge(std::make_shared<ScriptedTextAnalyzer>());
     const std::string first = "a ^b _ c";
diff --git a/build-support/check-header-deps.py 
b/build-support/check-header-deps.py
index 31fb94dad93..a28f2987d63 100755
--- a/build-support/check-header-deps.py
+++ b/build-support/check-header-deps.py
@@ -458,16 +458,6 @@ RULES = [
 # (header, banned include spelling or prefix, why). A header ending in "/" 
names
 # every header under it; a banned spelling ending in "/" bans the whole 
subtree.
 ANGLE_BANS = [
-    (
-        "storage/index/inverted/query/",
-        "CLucene/",
-        "query algorithms use the format SPI and do not include CLucene 
headers",
-    ),
-    (
-        "storage/index/inverted/query/",
-        "CLucene.h",
-        "query algorithms use the format SPI and do not include CLucene 
headers",
-    ),
     (
         "core/uint24.h",
         "fmt/",
@@ -608,10 +598,11 @@ PCH_QUOTED_WHITELIST = {
 # declarations only, so they cost nothing to include.
 FWD_SUFFIX = "_fwd.h"
 
-# CLucene-free roots. The code under these roots is moving off CLucene, and 
the other guards
-# cannot hold it there: ANGLE_BANS reads only a header's own includes, 
load_includes() keeps no
-# angle includes while most CLucene edges are angle includes, and the PCH 
hands CLucene to every
-# translation unit without any include at all. So two rules of their own:
+# CLucene-free roots. The code under these roots does not use CLucene, and the 
other guards cannot
+# keep it so: ANGLE_BANS reads only a header's own includes, load_includes() 
keeps no angle
+# includes while most CLucene edges are angle includes, and the PCH hands 
CLucene to every
+# translation unit without any include at all. So two rules of their own, 
neither with an
+# exception table:
 #   closure  no file under a root, sources included, and no project header a 
root reaches
 #            includes a CLucene header;
 #   symbols  the code under a root, with comments, string literals and 
includes stripped, names
@@ -635,17 +626,10 @@ CODE_NOISE = re.compile(
     re.S | re.M,
 )
 CLUCENE_WHY = (
-    "SNII, the analysis layer and ANN are moving off CLucene, and an include 
anywhere in the "
-    "closure of a root, or a symbol the PCH makes visible, ties them back to 
it"
+    "SNII, the analysis layer, the query engine, the shared inverted index 
code and ANN do not "
+    "use CLucene, and an include anywhere in the closure of a root, or a 
symbol the PCH makes "
+    "visible, ties them back to it"
 )
-# What still breaks the rules while the migration goes on, keyed by the file 
that breaks them,
-# not by the roots: one shared header puts many roots in violation, and its 
entry goes when the
-# task that cuts it lands. A missing entry and an entry that no longer breaks 
the rule both fail
-# the gate, so the tables only shrink.
-# Files that include a CLucene header and are under a root or reached from one.
-CLUCENE_INCLUDING_FILES = set()
-# Files under a root whose code names a CLucene symbol.
-CLUCENE_SYMBOL_FILES = set()
 
 
 def load_includes():
@@ -843,8 +827,6 @@ def enforce_clucene_closure(includes, clucene):
             if path in clucene and (header not in offenders or len(chain) < 
len(offenders[header])):
                 offenders[header] = chain
     for header, chain in sorted(offenders.items()):
-        if header in CLUCENE_INCLUDING_FILES:
-            continue
         failures += 1
         include = clucene[resolve(header, includes)][0]
         if len(chain) == 1:
@@ -855,50 +837,31 @@ def enforce_clucene_closure(includes, clucene):
         print("  chain:  " + "\n       -> ".join(chain + [f"<{include}>"]), 
file=sys.stderr)
         print(
             "  fix:    keep the CLucene type out of the header 
(forward-declare it, or put "
-            "the code behind an interface the root does not see); 
CLUCENE_INCLUDING_FILES "
-            "only lists what the migration has not cut yet",
-            file=sys.stderr,
-        )
-    for header in sorted(CLUCENE_INCLUDING_FILES - offenders.keys()):
-        failures += 1
-        print(
-            f"error: CLUCENE_INCLUDING_FILES lists {header}, which no 
CLucene-free root "
-            "reaches with a CLucene include any more",
+            "the code behind an interface the root does not see)",
             file=sys.stderr,
         )
-        print("  fix:    delete the entry", file=sys.stderr)
     return failures
 
 
 def enforce_clucene_symbols(includes):
     """The code under a root names no CLucene symbol."""
     failures = 0
-    offenders = {}
     for name in clucene_free_files(includes):
         with open(os.path.join(INCLUDE_ROOT, name), encoding="utf-8", 
errors="ignore") as handle:
             # Every stripped piece becomes the newlines it held, so line 
numbers stay right.
             code = CODE_NOISE.sub(lambda m: "\n" * m.group(0).count("\n"), 
handle.read())
         match = CLUCENE_SYMBOLS.search(code)
-        if match:
-            offenders[name] = (code.count("\n", 0, match.start()) + 1, 
match.group(0))
-    for name, (line, symbol) in sorted(offenders.items()):
-        if name in CLUCENE_SYMBOL_FILES:
+        if not match:
             continue
         failures += 1
-        print(f"error: {name}:{line} names the CLucene symbol {symbol}", 
file=sys.stderr)
+        line = code.count("\n", 0, match.start()) + 1
+        print(f"error: {name}:{line} names the CLucene symbol 
{match.group(0)}", file=sys.stderr)
         print(f"  reason: {CLUCENE_WHY}", file=sys.stderr)
         print(
             "  fix:    use the Doris type or error instead; the PCH makes 
CLucene visible "
             "without an include, so the compiler does not catch this",
             file=sys.stderr,
         )
-    for name in sorted(CLUCENE_SYMBOL_FILES - offenders.keys()):
-        failures += 1
-        print(
-            f"error: CLUCENE_SYMBOL_FILES lists {name}, which names no CLucene 
symbol any more",
-            file=sys.stderr,
-        )
-        print("  fix:    delete the entry", file=sys.stderr)
     return failures
 
 
@@ -1137,8 +1100,8 @@ def main():
             f"header hygiene: {len(RULES)} layering rule(s), "
             f"{len(ANGLE_BANS)} third-party ban(s), "
             f"{len(FORWARD_CLOSURE_BUDGETS)}+{len(REVERSE_REACH_BASELINES)} "
-            f"budget(s), pch whitelist, CLucene-free roots 
({len(CLUCENE_INCLUDING_FILES)}+"
-            f"{len(CLUCENE_SYMBOL_FILES)} exception(s)): all satisfied"
+            f"budget(s), pch whitelist, {len(CLUCENE_FREE_ROOTS)} CLucene-free 
root(s): "
+            "all satisfied"
         )
     return 0
 
diff --git a/build-support/tests/test-build-hygiene-header-deps.sh 
b/build-support/tests/test-build-hygiene-header-deps.sh
index 5da96404ae3..26bd2338edb 100755
--- a/build-support/tests/test-build-hygiene-header-deps.sh
+++ b/build-support/tests/test-build-hygiene-header-deps.sh
@@ -18,7 +18,7 @@
 # under the License.
 #
 # Self-test for the check-header-deps.py gate families: layering rules,
-# third-party bans, forward/reverse budgets, pch whitelist.
+# third-party bans, forward/reverse budgets, pch whitelist, CLucene-free roots.
 #
 # The gate runs against the real tree (its rule and budget tables name real
 # headers), so RED cases are proven by injecting one violation per family into
@@ -47,7 +47,6 @@ TARGETS=(
     "be/src/storage/index/inverted/query/spi/index_source.h"
     "be/src/storage/index/inverted/query/engine/intersection.cpp"
     "be/src/storage/index/inverted/common/query_info.h"
-    "build-support/check-header-deps.py"
     "be/src/storage/index/ann/ann_index_writer.h"
     "be/src/storage/index/ann/ann_index_storage.h"
 )
@@ -97,18 +96,31 @@ echo "${OUT}" | grep -q "fix:" || fail "query-format rule 
lacks a fix path"
 cp "${BACKUP}/be/src/storage/index/inverted/query/spi/index_source.h" \
     "${ROOT}/be/src/storage/index/inverted/query/spi/index_source.h"
 
-# ---- RED: a directory's third-party ban (query headers must not include 
CLucene) ----
+# ---- RED: CLucene-free roots ----
+# A root header including CLucene itself (query headers must not include 
CLucene), in both
+# spellings: angle, and quoted, which the closure rule reads as well.
 printf '#include <CLucene.h>\n' \
     >> "${ROOT}/be/src/storage/index/inverted/query/spi/index_source.h"
 OUT="$(run_gate)"; EC=$?
-[ "${EC}" -eq 1 ] || fail "directory angle-ban injection expected exit 1, got 
${EC}"
-echo "${OUT}" | grep -q "query/spi/index_source.h must not include 
<CLucene.h>" \
-    || fail "directory angle-ban violation not reported"
+[ "${EC}" -eq 1 ] || fail "CLucene include in a root header expected exit 1, 
got ${EC}"
+echo "${OUT}" | grep -q "query/spi/index_source.h includes <CLucene.h>" \
+    || fail "CLucene include in a root header not reported"
+echo "${OUT}" | grep -q "reason:" || fail "CLucene closure failure lacks the 
reason"
+echo "${OUT}" | grep -q "chain:" || fail "CLucene closure failure lacks the 
include chain"
+echo "${OUT}" | grep -q "fix:" || fail "CLucene closure failure lacks a fix 
path"
+cp "${BACKUP}/be/src/storage/index/inverted/query/spi/index_source.h" \
+    "${ROOT}/be/src/storage/index/inverted/query/spi/index_source.h"
+printf '#include "CLucene/analysis/AnalysisHeader.h"\n' \
+    >> "${ROOT}/be/src/storage/index/inverted/query/spi/index_source.h"
+OUT="$(run_gate)"; EC=$?
+[ "${EC}" -eq 1 ] || fail "quoted CLucene include in a root header expected 
exit 1, got ${EC}"
+echo "${OUT}" | grep -q \
+    "query/spi/index_source.h includes <CLucene/analysis/AnalysisHeader.h>" \
+    || fail "quoted CLucene include in a root header not reported"
 cp "${BACKUP}/be/src/storage/index/inverted/query/spi/index_source.h" \
     "${ROOT}/be/src/storage/index/inverted/query/spi/index_source.h"
 
-# ---- RED: third-party ban (uint24.h must not include fmt) ----
-# CLucene-free roots: an angle include two hops away from a root.
+# An angle include two hops away from a root.
 printf '#pragma once\n#include <CLucene/util/Misc.h>\n' > 
"${ROOT}/${PROBE_INNER}"
 printf '#pragma once\n#include "util/zz_clucene_probe_inner.h"\n' > 
"${ROOT}/${PROBE_OUTER}"
 printf '#include "util/zz_clucene_probe_outer.h"\n' \
@@ -135,22 +147,7 @@ echo "${OUT}" | grep -q "query/engine/intersection.cpp 
includes <CLucene.h>" \
 cp "${BACKUP}/be/src/storage/index/inverted/query/engine/intersection.cpp" \
     "${ROOT}/be/src/storage/index/inverted/query/engine/intersection.cpp"
 
-# An exception that no longer breaks the rule fails the gate. The tables are 
empty, so the probe
-# lists a clean file under a root, query_info.h. Written into the existing 
file, which keeps its
-# mode: e.g. "CLUCENE_INCLUDING_FILES = set()" becomes a set holding that one 
entry.
-add_clucene_exception() {
-    awk -v table="$1 = set()" -v entry="$1 = {\"$2\"}" '{ print ($0 == table ? 
entry : $0) }' \
-        "${BACKUP}/build-support/check-header-deps.py" > "${GATE}"
-}
-add_clucene_exception CLUCENE_INCLUDING_FILES 
"storage/index/inverted/common/query_info.h"
-OUT="$(run_gate)"; EC=$?
-[ "${EC}" -eq 1 ] || fail "stale CLucene include exception expected exit 1, 
got ${EC}"
-echo "${OUT}" | grep -q \
-    "CLUCENE_INCLUDING_FILES lists storage/index/inverted/common/query_info.h" 
\
-    || fail "stale CLucene include exception not reported"
-cat "${BACKUP}/build-support/check-header-deps.py" > "${GATE}"
-
-# The ANN index is CLucene-free and has no exception: a CLucene include in one 
of its headers fails.
+# The ANN index is a CLucene-free root too: a CLucene include in one of its 
headers fails.
 printf '\n#include <CLucene.h>\n' >> 
"${ROOT}/be/src/storage/index/ann/ann_index_writer.h"
 OUT="$(run_gate)"; EC=$?
 [ "${EC}" -eq 1 ] || fail "CLucene include in an ANN header expected exit 1, 
got ${EC}"
@@ -170,18 +167,10 @@ OUT="$(run_gate)"; EC=$?
 [ "${EC}" -eq 1 ] || fail "CLucene symbol in a root expected exit 1, got ${EC}"
 echo "${OUT}" | grep -q "common/query_info.h:[0-9]* names the CLucene symbol 
lucene::" \
     || fail "CLucene symbol in a root not reported"
+echo "${OUT}" | grep -q "fix:" || fail "CLucene symbol failure lacks a fix 
path"
 cp "${BACKUP}/be/src/storage/index/inverted/common/query_info.h" \
     "${ROOT}/be/src/storage/index/inverted/common/query_info.h"
 
-# A symbol exception that no longer breaks the rule fails the gate; the same 
made-up entry.
-add_clucene_exception CLUCENE_SYMBOL_FILES 
"storage/index/inverted/common/query_info.h"
-OUT="$(run_gate)"; EC=$?
-[ "${EC}" -eq 1 ] || fail "stale CLucene symbol exception expected exit 1, got 
${EC}"
-echo "${OUT}" | grep -q \
-    "CLUCENE_SYMBOL_FILES lists storage/index/inverted/common/query_info.h" \
-    || fail "stale CLucene symbol exception not reported"
-cat "${BACKUP}/build-support/check-header-deps.py" > "${GATE}"
-
 # A CLucene symbol in ANN code fails the gate as well.
 printf '\ninline lucene::store::Directory* clucene_gate_ann_symbol = 
nullptr;\n' \
     >> "${ROOT}/be/src/storage/index/ann/ann_index_storage.h"
@@ -192,6 +181,7 @@ echo "${OUT}" | grep -q 
"storage/index/ann/ann_index_storage.h:[0-9]* names the
 cp "${BACKUP}/be/src/storage/index/ann/ann_index_storage.h" \
     "${ROOT}/be/src/storage/index/ann/ann_index_storage.h"
 
+# ---- RED: third-party ban (uint24.h must not include fmt) ----
 printf '#include <fmt/format.h>\n' >> "${ROOT}/be/src/core/uint24.h"
 OUT="$(run_gate)"; EC=$?
 [ "${EC}" -eq 1 ] || fail "angle-ban injection expected exit 1, got ${EC}"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to