-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathload_json.py
51 lines (43 loc) · 1.38 KB
/
load_json.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
#!/usr/bin/env python
import os
import sys
import snowflake.connector
# Get the password from an appropriate env variable
PASSWORD = os.getenv('SNOWSQL_PWD')
# Get the other login info etc. from the command line.
if len(sys.argv) < 6:
print("ERROR: Please pass the following command-line parameters in order:")
print(" user, account, warehouse, database, schema [, password].")
sys.exit(-1)
else:
USER = sys.argv[1]
ACCOUNT = sys.argv[2]
WAREHOUSE = sys.argv[3]
DATABASE = sys.argv[4]
SCHEMA = sys.argv[5]
# Note that the command-line password (if any) overrides the env var (if any).
if len(sys.argv) >= 7:
PASSWORD = sys.argv[6]
# If the password wasn't set either in the environment var or on command line...
if PASSWORD == None or PASSWORD == '':
print("ERROR: Set password, e.g. with SNOWSQL_PWD environment variable")
sys.exit(-2)
print("Connecting...")
# -- (> ------------------- SECTION=connect_to_snowflake --------------------
con = snowflake.connector.connect(
user=USER,
password=PASSWORD,
account=ACCOUNT,
warehouse=WAREHOUSE,
database=DATABASE,
schema=SCHEMA
)
# -- <) ---------------------------- END_SECTION ----------------------------
cs = con.cursor()
try:
cs.execute("put file://data/sales.json @sf_tut_stage auto_compress=true")
one_row = cs.fetchone()
print(one_row[0])
finally:
cs.close()
con.close()