duckdb 0.3.5-dev116.0 → 0.3.5-dev154.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/duckdb.cpp +649 -132
- package/src/duckdb.hpp +35 -11
- package/src/parquet-amalgamation.cpp +30364 -30364
package/src/duckdb.cpp
CHANGED
|
@@ -6397,7 +6397,7 @@ string JoinTypeToString(JoinType type) {
|
|
|
6397
6397
|
case JoinType::INNER:
|
|
6398
6398
|
return "INNER";
|
|
6399
6399
|
case JoinType::OUTER:
|
|
6400
|
-
return "
|
|
6400
|
+
return "FULL";
|
|
6401
6401
|
case JoinType::SEMI:
|
|
6402
6402
|
return "SEMI";
|
|
6403
6403
|
case JoinType::ANTI:
|
|
@@ -34594,9 +34594,6 @@ bool ChunkCollection::Equals(ChunkCollection &other) {
|
|
|
34594
34594
|
if (ColumnCount() != other.ColumnCount()) {
|
|
34595
34595
|
return false;
|
|
34596
34596
|
}
|
|
34597
|
-
if (types != other.types) {
|
|
34598
|
-
return false;
|
|
34599
|
-
}
|
|
34600
34597
|
// if count is equal amount of chunks should be equal
|
|
34601
34598
|
for (idx_t row_idx = 0; row_idx < count; row_idx++) {
|
|
34602
34599
|
for (idx_t col_idx = 0; col_idx < ColumnCount(); col_idx++) {
|
|
@@ -39769,6 +39766,11 @@ DUCKDB_API interval_t Value::GetValue() const {
|
|
|
39769
39766
|
return GetValueInternal<interval_t>();
|
|
39770
39767
|
}
|
|
39771
39768
|
|
|
39769
|
+
template <>
|
|
39770
|
+
DUCKDB_API Value Value::GetValue() const {
|
|
39771
|
+
return Value(*this);
|
|
39772
|
+
}
|
|
39773
|
+
|
|
39772
39774
|
uintptr_t Value::GetPointer() const {
|
|
39773
39775
|
D_ASSERT(type() == LogicalType::POINTER);
|
|
39774
39776
|
return value_.pointer;
|
|
@@ -40684,6 +40686,9 @@ bool Value::ValuesAreEqual(const Value &result_value, const Value &value) {
|
|
|
40684
40686
|
return left == right;
|
|
40685
40687
|
}
|
|
40686
40688
|
default:
|
|
40689
|
+
if (result_value.type_.id() == LogicalTypeId::FLOAT || result_value.type_.id() == LogicalTypeId::DOUBLE) {
|
|
40690
|
+
return Value::ValuesAreEqual(value, result_value);
|
|
40691
|
+
}
|
|
40687
40692
|
return value == result_value;
|
|
40688
40693
|
}
|
|
40689
40694
|
}
|
|
@@ -101200,6 +101205,9 @@ static unique_ptr<FunctionData> DuckDBFunctionsBind(ClientContext &context, Tabl
|
|
|
101200
101205
|
names.emplace_back("macro_definition");
|
|
101201
101206
|
return_types.emplace_back(LogicalType::VARCHAR);
|
|
101202
101207
|
|
|
101208
|
+
names.emplace_back("has_side_effects");
|
|
101209
|
+
return_types.emplace_back(LogicalType::BOOLEAN);
|
|
101210
|
+
|
|
101203
101211
|
return nullptr;
|
|
101204
101212
|
}
|
|
101205
101213
|
|
|
@@ -101272,6 +101280,10 @@ struct ScalarFunctionExtractor {
|
|
|
101272
101280
|
static Value GetMacroDefinition(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
101273
101281
|
return Value();
|
|
101274
101282
|
}
|
|
101283
|
+
|
|
101284
|
+
static Value HasSideEffects(ScalarFunctionCatalogEntry &entry, idx_t offset) {
|
|
101285
|
+
return Value::BOOLEAN(entry.functions[offset].has_side_effects);
|
|
101286
|
+
}
|
|
101275
101287
|
};
|
|
101276
101288
|
|
|
101277
101289
|
struct AggregateFunctionExtractor {
|
|
@@ -101316,6 +101328,10 @@ struct AggregateFunctionExtractor {
|
|
|
101316
101328
|
static Value GetMacroDefinition(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
101317
101329
|
return Value();
|
|
101318
101330
|
}
|
|
101331
|
+
|
|
101332
|
+
static Value HasSideEffects(AggregateFunctionCatalogEntry &entry, idx_t offset) {
|
|
101333
|
+
return Value::BOOLEAN(entry.functions[offset].has_side_effects);
|
|
101334
|
+
}
|
|
101319
101335
|
};
|
|
101320
101336
|
|
|
101321
101337
|
struct MacroExtractor {
|
|
@@ -101364,10 +101380,12 @@ struct MacroExtractor {
|
|
|
101364
101380
|
}
|
|
101365
101381
|
|
|
101366
101382
|
static Value GetMacroDefinition(ScalarMacroCatalogEntry &entry, idx_t offset) {
|
|
101367
|
-
|
|
101368
|
-
|
|
101369
|
-
|
|
101370
|
-
|
|
101383
|
+
D_ASSERT(entry.function->type == MacroType::SCALAR_MACRO);
|
|
101384
|
+
auto &func = (ScalarMacroFunction &)*entry.function;
|
|
101385
|
+
return func.expression->ToString();
|
|
101386
|
+
}
|
|
101387
|
+
|
|
101388
|
+
static Value HasSideEffects(ScalarMacroCatalogEntry &entry, idx_t offset) {
|
|
101371
101389
|
return Value();
|
|
101372
101390
|
}
|
|
101373
101391
|
};
|
|
@@ -101424,6 +101442,10 @@ struct TableMacroExtractor {
|
|
|
101424
101442
|
}
|
|
101425
101443
|
return Value();
|
|
101426
101444
|
}
|
|
101445
|
+
|
|
101446
|
+
static Value HasSideEffects(TableMacroCatalogEntry &entry, idx_t offset) {
|
|
101447
|
+
return Value();
|
|
101448
|
+
}
|
|
101427
101449
|
};
|
|
101428
101450
|
|
|
101429
101451
|
struct TableFunctionExtractor {
|
|
@@ -101474,6 +101496,10 @@ struct TableFunctionExtractor {
|
|
|
101474
101496
|
static Value GetMacroDefinition(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
101475
101497
|
return Value();
|
|
101476
101498
|
}
|
|
101499
|
+
|
|
101500
|
+
static Value HasSideEffects(TableFunctionCatalogEntry &entry, idx_t offset) {
|
|
101501
|
+
return Value();
|
|
101502
|
+
}
|
|
101477
101503
|
};
|
|
101478
101504
|
|
|
101479
101505
|
struct PragmaFunctionExtractor {
|
|
@@ -101524,6 +101550,10 @@ struct PragmaFunctionExtractor {
|
|
|
101524
101550
|
static Value GetMacroDefinition(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
101525
101551
|
return Value();
|
|
101526
101552
|
}
|
|
101553
|
+
|
|
101554
|
+
static Value HasSideEffects(PragmaFunctionCatalogEntry &entry, idx_t offset) {
|
|
101555
|
+
return Value();
|
|
101556
|
+
}
|
|
101527
101557
|
};
|
|
101528
101558
|
|
|
101529
101559
|
template <class T, class OP>
|
|
@@ -101556,6 +101586,9 @@ bool ExtractFunctionData(StandardEntry *entry, idx_t function_idx, DataChunk &ou
|
|
|
101556
101586
|
// macro_definition, LogicalType::VARCHAR
|
|
101557
101587
|
output.SetValue(8, output_offset, OP::GetMacroDefinition(function, function_idx));
|
|
101558
101588
|
|
|
101589
|
+
// has_side_effects, LogicalType::BOOLEAN
|
|
101590
|
+
output.SetValue(9, output_offset, OP::HasSideEffects(function, function_idx));
|
|
101591
|
+
|
|
101559
101592
|
return function_idx + 1 == OP::FunctionCount(function);
|
|
101560
101593
|
}
|
|
101561
101594
|
|
|
@@ -103478,6 +103511,9 @@ public:
|
|
|
103478
103511
|
}
|
|
103479
103512
|
|
|
103480
103513
|
public:
|
|
103514
|
+
//! Convert the query node to a string
|
|
103515
|
+
string ToString() const override;
|
|
103516
|
+
|
|
103481
103517
|
bool Equals(const QueryNode *other) const override;
|
|
103482
103518
|
//! Create a copy of this SelectNode
|
|
103483
103519
|
unique_ptr<QueryNode> Copy() const override;
|
|
@@ -108079,7 +108115,8 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
|
|
|
108079
108115
|
// create a copy of the statement, and use the copy
|
|
108080
108116
|
// this way we verify that the copy correctly copies all properties
|
|
108081
108117
|
auto copied_statement = statement->Copy();
|
|
108082
|
-
|
|
108118
|
+
switch (statement->type) {
|
|
108119
|
+
case StatementType::SELECT_STATEMENT: {
|
|
108083
108120
|
// in case this is a select query, we verify the original statement
|
|
108084
108121
|
string error;
|
|
108085
108122
|
try {
|
|
@@ -108091,8 +108128,22 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
|
|
|
108091
108128
|
// error in verifying query
|
|
108092
108129
|
return make_unique<PendingQueryResult>(error);
|
|
108093
108130
|
}
|
|
108131
|
+
statement = move(copied_statement);
|
|
108132
|
+
break;
|
|
108133
|
+
}
|
|
108134
|
+
case StatementType::INSERT_STATEMENT:
|
|
108135
|
+
case StatementType::DELETE_STATEMENT:
|
|
108136
|
+
case StatementType::UPDATE_STATEMENT: {
|
|
108137
|
+
auto sql = statement->ToString();
|
|
108138
|
+
Parser parser;
|
|
108139
|
+
parser.ParseQuery(sql);
|
|
108140
|
+
statement = move(parser.statements[0]);
|
|
108141
|
+
break;
|
|
108142
|
+
}
|
|
108143
|
+
default:
|
|
108144
|
+
statement = move(copied_statement);
|
|
108145
|
+
break;
|
|
108094
108146
|
}
|
|
108095
|
-
statement = move(copied_statement);
|
|
108096
108147
|
}
|
|
108097
108148
|
return PendingStatementOrPreparedStatement(lock, query, move(statement), prepared, values);
|
|
108098
108149
|
}
|
|
@@ -108272,6 +108323,18 @@ void ClientContext::DisableProfiling() {
|
|
|
108272
108323
|
config.enable_profiler = false;
|
|
108273
108324
|
}
|
|
108274
108325
|
|
|
108326
|
+
struct VerifyStatement {
|
|
108327
|
+
VerifyStatement(unique_ptr<SelectStatement> statement_p, string statement_name_p, bool require_equality = true)
|
|
108328
|
+
: statement(move(statement_p)), statement_name(move(statement_name_p)), require_equality(require_equality),
|
|
108329
|
+
select_list(statement->node->GetSelectList()) {
|
|
108330
|
+
}
|
|
108331
|
+
|
|
108332
|
+
unique_ptr<SelectStatement> statement;
|
|
108333
|
+
string statement_name;
|
|
108334
|
+
bool require_equality;
|
|
108335
|
+
const vector<unique_ptr<ParsedExpression>> &select_list;
|
|
108336
|
+
};
|
|
108337
|
+
|
|
108275
108338
|
string ClientContext::VerifyQuery(ClientContextLock &lock, const string &query, unique_ptr<SQLStatement> statement) {
|
|
108276
108339
|
D_ASSERT(statement->type == StatementType::SELECT_STATEMENT);
|
|
108277
108340
|
// aggressive query verification
|
|
@@ -108281,8 +108344,10 @@ string ClientContext::VerifyQuery(ClientContextLock &lock, const string &query,
|
|
|
108281
108344
|
// Serialize()/Deserialize() of expressions
|
|
108282
108345
|
// Hash() of expressions
|
|
108283
108346
|
// Equality() of statements and expressions
|
|
108347
|
+
// ToString() of statements and expressions
|
|
108284
108348
|
// Correctness of plans both with and without optimizers
|
|
108285
|
-
|
|
108349
|
+
|
|
108350
|
+
vector<VerifyStatement> verify_statements;
|
|
108286
108351
|
|
|
108287
108352
|
// copy the statement
|
|
108288
108353
|
auto select_stmt = (SelectStatement *)statement.get();
|
|
@@ -108293,42 +108358,60 @@ string ClientContext::VerifyQuery(ClientContextLock &lock, const string &query,
|
|
|
108293
108358
|
select_stmt->Serialize(serializer);
|
|
108294
108359
|
BufferedDeserializer source(serializer);
|
|
108295
108360
|
auto deserialized_stmt = SelectStatement::Deserialize(source);
|
|
108361
|
+
|
|
108362
|
+
Parser parser;
|
|
108363
|
+
parser.ParseQuery(select_stmt->ToString());
|
|
108364
|
+
D_ASSERT(parser.statements.size() == 1);
|
|
108365
|
+
D_ASSERT(parser.statements[0]->type == StatementType::SELECT_STATEMENT);
|
|
108366
|
+
auto parsed_statement = move(parser.statements[0]);
|
|
108367
|
+
|
|
108368
|
+
verify_statements.emplace_back(unique_ptr_cast<SQLStatement, SelectStatement>(move(statement)),
|
|
108369
|
+
"Original statement");
|
|
108370
|
+
verify_statements.emplace_back(move(copied_stmt), "Copied statement");
|
|
108371
|
+
verify_statements.emplace_back(move(deserialized_stmt), "Deserialized statement");
|
|
108372
|
+
verify_statements.emplace_back(unique_ptr_cast<SQLStatement, SelectStatement>(move(parsed_statement)),
|
|
108373
|
+
"Parsed statement", false);
|
|
108374
|
+
|
|
108296
108375
|
// all the statements should be equal
|
|
108297
|
-
|
|
108298
|
-
|
|
108299
|
-
|
|
108376
|
+
for (idx_t i = 1; i < verify_statements.size(); i++) {
|
|
108377
|
+
if (!verify_statements[i].require_equality) {
|
|
108378
|
+
continue;
|
|
108379
|
+
}
|
|
108380
|
+
D_ASSERT(verify_statements[i].statement->Equals(verify_statements[0].statement.get()));
|
|
108381
|
+
}
|
|
108300
108382
|
|
|
108301
108383
|
// now perform checking on the expressions
|
|
108302
108384
|
#ifdef DEBUG
|
|
108303
|
-
|
|
108304
|
-
|
|
108305
|
-
|
|
108306
|
-
|
|
108307
|
-
|
|
108385
|
+
for (idx_t i = 1; i < verify_statements.size(); i++) {
|
|
108386
|
+
D_ASSERT(verify_statements[i].select_list.size() == verify_statements[0].select_list.size());
|
|
108387
|
+
}
|
|
108388
|
+
auto expr_count = verify_statements[0].select_list.size();
|
|
108389
|
+
auto &orig_expr_list = verify_statements[0].select_list;
|
|
108390
|
+
for (idx_t i = 0; i < expr_count; i++) {
|
|
108308
108391
|
// run the ToString, to verify that it doesn't crash
|
|
108309
108392
|
auto str = orig_expr_list[i]->ToString();
|
|
108310
|
-
|
|
108311
|
-
|
|
108312
|
-
|
|
108313
|
-
|
|
108314
|
-
|
|
108315
|
-
|
|
108316
|
-
|
|
108393
|
+
for (idx_t v_idx = 0; v_idx < verify_statements.size(); v_idx++) {
|
|
108394
|
+
if (!verify_statements[v_idx].require_equality && orig_expr_list[i]->HasSubquery()) {
|
|
108395
|
+
continue;
|
|
108396
|
+
}
|
|
108397
|
+
// check that the expressions are equivalent
|
|
108398
|
+
D_ASSERT(orig_expr_list[i]->Equals(verify_statements[v_idx].select_list[i].get()));
|
|
108399
|
+
// check that the hashes are equivalent too
|
|
108400
|
+
D_ASSERT(orig_expr_list[i]->Hash() == verify_statements[v_idx].select_list[i]->Hash());
|
|
108317
108401
|
|
|
108402
|
+
verify_statements[v_idx].select_list[i]->Verify();
|
|
108403
|
+
}
|
|
108318
108404
|
D_ASSERT(!orig_expr_list[i]->Equals(nullptr));
|
|
108319
|
-
orig_expr_list[i]->Verify();
|
|
108320
|
-
de_expr_list[i]->Verify();
|
|
108321
|
-
cp_expr_list[i]->Verify();
|
|
108322
108405
|
|
|
108323
|
-
// ToString round trip
|
|
108324
108406
|
if (orig_expr_list[i]->HasSubquery()) {
|
|
108325
108407
|
continue;
|
|
108326
108408
|
}
|
|
108409
|
+
// ToString round trip
|
|
108327
108410
|
auto parsed_list = Parser::ParseExpressionList(str);
|
|
108328
108411
|
D_ASSERT(parsed_list.size() == 1);
|
|
108329
108412
|
D_ASSERT(parsed_list[0]->Equals(orig_expr_list[i].get()));
|
|
108330
108413
|
}
|
|
108331
|
-
//
|
|
108414
|
+
// perform additional checking within the expressions
|
|
108332
108415
|
for (idx_t outer_idx = 0; outer_idx < orig_expr_list.size(); outer_idx++) {
|
|
108333
108416
|
auto hash = orig_expr_list[outer_idx]->Hash();
|
|
108334
108417
|
for (idx_t inner_idx = 0; inner_idx < orig_expr_list.size(); inner_idx++) {
|
|
@@ -108351,27 +108434,20 @@ string ClientContext::VerifyQuery(ClientContextLock &lock, const string &query,
|
|
|
108351
108434
|
// see below
|
|
108352
108435
|
auto statement_copy_for_explain = select_stmt->Copy();
|
|
108353
108436
|
|
|
108354
|
-
unique_ptr<MaterializedQueryResult> original_result =
|
|
108355
|
-
make_unique<MaterializedQueryResult>(StatementType::SELECT_STATEMENT),
|
|
108356
|
-
copied_result =
|
|
108357
|
-
make_unique<MaterializedQueryResult>(StatementType::SELECT_STATEMENT),
|
|
108358
|
-
deserialized_result =
|
|
108359
|
-
make_unique<MaterializedQueryResult>(StatementType::SELECT_STATEMENT),
|
|
108360
|
-
unoptimized_result =
|
|
108361
|
-
make_unique<MaterializedQueryResult>(StatementType::SELECT_STATEMENT);
|
|
108362
|
-
|
|
108363
108437
|
// execute the original statement
|
|
108364
|
-
|
|
108365
|
-
|
|
108366
|
-
|
|
108367
|
-
|
|
108368
|
-
|
|
108369
|
-
|
|
108438
|
+
vector<unique_ptr<MaterializedQueryResult>> results;
|
|
108439
|
+
for (idx_t i = 0; i < verify_statements.size(); i++) {
|
|
108440
|
+
interrupted = false;
|
|
108441
|
+
try {
|
|
108442
|
+
auto result = RunStatementInternal(lock, query, move(verify_statements[i].statement), false, false);
|
|
108443
|
+
results.push_back(unique_ptr_cast<QueryResult, MaterializedQueryResult>(move(result)));
|
|
108444
|
+
} catch (std::exception &ex) {
|
|
108445
|
+
results.push_back(make_unique<MaterializedQueryResult>(ex.what()));
|
|
108446
|
+
}
|
|
108370
108447
|
}
|
|
108371
|
-
interrupted = false;
|
|
108372
108448
|
|
|
108373
108449
|
// check explain, only if q does not already contain EXPLAIN
|
|
108374
|
-
if (
|
|
108450
|
+
if (results[0]->success) {
|
|
108375
108451
|
auto explain_q = "EXPLAIN " + query;
|
|
108376
108452
|
auto explain_stmt = make_unique<ExplainStatement>(move(statement_copy_for_explain));
|
|
108377
108453
|
try {
|
|
@@ -108381,34 +108457,6 @@ string ClientContext::VerifyQuery(ClientContextLock &lock, const string &query,
|
|
|
108381
108457
|
} // LCOV_EXCL_STOP
|
|
108382
108458
|
}
|
|
108383
108459
|
|
|
108384
|
-
// now execute the copied statement
|
|
108385
|
-
try {
|
|
108386
|
-
auto result = RunStatementInternal(lock, query, move(copied_stmt), false, false);
|
|
108387
|
-
copied_result = unique_ptr_cast<QueryResult, MaterializedQueryResult>(move(result));
|
|
108388
|
-
} catch (std::exception &ex) {
|
|
108389
|
-
copied_result->error = ex.what();
|
|
108390
|
-
copied_result->success = false;
|
|
108391
|
-
}
|
|
108392
|
-
interrupted = false;
|
|
108393
|
-
// now execute the deserialized statement
|
|
108394
|
-
try {
|
|
108395
|
-
auto result = RunStatementInternal(lock, query, move(deserialized_stmt), false, false);
|
|
108396
|
-
deserialized_result = unique_ptr_cast<QueryResult, MaterializedQueryResult>(move(result));
|
|
108397
|
-
} catch (std::exception &ex) {
|
|
108398
|
-
deserialized_result->error = ex.what();
|
|
108399
|
-
deserialized_result->success = false;
|
|
108400
|
-
}
|
|
108401
|
-
interrupted = false;
|
|
108402
|
-
// now execute the unoptimized statement
|
|
108403
|
-
config.enable_optimizer = false;
|
|
108404
|
-
try {
|
|
108405
|
-
auto result = RunStatementInternal(lock, query, move(unoptimized_stmt), false, false);
|
|
108406
|
-
unoptimized_result = unique_ptr_cast<QueryResult, MaterializedQueryResult>(move(result));
|
|
108407
|
-
} catch (std::exception &ex) {
|
|
108408
|
-
unoptimized_result->error = ex.what();
|
|
108409
|
-
unoptimized_result->success = false;
|
|
108410
|
-
}
|
|
108411
|
-
interrupted = false;
|
|
108412
108460
|
config.enable_optimizer = true;
|
|
108413
108461
|
|
|
108414
108462
|
if (profiling_is_enabled) {
|
|
@@ -108417,22 +108465,18 @@ string ClientContext::VerifyQuery(ClientContextLock &lock, const string &query,
|
|
|
108417
108465
|
|
|
108418
108466
|
// now compare the results
|
|
108419
108467
|
// the results of all runs should be identical
|
|
108420
|
-
|
|
108421
|
-
|
|
108422
|
-
|
|
108423
|
-
|
|
108424
|
-
|
|
108425
|
-
|
|
108426
|
-
if (original_result->success != results[i]->success) { // LCOV_EXCL_START
|
|
108427
|
-
string result = names[i] + " differs from original result!\n";
|
|
108428
|
-
result += "Original Result:\n" + original_result->ToString();
|
|
108429
|
-
result += names[i] + ":\n" + results[i]->ToString();
|
|
108468
|
+
for (idx_t i = 1; i < results.size(); i++) {
|
|
108469
|
+
auto name = verify_statements[i].statement_name;
|
|
108470
|
+
if (results[0]->success != results[i]->success) { // LCOV_EXCL_START
|
|
108471
|
+
string result = name + " differs from original result!\n";
|
|
108472
|
+
result += "Original Result:\n" + results[0]->ToString();
|
|
108473
|
+
result += name + ":\n" + results[i]->ToString();
|
|
108430
108474
|
return result;
|
|
108431
|
-
}
|
|
108432
|
-
if (!
|
|
108433
|
-
string result =
|
|
108434
|
-
result += "Original Result:\n" +
|
|
108435
|
-
result +=
|
|
108475
|
+
} // LCOV_EXCL_STOP
|
|
108476
|
+
if (!results[0]->collection.Equals(results[i]->collection)) { // LCOV_EXCL_START
|
|
108477
|
+
string result = name + " differs from original result!\n";
|
|
108478
|
+
result += "Original Result:\n" + results[0]->ToString();
|
|
108479
|
+
result += name + ":\n" + results[i]->ToString();
|
|
108436
108480
|
return result;
|
|
108437
108481
|
} // LCOV_EXCL_STOP
|
|
108438
108482
|
}
|
|
@@ -109930,11 +109974,15 @@ void DuckDB::SetExtensionLoaded(const std::string &name) {
|
|
|
109930
109974
|
#include "excel-extension.hpp"
|
|
109931
109975
|
#endif
|
|
109932
109976
|
|
|
109977
|
+
#if defined(BUILD_SQLSMITH_EXTENSION) && !defined(DISABLE_BUILTIN_EXTENSIONS)
|
|
109978
|
+
#include "sqlsmith-extension.hpp"
|
|
109979
|
+
#endif
|
|
109980
|
+
|
|
109933
109981
|
namespace duckdb {
|
|
109934
109982
|
|
|
109935
109983
|
void ExtensionHelper::LoadAllExtensions(DuckDB &db) {
|
|
109936
|
-
unordered_set<string> extensions {"parquet",
|
|
109937
|
-
"
|
|
109984
|
+
unordered_set<string> extensions {"parquet", "icu", "tpch", "tpcds", "fts", "httpfs",
|
|
109985
|
+
"substrait", "visualizer", "json", "excel", "sqlsmith"};
|
|
109938
109986
|
for (auto &ext : extensions) {
|
|
109939
109987
|
LoadExtensionInternal(db, ext, true);
|
|
109940
109988
|
}
|
|
@@ -110034,6 +110082,13 @@ ExtensionLoadResult ExtensionHelper::LoadExtensionInternal(DuckDB &db, const std
|
|
|
110034
110082
|
#else
|
|
110035
110083
|
// excel extension required but not build: skip this test
|
|
110036
110084
|
return ExtensionLoadResult::NOT_LOADED;
|
|
110085
|
+
#endif
|
|
110086
|
+
} else if (extension == "sqlsmith") {
|
|
110087
|
+
#if defined(BUILD_SQLSMITH_EXTENSION) && !defined(DISABLE_BUILTIN_EXTENSIONS)
|
|
110088
|
+
db.LoadExtension<SQLSmithExtension>();
|
|
110089
|
+
#else
|
|
110090
|
+
// excel extension required but not build: skip this test
|
|
110091
|
+
return ExtensionLoadResult::NOT_LOADED;
|
|
110037
110092
|
#endif
|
|
110038
110093
|
} else {
|
|
110039
110094
|
// unknown extension
|
|
@@ -120211,6 +120266,7 @@ protected:
|
|
|
120211
120266
|
DeleteStatement(const DeleteStatement &other);
|
|
120212
120267
|
|
|
120213
120268
|
public:
|
|
120269
|
+
string ToString() const override;
|
|
120214
120270
|
unique_ptr<SQLStatement> Copy() const override;
|
|
120215
120271
|
};
|
|
120216
120272
|
|
|
@@ -120477,6 +120533,9 @@ public:
|
|
|
120477
120533
|
}
|
|
120478
120534
|
|
|
120479
120535
|
public:
|
|
120536
|
+
//! Convert the query node to a string
|
|
120537
|
+
string ToString() const override;
|
|
120538
|
+
|
|
120480
120539
|
bool Equals(const QueryNode *other) const override;
|
|
120481
120540
|
//! Create a copy of this SelectNode
|
|
120482
120541
|
unique_ptr<QueryNode> Copy() const override;
|
|
@@ -120588,6 +120647,7 @@ public:
|
|
|
120588
120647
|
|
|
120589
120648
|
|
|
120590
120649
|
namespace duckdb {
|
|
120650
|
+
class ExpressionListRef;
|
|
120591
120651
|
|
|
120592
120652
|
class InsertStatement : public SQLStatement {
|
|
120593
120653
|
public:
|
|
@@ -120610,7 +120670,12 @@ protected:
|
|
|
120610
120670
|
InsertStatement(const InsertStatement &other);
|
|
120611
120671
|
|
|
120612
120672
|
public:
|
|
120673
|
+
string ToString() const override;
|
|
120613
120674
|
unique_ptr<SQLStatement> Copy() const override;
|
|
120675
|
+
|
|
120676
|
+
//! If the INSERT statement is inserted DIRECTLY from a values list (i.e. INSERT INTO tbl VALUES (...)) this returns
|
|
120677
|
+
//! the expression list Otherwise, this returns NULL
|
|
120678
|
+
ExpressionListRef *GetValuesList() const;
|
|
120614
120679
|
};
|
|
120615
120680
|
|
|
120616
120681
|
} // namespace duckdb
|
|
@@ -121525,6 +121590,7 @@ protected:
|
|
|
121525
121590
|
UpdateStatement(const UpdateStatement &other);
|
|
121526
121591
|
|
|
121527
121592
|
public:
|
|
121593
|
+
string ToString() const override;
|
|
121528
121594
|
unique_ptr<SQLStatement> Copy() const override;
|
|
121529
121595
|
};
|
|
121530
121596
|
|
|
@@ -138425,7 +138491,7 @@ FunctionExpression::FunctionExpression(const string &function_name, vector<uniqu
|
|
|
138425
138491
|
|
|
138426
138492
|
string FunctionExpression::ToString() const {
|
|
138427
138493
|
return ToString<FunctionExpression, ParsedExpression>(*this, schema, function_name, is_operator, distinct,
|
|
138428
|
-
filter.get(), order_bys.get(), export_state);
|
|
138494
|
+
filter.get(), order_bys.get(), export_state, true);
|
|
138429
138495
|
}
|
|
138430
138496
|
|
|
138431
138497
|
bool FunctionExpression::Equals(const FunctionExpression *a, const FunctionExpression *b) {
|
|
@@ -138818,7 +138884,19 @@ SubqueryExpression::SubqueryExpression()
|
|
|
138818
138884
|
}
|
|
138819
138885
|
|
|
138820
138886
|
string SubqueryExpression::ToString() const {
|
|
138821
|
-
|
|
138887
|
+
switch (subquery_type) {
|
|
138888
|
+
case SubqueryType::ANY:
|
|
138889
|
+
return child->ToString() + " " + ExpressionTypeToOperator(comparison_type) + " ANY(" + subquery->ToString() +
|
|
138890
|
+
")";
|
|
138891
|
+
case SubqueryType::EXISTS:
|
|
138892
|
+
return "EXISTS(" + subquery->ToString() + ")";
|
|
138893
|
+
case SubqueryType::NOT_EXISTS:
|
|
138894
|
+
return "NOT EXISTS(" + subquery->ToString() + ")";
|
|
138895
|
+
case SubqueryType::SCALAR:
|
|
138896
|
+
return "(" + subquery->ToString() + ")";
|
|
138897
|
+
default:
|
|
138898
|
+
throw InternalException("Unrecognized type for subquery");
|
|
138899
|
+
}
|
|
138822
138900
|
}
|
|
138823
138901
|
|
|
138824
138902
|
bool SubqueryExpression::Equals(const SubqueryExpression *a, const SubqueryExpression *b) {
|
|
@@ -139122,11 +139200,11 @@ bool KeywordHelper::RequiresQuotes(const string &text) {
|
|
|
139122
139200
|
return IsKeyword(text);
|
|
139123
139201
|
}
|
|
139124
139202
|
|
|
139125
|
-
string KeywordHelper::WriteOptionallyQuoted(const string &text) {
|
|
139203
|
+
string KeywordHelper::WriteOptionallyQuoted(const string &text, char quote) {
|
|
139126
139204
|
if (!RequiresQuotes(text)) {
|
|
139127
139205
|
return text;
|
|
139128
139206
|
}
|
|
139129
|
-
return
|
|
139207
|
+
return string(1, quote) + StringUtil::Replace(text, string(1, quote), string(2, quote)) + string(1, quote);
|
|
139130
139208
|
}
|
|
139131
139209
|
|
|
139132
139210
|
} // namespace duckdb
|
|
@@ -139756,6 +139834,9 @@ public:
|
|
|
139756
139834
|
}
|
|
139757
139835
|
|
|
139758
139836
|
public:
|
|
139837
|
+
//! Convert the query node to a string
|
|
139838
|
+
string ToString() const override;
|
|
139839
|
+
|
|
139759
139840
|
bool Equals(const QueryNode *other) const override;
|
|
139760
139841
|
//! Create a copy of this SelectNode
|
|
139761
139842
|
unique_ptr<QueryNode> Copy() const override;
|
|
@@ -145782,6 +145863,17 @@ string QueryErrorContext::FormatErrorRecursive(const string &msg, vector<Excepti
|
|
|
145782
145863
|
|
|
145783
145864
|
namespace duckdb {
|
|
145784
145865
|
|
|
145866
|
+
string RecursiveCTENode::ToString() const {
|
|
145867
|
+
string result;
|
|
145868
|
+
result += "(" + left->ToString() + ")";
|
|
145869
|
+
result += " UNION ";
|
|
145870
|
+
if (union_all) {
|
|
145871
|
+
result += " ALL ";
|
|
145872
|
+
}
|
|
145873
|
+
result += "(" + right->ToString() + ")";
|
|
145874
|
+
return result;
|
|
145875
|
+
}
|
|
145876
|
+
|
|
145785
145877
|
bool RecursiveCTENode::Equals(const QueryNode *other_p) const {
|
|
145786
145878
|
if (!QueryNode::Equals(other_p)) {
|
|
145787
145879
|
return false;
|
|
@@ -145837,12 +145929,108 @@ unique_ptr<QueryNode> RecursiveCTENode::Deserialize(FieldReader &reader) {
|
|
|
145837
145929
|
|
|
145838
145930
|
|
|
145839
145931
|
|
|
145932
|
+
|
|
145840
145933
|
namespace duckdb {
|
|
145841
145934
|
|
|
145842
145935
|
SelectNode::SelectNode()
|
|
145843
145936
|
: QueryNode(QueryNodeType::SELECT_NODE), aggregate_handling(AggregateHandling::STANDARD_HANDLING) {
|
|
145844
145937
|
}
|
|
145845
145938
|
|
|
145939
|
+
string SelectNode::ToString() const {
|
|
145940
|
+
string result;
|
|
145941
|
+
result = CTEToString();
|
|
145942
|
+
result += "SELECT ";
|
|
145943
|
+
|
|
145944
|
+
// search for a distinct modifier
|
|
145945
|
+
for (idx_t modifier_idx = 0; modifier_idx < modifiers.size(); modifier_idx++) {
|
|
145946
|
+
if (modifiers[modifier_idx]->type == ResultModifierType::DISTINCT_MODIFIER) {
|
|
145947
|
+
auto &distinct_modifier = (DistinctModifier &)*modifiers[modifier_idx];
|
|
145948
|
+
result += "DISTINCT ";
|
|
145949
|
+
if (!distinct_modifier.distinct_on_targets.empty()) {
|
|
145950
|
+
result += "ON (";
|
|
145951
|
+
for (idx_t k = 0; k < distinct_modifier.distinct_on_targets.size(); k++) {
|
|
145952
|
+
if (k > 0) {
|
|
145953
|
+
result += ", ";
|
|
145954
|
+
}
|
|
145955
|
+
result += distinct_modifier.distinct_on_targets[k]->ToString();
|
|
145956
|
+
}
|
|
145957
|
+
result += ") ";
|
|
145958
|
+
}
|
|
145959
|
+
}
|
|
145960
|
+
}
|
|
145961
|
+
for (idx_t i = 0; i < select_list.size(); i++) {
|
|
145962
|
+
if (i > 0) {
|
|
145963
|
+
result += ", ";
|
|
145964
|
+
}
|
|
145965
|
+
result += select_list[i]->ToString();
|
|
145966
|
+
if (!select_list[i]->alias.empty()) {
|
|
145967
|
+
result += " AS " + KeywordHelper::WriteOptionallyQuoted(select_list[i]->alias);
|
|
145968
|
+
}
|
|
145969
|
+
}
|
|
145970
|
+
if (from_table && from_table->type != TableReferenceType::EMPTY) {
|
|
145971
|
+
result += " FROM " + from_table->ToString();
|
|
145972
|
+
}
|
|
145973
|
+
if (where_clause) {
|
|
145974
|
+
result += " WHERE " + where_clause->ToString();
|
|
145975
|
+
}
|
|
145976
|
+
if (!groups.grouping_sets.empty()) {
|
|
145977
|
+
result += " GROUP BY ";
|
|
145978
|
+
// if we are dealing with multiple grouping sets, we have to add a few additional brackets
|
|
145979
|
+
bool grouping_sets = groups.grouping_sets.size() > 1;
|
|
145980
|
+
if (grouping_sets) {
|
|
145981
|
+
result += "GROUPING SETS (";
|
|
145982
|
+
}
|
|
145983
|
+
for (idx_t i = 0; i < groups.grouping_sets.size(); i++) {
|
|
145984
|
+
auto &grouping_set = groups.grouping_sets[i];
|
|
145985
|
+
if (i > 0) {
|
|
145986
|
+
result += ",";
|
|
145987
|
+
}
|
|
145988
|
+
if (grouping_set.empty()) {
|
|
145989
|
+
result += "()";
|
|
145990
|
+
continue;
|
|
145991
|
+
}
|
|
145992
|
+
if (grouping_sets) {
|
|
145993
|
+
result += "(";
|
|
145994
|
+
}
|
|
145995
|
+
bool first = true;
|
|
145996
|
+
for (auto &grp : grouping_set) {
|
|
145997
|
+
if (!first) {
|
|
145998
|
+
result += ", ";
|
|
145999
|
+
}
|
|
146000
|
+
result += groups.group_expressions[grp]->ToString();
|
|
146001
|
+
first = false;
|
|
146002
|
+
}
|
|
146003
|
+
if (grouping_sets) {
|
|
146004
|
+
result += ")";
|
|
146005
|
+
}
|
|
146006
|
+
}
|
|
146007
|
+
if (grouping_sets) {
|
|
146008
|
+
result += ")";
|
|
146009
|
+
}
|
|
146010
|
+
} else if (aggregate_handling == AggregateHandling::FORCE_AGGREGATES) {
|
|
146011
|
+
result += " GROUP BY ALL";
|
|
146012
|
+
}
|
|
146013
|
+
if (having) {
|
|
146014
|
+
result += " HAVING " + having->ToString();
|
|
146015
|
+
}
|
|
146016
|
+
if (qualify) {
|
|
146017
|
+
result += " QUALIFY " + qualify->ToString();
|
|
146018
|
+
}
|
|
146019
|
+
if (sample) {
|
|
146020
|
+
result += " USING SAMPLE ";
|
|
146021
|
+
result += sample->sample_size.ToString();
|
|
146022
|
+
if (sample->is_percentage) {
|
|
146023
|
+
result += "%";
|
|
146024
|
+
}
|
|
146025
|
+
result += " (" + SampleMethodToString(sample->method);
|
|
146026
|
+
if (sample->seed >= 0) {
|
|
146027
|
+
result += ", " + std::to_string(sample->seed);
|
|
146028
|
+
}
|
|
146029
|
+
result += ")";
|
|
146030
|
+
}
|
|
146031
|
+
return result + ResultModifiersToString();
|
|
146032
|
+
}
|
|
146033
|
+
|
|
145846
146034
|
bool SelectNode::Equals(const QueryNode *other_p) const {
|
|
145847
146035
|
if (!QueryNode::Equals(other_p)) {
|
|
145848
146036
|
return false;
|
|
@@ -145961,6 +146149,37 @@ unique_ptr<QueryNode> SelectNode::Deserialize(FieldReader &reader) {
|
|
|
145961
146149
|
|
|
145962
146150
|
namespace duckdb {
|
|
145963
146151
|
|
|
146152
|
+
string SetOperationNode::ToString() const {
|
|
146153
|
+
string result;
|
|
146154
|
+
result = CTEToString();
|
|
146155
|
+
result += "(" + left->ToString() + ") ";
|
|
146156
|
+
bool is_distinct = false;
|
|
146157
|
+
for (idx_t modifier_idx = 0; modifier_idx < modifiers.size(); modifier_idx++) {
|
|
146158
|
+
if (modifiers[modifier_idx]->type == ResultModifierType::DISTINCT_MODIFIER) {
|
|
146159
|
+
is_distinct = true;
|
|
146160
|
+
break;
|
|
146161
|
+
}
|
|
146162
|
+
}
|
|
146163
|
+
|
|
146164
|
+
switch (setop_type) {
|
|
146165
|
+
case SetOperationType::UNION:
|
|
146166
|
+
result += is_distinct ? "UNION" : "UNION ALL";
|
|
146167
|
+
break;
|
|
146168
|
+
case SetOperationType::EXCEPT:
|
|
146169
|
+
D_ASSERT(is_distinct);
|
|
146170
|
+
result += "EXCEPT";
|
|
146171
|
+
break;
|
|
146172
|
+
case SetOperationType::INTERSECT:
|
|
146173
|
+
D_ASSERT(is_distinct);
|
|
146174
|
+
result += "INTERSECT";
|
|
146175
|
+
break;
|
|
146176
|
+
default:
|
|
146177
|
+
throw InternalException("Unsupported set operation type");
|
|
146178
|
+
}
|
|
146179
|
+
result += " (" + right->ToString() + ")";
|
|
146180
|
+
return result + ResultModifiersToString();
|
|
146181
|
+
}
|
|
146182
|
+
|
|
145964
146183
|
bool SetOperationNode::Equals(const QueryNode *other_p) const {
|
|
145965
146184
|
if (!QueryNode::Equals(other_p)) {
|
|
145966
146185
|
return false;
|
|
@@ -146015,6 +146234,81 @@ unique_ptr<QueryNode> SetOperationNode::Deserialize(FieldReader &reader) {
|
|
|
146015
146234
|
|
|
146016
146235
|
namespace duckdb {
|
|
146017
146236
|
|
|
146237
|
+
string QueryNode::CTEToString() const {
|
|
146238
|
+
if (cte_map.empty()) {
|
|
146239
|
+
return string();
|
|
146240
|
+
}
|
|
146241
|
+
// check if there are any recursive CTEs
|
|
146242
|
+
bool has_recursive = false;
|
|
146243
|
+
for (auto &kv : cte_map) {
|
|
146244
|
+
if (kv.second->query->node->type == QueryNodeType::RECURSIVE_CTE_NODE) {
|
|
146245
|
+
has_recursive = true;
|
|
146246
|
+
break;
|
|
146247
|
+
}
|
|
146248
|
+
}
|
|
146249
|
+
string result = "WITH ";
|
|
146250
|
+
if (has_recursive) {
|
|
146251
|
+
result += "RECURSIVE ";
|
|
146252
|
+
}
|
|
146253
|
+
bool first_cte = true;
|
|
146254
|
+
for (auto &kv : cte_map) {
|
|
146255
|
+
if (!first_cte) {
|
|
146256
|
+
result += ", ";
|
|
146257
|
+
}
|
|
146258
|
+
auto &cte = *kv.second;
|
|
146259
|
+
result += KeywordHelper::WriteOptionallyQuoted(kv.first);
|
|
146260
|
+
if (!cte.aliases.empty()) {
|
|
146261
|
+
result += " (";
|
|
146262
|
+
for (idx_t k = 0; k < cte.aliases.size(); k++) {
|
|
146263
|
+
if (k > 0) {
|
|
146264
|
+
result += ", ";
|
|
146265
|
+
}
|
|
146266
|
+
result += KeywordHelper::WriteOptionallyQuoted(cte.aliases[k]);
|
|
146267
|
+
}
|
|
146268
|
+
result += ")";
|
|
146269
|
+
}
|
|
146270
|
+
result += " AS (";
|
|
146271
|
+
result += cte.query->ToString();
|
|
146272
|
+
result += ")";
|
|
146273
|
+
first_cte = false;
|
|
146274
|
+
}
|
|
146275
|
+
return result;
|
|
146276
|
+
}
|
|
146277
|
+
|
|
146278
|
+
string QueryNode::ResultModifiersToString() const {
|
|
146279
|
+
string result;
|
|
146280
|
+
for (idx_t modifier_idx = 0; modifier_idx < modifiers.size(); modifier_idx++) {
|
|
146281
|
+
auto &modifier = *modifiers[modifier_idx];
|
|
146282
|
+
if (modifier.type == ResultModifierType::ORDER_MODIFIER) {
|
|
146283
|
+
auto &order_modifier = (OrderModifier &)modifier;
|
|
146284
|
+
result += " ORDER BY ";
|
|
146285
|
+
for (idx_t k = 0; k < order_modifier.orders.size(); k++) {
|
|
146286
|
+
if (k > 0) {
|
|
146287
|
+
result += ", ";
|
|
146288
|
+
}
|
|
146289
|
+
result += order_modifier.orders[k].ToString();
|
|
146290
|
+
}
|
|
146291
|
+
} else if (modifier.type == ResultModifierType::LIMIT_MODIFIER) {
|
|
146292
|
+
auto &limit_modifier = (LimitModifier &)modifier;
|
|
146293
|
+
if (limit_modifier.limit) {
|
|
146294
|
+
result += " LIMIT " + limit_modifier.limit->ToString();
|
|
146295
|
+
}
|
|
146296
|
+
if (limit_modifier.offset) {
|
|
146297
|
+
result += " OFFSET " + limit_modifier.offset->ToString();
|
|
146298
|
+
}
|
|
146299
|
+
} else if (modifier.type == ResultModifierType::LIMIT_PERCENT_MODIFIER) {
|
|
146300
|
+
auto &limit_p_modifier = (LimitPercentModifier &)modifier;
|
|
146301
|
+
if (limit_p_modifier.limit) {
|
|
146302
|
+
result += " LIMIT " + limit_p_modifier.limit->ToString() + " %";
|
|
146303
|
+
}
|
|
146304
|
+
if (limit_p_modifier.offset) {
|
|
146305
|
+
result += " OFFSET " + limit_p_modifier.offset->ToString();
|
|
146306
|
+
}
|
|
146307
|
+
}
|
|
146308
|
+
}
|
|
146309
|
+
return result;
|
|
146310
|
+
}
|
|
146311
|
+
|
|
146018
146312
|
bool QueryNode::Equals(const QueryNode *other) const {
|
|
146019
146313
|
if (!other) {
|
|
146020
146314
|
return false;
|
|
@@ -146484,6 +146778,35 @@ DeleteStatement::DeleteStatement(const DeleteStatement &other) : SQLStatement(ot
|
|
|
146484
146778
|
}
|
|
146485
146779
|
}
|
|
146486
146780
|
|
|
146781
|
+
string DeleteStatement::ToString() const {
|
|
146782
|
+
string result;
|
|
146783
|
+
result += "DELETE FROM ";
|
|
146784
|
+
result += table->ToString();
|
|
146785
|
+
if (!using_clauses.empty()) {
|
|
146786
|
+
result += " USING ";
|
|
146787
|
+
for (idx_t i = 0; i < using_clauses.size(); i++) {
|
|
146788
|
+
if (i > 0) {
|
|
146789
|
+
result += ", ";
|
|
146790
|
+
}
|
|
146791
|
+
result += using_clauses[i]->ToString();
|
|
146792
|
+
}
|
|
146793
|
+
}
|
|
146794
|
+
if (condition) {
|
|
146795
|
+
result += " WHERE " + condition->ToString();
|
|
146796
|
+
}
|
|
146797
|
+
|
|
146798
|
+
if (!returning_list.empty()) {
|
|
146799
|
+
result += " RETURNING ";
|
|
146800
|
+
for (idx_t i = 0; i < returning_list.size(); i++) {
|
|
146801
|
+
if (i > 0) {
|
|
146802
|
+
result += ", ";
|
|
146803
|
+
}
|
|
146804
|
+
result += returning_list[i]->ToString();
|
|
146805
|
+
}
|
|
146806
|
+
}
|
|
146807
|
+
return result;
|
|
146808
|
+
}
|
|
146809
|
+
|
|
146487
146810
|
unique_ptr<SQLStatement> DeleteStatement::Copy() const {
|
|
146488
146811
|
return unique_ptr<DeleteStatement>(new DeleteStatement(*this));
|
|
146489
146812
|
}
|
|
@@ -146617,6 +146940,8 @@ unique_ptr<SQLStatement> ExportStatement::Copy() const {
|
|
|
146617
146940
|
} // namespace duckdb
|
|
146618
146941
|
|
|
146619
146942
|
|
|
146943
|
+
|
|
146944
|
+
|
|
146620
146945
|
namespace duckdb {
|
|
146621
146946
|
|
|
146622
146947
|
InsertStatement::InsertStatement() : SQLStatement(StatementType::INSERT_STATEMENT), schema(DEFAULT_SCHEMA) {
|
|
@@ -146628,10 +146953,73 @@ InsertStatement::InsertStatement(const InsertStatement &other)
|
|
|
146628
146953
|
columns(other.columns), table(other.table), schema(other.schema) {
|
|
146629
146954
|
}
|
|
146630
146955
|
|
|
146956
|
+
string InsertStatement::ToString() const {
|
|
146957
|
+
string result;
|
|
146958
|
+
result = "INSERT INTO ";
|
|
146959
|
+
if (!schema.empty()) {
|
|
146960
|
+
result += KeywordHelper::WriteOptionallyQuoted(schema) + ".";
|
|
146961
|
+
}
|
|
146962
|
+
result += KeywordHelper::WriteOptionallyQuoted(table);
|
|
146963
|
+
if (!columns.empty()) {
|
|
146964
|
+
result += " (";
|
|
146965
|
+
for (idx_t i = 0; i < columns.size(); i++) {
|
|
146966
|
+
if (i > 0) {
|
|
146967
|
+
result += ", ";
|
|
146968
|
+
}
|
|
146969
|
+
result += KeywordHelper::WriteOptionallyQuoted(columns[i]);
|
|
146970
|
+
}
|
|
146971
|
+
result += " )";
|
|
146972
|
+
}
|
|
146973
|
+
result += " ";
|
|
146974
|
+
auto values_list = GetValuesList();
|
|
146975
|
+
if (values_list) {
|
|
146976
|
+
values_list->alias = string();
|
|
146977
|
+
result += values_list->ToString();
|
|
146978
|
+
} else {
|
|
146979
|
+
result += select_statement->ToString();
|
|
146980
|
+
}
|
|
146981
|
+
if (!returning_list.empty()) {
|
|
146982
|
+
result += " RETURNING ";
|
|
146983
|
+
for (idx_t i = 0; i < returning_list.size(); i++) {
|
|
146984
|
+
if (i > 0) {
|
|
146985
|
+
result += ", ";
|
|
146986
|
+
}
|
|
146987
|
+
result += returning_list[i]->ToString();
|
|
146988
|
+
}
|
|
146989
|
+
}
|
|
146990
|
+
return result;
|
|
146991
|
+
}
|
|
146992
|
+
|
|
146631
146993
|
unique_ptr<SQLStatement> InsertStatement::Copy() const {
|
|
146632
146994
|
return unique_ptr<InsertStatement>(new InsertStatement(*this));
|
|
146633
146995
|
}
|
|
146634
146996
|
|
|
146997
|
+
ExpressionListRef *InsertStatement::GetValuesList() const {
|
|
146998
|
+
if (select_statement->node->type != QueryNodeType::SELECT_NODE) {
|
|
146999
|
+
return nullptr;
|
|
147000
|
+
}
|
|
147001
|
+
auto &node = (SelectNode &)*select_statement->node;
|
|
147002
|
+
if (node.where_clause || node.qualify || node.having) {
|
|
147003
|
+
return nullptr;
|
|
147004
|
+
}
|
|
147005
|
+
if (!node.cte_map.empty()) {
|
|
147006
|
+
return nullptr;
|
|
147007
|
+
}
|
|
147008
|
+
if (!node.groups.grouping_sets.empty()) {
|
|
147009
|
+
return nullptr;
|
|
147010
|
+
}
|
|
147011
|
+
if (node.aggregate_handling != AggregateHandling::STANDARD_HANDLING) {
|
|
147012
|
+
return nullptr;
|
|
147013
|
+
}
|
|
147014
|
+
if (node.select_list.size() != 1 || node.select_list[0]->type != ExpressionType::STAR) {
|
|
147015
|
+
return nullptr;
|
|
147016
|
+
}
|
|
147017
|
+
if (!node.from_table || node.from_table->type != TableReferenceType::EXPRESSION_LIST) {
|
|
147018
|
+
return nullptr;
|
|
147019
|
+
}
|
|
147020
|
+
return (ExpressionListRef *)node.from_table.get();
|
|
147021
|
+
}
|
|
147022
|
+
|
|
146635
147023
|
} // namespace duckdb
|
|
146636
147024
|
//===----------------------------------------------------------------------===//
|
|
146637
147025
|
// DuckDB
|
|
@@ -146780,6 +147168,10 @@ bool SelectStatement::Equals(const SQLStatement *other_p) const {
|
|
|
146780
147168
|
return node->Equals(other->node.get());
|
|
146781
147169
|
}
|
|
146782
147170
|
|
|
147171
|
+
string SelectStatement::ToString() const {
|
|
147172
|
+
return node->ToString();
|
|
147173
|
+
}
|
|
147174
|
+
|
|
146783
147175
|
} // namespace duckdb
|
|
146784
147176
|
//===----------------------------------------------------------------------===//
|
|
146785
147177
|
// DuckDB
|
|
@@ -146934,6 +147326,38 @@ UpdateStatement::UpdateStatement(const UpdateStatement &other)
|
|
|
146934
147326
|
}
|
|
146935
147327
|
}
|
|
146936
147328
|
|
|
147329
|
+
string UpdateStatement::ToString() const {
|
|
147330
|
+
string result;
|
|
147331
|
+
result = "UPDATE ";
|
|
147332
|
+
result += table->ToString();
|
|
147333
|
+
result += " SET ";
|
|
147334
|
+
D_ASSERT(columns.size() == expressions.size());
|
|
147335
|
+
for (idx_t i = 0; i < columns.size(); i++) {
|
|
147336
|
+
if (i > 0) {
|
|
147337
|
+
result += ", ";
|
|
147338
|
+
}
|
|
147339
|
+
result += KeywordHelper::WriteOptionallyQuoted(columns[i]);
|
|
147340
|
+
result += "=";
|
|
147341
|
+
result += expressions[i]->ToString();
|
|
147342
|
+
}
|
|
147343
|
+
if (from_table) {
|
|
147344
|
+
result += " FROM " + from_table->ToString();
|
|
147345
|
+
}
|
|
147346
|
+
if (condition) {
|
|
147347
|
+
result += " WHERE " + condition->ToString();
|
|
147348
|
+
}
|
|
147349
|
+
if (!returning_list.empty()) {
|
|
147350
|
+
result += " RETURNING ";
|
|
147351
|
+
for (idx_t i = 0; i < returning_list.size(); i++) {
|
|
147352
|
+
if (i > 0) {
|
|
147353
|
+
result += ", ";
|
|
147354
|
+
}
|
|
147355
|
+
result += returning_list[i]->ToString();
|
|
147356
|
+
}
|
|
147357
|
+
}
|
|
147358
|
+
return result;
|
|
147359
|
+
}
|
|
147360
|
+
|
|
146937
147361
|
unique_ptr<SQLStatement> UpdateStatement::Copy() const {
|
|
146938
147362
|
return unique_ptr<UpdateStatement>(new UpdateStatement(*this));
|
|
146939
147363
|
}
|
|
@@ -146985,10 +147409,13 @@ unique_ptr<SQLStatement> VacuumStatement::Copy() const {
|
|
|
146985
147409
|
|
|
146986
147410
|
|
|
146987
147411
|
|
|
147412
|
+
|
|
146988
147413
|
namespace duckdb {
|
|
146989
147414
|
|
|
146990
147415
|
string BaseTableRef::ToString() const {
|
|
146991
|
-
|
|
147416
|
+
string schema = schema_name.empty() ? "" : KeywordHelper::WriteOptionallyQuoted(schema_name) + ".";
|
|
147417
|
+
string result = schema + KeywordHelper::WriteOptionallyQuoted(table_name);
|
|
147418
|
+
return BaseToString(result, column_name_alias);
|
|
146992
147419
|
}
|
|
146993
147420
|
|
|
146994
147421
|
bool BaseTableRef::Equals(const TableRef *other_p) const {
|
|
@@ -147033,6 +147460,10 @@ unique_ptr<TableRef> BaseTableRef::Copy() {
|
|
|
147033
147460
|
|
|
147034
147461
|
namespace duckdb {
|
|
147035
147462
|
|
|
147463
|
+
string CrossProductRef::ToString() const {
|
|
147464
|
+
return left->ToString() + ", " + right->ToString();
|
|
147465
|
+
}
|
|
147466
|
+
|
|
147036
147467
|
bool CrossProductRef::Equals(const TableRef *other_p) const {
|
|
147037
147468
|
if (!TableRef::Equals(other_p)) {
|
|
147038
147469
|
return false;
|
|
@@ -147072,6 +147503,10 @@ unique_ptr<TableRef> CrossProductRef::Deserialize(FieldReader &reader) {
|
|
|
147072
147503
|
|
|
147073
147504
|
namespace duckdb {
|
|
147074
147505
|
|
|
147506
|
+
string EmptyTableRef::ToString() const {
|
|
147507
|
+
return "";
|
|
147508
|
+
}
|
|
147509
|
+
|
|
147075
147510
|
bool EmptyTableRef::Equals(const TableRef *other) const {
|
|
147076
147511
|
return TableRef::Equals(other);
|
|
147077
147512
|
}
|
|
@@ -147094,6 +147529,27 @@ unique_ptr<TableRef> EmptyTableRef::Deserialize(FieldReader &reader) {
|
|
|
147094
147529
|
|
|
147095
147530
|
namespace duckdb {
|
|
147096
147531
|
|
|
147532
|
+
string ExpressionListRef::ToString() const {
|
|
147533
|
+
D_ASSERT(!values.empty());
|
|
147534
|
+
string result = "(VALUES ";
|
|
147535
|
+
for (idx_t row_idx = 0; row_idx < values.size(); row_idx++) {
|
|
147536
|
+
if (row_idx > 0) {
|
|
147537
|
+
result += ", ";
|
|
147538
|
+
}
|
|
147539
|
+
auto &row = values[row_idx];
|
|
147540
|
+
result += "(";
|
|
147541
|
+
for (idx_t col_idx = 0; col_idx < row.size(); col_idx++) {
|
|
147542
|
+
if (col_idx > 0) {
|
|
147543
|
+
result += ", ";
|
|
147544
|
+
}
|
|
147545
|
+
result += row[col_idx]->ToString();
|
|
147546
|
+
}
|
|
147547
|
+
result += ")";
|
|
147548
|
+
}
|
|
147549
|
+
result += ")";
|
|
147550
|
+
return BaseToString(result, expected_names);
|
|
147551
|
+
}
|
|
147552
|
+
|
|
147097
147553
|
bool ExpressionListRef::Equals(const TableRef *other_p) const {
|
|
147098
147554
|
if (!TableRef::Equals(other_p)) {
|
|
147099
147555
|
return false;
|
|
@@ -147165,6 +147621,32 @@ unique_ptr<TableRef> ExpressionListRef::Deserialize(FieldReader &reader) {
|
|
|
147165
147621
|
|
|
147166
147622
|
namespace duckdb {
|
|
147167
147623
|
|
|
147624
|
+
string JoinRef::ToString() const {
|
|
147625
|
+
string result;
|
|
147626
|
+
result = left->ToString() + " ";
|
|
147627
|
+
if (is_natural) {
|
|
147628
|
+
result += "NATURAL ";
|
|
147629
|
+
}
|
|
147630
|
+
result += JoinTypeToString(type) + " JOIN ";
|
|
147631
|
+
result += right->ToString();
|
|
147632
|
+
if (condition) {
|
|
147633
|
+
D_ASSERT(using_columns.empty());
|
|
147634
|
+
result += " ON (";
|
|
147635
|
+
result += condition->ToString();
|
|
147636
|
+
result += ")";
|
|
147637
|
+
} else if (!using_columns.empty()) {
|
|
147638
|
+
result += " USING (";
|
|
147639
|
+
for (idx_t i = 0; i < using_columns.size(); i++) {
|
|
147640
|
+
if (i > 0) {
|
|
147641
|
+
result += ", ";
|
|
147642
|
+
}
|
|
147643
|
+
result += using_columns[i];
|
|
147644
|
+
}
|
|
147645
|
+
result += ")";
|
|
147646
|
+
}
|
|
147647
|
+
return result;
|
|
147648
|
+
}
|
|
147649
|
+
|
|
147168
147650
|
bool JoinRef::Equals(const TableRef *other_p) const {
|
|
147169
147651
|
if (!TableRef::Equals(other_p)) {
|
|
147170
147652
|
return false;
|
|
@@ -147224,6 +147706,11 @@ unique_ptr<TableRef> JoinRef::Deserialize(FieldReader &reader) {
|
|
|
147224
147706
|
|
|
147225
147707
|
namespace duckdb {
|
|
147226
147708
|
|
|
147709
|
+
string SubqueryRef::ToString() const {
|
|
147710
|
+
string result = "(" + subquery->ToString() + ")";
|
|
147711
|
+
return BaseToString(result, column_name_alias);
|
|
147712
|
+
}
|
|
147713
|
+
|
|
147227
147714
|
SubqueryRef::SubqueryRef(unique_ptr<SelectStatement> subquery_p, string alias_p)
|
|
147228
147715
|
: TableRef(TableReferenceType::SUBQUERY), subquery(move(subquery_p)) {
|
|
147229
147716
|
this->alias = move(alias_p);
|
|
@@ -147264,7 +147751,7 @@ unique_ptr<TableRef> SubqueryRef::Deserialize(FieldReader &reader) {
|
|
|
147264
147751
|
namespace duckdb {
|
|
147265
147752
|
|
|
147266
147753
|
string TableFunctionRef::ToString() const {
|
|
147267
|
-
return function->ToString();
|
|
147754
|
+
return BaseToString(function->ToString(), column_name_alias);
|
|
147268
147755
|
}
|
|
147269
147756
|
|
|
147270
147757
|
bool TableFunctionRef::Equals(const TableRef *other_p) const {
|
|
@@ -147306,10 +147793,38 @@ unique_ptr<TableRef> TableFunctionRef::Copy() {
|
|
|
147306
147793
|
|
|
147307
147794
|
|
|
147308
147795
|
|
|
147796
|
+
|
|
147309
147797
|
namespace duckdb {
|
|
147310
147798
|
|
|
147311
|
-
string TableRef::
|
|
147312
|
-
|
|
147799
|
+
string TableRef::BaseToString(string result) const {
|
|
147800
|
+
vector<string> column_name_alias;
|
|
147801
|
+
return BaseToString(move(result), column_name_alias);
|
|
147802
|
+
}
|
|
147803
|
+
|
|
147804
|
+
string TableRef::BaseToString(string result, const vector<string> &column_name_alias) const {
|
|
147805
|
+
if (!alias.empty()) {
|
|
147806
|
+
result += " AS " + KeywordHelper::WriteOptionallyQuoted(alias);
|
|
147807
|
+
}
|
|
147808
|
+
if (!column_name_alias.empty()) {
|
|
147809
|
+
D_ASSERT(!alias.empty());
|
|
147810
|
+
result += "(";
|
|
147811
|
+
for (idx_t i = 0; i < column_name_alias.size(); i++) {
|
|
147812
|
+
if (i > 0) {
|
|
147813
|
+
result += ", ";
|
|
147814
|
+
}
|
|
147815
|
+
result += KeywordHelper::WriteOptionallyQuoted(column_name_alias[i]);
|
|
147816
|
+
}
|
|
147817
|
+
result += ")";
|
|
147818
|
+
}
|
|
147819
|
+
if (sample) {
|
|
147820
|
+
result += " TABLESAMPLE " + SampleMethodToString(sample->method);
|
|
147821
|
+
result += "(" + sample->sample_size.ToString() + " " + string(sample->is_percentage ? "PERCENT" : "ROWS") + ")";
|
|
147822
|
+
if (sample->seed >= 0) {
|
|
147823
|
+
result += "REPEATABLE (" + to_string(sample->seed) + ")";
|
|
147824
|
+
}
|
|
147825
|
+
}
|
|
147826
|
+
|
|
147827
|
+
return result;
|
|
147313
147828
|
}
|
|
147314
147829
|
|
|
147315
147830
|
bool TableRef::Equals(const TableRef *other) const {
|
|
@@ -153980,11 +154495,14 @@ public:
|
|
|
153980
154495
|
throw InternalException("Cannot get select list of bound subquery node");
|
|
153981
154496
|
}
|
|
153982
154497
|
|
|
154498
|
+
string ToString() const override {
|
|
154499
|
+
throw InternalException("Cannot ToString bound subquery node");
|
|
154500
|
+
}
|
|
153983
154501
|
unique_ptr<QueryNode> Copy() const override {
|
|
153984
154502
|
throw InternalException("Cannot copy bound subquery node");
|
|
153985
154503
|
}
|
|
153986
154504
|
void Serialize(FieldWriter &writer) const override {
|
|
153987
|
-
throw InternalException("Cannot
|
|
154505
|
+
throw InternalException("Cannot serialize bound subquery node");
|
|
153988
154506
|
}
|
|
153989
154507
|
};
|
|
153990
154508
|
|
|
@@ -157447,37 +157965,36 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
|
|
|
157447
157965
|
}
|
|
157448
157966
|
|
|
157449
157967
|
idx_t expected_columns = stmt.columns.empty() ? table->columns.size() : stmt.columns.size();
|
|
157968
|
+
|
|
157450
157969
|
// special case: check if we are inserting from a VALUES statement
|
|
157451
|
-
|
|
157452
|
-
|
|
157453
|
-
|
|
157454
|
-
|
|
157455
|
-
|
|
157456
|
-
|
|
157457
|
-
|
|
157458
|
-
|
|
157459
|
-
|
|
157460
|
-
|
|
157461
|
-
|
|
157462
|
-
|
|
157463
|
-
|
|
157464
|
-
|
|
157465
|
-
|
|
157466
|
-
|
|
157467
|
-
|
|
157468
|
-
|
|
157469
|
-
|
|
157470
|
-
|
|
157471
|
-
|
|
157472
|
-
|
|
157473
|
-
|
|
157474
|
-
|
|
157475
|
-
|
|
157476
|
-
|
|
157477
|
-
|
|
157478
|
-
|
|
157479
|
-
expr_list.values[list_idx][col_idx] = make_unique<ConstantExpression>(Value(column.type));
|
|
157480
|
-
}
|
|
157970
|
+
auto values_list = stmt.GetValuesList();
|
|
157971
|
+
if (values_list) {
|
|
157972
|
+
auto &expr_list = (ExpressionListRef &)*values_list;
|
|
157973
|
+
expr_list.expected_types.resize(expected_columns);
|
|
157974
|
+
expr_list.expected_names.resize(expected_columns);
|
|
157975
|
+
|
|
157976
|
+
D_ASSERT(expr_list.values.size() > 0);
|
|
157977
|
+
CheckInsertColumnCountMismatch(expected_columns, expr_list.values[0].size(), !stmt.columns.empty(),
|
|
157978
|
+
table->name.c_str());
|
|
157979
|
+
|
|
157980
|
+
// VALUES list!
|
|
157981
|
+
for (idx_t col_idx = 0; col_idx < expected_columns; col_idx++) {
|
|
157982
|
+
idx_t table_col_idx = stmt.columns.empty() ? col_idx : named_column_map[col_idx];
|
|
157983
|
+
D_ASSERT(table_col_idx < table->columns.size());
|
|
157984
|
+
|
|
157985
|
+
// set the expected types as the types for the INSERT statement
|
|
157986
|
+
auto &column = table->columns[table_col_idx];
|
|
157987
|
+
expr_list.expected_types[col_idx] = column.type;
|
|
157988
|
+
expr_list.expected_names[col_idx] = column.name;
|
|
157989
|
+
|
|
157990
|
+
// now replace any DEFAULT values with the corresponding default expression
|
|
157991
|
+
for (idx_t list_idx = 0; list_idx < expr_list.values.size(); list_idx++) {
|
|
157992
|
+
if (expr_list.values[list_idx][col_idx]->type == ExpressionType::VALUE_DEFAULT) {
|
|
157993
|
+
// DEFAULT value! replace the entry
|
|
157994
|
+
if (column.default_value) {
|
|
157995
|
+
expr_list.values[list_idx][col_idx] = column.default_value->Copy();
|
|
157996
|
+
} else {
|
|
157997
|
+
expr_list.values[list_idx][col_idx] = make_unique<ConstantExpression>(Value(column.type));
|
|
157481
157998
|
}
|
|
157482
157999
|
}
|
|
157483
158000
|
}
|