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): Factor out Postgres type abstraction and test it independently of the driver #573

Merged
merged 90 commits into from
Apr 20, 2023

Conversation

paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Apr 3, 2023

The existing type.h/type.cc provides a limited abstraction of the postgres type system; however, eventually this driver will need to deal with range, domain, array, and record types. This PR factors out existing behaviour and includes a SetSchema() method to provide the default mapping from the postgres -> arrow type systems. This PR doesn't provide full type support but connects enough wires that future support for these types is more straightforward.

Many commits on this branch also implemented a COPY -> Arrow converter abstraction that can handle range, domain, array, and record types. I moved that to a separate branch ( paleolimbot#1 ) because it has an orthogonal scope to this one. If that's of interest I'll continue with that too (which would add support for Array, Domain, and date/time types in results).

@paleolimbot paleolimbot changed the title refactor(c/driver/postgresql): Experimental improvements to type support in postgres driver refactor(c/driver/postgresql): Factor out Postgres type abstraction and test it independently of the driver Apr 9, 2023
@paleolimbot paleolimbot marked this pull request as ready for review April 10, 2023 20:05
@lidavidm lidavidm self-requested a review April 19, 2023 00:15
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.

Cool! This looks much better than the existing approach. I had a few questions but LGTM

namespace adbcpq {

// An enum of the types available in most Postgres pg_type tables
enum PostgresTypeId {
Copy link
Member

Choose a reason for hiding this comment

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

nit/format: why not enum class and follow the convention of kUninitialized, etc.?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call on the enum class!

I usually see ALL_CAPS_STYLE_VALUES in Arrow C++...is the kXXX convention more common/the style used here?

Copy link
Member

Choose a reason for hiding this comment

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

kFoo is the recommended style: https://google.github.io/styleguide/cppguide.html#Enumerator_Names

Arrow is inconsistent about it, partly because it often follows this pattern instead:

class Foo {
    enum Bar { // note: NOT enum class
        CONSTANT,
    }
};

Foo::CONSTANT;

Copy link
Member Author

Choose a reason for hiding this comment

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

I see! I'll tackle the gnarly rename tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok! Enum values are fixed.

c/driver/postgresql/postgres_type.h Outdated Show resolved Hide resolved
c/driver/postgresql/postgres_type.h Show resolved Hide resolved
@lidavidm
Copy link
Member

Looks like there are some MSVC specific errors + you might need to dllexport some of the new things to use them in tests

@paleolimbot
Copy link
Member Author

I tried a few ways to get the tests to work on Windows but none of them worked...for now I just put everything back in the header. If you're particularly opposed to that I could try harder but it may take me a bit to learn the requisite linking-on-windows behaviour.

@lidavidm
Copy link
Member

No worries.

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 added this to the ADBC Libraries 0.4.0 milestone Apr 20, 2023
@lidavidm lidavidm merged commit d56915d into apache:main Apr 20, 2023
@paleolimbot paleolimbot deleted the postgresql-improvements branch April 27, 2023 15:12
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