From ca3d370e268ff20fb91a74cdae65275893051b7e Mon Sep 17 00:00:00 2001 From: Arjun Sunil Kumar Date: Wed, 8 May 2024 21:23:23 -0700 Subject: [PATCH] [BugFix]: FROM_BASE64 return NULL if throws error (#15924) Making FROM_BASE64 Mysql complaint. Approved by: @heni02, @m-schen --- pkg/sql/plan/function/func_unary.go | 21 +++++++++++++----- .../cases/function/func_encode_decode.result | Bin 10443 -> 10474 bytes .../cases/function/func_encode_decode.sql | 8 +++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pkg/sql/plan/function/func_unary.go b/pkg/sql/plan/function/func_unary.go index 2d8fcb00dabaf..64ffb4f80fe16 100644 --- a/pkg/sql/plan/function/func_unary.go +++ b/pkg/sql/plan/function/func_unary.go @@ -858,15 +858,26 @@ func ToBase64(ivecs []*vector.Vector, result vector.FunctionResultWrapper, proc }) } -func FromBase64(ivecs []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int) (err error) { - return opUnaryBytesToBytesWithErrorCheck(ivecs, result, proc, length, func(data []byte) ([]byte, error) { +func FromBase64(parameters []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int) error { + source := vector.GenerateFunctionStrParameter(parameters[0]) + rs := vector.MustFunctionResult[types.Varlena](result) + + rowCount := uint64(length) + for i := uint64(0); i < rowCount; i++ { + data, null := source.GetStrValue(i) + if null { + return rs.AppendMustNullForBytesResult() + } + buf := make([]byte, base64.StdEncoding.DecodedLen(len(functionUtil.QuickBytesToStr(data)))) _, err := base64.StdEncoding.Decode(buf, data) if err != nil { - return nil, err + return rs.AppendMustNullForBytesResult() } - return buf, nil - }) + _ = rs.AppendMustBytesValue(buf) + } + + return nil } func Length(ivecs []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int) error { diff --git a/test/distributed/cases/function/func_encode_decode.result b/test/distributed/cases/function/func_encode_decode.result index 936aab4ad2d920d1833e3b4cf3783e4a481e71fe..00d94527751a62009a6ac44a05fc8fb6cd61f32f 100644 GIT binary patch delta 110 zcmX>d_$qLN3!`LOQGRZGQettcnTbYbURh#JW{M_PUTIFw=5)pvOq27N1SWH`@J`NS q;g>*G>Y%KutP+=%mTG9EIk|=