From c2beaa929627a2f2aee9bb097bc78c3cfa20ed8c Mon Sep 17 00:00:00 2001 From: Yang Xuan Date: Thu, 6 Jun 2019 19:42:55 +0800 Subject: [PATCH] fix(python): sdk fix can't connect to thrift server error Former-commit-id: 32aa3aa7d090f13d4f575982a87a32ee5173d1d2 --- python/sdk/client/Abstract.py | 52 +++++++++---------- python/sdk/client/Client.py | 75 ++++++++++++++------------- python/sdk/examples/connection_exp.py | 20 +++---- 3 files changed, 71 insertions(+), 76 deletions(-) diff --git a/python/sdk/client/Abstract.py b/python/sdk/client/Abstract.py index 3344242bb6..93719f3441 100644 --- a/python/sdk/client/Abstract.py +++ b/python/sdk/client/Abstract.py @@ -3,8 +3,8 @@ from .Exceptions import ConnectParamMissingError class AbstactIndexType(object): - RAW = 1 - IVFFLAT = 2 + RAW = '1' + IVFFLAT = '2' class AbstractColumnType(object): @@ -24,10 +24,10 @@ class Column(object): Table column description :type type: ColumnType - :param type: type of the column + :param type: (Required) type of the column :type name: str - :param name: name of the column + :param name: (Required) name of the column """ def __init__(self, name=None, type=AbstractColumnType.INVALID): @@ -40,20 +40,20 @@ class VectorColumn(Column): Table vector column description :type dimension: int, int64 - :param dimension: vector dimension + :param dimension: (Required) vector dimension - :type index_type: IndexType - :param index_type: IndexType + :type index_type: string IndexType + :param index_type: (Required) IndexType :type store_raw_vector: bool - :param store_raw_vector: Is vector self stored in the table + :param store_raw_vector: (Required) Is vector self stored in the table `Column`: :type name: str - :param name: Name of the column + :param name: (Required) Name of the column :type type: ColumnType - :param type: Default type is ColumnType.VECTOR, can't change + :param type: (Required) Default type is ColumnType.VECTOR, can't change """ def __init__(self, name, @@ -72,20 +72,20 @@ class TableSchema(object): Table Schema :type table_name: str - :param table_name: name of table + :param table_name: (Required) name of table :type vector_columns: list[VectorColumn] - :param vector_columns: a list of VectorColumns, + :param vector_columns: (Required) a list of VectorColumns, Stores different types of vectors :type attribute_columns: list[Column] - :param attribute_columns: Columns description + :param attribute_columns: (Optional) Columns description List of `Columns` whose type isn't VECTOR :type partition_column_names: list[str] - :param partition_column_names: Partition column name + :param partition_column_names: (Optional) Partition column name `Partition columns` are `attribute columns`, the number of partition columns may be less than or equal to attribute columns, @@ -105,10 +105,10 @@ class Range(object): Range information :type start: str - :param start: Range start value + :param start: (Required) Range start value :type end: str - :param end: Range end value + :param end: (Required) Range end value """ def __init__(self, start, end): @@ -121,14 +121,14 @@ class CreateTablePartitionParam(object): Create table partition parameters :type table_name: str - :param table_name: Table name, + :param table_name: (Required) Table name, VECTOR/FLOAT32/FLOAT64 ColumnType is not allowed for partition :type partition_name: str - :param partition_name: partition name, created partition name + :param partition_name: (Required) partition name, created partition name :type column_name_to_range: dict{str : Range} - :param column_name_to_range: Column name to PartitionRange dictionary + :param column_name_to_range: (Required) Column name to PartitionRange dictionary """ # TODO Iterable def __init__(self, table_name, partition_name, column_name_to_range): @@ -142,10 +142,10 @@ class DeleteTablePartitionParam(object): Delete table partition parameters :type table_name: str - :param table_name: Table name + :param table_name: (Required) Table name :type partition_names: iterable, str - :param partition_names: Partition name array + :param partition_names: (Required) Partition name array """ # TODO Iterable @@ -159,10 +159,10 @@ class RowRecord(object): Record inserted :type column_name_to_vector: dict{str : list[float]} - :param column_name_to_vector: Column name to vector map + :param column_name_to_vector: (Required) Column name to vector map :type column_name_to_attribute: dict{str: str} - :param column_name_to_attribute: Other attribute columns + :param column_name_to_attribute: (Optional) Other attribute columns """ def __init__(self, column_name_to_vector, column_name_to_attribute): self.column_name_to_vector = column_name_to_vector @@ -173,14 +173,14 @@ class QueryRecord(object): """ Query record - :type column_name_to_vector: dict{str : list[float]} + :type column_name_to_vector: (Required) dict{str : list[float]} :param column_name_to_vector: Query vectors, column name to vector map :type selected_columns: list[str] - :param selected_columns: Output column array + :param selected_columns: (Optional) Output column array :type name_to_partition_ranges: dict{str : list[Range]} - :param name_to_partition_ranges: Range used to select partitions + :param name_to_partition_ranges: (Optional) Range used to select partitions """ def __init__(self, column_name_to_vector, selected_columns, name_to_partition_ranges): diff --git a/python/sdk/client/Client.py b/python/sdk/client/Client.py index 57fd3b135a..7b72902ba2 100644 --- a/python/sdk/client/Client.py +++ b/python/sdk/client/Client.py @@ -34,8 +34,8 @@ __NAME__ = 'Thrift_Client' class IndexType(AbstactIndexType): # TODO thrift in IndexType - RAW = 1 - IVFFLAT = 2 + RAW = '1' + IVFFLAT = '2' class ColumnType(AbstractColumnType): @@ -51,16 +51,17 @@ class ColumnType(AbstractColumnType): INT64 = TType.I64 VECTOR = TType.LIST - +# TODO Required and Optional +# TODO Examples +# TODO ORM class Prepare(object): @classmethod def column(cls, name, type): """ Table column param - # todo type - :param type: ColumnType, type of the column - :param name: str, name of the column + :param type: (Required) ColumnType, type of the column + :param name: (Required) str, name of the column :return Column """ @@ -69,34 +70,34 @@ class Prepare(object): @classmethod def vector_column(cls, name, dimension, - # index_type=IndexType.RAW, + index_type=IndexType.RAW, store_raw_vector=False): """ Table vector column description - :param dimension: int64, vector dimension - :param index_type: IndexType - :param store_raw_vector: Bool + :param dimension: (Required) int64, vector dimension + :param index_type: (Required) IndexType + :param store_raw_vector: (Required) Bool `Column`: - :param name: Name of the column - :param type: Default type is ColumnType.VECTOR, can't change + :param name: (Required) Name of the column + :param type: (Required) Default type is ColumnType.VECTOR, can't change :return VectorColumn """ - # temp = VectorColumn(name=name, dimension=dimension, - # index_type=index_type, store_raw_vector=store_raw_vector) - # return ttypes.VectorColumn(base=base, dimension=temp.dimension, - # store_raw_vector=temp.store_raw_vector, - # index_type=temp.index_type) - - # Without IndexType temp = VectorColumn(name=name, dimension=dimension, - store_raw_vector=store_raw_vector) + index_type=index_type, store_raw_vector=store_raw_vector) base = ttypes.Column(name=temp.name, type=ColumnType.VECTOR) return ttypes.VectorColumn(base=base, dimension=temp.dimension, - store_raw_vector=temp.store_raw_vector) + store_raw_vector=temp.store_raw_vector, + index_type=temp.index_type) + + # Without IndexType + # temp = VectorColumn(name=name, dimension=dimension, + # store_raw_vector=store_raw_vector) + # return ttypes.VectorColumn(base=base, dimension=temp.dimension, + # store_raw_vector=temp.store_raw_vector) @classmethod def table_schema(cls, table_name, @@ -105,8 +106,8 @@ class Prepare(object): partition_column_names): """ - :param table_name: Name of the table - :param vector_columns: List of VectorColumns + :param table_name: (Required) Name of the table + :param vector_columns: (Required) List of VectorColumns `VectorColumn`: - dimension: int, default = 0 @@ -119,14 +120,14 @@ class Prepare(object): Name of the column - type: ColumnType, default=ColumnType.VECTOR, can't change - :param attribute_columns: List of Columns. Attribute columns are Columns, + :param attribute_columns: (Optional) List of Columns. Attribute columns are Columns, whose types aren't ColumnType.VECTOR `Column`: - name: str - type: ColumnType, default=ColumnType.INVALID - :param partition_column_names: List of str. + :param partition_column_names: (Optional) List of str. Partition columns name indicates which attribute columns is used for partition, can @@ -148,8 +149,8 @@ class Prepare(object): @classmethod def range(cls, start, end): """ - :param start: Partition range start value - :param end: Partition range end value + :param start: (Required) Partition range start value + :param end: (Required) Partition range end value :return Range """ @@ -163,10 +164,10 @@ class Prepare(object): column_name_to_range): """ Create table partition parameters - :param table_name: str, Table name, + :param table_name: (Required) str, Table name, VECTOR/FLOAT32/FLOAT64 ColumnType is not allowed for partition - :param partition_name: str partition name, created partition name - :param column_name_to_range: dict, column name to partition range dictionary + :param partition_name: (Required) str partition name, created partition name + :param column_name_to_range: (Required) dict, column name to partition range dictionary :return CreateTablePartitionParam """ @@ -181,8 +182,8 @@ class Prepare(object): def delete_table_partition_param(cls, table_name, partition_names): """ Delete table partition parameters - :param table_name: Table name - :param partition_names: List of partition names + :param table_name: (Required) Table name + :param partition_names: (Required) List of partition names :return DeleteTablePartitionParam """ @@ -194,10 +195,10 @@ class Prepare(object): @classmethod def row_record(cls, column_name_to_vector, column_name_to_attribute): """ - :param column_name_to_vector: dict{str : list[float]} + :param column_name_to_vector: (Required) dict{str : list[float]} Column name to vector map - :param column_name_to_attribute: dict{str: str} + :param column_name_to_attribute: (Optional) dict{str: str} Other attribute columns """ temp = RowRecord(column_name_to_vector=column_name_to_vector, @@ -209,13 +210,13 @@ class Prepare(object): def query_record(cls, column_name_to_vector, selected_columns, name_to_partition_ranges): """ - :param column_name_to_vector: dict{str : list[float]} + :param column_name_to_vector: (Required) dict{str : list[float]} Query vectors, column name to vector map - :param selected_columns: list[str_column_name] + :param selected_columns: (Optional) list[str_column_name] List of Output columns - :param name_to_partition_ranges: dict{str : list[Range]} + :param name_to_partition_ranges: (Optional) dict{str : list[Range]} Partition Range used to search `Range`: diff --git a/python/sdk/examples/connection_exp.py b/python/sdk/examples/connection_exp.py index cf761d129a..e7d139f147 100644 --- a/python/sdk/examples/connection_exp.py +++ b/python/sdk/examples/connection_exp.py @@ -7,6 +7,7 @@ from megasearch.thrift import MegasearchService, ttypes def main(): mega = MegaSearch() + print(mega.client_version()) # Connect param = {'host': '192.168.1.129', 'port': '33001'} @@ -34,7 +35,7 @@ def main(): # get server version print(mega.server_status('version')) - + print(mega.client.Ping('version')) # show tables and their description statu, tables = mega.show_tables() print(tables) @@ -51,27 +52,20 @@ def main(): vector_column_array=[MegasearchService.VectorColumn( base=MegasearchService.Column( name='111', - type=ttypes.TType.I32 + type=ttypes.TType.LIST ), + index_type="aaa", dimension=256, + store_raw_vector=False, )], attribute_column_array=[], - partition_column_name_array=None + partition_column_name_array=[] ) - table_schema_empty = MegasearchService.TableSchema( - table_name='fake' + time.strftime('%H%M%S'), - - vector_column_array=[MegasearchService.VectorColumn()], - - attribute_column_array=[], - - partition_column_name_array=None - ) # 2. Create Table - create_status = mega.create_table(table_schema_full) + create_status = mega.client.CreateTable(param=table_schema_full) print('Create table status: {}'.format(create_status)) # add_vector