Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury-Fridlyand committed Oct 2, 2024
1 parent a15d0ec commit 237951c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions glide-core/src/protobuf/command_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ enum RequestType {
ScriptShow = 218;

FtCreate = 2000;
FtDrop = 2002;
}

message Command {
Expand Down
3 changes: 3 additions & 0 deletions glide-core/src/request_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ pub enum RequestType {
ScriptKill = 217,
ScriptShow = 218,
FtCreate = 2000,
FtDrop = 2002,
}

fn get_two_word_command(first: &str, second: &str) -> Cmd {
Expand Down Expand Up @@ -459,6 +460,7 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
ProtobufRequestType::ScriptKill => RequestType::ScriptKill,
ProtobufRequestType::ScriptShow => RequestType::ScriptShow,
ProtobufRequestType::FtCreate => RequestType::FtCreate,
ProtobufRequestType::FtDrop => RequestType::FtDrop,
}
}
}
Expand Down Expand Up @@ -688,6 +690,7 @@ impl RequestType {
RequestType::ScriptFlush => Some(get_two_word_command("SCRIPT", "FLUSH")),
RequestType::ScriptKill => Some(get_two_word_command("SCRIPT", "KILL")),
RequestType::FtCreate => Some(cmd("FT.CREATE")),
RequestType::FtDrop => Some(cmd("FT.DROPINDEX")),
}
}
}
7 changes: 7 additions & 0 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static command_request.CommandRequestOuterClass.RequestType.FCall;
import static command_request.CommandRequestOuterClass.RequestType.FCallReadOnly;
import static command_request.CommandRequestOuterClass.RequestType.FtCreate;
import static command_request.CommandRequestOuterClass.RequestType.FtDrop;
import static command_request.CommandRequestOuterClass.RequestType.GeoAdd;
import static command_request.CommandRequestOuterClass.RequestType.GeoDist;
import static command_request.CommandRequestOuterClass.RequestType.GeoHash;
Expand Down Expand Up @@ -5167,4 +5168,10 @@ public CompletableFuture<String> ftcreate(
return commandManager.submitNewCommand(
FtCreate, args.toArray(String[]::new), this::handleStringResponse);
}

@Override
public CompletableFuture<String> ftdrop(@NonNull String indexName) {
return commandManager.submitNewCommand(
FtDrop, new String[] {indexName}, this::handleStringResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface VectorSearchBaseCommands {
* Creates an index and initiates a backfill of that index.
*
* @see TODO
* @param indexName Key name where index is stored.
* @param indexName The index name.
* @param indexType The index type.
* @param prefixes (Optional) A list of prefixes of index definitions
* @param fields Fields to populate into the index.
Expand All @@ -30,4 +30,17 @@ public interface VectorSearchBaseCommands {
*/
CompletableFuture<String> ftcreate(
String indexName, IndexType indexType, String[] prefixes, FieldInfo[] fields);

/**
* Deletes an index and associated content. Keys are unaffected.
*
* @see TODO
* @param indexName The index name.
* @return <code>OK</code>.
* @example
* <pre>{@code
* client.ftdrop("hash_idx1").get();
* }</pre>
*/
CompletableFuture<String> ftdrop(String indexName);
}
4 changes: 2 additions & 2 deletions java/integTest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ test {

tasks.register('modulesTest', Test) {
doFirst {
systemProperty 'test.server.standalone.ports', 6379
systemProperty 'test.server.cluster.ports', 7000
standalonePorts = [6379]
clusterPorts = [7000]
}

filter {
Expand Down
59 changes: 59 additions & 0 deletions java/integTest/src/test/java/glide/modules/VectorSearchTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import static glide.TestUtilities.commonClientConfig;
import static glide.TestUtilities.commonClusterClientConfig;
import static glide.api.BaseClient.OK;
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleMultiNodeRoute.ALL_PRIMARIES;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -22,8 +24,10 @@
import glide.api.models.commands.vss.FTCreateOptions.VectorFieldHnsw;
import glide.api.models.exceptions.RequestException;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.SneakyThrows;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -167,4 +171,59 @@ public void ft_create(BaseClient client) {
assertInstanceOf(RequestException.class, exception.getCause());
assertTrue(exception.getMessage().contains("arguments are missing"));
}

@SneakyThrows
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("getClients")
@SuppressWarnings("unchecked")
public void ft_drop(BaseClient client) {
var index = UUID.randomUUID().toString();
assertEquals(
OK,
client
.ftcreate(
index,
IndexType.HASH,
new String[0],
new FieldInfo[] {
new FieldInfo("vec", VectorFieldHnsw.builder(DistanceMetric.L2, 2).build())
})
.get());

var before =
(Set<String>)
(client instanceof GlideClient
? ((GlideClient) client).customCommand(new String[] {"FT._LIST"}).get()
: ((GlideClusterClient) client)
.customCommand(new String[] {"FT._LIST"}, ALL_PRIMARIES)
.get()
.getMultiValue()
.values()
.stream()
.flatMap(s -> ((Set<String>) s).stream())
.collect(Collectors.toSet()));

assertEquals(OK, client.ftdrop(index).get());

var after =
(Set<String>)
(client instanceof GlideClient
? ((GlideClient) client).customCommand(new String[] {"FT._LIST"}).get()
: ((GlideClusterClient) client)
.customCommand(new String[] {"FT._LIST"}, ALL_PRIMARIES)
.get()
.getMultiValue()
.values()
.stream()
.flatMap(s -> ((Set<String>) s).stream())
.collect(Collectors.toSet()));

assertFalse(after.contains(index));
after.add(index);
assertEquals(after, before);

var exception = assertThrows(ExecutionException.class, () -> client.ftdrop(index).get());
assertInstanceOf(RequestException.class, exception.getCause());
assertTrue(exception.getMessage().contains("Unknown: Index name"));
}
}

0 comments on commit 237951c

Please sign in to comment.