-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: replace Pydantic BaseModel with dataclasses #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,73 +1,64 @@ | ||||||
| from dataclasses import dataclass | ||||||
| from datetime import datetime | ||||||
| from typing import ClassVar | ||||||
| from typing import Dict | ||||||
| from typing import List | ||||||
| from typing import Optional | ||||||
| from typing import Union | ||||||
|
|
||||||
| from pydantic.main import BaseModel | ||||||
| from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import CatalogV1 | ||||||
|
|
||||||
| from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import CatalogV1 as BaseCatalogV1 | ||||||
| from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import Metadata as BaseMetadata | ||||||
|
|
||||||
|
|
||||||
| class AltimateCatalogMetadata(BaseModel): | ||||||
| @dataclass | ||||||
| class AltimateCatalogMetadata: | ||||||
| dbt_schema_version: Optional[str] = "https://schemas.getdbt.com/dbt/catalog/v1.json" | ||||||
| dbt_version: Optional[str] = "0.19.0" | ||||||
| generated_at: Optional[datetime] = "2021-02-10T04:42:33.680487Z" | ||||||
| invocation_id: Optional[Optional[str]] = None | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove redundant Optional wrapping in 'invocation_id'; use Optional[str] instead.
Suggested change
|
||||||
| env: ClassVar[Optional[Dict[str, str]]] = {} | ||||||
|
|
||||||
|
|
||||||
| class AltimateCatalogTableMetadata(BaseModel): | ||||||
| @dataclass | ||||||
| class AltimateCatalogTableMetadata: | ||||||
| type: str | ||||||
| database: Optional[Optional[str]] = None | ||||||
| schema_name: str | ||||||
| name: str | ||||||
| database: Optional[Optional[str]] = None | ||||||
| comment: Optional[Optional[str]] = None | ||||||
| owner: Optional[Optional[str]] = None | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Field 'owner' has redundant Optional wrapping; simplify to Optional[str]. |
||||||
|
|
||||||
|
|
||||||
| class AltimateCatalogColumnMetadata(BaseModel): | ||||||
| @dataclass | ||||||
| class AltimateCatalogColumnMetadata: | ||||||
| type: str | ||||||
| comment: Optional[Optional[str]] = None | ||||||
| index: int | ||||||
| name: str | ||||||
| comment: Optional[Optional[str]] = None | ||||||
|
|
||||||
|
|
||||||
| class AltimateCatalogStatsItem(BaseModel): | ||||||
| @dataclass | ||||||
| class AltimateCatalogStatsItem: | ||||||
| id: str | ||||||
| label: str | ||||||
| include: bool | ||||||
| value: Optional[Optional[Union[bool, str, float]]] = None | ||||||
| description: Optional[Optional[str]] = None | ||||||
| include: bool | ||||||
|
|
||||||
|
|
||||||
| class AltimateCatalogTable(BaseModel): | ||||||
| @dataclass | ||||||
| class AltimateCatalogTable: | ||||||
| metadata: AltimateCatalogTableMetadata | ||||||
| columns: Dict[str, AltimateCatalogColumnMetadata] | ||||||
| stats: Dict[str, AltimateCatalogStatsItem] | ||||||
| unique_id: Optional[Optional[str]] = None | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Field 'unique_id' has redundant Optional wrapping; simplify to Optional[str].
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| class AltimateCatalogCatalogV1(BaseModel): | ||||||
| @dataclass | ||||||
| class AltimateCatalogCatalogV1: | ||||||
| metadata: AltimateCatalogMetadata | ||||||
| nodes: Dict[str, AltimateCatalogTable] | ||||||
| sources: Dict[str, AltimateCatalogTable] | ||||||
| errors: Optional[Optional[List[str]]] = None | ||||||
|
|
||||||
|
|
||||||
| # Custom classes to handle extra fields in newer dbt versions | ||||||
| class Metadata(BaseMetadata): | ||||||
| class Config: | ||||||
| extra = "allow" # Allow extra fields in metadata | ||||||
|
|
||||||
|
|
||||||
| class CatalogV1(BaseCatalogV1): | ||||||
| metadata: Metadata # Use our custom metadata class | ||||||
|
|
||||||
| class Config: | ||||||
| extra = "allow" # Allow extra fields | ||||||
|
|
||||||
|
|
||||||
| Catalog = CatalogV1 | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field 'generated_at' is typed as datetime but default is a string. Convert the default to a datetime object or update the type.