Fix bug for supporting single quotes (#24464)

Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
This commit is contained in:
cai.zhang 2023-05-29 09:55:27 +08:00 committed by GitHub
parent 0fe8342648
commit dc02c5b064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -951,10 +951,11 @@ func (v *ParserVisitor) getColumnInfoFromJSONIdentifier(identifier string) (*pla
if path == "" {
return nil, fmt.Errorf("invalid identifier: %s", identifier)
}
if strings.HasPrefix(path, "\"") && strings.HasSuffix(path, "\"") {
if (strings.HasPrefix(path, "\"") && strings.HasSuffix(path, "\"")) ||
(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)
return nil, fmt.Errorf("json key must be enclosed in double quotes or single quotes: \"%s\"", path)
}
nestedPath = append(nestedPath, path)
}

View File

@ -892,6 +892,33 @@ func Test_JSONExpr(t *testing.T) {
RoundDecimal: 0,
})
assert.NoError(t, err)
expr = `A['B'] == "abc\"bbb\"cc"`
_, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{
Topk: 0,
MetricType: "",
SearchParams: "",
RoundDecimal: 0,
})
assert.NoError(t, err)
expr = `A['B'] == 'abc"cba'`
_, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{
Topk: 0,
MetricType: "",
SearchParams: "",
RoundDecimal: 0,
})
assert.NoError(t, err)
expr = `A['B'] == 'abc\"cba'`
_, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{
Topk: 0,
MetricType: "",
SearchParams: "",
RoundDecimal: 0,
})
assert.NoError(t, err)
}
func Test_InvalidExprOnJSONField(t *testing.T) {