Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clp-s: Add boilerplate for new sql parser #504

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

gibber9809
Copy link
Contributor

@gibber9809 gibber9809 commented Jul 31, 2024

Description

This PR adds boilerplate for the new sql parser. This includes a stubbed out g4 grammar and visitor, as well as a basic unit test that tells us that the whole thing compiles and runs.

Validation performed

  • validated that unit test linking against sql parser library builds and runs successfully

Summary by CodeRabbit

  • New Features

    • Introduced SQL parsing capabilities with a new SQL parser and grammar.
    • Added a LogSuppressor class to manage logging during tests.
    • Implemented unit tests for SQL parsing functionality, including handling edge cases.
  • Bug Fixes

    • Enhanced error handling in SQL parsing to ensure proper logging and feedback.

@gibber9809 gibber9809 requested a review from LinZhihao-723 July 31, 2024 19:03
Copy link
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

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

Minor fixes

components/core/src/clp_s/search/sql/sql.cpp Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.hpp Outdated Show resolved Hide resolved
components/core/tests/test-sql.cpp Outdated Show resolved Hide resolved
components/core/tests/test-sql.cpp Outdated Show resolved Hide resolved
Comment on lines 17 to 43
class ErrorListener : public BaseErrorListener {
public:
void syntaxError(
Recognizer* recognizer,
Token* offending_symbol,
size_t line,
size_t char_position_in_line,
std::string const& msg,
std::exception_ptr e
) override {
m_error = true;
m_error_message = msg;
}

bool error() const { return m_error; }

std::string const& message() const { return m_error_message; }

private:
bool m_error{false};
std::string m_error_message;
};

class ParseTreeVisitor : public SqlBaseVisitor {
public:
std::any visitStart(SqlParser::StartContext* ctx) override { return EmptyExpr::create(); }
};
Copy link
Member

Choose a reason for hiding this comment

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

Sorry to miss this in the last round of review. Shall we move these two classes into the anon namespace? Or if there's plan to reuse them in other places, we should probably move them into the dedicated headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll move the ErrorListener into its own header, and put the visitor classes for sql and kql into the anonymous namespace.

I was worried that BaseErrorListener was part of the generated code for each grammar but it's part of the generic antlr runtime so there shouldn't be any issues.

using namespace sql;

namespace clp_s::search::sql {
class ErrorListener : public BaseErrorListener {
Copy link
Member

Choose a reason for hiding this comment

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

yeah it seems like we already have this class in clp_s::search::kql

using clp_s::search::antlr_common::ErrorListener;

namespace clp_s::search::sql {
class ErrorListener : public BaseErrorListener {
Copy link
Member

Choose a reason for hiding this comment

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

Should be removed right?

Copy link
Member

Choose a reason for hiding this comment

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

I will probably leave the change of kql to the next PR. Maybe ask Kirk's advice @kirkrodrigues

@gibber9809
Copy link
Contributor Author

@LinZhihao-723 fixed clang-tidy warnings. Re-review?

components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.hpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/CMakeLists.txt Outdated Show resolved Hide resolved
components/core/tests/test-sql.cpp Show resolved Hide resolved
Comment on lines 15 to 16
// Suppress logging
LogSuppressor suppressor{};
Copy link
Member

Choose a reason for hiding this comment

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

Not used?

Copy link
Contributor Author

@gibber9809 gibber9809 Sep 25, 2024

Choose a reason for hiding this comment

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

Its use is entirely implemented in the constructor/destructor. It just turns off spdlog logging once created, and re-enables it once destroyed.

Just allows you to run parsing unit tests without emitting tons of log messages for parsing failure.

components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes introduce a new SQL parsing feature into the project, which includes the addition of a SQL grammar definition and an implementation of a SQL expression parser. A new error listener class is created for error handling during parsing. Unit tests for the SQL parser are also added to ensure its functionality. The modifications to CMake configuration files accommodate the new SQL components, and updates to existing files integrate the new functionality.

Changes

File(s) Change Summary
components/core/CMakeLists.txt, components/core/src/clp_s/CMakeLists.txt Added new test file tests/test-sql.cpp and linked the sql library. Included SQL search subdirectory.
components/core/src/clp_s/search/antlr_common/ErrorListener.hpp Introduced ErrorListener class for handling syntax errors during parsing.
components/core/src/clp_s/search/kql/CMakeLists.txt, components/core/src/clp_s/search/kql/kql.cpp Added header file for ErrorListener and updated linked library from Boost::filesystem. Removed custom ErrorListener class.
components/core/src/clp_s/search/sql/CMakeLists.txt, components/core/src/clp_s/search/sql/Sql.g4, components/core/src/clp_s/search/sql/sql.cpp, components/core/src/clp_s/search/sql/sql.hpp Added SQL grammar file, implemented SQL parser, and declared parsing function in the header file.
components/core/tests/test-sql.cpp Introduced unit tests for SQL parsing functionality using the Catch2 framework.
components/core/tests/LogSuppressor.hpp Added LogSuppressor class to suppress logging during tests.

Possibly related PRs

Suggested reviewers

