NormalizeValToString normalizes values into types that can be compared. JSON types, any pg types and time and decimal type values are converted into string value. |normalizeNumeric| defines whether to normalize Numeric values into either Numeric type or string type. There are an infinite number of w
(dt *types.DoltgresType, v any)
| 660 | // There are an infinite number of ways to represent the same value in-memory, |
| 661 | // so we must at least normalize Numeric values. |
| 662 | func NormalizeValToString(dt *types.DoltgresType, v any) any { |
| 663 | if v == nil { |
| 664 | return nil |
| 665 | } |
| 666 | |
| 667 | switch dt.ID { |
| 668 | case types.Json.ID: |
| 669 | jsonBytes, err := json.Marshal(v) |
| 670 | if err != nil { |
| 671 | panic(err) |
| 672 | } |
| 673 | return string(jsonBytes) |
| 674 | case types.JsonB.ID: |
| 675 | // JSONB normalizes JSON with spaces after ':' and ',' (PostgreSQL JSONB format) |
| 676 | s, err := gmstypes.JSONDocument{Val: v}.JSONString() |
| 677 | if err != nil { |
| 678 | panic(err) |
| 679 | } |
| 680 | return s |
| 681 | case types.InternalChar.ID: |
| 682 | if v == nil { |
| 683 | return nil |
| 684 | } |
| 685 | var b []byte |
| 686 | if v.(int32) == 0 { |
| 687 | b = []byte{} |
| 688 | } else { |
| 689 | b = []byte{uint8(v.(int32))} |
| 690 | } |
| 691 | val, err := dt.FormatValue(string(b)) |
| 692 | if err != nil { |
| 693 | panic(err) |
| 694 | } |
| 695 | return val |
| 696 | case types.Interval.ID, types.Uuid.ID: |
| 697 | // These values need to be normalized into the appropriate types |
| 698 | // before being converted to string type using the Doltgres |
| 699 | // IoOutput method. |
| 700 | if v == nil { |
| 701 | return nil |
| 702 | } |
| 703 | tVal, err := dt.FormatValue(NormalizeVal(dt, v)) |
| 704 | if err != nil { |
| 705 | panic(err) |
| 706 | } |
| 707 | return tVal |
| 708 | case types.Date.ID: |
| 709 | if v == nil { |
| 710 | return nil |
| 711 | } |
| 712 | return functions.FormatDateTimeWithBC(v.(time.Time), "2006-01-02", false) |
| 713 | case types.Timestamp.ID, types.TimestampTZ.ID: |
| 714 | if v == nil { |
| 715 | return nil |
| 716 | } |
| 717 | return functions.FormatDateTimeWithBC(v.(time.Time).UTC(), "2006-01-02 15:04:05.999999", dt.ID == types.TimestampTZ.ID) |
| 718 | } |
| 719 |
no test coverage detected