You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "iffyio (via GitHub)" <gi...@apache.org> on 2026/02/03 13:36:45 UTC
Re: [PR] MySQL: Add support for DEFAULT CHARACTER SET in CREATE DATABASE [datafusion-sqlparser-rs]
iffyio commented on code in PR #2182:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2182#discussion_r2759095945
##########
src/ast/helpers/stmt_create_database.rs:
##########
@@ -85,6 +85,10 @@ pub struct CreateDatabaseBuilder {
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
/// Optional comment attached to the database.
pub comment: Option<String>,
+ /// Optional default character set (MySQL).
Review Comment:
can we include a link to the mysql documentation for the doc comments?
##########
src/parser/mod.rs:
##########
@@ -5309,6 +5311,26 @@ impl<'a> Parser<'a> {
None
};
+ // Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options
+ loop {
+ let has_default = self.parse_keyword(Keyword::DEFAULT);
+ if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET])
+ || self.parse_keyword(Keyword::CHARSET)
+ {
+ self.expect_token(&Token::Eq).ok();
+ default_charset = Some(self.parse_identifier()?.value);
+ } else if self.parse_keyword(Keyword::COLLATE) {
+ self.expect_token(&Token::Eq).ok();
Review Comment:
can we handle the errors in the calls to `expect_token`?
##########
src/parser/mod.rs:
##########
@@ -5309,6 +5311,26 @@ impl<'a> Parser<'a> {
None
};
+ // Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options
Review Comment:
Can we move the `default_charset` and `default_collation` closer here to the loop? (misread for a second wondering if the values were being previously set elsewhere before the loop)
##########
src/parser/mod.rs:
##########
@@ -5309,6 +5311,26 @@ impl<'a> Parser<'a> {
None
};
+ // Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options
+ loop {
+ let has_default = self.parse_keyword(Keyword::DEFAULT);
+ if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET])
+ || self.parse_keyword(Keyword::CHARSET)
+ {
+ self.expect_token(&Token::Eq).ok();
+ default_charset = Some(self.parse_identifier()?.value);
+ } else if self.parse_keyword(Keyword::COLLATE) {
Review Comment:
```suggestion
} else if default_collation.is_none() && self.parse_keyword(Keyword::COLLATE) {
```
##########
src/parser/mod.rs:
##########
@@ -5309,6 +5311,26 @@ impl<'a> Parser<'a> {
None
};
+ // Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options
+ loop {
+ let has_default = self.parse_keyword(Keyword::DEFAULT);
+ if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET])
Review Comment:
```suggestion
if default_charset.is_none() && self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET])
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org