fix: typecase support added for float to int (#5408)

This commit is contained in:
Nityananda Gohain 2024-07-04 12:08:42 +05:30 committed by GitHub
parent 2e0ddc7c7f
commit 1b0ec8ac43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -91,6 +91,10 @@ func ValidateAndCastValue(v interface{}, dataType v3.AttributeKeyDataType) (inte
return x, nil
case int, int64:
return x, nil
case float32:
return int64(x), nil
case float64:
return int64(x), nil
case string:
int64val, err := strconv.ParseInt(x, 10, 64)
if err != nil {

View File

@ -275,6 +275,24 @@ var testValidateAndCastValueData = []struct {
want: nil,
wantErr: true,
},
{
name: "v3.AttributeKeyDataTypeInt64: valid float32",
args: args{
v: float32(1000),
dataType: v3.AttributeKeyDataTypeInt64,
},
want: int64(1000),
wantErr: false,
},
{
name: "v3.AttributeKeyDataTypeInt64: valid float64",
args: args{
v: float64(1000),
dataType: v3.AttributeKeyDataTypeInt64,
},
want: int64(1000),
wantErr: false,
},
}
// Test cases for ValidateAndCastValue function in pkg/query-service/utils/format.go