  • kirkrodrigues

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (7)
components/core/src/clp_s/search/sql/Sql.g4 (2)

3-3: Consider adding a comment to explain the placeholder 'start' rule.

The current 'start' rule only matches EOF, which appears to be a placeholder. To improve clarity for future development, consider adding a comment explaining that this is a initial setup and will be expanded in future iterations.

Here's a suggested modification:

-start: EOF ;
+// TODO: Expand this rule to parse SQL statements
+start: EOF ;

1-5: Consider enhancing the grammar file with additional documentation and structure.

While this file provides a good starting point for the SQL grammar, consider the following suggestions to improve its structure and documentation:

  1. Add a file-level comment explaining the purpose and scope of this grammar.
  2. Include a TODO list or roadmap comment outlining the planned SQL constructs to be added.
  3. Consider adding placeholder rules for major SQL components (e.g., SELECT, FROM, WHERE) with TODO comments.

These additions would provide more context for future development and make the file more self-documenting.

components/core/tests/test-sql.cpp (2)

15-24: Test case implementation looks good. Consider adding more test cases.

The test case for parsing an empty string is well-implemented and serves as a good starting point. The use of std::dynamic_pointer_cast is appropriate for type checking in this context.

To improve test coverage, consider adding more test cases for:

  1. Valid SQL expressions
  2. Invalid SQL syntax
  3. Edge cases (e.g., very long expressions, expressions with special characters)
  4. Different types of SQL expressions (e.g., SELECT, INSERT, UPDATE)

This will help ensure the robustness of the SQL parser implementation.


16-17: Consider addressing the static analysis hint for LogSuppressor.

While not directly related to this file, the static analysis tool (cppcheck) suggests using an initialization list for 'm_previous_logging_level' in the LogSuppressor class.

In the file where LogSuppressor is implemented, consider updating the constructor to use an initialization list:

LogSuppressor::LogSuppressor() : m_previous_logging_level(spdlog::get_level()) {
    spdlog::set_level(spdlog::level::off);
}

This change can potentially improve performance slightly and follows C++ best practices.

components/core/src/clp_s/CMakeLists.txt (1)

1-2: LGTM! Consider grouping related subdirectories.

The addition of the search/sql subdirectory aligns well with the PR objectives of introducing a new SQL parser. This change complements the existing search/kql subdirectory and is consistent with the overall structure of the project.

For improved readability and organization, consider grouping related subdirectories together. You could apply this diff:

-add_subdirectory(search/kql)
-add_subdirectory(search/sql)
+# Search-related subdirectories
+add_subdirectory(search/kql)
+add_subdirectory(search/sql)

This minor change would make it easier to identify and manage search-related components in the future.

components/core/src/clp_s/search/kql/kql.cpp (2)

10-10: LGTM! Consider grouping related includes.

The addition of the ErrorListener.hpp include and the reordering of KQL-related includes are appropriate. To further improve readability, consider grouping related includes together. For example, you could move the KQL-related includes (KqlBaseVisitor.h, KqlLexer.h, KqlParser.h) next to the new ErrorListener.hpp include.

Also applies to: 20-22


204-204: LGTM! Consider improving error message formatting.

The removal of the custom ErrorListener class and the use of antlr_common::ErrorListener is a good improvement. It likely reduces code duplication and improves consistency across the project. The error handling logic in parse_kql_expression remains robust.

A minor suggestion: Consider using a more structured format for error messages, such as including the error type in the message. For example:

SPDLOG_ERROR("[LEXER_ERROR] {}", lexer_error_listener.message());
SPDLOG_ERROR("[PARSER_ERROR] {}", parser_error_listener.message());

This could make log parsing and error identification easier in the future.

Also applies to: 207-231

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3ceb17e and d09e6c4.

📒 Files selected for processing (10)
  • components/core/CMakeLists.txt (2 hunks)
  • components/core/src/clp_s/CMakeLists.txt (1 hunks)
  • components/core/src/clp_s/search/antlr_common/ErrorListener.hpp (1 hunks)
  • components/core/src/clp_s/search/kql/CMakeLists.txt (2 hunks)
  • components/core/src/clp_s/search/kql/kql.cpp (3 hunks)
  • components/core/src/clp_s/search/sql/CMakeLists.txt (1 hunks)
  • components/core/src/clp_s/search/sql/Sql.g4 (1 hunks)
  • components/core/src/clp_s/search/sql/sql.cpp (1 hunks)
  • components/core/src/clp_s/search/sql/sql.hpp (1 hunks)
  • components/core/tests/test-sql.cpp (1 hunks)
🧰 Additional context used
cppcheck
components/core/tests/test-sql.cpp

[performance] 7-7: Variable 'm_previous_logging_level' is assigned in constructor body. Consider performing initialization in initialization list.

(useInitializationList)

🔇 Additional comments not posted (19)
components/core/src/clp_s/search/sql/Sql.g4 (2)

1-1: LGTM: Grammar declaration is appropriate.

The grammar name 'Sql' is suitable for its intended purpose of SQL parsing.


5-5: LGTM: 'SPACE' token definition is correct and appropriate.

The 'SPACE' token correctly defines all common whitespace characters (space, tab, carriage return, and newline) and is set to be skipped during parsing. This is a standard and appropriate way to handle whitespace in most parsing scenarios.

components/core/src/clp_s/search/sql/sql.hpp (4)

1-8: LGTM: Header guards and includes are appropriate.

The header guards and include statements are correctly implemented and provide the necessary dependencies for the SQL parsing functionality.


9-9: LGTM: Namespace declaration is appropriate.

The namespace clp_s::search::sql aligns well with the file structure and provides a clear scope for the SQL parsing functionality.


10-14: LGTM: Function documentation is clear and concise.

The documentation for parse_sql_expression provides a clear description of its purpose, input, and return value. The previously suggested changes have been incorporated successfully.


15-15: LGTM: Function declaration follows modern C++ practices.

The declaration of parse_sql_expression is well-structured:

