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

Function defs

misc/python/materialize/mzexplore/extract.py:39–118  ·  view source on GitHub ↗

Extract CREATE statements for selected catalog items. Processes only items that match the ILIKE pattern defined by the parameter triple (DATABASE, SCHEMA, NAME).

(
    target: Path,
    database: str,
    schema: str,
    name: str,
    db_port: int,
    db_host: str,
    db_user: str,
    db_pass: str | None,
    db_require_ssl: bool,
    mzfmt: bool,
)

Source from the content-addressed store, hash-verified

37
38
39def defs(
40 target: Path,
41 database: str,
42 schema: str,
43 name: str,
44 db_port: int,
45 db_host: str,
46 db_user: str,
47 db_pass: str | None,
48 db_require_ssl: bool,
49 mzfmt: bool,
50) -> None:
51 """
52 Extract CREATE statements for selected catalog items.
53
54 Processes only items that match the ILIKE pattern defined by the parameter
55 triple (DATABASE, SCHEMA, NAME).
56 """
57
58 # Ensure that the target dir exists.
59 target.mkdir(parents=True, exist_ok=True)
60
61 with closing(
62 sql.Database(
63 port=db_port,
64 host=db_host,
65 user=db_user,
66 database=None,
67 password=db_pass,
68 require_ssl=db_require_ssl,
69 )
70 ) as db:
71 output_template = string.Template(textwrap.dedent("""
72 -- id: $id
73 -- oid: $oid
74 $create_sql
75 """).lstrip())
76
77 # Extract materialized view definitions
78 # -------------------------------------
79
80 for item in db.catalog_items(database, schema, name, system=False):
81 item_database = sql.identifier(item["database"])
82 item_schema = sql.identifier(item["schema"])
83 item_name = sql.identifier(item["name"])
84 fqname = f"{item_database}.{item_schema}.{item_name}"
85
86 try:
87 item_type = ItemType(item["type"])
88 except ValueError:
89 warn(f"Unsupported item type `{item['type']}` for {fqname}")
90 continue
91
92 create_file = CreateFile(
93 database=item["database"],
94 schema=item["schema"],
95 name=item["name"],
96 item_type=item_type,

Callers

nothing calls this directly

Calls 13

skipMethod · 0.95
show_createMethod · 0.95
sqlMethod · 0.95
pathMethod · 0.95
folderMethod · 0.95
ItemTypeClass · 0.90
warnFunction · 0.90
CreateFileClass · 0.90
infoFunction · 0.90
catalog_itemsMethod · 0.80
query_oneMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected