Skip to content

Commit 66d4bd5

Browse files
shubhambhargavbaloo
authored andcommitted
Added support for limited columnar access in MySQL using ORDINAL POSITION from information_schema.columns
1 parent bd4d88e commit 66d4bd5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def __get_table_information(self, schema, table):
550550
cur.execute("""
551551
SELECT
552552
COLUMN_NAME, COLLATION_NAME, CHARACTER_SET_NAME,
553-
COLUMN_COMMENT, COLUMN_TYPE, COLUMN_KEY
553+
COLUMN_COMMENT, COLUMN_TYPE, COLUMN_KEY, ORDINAL_POSITION
554554
FROM
555555
information_schema.columns
556556
WHERE

pymysqlreplication/row_event.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,25 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
580580
else:
581581
self.column_schemas = self._ctl_connection._get_table_information(self.schema, self.table)
582582

583+
ordinal_pos_loc = 0
584+
583585
if len(self.column_schemas) != 0:
584586
# Read columns meta data
585587
column_types = list(self.packet.read(self.column_count))
586588
self.packet.read_length_coded_binary()
587589
for i in range(0, len(column_types)):
588590
column_type = column_types[i]
589591
try:
590-
column_schema = self.column_schemas[i]
592+
column_schema = self.column_schemas[ordinal_pos_loc]
593+
594+
# only acknowledge the column definition if the iteration matches with ordinal position of
595+
# the column. this helps in maintaining support for restricted columnar access
596+
if i != (column_schema['ORDINAL_POSITION'] - 1):
597+
# raise IndexError to follow the workflow of dropping columns which are not matching the
598+
# underlying table schema
599+
raise IndexError
600+
601+
ordinal_pos_loc += 1
591602
except IndexError:
592603
# this a dirty hack to prevent row events containing columns which have been dropped prior
593604
# to pymysqlreplication start, but replayed from binlog from blowing up the service.

0 commit comments

Comments
 (0)