Skip to content

Commit

Permalink
rename to dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Nov 1, 2023
1 parent 8c99a48 commit 184b6d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
8 changes: 3 additions & 5 deletions core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections.abc import Hashable
from dataclasses import dataclass, field
from typing import Optional, TypeVar, Any, Type, Dict, Iterator, Tuple, Set, Union, FrozenSet
import uuid

from dbt.contracts.graph.nodes import SourceDefinition, ManifestNode, ResultNode, ParsedNode
from dbt.contracts.relation import (
Expand Down Expand Up @@ -37,7 +36,7 @@ class BaseRelation(FakeAPIObject, Hashable):
include_policy: Policy = field(default_factory=lambda: Policy())
quote_policy: Policy = field(default_factory=lambda: Policy())
dbt_created: bool = False
sample: Optional[int] = None
dry_run: bool = False

# register relation types that can be renamed for the purpose of replacing relations using stages and backups
# adding a relation type here also requires defining the associated rename macro
Expand Down Expand Up @@ -195,9 +194,8 @@ def _render_iterator(self) -> Iterator[Tuple[Optional[ComponentName], Optional[s
def render(self) -> str:
# if there is nothing set, this will return the empty string.
rendered_parts = ".".join(part for _, part in self._render_iterator() if part is not None)
if self.sample and rendered_parts:
alias = f"_dbt_sample_{uuid.uuid4().hex.upper()[:6]}"
return f"(select * from {rendered_parts} limit {self.sample}) {alias}"
if self.dry_run and rendered_parts:
return f"(select * from {rendered_parts} limit 0) _dbt_dryrun_subq"

Check warning on line 198 in core/dbt/adapters/base/relation.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/relation.py#L198

Added line #L198 was not covered by tests
return rendered_parts

def quoted(self, identifier):
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def docs_serve(ctx, **kwargs):
@p.profile
@p.profiles_dir
@p.project_dir
@p.sample
@p.dry_run
@p.select
@p.selector
@p.inline
Expand Down Expand Up @@ -457,7 +457,7 @@ def debug(ctx, **kwargs):
@p.target
@p.vars
@p.source
@p.dry_run
@p.dry_run_deps
@p.lock
@p.upgrade
@p.add_package
Expand Down Expand Up @@ -600,7 +600,7 @@ def parse(ctx, **kwargs):
@p.profile
@p.profiles_dir
@p.project_dir
@p.sample
@p.dry_run
@p.select
@p.selector
@p.state
Expand Down
15 changes: 7 additions & 8 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
)

dry_run = click.option(
"--dry-run",
envvar=None,
help="Limit input rows to 0 when resolving dbt ref and sources",
is_flag=True,
)

dry_run_deps = click.option(
"--dry-run",
envvar=None,
help="Option to run `dbt deps --add-package` without updating package-lock.yml file.",
Expand Down Expand Up @@ -415,14 +422,6 @@
hidden=True,
)

sample = click.option(
"--sample",
envvar="DBT_SAMPLE",
help="Limit by sample rows when resolving dbt ref and sources.",
type=click.INT,
default=None,
)

model_decls = ("-m", "--models", "--model")
select_decls = ("-s", "--select")
select_attrs = {
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ def create_relation(self, target_model: ManifestNode) -> RelationProxy:
if target_model.is_ephemeral_model:
self.model.set_cte(target_model.unique_id, None)
return self.Relation.create_ephemeral_from_node(

Check warning on line 534 in core/dbt/context/providers.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/context/providers.py#L534

Added line #L534 was not covered by tests
self.config, target_model, sample=self.config.args.sample
self.config, target_model, dry_run=self.config.args.dry_run
)
else:
return self.Relation.create_from(

Check warning on line 538 in core/dbt/context/providers.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/context/providers.py#L538

Added line #L538 was not covered by tests
self.config, target_model, sample=self.config.args.sample
self.config, target_model, dry_run=self.config.args.dry_run
)

def validate(
Expand Down Expand Up @@ -594,7 +594,7 @@ def resolve(self, source_name: str, table_name: str):
target_kind="source",
disabled=(isinstance(target_source, Disabled)),
)
return self.Relation.create_from_source(target_source, sample=self.config.args.sample)
return self.Relation.create_from_source(target_source, dry_run=self.config.args.dry_run)

Check warning on line 597 in core/dbt/context/providers.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/context/providers.py#L597

Added line #L597 was not covered by tests


# metric` implementations
Expand Down

0 comments on commit 184b6d9

Please sign in to comment.