enhance: improve error msg when expr invalid during isolation (#35127)

issue: #34336 

Signed-off-by: Patrick Weizhi Xu <weizhi.xu@zilliz.com>
(cherry picked from commit b1d7b24972e9414ab9488c7611aca9975e674cd4)
This commit is contained in:
Patrick Weizhi Xu 2024-07-31 17:23:51 +08:00 committed by GitHub
parent 6106a48acb
commit a9744d62b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -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
}

View File

@ -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",