Skip to content

Commit f58e6b8

Browse files
committed
Changed update to include in alter table command just those columns which actually change
1 parent 9d67f60 commit f58e6b8

File tree

2 files changed

+21
-109
lines changed

2 files changed

+21
-109
lines changed

clickhouse_mysql/writer/chwriter.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,33 @@ def update(self, event_or_events):
283283
self.dst_table))
284284

285285
# and UPDATE converted rows
286-
286+
# improve performance updating just those fields which have actually changed
287+
updated_values = dict(set(row['after_values'].items()).difference(set(row['before_values'].items())))
288+
287289
sql = ''
288290
try:
291+
# sql = 'ALTER TABLE `{0}`.`{1}` UPDATE {2}, `tb_upd`={3} where {4}'.format(
292+
# schema,
293+
# table,
294+
# ', '.join(filter(None, map(lambda column, value: "" if column in pk or value is None else self.get_data_format(column, value), row['after_values'].keys(), row['after_values'].values()))),
295+
# "'%s'" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
296+
# ' and '.join(filter(None, map(
297+
# lambda column, value: "" if column not in pk or value is None else self.get_data_format(column, value),
298+
# row['before_values'].keys(), row['before_values'].values())))
299+
# )
300+
289301
sql = 'ALTER TABLE `{0}`.`{1}` UPDATE {2}, `tb_upd`={3} where {4}'.format(
290302
schema,
291303
table,
292-
', '.join(filter(None, map(lambda column, value: "" if column in pk or value is None else self.get_data_format(column, value), row['after_values'].keys(), row['after_values'].values()))),
304+
', '.join(filter(None, map(lambda column, value: "" if column in pk or value is None else self.get_data_format(column, value), updated_values.keys(), updated_values.values()))),
293305
"'%s'" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
294306
' and '.join(filter(None, map(
295307
lambda column, value: "" if column not in pk or value is None else self.get_data_format(column, value),
296308
row['before_values'].keys(), row['before_values'].values())))
297309
)
298310

311+
logging.debug("SQL UPDATE: \n\n " + sql + "\n\n")
312+
299313
self.client.execute(sql)
300314
except Exception as ex:
301315
logging.critical('QUERY FAILED')

requirements.txt

+5-107
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,6 @@
1-
appdirs==1.4.4
2-
apturl==0.5.2
3-
astroid==2.4.2
4-
basictracer==3.1.0
5-
blinker==1.4
6-
Brlapi==0.7.0
7-
cachetools==4.0.0
8-
certifi==2020.12.5
9-
chardet==3.0.4
10-
chrome-gnome-shell==0.0.0
11-
Click==7.0
12-
clickhouse-driver==0.0.10
13-
clickhouse-toolset @ file:///tmp/clickhouse_toolset-0.9.dev0-cp38-cp38-linux_x86_64.whl
14-
colorama==0.4.3
15-
command-not-found==0.3
16-
configobj==5.0.6
17-
crcmod==1.7
18-
cryptography==3.0
19-
cupshelpers==1.0
20-
datasketch==1.2.10
21-
dbus-python==1.2.16
22-
defer==1.0.6
23-
distlib==0.3.1
24-
distro==1.5.0
25-
distro-info===0.23ubuntu1
26-
dlib==19.16.0
27-
filelock==3.0.12
28-
httplib2==0.18.1
29-
humanfriendly==8.2
30-
idna==2.6
31-
importlib-metadata==1.6.0
32-
isort==5.7.0
33-
jeepney==0.4.3
34-
keyring==21.3.0
35-
language-selector==0.1
36-
launchpadlib==1.10.13
37-
lazr.restfulclient==0.14.2
38-
lazr.uri==1.0.5
39-
lazy-object-proxy==1.4.3
40-
louis==3.14.0
41-
macaroonbakery==1.3.1
42-
Markdown==3.2.1
43-
mccabe==0.6.1
44-
more-itertools==4.2.0
45-
msal==1.5.0
46-
netifaces==0.10.4
47-
numpy==1.15.0
48-
oauthlib==3.1.0
49-
olefile==0.46
50-
opencv-python==4.4.0.46
51-
opentracing==2.0.0
52-
passlib==1.7.1
53-
pexpect==4.6.0
54-
Pillow==7.2.0
55-
powerline-status==2.8.1
56-
protobuf==3.12.3
57-
psutil==5.6.3
58-
psycopg2-binary==2.8.5
59-
pycairo==1.16.2
60-
pycups==2.0.1
61-
pycurl==7.43.0.6
62-
Pygments==2.3.1
63-
PyGObject==3.38.0
64-
PyJWT==1.6.4
65-
pylint==2.6.0
66-
pymacaroons==0.13.0
1+
clickhouse-driver==0.2.0
2+
mysql-replication==0.23
3+
mysqlclient==2.0.3
674
PyMySQL==1.0.2
68-
PyNaCl==1.4.0
69-
pyRFC3339==1.1
70-
python-apt==2.1.3+ubuntu1.3
71-
python-dateutil==2.8.1
72-
python-debian==0.1.37
73-
pytz==2020.1
74-
pyxdg==0.26
75-
PyYAML==5.3.1
76-
rangehttpserver==1.2.0
77-
redis==3.2.1
78-
reportlab==3.5.47
79-
requests==2.18.4
80-
requests-toolbelt==0.9.1
81-
requests-unixsocket==0.2.0
82-
screen-resolution-extra==0.0.0
83-
SecretStorage==3.1.2
84-
simplejson==3.17.0
85-
six==1.15.0
86-
streaming-form-data==1.1.0
87-
systemd-python==234
88-
tabulate==0.8.3
89-
terminator==1.92
90-
-e [email protected]:tinybird/analytics.git@0d13783b7e38c0decc97ac06901e8ce7b804221e#egg=tinybird
91-
tinybird-cli==1.0.0b12
92-
TLPUI==1.3.1.post3
93-
toml==0.10.2
94-
toposort==1.5
95-
tornado==5.1.1
96-
tornado-opentracing==1.0.1
97-
torngithub==0.2.0
98-
ubuntu-advantage-tools==24.4
99-
ubuntu-drivers-common==0.0.0
100-
ufw==0.36
101-
unattended-upgrades==0.1
102-
urllib3==1.22
103-
vboxapi==1.0
104-
virtualenv==20.0.29+ds
105-
wadllib==1.3.4
106-
wrapt==1.12.1
107-
xkit==0.0.0
108-
zipp==1.0.0
5+
pytz==2021.1
6+
tzlocal==2.1

0 commit comments

Comments
 (0)