Skip to content

Extended dialect triat to support numeric prefixed identifiers #1188

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

Merged
merged 3 commits into from
May 3, 2024

Conversation

groobyming
Copy link
Contributor

Relates to #1186. This PR includes changes to resolve the issue and enhance project functionality. Review appreciated.

@coveralls
Copy link

coveralls commented Apr 7, 2024

Pull Request Test Coverage Report for Build 8943194087

Details

  • 32 of 38 (84.21%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.007%) to 89.205%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dialect/hive.rs 1 2 50.0%
src/dialect/mod.rs 1 2 50.0%
src/dialect/mysql.rs 1 2 50.0%
src/tokenizer.rs 29 32 90.63%
Totals Coverage Status
Change from base Build 8943007892: -0.007%
Covered Lines: 24311
Relevant Lines: 27253

💛 - Coveralls

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution @groobyming -- I have a suggestion that I think would make the code cleaner and perhaps also work more like how you want

I apologize for the delay in reviewing

src/tokenizer.rs Outdated
@@ -800,7 +800,9 @@ impl<'a> Tokenizer<'a> {

// mysql dialect supports identifiers that start with a numeric prefix,
// as long as they aren't an exponent number.
if dialect_of!(self is MySqlDialect | HiveDialect) && exponent_part.is_empty() {
if (dialect_of!(self is MySqlDialect | HiveDialect) && exponent_part.is_empty())
|| self.dialect.supports_numeric_prefix()
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why the check for self.dialect.supports_numeric_prefix() doesn't also check exponent_part.is_empty?

That would mean that tokens like 1e4 are going to be parsed as identifiers

What if you wrote this check like

  if self.dialect.supports_numeric_prefix() && exponent_part.is_empty()) {

And then changed MySqlDialect and HiveDialect to return true for supports_numeric_prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion! I overlooked this scenario, and I'll fix this logic issue

@@ -143,6 +143,10 @@ pub trait Dialect: Debug + Any {
fn supports_start_transaction_modifier(&self) -> bool {
false
}
/// Returns true if the dialect supports identifiers that start with a numeric prefix
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add an example of such an identifier? (e.g. 123Column)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our scenario will use numbers as business ids. The rule for table names is the business id plus an underscore followed by the specific table name.
eg:59901_user_login

@alamb
Copy link
Contributor

alamb commented Apr 9, 2024

Marking as draft as I think this PR is no longer waiting on feedback. Please mark it as ready for review when it is ready for another look

@alamb alamb marked this pull request as draft April 9, 2024 20:20
@groobyming groobyming force-pushed the add_support_numeri_prefix branch from 20e3ad5 to b7f0d18 Compare April 15, 2024 03:54
@groobyming groobyming marked this pull request as ready for review April 15, 2024 06:22
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks again @groobyming -- I took the liberty of moving the check to be entirely trait based and merging up to resolve conflicts.

@alamb alamb merged commit 5ea9c01 into apache:main May 3, 2024
10 checks passed
JichaoS pushed a commit to luabase/sqlparser-rs that referenced this pull request May 7, 2024
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