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

feat(c/driver/postgresql): Implement GetTableSchema #577

Merged
merged 12 commits into from
May 5, 2023

Conversation

WillAyd
Copy link
Contributor

@WillAyd WillAyd commented Apr 7, 2023

Definitely a few things need to be ironed out and potentially done as pre-cursors, but I think this is far along enough to review

c/driver/postgresql/connection.cc Outdated Show resolved Hide resolved
c/driver/postgresql/connection.cc Outdated Show resolved Hide resolved
@paleolimbot
Copy link
Member

Just a note that #573 is also related to the postgres type system! (In particular, it factors out the PostgresType -> ArrowSchema step that, as you noted here, is needed in more than one place).

lidavidm pushed a commit that referenced this pull request Apr 12, 2023
)

Per lidavidm comment
#577 (comment)
made this act similar to the current nanoarrow setup
@WillAyd
Copy link
Contributor Author

WillAyd commented Apr 28, 2023

After #628 (whether accepted or not) will come back to this and clean up the string handling. I think the general structure is in place though, leveraging the great work @paleolimbot did on the type mapping

@WillAyd WillAyd marked this pull request as ready for review May 2, 2023 20:47
return ADBC_STATUS_INTERNAL;

if (db_schema != nullptr) {
char* schema = PQescapeIdentifier(conn_, db_schema, strlen(db_schema));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A bit tangential to this but I don't see the current test suite as validating that we are safe against SQL injection attacks. Probably a reasonable follow up to set those types of test in place

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, do you want to file something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #643

return ADBC_STATUS_INTERNAL;

if (db_schema != nullptr) {
char* schema = PQescapeIdentifier(conn_, db_schema, strlen(db_schema));
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, do you want to file something?

c/driver/postgresql/connection.cc Show resolved Hide resolved
c/driver/postgresql/connection.cc Show resolved Hide resolved
Comment on lines 120 to 124
// Disconnect since PostgreSQL connections can be heavy.
{
AdbcStatusCode status = database_->Disconnect(&conn_, error);
if (status != ADBC_STATUS_OK) final_status = status;
}
Copy link
Member

Choose a reason for hiding this comment

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

We don't connect in this method, so we probably shouldn't disconnect if I'm not mistaken?

c/driver/postgresql/connection.cc Show resolved Hide resolved
c/driver/postgresql/connection.cc Show resolved Hide resolved
ExecStatusType pq_status = PQresultStatus(result);
if (pq_status == PGRES_TUPLES_OK) {
int num_rows = PQntuples(result);
ArrowSchemaInit(schema);
Copy link
Member

Choose a reason for hiding this comment

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

This would leave a half-initialized schema in the output argument if we error below which may trip up callers; maybe use a nanoarrow::UniqueSchema and move the schema at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool thanks for the tip. Think I did what you are asking - if so then probably want to do the same thing in statement.cc:InferSchema

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yeah. Though that got removed by the other refactor anyways.

@lidavidm lidavidm changed the title feat(c/driver/postgres): Implement GetTableSchema feat(c/driver/postgresql): Implement GetTableSchema May 5, 2023
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 2b25f49 into apache:main May 5, 2023
@WillAyd WillAyd deleted the postgres-get-schema branch May 5, 2023 16:49
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