Josh
02/26/2024, 12:41 PMeager
or lazy
but by using explicit rulesScout
02/26/2024, 12:41 PMeager
or lazy
policies, you can construct an AutoMaterializePolicy
and then add or remove rules using the with_rules
and without_rules
methods. Here's how you can do it according to the documentation: 1. Adding Rules: To add rules to an auto-materialization policy, you can use the with_rules
method. This constructs a copy of the policy with the specified rules added. If an instance of a provided rule with the same type exists on this policy, it will be replaced. python from dagster import AutoMaterializePolicy, AutoMaterializeRule, asset # Construct an AutoMaterializePolicy and add custom rules custom_policy = AutoMaterializePolicy.eager().with_rules( AutoMaterializeRule.your_custom_rule() ) @asset(auto_materialize_policy=custom_policy) def your_asset(): ...
2. Removing Rules: To remove rules from an auto-materialization policy, you can use the without_rules
method. This constructs a copy of the policy with the specified rules removed. An error is raised if any of the arguments are not rules in this policy. python from dagster import AutoMaterializePolicy, AutoMaterializeRule, asset # Construct an AutoMaterializePolicy and remove specific rules custom_policy = AutoMaterializePolicy.eager().without_rules( AutoMaterializeRule.rule_to_remove() ) @asset(auto_materialize_policy=custom_policy) def your_asset(): ...
Remember that constructing an AutoMaterializePolicy
directly is not recommended as the API is subject to change. It is better to use AutoMaterializePolicy.eager()
or AutoMaterializePolicy.lazy()
as a starting point and then modify them with with_rules
or without_rules
as needed. Please note that the actual rule names like your_custom_rule
and rule_to_remove
are placeholders. You should replace them with actual AutoMaterializeRule
methods that correspond to the rules you want to add or remove. For example, AutoMaterializeRule.skip_on_not_all_parents_updated()
is a real rule that you can use with with_rules
to ensure that an asset is only materialized when all of its parents have been updated.