MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / downgradeType

Method downgradeType

pkg/sql/types/types.go:2696–2758  ·  view source on GitHub ↗

of the latest CRDB version. It updates the fields so that they will be marshaled into a format that is compatible with the previous version of CRDB. This is necessary to preserve backwards-compatibility in mixed-version scenarios, such as during upgrade.

()

Source from the content-addressed store, hash-verified

2694// CRDB. This is necessary to preserve backwards-compatibility in mixed-version
2695// scenarios, such as during upgrade.
2696func (t *T) downgradeType() error {
2697 // Set Family and VisibleType for 19.1 backwards-compatibility.
2698 switch t.Family() {
2699 case BitFamily:
2700 if t.Oid() == oid.T_varbit {
2701 t.InternalType.VisibleType = visibleVARBIT
2702 }
2703
2704 case FloatFamily:
2705 switch t.Width() {
2706 case 32:
2707 t.InternalType.VisibleType = visibleREAL
2708 }
2709
2710 case StringFamily, CollatedStringFamily:
2711 switch t.Oid() {
2712 case oid.T_text:
2713 // Nothing to do.
2714 case oid.T_varchar:
2715 t.InternalType.VisibleType = visibleVARCHAR
2716 case oid.T_bpchar:
2717 t.InternalType.VisibleType = visibleCHAR
2718 case oid.T_char:
2719 t.InternalType.VisibleType = visibleQCHAR
2720 case oid.T_name:
2721 t.InternalType.Family = name
2722 default:
2723 return errors.AssertionFailedf("unexpected Oid: %d", t.Oid())
2724 }
2725
2726 case ArrayFamily:
2727 // Marshaling/unmarshaling nested arrays is not yet supported.
2728 if t.ArrayContents().Family() == ArrayFamily {
2729 return errors.AssertionFailedf("nested array should never be marshaled")
2730 }
2731
2732 // Downgrade to array representation used before 19.2, in which the array
2733 // type fields specified the width, locale, etc. of the element type.
2734 temp := *t.InternalType.ArrayContents
2735 if err := temp.downgradeType(); err != nil {
2736 return err
2737 }
2738 t.InternalType.Width = temp.InternalType.Width
2739 t.InternalType.Precision = temp.InternalType.Precision
2740 t.InternalType.Locale = temp.InternalType.Locale
2741 t.InternalType.VisibleType = temp.InternalType.VisibleType
2742 t.InternalType.ArrayElemType = &t.InternalType.ArrayContents.InternalType.Family
2743
2744 switch t.Oid() {
2745 case oid.T_int2vector:
2746 t.InternalType.Family = int2vector
2747 case oid.T_oidvector:
2748 t.InternalType.Family = oidvector
2749 }
2750 }
2751
2752 // Map empty locale to nil.
2753 if t.InternalType.Locale != nil && len(*t.InternalType.Locale) == 0 {

Callers 5

MarshalJSONPBMethod · 0.80
SizeMethod · 0.80
MarshalMethod · 0.80
MarshalToSizedBufferMethod · 0.80
MarshalToMethod · 0.80

Calls 4

FamilyMethod · 0.95
OidMethod · 0.95
WidthMethod · 0.95
ArrayContentsMethod · 0.95

Tested by

no test coverage detected