Skip to content

Commit

Permalink
python: allow passing single strings instead of lists in more places
Browse files Browse the repository at this point in the history
Several of our APIs take lists of column names, but it's easy to
accidentally just pass a string. If we naively iterate over the string,
we end up interpreting "foo" as ["f", "o", "o"] which is obviously
incorrect.

This patch takes the approach of detecting the string argument and
converting to a singleton list.

An alternative would have been to raise TypeError, but it seems like we
do this conversion in other places, so I decided to be consistent.

Change-Id: I1a81dea5356b66b8860d22f9ee2935072fd4cd6c
Reviewed-on: http://gerrit.cloudera.org:8080/5019
Tested-by: Kudu Jenkins
Reviewed-by: Jordan Birdsell <[email protected]>
  • Loading branch information
toddlipcon authored and jtbirdsell committed Nov 9, 2016
1 parent 10f5255 commit 29f1543
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/kudu/client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,8 @@ class Partitioning(object):
-------
self: this object
"""
if isinstance(column_names, str):
column_names = [column_names]
self._range_partition_cols = column_names
return self

Expand Down Expand Up @@ -1464,6 +1466,8 @@ cdef class Scanner:
-------
self : Scanner
"""
if isinstance(names, str):
names = [names]
cdef vector[string] v_names
for name in names:
v_names.push_back(tobytes(name))
Expand Down Expand Up @@ -1930,6 +1934,8 @@ cdef class ScanTokenBuilder:
-------
self : ScanTokenBuilder
"""
if isinstance(names, str):
names = [names]
cdef vector[string] v_names
for name in names:
v_names.push_back(tobytes(name))
Expand Down

0 comments on commit 29f1543

Please sign in to comment.