-
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 plain and dictionary encoded INT64 timestamp in parquet files #8325
Open
mskapilks
wants to merge
6
commits into
facebookincubator:main
Choose a base branch
from
mskapilks:timestamp_int64
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,9 @@ | |
|
||
namespace facebook::velox::parquet { | ||
|
||
class TimestampColumnReader : public IntegerColumnReader { | ||
class TimestampInt96ColumnReader : public IntegerColumnReader { | ||
public: | ||
TimestampColumnReader( | ||
TimestampInt96ColumnReader( | ||
const TypePtr& requestedType, | ||
std::shared_ptr<const dwio::common::TypeWithId> fileType, | ||
ParquetParams& params, | ||
|
@@ -49,19 +49,7 @@ class TimestampColumnReader : public IntegerColumnReader { | |
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); | ||
rawValues[i].toPrecision(timestampPrecision_); | ||
} | ||
} | ||
|
||
|
@@ -82,4 +70,186 @@ class TimestampColumnReader : public IntegerColumnReader { | |
TimestampPrecision timestampPrecision_; | ||
}; | ||
|
||
class TimestampInt64ColumnReader : public IntegerColumnReader { | ||
public: | ||
TimestampInt64ColumnReader( | ||
const TypePtr& requestedType, | ||
std::shared_ptr<const dwio::common::TypeWithId> fileType, | ||
ParquetParams& params, | ||
common::ScanSpec& scanSpec) | ||
: IntegerColumnReader(requestedType, fileType, params, scanSpec), | ||
timestampPrecision_(params.timestampPrecision()) { | ||
auto& parquetFileType = static_cast<const ParquetTypeWithId&>(*fileType_); | ||
auto logicalTypeOpt = parquetFileType.logicalType_; | ||
VELOX_CHECK(logicalTypeOpt.has_value()); | ||
|
||
auto logicalType = logicalTypeOpt.value(); | ||
VELOX_CHECK(logicalType.__isset.TIMESTAMP); | ||
|
||
if (!logicalType.TIMESTAMP.isAdjustedToUTC) { | ||
VELOX_NYI("Only UTC adjusted Timestamp is supported."); | ||
} | ||
|
||
if (logicalType.TIMESTAMP.unit.__isset.MICROS) { | ||
parquetTimestampPrecision_ = TimestampPrecision::kMicroseconds; | ||
} else if (logicalType.TIMESTAMP.unit.__isset.MILLIS) { | ||
parquetTimestampPrecision_ = TimestampPrecision::kMilliseconds; | ||
} else { | ||
VELOX_NYI("Nano Timestamp unit is not supported."); | ||
} | ||
} | ||
|
||
bool hasBulkPath() const override { | ||
return true; | ||
} | ||
|
||
void | ||
processNulls(const bool isNull, const RowSet rows, const uint64_t* rawNulls) { | ||
if (!rawNulls) { | ||
return; | ||
} | ||
auto rawTs = values_->asMutable<Timestamp>(); | ||
|
||
returnReaderNulls_ = false; | ||
anyNulls_ = !isNull; | ||
allNull_ = isNull; | ||
vector_size_t idx = 0; | ||
for (vector_size_t i = 0; i < numValues_; i++) { | ||
if (isNull) { | ||
if (bits::isBitNull(rawNulls, i)) { | ||
bits::setNull(rawResultNulls_, idx); | ||
addOutputRow(rows[i]); | ||
idx++; | ||
} | ||
} else { | ||
if (!bits::isBitNull(rawNulls, i)) { | ||
bits::setNull(rawResultNulls_, idx, false); | ||
rawTs[idx] = rawTs[i]; | ||
addOutputRow(rows[i]); | ||
idx++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void processFilter( | ||
const common::Filter* filter, | ||
const RowSet rows, | ||
const uint64_t* rawNulls) { | ||
auto rawTs = values_->asMutable<Timestamp>(); | ||
|
||
returnReaderNulls_ = false; | ||
anyNulls_ = false; | ||
allNull_ = true; | ||
vector_size_t idx = 0; | ||
for (vector_size_t i = 0; i < numValues_; i++) { | ||
if (rawNulls && bits::isBitNull(rawNulls, i)) { | ||
if (filter->testNull()) { | ||
bits::setNull(rawResultNulls_, idx); | ||
addOutputRow(rows[i]); | ||
anyNulls_ = true; | ||
idx++; | ||
} | ||
} else { | ||
if (filter->testTimestamp(rawTs[i])) { | ||
if (rawNulls) { | ||
bits::setNull(rawResultNulls_, idx, false); | ||
} | ||
rawTs[idx] = rawTs[i]; | ||
addOutputRow(rows[i]); | ||
allNull_ = false; | ||
idx++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void getValues(RowSet rows, VectorPtr* result) override { | ||
getFlatValues<Timestamp, Timestamp>(rows, result, requestedType_); | ||
} | ||
|
||
template <bool isDense> | ||
void readHelper(common::Filter* filter, RowSet rows) { | ||
dwio::common::ExtractToReader extractValues(this); | ||
common::AlwaysTrue alwaysTrue; | ||
dwio::common::ColumnVisitor< | ||
int64_t, | ||
common::AlwaysTrue, | ||
decltype(extractValues), | ||
isDense> | ||
visitor(alwaysTrue, this, rows, extractValues); | ||
readWithVisitor(rows, visitor); | ||
|
||
auto tsValues = | ||
AlignedBuffer::allocate<Timestamp>(numValues_, &memoryPool_); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do it in-place instead of allocating new buffer for each batch? |
||
auto rawTs = tsValues->asMutable<Timestamp>(); | ||
auto rawTsInt64 = values_->asMutable<int64_t>(); | ||
|
||
const auto rawNulls = | ||
resultNulls() ? resultNulls()->as<uint64_t>() : nullptr; | ||
|
||
Timestamp timestamp; | ||
for (vector_size_t i = 0; i < numValues_; i++) { | ||
if (!rawNulls || !bits::isBitNull(rawNulls, i)) { | ||
if (parquetTimestampPrecision_ == TimestampPrecision::kMicroseconds) { | ||
timestamp = Timestamp::fromMicros(rawTsInt64[i]); | ||
} else { | ||
timestamp = Timestamp::fromMillis(rawTsInt64[i]); | ||
} | ||
rawTs[i] = timestamp; | ||
rawTs[i].toPrecision(timestampPrecision_); | ||
} | ||
} | ||
|
||
values_ = tsValues; | ||
rawValues_ = values_->asMutable<char>(); | ||
outputRows_.clear(); | ||
|
||
switch ( | ||
!filter || | ||
(filter->kind() == common::FilterKind::kIsNotNull && !rawNulls) | ||
? common::FilterKind::kAlwaysTrue | ||
: filter->kind()) { | ||
case common::FilterKind::kAlwaysTrue: | ||
// Simply add all rows to output. | ||
for (vector_size_t i = 0; i < numValues_; i++) { | ||
addOutputRow(rows[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to do this, we use |
||
} | ||
break; | ||
case common::FilterKind::kIsNull: | ||
processNulls(true, rows, rawNulls); | ||
break; | ||
case common::FilterKind::kIsNotNull: | ||
processNulls(false, rows, rawNulls); | ||
break; | ||
case common::FilterKind::kTimestampRange: | ||
case common::FilterKind::kMultiRange: | ||
processFilter(filter, rows, rawNulls); | ||
break; | ||
default: | ||
VELOX_UNSUPPORTED("Unsupported filter."); | ||
} | ||
} | ||
|
||
void read( | ||
vector_size_t offset, | ||
RowSet rows, | ||
const uint64_t* /*incomingNulls*/) override { | ||
auto& data = formatData_->as<ParquetData>(); | ||
prepareRead<int64_t>(offset, rows, nullptr); | ||
|
||
bool isDense = rows.back() == rows.size() - 1; | ||
if (isDense) { | ||
readHelper<true>(scanSpec_->filter(), rows); | ||
} else { | ||
readHelper<false>(scanSpec_->filter(), rows); | ||
} | ||
|
||
readOffset_ += rows.back() + 1; | ||
} | ||
|
||
private: | ||
TimestampPrecision parquetTimestampPrecision_; | ||
TimestampPrecision timestampPrecision_; | ||
}; | ||
} // 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.
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.
VectorPtr& batch