You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/10/15 11:27:05 UTC

(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2636-5d653a257a9dd981be1f2200c184b20547e75cf0 created (now 7cac9e17)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-2636-5d653a257a9dd981be1f2200c184b20547e75cf0
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


      at 7cac9e17 MySQL: Add support for `ZEROFILL` on numeric data types (#2636)

This branch includes the following new commits:

     new 7cac9e17 MySQL: Add support for `ZEROFILL` on numeric data types (#2636)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org


(datafusion-sqlparser-rs) 01/01: MySQL: Add support for `ZEROFILL` on numeric data types (#2636)

Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-2636-5d653a257a9dd981be1f2200c184b20547e75cf0
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit 7cac9e17a216f2d0bf0e852fd0758173d516fc76
Author: Johnathan Davis <da...@users.noreply.github.com>
AuthorDate: Thu Oct 15 11:26:40 2026 +0000

    MySQL: Add support for `ZEROFILL` on numeric data types (#2636)
---
 src/ast/data_type.rs     |  5 +++++
 src/dialect/generic.rs   |  4 ++++
 src/dialect/mod.rs       | 12 ++++++++++++
 src/dialect/mysql.rs     |  4 ++++
 src/keywords.rs          |  1 +
 src/parser/mod.rs        | 33 +++++++++++++++++++++++++++++++++
 tests/sqlparser_mysql.rs | 34 ++++++++++++++++++++++++++++++++++
 7 files changed, 93 insertions(+)

diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index 7b38f8c4..0a31ead3 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -346,6 +346,10 @@ pub enum DataType {
     ///
     /// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/numeric-type-syntax.html
     DoublePrecisionUnsigned,
+    /// [MySQL] numeric type padded with zeros, e.g. `INT(10) UNSIGNED ZEROFILL`.
+    ///
+    /// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/numeric-type-syntax.html
+    Zerofill(Box<DataType>),
     /// Bool is an alias for Boolean, see [PostgreSQL].
     ///
     /// [PostgreSQL]: https://www.postgresql.org/docs/current/datatype.html
@@ -672,6 +676,7 @@ impl fmt::Display for DataType {
             DataType::Float8 => write!(f, "FLOAT8"),
             DataType::DoublePrecision => write!(f, "DOUBLE PRECISION"),
             DataType::DoublePrecisionUnsigned => write!(f, "DOUBLE PRECISION UNSIGNED"),
+            DataType::Zerofill(data_type) => write!(f, "{data_type} ZEROFILL"),
             DataType::Bool => write!(f, "BOOL"),
             DataType::Boolean => write!(f, "BOOLEAN"),
             DataType::Date => write!(f, "DATE"),
diff --git a/src/dialect/generic.rs b/src/dialect/generic.rs
index 09a55185..694eb8f1 100644
--- a/src/dialect/generic.rs
+++ b/src/dialect/generic.rs
@@ -237,6 +237,10 @@ impl Dialect for GenericDialect {
         true
     }
 
+    fn supports_data_type_zerofill_suffix(&self) -> bool {
+        true
+    }
+
     fn supports_interval_options(&self) -> bool {
         true
     }
diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs
index f57907e1..bb6826f0 100644
--- a/src/dialect/mod.rs
+++ b/src/dialect/mod.rs
@@ -1648,6 +1648,18 @@ pub trait Dialect: Debug + Any {
         false
     }
 
+    /// Returns true if this dialect allows an optional `ZEROFILL` suffix after numeric data types.
+    ///
+    /// Example:
+    /// ```sql
+    /// CREATE TABLE t (i INT(10) UNSIGNED ZEROFILL);
+    /// ```
+    ///
+    /// <https://dev.mysql.com/doc/refman/8.4/en/numeric-type-syntax.html>
+    fn supports_data_type_zerofill_suffix(&self) -> bool {
+        false
+    }
+
     /// Returns true if the dialect supports the `INTERVAL` data type with [Postgres]-style options.
     ///
     /// Examples:
diff --git a/src/dialect/mysql.rs b/src/dialect/mysql.rs
index 4bfa17a6..97bdfe30 100644
--- a/src/dialect/mysql.rs
+++ b/src/dialect/mysql.rs
@@ -193,6 +193,10 @@ impl Dialect for MySqlDialect {
         true
     }
 
+    fn supports_data_type_zerofill_suffix(&self) -> bool {
+        true
+    }
+
     fn supports_cross_join_constraint(&self) -> bool {
         true
     }
diff --git a/src/keywords.rs b/src/keywords.rs
index deae7bbd..37adf45c 100644
--- a/src/keywords.rs
+++ b/src/keywords.rs
@@ -1190,6 +1190,7 @@ define_keywords!(
     YEAR,
     YEARS,
     YES,
+    ZEROFILL,
     ZONE,
     ZORDER,
     ZSTD
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 6daad0f6..ae435c91 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -13411,6 +13411,10 @@ impl<'a> Parser<'a> {
             _ => self.expected_at("a data type name", next_token_index),
         }?;
 
+        if self.is_zerofill_allowed(next_token_index) && self.parse_keyword(Keyword::ZEROFILL) {
+            data = DataType::Zerofill(Box::new(data));
+        }
+
         if self.dialect.supports_array_typedef_with_brackets() {
             while self.consume_token(&Token::LBracket) {
                 // Parse optional array data type size
@@ -13449,6 +13453,35 @@ impl<'a> Parser<'a> {
         Ok((data_type, trailing_bracket))
     }
 
+    fn is_zerofill_allowed(&self, token_index: usize) -> bool {
+        if !self.dialect.supports_data_type_zerofill_suffix() {
+            return false;
+        }
+        match &self.token_at(token_index).token {
+            Token::Word(w) => matches!(
+                w.keyword,
+                Keyword::TINYINT
+                    | Keyword::SMALLINT
+                    | Keyword::MEDIUMINT
+                    | Keyword::INT
+                    | Keyword::INTEGER
+                    | Keyword::BIGINT
+                    | Keyword::INT2
+                    | Keyword::INT4
+                    | Keyword::INT8
+                    | Keyword::DECIMAL
+                    | Keyword::DEC
+                    | Keyword::NUMERIC
+                    | Keyword::FLOAT
+                    | Keyword::FLOAT4
+                    | Keyword::FLOAT8
+                    | Keyword::DOUBLE
+                    | Keyword::REAL
+            ),
+            _ => false,
+        }
+    }
+
     fn parse_returns_table_column(&mut self) -> Result<ColumnDef, ParserError> {
         self.parse_column_def()
     }
diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs
index e3fa77f0..369d4d69 100644
--- a/tests/sqlparser_mysql.rs
+++ b/tests/sqlparser_mysql.rs
@@ -1915,6 +1915,40 @@ fn parse_deprecated_mysql_unsigned_data_types() {
     }
 }
 
+#[test]
+fn parse_zerofill() {
+    for data_type in [
+        "TINYINT",
+        "SMALLINT",
+        "MEDIUMINT",
+        "INT",
+        "INTEGER",
+        "BIGINT",
+        "INT2",
+        "INT4",
+        "INT8",
+        "DECIMAL",
+        "DEC",
+        "NUMERIC",
+        "FLOAT",
+        "FLOAT4",
+        "FLOAT8",
+        "DOUBLE",
+        "REAL",
+    ] {
+        mysql_and_generic().verified_stmt(&format!("CREATE TABLE t (a {data_type} ZEROFILL)"));
+    }
+    mysql_and_generic().verified_stmt("CREATE TABLE t (a INT(10) UNSIGNED ZEROFILL)");
+    assert!(mysql_and_generic()
+        .parse_sql_statements("CREATE TABLE t (a VARCHAR(10) ZEROFILL)")
+        .is_err());
+    assert!(
+        all_dialects_except(|d| d.supports_data_type_zerofill_suffix())
+            .parse_sql_statements("CREATE TABLE t (a INT ZEROFILL)")
+            .is_err()
+    );
+}
+
 #[test]
 fn parse_simple_insert() {
     let sql = r"INSERT INTO tasks (title, priority) VALUES ('Test Some Inserts', 1), ('Test Entry 2', 2), ('Test Entry 3', 3)";


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org