sqlmesh.core.config.model
1from __future__ import annotations 2 3import typing as t 4 5from sqlglot import exp 6from sqlmesh.core.dialect import parse_one, extract_func_call 7from sqlmesh.core.config.base import BaseConfig 8from sqlmesh.core.model.kind import ( 9 ModelKind, 10 OnDestructiveChange, 11 model_kind_validator, 12 on_destructive_change_validator, 13 on_additive_change_validator, 14 OnAdditiveChange, 15) 16from sqlmesh.core.model.meta import FunctionCall 17from sqlmesh.core.node import IntervalUnit 18from sqlmesh.utils.date import TimeLike 19from sqlmesh.utils.pydantic import field_validator 20 21 22class ModelDefaultsConfig(BaseConfig): 23 """A config object for default values applied to model definitions. 24 25 Args: 26 kind: The model kind. 27 dialect: The SQL dialect that the model's query is written in. 28 cron: A cron string specifying how often the model should be refreshed, leveraging the 29 [croniter](https://github.com/kiorky/croniter) library. 30 owner: The owner of the model. 31 start: The earliest date that the model will be backfilled for. If this is None, 32 then the date is inferred by taking the most recent start date of its ancestors. 33 The start date can be a static datetime or a relative datetime like "1 year ago" 34 table_format: The table format used to manage the physical table files defined by `storage_format`, only applicable in certain engines. 35 (eg, 'iceberg', 'delta', 'hudi') 36 storage_format: The storage format used to store the physical table, only applicable in certain engines. 37 (eg. 'parquet', 'orc') 38 on_destructive_change: What should happen when a forward-only model requires a destructive schema change. 39 on_additive_change: What should happen when a forward-only model requires an additive schema change. 40 physical_properties: A key-value mapping of arbitrary properties that are applied to the model table / view in the physical layer. 41 virtual_properties: A key-value mapping of arbitrary properties that are applied to the model view in the virtual layer. 42 session_properties: A key-value mapping of properties specific to the target engine that are applied to the engine session. 43 audits: The audits to be applied globally to all models in the project. 44 optimize_query: Whether the SQL models should be optimized. 45 allow_partials: Whether the models can process partial (incomplete) data intervals. 46 enabled: Whether the models are enabled. 47 interval_unit: The temporal granularity of the models data intervals. By default computed from cron. 48 batch_concurrency: The maximum number of batches that can run concurrently for an incremental model. 49 pre_statements: The list of SQL statements that get executed before a model runs. 50 post_statements: The list of SQL statements that get executed before a model runs. 51 on_virtual_update: The list of SQL statements to be executed after the virtual update. 52 53 """ 54 55 kind: t.Optional[ModelKind] = None 56 dialect: t.Optional[str] = None 57 cron: t.Optional[str] = None 58 owner: t.Optional[str] = None 59 start: t.Optional[TimeLike] = None 60 table_format: t.Optional[str] = None 61 storage_format: t.Optional[str] = None 62 on_destructive_change: t.Optional[OnDestructiveChange] = None 63 on_additive_change: t.Optional[OnAdditiveChange] = None 64 physical_properties: t.Optional[t.Dict[str, t.Any]] = None 65 virtual_properties: t.Optional[t.Dict[str, t.Any]] = None 66 session_properties: t.Optional[t.Dict[str, t.Any]] = None 67 audits: t.Optional[t.List[FunctionCall]] = None 68 optimize_query: t.Optional[t.Union[str, bool]] = None 69 allow_partials: t.Optional[t.Union[str, bool]] = None 70 interval_unit: t.Optional[t.Union[str, IntervalUnit]] = None 71 enabled: t.Optional[t.Union[str, bool]] = None 72 formatting: t.Optional[t.Union[str, bool]] = None 73 batch_concurrency: t.Optional[int] = None 74 pre_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None 75 post_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None 76 on_virtual_update: t.Optional[t.List[t.Union[str, exp.Expr]]] = None 77 78 _model_kind_validator = model_kind_validator 79 _on_destructive_change_validator = on_destructive_change_validator 80 _on_additive_change_validator = on_additive_change_validator 81 82 @field_validator("audits", mode="before") 83 def _audits_validator(cls, v: t.Any) -> t.Any: 84 if isinstance(v, list): 85 return [extract_func_call(parse_one(audit)) for audit in v] 86 87 return v
23class ModelDefaultsConfig(BaseConfig): 24 """A config object for default values applied to model definitions. 25 26 Args: 27 kind: The model kind. 28 dialect: The SQL dialect that the model's query is written in. 29 cron: A cron string specifying how often the model should be refreshed, leveraging the 30 [croniter](https://github.com/kiorky/croniter) library. 31 owner: The owner of the model. 32 start: The earliest date that the model will be backfilled for. If this is None, 33 then the date is inferred by taking the most recent start date of its ancestors. 34 The start date can be a static datetime or a relative datetime like "1 year ago" 35 table_format: The table format used to manage the physical table files defined by `storage_format`, only applicable in certain engines. 36 (eg, 'iceberg', 'delta', 'hudi') 37 storage_format: The storage format used to store the physical table, only applicable in certain engines. 38 (eg. 'parquet', 'orc') 39 on_destructive_change: What should happen when a forward-only model requires a destructive schema change. 40 on_additive_change: What should happen when a forward-only model requires an additive schema change. 41 physical_properties: A key-value mapping of arbitrary properties that are applied to the model table / view in the physical layer. 42 virtual_properties: A key-value mapping of arbitrary properties that are applied to the model view in the virtual layer. 43 session_properties: A key-value mapping of properties specific to the target engine that are applied to the engine session. 44 audits: The audits to be applied globally to all models in the project. 45 optimize_query: Whether the SQL models should be optimized. 46 allow_partials: Whether the models can process partial (incomplete) data intervals. 47 enabled: Whether the models are enabled. 48 interval_unit: The temporal granularity of the models data intervals. By default computed from cron. 49 batch_concurrency: The maximum number of batches that can run concurrently for an incremental model. 50 pre_statements: The list of SQL statements that get executed before a model runs. 51 post_statements: The list of SQL statements that get executed before a model runs. 52 on_virtual_update: The list of SQL statements to be executed after the virtual update. 53 54 """ 55 56 kind: t.Optional[ModelKind] = None 57 dialect: t.Optional[str] = None 58 cron: t.Optional[str] = None 59 owner: t.Optional[str] = None 60 start: t.Optional[TimeLike] = None 61 table_format: t.Optional[str] = None 62 storage_format: t.Optional[str] = None 63 on_destructive_change: t.Optional[OnDestructiveChange] = None 64 on_additive_change: t.Optional[OnAdditiveChange] = None 65 physical_properties: t.Optional[t.Dict[str, t.Any]] = None 66 virtual_properties: t.Optional[t.Dict[str, t.Any]] = None 67 session_properties: t.Optional[t.Dict[str, t.Any]] = None 68 audits: t.Optional[t.List[FunctionCall]] = None 69 optimize_query: t.Optional[t.Union[str, bool]] = None 70 allow_partials: t.Optional[t.Union[str, bool]] = None 71 interval_unit: t.Optional[t.Union[str, IntervalUnit]] = None 72 enabled: t.Optional[t.Union[str, bool]] = None 73 formatting: t.Optional[t.Union[str, bool]] = None 74 batch_concurrency: t.Optional[int] = None 75 pre_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None 76 post_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None 77 on_virtual_update: t.Optional[t.List[t.Union[str, exp.Expr]]] = None 78 79 _model_kind_validator = model_kind_validator 80 _on_destructive_change_validator = on_destructive_change_validator 81 _on_additive_change_validator = on_additive_change_validator 82 83 @field_validator("audits", mode="before") 84 def _audits_validator(cls, v: t.Any) -> t.Any: 85 if isinstance(v, list): 86 return [extract_func_call(parse_one(audit)) for audit in v] 87 88 return v
A config object for default values applied to model definitions.
Arguments:
- kind: The model kind.
- dialect: The SQL dialect that the model's query is written in.
- cron: A cron string specifying how often the model should be refreshed, leveraging the croniter library.
- owner: The owner of the model.
- start: The earliest date that the model will be backfilled for. If this is None, then the date is inferred by taking the most recent start date of its ancestors. The start date can be a static datetime or a relative datetime like "1 year ago"
- table_format: The table format used to manage the physical table files defined by
storage_format, only applicable in certain engines. (eg, 'iceberg', 'delta', 'hudi') - storage_format: The storage format used to store the physical table, only applicable in certain engines. (eg. 'parquet', 'orc')
- on_destructive_change: What should happen when a forward-only model requires a destructive schema change.
- on_additive_change: What should happen when a forward-only model requires an additive schema change.
- physical_properties: A key-value mapping of arbitrary properties that are applied to the model table / view in the physical layer.
- virtual_properties: A key-value mapping of arbitrary properties that are applied to the model view in the virtual layer.
- session_properties: A key-value mapping of properties specific to the target engine that are applied to the engine session.
- audits: The audits to be applied globally to all models in the project.
- optimize_query: Whether the SQL models should be optimized.
- allow_partials: Whether the models can process partial (incomplete) data intervals.
- enabled: Whether the models are enabled.
- interval_unit: The temporal granularity of the models data intervals. By default computed from cron.
- batch_concurrency: The maximum number of batches that can run concurrently for an incremental model.
- pre_statements: The list of SQL statements that get executed before a model runs.
- post_statements: The list of SQL statements that get executed before a model runs.
- on_virtual_update: The list of SQL statements to be executed after the virtual update.
kind: Optional[Annotated[Union[sqlmesh.core.model.kind.EmbeddedKind, sqlmesh.core.model.kind.ExternalKind, sqlmesh.core.model.kind.FullKind, sqlmesh.core.model.kind.IncrementalByTimeRangeKind, sqlmesh.core.model.kind.IncrementalByUniqueKeyKind, sqlmesh.core.model.kind.IncrementalByPartitionKind, sqlmesh.core.model.kind.IncrementalUnmanagedKind, sqlmesh.core.model.kind.SeedKind, sqlmesh.core.model.kind.ViewKind, sqlmesh.core.model.kind.SCDType2ByTimeKind, sqlmesh.core.model.kind.SCDType2ByColumnKind, sqlmesh.core.model.kind.CustomKind, sqlmesh.core.model.kind.ManagedKind, sqlmesh.core.model.kind.DbtCustomKind], FieldInfo(annotation=NoneType, required=True, discriminator='name')]]
on_destructive_change: Optional[sqlmesh.core.model.kind.OnDestructiveChange]
on_additive_change: Optional[sqlmesh.core.model.kind.OnAdditiveChange]
interval_unit: Union[str, sqlmesh.core.node.IntervalUnit, NoneType]
model_config =
{'json_encoders': {<class 'sqlglot.expressions.core.Expr'>: <function _expression_encoder>, <class 'sqlglot.expressions.datatypes.DataType'>: <function _expression_encoder>, <class 'sqlglot.expressions.query.Tuple'>: <function _expression_encoder>, typing.Union[sqlglot.expressions.query.Query, sqlmesh.core.dialect.JinjaQuery]: <function _expression_encoder>, typing.Union[sqlglot.expressions.query.Query, sqlmesh.core.dialect.JinjaQuery, sqlmesh.core.dialect.MacroFunc]: <function _expression_encoder>, <class 'datetime.tzinfo'>: <function PydanticModel.<lambda>>}, 'arbitrary_types_allowed': True, 'extra': 'forbid', 'protected_namespaces': ()}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Inherited Members
- pydantic.main.BaseModel
- BaseModel
- model_fields
- model_computed_fields
- model_extra
- model_fields_set
- model_construct
- model_copy
- model_dump
- model_dump_json
- model_json_schema
- model_parametrized_name
- model_post_init
- model_rebuild
- model_validate
- model_validate_json
- model_validate_strings
- parse_file
- from_orm
- construct
- schema
- schema_json
- validate
- update_forward_refs