  • The [[nodiscard]] attribute encourages proper error handling.
  • The use of auto with a trailing return type enhances readability.
  • Taking std::istream& as input provides flexibility in parsing sources.
  • Returning std::shared_ptr<Expression> allows for nullable returns and shared ownership.
components/core/src/clp_s/search/kql/CMakeLists.txt (1)

11-11: LGTM: Addition of ErrorListener header

The inclusion of the ErrorListener.hpp header file is a good addition. It aligns with the PR objective of introducing a new SQL parser and suggests improved error handling capabilities for the parsing process.

components/core/tests/test-sql.cpp (2)

1-13: LGTM! Include statements and using declarations are well-organized.

The necessary headers have been included, and the using declarations are appropriate for the test case. The suggestion to add the header has been addressed.

🧰 Tools
cppcheck

[performance] 7-7: Variable 'm_previous_logging_level' is assigned in constructor body. Consider performing initialization in initialization list.

(useInitializationList)


16-17: LogSuppressor usage is appropriate for test execution.

The LogSuppressor is correctly used to prevent excessive log output during test execution, as explained in the previous discussion. This is a good practice for maintaining clean test output.

components/core/src/clp_s/search/sql/CMakeLists.txt (2)

1-6: LGTM: ANTLR target configuration is well-structured.

The ANTLR target configuration for SqlParser is correctly set up. It properly specifies the grammar file, generates the necessary components (lexer, parser, and visitor), and sets the package name. This configuration follows best practices for ANTLR integration in CMake.


27-29: LGTM: Compiler and linker settings are appropriate.

The compiler and linker settings for the SQL library are well-configured:

