-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[cherry-pick](branch-2.1) add parquet tvf cases and fix some parquet bug #41931
Merged
yiguolei
merged 6 commits into
apache:branch-2.1
from
suxiaogang223:parquet_hdfs_tvf_case
Oct 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34ef067
[regression-test](parquet) add some parquet cases with tvf (#40379)
suxiaogang223 fa24bf2
[opt](ci) start dockers in parallel (#41338)
suxiaogang223 e30d8bd
[fix](parquet) fix dict page offset zero incompatible behaviour (#41506)
suxiaogang223 3ff7697
[enhance](parquet) support decimal256 for parquet reader (#41526)
suxiaogang223 c476529
[enhance](parquet) Support BYTE_STREAM_SPLIT encoding for parquet rea…
suxiaogang223 26132b1
Revert "[enhance](parquet) support decimal256 for parquet reader (#41…
suxiaogang223 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[enhance](parquet) Support BYTE_STREAM_SPLIT encoding for parquet rea…
…der (#41683) ## Proposed changes Impl ByteStreamSplitDecoder to decode BYTE_STREAM_SPLIT encoding parquet. relate pr: apache/arrow#42372 > Apache Parquet does not have any encodings suitable for FP data and the available text compressors (zstd, gzip, etc) do not handle FP data very well. It is possible to apply a simple data transformation named "stream splitting". Such could be "byte stream splitting" which creates K streams of length N where K is the number of bytes in the data type (4 for floats, 8 for doubles) and N is the number of elements in the sequence. --------- Co-authored-by: morningman <morningman@163.com>
- Loading branch information
commit c476529f5ea10a9a380f1710cc36e0373e95870a
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
warning: 'glog/logging.h' file not found [clang-diagnostic-error]