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

Function TestVarintCompatibility

pkg/util/rowcodec/rowcodec_test.go:697–750  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

695}
696
697func TestVarintCompatibility(t *testing.T) {
698 td := []testData{
699 {
700 1,
701 types.NewFieldType(mysql.TypeLonglong),
702 types.NewIntDatum(1),
703 types.NewIntDatum(1),
704 nil,
705 false,
706 },
707 {
708 2,
709 withUnsigned(types.NewFieldType(mysql.TypeLonglong)),
710 types.NewUintDatum(1),
711 types.NewUintDatum(1),
712 nil,
713 false,
714 },
715 }
716
717 // transform test data into input.
718 colIDs := make([]int64, 0, len(td))
719 dts := make([]types.Datum, 0, len(td))
720 cols := make([]rowcodec.ColInfo, 0, len(td))
721 for _, d := range td {
722 colIDs = append(colIDs, d.id)
723 dts = append(dts, d.input)
724 cols = append(cols, rowcodec.ColInfo{
725 ID: d.id,
726 IsPKHandle: d.handle,
727 Ft: d.ft,
728 })
729 }
730
731 // test encode input.
732 var encoder rowcodec.Encoder
733 newRow, err := encoder.Encode(time.UTC, colIDs, dts, nil, nil)
734 require.NoError(t, err)
735
736 decoder := rowcodec.NewByteDecoder(cols, []int64{-1}, nil, time.UTC)
737 // decode to old row bytes.
738 colOffset := make(map[int64]int)
739 for i, t := range td {
740 colOffset[t.id] = i
741 }
742 oldRow, err := decoder.DecodeToBytes(colOffset, kv.IntHandle(1), newRow, nil)
743 require.NoError(t, err)
744
745 for i, d := range td {
746 oldVarint, err := tablecodec.EncodeValue(nil, nil, d.output) // tablecodec will encode as varint/varuint
747 require.NoError(t, err)
748 require.Equal(t, oldRow[i], oldVarint)
749 }
750}
751
752func TestCodecUtil(t *testing.T) {
753 colIDs := []int64{1, 2, 3, 4}

Callers

nothing calls this directly

Calls 9

EncodeMethod · 0.95
NewFieldTypeFunction · 0.92
NewIntDatumFunction · 0.92
NewUintDatumFunction · 0.92
NewByteDecoderFunction · 0.92
IntHandleTypeAlias · 0.92
EncodeValueFunction · 0.92
DecodeToBytesMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…