Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
3b5b50bd
M
milvus
项目概览
milvus
/
milvus
9 个月 前同步成功
通知
260
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
3b5b50bd
编写于
6月 16, 2023
作者:
Z
Zhao Shunjie
提交者:
GitHub
6月 16, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add autoID to varchar dataType (#24907)
Signed-off-by:
N
shunjiezhao
<
939038111@qq.com
>
上级
c7dc1c06
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
21 deletion
+39
-21
internal/proxy/util.go
internal/proxy/util.go
+32
-16
internal/proxy/util_test.go
internal/proxy/util_test.go
+1
-1
tests/python_client/testcases/test_collection.py
tests/python_client/testcases/test_collection.py
+6
-4
未找到文件。
internal/proxy/util.go
浏览文件 @
3b5b50bd
...
@@ -341,11 +341,11 @@ func validatePrimaryKey(coll *schemapb.CollectionSchema) error {
...
@@ -341,11 +341,11 @@ func validatePrimaryKey(coll *schemapb.CollectionSchema) error {
// varchar field do not support autoID
// varchar field do not support autoID
// If autoID is required, it is recommended to use int64 field as the primary key
// If autoID is required, it is recommended to use int64 field as the primary key
if
field
.
DataType
==
schemapb
.
DataType_VarChar
{
//
if field.DataType == schemapb.DataType_VarChar {
if
field
.
AutoID
{
//
if field.AutoID {
return
fmt
.
Errorf
(
"autoID is not supported when the VarChar field is the primary key"
)
//
return fmt.Errorf("autoID is not supported when the VarChar field is the primary key")
}
//
}
}
//
}
idx
=
i
idx
=
i
}
}
...
@@ -551,20 +551,36 @@ func autoGenPrimaryFieldData(fieldSchema *schemapb.FieldSchema, data interface{}
...
@@ -551,20 +551,36 @@ func autoGenPrimaryFieldData(fieldSchema *schemapb.FieldSchema, data interface{}
fieldData
.
Type
=
fieldSchema
.
DataType
fieldData
.
Type
=
fieldSchema
.
DataType
switch
data
:=
data
.
(
type
)
{
switch
data
:=
data
.
(
type
)
{
case
[]
int64
:
case
[]
int64
:
if
fieldSchema
.
DataType
!=
schemapb
.
DataType_Int64
{
switch
fieldData
.
Type
{
return
nil
,
errors
.
New
(
"the data type of the data and the schema do not match"
)
case
schemapb
.
DataType_Int64
:
}
fieldData
.
Field
=
&
schemapb
.
FieldData_Scalars
{
fieldData
.
Field
=
&
schemapb
.
FieldData_Scalars
{
Scalars
:
&
schemapb
.
ScalarField
{
Scalars
:
&
schemapb
.
ScalarField
{
Data
:
&
schemapb
.
ScalarField_LongData
{
Data
:
&
schemapb
.
ScalarField_LongData
{
LongData
:
&
schemapb
.
LongArray
{
LongData
:
&
schemapb
.
LongArray
{
Data
:
data
,
Data
:
data
,
}
,
},
},
},
},
},
}
case
schemapb
.
DataType_VarChar
:
strIds
:=
make
([]
string
,
len
(
data
))
for
i
,
v
:=
range
data
{
strIds
[
i
]
=
strconv
.
FormatInt
(
v
,
10
)
}
fieldData
.
Field
=
&
schemapb
.
FieldData_Scalars
{
Scalars
:
&
schemapb
.
ScalarField
{
Data
:
&
schemapb
.
ScalarField_StringData
{
StringData
:
&
schemapb
.
StringArray
{
Data
:
strIds
,
},
},
},
}
default
:
return
nil
,
errors
.
New
(
"currently only support autoID for int64 and varchar PrimaryField"
)
}
}
default
:
default
:
return
nil
,
errors
.
New
(
"currently only
support autoID for int64
PrimaryField"
)
return
nil
,
errors
.
New
(
"currently only
int64 is supported as the data source for the autoID of a
PrimaryField"
)
}
}
return
&
fieldData
,
nil
return
&
fieldData
,
nil
...
@@ -1050,7 +1066,7 @@ func checkPrimaryFieldData(schema *schemapb.CollectionSchema, result *milvuspb.M
...
@@ -1050,7 +1066,7 @@ func checkPrimaryFieldData(schema *schemapb.CollectionSchema, result *milvuspb.M
if
typeutil
.
IsPrimaryFieldDataExist
(
insertMsg
.
GetFieldsData
(),
primaryFieldSchema
)
{
if
typeutil
.
IsPrimaryFieldDataExist
(
insertMsg
.
GetFieldsData
(),
primaryFieldSchema
)
{
return
nil
,
fmt
.
Errorf
(
"can not assign primary field data when auto id enabled %v"
,
primaryFieldSchema
.
Name
)
return
nil
,
fmt
.
Errorf
(
"can not assign primary field data when auto id enabled %v"
,
primaryFieldSchema
.
Name
)
}
}
// if autoID == true, currently
only support autoID for int64
PrimaryField
// if autoID == true, currently
support autoID for int64 and varchar
PrimaryField
primaryFieldData
,
err
=
autoGenPrimaryFieldData
(
primaryFieldSchema
,
insertMsg
.
GetRowIDs
())
primaryFieldData
,
err
=
autoGenPrimaryFieldData
(
primaryFieldSchema
,
insertMsg
.
GetRowIDs
())
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Info
(
"generate primary field data failed when autoID == true"
,
zap
.
String
(
"collectionName"
,
insertMsg
.
CollectionName
),
zap
.
Error
(
err
))
log
.
Info
(
"generate primary field data failed when autoID == true"
,
zap
.
String
(
"collectionName"
,
insertMsg
.
CollectionName
),
zap
.
Error
(
err
))
...
...
internal/proxy/util_test.go
浏览文件 @
3b5b50bd
...
@@ -309,7 +309,7 @@ func TestValidatePrimaryKey(t *testing.T) {
...
@@ -309,7 +309,7 @@ func TestValidatePrimaryKey(t *testing.T) {
// test collection with varChar field as primary and autoID = true
// test collection with varChar field as primary and autoID = true
VarCharField
.
AutoID
=
true
VarCharField
.
AutoID
=
true
assert
.
Error
(
t
,
validatePrimaryKey
(
&
schemapb
.
CollectionSchema
{
assert
.
Nil
(
t
,
validatePrimaryKey
(
&
schemapb
.
CollectionSchema
{
Name
:
"coll1"
,
Name
:
"coll1"
,
Description
:
""
,
Description
:
""
,
AutoID
:
true
,
AutoID
:
true
,
...
...
tests/python_client/testcases/test_collection.py
浏览文件 @
3b5b50bd
...
@@ -3754,7 +3754,7 @@ class TestCollectionString(TestcaseBase):
...
@@ -3754,7 +3754,7 @@ class TestCollectionString(TestcaseBase):
"""
"""
target: test create collection with string field
target: test create collection with string field
method: create collection with string field, the string field primary and auto id are true
method: create collection with string field, the string field primary and auto id are true
expected:
Raise exception
expected:
Create collection successfully
"""
"""
self
.
_connect
()
self
.
_connect
()
int_field
=
cf
.
gen_int64_field
()
int_field
=
cf
.
gen_int64_field
()
...
@@ -3762,9 +3762,11 @@ class TestCollectionString(TestcaseBase):
...
@@ -3762,9 +3762,11 @@ class TestCollectionString(TestcaseBase):
string_field
=
cf
.
gen_string_field
(
is_primary
=
True
,
auto_id
=
True
)
string_field
=
cf
.
gen_string_field
(
is_primary
=
True
,
auto_id
=
True
)
fields
=
[
int_field
,
string_field
,
vec_field
]
fields
=
[
int_field
,
string_field
,
vec_field
]
schema
,
_
=
self
.
collection_schema_wrap
.
init_collection_schema
(
fields
=
fields
)
schema
,
_
=
self
.
collection_schema_wrap
.
init_collection_schema
(
fields
=
fields
)
error
=
{
ct
.
err_code
:
0
,
ct
.
err_msg
:
"autoID is not supported when the VarChar field is the primary key"
}
# error = {ct.err_code: 0, ct.err_msg: "autoID is not supported when the VarChar field is the primary key"}
self
.
collection_wrap
.
init_collection
(
name
=
cf
.
gen_unique_str
(
prefix
),
schema
=
schema
,
c_name
=
cf
.
gen_unique_str
(
prefix
)
check_task
=
CheckTasks
.
err_res
,
check_items
=
error
)
self
.
collection_wrap
.
init_collection
(
name
=
c_name
,
schema
=
schema
,
check_task
=
CheckTasks
.
check_collection_property
,
check_items
=
{
exp_name
:
c_name
,
exp_schema
:
schema
})
class
TestCollectionJSON
(
TestcaseBase
):
class
TestCollectionJSON
(
TestcaseBase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录