duckdb 0.3.3-dev844.0 → 0.3.3-dev891.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/lib/duckdb-binding.js +4 -2
- package/package.json +1 -1
- package/src/duckdb.cpp +177 -15
- package/src/duckdb.hpp +2 -2
- package/src/parquet-amalgamation.cpp +36689 -36691
- package/test/extension.test.js +86 -0
package/lib/duckdb-binding.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var os = require('os');
|
|
1
2
|
var binary = require('@mapbox/node-pre-gyp');
|
|
2
3
|
var path = require('path');
|
|
3
4
|
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
|
|
4
|
-
var binding = require(binding_path);
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// // dlopen is used because we need to specify the RTLD_GLOBAL flag to be able to resolve duckdb symbols
|
|
7
|
+
// on linux where RTLD_LOCAL is the default.
|
|
8
|
+
process.dlopen(module, binding_path, os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL)
|
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -62217,7 +62217,7 @@ namespace duckdb {
|
|
|
62217
62217
|
class PhysicalInsert : public PhysicalOperator {
|
|
62218
62218
|
public:
|
|
62219
62219
|
PhysicalInsert(vector<LogicalType> types, TableCatalogEntry *table, vector<idx_t> column_index_map,
|
|
62220
|
-
vector<unique_ptr<Expression>> bound_defaults, idx_t estimated_cardinality);
|
|
62220
|
+
vector<unique_ptr<Expression>> bound_defaults, idx_t estimated_cardinality, bool return_chunk);
|
|
62221
62221
|
|
|
62222
62222
|
//! The map from insert column index to table column index
|
|
62223
62223
|
vector<idx_t> column_index_map;
|
|
@@ -62225,6 +62225,8 @@ public:
|
|
|
62225
62225
|
TableCatalogEntry *table;
|
|
62226
62226
|
//! The default expressions of the columns for which no value is provided
|
|
62227
62227
|
vector<unique_ptr<Expression>> bound_defaults;
|
|
62228
|
+
//! If the returning statement is present, return the whole chunk
|
|
62229
|
+
bool return_chunk;
|
|
62228
62230
|
|
|
62229
62231
|
public:
|
|
62230
62232
|
// Source interface
|
|
@@ -62266,11 +62268,13 @@ namespace duckdb {
|
|
|
62266
62268
|
//===--------------------------------------------------------------------===//
|
|
62267
62269
|
class InsertGlobalState : public GlobalSinkState {
|
|
62268
62270
|
public:
|
|
62269
|
-
InsertGlobalState() : insert_count(0) {
|
|
62271
|
+
InsertGlobalState() : insert_count(0), returned_chunk_count(0) {
|
|
62270
62272
|
}
|
|
62271
62273
|
|
|
62272
62274
|
mutex lock;
|
|
62273
62275
|
idx_t insert_count;
|
|
62276
|
+
ChunkCollection return_chunk_collection;
|
|
62277
|
+
idx_t returned_chunk_count;
|
|
62274
62278
|
};
|
|
62275
62279
|
|
|
62276
62280
|
class InsertLocalState : public LocalSinkState {
|
|
@@ -62285,9 +62289,11 @@ public:
|
|
|
62285
62289
|
};
|
|
62286
62290
|
|
|
62287
62291
|
PhysicalInsert::PhysicalInsert(vector<LogicalType> types, TableCatalogEntry *table, vector<idx_t> column_index_map,
|
|
62288
|
-
vector<unique_ptr<Expression>> bound_defaults, idx_t estimated_cardinality
|
|
62292
|
+
vector<unique_ptr<Expression>> bound_defaults, idx_t estimated_cardinality,
|
|
62293
|
+
bool return_chunk)
|
|
62289
62294
|
: PhysicalOperator(PhysicalOperatorType::INSERT, move(types), estimated_cardinality),
|
|
62290
|
-
column_index_map(std::move(column_index_map)), table(table), bound_defaults(move(bound_defaults))
|
|
62295
|
+
column_index_map(std::move(column_index_map)), table(table), bound_defaults(move(bound_defaults)),
|
|
62296
|
+
return_chunk(return_chunk) {
|
|
62291
62297
|
}
|
|
62292
62298
|
|
|
62293
62299
|
SinkResultType PhysicalInsert::Sink(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate,
|
|
@@ -62300,6 +62306,7 @@ SinkResultType PhysicalInsert::Sink(ExecutionContext &context, GlobalSinkState &
|
|
|
62300
62306
|
|
|
62301
62307
|
istate.insert_chunk.Reset();
|
|
62302
62308
|
istate.insert_chunk.SetCardinality(chunk);
|
|
62309
|
+
|
|
62303
62310
|
if (!column_index_map.empty()) {
|
|
62304
62311
|
// columns specified by the user, use column_index_map
|
|
62305
62312
|
for (idx_t i = 0; i < table->columns.size(); i++) {
|
|
@@ -62323,6 +62330,11 @@ SinkResultType PhysicalInsert::Sink(ExecutionContext &context, GlobalSinkState &
|
|
|
62323
62330
|
|
|
62324
62331
|
lock_guard<mutex> glock(gstate.lock);
|
|
62325
62332
|
table->storage->Append(*table, context.client, istate.insert_chunk);
|
|
62333
|
+
|
|
62334
|
+
if (return_chunk) {
|
|
62335
|
+
gstate.return_chunk_collection.Append(istate.insert_chunk);
|
|
62336
|
+
}
|
|
62337
|
+
|
|
62326
62338
|
gstate.insert_count += chunk.size();
|
|
62327
62339
|
return SinkResultType::NEED_MORE_INPUT;
|
|
62328
62340
|
}
|
|
@@ -62360,14 +62372,27 @@ unique_ptr<GlobalSourceState> PhysicalInsert::GetGlobalSourceState(ClientContext
|
|
|
62360
62372
|
void PhysicalInsert::GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate,
|
|
62361
62373
|
LocalSourceState &lstate) const {
|
|
62362
62374
|
auto &state = (InsertSourceState &)gstate;
|
|
62363
|
-
auto &
|
|
62375
|
+
auto &insert_gstate = (InsertGlobalState &)*sink_state;
|
|
62364
62376
|
if (state.finished) {
|
|
62365
62377
|
return;
|
|
62366
62378
|
}
|
|
62379
|
+
if (!return_chunk) {
|
|
62380
|
+
chunk.SetCardinality(1);
|
|
62381
|
+
chunk.SetValue(0, 0, Value::BIGINT(insert_gstate.insert_count));
|
|
62382
|
+
state.finished = true;
|
|
62383
|
+
}
|
|
62384
|
+
|
|
62385
|
+
idx_t chunk_return = insert_gstate.returned_chunk_count;
|
|
62386
|
+
if (chunk_return >= insert_gstate.return_chunk_collection.Chunks().size()) {
|
|
62387
|
+
return;
|
|
62388
|
+
}
|
|
62367
62389
|
|
|
62368
|
-
chunk.
|
|
62369
|
-
chunk.
|
|
62370
|
-
|
|
62390
|
+
chunk.Reference(insert_gstate.return_chunk_collection.GetChunk(chunk_return));
|
|
62391
|
+
chunk.SetCardinality((insert_gstate.return_chunk_collection.GetChunk(chunk_return)).size());
|
|
62392
|
+
insert_gstate.returned_chunk_count += 1;
|
|
62393
|
+
if (insert_gstate.returned_chunk_count >= insert_gstate.return_chunk_collection.Chunks().size()) {
|
|
62394
|
+
state.finished = true;
|
|
62395
|
+
}
|
|
62371
62396
|
}
|
|
62372
62397
|
|
|
62373
62398
|
} // namespace duckdb
|
|
@@ -67549,7 +67574,7 @@ namespace duckdb {
|
|
|
67549
67574
|
class LogicalInsert : public LogicalOperator {
|
|
67550
67575
|
public:
|
|
67551
67576
|
explicit LogicalInsert(TableCatalogEntry *table)
|
|
67552
|
-
: LogicalOperator(LogicalOperatorType::LOGICAL_INSERT), table(table) {
|
|
67577
|
+
: LogicalOperator(LogicalOperatorType::LOGICAL_INSERT), table(table), table_index(0), return_chunk(false) {
|
|
67553
67578
|
}
|
|
67554
67579
|
|
|
67555
67580
|
vector<vector<unique_ptr<Expression>>> insert_values;
|
|
@@ -67559,12 +67584,26 @@ public:
|
|
|
67559
67584
|
vector<LogicalType> expected_types;
|
|
67560
67585
|
//! The base table to insert into
|
|
67561
67586
|
TableCatalogEntry *table;
|
|
67587
|
+
idx_t table_index;
|
|
67588
|
+
//! if returning option is used, return actual chunk to projection
|
|
67589
|
+
bool return_chunk;
|
|
67562
67590
|
//! The default statements used by the table
|
|
67563
67591
|
vector<unique_ptr<Expression>> bound_defaults;
|
|
67564
67592
|
|
|
67565
67593
|
protected:
|
|
67594
|
+
vector<ColumnBinding> GetColumnBindings() override {
|
|
67595
|
+
if (return_chunk) {
|
|
67596
|
+
return GenerateColumnBindings(table_index, table->columns.size());
|
|
67597
|
+
}
|
|
67598
|
+
return {ColumnBinding(0, 0)};
|
|
67599
|
+
}
|
|
67600
|
+
|
|
67566
67601
|
void ResolveTypes() override {
|
|
67567
|
-
|
|
67602
|
+
if (return_chunk) {
|
|
67603
|
+
types = table->GetTypes();
|
|
67604
|
+
} else {
|
|
67605
|
+
types.emplace_back(LogicalType::BIGINT);
|
|
67606
|
+
}
|
|
67568
67607
|
}
|
|
67569
67608
|
};
|
|
67570
67609
|
} // namespace duckdb
|
|
@@ -67581,7 +67620,7 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalInsert &op
|
|
|
67581
67620
|
|
|
67582
67621
|
dependencies.insert(op.table);
|
|
67583
67622
|
auto insert = make_unique<PhysicalInsert>(op.types, op.table, op.column_index_map, move(op.bound_defaults),
|
|
67584
|
-
op.estimated_cardinality);
|
|
67623
|
+
op.estimated_cardinality, op.return_chunk);
|
|
67585
67624
|
if (plan) {
|
|
67586
67625
|
insert->children.push_back(move(plan));
|
|
67587
67626
|
}
|
|
@@ -116169,6 +116208,9 @@ public:
|
|
|
116169
116208
|
//! Schema name to insert to
|
|
116170
116209
|
string schema;
|
|
116171
116210
|
|
|
116211
|
+
//! keep track of optional returningList if statement contains a RETURNING keyword
|
|
116212
|
+
vector<unique_ptr<ParsedExpression>> returning_list;
|
|
116213
|
+
|
|
116172
116214
|
protected:
|
|
116173
116215
|
InsertStatement(const InsertStatement &other);
|
|
116174
116216
|
|
|
@@ -124445,6 +124487,15 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) {
|
|
|
124445
124487
|
remove.VisitOperator(*op.children[0]);
|
|
124446
124488
|
return;
|
|
124447
124489
|
}
|
|
124490
|
+
case LogicalOperatorType::LOGICAL_INSERT: {
|
|
124491
|
+
//! When RETURNING is used, a PROJECTION is the top level operator
|
|
124492
|
+
//! We still need to project all values from the insert so the projection
|
|
124493
|
+
//! on top of the INSERT can select from only that table values being inserted
|
|
124494
|
+
RemoveUnusedColumns remove(binder, context, true);
|
|
124495
|
+
remove.VisitOperatorExpressions(op);
|
|
124496
|
+
remove.VisitOperator(*op.children[0]);
|
|
124497
|
+
return;
|
|
124498
|
+
}
|
|
124448
124499
|
case LogicalOperatorType::LOGICAL_GET:
|
|
124449
124500
|
LogicalOperatorVisitor::VisitOperatorExpressions(op);
|
|
124450
124501
|
if (!everything_referenced) {
|
|
@@ -146299,6 +146350,11 @@ unique_ptr<InsertStatement> Transformer::TransformInsert(duckdb_libpgquery::PGNo
|
|
|
146299
146350
|
result->columns.emplace_back(target->name);
|
|
146300
146351
|
}
|
|
146301
146352
|
}
|
|
146353
|
+
|
|
146354
|
+
// Grab and transform the returning columns from the parser.
|
|
146355
|
+
if (stmt->returningList) {
|
|
146356
|
+
Transformer::TransformExpressionList(*(stmt->returningList), result->returning_list);
|
|
146357
|
+
}
|
|
146302
146358
|
result->select_statement = TransformSelect(stmt->selectStmt, false);
|
|
146303
146359
|
|
|
146304
146360
|
auto qname = TransformQualifiedName(stmt->relation);
|
|
@@ -152271,6 +152327,35 @@ protected:
|
|
|
152271
152327
|
|
|
152272
152328
|
|
|
152273
152329
|
|
|
152330
|
+
|
|
152331
|
+
|
|
152332
|
+
//===----------------------------------------------------------------------===//
|
|
152333
|
+
// DuckDB
|
|
152334
|
+
//
|
|
152335
|
+
// duckdb/planner/expression_binder/returning_binder.hpp
|
|
152336
|
+
//
|
|
152337
|
+
//
|
|
152338
|
+
//===----------------------------------------------------------------------===//
|
|
152339
|
+
|
|
152340
|
+
|
|
152341
|
+
|
|
152342
|
+
|
|
152343
|
+
|
|
152344
|
+
namespace duckdb {
|
|
152345
|
+
|
|
152346
|
+
//! The RETURNING binder is responsible for binding expressions within the RETURNING statement
|
|
152347
|
+
class ReturningBinder : public ExpressionBinder {
|
|
152348
|
+
public:
|
|
152349
|
+
ReturningBinder(Binder &binder, ClientContext &context);
|
|
152350
|
+
|
|
152351
|
+
protected:
|
|
152352
|
+
BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
|
|
152353
|
+
bool root_expression = false) override;
|
|
152354
|
+
};
|
|
152355
|
+
|
|
152356
|
+
} // namespace duckdb
|
|
152357
|
+
|
|
152358
|
+
|
|
152274
152359
|
namespace duckdb {
|
|
152275
152360
|
|
|
152276
152361
|
static void CheckInsertColumnCountMismatch(int64_t expected_columns, int64_t result_columns, bool columns_provided,
|
|
@@ -152378,18 +152463,73 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
|
|
|
152378
152463
|
}
|
|
152379
152464
|
}
|
|
152380
152465
|
|
|
152381
|
-
// insert from select statement
|
|
152382
152466
|
// parse select statement and add to logical plan
|
|
152383
152467
|
auto root_select = Bind(*stmt.select_statement);
|
|
152384
152468
|
CheckInsertColumnCountMismatch(expected_columns, root_select.types.size(), !stmt.columns.empty(),
|
|
152385
152469
|
table->name.c_str());
|
|
152386
152470
|
|
|
152387
152471
|
auto root = CastLogicalOperatorToTypes(root_select.types, insert->expected_types, move(root_select.plan));
|
|
152472
|
+
|
|
152388
152473
|
insert->AddChild(move(root));
|
|
152389
152474
|
|
|
152390
|
-
|
|
152391
|
-
|
|
152392
|
-
|
|
152475
|
+
if (!stmt.returning_list.empty()) {
|
|
152476
|
+
insert->return_chunk = true;
|
|
152477
|
+
// clear result type and names because returning list will update them
|
|
152478
|
+
result.types.clear();
|
|
152479
|
+
result.names.clear();
|
|
152480
|
+
|
|
152481
|
+
auto insert_table_index = GenerateTableIndex();
|
|
152482
|
+
insert->table_index = insert_table_index;
|
|
152483
|
+
|
|
152484
|
+
auto binder = Binder::CreateBinder(context);
|
|
152485
|
+
auto types = table->GetTypes();
|
|
152486
|
+
vector<std::string> names;
|
|
152487
|
+
for (auto &col : table->columns) {
|
|
152488
|
+
names.push_back(col.name);
|
|
152489
|
+
}
|
|
152490
|
+
|
|
152491
|
+
binder->bind_context.AddGenericBinding(insert->table_index, stmt.table, names, types);
|
|
152492
|
+
ReturningBinder returning_binder(*binder, context);
|
|
152493
|
+
|
|
152494
|
+
unique_ptr<LogicalOperator> insert_as_logicaloperator = move(insert);
|
|
152495
|
+
|
|
152496
|
+
vector<unique_ptr<Expression>> projection_expressions;
|
|
152497
|
+
LogicalType result_type;
|
|
152498
|
+
for (auto &returning_expr : stmt.returning_list) {
|
|
152499
|
+
auto expr_type = returning_expr->GetExpressionType();
|
|
152500
|
+
if (expr_type == ExpressionType::STAR) {
|
|
152501
|
+
auto generated_star_list = vector<unique_ptr<ParsedExpression>>();
|
|
152502
|
+
binder->bind_context.GenerateAllColumnExpressions((StarExpression &)*returning_expr,
|
|
152503
|
+
generated_star_list);
|
|
152504
|
+
|
|
152505
|
+
for (auto &star_column : generated_star_list) {
|
|
152506
|
+
auto star_expr = returning_binder.Bind(star_column, &result_type);
|
|
152507
|
+
result.types.push_back(result_type);
|
|
152508
|
+
result.names.push_back(star_expr->GetName());
|
|
152509
|
+
projection_expressions.push_back(move(star_expr));
|
|
152510
|
+
}
|
|
152511
|
+
} else {
|
|
152512
|
+
auto expr = returning_binder.Bind(returning_expr, &result_type);
|
|
152513
|
+
result.names.push_back(expr->GetName());
|
|
152514
|
+
result.types.push_back(result_type);
|
|
152515
|
+
projection_expressions.push_back(move(expr));
|
|
152516
|
+
}
|
|
152517
|
+
}
|
|
152518
|
+
|
|
152519
|
+
auto projection = make_unique<LogicalProjection>(GenerateTableIndex(), move(projection_expressions));
|
|
152520
|
+
projection->AddChild(move(insert_as_logicaloperator));
|
|
152521
|
+
result.plan = move(projection);
|
|
152522
|
+
D_ASSERT(result.types.size() == result.names.size());
|
|
152523
|
+
this->allow_stream_result = true;
|
|
152524
|
+
return result;
|
|
152525
|
+
} else {
|
|
152526
|
+
insert->table_index = 0;
|
|
152527
|
+
insert->return_chunk = false;
|
|
152528
|
+
D_ASSERT(result.types.size() == result.names.size());
|
|
152529
|
+
result.plan = move(insert);
|
|
152530
|
+
this->allow_stream_result = false;
|
|
152531
|
+
return result;
|
|
152532
|
+
}
|
|
152393
152533
|
}
|
|
152394
152534
|
|
|
152395
152535
|
} // namespace duckdb
|
|
@@ -156138,6 +156278,28 @@ string RelationBinder::UnsupportedAggregateMessage() {
|
|
|
156138
156278
|
|
|
156139
156279
|
|
|
156140
156280
|
|
|
156281
|
+
namespace duckdb {
|
|
156282
|
+
|
|
156283
|
+
ReturningBinder::ReturningBinder(Binder &binder, ClientContext &context) : ExpressionBinder(binder, context) {
|
|
156284
|
+
}
|
|
156285
|
+
|
|
156286
|
+
BindResult ReturningBinder::BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) {
|
|
156287
|
+
auto &expr = **expr_ptr;
|
|
156288
|
+
switch (expr.GetExpressionClass()) {
|
|
156289
|
+
case ExpressionClass::SUBQUERY:
|
|
156290
|
+
return BindResult("SUBQUERY is not supported in returning statements");
|
|
156291
|
+
case ExpressionClass::BOUND_SUBQUERY:
|
|
156292
|
+
return BindResult("BOUND SUBQUERY is not supported in returning statements");
|
|
156293
|
+
default:
|
|
156294
|
+
return ExpressionBinder::BindExpression(expr_ptr, depth);
|
|
156295
|
+
}
|
|
156296
|
+
}
|
|
156297
|
+
|
|
156298
|
+
} // namespace duckdb
|
|
156299
|
+
|
|
156300
|
+
|
|
156301
|
+
|
|
156302
|
+
|
|
156141
156303
|
|
|
156142
156304
|
|
|
156143
156305
|
|
package/src/duckdb.hpp
CHANGED
|
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
11
11
|
#pragma once
|
|
12
12
|
#define DUCKDB_AMALGAMATION 1
|
|
13
13
|
#define DUCKDB_AMALGAMATION_EXTENDED 1
|
|
14
|
-
#define DUCKDB_SOURCE_ID "
|
|
15
|
-
#define DUCKDB_VERSION "v0.3.3-
|
|
14
|
+
#define DUCKDB_SOURCE_ID "96666e411"
|
|
15
|
+
#define DUCKDB_VERSION "v0.3.3-dev891"
|
|
16
16
|
//===----------------------------------------------------------------------===//
|
|
17
17
|
// DuckDB
|
|
18
18
|
//
|