Skip to content

Commit

Permalink
Add --dry-run option to validate.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajwelch4 committed Mar 15, 2023
1 parent a7889bf commit 09a50e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
22 changes: 18 additions & 4 deletions data_validation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,12 @@ def convert_config_to_yaml(args, config_managers):
return yaml_config


def run_validation(config_manager, verbose=False):
def run_validation(config_manager, dry_run=False, verbose=False):
"""Run a single validation.
Args:
config_manager (ConfigManager): Validation config manager instance.
dry_run (bool): Print source and target SQL to stdout in lieu of validation.
verbose (bool): Validation setting to log queries run.
"""
validator = DataValidation(
Expand All @@ -432,7 +433,18 @@ def run_validation(config_manager, verbose=False):
result_handler=None,
verbose=verbose,
)
validator.execute()
if dry_run:
print(
json.dumps(
{
"source_query": validator.validation_builder.get_source_query().compile(),
"target_query": validator.validation_builder.get_target_query().compile(),
},
indent=4
)
)
else:
validator.execute()


def run_validations(args, config_managers):
Expand All @@ -449,15 +461,17 @@ def run_validations(args, config_managers):
config_manager.config[consts.CONFIG_FILE],
)
try:
run_validation(config_manager, verbose=args.verbose)
run_validation(
config_manager, dry_run=args.dry_run, verbose=args.verbose
)
except Exception as e:
logging.error(
"Error %s occured while running config file %s. Skipping it for now.",
str(e),
config_manager.config[consts.CONFIG_FILE],
)
else:
run_validation(config_manager, verbose=args.verbose)
run_validation(config_manager, dry_run=args.dry_run, verbose=args.verbose)


def store_yaml_config_file(args, config_managers):
Expand Down
7 changes: 7 additions & 0 deletions data_validation/cli_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ def _configure_validate_parser(subparsers):
"validate", help="Run a validation and optionally store to config"
)

validate_parser.add_argument(
"--dry-run",
"-dr",
action="store_true",
help="Prints source and target SQL to stdout in lieu of performing a validation.",
)

validate_subparsers = validate_parser.add_subparsers(dest="validate_cmd")

column_parser = validate_subparsers.add_parser(
Expand Down

0 comments on commit 09a50e7

Please sign in to comment.