-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FLASH-795 support chblock encode type (#383)
* support chblock encode type for cop request * fix timestamp bug for ch block encode * add unsupported type for chblock encode * refine code * fix build error * address comments
- Loading branch information
1 parent
ed0ecec
commit d6d1d2c
Showing
12 changed files
with
268 additions
and
170 deletions.
There are no files selected for viewing
Submodule tipb
updated
4 files
+294 −290 | go-tipb/expression.pb.go | |
+61 −56 | go-tipb/select.pb.go | |
+3 −2 | proto/expression.proto | |
+2 −0 | proto/select.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <DataStreams/IBlockInputStream.h> | ||
#include <DataStreams/NativeBlockInputStream.h> | ||
#include <Flash/Coprocessor/CHBlockChunkCodec.h> | ||
#include <IO/ReadBufferFromString.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
class CHBlockChunkCodecStream : public ChunkCodecStream | ||
{ | ||
public: | ||
explicit CHBlockChunkCodecStream(const std::vector<tipb::FieldType> & field_types) : ChunkCodecStream(field_types) | ||
{ | ||
output = std::make_unique<WriteBufferFromOwnString>(); | ||
} | ||
|
||
String getString() override | ||
{ | ||
std::stringstream ss; | ||
return output->str(); | ||
} | ||
void clear() override { output = std::make_unique<WriteBufferFromOwnString>(); } | ||
void encode(const Block & block, size_t start, size_t end) override; | ||
std::unique_ptr<WriteBufferFromOwnString> output; | ||
}; | ||
|
||
void writeData(const IDataType & type, const ColumnPtr & column, WriteBuffer & ostr, size_t offset, size_t limit) | ||
{ | ||
/** If there are columns-constants - then we materialize them. | ||
* (Since the data type does not know how to serialize / deserialize constants.) | ||
*/ | ||
ColumnPtr full_column; | ||
|
||
if (ColumnPtr converted = column->convertToFullColumnIfConst()) | ||
full_column = converted; | ||
else | ||
full_column = column; | ||
|
||
IDataType::OutputStreamGetter output_stream_getter = [&](const IDataType::SubstreamPath &) { return &ostr; }; | ||
type.serializeBinaryBulkWithMultipleStreams(*full_column, output_stream_getter, offset, limit, false, {}); | ||
} | ||
|
||
void CHBlockChunkCodecStream::encode(const Block & block, size_t start, size_t end) | ||
{ | ||
// Encode data in chunk by chblock encode | ||
if (start != 0 || end != block.rows()) | ||
throw Exception("CHBlock encode only support encode whole block"); | ||
block.checkNumberOfRows(); | ||
size_t columns = block.columns(); | ||
size_t rows = block.rows(); | ||
|
||
writeVarUInt(columns, *output); | ||
writeVarUInt(rows, *output); | ||
|
||
for (size_t i = 0; i < columns; i++) | ||
{ | ||
const ColumnWithTypeAndName & column = block.safeGetByPosition(i); | ||
|
||
writeStringBinary(column.name, *output); | ||
writeStringBinary(column.type->getName(), *output); | ||
|
||
if (rows) | ||
writeData(*column.type, column.column, *output, 0, 0); | ||
} | ||
} | ||
|
||
std::unique_ptr<ChunkCodecStream> CHBlockChunkCodec::newCodecStream(const std::vector<tipb::FieldType> & field_types) | ||
{ | ||
return std::make_unique<CHBlockChunkCodecStream>(field_types); | ||
} | ||
|
||
Block CHBlockChunkCodec::decode(const tipb::Chunk & chunk, const DAGSchema &) | ||
{ | ||
const String & row_data = chunk.rows_data(); | ||
ReadBufferFromString read_buffer(row_data); | ||
NativeBlockInputStream block_in(read_buffer, 0); | ||
return block_in.read(); | ||
} | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <Flash/Coprocessor/ChunkCodec.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
class CHBlockChunkCodec : public ChunkCodec | ||
{ | ||
public: | ||
CHBlockChunkCodec() = default; | ||
Block decode(const tipb::Chunk &, const DAGSchema &) override; | ||
std::unique_ptr<ChunkCodecStream> newCodecStream(const std::vector<tipb::FieldType> & field_types) override; | ||
}; | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.