-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rowcodec: make rowcodec can be used for mocktikv & unistore #13774
Conversation
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #13774 +/- ##
===========================================
Coverage 80.2253% 80.2253%
===========================================
Files 481 481
Lines 120791 120791
===========================================
Hits 96905 96905
Misses 16171 16171
Partials 7715 7715 |
@jackysp @coocood I have make some refactor: mainly split Decoder into DatumMapDecoder/ChunkDecoder/BytesDecoder, after refactor:
PTAL if free |
util/rowcodec/decoder.go
Outdated
"github.com/pingcap/tidb/types" | ||
"github.com/pingcap/tidb/types/json" | ||
"github.com/pingcap/tidb/util/chunk" | ||
"github.com/pingcap/tidb/util/codec" | ||
) | ||
|
||
// Decoder decodes the row to chunk.Chunk. | ||
// Decoder contains base util for decode row. | ||
type Decoder struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make it unexported?
util/rowcodec/decoder.go
Outdated
func (decoder *Decoder) decodeColData(colIdx int, colData []byte, chk *chunk.Chunk) error { | ||
ft := decoder.requestTypes[colIdx] | ||
switch ft.Tp { | ||
func (decoder *ChunkDecoder) decodeColChunk(colIdx int, col *ColInfo, colData []byte, chk *chunk.Chunk) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decodeColToChunk
util/rowcodec/decoder.go
Outdated
} | ||
|
||
// NewByteDecoder creates a BytesDecoder. | ||
func NewByteDecoder(columns []ColInfo, handleColID int64, defBytes []func() ([]byte, error), loc *time.Location) *BytesDecoder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need comments about the defBytes
argument.
util/rowcodec/decoder.go
Outdated
// BytesDecoder decodes the row to old datums bytes. | ||
type BytesDecoder struct { | ||
decoder | ||
defBytes []func() ([]byte, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make the defBytes
accept an i
argument, then we only need to implement one function.
LGTM |
PTAL @jackysp 😄 |
PTAL @jackysp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
What problem does this PR solve?
first part of split PRs of #12634 (there are too many lines but almost them are test)
in #7597, we add rowcodec lib, but after see real-world usage old code need some change, and in this PR add much Unit Test to cover normal code path.
rowcodec provide:
Encode
: datumn array into row bytes, pay attention this method will flatten type and make int/unit as non-varint encode.DecodeToDatumMap
: decode row into datum map, mainly used in ddl operation in TiDBDecodeToChunk
: decode row into chunk, mainly used in unistore executor and batch-get/point executorDecodeToBytes
: decode row into old datum bytes, mainly used in TiDB memtable reader and mocktikv executorDecodeToBytes
can force varin viaWithVarint
option to decode int value as varint(in col value, pk value and default value), this will be used in mocktikv analyze columns executor to build table reader .What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes
Release note
This change is