-
Notifications
You must be signed in to change notification settings - Fork 256
9 - Added ReSQL - DuckDB support #224
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
Open
Burnfireblaze
wants to merge
45
commits into
apache:master
Choose a base branch
from
DDS-Project-Team:feature/resql-service
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
d158693
Readme changes
f7644f5
Merge pull request #1 from chanchanmano/sudarsan-changes
Burnfireblaze 73660ab
Add DuckDB Bazel dependency
Ashay2001K f175cba
Modify kv_executor + proto
Ashay2001K ed4fc8d
added new duckdb files, modified storage headers, added proto for duc…
chanchanmano 6ef61f2
Adds duckDB runtime flag to kv_service
khodetejas 42c2017
Merge pull request #2 from DDS-Project-Team/feature/modify-kv-executor
chanchanmano d49a33e
Merge pull request #3 from DDS-Project-Team/duckdb_storage_interface_…
Burnfireblaze 05a39f9
KV Fixes and CLI fixes
e38e987
fixes for kv service build
53732cb
fixes for kv service build
823da6f
server config modified
dbc8ffa
Revert server config
2e17505
Removes Changes made to kv
khodetejas 227599d
Merge pull request #6 from DDS-Project-Team/feature/fixes-kv-cli-fixes
Burnfireblaze 50ae340
Merge pull request #4 from DDS-Project-Team/feature/service-sql-backe…
Burnfireblaze 5e42200
RESQL Start Service added
b333bfa
Merge pull request #7 from DDS-Project-Team/feature/resql-start-service
Burnfireblaze 8c4e62f
removed passing of path to rely on default
chanchanmano 5263dc3
Merge pull request #8 from DDS-Project-Team/resql_startup_script
Burnfireblaze 916c332
added a test_sql script that tests the functionalities offered by the…
chanchanmano 1a10083
Merge pull request #9 from DDS-Project-Team/resql_test_script
Burnfireblaze 6487106
Logging enabled
466520d
Logging enabled 2
df62631
Logging enabled 3
3a64ce6
Logging enabled 4
dadfe7d
Logging enabled 5
6c605a9
Start Resql service
8b0b0f8
modified
bc77c9c
modified
0bb0c27
Autocomplete flags
b4f54ba
Flags set automatically
5066ae8
Merge pull request #10 from DDS-Project-Team/feature/logging-enabled
Burnfireblaze 05b847d
[temp] added creation of folders to start_resql_script to avoid node …
chanchanmano 3431672
Merge pull request #12 from DDS-Project-Team/making_folders_in_script
chanchanmano a9b6c73
Add DuckDB Bazel dependency
Ashay2001K 7c1ba12
Modify kv_executor + proto
Ashay2001K ade45b2
added new duckdb files, modified storage headers, added proto for duc…
chanchanmano 057efbb
KV Fixes and CLI fixes
c7fc425
added a test_sql script that tests the functionalities offered by the…
chanchanmano edb4814
Start Resql service
d98f47f
Flags set automatically
88d1011
Rebased DuckDB Code
31cf735
Merge branch 'develop' into feature/squash-commits-v4
Burnfireblaze bee02e3
Merge pull request #13 from DDS-Project-Team/feature/squash-commits-v4
Burnfireblaze File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #include "chain/storage/duckdb.h" | ||
|
|
||
| #include <glog/logging.h> | ||
|
|
||
| #include <exception> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "duckdb.hpp" | ||
|
|
||
| namespace resdb { | ||
| namespace storage { | ||
|
|
||
| std::unique_ptr<Storage> NewResQL(const std::string& path, | ||
| const DuckDBInfo& config) { | ||
| DuckDBInfo cfg = config; | ||
| cfg.set_path(path); | ||
|
|
||
| return std::make_unique<ResQL>(cfg); | ||
| } | ||
|
|
||
| ResQL::ResQL(const DuckDBInfo& config) : config_(config) { | ||
| std::string path = "/tmp/resql-duckdb"; | ||
| if (!config.path().empty()) { | ||
| path = config.path(); | ||
| } | ||
| CreateDB(config); | ||
| } | ||
|
|
||
| ResQL::~ResQL() = default; | ||
|
|
||
| void ResQL::CreateDB(const DuckDBInfo& config) { | ||
| std::string db_path = config.path(); | ||
|
|
||
| duckdb::DBConfig db_config; | ||
|
|
||
| if (config.has_max_memory()) { | ||
| db_config.SetOption("max_memory", duckdb::Value(config.max_memory())); | ||
| } | ||
|
|
||
| LOG(INFO) << "Initializing DuckDB at " | ||
| << (db_path.empty() ? "in-memory" : db_path) | ||
| << " (autoload/autoinstall extensions enabled)"; | ||
|
|
||
| if (db_path.empty()) { | ||
| db_ = std::make_unique<duckdb::DuckDB>(nullptr, &db_config); | ||
| } else { | ||
| db_ = std::make_unique<duckdb::DuckDB>(db_path, &db_config); | ||
| } | ||
|
|
||
| // Ensure extension auto-install/load is enabled at the connection level too. | ||
| try { | ||
| duckdb::Connection init_conn(*db_); | ||
| init_conn.Query("SET autoload_known_extensions=1"); | ||
| init_conn.Query("SET autoinstall_known_extensions=1"); | ||
| } catch (const std::exception& e) { | ||
| LOG(ERROR) << "Failed to set DuckDB extension auto-load/install flags: " | ||
| << e.what(); | ||
| } | ||
| } | ||
|
|
||
| std::string ResQL::ExecuteSQL(const std::string& sql_string){ | ||
| if (sql_string.empty()) { | ||
| return "Error: empty SQL query"; | ||
| } | ||
|
|
||
| if (!db_) { | ||
| LOG(ERROR) << "DuckDB is not initialized"; | ||
| return "Error: database not initialized"; | ||
| } | ||
|
|
||
| try { | ||
| LOG(INFO) << "Executing SQL: " << sql_string; | ||
| conn_ = std::make_unique<duckdb::Connection> (*db_); | ||
| auto result = conn_->Query(sql_string); | ||
|
|
||
| if (!result) { | ||
| LOG(ERROR) << "Query returned nullptr"; | ||
| return "Error: query returned no result"; | ||
| } | ||
|
|
||
| if (result->HasError()) { | ||
| LOG(ERROR) << "SQL Error: " << result->GetError(); | ||
| return "Error: " + result->GetError(); | ||
| } | ||
|
|
||
| std::string response = result->ToString(); | ||
| LOG(INFO) << "SQL succeeded. Rows: " << result->RowCount() | ||
| << " Cols: " << result->ColumnCount(); | ||
| LOG(INFO) << "SQL Result:\n" << response; | ||
| return response; | ||
| } catch (const std::exception& e) { | ||
| LOG(ERROR) << "SQL execution threw: " << e.what(); | ||
| return std::string("Error: ") + e.what(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace storage | ||
| } // namespace resdb | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #pragma once | ||
|
|
||
| #include <map> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
|
|
||
| #include "chain/storage/proto/duckdb_config.pb.h" | ||
|
|
||
| #include "storage.h" | ||
| #include "duckdb.hpp" | ||
|
|
||
| namespace resdb { | ||
| namespace storage { | ||
|
|
||
| class ResQL : public Storage { | ||
| public: | ||
| explicit ResQL(const DuckDBInfo& config); | ||
| ~ResQL() override; | ||
|
|
||
| // Main functionality | ||
| std::string ExecuteSQL(const std::string& sql_string) override; | ||
| void CreateDB(const DuckDBInfo& config); | ||
|
|
||
| // No-op overrides | ||
| int SetValue(const std::string&, const std::string&) override { return 0; } | ||
| std::string GetValue(const std::string&) override { return ""; } | ||
| std::string GetAllValues() override { return ""; } | ||
| std::string GetRange(const std::string&, const std::string&) override { | ||
| return ""; | ||
| } | ||
| int SetValueWithVersion(const std::string&, const std::string&, int) override { | ||
| return 0; | ||
| } | ||
| std::pair<std::string, int> GetValueWithVersion(const std::string&, | ||
| int) override { | ||
| return {"", 0}; | ||
| } | ||
| std::map<std::string, std::pair<std::string, int>> GetAllItems() override { | ||
| return {}; | ||
| } | ||
| std::map<std::string, std::pair<std::string, int>> GetKeyRange( | ||
| const std::string&, const std::string&) override { | ||
| return {}; | ||
| } | ||
| std::vector<std::pair<std::string, int>> GetHistory(const std::string&, int, | ||
| int) override { | ||
| return {}; | ||
| } | ||
| std::vector<std::pair<std::string, int>> GetTopHistory(const std::string&, | ||
| int) override { | ||
| return {}; | ||
| } | ||
| bool Flush() override { return true; } | ||
|
|
||
| private: | ||
| std::unique_ptr<duckdb::DuckDB> db_; | ||
| std::unique_ptr<duckdb::Connection> conn_; | ||
| std::optional<DuckDBInfo> config_; | ||
| }; | ||
|
|
||
|
|
||
| // Factory function | ||
| std::unique_ptr<Storage> NewResQL( | ||
| const std::string& path, | ||
| const DuckDBInfo& config = DuckDBInfo()); | ||
| } // namespace storage | ||
| } // namespace resdb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include "chain/storage/duckdb.h" | ||
| #include "chain/storage/proto/duckdb_config.pb.h" | ||
|
|
||
| #include <iostream> | ||
| #include <iterator> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| int main() { | ||
| using namespace resdb::storage; | ||
|
|
||
| // 1. Create a DuckDBInfo proto for file-backed DB | ||
| DuckDBInfo config; | ||
| config.set_path("/home/aryan/resilientdb-resql/dtest/dtest.db"); | ||
|
|
||
| // 2. Construct ResQL instance | ||
| std::unique_ptr<ResQL> my_db; | ||
| try { | ||
| my_db = std::make_unique<ResQL>(config); | ||
| std::cout << "ResQL (DuckDB) created successfully!" << std::endl; | ||
| } catch (std::exception& e) { | ||
| std::cerr << "Failed to create ResQL: " << e.what() << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| { | ||
| std::string create_sql = | ||
| "CREATE TABLE IF NOT EXISTS users (" | ||
| "id INTEGER, " | ||
| "name TEXT" | ||
| ");"; | ||
|
|
||
| std::string resp = my_db->ExecuteSQL(create_sql); | ||
| std::cout << "CREATE: " << resp << std::endl; | ||
| } | ||
|
|
||
| { | ||
| std::string insert_sql = | ||
| "INSERT INTO users VALUES (1, 'batman');"; | ||
|
|
||
| std::string resp = my_db->ExecuteSQL(insert_sql); | ||
| std::cout << "INSERT: " << resp << std::endl; | ||
| } | ||
|
|
||
| { | ||
| std::string select_sql = "SELECT * FROM users;"; | ||
|
|
||
| std::string resp = my_db->ExecuteSQL(select_sql); | ||
| std::cout << "SELECT: " << resp << std::endl; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| syntax = "proto3"; | ||
|
|
||
| package resdb.storage; | ||
|
|
||
| message DuckDBInfo { | ||
| string path = 1; | ||
| optional bool use_wal = 2; | ||
| optional string max_memory = 3; | ||
| optional uint32 threads = 4; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename is dockdb. Why is this called ResQL?