  1. The use of C++20 features is excellent for modern C++ development.
  2. Including the ANTLR output directory is necessary for accessing the generated files.
  3. Linking against antlr4_static and spdlog::spdlog is appropriate for a parser library with logging capabilities.

It's good to see that the previous suggestion to remove Boost::filesystem has been addressed in this version.

components/core/src/clp_s/search/antlr_common/ErrorListener.hpp (5)

1-9: Include statements and guards look good!

The include guards are properly formatted, and all necessary headers are included. The suggested <string_view> header from the past review has been added, which is great for using std::string_view in the class.


11-28: Class declaration and public methods are well-implemented!

The ErrorListener class is correctly declared within the clp_s::search::antlr_common namespace and inherits from antlr4::BaseErrorListener. The public methods have been improved as per previous suggestions:

  1. The syntaxError method signature now uses [[maybe_unused]] attributes appropriately.
  2. Both error() and message() methods are marked with [[nodiscard]] and use the trailing return type syntax.
  3. The message() method now returns a std::string_view, which is more efficient for read-only access.

These changes enhance the code's clarity and efficiency.


14-24: The syntaxError method implementation is correct and efficient.

The method properly sets the error flag and stores the error message. The use of [[maybe_unused]] for parameters not used in the current implementation is a good practice to prevent compiler warnings while leaving room for future expansion if needed.


30-32: Private member variables are well-defined.

The private section correctly declares two member variables:

  1. m_error: A boolean initialized to false, which is a good practice.
  2. m_error_message: A std::string to store the error message.

These members appropriately support the class's functionality.


1-36: Excellent implementation of the ErrorListener class!

This file presents a well-structured and efficient implementation of an error listener for ANTLR4-based parsing. Key points:

  1. Proper use of include guards and necessary headers.
  2. Clear namespace declaration.
  3. Effective use of modern C++ features like [[nodiscard]], [[maybe_unused]], and std::string_view.
  4. Concise and correct implementation of the syntaxError method.
  5. Appropriate use of private member variables for maintaining state.

All previous review comments have been addressed, resulting in a high-quality, maintainable piece of code. Great job on implementing this ErrorListener class!

components/core/src/clp_s/search/kql/kql.cpp (1)

26-26: LGTM! Good use of namespace alias.

The addition of the using statement for clp_s::search::antlr_common::ErrorListener is appropriate and consistent with the changes made to error handling. It improves code readability by allowing direct use of ErrorListener without the full namespace.

components/core/CMakeLists.txt (2)

522-522: LGTM: New SQL test file added

The addition of tests/test-sql.cpp to the SOURCE_FILES_unitTest list is appropriate. This aligns with the PR objective of introducing a new SQL parser and follows good development practices by including unit tests for the new functionality.


543-543: LGTM: SQL library linked to unit tests

The addition of the sql library to the target_link_libraries section for the unitTest target is correct and necessary for the new SQL functionality.

To ensure the SQL library is properly integrated, please run the following verification script:

components/core/src/clp_s/search/kql/CMakeLists.txt Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment explaining this is a boilerplate? Asked Kirk to take a brief view and his feedback is this file can be confusing to people new to it without a comment explaining it's a WIP config

Copy link
Member

Choose a reason for hiding this comment

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

Fwiw, the Rabbit agrees with me, lol.

components/core/tests/test-sql.cpp Outdated Show resolved Hide resolved
components/core/tests/test-sql.cpp Outdated Show resolved Hide resolved
components/core/tests/test-sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
components/core/tests/test-sql.cpp (2)

18-22: Consider simplifying the REQUIRE statement for better readability.

The test logic for parsing an empty string looks good. However, the REQUIRE statement can be simplified for better readability.

Consider changing:

REQUIRE((nullptr != filter));

to:

REQUIRE(filter != nullptr);

This change improves readability while maintaining the same functionality.


1-23: Consider expanding test coverage in future iterations.

The current test file provides a good starting point by testing the empty string scenario. However, to ensure robust SQL parsing functionality, it would be beneficial to add more test cases in the future. These could include:

