From 21804671217bbe86e6c6607dd71189cb00a1c66b Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Fri, 16 Feb 2024 22:27:48 +0100 Subject: [PATCH 1/8] Unwrap error on SetOptionByName --- src/database.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/database.cpp b/src/database.cpp index 819ff8fb..a96027f8 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -45,7 +45,8 @@ struct OpenTask : public Task { try { duckdb_config.SetOptionByName(key, duckdb::Value(val)); } catch (std::exception &e) { - throw Napi::TypeError::New(env, "Failed to set configuration option " + key + ": " + e.what()); + duckdb::ErrorData error(e); + throw Napi::TypeError::New(env, "Failed to set configuration option " + key + ": " + error.Message()); } } } From 0c9b3132efe716024d46fbcbf45c3a00ced2cd5e Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Fri, 16 Feb 2024 22:28:56 +0100 Subject: [PATCH 2/8] Handle new fuller range for HUGEINT --- src/statement.cpp | 17 +++++++++++------ test/test_all_types.test.ts | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/statement.cpp b/src/statement.cpp index 01420d71..fb83061b 100644 --- a/src/statement.cpp +++ b/src/statement.cpp @@ -163,13 +163,18 @@ static Napi::Value convert_col_val(Napi::Env &env, duckdb::Value dval, duckdb::L } break; case duckdb::LogicalTypeId::HUGEINT: { auto val = duckdb::HugeIntValue::Get(dval); - auto negative = val.upper < 0; - if (negative) { - duckdb::Hugeint::NegateInPlace(val); // remove signing bit + const uint64_t words_min[] = {0, 1ull<<63}; + if (val == duckdb::NumericLimits::Minimum()) { + value = Napi::BigInt::New(env, true, 2, words_min); + } else { + auto negative = val.upper < 0; + if (negative) { + duckdb::Hugeint::NegateInPlace(val); // remove signing bit + } + D_ASSERT(val.upper >= 0); + const uint64_t words[] = {val.lower, static_cast(val.upper)}; + value = Napi::BigInt::New(env, negative, 2, words); } - D_ASSERT(val.upper >= 0); - const uint64_t words[] = {val.lower, static_cast(val.upper)}; - value = Napi::BigInt::New(env, negative, 2, words); } break; case duckdb::LogicalTypeId::DECIMAL: { value = Napi::Number::New(env, dval.GetValue()); diff --git a/test/test_all_types.test.ts b/test/test_all_types.test.ts index f13a8831..274997f1 100644 --- a/test/test_all_types.test.ts +++ b/test/test_all_types.test.ts @@ -49,7 +49,7 @@ const correct_answer_map: Record = { bigint: [BigInt("-9223372036854775808"), BigInt("9223372036854775807"), null], hugeint: [ - BigInt("-170141183460469231731687303715884105727"), + BigInt("-170141183460469231731687303715884105728"), BigInt("170141183460469231731687303715884105727"), null, ], @@ -74,7 +74,7 @@ const correct_answer_map: Record = { null, ], uuid: [ - "00000000-0000-0000-0000-000000000001", + "00000000-0000-0000-0000-000000000000", "ffffffff-ffff-ffff-ffff-ffffffffffff", null, ], From 9194f0e90e4e6e3aeb02eca72beae6ce096b3f7b Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Fri, 16 Feb 2024 22:29:28 +0100 Subject: [PATCH 3/8] Handle new ranges for time[_tz] --- test/test_all_types.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_all_types.test.ts b/test/test_all_types.test.ts index 274997f1..89618b9b 100644 --- a/test/test_all_types.test.ts +++ b/test/test_all_types.test.ts @@ -60,7 +60,7 @@ const correct_answer_map: Record = { uint: [0, 4294967295, null], ubigint: [BigInt(0), BigInt("18446744073709551615"), null], - time: ["00:00:00", "23:59:59.999999", null], + time: ["00:00:00", "24:00:00", null], float: [-3.4028234663852886e38, 3.4028234663852886e38, null], double: [-1.7976931348623157e308, 1.7976931348623157e308, null], @@ -161,7 +161,7 @@ const correct_answer_map: Record = { map: ["{}", "{key1=🦆🦆🦆🦆🦆🦆, key2=goose}", null], union: ["Frank", "5", null], - time_tz: ["00:00:00-1559", "23:59:59.999999+1559", null], + time_tz: ["00:00:00+15:59:59", "24:00:00-15:59:59", null], interval: [ timedelta({ days: 0, From 161e0d9cd3cce334febdf272e244e817803b2083 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Fri, 16 Feb 2024 22:30:05 +0100 Subject: [PATCH 4/8] Exclude uhugeint from test_all_types --- test/columns.test.ts | 2 +- test/test_all_types.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/columns.test.ts b/test/columns.test.ts index 52bfdb3d..732a69fc 100644 --- a/test/columns.test.ts +++ b/test/columns.test.ts @@ -7,7 +7,7 @@ describe('Column Types', function() { it('should prepare a statement and return the columns and their types', function(done) { // we dont include the large_enum and small_enum since they are huge and test the same code path as the small_enum - var stmt = db.prepare("SELECT * EXCLUDE(medium_enum, large_enum) FROM test_all_types()", function(err: null | Error) { + var stmt = db.prepare("SELECT * EXCLUDE(medium_enum, large_enum, uhugeint) FROM test_all_types()", function(err: null | Error) { if (err) throw err; let cols = stmt.columns(); diff --git a/test/test_all_types.test.ts b/test/test_all_types.test.ts index 89618b9b..f2790eb2 100644 --- a/test/test_all_types.test.ts +++ b/test/test_all_types.test.ts @@ -5,7 +5,7 @@ function get_all_types(): Promise { return new Promise((resolve, reject) => { const conn = new duckdb.Database(":memory:"); conn.all( - "describe select * from test_all_types()", + "describe select * EXCLUDE (uhugeint) from test_all_types()", (error: DuckDbError | null, data: TableData) => { if (error) reject(error); resolve(data.map((row) => row.column_name)); From f5d990f653712b58d6d06cb0a3b9f92916bbd8a0 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Fri, 16 Feb 2024 22:30:33 +0100 Subject: [PATCH 5/8] Add initial handling fro UHUGEINTs --- src/statement.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/statement.cpp b/src/statement.cpp index fb83061b..eb9de676 100644 --- a/src/statement.cpp +++ b/src/statement.cpp @@ -161,6 +161,11 @@ static Napi::Value convert_col_val(Napi::Env &env, duckdb::Value dval, duckdb::L case duckdb::LogicalTypeId::DOUBLE: { value = Napi::Number::New(env, duckdb::DoubleValue::Get(dval)); } break; + case duckdb::LogicalTypeId::UHUGEINT: { + auto val = duckdb::UhugeIntValue::Get(dval); + const uint64_t words[] = {val.lower, val.upper}; + value = Napi::BigInt::New(env, false, 2, words); + } break; case duckdb::LogicalTypeId::HUGEINT: { auto val = duckdb::HugeIntValue::Get(dval); const uint64_t words_min[] = {0, 1ull<<63}; From e4e0166e77e8c21741339e5947360a23daea7ef0 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Fri, 16 Feb 2024 22:32:51 +0100 Subject: [PATCH 6/8] Revert "Exclude uhugeint from test_all_types" This reverts commit 161e0d9cd3cce334febdf272e244e817803b2083. --- test/columns.test.ts | 2 +- test/test_all_types.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/columns.test.ts b/test/columns.test.ts index 732a69fc..52bfdb3d 100644 --- a/test/columns.test.ts +++ b/test/columns.test.ts @@ -7,7 +7,7 @@ describe('Column Types', function() { it('should prepare a statement and return the columns and their types', function(done) { // we dont include the large_enum and small_enum since they are huge and test the same code path as the small_enum - var stmt = db.prepare("SELECT * EXCLUDE(medium_enum, large_enum, uhugeint) FROM test_all_types()", function(err: null | Error) { + var stmt = db.prepare("SELECT * EXCLUDE(medium_enum, large_enum) FROM test_all_types()", function(err: null | Error) { if (err) throw err; let cols = stmt.columns(); diff --git a/test/test_all_types.test.ts b/test/test_all_types.test.ts index f2790eb2..89618b9b 100644 --- a/test/test_all_types.test.ts +++ b/test/test_all_types.test.ts @@ -5,7 +5,7 @@ function get_all_types(): Promise { return new Promise((resolve, reject) => { const conn = new duckdb.Database(":memory:"); conn.all( - "describe select * EXCLUDE (uhugeint) from test_all_types()", + "describe select * from test_all_types()", (error: DuckDbError | null, data: TableData) => { if (error) reject(error); resolve(data.map((row) => row.column_name)); From 2032b226ab434e0fa51eaa77d0ccaf18c851d397 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Fri, 16 Feb 2024 22:37:10 +0100 Subject: [PATCH 7/8] Handle uhugeints as output from test_all_types --- test/columns.test.ts | 3 ++- test/test_all_types.test.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/columns.test.ts b/test/columns.test.ts index 52bfdb3d..3073b3de 100644 --- a/test/columns.test.ts +++ b/test/columns.test.ts @@ -12,7 +12,7 @@ describe('Column Types', function() { let cols = stmt.columns(); - assert.equal(cols.length, 42); + assert.equal(cols.length, 43); var expected = [ { name: 'bool', type: { id: 'BOOLEAN', sql_type: 'BOOLEAN' } }, @@ -21,6 +21,7 @@ describe('Column Types', function() { { name: 'int', type: { id: 'INTEGER', sql_type: 'INTEGER' } }, { name: 'bigint', type: { id: 'BIGINT', sql_type: 'BIGINT' } }, { name: 'hugeint', type: { id: 'HUGEINT', sql_type: 'HUGEINT' } }, + { name: 'uhugeint', type: { id: 'UHUGEINT', sql_type: 'UHUGEINT' } }, { name: 'utinyint', type: { id: 'UTINYINT', sql_type: 'UTINYINT' } }, { name: 'usmallint', type: { id: 'USMALLINT', sql_type: 'USMALLINT' } }, { name: 'uint', type: { id: 'UINTEGER', sql_type: 'UINTEGER' } }, diff --git a/test/test_all_types.test.ts b/test/test_all_types.test.ts index 89618b9b..db0ea5cd 100644 --- a/test/test_all_types.test.ts +++ b/test/test_all_types.test.ts @@ -48,6 +48,11 @@ const correct_answer_map: Record = { int: [-2147483648, 2147483647, null], bigint: [BigInt("-9223372036854775808"), BigInt("9223372036854775807"), null], + uhugeint: [ + BigInt("0"), + BigInt("340282366920938463463374607431768211455"), + null, + ], hugeint: [ BigInt("-170141183460469231731687303715884105728"), BigInt("170141183460469231731687303715884105727"), From 4b585ef0a95bc9ba669f7f03bd1f4c4e1c151c13 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Sat, 17 Feb 2024 00:08:44 +0100 Subject: [PATCH 8/8] Attempt at fixing restartmanager missing libraries on Win --- src/duckdb/src/common/local_file_system.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/duckdb/src/common/local_file_system.cpp b/src/duckdb/src/common/local_file_system.cpp index b1d29251..75ada199 100644 --- a/src/duckdb/src/common/local_file_system.cpp +++ b/src/duckdb/src/common/local_file_system.cpp @@ -50,6 +50,7 @@ extern "C" WINBASEAPI BOOL WINAPI GetPhysicallyInstalledSystemMemory(PULONGLONG) #endif // NOLINT #elif defined(_WIN32) #include +#pragma comment(lib, "rstrtmgr.lib") #endif namespace duckdb {