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

Factorize simple DuckDB queries #272

Merged
merged 2 commits into from
Oct 11, 2024
Merged

Factorize simple DuckDB queries #272

merged 2 commits into from
Oct 11, 2024

Conversation

Y--
Copy link
Collaborator

@Y-- Y-- commented Oct 11, 2024

  • change DuckDBManager::GetConnection() member into a static CreateConnection()
  • introduce 3 flavor of DuckDBQueryOrThrow to simplify recurring pattern

@@ -15,13 +15,24 @@ class DuckDBManager {
static inline DuckDBManager &
Get() {
static DuckDBManager instance;
if (!instance.database) {
instance.Initialize();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perform initialization out of constructor so we don't throw during object creation.

@Y-- Y-- requested a review from JelteF October 11, 2024 10:14
@Y-- Y-- force-pushed the yl/factorize-simple-ddb-queries branch from e1a4a43 to 6341cf0 Compare October 11, 2024 10:16
@Y-- Y-- enabled auto-merge (squash) October 11, 2024 10:21
@Y-- Y-- requested a review from mkaruza October 11, 2024 10:21
Comment on lines +107 to +112
duckdb::unique_ptr<duckdb::QueryResult> DuckDBQueryOrThrow(duckdb::ClientContext &context, const std::string &query);

duckdb::unique_ptr<duckdb::QueryResult> DuckDBQueryOrThrow(duckdb::Connection &connection, const std::string &query);

duckdb::unique_ptr<duckdb::QueryResult> DuckDBQueryOrThrow(const std::string &query);

Copy link
Collaborator

@JelteF JelteF Oct 11, 2024

Choose a reason for hiding this comment

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

I think it'd be good to have const char* versions of this too that use an elog(ERROR. In many cases where we want to do a DuckDB query, we'll be in a Postgres C context.

That could be a separate PR though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I'm coming with a dedicated PR that rationalize this.

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've actually made so that they always throw PG errors for now (which was the case already)

elog(ERROR, "(PGDuckDB/duckdb_create_table_trigger) Could not create table: %s", result->GetError().c_str());
}

pgduckdb::DuckDBQueryOrThrow(pgduckdb_get_tabledef(relid));
Copy link
Collaborator

@JelteF JelteF Oct 11, 2024

Choose a reason for hiding this comment

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

It seems incorrect to go from elog to throw here. This will cause a Postgres crash currently if this fails.

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 yes - I extracted it from my PR that wraps all functions with try/catch but didn't pay attention here. Will review other places too.

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've made these function "throw" PG errors.

@Y-- Y-- requested a review from JelteF October 11, 2024 11:42
@Y-- Y-- merged commit ce02dc0 into main Oct 11, 2024
4 checks passed
@Y-- Y-- deleted the yl/factorize-simple-ddb-queries branch October 11, 2024 12:07
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