Skip to content

Commit 931134b

Browse files
authored
Add source_collection to indexMetaDatabase object and ignore newly added fields (#58)
## Problem `source_collection` is a newly added field in `indexMetaDatabase` object of describeIndex response body. But without adding it to the response body of describe index call, it breaks. ## Solution Added the field as well as added support to ignore newly added fields. ## Type of Change - [X] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan Ran integration tests and added unit test for the same
1 parent 14224b6 commit 931134b

14 files changed

+104
-38
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
[comment]: <> (When bumping [pc:VERSION_LATEST_RELEASE] create a new entry below)
44
### Unreleased version
5+
### v0.7.4
6+
- Add source_collection and support to ignore newly added fields to the response body for describeIndex's indexMetaDatabase object
7+
58
### v0.7.3
69
- Add assert with retry mechanism
710
- Add deprecation warning for queries parameter

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ Maven:
1515
<dependency>
1616
<groupId>io.pinecone</groupId>
1717
<artifactId>pinecone-client</artifactId>
18-
<version>0.7.3</version>
18+
<version>0.7.4</version>
1919
</dependency>
2020
```
2121

2222
[comment]: <> (^ [pc:VERSION_LATEST_RELEASE])
2323

2424
Gradle:
2525
```
26-
implementation "io.pinecone:pinecone-client:0.7.3"
26+
implementation "io.pinecone:pinecone-client:0.7.4"
2727
```
2828

2929
[comment]: <> (^ [pc:VERSION_LATEST_RELEASE])
3030

31-
Alternatively, you can use our standalone uberjar [pinecone-client-0.7.3-all.jar](https://repo1.maven.org/maven2/io/pinecone/pinecone-client/0.7.3/pinecone-client-0.7.3-all.jar), which bundles the pinecone client and all dependencies together inside a single jar. You can include this on your classpath like any 3rd party JAR without having to obtain the *pinecone-client* dependencies separately.
31+
Alternatively, you can use our standalone uberjar [pinecone-client-0.7.4-all.jar](https://repo1.maven.org/maven2/io/pinecone/pinecone-client/0.7.4/pinecone-client-0.7.4-all.jar), which bundles the pinecone client and all dependencies together inside a single jar. You can include this on your classpath like any 3rd party JAR without having to obtain the *pinecone-client* dependencies separately.
3232

3333
[comment]: <> (^ [pc:VERSION_LATEST_RELEASE])
3434

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pineconeClientVersion = 0.7.3
1+
pineconeClientVersion = 0.7.4

src/integration/java/io/pinecone/helpers/RetryAssert.java renamed to src/integration/java/io/pinecone/helpers/AssertRetry.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package io.pinecone.helpers;
22

3+
import java.io.IOException;
34
import java.util.concurrent.ExecutionException;
45

5-
public class RetryAssert {
6+
public class AssertRetry {
67
private static final int maxRetry = 4;
78
private static int delay = 1500;
89

@@ -14,7 +15,7 @@ public static void assertWithRetry(AssertionRunnable assertionRunnable) throws I
1415
try {
1516
assertionRunnable.run();
1617
success = true;
17-
} catch (AssertionError | ExecutionException e) {
18+
} catch (AssertionError | ExecutionException | IOException e) {
1819
retryCount++;
1920
delay*=2;
2021
Thread.sleep(delay);
@@ -24,6 +25,6 @@ public static void assertWithRetry(AssertionRunnable assertionRunnable) throws I
2425

2526
@FunctionalInterface
2627
public interface AssertionRunnable {
27-
void run() throws AssertionError, ExecutionException, InterruptedException;
28+
void run() throws AssertionError, ExecutionException, InterruptedException, IOException;
2829
}
2930
}

src/integration/java/io/pinecone/helpers/IndexManager.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.io.IOException;
88
import java.util.List;
99

10+
import static io.pinecone.helpers.AssertRetry.assertWithRetry;
11+
1012
public class IndexManager {
1113
private static PineconeClientConfig config;
1214

@@ -67,15 +69,12 @@ private static String createNewIndex(int dimension, PineconeIndexOperationClient
6769

6870
public static IndexMeta isIndexReady(String indexName, PineconeIndexOperationClient indexOperationClient)
6971
throws IOException, InterruptedException {
70-
IndexMeta indexMeta;
71-
while (true) {
72-
indexMeta = indexOperationClient.describeIndex(indexName);
73-
if (indexMeta.getStatus().getState().equalsIgnoreCase("ready")) {
74-
break;
75-
}
76-
Thread.sleep(1000);
77-
}
72+
final IndexMeta[] indexMeta = new IndexMeta[1];
73+
assertWithRetry(() -> {
74+
indexMeta[0] = indexOperationClient.describeIndex(indexName);
75+
assert (indexMeta[0].getStatus().getState().equalsIgnoreCase("ready"));
76+
});
7877

79-
return indexMeta;
78+
return indexMeta[0];
8079
}
8180
}

src/integration/java/io/pinecone/integration/controlPlane/ConfigureIndexTest.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public void configureIndexWithInvalidIndexName() {
4343
try {
4444
isIndexReady(indexName, indexOperationClient);
4545
indexOperationClient.configureIndex("non-existent-index", configureIndexRequest);
46-
} catch (PineconeNotFoundException exception) {
47-
assert (exception.getLocalizedMessage().contains("404: Not Found"));
46+
} catch (PineconeNotFoundException notFoundException) {
47+
assert (notFoundException.getLocalizedMessage().toLowerCase().contains("not found"));
4848
} catch (IOException | InterruptedException exception) {
4949
logger.error(exception.toString());
5050
}
@@ -57,10 +57,8 @@ public void configureIndexExceedingQuota() {
5757
try {
5858
isIndexReady(indexName, indexOperationClient);
5959
indexOperationClient.configureIndex(indexName, configureIndexRequest);
60-
} catch (PineconeBadRequestException exception) {
61-
assert (exception.getLocalizedMessage().contains("The index exceeds the project quota"));
62-
assert (exception.getLocalizedMessage().contains("Upgrade your account or change" +
63-
" the project settings to increase the quota."));
60+
} catch (PineconeBadRequestException badRequestException) {
61+
assert (badRequestException.getLocalizedMessage().contains("Capacity Reached. Increase your quota or upgrade to create more indexes."));
6462
} catch (Exception exception) {
6563
logger.error(exception.toString());
6664
}
@@ -110,8 +108,8 @@ public void changingBasePodType() {
110108

111109
isIndexReady(indexName, indexOperationClient);
112110
indexOperationClient.configureIndex(indexName, configureIndexRequest);
113-
} catch (PineconeBadRequestException pineconeBadRequestException) {
114-
assertEquals(pineconeBadRequestException.getMessage(), "updating base pod type is not supported");
111+
} catch (PineconeBadRequestException badRequestException) {
112+
assertEquals(badRequestException.getMessage(), "Bad request: Cannot change pod type.");
115113
} catch (Exception exception) {
116114
logger.error(exception.getLocalizedMessage());
117115
}
@@ -166,7 +164,7 @@ public void sizeDown() throws IOException, InterruptedException {
166164
Thread.sleep(3500);
167165
} catch (Exception exception) {
168166
assertEquals(exception.getClass(), PineconeBadRequestException.class);
169-
assertEquals(exception.getMessage(), "scaling down pod type is not supported");
167+
assert(exception.getMessage().contains("Bad request: Cannot scale down an index, only up."));
170168
} finally {
171169
// Delete this index since it'll be unused for other tests
172170
indexOperationClient.deleteIndex(indexName);

src/integration/java/io/pinecone/integration/dataplane/PineconeClientLiveIntegTest.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
import java.util.List;
1919

2020
import static io.pinecone.helpers.IndexManager.createIndexIfNotExistsDataPlane;
21-
import static io.pinecone.helpers.RetryAssert.assertWithRetry;
22-
import static org.hamcrest.MatcherAssert.assertThat;
23-
import static org.hamcrest.Matchers.equalTo;
24-
import static org.hamcrest.Matchers.notNullValue;
21+
import static io.pinecone.helpers.AssertRetry.assertWithRetry;
2522

2623
public class PineconeClientLiveIntegTest {
2724

@@ -155,8 +152,7 @@ public void sanity() throws InterruptedException {
155152

156153
assertWithRetry(() -> {
157154
QueryResponse queryResponse = blockingStub.query(queryByIdRequest);
158-
assertThat(queryResponse, notNullValue());
159-
assertThat(queryResponse.getMatchesCount(), equalTo(1));
155+
Assertions.assertEquals(queryResponse.getMatchesCount(),1);
160156
assert (queryResponse.getMatches(0).getValuesList().containsAll(updateValueList));
161157
});
162158

src/integration/java/io/pinecone/integration/dataplane/UpsertAndDescribeIndexStatsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import static io.pinecone.helpers.BuildUpsertRequest.*;
88
import static io.pinecone.helpers.IndexManager.createIndexIfNotExistsDataPlane;
9-
import static io.pinecone.helpers.RetryAssert.assertWithRetry;
9+
import static io.pinecone.helpers.AssertRetry.assertWithRetry;
1010
import static org.junit.jupiter.api.Assertions.assertEquals;
1111

1212
import java.io.IOException;

src/main/java/io/pinecone/PineconeClientConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private String maskedApiKey() {
139139
}
140140

141141
public String getUserAgent() {
142-
String userAgentLanguage = "lang=java; pineconeClientVersion = v0.7.3";
142+
String userAgentLanguage = "lang=java; pineconeClientVersion = v0.7.4";
143143
return (this.getUsageContext() != null) ?
144144
userAgentLanguage + "; usageContext=" + this.getUsageContext() : userAgentLanguage;
145145
}

src/main/java/io/pinecone/model/CreateIndexRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CreateIndexRequest {
1212

1313
private String metric = "cosine";
1414

15-
private Integer pods = 1;
15+
private Integer pods;
1616

1717
private Integer replicas = 1;
1818

src/main/java/io/pinecone/model/IndexMetaDatabase.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.pinecone.model;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45

6+
@JsonIgnoreProperties(ignoreUnknown = true)
57
public class IndexMetaDatabase {
68
private String name;
79

@@ -18,6 +20,9 @@ public class IndexMetaDatabase {
1820
@JsonProperty("pod_type")
1921
private String podType;
2022

23+
@JsonProperty("source_collection")
24+
private String sourceCollection;
25+
2126
private IndexMetadataConfig metadataConfig;
2227

2328
public IndexMetaDatabase () {
@@ -87,6 +92,15 @@ public IndexMetaDatabase withPodType(String podType) {
8792
return this;
8893
}
8994

95+
public String getSourceCollection() {
96+
return sourceCollection;
97+
}
98+
99+
public IndexMetaDatabase withSourceCollection(String sourceCollection) {
100+
this.sourceCollection = sourceCollection;
101+
return this;
102+
}
103+
90104
public IndexMetadataConfig getMetadataConfig() {
91105
return metadataConfig;
92106
}
@@ -107,6 +121,7 @@ public String toString() {
107121
", shards=" + shards +
108122
", podType='" + podType + '\'' +
109123
", metadataConfig=" + metadataConfig +
124+
", sourceCollection=" + sourceCollection +
110125
'}';
111126
}
112127
}

src/test/java/io/pinecone/PineconeIndexOperationClientTest.java

+56-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.junit.jupiter.api.BeforeAll;
1111

1212
import java.io.IOException;
13+
import java.nio.file.Files;
14+
import java.nio.file.Paths;
1315
import java.util.Arrays;
1416
import java.util.List;
1517

@@ -176,10 +178,59 @@ public void testCreateIndexWithAllFields() throws IOException {
176178
@Test
177179
public void testDescribeIndex() throws IOException {
178180
String indexName = "testIndex";
179-
String indexJsonString = "{\"database\":{\"name\":\"testIndex\",\"metric\":\"cosine\",\"dimension\":3," +
180-
"\"replicas\":1,\"shards\":1,\"pods\":1,\"pod_type\":\"p1.x1\"}," +
181-
"\"status\":{\"waiting\":[],\"crashed\":[],\"host\":\"url\",\"port\":433," +
182-
"\"state\":\"Ready\",\"ready\":true}}";
181+
String indexString = "";
182+
String filePath = "src/test/resources/indexJsonString.json";
183+
String indexJsonString = new String(Files.readAllBytes(Paths.get(filePath)));
184+
185+
PineconeClientConfig clientConfig = new PineconeClientConfig()
186+
.withApiKey("testApiKey")
187+
.withEnvironment("testEnvironment");
188+
IndexMetaDatabase metaDatabase = new IndexMetaDatabase()
189+
.withName("testIndex")
190+
.withMetric("cosine")
191+
.withDimension(3)
192+
.withReplicas(1)
193+
.withShards(1)
194+
.withPods(1)
195+
.withPodType("p1.x1")
196+
.withSourceCollection("randomCollection");
197+
IndexStatus indexStatus = new IndexStatus()
198+
.withHost("url")
199+
.withState("Ready")
200+
.withReady(true)
201+
.withPort("433");
202+
203+
IndexMeta expectedIndexMeta = new IndexMeta()
204+
.withMetaDatabase(metaDatabase)
205+
.withStatus(indexStatus);
206+
207+
Call mockCall = mock(Call.class);
208+
Response mockResponse = new Response.Builder()
209+
.request(new Request.Builder().url("http://localhost").build())
210+
.protocol(Protocol.HTTP_1_1)
211+
.code(200)
212+
.message("OK")
213+
.body(ResponseBody.create(indexJsonString, MediaType.parse("application/json")))
214+
.build();
215+
216+
when(mockCall.execute()).thenReturn(mockResponse);
217+
218+
OkHttpClient mockClient = mock(OkHttpClient.class);
219+
when(mockClient.newCall(any(Request.class))).thenReturn(mockCall);
220+
when(mockCall.execute()).thenReturn(mockResponse);
221+
222+
PineconeIndexOperationClient indexOperationClient = new PineconeIndexOperationClient(clientConfig, mockClient);
223+
IndexMeta actualIndexMeta = indexOperationClient.describeIndex(indexName);
224+
225+
assertEquals(expectedIndexMeta.toString(), actualIndexMeta.toString());
226+
}
227+
228+
@Test
229+
public void testDescribeIndexWithExtraFields() throws IOException {
230+
String indexName = "testIndex";
231+
String filePath = "src/test/resources/indexJsonStringWithExtraFields.json";
232+
String indexJsonString = new String(Files.readAllBytes(Paths.get(filePath)));
233+
183234
PineconeClientConfig clientConfig = new PineconeClientConfig()
184235
.withApiKey("testApiKey")
185236
.withEnvironment("testEnvironment");
@@ -191,6 +242,7 @@ public void testDescribeIndex() throws IOException {
191242
.withShards(1)
192243
.withPods(1)
193244
.withPodType("p1.x1");
245+
194246
IndexStatus indexStatus = new IndexStatus()
195247
.withHost("url")
196248
.withState("Ready")
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"database":{"name":"testIndex","metric":"cosine","dimension":3,"replicas":1,"shards":1,"pods":1,"pod_type":"p1.x1", "source_collection":"randomCollection"},"status":{"waiting":[],"crashed":[],"host":"url","port":433,"state":"Ready","ready":true}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"database":{"name":"testIndex","metric":"cosine","dimension":3,"replicas":1,"shards":1,"pods":1,"pod_type":"p1.x1","extra_field":"random1"},"status":{"waiting":[],"crashed":[],"host":"url","port":433,"state":"Ready","ready":true, "extra_field":"random2"}}

0 commit comments

Comments
 (0)