-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
9 deletions.
There are no files selected for viewing
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,33 @@ | ||
package io.qdrant.client.utils; | ||
|
||
import io.qdrant.client.grpc.Collections.ShardKey; | ||
|
||
/** | ||
* Utility class for working with collections. | ||
*/ | ||
public class CollectionUtil { | ||
|
||
/** | ||
* Creates a {@link ShardKey} based on a keyword. | ||
* | ||
* @param keyword The keyword to create the shard key from | ||
* @return The {@link ShardKey} object | ||
*/ | ||
public static ShardKey shardKey(String keyword) { | ||
return ShardKey.newBuilder() | ||
.setKeyword(keyword) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Creates a {@link ShardKey} based on a number. | ||
* | ||
* @param number The number to create the shard key from | ||
* @return The {@link ShardKey} object | ||
*/ | ||
public static ShardKey shardKey(long number) { | ||
return ShardKey.newBuilder() | ||
.setNumber(number) | ||
.build(); | ||
} | ||
} |
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
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
27 changes: 27 additions & 0 deletions
27
src/test/java/io/qdrant/client/utils/CollectionUtilTest.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,27 @@ | ||
package io.qdrant.client.utils; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import io.qdrant.client.grpc.Collections.ShardKey; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class CollectionUtilTest { | ||
|
||
@Test | ||
void testShardKeyWithString() { | ||
String keyword = "somethinKeySomething"; | ||
ShardKey shardKey = CollectionUtil.shardKey(keyword); | ||
assertNotNull(shardKey); | ||
assertEquals(keyword, shardKey.getKeyword()); | ||
} | ||
|
||
@Test | ||
void testShardKeyWithLong() { | ||
long number = 12345L; | ||
ShardKey shardKey = CollectionUtil.shardKey(number); | ||
assertNotNull(shardKey); | ||
assertEquals(number, shardKey.getNumber()); | ||
} | ||
} |
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