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

feat(logicaldatabase): logical table expression parser #2274

Merged
merged 20 commits into from
Apr 29, 2024

Conversation

MarkPotato777
Copy link
Collaborator

@MarkPotato777 MarkPotato777 commented Apr 22, 2024

What type of PR is this?

type-feature

What this PR does / why we need it:

This PR supports parsing logical table expressions.

  1. The syntax for logic table expressions has been defined using ANTLR4, and the auto-generated Visitor class from ANTLR4 has been extended to implement specific business logic.
  2. The syntax supports multiple logic table expressions connected by commas to avoid writing separate clause logic. At the business layer, the caller does not need to worry about whether it is a single expression or a list of expressions separated by commas; in fact, it can be considered as one expression either way.
  3. More specifically, this leverages the BaseStatement abstraction defined by the ob-sql-parser to avoid some repetitive tasks, such as getText, getStart, getStop, etc.
  4. The entry class is LogicalTableService#resolve, which is used to parse an expression into a List<DataNode>. Its implementation uses DefaultLogicalTableExpressionParser to parse and obtain BaseLogicalTableExpression, and then calls BaseLogicalTableExpression#evaluate to compute all the values derived from the expression.
  5. The custom exception BadExpressionException has been defined for scenarios involving illegal expressions. This may be due to lexical or syntactic errors detected by ANTLR4 parsing, or could be semantic errors defined at the business layer, such as the requirement for the number of tables to be evenly divisible by the number of databases.
  6. Furthermore, unit tests are divided into two parts: scenarios where the expression is invalid and scenarios where the expression is valid.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Additional documentation e.g., usage docs, etc.:


@MarkPotato777 MarkPotato777 added the type-feature The functionality to be implemented label Apr 22, 2024
@MarkPotato777 MarkPotato777 added this to the ODC 4.3.0 milestone Apr 22, 2024
@MarkPotato777 MarkPotato777 self-assigned this Apr 22, 2024
@MarkPotato777 MarkPotato777 marked this pull request as draft April 22, 2024 14:09
@yhilmare yhilmare changed the title feat(logicaldatabase): logical table expression parser [WIP] feat(logicaldatabase): logical table expression parser Apr 23, 2024
@MarkPotato777 MarkPotato777 marked this pull request as ready for review April 23, 2024 12:58
@MarkPotato777 MarkPotato777 changed the title [WIP] feat(logicaldatabase): logical table expression parser feat(logicaldatabase): logical table expression parser Apr 23, 2024
Copy link
Contributor

@yizhouxw yizhouxw left a comment

Choose a reason for hiding this comment

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

great job 👍

Copy link
Contributor

@yhilmare yhilmare left a comment

Choose a reason for hiding this comment

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

lgtm

@yhilmare yhilmare merged commit 2291333 into dev/4.3.x Apr 29, 2024
11 checks passed
@yhilmare yhilmare deleted the lebie_430_logicaldatabase_expression_parse_0416 branch April 29, 2024 01:53
Copy link
Collaborator

@PeachThinking PeachThinking left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature The functionality to be implemented
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants