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

Method value

misc/python/materialize/workload_replay/column.py:215–361  ·  view source on GitHub ↗

Generate a value suitable for SQL queries or COPY operations.

(self, rng: random.Random, in_query: bool = True)

Source from the content-addressed store, hash-verified

213 raise ValueError(f"Unhandled data type {self.typ}")
214
215 def value(self, rng: random.Random, in_query: bool = True) -> Any:
216 """Generate a value suitable for SQL queries or COPY operations."""
217 if self.default and rng.randrange(10) == 0 and self.default != "NULL":
218 return str(self.default) if in_query else self.default
219
220 if self.nullable and rng.randrange(10) == 0:
221 return "NULL" if in_query else None
222
223 if self.typ == "boolean":
224 val = rng.random() < 0.2
225 return ("true" if val else "false") if in_query else val
226
227 elif self.typ == "smallint":
228 val = long_tail_int(-32768, 32767, rng=rng)
229 return str(val) if in_query else val
230
231 elif self.typ == "integer":
232 val = long_tail_int(-2147483648, 2147483647, rng=rng)
233 return str(val) if in_query else val
234
235 elif self.typ == "bigint":
236 val = long_tail_int(-9223372036854775808, 9223372036854775807, rng=rng)
237 return str(val) if in_query else val
238
239 elif self.typ == "uint2":
240 val = long_tail_int(0, 65535, rng=rng)
241 return str(val) if in_query else val
242
243 elif self.typ == "uint4":
244 val = long_tail_int(0, 4294967295, rng=rng)
245 return str(val) if in_query else val
246
247 elif self.typ == "uint8":
248 val = long_tail_int(0, 18446744073709551615, rng=rng)
249 return str(val) if in_query else val
250
251 elif self.typ in ("float", "double precision", "numeric"):
252 shaped = self._shaped_float(rng)
253 if shaped is not None:
254 return str(shaped) if in_query else shaped
255 val = long_tail_float(-1_000_000_000.0, 1_000_000_000.0, rng=rng)
256 return str(val) if in_query else val
257
258 elif self.typ in ("text", "bytea"):
259 shaped = self._shaped_text(rng)
260 if shaped is not None:
261 return literal(shaped) if in_query else shaped
262 s = long_tail_text(self.chars, 100, self._hot_strings, rng=rng)
263 return literal(s) if in_query else s
264
265 elif self.typ in ("character", "character varying"):
266 shaped = self._shaped_text(rng)
267 if shaped is not None:
268 return literal(shaped) if in_query else shaped
269 s = long_tail_text(self.chars, 10, self._hot_strings, rng=rng)
270 return literal(s) if in_query else s
271
272 elif self.typ == "uuid":

Callers 3

ingestFunction · 0.45
_copy_chunkFunction · 0.45
_mysql_chunkFunction · 0.45

Calls 7

_shaped_floatMethod · 0.95
_shaped_textMethod · 0.95
_random_dateMethod · 0.95
long_tail_intFunction · 0.90
long_tail_floatFunction · 0.90
long_tail_textFunction · 0.90
joinMethod · 0.45

Tested by

no test coverage detected