Skip to content

split huge header file#990

Merged
LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:visitor
Jul 30, 2025
Merged

split huge header file#990
LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:visitor

Conversation

@LHT129

@LHT129 LHT129 commented Jul 30, 2025

Copy link
Copy Markdown
Collaborator

Summary by Sourcery

Split the bulky expression visitor header by extracting the AST parsing entrypoint and helper logic into a dedicated argparse module, clean up the visitor header, and update build configuration and includes accordingly

New Features:

  • Introduce attr/argparse.h and argparse.cpp to host the AstParse function

Enhancements:

  • Move helper functions and implementation details out of expression_visitor.h into its .cpp file
  • Replace direct inclusion of expression_visitor.h with argparse.h across source and test files

Build:

  • Add argparse.cpp to attr CMakeLists.txt

@LHT129 LHT129 self-assigned this Jul 30, 2025
@LHT129 LHT129 added kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 version/0.16 1. Add SINDI 2. Extend HGraph 1. 新增SINDI 2. 扩展 HGraph labels Jul 30, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@sourcery-ai

sourcery-ai Bot commented Jul 30, 2025

Copy link
Copy Markdown

Reviewer's Guide

Refactor expression parsing by extracting the AST entry point and helper routines into a dedicated argparse module, slimming down the visitor header and updating downstream includes and build configuration.

Class diagram for refactored expression parsing (argparse split)

classDiagram
    class FCExpressionVisitor {
        +FCExpressionVisitor(AttrTypeSchema* schema)
        +visitFilter_condition(FCParser::Filter_conditionContext* ctx)
        +visitParenExpr(FCParser::ParenExprContext* ctx)
        +visitNotExpr(FCParser::NotExprContext* ctx)
        +visitLogicalExpr(FCParser::LogicalExprContext* ctx)
        +visitCompExpr(FCParser::CompExprContext* ctx)
        +visitIntPipeListExpr(FCParser::IntPipeListExprContext* ctx)
        +visitStrPipeListExpr(FCParser::StrPipeListExprContext* ctx)
        +visitIntListExpr(FCParser::IntListExprContext* ctx)
        +visitStrListExpr(FCParser::StrListExprContext* ctx)
        +visitNumericComparison(FCParser::NumericComparisonContext* ctx)
        +visitStringComparison(FCParser::StringComparisonContext* ctx)
        +visitParenFieldExpr(FCParser::ParenFieldExprContext* ctx)
        +visitFieldRef(FCParser::FieldRefContext* ctx)
        +visitArithmeticExpr(FCParser::ArithmeticExprContext* ctx)
        +visitNumericConst(FCParser::NumericConstContext* ctx)
        +visitStr_value_list(FCParser::Str_value_listContext* ctx)
        +visitInt_value_list(FCParser::Int_value_listContext* ctx)
        +visitInt_value_list(FCParser::Int_value_listContext* ctx, const bool is_string_type)
        +visitInt_pipe_list(FCParser::Int_pipe_listContext* ctx)
        +visitInt_pipe_list(FCParser::Int_pipe_listContext* ctx, const bool is_string_type)
        +visitStr_pipe_list(FCParser::Str_pipe_listContext* ctx)
        +visitField_name(FCParser::Field_nameContext* ctx)
        +visitNumeric(FCParser::NumericContext* ctx)
        -StrViewSplit(std::string_view str, char delim)
        -IsStringType(const ExprPtr& expr)
        -AttrTypeSchema* schema_
    }
    class argparse {
        +AstParse(const std::string& filter_condition_str, AttrTypeSchema* schema = nullptr)
    }
    argparse ..> FCExpressionVisitor : uses
    FCExpressionVisitor ..> AttrTypeSchema
    FCExpressionVisitor ..> FCParser
    FCExpressionVisitor ..> ExprPtr
    argparse ..> AttrTypeSchema
    argparse ..> ExprPtr
Loading

File-Level Changes

Change Details Files
Extract parsing entrypoint and static helpers into a new argparse module
  • Add new files attr/argparse.h and attr/argparse.cpp with AstParse and helper logic
  • Move static operator-conversion and BuildIntListPtr routines out of expression_visitor.h
  • Refactor expression_visitor.cpp to remove redundant parsing entrypoint
  • Encapsulate parser setup and visitor invocation in argparse.cpp
src/attr/argparse.h
src/attr/argparse.cpp
src/attr/expression_visitor.h
src/attr/expression_visitor.cpp
Slim down expression_visitor.h to declarations only
  • Remove inline implementations and static functions from the header
  • Drop unused fmt/chrono include
  • Retain only visitor method declarations and private members
  • Add constructor declaration for FCExpressionVisitor
src/attr/expression_visitor.h
Update consumer code to use the new argparse interface
  • Replace includes of expression_visitor.h with argparse.h in ivf.cpp and tests
  • Add include for attr/argparse.h where parsing is invoked
  • Ensure test_fc_visitor.cpp and executor tests reference the new module
