Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ concurrency:
cancel-in-progress: true

jobs:
# duckdb-next-build:
# name: Build extension binaries
# uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
# with:
# duckdb_version: main
# ci_tools_version: main
# extension_name: parser_tools
duckdb-next-build:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
with:
duckdb_version: main
ci_tools_version: main
extension_name: parser_tools

duckdb-stable-build:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.3.0
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.4.0
with:
duckdb_version: v1.3.0
ci_tools_version: v1.3.0
duckdb_version: v1.4.0
ci_tools_version: v1.4.0
extension_name: parser_tools
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 3475 files
6 changes: 3 additions & 3 deletions src/include/parse_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
namespace duckdb {

// Forward declarations
class DatabaseInstance;
class ExtensionLoader;

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

void RegisterParseFunctionsFunction(DatabaseInstance &db);
void RegisterParseFunctionScalarFunction(DatabaseInstance &db);
void RegisterParseFunctionsFunction(ExtensionLoader &loader);
void RegisterParseFunctionScalarFunction(ExtensionLoader &loader);

} // namespace duckdb
4 changes: 2 additions & 2 deletions src/include/parse_tables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void ExtractTablesFromQueryNode(
const duckdb::CommonTableExpressionMap *cte_map = nullptr
);

void RegisterParseTablesFunction(duckdb::DatabaseInstance &db);
void RegisterParseTableScalarFunction(DatabaseInstance &db);
void RegisterParseTablesFunction(duckdb::ExtensionLoader &loader);
void RegisterParseTableScalarFunction(ExtensionLoader &loader);

} // namespace duckdb
8 changes: 4 additions & 4 deletions src/include/parse_where.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace duckdb {

// Forward declarations
class DatabaseInstance;
class ExtensionLoader;

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

void RegisterParseWhereFunction(DatabaseInstance &db);
void RegisterParseWhereScalarFunction(DatabaseInstance &db);
void RegisterParseWhereDetailedFunction(DatabaseInstance &db);
void RegisterParseWhereFunction(ExtensionLoader &loader);
void RegisterParseWhereScalarFunction(ExtensionLoader &loader);
void RegisterParseWhereDetailedFunction(ExtensionLoader &loader);

} // namespace duckdb
2 changes: 1 addition & 1 deletion src/include/parser_tools_extension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace duckdb {

class ParserToolsExtension : public Extension {
public:
void Load(DuckDB &db) override;
void Load(ExtensionLoader &loader) override;
std::string Name() override;
std::string Version() const override;
};
Expand Down
21 changes: 14 additions & 7 deletions src/parse_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#include "duckdb.hpp"
#include "duckdb/parser/parser.hpp"
#include "duckdb/parser/statement/select_statement.hpp"
#include "duckdb/parser/query_node/cte_node.hpp"
#include "duckdb/parser/query_node/select_node.hpp"
#include "duckdb/parser/expression/function_expression.hpp"
#include "duckdb/parser/expression/window_expression.hpp"
#include "duckdb/parser/parsed_expression_iterator.hpp"
#include "duckdb/parser/result_modifier.hpp"
#include "duckdb/main/extension_util.hpp"
#include "duckdb/function/scalar/nested_functions.hpp"


Expand Down Expand Up @@ -202,7 +202,14 @@ static void ExtractFunctionsFromQueryNode(const QueryNode &node, std::vector<Fun
}
}
}
}
// additional step necessary for duckdb v1.4.0: unwrap CTE node
} else if (node.type == QueryNodeType::CTE_NODE) {
auto &cte_node = (CTENode &)node;

if (cte_node.child) {
ExtractFunctionsFromQueryNode(*cte_node.child, results);
}
}
}

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

