Skip to content

Commit da3e91e

Browse files
authored
Merge pull request #7 from zfarrell/1.4.0
Upgrade parser_tools to support duckdb 1.4.0
2 parents e4da802 + 3981edb commit da3e91e

File tree

10 files changed

+73
-66
lines changed

10 files changed

+73
-66
lines changed

.github/workflows/MainDistributionPipeline.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15-
# duckdb-next-build:
16-
# name: Build extension binaries
17-
# uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
18-
# with:
19-
# duckdb_version: main
20-
# ci_tools_version: main
21-
# extension_name: parser_tools
15+
duckdb-next-build:
16+
name: Build extension binaries
17+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
18+
with:
19+
duckdb_version: main
20+
ci_tools_version: main
21+
extension_name: parser_tools
2222

2323
duckdb-stable-build:
2424
name: Build extension binaries
25-
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.3.0
25+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.4.0
2626
with:
27-
duckdb_version: v1.3.0
28-
ci_tools_version: v1.3.0
27+
duckdb_version: v1.4.0
28+
ci_tools_version: v1.4.0
2929
extension_name: parser_tools

duckdb

Submodule duckdb updated 3475 files

src/include/parse_functions.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
namespace duckdb {
88

99
// Forward declarations
10-
class DatabaseInstance;
10+
class ExtensionLoader;
1111

1212
struct FunctionResult {
1313
std::string function_name;
1414
std::string schema;
1515
std::string context; // The context where this function appears (SELECT, WHERE, etc.)
1616
};
1717

18-
void RegisterParseFunctionsFunction(DatabaseInstance &db);
19-
void RegisterParseFunctionScalarFunction(DatabaseInstance &db);
18+
void RegisterParseFunctionsFunction(ExtensionLoader &loader);
19+
void RegisterParseFunctionScalarFunction(ExtensionLoader &loader);
2020

2121
} // namespace duckdb

src/include/parse_tables.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void ExtractTablesFromQueryNode(
3333
const duckdb::CommonTableExpressionMap *cte_map = nullptr
3434
);
3535

36-
void RegisterParseTablesFunction(duckdb::DatabaseInstance &db);
37-
void RegisterParseTableScalarFunction(DatabaseInstance &db);
36+
void RegisterParseTablesFunction(duckdb::ExtensionLoader &loader);
37+
void RegisterParseTableScalarFunction(ExtensionLoader &loader);
3838

3939
} // namespace duckdb

src/include/parse_where.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace duckdb {
88

99
// Forward declarations
10-
class DatabaseInstance;
10+
class ExtensionLoader;
1111

1212
struct WhereConditionResult {
1313
std::string condition;
@@ -23,8 +23,8 @@ struct DetailedWhereConditionResult {
2323
std::string context; // The context where this condition appears (WHERE, HAVING, etc.)
2424
};
2525

26-
void RegisterParseWhereFunction(DatabaseInstance &db);
27-
void RegisterParseWhereScalarFunction(DatabaseInstance &db);
28-
void RegisterParseWhereDetailedFunction(DatabaseInstance &db);
26+
void RegisterParseWhereFunction(ExtensionLoader &loader);
27+
void RegisterParseWhereScalarFunction(ExtensionLoader &loader);
28+
void RegisterParseWhereDetailedFunction(ExtensionLoader &loader);
2929

3030
} // namespace duckdb

src/include/parser_tools_extension.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace duckdb {
66

77
class ParserToolsExtension : public Extension {
88
public:
9-
void Load(DuckDB &db) override;
9+
void Load(ExtensionLoader &loader) override;
1010
std::string Name() override;
1111
std::string Version() const override;
1212
};

src/parse_functions.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#include "duckdb.hpp"
33
#include "duckdb/parser/parser.hpp"
44
#include "duckdb/parser/statement/select_statement.hpp"
5+
#include "duckdb/parser/query_node/cte_node.hpp"
56
#include "duckdb/parser/query_node/select_node.hpp"
67
#include "duckdb/parser/expression/function_expression.hpp"
78
#include "duckdb/parser/expression/window_expression.hpp"
89
#include "duckdb/parser/parsed_expression_iterator.hpp"
910
#include "duckdb/parser/result_modifier.hpp"
10-
#include "duckdb/main/extension_util.hpp"
1111
#include "duckdb/function/scalar/nested_functions.hpp"
1212

1313

@@ -202,7 +202,14 @@ static void ExtractFunctionsFromQueryNode(const QueryNode &node, std::vector<Fun
202202
}
203203
}
204204
}
205-
}
205+
// additional step necessary for duckdb v1.4.0: unwrap CTE node
206+
} else if (node.type == QueryNodeType::CTE_NODE) {
207+
auto &cte_node = (CTENode &)node;
208+
209+
if (cte_node.child) {
210+
ExtractFunctionsFromQueryNode(*cte_node.child, results);
211+
}
212+
}
206213
}
207214

