Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from milvus-io/apply-rc8
Browse files Browse the repository at this point in the history
Apply rc8
  • Loading branch information
czhen-zilliz committed Nov 3, 2021
2 parents 4bcf6dd + 6ff4532 commit 28d011f
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 15 deletions.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
- [`clear`](#clear)
- [`connect`](#connect)
- [`create`](#create)
- [`create alias`](#create-alias)
- [`create collection`](#create-collection)
- [`create partition`](#create-partition)
- [`create index`](#create-index)
- [`delete`](#delete)
- [`delete alias`](#delete-alias)
- [`delete collection`](#delete-collection)
- [`delete partition`](#delete-partition)
- [`delete index`](#delete-index)
Expand All @@ -39,6 +41,7 @@
- [`show connection`](#show-connection)
- [`show index_progress`](#show-index_progress)
- [`show loading_progress`](#show-loading_progress)
- [`show query_segment`](#show-query_segment)
- [`version`](#version)

## Overview
Expand All @@ -56,6 +59,7 @@ Milvus CLI based on [Milvus Python ORM SDK](https://github.com/milvus-io/pymilvu
| 2.0.0-RC5 | 2.0.0rc5 | 0.1.5 |
| 2.0.0-RC6 | 2.0.0rc6 | 0.1.6 |
| 2.0.0-RC7 | 2.0.0rc7 | 0.1.7 |
<!-- | 2.0.0-RC8 | 2.0.0rc8 | 0.1.8 | -->

*\*It should be noted that Milvus 2.0.0-RC7 is NOT compatible with previous versions of Milvus 2.0.0 because of some changes made to storage format.*

Expand Down Expand Up @@ -222,6 +226,36 @@ Commands:
partition Create partition.
```

##### `create alias`

```
milvus_cli > create alias --help
Usage: milvus_cli create alias [OPTIONS]
Specify alias for a collection. Alias cannot be duplicated, you can't assign
same alias to different collections. But you can specify multiple aliases
for a collection, for example:
create alias -c car -a carAlias1 -a carAlias2
You can also change alias of a collection to another collection. If the
alias doesn't exist, it will return error. Use "-A" option to change alias
owner collection, for example:
create alias -c car2 -A -a carAlias1 -a carAlias2
Options:
-c, --collection-name TEXT Collection name to specify alias.
-a, --alias-name TEXT [Multiple] - The alias of the collection.
-A, --alter [Optional, Flag] - Change an existing alias to
current collection.
-t, --timeout FLOAT [Optional] - An optional duration of time in
seconds to allow for the RPC. If timeout is not
set, the client keeps waiting until the server
responds or an error occurs.
--help Show this message and exit.
```

##### `create collection`

```
Expand Down Expand Up @@ -314,6 +348,24 @@ Commands:
partition Drop the partition and its corresponding index files.
```

##### `delete alias`

```
milvus_cli > delete alias --help
Usage: milvus_cli.py delete alias [OPTIONS]
Delete an alias.
Options:
-c, --collection-name TEXT Collection name to be specified alias.
-a, --alias-name TEXT The alias of the collection.
-t, --timeout FLOAT [Optional] - An optional duration of time in
seconds to allow for the RPC. If timeout is not
set, the client keeps waiting until the server
responds or an error occurs.
--help Show this message and exit.
```

##### `delete collection`

```
Expand Down Expand Up @@ -816,6 +868,23 @@ Options:
--help Show this message and exit.
```

##### `show query_segment`

```
milvus_cli > show query_segment --help
Usage: milvus_cli show query_segment [OPTIONS]
Notifies Proxy to return segments information from query nodes.
Options:
-c, --collection TEXT A string representing the collection to get segments
info.
-t, --timeout FLOAT [Optional] - An optional duration of time in seconds
to allow for the RPC. When timeout is not set, client
waits until server response or error occur.
--help Show this message and exit.
```

#### `version`

```
Expand Down
82 changes: 73 additions & 9 deletions milvus_cli/scripts/milvus_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def indexProgress(obj, collection, index):
'indexed_rows', 'total_rows'], tablefmt='pretty'))


@show.command('query_segment')
@click.option('-c', '--collection', 'collection', help='A string representing the collection to get segments info.')
@click.option('-t', '--timeout', 'timeout', help="[Optional] - An optional duration of time in seconds to allow for the RPC. When timeout is not set, client waits until server response or error occur.", default=None, type=float)
@click.pass_obj
def querySegmentInfo(obj, collection, timeout):
"""Notifies Proxy to return segments information from query nodes."""
click.echo(obj.getQuerySegmentInfo(collection, timeout, prettierFormat=True))


@cli.command()
@click.option('-c', '--collection', 'collection', help='The name of collection to load.')
@click.option('-p', '--partition', 'partition', help='[Optional, Multiple] - The name of partition to load.', default=[], multiple=True)
Expand Down Expand Up @@ -292,8 +301,41 @@ def createDetails(obj):
pass


@createDetails.command('alias')
@click.option('-c', '--collection-name', 'collectionName', help='Collection name to be specified alias.', type=str)
@click.option('-a', '--alias-name', 'aliasNames', help='[Multiple] - The alias of the collection.', type=str, multiple=True)
@click.option('-A', '--alter', 'alter', help='[Optional, Flag] - Change an existing alias to current collection.', default=False, is_flag=True)
@click.option('-t', '--timeout', 'timeout', help='[Optional] - An optional duration of time in seconds to allow for the RPC. If timeout is not set, the client keeps waiting until the server responds or an error occurs.', default=None, type=float)
@click.pass_obj
def createAlias(obj, collectionName, aliasNames, alter, timeout):
"""
Specify alias for a collection.
Alias cannot be duplicated, you can't assign same alias to different collections.
But you can specify multiple aliases for a collection, for example:
create alias -c car -a carAlias1 -a carAlias2
You can also change alias of a collection to another collection.
If the alias doesn't exist, it will return error.
Use "-A" option to change alias owner collection, for example:
create alias -c car2 -A -a carAlias1 -a carAlias2
"""
try:
obj.checkConnection()
if alter:
result = obj.alterCollectionAliasList(collectionName, aliasNames, timeout)
else:
result = obj.createCollectionAliasList(collectionName, aliasNames, timeout)
except ConnectException as ce:
click.echo("Error!\n{}".format(str(ce)))
else:
if len(result) == len(aliasNames):
click.echo(f"""{len(result)} alias {"altered" if alter else "created"} successfully.""")


@createDetails.command('collection')
@click.option('-c', '--collection-name', 'collectionName', help='Collection name to be created.')
@click.option('-c', '--collection-name', 'collectionName', help='Collection name to specify alias.', type=str)
@click.option('-p', '--schema-primary-field', 'primaryField', help='Primary field name.')
@click.option('-a', '--schema-auto-id', 'autoId', help='[Optional, Flag] - Enable auto id.', default=False, is_flag=True)
@click.option('-d', '--schema-description', 'description', help='[Optional] - Description details.', default='')
Expand Down Expand Up @@ -403,6 +445,28 @@ def deleteObject(obj):
pass


@deleteObject.command('alias')
@click.option('-c', '--collection-name', 'collectionName', help='Collection name to be specified alias.', type=str)
@click.option('-a', '--alias-name', 'aliasName', help='The alias of the collection.', type=str)
@click.option('-t', '--timeout', 'timeout', help='[Optional] - An optional duration of time in seconds to allow for the RPC. If timeout is not set, the client keeps waiting until the server responds or an error occurs.', default=None, type=float)
@click.pass_obj
def deleteAlias(obj, collectionName, aliasName, timeout):
"""
Delete an alias.
"""
click.echo(
"Warning!\nYou are trying to delete an alias. This action cannot be undone!\n")
if not click.confirm('Do you want to continue?'):
return
try:
obj.checkConnection()
obj.dropCollectionAlias(collectionName, aliasName, timeout)
except ConnectException as ce:
click.echo("Error!\n{}".format(str(ce)))
else:
click.echo(f"Drop alias '{aliasName}' successfully.")


@deleteObject.command('collection')
@click.option('-c', '--collection', 'collectionName', help='The name of collection to be deleted.')
@click.option('-t', '--timeout', 'timeout', help='[Optional] - An optional duration of time in seconds to allow for the RPC. If timeout is not set, the client keeps waiting until the server responds or an error occurs.', default=None, type=float)
Expand Down Expand Up @@ -902,14 +966,14 @@ def runCliPrompt():
# trap argparse error message
# print('error', SystemExit)
continue
except ParameterException as pe:
click.echo(message=f"{str(pe)}", err=True)
except ConnectException as ce:
click.echo(
message="Connect to milvus Error!\nPlease check your connection.", err=True)
except Exception as e:
click.echo(
message=f"Error occurred!\n{str(e)}", err=True)
# except ParameterException as pe:
# click.echo(message=f"{str(pe)}", err=True)
# except ConnectException as ce:
# click.echo(
# message="Connect to milvus Error!\nPlease check your connection.", err=True)
# except Exception as e:
# click.echo(
# message=f"Error occurred!\n{str(e)}", err=True)
except (KeyboardInterrupt, EOFError):
print()
sys.exit(0)
Expand Down
48 changes: 44 additions & 4 deletions milvus_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,47 @@ def deleteEntities(self, expr, collectionName, partition_name=None, timeout=None
collection = self.getTargetCollection(collectionName)
result = collection.delete(expr, partition_name=partition_name, timeout=timeout)
return result


def getQuerySegmentInfo(self, collectionName, timeout=None, prettierFormat=False):
from pymilvus import utility
result = utility.get_query_segment_info(collectionName, timeout=timeout, using=self.alias)
if not prettierFormat or not result:
return result
firstChild = result[0]
headers = ["segmentID", "collectionID", "partitionID", "mem_size", "num_rows"]
return tabulate([[getattr(_, i) for i in headers] for _ in result], headers=headers, showindex=True)

def createCollectionAlias(self, collectionName, collectionAliasName="", timeout=None):
collection = self.getTargetCollection(collectionName)
result = collection.create_alias(collectionAliasName, timeout=timeout)
return result

def dropCollectionAlias(self, collectionName, collectionAliasName="", timeout=None):
collection = self.getTargetCollection(collectionName)
result = collection.drop_alias(collectionAliasName, timeout=timeout)
return result

def alterCollectionAlias(self, collectionName, collectionAliasName="", timeout=None):
collection = self.getTargetCollection(collectionName)
result = collection.alter_alias(collectionAliasName, timeout=timeout)
return result

def createCollectionAliasList(self, collectionName, aliasList=[], timeout=None):
collection = self.getTargetCollection(collectionName)
result = []
for aliasItem in aliasList:
aliasResult = collection.create_alias(aliasItem, timeout=timeout)
result.append(aliasResult)
return result

def alterCollectionAliasList(self, collectionName, aliasList=[], timeout=None):
collection = self.getTargetCollection(collectionName)
result = []
for aliasItem in aliasList:
aliasResult = collection.alter_alias(aliasItem, timeout=timeout)
result.append(aliasResult)
return result


class Completer(object):
# COMMANDS = ['clear', 'connect', 'create', 'delete', 'describe', 'exit',
Expand All @@ -337,8 +377,8 @@ class Completer(object):
'calc': [],
'clear': [],
'connect': [],
'create': ['collection', 'partition', 'index'],
'delete': ['collection', 'partition', 'index'],
'create': ['alias', 'collection', 'partition', 'index'],
'delete': ['alias', 'collection', 'partition', 'index'],
'describe': ['collection', 'partition', 'index'],
'exit': [],
'help': [],
Expand All @@ -348,7 +388,7 @@ class Completer(object):
'query': [],
'release': [],
'search': [],
'show': ['connection', 'index_progress', 'loading_progress'],
'show': ['connection', 'index_progress', 'loading_progress', 'query_segment'],
'version': [],
}

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='milvus_cli',
version='0.1.7beta4',
version='0.1.8beta1',
author='Milvus Team',
author_email='milvus-team@zilliz.com',
url='https://github.com/milvus-io/milvus_cli',
Expand All @@ -17,7 +17,7 @@
include_package_data=True,
install_requires=[
'Click==8.0.1',
'pymilvus==2.0.0rc7',
'pymilvus==2.0.0rc8',
'tabulate==0.8.9'
],
entry_points={
Expand Down

0 comments on commit 28d011f

Please sign in to comment.