Skip to content

[#1013] Implement the Database Adapter#1035

Open
marcocapozzoli wants to merge 63 commits intomasterfrom
masc/1013-database-adapter-cpp-3
Open

[#1013] Implement the Database Adapter#1035
marcocapozzoli wants to merge 63 commits intomasterfrom
masc/1013-database-adapter-cpp-3

Conversation

@marcocapozzoli
Copy link
Collaborator

This PR adds Processors to the database connection. i.e, implement commons/processor/Processor.h

Resolves #1013

@marcocapozzoli marcocapozzoli changed the title [#1013] Implement the Database Adapter [#1013] Implement the Database Adapter 3 Feb 10, 2026
@marcocapozzoli marcocapozzoli changed the base branch from masc/1013-database-adapter-cpp-2 to master February 26, 2026 16:44
@marcocapozzoli marcocapozzoli changed the title [#1013] Implement the Database Adapter 3 [#1013] Implement the Database Adapter Feb 26, 2026
- Introduced `load_query_file` method in `ContextLoader` to read SQL queries from a file.
- Updated `run` function in `database_adapter_main` to handle multiple queries.
- Refactored `AtomPersistenceJob` to include a method for setting producer finished status.
- Adjusted batch size in `Pipeline.h` for improved performance.
- Added a new Makefile target for running the adapter.
}
delete[] children;
delete value;
if (value != NULL) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a TODO here so we can remove this check once we improve HandleTrie::insert() to not accept NULL as value


bool HandleTrie::exists(const string& key) {
TrieNode* node = lookup_node(key);
return node != NULL ? true : false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion:

return lookup_node(key) != NULL;

#include <iostream>
#include <stack>

#include "Logger.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unused


if (!table.contains("table_name")) {
LOG_ERROR(msg_base + " missing required key: 'table_name'");
has_error = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we want to break the for loop once validation has failed?
Why we would keep iterating when a single validation failure is not allowed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So that the user can check all the errors I may make at once, instead of fixing them one by one.

bool BaseSQL2Mapper::insert_handle_if_missing(const string& handle) {
auto exists = this->handle_trie.exists(handle);
if (exists) return false;
this->handle_trie.insert(handle, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we don't want to allow NULL here...
We should use the same approach that I used at the RemoteAtomDBPeer.h (the EmptyTrieValue).
Maybe we should move the EmptyTrieValue class to commons and use it here

int port;

private:
bool connected;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this need to me atomic?

std::atomic<bool> connected

bool second_level = false) override;
void map_sql_query(const string& virtual_name, const string& raw_query) override;

mutex api_mutex;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be public?

for (const auto& table : tables) {
if (table.name == name) return table;
}
Utils::error("Table '" + name + "' not found in the database.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to not throw here, just log the error.


conn->stop();

EXPECT_FALSE(conn->is_connected());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a delete conn here and in the catch so we can release the connection.


vector<Table> tables_cached = wrapper->list_tables();

ASSERT_EQ(tables_cached.size(), tables_cached.size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

ASSERT_EQ(tables_cached.size(), tables.size())

using namespace db_adapter;
using namespace processor;

void ctrl_c_handler(int) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As we are dealing with DBs, it would be better to be sure all operations were done before exit(0) so we don't corrupt any data.

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.

Implement the Database Adapter in C++

4 participants