Skip to content

Commit 2833f46

Browse files
dssysolyatindssysolyatin
authored and
dssysolyatin
committed
[CALCITE-6624] SqlBabelParser should parse MySQL DATETIME type
1 parent df2328b commit 2833f46

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

babel/src/main/codegen/config.fmpp

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ data: {
176176
"CYCLE"
177177
"DATA"
178178
# "DATE"
179+
"DATETIME"
179180
"DATETIME_DIFF"
180181
"DAY"
181182
"DEALLOCATE"

babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ public static void main(String[] args) throws Exception {
124124
typeFactory.createSqlType(
125125
SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE)))
126126
.connect();
127+
case "scott-mysql":
128+
return CalciteAssert.that()
129+
.with(CalciteAssert.SchemaSpec.SCOTT)
130+
.with(CalciteConnectionProperty.FUN, "standard,mysql")
131+
.with(CalciteConnectionProperty.LEX, Lex.MYSQL)
132+
.with(CalciteConnectionProperty.PARSER_FACTORY,
133+
BabelDdlExecutor.class.getName() + "#PARSER_FACTORY")
134+
.with(CalciteConnectionProperty.CONFORMANCE,
135+
SqlConformanceEnum.BABEL)
136+
.with(CalciteConnectionProperty.LENIENT_OPERATOR_LOOKUP, true)
137+
.with(
138+
ConnectionFactories.addType("DATETIME", typeFactory ->
139+
typeFactory.createSqlType(SqlTypeName.TIMESTAMP)))
140+
.connect();
127141
case "scott-postgresql":
128142
return CalciteAssert.that()
129143
.with(CalciteAssert.SchemaSpec.SCOTT)

babel/src/test/resources/sql/mysql.iq

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# mysql.iq - Babel test for MySQL dialect of SQL
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to you under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
!use scott-mysql
19+
!set outputformat mysql
20+
21+
SELECT cast(cast(TIMESTAMP'1000-01-01 00:00:00' as DATETIME) as DATETIME);
22+
+---------------------+
23+
| EXPR$0 |
24+
+---------------------+
25+
| 1000-01-01 00:00:00 |
26+
+---------------------+
27+
(1 row)
28+
29+
!ok
30+
31+
SELECT cast(cast(TIMESTAMP'9999-12-31 23:59:59' as DATETIME) as DATETIME);
32+
+---------------------+
33+
| EXPR$0 |
34+
+---------------------+
35+
| 9999-12-31 23:59:59 |
36+
+---------------------+
37+
(1 row)
38+
39+
!ok

core/src/main/codegen/templates/Parser.jj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6154,7 +6154,7 @@ SqlTypeNameSpec CharacterTypeName(Span s) :
61546154
}
61556155

61566156
/**
6157-
* Parse datetime types: date, time, timestamp.
6157+
* Parse datetime types: date, time, timestamp, datetime.
61586158
*/
61596159
SqlTypeNameSpec DateTimeTypeName() :
61606160
{

0 commit comments

Comments
 (0)