MCPcopy Create free account
hub / github.com/pingcap/tidb / evalJSON

Method evalJSON

pkg/expression/builtin_cast.go:666–698  ·  view source on GitHub ↗
(ctx EvalContext, row chunk.Row)

Source from the content-addressed store, hash-verified

664}
665
666func (b *castJSONAsArrayFunctionSig) evalJSON(ctx EvalContext, row chunk.Row) (res types.BinaryJSON, isNull bool, err error) {
667 val, isNull, err := b.args[0].EvalJSON(ctx, row)
668 if isNull || err != nil {
669 return res, isNull, err
670 }
671
672 if val.TypeCode == types.JSONTypeCodeObject {
673 return types.BinaryJSON{}, false, ErrNotSupportedYet.GenWithStackByArgs("CAST-ing JSON OBJECT type to array")
674 }
675
676 arrayVals := make([]any, 0, 8)
677 ft := b.tp.ArrayType()
678 f := convertJSON2Tp(ft.EvalType())
679 if f == nil {
680 return types.BinaryJSON{}, false, ErrNotSupportedYet.GenWithStackByArgs(fmt.Sprintf("CAS-ing data to array of %s", ft.String()))
681 }
682 if val.TypeCode != types.JSONTypeCodeArray {
683 item, err := f(fakeSctx, val, ft)
684 if err != nil {
685 return types.BinaryJSON{}, false, err
686 }
687 arrayVals = append(arrayVals, item)
688 } else {
689 for i := 0; i < val.GetElemCount(); i++ {
690 item, err := f(fakeSctx, val.ArrayGetElem(i), ft)
691 if err != nil {
692 return types.BinaryJSON{}, false, err
693 }
694 arrayVals = append(arrayVals, item)
695 }
696 }
697 return types.CreateBinaryJSON(arrayVals), false, nil
698}
699
700// ConvertJSON2Tp converts JSON to the specified type.
701func ConvertJSON2Tp(v types.BinaryJSON, targetType *types.FieldType) (any, error) {

Callers

nothing calls this directly

Calls 9

CreateBinaryJSONFunction · 0.92
convertJSON2TpFunction · 0.85
ArrayTypeMethod · 0.80
EvalTypeMethod · 0.80
GetElemCountMethod · 0.80
ArrayGetElemMethod · 0.80
EvalJSONMethod · 0.65
StringMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected