Skip to content
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

CT 1443 remove root path #6172

Merged
merged 12 commits into from
Nov 4, 2022
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20221028-104837.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Remove the 'root_path' field from most nodes
time: 2022-10-28T10:48:37.687886-04:00
custom:
Author: gshank
Issue: "6171"
PR: "6172"
1 change: 1 addition & 0 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ def load_agate_table(self) -> agate.Table:
raise_compiler_error(
"can only load_agate_table for seeds (got a {})".format(self.model.resource_type)
)
assert self.model.root_path
path = os.path.join(self.model.root_path, self.model.original_file_path)
column_types = self.model.config.column_types
try:
Expand Down
1 change: 1 addition & 0 deletions core/dbt/contracts/graph/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CompiledSeedNode(CompiledNode):
# keep this in sync with ParsedSeedNode!
resource_type: NodeType = field(metadata={"restrict": [NodeType.Seed]})
config: SeedConfig = field(default_factory=SeedConfig)
root_path: Optional[str] = None

@property
def empty(self):
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ def __init__(self, macros):


@dataclass
@schema_version("manifest", 7)
@schema_version("manifest", 8)
class WritableManifest(ArtifactMixin):
nodes: Mapping[UniqueID, ManifestNode] = field(
metadata=dict(description=("The nodes defined in the dbt project and its dependencies"))
Expand Down Expand Up @@ -1229,7 +1229,7 @@ class WritableManifest(ArtifactMixin):

@classmethod
def compatible_previous_versions(self):
return [("manifest", 4), ("manifest", 5), ("manifest", 6)]
return [("manifest", 4), ("manifest", 5), ("manifest", 6), ("manifest", 7)]

def __post_serialize__(self, dct):
for unique_id, node in dct["nodes"].items():
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ class ParsedSeedNode(ParsedNode):
# keep this in sync with CompiledSeedNode!
resource_type: NodeType = field(metadata={"restrict": [NodeType.Seed]})
config: SeedConfig = field(default_factory=SeedConfig)
# seeds need the root_path because the contents are not loaded initially
# and we need the root_path to load the seed later
root_path: Optional[str] = None

@property
def empty(self):
Expand Down
2 changes: 0 additions & 2 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@dataclass
class UnparsedBaseNode(dbtClassMixin, Replaceable):
package_name: str
root_path: str
path: str
original_file_path: str

Expand Down Expand Up @@ -364,7 +363,6 @@ def get_table_named(self, name: str) -> Optional[SourceTablePatch]:
@dataclass
class UnparsedDocumentation(dbtClassMixin, Replaceable):
package_name: str
root_path: str
path: str
original_file_path: str

Expand Down
23 changes: 21 additions & 2 deletions core/dbt/contracts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,32 @@ def rename_sql_attr(node_content: dict) -> dict:
def upgrade_manifest_json(manifest: dict) -> dict:
for node_content in manifest.get("nodes", {}).values():
node_content = rename_sql_attr(node_content)
if node_content["resource_type"] != "seed" and "root_path" in node_content:
del node_content["root_path"]
for disabled in manifest.get("disabled", {}).values():
# There can be multiple disabled nodes for the same unique_id
# so make sure all the nodes get the attr renamed
disabled = [rename_sql_attr(n) for n in disabled]
for node_content in disabled:
rename_sql_attr(node_content)
if node_content["resource_type"] != "seed" and "root_path" in node_content:
del node_content["root_path"]
for metric_content in manifest.get("metrics", {}).values():
# handle attr renames + value translation ("expression" -> "derived")
metric_content = rename_metric_attr(metric_content)
if "root_path" in metric_content:
del metric_content["root_path"]
for exposure_content in manifest.get("exposures", {}).values():
if "root_path" in exposure_content:
del exposure_content["root_path"]
for source_content in manifest.get("sources", {}).values():
if "root_path" in exposure_content:
del source_content["root_path"]
for macro_content in manifest.get("macros", {}).values():
if "root_path" in macro_content:
del macro_content["root_path"]
for doc_content in manifest.get("docs", {}).values():
if "root_path" in doc_content:
del doc_content["root_path"]
return manifest


Expand Down Expand Up @@ -291,7 +310,7 @@ def read_and_check_versions(cls, path: str):
expected=str(cls.dbt_schema_version),
found=previous_schema_version,
)
if get_manifest_schema_version(data) <= 6:
if get_manifest_schema_version(data) <= 7:
data = upgrade_manifest_json(data)
return cls.from_dict(data) # type: ignore

