Skip to content

Commit 5b2e27e

Browse files
committed
feat: update property description
1 parent 10695c7 commit 5b2e27e

6 files changed

Lines changed: 127 additions & 52 deletions

File tree

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void testCrossReferences() throws IOException {
6161
.as("after create Things").get()
6262
.satisfies(c -> {
6363
Assertions.assertThat(c.references())
64-
.as("ownedBy").filteredOn(p -> p.name().equals("ownedBy")).first()
64+
.as("ownedBy").filteredOn(p -> p.propertyName().equals("ownedBy")).first()
6565
.extracting(p -> p.dataTypes(), InstanceOfAssertFactories.LIST)
6666
.containsOnly(nsOwners);
6767
});
@@ -81,7 +81,7 @@ public void testCrossReferences() throws IOException {
8181
.as("after add property").get()
8282
.satisfies(c -> {
8383
Assertions.assertThat(c.references())
84-
.as("soldIn").filteredOn(p -> p.name().equals("soldIn")).first()
84+
.as("soldIn").filteredOn(p -> p.propertyName().equals("soldIn")).first()
8585
.extracting(p -> p.dataTypes(), InstanceOfAssertFactories.LIST)
8686
.containsOnly(nsOnlineStores, nsMarkets);
8787
});
@@ -117,33 +117,33 @@ public void testListDeleteAll() throws IOException {
117117

118118
@Test
119119
public void testUpdateCollection() throws IOException {
120-
try {
121-
var nsBoxes = ns("Boxes");
122-
var nsThings = ns("Things");
123-
124-
client.collections.create(nsBoxes);
125-
126-
client.collections.create(nsThings,
127-
collection -> collection
128-
.description("Things stored in boxes")
129-
.properties(
130-
Property.text("name"),
131-
Property.integer("width"))
132-
.references(
133-
Property.reference("storedIn", nsBoxes)));
134-
135-
var things = client.collections.use(nsThings);
136-
137-
// Act
138-
things.config.update(nsThings, collection -> collection
139-
.description("Things stored on shelves"));
140-
141-
// Assert
142-
var thingsConfig = things.config.get();
143-
Assertions.assertThat(thingsConfig).get()
144-
.returns("Things stored on shelves", CollectionConfig::description);
145-
} catch (Exception e) {
146-
e.printStackTrace();
147-
}
120+
var nsBoxes = ns("Boxes");
121+
var nsThings = ns("Things");
122+
123+
client.collections.create(nsBoxes);
124+
125+
client.collections.create(nsThings,
126+
collection -> collection
127+
.description("Things stored in boxes")
128+
.properties(
129+
Property.text("name"),
130+
Property.integer("width",
131+
w -> w.description("how wide this thing is")))
132+
.invertedIndex(index -> index.cleanupIntervalSeconds(10))
133+
.replication(replicate -> replicate.asyncEnabled(true)));
134+
135+
var things = client.collections.use(nsThings);
136+
137+
// Act
138+
things.config.update(nsThings, collection -> collection
139+
.description("Things stored on shelves")
140+
.propertyDescription("width", "not height"));
141+
142+
// Assert
143+
var updated = things.config.get();
144+
Assertions.assertThat(updated).get()
145+
.returns("Things stored on shelves", CollectionConfig::description)
146+
.extracting(CollectionConfig::properties, InstanceOfAssertFactories.list(Property.class))
147+
.extracting(Property::description).contains("not height");
148148
}
149149
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void testReferences() throws IOException {
6161
.as("Artists: create collection")
6262
.extracting(c -> c.references().stream().findFirst())
6363
.as("has one reference property").extracting(Optional::get)
64-
.returns("hasAwards", ReferenceProperty::name)
64+
.returns("hasAwards", ReferenceProperty::propertyName)
6565
.extracting(ReferenceProperty::dataTypes, InstanceOfAssertFactories.list(String.class))
6666
.containsOnly(nsGrammy, nsOscar);
6767

@@ -87,7 +87,7 @@ public void testReferences() throws IOException {
8787
Assertions.assertThat(collectionArtists).get()
8888
.as("Artists: add reference to Movies")
8989
.extracting(c -> c.references().stream()
90-
.filter(property -> property.name().equals("featuredIn")).findFirst())
90+
.filter(property -> property.propertyName().equals("featuredIn")).findFirst())
9191
.as("featuredIn reference property").extracting(Optional::get)
9292
.extracting(ReferenceProperty::dataTypes, InstanceOfAssertFactories.list(String.class))
9393
.containsOnly(nsMovies);

src/main/java/io/weaviate/client6/v1/api/collections/CollectionConfig.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public CollectionConfig(Builder builder) {
7070
this(
7171
builder.collectionName,
7272
builder.description,
73-
builder.properties,
74-
builder.references,
73+
builder.propertyList(),
74+
builder.referenceList(),
7575
builder.vectors,
7676
builder.multiTenancy,
7777
builder.sharding,
@@ -86,8 +86,8 @@ public static class Builder implements ObjectBuilder<CollectionConfig> {
8686
private final String collectionName;
8787

8888
private String description;
89-
private List<Property> properties = new ArrayList<>();
90-
private List<ReferenceProperty> references = new ArrayList<>();
89+
private Map<String, Property> properties = new HashMap<>();
90+
private Map<String, ReferenceProperty> references = new HashMap<>();
9191
private Map<String, VectorIndex> vectors = new HashMap<>();
9292
private MultiTenancy multiTenancy;
9393
private Sharding sharding;
@@ -110,19 +110,27 @@ public Builder properties(Property... properties) {
110110
}
111111

112112
public Builder properties(List<Property> properties) {
113-
this.properties.addAll(properties);
113+
properties.forEach(property -> this.properties.put(property.propertyName(), property));
114114
return this;
115115
}
116116

117+
private List<Property> propertyList() {
118+
return this.properties.values().stream().toList();
119+
}
120+
117121
public Builder references(ReferenceProperty... references) {
118122
return references(Arrays.asList(references));
119123
}
120124

121125
public Builder references(List<ReferenceProperty> references) {
122-
this.references.addAll(references);
126+
references.forEach(reference -> this.references.put(reference.propertyName(), reference));
123127
return this;
124128
}
125129

130+
private List<ReferenceProperty> referenceList() {
131+
return this.references.values().stream().toList();
132+
}
133+
126134
public Builder vector(VectorIndex vector) {
127135
this.vectors.put(VectorIndex.DEFAULT_VECTOR_NAME, vector);
128136
return this;

src/main/java/io/weaviate/client6/v1/api/collections/Property.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ public static ReferenceProperty reference(String name, List<String> collections)
5151
return new ReferenceProperty(name, collections);
5252
}
5353

54+
public Builder edit() {
55+
return new Builder(propertyName, dataTypes)
56+
.description(description)
57+
.indexInverted(indexInverted)
58+
.indexFilterable(indexFilterable)
59+
.indexRangeFilters(indexRangeFilters)
60+
.indexSearchable(indexSearchable)
61+
.skipVectorization(skipVectorization)
62+
.vectorizePropertyName(vectorizePropertyName);
63+
}
64+
65+
public Property edit(Function<Builder, ObjectBuilder<Property>> fn) {
66+
return fn.apply(edit()).build();
67+
}
68+
5469
public Property(Builder builder) {
5570
this(
5671
builder.propertyName,
@@ -102,32 +117,32 @@ public Builder description(String description) {
102117
return this;
103118
}
104119

105-
public Builder indexInverted(boolean indexInverted) {
120+
public Builder indexInverted(Boolean indexInverted) {
106121
this.indexInverted = indexInverted;
107122
return this;
108123
}
109124

110-
public Builder indexFilterable(boolean indexFilterable) {
125+
public Builder indexFilterable(Boolean indexFilterable) {
111126
this.indexFilterable = indexFilterable;
112127
return this;
113128
}
114129

115-
public Builder indexRangeFilters(boolean indexRangeFilters) {
130+
public Builder indexRangeFilters(Boolean indexRangeFilters) {
116131
this.indexRangeFilters = indexRangeFilters;
117132
return this;
118133
}
119134

120-
public Builder indexSearchable(boolean indexSearchable) {
135+
public Builder indexSearchable(Boolean indexSearchable) {
121136
this.indexSearchable = indexSearchable;
122137
return this;
123138
}
124139

125-
public Builder skipVectorization(boolean skipVectorization) {
140+
public Builder skipVectorization(Boolean skipVectorization) {
126141
this.skipVectorization = skipVectorization;
127142
return this;
128143
}
129144

130-
public Builder vectorizePropertyName(boolean vectorizePropertyName) {
145+
public Builder vectorizePropertyName(Boolean vectorizePropertyName) {
131146
this.vectorizePropertyName = vectorizePropertyName;
132147
return this;
133148
}

src/main/java/io/weaviate/client6/v1/api/collections/ReferenceProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import com.google.gson.annotations.SerializedName;
66

77
public record ReferenceProperty(
8-
@SerializedName("name") String name,
8+
@SerializedName("name") String propertyName,
99
@SerializedName("dataType") List<String> dataTypes) {
1010

1111
public Property toProperty() {
12-
return new Property.Builder(name, dataTypes).build();
12+
return new Property.Builder(propertyName, dataTypes).build();
1313
}
1414
}

src/main/java/io/weaviate/client6/v1/api/collections/config/UpdateCollectionRequest.java

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package io.weaviate.client6.v1.api.collections.config;
22

33
import java.util.Collections;
4+
import java.util.List;
45
import java.util.Map;
56
import java.util.function.Function;
67

78
import org.apache.hc.core5.http.HttpStatus;
89

910
import io.weaviate.client6.v1.api.collections.CollectionConfig;
11+
import io.weaviate.client6.v1.api.collections.Generative;
12+
import io.weaviate.client6.v1.api.collections.InvertedIndex;
13+
import io.weaviate.client6.v1.api.collections.Replication;
14+
import io.weaviate.client6.v1.api.collections.Reranker;
1015
import io.weaviate.client6.v1.api.collections.VectorIndex;
1116
import io.weaviate.client6.v1.internal.ObjectBuilder;
1217
import io.weaviate.client6.v1.internal.json.JSON;
@@ -32,7 +37,9 @@ public UpdateCollectionRequest(Builder builder) {
3237
}
3338

3439
public static class Builder implements ObjectBuilder<UpdateCollectionRequest> {
40+
// For updating property descriptions
3541
private final CollectionConfig currentCollection;
42+
// Builder for the updated collection config.
3643
private final CollectionConfig.Builder newCollection;
3744

3845
public Builder(CollectionConfig currentCollection) {
@@ -45,18 +52,63 @@ public Builder description(String description) {
4552
return this;
4653
}
4754

55+
public Builder propertyDescription(String propertyName, String description) {
56+
for (var property : currentCollection.properties()) {
57+
if (property.propertyName().equals(propertyName)) {
58+
var newProperty = property.edit(p -> p.description(description));
59+
this.newCollection.properties(newProperty);
60+
break;
61+
}
62+
}
63+
return this;
64+
}
65+
66+
public Builder replication(Replication replication) {
67+
this.newCollection.replication(replication);
68+
return this;
69+
}
70+
71+
public Builder replication(Function<Replication.Builder, ObjectBuilder<Replication>> fn) {
72+
this.newCollection.replication(fn);
73+
return this;
74+
}
75+
76+
public Builder invertedIndex(InvertedIndex invertedIndex) {
77+
this.newCollection.invertedIndex(invertedIndex);
78+
return this;
79+
}
80+
81+
public Builder invertedIndex(Function<InvertedIndex.Builder, ObjectBuilder<InvertedIndex>> fn) {
82+
this.newCollection.invertedIndex(fn);
83+
return this;
84+
}
85+
86+
public Builder rerankerModules(Reranker... rerankerModules) {
87+
this.newCollection.rerankerModules(rerankerModules);
88+
return this;
89+
}
90+
91+
public Builder rerankerModules(List<Reranker> rerankerModules) {
92+
this.newCollection.rerankerModules(rerankerModules);
93+
return this;
94+
}
95+
96+
public Builder generativeModules(Generative... generativeModules) {
97+
this.newCollection.generativeModules(generativeModules);
98+
return this;
99+
}
100+
101+
public Builder generativeModules(List<Generative> generativeModules) {
102+
this.newCollection.generativeModules(generativeModules);
103+
return this;
104+
}
105+
48106
@SafeVarargs
49107
public final Builder vectors(Map.Entry<String, VectorIndex>... vectors) {
50108
this.newCollection.vectors(Map.ofEntries(vectors));
51109
return this;
52110
}
53111

54-
// TODO: propertyDescriptions
55-
// TODO: generative config
56-
// TODO: inverted index
57-
// TODO: replication
58-
// TODO: reranker
59-
60112
@Override
61113
public UpdateCollectionRequest build() {
62114
return new UpdateCollectionRequest(this);

0 commit comments

Comments
 (0)