From 1f9be91fbd06b2058c0871a00d18f82d2137f369 Mon Sep 17 00:00:00 2001 From: Anush008 Date: Tue, 17 Sep 2024 15:09:43 +0530 Subject: [PATCH] refactor: Make vectors optional --- build.gradle | 2 +- src/main/java/io/qdrant/kafka/ValueExtractor.java | 7 ++++++- src/test/java/io/qdrant/kafka/ExtractorTest.java | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 8375dc4..6ff4349 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ plugins { } group = 'io.qdrant' -version = '1.1.0' +version = '1.1.1' description = 'Kafka Sink Connector for Qdrant.' java.sourceCompatibility = JavaVersion.VERSION_1_8 java.targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/java/io/qdrant/kafka/ValueExtractor.java b/src/main/java/io/qdrant/kafka/ValueExtractor.java index f882927..d5d32ed 100644 --- a/src/main/java/io/qdrant/kafka/ValueExtractor.java +++ b/src/main/java/io/qdrant/kafka/ValueExtractor.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.google.protobuf.InvalidProtocolBufferException; import io.qdrant.client.grpc.JsonWithInt.Value; +import io.qdrant.client.grpc.Points.NamedVectors; import io.qdrant.client.grpc.Points.PointId; import io.qdrant.client.grpc.Points.PointStruct; import io.qdrant.client.grpc.Points.Vectors; @@ -18,7 +19,7 @@ class ValueExtractor { private static final String COLLECTION_NAME_KEY = "collection_name"; private static final String VECTOR_KEY = "vector"; private static final String PAYLOAD_KEY = "payload"; - private static final String[] REQUIRED_FIELDS = {"collection_name", "id", "vector"}; + private static final String[] REQUIRED_FIELDS = {"collection_name", "id"}; private final Map valueMap; @@ -76,6 +77,10 @@ public Map getPayload() { public Vectors getVector() { Value vectorValue = this.valueMap.get(VECTOR_KEY); + if (vectorValue == null) { + return Vectors.newBuilder().setVectors(NamedVectors.getDefaultInstance()).build(); + } + return VectorsFactory.vectors(vectorValue); } diff --git a/src/test/java/io/qdrant/kafka/ExtractorTest.java b/src/test/java/io/qdrant/kafka/ExtractorTest.java index f044625..4a47aca 100644 --- a/src/test/java/io/qdrant/kafka/ExtractorTest.java +++ b/src/test/java/io/qdrant/kafka/ExtractorTest.java @@ -122,7 +122,7 @@ void testValidateOptionsMissingField() valueMap.put("id", 12345L); ValueExtractor extractor = new ValueExtractor(valueMap); - assertThrows(DataException.class, extractor::validateOptions); + assertDoesNotThrow(extractor::validateOptions); } @Test