Skip to content

Commit 2cea539

Browse files
authored
Merge pull request #459 from weaviate/v6-orm
v6: ORM
2 parents 2241daa + c87e3eb commit 2cea539

36 files changed

Lines changed: 1159 additions & 76 deletions

src/it/java/io/weaviate/containers/Weaviate.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ public static Weaviate.Builder custom() {
9292
public static class Builder {
9393
private String versionTag;
9494
private Set<String> enableModules = new HashSet<>();
95-
private boolean telemetry;
9695

9796
private Map<String, String> environment = new HashMap<>();
9897

9998
public Builder() {
10099
this.versionTag = VERSION;
101-
this.telemetry = false;
100+
enableAutoSchema(false);
102101
}
103102

104103
public Builder withVersion(String version) {
@@ -143,6 +142,11 @@ public Builder enableTelemetry(boolean enable) {
143142
return this;
144143
}
145144

145+
public Builder enableAutoSchema(boolean enable) {
146+
environment.put("AUTOSCHEMA_ENABLED", Boolean.toString(!enable));
147+
return this;
148+
}
149+
146150
public Builder enableAnonymousAccess(boolean enable) {
147151
environment.put("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", Boolean.toString(enable));
148152
return this;
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
package io.weaviate.integration;
2+
3+
import java.time.OffsetDateTime;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.UUID;
7+
8+
import org.assertj.core.api.Assertions;
9+
import org.assertj.core.api.InstanceOfAssertFactories;
10+
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
11+
import org.junit.BeforeClass;
12+
import org.junit.Test;
13+
14+
import io.weaviate.ConcurrentTest;
15+
import io.weaviate.client6.v1.api.WeaviateClient;
16+
import io.weaviate.client6.v1.api.collections.CollectionConfig;
17+
import io.weaviate.client6.v1.api.collections.annotations.Collection;
18+
import io.weaviate.client6.v1.api.collections.annotations.Property;
19+
import io.weaviate.client6.v1.api.collections.data.InsertManyResponse.InsertObject;
20+
import io.weaviate.client6.v1.api.collections.query.Where;
21+
import io.weaviate.containers.Container;
22+
23+
public class ORMITest extends ConcurrentTest {
24+
private static WeaviateClient client = Container.WEAVIATE.getClient();
25+
26+
@Collection("ORMITest")
27+
static record Thing(
28+
// text / text[]
29+
String text,
30+
String[] textArray,
31+
List<String> textList,
32+
33+
// date / date[]
34+
OffsetDateTime date,
35+
OffsetDateTime[] dateArray,
36+
List<OffsetDateTime> dateList,
37+
38+
// uuid / uuid[]
39+
UUID uuid,
40+
UUID[] uuidArray,
41+
List<UUID> uuidList,
42+
43+
// int / int[]
44+
@Property("short") short short_,
45+
Short shortBoxed,
46+
short[] shortArray,
47+
Short[] shortBoxedArray,
48+
List<Short> shortBoxedList,
49+
50+
@Property("int") int int_,
51+
Integer intBoxed,
52+
int[] intArray,
53+
Integer[] intBoxedArray,
54+
List<Integer> intBoxedList,
55+
56+
@Property("long") long long_,
57+
Long longBoxed,
58+
long[] longArray,
59+
Long[] longBoxedArray,
60+
List<Long> longBoxedList,
61+
62+
// number / number[]
63+
@Property("float") float float_,
64+
Float floatBoxed,
65+
float[] floatArray,
66+
Float[] floatBoxedArray,
67+
List<Float> floatBoxedList,
68+
69+
@Property("double") double double_,
70+
Double doubleBoxed,
71+
double[] doubleArray,
72+
Double[] doubleBoxedArray,
73+
List<Double> doubleBoxedList,
74+
75+
// boolean / boolean[]
76+
@Property("boolean") boolean boolean_,
77+
Boolean booleanBoxed,
78+
boolean[] booleanArray,
79+
Boolean[] booleanBoxedArray,
80+
List<Boolean> booleanBoxedList) {
81+
}
82+
83+
@BeforeClass
84+
public static void setUp() throws Exception {
85+
client.collections.create(Thing.class);
86+
}
87+
88+
@Test
89+
public void test_createCollection() throws Exception {
90+
// Arrange
91+
var things = client.collections.use(Thing.class);
92+
93+
// Act
94+
var config = things.config.get();
95+
96+
// Assert
97+
Assertions.assertThat(config).get()
98+
.returns("ORMITest", CollectionConfig::collectionName)
99+
.extracting(CollectionConfig::properties,
100+
InstanceOfAssertFactories.list(io.weaviate.client6.v1.api.collections.Property.class))
101+
.extracting(p -> Map.entry(
102+
p.propertyName(),
103+
p.dataTypes().get(0)))
104+
.contains(
105+
Map.entry("text", "text"),
106+
Map.entry("textArray", "text[]"),
107+
Map.entry("textList", "text[]"),
108+
109+
Map.entry("date", "date"),
110+
Map.entry("dateArray", "date[]"),
111+
Map.entry("dateList", "date[]"),
112+
113+
Map.entry("uuid", "uuid"),
114+
Map.entry("uuidArray", "uuid[]"),
115+
Map.entry("uuidList", "uuid[]"),
116+
117+
Map.entry("short", "int"),
118+
Map.entry("shortBoxed", "int"),
119+
Map.entry("shortArray", "int[]"),
120+
Map.entry("shortBoxedArray", "int[]"),
121+
Map.entry("shortBoxedList", "int[]"),
122+
123+
Map.entry("int", "int"),
124+
Map.entry("intBoxed", "int"),
125+
Map.entry("intArray", "int[]"),
126+
Map.entry("intBoxedArray", "int[]"),
127+
Map.entry("intBoxedList", "int[]"),
128+
129+
Map.entry("long", "int"),
130+
Map.entry("longBoxed", "int"),
131+
Map.entry("longArray", "int[]"),
132+
Map.entry("longBoxedArray", "int[]"),
133+
Map.entry("longBoxedList", "int[]"),
134+
135+
Map.entry("float", "number"),
136+
Map.entry("floatBoxed", "number"),
137+
Map.entry("floatArray", "number[]"),
138+
Map.entry("floatBoxedArray", "number[]"),
139+
Map.entry("floatBoxedList", "number[]"),
140+
141+
Map.entry("double", "number"),
142+
Map.entry("doubleBoxed", "number"),
143+
Map.entry("doubleArray", "number[]"),
144+
Map.entry("doubleBoxedArray", "number[]"),
145+
Map.entry("doubleBoxedList", "number[]"),
146+
147+
Map.entry("boolean", "boolean"),
148+
Map.entry("booleanBoxed", "boolean"),
149+
Map.entry("booleanArray", "boolean[]"),
150+
Map.entry("booleanBoxedArray", "boolean[]"),
151+
Map.entry("booleanBoxedList", "boolean[]"));
152+
}
153+
154+
private final RecursiveComparisonConfiguration COMPARISON_CONFIG = RecursiveComparisonConfiguration.builder()
155+
// Assertj is having a really bad time comparing List<Float>,
156+
// so we'll just always return true here.
157+
.withComparatorForFields((a, b) -> 0, "floatBoxedList")
158+
.withComparatorForType((a, b) -> Double.compare(a.doubleValue(), b.doubleValue()), Number.class)
159+
.build();
160+
161+
@Test
162+
public void test_insertAndQuery() throws Exception {
163+
short short_ = 666;
164+
int int_ = 666;
165+
long long_ = 666;
166+
float float_ = 666;
167+
double double_ = 666;
168+
boolean boolean_ = true;
169+
UUID uuid = UUID.randomUUID();
170+
OffsetDateTime date = OffsetDateTime.now();
171+
String text = "hello";
172+
173+
var thing = new Thing(
174+
text,
175+
new String[] { text },
176+
List.of(text),
177+
178+
OffsetDateTime.now(),
179+
new OffsetDateTime[] { date },
180+
List.of(date),
181+
182+
UUID.randomUUID(),
183+
new UUID[] { uuid },
184+
List.of(uuid),
185+
186+
short_,
187+
short_,
188+
new short[] { short_ },
189+
new Short[] { short_ },
190+
List.of(short_),
191+
192+
int_,
193+
int_,
194+
new int[] { int_ },
195+
new Integer[] { int_ },
196+
List.of(int_),
197+
198+
long_,
199+
long_,
200+
new long[] { long_ },
201+
new Long[] { long_ },
202+
List.of(long_),
203+
204+
float_,
205+
float_,
206+
new float[] { float_ },
207+
new Float[] { float_ },
208+
List.of(float_),
209+
210+
double_,
211+
double_,
212+
new double[] { double_ },
213+
new Double[] { double_ },
214+
List.of(double_),
215+
216+
boolean_,
217+
boolean_,
218+
new boolean[] { boolean_ },
219+
new Boolean[] { boolean_ },
220+
List.of(boolean_));
221+
222+
var things = client.collections.use(Thing.class);
223+
224+
// Act
225+
var inserted = things.data.insert(thing);
226+
227+
// Assert
228+
var response = things.query.byId(inserted.uuid());
229+
var got = Assertions.assertThat(response).get().actual();
230+
231+
Assertions.assertThat(got.properties())
232+
.usingRecursiveComparison(COMPARISON_CONFIG)
233+
.isEqualTo(thing);
234+
}
235+
236+
@Test
237+
public void test_insertManyAndQuery() throws Exception {
238+
short short_ = 666;
239+
int int_ = 666;
240+
long long_ = 666;
241+
float float_ = 666;
242+
double double_ = 666;
243+
boolean boolean_ = true;
244+
UUID uuid = UUID.randomUUID();
245+
OffsetDateTime date = OffsetDateTime.now();
246+
String text = "hello";
247+
248+
var thing = new Thing(
249+
text,
250+
new String[] { text },
251+
List.of(text),
252+
253+
OffsetDateTime.now(),
254+
new OffsetDateTime[] { date },
255+
List.of(date),
256+
257+
UUID.randomUUID(),
258+
new UUID[] { uuid },
259+
List.of(uuid),
260+
261+
short_,
262+
short_,
263+
new short[] { short_ },
264+
new Short[] { short_ },
265+
List.of(short_),
266+
267+
int_,
268+
int_,
269+
new int[] { int_ },
270+
new Integer[] { int_ },
271+
List.of(int_),
272+
273+
long_,
274+
long_,
275+
new long[] { long_ },
276+
new Long[] { long_ },
277+
List.of(long_),
278+
279+
float_,
280+
float_,
281+
new float[] { float_ },
282+
new Float[] { float_ },
283+
List.of(float_),
284+
285+
double_,
286+
double_,
287+
new double[] { double_ },
288+
new Double[] { double_ },
289+
List.of(double_),
290+
291+
boolean_,
292+
boolean_,
293+
new boolean[] { boolean_ },
294+
new Boolean[] { boolean_ },
295+
List.of(boolean_));
296+
297+
var things = client.collections.use(Thing.class);
298+
299+
// Act
300+
var inserted = things.data.insertMany(thing, thing, thing);
301+
302+
// Assert
303+
var uuids = inserted.responses().stream().map(InsertObject::uuid).toArray(String[]::new);
304+
var got = things.query.fetchObjects(q -> q.where(Where.uuid().containsAny(uuids)));
305+
Assertions.assertThat(got.objects())
306+
.hasSize(3)
307+
.usingRecursiveComparison(COMPARISON_CONFIG)
308+
.asInstanceOf(InstanceOfAssertFactories.list(Thing.class));
309+
}
310+
}

0 commit comments

Comments
 (0)