(ctx EvalContext, row chunk.Row)
| 664 | } |
| 665 | |
| 666 | func (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. |
| 701 | func ConvertJSON2Tp(v types.BinaryJSON, targetType *types.FieldType) (any, error) { |
nothing calls this directly
no test coverage detected