You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/02/04 06:33:46 UTC
[3/5] incubator-kudu git commit: [python] - Allow to scan null values
[python] - Allow to scan null values
Currently scanning a column with null values causes a crash when
the client tries to get the null value.
This adds an is_null() check so that we add 'None' to the tuple
if the value is null in the tablet.
This also alters the scanner test to produce and read null values.
Change-Id: I0264c30d1177b31c92db1669c6b1883d1ec691ba
Reviewed-on: http://gerrit.cloudera.org:8080/1989
Tested-by: Kudu Jenkins
Reviewed-by: David Ribeiro Alves <da...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/acbb5b75
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/acbb5b75
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/acbb5b75
Branch: refs/heads/master
Commit: acbb5b75fb1104ef4d0b1c78b57e3efd2619c07a
Parents: b6fb449
Author: David Alves <da...@cloudera.com>
Authored: Mon Feb 1 21:26:04 2016 -0800
Committer: David Ribeiro Alves <da...@cloudera.com>
Committed: Thu Feb 4 04:13:29 2016 +0000
----------------------------------------------------------------------
python/kudu/client.pyx | 11 +++++++++--
python/kudu/tests/test_scanner.py | 9 +++++----
2 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/acbb5b75/python/kudu/client.pyx
----------------------------------------------------------------------
diff --git a/python/kudu/client.pyx b/python/kudu/client.pyx
index a6e2023..f23bdeb 100644
--- a/python/kudu/client.pyx
+++ b/python/kudu/client.pyx
@@ -808,9 +808,13 @@ cdef class Row:
k = self.table.num_columns
tup = cpython.PyTuple_New(k)
for i in range(k):
- val = self.get_slot(i)
- cpython.PyTuple_SET_ITEM(tup, i, val)
+ val = None
+
+ if not self.is_null(i):
+ val = self.get_slot(i)
+
cpython.Py_INCREF(val)
+ cpython.PyTuple_SET_ITEM(tup, i, val)
return tup
@@ -880,6 +884,9 @@ cdef class Row:
else:
raise TypeError(t)
+ cdef inline bint is_null(self, int i):
+ return self.row.IsNull(i)
+
cdef class RowBatch:
"""
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/acbb5b75/python/kudu/tests/test_scanner.py
----------------------------------------------------------------------
diff --git a/python/kudu/tests/test_scanner.py b/python/kudu/tests/test_scanner.py
index 86decb1..e6f1da4 100644
--- a/python/kudu/tests/test_scanner.py
+++ b/python/kudu/tests/test_scanner.py
@@ -36,10 +36,11 @@ class TestScanner(KuduTestBase, unittest.TestCase):
tuples = []
for i in range(cls.nrows):
op = table.new_insert()
- tup = i, i * 2, 'hello_%d' % i
+ tup = i, i * 2, 'hello_%d' % i if i % 2 == 0 else None
op['key'] = tup[0]
op['int_val'] = tup[1]
- op['string_val'] = tup[2]
+ if i % 2 == 0:
+ op['string_val'] = tup[2]
session.apply(op)
tuples.append(tup)
session.flush()
@@ -84,12 +85,12 @@ class TestScanner(KuduTestBase, unittest.TestCase):
sv = self.table['string_val']
scanner.add_predicates([sv >= 'hello_20',
- sv <= 'hello_25'])
+ sv <= 'hello_22'])
scanner.open()
tuples = scanner.read_all_tuples()
- self.assertEqual(sorted(tuples), self.tuples[20:26])
+ self.assertEqual(sorted(tuples), [(20, 40, 'hello_20'), (22, 44, 'hello_22')])
def test_scan_invalid_predicates(self):
scanner = self.table.scanner()