Skip to content

Conversation

@Y--
Copy link
Collaborator

@Y-- Y-- commented Nov 11, 2024

Convert pgduckdb_tables file to a pure C++ file.

@Y-- Y-- changed the title Add helper to ensure we're not including PG files Remove PG code from pgduckdb_tables Nov 11, 2024
@Y-- Y-- marked this pull request as draft November 11, 2024 15:02
@Y-- Y-- force-pushed the yl/pgduckdb-table-cpp branch 5 times, most recently from c99f4a4 to 3a5bb6a Compare November 12, 2024 09:35
@Y-- Y-- marked this pull request as ready for review November 12, 2024 09:35
@Y-- Y-- requested review from JelteF and mkaruza and removed request for mkaruza November 12, 2024 09:35
@Y-- Y-- force-pushed the yl/pgduckdb-table-cpp branch from 3a5bb6a to 207aca4 Compare November 12, 2024 10:36
@Y-- Y-- requested a review from JelteF November 12, 2024 10:36
@Y-- Y-- force-pushed the yl/pgduckdb-table-cpp branch from 207aca4 to 30ef721 Compare November 12, 2024 10:37
Comment on lines 59 to 63
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the idea behind this wrapper function? Why not declare the original definition in the header? If this would contain a lock-held assert then it would make sense to me (see other comment).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't want to bring them in the header because it would bring PG's headers with it. The point of wrapping them is to decouple PG code from places where we use C++.

Copy link
Collaborator

@JelteF JelteF Nov 12, 2024

Choose a reason for hiding this comment

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

I'm confused. What headers would that bring in? Can't you do:

extern "C" {
void estimate_rel_size(Relation rel, int32_t *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah sorry I misunderstood. Yeah absolutely, though I actually meant to wrap the call with a PG guard since it's not trivial.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah alright, yeah then having the wrapper makes total sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does only this one need tho PD prefix? does ::RelationGetDescr not work for macros?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, macros are basically inline (as text) directly in the source code.

So if you have something like this:

#define foo(a, b) something_foo(a, b)

And you try to declare a function of the same name:

// In the header
void foo(int a, int b);

// In the source file
#include "my_foo_macro.h"

void foo(int a, int b) {
  ::foo(a, b);
}

Then the pre-processor will transform the source file to:

void foo(int a, int b) {
  something_foo(a, b)(a, b);
}

Which sadly doesn't compile.

We should be able to do this:

void foo(int a, int b) {
  foo
}

As long as the parameter match, but that is super hacky and not very readable IMHO

Copy link
Collaborator

@JelteF JelteF Nov 12, 2024

Choose a reason for hiding this comment

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

Ah yeah makes sense. But in this case you're not actually calling the original macro. It's still defined though, and thus even expands the function definition. But it seems nicer to #undef it, then we can use the same names as Postgres uses.

#undef RelationGetDescr
TupleDesc RelationGetDescr(Relation relation) {
	return relation->rd_att;
}

Comment on lines 7 to 9
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to declare these here. Especially the idx_t seems strange to declare. Why not include duckdb.hpp anymore?

I guess PostgresScanGlobalState and PostgresScanLocalState forward declarations are useful because include/pgduckdb/scan/postgres_scan.hpp is including postgres.h. Can we change that instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because pgduckdb_types.hpp is included in a bunch of file I wanted to remain very conservative with adding headers, especially duckdb.h. Instead of declaring idx_t I've updated the interface to remain consistent, that's even better I think.

because include/pgduckdb/scan/postgres_scan.hpp is including postgres.h. Can we change that instead?

yep, it's coming :-)

@Y-- Y-- requested a review from JelteF November 12, 2024 11:17
@Y-- Y-- force-pushed the yl/pgduckdb-table-cpp branch from 70127ec to 8a52066 Compare November 12, 2024 13:16
@Y-- Y-- merged commit 7efda5d into main Nov 12, 2024
4 checks passed
@Y-- Y-- deleted the yl/pgduckdb-table-cpp branch November 12, 2024 13:33
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.

3 participants