From a9744d62b16f2c4e2c361b05427f66d69844b81b Mon Sep 17 00:00:00 2001 From: Patrick Weizhi Xu Date: Wed, 31 Jul 2024 17:23:51 +0800 Subject: [PATCH] enhance: improve error msg when expr invalid during isolation (#35127) issue: #34336 Signed-off-by: Patrick Weizhi Xu (cherry picked from commit b1d7b24972e9414ab9488c7611aca9975e674cd4) --- internal/util/exprutil/expr_checker.go | 11 ++++++++++- internal/util/exprutil/expr_checker_test.go | 11 ++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/util/exprutil/expr_checker.go b/internal/util/exprutil/expr_checker.go index eddb4c740c..6744138968 100644 --- a/internal/util/exprutil/expr_checker.go +++ b/internal/util/exprutil/expr_checker.go @@ -516,7 +516,7 @@ func ValidatePartitionKeyIsolation(expr *planpb.Expr) error { return err } if !foundPartitionKey { - return errors.New("partition key not found in expr when validating partition key isolation") + return errors.New("partition key not found in expr or the expr is invalid when validating partition key isolation") } return nil } @@ -531,6 +531,8 @@ func validatePartitionKeyIsolationFromExpr(expr *planpb.Expr) (bool, error) { return validatePartitionKeyIsolationFromTermExpr(expr.TermExpr) case *planpb.Expr_UnaryRangeExpr: return validatePartitionKeyIsolationFromRangeExpr(expr.UnaryRangeExpr) + case *planpb.Expr_BinaryRangeExpr: + return validatePartitionKeyIsolationFromBinaryRangeExpr(expr.BinaryRangeExpr) } return false, nil } @@ -601,3 +603,10 @@ func validatePartitionKeyIsolationFromRangeExpr(expr *planpb.UnaryRangeExpr) (bo } return false, nil } + +func validatePartitionKeyIsolationFromBinaryRangeExpr(expr *planpb.BinaryRangeExpr) (bool, error) { + if expr.GetColumnInfo().GetIsPartitionKey() { + return true, errors.New("partition key isolation does not support BinaryRange") + } + return false, nil +} diff --git a/internal/util/exprutil/expr_checker_test.go b/internal/util/exprutil/expr_checker_test.go index f417de14a8..c45be7ae54 100644 --- a/internal/util/exprutil/expr_checker_test.go +++ b/internal/util/exprutil/expr_checker_test.go @@ -371,7 +371,7 @@ func TestValidatePartitionKeyIsolation(t *testing.T) { { name: "partition key isolation empty", expr: "", - expectedErrorString: "partition key not found in expr when validating partition key isolation", + expectedErrorString: "partition key not found in expr or the expr is invalid when validating partition key isolation", }, { name: "partition key isolation not equal", @@ -413,6 +413,11 @@ func TestValidatePartitionKeyIsolation(t *testing.T) { expr: "key_field >= 10", expectedErrorString: "partition key isolation does not support GreaterEqual", }, + { + name: "partition key isolation binary range", + expr: "1 < key_field < 10", + expectedErrorString: "partition key isolation does not support BinaryRange", + }, { name: "partition key isolation NOT equal", expr: "not(key_field == 10)", @@ -456,12 +461,12 @@ func TestValidatePartitionKeyIsolation(t *testing.T) { { name: "partition key isolation other field equal", expr: "varChar_field == 'a'", - expectedErrorString: "partition key not found in expr when validating partition key isolation", + expectedErrorString: "partition key not found in expr or the expr is invalid when validating partition key isolation", }, { name: "partition key isolation other field equal AND", expr: "varChar_field == 'a' && int64_field == 1", - expectedErrorString: "partition key not found in expr when validating partition key isolation", + expectedErrorString: "partition key not found in expr or the expr is invalid when validating partition key isolation", }, { name: "partition key isolation complex OR",