From 42206a978c29819c4bba32735022855fdf06a863 Mon Sep 17 00:00:00 2001 From: dssysolyatin Date: Fri, 11 Oct 2024 18:34:17 +0300 Subject: [PATCH] [CALCITE-6624] SqlBabelParser should parse MySQL DATETIME type --- babel/src/main/codegen/config.fmpp | 1 + .../apache/calcite/test/BabelQuidemTest.java | 14 +++++++ babel/src/test/resources/sql/mysql.iq | 39 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 babel/src/test/resources/sql/mysql.iq diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index bf5895c7c7d0..03208e30f7fc 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -176,6 +176,7 @@ data: { "CYCLE" "DATA" # "DATE" + "DATETIME" "DATETIME_DIFF" "DAY" "DEALLOCATE" 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..fab79097e368 --- /dev/null +++ b/babel/src/test/resources/sql/mysql.iq @@ -0,0 +1,39 @@ +# mysql.iq - Babel test for MySQL dialect of SQL +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +!use scott-mysql +!set outputformat mysql + +SELECT cast(cast(TIMESTAMP'1000-01-01 00:00:00' as DATETIME) as DATETIME); ++---------------------+ +| EXPR$0 | ++---------------------+ +| 1000-01-01 00:00:00 | ++---------------------+ +(1 row) + +!ok + +SELECT cast(cast(TIMESTAMP'9999-12-31 23:59:59' as DATETIME) as DATETIME); ++---------------------+ +| EXPR$0 | ++---------------------+ +| 9999-12-31 23:59:59 | ++---------------------+ +(1 row) + +!ok