MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / changes

Function changes

misc/python/materialize/mzexplore/analyze.py:22–79  ·  view source on GitHub ↗

Append sections to an `*.md` file with items corresponding to changes pairs of optimized plans for the same catalog item extracted with the given `base` and `diff` suffix.

(
    out: TextIO,
    target: Path,
    header_name: str,
    base_suffix: str,
    diff_suffix: str,
)

Source from the content-addressed store, hash-verified

20
21
22def changes(
23 out: TextIO,
24 target: Path,
25 header_name: str,
26 base_suffix: str,
27 diff_suffix: str,
28) -> None:
29 """
30 Append sections to an `*.md` file with items corresponding to changes pairs
31 of optimized plans for the same catalog item extracted with the given `base`
32 and `diff` suffix.
33 """
34
35 # Ensure that the target dir exists
36 if not target.is_dir():
37 warn(f"Target path `{target}` is not a folder")
38 return
39
40 info(f"Comparing `{base_suffix}` vs `{diff_suffix}` " f"plans in {target}")
41
42 info("Comparing optimized plans")
43 out.write(dedent(f"""
44 ## {header_name}
45
46 """).lstrip("\n"))
47
48 for base_path in target.glob(f"**/*.optimized_plan.{base_suffix}.txt"):
49 base = explain_file(base_path)
50 if base is None:
51 warn(f"File {base_path} is not recognized as an ExplainFile")
52 continue
53
54 diff = explain_diff(base=base, diff_suffix=diff_suffix)
55 if not (target / diff.path()).is_file():
56 warn(f"Cannot find diff file {diff.file_name()} for {base}")
57 continue
58
59 item_type = base.item_type
60 database = sql.identifier(base.database)
61 schema = sql.identifier(base.schema)
62 name = sql.identifier(base.name)
63
64 base_data = (target / base.path()).read_text(encoding="utf8")
65 diff_data = (target / diff.path()).read_text(encoding="utf8")
66
67 if base_data != diff_data:
68 info(f"Found diff at {item_type.sql()} `{database}.{schema}.{name}`")
69
70 out.write(dedent(f"""
71 - TODO(REGRESSION|IMPROVEMENT) in {item_type.sql()} `{database}.{schema}.{name}`
72
73 ```bash
74 code --diff \\
75 {target / base.path()} \\
76 {target / diff.path()}
77 ```
78
79 """).lstrip("\n"))

Callers

nothing calls this directly

Calls 8

warnFunction · 0.90
infoFunction · 0.90
explain_fileFunction · 0.90
explain_diffFunction · 0.90
writeMethod · 0.45
pathMethod · 0.45
file_nameMethod · 0.45
sqlMethod · 0.45

Tested by

no test coverage detected