hudi-agent commented on code in PR #19318:
URL: https://github.com/apache/hudi/pull/19318#discussion_r3686694402
##########
hudi-common/src/main/java/org/apache/hudi/metadata/HoodieMetadataPayload.java:
##########
@@ -210,6 +254,7 @@ public class HoodieMetadataPayload implements
HoodieRecordPayload<HoodieMetadata
protected HoodieMetadataColumnStats columnStatMetadata = null;
protected HoodieRecordIndexInfo recordIndexMetadata;
protected HoodieSecondaryIndexInfo secondaryIndexMetadata;
+ protected Object vectorIndexMetadata;
Review Comment:
🤖 nit: every other metadata payload field has its specific Avro type
(`HoodieMetadataBloomFilter`, `HoodieRecordIndexInfo`,
`HoodieSecondaryIndexInfo`, …), but this one is `Object`. Could you introduce a
marker interface (e.g. `HoodieVectorIndexEntry`) that the Avro-generated types
implement, or at least use a common base type? As-is, readers have no way to
know what concrete types can land here without searching all constructors.
<sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-common/src/test/java/org/apache/hudi/common/index/vector/MetricEstimatorIdentityTest.java:
##########
@@ -0,0 +1,321 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file for details.
+ */
+
+package org.apache.hudi.common.index.vector;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import java.util.Random;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The metric certification suite. Three families:
+ *
+ * <p>IDENTITY: for random (x, c, q), the query-state composition over the
NEUTRAL factors
+ * must equal the exact estimator composed in double precision, for both
passes and every
+ * metric. This pins encoder and scorer to each other; every silent-recall bug
this index
+ * has had (zero factors, folded conventions, sign drift) fails this test.
+ *
+ * <p>BOUND: optimisticRankingDistance must never exceed the
estimator-composed distance, and the
+ * true distance must lie within the propagated bound at the calibrated rate.
The direction
+ * (rip + errAbs for ALL metrics) is the designated sign-bug site.
+ *
+ * <p>DEGENERATE: the normative special cases compose to EXACT values.
+ *
+ * <p>Codes here are synthetic centered codes built directly from the residual
(sign code
+ * c1_i = +-0.5; multibit codeEx from B-bit grid) so the suite tests the
FACTOR/COMPOSITION
+ * contract independent of bit-packing; the golden round-trip test (separate)
certifies
+ * packing. Together they certify the full path.
+ */
+public class MetricEstimatorIdentityTest {
+
+ private static final int DIM = 96;
+ private static final int TRIALS = 200;
+ private static final int BITS = 4;
Review Comment:
🤖 nit: could you rename this to `TestMetricEstimatorIdentity`? Every other
test class in this PR and the surrounding package uses the `Test*` prefix
convention (`TestRaBitQEncoder`, `TestMetricQueryStateRotation`, etc.) — the
`*Test` suffix stands out as an outlier.
<sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-common/src/main/java/org/apache/hudi/metadata/VectorPostingPrefixRawKey.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.hudi.metadata;
+
+import lombok.Value;
+
+/**
+ * Raw key prefix for vector posting scans.
+ */
+@Value
+public class VectorPostingPrefixRawKey implements RawKey {
+
+ int generationId;
+ int clusterId;
+ Integer shardId;
+
+ @Override
+ public String encode() {
+ return shardId == null
Review Comment:
🤖 nit: the `substring(0, 9)` magic number is duplicated from
`HoodieTableMetadataUtil.getVectorIndexPostingPrefix` — could this delegate to
that helper, or at least reference a named constant for the cluster-prefix
length? It's non-obvious why 9 bytes is the right cut-off here.
<sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-common/src/main/java/org/apache/hudi/metadata/HoodieMetadataPayload.java:
##########
@@ -253,6 +298,442 @@ protected HoodieMetadataPayload(String key,
HoodieSecondaryIndexInfo secondaryIn
this(key, MetadataPartitionType.SECONDARY_INDEX.getRecordType(), null,
null, null, null, secondaryIndexMetadata,
secondaryIndexMetadata.getIsDeleted());
}
+ protected HoodieMetadataPayload(String key, Object vectorIndexInfo) {
+ this.key = key;
+ this.type = MetadataPartitionType.VECTOR_INDEX.getRecordType();
+ this.vectorIndexMetadata = vectorIndexInfo;
+ this.isDeletedRecord = vectorIndexInfo instanceof
HoodieVectorIndexTombstone;
+ }
+
+ /**
+ * Create the generation-one centroid record for the given index partition.
+ */
+ public static HoodieRecord<HoodieMetadataPayload>
createVectorIndexCentroidsRecord(
+ ByteBuffer centroidBytes, String partitionPath) {
+ HoodieVectorIndexCentroids centroids = new HoodieVectorIndexCentroids(
+ 0L,
+ ByteBuffer.allocate(0),
+ centroidBytes,
+ ByteBuffer.allocate(0));
+ HoodieMetadataPayload payload = new
HoodieMetadataPayload(VectorIndexMetadataKey.centroids(1, 0L, 0), centroids);
+ HoodieKey key = new HoodieKey(VectorIndexMetadataKey.centroids(1, 0L, 0),
partitionPath);
+ return new HoodieAvroRecord<>(key, payload);
+ }
+
+ public static HoodieRecord<HoodieMetadataPayload>
createVectorIndexCentroidsRecord(
+ int generation,
+ long centroidEpoch,
+ int chunk,
+ ByteBuffer clusterIds,
+ ByteBuffer centroidBytes,
+ ByteBuffer clusterRadii,
+ String partitionPath) {
+ String recordKey = VectorIndexMetadataKey.centroids(generation,
centroidEpoch, chunk);
+ HoodieVectorIndexCentroids centroids = new HoodieVectorIndexCentroids(
+ centroidEpoch, clusterIds, centroidBytes, clusterRadii);
+ return new HoodieAvroRecord<>(
+ new HoodieKey(recordKey, partitionPath),
+ new HoodieMetadataPayload(recordKey, centroids));
+ }
+
+ /**
+ * Create the generation-one quantizer metadata record for the given index
partition.
+ */
+ public static HoodieRecord<HoodieMetadataPayload>
createVectorIndexQuantizerMetadataRecord(
+ String quantizerType,
+ int quantizedCodeBytes,
+ long randomSeed,
+ boolean assumeNormalized,
+ String partitionPath) {
+ return createVectorIndexQuantizerMetadataRecord(
+ quantizerType,
+ quantizedCodeBytes,
+ 1,
+ randomSeed,
+ assumeNormalized,
+ partitionPath);
Review Comment:
🤖 nit: this overload accepts `quantizedCodeBytes`, `rabitqBits`, and
`assumeNormalized` but silently drops all three when delegating to the lower
overload. Could the unused parameters be removed from the signature, or have a
comment explaining why they're intentionally ignored? A caller passing a
non-default `rabitqBits` here would have no indication their value is discarded.
<sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
--
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]