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


##########
sql/core/src/test/scala/org/apache/spark/sql/CollationSQLExpressionsSuite.scala:
##########
@@ -1584,6 +1584,234 @@ class CollationSQLExpressionsSuite
     })
   }
 
+  test("CurrentTimeZone expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query = "select current_timezone()"
+      // Result
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = StringType(collationName)
+        assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      }
+    })
+  }
+
+  test("DayName expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query = "select dayname(current_date())"
+      // Result
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = StringType(collationName)
+        assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      }
+    })
+  }
+
+  test("ToUnixTimestamp expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").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
+      val testQuery = sql(query)
+      val dataType = LongType
+      val expectedResult = 1609488000L
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      assertResult(expectedResult)(testQuery.collect().head.getLong(0))
+    })
+  }
+
+  test("FromUnixTime expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select from_unixtime(1609488000, collate('yyyy-MM-dd HH:mm:ss', 
'${collationName}'))
+          |""".stripMargin
+      // Result
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = StringType(collationName)
+        val expectedResult = "2021-01-01 00:00:00"
+        assertResult(dataType)(testQuery.schema.fields.head.dataType)
+        assertResult(expectedResult)(testQuery.collect().head.getString(0))
+      }
+    })
+  }
+
+  test("NextDay expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select next_day('2015-01-14', collate('TU', '${collationName}'))
+          |""".stripMargin
+      // Result
+      withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
+        val testQuery = sql(query)
+        val dataType = DateType
+        val expectedResult = "2015-01-20"
+        assertResult(dataType)(testQuery.schema.fields.head.dataType)
+        
assertResult(expectedResult)(testQuery.collect().head.getDate(0).toString)
+      }
+    })
+  }
+
+  test("FromUTCTimestamp expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select from_utc_timestamp(collate('2016-08-31', '${collationName}'),
+          |collate('Asia/Seoul', '${collationName}'))
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2016-08-31 09:00:00.0"
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      
assertResult(expectedResult)(testQuery.collect().head.getTimestamp(0).toString)
+    })
+  }
+
+  test("ToUTCTimestamp expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select to_utc_timestamp(collate('2016-08-31 09:00:00', 
'${collationName}'),
+          |collate('Asia/Seoul', '${collationName}'))
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2016-08-31 00:00:00.0"
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      
assertResult(expectedResult)(testQuery.collect().head.getTimestamp(0).toString)
+    })
+  }
+
+  test("ParseToDate expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select to_date(collate('2016-12-31', '${collationName}'),
+          |collate('yyyy-MM-dd', '${collationName}'))
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = DateType
+      val expectedResult = "2016-12-31"
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      
assertResult(expectedResult)(testQuery.collect().head.getDate(0).toString)
+    })
+  }
+
+  test("ParseToTimestamp expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").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
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2016-12-31 23:59:59.0"
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      
assertResult(expectedResult)(testQuery.collect().head.getTimestamp(0).toString)
+    })
+  }
+
+  test("TruncDate expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select trunc(collate('2016-12-31 23:59:59', '${collationName}'), 
'MM')
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = DateType
+      val expectedResult = "2016-12-01"
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      
assertResult(expectedResult)(testQuery.collect().head.getDate(0).toString)
+    })
+  }
+
+  test("TruncTimestamp expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select date_trunc(collate('HOUR', '${collationName}'),
+          |collate('2015-03-05T09:32:05.359', '${collationName}'))
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2015-03-05 09:00:00.0"
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      
assertResult(expectedResult)(testQuery.collect().head.getTimestamp(0).toString)
+    })
+  }
+
+  test("MakeTimestamp expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select make_timestamp(2014, 12, 28, 6, 30, 45.887, collate('CET', 
'${collationName}'))
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = TimestampType
+      val expectedResult = "2014-12-27 21:30:45.887"
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      
assertResult(expectedResult)(testQuery.collect().head.getTimestamp(0).toString)
+    })
+  }
+
+  test("DatePart expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select date_part(collate('Week', '${collationName}'),
+          |collate('2019-08-12 01:00:00.123456', '${collationName}'))
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = IntegerType
+      val expectedResult = 33
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)
+      assertResult(expectedResult)(testQuery.collect().head.getInt(0))
+    })
+  }
+
+  test("ConvertTimezone expression with collation") {
+    // Supported collations
+    Seq("UTF8_BINARY", "UTF8_BINARY_LCASE", "UNICODE", 
"UNICODE_CI").foreach(collationName => {
+      val query =
+        s"""
+          |select convert_timezone(collate('America/Los_Angeles', 
'${collationName}'),
+          |collate('UTC', '${collationName}'), collate('2021-12-06 00:00:00', 
'${collationName}'))
+          |""".stripMargin
+      // Result
+      val testQuery = sql(query)
+      val dataType = TimestampNTZType
+      assertResult(dataType)(testQuery.schema.fields.head.dataType)

Review Comment:
   for all tests, we need to check both query result value, as well as result 
data type (like other tests from this suite)



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