|
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 | from databricks.bundles.volumes._models.volume import Volume |
12 | 13 |
|
13 | 14 | _T = TypeVar("_T", bound=Resource) |
@@ -130,6 +131,38 @@ def my_pipeline_mutator(bundle: Bundle, pipeline: Pipeline) -> Pipeline: |
130 | 131 | return ResourceMutator(resource_type=Pipeline, function=function) |
131 | 132 |
|
132 | 133 |
|
| 134 | +@overload |
| 135 | +def schema_mutator( |
| 136 | + function: Callable[[Bundle, "Schema"], "Schema"], |
| 137 | +) -> ResourceMutator["Schema"]: ... |
| 138 | + |
| 139 | + |
| 140 | +@overload |
| 141 | +def schema_mutator( |
| 142 | + function: Callable[["Schema"], "Schema"], |
| 143 | +) -> ResourceMutator["Schema"]: ... |
| 144 | + |
| 145 | + |
| 146 | +def schema_mutator(function: Callable) -> ResourceMutator["Schema"]: |
| 147 | + """ |
| 148 | + Decorator for defining a schema mutator. Function should return a new instance of the schema with the desired changes, |
| 149 | + instead of mutating the input schema. |
| 150 | +
|
| 151 | + Example: |
| 152 | +
|
| 153 | + .. code-block:: python |
| 154 | +
|
| 155 | + @schema_mutator |
| 156 | + def my_schema_mutator(bundle: Bundle, schema: Schema) -> Schema: |
| 157 | + return replace(schema, name="my_schema") |
| 158 | +
|
| 159 | + :param function: Function that mutates a schema. |
| 160 | + """ |
| 161 | + from databricks.bundles.schemas._models.schema import Schema |
| 162 | + |
| 163 | + return ResourceMutator(resource_type=Schema, function=function) |
| 164 | + |
| 165 | + |
133 | 166 | @overload |
134 | 167 | def volume_mutator( |
135 | 168 | function: Callable[[Bundle, "Volume"], "Volume"], |
|
0 commit comments