charlhhhh commented on code in PR #60148:
URL: https://github.com/apache/spark/pull/60148#discussion_r4542627566
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/toFromProtobufSqlFunctions.scala:
##########
@@ -167,7 +167,10 @@ case class FromProtobuf(
case bytes: Array[Byte] => Some(bytes)
case null => None
}
- val optionsValue: Map[String, String] = options.eval() match {
+ // Concurrent canonicalization can evaluate the same CreateMap and corrupt
its map builder.
+ // Copy stateful options to avoid duplicate-key errors and mismatched
key/value array lengths.
+ val freshOptions = options.freshCopyIfContainsStatefulExpression()
Review Comment:
It only happens when all of these hold:
- The options repeat a key, e.g. map('mode', 'PERMISSIVE', 'mode',
'FAILFAST'), which I think is rare, since users are unlikely to set the same
option twice.
- The query is analyzed under LAST_WIN. Under the default EXCEPTION it
already fails at analysis.
- The first canonicalization of the cached plan then happens under
EXCEPTION, e.g. a lookup from another session or after the session switches the
policy. If the plan was already compared once under LAST_WIN, later lookups
reuse the canonicalized plan and succeed.
Options without a repeated key are not affected. Fixing it means persisting
the analysis-time map-key policy in FromProtobuf/ToProtobuf, which changes the
case class shape and every place that constructs or matches it.
@HeartSaVioR is it OK to keep the current behavior, given how narrow this
is? If you think it should be fixed, would it be OK to merge this PR first for
the race fix and track the policy pinning separately?
--
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]