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

refactor(c/driver/postgresql): Factory func for CopyWriter construction #1998

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

WillAyd
Copy link
Contributor

@WillAyd WillAyd commented Jul 9, 2024

This is a follow up to #1962, which required each writer construction to subsequently call ->Init() to assign to a protected array_view_ member.

This takes inspiration from the following cpp guideline to have the class manage its construction more appropriately:

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#discussion-use-a-factory-function-if-you-need-virtual-behavior-during-initialization

@WillAyd WillAyd requested a review from lidavidm as a code owner July 9, 2024 17:23
@github-actions github-actions bot added this to the ADBC Libraries 14 milestone Jul 9, 2024
@@ -92,13 +92,20 @@ class PostgresCopyFieldWriter {
public:
virtual ~PostgresCopyFieldWriter() {}

void Init(struct ArrowArrayView* array_view) { array_view_ = array_view; };
template <class T, typename... Params>
static std::unique_ptr<T> Create(struct ArrowArrayView* array_view, Params&&... args) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this even needs to be a static method? It could just be a free function and you can then just invoke

*out = MakeWriter<T>(array_view);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think would have to make the Init method public to do that - do you think that is better?

../driver/postgresql/copy/writer.h:564:15: error: ‘virtual void adbcpq::PostgresCopyFieldWriter::Init(ArrowArrayView*)’ is protected within this context
  564 |   writer->Init(array_view);
      |   ~~~~~~~~~~~~^~~~~~~~~~~~
../driver/postgresql/copy/writer.h:100:16: note: declared protected here
  100 |   virtual void Init(struct ArrowArrayView* array_view) { array_view_ = array_view; };

Copy link
Member

Choose a reason for hiding this comment

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

Ah...

This is fine then. The T::Create<T> bugged me a little bit but it's not actually a problem.

Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

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

Thanks!

@lidavidm lidavidm merged commit 40c325f into apache:main Jul 10, 2024
67 checks passed
@WillAyd WillAyd deleted the refactor-writer branch July 10, 2024 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants