diff --git a/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java b/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java index 543bfc000719..f16af04c3188 100644 --- a/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java +++ b/babel/src/test/java/org/apache/calcite/test/BabelQuidemTest.java @@ -124,6 +124,20 @@ public static void main(String[] args) throws Exception { typeFactory.createSqlType( SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE))) .connect(); + case "scott-mysql": + return CalciteAssert.that() + .with(CalciteAssert.SchemaSpec.SCOTT) + .with(CalciteConnectionProperty.FUN, "standard,mysql") + .with(CalciteConnectionProperty.LEX, Lex.MYSQL) + .with(CalciteConnectionProperty.PARSER_FACTORY, + BabelDdlExecutor.class.getName() + "#PARSER_FACTORY") + .with(CalciteConnectionProperty.CONFORMANCE, + SqlConformanceEnum.BABEL) + .with(CalciteConnectionProperty.LENIENT_OPERATOR_LOOKUP, true) + .with( + ConnectionFactories.addType("DATETIME", typeFactory -> + typeFactory.createSqlType(SqlTypeName.TIMESTAMP))) + .connect(); case "scott-postgresql": return CalciteAssert.that() .with(CalciteAssert.SchemaSpec.SCOTT) diff --git a/babel/src/test/resources/sql/mysql.iq b/babel/src/test/resources/sql/mysql.iq new file mode 100644 index 000000000000..72ba18761f1f --- /dev/null +++ b/babel/src/test/resources/sql/mysql.iq @@ -0,0 +1,22 @@ +!use scott-mysql +!set outputformat mysql + +SELECT cast(cast(DATETIME '1000-01-01 00:00:00' as DATETIME) as DATETIME); ++---------------------+ +| EXPR$0 | ++---------------------+ +| 1000-01-01 00:00:00 | ++---------------------+ +(1 row) + +!ok + +SELECT cast(cast(DATETIME '9999-12-31 23:59:59' as DATETIME) as DATETIME); ++---------------------+ +| EXPR$0 | ++---------------------+ +| 9999-12-31 23:59:59 | ++---------------------+ +(1 row) + +!ok diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index b26efd896e6d..874ef4c8d6d7 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -6154,7 +6154,7 @@ SqlTypeNameSpec CharacterTypeName(Span s) : } /** -* Parse datetime types: date, time, timestamp. +* Parse datetime types: date, time, timestamp, datetime. */ SqlTypeNameSpec DateTimeTypeName() : { @@ -6182,6 +6182,12 @@ SqlTypeNameSpec DateTimeTypeName() : { return new SqlBasicTypeNameSpec(typeName, precision, s.end(this)); } +| + { s = span(); } + precision = PrecisionOpt() + { + return new SqlBasicTypeNameSpec(SqlTypeName.TIMESTAMP, precision, s.end(this)); + } } // Parse an optional data type precision, default is -1.