Skip to content

Commit edda2b2

Browse files
committed
initial updates to support new extension loader model
1 parent e4da802 commit edda2b2

File tree

10 files changed

+47
-49
lines changed

10 files changed

+47
-49
lines changed

.github/workflows/MainDistributionPipeline.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "duckdb/parser/expression/window_expression.hpp"
88
#include "duckdb/parser/parsed_expression_iterator.hpp"
99
#include "duckdb/parser/result_modifier.hpp"
10-
#include "duckdb/main/extension_util.hpp"
1110
#include "duckdb/function/scalar/nested_functions.hpp"
1211

1312

@@ -328,15 +327,15 @@ static void ParseFunctionsScalarFunction_struct(DataChunk &args, ExpressionState
328327
// Extension scaffolding
329328
// ---------------------------------------------------
330329

331-
void RegisterParseFunctionsFunction(DatabaseInstance &db) {
330+
void RegisterParseFunctionsFunction(ExtensionLoader &loader) {
332331
TableFunction tf("parse_functions", {LogicalType::VARCHAR}, ParseFunctionsFunction, ParseFunctionsBind, ParseFunctionsInit);
333-
ExtensionUtil::RegisterFunction(db, tf);
332+
loader.RegisterFunction(tf);
334333
}
335334

336-
void RegisterParseFunctionScalarFunction(DatabaseInstance &db) {
335+
void RegisterParseFunctionScalarFunction(ExtensionLoader &loader) {
337336
// parse_function_names is a scalar function that returns a list of function names
338337
ScalarFunction sf("parse_function_names", {LogicalType::VARCHAR}, LogicalType::LIST(LogicalType::VARCHAR), ParseFunctionNamesScalarFunction);
339-
ExtensionUtil::RegisterFunction(db, sf);
338+
loader.RegisterFunction(sf);
340339

341340
// parse_functions_struct is a scalar function that returns a list of structs
342341
auto return_type = LogicalType::LIST(LogicalType::STRUCT({
@@ -345,7 +344,7 @@ void RegisterParseFunctionScalarFunction(DatabaseInstance &db) {
345344
{"context", LogicalType::VARCHAR}
346345
}));
347346
ScalarFunction sf_struct("parse_functions", {LogicalType::VARCHAR}, return_type, ParseFunctionsScalarFunction_struct);
348-
ExtensionUtil::RegisterFunction(db, sf_struct);
347+
loader.RegisterFunction(sf_struct);
349348
}
350349

351350

src/parse_tables.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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"
69
#include "duckdb/parser/tableref/basetableref.hpp"
710
#include "duckdb/parser/tableref/joinref.hpp"
811
#include "duckdb/parser/tableref/subqueryref.hpp"
9-
#include "duckdb/main/extension_util.hpp"
1012
#include "duckdb/function/scalar/nested_functions.hpp"
1113

1214

@@ -152,9 +154,8 @@ static void ExtractTablesFromSQL(const std::string &sql, std::vector<TableRefRes
152154
parser.ParseQuery(sql);
153155
} catch (const ParserException &ex) {
154156
// swallow parser exceptions to make this function more robust. is_parsable can be used if needed
155-
return;
157+
return;
156158
}
157-
158159

159160
for (auto &stmt : parser.statements) {
160161
if (stmt->type == StatementType::SELECT_STATEMENT) {
@@ -323,19 +324,19 @@ static void IsParsableFunction(DataChunk &args, ExpressionState &state, Vector &
323324
// Extension scaffolding
324325
// ---------------------------------------------------
325326

326-
void RegisterParseTablesFunction(DatabaseInstance &db) {
327+
void RegisterParseTablesFunction(ExtensionLoader &loader) {
327328
TableFunction tf("parse_tables", {LogicalType::VARCHAR}, ParseTablesFunction, ParseTablesBind, ParseTablesInit);
328-
ExtensionUtil::RegisterFunction(db, tf);
329+
loader.RegisterFunction(tf);
329330
}
330331

331-
void RegisterParseTableScalarFunction(DatabaseInstance &db) {
332+
void RegisterParseTableScalarFunction(ExtensionLoader &loader) {
332333
// parse_table_names is overloaded, allowing for an optional boolean argument
333334
// that indicates whether to include CTEs in the result
334335
// usage: parse_tables(sql_query [, include_cte])
335336
ScalarFunctionSet set("parse_table_names");
336337
set.AddFunction(ScalarFunction({LogicalType::VARCHAR}, LogicalType::LIST(LogicalType::VARCHAR), ParseTablesScalarFunction));
337338
set.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::BOOLEAN}, LogicalType::LIST(LogicalType::VARCHAR), ParseTablesScalarFunction));
338-
ExtensionUtil::RegisterFunction(db, set);
339+
loader.RegisterFunction(set);
339340

340341
// parse_tables_struct is a scalar function that returns a list of structs
341342
auto return_type = LogicalType::LIST(LogicalType::STRUCT({
@@ -344,11 +345,11 @@ void RegisterParseTableScalarFunction(DatabaseInstance &db) {
344345
{"context", LogicalType::VARCHAR}
345346
}));
346347
ScalarFunction sf("parse_tables", {LogicalType::VARCHAR}, return_type, ParseTablesScalarFunction_struct);
347-
ExtensionUtil::RegisterFunction(db, sf);
348+
loader.RegisterFunction(sf);
348349

349350
// is_parsable is a scalar function that returns a boolean indicating whether the SQL query is parsable (no parse errors)
350351
ScalarFunction is_parsable("is_parsable", {LogicalType::VARCHAR}, LogicalType::BOOLEAN, IsParsableFunction);
351-
ExtensionUtil::RegisterFunction(db, is_parsable);
352+
loader.RegisterFunction(is_parsable);
352353
}
353354

354355
} // 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 & 13 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,9 +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

6059
DUCKDB_EXTENSION_API const char *parser_tools_version() {

0 commit comments

Comments
 (0)