uros-db commented on code in PR #46618:
URL: https://github.com/apache/spark/pull/46618#discussion_r1606726766


##########
sql/core/src/test/scala/org/apache/spark/sql/CollationSQLExpressionsSuite.scala:
##########
@@ -1584,6 +1587,237 @@ class CollationSQLExpressionsSuite
     })
   }
 
+  test("CurrentTimeZone expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query = "select current_timezone()"
+      // Data type check
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = StringType(collationName)
+        assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      }
+    })
+  }
+
+  test("DayName expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query = "select dayname(current_date())"
+      // Data type check
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = StringType(collationName)
+        assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      }
+    })
+  }
+
+  test("ToUnixTimestamp expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select to_unix_timestamp(collate('2021-01-01 00:00:00', 
'${collationName}'),
+          |collate('yyyy-MM-dd HH:mm:ss', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = LongType
+      val expectedResult = 1609488000L
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(expectedResult))
+    })
+  }
+
+  test("FromUnixTime expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select from_unixtime(1609488000, collate('yyyy-MM-dd HH:mm:ss', 
'${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = StringType(collationName)
+        val expectedResult = "2021-01-01 00:00:00"
+        assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+        checkAnswer(testQuery, Row(expectedResult))
+      }
+    })
+  }
+
+  test("NextDay expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select next_day('2015-01-14', collate('TU', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = DateType
+        val expectedResult = "2015-01-20"
+        assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+        checkAnswer(testQuery, Row(Date.valueOf(expectedResult)))
+      }
+    })
+  }
+
+  test("FromUTCTimestamp expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select from_utc_timestamp(collate('2016-08-31', '${collationName}'),
+          |collate('Asia/Seoul', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2016-08-31 09:00:00.0"
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(Timestamp.valueOf(expectedResult)))
+    })
+  }
+
+  test("ToUTCTimestamp expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select to_utc_timestamp(collate('2016-08-31 09:00:00', 
'${collationName}'),
+          |collate('Asia/Seoul', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2016-08-31 00:00:00.0"
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(Timestamp.valueOf(expectedResult)))
+    })
+  }
+
+  test("ParseToDate expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select to_date(collate('2016-12-31', '${collationName}'),
+          |collate('yyyy-MM-dd', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = DateType
+      val expectedResult = "2016-12-31"
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(Date.valueOf(expectedResult)))
+    })
+  }
+
+  test("ParseToTimestamp expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select to_timestamp(collate('2016-12-31 23:59:59', 
'${collationName}'),
+          |collate('yyyy-MM-dd HH:mm:ss', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2016-12-31 23:59:59.0"
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(Timestamp.valueOf(expectedResult)))
+    })
+  }
+
+  test("TruncDate expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select trunc(collate('2016-12-31 23:59:59', '${collationName}'), 
'MM')
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = DateType
+      val expectedResult = "2016-12-01"
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(Date.valueOf(expectedResult)))
+    })
+  }
+
+  test("TruncTimestamp expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select date_trunc(collate('HOUR', '${collationName}'),
+          |collate('2015-03-05T09:32:05.359', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2015-03-05 09:00:00.0"
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(Timestamp.valueOf(expectedResult)))
+    })
+  }
+
+  test("MakeTimestamp expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select make_timestamp(2014, 12, 28, 6, 30, 45.887, collate('CET', 
'${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2014-12-27 21:30:45.887"
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(Timestamp.valueOf(expectedResult)))
+    })
+  }
+
+  test("DatePart expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select date_part(collate('Week', '${collationName}'),
+          |collate('2019-08-12 01:00:00.123456', '${collationName}'))
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = IntegerType
+      val expectedResult = 33
+      assert(testQuery.schema.fields.head.dataType.sameType(dataType))
+      checkAnswer(testQuery, Row(expectedResult))
+    })
+  }
+
+  test("ConvertTimezone expression with collation") {
+    // Supported collations
+    testSuppCollations.foreach(collationName => {
+      val query =
+        s"""
+          |select date_format(convert_timezone(collate('America/Los_Angeles', 
'${collationName}'),
+          |collate('UTC', '${collationName}'), collate('2021-12-06 00:00:00', 
'${collationName}')),
+          |'yyyy-MM-dd HH:mm:ss.S')
+          |""".stripMargin
+      // Result & data type check
+      val testQuery = sql(query)
+      val dataType = StringType

Review Comment:
   well then no need to test that here if we're already testing it thoroughly 
in a separate PR?



-- 
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.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to