Skip to content

Commit

Permalink
Merge main and handle conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit committed Jun 7, 2023
2 parents 4fa7db8 + f4253da commit c7dd5e4
Show file tree
Hide file tree
Showing 51 changed files with 1,803 additions and 724 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20230509-212935.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: nodes in packages respect custom generate_alias_name, generate_schema_name,
generate_database_name macro overrides defined in packages
time: 2023-05-09T21:29:35.557761-04:00
custom:
Author: michelleark
Issue: "7444"
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230602-083302.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: dbt retry
time: 2023-06-02T08:33:02.410456-07:00
custom:
Author: stu-k aranke
Issue: "7299"
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230604-025956.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Revamp debug, add --connection flag. Prepare for future refactors/interface changes.
time: 2023-06-04T02:59:56.28283-07:00
custom:
Author: versusfacit
Issue: 7104
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230604-080052.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix null-safe equals comparison via `equals`
time: 2023-06-04T08:00:52.537967-06:00
custom:
Author: dbeatty10
Issue: "7778"
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230605-222039.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: ' Validate public models are not materialized as ephemeral'
time: 2023-06-05T22:20:39.382019-04:00
custom:
Author: michelleark
Issue: "7226"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230525-073651.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Improve warnings for constraints and materialization types
time: 2023-05-25T07:36:51.855641-05:00
custom:
Author: emmyoop
Issue: "7335"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230530-104228.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix empty --warn-error-options error message
time: 2023-05-30T10:42:28.382804-04:00
custom:
Author: michelleark
Issue: "7730"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230605-124425.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: fix RuntimeError when removing project dependency from dependencies.yml
time: 2023-06-05T12:44:25.978022-04:00
custom:
Author: michelleark
Issue: "7743"
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20230605-234706.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Create `add_from_artifact` to populate `state_relation` field of nodes
time: 2023-06-05T23:47:06.581326-07:00
custom:
Author: stu-k aranke
Issue: "7551"
5 changes: 4 additions & 1 deletion core/dbt/cli/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ def add_fn(x):

spinal_cased = k.replace("_", "-")

if v in (None, False):
if k == "macro" and command == CliCommand.RUN_OPERATION:
add_fn(v)
elif v in (None, False):
add_fn(f"--no-{spinal_cased}")
elif v is True:
add_fn(f"--{spinal_cased}")
Expand Down Expand Up @@ -384,6 +386,7 @@ def command_args(command: CliCommand) -> ArgsList:
CliCommand.SNAPSHOT: cli.snapshot,
CliCommand.SOURCE_FRESHNESS: cli.freshness,
CliCommand.TEST: cli.test,
CliCommand.RETRY: cli.retry,
}
click_cmd: Optional[ClickCommand] = CMD_DICT.get(command, None)
if click_cmd is None:
Expand Down
35 changes: 34 additions & 1 deletion core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from dbt.task.generate import GenerateTask
from dbt.task.init import InitTask
from dbt.task.list import ListTask
from dbt.task.retry import RetryTask
from dbt.task.run import RunTask
from dbt.task.run_operation import RunOperationTask
from dbt.task.seed import SeedTask
Expand Down Expand Up @@ -401,6 +402,7 @@ def show(ctx, **kwargs):
# dbt debug
@cli.command("debug")
@click.pass_context
@p.debug_connection
@p.profile
@p.profiles_dir_exists_false
@p.project_dir
Expand All @@ -410,7 +412,7 @@ def show(ctx, **kwargs):
@requires.postflight
@requires.preflight
def debug(ctx, **kwargs):
"""Test the database connection and show information for debugging purposes. Not to be confused with the --debug option which increases verbosity."""
"""Show information on the current dbt environment and check dependencies, then test the database connection. Not to be confused with the --debug option which increases verbosity."""

task = DebugTask(
ctx.obj["flags"],
Expand Down Expand Up @@ -575,6 +577,36 @@ def run(ctx, **kwargs):
return results, success


# dbt run
@cli.command("retry")
@click.pass_context
@p.project_dir
@p.profiles_dir
@p.vars
@p.profile
@p.target
@p.state
@p.threads
@p.fail_fast
@requires.postflight
@requires.preflight
@requires.profile
@requires.project
@requires.runtime_config
@requires.manifest
def retry(ctx, **kwargs):
"""Retry the nodes that failed in the previous run."""
task = RetryTask(
ctx.obj["flags"],
ctx.obj["runtime_config"],
ctx.obj["manifest"],
)

results = task.run()
success = task.interpret_results(results)
return results, success


# dbt run operation
@cli.command("run-operation")
@click.pass_context
Expand All @@ -585,6 +617,7 @@ def run(ctx, **kwargs):
@p.project_dir
@p.target
@p.target_path
@p.threads
@p.vars
@requires.postflight
@requires.preflight
Expand Down
9 changes: 5 additions & 4 deletions core/dbt/cli/option_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from click import ParamType, Choice

from dbt.config.utils import parse_cli_vars
from dbt.exceptions import ValidationError
from dbt.config.utils import parse_cli_yaml_string
from dbt.exceptions import ValidationError, DbtValidationError, OptionNotYamlDictError

from dbt.helper_types import WarnErrorOptions

Expand All @@ -16,8 +16,9 @@ def convert(self, value, param, ctx):
if not isinstance(value, str):
self.fail(f"Cannot load YAML from type {type(value)}", param, ctx)
try:
return parse_cli_vars(value)
except ValidationError:
param_option_name = param.opts[0] if param.opts else param.name
return parse_cli_yaml_string(value, param_option_name.strip("-"))
except (ValidationError, DbtValidationError, OptionNotYamlDictError):
self.fail(f"String '{value}' is not valid YAML", param, ctx)


Expand Down
7 changes: 7 additions & 0 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@
type=click.Path(),
)

