From 184b6d98305c525f33a31dffa6683faa7fd9df8b Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Wed, 1 Nov 2023 13:08:02 -0400 Subject: [PATCH] rename to dry-run --- core/dbt/adapters/base/relation.py | 8 +++----- core/dbt/cli/main.py | 6 +++--- core/dbt/cli/params.py | 15 +++++++-------- core/dbt/context/providers.py | 6 +++--- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/core/dbt/adapters/base/relation.py b/core/dbt/adapters/base/relation.py index d5132c6b8a1..654cda46458 100644 --- a/core/dbt/adapters/base/relation.py +++ b/core/dbt/adapters/base/relation.py @@ -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 ( @@ -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 @@ -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" return rendered_parts def quoted(self, identifier): diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py index 97a48ce4426..e9cde052da6 100644 --- a/core/dbt/cli/main.py +++ b/core/dbt/cli/main.py @@ -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 @@ -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 @@ -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 diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py index 445e7995151..f30147bb52c 100644 --- a/core/dbt/cli/params.py +++ b/core/dbt/cli/params.py @@ -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.", @@ -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 = { diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py index b7334118c39..fa97050ac5e 100644 --- a/core/dbt/context/providers.py +++ b/core/dbt/context/providers.py @@ -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( - 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( - self.config, target_model, sample=self.config.args.sample + self.config, target_model, dry_run=self.config.args.dry_run ) def validate( @@ -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) # metric` implementations