Skip to content

Commit b24d053

Browse files
dssysolyatindssysolyatin
authored andcommitted
[CALCITE-6624] SqlParser should parse MySQL DATETIME type
1 parent 7ce986f commit b24d053

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
!use scott-mysql
2+
!set outputformat mysql
3+
4+
SELECT cast(cast(DATETIME '1000-01-01 00:00:00' as DATETIME) as DATETIME);
5+
+---------------------+
6+
| EXPR$0 |
7+
+---------------------+
8+
| 1000-01-01 00:00:00 |
9+
+---------------------+
10+
(1 row)
11+
12+
!ok
13+
14+
SELECT cast(cast(DATETIME '9999-12-31 23:59:59' as DATETIME) as DATETIME);
15+
+---------------------+
16+
| EXPR$0 |
17+
+---------------------+
18+
| 9999-12-31 23:59:59 |
19+
+---------------------+
20+
(1 row)
21+
22+
!ok

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

Lines changed: 7 additions & 1 deletion
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
{
@@ -6182,6 +6182,12 @@ SqlTypeNameSpec DateTimeTypeName() :
61826182
{
61836183
return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));
61846184
}
6185+
|
6186+
<DATETIME> { s = span(); }
6187+
precision = PrecisionOpt()
6188+
{
6189+
return new SqlBasicTypeNameSpec(SqlTypeName.TIMESTAMP, precision, s.end(this));
6190+
}
61856191
}
61866192

61876193
// Parse an optional data type precision, default is -1.

0 commit comments

Comments
 (0)