Skip to content

Commit

Permalink
InProgress: Add tags to SavedQueries
Browse files Browse the repository at this point in the history
  • Loading branch information
theyostalservice committed Nov 12, 2024
1 parent 89caa33 commit 150228b
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 7 deletions.
8 changes: 7 additions & 1 deletion core/dbt/artifacts/resources/v1/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import time
from dataclasses import dataclass, field
from typing import Any, Dict, List, Literal, Optional
from typing import Any, Dict, List, Literal, Optional, Union

from dbt.artifacts.resources.base import GraphResource
from dbt.artifacts.resources.types import NodeType
from dbt.artifacts.resources.v1.components import DependsOn, RefArgs
from dbt.artifacts.resources.v1.config import list_str, metas
from dbt.artifacts.resources.v1.semantic_layer_components import (
SourceFileMetadata,
WhereFilterIntersection,
)
from dbt_common.contracts.config.base import BaseConfig, CompareBehavior, MergeBehavior
from dbt_common.contracts.config.metadata import ShowBehavior
from dbt_common.dataclass_schema import dbtClassMixin
from dbt_semantic_interfaces.type_enums.export_destination_type import (
ExportDestinationType,
Expand Down Expand Up @@ -95,6 +97,10 @@ class SavedQuery(SavedQueryMandatory):
depends_on: DependsOn = field(default_factory=DependsOn)
created_at: float = field(default_factory=lambda: time.time())
refs: List[RefArgs] = field(default_factory=list)
tags: Union[List[str], str] = field(
default_factory=list_str,
metadata=metas(ShowBehavior.Hide, MergeBehavior.Append, CompareBehavior.Exclude),
)

@property
def metrics(self) -> List[str]:
Expand Down
4 changes: 4 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,9 @@ def same_exports(self, old: "SavedQuery") -> bool:

return True

def same_tags(self, old: "SavedQuery") -> bool:
return self.tags == old.tags

def same_contents(self, old: Optional["SavedQuery"]) -> bool:
# existing when it didn't before is a change!
# metadata/tags changes are not "changes"
Expand All @@ -1618,6 +1621,7 @@ def same_contents(self, old: Optional["SavedQuery"]) -> bool:
and self.same_config(old)
and self.same_group(old)
and self.same_exports(old)
and self.same_tags(old)
and True
)

Expand Down
7 changes: 7 additions & 0 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
UnitTestOutputFixture,
UnitTestOverrides,
)
from dbt.artifacts.resources.v1.config import list_str, metas
from dbt.exceptions import ParsingError
from dbt.node_types import NodeType
from dbt_common.contracts.config.base import CompareBehavior, MergeBehavior
from dbt_common.contracts.config.metadata import ShowBehavior
from dbt_common.contracts.config.properties import AdditionalPropertiesMixin
from dbt_common.contracts.util import Mergeable
from dbt_common.dataclass_schema import (
Expand Down Expand Up @@ -740,6 +743,10 @@ class UnparsedSavedQuery(dbtClassMixin):
label: Optional[str] = None
exports: List[UnparsedExport] = field(default_factory=list)
config: Dict[str, Any] = field(default_factory=dict)
tags: Union[List[str], str] = field(
default_factory=list_str,
metadata=metas(ShowBehavior.Hide, MergeBehavior.Append, CompareBehavior.Exclude),
)


def normalize_date(d: Optional[datetime.date]) -> Optional[datetime.datetime]:
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ def parse_saved_query(self, unparsed: UnparsedSavedQuery) -> None:
config=config,
unrendered_config=unrendered_config,
group=config.group,
tags=unparsed.tags,
)

for export in parsed.exports:
Expand Down Expand Up @@ -859,6 +860,8 @@ def parse_saved_query(self, unparsed: UnparsedSavedQuery) -> None:
def parse(self) -> ParseResult:
for data in self.get_key_dicts():
try:
if isinstance(data["tags"], str):
data["tags"] = [data["tags"]]
UnparsedSavedQuery.validate(data)
unparsed = UnparsedSavedQuery.from_dict(data)
except (ValidationError, JSONValidationError) as exc:
Expand Down
2 changes: 1 addition & 1 deletion core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
# These are major-version-0 packages also maintained by dbt-labs.
# Accept patches but avoid automatically updating past a set minor version range.
"dbt-extractor>=0.5.0,<=0.6",
"dbt-semantic-interfaces>=0.7.4,<0.8",
# "dbt-semantic-interfaces>=0.7.4,<0.8",
# Minor versions for these are expected to be backwards-compatible
"dbt-common>=1.11.0,<2.0",
"dbt-adapters>=1.8.0,<2.0",
Expand Down
1 change: 1 addition & 0 deletions editable-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-e ./core
-e /Users/patricky/git/dbt-semantic-interfaces
2 changes: 1 addition & 1 deletion schemas/dbt/catalog/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dbt_version": {
"type": "string",
"default": "1.9.0b2"
"default": "1.9.0b4"
},
"generated_at": {
"type": "string"
Expand Down
30 changes: 28 additions & 2 deletions schemas/dbt/manifest/v12.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dbt_version": {
"type": "string",
"default": "1.9.0b2"
"default": "1.9.0b4"
},
"generated_at": {
"type": "string"
Expand Down Expand Up @@ -19969,6 +19969,19 @@
"name"
]
}
},
"tags": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -21524,6 +21537,19 @@
"name"
]
}
},
"tags": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -22648,4 +22674,4 @@
"unit_tests"
],
"$id": "https://schemas.getdbt.com/dbt/manifest/v12.json"
}
}
2 changes: 1 addition & 1 deletion schemas/dbt/run-results/v6.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dbt_version": {
"type": "string",
"default": "1.9.0b2"
"default": "1.9.0b4"
},
"generated_at": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion schemas/dbt/sources/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dbt_version": {
"type": "string",
"default": "1.9.0b2"
"default": "1.9.0b4"
},
"generated_at": {
"type": "string"
Expand Down

0 comments on commit 150228b

Please sign in to comment.