-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[CT-968] [Feature] Disallow “view” materialization if Python #5569
Comments
Copying idea shared in Slack thread
This is a pattern I could see wanting to extend for other things that are implicit in their macro code today. E.g.
We have syntax today to "tag" (?) materializations with their intended adapter support:
Maybe there's something we could use/extend here?
Behind the scenes, dbt uses those not-quite-arguments to construct the actual macro name (e.g. dbt-core/core/dbt/clients/jinja.py Lines 345 to 374 in 1071a46
|
The place in the code (runtime) where the validation error should raise: Lines 256 to 266 in 40b55ed
why do this?If we don't do this, dbt does this: create view ... as (
... python code ...
) Which is a very confusing message for end users :) |
Updates that came from some pairing time with @stu-k today: If we write our materialization macro as something like: {% materialization seed, adapter='snowflake', language=['sql'] %}
actual logic
{% endmaterialization %} we can just parse out the args and also add a default value for things that doesn't have language specified by updating part of the parsing code from dbt-core/core/dbt/clients/jinja.py Lines 345 to 374 in 1071a46
into def parse(self, parser):
node = jinja2.nodes.Macro(lineno=next(parser.stream).lineno)
materialization_name = parser.parse_assign_target(name_only=True).name
adapter_name = "default"
node.args = []
node.defaults = []
while parser.stream.skip_if("comma"):
target = parser.parse_assign_target(name_only=True)
if target.name == "default":
pass
elif target.name == "adapter":
parser.stream.expect("assign")
value = parser.parse_expression()
adapter_name = value.value
elif target.name == "language":
parser.stream.expect("assign")
value = parser.parse_expression()
target.set_ctx("param")
node.args.append(target)
node.defaults.append(value)
else:
invalid_materialization_argument(materialization_name, target.name)
if not node.args:
node.args = [jinja2.nodes.Name("language", "store")]
node.defaults = [jinja2.nodes.List([jinja2.nodes.Const('sql')])]
node.name = get_materialization_macro_name(materialization_name, adapter_name)
node.body = parser.parse_statements(("name:endmaterialization",), drop_needle=True)
return node Then Note that this part of the parsing actually doesn't look into any of the body of materialization macro. It just look up the function definition and originally only used to get the name. The code that calls the parsing logic above is the following dbt-core/core/dbt/parser/macros.py Lines 69 to 89 in a7ff003
You can see macro_name is being passed to create a ParsedMacro. We can add an optional attribute in ParsedMacro to store the supported language, then check that and model's language at where @jtcohen6 linked above. @gshank any suggestions on better ways of doing this is welcomed. I feel like we are abusing those attributes a bit but not too sure what's the better way to do it |
Is this your first time opening an issue?
Describe the Feature
Current dbt python model doesn't support view materialization. But instead of raise a clear error, it will try to run python code with sql together.
Describe alternatives you've considered
Add check for language in materialization code- meaning we will have to update a lot of them
Who will this benefit?
python model user
Are you interested in contributing this feature?
Yes
Anything else?
No response
The text was updated successfully, but these errors were encountered: