Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
ccd68501
M
milvus
项目概览
milvus
/
milvus
10 个月 前同步成功
通知
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 搜索 >>
未验证
提交
ccd68501
编写于
5月 16, 2023
作者:
C
cai.zhang
提交者:
GitHub
5月 16, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Json key must be enclosed in double quotes (#24113)
Signed-off-by:
N
cai.zhang
<
cai.zhang@zilliz.com
>
上级
3ea4a390
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
306 addition
and
233 deletion
+306
-233
internal/parser/planparserv2/Plan.g4
internal/parser/planparserv2/Plan.g4
+2
-2
internal/parser/planparserv2/generated/PlanLexer.interp
internal/parser/planparserv2/generated/PlanLexer.interp
+1
-1
internal/parser/planparserv2/generated/plan_lexer.go
internal/parser/planparserv2/generated/plan_lexer.go
+192
-194
internal/parser/planparserv2/parser_visitor.go
internal/parser/planparserv2/parser_visitor.go
+18
-8
internal/parser/planparserv2/plan_parser_v2_test.go
internal/parser/planparserv2/plan_parser_v2_test.go
+88
-22
internal/parser/planparserv2/pool_test.go
internal/parser/planparserv2/pool_test.go
+1
-3
pkg/util/typeutil/schema.go
pkg/util/typeutil/schema.go
+3
-3
tests/integration/json_expr_test.go
tests/integration/json_expr_test.go
+1
-0
未找到文件。
internal/parser/planparserv2/Plan.g4
浏览文件 @
ccd68501
...
...
@@ -85,7 +85,7 @@ FloatingConstant:
Identifier: Nondigit (Nondigit | Digit)*;
StringLiteral: EncodingPrefix? '"' SCharSequence? '"';
JSONIdentifier: Identifier('[' (
'"' SCharSequence '"' | '\'' SCharSequence '\'' | SCharSequence | Integer
Constant) ']')+;
JSONIdentifier: Identifier('[' (
StringLiteral | Decimal
Constant) ']')+;
fragment EncodingPrefix: 'u8' | 'u' | 'U' | 'L';
...
...
@@ -95,7 +95,7 @@ fragment SChar: ~["\\\r\n] | EscapeSequence | '\\\n' | '\\\r\n';
fragment Nondigit: [a-zA-Z_];
fragment Digit: [0-9];
fragment BinaryConstant: '0' [bB] [0-1]+;
fragment DecimalConstant: NonzeroDigit Digit*;
fragment DecimalConstant: NonzeroDigit Digit*
| '0'
;
fragment OctalConstant: '0' OctalDigit*;
fragment HexadecimalConstant: '0' [xX] HexadecimalDigitSequence;
fragment NonzeroDigit: [1-9];
...
...
internal/parser/planparserv2/generated/PlanLexer.interp
浏览文件 @
ccd68501
此差异已折叠。
点击以展开。
internal/parser/planparserv2/generated/plan_lexer.go
浏览文件 @
ccd68501
此差异已折叠。
点击以展开。
internal/parser/planparserv2/parser_visitor.go
浏览文件 @
ccd68501
...
...
@@ -6,7 +6,6 @@ import (
"strings"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/milvus-io/milvus-proto/go-api/schemapb"
parser
"github.com/milvus-io/milvus/internal/parser/planparserv2/generated"
"github.com/milvus-io/milvus/internal/proto/planpb"
...
...
@@ -561,7 +560,10 @@ func (v *ParserVisitor) getChildColumnInfo(identifier, child antlr.TerminalNode)
// VisitRange translates expr to range plan.
func
(
v
*
ParserVisitor
)
VisitRange
(
ctx
*
parser
.
RangeContext
)
interface
{}
{
columnInfo
,
err
:=
v
.
getChildColumnInfo
(
ctx
.
Identifier
(),
ctx
.
JSONIdentifier
())
if
columnInfo
==
nil
||
err
!=
nil
{
if
err
!=
nil
{
return
err
}
if
columnInfo
==
nil
{
return
fmt
.
Errorf
(
"range operations are only supported on single fields now, got: %s"
,
ctx
.
Expr
(
1
)
.
GetText
())
}
...
...
@@ -931,10 +933,8 @@ func (v *ParserVisitor) VisitBitOr(ctx *parser.BitOrContext) interface{} {
*/
// More tests refer to plan_parser_v2_test.go::Test_JSONExpr
func
(
v
*
ParserVisitor
)
getColumnInfoFromJSONIdentifier
(
identifier
string
)
(
*
planpb
.
ColumnInfo
,
error
)
{
ss
:=
strings
.
Split
(
identifier
,
"["
)
fieldName
:=
ss
[
0
]
length
:=
len
(
ss
)
nestedPath
:=
make
([]
string
,
0
,
length
)
fieldName
:=
strings
.
Split
(
identifier
,
"["
)[
0
]
nestedPath
:=
make
([]
string
,
0
)
jsonField
,
err
:=
v
.
schema
.
GetFieldFromNameDefaultJSON
(
fieldName
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -942,8 +942,18 @@ func (v *ParserVisitor) getColumnInfoFromJSONIdentifier(identifier string) (*pla
if
fieldName
!=
jsonField
.
Name
{
nestedPath
=
append
(
nestedPath
,
fieldName
)
}
for
i
:=
1
;
i
<
length
;
i
++
{
path
:=
strings
.
Trim
(
strings
.
Trim
(
ss
[
i
],
"[]"
),
"
\"
"
)
jsonKeyStr
:=
identifier
[
len
(
fieldName
)
:
]
ss
:=
strings
.
Split
(
jsonKeyStr
,
"]["
)
for
i
:=
0
;
i
<
len
(
ss
);
i
++
{
path
:=
strings
.
Trim
(
ss
[
i
],
"[]"
)
if
path
==
""
{
return
nil
,
fmt
.
Errorf
(
"invalid identifier: %s"
,
identifier
)
}
if
strings
.
HasPrefix
(
path
,
"
\"
"
)
&&
strings
.
HasSuffix
(
path
,
"
\"
"
)
{
path
=
path
[
1
:
len
(
path
)
-
1
]
}
else
if
_
,
err
:=
strconv
.
ParseInt
(
path
,
10
,
64
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"json key must be enclosed in double quotes:
\"
%s
\"
"
,
path
)
}
nestedPath
=
append
(
nestedPath
,
path
)
}
...
...
internal/parser/planparserv2/plan_parser_v2_test.go
浏览文件 @
ccd68501
...
...
@@ -4,15 +4,12 @@ import (
"sync"
"testing"
"github.com/milvus-io/milvus/pkg/log"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/proto/planpb"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus-proto/go-api/schemapb"
"github.com/milvus-io/milvus/internal/proto/planpb"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/typeutil"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
func
newTestSchema
()
*
schemapb
.
CollectionSchema
{
...
...
@@ -25,6 +22,12 @@ func newTestSchema() *schemapb.CollectionSchema {
newField
:=
&
schemapb
.
FieldSchema
{
FieldID
:
int64
(
100
+
value
),
Name
:
name
+
"Field"
,
IsPrimaryKey
:
false
,
Description
:
""
,
DataType
:
dataType
,
}
if
value
==
int32
(
schemapb
.
DataType_JSON
)
{
newField
=
&
schemapb
.
FieldSchema
{
FieldID
:
int64
(
100
+
value
),
Name
:
name
+
"Field"
,
IsPrimaryKey
:
false
,
Description
:
""
,
DataType
:
dataType
,
//IsDynamic: true,
}
}
fields
=
append
(
fields
,
newField
)
}
...
...
@@ -687,6 +690,24 @@ func Test_JSONExpr(t *testing.T) {
})
assert
.
NoError
(
t
,
err
)
expr
=
`C["0"] not in [90, 91, 95, 97]`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
NoError
(
t
,
err
)
expr
=
`C[0] in [90, 91, 95, 97]`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
NoError
(
t
,
err
)
expr
=
`C["0"] > 90`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
...
...
@@ -795,25 +816,16 @@ func Test_JSONExpr(t *testing.T) {
})
assert
.
NoError
(
t
,
err
)
expr
=
`exists JSONField["A"] > 10 `
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`exists Int64Field `
expr
=
`exists JSONField["A"]["B"]["C"] `
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
assert
.
No
Error
(
t
,
err
)
expr
=
`
exists JSONField["A"]["B"]["C"]
`
expr
=
`
A["B"][0] > 100
`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
...
...
@@ -831,7 +843,7 @@ func Test_JSONExpr(t *testing.T) {
})
assert
.
NoError
(
t
,
err
)
expr
=
`
A[B]
[0] > 100`
expr
=
`
JSONField
[0] > 100`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
...
...
@@ -840,7 +852,7 @@ func Test_JSONExpr(t *testing.T) {
})
assert
.
NoError
(
t
,
err
)
expr
=
`A[
'B'][0] > 10
0`
expr
=
`A[
"\"\"B\"\""] > 1
0`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
...
...
@@ -849,7 +861,7 @@ func Test_JSONExpr(t *testing.T) {
})
assert
.
NoError
(
t
,
err
)
expr
=
`
JSONField[0] > 100
`
expr
=
`
A["[\"B\"]"] == "abc\"bbb\"cc"
`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
...
...
@@ -934,6 +946,60 @@ func Test_InvalidExprOnJSONField(t *testing.T) {
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`exists JSONField["A"] > 10 `
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`exists Int64Field `
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`A[[""B""]] > 10`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`A["[""B""]"] > 10`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`A[[""B""]] > 10`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`A[B] > 10`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
}
func
Test_InvalidExprWithoutJSONField
(
t
*
testing
.
T
)
{
...
...
internal/parser/planparserv2/pool_test.go
浏览文件 @
ccd68501
...
...
@@ -3,11 +3,9 @@ package planparserv2
import
(
"testing"
"github.com/stretchr/testify/assert"
"github.com/antlr/antlr4/runtime/Go/antlr"
antlrparser
"github.com/milvus-io/milvus/internal/parser/planparserv2/generated"
"github.com/stretchr/testify/assert"
)
func
genNaiveInputStream
()
*
antlr
.
InputStream
{
...
...
pkg/util/typeutil/schema.go
浏览文件 @
ccd68501
...
...
@@ -23,9 +23,8 @@ import (
"github.com/cockroachdb/errors"
"github.com/milvus-io/milvus-proto/go-api/schemapb"
"go.uber.org/zap"
"github.com/milvus-io/milvus/pkg/log"
"go.uber.org/zap"
)
const
DynamicFieldMaxLength
=
512
...
...
@@ -249,6 +248,7 @@ func (helper *SchemaHelper) getDefaultJSONField() (*schemapb.FieldSchema, error)
var
field
*
schemapb
.
FieldSchema
for
_
,
f
:=
range
helper
.
schema
.
GetFields
()
{
// TODO @xiaocai2333: get $SYS_META json field
//if f.DataType == schemapb.DataType_JSON && f.GetIsDynamic() {
if
f
.
DataType
==
schemapb
.
DataType_JSON
{
if
field
!=
nil
{
// TODO @xiaocai2333: will not return error after support $SYS_META
...
...
@@ -260,7 +260,7 @@ func (helper *SchemaHelper) getDefaultJSONField() (*schemapb.FieldSchema, error)
}
}
if
field
==
nil
{
errMsg
:=
"there is no json field in schema, need to specified field name"
errMsg
:=
"there is no
dynamic
json field in schema, need to specified field name"
log
.
Warn
(
errMsg
)
return
nil
,
fmt
.
Errorf
(
errMsg
)
}
...
...
tests/integration/json_expr_test.go
浏览文件 @
ccd68501
...
...
@@ -84,6 +84,7 @@ func TestJsonExpr(t *testing.T) {
Name
:
jsonField
,
Description
:
"this is a json field"
,
DataType
:
schemapb
.
DataType_JSON
,
//IsDynamic: true,
}
return
&
schemapb
.
CollectionSchema
{
Name
:
collectionName
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录