-
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.
Support for INT64 timestamp in parquet files
- Loading branch information
Showing
14 changed files
with
347 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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/common/DirectDecoder.h" | ||
|
||
namespace facebook::velox::dwio::common { | ||
|
||
enum TIMESTAMP_PRECISION { MILLIS, MICROS }; | ||
|
||
class TimestampDecoder : public DirectDecoder<false> { | ||
public: | ||
TimestampDecoder( | ||
TIMESTAMP_PRECISION precision, | ||
std::unique_ptr<dwio::common::SeekableInputStream> input, | ||
bool useVInts, | ||
uint32_t numBytes, | ||
bool bigEndian = false) | ||
: DirectDecoder<false>{std::move(input), useVInts, numBytes, bigEndian}, | ||
_precision(precision) {} | ||
|
||
template <bool hasNulls, typename Visitor> | ||
void readWithVisitor( | ||
const uint64_t* FOLLY_NULLABLE nulls, | ||
Visitor visitor, | ||
bool useFastPath = true) { | ||
int32_t current = visitor.start(); | ||
skip<hasNulls>(current, 0, nulls); | ||
const bool allowNulls = hasNulls && visitor.allowNulls(); | ||
for (;;) { | ||
bool atEnd = false; | ||
int32_t toSkip; | ||
if (hasNulls) { | ||
if (!allowNulls) { | ||
toSkip = visitor.checkAndSkipNulls(nulls, current, atEnd); | ||
if (!Visitor::dense) { | ||
skip<false>(toSkip, current, nullptr); | ||
} | ||
if (atEnd) { | ||
return; | ||
} | ||
} else { | ||
if (bits::isBitNull(nulls, current)) { | ||
toSkip = visitor.processNull(atEnd); | ||
goto skip; | ||
} | ||
} | ||
} | ||
if constexpr (std::is_same_v<typename Visitor::DataType, int128_t>) { | ||
auto units = IntDecoder<false>::template readInt<int64_t>(); | ||
Timestamp timestap; | ||
if (_precision == TIMESTAMP_PRECISION::MILLIS) { | ||
timestap = facebook::velox::util::fromUTCMillisParquet(units); | ||
} else { | ||
timestap = facebook::velox::util::fromUTCMicrosParquet(units); | ||
} | ||
|
||
toSkip = | ||
visitor.process(*reinterpret_cast<int128_t*>(×tap), atEnd); | ||
} else { | ||
toSkip = visitor.process( | ||
IntDecoder<false>::template readInt<int64_t>(), atEnd); | ||
} | ||
skip: | ||
++current; | ||
if (toSkip) { | ||
skip<hasNulls>(toSkip, current, nulls); | ||
current += toSkip; | ||
} | ||
if (atEnd) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
private: | ||
TIMESTAMP_PRECISION _precision; | ||
}; | ||
} // namespace facebook::velox::dwio::common |
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
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,49 @@ | ||
/* | ||
* 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/IntegerColumnReader.h" | ||
#include "velox/dwio/parquet/reader/ParquetColumnReader.h" | ||
|
||
namespace facebook::velox::parquet { | ||
|
||
class TimestampColumnReader : public IntegerColumnReader { | ||
public: | ||
TimestampColumnReader( | ||
const std::shared_ptr<const dwio::common::TypeWithId>& requestedType, | ||
std::shared_ptr<const dwio::common::TypeWithId> fileType, | ||
ParquetParams& params, | ||
common::ScanSpec& scanSpec) | ||
: IntegerColumnReader(requestedType, fileType, params, scanSpec) {} | ||
|
||
bool hasBulkPath() const override { | ||
return false; | ||
} | ||
|
||
void read( | ||
vector_size_t offset, | ||
RowSet rows, | ||
const uint64_t* /*incomingNulls*/) override { | ||
auto& data = formatData_->as<ParquetData>(); | ||
// Use int128_t as a workaroud. Timestamp in Velox is of 16-byte length. | ||
prepareRead<int128_t>(offset, rows, nullptr); | ||
readCommon<IntegerColumnReader>(rows); | ||
readOffset_ += rows.back() + 1; | ||
} | ||
}; | ||
|
||
} // namespace facebook::velox::parquet |
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+517 Bytes
velox/dwio/parquet/tests/examples/int64_millis_compatibility.parquet
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.