-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Minhan Cao <[email protected]>
- Loading branch information
Showing
8 changed files
with
315 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed 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 "velox/dwio/parquet/reader/RleBpDecoder.h" | ||
|
||
namespace facebook::velox::parquet { | ||
|
||
class RleBooleanDecoder : public facebook::velox::parquet::RleBpDecoder { | ||
public: | ||
using super = facebook::velox::parquet::RleBpDecoder; | ||
RleBooleanDecoder(const char* start, const char* end, int32_t& len) | ||
: super::RleBpDecoder{start + 4, end, 1} { | ||
if (len < 4) { | ||
VELOX_FAIL( | ||
"Received invalid length : " + std::to_string(len) + | ||
" (corrupt data page?)"); | ||
} | ||
// num_bytes will be the first 4 bytes that tell us the length of encoded | ||
// data | ||
num_bytes = | ||
::arrow::bit_util::FromLittleEndian(::arrow::util::SafeLoadAs<uint32_t>( | ||
reinterpret_cast<const uint8_t*>(start))); | ||
if (num_bytes < 0 || num_bytes > static_cast<uint32_t>(len - 4)) { | ||
VELOX_FAIL( | ||
"Received invalid number of bytes : " + std::to_string(num_bytes) + | ||
" (corrupt data page?)"); | ||
} | ||
} | ||
|
||
void skip(uint64_t numValues) { | ||
skip<false>(numValues, 0, nullptr); | ||
} | ||
|
||
template <bool hasNulls> | ||
inline void skip(int32_t numValues, int32_t current, const uint64_t* nulls) { | ||
if (hasNulls) { | ||
numValues = bits::countNonNulls(nulls, current, current + numValues); | ||
} | ||
|
||
super::skip(numValues); | ||
} | ||
|
||
template <bool hasNulls, typename Visitor> | ||
void readWithVisitor(const uint64_t* nulls, Visitor visitor) { | ||
int32_t current = visitor.start(); | ||
|
||
skip<hasNulls>(current, 0, nulls); | ||
int32_t toSkip; | ||
bool atEnd = false; | ||
const bool allowNulls = hasNulls && visitor.allowNulls(); | ||
std::vector<uint64_t> outputBuffer(20); | ||
bool* b = nullptr; | ||
for (;;) { | ||
if (hasNulls && allowNulls && bits::isBitNull(nulls, current)) { | ||
toSkip = visitor.processNull(atEnd); | ||
} else { | ||
if (hasNulls && !allowNulls) { | ||
toSkip = visitor.checkAndSkipNulls(nulls, current, atEnd); | ||
if (!Visitor::dense) { | ||
skip<false>(toSkip, current, nullptr); | ||
} | ||
if (atEnd) { | ||
return; | ||
} | ||
} | ||
|
||
// We are at a non-null value on a row to visit. | ||
std::vector<uint8_t> outputValues_; | ||
outputValues_.resize(visitor.numRows(), 0); | ||
uint8_t* output = outputValues_.data(); | ||
if (!remainingValues_) { | ||
readHeader(); | ||
} | ||
if (repeating_) { | ||
toSkip = visitor.process(value_, atEnd); | ||
} else { | ||
value_ = readBitField(); | ||
toSkip = visitor.process(value_, atEnd); | ||
} | ||
--remainingValues_; | ||
} | ||
++current; | ||
if (toSkip) { | ||
skip<hasNulls>(toSkip, current, nulls); | ||
current += toSkip; | ||
} | ||
if (atEnd) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
private: | ||
int64_t readBitField() { | ||
auto value = | ||
dwio::common::safeLoadBits( | ||
super::bufferStart_, bitOffset_, bitWidth_, lastSafeWord_) & | ||
bitMask_; | ||
bitOffset_ += bitWidth_; | ||
super::bufferStart_ += bitOffset_ >> 3; | ||
bitOffset_ &= 7; | ||
return value; | ||
} | ||
|
||
const char* bufferStart_; | ||
uint32_t num_bytes = 0; | ||
}; | ||
|
||
} // namespace facebook::velox::parquet |
Binary file not shown.
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