-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema_transform.py
More file actions
25 lines (21 loc) · 884 Bytes
/
schema_transform.py
File metadata and controls
25 lines (21 loc) · 884 Bytes
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
def transform_data(columns, rows):
documents = []
for row in rows:
doc = {columns[i]: row[i] for i in range(len(columns))}
documents.append(doc)
return documents
# def transform_data(columns, rows):
# documents = []
# for row in rows:
# doc = {}
# for i in range(len(columns)):
# value = row[i]
# # Convert MySQL DATE (datetime.date) to datetime.datetime for MongoDB
# if isinstance(value, date) and not isinstance(value, datetime):
# value = datetime.combine(value, datetime.min.time())
# # Convert datetime to ISO format if needed
# elif isinstance(value, datetime):
# value = value.isoformat() # Store as "YYYY-MM-DDTHH:MM:SS"
# doc[columns[i]] = value
# documents.append(doc)
# return documents