gengliangwang commented on code in PR #60356:
URL: https://github.com/apache/spark/pull/60356#discussion_r4637943062


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -331,7 +331,7 @@ case class ArraysZip(children: Seq[Expression], names: 
Seq[Expression])
         case (e: NamedExpression, _) => NamePlaceholder
         case (g: GetStructField, _) => Literal(g.extractFieldName)
         case (g: GetArrayStructFields, _) => Literal(g.field.name)
-        case (g: GetMapValue, _) => Literal(g.key)
+        case (GetMapValue(_, Literal(key: UTF8String, _: StringType)), _) => 
Literal(key)

Review Comment:
   **[P2] Design: Inline string-literal match duplicates the existing 
StringLiteral extractor**
   
   The new case `GetMapValue(_, Literal(key: UTF8String, _: StringType))` 
repeats the body of `object StringLiteral` in 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala:472-476
 (`case Literal(s: UTF8String, _: StringType) => Some(s.toString)`) almost 
token for token. That extractor is the usual way catalyst matches non-null 
string literals, for example CoalesceHintUtils.scala:54 and :163, 
ResolveHints.scala:167, datetimeExpressions.scala:80, 
regexpExpressions.scala:315 and stringExpressions.scala:2493. It is in the same 
package as `ArraysZip`, so no import is needed. Suggested change: `case 
(GetMapValue(_, StringLiteral(key)), _) => Literal(key)`. The behavior stays 
the same: a non-null literal of any `StringType`, collated or not, becomes a 
plain `StringType` name literal.
   
   **Why it matters:** The rule for what counts as a string-literal map key 
would live in two places. If `StringLiteral` changes later (for example in how 
it treats collated strings), `arrays_zip` field naming would quietly stop 
matching the other string-literal handling. Fixing it now is a one-token change.



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