Skip to content

Commit

Permalink
KUDU-1851 - [python] TableAlterer direct instantiation causes SIGSEGV
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jtbirdsell authored and toddlipcon committed Jan 31, 2017
1 parent cf20c0e commit 2882f0f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions python/kudu/client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)


#----------------------------------------------------------------------
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions python/kudu/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,27 @@ def test_alter_table_add_drop_column(self):
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)
Expand Down

0 comments on commit 2882f0f

Please sign in to comment.