Skip to content

Add ODBC escape syntax support for time expressions #1953

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

Conversation

etgarperets
Copy link
Contributor

…timestamp literals. For this I modified TypedString by adding uses_odbc_syntax flag.

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

Thanks @etgarperets! The changes look good to me overall, left some minor comments

@@ -2016,6 +2018,46 @@ impl<'a> Parser<'a> {
})
}

// Tries to parse the body of an [ODBC escaping sequence]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Tries to parse the body of an [ODBC escaping sequence]
/// Tries to parse the body of an [ODBC escaping sequence]

@@ -2016,6 +2018,46 @@ impl<'a> Parser<'a> {
})
}

// Tries to parse the body of an [ODBC escaping sequence]
Copy link
Contributor

Choose a reason for hiding this comment

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

[ODBC escaping sequence]

Can we include a doc link referencing this part of the comment?


#[test]
fn test_odbc_time_date_timestamp_support() {
let sql_d = "SELECT {d '2025-07-17'}, category_name FROM categories";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we include a negative test for an expression that doesn't use the expected character? e.g. SELECT {tt '14:12:01'} FROM foo

src/ast/mod.rs Outdated
Comment on lines 7425 to 7430
true => match data_type {
DataType::Date => write!(f, "{{d {value}}}"),
DataType::Time(..) => write!(f, "{{t {value}}}"),
DataType::Timestamp(..) => write!(f, "{{ts {value}}}"),
_ => write!(f, "{{? {value}}}"),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
true => match data_type {
DataType::Date => write!(f, "{{d {value}}}"),
DataType::Time(..) => write!(f, "{{t {value}}}"),
DataType::Timestamp(..) => write!(f, "{{ts {value}}}"),
_ => write!(f, "{{? {value}}}"),
},
true => {
let dt = match data_type {
DataType::Date => "d",
DataType::Time(..) => "t"
DataType::Timestamp(..) => "ts",
};
write!("{{ {dt} }}")
},

I think this branch could be simplified to something like above?

@iffyio iffyio changed the title SGA-11414 Added support for odbc escape sequencing for time date and … Add ODBC escape syntax support for time expressions Jul 21, 2025
@etgarperets etgarperets force-pushed the “odbc-time-date-timestamp-support” branch 2 times, most recently from b988fbc to 3b08353 Compare July 24, 2025 13:58
Comment on lines 16327 to 16342
#[test]
#[should_panic]
fn test_invalid_odbc_literal_fails() {
let sql = "SELECT {tt '14:12:01'} FROM foo";
let _ = all_dialects().verified_stmt(sql);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

here's one example of how we do negative tests, can we rewrite to use that pattern instead of the should_panic macro? Also we can inline the scenario into the test_odbc_time_date_timestamp_support function since they belong to the same feature

@@ -16289,6 +16314,23 @@ fn parse_notnull() {
notnull_unsupported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL");
}

#[test]
fn test_odbc_time_date_timestamp_support() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn test_odbc_time_date_timestamp_support() {
fn parse_odbc_time_date_timestamp() {

@etgarperets etgarperets force-pushed the “odbc-time-date-timestamp-support” branch from 3b08353 to 6fe0261 Compare July 27, 2025 07:37
@iffyio
Copy link
Contributor

iffyio commented Jul 28, 2025

@etgarperets could you take a look at resolving the conflicts on the branch when you get the chance?

@etgarperets etgarperets force-pushed the “odbc-time-date-timestamp-support” branch from 6fe0261 to 073c434 Compare July 29, 2025 10:00
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @etgarperets!
cc @alamb

@iffyio iffyio merged commit bde269b into apache:main Jul 29, 2025
10 checks passed
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.

2 participants