Expand Down
2 changes: 0 additions & 2 deletions core/dbt/graph/selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
root = Path.cwd()
paths = set(p.relative_to(root) for p in root.glob(selector))
for node, real_node in self.all_nodes(included_nodes):
if Path(real_node.root_path) != root:
continue
ofp = Path(real_node.original_file_path)
if ofp in paths:
yield node
Expand Down
2 changes: 0 additions & 2 deletions core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def _create_error_node(
resource_type=self.resource_type,
path=path,
original_file_path=original_file_path,
root_path=self.project.project_root,
package_name=self.project.project_name,
raw_code=raw_code,
language=language,
Expand Down Expand Up @@ -202,7 +201,6 @@ def _create_parsetime_node(
"database": self.default_database,
"fqn": fqn,
"name": name,
"root_path": self.project.project_root,
"resource_type": self.resource_type,
"path": path,
"original_file_path": block.path.original_file_path,
Expand Down
1 change: 0 additions & 1 deletion core/dbt/parser/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def parse_block(self, block: BlockContents) -> Iterable[ParsedDocumentation]:
contents = get_rendered(block.contents, {}).strip()

doc = ParsedDocumentation(
root_path=self.project.project_root,
path=block.file.path.relative_path,
original_file_path=block.path.original_file_path,
package_name=self.project.project_name,
Expand Down
2 changes: 0 additions & 2 deletions core/dbt/parser/generic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def parse_generic_test(
macro_sql=block.full_block,
original_file_path=base_node.original_file_path,
package_name=base_node.package_name,
root_path=base_node.root_path,
resource_type=base_node.resource_type,
name=name,
unique_id=unique_id,
Expand Down Expand Up @@ -96,7 +95,6 @@ def parse_file(self, block: FileBlock):
original_file_path=original_file_path,
package_name=self.project.project_name,
raw_code=source_file.contents,
root_path=self.project.project_root,
resource_type=NodeType.Macro,
language="sql",
)
Expand Down
2 changes: 0 additions & 2 deletions core/dbt/parser/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def parse_macro(
macro_sql=block.full_block,
original_file_path=base_node.original_file_path,
package_name=base_node.package_name,
root_path=base_node.root_path,
resource_type=base_node.resource_type,
name=name,
unique_id=unique_id,
Expand Down Expand Up @@ -103,7 +102,6 @@ def parse_file(self, block: FileBlock):
original_file_path=original_file_path,
package_name=self.project.project_name,
raw_code=source_file.contents,
root_path=self.project.project_root,
resource_type=NodeType.Macro,
language="sql",
)
Expand Down
4 changes: 0 additions & 4 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ def get_hashable_md(data: Union[str, int, float, List, Dict]) -> Union[str, List
"database": self.default_database,
"fqn": fqn,
"name": name,
"root_path": self.project.project_root,
"resource_type": self.resource_type,
"tags": tags,
"path": path,
Expand Down Expand Up @@ -728,7 +727,6 @@ def add_source_definitions(self, source: UnparsedSourceDefinition) -> None:
table=table,
path=original_file_path,
original_file_path=original_file_path,
root_path=self.project.project_root,
package_name=package_name,
unique_id=unique_id,
resource_type=NodeType.Source,
Expand Down Expand Up @@ -1031,7 +1029,6 @@ def parse_exposure(self, unparsed: UnparsedExposure):

parsed = ParsedExposure(
package_name=package_name,
root_path=self.project.project_root,
path=path,
original_file_path=self.yaml.path.original_file_path,
unique_id=unique_id,
Expand Down Expand Up @@ -1135,7 +1132,6 @@ def parse_metric(self, unparsed: UnparsedMetric):

parsed = ParsedMetric(
package_name=package_name,
root_path=self.project.project_root,
path=path,
original_file_path=self.yaml.path.original_file_path,
unique_id=unique_id,
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/parser/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class SeedParser(SimpleSQLParser[ParsedSeedNode]):
def parse_from_dict(self, dct, validate=True) -> ParsedSeedNode:
# seeds need the root_path because the contents are not loaded
dct["root_path"] = self.project.project_root
if validate:
ParsedSeedNode.validate(dct)
return ParsedSeedNode.from_dict(dct)
Expand Down
1 change: 0 additions & 1 deletion core/dbt/parser/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def parse_source(self, target: UnpatchedSourceDefinition) -> ParsedSourceDefinit
database=(source.database or default_database),
schema=(source.schema or source.name),
identifier=(table.identifier or table.name),
root_path=target.root_path,
path=target.path,
original_file_path=target.original_file_path,
columns=refs.column_info,
Expand Down
1 change: 0 additions & 1 deletion core/dbt/parser/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def parse_remote(self, contents) -> Iterable[ParsedMacro]:
package_name=self.project.project_name,
raw_code=contents,
language="sql",
root_path=self.project.project_root,
resource_type=NodeType.Macro,
)
for node in self.parse_unparsed_macros(base):
Expand Down
Loading