-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from weaviate/grpc-cross-refs-support
Add support for cross references in gRPC Batch API
- Loading branch information
Showing
13 changed files
with
460 additions
and
59 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/io/weaviate/client/base/util/CrossReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.weaviate.client.base.util; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.experimental.FieldDefaults; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@ToString | ||
@Getter | ||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) | ||
public class CrossReference { | ||
String peerName; | ||
String className; | ||
String targetID; | ||
boolean local; | ||
|
||
public CrossReference(String peerName, String className, String targetID) { | ||
this.local = peerName != null && peerName.equals("localhost"); | ||
this.peerName = peerName; | ||
this.className = className; | ||
this.targetID = targetID; | ||
} | ||
|
||
public static CrossReference fromBeacon(String beacon) { | ||
if (StringUtils.isNotBlank(beacon) && beacon.startsWith("weaviate://")) { | ||
String path = beacon.replaceFirst("weaviate://", ""); | ||
String[] parts = path.split("/"); | ||
if (parts.length == 3) { | ||
return new CrossReference(parts[0], parts[1], parts[2]); | ||
} | ||
if (parts.length == 2) { | ||
return new CrossReference(parts[0], "", parts[1]); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/io/weaviate/client/base/util/CrossReferenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.weaviate.client.base.util; | ||
|
||
import org.junit.Test; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CrossReferenceTest { | ||
|
||
@Test | ||
public void testParseBeaconWithClass() { | ||
// given | ||
String beacon = "weaviate://localhost/RefClass/f81bfe5e-16ba-4615-a516-46c2ae2e5a80"; | ||
// when | ||
CrossReference crossRef = CrossReference.fromBeacon(beacon); | ||
// then | ||
assertThat(crossRef).isNotNull().satisfies(cf -> { | ||
assertThat(cf.isLocal()).isTrue(); | ||
assertThat(cf.getPeerName()).isEqualTo("localhost"); | ||
assertThat(cf.getClassName()).isEqualTo("RefClass"); | ||
assertThat(cf.getTargetID()).isEqualTo("f81bfe5e-16ba-4615-a516-46c2ae2e5a80"); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testParseBeaconWithoutClass() { | ||
// given | ||
String beacon = "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80"; | ||
// when | ||
CrossReference crossRef = CrossReference.fromBeacon(beacon); | ||
// then | ||
assertThat(crossRef).isNotNull().satisfies(cf -> { | ||
assertThat(cf.isLocal()).isTrue(); | ||
assertThat(cf.getPeerName()).isEqualTo("localhost"); | ||
assertThat(cf.getClassName()).isEqualTo(""); | ||
assertThat(cf.getTargetID()).isEqualTo("f81bfe5e-16ba-4615-a516-46c2ae2e5a80"); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testParseBeaconEmpty() { | ||
// given | ||
String beacon = ""; | ||
// when | ||
CrossReference crossRef = CrossReference.fromBeacon(beacon); | ||
// then | ||
assertThat(crossRef).isNull(); | ||
} | ||
} |
Oops, something went wrong.