-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support for dictionary encoded INT96 timestamp in parquet files #4680
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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,85 @@ | ||
/* | ||
* 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: | ||
rui-mo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TimestampColumnReader( | ||
const TypePtr& requestedType, | ||
std::shared_ptr<const dwio::common::TypeWithId> fileType, | ||
ParquetParams& params, | ||
common::ScanSpec& scanSpec) | ||
: IntegerColumnReader(requestedType, fileType, params, scanSpec), | ||
timestampPrecision_(params.timestampPrecision()) {} | ||
|
||
bool hasBulkPath() const override { | ||
return false; | ||
} | ||
|
||
void getValues(RowSet rows, VectorPtr* result) override { | ||
rui-mo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getFlatValues<Timestamp, Timestamp>(rows, result, requestedType_); | ||
if (allNull_) { | ||
return; | ||
} | ||
|
||
// Adjust timestamp nanos to the requested precision. | ||
VectorPtr resultVector = *result; | ||
auto rawValues = | ||
resultVector->asUnchecked<FlatVector<Timestamp>>()->mutableRawValues(); | ||
for (auto i = 0; i < numValues_; ++i) { | ||
if (resultVector->isNullAt(i)) { | ||
continue; | ||
} | ||
const auto timestamp = rawValues[i]; | ||
uint64_t nanos = timestamp.getNanos(); | ||
switch (timestampPrecision_) { | ||
case TimestampPrecision::kMilliseconds: | ||
nanos = nanos / 1'000'000 * 1'000'000; | ||
break; | ||
case TimestampPrecision::kMicroseconds: | ||
nanos = nanos / 1'000 * 1'000; | ||
break; | ||
case TimestampPrecision::kNanoseconds: | ||
break; | ||
} | ||
rawValues[i] = Timestamp(timestamp.getSeconds(), nanos); | ||
} | ||
} | ||
|
||
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, true>(rows); | ||
readOffset_ += rows.back() + 1; | ||
} | ||
|
||
private: | ||
// The requested precision can be specified from HiveConfig to read timestamp | ||
// from Parquet. | ||
TimestampPrecision timestampPrecision_; | ||
}; | ||
|
||
} // 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
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.
The unit should be read from the Parquet logical type for this column, not set by the user as a config property. See https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#timestamp
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.
This is corresponding to the timestamp unit that can be handled in compute engine (usually milliseconds for Presto and maybe some other values for Spark), not related to the type in the file. The reader should use the more coarse one of both.
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.
@yingsu00 In a Parquet file, the unit of int96 is fixed because it is made up of days and nanos, unlike int64-timestamp, which can have different units. We parse days and nanos from Parquet, while the compute engine may need different units of timestamps, e.g. Presto needs milli while Spark needs micro. This config allows us to adjust timestamp precision according to user's requirement.
Without this change, the filter result could become incorrect. For example, for a Spark filter
a == 2000-09-12 22:36:29.000000
, if a is stored as nano unit in Velox, when a is2000-09-12 22:36:29.000000111
Velox returns false but Spark needs true because it only cares about the micro digits.Therefore, we need to truncate the value and this logic is also needed for int64-timestamp reader. Does this makes sense? Thanks.
Reference for Int96 in Parquet: https://github.com/apache/parquet-format/pull/49/files#diff-0e877db0daf579f98a11e5e113b29250a2dcae3decb1e83a88db1e6f092bee96R149-R150
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.
THanks @rui-mo for explaining. Sorry I didn't check the INT96 Timestamp spec. Just approved this PR.
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.
Thank you for helping review this PR.