  1. Parsing simple SQL queries
  2. Testing different SQL clauses (SELECT, WHERE, JOIN, etc.)
  3. Handling of various data types in SQL expressions
  4. Error cases and invalid SQL syntax

Expanding the test suite will help catch potential issues and ensure the reliability of the SQL parser as it evolves.

Would you like assistance in outlining additional test cases for future implementation?

🧰 Tools
🪛 cppcheck

[performance] 7-7: Variable 'm_previous_logging_level' is assigned in constructor body. Consider performing initialization in initialization list.

(useInitializationList)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d09e6c4 and 991ca73.

📒 Files selected for processing (2)
  • components/core/src/clp_s/search/sql/sql.cpp (1 hunks)
  • components/core/tests/test-sql.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/src/clp_s/search/sql/sql.cpp
🧰 Additional context used
🪛 cppcheck
components/core/tests/test-sql.cpp

[performance] 7-7: Variable 'm_previous_logging_level' is assigned in constructor body. Consider performing initialization in initialization list.

(useInitializationList)

🔇 Additional comments (2)
components/core/tests/test-sql.cpp (2)

1-12: LGTM! Include statements and using declarations are appropriate.

The necessary headers are included, and the using declarations are correctly implemented. The suggestions from previous comments have been addressed appropriately.

🧰 Tools
🪛 cppcheck

[performance] 7-7: Variable 'm_previous_logging_level' is assigned in constructor body. Consider performing initialization in initialization list.

(useInitializationList)


14-17: Test case setup looks good.

The test case is well-defined using the Catch2 framework, and the use of LogSuppressor is appropriate for suppressing unnecessary log output during testing.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
components/core/tests/LogSuppressor.hpp (2)

1-2: Consider using a more specific header guard name.

The current header guard TESTS_LOGSUPPRESSOR_HPP could potentially clash with other test utilities. Consider prefixing it with the project or component name, e.g., CORE_TESTS_LOGSUPPRESSOR_HPP.


Line range hint 6-26: Add thread safety documentation and improve exception safety.

The class modifies global logger state which has thread safety implications. Consider the following improvements:

  1. Document thread safety requirements
  2. Mark the member variable as const after initialization
  3. Add noexcept to the destructor

Here's the suggested implementation:

 /**
  * A class that suppresses logs so long as it's instantiated.
+ * 
+ * Note: This class modifies global logger state and should be used with caution
+ * in multi-threaded contexts as it may affect logging from other threads.
  */
 class LogSuppressor {
 public:
     LogSuppressor() {
         m_previous_logging_level = spdlog::default_logger()->level();
         spdlog::default_logger()->set_level(spdlog::level::off);
     }

     LogSuppressor(LogSuppressor const& other) = default;
     LogSuppressor(LogSuppressor&& other) noexcept = default;

     LogSuppressor& operator=(LogSuppressor const& other) = default;
     LogSuppressor& operator=(LogSuppressor&& other) noexcept = default;

-    ~LogSuppressor() { spdlog::default_logger()->set_level(m_previous_logging_level); }
+    ~LogSuppressor() noexcept { spdlog::default_logger()->set_level(m_previous_logging_level); }

 private:
-    spdlog::level::level_enum m_previous_logging_level;
+    const spdlog::level::level_enum m_previous_logging_level;
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 991ca73 and c2432bb.

📒 Files selected for processing (3)
  • components/core/src/clp_s/search/sql/Sql.g4 (1 hunks)
  • components/core/src/clp_s/search/sql/sql.cpp (1 hunks)
  • components/core/tests/LogSuppressor.hpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/src/clp_s/search/sql/Sql.g4
🧰 Additional context used
🔇 Additional comments (4)
components/core/tests/LogSuppressor.hpp (1)

27-28: LGTM!

The header guard closure is properly implemented with a descriptive comment.

components/core/src/clp_s/search/sql/sql.cpp (3)

1-2: Remove unused iostream include

The iostream header is not used in this implementation.


47-54: LGTM: Consistent error handling

The error handling implementation is well-structured with:

