janhoy commented on code in PR #4910:
URL: https://github.com/apache/solr/pull/4910#discussion_r4529370774


##########
solr/core/src/java/org/apache/solr/handler/loader/NDJsonParser.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.solr.handler.loader;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Arrays;
+import org.apache.solr.common.SolrException;
+import org.noggit.JSONParser;
+
+/**
+ * A {@link JSONParser} that enforces the newline delimited JSON contract 
while parsing: every
+ * document is a strict JSON object sitting on a line of its own. Newlines are 
only whitespace to
+ * JSON itself, so the contract is checked here rather than by framing the 
input into lines, which
+ * lets documents stream without ever being materialized as a line.
+ *
+ * <p>Tracking happens in {@link #fill()}, which sees every character exactly 
once as it enters the
+ * buffer, and in {@link #nextEvent()}, which observes where each top level 
object starts and ends.
+ */
+class NDJsonParser extends JSONParser {
+
+  private static final int BUFFER_SIZE = 8192;
+
+  /** Absolute offsets of newlines already seen by {@link #fill()}, not yet 
reached by parsing. */
+  private long[] newlines = new long[16];
+
+  private int head;
+  private int tail;
+
+  private boolean lastWasCarriageReturn;
+
+  /** Lines consumed up to {@link #consumedPosition}, 1-based. */
+  private long line = 1;
+
+  private long consumedPosition;
+
+  private long documentStartLine = -1;
+  private long previousDocumentEndLine = -1;
+
+  NDJsonParser(Reader in) {
+    super(in, new char[BUFFER_SIZE]);
+    // Every line has to be a JSON value, so none of noggit's lenient dialects 
are accepted
+    setFlags(FLAGS_STRICT);

Review Comment:
   🤖 Disagree. NDJSON reuses noggit's `FLAGS_STRICT`, which is Solr's shared 
definition of strict JSON; a per-format number/string/whitespace validator 
would make this endpoint diverge from every other JSON endpoint. Any tightening 
of the lexer belongs in noggit itself.



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