Skip to content

ORC-1401: [C++] allow writing an intermediate footer - #1455

Merged
wgtmac merged 14 commits into
apache:mainfrom
hinxx:cpp-intermediate-footer
Apr 24, 2023
Merged

wgtmac merged 14 commits into
apache:mainfrom
hinxx:cpp-intermediate-footer

Conversation

@hinxx

@hinxx hinxx commented Mar 29, 2023

Copy link
Copy Markdown
Contributor

Current C++ code base does not support writing intermediate footers as Java code base does.

It would be beneficial to the C++ based writers to have an ability to write intermediate footer(s) to the opened file while streaming data into it. The benefit is not losing the so far persisted data (after flushing stripes) in case of writer failure in closing the file (application crash).

The writer that wants to support the feature would follow similar approach as Hive does in writing a side file with the latest footer offsets. The reader would be able to determine the location of the last valid footer by using the last footer location from the side file (instead of assuming that the footer is at the end of the file).

The change was tested by creating a small ORC file writer test application that calls newly added WriterImpl::writeIntermediateFooter() after adding a batch of rows:

        writer->add(*batch);
        writer->writeIntermediateFooter();

The resulting ORC file is readable by the provided stock C++ and Java tools. The preliminary C++ test code and results from the tools are attached to this PR here notes.txt.

Not all aspects of the possible use were tested yet namely unclean writer app shutdown, writing of the side file, loading of the side file, reading of the last valid footer when file was not properly closed.

This is a draft PR. No proper tests are added at the moment because of incomplete PR.

I'm looking for opinions from the ORC experts in order to finish up the PR.

@github-actions github-actions Bot added the CPP label Mar 29, 2023
Comment thread c++/src/Writer.cc Resolved
Comment thread c++/src/Writer.cc Resolved
Comment thread c++/src/Writer.cc Resolved

@dongjoon-hyun dongjoon-hyun 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.

Thank you for filing a JIRA and making a PR, @hinxx .
I clicked the CI approval button in order to trigger the tests.

@dongjoon-hyun

Copy link
Copy Markdown
Member

cc @omalley and @wgtmac

Hinko Kocevar added 4 commits March 30, 2023 10:04

@wgtmac wgtmac 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.

Thanks for the change! I haven't gone through all the change. Will take a deep look over the weekend.

Comment thread c++/include/orc/OrcFile.hh Resolved
Comment thread c++/include/orc/Writer.hh Resolved

@wgtmac wgtmac 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 addition!

cc @stiga-huang @coderex2522

Comment thread c++/src/Writer.cc Resolved
Comment thread c++/src/Writer.cc Resolved
Comment thread c++/test/TestWriter.cc Resolved

@wgtmac wgtmac 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.

Could you please make the CI happy?

Comment thread c++/src/Writer.cc Resolved
Comment thread c++/src/Writer.cc Resolved
Comment thread c++/src/Writer.cc Resolved
@wgtmac

wgtmac commented Apr 14, 2023

Copy link
Copy Markdown
Member

Some CI checks fail due to following reason, please use static_cast to fix those errors.

/Users/runner/work/orc/orc/c++/src/Writer.cc:324:10: error: virtual function 'writeIntermediateFooter' has a different return type ('long') than the function it overrides (which has return type 'int64_t' (aka 'long long'))
    long writeIntermediateFooter() override;
    ~~~~ ^
/Users/runner/work/orc/orc/c++/include/orc/Writer.hh:312:21: note: overridden virtual function is here
    virtual int64_t writeIntermediateFooter() = 0;
            ~~~~~~~ ^
/Users/runner/work/orc/orc/c++/src/Writer.cc:418:36: error: implicit conversion changes signedness: 'uint64_t' (aka 'unsigned long long') to 'long' [-Werror,-Wsign-conversion]
      lastFlushOffset = outStream->getLength();
                      ~ ~~~~~~~~~~~^~~~~~~~~~~
/Users/runner/work/orc/orc/c++/src/Writer.cc:419:23: error: implicit conversion changes signedness: 'long' to 'uint64_t' (aka 'unsigned long long') [-Werror,-Wsign-conversion]
      currentOffset = lastFlushOffset;
                    ~ ^~~~~~~~~~~~~~~
3 errors generated.

In addition, the C++ format check failures can be fixed by applying clang-format. @hinxx

@hinxx

hinxx commented Apr 18, 2023

Copy link
Copy Markdown
Contributor Author

I checked the CI logs and I think I solved all the issue regarding the data types and formatting.

@wgtmac
wgtmac marked this pull request as ready for review April 18, 2023 15:37
@wgtmac

wgtmac commented Apr 18, 2023

Copy link
Copy Markdown
Member

I checked the CI logs and I think I solved all the issue regarding the data types and formatting.

Seems the build on macos has a different opinion.

[ 58%] Building CXX object c++/src/CMakeFiles/orc.dir/Writer.cc.o
/Users/runner/work/orc/orc/c++/src/Writer.cc:419:36: error: implicit conversion changes signedness: 'uint64_t' (aka 'unsigned long long') to 'int64_t' (aka 'long long') [-Werror,-Wsign-conversion]
      lastFlushOffset = outStream->getLength();
                      ~ ~~~~~~~~~~~^~~~~~~~~~~
/Users/runner/work/orc/orc/c++/src/Writer.cc:420:23: error: implicit conversion changes signedness: 'int64_t' (aka 'long long') to 'uint64_t' (aka 'unsigned long long') [-Werror,-Wsign-conversion]
      currentOffset = lastFlushOffset;
                    ~ ^~~~~~~~~~~~~~~
/Users/runner/work/orc/orc/c++/src/Writer.cc:424:12: error: implicit conversion changes signedness: 'int64_t' (aka 'long long') to 'uint64_t' (aka 'unsigned long long') [-Werror,-Wsign-conversion]
    return lastFlushOffset;
    ~~~~~~ ^~~~~~~~~~~~~~~
3 errors generated.
make[2]: *** [c++/src/CMakeFiles/orc.dir/Writer.cc.o] Error 1
make[1]: *** [c++/src/CMakeFiles/orc.dir/all] Error 2
make: *** [all] Error 2
Error: Process completed with exit code 2.

@hinxx

hinxx commented Apr 19, 2023

Copy link
Copy Markdown
Contributor Author

Seems the build on macos has a different opinion.

This is becoming embarrassing. I would expect to see these sign related errors in my Linux g++ build, but for some reason I don't.
Changed lastFlushOffset data type to uint64_t.

@wgtmac wgtmac 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.

LGTM. Thanks! @hinxx

@wgtmac
wgtmac merged commit 071b757 into apache:main Apr 24, 2023
@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you, @hinxx and @wgtmac !

@dongjoon-hyun dongjoon-hyun added this to the 1.9.0 milestone Apr 26, 2023
cxzl25 pushed a commit to cxzl25/orc that referenced this pull request Jan 11, 2024
Current C++ code base does not support writing intermediate footers as Java code base does.

It would be beneficial to the C++ based writers to have an ability to write intermediate footer(s) to the opened file while streaming data into it. The benefit is not losing the so far persisted data (after flushing stripes) in case of writer failure in closing the file (application crash).

The writer that wants to support the feature would follow similar approach as Hive does in writing a side file with the latest footer offsets. The reader would be able to determine the location of the last valid footer by using the last footer location from the side file (instead of assuming that the footer is at the end of the file).

The change was tested by creating a small ORC file writer test application that calls newly added WriterImpl::writeIntermediateFooter() after adding a batch of rows: The resulting ORC file is readable by the provided stock C++ and Java tools.

This closes apache#1455
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants