spark-test commented on code in PR #60148:
URL: https://github.com/apache/spark/pull/60148#discussion_r4546887900
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/toFromProtobufSqlFunctions.scala:
##########
@@ -153,21 +167,39 @@ case class FromProtobuf(
}
override lazy val replacement: Expression = {
- val messageNameValue: String = messageName.eval() match {
+ val conf = SQLConf.get
+ if (conf.getConf(SQLConf.MAP_KEY_DEDUP_POLICY) == mapKeyDedupPolicy) {
Review Comment:
**Nit (P3):** This branch clones the whole session conf whenever the active
`spark.sql.mapKeyDedupPolicy` differs from the recorded one, even when none of
the arguments can read the policy. Only `ArrayBasedMapBuilder` reads it, and
every expression whose evaluation creates one is stateful. So when the message
name, descriptor, and options contain no stateful expression, as with literal
arguments and no options, every fresh copy is the argument itself and the clone
cannot change any value. For example, `from_protobuf(data, 'M',
'/path/m.desc')` in a view created with `spark.sql.mapKeyDedupPolicy=LAST_WIN`
set records LAST_WIN, and each canonicalization from a session on EXCEPTION,
such as a cache lookup, clones the conf. `SQLConf.clone()` calls
`setConfString` for every conf set in the session, which re-validates each
value and logs a warning for each deprecated conf. The base branch never
clones. The cost is bounded and per query rather than per row, but it buys
nothing here; the
earlier suggestion to clone only when the two policies differ did not exclude
this case.
Taking this branch only when some argument contains a stateful expression,
for example `Seq(messageName, descFilePath,
options).exists(_.exists(_.stateful))`, in both `FromProtobuf` and
`ToProtobuf`, gives the same result without the clone. A short comment there
should note that the check relies on the same `stateful` marking that the fresh
copies already rely on.
This extends an [existing
discussion](https://github.com/apache/spark/pull/60148#discussion_r4533237723).
**Verification:**
- **Regression:** For both from_protobuf and to_protobuf, take an expression
whose message name, descriptor, and options contain no stateful expression,
create it under LAST_WIN, and canonicalize it under EXCEPTION, for example with
the suite's StringLiteralWithEvalHook as the message name and a hook that
records SQLConf.get. The arguments are evaluated with the session's own conf
rather than a clone, and the canonical form has the same message name,
descriptor, and options as when canonicalized under LAST_WIN.
- **Compatibility:** For both functions, the tests of the analysis-time map
key policy, the cross-session cache lookup, and execution after a policy switch
keep passing, because each of those expressions has an argument that contains a
map and so must still be evaluated under the cloned conf.
- **Inspection:** In both wrappers, the active conf is cloned only on the
branch where the active policy differs from the recorded one and some argument
contains a stateful expression, and that branch still evaluates all three
arguments under the clone.
--
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]