Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d158693
Readme changes
Nov 10, 2025
f7644f5
Merge pull request #1 from chanchanmano/sudarsan-changes
Burnfireblaze Nov 10, 2025
73660ab
Add DuckDB Bazel dependency
Ashay2001K Nov 22, 2025
f175cba
Modify kv_executor + proto
Ashay2001K Nov 25, 2025
ed4fc8d
added new duckdb files, modified storage headers, added proto for duc…
chanchanmano Nov 29, 2025
6ef61f2
Adds duckDB runtime flag to kv_service
khodetejas Nov 30, 2025
42c2017
Merge pull request #2 from DDS-Project-Team/feature/modify-kv-executor
chanchanmano Dec 1, 2025
d49a33e
Merge pull request #3 from DDS-Project-Team/duckdb_storage_interface_…
Burnfireblaze Dec 1, 2025
05a39f9
KV Fixes and CLI fixes
Dec 1, 2025
e38e987
fixes for kv service build
Dec 1, 2025
53732cb
fixes for kv service build
Dec 1, 2025
823da6f
server config modified
Dec 1, 2025
dbc8ffa
Revert server config
Dec 2, 2025
2e17505
Removes Changes made to kv
khodetejas Dec 2, 2025
227599d
Merge pull request #6 from DDS-Project-Team/feature/fixes-kv-cli-fixes
Burnfireblaze Dec 2, 2025
50ae340
Merge pull request #4 from DDS-Project-Team/feature/service-sql-backe…
Burnfireblaze Dec 2, 2025
5e42200
RESQL Start Service added
Dec 2, 2025
b333bfa
Merge pull request #7 from DDS-Project-Team/feature/resql-start-service
Burnfireblaze Dec 2, 2025
8c4e62f
removed passing of path to rely on default
chanchanmano Dec 2, 2025
5263dc3
Merge pull request #8 from DDS-Project-Team/resql_startup_script
Burnfireblaze Dec 2, 2025
916c332
added a test_sql script that tests the functionalities offered by the…
chanchanmano Dec 2, 2025
1a10083
Merge pull request #9 from DDS-Project-Team/resql_test_script
Burnfireblaze Dec 2, 2025
6487106
Logging enabled
Dec 2, 2025
466520d
Logging enabled 2
Dec 2, 2025
df62631
Logging enabled 3
Dec 2, 2025
3a64ce6
Logging enabled 4
Dec 3, 2025
dadfe7d
Logging enabled 5
Dec 3, 2025
6c605a9
Start Resql service
Dec 3, 2025
8b0b0f8
modified
Dec 3, 2025
bc77c9c
modified
Dec 3, 2025
0bb0c27
Autocomplete flags
Dec 5, 2025
b4f54ba
Flags set automatically
Dec 5, 2025
5066ae8
Merge pull request #10 from DDS-Project-Team/feature/logging-enabled
Burnfireblaze Dec 5, 2025
05b847d
[temp] added creation of folders to start_resql_script to avoid node …
chanchanmano Dec 5, 2025
3431672
Merge pull request #12 from DDS-Project-Team/making_folders_in_script
chanchanmano Dec 5, 2025
a9b6c73
Add DuckDB Bazel dependency
Ashay2001K Nov 22, 2025
7c1ba12
Modify kv_executor + proto
Ashay2001K Nov 25, 2025
ade45b2
added new duckdb files, modified storage headers, added proto for duc…
chanchanmano Nov 29, 2025
057efbb
KV Fixes and CLI fixes
Dec 1, 2025
c7fc425
added a test_sql script that tests the functionalities offered by the…
chanchanmano Dec 2, 2025
edb4814
Start Resql service
Dec 3, 2025
d98f47f
Flags set automatically
Dec 5, 2025
88d1011
Rebased DuckDB Code
Jan 9, 2026
31cf735
Merge branch 'develop' into feature/squash-commits-v4
Burnfireblaze Jan 12, 2026
bee02e3
Merge pull request #13 from DDS-Project-Team/feature/squash-commits-v4
Burnfireblaze Jan 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,6 @@ Then re-run the start script:
## Smart Contract ##
If you want to use smart contracts, please go to:
https://blog.resilientdb.com/2025/02/14/GettingStartedSmartContract.html


