forked from naddeoa/snowflake-whylogs-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-data.py
88 lines (65 loc) · 2.56 KB
/
generate-data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import random
from functools import partial
from faker import Faker # type: ignore
from typing import Any
def conditional(value_getter, override_condition, override_getter, chance=-1.1) -> Any:
if override_condition and random.random() < chance:
return override_getter()
return value_getter()
fake = Faker()
# Number of fake records you wanna create
num_records = 16_000
# Your SQL table name
table_name = "employees"
# Initialize empty list for your SQL rows
sql_rows = []
job_list = ["Software Engineer", "Marketing Manager", "Nurse", "Data Analyst", "Electrician", "Journalist", "Chef", "Architect"]
start_epoch = 1690395957
now_ms_epoch = 1695752819
def generate_random_epoch_between(start: int, end: int) -> int:
"""Generate a random epoch between start and end"""
return random.randint(start, end)
# Generate fake data
for _ in range(num_records):
fake_name = fake.name().replace("'", "''")
fake_role: str = random.choice(job_list)
fake_state = fake.state_abbr(include_territories=False, include_freely_associated_states=False)
hire_date_epoch = generate_random_epoch_between(start_epoch, now_ms_epoch)
fake_salary = conditional(
value_getter=partial(fake.random_int, min=40_000, max=120_000),
override_condition=fake_state == "CA" or fake_role == "Software Engineer",
override_getter=partial(fake.random_int, min=100_000, max=200_000), # California branch makes more
chance=0.5,
)
fake_email = fake.email().replace("'", "''")
fake_phone = fake.phone_number().replace("'", "''")
fake_dob = fake.date_of_birth().strftime("%Y-%m-%d")
fake_ssn = fake.ssn()
years_xp = conditional(
value_getter=partial(fake.random_int, min=0, max=20),
override_condition=fake_state == "NY",
override_getter=partial(fake.random_int, min=0, max=8), # Lots of turnover in the NY office
chance=0.1,
)
row_item_list = [
f"'{fake_name}'",
str(fake_salary),
f"'{fake_role}'",
f"'{fake_state}'",
f"'{fake_email}'",
f"'{fake_phone}'",
f"'{fake_dob}'",
f"'{fake_ssn}'",
f"TO_TIMESTAMP_NTZ({hire_date_epoch})",
str(years_xp),
]
row = ",".join(row_item_list)
sql_rows.append(f"({row})\n")
# Create a single SQL Insert Statement for bulk insert
statements = [
"use whylogs_demo;",
"use warehouse whylogs_warehouse;",
"INSERT INTO employees (name, salary, job, state, email, phone, dob, ssn, hire_date, years_xp) VALUES",
f"{', '.join(sql_rows)};",
]
print("\n".join(statements))