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

Patch c str api #1353

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/include/main/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Connection {
* @return the maximum number of threads to use for execution in the current connection.
*/
KUZU_API uint64_t getMaxNumThreadForExec();

/**
* @brief Executes the given query and returns the result.
* @param query The query to execute.
Expand Down Expand Up @@ -126,6 +127,10 @@ class Connection {
*/
KUZU_API std::string getRelPropertyNames(const std::string& relTableName);

// Temporary patching for C-style APIs.
// TODO(Change): move this to C-header once we have C-APIs.
KUZU_API std::unique_ptr<QueryResult> kuzu_query(const char* queryString);

protected:
ConnectionTransactionMode getTransactionMode();
void setTransactionModeNoLock(ConnectionTransactionMode newTransactionMode);
Expand Down
5 changes: 5 additions & 0 deletions src/include/main/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class Database {
*/
KUZU_API void resizeBufferManager(uint64_t newSize);

// Temporary patching for C-style APIs.
// TODO(Change): move this to C-header once we have C-APIs.
KUZU_API explicit Database(const char* databasePath);
KUZU_API Database(const char* databasePath, SystemConfig systemConfig);

private:
// Commits and checkpoints a write transaction or rolls that transaction back. This involves
// either replaying the WAL and either redoing or undoing and in either case at the end WAL is
Expand Down
4 changes: 4 additions & 0 deletions src/main/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ std::string Connection::getRelPropertyNames(const std::string& relTableName) {
return result;
}

std::unique_ptr<QueryResult> Connection::kuzu_query(const char* queryString) {
return query(queryString);
}

std::unique_ptr<QueryResult> Connection::executeWithParams(PreparedStatement* preparedStatement,
std::unordered_map<std::string, std::shared_ptr<Value>>& inputParams) {
lock_t lck{mtx};
Expand Down
6 changes: 6 additions & 0 deletions src/main/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ Database::Database(std::string databasePath, SystemConfig systemConfig)
transactionManager = std::make_unique<transaction::TransactionManager>(*wal);
}

Database::Database(const char* databasePath)
: Database{std::string{databasePath}, SystemConfig()} {}

Database::Database(const char* databasePath, SystemConfig systemConfig)
: Database{std::string{databasePath}, systemConfig} {}

Database::~Database() {
dropLoggers();
}
Expand Down
2 changes: 1 addition & 1 deletion test/include/main_test_helper/main_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace kuzu {
namespace testing {

class ApiTest : public BaseGraphTest {

public:
void SetUp() override {
BaseGraphTest::SetUp();
Expand All @@ -29,5 +28,6 @@ class ApiTest : public BaseGraphTest {
ASSERT_FALSE(result->hasNext());
}
};

} // namespace testing
} // namespace kuzu
1 change: 1 addition & 0 deletions test/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_kuzu_test(main_test
capi_test.cpp
config_test.cpp
connection_test.cpp
csv_output_test.cpp
Expand Down
25 changes: 25 additions & 0 deletions test/main/capi_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "graph_test/graph_test.h"

using namespace kuzu::testing;

class CApiTest : public BaseGraphTest {
public:
void SetUp() override {
BaseGraphTest::SetUp();
const char* dbPath = databasePath.c_str();
database = std::make_unique<Database>(dbPath, *systemConfig);
conn = std::make_unique<Connection>(database.get());
initGraph();
}

std::string getInputDir() override {
return TestHelper::appendKuzuRootPath("dataset/tinysnb/");
}
};

TEST_F(CApiTest, Basic) {
char query[] = "MATCH (a:person) RETURN COUNT(*)";
auto result = conn->kuzu_query(query);
auto groundTruth = std::vector<std::string>{"8"};
ASSERT_EQ(TestHelper::convertResultToString(*result), groundTruth);
}