Skip to content

Commit

Permalink
Java: FT.DROPINDEX. (valkey-io#2440)
Browse files Browse the repository at this point in the history
* `FT.DROPINDEX`.

Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
Co-authored-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
  • Loading branch information
2 people authored and avifenesh committed Oct 21, 2024
1 parent ff7f640 commit 174600d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Python: Add JSON.TYPE command ([#2409](https://github.com/valkey-io/valkey-glide/pull/2409))
* Python: Add JSON.NUMINCRBY command ([#2448](https://github.com/valkey-io/valkey-glide/pull/2448))
* Java: Added `FT.CREATE` ([#2414](https://github.com/valkey-io/valkey-glide/pull/2414))
* Java: Added `FT.DROPINDEX` ([#2440](https://github.com/valkey-io/valkey-glide/pull/2440))
* Core: Update routing for commands from server modules ([#2461](https://github.com/valkey-io/valkey-glide/pull/2461))

#### Breaking Changes
Expand Down
30 changes: 30 additions & 0 deletions java/client/src/main/java/glide/api/commands/servermodules/FT.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,36 @@ public static CompletableFuture<String> create(
return executeCommand(client, args, false);
}

/**
* Deletes an index and associated content. Indexed document keys are unaffected.
*
* @param indexName The index name.
* @return <code>"OK"</code>.
* @example
* <pre>{@code
* FT.dropindex(client, "hash_idx1").get();
* }</pre>
*/
public static CompletableFuture<String> dropindex(
@NonNull BaseClient client, @NonNull String indexName) {
return executeCommand(client, new GlideString[] {gs("FT.DROPINDEX"), gs(indexName)}, false);
}

/**
* Deletes an index and associated content. Indexed document keys are unaffected.
*
* @param indexName The index name.
* @return <code>"OK"</code>.
* @example
* <pre>{@code
* FT.dropindex(client, gs("hash_idx1")).get();
* }</pre>
*/
public static CompletableFuture<String> dropindex(
@NonNull BaseClient client, @NonNull GlideString indexName) {
return executeCommand(client, new GlideString[] {gs("FT.DROPINDEX"), indexName}, false);
}

/**
* A wrapper for custom command API.
*
Expand Down
38 changes: 38 additions & 0 deletions java/integTest/src/test/java/glide/modules/VectorSearchTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleMultiNodeRoute.ALL_PRIMARIES;
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleSingleNodeRoute.RANDOM;
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 @@ -24,6 +25,8 @@
import glide.api.models.commands.FlushMode;
import glide.api.models.commands.InfoOptions.Section;
import glide.api.models.exceptions.RequestException;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -182,4 +185,39 @@ public void ft_create() {
assertInstanceOf(RequestException.class, exception.getCause());
assertTrue(exception.getMessage().contains("already exists"));
}

@SneakyThrows
@Test
public void ft_drop() {
var index = UUID.randomUUID().toString();
assertEquals(
OK,
FT.create(
client,
index,
new FieldInfo[] {
new FieldInfo("vec", VectorFieldHnsw.builder(DistanceMetric.L2, 2).build())
})
.get());

// TODO use FT.LIST with it is done
var before =
Set.of((Object[]) client.customCommand(new String[] {"FT._LIST"}).get().getSingleValue());

assertEquals(OK, FT.dropindex(client, index).get());

// TODO use FT.LIST with it is done
var after =
new HashSet<>(
Set.of(
(Object[]) client.customCommand(new String[] {"FT._LIST"}).get().getSingleValue()));

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

var exception = assertThrows(ExecutionException.class, () -> FT.dropindex(client, index).get());
assertInstanceOf(RequestException.class, exception.getCause());
assertTrue(exception.getMessage().contains("Index does not exist"));
}
}

0 comments on commit 174600d

Please sign in to comment.