-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy path10_insert_data.py
More file actions
42 lines (34 loc) · 1.08 KB
/
10_insert_data.py
File metadata and controls
42 lines (34 loc) · 1.08 KB
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
# Copyright 2023-2025 Broadcom
# SPDX-License-Identifier: Apache-2.0
import json
import pathlib
from vdk.api.job_input import IJobInput
def run(job_input: IJobInput):
data_job_dir = pathlib.Path(job_input.get_job_directory())
data_file = data_job_dir / "data.json"
if data_file.exists():
with open(data_file) as f:
data = json.load(f)
rows = [tuple(i.values()) for i in data]
insert_query = """
INSERT INTO memory.default.test_dag_two VALUES
""" + ", ".join(
str(i) for i in rows
)
job_input.execute_query(
"""
CREATE TABLE IF NOT EXISTS memory.default.test_dag_two
(
id integer,
first_name varchar,
last_name varchar,
city varchar,
country varchar,
phone varchar
)
"""
)
job_input.execute_query(insert_query)
print("Success! The data was send trino.")
else:
print("No data File Available! Exiting job execution!")