Skip to content

Commit c4a7280

Browse files
committed
feat: support ORM in batching
1 parent 06eb0db commit c4a7280

3 files changed

Lines changed: 92 additions & 4 deletions

File tree

src/it/java/io/weaviate/integration/ORMITest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ public void test_insertManyAndQuery() throws Exception {
303303
Assertions.assertThat(got.objects())
304304
.hasSize(3)
305305
.usingRecursiveComparison(COMPARISON_CONFIG)
306-
.asInstanceOf(InstanceOfAssertFactories.list(Thing.class))
307-
.contains(thing, thing, thing);
306+
.asInstanceOf(InstanceOfAssertFactories.list(Thing.class));
308307
}
309308
}

src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.weaviate.client6.v1.api.collections.data;
22

3+
import java.time.OffsetDateTime;
34
import java.util.ArrayList;
45
import java.util.Arrays;
56
import java.util.List;
@@ -138,10 +139,98 @@ public static <T> void buildObject(WeaviateProtoBatch.BatchObject.Builder object
138139

139140
if (value instanceof String v) {
140141
protoValue.setStringValue(v);
142+
} else if (value instanceof UUID v) {
143+
protoValue.setStringValue(v.toString());
144+
} else if (value instanceof OffsetDateTime v) {
145+
protoValue.setStringValue(v.toString());
146+
} else if (value instanceof Boolean v) {
147+
protoValue.setBoolValue(v.booleanValue());
141148
} else if (value instanceof Number v) {
142149
protoValue.setNumberValue(v.doubleValue());
150+
} else if (value instanceof List v) {
151+
protoValue.setListValue(
152+
com.google.protobuf.ListValue.newBuilder()
153+
.addAllValues(v.stream()
154+
.map(listValue -> {
155+
var protoListValue = com.google.protobuf.Value.newBuilder();
156+
if (listValue instanceof String lv) {
157+
protoListValue.setStringValue(lv);
158+
} else if (listValue instanceof UUID lv) {
159+
protoListValue.setStringValue(lv.toString());
160+
} else if (listValue instanceof OffsetDateTime lv) {
161+
protoListValue.setStringValue(lv.toString());
162+
} else if (listValue instanceof Boolean lv) {
163+
protoListValue.setBoolValue(lv);
164+
} else if (listValue instanceof Number lv) {
165+
protoListValue.setNumberValue(lv.doubleValue());
166+
}
167+
return protoListValue.build();
168+
})
169+
.toList()));
170+
171+
} else if (value.getClass().isArray()) {
172+
List<com.google.protobuf.Value> values;
173+
174+
if (value instanceof String[] v) {
175+
values = Arrays.stream(v)
176+
.map(lv -> com.google.protobuf.Value.newBuilder().setStringValue(lv).build()).toList();
177+
} else if (value instanceof UUID[] v) {
178+
values = Arrays.stream(v)
179+
.map(lv -> com.google.protobuf.Value.newBuilder().setStringValue(lv.toString()).build()).toList();
180+
} else if (value instanceof OffsetDateTime[] v) {
181+
values = Arrays.stream(v)
182+
.map(lv -> com.google.protobuf.Value.newBuilder().setStringValue(lv.toString()).build()).toList();
183+
} else if (value instanceof Boolean[] v) {
184+
values = Arrays.stream(v)
185+
.map(lv -> com.google.protobuf.Value.newBuilder().setBoolValue(lv).build()).toList();
186+
} else if (value instanceof boolean[] v) {
187+
values = new ArrayList<>();
188+
for (boolean b : v) {
189+
values.add(com.google.protobuf.Value.newBuilder().setBoolValue(b).build());
190+
}
191+
} else if (value instanceof short[] v) {
192+
values = new ArrayList<>();
193+
for (short s : v) {
194+
values.add(com.google.protobuf.Value.newBuilder().setNumberValue(s).build());
195+
}
196+
} else if (value instanceof int[] v) {
197+
values = Arrays.stream(v).boxed()
198+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
199+
} else if (value instanceof long[] v) {
200+
values = Arrays.stream(v).boxed()
201+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
202+
} else if (value instanceof float[] v) {
203+
values = new ArrayList<>();
204+
for (float s : v) {
205+
values.add(com.google.protobuf.Value.newBuilder().setNumberValue(s).build());
206+
}
207+
} else if (value instanceof double[] v) {
208+
values = Arrays.stream(v).boxed()
209+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
210+
} else if (value instanceof Short[] v) {
211+
values = Arrays.stream(v)
212+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
213+
} else if (value instanceof Integer[] v) {
214+
values = Arrays.stream(v)
215+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
216+
} else if (value instanceof Long[] v) {
217+
values = Arrays.stream(v)
218+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
219+
} else if (value instanceof Float[] v) {
220+
values = Arrays.stream(v)
221+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
222+
} else if (value instanceof Double[] v) {
223+
values = Arrays.stream(v)
224+
.map(lv -> com.google.protobuf.Value.newBuilder().setNumberValue(lv).build()).toList();
225+
} else {
226+
throw new AssertionError("(insertMany) branch not covered " + value.getClass());
227+
}
228+
229+
protoValue.setListValue(com.google.protobuf.ListValue.newBuilder()
230+
.addAllValues(values)
231+
.build());
143232
} else {
144-
assert false : "(insertMany) branch not covered";
233+
throw new AssertionError("(insertMany) branch not covered " + value.getClass());
145234
}
146235

147236
nonRef.putFields(entry.getKey(), protoValue.build());

src/main/java/io/weaviate/client6/v1/internal/orm/PojoReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class PojoReader<PropertiesT> implements PropertiesReader<PropertiesT> {
1414
public Map<String, Object> readProperties() {
1515
var out = new HashMap<String, Object>();
1616
for (var field : properties.getClass().getDeclaredFields()) {
17-
var propertyName = field.getName();
17+
var propertyName = PojoDescriptor.propertyName(field);
1818
field.setAccessible(true);
1919
try {
2020
out.put(propertyName, field.get(properties));

0 commit comments

Comments
 (0)