Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python FT.DROPINDEX command #2437

Merged
merged 14 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Python: Python FT.DROPINDEX command ([#2437](https://github.com/valkey-io/valkey-glide/pull/2437))
* Python: Python: Added FT.CREATE command([#2413](https://github.com/valkey-io/valkey-glide/pull/2413))
* Python: Add JSON.ARRLEN command ([#2403](https://github.com/valkey-io/valkey-glide/pull/2403))
* Python: Add JSON.CLEAR command ([#2418](https://github.com/valkey-io/valkey-glide/pull/2418))
Expand Down
27 changes: 27 additions & 0 deletions python/python/glide/async_commands/server_modules/ft.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,30 @@ async def create(
for field in schema:
args.extend(field.toArgs())
return cast(TOK, await client.custom_command(args))


async def dropindex(client: TGlideClient, indexName: TEncodable):
acarbonetto marked this conversation as resolved.
Show resolved Hide resolved
"""
Drops an index. The index definition and associated content are deleted. Keys are unaffected.

Args:
client (TGlideClient): The client to execute the command.
indexName (TEncodable): The index name for the index to be dropped.

Returns:
If the index is successfully dropped, returns "OK".
prateek-kumar-improving marked this conversation as resolved.
Show resolved Hide resolved

Examples:
>>> from glide.async_commands.server_modules import ft
>>> schema: List[Field] = []
>>> textField: TextField = TextField("title")
>>> schema.append(textField)
>>> prefixes: List[str] = []
>>> prefixes.append("blog:post:")
>>> indexName = "idx"
>>> await ft.create(glide_client, index, schema, FtCreateOptions(DataType.HASH, prefixes))
>>> result = await ft.dropindex(glide_client, indexName)
b'OK' # Indicates successful deletion/dropping of index named 'idx'
acarbonetto marked this conversation as resolved.
Show resolved Hide resolved
"""
args: List[TEncodable] = [CommandNames.FT_DROPINDEX, indexName]
return cast(TOK, await client.custom_command(args))
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CommandNames:
"""

FT_CREATE = "FT.CREATE"
FT_DROPINDEX = "FT.DROPINDEX"


class FtCreateKeywords:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@


@pytest.mark.asyncio
class TestVss:
class TestFtCreate:
@pytest.mark.parametrize("cluster_mode", [True])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_vss_create(self, glide_client: GlideClusterClient):
async def test_ft_create(self, glide_client: GlideClusterClient):
fields: List[Field] = []
textFieldTitle: TextField = TextField("$title")
numberField: NumericField = NumericField("$published_at")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import uuid
from typing import List

import pytest
from glide.async_commands.server_modules import ft
from glide.async_commands.server_modules.ft_options.ft_create_options import (
DataType,
Field,
FtCreateOptions,
TextField,
)
from glide.config import ProtocolVersion
from glide.constants import OK
from glide.exceptions import RequestError
from glide.glide_client import GlideClusterClient


@pytest.mark.asyncio
class TestFtDropIndex:
@pytest.mark.parametrize("cluster_mode", [True])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_ft_dropindex(self, glide_client: GlideClusterClient):
# Index name for the index to be dropped.
indexName = str(uuid.uuid4())
prateek-kumar-improving marked this conversation as resolved.
Show resolved Hide resolved

fields: List[Field] = []
textFieldTitle: TextField = TextField("$title")
fields.append(textFieldTitle)
prefixes: List[str] = []
prefixes.append("blog:post:")

# Create an index with multiple fields with Hash data type.
result = await ft.create(
glide_client, indexName, fields, FtCreateOptions(DataType.HASH, prefixes)
)
assert result == OK

# Drop the index. Expects "OK" as a response.
result = await ft.dropindex(glide_client, indexName)
assert result == OK

# Drop a non existent index. Expects a RequestError.
with pytest.raises(RequestError):
await ft.dropindex(glide_client, indexName)
Loading