-
Notifications
You must be signed in to change notification settings - Fork 22
/
FastLoadBatch.py
137 lines (109 loc) · 4.94 KB
/
FastLoadBatch.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright 2019 by Teradata Corporation. All rights reserved.
# This sample program demonstrates how to FastLoad batches of rows.
import teradatasql
with teradatasql.connect (host="whomooz", user="guest", password="please") as con:
with con.cursor () as cur:
sTableName = "FastLoadBatch"
sRequest = "DROP TABLE " + sTableName
print (sRequest)
cur.execute (sRequest, ignoreErrors=3807)
sRequest = "CREATE TABLE " + sTableName + " (c1 INTEGER NOT NULL, c2 VARCHAR(10))"
print (sRequest)
cur.execute (sRequest)
try:
print ("con.autocommit = False")
con.autocommit = False
try:
aaoValues = [
[1, # c1 INTEGER NOT NULL
None, # c2 VARCHAR
],
[2, # c1 INTEGER NOT NULL
"abc", # c2 VARCHAR
],
[3, # c1 INTEGER NOT NULL
"def", # c2 VARCHAR
],
]
sInsert = "{fn teradata_try_fastload}INSERT INTO " + sTableName + " (?, ?)"
print (sInsert)
cur.execute (sInsert, aaoValues)
# obtain the warnings and errors for transmitting the data to the database -- the acquisition phase
sRequest = "{fn teradata_nativesql}{fn teradata_get_warnings}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
sRequest = "{fn teradata_nativesql}{fn teradata_get_errors}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
sRequest = "{fn teradata_nativesql}{fn teradata_logon_sequence_number}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
aaoValues = [
[4, # c1 INTEGER NOT NULL
"mno", # c2 VARCHAR
],
[5, # c1 INTEGER NOT NULL
None, # c2 VARCHAR
],
[6, # c1 INTEGER NOT NULL
"pqr", # c2 VARCHAR
],
]
print (sInsert)
cur.execute (sInsert, aaoValues)
# obtain the warnings and errors for transmitting the data to the database -- the acquisition phase
sRequest = "{fn teradata_nativesql}{fn teradata_get_warnings}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
sRequest = "{fn teradata_nativesql}{fn teradata_get_errors}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
aaoValues = [
[7, # c1 INTEGER NOT NULL
"uvw", # c2 VARCHAR
],
[8, # c1 INTEGER NOT NULL
"xyz", # c2 VARCHAR
],
[9, # c1 INTEGER NOT NULL
None, # c2 VARCHAR
],
]
print (sInsert)
cur.execute (sInsert, aaoValues)
# obtain the warnings and errors for transmitting the data to the database -- the acquisition phase
sRequest = "{fn teradata_nativesql}{fn teradata_get_warnings}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
sRequest = "{fn teradata_nativesql}{fn teradata_get_errors}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
print ("con.commit()")
con.commit ()
# obtain the warnings and errors for the apply phase
sRequest = "{fn teradata_nativesql}{fn teradata_get_warnings}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
sRequest = "{fn teradata_nativesql}{fn teradata_get_errors}" + sInsert
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
finally:
print ("con.autocommit = True")
con.autocommit = True
sRequest = "SELECT * FROM " + sTableName + " ORDER BY 1"
print (sRequest)
cur.execute (sRequest)
[ print (row) for row in cur.fetchall () ]
finally:
sRequest = "DROP TABLE " + sTableName
print (sRequest)
cur.execute (sRequest)