sqlmesh.dbt.column
1from __future__ import annotations 2 3import typing as t 4 5from pydantic import validator 6from sqlglot import exp, parse_one 7from sqlglot.helper import ensure_list 8 9from sqlmesh.dbt.common import GeneralConfig 10from sqlmesh.utils.conversions import ensure_bool 11 12 13def yaml_to_columns( 14 yaml: t.Dict[str, ColumnConfig] | t.List[t.Dict[str, ColumnConfig]] 15) -> t.Dict[str, ColumnConfig]: 16 columns = {} 17 mappings: t.List[t.Dict[str, ColumnConfig]] = ensure_list(yaml) 18 for column in mappings: 19 config = ColumnConfig(**column) 20 columns[config.name] = config 21 22 return columns 23 24 25def column_types_to_sqlmesh(columns: t.Dict[str, ColumnConfig]) -> t.Dict[str, exp.DataType]: 26 """ 27 Get the sqlmesh column types 28 29 Returns: 30 A dict of column name to exp.DataType 31 """ 32 return { 33 name: parse_one(column.data_type, into=exp.DataType) 34 for name, column in columns.items() 35 if column.enabled and column.data_type 36 } 37 38 39def column_descriptions_to_sqlmesh(columns: t.Dict[str, ColumnConfig]) -> t.Dict[str, str]: 40 """ 41 Get the sqlmesh column types 42 43 Returns: 44 A dict of column name to description 45 """ 46 return { 47 name: column.description 48 for name, column in columns.items() 49 if column.enabled and column.description 50 } 51 52 53class ColumnConfig(GeneralConfig): 54 """ 55 Column configuration for a DBT project 56 57 Args: 58 name: Name of the column 59 data_type: The column's data type 60 description: User defined description of the column 61 meta: Meta data associated with the column 62 quote: Boolean flag to use quoting for the column name 63 tests: Tests associated with this column 64 tags: Tags associated with this column 65 """ 66 67 name: str 68 data_type: t.Optional[str] = None 69 quote: t.Optional[bool] = False 70 71 @validator("quote", pre=True) 72 def _validate_bool(cls, v: str) -> bool: 73 return ensure_bool(v)
def
yaml_to_columns( yaml: Union[Dict[str, sqlmesh.dbt.column.ColumnConfig], List[Dict[str, sqlmesh.dbt.column.ColumnConfig]]]) -> Dict[str, sqlmesh.dbt.column.ColumnConfig]:
14def yaml_to_columns( 15 yaml: t.Dict[str, ColumnConfig] | t.List[t.Dict[str, ColumnConfig]] 16) -> t.Dict[str, ColumnConfig]: 17 columns = {} 18 mappings: t.List[t.Dict[str, ColumnConfig]] = ensure_list(yaml) 19 for column in mappings: 20 config = ColumnConfig(**column) 21 columns[config.name] = config 22 23 return columns
def
column_types_to_sqlmesh( columns: Dict[str, sqlmesh.dbt.column.ColumnConfig]) -> Dict[str, sqlglot.expressions.DataType]:
26def column_types_to_sqlmesh(columns: t.Dict[str, ColumnConfig]) -> t.Dict[str, exp.DataType]: 27 """ 28 Get the sqlmesh column types 29 30 Returns: 31 A dict of column name to exp.DataType 32 """ 33 return { 34 name: parse_one(column.data_type, into=exp.DataType) 35 for name, column in columns.items() 36 if column.enabled and column.data_type 37 }
Get the sqlmesh column types
Returns:
A dict of column name to exp.DataType
def
column_descriptions_to_sqlmesh(columns: Dict[str, sqlmesh.dbt.column.ColumnConfig]) -> Dict[str, str]:
40def column_descriptions_to_sqlmesh(columns: t.Dict[str, ColumnConfig]) -> t.Dict[str, str]: 41 """ 42 Get the sqlmesh column types 43 44 Returns: 45 A dict of column name to description 46 """ 47 return { 48 name: column.description 49 for name, column in columns.items() 50 if column.enabled and column.description 51 }
Get the sqlmesh column types
Returns:
A dict of column name to description
54class ColumnConfig(GeneralConfig): 55 """ 56 Column configuration for a DBT project 57 58 Args: 59 name: Name of the column 60 data_type: The column's data type 61 description: User defined description of the column 62 meta: Meta data associated with the column 63 quote: Boolean flag to use quoting for the column name 64 tests: Tests associated with this column 65 tags: Tags associated with this column 66 """ 67 68 name: str 69 data_type: t.Optional[str] = None 70 quote: t.Optional[bool] = False 71 72 @validator("quote", pre=True) 73 def _validate_bool(cls, v: str) -> bool: 74 return ensure_bool(v)
Column configuration for a DBT project
Arguments:
- name: Name of the column
- data_type: The column's data type
- description: User defined description of the column
- meta: Meta data associated with the column
- quote: Boolean flag to use quoting for the column name
- tests: Tests associated with this column
- tags: Tags associated with this column
Inherited Members
- pydantic.main.BaseModel
- BaseModel
- parse_obj
- parse_raw
- parse_file
- from_orm
- construct
- copy
- schema
- schema_json
- validate
- update_forward_refs