|
8 | 8 | if TYPE_CHECKING: |
9 | 9 | from databricks.bundles.jobs._models.job import Job |
10 | 10 | from databricks.bundles.pipelines._models.pipeline import Pipeline |
| 11 | + from databricks.bundles.schemas._models.schema import Schema |
11 | 12 |
|
12 | 13 | _T = TypeVar("_T", bound=Resource) |
13 | 14 |
|
@@ -127,3 +128,35 @@ def my_pipeline_mutator(bundle: Bundle, pipeline: Pipeline) -> Pipeline: |
127 | 128 | from databricks.bundles.pipelines._models.pipeline import Pipeline |
128 | 129 |
|
129 | 130 | return ResourceMutator(resource_type=Pipeline, function=function) |
| 131 | + |
| 132 | + |
| 133 | +@overload |
| 134 | +def schema_mutator( |
| 135 | + function: Callable[[Bundle, "Schema"], "Schema"], |
| 136 | +) -> ResourceMutator["Schema"]: ... |
| 137 | + |
| 138 | + |
| 139 | +@overload |
| 140 | +def schema_mutator( |
| 141 | + function: Callable[["Schema"], "Schema"], |
| 142 | +) -> ResourceMutator["Schema"]: ... |
| 143 | + |
| 144 | + |
| 145 | +def schema_mutator(function: Callable) -> ResourceMutator["Schema"]: |
| 146 | + """ |
| 147 | + Decorator for defining a schema mutator. Function should return a new instance of the schema with the desired changes, |
| 148 | + instead of mutating the input schema. |
| 149 | +
|
| 150 | + Example: |
| 151 | +
|
| 152 | + .. code-block:: python |
| 153 | +
|
| 154 | + @schema_mutator |
| 155 | + def my_schema_mutator(bundle: Bundle, schema: Schema) -> Schema: |
| 156 | + return replace(schema, name="my_schema") |
| 157 | +
|
| 158 | + :param function: Function that mutates a schema. |
| 159 | + """ |
| 160 | + from databricks.bundles.schemas._models.schema import Schema |
| 161 | + |
| 162 | + return ResourceMutator(resource_type=Schema, function=function) |
0 commit comments