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

Conversation

wushap
Copy link
Contributor

@wushap wushap commented Feb 24, 2025

What changes were proposed in this pull request?

add a C++ API in reader to get stripe level statistics without reading row group index.

Why are the changes needed?

To #2137

How was this patch tested?

UT PASS

Was this patch authored or co-authored using generative AI tooling?

NO

@github-actions github-actions bot added the CPP label Feb 24, 2025
@dongjoon-hyun
Copy link
Member

Thank you for making a PR, @wushap .

cc @wgtmac

@dongjoon-hyun dongjoon-hyun added this to the 2.2.0 milestone Feb 24, 2025
@ffacs
Copy link
Contributor

ffacs commented Feb 26, 2025

@wushap Gently ping, could you make the CI happy?

throw std::logic_error("No stripe statistics in file");
}
StatContext statContext(hasCorrectStatistics());
return std::unique_ptr<Statistics>(new StatisticsImpl(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::make_unique would be better

@wgtmac
Copy link
Member

wgtmac commented Feb 26, 2025

Thanks for adding this! Could you please create a JIRA issue for this? If you don't have one, please request one from https://selfserve.apache.org/jira-account.html.

@github-actions github-actions bot added the DOCS label Feb 26, 2025
@wushap wushap changed the title add StripeStatistic api and test ORC-1858:add StripeStatistic api and test Feb 27, 2025
@wushap wushap changed the title ORC-1858:add StripeStatistic api and test ORC-1858: [C++]add StripeStatistic api and test Feb 27, 2025
@wushap
Copy link
Contributor Author

wushap commented Feb 27, 2025

Thanks for adding this! Could you please create a JIRA issue for this? If you don't have one, please request one from https://selfserve.apache.org/jira-account.html.

https://issues.apache.org/jira/browse/ORC-1858
here

* @param stripeIndex the index of the stripe (0 to N-1) to get statistics about
* @return the statistics about that stripe without reading row group index statistics
*/
virtual std::unique_ptr<Statistics> getStripeStatisticsOnly(uint64_t stripeIndex) const = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to introduce a new API, especially when the name of getStripeStatisticsOnly is a little bit misleading. This is not your fault, getStripeStatistics does not clearly state it carries row index statistics as well :(

What about changing the existing API like below:

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

Then return different StripeStatistics subclasses depending on the value of includeRowIndex.

  class StripeStatisticsImpl : public StripeStatistics {
   private:
    std::unique_ptr<StatisticsImpl> columnStats_;

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

   public:
    StripeStatisticsImpl(const proto::StripeStatistics& stripeStats,
                         const StatContext& statContext);

    virtual const ColumnStatistics* getColumnStatistics(uint32_t columnId) const override {
      return columnStats_->getColumnStatistics(columnId);
    }

    uint32_t getNumberOfColumns() const override {
      return columnStats_->getNumberOfColumns();
    }

    virtual const ColumnStatistics* getRowIndexStatistics(uint32_t columnId,
                                                          uint32_t rowIndex) const override {
      throw NotImplementedYet("getRowIndexStatistics");
    }

    virtual ~StripeStatisticsImpl() override;

    uint32_t getNumberOfRowIndexStats(uint32_t columnId) const override {
      throw NotImplementedYet("getNumberOfRowIndexStats");
    }
  };

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

   public:
    StripeStatisticsWithRowIndexImpl(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 ~StripeStatisticsWithRowIndexImpl() override;

    uint32_t getNumberOfRowIndexStats(uint32_t columnId) const override {
      return static_cast<uint32_t>(rowIndexStats_[columnId].size());
    }
  };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks better

@wgtmac wgtmac changed the title ORC-1858: [C++]add StripeStatistic api and test ORC-1858: [C++] Add support to get StripeStatistics without row index Mar 1, 2025
Copy link
Member

@wgtmac wgtmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Thanks @wushap!

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Thank you, @wushap and @wgtmac .
Merged to main for Apache ORC 2.2.0.

@dongjoon-hyun
Copy link
Member

Welcome to the Apache ORC community and congratulation for your first commit, @wushap .

I added you to the Apache ORC contributor group and assigned ORC-1858 to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants