Skip to content

Commit 06aa860

Browse files
peeyushguptaGeert Vanderkelen
authored and
Geert Vanderkelen
committed
BUG20324089: Fix HASH based sharding with MySQL Fabric
We fix HASH based sharding which was causing the following runtime error: ValueError: Unsupported sharding type HASH A unit test has been added for BUG#20324089. (cherry picked from commit 0f7a8e7)
1 parent 2a37147 commit 06aa860

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/mysql/connector/fabric/caching.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -130,6 +130,8 @@ def add_partition(self, key, group):
130130
))
131131
elif self.shard_type == 'RANGE_STRING':
132132
pass
133+
elif self.shard_type == "HASH":
134+
pass
133135
else:
134136
raise ValueError("Unsupported sharding type {0}".format(
135137
self.shard_type

tests/test_fabric.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -626,3 +626,39 @@ def test_bug19331658(self):
626626
)
627627

628628
mysql.connector._CONNECTION_POOLS = {}
629+
630+
def test_range_hash(self):
631+
self.assertTrue(self._check_table(
632+
"employees.employees_hash", 'HASH'))
633+
tbl_name = "employees_hash"
634+
635+
tables = ["employees.{0}".format(tbl_name)]
636+
637+
self.cnx.set_property(tables=tables,
638+
scope=fabric.SCOPE_GLOBAL,
639+
mode=fabric.MODE_READWRITE)
640+
641+
cur = self.cnx.cursor()
642+
gtid_executed = self._truncate(cur, tbl_name)
643+
self.cnx.commit()
644+
645+
insert = ("INSERT INTO {0} "
646+
"VALUES (%s, %s, %s, %s, %s, %s)").format(tbl_name)
647+
648+
self._populate(self.cnx, gtid_executed, tbl_name, insert,
649+
self.emp_data[1985] + self.emp_data[2000], 3)
650+
651+
time.sleep(2)
652+
653+
emp_exp_hash = self.emp_data[1985] + self.emp_data[2000]
654+
655+
rows = []
656+
self.cnx.reset_properties()
657+
str_keys = ['group1', 'group2']
658+
for str_key in str_keys:
659+
self.cnx.set_property(group=str_key, mode=fabric.MODE_READONLY)
660+
cur = self.cnx.cursor()
661+
cur.execute("SELECT * FROM {0}".format(tbl_name))
662+
rows += cur.fetchall()
663+
664+
self.assertEqual(rows, emp_exp_hash)

0 commit comments

Comments
 (0)