You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/04/17 04:29:43 UTC

[GitHub] [flink] JingsongLi commented on a change in pull request #8184: [FLINK-12211][table-planner-blink] Add more it cases to blink batch

JingsongLi commented on a change in pull request #8184: [FLINK-12211][table-planner-blink] Add more it cases to blink batch
URL: https://github.com/apache/flink/pull/8184#discussion_r276075315
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/runtime/batch/sql/DateFunctionsITCase.scala
 ##########
 @@ -0,0 +1,253 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.table.runtime.batch.sql
+
+import org.apache.flink.table.api.TableConfigOptions
+import org.apache.flink.table.dataformat.DataFormatConverters.{DateConverter, TimestampConverter}
+import org.apache.flink.table.runtime.utils.BatchTestBase
+import org.apache.flink.table.runtime.utils.BatchTestBase.row
+import org.apache.flink.table.runtime.utils.TestData._
+import org.apache.flink.table.util.DateTimeTestUtil._
+
+import org.junit.{Assert, Before, Ignore, Test}
+
+import java.sql.Date
+
+class DateFunctionsITCase extends BatchTestBase {
+
+  @Before
+  def before(): Unit = {
+    tEnv.getConfig.getConf.setInteger(TableConfigOptions.SQL_RESOURCE_DEFAULT_PARALLELISM, 3)
+    registerCollection("testTable", buildInData, buildInType, "a,b,c,d,e,f,g,h,i,j")
+  }
+
+  @Test
+  def testCurrentDate(): Unit = {
+    // Execution in on Query should return the same value
+    checkResult("SELECT CURRENT_DATE = CURRENT_DATE FROM testTable WHERE a = TRUE",
+      Seq(row(true)))
+
+    val d0 = DateConverter.INSTANCE.toInternal(new Date(System.currentTimeMillis()))
+
+    val table = parseQuery("SELECT CURRENT_DATE FROM testTable WHERE a = TRUE")
+    val result = executeQuery(table)
+    val d1 = DateConverter.INSTANCE.toInternal(
+      result.toList.head.getField(0).asInstanceOf[java.sql.Date])
+
+    Assert.assertTrue(d0 <= d1 && d1 - d0 <= 1)
+  }
+
+  @Test
+  def testCurrentTimestamp(): Unit = {
+    // Execution in on Query should return the same value
+    checkResult("SELECT CURRENT_TIMESTAMP = CURRENT_TIMESTAMP FROM testTable WHERE a = TRUE",
+      Seq(row(true)))
+
+    // CURRENT_TIMESTAMP should return the current timestamp
+    val ts0 = System.currentTimeMillis()
+
+    val table = parseQuery("SELECT CURRENT_TIMESTAMP FROM testTable WHERE a = TRUE")
+    val result = executeQuery(table)
+    val ts1 = TimestampConverter.INSTANCE.toInternal(
+                result.toList.head.getField(0).asInstanceOf[java.sql.Timestamp])
+
+    val ts2 = System.currentTimeMillis()
+
+    Assert.assertTrue(ts0 <= ts1 && ts1 <= ts2)
+  }
+
+  @Test
+  def testCurrentTime(): Unit = {
+    // Execution in on Query should return the same value
+    checkResult("SELECT CURRENT_TIME = CURRENT_TIME FROM testTable WHERE a = TRUE",
+      Seq(row(true)))
+  }
+
+  def testTimestampCompareWithDate(): Unit = {
+    checkResult("SELECT j FROM testTable WHERE j < DATE '2017-11-11'",
+      Seq(row(true)))
+  }
+
+  @Test
+  def testTimestampCompareWithDateString(): Unit = {
+    //j 2015-05-20 10:00:00.887
+    checkResult("SELECT j FROM testTable WHERE j < '2017-11-11'",
+      Seq(row(UTCTimestamp("2015-05-20 10:00:00.887"))))
+  }
+
+  @Test
+  def testDateCompareWithDateString(): Unit = {
+    checkResult("SELECT h FROM testTable WHERE h <= '2017-12-12'",
+      Seq(
+        row(UTCDate("2017-12-12")),
+        row(UTCDate("2017-12-12"))
+      ))
+  }
+
+  @Ignore
+  @Test
+  def testDateEqualsWithDateString(): Unit = {
+    // TODO: May be a bug
 
 Review comment:
   It is a legacy of the past, no longer a bug.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services