Edit on GitHub

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, cron_tz_validator
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        cron_tz: The timezone for the cron expression, defaults to UTC. [IANA time zones](https://docs.python.org/3/library/zoneinfo.html).
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    cron_tz: t.Any = None
60    owner: t.Optional[str] = None
61    start: t.Optional[TimeLike] = None
62    table_format: t.Optional[str] = None
63    storage_format: t.Optional[str] = None
64    on_destructive_change: t.Optional[OnDestructiveChange] = None
65    on_additive_change: t.Optional[OnAdditiveChange] = None
66    physical_properties: t.Optional[t.Dict[str, t.Any]] = None
67    virtual_properties: t.Optional[t.Dict[str, t.Any]] = None
68    session_properties: t.Optional[t.Dict[str, t.Any]] = None
69    audits: t.Optional[t.List[FunctionCall]] = None
70    optimize_query: t.Optional[t.Union[str, bool]] = None
71    allow_partials: t.Optional[t.Union[str, bool]] = None
72    interval_unit: t.Optional[t.Union[str, IntervalUnit]] = None
73    enabled: t.Optional[t.Union[str, bool]] = None
74    formatting: t.Optional[t.Union[str, bool]] = None
75    batch_concurrency: t.Optional[int] = None
76    pre_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None
77    post_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None
78    on_virtual_update: t.Optional[t.List[t.Union[str, exp.Expr]]] = None
79
80    _model_kind_validator = model_kind_validator
81    _on_destructive_change_validator = on_destructive_change_validator
82    _on_additive_change_validator = on_additive_change_validator
83    _cron_tz_validator = cron_tz_validator
84
85    @field_validator("audits", mode="before")
86    def _audits_validator(cls, v: t.Any) -> t.Any:
87        if isinstance(v, list):
88            return [extract_func_call(parse_one(audit)) for audit in v]
89
90        return v
class ModelDefaultsConfig(sqlmesh.core.config.base.BaseConfig):
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        cron_tz: The timezone for the cron expression, defaults to UTC. [IANA time zones](https://docs.python.org/3/library/zoneinfo.html).
32        owner: The owner of the model.
33        start: The earliest date that the model will be backfilled for. If this is None,
34            then the date is inferred by taking the most recent start date of its ancestors.
35            The start date can be a static datetime or a relative datetime like "1 year ago"
36        table_format: The table format used to manage the physical table files defined by `storage_format`, only applicable in certain engines.
37            (eg, 'iceberg', 'delta', 'hudi')
38        storage_format: The storage format used to store the physical table, only applicable in certain engines.
39            (eg. 'parquet', 'orc')
40        on_destructive_change: What should happen when a forward-only model requires a destructive schema change.
41        on_additive_change: What should happen when a forward-only model requires an additive schema change.
42        physical_properties: A key-value mapping of arbitrary properties that are applied to the model table / view in the physical layer.
43        virtual_properties: A key-value mapping of arbitrary properties that are applied to the model view in the virtual layer.
44        session_properties: A key-value mapping of properties specific to the target engine that are applied to the engine session.
45        audits: The audits to be applied globally to all models in the project.
46        optimize_query: Whether the SQL models should be optimized.
47        allow_partials: Whether the models can process partial (incomplete) data intervals.
48        enabled: Whether the models are enabled.
49        interval_unit: The temporal granularity of the models data intervals. By default computed from cron.
50        batch_concurrency: The maximum number of batches that can run concurrently for an incremental model.
51        pre_statements: The list of SQL statements that get executed before a model runs.
52        post_statements: The list of SQL statements that get executed before a model runs.
53        on_virtual_update: The list of SQL statements to be executed after the virtual update.
54
55    """
56
57    kind: t.Optional[ModelKind] = None
58    dialect: t.Optional[str] = None
59    cron: t.Optional[str] = None
60    cron_tz: t.Any = None
61    owner: t.Optional[str] = None
62    start: t.Optional[TimeLike] = None
63    table_format: t.Optional[str] = None
64    storage_format: t.Optional[str] = None
65    on_destructive_change: t.Optional[OnDestructiveChange] = None
66    on_additive_change: t.Optional[OnAdditiveChange] = None
67    physical_properties: t.Optional[t.Dict[str, t.Any]] = None
68    virtual_properties: t.Optional[t.Dict[str, t.Any]] = None
69    session_properties: t.Optional[t.Dict[str, t.Any]] = None
70    audits: t.Optional[t.List[FunctionCall]] = None
71    optimize_query: t.Optional[t.Union[str, bool]] = None
72    allow_partials: t.Optional[t.Union[str, bool]] = None
73    interval_unit: t.Optional[t.Union[str, IntervalUnit]] = None
74    enabled: t.Optional[t.Union[str, bool]] = None
75    formatting: t.Optional[t.Union[str, bool]] = None
76    batch_concurrency: t.Optional[int] = None
77    pre_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None
78    post_statements: t.Optional[t.List[t.Union[str, exp.Expr]]] = None
79    on_virtual_update: t.Optional[t.List[t.Union[str, exp.Expr]]] = None
80
81    _model_kind_validator = model_kind_validator
82    _on_destructive_change_validator = on_destructive_change_validator
83    _on_additive_change_validator = on_additive_change_validator
84    _cron_tz_validator = cron_tz_validator
85
86    @field_validator("audits", mode="before")
87    def _audits_validator(cls, v: t.Any) -> t.Any:
88        if isinstance(v, list):
89            return [extract_func_call(parse_one(audit)) for audit in v]
90
91        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.
  • cron_tz: The timezone for the cron expression, defaults to UTC. IANA time zones.
  • 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.
dialect: Optional[str]
cron: Optional[str]
cron_tz: Any
owner: Optional[str]
start: Union[datetime.date, datetime.datetime, str, int, float, NoneType]
table_format: Optional[str]
storage_format: Optional[str]
on_destructive_change: Optional[sqlmesh.core.model.kind.OnDestructiveChange]
on_additive_change: Optional[sqlmesh.core.model.kind.OnAdditiveChange]
physical_properties: Optional[Dict[str, Any]]
virtual_properties: Optional[Dict[str, Any]]
session_properties: Optional[Dict[str, Any]]
audits: Optional[List[Tuple[str, Dict[str, sqlglot.expressions.core.Expr]]]]
optimize_query: Union[str, bool, NoneType]
allow_partials: Union[str, bool, NoneType]
interval_unit: Union[str, sqlmesh.core.node.IntervalUnit, NoneType]
enabled: Union[str, bool, NoneType]
formatting: Union[str, bool, NoneType]
batch_concurrency: Optional[int]
pre_statements: Optional[List[Union[str, sqlglot.expressions.core.Expr]]]
post_statements: Optional[List[Union[str, sqlglot.expressions.core.Expr]]]
on_virtual_update: Optional[List[Union[str, sqlglot.expressions.core.Expr]]]
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
sqlmesh.core.config.base.BaseConfig
update_with
sqlmesh.utils.pydantic.PydanticModel
dict
json
copy
fields_set
parse_obj
parse_raw
missing_required_fields
extra_fields
all_fields
all_field_infos
required_fields