Edit on GitHub

sqlmesh.core.config.format

 1from __future__ import annotations
 2
 3import typing as t
 4
 5from sqlmesh.core.config.base import BaseConfig
 6
 7
 8class FormatConfig(BaseConfig):
 9    """The format configuration for SQL code.
10
11    Args:
12        normalize: Whether to normalize the SQL code or not.
13        pad: The number of spaces to use for padding.
14        indent: The number of spaces to use for indentation.
15        normalize_functions: How to normalize function name casing.
16
17            * ``False`` (default) — preserves the original spelling of custom and audit
18              function names.  SQLGlot built-in functions (e.g. ``COUNT``, ``SUM``) may
19              still be uppercased because the parser discards the original token.
20            * ``"upper"`` — uppercases all function names, including custom audit
21              references.
22            * ``"lower"`` — lowercases all function names, including built-in ones.
23            * ``True`` — defers to SQLGlot's generator default, which uppercases all
24              function names including custom ones.
25            * ``None`` — excluded from the serialized generator options by Pydantic's
26              ``exclude_none`` behaviour, so ``format_model_expressions`` falls back to
27              its own ``False`` default.  Setting this in YAML as ``null`` or omitting
28              the key is therefore equivalent to ``false``; it does **not** defer to
29              SQLGlot's generator default the way ``True`` does.
30        leading_comma: Whether to use leading commas or not.
31        max_text_width: The maximum text width in a segment before creating new lines.
32        append_newline: Whether to append a newline to the end of the file or not.
33        no_rewrite_casts: Preserve the existing casts, without rewriting them to use the :: syntax.
34    """
35
36    normalize: bool = False
37    pad: int = 2
38    indent: int = 2
39    normalize_functions: t.Union[str, bool, None] = False
40    leading_comma: bool = False
41    max_text_width: int = 80
42    append_newline: bool = False
43    no_rewrite_casts: bool = False
44
45    @property
46    def generator_options(self) -> t.Dict[str, t.Any]:
47        """Options which can be passed through to the SQLGlot Generator class.
48
49        Returns:
50            The generator options.
51        """
52        return self.dict(exclude={"append_newline", "no_rewrite_casts"})
class FormatConfig(sqlmesh.core.config.base.BaseConfig):
 9class FormatConfig(BaseConfig):
10    """The format configuration for SQL code.
11
12    Args:
13        normalize: Whether to normalize the SQL code or not.
14        pad: The number of spaces to use for padding.
15        indent: The number of spaces to use for indentation.
16        normalize_functions: How to normalize function name casing.
17
18            * ``False`` (default) — preserves the original spelling of custom and audit
19              function names.  SQLGlot built-in functions (e.g. ``COUNT``, ``SUM``) may
20              still be uppercased because the parser discards the original token.
21            * ``"upper"`` — uppercases all function names, including custom audit
22              references.
23            * ``"lower"`` — lowercases all function names, including built-in ones.
24            * ``True`` — defers to SQLGlot's generator default, which uppercases all
25              function names including custom ones.
26            * ``None`` — excluded from the serialized generator options by Pydantic's
27              ``exclude_none`` behaviour, so ``format_model_expressions`` falls back to
28              its own ``False`` default.  Setting this in YAML as ``null`` or omitting
29              the key is therefore equivalent to ``false``; it does **not** defer to
30              SQLGlot's generator default the way ``True`` does.
31        leading_comma: Whether to use leading commas or not.
32        max_text_width: The maximum text width in a segment before creating new lines.
33        append_newline: Whether to append a newline to the end of the file or not.
34        no_rewrite_casts: Preserve the existing casts, without rewriting them to use the :: syntax.
35    """
36
37    normalize: bool = False
38    pad: int = 2
39    indent: int = 2
40    normalize_functions: t.Union[str, bool, None] = False
41    leading_comma: bool = False
42    max_text_width: int = 80
43    append_newline: bool = False
44    no_rewrite_casts: bool = False
45
46    @property
47    def generator_options(self) -> t.Dict[str, t.Any]:
48        """Options which can be passed through to the SQLGlot Generator class.
49
50        Returns:
51            The generator options.
52        """
53        return self.dict(exclude={"append_newline", "no_rewrite_casts"})

The format configuration for SQL code.

Arguments:
  • normalize: Whether to normalize the SQL code or not.
  • pad: The number of spaces to use for padding.
  • indent: The number of spaces to use for indentation.
  • normalize_functions: How to normalize function name casing.

    • False (default) — preserves the original spelling of custom and audit function names. SQLGlot built-in functions (e.g. COUNT, SUM) may still be uppercased because the parser discards the original token.
    • "upper" — uppercases all function names, including custom audit references.
    • "lower" — lowercases all function names, including built-in ones.
    • True — defers to SQLGlot's generator default, which uppercases all function names including custom ones.
    • None — excluded from the serialized generator options by Pydantic's exclude_none behaviour, so format_model_expressions falls back to its own False default. Setting this in YAML as null or omitting the key is therefore equivalent to false; it does not defer to SQLGlot's generator default the way True does.
  • leading_comma: Whether to use leading commas or not.
  • max_text_width: The maximum text width in a segment before creating new lines.
  • append_newline: Whether to append a newline to the end of the file or not.
  • no_rewrite_casts: Preserve the existing casts, without rewriting them to use the :: syntax.
normalize: bool
pad: int
indent: int
normalize_functions: Union[str, bool, NoneType]
leading_comma: bool
max_text_width: int
append_newline: bool
no_rewrite_casts: bool
generator_options: Dict[str, Any]
46    @property
47    def generator_options(self) -> t.Dict[str, t.Any]:
48        """Options which can be passed through to the SQLGlot Generator class.
49
50        Returns:
51            The generator options.
52        """
53        return self.dict(exclude={"append_newline", "no_rewrite_casts"})

Options which can be passed through to the SQLGlot Generator class.

Returns:

The generator options.

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