mvzink commented on code in PR #2172:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2172#discussion_r2765519168
##########
src/parser/mod.rs:
##########
@@ -14032,6 +14050,79 @@ impl<'a> Parser<'a> {
})
}
+ /// Parses SELECT modifiers and DISTINCT/ALL in any order. Allows
HIGH_PRIORITY, STRAIGHT_JOIN,
+ /// SQL_SMALL_RESULT, SQL_BIG_RESULT, SQL_BUFFER_RESULT, SQL_NO_CACHE,
SQL_CALC_FOUND_ROWS and
+ /// DISTINCT/DISTINCTROW/ALL to appear in any order.
+ fn parse_select_modifiers(
+ &mut self,
+ ) -> Result<(SelectModifiers, Option<Distinct>), ParserError> {
+ let mut modifiers = SelectModifiers::default();
+ let mut distinct: Option<Distinct> = None;
+ let mut has_all = false;
+
+ let keywords = &[
+ Keyword::ALL,
+ Keyword::DISTINCT,
+ Keyword::DISTINCTROW,
+ Keyword::HIGH_PRIORITY,
+ Keyword::STRAIGHT_JOIN,
+ Keyword::SQL_SMALL_RESULT,
+ Keyword::SQL_BIG_RESULT,
+ Keyword::SQL_BUFFER_RESULT,
+ Keyword::SQL_NO_CACHE,
+ Keyword::SQL_CALC_FOUND_ROWS,
+ ];
+
+ while let Some(keyword) = self.parse_one_of_keywords(keywords) {
+ match keyword {
+ Keyword::ALL => {
+ if has_all {
+ self.prev_token();
+ return self.expected("SELECT without duplicate ALL",
self.peek_token());
+ }
+ if distinct.is_some() {
+ self.prev_token();
+ return self.expected("DISTINCT alone without ALL",
self.peek_token());
+ }
+ has_all = true;
+ }
+ Keyword::DISTINCT | Keyword::DISTINCTROW => {
+ if distinct.is_some() {
+ self.prev_token();
+ return self.expected(
+ "SELECT without duplicate DISTINCT or DISTINCTROW",
+ self.peek_token(),
+ );
+ }
+ if has_all {
+ self.prev_token();
+ return self.expected(
+ "ALL alone without DISTINCT or DISTINCTROW",
+ self.peek_token(),
+ );
+ }
+ distinct = Some(Distinct::Distinct);
+ }
+ Keyword::HIGH_PRIORITY => modifiers.high_priority = true,
Review Comment:
They are all allowed multiple times, but that took manual testing to find
out. I'll add a test and a comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]