-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathevent_log
263 lines (204 loc) · 5 KB
/
event_log
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
##################
# TABLE DDL
##################
# Create two tables + superfluous "IF NOT EXISTS"
##################
statement ok
CREATE TABLE test.a (id INT PRIMARY KEY)
statement ok
CREATE TABLE IF NOT EXISTS test.b (id INT PRIMARY KEY)
statement ok
CREATE TABLE IF NOT EXISTS a (id INT PRIMARY KEY)
# Verify that two create tables were logged - the second
# NOT EXISTS should not result in a log message.
##################
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'create_table'
----
51 1
52 1
# Verify the contents of the 'Info' field of each log message using a LIKE
# statement.
##################
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'create_table'
AND info LIKE '%CREATE TABLE test.a%'
----
51 1
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'create_table'
AND info LIKE '%CREATE TABLE IF NOT EXISTS test.b%'
----
52 1
# Sanity check - check for a non-matching info value.
##################
query I
SELECT COUNT(*)
FROM system.eventlog
WHERE eventType = 'create_table'
AND info LIKE '%CREATE TABLE badtable%'
----
0
# Alter the table. Expect "alter_table" and "finish_schema_change" events.
##################
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'alter_table'
----
statement ok
ALTER TABLE test.a ADD val INT
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'alter_table'
----
51 1
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'finish_schema_change'
----
51 0
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'reverse_schema_change'
----
# Verify the contents of the 'Info' field of each log message using a LIKE
# statement.
##################
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'alter_table'
AND info LIKE '%ALTER TABLE test.a%'
----
51 1
# Add a UNIQUE constraint to the table in a way that will ensure the schema
# change is reversed.
##################
statement ok
INSERT INTO test.a VALUES (1, 1), (2, 1)
statement error pq: duplicate key value \(val\)=\(1\) violates unique constraint \"foo\"
ALTER TABLE test.a ADD CONSTRAINT foo UNIQUE(val)
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'alter_table'
----
51 1
51 1
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'finish_schema_change'
----
51 0
51 0
query II
SELECT targetID, reportingID FROM system.eventlog
WHERE eventType = 'reverse_schema_change'
----
51 0
# Drop both tables + superfluous "IF EXISTS"
##################
statement ok
DROP TABLE test.a
statement ok
DROP TABLE IF EXISTS test.b
statement ok
DROP TABLE IF EXISTS test.b
# Verify that two drop table events were logged - the second IF EXISTS statement
# should have failed.
##################
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'drop_table'
----
51 1
52 1
# Verify the contents of the 'info' field of each event.
##################
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'drop_table'
AND info LIKE '%DROP TABLE test.a%'
----
51 1
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'drop_table'
AND info LIKE '%DROP TABLE IF EXISTS test.b%'
----
52 1
##################
# DATABASE DDL
##################
# Create two databases + superfluous "IF NOT EXISTS"
##################
statement ok
CREATE DATABASE eventLogTest
statement ok
CREATE DATABASE IF NOT EXISTS otherEventLogTest
statement ok
CREATE DATABASE IF NOT EXISTS otherEventLogTest
# Verify the two events that were logged.
##################
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'create_database'
AND info LIKE '%CREATE DATABASE eventLogTest%'
----
53 1
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'create_database'
AND info LIKE '%CREATE DATABASE IF NOT EXISTS otherEventLogTest%'
----
54 1
# Add some tables to eventLogTest.
##################
statement ok
SET DATABASE = eventLogTest
statement ok
CREATE TABLE eventLogTest.testTable (id int PRIMARY KEY)
statement ok
CREATE TABLE eventLogTest.anotherTestTable (id int PRIMARY KEY)
# drop both databases.
##################
statement ok
DROP DATABASE eventLogTest
statement ok
DROP DATABASE IF EXISTS otherEventLogTest
statement ok
DROP DATABASE IF EXISTS otherEventLogTest
# verify contents of drop event
##################
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'drop_database'
AND info LIKE '%DROP DATABASE eventLogTest%'
----
53 1
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'drop_database'
AND info LIKE '%DROP DATABASE IF EXISTS otherEventLogTest%'
----
54 1
# verify cascading table drops are logged.
##################
query II
SELECT targetID, reportingID
FROM system.eventlog
WHERE eventType = 'drop_database'
AND info LIKE '%testTable%'
AND info LIKE '%anotherTestTable%'
----
53 1