You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by pc...@apache.org on 2018/11/10 05:59:51 UTC

[arrow] branch master updated: ARROW-3742: Fix pyarrow.types & gandiva cython bindings

This is an automated email from the ASF dual-hosted git repository.

pcmoritz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new d8d07dc  ARROW-3742: Fix pyarrow.types & gandiva cython bindings
d8d07dc is described below

commit d8d07dcdbb6b51dc31c07f1e6b86d9e2fda4328f
Author: suquark <su...@gmail.com>
AuthorDate: Fri Nov 9 21:59:40 2018 -0800

    ARROW-3742: Fix pyarrow.types & gandiva cython bindings
    
    https://issues.apache.org/jira/browse/ARROW-3742
    
    Author: suquark <su...@gmail.com>
    
    Closes #2931 from suquark/gandiva-more and squashes the following commits:
    
    91a4ac40e <suquark> change parameter name
    27d68d07c <suquark> Fix bugs
---
 python/pyarrow/gandiva.pyx             | 19 ++++++++++++++++---
 python/pyarrow/includes/libgandiva.pxd | 12 +++++++++++-
 python/pyarrow/types.py                |  3 ++-
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/python/pyarrow/gandiva.pyx b/python/pyarrow/gandiva.pyx
index 7a6c09e..84fc5fa 100644
--- a/python/pyarrow/gandiva.pyx
+++ b/python/pyarrow/gandiva.pyx
@@ -52,7 +52,9 @@ from pyarrow.includes.libgandiva cimport (CCondition, CExpression,
                                           TreeExprBuilder_MakeField,
                                           TreeExprBuilder_MakeIf,
                                           TreeExprBuilder_MakeCondition,
+                                          SelectionVector_MakeInt16,
                                           SelectionVector_MakeInt32,
+                                          SelectionVector_MakeInt64,
                                           Projector_Make,
                                           Filter_Make)
 
@@ -154,10 +156,21 @@ cdef class Filter:
         self.filter = filter
         return self
 
-    def evaluate(self, RecordBatch batch, MemoryPool pool):
+    def evaluate(self, RecordBatch batch, MemoryPool pool, dtype='int32'):
         cdef shared_ptr[CSelectionVector] selection
-        check_status(SelectionVector_MakeInt32(
-            batch.num_rows, pool.pool, &selection))
+        cdef DataType type = _as_type(dtype)
+        if type.id == _Type_INT16:
+            check_status(SelectionVector_MakeInt16(
+                batch.num_rows, pool.pool, &selection))
+        elif type.id == _Type_INT32:
+            check_status(SelectionVector_MakeInt32(
+                batch.num_rows, pool.pool, &selection))
+        elif type.id == _Type_INT64:
+            check_status(SelectionVector_MakeInt64(
+                batch.num_rows, pool.pool, &selection))
+        else:
+            raise ValueError("'dtype' of the selection vector should be "
+                             "one of 'int16', 'int32' and 'int64'.")
         check_status(self.filter.get().Evaluate(
             batch.sp_batch.get()[0], selection))
         return SelectionVector.create(selection)
diff --git a/python/pyarrow/includes/libgandiva.pxd b/python/pyarrow/includes/libgandiva.pxd
index f8106bc..a9f4a7e 100644
--- a/python/pyarrow/includes/libgandiva.pxd
+++ b/python/pyarrow/includes/libgandiva.pxd
@@ -39,9 +39,19 @@ cdef extern from "gandiva/selection_vector.h" namespace "gandiva" nogil:
 
         shared_ptr[CArray] ToArray()
 
+    cdef CStatus SelectionVector_MakeInt16\
+        "gandiva::SelectionVector::MakeInt16"(
+            int64_t max_slots, CMemoryPool* pool,
+            shared_ptr[CSelectionVector]* selection_vector)
+
     cdef CStatus SelectionVector_MakeInt32\
         "gandiva::SelectionVector::MakeInt32"(
-            int max_slots, CMemoryPool* pool,
+            int64_t max_slots, CMemoryPool* pool,
+            shared_ptr[CSelectionVector]* selection_vector)
+
+    cdef CStatus SelectionVector_MakeInt64\
+        "gandiva::SelectionVector::MakeInt64"(
+            int64_t max_slots, CMemoryPool* pool,
             shared_ptr[CSelectionVector]* selection_vector)
 
 cdef extern from "gandiva/condition.h" namespace "gandiva" nogil:
diff --git a/python/pyarrow/types.py b/python/pyarrow/types.py
index 2bd7027..d07dcca 100644
--- a/python/pyarrow/types.py
+++ b/python/pyarrow/types.py
@@ -19,7 +19,8 @@
 
 from pyarrow.lib import (is_boolean_value,  # noqa
                          is_integer_value,
-                         is_float_value)
+                         is_float_value,
+                         _as_type)
 
 import pyarrow.lib as lib