Skip to content

Conversation

@watarukura
Copy link
Contributor

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

CREATE TABLE `warehouses` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

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 7.64s
     Running `target/debug/examples/cli create_table.sql --mysql`
Parsing from file 'create_table.sql' using MySqlDialect
2022-02-20T07:04:04.134Z DEBUG [sqlparser::parser] Parsing sql 'CREATE TABLE `warehouses` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
'...
Error during parsing: ParserError("Expected end of statement, found: COLLATE")

add table's collation definition.

❯ 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 6.45s
     Running `target/debug/examples/cli create_table.sql --mysql`
Parsing from file 'create_table.sql' using MySqlDialect
2022-02-20T07:06:01.449Z DEBUG [sqlparser::parser] Parsing sql 'CREATE TABLE `warehouses` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
'...
Round-trip:
'CREATE TABLE `warehouses` (`id` BIGINT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci'
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": "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",
      "collation": "utf8mb4_0900_ai_ci"
    }
  }
]

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1871206212

  • 24 of 25 (96.0%) changed or added relevant lines in 3 files are covered.
  • 6 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.03%) to 90.546%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser.rs 7 8 87.5%
Files with Coverage Reduction New Missed Lines %
src/tokenizer.rs 1 90.44%
src/ast/query.rs 2 86.12%
src/ast/mod.rs 3 77.74%
Totals Coverage Status
Change from base Build 1858728297: -0.03%
Covered Lines: 7126
Relevant Lines: 7870

💛 - Coveralls

@alamb alamb changed the title mysql table collation Support COLLATION keywork on CREATE TABLE Feb 28, 2022
@alamb
Copy link
Contributor

alamb commented Feb 28, 2022

Thanks @watarukura

@alamb alamb merged commit 2ebe18a into apache:main Feb 28, 2022
@alamb alamb changed the title Support COLLATION keywork on CREATE TABLE Support COLLATE keywork on CREATE TABLE Feb 28, 2022
@alamb alamb changed the title Support COLLATE keywork on CREATE TABLE Support COLLATE keyword on CREATE TABLE Feb 28, 2022
@watarukura watarukura deleted the feat/mysql_table_collate branch March 2, 2022 03:38
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