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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/json/JsonExpressionEvalUtils.scala:
##########
@@ -483,6 +483,63 @@ 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`.
+   *
+   * A single parser both navigates the path and validates well-formedness: 
after the matched value
+   * is captured (or the path is found missing), [[drainToRootEnd]] consumes 
the rest of the root
+   * value and rejects any trailing content, so a valid prefix followed by 
garbage (or a second
+   * root value) is rejected exactly as a fully malformed document is. This 
avoids the extra
+   * O(document size) validation pass a separate `isSingleWellFormedValue` 
scan would add per row.
+   */
+  final def lookup(json: UTF8String): Option[JsonPathResult] = {
+    Utils.tryWithResource(CreateJacksonParser.utf8String(jsonFactory, json)) { 
parser =>
+      try {
+        if (parser.nextToken() == null) {
+          None // empty or whitespace-only
+        } else {
+          val result = positionAt(parser, containerPath) match {
+            case PositionResult.Missing => JsonPathResult.Missing
+            case PositionResult.NullValue => JsonPathResult.NullValue
+            case PositionResult.AtValue => 
JsonPathResult.Found(serializeCurrentValue(parser))

Review Comment:
   Done.



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