Skip to content

GH-26153: [C++] Share common codes for RecordBatchStreamReader and StreamDecoder - #36344

Merged
kou merged 5 commits into
apache:mainfrom
kou:cpp-recored-batch-stream-reader-stream-decoder
Jul 4, 2023
Merged

kou merged 5 commits into
apache:mainfrom
kou:cpp-recored-batch-stream-reader-stream-decoder

Conversation

@kou

@kou kou commented Jun 28, 2023 •

Copy link
Copy Markdown
Member

Rationale for this change

Because they (pull-based and push-based) must have the same behavior.

What changes are included in this PR?

This PR extracts reusable codes to StreamDecoderInternal from StreamDecoderImpl. External API isn't changed for
RecordBatchStreamReader and StreamDecoder.

This PR adds some external API to implement this:

  • arrow::Status::ToStringWithoutContextLines(): This is only for testing. We can get stable result of ASSERT_RAISES_WITH_MESSAGE() with/without -DARROW_EXTRA_ERROR_CONTEXT=ON by this.

    We can extract this and related changes to separated PR if we want.

  • arrow::ipc::Listener::OnRecordBatchWithMetadataDecoded(): Because RecordBatchStreamReader wants not only RecordBatch but also custom metadata. OnRecordBatchWithMetadataDecoded() receives RecordBatchWithMetadata. OnRecordBatchDecoded() still exists and it's used by default for backward compatibility.

  • arrow::ipc::CollectListener::metadatas(), arrow::ipc::CollectListener::num_record_batches(), arrow::ipc::CollectListener::PopRecordBatch(), arrow::ipc::CollectListener::PopRecordBatchWithMetadat(): If we add these APIs, we can use CollectListner in RecordBatchStreamReader. We can create an internal listener only for RecordBatchStreamReader if don't want to extend CollectListener.

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes.

This PR includes breaking changes to public APIs.

arrow::ipc::CollectListener::record_batches() returns const std::vector<std::shared_ptr<RecordBatch>>& instead of std::vector<std::shared_ptr<RecordBatch>>.

Comment thread cpp/src/arrow/ipc/reader.h Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We may want to use better name for a vector of metadata...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is ok.

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

Comment thread cpp/src/arrow/ipc/reader.cc Resolved
Comment thread cpp/src/arrow/ipc/reader.cc Resolved
Comment thread cpp/src/arrow/ipc/reader.h Resolved
Comment thread cpp/src/arrow/ipc/reader.h Resolved
Comment thread cpp/src/arrow/ipc/reader.h Resolved
Comment thread cpp/src/arrow/ipc/reader.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is ok.

Comment thread cpp/src/arrow/ipc/reader.h Resolved
Comment thread cpp/src/arrow/ipc/reader.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is schema_ used anywhere?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@pitrou pitrou Jun 29, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ahh... Isn't it error-prone that schema() returns the filtered schema (out_schema_) but OnSchemaDecoded is called with the unfiltered schema (schema_)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can understand your concern.

How about adding Listener::OnSchemaDecoded(std::shared_ptr<Schema> schema, std::shared_ptr<Schema> filtered_schema) and it calls Listener::OnSchemaDecoded(std::shared_ptr<Schema> schema) by default for keeping backward compatibility? (Is filtered_schema name good? I think that out_schema is difficult to understand.)

If we want to do it, I want to do it in a separated pull request instead of including it to this pull request. Because it's not related to this pull request.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's a good idea, thanks for suggesting it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK. I've opened #36407 for it.

@kou

kou commented Jun 29, 2023

Copy link
Copy Markdown
Member Author

The integration test failures seems related:

https://github.com/apache/arrow/actions/runs/5407939797/jobs/9826488521?pr=36344#step:7:14040

################# FAILURES #################
FAILED TEST: nested_dictionary Rust producing,  C++ consuming

FAILED TEST: shared_dict C++ producing,  C++ consuming

@kou

kou commented Jun 29, 2023

Copy link
Copy Markdown
Member Author

The integration test failures are fixed.

@pitrou

pitrou commented Jun 29, 2023 •

Copy link
Copy Markdown
Member

It seems like Homebrew is broken currently? @kou

Edit: it seems to feel better now.

@kou
kou force-pushed the cpp-recored-batch-stream-reader-stream-decoder branch from d6f1948 to b46f6a7 Compare June 30, 2023 02:00
@kou

kou commented Jun 30, 2023

Copy link
Copy Markdown
Member Author

It seems like Homebrew is broken currently?

I've fixed it by #36403 and rebased on main.

@kou

kou commented Jun 30, 2023

Copy link
Copy Markdown
Member Author

AppVeyor failure: #36405

@pitrou

pitrou commented Jun 30, 2023

Copy link
Copy Markdown
Member

The R failures look unexpected. @paleolimbot @thisisnic Any clue about them?

@thisisnic

Copy link
Copy Markdown
Member

R failures are unrelated; the fix is in #36397

@kou

kou commented Jun 30, 2023

Copy link
Copy Markdown
Member Author

I think that #36381 introduced it and it's tracked by #36396.

kou and others added 5 commits July 3, 2023 15:28
…and StreamDecoder

Because they (pull-based and push-based) must have the same behavior.

This PR extracts reusable codes to StreamDecoderInternal from
StreamDecoderImpl. External API isn't changed for
RecordBatchStreamReader and StreamDecoder.

This PR adds some external API to implement this:

* arrow::Status::ToStringWithoutContextLines(): This is only for
  testing. We can get stable result of ASSERT_RAISES_WITH_MESSAGE()
  with/without -DARROW_EXTRA_ERROR_CONTEXT=ON by this.

  We can extract this and related changes to separated PR if we want.

* arrow::ipc::Listener::OnRecordBatchWithMetadataDecoded(): Because
  RecordBatchStreamReader wants not only RecordBatch but also custom
  metadata. OnRecordBatchWithMetadataDecoded() receives
  RecordBatchWithMetadata. OnRecordBatchDecoded() still exists and
  it's used by default for backward compatibility.

* arrow::ipc::CollectListener::metadatas(),
  arrow::ipc::CollectListener::num_record_batches(),
  arrow::ipc::CollectListener::PopRecordBatch(),
  arrow::ipc::CollectListener::PopRecordBatchWithMetadat(): If we add
  these APIs, we can use CollectListner in RecordBatchStreamReader. We
  can create an internal listener only for RecordBatchStreamReader if
  don't want to extend CollectListener.
Co-authored-by: Antoine Pitrou <[email protected]>
Co-authored-by: Antoine Pitrou <[email protected]>
@kou
kou force-pushed the cpp-recored-batch-stream-reader-stream-decoder branch from b46f6a7 to 9e1ca8d Compare July 3, 2023 06:28
@kou

kou commented Jul 3, 2023

Copy link
Copy Markdown
Member Author

#36397 was merged and I've rebased on main.

@kou

kou commented Jul 4, 2023

Copy link
Copy Markdown
Member Author

The R failures have gone.
I'll merge this.

@kou
kou merged commit 7ebc88c into apache:main Jul 4, 2023
@kou
kou deleted the cpp-recored-batch-stream-reader-stream-decoder branch July 4, 2023 00:35
@conbench-apache-arrow

Copy link
Copy Markdown

Conbench analyzed the 6 benchmark runs on commit 7ebc88c8.

There were 3 benchmark results indicating a performance regression:

The full Conbench report has more details.

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.

[C++] RecordBatchStreamReader should use StreamDecoder

3 participants