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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CollationTypeCasts.scala:
##########
@@ -54,7 +54,7 @@ object CollationTypeCasts extends TypeCoercionRule {
 
     case otherExpr @ (
       _: In | _: InSubquery | _: CreateArray | _: ArrayJoin | _: Concat | _: 
Greatest | _: Least |
-      _: Coalesce | _: BinaryExpression | _: ConcatWs) =>
+      _: Coalesce | _: BinaryExpression | _: ConcatWs | _: StringLPad | _: 
StringRPad) =>

Review Comment:
   unfortunately, CollationTypeCasts doesn't quite do what you would expect 
based on those descriptions - we're working on fixing that
   
   but if you were to run this:
   ```
     test("Support StringLPad string expressions with collation") {
       val query = "SELECT lpad('abc', collate('5', 'unicode_ci'), ' ')"
       checkAnswer(sql(query), Row("  abc"))
       assert(sql(query).schema.fields.head.dataType.sameType(StringType(3)))
     }
   ```
     you would find that resulting datatype is UNICODE_CI (instead of 
UTF8_BINARY which should be the correct type)
     
     the reason for this behaviour is found in the ordering of rules in 
`TypeCoercion` - here you'll find that for example `CollationTypeCasts` comes 
before `FunctionArgumentConversion`, so in the above example collation is taken 
from '5' before it's converted into a 5



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