From 9ef249044b05b09d2291d3c2b0c339dbb79aa1a4 Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Mon, 1 Jul 2024 16:40:46 +0530 Subject: [PATCH 1/3] feat(cli): add more details to get cli --- docs/how/updating-datahub.md | 1 + metadata-ingestion/src/datahub/cli/cli_utils.py | 8 +++++++- metadata-ingestion/src/datahub/cli/get_cli.py | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/how/updating-datahub.md b/docs/how/updating-datahub.md index 2bafcdcaa5f89f..e4bee339d418de 100644 --- a/docs/how/updating-datahub.md +++ b/docs/how/updating-datahub.md @@ -22,6 +22,7 @@ This file documents any backwards-incompatible changes in DataHub and assists pe - Protobuf CLI will no longer create binary encoded protoc custom properties. Flag added `-protocProp` in case this behavior is required. +- `datahub get ...` CLI output format changed a bit. To use the older output format pass `datahub get -v 1 ...` ### Potential Downtime diff --git a/metadata-ingestion/src/datahub/cli/cli_utils.py b/metadata-ingestion/src/datahub/cli/cli_utils.py index 1bb3b01e078dd9..c6fda7108a3c43 100644 --- a/metadata-ingestion/src/datahub/cli/cli_utils.py +++ b/metadata-ingestion/src/datahub/cli/cli_utils.py @@ -522,6 +522,7 @@ def get_aspects_for_entity( aspects: List[str], typed: bool = False, cached_session_host: Optional[Tuple[Session, str]] = None, + version: int = 1, ) -> Dict[str, Union[dict, _Aspect]]: # Process non-timeseries aspects non_timeseries_aspects = [a for a in aspects if a not in TIMESERIES_ASPECT_MAP] @@ -553,7 +554,12 @@ def get_aspects_for_entity( aspect_name ) - aspect_dict = a["value"] + if version == 2: + aspect_dict = a + for k in ["name", "version", "type"]: + del aspect_dict[k] + else: + aspect_dict = a["value"] if not typed: aspect_map[aspect_name] = aspect_dict elif aspect_py_class: diff --git a/metadata-ingestion/src/datahub/cli/get_cli.py b/metadata-ingestion/src/datahub/cli/get_cli.py index 6b779f8565a7f3..73bb68dd8c1008 100644 --- a/metadata-ingestion/src/datahub/cli/get_cli.py +++ b/metadata-ingestion/src/datahub/cli/get_cli.py @@ -21,10 +21,18 @@ def get() -> None: @get.command() @click.option("--urn", required=False, type=str) @click.option("-a", "--aspect", required=False, multiple=True, type=str) +@click.option( + "-v", + "--version", + required=False, + type=int, + default=2, + help="Version of get CLI to use.", +) @click.pass_context @upgrade.check_upgrade @telemetry.with_telemetry() -def urn(ctx: Any, urn: Optional[str], aspect: List[str]) -> None: +def urn(ctx: Any, urn: Optional[str], aspect: List[str], version: int) -> None: """ Get metadata for an entity with an optional list of aspects to project. This works for both versioned aspects and timeseries aspects. For timeseries aspects, it fetches the latest value. @@ -39,7 +47,9 @@ def urn(ctx: Any, urn: Optional[str], aspect: List[str]) -> None: logger.debug(f"Using urn from args {urn}") click.echo( json.dumps( - get_aspects_for_entity(entity_urn=urn, aspects=aspect, typed=False), + get_aspects_for_entity( + entity_urn=urn, aspects=aspect, typed=False, version=version + ), sort_keys=True, indent=2, ) From 9bd41d2d396b3959010075106170d36b24cccc2f Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Tue, 2 Jul 2024 15:08:50 +0530 Subject: [PATCH 2/3] code review feedback --- docs/how/updating-datahub.md | 2 +- metadata-ingestion/src/datahub/cli/cli_utils.py | 4 ++-- metadata-ingestion/src/datahub/cli/get_cli.py | 13 ++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/how/updating-datahub.md b/docs/how/updating-datahub.md index e4bee339d418de..0da6c864b2c7a8 100644 --- a/docs/how/updating-datahub.md +++ b/docs/how/updating-datahub.md @@ -22,7 +22,7 @@ This file documents any backwards-incompatible changes in DataHub and assists pe - Protobuf CLI will no longer create binary encoded protoc custom properties. Flag added `-protocProp` in case this behavior is required. -- `datahub get ...` CLI output format changed a bit. To use the older output format pass `datahub get -v 1 ...` +- `datahub get ...` CLI output format changed a bit. To use the older output format pass `datahub get --no-details ...` ### Potential Downtime diff --git a/metadata-ingestion/src/datahub/cli/cli_utils.py b/metadata-ingestion/src/datahub/cli/cli_utils.py index c6fda7108a3c43..d8939ddcff09c7 100644 --- a/metadata-ingestion/src/datahub/cli/cli_utils.py +++ b/metadata-ingestion/src/datahub/cli/cli_utils.py @@ -522,7 +522,7 @@ def get_aspects_for_entity( aspects: List[str], typed: bool = False, cached_session_host: Optional[Tuple[Session, str]] = None, - version: int = 1, + details: bool = False, ) -> Dict[str, Union[dict, _Aspect]]: # Process non-timeseries aspects non_timeseries_aspects = [a for a in aspects if a not in TIMESERIES_ASPECT_MAP] @@ -554,7 +554,7 @@ def get_aspects_for_entity( aspect_name ) - if version == 2: + if details: aspect_dict = a for k in ["name", "version", "type"]: del aspect_dict[k] diff --git a/metadata-ingestion/src/datahub/cli/get_cli.py b/metadata-ingestion/src/datahub/cli/get_cli.py index 73bb68dd8c1008..3eceab99a9ce54 100644 --- a/metadata-ingestion/src/datahub/cli/get_cli.py +++ b/metadata-ingestion/src/datahub/cli/get_cli.py @@ -22,17 +22,16 @@ def get() -> None: @click.option("--urn", required=False, type=str) @click.option("-a", "--aspect", required=False, multiple=True, type=str) @click.option( - "-v", - "--version", + "--details/--no-details", required=False, - type=int, - default=2, - help="Version of get CLI to use.", + is_flag=True, + default=True, + help="Whether to .", ) @click.pass_context @upgrade.check_upgrade @telemetry.with_telemetry() -def urn(ctx: Any, urn: Optional[str], aspect: List[str], version: int) -> None: +def urn(ctx: Any, urn: Optional[str], aspect: List[str], details: bool) -> None: """ Get metadata for an entity with an optional list of aspects to project. This works for both versioned aspects and timeseries aspects. For timeseries aspects, it fetches the latest value. @@ -48,7 +47,7 @@ def urn(ctx: Any, urn: Optional[str], aspect: List[str], version: int) -> None: click.echo( json.dumps( get_aspects_for_entity( - entity_urn=urn, aspects=aspect, typed=False, version=version + entity_urn=urn, aspects=aspect, typed=False, details=details ), sort_keys=True, indent=2, From 5a69a8deabc0ed4356c6424d8a7f0efee6790cd9 Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Tue, 2 Jul 2024 21:47:46 +0530 Subject: [PATCH 3/3] code review feedback --- docs/how/updating-datahub.md | 1 - metadata-ingestion/src/datahub/cli/get_cli.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/how/updating-datahub.md b/docs/how/updating-datahub.md index 0da6c864b2c7a8..2bafcdcaa5f89f 100644 --- a/docs/how/updating-datahub.md +++ b/docs/how/updating-datahub.md @@ -22,7 +22,6 @@ This file documents any backwards-incompatible changes in DataHub and assists pe - Protobuf CLI will no longer create binary encoded protoc custom properties. Flag added `-protocProp` in case this behavior is required. -- `datahub get ...` CLI output format changed a bit. To use the older output format pass `datahub get --no-details ...` ### Potential Downtime diff --git a/metadata-ingestion/src/datahub/cli/get_cli.py b/metadata-ingestion/src/datahub/cli/get_cli.py index 3eceab99a9ce54..46e2fdf5b1f79f 100644 --- a/metadata-ingestion/src/datahub/cli/get_cli.py +++ b/metadata-ingestion/src/datahub/cli/get_cli.py @@ -25,8 +25,8 @@ def get() -> None: "--details/--no-details", required=False, is_flag=True, - default=True, - help="Whether to .", + default=False, + help="Whether to print details from database which help in audit.", ) @click.pass_context @upgrade.check_upgrade