yashmayya commented on code in PR #19223:
URL: https://github.com/apache/pinot/pull/19223#discussion_r3771202463


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/JsonExtractScalarTransformFunction.java:
##########
@@ -241,6 +260,15 @@ public void init(List<TransformFunction> arguments, 
Map<String, ColumnContext> c
       }
     }
     _resultMetadata = new TransformResultMetadata(_dataType, isSingleValue, 
false);
+    DataType inputDataType = firstArgument.getResultMetadata().getDataType();
+    _foryEligible = _extractionMode == ExtractionMode.FORY && _simpleJsonPath 
!= null
+        && inputDataType == DataType.STRING && isSingleValue && _dataType != 
DataType.STRING
+        && _dataType != DataType.JSON && _dataType != DataType.BIG_DECIMAL;

Review Comment:
   `_dataType != DataType.STRING` removes the most common case from the fast 
path.
   
   The scalar function `jsonPathStringFory` still sends string values through 
Fory. So the same extraction is accelerated during ingestion, but not during a 
query.
   
   My differential run over 83 documents found no difference between 
`jsonPathStringFory` and `jsonPathString`, and that function does use Fory for 
strings. My timing run shows the largest win on exactly this shape: a string 
leaf in a 25-level document measured 0.33 us/op against 2.09 us/op for Jayway.
   
   What is the reason to exclude `STRING` here? If a `toString` coercion case 
breaks, one test can show it, and then the exclusion is clearly correct. If 
there is no such case, this line gives up the main benefit of the change.



##########
pinot-common/src/main/java/org/apache/pinot/common/function/ForyJsonPathExtractor.java:
##########
@@ -0,0 +1,388 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.function;
+
+import com.fasterxml.jackson.core.StreamReadConstraints;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.annotation.Nullable;
+import org.apache.fory.json.ForyJson;
+import org.apache.fory.json.codec.JsonValueCodec;
+import org.apache.fory.json.reader.JsonReader;
+import org.apache.fory.json.reader.Latin1JsonReader;
+import org.apache.fory.json.reader.Utf16JsonReader;
+import org.apache.fory.json.reader.Utf8JsonReader;
+import org.apache.fory.json.writer.StringJsonWriter;
+import org.apache.fory.json.writer.Utf8JsonWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Shared Fory JSON parser for opt-in JSON-path implementations.
+///
+/// Streaming extraction uses one bounded parser pool shared by all worker 
threads. Initialization or runtime linkage
+/// failures permanently disable the optional path, allowing callers to fall 
back to Jackson/Jayway. Jackson's
+/// document, token, nesting, field-name, string, and number constraints are 
enforced while walking the document.
+/// The Fory runtime is an optional dependency; applications must add it to 
the application classpath to enable this
+/// experimental path.
+public final class ForyJsonPathExtractor {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(ForyJsonPathExtractor.class);
+  private static final StreamReadConstraints JACKSON_CONSTRAINTS = 
StreamReadConstraints.defaults();
+  private static final ThreadLocal<PathContext> PATH_CONTEXT = 
ThreadLocal.withInitial(PathContext::new);
+  private static final AtomicBoolean UNAVAILABLE_WARNING_LOGGED = new 
AtomicBoolean();
+  private static final Object FALLBACK_REQUIRED = new Object();
+
+  private ForyJsonPathExtractor() {
+  }
+
+  private static final class Holder {
+    @Nullable
+    private static final ForyJson STREAMING_PARSER = buildStreamingParser();
+    private static volatile boolean _streamingAvailable = STREAMING_PARSER != 
null;
+
+    private Holder() {
+    }
+
+    @Nullable
+    private static ForyJson buildStreamingParser() {
+      try {
+        return 
ForyJson.builder().withCodegen(false).withAsyncCompilation(false)
+            .maxDepth(JACKSON_CONSTRAINTS.getMaxNestingDepth())
+            .registerCodec(PathResult.class, PathCodec.INSTANCE).build();
+      } catch (RuntimeException | LinkageError e) {
+        logUnavailable(e);
+        return null;
+      }
+    }
+  }
+
+  /// Returns whether the optional Fory runtime initialized successfully.
+  public static boolean isAvailable() {
+    return Holder._streamingAvailable;
+  }
+
+  /// Returns whether an extracted value requires the reference parser for 
exact container/coercion semantics.
+  public static boolean isFallbackRequired(@Nullable Object value) {

Review Comment:
   The sentinel works. I ran 36 documents through both call paths, including 
duplicate keys in each order, containers under a nested path, malformed tails, 
and depths from 5 to 1001. There were no leaks and no differences against 
Jayway.
   
   The API shape stays fragile. `extract` returns an `Object` that can be a 
real value, `null`, or a private marker. A caller that forgets 
`isFallbackRequired` writes `java.lang.Object@1a2b3c` into user data, and no 
test catches it.
   
   A small result holder, or a second method such as `extractOrNull` plus 
`extractContainerFlag`, removes that risk. This is not urgent, because there 
are only two call sites today.



##########
pinot-common/pom.xml:
##########
@@ -280,6 +293,11 @@
       <groupId>com.jayway.jsonpath</groupId>
       <artifactId>json-path</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.fory</groupId>
+      <artifactId>fory-json</artifactId>
+      <optional>true</optional>

Review Comment:
   This is the right call for an experiment, and I verified that it works. The 
shaded jar contains no Fory classes, and an optional dependency never reaches 
`pinot-distribution`.
   
   It also means that a standard Pinot build cannot run the fast path. All four 
functions return the Jayway result, and the operator sees one WARN line.
   
   Two requests.
   
   First, name the exact artifact where a user can find it, for example 
`org.apache.fory:fory-json:1.6.0`. The Javadoc says only "add it to the 
application classpath", which does not tell the user what to add.
   
   Second, please state this in the PR description, above the benchmark tables. 
A reader can expect those numbers from a standard build today.
   
   Note that `pinot-integration-tests` declares Fory in test scope. So 
`JsonPathTest` asserts the accelerated path in a configuration that the 
distribution does not ship. The child JVM tests cover the shipped 
configuration, so the gap is small, but it is worth knowing.



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