Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store unqualified macro parameters, qualify before binding #10266

Merged
merged 2 commits into from
Jan 18, 2024
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
5 changes: 5 additions & 0 deletions src/planner/binder/expression/bind_macro_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ BindResult ExpressionBinder::BindMacro(FunctionExpression &function, ScalarMacro
// replace current expression with stored macro expression
expr = macro_def.expression->Copy();

// qualify only the macro parameters with a new empty binder that only knows the macro binding
auto dummy_binder = Binder::CreateBinder(context);
dummy_binder->macro_binding = new_macro_binding.get();
ExpressionBinder::QualifyColumnNames(*dummy_binder, expr);

// now replace the parameters
vector<unordered_set<string>> lambda_params;
ReplaceMacroParameters(expr, lambda_params);
Expand Down
2 changes: 1 addition & 1 deletion src/planner/binder/statement/bind_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ SchemaCatalogEntry &Binder::BindCreateFunctionInfo(CreateInfo &info) {
}
auto this_macro_binding = make_uniq<DummyBinding>(dummy_types, dummy_names, base.name);
macro_binding = this_macro_binding.get();
ExpressionBinder::QualifyColumnNames(*this, scalar_function.expression);

// create a copy of the expression because we do not want to alter the original
auto expression = scalar_function.expression->Copy();
ExpressionBinder::QualifyColumnNames(*this, expression);

// bind it to verify the function was defined correctly
string error;
Expand Down
21 changes: 21 additions & 0 deletions test/sql/catalog/function/test_simple_macro.test
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,24 @@ SELECT my_macro(x := 42);
statement error
SELECT my_macro(a := 42, a := 42);
----

# internal issue 1044
statement ok
create macro zz1(x) as (select 10+x);

statement ok
create macro zz2(x) as 20+x;

query II
select zz1(1),zz2(2);
----
11 22

# should not return any results (because we shouldn't display "macro_parameters"
query III
select function_name, parameters, macro_definition
from duckdb_functions()
where function_name like 'zz%'
and macro_definition like '%macro_parameters%';
----

Loading