stream_processor: fix operator precedence for logical operations
Fixes https://github.com/fluent/fluent-bit/issues/3763
Summary
This pull request addresses the issue where the precedence of logical operators (AND, OR, NOT) was not defined in the grammar for the stream processor.
Changes Made
- Added precedence rules for
NOT,AND, andORoperators to the Bison grammar file.NOTnow has the highest precedence.ANDhas middle precedence.ORhas the lowest precedence.
Issue Addressed
Fixes GitHub issue: stream_processor: precedence of AND, OR, and NOT not defined in grammar.
Impact
This change ensures that logical operations in conditions are parsed with the correct precedence, aligning with expected logical operation rules.
Testing
Please verify that the logical operations in conditions are handled correctly according to the new precedence rules.
Feel free to reach out if there are any questions or further adjustments needed.
Thanks @unitmatrix, it would be great if the syntax (https://github.com/fluent/fluent-bit/tree/master/src/stream_processor#sql-statement-syntax) can be updated based on your changes as well.
Hi @koleini,
Thank you for your feedback. To ensure that I address your request accurately, I revisited my changes and believe they do not impact the existing SQL statement syntax as outlined in the documentation. Could you please specify which part of the syntax might be affected, or if there are specific updates you have in mind? This will help me make the necessary adjustments to the documentation more effectively.
Looking forward to your guidance. Best regards.
Hi team,
I hope everyone is doing well. I wanted to follow up on this pull request submitted on Sep 14. I've made the necessary updates based on the pipeline checks and have responded to all the questions so far. Could someone please provide an update on the status of this PR? I'm looking forward to any further feedback or actions needed to move this forward.
Thank you for your time!
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.
@koleini @unitmatrix is this ready to go ?
This PR is ready to go, @edsiper.
Hi @unitmatrix, I reviewed the BNF syntax and looks like it requires further cleaning up, which will take care of it.
I am just wondering if your test functions would cover all the combinations and ensures the precedence is implemented correctly: NOT > AND > OR. Would you please verify?
Walkthrough
Adds operator precedence rules for boolean expressions (NOT > AND > OR), updates Bison name-prefix syntax and parser parse-params, adds a destructor for IDENTIFIER tokens, and introduces three tests and callbacks validating boolean precedence in WHERE clauses.
Changes
| Cohort / File(s) | Summary |
|---|---|
Parser grammar updatessrc/stream_processor/parser/sql.y |
Change Bison name-prefix syntax to %name-prefix "flb_sp_"; add precedence/associativity directives (%right NOT, %left AND, %left OR); add +%parse-param { const char *query };; add %destructor { flb_free ($$); } IDENTIFIER; annotate NOT condition with %prec NOT. |
Test callbacks for precedencetests/internal/include/sp_cb_functions.h |
Add three static callbacks: cb_select_and_or_precedence, cb_select_not_or_precedence, cb_select_not_and_precedence that count rows and assert expected results. |
SELECT keys tests for precedencetests/internal/include/sp_select_keys.h |
Append three tests (ids 18β20) exercising AND/OR/NOT precedence with the new callbacks and queries targeting WHERE clauses combining NOT/AND/OR. |
Sequence Diagram(s)
sequenceDiagram
participant Test as Test Case
participant Parser as Lexer/Bison Parser
participant AST as AST
participant Eval as Evaluator
participant CB as Test Callback
Test->>Parser: Submit SQL query with WHERE using NOT/AND/OR
Parser->>AST: Parse and build AST using precedence (NOT > AND > OR)
AST->>Eval: Evaluate expression per row
Eval-->>Test: Return result set
Test->>CB: Invoke callback with results
CB-->>Test: Perform assertions
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~20 minutes
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Define precedence of AND, OR, NOT in grammar and ensure correct parsing semantics (#3763) | β |
Assessment against linked issues: Out-of-scope changes
| Code Change | Explanation |
|---|---|
Change Bison name-prefix directive syntax (src/stream_processor/parser/sql.y) |
Affects generated symbol naming and public symbol names; not required to address operator precedence. |
Added %parse-param { const char *query } to parser signature (src/stream_processor/parser/sql.y) |
Expands parser public API with an extra parameter unrelated to precedence fix or the linked issue. |
I twitch my whiskers, parse the breeze,
NOT hops first, then AND with ease;
OR drifts last along the way,
tests count rows and cheer hoorayβ
carrots crunch, the parser sings π₯π
[!TIP]
π Remote MCP (Model Context Protocol) integration is now available!
Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.
π Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
π‘ Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
π₯ Commits
Reviewing files that changed from the base of the PR and between 53795fc64b9277b7f6487b32a24e46523c9c4be8 and a722215bfbfbc620abe819fb97cc0219f1b9237f.
π Files selected for processing (3)
src/stream_processor/parser/sql.y(3 hunks)tests/internal/include/sp_cb_functions.h(1 hunks)tests/internal/include/sp_select_keys.h(1 hunks)
π§ Files skipped from review as they are similar to previous changes (3)
- tests/internal/include/sp_cb_functions.h
- tests/internal/include/sp_select_keys.h
- src/stream_processor/parser/sql.y
β¨ Finishing Touches
- [ ] π Generate Docstrings
π§ͺ Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
πͺ§ 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.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- 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.
Hi @unitmatrix, I reviewed the BNF syntax and looks like it requires further cleaning up, which will take care of it.
I am just wondering if your test functions would cover all the combinations and ensures the precedence is implemented correctly:
NOT>AND>OR. Would you please verify?
Hi @koleini. Added 'NOT' > 'AND' test for completeness. Thank you.