ganeshashree commented on code in PR #57888:
URL: https://github.com/apache/spark/pull/57888#discussion_r3751203876


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/json/JsonExpressionEvalUtils.scala:
##########
@@ -483,6 +483,36 @@ case class JsonTableEvaluator(containerPath: 
Seq[PathInstruction], explodeRoot:
     }
   }
 
+  /**
+   * Resolves `containerPath` against a single JSON value, preserving the 
missing / JSON-null /
+   * found distinction that [[evaluate]] collapses. Returns:
+   *
+   *   - `None` if the input is not a single well-formed JSON value (malformed 
/ trailing garbage /
+   *     empty);
+   *   - `Some(Missing)` if the path matches nothing;
+   *   - `Some(NullValue)` if the path matches an explicit JSON `null`;
+   *   - `Some(Found(raw))` if the path matches a value, where `raw` is its 
verbatim JSON text
+   *     (strings keep their enclosing quotes; an object/array is the whole 
fragment).
+   *
+   * A `null` input is the caller's responsibility. `explodeRoot` is ignored: 
this is a single-value
+   * lookup, so construct the evaluator with `explodeRoot = false`.
+   */
+  final def lookup(json: UTF8String): Option[JsonPathResult] = {
+    if (!isSingleWellFormedValue(json)) return None

Review Comment:
   Done. lookup now uses a single parser: it navigates to and serializes the 
matched value, then drainToRootEnd consumes the rest of the root and rejects 
any trailing content, so malformed/trailing-garbage inputs are caught without 
the second O(document size) pass.



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