u70b3 commented on code in PR #66637:
URL: https://github.com/apache/doris/pull/66637#discussion_r3804279224


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/lance/LanceIndexMetadataLoader.java:
##########
@@ -0,0 +1,247 @@
+// 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.doris.datasource.lance;
+
+import org.apache.doris.persist.gson.GsonUtils;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.commons.lang3.StringUtils;
+import org.lance.Dataset;
+import org.lance.index.IndexDescription;
+import org.lance.schema.LanceField;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.Set;
+import java.util.TreeMap;
+
+/** Loads and normalizes logical index metadata from one latest Lance dataset 
snapshot. */
+public final class LanceIndexMetadataLoader {
+    private static final int MAX_LOGICAL_INDEXES = 256;
+    private static final int MAX_COLUMNS_PER_INDEX = 64;
+    private static final int MAX_COLUMN_NAMES_BYTES = 16 * 1024;
+    private static final int MAX_EXTERNAL_STRING_BYTES = 1024;
+    private static final int MAX_PROPERTIES_BYTES = 400;
+
+    private static final Set<String> PROPERTY_ALLOWLIST = ImmutableSet.of(

Review Comment:
   Fixed in 8b58182cd. `normalizeProperties` now parses the SDK's actual nested 
shape: a top-level allowlist (`metric_type`, `target_partition_size`) plus 
bounded nested allowlists for `compression` 
(`type`/`num_bits`/`num_sub_vectors`/`rotation_type`) and `hnsw` 
(`construction_ef`/`max_connections`/`max_level`). The regression now asserts 
the nested form, e.g. 
`{"compression":{"num_bits":4,"num_sub_vectors":4,"type":"pq"},"metric_type":"L2"}`.
   



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/lance/LanceIndexMetadataLoader.java:
##########
@@ -0,0 +1,247 @@
+// 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.doris.datasource.lance;
+
+import org.apache.doris.persist.gson.GsonUtils;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.commons.lang3.StringUtils;
+import org.lance.Dataset;
+import org.lance.index.IndexDescription;
+import org.lance.schema.LanceField;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.Set;
+import java.util.TreeMap;
+
+/** Loads and normalizes logical index metadata from one latest Lance dataset 
snapshot. */
+public final class LanceIndexMetadataLoader {
+    private static final int MAX_LOGICAL_INDEXES = 256;
+    private static final int MAX_COLUMNS_PER_INDEX = 64;
+    private static final int MAX_COLUMN_NAMES_BYTES = 16 * 1024;
+    private static final int MAX_EXTERNAL_STRING_BYTES = 1024;
+    private static final int MAX_PROPERTIES_BYTES = 400;
+
+    private static final Set<String> PROPERTY_ALLOWLIST = ImmutableSet.of(
+            "metric_type",
+            "target_partition_size",
+            "compression_type",
+            "num_bits",
+            "num_sub_vectors",
+            "hnsw_max_connections",
+            "hnsw_construction_ef",
+            "hnsw_max_level");
+
+    private LanceIndexMetadataLoader() {
+    }
+
+    /** Loads logical indexes and schema fields from the same latest dataset 
snapshot. */
+    public static List<LanceLogicalIndex> load(String datasetUri,
+            Map<String, String> javaStorageOptions, BufferAllocator allocator) 
throws Exception {
+        try (Dataset dataset = 
Dataset.open().allocator(allocator).uri(datasetUri)
+                .readOptions(LanceReadOptions.build(javaStorageOptions, 
OptionalLong.empty())).build()) {
+            Map<Integer, String> topLevelFieldNames = new HashMap<>();
+            for (LanceField field : dataset.getLanceSchema().fields()) {

Review Comment:
   Fixed in 8b58182cd. `buildFieldNamesById` now DFS-traverses the full schema 
(depth ≤ 64, ≤ 16,384 fields) and maps every field ID to its canonical dotted 
path with backtick-escaped segments, so indexes on nested fields resolve 
instead of failing the whole SHOW INDEX. Covered by a real nested-index 
regression case (`nested_label_btree` on a child field whose name contains a 
dot).
   



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/lance/LanceIndexMetadataLoader.java:
##########
@@ -0,0 +1,247 @@
+// 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.doris.datasource.lance;
+
+import org.apache.doris.persist.gson.GsonUtils;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.commons.lang3.StringUtils;
+import org.lance.Dataset;
+import org.lance.index.IndexDescription;
+import org.lance.schema.LanceField;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.Set;
+import java.util.TreeMap;
+
+/** Loads and normalizes logical index metadata from one latest Lance dataset 
snapshot. */
+public final class LanceIndexMetadataLoader {
+    private static final int MAX_LOGICAL_INDEXES = 256;
+    private static final int MAX_COLUMNS_PER_INDEX = 64;
+    private static final int MAX_COLUMN_NAMES_BYTES = 16 * 1024;
+    private static final int MAX_EXTERNAL_STRING_BYTES = 1024;
+    private static final int MAX_PROPERTIES_BYTES = 400;
+
+    private static final Set<String> PROPERTY_ALLOWLIST = ImmutableSet.of(
+            "metric_type",
+            "target_partition_size",
+            "compression_type",
+            "num_bits",
+            "num_sub_vectors",
+            "hnsw_max_connections",
+            "hnsw_construction_ef",
+            "hnsw_max_level");
+
+    private LanceIndexMetadataLoader() {
+    }
+
+    /** Loads logical indexes and schema fields from the same latest dataset 
snapshot. */
+    public static List<LanceLogicalIndex> load(String datasetUri,
+            Map<String, String> javaStorageOptions, BufferAllocator allocator) 
throws Exception {
+        try (Dataset dataset = 
Dataset.open().allocator(allocator).uri(datasetUri)
+                .readOptions(LanceReadOptions.build(javaStorageOptions, 
OptionalLong.empty())).build()) {
+            Map<Integer, String> topLevelFieldNames = new HashMap<>();
+            for (LanceField field : dataset.getLanceSchema().fields()) {
+                topLevelFieldNames.put(field.getId(), field.getName());
+            }
+            return normalize(dataset.describeIndices(), topLevelFieldNames);

Review Comment:
   Fixed in 8b58182cd. Bulk `describeIndices()` is no longer used. 
`describeUserIndexes()` lists physical entries via `listIndexes()`, filters 
`__lance_frag_reuse` / `__lance_mem_wal`, dedupes by logical name, then 
describes each user index through an exact `IndexCriteria.hasName` lookup 
(validating exactly-one cardinality and name match), so system entries never 
reach the details path.
   



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowIndexCommand.java:
##########
@@ -108,30 +112,58 @@ private ShowResultSet handleShowIndex(ConnectContext ctx, 
StmtExecutor executor)
         analyze(ctx);
 
         List<List<String>> rows = Lists.newArrayList();
-        // in show index, only support internal catalog
-        DatabaseIf db = Env.getCurrentEnv().getCatalogMgr()
-                .getCatalogOrAnalysisException(tableNameInfo.getCtl())
-                .getDbOrAnalysisException(tableNameInfo.getDb());
+        CatalogIf catalog = Env.getCurrentEnv().getCatalogMgr()
+                .getCatalogOrAnalysisException(tableNameInfo.getCtl());
+        DatabaseIf db = 
catalog.getDbOrAnalysisException(tableNameInfo.getDb());

Review Comment:
   Fixed in 8b58182cd. `handleShowIndex` now rejects a configured Lance REST 
catalog immediately after the privilege check and before 
`getDbOrAnalysisException` (ShowIndexCommand.java:117), so the fixed 
unsupported error is returned without any namespace or table I/O.
   



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