CrownChu commented on code in PR #10777:
URL: https://github.com/apache/paimon/pull/10777#discussion_r4376944416


##########
paimon-core/src/main/java/org/apache/paimon/globalindex/EsSearchResult.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.paimon.globalindex;
+
+import org.apache.paimon.globalindex.EsIndexSearch.Hit;
+import org.apache.paimon.utils.JsonSerdeUtil;
+
+import 
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/** Bounded HIT/PAGE_END records shared by Spark, Flink and the Java SDK. */
+public final class EsSearchResult {
+    private static final String[] COLUMNS = {
+        "record_kind",
+        "query_id",
+        "query_ordinal",
+        "execution_query_id",
+        "target",
+        "table_name",
+        "branch",
+        "snapshot_id",
+        "row_id",
+        "score",
+        "rank",
+        "sort_values_json",
+        "source_schema_json",
+        "source_binary",
+        "source_encoding",
+        "metadata_json",
+        "index_fields_json"
+    };
+
+    private final List<Object[]> records;
+    private final List<Hit> hits;
+
+    EsSearchResult(EsSearchRequest request, EsIndexSearch.Plan plan, List<Hit> 
hits)
+            throws Exception {
+        this.hits = Collections.unmodifiableList(new ArrayList<>(hits));
+        Map<Long, byte[]> source = request.fetchSource ? plan.fetch(hits) : 
Collections.emptyMap();
+        String schema = request.fetchSource ? 
JsonSerdeUtil.toJson(plan.sourceType()) : null;
+        String queryId = UUID.randomUUID().toString();
+        ObjectNode metadata = 
JsonSerdeUtil.OBJECT_MAPPER_INSTANCE.createObjectNode();
+        metadata.put("snapshotId", Long.toString(plan.snapshotId));
+        metadata.put("indexType", "es-index");
+        metadata.put("coverageComplete", true);
+        metadata.put("scoring", "QUERY_THEN_FETCH");
+        metadata.put("totalHitsTracked", false);
+        metadata.put("hitCount", hits.size());
+        records = new ArrayList<>();
+        for (int i = 0; i <= hits.size(); i++) {
+            boolean end = i == hits.size();
+            Object[] row = new Object[COLUMNS.length];
+            row[0] = end ? "PAGE_END" : "HIT";
+            row[1] = queryId;
+            row[2] = 0;
+            row[3] = queryId;
+            row[4] = request.target;
+            row[5] = request.database + "." + request.table;
+            row[6] = "main";

Review Comment:
     Addressed in aa86d32.
   
     Search now validates the parsed identifier before catalog lookup and 
rejects a resolved
     non-main table at the start of planning. The `prepare(FileStoreTable, 
request)` overload
     also validates the request identifier.
   
     Added tests using a tag-derived dev branch with persisted Java indexes for 
all three
     cases:
     - A dev-qualified request through the catalog.
     - A dev table passed directly.
     - A dev-qualified request passed alongside a main table.
   
     All three are rejected. Existing Spark/SDK tests also verify that every 
HIT and PAGE_END
     record carries the main branch identity.
   
     Local validation passed: 110 functional cases, 30 CI routing/command 
tests, and Maven
     compatibility checks. Maven `verify` completed on JDK 11 with Checkstyle, 
Spotless,
     Enforcer, and RAT enabled. These are local validation results, not a claim 
that all
     upstream CI checks have passed.



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

Reply via email to