Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
6804bda8
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 搜索 >>
未验证
提交
6804bda8
编写于
5月 25, 2023
作者:
C
cai.zhang
提交者:
GitHub
5月 25, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support single quotes with string (#24386)
Signed-off-by:
N
cai.zhang
<
cai.zhang@zilliz.com
>
上级
2fdbe7f4
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
352 addition
and
231 deletion
+352
-231
internal/parser/planparserv2/Plan.g4
internal/parser/planparserv2/Plan.g4
+5
-3
internal/parser/planparserv2/generated/PlanLexer.interp
internal/parser/planparserv2/generated/PlanLexer.interp
+5
-3
internal/parser/planparserv2/generated/plan_lexer.go
internal/parser/planparserv2/generated/plan_lexer.go
+231
-219
internal/parser/planparserv2/parser_visitor.go
internal/parser/planparserv2/parser_visitor.go
+8
-6
internal/parser/planparserv2/plan_parser_v2.go
internal/parser/planparserv2/plan_parser_v2.go
+8
-0
internal/parser/planparserv2/plan_parser_v2_test.go
internal/parser/planparserv2/plan_parser_v2_test.go
+59
-0
tests/integration/jsonexpr/json_expr_test.go
tests/integration/jsonexpr/json_expr_test.go
+36
-0
未找到文件。
internal/parser/planparserv2/Plan.g4
浏览文件 @
6804bda8
...
@@ -84,14 +84,16 @@ FloatingConstant:
...
@@ -84,14 +84,16 @@ FloatingConstant:
Identifier: Nondigit (Nondigit | Digit)* | '$meta';
Identifier: Nondigit (Nondigit | Digit)* | '$meta';
StringLiteral: EncodingPrefix?
'"' SCharSequence? '"'
;
StringLiteral: EncodingPrefix?
('"' DoubleSCharSequence? '"' | '\'' SingleSCharSequence? '\'')
;
JSONIdentifier: Identifier('[' (StringLiteral | DecimalConstant) ']')+;
JSONIdentifier: Identifier('[' (StringLiteral | DecimalConstant) ']')+;
fragment EncodingPrefix: 'u8' | 'u' | 'U' | 'L';
fragment EncodingPrefix: 'u8' | 'u' | 'U' | 'L';
fragment SCharSequence: SChar+;
fragment DoubleSCharSequence: DoubleSChar+;
fragment SingleSCharSequence: SingleSChar+;
fragment SChar: ~["\\\r\n] | EscapeSequence | '\\\n' | '\\\r\n';
fragment DoubleSChar: ~["\\\r\n] | EscapeSequence | '\\\n' | '\\\r\n';
fragment SingleSChar: ~['\\\r\n] | EscapeSequence | '\\\n' | '\\\r\n';
fragment Nondigit: [a-zA-Z_];
fragment Nondigit: [a-zA-Z_];
fragment Digit: [0-9];
fragment Digit: [0-9];
fragment BinaryConstant: '0' [bB] [0-1]+;
fragment BinaryConstant: '0' [bB] [0-1]+;
...
...
internal/parser/planparserv2/generated/PlanLexer.interp
浏览文件 @
6804bda8
此差异已折叠。
点击以展开。
internal/parser/planparserv2/generated/plan_lexer.go
浏览文件 @
6804bda8
此差异已折叠。
点击以展开。
internal/parser/planparserv2/parser_visitor.go
浏览文件 @
6804bda8
...
@@ -125,9 +125,10 @@ func (v *ParserVisitor) VisitFloating(ctx *parser.FloatingContext) interface{} {
...
@@ -125,9 +125,10 @@ func (v *ParserVisitor) VisitFloating(ctx *parser.FloatingContext) interface{} {
// VisitString translates expr to GenericValue.
// VisitString translates expr to GenericValue.
func
(
v
*
ParserVisitor
)
VisitString
(
ctx
*
parser
.
StringContext
)
interface
{}
{
func
(
v
*
ParserVisitor
)
VisitString
(
ctx
*
parser
.
StringContext
)
interface
{}
{
literal
,
err
:=
strconv
.
Unquote
(
ctx
.
StringLiteral
()
.
GetText
())
literal
:=
ctx
.
StringLiteral
()
.
GetText
()
if
err
!=
nil
{
if
(
strings
.
HasPrefix
(
literal
,
"
\"
"
)
&&
strings
.
HasSuffix
(
literal
,
"
\"
"
))
||
return
err
(
strings
.
HasPrefix
(
literal
,
"'"
)
&&
strings
.
HasSuffix
(
literal
,
"'"
))
{
literal
=
literal
[
1
:
len
(
literal
)
-
1
]
}
}
return
&
ExprWithType
{
return
&
ExprWithType
{
dataType
:
schemapb
.
DataType_VarChar
,
dataType
:
schemapb
.
DataType_VarChar
,
...
@@ -418,9 +419,10 @@ func (v *ParserVisitor) VisitLike(ctx *parser.LikeContext) interface{} {
...
@@ -418,9 +419,10 @@ func (v *ParserVisitor) VisitLike(ctx *parser.LikeContext) interface{} {
return
fmt
.
Errorf
(
"like operation on complicated expr is unsupported"
)
return
fmt
.
Errorf
(
"like operation on complicated expr is unsupported"
)
}
}
pattern
,
err
:=
strconv
.
Unquote
(
ctx
.
StringLiteral
()
.
GetText
())
pattern
:=
ctx
.
StringLiteral
()
.
GetText
()
if
err
!=
nil
{
if
(
strings
.
HasPrefix
(
pattern
,
"
\"
"
)
&&
strings
.
HasSuffix
(
pattern
,
"
\"
"
))
||
return
err
(
strings
.
HasPrefix
(
pattern
,
"'"
)
&&
strings
.
HasSuffix
(
pattern
,
"'"
))
{
pattern
=
pattern
[
1
:
len
(
pattern
)
-
1
]
}
}
op
,
operand
,
err
:=
translatePatternMatch
(
pattern
)
op
,
operand
,
err
:=
translatePatternMatch
(
pattern
)
...
...
internal/parser/planparserv2/plan_parser_v2.go
浏览文件 @
6804bda8
...
@@ -3,9 +3,12 @@ package planparserv2
...
@@ -3,9 +3,12 @@ package planparserv2
import
(
import
(
"fmt"
"fmt"
"go.uber.org/zap"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/milvus-io/milvus-proto/go-api/schemapb"
"github.com/milvus-io/milvus-proto/go-api/schemapb"
"github.com/milvus-io/milvus/internal/proto/planpb"
"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/milvus-io/milvus/pkg/util/typeutil"
)
)
...
@@ -32,6 +35,11 @@ func handleExpr(schema *typeutil.SchemaHelper, exprStr string) interface{} {
...
@@ -32,6 +35,11 @@ func handleExpr(schema *typeutil.SchemaHelper, exprStr string) interface{} {
return
errorListener
.
err
return
errorListener
.
err
}
}
if
parser
.
GetCurrentToken
()
.
GetTokenType
()
!=
antlr
.
TokenEOF
{
log
.
Info
(
"invalid expression"
,
zap
.
String
(
"expr"
,
exprStr
))
return
fmt
.
Errorf
(
"invalid expression: %s"
,
exprStr
)
}
// lexer & parser won't be used by this thread, can be put into pool.
// lexer & parser won't be used by this thread, can be put into pool.
putLexer
(
lexer
)
putLexer
(
lexer
)
putParser
(
parser
)
putParser
(
parser
)
...
...
internal/parser/planparserv2/plan_parser_v2_test.go
浏览文件 @
6804bda8
...
@@ -1148,3 +1148,62 @@ func Test_InvalidExprWithMultipleJSONField(t *testing.T) {
...
@@ -1148,3 +1148,62 @@ func Test_InvalidExprWithMultipleJSONField(t *testing.T) {
})
})
assert
.
Error
(
t
,
err
)
assert
.
Error
(
t
,
err
)
}
}
func
Test_exprWithSingleQuotes
(
t
*
testing
.
T
)
{
schema
:=
newTestSchema
()
expr
:=
""
var
err
error
expr
=
`'abc' < StringField < "def"`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
NoError
(
t
,
err
)
expr
=
`'ab"c' < StringField < "d'ef"`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
NoError
(
t
,
err
)
expr
=
`'ab\"c' < StringField < "d\'ef"`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
NoError
(
t
,
err
)
expr
=
`'ab\'c' < StringField < "d\"ef"`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
NoError
(
t
,
err
)
expr
=
`'abc'd' < StringField < "def"`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
expr
=
`'abc' < StringField < "def"g"`
_
,
err
=
CreateSearchPlan
(
schema
,
expr
,
"FloatVectorField"
,
&
planpb
.
QueryInfo
{
Topk
:
0
,
MetricType
:
""
,
SearchParams
:
""
,
RoundDecimal
:
0
,
})
assert
.
Error
(
t
,
err
)
}
tests/integration/jsonexpr/json_expr_test.go
浏览文件 @
6804bda8
...
@@ -615,6 +615,40 @@ func (s *JSONExprSuite) checkSearch(collectionName, fieldName string, dim int) {
...
@@ -615,6 +615,40 @@ func (s *JSONExprSuite) checkSearch(collectionName, fieldName string, dim int) {
s
.
doSearch
(
collectionName
,
[]
string
{
fieldName
},
expr
,
dim
,
checkFunc
)
s
.
doSearch
(
collectionName
,
[]
string
{
fieldName
},
expr
,
dim
,
checkFunc
)
log
.
Info
(
"like expression run successfully"
)
log
.
Info
(
"like expression run successfully"
)
expr
=
`str1 like 'abc\"def-%'`
checkFunc
=
func
(
result
*
milvuspb
.
SearchResults
)
{
s
.
Equal
(
1
,
len
(
result
.
Results
.
FieldsData
))
s
.
Equal
(
fieldName
,
result
.
Results
.
FieldsData
[
0
]
.
GetFieldName
())
s
.
Equal
(
schemapb
.
DataType_JSON
,
result
.
Results
.
FieldsData
[
0
]
.
GetType
())
s
.
Equal
(
10
,
len
(
result
.
Results
.
FieldsData
[
0
]
.
GetScalars
()
.
GetJsonData
()
.
GetData
()))
}
s
.
doSearch
(
collectionName
,
[]
string
{
fieldName
},
expr
,
dim
,
checkFunc
)
log
.
Info
(
"like expression run successfully"
)
expr
=
`str1 like 'abc"def-%'`
checkFunc
=
func
(
result
*
milvuspb
.
SearchResults
)
{
s
.
Equal
(
0
,
len
(
result
.
Results
.
FieldsData
))
}
s
.
doSearch
(
collectionName
,
[]
string
{
fieldName
},
expr
,
dim
,
checkFunc
)
log
.
Info
(
"like expression run successfully"
)
expr
=
`str2 like 'abc\"def-%'`
checkFunc
=
func
(
result
*
milvuspb
.
SearchResults
)
{
s
.
Equal
(
0
,
len
(
result
.
Results
.
FieldsData
))
}
s
.
doSearch
(
collectionName
,
[]
string
{
fieldName
},
expr
,
dim
,
checkFunc
)
log
.
Info
(
"like expression run successfully"
)
expr
=
`str2 like 'abc"def-%'`
checkFunc
=
func
(
result
*
milvuspb
.
SearchResults
)
{
s
.
Equal
(
1
,
len
(
result
.
Results
.
FieldsData
))
s
.
Equal
(
fieldName
,
result
.
Results
.
FieldsData
[
0
]
.
GetFieldName
())
s
.
Equal
(
schemapb
.
DataType_JSON
,
result
.
Results
.
FieldsData
[
0
]
.
GetType
())
s
.
Equal
(
10
,
len
(
result
.
Results
.
FieldsData
[
0
]
.
GetScalars
()
.
GetJsonData
()
.
GetData
()))
}
s
.
doSearch
(
collectionName
,
[]
string
{
fieldName
},
expr
,
dim
,
checkFunc
)
log
.
Info
(
"like expression run successfully"
)
expr
=
`A in []`
expr
=
`A in []`
checkFunc
=
func
(
result
*
milvuspb
.
SearchResults
)
{
checkFunc
=
func
(
result
*
milvuspb
.
SearchResults
)
{
s
.
Equal
(
0
,
len
(
result
.
Results
.
FieldsData
))
s
.
Equal
(
0
,
len
(
result
.
Results
.
FieldsData
))
...
@@ -810,6 +844,8 @@ func newJSONData(fieldName string, rowNum int) *schemapb.FieldData {
...
@@ -810,6 +844,8 @@ func newJSONData(fieldName string, rowNum int) *schemapb.FieldData {
"F"
:
i
,
"F"
:
i
,
"G"
:
i
+
10
,
"G"
:
i
+
10
,
},
},
"str1"
:
`abc\"def-`
+
string
(
rune
(
i
)),
"str2"
:
fmt
.
Sprintf
(
"abc
\"
def-%d"
,
i
),
}
}
if
i
%
2
==
0
{
if
i
%
2
==
0
{
data
=
map
[
string
]
interface
{}{
data
=
map
[
string
]
interface
{}{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录