void RegisterParseFunctionsFunction(DatabaseInstance &db) {
void RegisterParseFunctionsFunction(ExtensionLoader &loader) {
TableFunction tf("parse_functions", {LogicalType::VARCHAR}, ParseFunctionsFunction, ParseFunctionsBind, ParseFunctionsInit);
ExtensionUtil::RegisterFunction(db, tf);
loader.RegisterFunction(tf);
}

void RegisterParseFunctionScalarFunction(DatabaseInstance &db) {
void RegisterParseFunctionScalarFunction(ExtensionLoader &loader) {
// parse_function_names is a scalar function that returns a list of function names
ScalarFunction sf("parse_function_names", {LogicalType::VARCHAR}, LogicalType::LIST(LogicalType::VARCHAR), ParseFunctionNamesScalarFunction);
ExtensionUtil::RegisterFunction(db, sf);
loader.RegisterFunction(sf);

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


Expand Down
31 changes: 20 additions & 11 deletions src/parse_tables.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include "parse_tables.hpp"
#include "duckdb.hpp"
#include "duckdb/parser/parser.hpp"
#include "duckdb/parser/parser_options.hpp"
#include <algorithm>
#include <cctype>
#include "duckdb/parser/statement/select_statement.hpp"
#include "duckdb/parser/query_node/select_node.hpp"
#include "duckdb/parser/query_node/cte_node.hpp"
#include "duckdb/parser/tableref/basetableref.hpp"
#include "duckdb/parser/tableref/joinref.hpp"
#include "duckdb/parser/tableref/subqueryref.hpp"
#include "duckdb/main/extension_util.hpp"
#include "duckdb/function/scalar/nested_functions.hpp"


namespace duckdb {

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

// Emit CTE definitions
// Handle CTE definitions
for (const auto &entry : select_node.cte_map.map) {
results.push_back(TableRefResult{
"", entry.first, TableContext::CTE
Expand All @@ -142,6 +144,14 @@ static void ExtractTablesFromQueryNode(
if (select_node.from_table) {
ExtractTablesFromRef(*select_node.from_table, results, context, true, &select_node.cte_map);
}
}
// additional step necessary for duckdb v1.4.0: unwrap CTE node
else if (node.type == QueryNodeType::CTE_NODE) {
auto &cte_node = (CTENode &)node;

if (cte_node.child) {
ExtractTablesFromQueryNode(*cte_node.child, results, context, cte_map);
}
}
}

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


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

void RegisterParseTablesFunction(DatabaseInstance &db) {
void RegisterParseTablesFunction(ExtensionLoader &loader) {
TableFunction tf("parse_tables", {LogicalType::VARCHAR}, ParseTablesFunction, ParseTablesBind, ParseTablesInit);
ExtensionUtil::RegisterFunction(db, tf);
loader.RegisterFunction(tf);
}

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

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

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

} // namespace duckdb
13 changes: 6 additions & 7 deletions src/parse_where.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "duckdb/parser/expression/positional_reference_expression.hpp"
#include "duckdb/parser/expression/parameter_expression.hpp"
#include "duckdb/parser/tableref/basetableref.hpp"
#include "duckdb/main/extension_util.hpp"

namespace duckdb {

Expand Down Expand Up @@ -236,19 +235,19 @@ static void ParseWhereScalarFunction(DataChunk &args, ExpressionState &state, Ve
});
}

void RegisterParseWhereFunction(DatabaseInstance &db) {
void RegisterParseWhereFunction(ExtensionLoader &loader) {
TableFunction tf("parse_where", {LogicalType::VARCHAR}, ParseWhereFunction, ParseWhereBind, ParseWhereInit);
ExtensionUtil::RegisterFunction(db, tf);
loader.RegisterFunction(tf);
}

void RegisterParseWhereScalarFunction(DatabaseInstance &db) {
void RegisterParseWhereScalarFunction(ExtensionLoader &loader) {
auto return_type = LogicalType::LIST(LogicalType::STRUCT({
{"condition", LogicalType::VARCHAR},
{"table_name", LogicalType::VARCHAR},
{"context", LogicalType::VARCHAR}
}));
ScalarFunction sf("parse_where", {LogicalType::VARCHAR}, return_type, ParseWhereScalarFunction);
ExtensionUtil::RegisterFunction(db, sf);
loader.RegisterFunction(sf);
}

static string DetailedExpressionTypeToOperator(ExpressionType type) {
Expand Down Expand Up @@ -476,9 +475,9 @@ static void ParseWhereDetailedFunction(ClientContext &context,
state.row++;
}

void RegisterParseWhereDetailedFunction(DatabaseInstance &db) {
void RegisterParseWhereDetailedFunction(ExtensionLoader &loader) {
TableFunction tf("parse_where_detailed", {LogicalType::VARCHAR}, ParseWhereDetailedFunction, ParseWhereDetailedBind, ParseWhereDetailedInit);
ExtensionUtil::RegisterFunction(db, tf);
loader.RegisterFunction(tf);
}

} // namespace duckdb
32 changes: 12 additions & 20 deletions src/parser_tools_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ namespace duckdb {
// ---------------------------------------------------
// EXTENSION SCAFFOLDING

static void LoadInternal(DatabaseInstance &instance) {
RegisterParseTablesFunction(instance);
RegisterParseTableScalarFunction(instance);
RegisterParseWhereFunction(instance);
RegisterParseWhereScalarFunction(instance);
RegisterParseWhereDetailedFunction(instance);
RegisterParseFunctionsFunction(instance);
RegisterParseFunctionScalarFunction(instance);
static void LoadInternal(ExtensionLoader &loader) {
RegisterParseTablesFunction(loader);
RegisterParseTableScalarFunction(loader);
RegisterParseWhereFunction(loader);
RegisterParseWhereScalarFunction(loader);
RegisterParseWhereDetailedFunction(loader);
RegisterParseFunctionsFunction(loader);
RegisterParseFunctionScalarFunction(loader);
}

void ParserToolsExtension::Load(DuckDB &db) {
LoadInternal(*db.instance);
void ParserToolsExtension::Load(ExtensionLoader &loader) {
LoadInternal(loader);
}

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

extern "C" {

DUCKDB_EXTENSION_API void parser_tools_init(duckdb::DatabaseInstance &db) {
duckdb::DuckDB db_wrapper(db);
db_wrapper.LoadExtension<duckdb::ParserToolsExtension>();
DUCKDB_CPP_EXTENSION_ENTRY(parser_tools, loader) {
duckdb::LoadInternal(loader);
}

DUCKDB_EXTENSION_API const char *parser_tools_version() {
return duckdb::DuckDB::LibraryVersion();
}
}

#ifndef DUCKDB_EXTENSION_MAIN
#error DUCKDB_EXTENSION_MAIN not defined
#endif
Loading