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


##########
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:
   Addressed in 760d96a56e. The extractor, scalar-function, and transform 
Javadocs now name the exact optional runtime coordinate 
`org.apache.fory:fory-json:1.6.0` (with transitive `fory-core`). I also added 
an IMPORTANT runtime-availability section above the benchmark tables in the PR 
description: standard builds/distributions do not ship Fory and therefore use 
the Jackson/Jayway fallback, while the benchmarks and `pinot-integration-tests` 
explicitly include Fory.



##########
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:
   The exclusion is intentional because query `jsonExtractScalar(..., 
'STRING')` has a stronger precision contract than the ingestion 
`jsonPathString` helper. The query path uses 
`JSON_PARSER_CONTEXT_WITH_BIG_DECIMAL` so a non-string numeric leaf such as 
`{"v":12345678901234567890.123456789}` must be returned as the exact string 
`12345678901234567890.123456789`; `testExtractStringPreservesNumericPrecision` 
covers this for all variants. Fory 1.6 materializes fractional/exponent numbers 
as `Double`, so enabling it for the generic STRING result would round that 
value. Ingestion `jsonPathString` uses the normal non-BigDecimal Jayway 
context, which is why its Fory counterpart has a different eligible envelope. 
Commit 760d96a56e adds this rationale next to the eligibility decision. A 
future token-aware path could accelerate string leaves while falling back 
before fractional-number coercion, but I kept the experimental path 
conservative here.



##########
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:
   Agreed that a typed result holder would be safer if this API grows. I am 
keeping the private identity sentinel in this experimental patch because there 
are only two production callers, both immediately check `isFallbackRequired`, 
and direct tests cover duplicate ordering, container fallback, malformed tails, 
and cross-thread cleanup. I will treat a result-holder API as the follow-up 
before exposing additional callers rather than expanding this PR further.



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