Repository: kudu Updated Branches: refs/heads/master cf20c0e59 -> e87fb7907
KUDU-1851 - [python] TableAlterer direct instantiation causes SIGSEGV The python client is currently crashing when a TableAlterer is directly instantiated as opposed to instantiating via the new_table_alterer method in the Client class. This patch addresses this issue and includes a new unit test. Change-Id: I074737c8f6992a7cd21f72f711337e915ffe2e82 Reviewed-on: http://gerrit.cloudera.org:8080/5822 Reviewed-by: Todd Lipcon <[email protected]> Tested-by: Todd Lipcon <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/2882f0f3 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/2882f0f3 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/2882f0f3 Branch: refs/heads/master Commit: 2882f0f3e255ed28769aa444f4d999ff796ebd7d Parents: cf20c0e Author: Jordan Birdsell <[email protected]> Authored: Sat Jan 28 11:17:28 2017 -0500 Committer: Todd Lipcon <[email protected]> Committed: Tue Jan 31 02:25:34 2017 +0000 ---------------------------------------------------------------------- python/kudu/client.pyx | 8 +++----- python/kudu/tests/test_client.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/2882f0f3/python/kudu/client.pyx ---------------------------------------------------------------------- diff --git a/python/kudu/client.pyx b/python/kudu/client.pyx index ab6a70a..c95844d 100644 --- a/python/kudu/client.pyx +++ b/python/kudu/client.pyx @@ -544,11 +544,7 @@ cdef class Client: ------- alterer : TableAlterer """ - cdef: - TableAlterer alterer = TableAlterer(table) - - alterer._init(self.cp.NewTableAlterer(tobytes(table.name))) - return alterer + return TableAlterer(table) #---------------------------------------------------------------------- @@ -2563,6 +2559,8 @@ cdef class TableAlterer: def __cinit__(self, Table table): self._table = table self._new_name = None + self._init(self._table.parent.cp + .NewTableAlterer(tobytes(self._table.name))) def __dealloc__(self): if self._alterer != NULL: http://git-wip-us.apache.org/repos/asf/kudu/blob/2882f0f3/python/kudu/tests/test_client.py ---------------------------------------------------------------------- diff --git a/python/kudu/tests/test_client.py b/python/kudu/tests/test_client.py index 3183051..779cd25 100644 --- a/python/kudu/tests/test_client.py +++ b/python/kudu/tests/test_client.py @@ -345,6 +345,27 @@ class TestClient(KuduTestBase, unittest.TestCase): with self.assertRaises(KeyError): col = table['added-column'] + def test_alter_table_direct_instantiation(self): + # Run the add_drop_column test with direct instantiation of + # the TableAlterer + table = self.client.table(self.ex_table) + alterer = kudu.client.TableAlterer(table) + alterer.add_column('added-column', type_='int64', default=0) + table = alterer.alter() + + # Confirm column was added + expected_repr = 'Column(added-column, parent={0}, type=int64)' \ + .format(self.ex_table) + self.assertEqual(expected_repr, repr(table['added-column'])) + + alterer = self.client.new_table_alterer(table) + alterer.drop_column('added-column') + table = alterer.alter() + + # Confirm column has been dropped. + with self.assertRaises(KeyError): + col = table['added-column'] + def test_alter_table_add_drop_partition(self): # Add Range Partition table = self.client.table(self.ex_table)
