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


##########
pinot-plugins/pinot-input-format/pinot-json/src/main/java/org/apache/pinot/plugin/inputformat/json/format/JsonPayloadFormat.java:
##########
@@ -0,0 +1,82 @@
+/**
+ * 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.plugin.inputformat.json.format;
+
+import java.util.Locale;
+import javax.annotation.Nullable;
+
+
+/// The payload encodings the JSON stream decoder understands. Selected 
through the `jsonFormat` decoder
+/// property; [#AUTO] (the default) sniffs each message's leading bytes.
+public enum JsonPayloadFormat {
+  /// Detect the encoding per message from its leading magic / version bytes, 
falling back to text JSON.
+  AUTO(new AutoDetectPayloadParser()),
+  /// UTF-8 text JSON (the historical default).
+  TEXT(new TextJsonPayloadParser()),
+  /// PostgreSQL `jsonb` binary wire format (version byte + text JSON).
+  POSTGRES_JSONB(new PostgresJsonbPayloadParser()),
+  /// SQLite 3.45+ JSONB binary format.
+  SQLITE_JSONB(new SqliteJsonbPayloadParser()),
+  /// Jackson Smile binary JSON.
+  SMILE(new SmileJsonPayloadParser()),
+  /// CBOR (RFC 8949).
+  CBOR(new CborJsonPayloadParser());
+
+  // AUTO detection precedence: formats with strong, unambiguous magic bytes 
first; text (the catch-all,
+  // detected only by a leading '{' / '[') last so it never shadows a binary 
format. POSTGRES_JSONB precedes
+  // TEXT because its body *is* text JSON behind a version byte.
+  private static final JsonPayloadFormat[] DETECTION_ORDER =
+      {SMILE, CBOR, POSTGRES_JSONB, SQLITE_JSONB, TEXT};
+
+  private final JsonPayloadParser _parser;
+
+  JsonPayloadFormat(JsonPayloadParser parser) {
+    _parser = parser;
+  }
+
+  /// The parser for this format. For [#AUTO] this is a parser that resolves 
the concrete format per message.
+  public JsonPayloadParser getParser() {
+    return _parser;
+  }
+
+  /// Resolves a configured format name (case-insensitive), returning [#AUTO] 
when unset.
+  public static JsonPayloadFormat fromConfig(@Nullable String value) {
+    if (value == null || value.trim().isEmpty()) {
+      return AUTO;

Review Comment:
   Agreed — you're right on both counts, and I'd been keeping AUTO as the 
default on the strength of an earlier "detect when unconfigured" request. Fixed 
in `68af742`, taking both remedies you offered:
   
   **1. Unset `jsonFormat` now means `TEXT`.** `fromConfig(null)` returns 
`TEXT`, so existing tables are byte-for-byte unchanged; `AUTO` must be 
requested explicitly. New test `testUnsetFormatDoesNotAutoDetectBinary` asserts 
an unset format decodes text and *rejects* Smile, CBOR, Postgres, SQLite and a 
bare `0x0c`.
   
   **2. SQLite detection now sits behind a stronger validity gate.** 
`matches()` additionally requires the top-level object's declared size to 
exactly fill the payload — the same rule `parse()` enforces — so the single 
nibble can no longer hand a corrupt message to the parser. It is 
allocation-free and covers all four size descriptors, including an 8-byte size 
whose sign bit is set. `testSqliteDetectionRequiresAnExactlyFillingObject` pins 
it: `0x0c`-then-data and `0xfc deadbeef` are no longer claimed and fall back to 
text.
   
   The lone `0x0c` you identified does remain a validly-exact empty object 
under an *explicit* `SQLITE_JSONB`/`AUTO`, which is correct for the format — 
but it can no longer reach a text stream. PR description and release-note line 
updated to match.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



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