-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) (#41923) ## Proposed changes pick prs: #41506 #41526 #41683 #41816 --------- Co-authored-by: morningman <morningman@163.com>
- Loading branch information
1 parent
4ce294f
commit e634f0d
Showing
23 changed files
with
504 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include "byte_stream_split.h" | ||
|
||
#include <glog/logging.h> | ||
|
||
#include <array> | ||
#include <cstring> | ||
#include <vector> | ||
|
||
#include "gutil/port.h" | ||
|
||
namespace doris { | ||
|
||
inline void do_merge_streams(const uint8_t** src_streams, int width, int64_t nvalues, | ||
uint8_t* dest) { | ||
// Value empirically chosen to provide the best performance on the author's machine | ||
constexpr int kBlockSize = 128; | ||
|
||
while (nvalues >= kBlockSize) { | ||
for (int stream = 0; stream < width; ++stream) { | ||
// Take kBlockSize bytes from the given stream and spread them | ||
// to their logical places in destination. | ||
const uint8_t* src = src_streams[stream]; | ||
for (int i = 0; i < kBlockSize; i += 8) { | ||
uint64_t v; | ||
std::memcpy(&v, src + i, sizeof(v)); | ||
#ifdef IS_LITTLE_ENDIAN | ||
dest[stream + i * width] = static_cast<uint8_t>(v); | ||
dest[stream + (i + 1) * width] = static_cast<uint8_t>(v >> 8); | ||
dest[stream + (i + 2) * width] = static_cast<uint8_t>(v >> 16); | ||
dest[stream + (i + 3) * width] = static_cast<uint8_t>(v >> 24); | ||
dest[stream + (i + 4) * width] = static_cast<uint8_t>(v >> 32); | ||
dest[stream + (i + 5) * width] = static_cast<uint8_t>(v >> 40); | ||
dest[stream + (i + 6) * width] = static_cast<uint8_t>(v >> 48); | ||
dest[stream + (i + 7) * width] = static_cast<uint8_t>(v >> 56); | ||
#elif defined IS_BIG_ENDIAN | ||
dest[stream + i * width] = static_cast<uint8_t>(v >> 56); | ||
dest[stream + (i + 1) * width] = static_cast<uint8_t>(v >> 48); | ||
dest[stream + (i + 2) * width] = static_cast<uint8_t>(v >> 40); | ||
dest[stream + (i + 3) * width] = static_cast<uint8_t>(v >> 32); | ||
dest[stream + (i + 4) * width] = static_cast<uint8_t>(v >> 24); | ||
dest[stream + (i + 5) * width] = static_cast<uint8_t>(v >> 16); | ||
dest[stream + (i + 6) * width] = static_cast<uint8_t>(v >> 8); | ||
dest[stream + (i + 7) * width] = static_cast<uint8_t>(v); | ||
#endif | ||
} | ||
src_streams[stream] += kBlockSize; | ||
} | ||
dest += width * kBlockSize; | ||
nvalues -= kBlockSize; | ||
} | ||
|
||
// Epilog | ||
for (int stream = 0; stream < width; ++stream) { | ||
const uint8_t* src = src_streams[stream]; | ||
for (int64_t i = 0; i < nvalues; ++i) { | ||
dest[stream + i * width] = src[i]; | ||
} | ||
} | ||
} | ||
|
||
template <int kNumStreams> | ||
void byte_stream_split_decode_scalar(const uint8_t* src, int width, int64_t offset, | ||
int64_t num_values, int64_t stride, uint8_t* dest) { | ||
DCHECK(width == kNumStreams); | ||
std::array<const uint8_t*, kNumStreams> src_streams; | ||
for (int stream = 0; stream < kNumStreams; ++stream) { | ||
src_streams[stream] = &src[stream * stride + offset]; | ||
} | ||
do_merge_streams(src_streams.data(), kNumStreams, num_values, dest); | ||
} | ||
|
||
inline void byte_stream_split_decode_scalar_dynamic(const uint8_t* src, int width, int64_t offset, | ||
int64_t num_values, int64_t stride, | ||
uint8_t* dest) { | ||
std::vector<const uint8_t*> src_streams; | ||
src_streams.resize(width); | ||
for (int stream = 0; stream < width; ++stream) { | ||
src_streams[stream] = &src[stream * stride + offset]; | ||
} | ||
do_merge_streams(src_streams.data(), width, num_values, dest); | ||
} | ||
|
||
// TODO: optimize using simd: https://github.com/apache/arrow/pull/38529 | ||
void byte_stream_split_decode(const uint8_t* src, int width, int64_t offset, int64_t num_values, | ||
int64_t stride, uint8_t* dest) { | ||
switch (width) { | ||
case 1: | ||
memcpy(dest, src + offset * width, num_values); | ||
return; | ||
case 2: | ||
return byte_stream_split_decode_scalar<2>(src, width, offset, num_values, stride, dest); | ||
case 4: | ||
return byte_stream_split_decode_scalar<4>(src, width, offset, num_values, stride, dest); | ||
case 8: | ||
return byte_stream_split_decode_scalar<8>(src, width, offset, num_values, stride, dest); | ||
case 16: | ||
return byte_stream_split_decode_scalar<16>(src, width, offset, num_values, stride, dest); | ||
} | ||
return byte_stream_split_decode_scalar_dynamic(src, width, offset, num_values, stride, dest); | ||
} | ||
|
||
} // namespace doris |
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,37 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace doris { | ||
|
||
/** | ||
* @brief Decode a byte stream into a byte stream split format. | ||
* | ||
* @param src The encoded data by byte stream split. | ||
* @param width The width of type. | ||
* @param offset The offset of encoded data. | ||
* @param num_values The num of values to decode. | ||
* @param stride The length of each stream. | ||
* @param dest The buffer to store the decoded data. | ||
*/ | ||
void byte_stream_split_decode(const uint8_t* src, int width, int64_t offset, int64_t num_values, | ||
int64_t stride, uint8_t* dest); | ||
|
||
} // namespace doris |
95 changes: 95 additions & 0 deletions
95
be/src/vec/exec/format/parquet/byte_stream_split_decoder.cpp
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,95 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include "byte_stream_split_decoder.h" | ||
|
||
#include <cstdint> | ||
|
||
#include "util/byte_stream_split.h" | ||
|
||
namespace doris::vectorized { | ||
|
||
Status ByteStreamSplitDecoder::decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type, | ||
ColumnSelectVector& select_vector, | ||
bool is_dict_filter) { | ||
if (select_vector.has_filter()) { | ||
return _decode_values<true>(doris_column, data_type, select_vector, is_dict_filter); | ||
} else { | ||
return _decode_values<false>(doris_column, data_type, select_vector, is_dict_filter); | ||
} | ||
} | ||
|
||
template <bool has_filter> | ||
Status ByteStreamSplitDecoder::_decode_values(MutableColumnPtr& doris_column, | ||
DataTypePtr& data_type, | ||
ColumnSelectVector& select_vector, | ||
bool is_dict_filter) { | ||
size_t non_null_size = select_vector.num_values() - select_vector.num_nulls(); | ||
if (UNLIKELY(_offset + non_null_size > _data->size)) { | ||
return Status::IOError( | ||
"Out-of-bounds access in parquet data decoder: offset = {}, non_null_size = " | ||
"{},size = {}", | ||
_offset, non_null_size, _data->size); | ||
} | ||
|
||
size_t primitive_length = remove_nullable(data_type)->get_size_of_value_in_memory(); | ||
size_t data_index = doris_column->size() * primitive_length; | ||
size_t scale_size = (select_vector.num_values() - select_vector.num_filtered()) * | ||
(_type_length / primitive_length); | ||
doris_column->resize(doris_column->size() + scale_size); | ||
char* raw_data = const_cast<char*>(doris_column->get_raw_data().data); | ||
ColumnSelectVector::DataReadType read_type; | ||
DCHECK(_data->get_size() % _type_length == 0); | ||
int64_t stride = _data->get_size() / _type_length; | ||
|
||
while (size_t run_length = select_vector.get_next_run<has_filter>(&read_type)) { | ||
switch (read_type) { | ||
case ColumnSelectVector::CONTENT: { | ||
byte_stream_split_decode(reinterpret_cast<const uint8_t*>(_data->get_data()), | ||
_type_length, _offset / _type_length, run_length, stride, | ||
reinterpret_cast<uint8_t*>(raw_data) + data_index); | ||
_offset += run_length * _type_length; | ||
data_index += run_length * _type_length; | ||
break; | ||
} | ||
case ColumnSelectVector::NULL_DATA: { | ||
data_index += run_length * _type_length; | ||
break; | ||
} | ||
case ColumnSelectVector::FILTERED_CONTENT: { | ||
_offset += _type_length * run_length; | ||
break; | ||
} | ||
case ColumnSelectVector::FILTERED_NULL: { | ||
// do nothing | ||
break; | ||
} | ||
} | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
Status ByteStreamSplitDecoder::skip_values(size_t num_values) { | ||
_offset += _type_length * num_values; | ||
if (UNLIKELY(_offset > _data->size)) { | ||
return Status::IOError( | ||
"Out-of-bounds access in parquet data decoder: offset = {}, size = {}", _offset, | ||
_data->size); | ||
} | ||
return Status::OK(); | ||
} | ||
}; // namespace doris::vectorized |
38 changes: 38 additions & 0 deletions
38
be/src/vec/exec/format/parquet/byte_stream_split_decoder.h
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,38 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include "vec/exec/format/parquet/decoder.h" | ||
|
||
namespace doris::vectorized { | ||
class ByteStreamSplitDecoder final : public Decoder { | ||
public: | ||
ByteStreamSplitDecoder() = default; | ||
~ByteStreamSplitDecoder() override = default; | ||
|
||
Status decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type, | ||
ColumnSelectVector& select_vector, bool is_dict_filter) override; | ||
|
||
template <bool has_filter> | ||
Status _decode_values(MutableColumnPtr& doris_column, DataTypePtr& data_type, | ||
ColumnSelectVector& select_vector, bool is_dict_filter); | ||
|
||
Status skip_values(size_t num_values) override; | ||
}; | ||
|
||
} // namespace doris::vectorized |
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.