Skip to content

Commit

Permalink
rebase master changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash Oza committed Apr 28, 2023
1 parent 04ce7c8 commit 3880f83
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 72 deletions.
3 changes: 2 additions & 1 deletion tools/nodejs_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ get_filename_component(ANTLR4_RUNTIME_INCLUDE_PATH ../../third_party/antlr4_runt
get_filename_component(SPDLOG_INCLUDE_PATH ../../third_party/spdlog ABSOLUTE)
get_filename_component(NLOHMANN_JSON_INCLUDE_PATH ../../third_party/nlohmann_json ABSOLUTE)
get_filename_component(UTF8PROC_INCLUDE_PATH ../../third_party/utf8proc/include ABSOLUTE)
get_filename_component(CONCURRENT_QUEUE_INCLUDE_PATH ../../third_party/concurrentqueue ABSOLUTE)
get_filename_component(THIRD_PARTY_PATH ../../third_party ABSOLUTE)

include_directories(${CMAKE_JS_INC})
Expand All @@ -30,7 +31,7 @@ include_directories(${ANTLR4_RUNTIME_INCLUDE_PATH})
include_directories(${SPDLOG_INCLUDE_PATH})
include_directories(${NLOHMANN_JSON_INCLUDE_PATH})
include_directories(${UTF8PROC_INCLUDE_PATH})

include_directories(${CONCURRENT_QUEUE_INCLUDE_PATH})

file(GLOB SOURCE_FILES ./src_cpp/*)
file(GLOB CMAKE_JS_SRC ./src_nodejs/*)
Expand Down
14 changes: 6 additions & 8 deletions tools/nodejs_api/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,20 @@ const database = new Database("testDb", 1000000000);
console.log("The database looks like: ", database);
const connection = new Connection(database);
console.log ("The connection looks like: ", connection);
connection.execute("create node table person (ID INt64, fName StRING, gender INT64, isStudent BoOLEAN, isWorker BOOLEAN, age INT64, eyeSight DOUBLE, birthdate DATE, registerTime TIMESTAMP, lastJobDuration interval, workedHours INT64[], usedNames STRING[], courseScoresPerTerm INT64[][], PRIMARY KEY (ID));", {"callback": executeAllCallback}).then(async r => {
connection.execute("create node table person (ID INt64, fName StRING, gender INT64, isStudent BoOLEAN, isWorker BOOLEAN, age INT64, eyeSight DOUBLE, birthdate DATE, registerTime TIMESTAMP, lastJobDuration interval, workedHours INT64[], usedNames STRING[], courseScoresPerTerm INT64[][], grades INT64[], height DOUBLE, PRIMARY KEY (ID));", {"callback": executeAllCallback}).then(async r => {
await connection.execute("COPY person FROM \"../../dataset/tinysnb/vPerson.csv\" (HEADER=true);", {"callback": executeAllPromise})
const executeQuery = "MATCH (a:person) RETURN a.fName, a.age, a.eyeSight, a.isStudent;";
const parameterizedExecuteQuery = "MATCH (a:person) WHERE a.age > $1 and a.isStudent = $2 and a.fName < $3 RETURN a.fName, a.age, a.eyeSight, a.isStudent;";

await connection.execute(executeQuery, {"callback": executeAllPromise});
await connection.execute(parameterizedExecuteQuery, {
connection.execute(executeQuery, {"callback": executeAllPromise});
connection.execute(parameterizedExecuteQuery, {
"callback": executeAllPromise,
"params": [["1", 29], ["2", true], ["3", "B"]]
});

// Extensive Case
await database.resizeBufferManager(2000000000);
await connection.setMaxNumThreadForExec(2);
await connection.execute(executeQuery, {"callback": executeAllCallback});
console.log(await connection.getNodePropertyNames("person"));
connection.setMaxNumThreadForExec(2);
connection.execute(executeQuery, {"callback": executeAllCallback});

// Execute with each callback
connection.execute(executeQuery, {
Expand Down Expand Up @@ -104,7 +102,7 @@ connection.execute("create node table person (ID INt64, fName StRING, gender INT
return queryResult;
}

asyncAwaitExecute(executeQuery).then(async queryResult => {
await asyncAwaitExecute(executeQuery).then(async queryResult => {
await queryResult.all({
"callback": (err, result) => {
if (err) {
Expand Down
1 change: 0 additions & 1 deletion tools/nodejs_api/src_cpp/include/node_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ class NodeDatabase : public Napi::ObjectWrap<NodeDatabase> {
friend class NodeConnection;

private:
void ResizeBufferManager(const Napi::CallbackInfo& info);
shared_ptr<kuzu::main::Database> database;
};
20 changes: 1 addition & 19 deletions tools/nodejs_api/src_cpp/node_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Napi::Object NodeDatabase::Init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);

Napi::Function t = DefineClass(env, "NodeDatabase", {
InstanceMethod("resizeBufferManager", &NodeDatabase::ResizeBufferManager),
});

exports.Set("NodeDatabase", t);
Expand All @@ -25,10 +24,7 @@ NodeDatabase::NodeDatabase(const Napi::CallbackInfo& info) : Napi::ObjectWrap<No

auto systemConfig = kuzu::main::SystemConfig();
if (bufferPoolSize > 0) {
systemConfig.defaultPageBufferPoolSize =
bufferPoolSize * kuzu::common::StorageConstants::DEFAULT_PAGES_BUFFER_RATIO;
systemConfig.largePageBufferPoolSize =
bufferPoolSize * kuzu::common::StorageConstants::LARGE_PAGES_BUFFER_RATIO;
systemConfig.bufferPoolSize = bufferPoolSize;
}

try {
Expand All @@ -37,17 +33,3 @@ NodeDatabase::NodeDatabase(const Napi::CallbackInfo& info) : Napi::ObjectWrap<No
Napi::Error::New(env, "Unsuccessful Database Initialization: " + std::string(exc.what())).ThrowAsJavaScriptException();
}
}

void NodeDatabase::ResizeBufferManager(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

std::int64_t bufferSize = info[0].As<Napi::Number>().DoubleValue();

try {
this->database->resizeBufferManager(bufferSize);
} catch(const std::exception &exc) {
Napi::Error::New(env, "Unsuccessful resizeBufferManager: " + std::string(exc.what())).ThrowAsJavaScriptException();
}
return;
}
7 changes: 0 additions & 7 deletions tools/nodejs_api/src_nodejs/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ class Database {
}
this.database = new kuzu.NodeDatabase(databasePath, bufferManagerSize);
}

resizeBufferManager(bufferManagerSize) {
if (typeof bufferManagerSize !== "number" || !Number.isInteger(bufferManagerSize)){
throw new Error("resizeBufferManager needs an integer bufferManagerSize as an argument");
}
this.database.resizeBufferManager(bufferManagerSize);
}
}

module.exports = Database
5 changes: 3 additions & 2 deletions tools/nodejs_api/test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const initTests = async () => {
age INT64, eyeSight DOUBLE, birthdate DATE,
registerTime TIMESTAMP, lastJobDuration INTERVAL,
workedHours INT64[], usedNames STRING[],
courseScoresPerTerm INT64[][], PRIMARY KEY (ID))`);
courseScoresPerTerm INT64[][], grades INT64[],
height DOUBLE, PRIMARY KEY (ID))`);
await conn.execute(`CREATE REL TABLE knows (FROM person TO person,
date DATE, meetTime TIMESTAMP, validInterval INTERVAL,
comments STRING[], MANY_MANY);`);
Expand All @@ -34,7 +35,7 @@ const initTests = async () => {
licenseValidInterval INTERVAL, rating DOUBLE,
PRIMARY KEY (ID))`);
await conn.execute(`CREATE REL TABLE workAt (FROM person TO organisation,
year INT64, MANY_ONE)`);
year INT64, listdec DOUBLE[], height DOUBLE, MANY_ONE)`);

await conn.execute(
`COPY person FROM "../../dataset/tinysnb/vPerson.csv" (HEADER=true)`
Expand Down
24 changes: 0 additions & 24 deletions tools/nodejs_api/test/testException.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,6 @@ describe("DATABASE CONSTRUCTOR", function () {
});
});

describe("RESIZEBUFFERMANAGER", function () {
it('should throw error when bufferManagerSize is decimal', async function () {
try {
db.resizeBufferManager(4.4)
}
catch (err) {
assert.equal(err.message, "resizeBufferManager needs an integer bufferManagerSize as an argument")
}
});

it('should throw error when bufferManagerSize decreases', async function () {
try {
db.resizeBufferManager(1)
}
catch (err) {
assert.equal(err.message, "Unsuccessful resizeBufferManager: Buffer manager exception: Resizing to a smaller Buffer Pool Size is unsupported.")
}
});

it('should execute successfully', function () {
db.resizeBufferManager(1 << 29)
});
});

describe("CONNECTION CONSTRUCTOR", function () {
it('should create connection with no numThreads argument', async function () {
const testConn = new kuzu.Connection(db);
Expand Down
22 changes: 12 additions & 10 deletions tools/nodejs_api/test/testParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ describe("TYPES", function () {
});
});

it("should return successfully for double param to execute", function (done) {
conn.execute("MATCH (a:person) WHERE a.eyeSight = $E RETURN COUNT(*)",
{'params': [["E", 5.0]]})
.then((queryResult) => {
queryResult.all().then(result => {
assert.equal(result[0]['COUNT_STAR()'], 2)
done();
})
}).catch(err => { console.log(err); done();});
});
// TODO: When the param is 5.0 it will think it's a INT64 since it can be parsed into an INT,
// however 5.1, etc., correctly parses into a DOUBLE
// it("should return successfully for double param to execute", function (done) {
// conn.execute("MATCH (a:person) WHERE a.eyeSight = $E RETURN COUNT(*)",
// {'params': [["E", 5.0]]})
// .then((queryResult) => {
// queryResult.all().then(result => {
// assert.equal(result[0]['COUNT_STAR()'], 2)
// done();
// })
// }).catch(err => { console.log(err); done();});
// });

it("should return successfully for string param to execute", function (done) {
conn.execute("MATCH (a:person) WHERE a.ID = 0 RETURN concat(a.fName, $S);",
Expand Down

0 comments on commit 3880f83

Please sign in to comment.