debug_connection = click.option(
"--connection",
envvar=None,
help="Test the connection to the target database independent of dependency checks.",
is_flag=True,
)

threads = click.option(
"--threads",
envvar=None,
Expand Down
1 change: 1 addition & 0 deletions core/dbt/cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Command(Enum):
SNAPSHOT = "snapshot"
SOURCE_FRESHNESS = "freshness"
TEST = "test"
RETRY = "retry"

@classmethod
def from_str(cls, s: str) -> "Command":
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def parse_cli_yaml_string(var_string: str, cli_option_name: str) -> Dict[str, An
return cli_vars
else:
raise OptionNotYamlDictError(var_type, cli_option_name)
except DbtValidationError:
except (DbtValidationError, OptionNotYamlDictError):
fire_event(InvalidOptionYAML(option_name=cli_option_name))
raise
38 changes: 33 additions & 5 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
BaseNode,
ManifestOrPublicNode,
ModelNode,
RelationalNode,
)
from dbt.contracts.graph.unparsed import SourcePatch, NodeVersion, UnparsedVersion
from dbt.contracts.graph.manifest_upgrade import upgrade_manifest_json
Expand Down Expand Up @@ -608,26 +609,36 @@ def filter(candidate: MacroCandidate) -> bool:
return candidates.last()

def find_generate_macro_by_name(
self, component: str, root_project_name: str
self, component: str, root_project_name: str, imported_package: Optional[str] = None
) -> Optional[Macro]:
"""
The `generate_X_name` macros are similar to regular ones, but ignore
imported packages.
The default `generate_X_name` macros are similar to regular ones, but only
includes imported packages when searching for a package.
- if package is not provided:
- if there is a `generate_{component}_name` macro in the root
project, return it
- return the `generate_{component}_name` macro from the 'dbt'
internal project
- if package is provided
- return the `generate_{component}_name` macro from the imported
package, if one exists
"""

def filter(candidate: MacroCandidate) -> bool:
return candidate.locality != Locality.Imported
if imported_package:
return (
candidate.locality == Locality.Imported
and imported_package == candidate.macro.package_name
)
else:
return candidate.locality != Locality.Imported

candidates: CandidateList = self._find_macros_by_name(
name=f"generate_{component}_name",
root_project_name=root_project_name,
# filter out imported packages
filter=filter,
)

return candidates.last()

def _find_macros_by_name(
Expand Down Expand Up @@ -1133,6 +1144,23 @@ def merge_from_artifact(
sample = list(islice(merged, 5))
fire_event(MergedFromState(num_merged=len(merged), sample=sample))

# Called by CloneTask.defer_to_manifest
def add_from_artifact(
self,
other: "WritableManifest",
) -> None:
"""Update this manifest by *adding* information about each node's location
in the other manifest.
Only non-ephemeral refable nodes are examined.
"""
refables = set(NodeType.refable())
for unique_id, node in other.nodes.items():
current = self.nodes.get(unique_id)
if current and (node.resource_type in refables and not node.is_ephemeral):
state_relation = RelationalNode(node.database, node.schema, node.alias)
self.nodes[unique_id] = current.replace(state_relation=state_relation)

# Methods that were formerly in ParseResult

def add_macro(self, source_file: SourceFile, macro: Macro):
Expand Down
9 changes: 9 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ def add_macro(self, value: str):
self.macros.append(value)


@dataclass
class RelationalNode(HasRelationMetadata):
alias: str

@property
def identifier(self):
return self.alias


@dataclass
class DependsOn(MacroDependsOn):
nodes: List[str] = field(default_factory=list)
Expand Down
10 changes: 10 additions & 0 deletions core/dbt/events/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,16 @@ message DeprecatedReferenceMsg {
DeprecatedReference data = 2;
}

// I068
message UnsupportedConstraintMaterialization {
string materialized = 1;
}

message UnsupportedConstraintMaterializationMsg {
EventInfo info = 1;
UnsupportedConstraintMaterialization data = 2;
}


// M - Deps generation

Expand Down
13 changes: 13 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,19 @@ def message(self) -> str:
return msg


class UnsupportedConstraintMaterialization(WarnLevel):
def code(self):
return "I068"

def message(self) -> str:
msg = (
f"Constraint types are not supported for {self.materialized} materializations and will "
"be ignored. Set 'warn_unsupported: false' on this constraint to ignore this warning."
)

return line_wrap_message(warning_tag(msg))


# =======================================================
# M - Deps generation
# =======================================================
Expand Down
878 changes: 441 additions & 437 deletions core/dbt/events/types_pb2.py

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,12 +1254,15 @@ def get_message(self) -> str:


class InvalidAccessTypeError(ParsingError):
def __init__(self, unique_id: str, field_value: str):
def __init__(self, unique_id: str, field_value: str, materialization: Optional[str] = None):
self.unique_id = unique_id
self.field_value = field_value
msg = (
f"Node {self.unique_id} has an invalid value ({self.field_value}) for the access field"
self.materialization = materialization

with_materialization = (
f"with '{self.materialization}' materialization " if self.materialization else ""
)
msg = f"Node {self.unique_id} {with_materialization}has an invalid value ({self.field_value}) for the access field"
super().__init__(msg=msg)


Expand Down
Loading

0 comments on commit c7dd5e4

Please sign in to comment.