This is an automated email from the ASF dual-hosted git repository.
Jackie-Jiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new d25aa722e24 Add equals() and hashCode() to VectorIndexConfig (#18957)
d25aa722e24 is described below
commit d25aa722e248a7e2f69ce4556dc83017f58a529a
Author: Akanksha kedia <[email protected]>
AuthorDate: Fri Jul 10 23:15:37 2026 +0530
Add equals() and hashCode() to VectorIndexConfig (#18957)
---
.../spi/index/creator/VectorIndexConfig.java | 25 +++++
.../spi/index/creator/VectorIndexConfigTest.java | 121 +++++++++++++++++++++
2 files changed, 146 insertions(+)
diff --git
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/VectorIndexConfig.java
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/VectorIndexConfig.java
index 3bc65794843..555d4fdcefd 100644
---
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/VectorIndexConfig.java
+++
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/VectorIndexConfig.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import java.util.Map;
+import java.util.Objects;
import javax.annotation.Nullable;
import org.apache.pinot.spi.config.table.IndexConfig;
@@ -178,6 +179,30 @@ public class VectorIndexConfig extends IndexConfig {
return VectorIndexConfigValidator.resolveBackendType(this);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ if (!super.equals(o)) {
+ return false;
+ }
+ VectorIndexConfig that = (VectorIndexConfig) o;
+ return _vectorDimension == that._vectorDimension && _version ==
that._version
+ && Objects.equals(_vectorIndexType, that._vectorIndexType)
+ && _vectorDistanceFunction == that._vectorDistanceFunction
+ && Objects.equals(_properties, that._properties);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), _vectorIndexType, _vectorDimension,
_version,
+ _vectorDistanceFunction, _properties);
+ }
+
public String toString() {
return "VectorIndexConfig{" + "_vectorIndexType='" + _vectorIndexType +
"', _vectorDimension="
+ _vectorDimension + ", _version=" + _version + ",
_vectorDistanceFunction="
diff --git
a/pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/creator/VectorIndexConfigTest.java
b/pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/creator/VectorIndexConfigTest.java
new file mode 100644
index 00000000000..4fb3da5df3b
--- /dev/null
+++
b/pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/creator/VectorIndexConfigTest.java
@@ -0,0 +1,121 @@
+/**
+ * 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.segment.spi.index.creator;
+
+import java.util.Map;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
+
+
+/**
+ * Unit tests for {@link VectorIndexConfig#equals(Object)} and {@link
VectorIndexConfig#hashCode()}.
+ */
+public class VectorIndexConfigTest {
+
+ //
---------------------------------------------------------------------------
+ // equals
+ //
---------------------------------------------------------------------------
+
+ @Test
+ public void testEqualsSameInstance() {
+ VectorIndexConfig config = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ assertEquals(config, config);
+ }
+
+ @Test
+ public void testEqualsIdenticalConfigs() {
+ VectorIndexConfig a = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ VectorIndexConfig b = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ assertEquals(a, b);
+ }
+
+ @Test
+ public void testNotEqualsDifferentDimension() {
+ VectorIndexConfig a = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ VectorIndexConfig b = hnswConfig(8,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ assertNotEquals(a, b);
+ }
+
+ @Test
+ public void testNotEqualsDifferentDistanceFunction() {
+ VectorIndexConfig a = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ VectorIndexConfig b = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.EUCLIDEAN);
+ assertNotEquals(a, b);
+ }
+
+ @Test
+ public void testNotEqualsDifferentBackend() {
+ VectorIndexConfig a = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ VectorIndexConfig b = new VectorIndexConfig(false, "IVF_PQ", 4, 1,
+ VectorIndexConfig.VectorDistanceFunction.COSINE, Map.of());
+ assertNotEquals(a, b);
+ }
+
+ @Test
+ public void testNotEqualsDifferentProperties() {
+ VectorIndexConfig a = new VectorIndexConfig(false, "HNSW", 4, 1,
+ VectorIndexConfig.VectorDistanceFunction.COSINE, Map.of("maxCon",
"16"));
+ VectorIndexConfig b = new VectorIndexConfig(false, "HNSW", 4, 1,
+ VectorIndexConfig.VectorDistanceFunction.COSINE, Map.of("maxCon",
"32"));
+ assertNotEquals(a, b);
+ }
+
+ @Test
+ public void testNotEqualsDisabledVsEnabled() {
+ VectorIndexConfig enabled = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ VectorIndexConfig disabled = new VectorIndexConfig(true);
+ assertNotEquals(enabled, disabled);
+ }
+
+ @Test
+ public void testNotEqualsNull() {
+ VectorIndexConfig config = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ assertNotEquals(config, null);
+ }
+
+ //
---------------------------------------------------------------------------
+ // hashCode
+ //
---------------------------------------------------------------------------
+
+ @Test
+ public void testHashCodeConsistentWithEquals() {
+ VectorIndexConfig a = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ VectorIndexConfig b = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ assertEquals(a, b);
+ assertEquals(a.hashCode(), b.hashCode());
+ }
+
+ @Test
+ public void testHashCodeDiffersForDifferentDimension() {
+ VectorIndexConfig a = hnswConfig(4,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ VectorIndexConfig b = hnswConfig(8,
VectorIndexConfig.VectorDistanceFunction.COSINE);
+ assertNotEquals(a.hashCode(), b.hashCode());
+ }
+
+ //
---------------------------------------------------------------------------
+ // Helpers
+ //
---------------------------------------------------------------------------
+
+ private static VectorIndexConfig hnswConfig(int dimension,
+ VectorIndexConfig.VectorDistanceFunction distanceFunction) {
+ return new VectorIndexConfig(false, "HNSW", dimension, 1,
distanceFunction, Map.of());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]