Skip to content

Conversation

@watarukura
Copy link
Contributor

This MySQL DDL I'm using in my project has the following definition.

❯ cat create_table.sql
CREATE TABLE `warehouses` (
  `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

ParseError occurred.

❯ cargo run --features json_example --example cli create_table.sql --mysql
   Compiling sqlparser v0.14.0 (/Users/watarukura/src/github.com/sqlparser-rs/sqlparser-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 9.47s
     Running `target/debug/examples/cli create_table.sql --mysql`
Parsing from file 'create_table.sql' using MySqlDialect
2022-02-20T08:14:31.123Z DEBUG [sqlparser::parser] Parsing sql 'CREATE TABLE `warehouses` (
  `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
'...
Error during parsing: ParserError("Expected ',' or ')' after column definition, found: UNSIGNED")

add UNSIGNED to column option for MySQL Dialect.

❯ cargo run --features json_example --example cli create_table.sql --mysql
   Compiling sqlparser v0.14.0 (/Users/watarukura/src/github.com/sqlparser-rs/sqlparser-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 7.95s
     Running `target/debug/examples/cli create_table.sql --mysql`
Parsing from file 'create_table.sql' using MySqlDialect
2022-02-20T08:15:27.661Z DEBUG [sqlparser::parser] Parsing sql 'CREATE TABLE `warehouses` (
  `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
'...
Round-trip:
'CREATE TABLE `warehouses` (`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4'
Serialized as JSON:
[
  {
    "CreateTable": {
      "or_replace": false,
      "temporary": false,
      "external": false,
      "if_not_exists": false,
      "name": [
        {
          "value": "warehouses",
          "quote_style": "`"
        }
      ],
      "columns": [
        {
          "name": {
            "value": "id",
            "quote_style": "`"
          },
          "data_type": {
            "BigInt": null
          },
          "collation": null,
          "options": [
            {
              "name": null,
              "option": "Unsigned"
            },
            {
              "name": null,
              "option": "NotNull"
            },
            {
              "name": null,
              "option": {
                "DialectSpecific": [
                  {
                    "Word": {
                      "value": "AUTO_INCREMENT",
                      "quote_style": null,
                      "keyword": "AUTO_INCREMENT"
                    }
                  }
                ]
              }
            }
          ]
        }
      ],
      "constraints": [
        {
          "Unique": {
            "name": null,
            "columns": [
              {
                "value": "id",
                "quote_style": "`"
              }
            ],
            "is_primary": true
          }
        }
      ],
      "hive_distribution": "NONE",
      "hive_formats": {
        "row_format": null,
        "storage": null,
        "location": null
      },
      "table_properties": [],
      "with_options": [],
      "file_format": null,
      "location": null,
      "query": null,
      "without_rowid": false,
      "like": null,
      "engine": "InnoDB",
      "default_charset": "utf8mb4"
    }
  }
]

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1871338205

  • 18 of 25 (72.0%) changed or added relevant lines in 3 files are covered.
  • 5 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.1%) to 90.47%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser.rs 4 11 36.36%
Files with Coverage Reduction New Missed Lines %
src/tokenizer.rs 1 90.44%
src/ast/mod.rs 2 77.67%
src/ast/query.rs 2 86.12%
Totals Coverage Status
Change from base Build 1858728297: -0.1%
Covered Lines: 7120
Relevant Lines: 7870

💛 - 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.

Sorry for the delayed review @watarukura -- I have been away. I don't think adding UNSIGNED as ColumnOption is correct -- it should be a data type instead

DialectSpecific(Vec<Token>),
CharacterSet(ObjectName),
Comment(String),
Unsigned,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think UNSIGNED is a DataType (not an option on the column definition)

Specifically you can do something like

mysql> select cast(x as unsigned) from bar;
+---------------------+
| cast(x as unsigned) |
+---------------------+
|                   1 |
|                NULL |
+---------------------+
2 rows in set (0.00 sec)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for good review!
I think too, close this pull request, and I will retry.

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.

4 participants