# New Change
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ http_archive(
sha256 = "91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9",
strip_prefix = "zlib-1.2.12",
urls = [
"https://zlib.net/fossils/zlib-1.2.12.tar.gz",
"https://downloads.sourceforge.net/project/libpng/zlib/1.2.12/zlib-1.2.12.tar.gz",
"https://zlib.net/fossils/zlib-1.2.12.tar.gz",
"https://storage.googleapis.com/bazel-mirror/zlib.net/zlib-1.2.12.tar.gz",
],
)
Expand All @@ -188,6 +191,19 @@ http_archive(
strip_prefix = "leveldb-1.23",
url = "https://github.com/google/leveldb/archive/refs/tags/1.23.zip",
)
http_archive(
name = "duckdb",
urls = [
# pick one version and stick to it
"https://github.com/duckdb/duckdb/releases/download/v1.4.0/libduckdb-src.zip",
],
# This zip is just flat: duckdb.cpp, duckdb.hpp, duckdb.h at the root.
# So no strip_prefix is needed.
build_file = "//third_party:duckdb.BUILD",
# Optional: you can add sha256 once Bazel prints it for you.
# sha256 = "<FILL_ME_FROM_BAZEL_ERROR>",
)


bind(
name = "snappy",
Expand Down
46 changes: 46 additions & 0 deletions chain/storage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,49 @@ cc_test(
"//platform/statistic:stats",
],
)

cc_library(
name = "duckdb_storage",
srcs = ["duckdb.cpp"],
hdrs = ["duckdb.h"],
deps = [
":storage",
"//chain/storage/proto:duckdb_config_cc_proto",
"//third_party:duckdb",
"//common:glog",
],
)

cc_binary(
name = "duckdb_test",
srcs = ["duckdb_test.cpp"],
deps = [
":duckdb_storage",
"//third_party:duckdb",
"//common:glog",
"//chain/storage/proto:duckdb_config_cc_proto",
],
)

cc_library(
name = "duckdb_storage",
srcs = ["duckdb.cpp"],
hdrs = ["duckdb.h"],
deps = [
":storage",
"//chain/storage/proto:duckdb_config_cc_proto",
"//third_party:duckdb",
"//common:glog",
],
)

cc_binary(
name = "duckdb_test",
srcs = ["duckdb_test.cpp"],
deps = [
":duckdb_storage",
"//third_party:duckdb",
"//common:glog",
"//chain/storage/proto:duckdb_config_cc_proto",
],
)
99 changes: 99 additions & 0 deletions chain/storage/duckdb.cpp
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) {
Copy link
Contributor

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?

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
70 changes: 70 additions & 0 deletions chain/storage/duckdb.h
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
53 changes: 53 additions & 0 deletions chain/storage/duckdb_test.cpp
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;
}
11 changes: 11 additions & 0 deletions chain/storage/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ cc_proto_library(
name = "leveldb_config_cc_proto",
deps = [":leveldb_config_proto"],
)

proto_library(
name = "duckdb_config_proto",
srcs = ["duckdb_config.proto"],
)

cc_proto_library(
name = "duckdb_config_cc_proto",
deps = [":duckdb_config_proto"],
)

29 changes: 29 additions & 0 deletions chain/storage/proto/duckdb_config.proto
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;
}
3 changes: 3 additions & 0 deletions chain/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class Storage {
virtual std::vector<std::pair<std::string, int>> GetTopHistory(
const std::string& key, int number) = 0;

// Default no-op SQL execution for non-SQL backends.
virtual std::string ExecuteSQL(const std::string& sql_string) { return ""; }

virtual bool Flush() { return true; };

virtual uint64_t GetLastCheckpoint() { return 0; }
Expand Down
Loading