You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by jd...@apache.org on 2016/02/05 21:53:48 UTC

[4/5] incubator-kudu git commit: [python] - Make the python client adopt the new KuduScanBatch

[python] - Make the python client adopt the new KuduScanBatch

This makes the python client adopt the new KuduScanBatch and use
it instead of a vector of KuduRowResult.

Change-Id: Id482f6a6ea3aa112d2a599898d3f410a8f77e6a9
Reviewed-on: http://gerrit.cloudera.org:8080/2064
Reviewed-by: David Ribeiro Alves <da...@cloudera.com>
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/8581923d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/8581923d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/8581923d

Branch: refs/heads/master
Commit: 8581923d4702fc16d8eaee47471532129a449c75
Parents: 786834d
Author: David Alves <da...@cloudera.com>
Authored: Thu Feb 4 20:26:49 2016 -0800
Committer: David Ribeiro Alves <da...@cloudera.com>
Committed: Fri Feb 5 20:41:33 2016 +0000

----------------------------------------------------------------------
 python/kudu/client.pyx         | 23 +++++++++--------------
 python/kudu/libkudu_client.pxd | 12 +++++++-----
 2 files changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8581923d/python/kudu/client.pyx
----------------------------------------------------------------------
diff --git a/python/kudu/client.pyx b/python/kudu/client.pyx
index bb9a5d7..153c7a8 100644
--- a/python/kudu/client.pyx
+++ b/python/kudu/client.pyx
@@ -784,11 +784,10 @@ cdef class Row:
         RowBatch parent
 
         # This object is owned by the parent RowBatch
-        KuduRowResult* row
+        KuduRowPtr row
 
     def __cinit__(self, batch):
         self.parent = batch
-        self.row = NULL
 
     def __dealloc__(self):
         pass
@@ -801,7 +800,7 @@ cdef class Row:
             int i, k
             tuple tup
 
-        k = self.row.row_schema().num_columns()
+        k = self.parent.batch.projection_schema().num_columns()
         tup = cpython.PyTuple_New(k)
         for i in range(k):
             val = None
@@ -859,7 +858,7 @@ cdef class Row:
     cdef inline get_slot(self, int i):
         cdef:
             Status s
-            DataType t = self.row.row_schema().Column(i).type()
+            DataType t = self.parent.batch.projection_schema().Column(i).type()
 
         if t == KUDU_BOOL:
             return self.get_bool(i)
@@ -888,12 +887,12 @@ cdef class RowBatch:
     """
     Class holding a batch of rows from a Scanner
     """
-    # This class owns the KuduRowResult data
+    # This class owns the KuduScanBatch data
     cdef:
-        vector[KuduRowResult] rows
+        KuduScanBatch batch
 
     def __len__(self):
-        return self.rows.size()
+        return self.batch.NumRows()
 
     def __getitem__(self, i):
         return self.get_row(i).as_tuple()
@@ -910,7 +909,7 @@ cdef class RowBatch:
         To simplify testing for the moment.
         """
         cdef list tuples = []
-        for i in range(self.rows.size()):
+        for i in range(self.batch.NumRows()):
             tuples.append(self.get_row(i).as_tuple())
         return tuples
 
@@ -921,12 +920,8 @@ cdef class RowBatch:
         # on to a reference internally so that if the RowBatch goes out of
         # scope we won't end up with orphaned Row objects. This isn't the best,
         # but an intermediate solution until we can do something better..
-        #
-        # One alternative is to copy the KuduRowResult into the Row, but that
-        # doesn't feel right.
         cdef Row row = Row(self)
-        row.row = &self.rows[i]
-
+        row.row = self.batch.Row(i)
         return row
 
 
@@ -1110,7 +1105,7 @@ cdef class Scanner:
             raise StopIteration
 
         cdef RowBatch batch = RowBatch()
-        check_status(self.scanner.NextBatch(&batch.rows))
+        check_status(self.scanner.NextBatch(&batch.batch))
         return batch
 
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8581923d/python/kudu/libkudu_client.pxd
----------------------------------------------------------------------
diff --git a/python/kudu/libkudu_client.pxd b/python/kudu/libkudu_client.pxd
index 5405f84..a8ae066 100644
--- a/python/kudu/libkudu_client.pxd
+++ b/python/kudu/libkudu_client.pxd
@@ -190,10 +190,14 @@ cdef extern from "kudu/client/schema.h" namespace "kudu::client" nogil:
 
         Status Build(KuduSchema* schema)
 
+cdef extern from "kudu/client/scan_batch.h" namespace "kudu::client" nogil:
 
-cdef extern from "kudu/client/row_result.h" namespace "kudu::client" nogil:
+    cdef cppclass KuduScanBatch:
+        int NumRows() const;
+        KuduRowPtr Row(int idx) const;
+        const KuduSchema* projection_schema() const;
 
-    cdef cppclass KuduRowResult:
+    cdef cppclass KuduRowPtr " kudu::client::KuduScanBatch::RowPtr":
         c_bool IsNull(Slice& col_name)
         c_bool IsNull(int col_idx)
 
@@ -230,10 +234,8 @@ cdef extern from "kudu/client/row_result.h" namespace "kudu::client" nogil:
         Status GetBinary(int col_idx, Slice* val)
 
         const void* cell(int col_idx)
-        const KuduSchema* row_schema();
         string ToString()
 
-
 cdef extern from "kudu/util/slice.h" namespace "kudu" nogil:
 
     cdef cppclass Slice:
@@ -585,7 +587,7 @@ cdef extern from "kudu/client/client.h" namespace "kudu::client" nogil:
         void Close()
 
         c_bool HasMoreRows()
-        Status NextBatch(vector[KuduRowResult]* rows)
+        Status NextBatch(KuduScanBatch* batch)
         Status SetBatchSizeBytes(uint32_t batch_size)
 
         # Pending definition of ReplicaSelection enum