Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6624] SqlParser should parse MySQL DATETIME type #4002

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dssysolyatin
Copy link
Contributor

No description provided.

@dssysolyatin dssysolyatin force-pushed the feature/support-mysql-datetime-type-parsing branch from b24d053 to 86e204b Compare October 11, 2024 15:56
@@ -6182,6 +6182,12 @@ SqlTypeNameSpec DateTimeTypeName() :
{
return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));
}
|
Copy link
Contributor

Choose a reason for hiding this comment

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

is this supposed to be in Babel?

Copy link
Contributor Author

@dssysolyatin dssysolyatin Oct 13, 2024

Choose a reason for hiding this comment

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

Regarding Babel, my initial plan was to implement DATETIME datatype parsing at the Babel parser level, but I noticed that we have DATETIME literal parsing for BigQuery inside Parser.jj, which is also valid for MySQL. Therefore, I decided to put DATETIME type parsing in Parser.jj, as it would be better to have both DATETIME datatype parsing and DATETIME literal parsing in the same place.

@dssysolyatin dssysolyatin force-pushed the feature/support-mysql-datetime-type-parsing branch 2 times, most recently from 492a2ae to 2833f46 Compare October 17, 2024 11:41
@dssysolyatin dssysolyatin force-pushed the feature/support-mysql-datetime-type-parsing branch from 2833f46 to 42206a9 Compare October 17, 2024 11:42
@dssysolyatin dssysolyatin changed the title [CALCITE-6624] SqlParser should parse MySQL DATETIME type [CALCITE-6624] SqlBabelParser should parse MySQL DATETIME type Oct 17, 2024
Copy link

Please retry analysis of this Pull-Request directly on SonarCloud


!ok

SELECT cast(cast(TIMESTAMP'9999-12-31 23:59:59' as DATETIME) as DATETIME);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also write DATETIME '1000-01-01 00:00:00'?
Are you supposed to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MySQL syntax is kind of messy

  1. Time literals can only be defined using DATE 'str', TIME 'str', or TIMESTAMP 'str'. There is no syntax like DATETIME 'str'.

  2. The TIMESTAMP syntax produces a DATETIME value in MySQL because DATETIME has a range that more closely corresponds to the standard SQL TIMESTAMP type, which has a year range from 0001 to 9999. (The MySQL TIMESTAMP year range is 1970 to 2038.)

Currently, SELECT DATETIME '1000-01-01 00:00:00' works in Calcite when using the MySQL dialect. Ideally, it should throw an exception. However, I’m not sure if anyone actually needs this behavior or if it’s worth spending time on.

@mihaibudiu mihaibudiu changed the title [CALCITE-6624] SqlBabelParser should parse MySQL DATETIME type [CALCITE-6624] SqlParser should parse MySQL DATETIME type Nov 28, 2024
@mihaibudiu
Copy link
Contributor

If we decide that this is a useful feature, the PR is fine.
I was very confused by the PR title (and the commit message). I changed the PR title to match the issue title, that's better.
I am worried that DATETIME means different things in different contexts.

@mihaibudiu
Copy link
Contributor

Anyone else wants to comment on this issue?
I think the PR is fine if we accept the fact that the issue is a problem.

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.

2 participants