stefankandic commented on code in PR #45592:
URL: https://github.com/apache/spark/pull/45592#discussion_r1530424813


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala:
##########
@@ -69,10 +69,41 @@ object Literal {
     case f: Float => Literal(f, FloatType)
     case b: Byte => Literal(b, ByteType)
     case s: Short => Literal(s, ShortType)
-    case s: String => Literal(UTF8String.fromString(s), StringType)
-    case s: UTF8String => Literal(s, StringType)
-    case c: Char => Literal(UTF8String.fromString(c.toString), StringType)
-    case ac: Array[Char] => Literal(UTF8String.fromString(String.valueOf(ac)), 
StringType)
+    case s: String =>
+      if (CollationFactory.collationNameToId(SQLConf.get.defaultCollation)
+        == CollationFactory.SPARK_INTERNAL_COLLATION_ID) {
+        Literal(UTF8String.fromString(s), StringType)
+      }
+      else {
+        Literal(UTF8String.fromString(s),
+          
StringType(CollationFactory.collationNameToId(SQLConf.get.defaultCollation)))
+      }
+    case s: UTF8String =>
+      if (CollationFactory.collationNameToId(SQLConf.get.defaultCollation)
+        == CollationFactory.SPARK_INTERNAL_COLLATION_ID) {
+        Literal(s, StringType)
+      }
+      else {
+        Literal(s, 
StringType(CollationFactory.collationNameToId(SQLConf.get.defaultCollation)))
+      }
+    case c: Char =>
+      if (CollationFactory.collationNameToId(SQLConf.get.defaultCollation)
+        == CollationFactory.SPARK_INTERNAL_COLLATION_ID) {
+        Literal(UTF8String.fromString(c.toString), StringType)
+      }
+      else {
+        Literal(UTF8String.fromString(c.toString),
+          
StringType(CollationFactory.collationNameToId(SQLConf.get.defaultCollation)))
+      }
+    case ac: Array[Char] =>
+      if (CollationFactory.collationNameToId(SQLConf.get.defaultCollation)
+        == CollationFactory.SPARK_INTERNAL_COLLATION_ID) {
+        Literal(UTF8String.fromString(String.valueOf(ac)), StringType)

Review Comment:
   can't you use `String.valueOf` for others as well? AFAIK it accepts `Object` 
as well.
   
   if not at least try to extract some of this functionality into a common 
method or something because it seems repetitive for these 4 cases



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to