Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
baf8eaee
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
baf8eaee
编写于
6月 06, 2019
作者:
Y
Yang Xuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
small verify
Former-commit-id: f11084a887b30724e7d31ce89214c03f59c828bc
上级
8623ae24
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
80 addition
and
46 deletion
+80
-46
python/sdk/client/Abstract.py
python/sdk/client/Abstract.py
+4
-3
python/sdk/client/Client.py
python/sdk/client/Client.py
+11
-16
python/sdk/examples/connection_exp.py
python/sdk/examples/connection_exp.py
+59
-22
python/sdk/tests/TestClient.py
python/sdk/tests/TestClient.py
+6
-5
未找到文件。
python/sdk/client/Abstract.py
浏览文件 @
baf8eaee
...
...
@@ -58,12 +58,13 @@ class VectorColumn(Column):
"""
def
__init__
(
self
,
name
,
dimension
=
0
,
index_type
=
AbstactIndexType
.
RAW
,
store_raw_vector
=
False
):
index_type
=
None
,
store_raw_vector
=
False
,
type
=
None
):
self
.
dimension
=
dimension
self
.
index_type
=
index_type
self
.
store_raw_vector
=
store_raw_vector
super
(
VectorColumn
,
self
).
__init__
(
name
,
type
=
AbstractColumnType
.
VECTOR
)
super
(
VectorColumn
,
self
).
__init__
(
name
,
type
=
type
)
class
TableSchema
(
object
):
...
...
python/sdk/client/Client.py
浏览文件 @
baf8eaee
...
...
@@ -2,6 +2,7 @@ import logging, logging.config
from
thrift.transport
import
TSocket
from
thrift.transport
import
TTransport
from
thrift.transport.TTransport
import
TTransportException
from
thrift.protocol
import
TBinaryProtocol
,
TCompactProtocol
,
TJSONProtocol
from
thrift.Thrift
import
TException
,
TApplicationException
,
TType
...
...
@@ -38,15 +39,10 @@ class IndexType(AbstactIndexType):
class
ColumnType
(
AbstractColumnType
):
# INVALID = 1
# INT8 = 2
# INT16 = 3
# INT32 = 4
# INT64 = 5
FLOAT32
=
6
FLOAT64
=
7
DATE
=
8
# VECTOR = 9
INVALID
=
TType
.
STOP
INT8
=
TType
.
I08
...
...
@@ -62,13 +58,12 @@ class Prepare(object):
def
column
(
cls
,
name
,
type
):
"""
Table column param
# todo type
:param type: ColumnType, type of the column
:param name: str, name of the column
:return Column
"""
# TODO type in Thrift, may have error
temp_column
=
Column
(
name
=
name
,
type
=
type
)
return
ttypes
.
Column
(
name
=
temp_column
.
name
,
type
=
temp_column
.
type
)
...
...
@@ -81,7 +76,7 @@ class Prepare(object):
:param dimension: int64, vector dimension
:param index_type: IndexType
:param store_raw_vector: Bool
, Is vector self stored in the table
:param store_raw_vector: Bool
`Column`:
:param name: Name of the column
...
...
@@ -124,8 +119,8 @@ 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 whose type
aren't ColumnType.VECTOR
:param attribute_columns: List of Columns. Attribute
columns are Columns,
whose types
aren't ColumnType.VECTOR
`Column`:
- name: str
...
...
@@ -266,7 +261,7 @@ class MegaSearch(ConnectIntf):
transport
=
TSocket
.
TSocket
(
host
=
host
,
port
=
port
)
self
.
transport
=
TTransport
.
TBufferedTransport
(
transport
)
protocol
=
T
JSONProtocol
.
TJSON
Protocol
(
transport
)
protocol
=
T
BinaryProtocol
.
TBinary
Protocol
(
transport
)
self
.
client
=
MegasearchService
.
Client
(
protocol
)
try
:
...
...
@@ -312,8 +307,9 @@ class MegaSearch(ConnectIntf):
raise
NotConnectError
(
'Please Connect to the server first!'
)
try
:
LOGGER
.
error
(
param
)
self
.
client
.
CreateTable
(
param
)
except
(
TApplicationException
,
TException
)
as
e
:
except
(
TApplicationException
,
)
as
e
:
LOGGER
.
error
(
'Unable to create table'
)
return
Status
(
Status
.
INVALID
,
str
(
e
))
return
Status
(
message
=
'Table {} created!'
.
format
(
param
.
table_name
))
...
...
@@ -463,11 +459,10 @@ class MegaSearch(ConnectIntf):
# TODO How to get server version
pass
def
server_status
(
self
,
cmd
):
def
server_status
(
self
,
cmd
=
None
):
"""
Provide server status
:return: Server status
"""
self
.
client
.
Ping
(
cmd
)
pass
return
self
.
client
.
Ping
(
cmd
)
python/sdk/examples/connection_exp.py
浏览文件 @
baf8eaee
from
client.Client
import
MegaSearch
,
Prepare
,
IndexType
,
ColumnType
from
client.Status
import
Status
import
time
from
megasearch.thrift
import
MegasearchService
,
ttypes
def
main
():
...
...
@@ -13,31 +16,65 @@ def main():
is_connected
=
mega
.
connected
print
(
'Connect status: {}'
.
format
(
is_connected
))
# # Create table with 1 vector column, 1 attribute column and 1 partition column
# # 1. prepare table_schema
# vector_column = {
# 'name': 'fake_vec_name01',
# 'store_raw_vector': True,
# 'dimension': 10
# }
# attribute_column = {
# 'name': 'fake_attri_name01',
# 'type': ColumnType.DATE,
# }
# Create table with 1 vector column, 1 attribute column and 1 partition column
# 1. prepare table_schema
# table_schema = Prepare.table_schema(
# table_name='fake_table_name' + time.strftime('%H%M%S'),
#
# table = {
# 'table_name': 'fake_table_name01',
# 'vector_columns': [Prepare.vector_column(**vector_column)],
# 'attribute_columns': [Prepare.column(**attribute_column)],
# 'partition_column_names': ['fake_attri_name01']
# }
# table_schema = Prepare.table_schema(**table)
# vector_columns=[Prepare.vector_column(
# name='fake_vector_name' + time.strftime('%H%M%S'),
# store_raw_vector=False,
# dimension=256)],
#
# # 2. Create Table
# create_status = mega.create_table(table_schema)
# print('Create table status: {}'.format(create_status))
# attribute_columns=[],
#
# partition_column_names=[]
# )
# get server version
print
(
mega
.
server_status
(
'version'
))
# show tables and their description
statu
,
tables
=
mega
.
show_tables
()
print
(
tables
)
for
table
in
tables
:
s
,
t
=
mega
.
describe_table
(
table
)
print
(
'table: {}'
.
format
(
t
))
# Create table
# 1. create table schema
table_schema_full
=
MegasearchService
.
TableSchema
(
table_name
=
'fake'
+
time
.
strftime
(
'%H%M%S'
),
vector_column_array
=
[
MegasearchService
.
VectorColumn
(
base
=
MegasearchService
.
Column
(
name
=
'111'
,
type
=
ttypes
.
TType
.
I32
),
dimension
=
256
,
)],
attribute_column_array
=
[],
partition_column_name_array
=
None
)
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
)
print
(
'Create table status: {}'
.
format
(
create_status
))
mega
.
server_status
(
'ok!'
)
# add_vector
# Disconnect
discnn_status
=
mega
.
disconnect
()
...
...
python/sdk/tests/TestClient.py
浏览文件 @
baf8eaee
...
...
@@ -14,6 +14,7 @@ from client.Exceptions import (
from
thrift.transport.TSocket
import
TSocket
from
megasearch.thrift
import
ttypes
,
MegasearchService
from
thrift.transport.TTransport
import
TTransportException
LOGGER
=
logging
.
getLogger
(
__name__
)
...
...
@@ -38,7 +39,6 @@ def vector_column_factory():
return
{
'name'
:
fake
.
name
(),
'dimension'
:
fake
.
dim
(),
'index_type'
:
IndexType
.
IVFFLAT
,
'store_raw_vector'
:
True
}
...
...
@@ -46,7 +46,7 @@ def vector_column_factory():
def
column_factory
():
return
{
'name'
:
fake
.
table_name
(),
'type'
:
IndexType
.
RAW
'type'
:
ColumnType
.
INT32
}
...
...
@@ -146,6 +146,7 @@ class TestTable:
def
test_false_create_table
(
self
,
client
):
param
=
table_schema_factory
()
with
pytest
.
raises
(
TTransportException
):
res
=
client
.
create_table
(
param
)
LOGGER
.
error
(
'{}'
.
format
(
res
))
assert
res
!=
Status
.
OK
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录