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

Function _mysql_chunk

misc/python/materialize/workload_replay/data.py:178–208  ·  view source on GitHub ↗

Generate random data and INSERT into MySQL.

(
    conn_params: dict[str, Any],
    table: str,
    column_dicts: list[dict[str, Any]],
    num_rows: int,
    rng_seed: int,
)

Source from the content-addressed store, hash-verified

176
177
178def _mysql_chunk(
179 conn_params: dict[str, Any],
180 table: str,
181 column_dicts: list[dict[str, Any]],
182 num_rows: int,
183 rng_seed: int,
184) -> int:
185 """Generate random data and INSERT into MySQL."""
186 import pymysql
187
188 rng = random.Random(rng_seed)
189 columns = [
190 Column(c["name"], c["type"], c["nullable"], c["default"], c.get("data_shape"))
191 for c in column_dicts
192 ]
193
194 conn = pymysql.connect(**conn_params)
195
196 batch_size = 10000
197 for start in range(0, num_rows, batch_size):
198 batch_rows = min(batch_size, num_rows - start)
199 rows_sql = []
200 for _ in range(batch_rows):
201 row = [col.value(rng) for col in columns]
202 rows_sql.append("(" + ", ".join(row) + ")")
203 stmt = f"INSERT INTO {table} VALUES " + ", ".join(rows_sql)
204 with conn.cursor() as cur:
205 cur.execute(stmt)
206
207 conn.close()
208 return num_rows
209
210
211def _submit_chunks(

Callers

nothing calls this directly

Calls 9

ColumnClass · 0.90
cursorMethod · 0.80
getMethod · 0.45
connectMethod · 0.45
valueMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected