duckdb 1.2.0 → 1.2.1-dev4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/connection.cpp +42 -15
package/package.json
CHANGED
package/src/connection.cpp
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
#include "duckdb/parser/parser.hpp"
|
5
5
|
#include "duckdb/parser/parsed_data/drop_info.hpp"
|
6
6
|
#include "duckdb/parser/expression/cast_expression.hpp"
|
7
|
+
#include "duckdb/common/types/value.hpp"
|
8
|
+
#include "duckdb/main/relation/table_function_relation.hpp"
|
9
|
+
|
10
|
+
|
7
11
|
#include <iostream>
|
8
12
|
#include <thread>
|
9
13
|
|
@@ -451,6 +455,27 @@ Napi::Value Connection::Exec(const Napi::CallbackInfo &info) {
|
|
451
455
|
return Value();
|
452
456
|
}
|
453
457
|
|
458
|
+
struct CreateArrowViewTask : public Task {
|
459
|
+
CreateArrowViewTask(Connection &connection, duckdb::vector<duckdb::Value>& parameters, std::string &view_name)
|
460
|
+
: Task(connection), parameters(parameters), view_name(view_name) {
|
461
|
+
}
|
462
|
+
|
463
|
+
void DoWork() override {
|
464
|
+
auto &connection = Get<Connection>();
|
465
|
+
auto &con = *connection.connection;
|
466
|
+
// Now we create a table function relation
|
467
|
+
auto table_function_relation = duckdb::make_shared_ptr<duckdb::TableFunctionRelation>(con.context,"scan_arrow_ipc",parameters);
|
468
|
+
// Creates a relation for a temporary view that does replace
|
469
|
+
auto view_relation = table_function_relation->CreateView(view_name,true,true);
|
470
|
+
|
471
|
+
view_relation->Execute();
|
472
|
+
|
473
|
+
}
|
474
|
+
|
475
|
+
duckdb::vector<duckdb::Value> parameters;
|
476
|
+
std::string view_name;
|
477
|
+
};
|
478
|
+
|
454
479
|
// Register Arrow IPC buffers for scanning from DuckDB
|
455
480
|
Napi::Value Connection::RegisterBuffer(const Napi::CallbackInfo &info) {
|
456
481
|
auto env = info.Env();
|
@@ -475,9 +500,10 @@ Napi::Value Connection::RegisterBuffer(const Napi::CallbackInfo &info) {
|
|
475
500
|
}
|
476
501
|
|
477
502
|
array_references[name] = Napi::Persistent(array);
|
503
|
+
auto &db = *connection->context->db;
|
478
504
|
|
479
|
-
|
480
|
-
|
505
|
+
vector<duckdb::Value> values;
|
506
|
+
|
481
507
|
for (uint64_t ipc_idx = 0; ipc_idx < array.Length(); ipc_idx++) {
|
482
508
|
Napi::Value v = array[ipc_idx];
|
483
509
|
if (!v.IsObject()) {
|
@@ -486,19 +512,20 @@ Napi::Value Connection::RegisterBuffer(const Napi::CallbackInfo &info) {
|
|
486
512
|
Napi::Uint8Array arr = v.As<Napi::Uint8Array>();
|
487
513
|
auto raw_ptr = reinterpret_cast<uint64_t>(arr.ArrayBuffer().Data());
|
488
514
|
auto length = (uint64_t)arr.ElementLength();
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
515
|
+
duckdb::child_list_t<duckdb::Value> buffer_values;
|
516
|
+
// This is a little bit evil, but allows us to support both libraries in between 1.2 and 1.3
|
517
|
+
if (db.ExtensionIsLoaded("nanoarrow")){
|
518
|
+
buffer_values.push_back({"ptr", duckdb::Value::POINTER(raw_ptr)});
|
519
|
+
} else {
|
520
|
+
buffer_values.push_back({"ptr", duckdb::Value::UBIGINT(raw_ptr)});
|
521
|
+
}
|
522
|
+
buffer_values.push_back({"size", duckdb::Value::UBIGINT(length)});
|
523
|
+
values.push_back(duckdb::Value::STRUCT(buffer_values));
|
524
|
+
}
|
525
|
+
duckdb::vector<duckdb::Value> list_value;
|
526
|
+
list_value.push_back(duckdb::Value::LIST(values));
|
527
|
+
|
528
|
+
database_ref->Schedule(info.Env(), duckdb::make_uniq<CreateArrowViewTask>(*this, list_value, name));
|
502
529
|
|
503
530
|
return Value();
|
504
531
|
}
|