Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20230706-175507.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Add option to specify partial parse file
time: 2023-07-06T17:55:07.525287-07:00
custom:
Author: ChenyuLInx
Issue: "7911"
1 change: 1 addition & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult:
@p.log_path
@p.macro_debugging
@p.partial_parse
@p.partial_parse_file_path
@p.populate_cache
@p.print
@p.printer_width
Expand Down
9 changes: 9 additions & 0 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@
default=True,
)

partial_parse_file_path = click.option(
"--partial-parse-file-path",
envvar="DBT_PARTIAL_PARSE_FILE_PATH",
help="Internal flag for path to partial_parse.manifest file.",
default=None,
hidden=True,
type=click.Path(exists=True, dir_okay=False, resolve_path=True),
)

populate_cache = click.option(
"--populate-cache/--no-populate-cache",
envvar="DBT_POPULATE_CACHE",
Expand Down
7 changes: 5 additions & 2 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,13 @@ def skip_partial_parsing_because_of_macros(self):
return False

def read_manifest_for_partial_parse(self) -> Optional[Manifest]:
if not get_flags().PARTIAL_PARSE:
flags = get_flags()
if not flags.PARTIAL_PARSE:
fire_event(PartialParsingNotEnabled())
return None
path = os.path.join(self.root_project.project_target_path, PARTIAL_PARSE_FILE_NAME)
path = flags.partial_parse_file_path or os.path.join(
self.root_project.project_target_path, PARTIAL_PARSE_FILE_NAME
)

reparse_reason = None

Expand Down
22 changes: 21 additions & 1 deletion tests/unit/test_parse_manifest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import unittest
from unittest import mock
from unittest.mock import patch
from unittest.mock import patch, MagicMock
from argparse import Namespace

from .utils import config_from_parts_or_dicts, normalize

from dbt.contracts.files import SourceFile, FileHash, FilePath
from dbt.contracts.graph.manifest import Manifest, ManifestStateCheck
from dbt.parser import manifest
from dbt.parser.manifest import ManifestLoader
from dbt.config import RuntimeConfig
from dbt.flags import set_from_args


class MatchingHash(FileHash):
Expand Down Expand Up @@ -99,3 +103,19 @@ def _new_file(self, searched, name, match):
project_root=normalize(self.root_project_config.project_root),
)
return SourceFile(path=path, checksum=checksum)


class TestPartialParse(unittest.TestCase):
@patch("dbt.parser.manifest.ManifestLoader.build_manifest_state_check")
@patch("dbt.parser.manifest.os.path.exists")
def test_partial_parse_file_path(self, patched_os_exist, patched_state_check):
mock_project = MagicMock(RuntimeConfig)
mock_project.project_target_path = "mock_target_path"
set_from_args(Namespace(), {})
ManifestLoader(mock_project, {})
# by default we use the project_target_path
patched_os_exist.assert_called_with("mock_target_path/partial_parse.msgpack")
set_from_args(Namespace(partial_parse_file_path="specified_partial_parse_path"), {})
ManifestLoader(mock_project, {})
# if specified in flags, we use the specified path
patched_os_exist.assert_called_with("specified_partial_parse_path")