208215
static void ExtractFunctionsFromSQL(const std::string &sql, std::vector<FunctionResult> &results) {
@@ -328,15 +335,15 @@ static void ParseFunctionsScalarFunction_struct(DataChunk &args, ExpressionState
328335
// Extension scaffolding
329336
// ---------------------------------------------------
330337

331-
void RegisterParseFunctionsFunction(DatabaseInstance &db) {
338+
void RegisterParseFunctionsFunction(ExtensionLoader &loader) {
332339
TableFunction tf("parse_functions", {LogicalType::VARCHAR}, ParseFunctionsFunction, ParseFunctionsBind, ParseFunctionsInit);
333-
ExtensionUtil::RegisterFunction(db, tf);
340+
loader.RegisterFunction(tf);
334341
}
335342

336-
void RegisterParseFunctionScalarFunction(DatabaseInstance &db) {
343+
void RegisterParseFunctionScalarFunction(ExtensionLoader &loader) {
337344
// parse_function_names is a scalar function that returns a list of function names
338345
ScalarFunction sf("parse_function_names", {LogicalType::VARCHAR}, LogicalType::LIST(LogicalType::VARCHAR), ParseFunctionNamesScalarFunction);
339-
ExtensionUtil::RegisterFunction(db, sf);
346+
loader.RegisterFunction(sf);
340347

341348
// parse_functions_struct is a scalar function that returns a list of structs
342349
auto return_type = LogicalType::LIST(LogicalType::STRUCT({
@@ -345,7 +352,7 @@ void RegisterParseFunctionScalarFunction(DatabaseInstance &db) {
345352
{"context", LogicalType::VARCHAR}
346353
}));
347354
ScalarFunction sf_struct("parse_functions", {LogicalType::VARCHAR}, return_type, ParseFunctionsScalarFunction_struct);
348-
ExtensionUtil::RegisterFunction(db, sf_struct);
355+
loader.RegisterFunction(sf_struct);
349356
}
350357

351358

src/parse_tables.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#include "parse_tables.hpp"
22
#include "duckdb.hpp"
33
#include "duckdb/parser/parser.hpp"
4+
#include "duckdb/parser/parser_options.hpp"
5+
#include <algorithm>
6+
#include <cctype>
47
#include "duckdb/parser/statement/select_statement.hpp"
58
#include "duckdb/parser/query_node/select_node.hpp"
9+
#include "duckdb/parser/query_node/cte_node.hpp"
610
#include "duckdb/parser/tableref/basetableref.hpp"
711
#include "duckdb/parser/tableref/joinref.hpp"
812
#include "duckdb/parser/tableref/subqueryref.hpp"
9-
#include "duckdb/main/extension_util.hpp"
1013
#include "duckdb/function/scalar/nested_functions.hpp"
1114

12-
1315
namespace duckdb {
1416

1517
inline const char *ToString(TableContext context) {
@@ -128,7 +130,7 @@ static void ExtractTablesFromQueryNode(
128130
if (node.type == QueryNodeType::SELECT_NODE) {
129131
auto &select_node = (SelectNode &)node;
130132

131-
// Emit CTE definitions
133+
// Handle CTE definitions
132134
for (const auto &entry : select_node.cte_map.map) {
133135
results.push_back(TableRefResult{
134136
"", entry.first, TableContext::CTE
@@ -142,6 +144,14 @@ static void ExtractTablesFromQueryNode(
142144
if (select_node.from_table) {
143145
ExtractTablesFromRef(*select_node.from_table, results, context, true, &select_node.cte_map);
144146
}
147+
}
148+
// additional step necessary for duckdb v1.4.0: unwrap CTE node
149+
else if (node.type == QueryNodeType::CTE_NODE) {
150+
auto &cte_node = (CTENode &)node;
151+
152+
if (cte_node.child) {
153+
ExtractTablesFromQueryNode(*cte_node.child, results, context, cte_map);
154+
}
145155
}
146156
}
147157

@@ -152,9 +162,8 @@ static void ExtractTablesFromSQL(const std::string &sql, std::vector<TableRefRes
152162
parser.ParseQuery(sql);
153163
} catch (const ParserException &ex) {
154164
// swallow parser exceptions to make this function more robust. is_parsable can be used if needed
155-
return;
165+
return;
156166
}
157-
158167

159168
for (auto &stmt : parser.statements) {
160169
if (stmt->type == StatementType::SELECT_STATEMENT) {
@@ -323,19 +332,19 @@ static void IsParsableFunction(DataChunk &args, ExpressionState &state, Vector &
323332
// Extension scaffolding
324333
// ---------------------------------------------------
325334

326-
void RegisterParseTablesFunction(DatabaseInstance &db) {
335+
void RegisterParseTablesFunction(ExtensionLoader &loader) {
327336
TableFunction tf("parse_tables", {LogicalType::VARCHAR}, ParseTablesFunction, ParseTablesBind, ParseTablesInit);
328-
ExtensionUtil::RegisterFunction(db, tf);
337+
loader.RegisterFunction(tf);
329338
}
330339

331-
void RegisterParseTableScalarFunction(DatabaseInstance &db) {
340+
void RegisterParseTableScalarFunction(ExtensionLoader &loader) {
332341
// parse_table_names is overloaded, allowing for an optional boolean argument
333342
// that indicates whether to include CTEs in the result
334343
// usage: parse_tables(sql_query [, include_cte])
335344
ScalarFunctionSet set("parse_table_names");
336345
set.AddFunction(ScalarFunction({LogicalType::VARCHAR}, LogicalType::LIST(LogicalType::VARCHAR), ParseTablesScalarFunction));
337346
set.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::BOOLEAN}, LogicalType::LIST(LogicalType::VARCHAR), ParseTablesScalarFunction));
338-
ExtensionUtil::RegisterFunction(db, set);
347+
loader.RegisterFunction(set);
339348

340349
// parse_tables_struct is a scalar function that returns a list of structs
341350
auto return_type = LogicalType::LIST(LogicalType::STRUCT({
@@ -344,11 +353,11 @@ void RegisterParseTableScalarFunction(DatabaseInstance &db) {
344353
{"context", LogicalType::VARCHAR}
345354
}));
346355
ScalarFunction sf("parse_tables", {LogicalType::VARCHAR}, return_type, ParseTablesScalarFunction_struct);
347-
ExtensionUtil::RegisterFunction(db, sf);
356+
loader.RegisterFunction(sf);
348357

349358
// is_parsable is a scalar function that returns a boolean indicating whether the SQL query is parsable (no parse errors)
350359
ScalarFunction is_parsable("is_parsable", {LogicalType::VARCHAR}, LogicalType::BOOLEAN, IsParsableFunction);
351-
ExtensionUtil::RegisterFunction(db, is_parsable);
360+
loader.RegisterFunction(is_parsable);
352361
}
353362

354363
} // namespace duckdb

src/parse_where.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "duckdb/parser/expression/positional_reference_expression.hpp"
2020
#include "duckdb/parser/expression/parameter_expression.hpp"
2121
#include "duckdb/parser/tableref/basetableref.hpp"
22-
#include "duckdb/main/extension_util.hpp"
2322

2423
namespace duckdb {
2524

@@ -236,19 +235,19 @@ static void ParseWhereScalarFunction(DataChunk &args, ExpressionState &state, Ve
236235
});
237236
}
238237

239-
void RegisterParseWhereFunction(DatabaseInstance &db) {
238+
void RegisterParseWhereFunction(ExtensionLoader &loader) {
240239
TableFunction tf("parse_where", {LogicalType::VARCHAR}, ParseWhereFunction, ParseWhereBind, ParseWhereInit);
241-
ExtensionUtil::RegisterFunction(db, tf);
240+
loader.RegisterFunction(tf);
242241
}
243242

244-
void RegisterParseWhereScalarFunction(DatabaseInstance &db) {
243+
void RegisterParseWhereScalarFunction(ExtensionLoader &loader) {
245244
auto return_type = LogicalType::LIST(LogicalType::STRUCT({
246245
{"condition", LogicalType::VARCHAR},
247246
{"table_name", LogicalType::VARCHAR},
248247
{"context", LogicalType::VARCHAR}
249248
}));
250249
ScalarFunction sf("parse_where", {LogicalType::VARCHAR}, return_type, ParseWhereScalarFunction);
251-
ExtensionUtil::RegisterFunction(db, sf);
250+
loader.RegisterFunction(sf);
252251
}
253252

254253
static string DetailedExpressionTypeToOperator(ExpressionType type) {
@@ -476,9 +475,9 @@ static void ParseWhereDetailedFunction(ClientContext &context,
476475
state.row++;
477476
}
478477

479-
void RegisterParseWhereDetailedFunction(DatabaseInstance &db) {
478+
void RegisterParseWhereDetailedFunction(ExtensionLoader &loader) {
480479
TableFunction tf("parse_where_detailed", {LogicalType::VARCHAR}, ParseWhereDetailedFunction, ParseWhereDetailedBind, ParseWhereDetailedInit);
481-
ExtensionUtil::RegisterFunction(db, tf);
480+
loader.RegisterFunction(tf);
482481
}
483482

484483
} // namespace duckdb

src/parser_tools_extension.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ namespace duckdb {
2222
// ---------------------------------------------------
2323
// EXTENSION SCAFFOLDING
2424

25-
static void LoadInternal(DatabaseInstance &instance) {
26-
RegisterParseTablesFunction(instance);
27-
RegisterParseTableScalarFunction(instance);
28-
RegisterParseWhereFunction(instance);
29-
RegisterParseWhereScalarFunction(instance);
30-
RegisterParseWhereDetailedFunction(instance);
31-
RegisterParseFunctionsFunction(instance);
32-
RegisterParseFunctionScalarFunction(instance);
25+
static void LoadInternal(ExtensionLoader &loader) {
26+
RegisterParseTablesFunction(loader);
27+
RegisterParseTableScalarFunction(loader);
28+
RegisterParseWhereFunction(loader);
29+
RegisterParseWhereScalarFunction(loader);
30+
RegisterParseWhereDetailedFunction(loader);
31+
RegisterParseFunctionsFunction(loader);
32+
RegisterParseFunctionScalarFunction(loader);
3333
}
3434

35-
void ParserToolsExtension::Load(DuckDB &db) {
36-
LoadInternal(*db.instance);
35+
void ParserToolsExtension::Load(ExtensionLoader &loader) {
36+
LoadInternal(loader);
3737
}
3838

3939
std::string ParserToolsExtension::Name() {
@@ -52,16 +52,8 @@ std::string ParserToolsExtension::Version() const {
5252

5353
extern "C" {
5454

55-
DUCKDB_EXTENSION_API void parser_tools_init(duckdb::DatabaseInstance &db) {
56-
duckdb::DuckDB db_wrapper(db);
57-
db_wrapper.LoadExtension<duckdb::ParserToolsExtension>();
55+
DUCKDB_CPP_EXTENSION_ENTRY(parser_tools, loader) {
56+
duckdb::LoadInternal(loader);
5857
}
5958

60-
DUCKDB_EXTENSION_API const char *parser_tools_version() {
61-
return duckdb::DuckDB::LibraryVersion();
6259
}
63-
}
64-
65-
#ifndef DUCKDB_EXTENSION_MAIN
66-
#error DUCKDB_EXTENSION_MAIN not defined
67-
#endif

0 commit comments

Comments
 (0)