src/algorithm/ivf.cpp
src/attr/executor/comparison_executor_test.cpp
src/attr/executor/integer_list_executor_test.cpp
src/attr/executor/logical_executor_test.cpp
src/attr/executor/string_list_executor_test.cpp
tests/test_fc_visitor.cpp
Adjust build configuration to include argparse.cpp
  • Append argparse.cpp to ATTR_SRCS in src/attr/CMakeLists.txt
src/attr/CMakeLists.txt
Add missing include in executor test header
  • Include <unordered_set> in executor_test.h
src/attr/executor/executor_test.h

Possibly linked issues

  • #0: The PR directly implements the issue's solution by splitting header files to optimize compilation speed.
  • #0: The PR splits a large header file and refactors include dependencies by creating a new argparse module, directly addressing the issue's goal of splitting modules and header dependencies.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @LHT129 - I've reviewed your changes - here's some feedback:

  • Prefer putting internal helper functions into an anonymous namespace instead of using static at global scope in the .cpp to better encapsulate them.
  • Consider renaming argparse.{cpp,h} to something more domain-specific (e.g. filter_parser) to avoid confusion with common ‘argparse’ naming and clarify its responsibility.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Prefer putting internal helper functions into an anonymous namespace instead of using static at global scope in the .cpp to better encapsulate them.
- Consider renaming argparse.{cpp,h} to something more domain-specific (e.g. filter_parser) to avoid confusion with common ‘argparse’ naming and clarify its responsibility.

## Individual Comments

### Comment 1
<location> `src/attr/expression_visitor.cpp:35` </location>
<code_context>
+    parser.addErrorListener(&error_listener);
+    FCExpressionVisitor visitor(schema);
+    auto expr_ptr = std::any_cast<ExprPtr>(visitor.visit(parser.filter_condition()));
+    return std::move(expr_ptr);
+}
+}  // namespace vsag
</code_context>

<issue_to_address>
Unnecessary use of std::move on local variable being returned.

Return expr_ptr directly to allow the compiler to apply RVO.
</issue_to_address>

### Comment 2
<location> `src/attr/expression_visitor.cpp:395` </location>
<code_context>
+        end = str.find(delim, start);
+    }
+    result.emplace_back(str.substr(start));
+    return std::move(result);
+}
+
</code_context>

<issue_to_address>
Unnecessary use of std::move on local variable return.

Return 'result' directly to allow copy elision and avoid unnecessary std::move.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    result.emplace_back(str.substr(start));
    return std::move(result);
}
=======
    result.emplace_back(str.substr(start));
    return result;
}
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `src/attr/expression_visitor.cpp:400` </location>
<code_context>
+
+bool
+FCExpressionVisitor::IsStringType(const ExprPtr& expr) {
+    if (auto field_expr = std::dynamic_pointer_cast<FieldExpression>(expr); field_expr != nullptr) {
+        return schema_->GetTypeOfField(field_expr->fieldName) == STRING;
+    }
</code_context>

<issue_to_address>
No null check for schema_ before dereferencing.

If schema_ can be null, dereferencing it here may cause undefined behavior. Please add a null check or assertion.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/attr/expression_visitor.cpp
Comment thread src/attr/expression_visitor.cpp Outdated
Comment thread src/attr/expression_visitor.cpp
@codecov

codecov Bot commented Jul 30, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.97163% with 17 lines in your changes missing coverage. Please review.

@@            Coverage Diff             @@
##             main     #990      +/-   ##
==========================================
+ Coverage   91.39%   91.62%   +0.23%     
==========================================
  Files         294      294              
  Lines       16974    17011      +37     
==========================================
+ Hits        15513    15586      +73     
+ Misses       1461     1425      -36     
Flag Coverage Δ
cpp 91.62% <93.97%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 91.87% <100.00%> (-0.11%) ⬇️
datacell 91.43% <80.28%> (+0.73%) ⬆️
index 90.45% <65.38%> (-0.04%) ⬇️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7149a9...f8a7624. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

1 similar comment
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@inabao inabao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wxyucs wxyucs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@LHT129
LHT129 merged commit b1d63e4 into antgroup:main Jul 30, 2025
23 checks passed
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

LHT129 added a commit to LHT129/vsag that referenced this pull request Apr 16, 2026
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
LHT129 added a commit that referenced this pull request May 11, 2026
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
@LHT129
LHT129 deleted the visitor branch May 29, 2026 07:20
Sia-Sheerland pushed a commit to Sia-Sheerland/vsag that referenced this pull request Jun 26, 2026
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Signed-off-by: Sia Sheerland <x1075956441x@163.com>

Signed-off-by: Sia Sheerland <x1075956441x@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 module/testing size/XL version/0.16 1. Add SINDI 2. Extend HGraph 1. 新增SINDI 2. 扩展 HGraph

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants