Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ingest): add rewrite option for metadata file check #5763

Merged
merged 5 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 37 additions & 4 deletions metadata-ingestion/src/datahub/cli/check_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import shutil
import tempfile

import click

from datahub import __package_name__
from datahub.cli.json_file import check_mce_file
from datahub.ingestion.run.pipeline import Pipeline
from datahub.ingestion.sink.sink_registry import sink_registry
from datahub.ingestion.source.source_registry import source_registry
from datahub.ingestion.transformer.transform_registry import transform_registry
Expand All @@ -15,11 +19,40 @@ def check() -> None:

@check.command()
@click.argument("json-file", type=click.Path(exists=True, dir_okay=False))
def mce_file(json_file: str) -> None:
"""Check the schema of a MCE JSON file."""
@click.option(
"--rewrite",
default=False,
is_flag=True,
help="Rewrite the JSON file to it's canonical form.",
)
def metadata_file(json_file: str, rewrite: bool) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to leave the old command in for backwards compat, with help text saying: "Deprecated: use metadata_file instead"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we don't reference this command in our docs at all, my suspicion is that nobody was really using it (we really should have telemetry for cli commands by default). We can add the alias + deprecation warning, but I don't think it's necessary.

"""Check the schema of a metadata (MCE or MCP) JSON file."""

if not rewrite:
report = check_mce_file(json_file)
click.echo(report)

else:
with tempfile.NamedTemporaryFile() as out_file:
pipeline = Pipeline.create(
{
"source": {
"type": "file",
"config": {"filename": json_file},
"extractor": "generic",
"extractor_config": {"set_system_metadata": False},
},
"sink": {
"type": "file",
"config": {"filename": out_file.name},
},
}
)

pipeline.run()
pipeline.raise_from_status()

report = check_mce_file(json_file)
click.echo(report)
shutil.copy(out_file.name, json_file)


@check.command()
Expand Down
Loading