  • Clear error messages using SPDLOG
  • Consistent use of nullptr for error conditions
  • Separate handling of lexer and parser errors

24-30: LGTM: Good boilerplate implementation

The visitor class provides a solid foundation for future SQL parsing implementation. The use of anonymous namespace and [[nodiscard]] attribute follows best practices.

Let's verify the EmptyExpr implementation:

✅ Verification successful

The previous ast-grep pattern might have failed due to syntax or formatting differences. Let's try to locate the EmptyExpr implementation using alternative search methods to verify its existence and implementation details.


Implementation verified and properly used throughout the codebase

The EmptyExpr class is well-implemented in components/core/src/clp_s/search/EmptyExpr.hpp with:

  • Proper inheritance from Expression base class
  • Static factory method create() that returns std::shared_ptr<Expression>
  • Appropriate usage throughout the codebase for representing empty/null expressions
  • Consistent usage in transformation passes and SQL parsing

The ParseTreeVisitor's use of EmptyExpr::create() aligns with the established pattern in the codebase, making it a suitable foundation for the SQL parsing implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify EmptyExpr implementation
ast-grep --pattern 'class EmptyExpr : public Expression {
  $$$
  static auto create() -> std::shared_ptr<EmptyExpr> {
    $$$
  }
  $$$
}'

Length of output: 141


Script:

#!/bin/bash
# Let's try to find EmptyExpr implementation with ripgrep
rg -A 10 "class EmptyExpr" --type cpp

# Also search for Expression base class
rg -A 5 "class Expression" --type cpp

# Search for any files containing EmptyExpr
fd -e cpp -e hpp -x rg "EmptyExpr"

Length of output: 4278

components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
Copy link
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

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

Should be good to merge after this round.
I will approve after the workflow failure is resolved.

components/core/src/clp_s/search/sql/sql.cpp Outdated Show resolved Hide resolved
@kirkrodrigues
Copy link
Member

Can we merge main? The latest workflow failure should be resolved by #578.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
components/core/src/clp_s/search/kql/kql.cpp (2)

Line range hint 31-206: Consider enhancing code maintainability with these improvements, eh?

The ParseTreeVisitor implementation is solid but could benefit from these refinements:

  1. The string manipulation methods like unquote_string and unquote_date_string contain magic numbers. Consider extracting these as named constants, eh?

  2. The catch block in parse_kql_expression catches all exceptions, which might mask specific issues. Consider handling specific exceptions separately.

Example for string constants:

namespace {
constexpr char kDatePrefix[] = "date(";
constexpr size_t kDatePrefixLength = 5;
constexpr size_t kDateSuffixLength = 1;  // closing parenthesis

static std::string unquote_date_string(std::string const& text) {
    return unquote_string(text.substr(kDatePrefixLength, 
        text.size() - (kDatePrefixLength + kDateSuffixLength)));
}
}

Line range hint 209-238: Consider enhancing error handling robustness, eh?

The current implementation returns an empty shared_ptr on errors, which might make it difficult for callers to distinguish between different error cases. Consider these improvements:

  1. Return a Result/Expected type or throw specific exceptions for different error cases
  2. Include more context in error messages (like line/column numbers)
  3. Add debug logging for successful parsing

Example approach:

struct ParseResult {
    std::shared_ptr<Expression> expression;
    std::string error_message;
    bool success() const { return expression != nullptr; }
};

ParseResult parse_kql_expression(std::istream& in) {
    // ... existing setup code ...
    
    if (lexer_error_listener.error()) {
        return ParseResult{
            nullptr,
            fmt::format("Lexer error at line {}: {}", 
                       lexer.getCurrentToken()->getLine(),
                       lexer_error_listener.message())
        };
    }
    // ... rest of the implementation ...
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d687fe4 and 8f00de2.

📒 Files selected for processing (1)
  • components/core/src/clp_s/search/kql/kql.cpp (3 hunks)
🔇 Additional comments (1)
components/core/src/clp_s/search/kql/kql.cpp (1)

10-10: Consider deferring KQL changes to a separate PR, eh?

These changes to the KQL parser, while beneficial for standardizing error handling, appear to be outside the scope of the SQL parser implementation. As mentioned in the previous review, it might be better to handle these modifications in a dedicated PR.

Also applies to: 26-26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants