Skip to content

Commit

Permalink
Node: FT.INFO (#2540)
Browse files Browse the repository at this point in the history
* `FT.INFO`.

Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
  • Loading branch information
Yury-Fridlyand authored Oct 30, 2024
1 parent 5b90096 commit d4ef3c3
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Java: Added `FT.PROFILE` ([#2473](https://github.com/valkey-io/valkey-glide/pull/2473))
* Java: Added `JSON.SET` and `JSON.GET` ([#2462](https://github.com/valkey-io/valkey-glide/pull/2462))
* Node: Added `FT.CREATE` ([#2501](https://github.com/valkey-io/valkey-glide/pull/2501))
* Node: Added `FT.INFO` ([#2540](https://github.com/valkey-io/valkey-glide/pull/2540))
* Java: Added `JSON.DEBUG` ([#2520](https://github.com/valkey-io/valkey-glide/pull/2520))
* Java: Added `JSON.ARRINSERT` and `JSON.ARRLEN` ([#2476](https://github.com/valkey-io/valkey-glide/pull/2476))
* Java: Added `JSON.ARRPOP` ([#2486](https://github.com/valkey-io/valkey-glide/pull/2486))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public static CompletableFuture<Object[]> profile(
* Map<String, Object> response = client.ftinfo("myIndex").get();
* // the response contains data in the following format:
* Map<String, Object> data = Map.of(
* "index_name", gs("bcd97d68-4180-4bc5-98fe-5125d0abbcb8"),
* "index_name", gs("myIndex"),
* "index_status", gs("AVAILABLE"),
* "key_type", gs("JSON"),
* "creation_timestamp", 1728348101728771L,
Expand All @@ -566,7 +566,7 @@ public static CompletableFuture<Object[]> profile(
* gs("dimension", 6L,
* gs("block_size", 1024L,
* gs("algorithm", gs("FLAT")
* )
* )
* ),
* Map.of(
* gs("identifier"), gs("name"),
Expand Down Expand Up @@ -599,7 +599,7 @@ public static CompletableFuture<Map<String, Object>> info(
* Map<String, Object> response = client.ftinfo(gs("myIndex")).get();
* // the response contains data in the following format:
* Map<String, Object> data = Map.of(
* "index_name", gs("bcd97d68-4180-4bc5-98fe-5125d0abbcb8"),
* "index_name", gs("myIndex"),
* "index_status", gs("AVAILABLE"),
* "key_type", gs("JSON"),
* "creation_timestamp", 1728348101728771L,
Expand All @@ -625,7 +625,7 @@ public static CompletableFuture<Map<String, Object>> info(
* gs("dimension", 6L,
* gs("block_size", 1024L,
* gs("algorithm", gs("FLAT")
* )
* )
* ),
* Map.of(
* gs("identifier"), gs("name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,6 @@ public void ft_aggregate() {
@Test
@SneakyThrows
public void ft_info() {
// TODO use FT.LIST when it is done
var indices = (Object[]) client.customCommand(new String[] {"FT._LIST"}).get().getSingleValue();

// check that we can get a response for all indices (no crashes on value conversion or so)
for (var idx : indices) {
FT.info(client, (String) idx).get();
}

var index = UUID.randomUUID().toString();
assertEquals(
OK,
Expand Down
2 changes: 2 additions & 0 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function initialize() {
VectorFieldAttributesFlat,
VectorFieldAttributesHnsw,
FtCreateOptions,
FtInfoReturnType,
GlideRecord,
GlideString,
JsonGetOptions,
Expand Down Expand Up @@ -244,6 +245,7 @@ function initialize() {
VectorFieldAttributesFlat,
VectorFieldAttributesHnsw,
FtCreateOptions,
FtInfoReturnType,
GlideRecord,
GlideJson,
GlideString,
Expand Down
3 changes: 0 additions & 3 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5510,7 +5510,6 @@ export class BaseClient {
* attributes of a consumer group for the stream at `key`.
* @example
* ```typescript
* <pre>{@code
* const result = await client.xinfoGroups("my_stream");
* console.log(result); // Output:
* // [
Expand Down Expand Up @@ -5963,13 +5962,11 @@ export class BaseClient {
*
* @example
* ```typescript
* <pre>{@code
* const entryId = await client.xadd("mystream", ["myfield", "mydata"]);
* // read messages from streamId
* const readResult = await client.xreadgroup(["myfield", "mydata"], "mygroup", "my0consumer");
* // acknowledge messages on stream
* console.log(await client.xack("mystream", "mygroup", [entryId])); // Output: 1
* </pre>
* ```
*/
public async xack(
Expand Down
92 changes: 87 additions & 5 deletions node/src/server-modules/GlideFt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/

import { Decoder, DecoderOption, GlideString } from "../BaseClient";
import {
convertGlideRecordToRecord,
Decoder,
DecoderOption,
GlideRecord,
GlideReturnType,
GlideString,
} from "../BaseClient";
import { GlideClient } from "../GlideClient";
import { GlideClusterClient } from "../GlideClusterClient";
import { Field, FtCreateOptions } from "./GlideFtOptions";

/** Module for Vector Search commands */
/** Data type of {@link GlideFt.info | info} command response. */
type FtInfoReturnType = Record<
string,
| GlideString
| number
| GlideString[]
| Record<string, GlideString | Record<string, GlideString | number>[]>
>;

/** Module for Vector Search commands. */
export class GlideFt {
/**
* Creates an index and initiates a backfill of that index.
Expand Down Expand Up @@ -187,16 +203,82 @@ export class GlideFt {
decoder: Decoder.String,
}) as Promise<"OK">;
}

/**
* Returns information about a given index.
*
* @param client - The client to execute the command.
* @param indexName - The index name.
* @param options - (Optional) See {@link DecoderOption}.
*
* @returns Nested maps with info about the index. See example for more details.
*
* @example
* ```typescript
* const info = await GlideFt.info(client, "myIndex");
* console.log(info); // Output:
* // {
* // index_name: 'myIndex',
* // index_status: 'AVAILABLE',
* // key_type: 'JSON',
* // creation_timestamp: 1728348101728771,
* // key_prefixes: [ 'json:' ],
* // num_indexed_vectors: 0,
* // space_usage: 653471,
* // num_docs: 0,
* // vector_space_usage: 653471,
* // index_degradation_percentage: 0,
* // fulltext_space_usage: 0,
* // current_lag: 0,
* // fields: [
* // {
* // identifier: '$.vec',
* // type: 'VECTOR',
* // field_name: 'VEC',
* // option: '',
* // vector_params: {
* // data_type: 'FLOAT32',
* // initial_capacity: 1000,
* // current_capacity: 1000,
* // distance_metric: 'L2',
* // dimension: 6,
* // block_size: 1024,
* // algorithm: 'FLAT'
* // }
* // },
* // {
* // identifier: 'name',
* // type: 'TEXT',
* // field_name: 'name',
* // option: ''
* // },
* // ]
* // }
* ```
*/
static async info(
client: GlideClient | GlideClusterClient,
indexName: GlideString,
options?: DecoderOption,
): Promise<FtInfoReturnType> {
const args: GlideString[] = ["FT.INFO", indexName];

return (
_handleCustomCommand(client, args, options) as Promise<
GlideRecord<GlideString>
>
).then(convertGlideRecordToRecord);
}
}

/**
* @internal
*/
function _handleCustomCommand(
async function _handleCustomCommand(
client: GlideClient | GlideClusterClient,
args: GlideString[],
decoderOption: DecoderOption,
) {
decoderOption?: DecoderOption,
): Promise<GlideReturnType> {
return client instanceof GlideClient
? (client as GlideClient).customCommand(args, decoderOption)
: (client as GlideClusterClient).customCommand(args, decoderOption);
Expand Down
Loading

0 comments on commit d4ef3c3

Please sign in to comment.