From 8d49ffcc8b96e65026b1a97be7784e06d33dee2e Mon Sep 17 00:00:00 2001 From: aoiasd <45024769+aoiasd@users.noreply.github.com> Date: Wed, 20 Aug 2025 10:59:46 +0800 Subject: [PATCH] enhance: report field name when text match or pharse match failed because field not enable match (#43366) relate: https://github.com/milvus-io/milvus/issues/41953 Signed-off-by: aoiasd --- internal/parser/planparserv2/parser_visitor.go | 18 +++++++++++++----- .../parser/planparserv2/plan_parser_v2_test.go | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/parser/planparserv2/parser_visitor.go b/internal/parser/planparserv2/parser_visitor.go index cd4763d653..21f920a2c5 100644 --- a/internal/parser/planparserv2/parser_visitor.go +++ b/internal/parser/planparserv2/parser_visitor.go @@ -500,20 +500,21 @@ func (v *ParserVisitor) VisitLike(ctx *parser.LikeContext) interface{} { } func (v *ParserVisitor) VisitTextMatch(ctx *parser.TextMatchContext) interface{} { - column, err := v.translateIdentifier(ctx.Identifier().GetText()) + identifier := ctx.Identifier().GetText() + column, err := v.translateIdentifier(identifier) if err != nil { return err } columnInfo := toColumnInfo(column) - if !v.schema.IsFieldTextMatchEnabled(columnInfo.FieldId) { - return fmt.Errorf("field %v does not enable text match", columnInfo.FieldId) - } if !typeutil.IsStringType(column.dataType) { return errors.New("text match operation on non-string is unsupported") } if column.dataType == schemapb.DataType_Text { return errors.New("text match operation on text field is not supported yet") } + if !v.schema.IsFieldTextMatchEnabled(columnInfo.FieldId) { + return fmt.Errorf("field \"%s\" does not enable match", identifier) + } queryText, err := convertEscapeSingle(ctx.StringLiteral().GetText()) if err != nil { @@ -535,13 +536,20 @@ func (v *ParserVisitor) VisitTextMatch(ctx *parser.TextMatchContext) interface{} } func (v *ParserVisitor) VisitPhraseMatch(ctx *parser.PhraseMatchContext) interface{} { - column, err := v.translateIdentifier(ctx.Identifier().GetText()) + identifier := ctx.Identifier().GetText() + column, err := v.translateIdentifier(identifier) if err != nil { return err } + + columnInfo := toColumnInfo(column) if !typeutil.IsStringType(column.dataType) { return errors.New("phrase match operation on non-string is unsupported") } + if !v.schema.IsFieldTextMatchEnabled(columnInfo.FieldId) { + return fmt.Errorf("field \"%s\" does not enable match", identifier) + } + queryText, err := convertEscapeSingle(ctx.StringLiteral().GetText()) if err != nil { return err diff --git a/internal/parser/planparserv2/plan_parser_v2_test.go b/internal/parser/planparserv2/plan_parser_v2_test.go index c94030fec9..a6364bcb7a 100644 --- a/internal/parser/planparserv2/plan_parser_v2_test.go +++ b/internal/parser/planparserv2/plan_parser_v2_test.go @@ -294,6 +294,7 @@ func TestExpr_TextMatch(t *testing.T) { func TestExpr_PhraseMatch(t *testing.T) { schema := newTestSchema(true) helper, err := typeutil.CreateSchemaHelper(schema) + enableMatch(schema) assert.NoError(t, err) exprStrs := []string{