Skip to content
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

ORC-1858: [C++] Add support to get StripeStatistics without row index #2144

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions c++/build-support/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To use `run_clang_format.py` you could act like below:
```shell
mkdir build
cd build
cmake .. -DBUILD_JAVA=OFF -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=1
cmake .. -DBUILD_JAVA=OFF -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DORC_ENABLE_CLANG_TOOLS=1
make check-format # Do checks only
make format # This would apply suggested changes, take care!
```
Expand All @@ -23,7 +23,7 @@ To use `run_clang_tidy.py` you could act like below:
```shell
mkdir build
cd build
cmake .. -DBUILD_JAVA=OFF -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=1
cmake .. -DBUILD_JAVA=OFF -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DORC_ENABLE_CLANG_TOOLS=1
make -j`nproc` # Important
make check-clang-tidy # Do checks only
make fix-clang-tidy # This would apply suggested changes, take care!
Expand Down
6 changes: 4 additions & 2 deletions c++/include/orc/Reader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,11 @@ namespace orc {
/**
* Get the statistics about a stripe.
* @param stripeIndex the index of the stripe (0 to N-1) to get statistics about
* @return the statistics about that stripe
* @param includeRowIndex whether the row index of the stripe is included
* @return the statistics about that stripe and row group index statistics
*/
virtual std::unique_ptr<StripeStatistics> getStripeStatistics(uint64_t stripeIndex) const = 0;
virtual std::unique_ptr<StripeStatistics> getStripeStatistics(
uint64_t stripeIndex, bool includeRowIndex = true) const = 0;

/**
* Get the length of the data stripes in the file.
Expand Down
22 changes: 15 additions & 7 deletions c++/src/Reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,27 +751,35 @@ namespace orc {
return *(contents_->schema.get());
}

std::unique_ptr<StripeStatistics> ReaderImpl::getStripeStatistics(uint64_t stripeIndex) const {
std::unique_ptr<StripeStatistics> ReaderImpl::getStripeStatistics(uint64_t stripeIndex,
bool includeRowIndex) const {
if (!isMetadataLoaded_) {
readMetadata();
}
if (contents_->metadata == nullptr) {
throw std::logic_error("No stripe statistics in file");
}
size_t num_cols = static_cast<size_t>(
contents_->metadata->stripe_stats(static_cast<int>(stripeIndex)).col_stats_size());
std::vector<std::vector<proto::ColumnStatistics>> indexStats(num_cols);

proto::StripeInformation currentStripeInfo = footer_->stripes(static_cast<int>(stripeIndex));
proto::StripeFooter currentStripeFooter = getStripeFooter(currentStripeInfo, *contents_.get());

getRowIndexStatistics(currentStripeInfo, stripeIndex, currentStripeFooter, &indexStats);

const Timezone& writerTZ = currentStripeFooter.has_writer_timezone()
? getTimezoneByName(currentStripeFooter.writer_timezone())
: getLocalTimezone();
StatContext statContext(hasCorrectStatistics(), &writerTZ);
return std::make_unique<StripeStatisticsImpl>(

if (!includeRowIndex) {
return std::make_unique<StripeStatisticsImpl>(
contents_->metadata->stripe_stats(static_cast<int>(stripeIndex)), statContext);
}

size_t num_cols = static_cast<size_t>(
contents_->metadata->stripe_stats(static_cast<int>(stripeIndex)).col_stats_size());
std::vector<std::vector<proto::ColumnStatistics>> indexStats(num_cols);

getRowIndexStatistics(currentStripeInfo, stripeIndex, currentStripeFooter, &indexStats);

return std::make_unique<StripeStatisticsWithRowGroupIndexImpl>(
contents_->metadata->stripe_stats(static_cast<int>(stripeIndex)), indexStats, statContext);
}

Expand Down
3 changes: 2 additions & 1 deletion c++/src/Reader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ namespace orc {

const std::string& getStreamName() const override;

std::unique_ptr<StripeStatistics> getStripeStatistics(uint64_t stripeIndex) const override;
std::unique_ptr<StripeStatistics> getStripeStatistics(
uint64_t stripeIndex, bool includeRowIndex = true) const override;

std::unique_ptr<RowReader> createRowReader() const override;

Expand Down
15 changes: 12 additions & 3 deletions c++/src/Statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,20 @@ namespace orc {
// PASS
}

StripeStatisticsImpl::StripeStatisticsImpl(
StripeStatisticsImpl::StripeStatisticsImpl(const proto::StripeStatistics& stripeStats,
const StatContext& statContext) {
columnStats_ = std::make_unique<StatisticsImpl>(stripeStats, statContext);
}

StripeStatisticsWithRowGroupIndexImpl::~StripeStatisticsWithRowGroupIndexImpl() {
// PASS
}

StripeStatisticsWithRowGroupIndexImpl::StripeStatisticsWithRowGroupIndexImpl(
const proto::StripeStatistics& stripeStats,
std::vector<std::vector<proto::ColumnStatistics> >& indexStats,
const StatContext& statContext) {
columnStats_ = std::make_unique<StatisticsImpl>(stripeStats, statContext);
const StatContext& statContext)
: StripeStatisticsImpl(stripeStats, statContext) {
rowIndexStats_.resize(indexStats.size());
for (size_t i = 0; i < rowIndexStats_.size(); i++) {
for (size_t j = 0; j < indexStats[i].size(); j++) {
Expand Down
29 changes: 26 additions & 3 deletions c++/src/Statistics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1713,15 +1713,13 @@ namespace orc {
class StripeStatisticsImpl : public StripeStatistics {
private:
std::unique_ptr<StatisticsImpl> columnStats_;
std::vector<std::vector<std::shared_ptr<const ColumnStatistics> > > rowIndexStats_;

// DELIBERATELY NOT IMPLEMENTED
StripeStatisticsImpl(const StripeStatisticsImpl&);
StripeStatisticsImpl& operator=(const StripeStatisticsImpl&);

public:
StripeStatisticsImpl(const proto::StripeStatistics& stripeStats,
std::vector<std::vector<proto::ColumnStatistics> >& indexStats,
const StatContext& statContext);

virtual const ColumnStatistics* getColumnStatistics(uint32_t columnId) const override {
Expand All @@ -1732,13 +1730,38 @@ namespace orc {
return columnStats_->getNumberOfColumns();
}

virtual const ColumnStatistics* getRowIndexStatistics(uint32_t, uint32_t) const override {
throw NotImplementedYet("set includeRowIndex true to get row index stats");
}

virtual ~StripeStatisticsImpl() override;

virtual uint32_t getNumberOfRowIndexStats(uint32_t) const override {
throw NotImplementedYet("set includeRowIndex true to get row index stats");
}
};

class StripeStatisticsWithRowGroupIndexImpl : public StripeStatisticsImpl {
private:
std::vector<std::vector<std::shared_ptr<const ColumnStatistics> > > rowIndexStats_;

// DELIBERATELY NOT IMPLEMENTED
StripeStatisticsWithRowGroupIndexImpl(const StripeStatisticsWithRowGroupIndexImpl&);
StripeStatisticsWithRowGroupIndexImpl& operator=(const StripeStatisticsWithRowGroupIndexImpl&);

public:
StripeStatisticsWithRowGroupIndexImpl(
const proto::StripeStatistics& stripeStats,
std::vector<std::vector<proto::ColumnStatistics> >& indexStats,
const StatContext& statContext);

virtual const ColumnStatistics* getRowIndexStatistics(uint32_t columnId,
uint32_t rowIndex) const override {
// check id indices are valid
return rowIndexStats_[columnId][rowIndex].get();
}

virtual ~StripeStatisticsImpl() override;
virtual ~StripeStatisticsWithRowGroupIndexImpl() override;

uint32_t getNumberOfRowIndexStats(uint32_t columnId) const override {
return static_cast<uint32_t>(rowIndexStats_[columnId].size());
Expand Down
25 changes: 25 additions & 0 deletions c++/test/TestStripeIndexStatistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ namespace orc {
"length: "
"8000\n",
stringColStats->toString());

std::unique_ptr<orc::Statistics> stripeLevelStats = reader->getStripeStatistics(0, false);
const orc::IntegerColumnStatistics* stripeLevelIntColStats;
stripeLevelIntColStats = reinterpret_cast<const orc::IntegerColumnStatistics*>(
stripeLevelStats->getColumnStatistics(1));
EXPECT_EQ(
"Data type: Integer\nValues: 6000\nHas null: yes\nMinimum: 1\nMaximum: 6000\nSum: "
"18003000\n",
stripeLevelIntColStats->toString());

const orc::StringColumnStatistics* stripeLevelStringColStats;
stripeLevelStringColStats = reinterpret_cast<const orc::StringColumnStatistics*>(
stripeLevelStats->getColumnStatistics(2));
EXPECT_EQ(
"Data type: String\nValues: 6000\nHas null: yes\nMinimum: 1000\nMaximum: 9a\nTotal length: "
"23892\n",
stripeLevelStringColStats->toString());

intColStats =
reinterpret_cast<const orc::IntegerColumnStatistics*>(stripeStats->getColumnStatistics(1));
stringColStats =
reinterpret_cast<const orc::StringColumnStatistics*>(stripeStats->getColumnStatistics(2));

EXPECT_EQ(intColStats->toString(), stripeLevelIntColStats->toString());
EXPECT_EQ(stringColStats->toString(), stripeLevelStringColStats->toString());
}

} // namespace orc
13 changes: 13 additions & 0 deletions c++/test/TestTimestampStatistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ namespace orc {
"00:00:00.688\nLowerBound: 1995-01-01 00:00:00.688\nMaximum: 2037-01-01 "
"00:00:00.0\nUpperBound: 2037-01-01 00:00:00.1\n",
stripeColStats->toString());

std::unique_ptr<orc::StripeStatistics> stripeStatsWithOutRowIndex =
reader->getStripeStatistics(0, false);
const orc::TimestampColumnStatistics* stripeColStatsOnly =
reinterpret_cast<const orc::TimestampColumnStatistics*>(
stripeStatsWithOutRowIndex->getColumnStatistics(0));

EXPECT_TRUE(stripeColStatsOnly->hasMinimum());
EXPECT_TRUE(stripeColStatsOnly->hasMaximum());
EXPECT_EQ(stripeColStats->toString(), stripeColStatsOnly->toString());
EXPECT_EQ(stripeStats->getNumberOfColumns(), stripeStatsWithOutRowIndex->getNumberOfColumns());
EXPECT_THROW(stripeStatsWithOutRowIndex->getRowIndexStatistics(1, 1), NotImplementedYet);
EXPECT_THROW(stripeStatsWithOutRowIndex->getNumberOfRowIndexStats(1), NotImplementedYet);
}

TEST(TestTimestampStatistics, testTimezoneUTC) {
Expand Down
Loading