Skip to content

Commit 599d6a6

Browse files
yaooqinnCopilot
andcommitted
Add rdd command for individual RDD details
Completes full SHS REST API coverage - all 20 endpoints now have CLI commands. Co-authored-by: Copilot <[email protected]>
1 parent 784a499 commit 599d6a6

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

spark_history_cli/cli.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def repl(state: CliState):
147147
"summary": "Application overview (config + workload)",
148148
"processes": "List miscellaneous processes",
149149
"rdds": "List cached RDDs for current app",
150+
"rdd <id>": "Show RDD details",
150151
"env": "Show application environment",
151152
"logs <path>": "Download event logs to file",
152153
"version": "Show Spark version",
@@ -458,6 +459,15 @@ def repl(state: CliState):
458459
headers, rows = fmt.format_rdd_list(rdds)
459460
output_table(skin, headers, rows)
460461

462+
elif cmd == "rdd":
463+
if not args or not args[0].isdigit():
464+
skin.error("Usage: rdd <rdd-id>")
465+
else:
466+
app_id = state.session.require_app()
467+
data = client.get_rdd(app_id, int(args[0]))
468+
info = fmt.format_rdd_detail(data)
469+
output_status_block(skin, info, title=f"RDD {args[0]}")
470+
461471
elif cmd == "env":
462472
app_id = state.resolve_app_id(None)
463473
env = client.get_environment(app_id)
@@ -979,6 +989,28 @@ def cmd_rdds(state: CliState):
979989
output_table(skin, headers, rows)
980990

981991

992+
@cli.command("rdd")
993+
@click.argument("rdd_id", type=int)
994+
@pass_state
995+
def cmd_rdd(state: CliState, rdd_id: int):
996+
"""Show details for a specific cached RDD.
997+
998+
Examples:
999+
1000+
spark-history-cli -a <app> rdd 42
1001+
"""
1002+
client = state.ensure_client()
1003+
app_id = state.resolve_app_id(None)
1004+
data = client.get_rdd(app_id, rdd_id)
1005+
if state.json_mode:
1006+
output_json(data)
1007+
else:
1008+
from spark_history_cli.utils.repl_skin import ReplSkin
1009+
skin = ReplSkin("spark_history", version=__version__)
1010+
info = fmt.format_rdd_detail(data)
1011+
output_status_block(skin, info, title=f"RDD {rdd_id}")
1012+
1013+
9821014
@cli.command("env")
9831015
@pass_state
9841016
def cmd_env(state: CliState):

spark_history_cli/core/formatters.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,23 @@ def format_rdd_list(rdds: list[dict]) -> tuple[list[str], list[list[str]]]:
496496
return headers, rows
497497

498498

499+
def format_rdd_detail(rdd: dict) -> dict[str, str]:
500+
"""Format RDD storage detail as a status block."""
501+
info = {
502+
"RDD ID": str(rdd.get("id", "")),
503+
"Name": rdd.get("name", ""),
504+
"Storage Level": rdd.get("storageLevel", ""),
505+
"Partitions (cached/total)": f"{rdd.get('numCachedPartitions', 0)}/{rdd.get('numPartitions', 0)}",
506+
"Memory Used": _bytes(rdd.get("memoryUsed")),
507+
"Disk Used": _bytes(rdd.get("diskUsed")),
508+
}
509+
# Add per-partition data distribution if available
510+
partitions = rdd.get("dataDistribution", rdd.get("partitions", []))
511+
if partitions:
512+
info["Data Distribution"] = f"{len(partitions)} entries"
513+
return info
514+
515+
499516
# ── SQL Plan Formatters ───────────────────────────────────────────────
500517

501518

0 commit comments

Comments
 (0)