duckdb 0.4.1-dev188.0 → 0.4.1-dev204.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 +101 -40
- package/src/duckdb.hpp +413 -398
- package/src/parquet-amalgamation.cpp +25278 -25278
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -1533,7 +1533,7 @@ public:
|
|
|
1533
1533
|
}
|
|
1534
1534
|
|
|
1535
1535
|
template <class T, class RETURN_TYPE = unique_ptr<T>, typename... ARGS>
|
|
1536
|
-
RETURN_TYPE ReadSerializable(RETURN_TYPE default_value, ARGS &&...args) {
|
|
1536
|
+
RETURN_TYPE ReadSerializable(RETURN_TYPE default_value, ARGS &&... args) {
|
|
1537
1537
|
if (field_count >= max_field_count) {
|
|
1538
1538
|
// field is not there, read the default value
|
|
1539
1539
|
return default_value;
|
|
@@ -1555,7 +1555,7 @@ public:
|
|
|
1555
1555
|
}
|
|
1556
1556
|
|
|
1557
1557
|
template <class T, class RETURN_TYPE = unique_ptr<T>, typename... ARGS>
|
|
1558
|
-
RETURN_TYPE ReadRequiredSerializable(ARGS &&...args) {
|
|
1558
|
+
RETURN_TYPE ReadRequiredSerializable(ARGS &&... args) {
|
|
1559
1559
|
if (field_count >= max_field_count) {
|
|
1560
1560
|
// field is not there, read the default value
|
|
1561
1561
|
throw SerializationException("Attempting to read mandatory field, but field is missing");
|
|
@@ -128701,6 +128701,7 @@ public:
|
|
|
128701
128701
|
|
|
128702
128702
|
|
|
128703
128703
|
|
|
128704
|
+
|
|
128704
128705
|
namespace duckdb {
|
|
128705
128706
|
|
|
128706
128707
|
class DeleteStatement : public SQLStatement {
|
|
@@ -128711,6 +128712,8 @@ public:
|
|
|
128711
128712
|
unique_ptr<TableRef> table;
|
|
128712
128713
|
vector<unique_ptr<TableRef>> using_clauses;
|
|
128713
128714
|
vector<unique_ptr<ParsedExpression>> returning_list;
|
|
128715
|
+
//! CTEs
|
|
128716
|
+
CommonTableExpressionMap cte_map;
|
|
128714
128717
|
|
|
128715
128718
|
protected:
|
|
128716
128719
|
DeleteStatement(const DeleteStatement &other);
|
|
@@ -129096,6 +129099,7 @@ public:
|
|
|
129096
129099
|
|
|
129097
129100
|
|
|
129098
129101
|
|
|
129102
|
+
|
|
129099
129103
|
namespace duckdb {
|
|
129100
129104
|
class ExpressionListRef;
|
|
129101
129105
|
|
|
@@ -129116,6 +129120,9 @@ public:
|
|
|
129116
129120
|
//! keep track of optional returningList if statement contains a RETURNING keyword
|
|
129117
129121
|
vector<unique_ptr<ParsedExpression>> returning_list;
|
|
129118
129122
|
|
|
129123
|
+
//! CTEs
|
|
129124
|
+
CommonTableExpressionMap cte_map;
|
|
129125
|
+
|
|
129119
129126
|
protected:
|
|
129120
129127
|
InsertStatement(const InsertStatement &other);
|
|
129121
129128
|
|
|
@@ -130022,6 +130029,7 @@ void TableRelation::Delete(const string &condition) {
|
|
|
130022
130029
|
|
|
130023
130030
|
|
|
130024
130031
|
|
|
130032
|
+
|
|
130025
130033
|
namespace duckdb {
|
|
130026
130034
|
|
|
130027
130035
|
class UpdateStatement : public SQLStatement {
|
|
@@ -130035,6 +130043,8 @@ public:
|
|
|
130035
130043
|
vector<unique_ptr<ParsedExpression>> expressions;
|
|
130036
130044
|
//! keep track of optional returningList if statement contains a RETURNING keyword
|
|
130037
130045
|
vector<unique_ptr<ParsedExpression>> returning_list;
|
|
130046
|
+
//! CTEs
|
|
130047
|
+
CommonTableExpressionMap cte_map;
|
|
130038
130048
|
|
|
130039
130049
|
protected:
|
|
130040
130050
|
UpdateStatement(const UpdateStatement &other);
|
|
@@ -149986,7 +149996,7 @@ void ParsedExpressionIterator::EnumerateQueryNodeChildren(
|
|
|
149986
149996
|
EnumerateQueryNodeModifiers(node, callback);
|
|
149987
149997
|
}
|
|
149988
149998
|
|
|
149989
|
-
for (auto &kv : node.cte_map) {
|
|
149999
|
+
for (auto &kv : node.cte_map.map) {
|
|
149990
150000
|
EnumerateQueryNodeChildren(*kv.second->query->node, callback);
|
|
149991
150001
|
}
|
|
149992
150002
|
}
|
|
@@ -150015,6 +150025,7 @@ void ParsedExpressionIterator::EnumerateQueryNodeChildren(
|
|
|
150015
150025
|
|
|
150016
150026
|
|
|
150017
150027
|
|
|
150028
|
+
|
|
150018
150029
|
// LICENSE_CHANGE_BEGIN
|
|
150019
150030
|
// The following code up to LICENSE_CHANGE_END is subject to THIRD PARTY LICENSE #11
|
|
150020
150031
|
// See the end of this file for a list
|
|
@@ -155191,7 +155202,7 @@ private:
|
|
|
155191
155202
|
//===--------------------------------------------------------------------===//
|
|
155192
155203
|
OnCreateConflict TransformOnConflict(duckdb_libpgquery::PGOnCreateConflict conflict);
|
|
155193
155204
|
string TransformAlias(duckdb_libpgquery::PGAlias *root, vector<string> &column_name_alias);
|
|
155194
|
-
void TransformCTE(duckdb_libpgquery::PGWithClause *de_with_clause,
|
|
155205
|
+
void TransformCTE(duckdb_libpgquery::PGWithClause *de_with_clause, CommonTableExpressionMap &cte_map);
|
|
155195
155206
|
unique_ptr<SelectStatement> TransformRecursiveCTE(duckdb_libpgquery::PGCommonTableExpr *node,
|
|
155196
155207
|
CommonTableExpressionInfo &info);
|
|
155197
155208
|
|
|
@@ -155862,7 +155873,7 @@ SelectNode::SelectNode()
|
|
|
155862
155873
|
|
|
155863
155874
|
string SelectNode::ToString() const {
|
|
155864
155875
|
string result;
|
|
155865
|
-
result =
|
|
155876
|
+
result = cte_map.ToString();
|
|
155866
155877
|
result += "SELECT ";
|
|
155867
155878
|
|
|
155868
155879
|
// search for a distinct modifier
|
|
@@ -156075,7 +156086,7 @@ namespace duckdb {
|
|
|
156075
156086
|
|
|
156076
156087
|
string SetOperationNode::ToString() const {
|
|
156077
156088
|
string result;
|
|
156078
|
-
result =
|
|
156089
|
+
result = cte_map.ToString();
|
|
156079
156090
|
result += "(" + left->ToString() + ") ";
|
|
156080
156091
|
bool is_distinct = false;
|
|
156081
156092
|
for (idx_t modifier_idx = 0; modifier_idx < modifiers.size(); modifier_idx++) {
|
|
@@ -156158,13 +156169,29 @@ unique_ptr<QueryNode> SetOperationNode::Deserialize(FieldReader &reader) {
|
|
|
156158
156169
|
|
|
156159
156170
|
namespace duckdb {
|
|
156160
156171
|
|
|
156161
|
-
|
|
156162
|
-
|
|
156172
|
+
CommonTableExpressionMap::CommonTableExpressionMap() {
|
|
156173
|
+
}
|
|
156174
|
+
|
|
156175
|
+
CommonTableExpressionMap CommonTableExpressionMap::Copy() const {
|
|
156176
|
+
CommonTableExpressionMap res;
|
|
156177
|
+
for (auto &kv : this->map) {
|
|
156178
|
+
auto kv_info = make_unique<CommonTableExpressionInfo>();
|
|
156179
|
+
for (auto &al : kv.second->aliases) {
|
|
156180
|
+
kv_info->aliases.push_back(al);
|
|
156181
|
+
}
|
|
156182
|
+
kv_info->query = unique_ptr_cast<SQLStatement, SelectStatement>(kv.second->query->Copy());
|
|
156183
|
+
res.map[kv.first] = move(kv_info);
|
|
156184
|
+
}
|
|
156185
|
+
return res;
|
|
156186
|
+
}
|
|
156187
|
+
|
|
156188
|
+
string CommonTableExpressionMap::ToString() const {
|
|
156189
|
+
if (map.empty()) {
|
|
156163
156190
|
return string();
|
|
156164
156191
|
}
|
|
156165
156192
|
// check if there are any recursive CTEs
|
|
156166
156193
|
bool has_recursive = false;
|
|
156167
|
-
for (auto &kv :
|
|
156194
|
+
for (auto &kv : map) {
|
|
156168
156195
|
if (kv.second->query->node->type == QueryNodeType::RECURSIVE_CTE_NODE) {
|
|
156169
156196
|
has_recursive = true;
|
|
156170
156197
|
break;
|
|
@@ -156175,7 +156202,7 @@ string QueryNode::CTEToString() const {
|
|
|
156175
156202
|
result += "RECURSIVE ";
|
|
156176
156203
|
}
|
|
156177
156204
|
bool first_cte = true;
|
|
156178
|
-
for (auto &kv :
|
|
156205
|
+
for (auto &kv : map) {
|
|
156179
156206
|
if (!first_cte) {
|
|
156180
156207
|
result += ", ";
|
|
156181
156208
|
}
|
|
@@ -156252,12 +156279,12 @@ bool QueryNode::Equals(const QueryNode *other) const {
|
|
|
156252
156279
|
}
|
|
156253
156280
|
}
|
|
156254
156281
|
// WITH clauses (CTEs)
|
|
156255
|
-
if (cte_map.size() != other->cte_map.size()) {
|
|
156282
|
+
if (cte_map.map.size() != other->cte_map.map.size()) {
|
|
156256
156283
|
return false;
|
|
156257
156284
|
}
|
|
156258
|
-
for (auto &entry : cte_map) {
|
|
156259
|
-
auto other_entry = other->cte_map.find(entry.first);
|
|
156260
|
-
if (other_entry == other->cte_map.end()) {
|
|
156285
|
+
for (auto &entry : cte_map.map) {
|
|
156286
|
+
auto other_entry = other->cte_map.map.find(entry.first);
|
|
156287
|
+
if (other_entry == other->cte_map.map.end()) {
|
|
156261
156288
|
return false;
|
|
156262
156289
|
}
|
|
156263
156290
|
if (entry.second->aliases != other_entry->second->aliases) {
|
|
@@ -156274,13 +156301,13 @@ void QueryNode::CopyProperties(QueryNode &other) const {
|
|
|
156274
156301
|
for (auto &modifier : modifiers) {
|
|
156275
156302
|
other.modifiers.push_back(modifier->Copy());
|
|
156276
156303
|
}
|
|
156277
|
-
for (auto &kv : cte_map) {
|
|
156304
|
+
for (auto &kv : cte_map.map) {
|
|
156278
156305
|
auto kv_info = make_unique<CommonTableExpressionInfo>();
|
|
156279
156306
|
for (auto &al : kv.second->aliases) {
|
|
156280
156307
|
kv_info->aliases.push_back(al);
|
|
156281
156308
|
}
|
|
156282
156309
|
kv_info->query = unique_ptr_cast<SQLStatement, SelectStatement>(kv.second->query->Copy());
|
|
156283
|
-
other.cte_map[kv.first] = move(kv_info);
|
|
156310
|
+
other.cte_map.map[kv.first] = move(kv_info);
|
|
156284
156311
|
}
|
|
156285
156312
|
}
|
|
156286
156313
|
|
|
@@ -156289,9 +156316,9 @@ void QueryNode::Serialize(Serializer &main_serializer) const {
|
|
|
156289
156316
|
writer.WriteField<QueryNodeType>(type);
|
|
156290
156317
|
writer.WriteSerializableList(modifiers);
|
|
156291
156318
|
// cte_map
|
|
156292
|
-
writer.WriteField<uint32_t>((uint32_t)cte_map.size());
|
|
156319
|
+
writer.WriteField<uint32_t>((uint32_t)cte_map.map.size());
|
|
156293
156320
|
auto &serializer = writer.GetSerializer();
|
|
156294
|
-
for (auto &cte : cte_map) {
|
|
156321
|
+
for (auto &cte : cte_map.map) {
|
|
156295
156322
|
serializer.WriteString(cte.first);
|
|
156296
156323
|
serializer.WriteStringVector(cte.second->aliases);
|
|
156297
156324
|
cte.second->query->Serialize(serializer);
|
|
@@ -156308,15 +156335,14 @@ unique_ptr<QueryNode> QueryNode::Deserialize(Deserializer &main_source) {
|
|
|
156308
156335
|
// cte_map
|
|
156309
156336
|
auto cte_count = reader.ReadRequired<uint32_t>();
|
|
156310
156337
|
auto &source = reader.GetSource();
|
|
156311
|
-
unordered_map<string, unique_ptr<CommonTableExpressionInfo>>
|
|
156338
|
+
unordered_map<string, unique_ptr<CommonTableExpressionInfo>> new_map;
|
|
156312
156339
|
for (idx_t i = 0; i < cte_count; i++) {
|
|
156313
156340
|
auto name = source.Read<string>();
|
|
156314
156341
|
auto info = make_unique<CommonTableExpressionInfo>();
|
|
156315
156342
|
source.ReadStringVector(info->aliases);
|
|
156316
156343
|
info->query = SelectStatement::Deserialize(source);
|
|
156317
|
-
|
|
156344
|
+
new_map[name] = move(info);
|
|
156318
156345
|
}
|
|
156319
|
-
|
|
156320
156346
|
unique_ptr<QueryNode> result;
|
|
156321
156347
|
switch (type) {
|
|
156322
156348
|
case QueryNodeType::SELECT_NODE:
|
|
@@ -156332,7 +156358,7 @@ unique_ptr<QueryNode> QueryNode::Deserialize(Deserializer &main_source) {
|
|
|
156332
156358
|
throw SerializationException("Could not deserialize Query Node: unknown type!");
|
|
156333
156359
|
}
|
|
156334
156360
|
result->modifiers = move(modifiers);
|
|
156335
|
-
result->cte_map = move(
|
|
156361
|
+
result->cte_map.map = move(new_map);
|
|
156336
156362
|
reader.Finalize();
|
|
156337
156363
|
return result;
|
|
156338
156364
|
}
|
|
@@ -156691,6 +156717,7 @@ unique_ptr<SQLStatement> CreateStatement::Copy() const {
|
|
|
156691
156717
|
} // namespace duckdb
|
|
156692
156718
|
|
|
156693
156719
|
|
|
156720
|
+
|
|
156694
156721
|
namespace duckdb {
|
|
156695
156722
|
|
|
156696
156723
|
DeleteStatement::DeleteStatement() : SQLStatement(StatementType::DELETE_STATEMENT) {
|
|
@@ -156703,10 +156730,12 @@ DeleteStatement::DeleteStatement(const DeleteStatement &other) : SQLStatement(ot
|
|
|
156703
156730
|
for (const auto &using_clause : other.using_clauses) {
|
|
156704
156731
|
using_clauses.push_back(using_clause->Copy());
|
|
156705
156732
|
}
|
|
156733
|
+
cte_map = other.cte_map.Copy();
|
|
156706
156734
|
}
|
|
156707
156735
|
|
|
156708
156736
|
string DeleteStatement::ToString() const {
|
|
156709
156737
|
string result;
|
|
156738
|
+
result = cte_map.ToString();
|
|
156710
156739
|
result += "DELETE FROM ";
|
|
156711
156740
|
result += table->ToString();
|
|
156712
156741
|
if (!using_clauses.empty()) {
|
|
@@ -156891,11 +156920,13 @@ InsertStatement::InsertStatement(const InsertStatement &other)
|
|
|
156891
156920
|
: SQLStatement(other),
|
|
156892
156921
|
select_statement(unique_ptr_cast<SQLStatement, SelectStatement>(other.select_statement->Copy())),
|
|
156893
156922
|
columns(other.columns), table(other.table), schema(other.schema) {
|
|
156923
|
+
cte_map = other.cte_map.Copy();
|
|
156894
156924
|
}
|
|
156895
156925
|
|
|
156896
156926
|
string InsertStatement::ToString() const {
|
|
156897
156927
|
string result;
|
|
156898
|
-
result =
|
|
156928
|
+
result = cte_map.ToString();
|
|
156929
|
+
result += "INSERT INTO ";
|
|
156899
156930
|
if (!schema.empty()) {
|
|
156900
156931
|
result += KeywordHelper::WriteOptionallyQuoted(schema) + ".";
|
|
156901
156932
|
}
|
|
@@ -156942,7 +156973,7 @@ ExpressionListRef *InsertStatement::GetValuesList() const {
|
|
|
156942
156973
|
if (node.where_clause || node.qualify || node.having) {
|
|
156943
156974
|
return nullptr;
|
|
156944
156975
|
}
|
|
156945
|
-
if (!node.cte_map.empty()) {
|
|
156976
|
+
if (!node.cte_map.map.empty()) {
|
|
156946
156977
|
return nullptr;
|
|
156947
156978
|
}
|
|
156948
156979
|
if (!node.groups.grouping_sets.empty()) {
|
|
@@ -157248,6 +157279,7 @@ unique_ptr<SQLStatement> TransactionStatement::Copy() const {
|
|
|
157248
157279
|
} // namespace duckdb
|
|
157249
157280
|
|
|
157250
157281
|
|
|
157282
|
+
|
|
157251
157283
|
namespace duckdb {
|
|
157252
157284
|
|
|
157253
157285
|
UpdateStatement::UpdateStatement() : SQLStatement(StatementType::UPDATE_STATEMENT) {
|
|
@@ -157264,11 +157296,13 @@ UpdateStatement::UpdateStatement(const UpdateStatement &other)
|
|
|
157264
157296
|
for (auto &expr : other.expressions) {
|
|
157265
157297
|
expressions.emplace_back(expr->Copy());
|
|
157266
157298
|
}
|
|
157299
|
+
cte_map = other.cte_map.Copy();
|
|
157267
157300
|
}
|
|
157268
157301
|
|
|
157269
157302
|
string UpdateStatement::ToString() const {
|
|
157270
157303
|
string result;
|
|
157271
|
-
result =
|
|
157304
|
+
result = cte_map.ToString();
|
|
157305
|
+
result += "UPDATE ";
|
|
157272
157306
|
result += table->ToString();
|
|
157273
157307
|
result += " SET ";
|
|
157274
157308
|
D_ASSERT(columns.size() == expressions.size());
|
|
@@ -159188,12 +159222,14 @@ unique_ptr<ParsedExpression> Transformer::TransformSubquery(duckdb_libpgquery::P
|
|
|
159188
159222
|
string((reinterpret_cast<duckdb_libpgquery::PGValue *>(root->operName->head->data.ptr_value))->val.str);
|
|
159189
159223
|
subquery_expr->comparison_type = OperatorToExpressionType(operator_name);
|
|
159190
159224
|
}
|
|
159191
|
-
|
|
159192
|
-
|
|
159193
|
-
|
|
159194
|
-
|
|
159195
|
-
|
|
159196
|
-
|
|
159225
|
+
if (subquery_expr->comparison_type != ExpressionType::COMPARE_EQUAL &&
|
|
159226
|
+
subquery_expr->comparison_type != ExpressionType::COMPARE_NOTEQUAL &&
|
|
159227
|
+
subquery_expr->comparison_type != ExpressionType::COMPARE_GREATERTHAN &&
|
|
159228
|
+
subquery_expr->comparison_type != ExpressionType::COMPARE_GREATERTHANOREQUALTO &&
|
|
159229
|
+
subquery_expr->comparison_type != ExpressionType::COMPARE_LESSTHAN &&
|
|
159230
|
+
subquery_expr->comparison_type != ExpressionType::COMPARE_LESSTHANOREQUALTO) {
|
|
159231
|
+
throw ParserException("ANY and ALL operators require one of =,<>,>,<,>=,<= comparisons!");
|
|
159232
|
+
}
|
|
159197
159233
|
if (root->subLinkType == duckdb_libpgquery::PG_ALL_SUBLINK) {
|
|
159198
159234
|
// ALL sublink is equivalent to NOT(ANY) with inverted comparison
|
|
159199
159235
|
// e.g. [= ALL()] is equivalent to [NOT(<> ANY())]
|
|
@@ -160063,7 +160099,7 @@ string Transformer::TransformAlias(duckdb_libpgquery::PGAlias *root, vector<stri
|
|
|
160063
160099
|
|
|
160064
160100
|
namespace duckdb {
|
|
160065
160101
|
|
|
160066
|
-
void Transformer::TransformCTE(duckdb_libpgquery::PGWithClause *de_with_clause,
|
|
160102
|
+
void Transformer::TransformCTE(duckdb_libpgquery::PGWithClause *de_with_clause, CommonTableExpressionMap &cte_map) {
|
|
160067
160103
|
// TODO: might need to update in case of future lawsuit
|
|
160068
160104
|
D_ASSERT(de_with_clause);
|
|
160069
160105
|
|
|
@@ -160106,12 +160142,12 @@ void Transformer::TransformCTE(duckdb_libpgquery::PGWithClause *de_with_clause,
|
|
|
160106
160142
|
D_ASSERT(info->query);
|
|
160107
160143
|
auto cte_name = string(cte->ctename);
|
|
160108
160144
|
|
|
160109
|
-
auto it =
|
|
160110
|
-
if (it !=
|
|
160145
|
+
auto it = cte_map.map.find(cte_name);
|
|
160146
|
+
if (it != cte_map.map.end()) {
|
|
160111
160147
|
// can't have two CTEs with same name
|
|
160112
160148
|
throw ParserException("Duplicate CTE name \"%s\"", cte_name);
|
|
160113
160149
|
}
|
|
160114
|
-
|
|
160150
|
+
cte_map.map[cte_name] = move(info);
|
|
160115
160151
|
}
|
|
160116
160152
|
}
|
|
160117
160153
|
|
|
@@ -161449,6 +161485,9 @@ unique_ptr<DeleteStatement> Transformer::TransformDelete(duckdb_libpgquery::PGNo
|
|
|
161449
161485
|
auto stmt = reinterpret_cast<duckdb_libpgquery::PGDeleteStmt *>(node);
|
|
161450
161486
|
D_ASSERT(stmt);
|
|
161451
161487
|
auto result = make_unique<DeleteStatement>();
|
|
161488
|
+
if (stmt->withClause) {
|
|
161489
|
+
TransformCTE(reinterpret_cast<duckdb_libpgquery::PGWithClause *>(stmt->withClause), result->cte_map);
|
|
161490
|
+
}
|
|
161452
161491
|
|
|
161453
161492
|
result->condition = TransformExpression(stmt->whereClause);
|
|
161454
161493
|
result->table = TransformRangeVar(stmt->relation);
|
|
@@ -161625,8 +161664,14 @@ unique_ptr<InsertStatement> Transformer::TransformInsert(duckdb_libpgquery::PGNo
|
|
|
161625
161664
|
if (stmt->onConflictClause && stmt->onConflictClause->action != duckdb_libpgquery::PG_ONCONFLICT_NONE) {
|
|
161626
161665
|
throw ParserException("ON CONFLICT IGNORE/UPDATE clauses are not supported");
|
|
161627
161666
|
}
|
|
161667
|
+
if (!stmt->selectStmt) {
|
|
161668
|
+
throw ParserException("DEFAULT VALUES clause is not supported!");
|
|
161669
|
+
}
|
|
161628
161670
|
|
|
161629
161671
|
auto result = make_unique<InsertStatement>();
|
|
161672
|
+
if (stmt->withClause) {
|
|
161673
|
+
TransformCTE(reinterpret_cast<duckdb_libpgquery::PGWithClause *>(stmt->withClause), result->cte_map);
|
|
161674
|
+
}
|
|
161630
161675
|
|
|
161631
161676
|
// first check if there are any columns specified
|
|
161632
161677
|
if (stmt->cols) {
|
|
@@ -161936,7 +161981,7 @@ unique_ptr<QueryNode> Transformer::TransformSelectNode(duckdb_libpgquery::PGSele
|
|
|
161936
161981
|
node = make_unique<SelectNode>();
|
|
161937
161982
|
auto result = (SelectNode *)node.get();
|
|
161938
161983
|
if (stmt->withClause) {
|
|
161939
|
-
TransformCTE(reinterpret_cast<duckdb_libpgquery::PGWithClause *>(stmt->withClause),
|
|
161984
|
+
TransformCTE(reinterpret_cast<duckdb_libpgquery::PGWithClause *>(stmt->withClause), node->cte_map);
|
|
161940
161985
|
}
|
|
161941
161986
|
if (stmt->windowClause) {
|
|
161942
161987
|
for (auto window_ele = stmt->windowClause->head; window_ele != nullptr; window_ele = window_ele->next) {
|
|
@@ -161998,7 +162043,7 @@ unique_ptr<QueryNode> Transformer::TransformSelectNode(duckdb_libpgquery::PGSele
|
|
|
161998
162043
|
node = make_unique<SetOperationNode>();
|
|
161999
162044
|
auto result = (SetOperationNode *)node.get();
|
|
162000
162045
|
if (stmt->withClause) {
|
|
162001
|
-
TransformCTE(reinterpret_cast<duckdb_libpgquery::PGWithClause *>(stmt->withClause),
|
|
162046
|
+
TransformCTE(reinterpret_cast<duckdb_libpgquery::PGWithClause *>(stmt->withClause), node->cte_map);
|
|
162002
162047
|
}
|
|
162003
162048
|
result->left = TransformSelectNode(stmt->larg);
|
|
162004
162049
|
result->right = TransformSelectNode(stmt->rarg);
|
|
@@ -162217,6 +162262,9 @@ unique_ptr<UpdateStatement> Transformer::TransformUpdate(duckdb_libpgquery::PGNo
|
|
|
162217
162262
|
D_ASSERT(stmt);
|
|
162218
162263
|
|
|
162219
162264
|
auto result = make_unique<UpdateStatement>();
|
|
162265
|
+
if (stmt->withClause) {
|
|
162266
|
+
TransformCTE(reinterpret_cast<duckdb_libpgquery::PGWithClause *>(stmt->withClause), result->cte_map);
|
|
162267
|
+
}
|
|
162220
162268
|
|
|
162221
162269
|
result->table = TransformRangeVar(stmt->relation);
|
|
162222
162270
|
if (stmt->fromClause) {
|
|
@@ -167845,6 +167893,9 @@ BoundStatement Binder::Bind(DeleteStatement &stmt) {
|
|
|
167845
167893
|
properties.read_only = false;
|
|
167846
167894
|
}
|
|
167847
167895
|
|
|
167896
|
+
// Add CTEs as bindable
|
|
167897
|
+
AddCTEMap(stmt.cte_map);
|
|
167898
|
+
|
|
167848
167899
|
// plan any tables from the various using clauses
|
|
167849
167900
|
if (!stmt.using_clauses.empty()) {
|
|
167850
167901
|
unique_ptr<LogicalOperator> child_operator;
|
|
@@ -168291,6 +168342,9 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
|
|
|
168291
168342
|
|
|
168292
168343
|
auto insert = make_unique<LogicalInsert>(table);
|
|
168293
168344
|
|
|
168345
|
+
// Add CTEs as bindable
|
|
168346
|
+
AddCTEMap(stmt.cte_map);
|
|
168347
|
+
|
|
168294
168348
|
idx_t generated_column_count = 0;
|
|
168295
168349
|
vector<idx_t> named_column_map;
|
|
168296
168350
|
if (!stmt.columns.empty()) {
|
|
@@ -168912,6 +168966,9 @@ BoundStatement Binder::Bind(UpdateStatement &stmt) {
|
|
|
168912
168966
|
auto &table_binding = (BoundBaseTableRef &)*bound_table;
|
|
168913
168967
|
auto table = table_binding.table;
|
|
168914
168968
|
|
|
168969
|
+
// Add CTEs as bindable
|
|
168970
|
+
AddCTEMap(stmt.cte_map);
|
|
168971
|
+
|
|
168915
168972
|
if (stmt.from_table) {
|
|
168916
168973
|
BoundCrossProductRef bound_crossproduct;
|
|
168917
168974
|
bound_crossproduct.left = move(bound_table);
|
|
@@ -170413,11 +170470,15 @@ BoundStatement Binder::Bind(SQLStatement &statement) {
|
|
|
170413
170470
|
} // LCOV_EXCL_STOP
|
|
170414
170471
|
}
|
|
170415
170472
|
|
|
170416
|
-
|
|
170417
|
-
|
|
170418
|
-
for (auto &cte_it : node.cte_map) {
|
|
170473
|
+
void Binder::AddCTEMap(CommonTableExpressionMap &cte_map) {
|
|
170474
|
+
for (auto &cte_it : cte_map.map) {
|
|
170419
170475
|
AddCTE(cte_it.first, cte_it.second.get());
|
|
170420
170476
|
}
|
|
170477
|
+
}
|
|
170478
|
+
|
|
170479
|
+
unique_ptr<BoundQueryNode> Binder::BindNode(QueryNode &node) {
|
|
170480
|
+
// first we visit the set of CTEs and add them to the bind context
|
|
170481
|
+
AddCTEMap(node.cte_map);
|
|
170421
170482
|
// now we bind the node
|
|
170422
170483
|
unique_ptr<BoundQueryNode> result;
|
|
170423
170484
|
switch (node.type) {
|