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

Function defs

misc/python/materialize/mzexplore/clone.py:27–166  ·  view source on GitHub ↗

Generate a DDL script that clones object_ids and dependencies that live in the same cluster into a different cluster.

(
    ddl_out: TextIO,
    cmp_out: TextIO,
    database: str,
    schema: str,
    cluster: str,
    object_ids: list[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

25
26
27def defs(
28 ddl_out: TextIO,
29 cmp_out: TextIO,
30 database: str,
31 schema: str,
32 cluster: str,
33 object_ids: list[str],
34 db_port: int,
35 db_host: str,
36 db_user: str,
37 db_pass: str | None,
38 db_require_ssl: bool,
39 mzfmt: bool,
40) -> None:
41 """
42 Generate a DDL script that clones object_ids and dependencies that live in
43 the same cluster into a different cluster.
44 """
45
46 database_new = sql.identifier(database, True)
47 schema_new = sql.identifier(schema, True)
48 cluster_new = sql.identifier(cluster, True)
49
50 with closing(
51 sql.Database(
52 port=db_port,
53 host=db_host,
54 user=db_user,
55 database=None,
56 password=db_pass,
57 require_ssl=db_require_ssl,
58 )
59 ) as db:
60 output_template = string.Template(textwrap.dedent("""
61 -- original id: $id
62 $create_sql
63 """).lstrip())
64
65 # Extract dependencies
66 # --------------------
67
68 if len(object_ids) == 0:
69 msg = "At least one object_id necessary"
70 raise ValueError(msg)
71
72 old_clusters = list(db.object_clusters(object_ids))
73 if len(old_clusters) != 1:
74 msg = f"Cannot find unique old cluster for object ids: {object_ids}"
75 raise ValueError(msg)
76
77 [cluster_old] = old_clusters
78
79 if cluster_old["name"] == cluster:
80 msg = f"Old and new clusters can't have the same name: {cluster}"
81 raise ValueError(msg)
82
83 # Replacement pattern for clusters.
84 cluster_str_old = f"IN CLUSTER {sql.identifier(cluster_old['name'], True)}"

Callers

nothing calls this directly

Calls 15

show_createMethod · 0.95
create_name_oldMethod · 0.95
create_name_newMethod · 0.95
aliased_ref_oldMethod · 0.95
aliased_ref_newMethod · 0.95
index_on_ref_oldMethod · 0.95
index_on_ref_newMethod · 0.95
simple_ref_oldMethod · 0.95
simple_ref_newMethod · 0.95
sqlMethod · 0.95
ItemTypeClass · 0.90
warnFunction · 0.90

Tested by

no test coverage detected