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/15 06:38:12 UTC

[arrow] branch master updated: ARROW-3751: [Gandiva][Python] Add more cython bindings for gandiva

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 217c28a  ARROW-3751: [Gandiva][Python] Add more cython bindings for gandiva
217c28a is described below

commit 217c28a30f25d4f80089d35a49b7a1698b296a9b
Author: suquark <su...@gmail.com>
AuthorDate: Wed Nov 14 22:38:01 2018 -0800

    ARROW-3751: [Gandiva][Python] Add more cython bindings for gandiva
    
    https://issues.apache.org/jira/projects/ARROW/issues/ARROW-3751
    
    Author: suquark <su...@gmail.com>
    Author: Philipp Moritz <pc...@gmail.com>
    
    Closes #2936 from suquark/gandiva-more and squashes the following commits:
    
    3b7477334 <Philipp Moritz> small fix
    19bbf21ae <suquark> Fix cython bindings.
    05dfd0619 <suquark> lint
    e3790322c <suquark> rename gandiva operations
    547eba672 <suquark> lint
    c04d4e5e6 <suquark> fix test
    ee36a6221 <suquark> lint
    72b9dde5c <suquark> more fix, more test
    8be6339fa <suquark> fix test
    9efc58b8c <suquark> lint
    2e00cd2e2 <suquark> Fix make_in_expression and add tests.
    4577e88fb <suquark> lint
    0ea3a0ef1 <suquark> Add test for make_or and make_and
    9e5e8089b <suquark> Implement make_in_expression
    1e90fe114 <suquark> Create 'make_add' & 'make_or'
---
 cpp/src/gandiva/tree_expr_builder.cc   |   6 +-
 cpp/src/gandiva/tree_expr_builder.h    |  26 +++--
 python/pyarrow/gandiva.pyx             | 192 ++++++++++++++++++++++++++++-----
 python/pyarrow/includes/libgandiva.pxd |  46 ++++++++
 python/pyarrow/tests/test_gandiva.py   | 138 ++++++++++++++++++++++++
 5 files changed, 371 insertions(+), 37 deletions(-)

diff --git a/cpp/src/gandiva/tree_expr_builder.cc b/cpp/src/gandiva/tree_expr_builder.cc
index 91e97ab..86a2824 100644
--- a/cpp/src/gandiva/tree_expr_builder.cc
+++ b/cpp/src/gandiva/tree_expr_builder.cc
@@ -185,9 +185,11 @@ ConditionPtr TreeExprBuilder::MakeCondition(const std::string& function,
 
 MAKE_IN(Int32, int32_t);
 MAKE_IN(Int64, int64_t);
-MAKE_IN(Date, int64_t);
+MAKE_IN(Date32, int32_t);
+MAKE_IN(Date64, int64_t);
 MAKE_IN(TimeStamp, int64_t);
-MAKE_IN(Time, int32_t);
+MAKE_IN(Time32, int32_t);
+MAKE_IN(Time64, int64_t);
 MAKE_IN(String, std::string);
 MAKE_IN(Binary, std::string);
 
diff --git a/cpp/src/gandiva/tree_expr_builder.h b/cpp/src/gandiva/tree_expr_builder.h
index 5d4946e..cd261c8 100644
--- a/cpp/src/gandiva/tree_expr_builder.h
+++ b/cpp/src/gandiva/tree_expr_builder.h
@@ -90,18 +90,32 @@ class TreeExprBuilder {
   /// \brief creates an in expression
   static NodePtr MakeInExpressionInt32(NodePtr node,
                                        const std::unordered_set<int32_t>& constants);
+
   static NodePtr MakeInExpressionInt64(NodePtr node,
                                        const std::unordered_set<int64_t>& constants);
+
   static NodePtr MakeInExpressionString(NodePtr node,
                                         const std::unordered_set<std::string>& constants);
+
   static NodePtr MakeInExpressionBinary(NodePtr node,
                                         const std::unordered_set<std::string>& constants);
-  /// \brief Date as millis since epoch.
-  static NodePtr MakeInExpressionDate(NodePtr node,
-                                      const std::unordered_set<int64_t>& constants);
-  /// \brief Time as millis of day
-  static NodePtr MakeInExpressionTime(NodePtr node,
-                                      const std::unordered_set<int32_t>& constants);
+
+  /// \brief Date as s/millis since epoch.
+  static NodePtr MakeInExpressionDate32(NodePtr node,
+                                        const std::unordered_set<int32_t>& constants);
+
+  /// \brief Date as millis/us/ns since epoch.
+  static NodePtr MakeInExpressionDate64(NodePtr node,
+                                        const std::unordered_set<int64_t>& constants);
+
+  /// \brief Time as s/millis of day
+  static NodePtr MakeInExpressionTime32(NodePtr node,
+                                        const std::unordered_set<int32_t>& constants);
+
+  /// \brief Time as millis/us/ns of day
+  static NodePtr MakeInExpressionTime64(NodePtr node,
+                                        const std::unordered_set<int64_t>& constants);
+
   /// \brief Timestamp as millis since epoch.
   static NodePtr MakeInExpressionTimeStamp(NodePtr node,
                                            const std::unordered_set<int64_t>& constants);
diff --git a/python/pyarrow/gandiva.pyx b/python/pyarrow/gandiva.pyx
index 162517a..418d0d6 100644
--- a/python/pyarrow/gandiva.pyx
+++ b/python/pyarrow/gandiva.pyx
@@ -23,7 +23,8 @@ from libcpp cimport bool as c_bool, nullptr
 from libcpp.memory cimport shared_ptr, unique_ptr, make_shared
 from libcpp.string cimport string as c_string
 from libcpp.vector cimport vector as c_vector
-from libc.stdint cimport int64_t, uint8_t, uintptr_t
+from libcpp.unordered_set cimport unordered_set as c_unordered_set
+from libc.stdint cimport int64_t, int32_t, uint8_t, uintptr_t
 
 from pyarrow.includes.libarrow cimport *
 from pyarrow.compat import frombytes
@@ -32,34 +33,46 @@ from pyarrow.lib cimport (Array, DataType, Field, MemoryPool, RecordBatch,
                           Schema, check_status, pyarrow_wrap_array,
                           pyarrow_wrap_data_type)
 
-from pyarrow.includes.libgandiva cimport (CCondition, CExpression,
-                                          CNode, CProjector, CFilter,
-                                          CSelectionVector,
-                                          TreeExprBuilder_MakeExpression,
-                                          TreeExprBuilder_MakeFunction,
-                                          TreeExprBuilder_MakeBoolLiteral,
-                                          TreeExprBuilder_MakeUInt8Literal,
-                                          TreeExprBuilder_MakeUInt16Literal,
-                                          TreeExprBuilder_MakeUInt32Literal,
-                                          TreeExprBuilder_MakeUInt64Literal,
-                                          TreeExprBuilder_MakeInt8Literal,
-                                          TreeExprBuilder_MakeInt16Literal,
-                                          TreeExprBuilder_MakeInt32Literal,
-                                          TreeExprBuilder_MakeInt64Literal,
-                                          TreeExprBuilder_MakeFloatLiteral,
-                                          TreeExprBuilder_MakeDoubleLiteral,
-                                          TreeExprBuilder_MakeStringLiteral,
-                                          TreeExprBuilder_MakeBinaryLiteral,
-                                          TreeExprBuilder_MakeField,
-                                          TreeExprBuilder_MakeIf,
-                                          TreeExprBuilder_MakeCondition,
-                                          SelectionVector_MakeInt16,
-                                          SelectionVector_MakeInt32,
-                                          SelectionVector_MakeInt64,
-                                          Projector_Make,
-                                          Filter_Make,
-                                          CFunctionSignature,
-                                          GetRegisteredFunctionSignatures)
+from pyarrow.includes.libgandiva cimport (
+    CCondition, CExpression,
+    CNode, CProjector, CFilter,
+    CSelectionVector,
+    TreeExprBuilder_MakeExpression,
+    TreeExprBuilder_MakeFunction,
+    TreeExprBuilder_MakeBoolLiteral,
+    TreeExprBuilder_MakeUInt8Literal,
+    TreeExprBuilder_MakeUInt16Literal,
+    TreeExprBuilder_MakeUInt32Literal,
+    TreeExprBuilder_MakeUInt64Literal,
+    TreeExprBuilder_MakeInt8Literal,
+    TreeExprBuilder_MakeInt16Literal,
+    TreeExprBuilder_MakeInt32Literal,
+    TreeExprBuilder_MakeInt64Literal,
+    TreeExprBuilder_MakeFloatLiteral,
+    TreeExprBuilder_MakeDoubleLiteral,
+    TreeExprBuilder_MakeStringLiteral,
+    TreeExprBuilder_MakeBinaryLiteral,
+    TreeExprBuilder_MakeField,
+    TreeExprBuilder_MakeIf,
+    TreeExprBuilder_MakeAnd,
+    TreeExprBuilder_MakeOr,
+    TreeExprBuilder_MakeCondition,
+    TreeExprBuilder_MakeInExpressionInt32,
+    TreeExprBuilder_MakeInExpressionInt64,
+    TreeExprBuilder_MakeInExpressionTime32,
+    TreeExprBuilder_MakeInExpressionTime64,
+    TreeExprBuilder_MakeInExpressionDate32,
+    TreeExprBuilder_MakeInExpressionDate64,
+    TreeExprBuilder_MakeInExpressionTimeStamp,
+    TreeExprBuilder_MakeInExpressionString,
+    TreeExprBuilder_MakeInExpressionBinary,
+    SelectionVector_MakeInt16,
+    SelectionVector_MakeInt32,
+    SelectionVector_MakeInt64,
+    Projector_Make,
+    Filter_Make,
+    CFunctionSignature,
+    GetRegisteredFunctionSignatures)
 
 
 cdef class Node:
@@ -241,6 +254,127 @@ cdef class TreeExprBuilder:
             return_type.sp_type)
         return Node.create(r)
 
+    def make_and(self, children):
+        cdef c_vector[shared_ptr[CNode]] c_children
+        cdef Node child
+        for child in children:
+            c_children.push_back(child.node)
+        cdef shared_ptr[CNode] r = TreeExprBuilder_MakeAnd(c_children)
+        return Node.create(r)
+
+    def make_or(self, children):
+        cdef c_vector[shared_ptr[CNode]] c_children
+        cdef Node child
+        for child in children:
+            c_children.push_back(child.node)
+        cdef shared_ptr[CNode] r = TreeExprBuilder_MakeOr(c_children)
+        return Node.create(r)
+
+    def _make_in_expression_int32(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[int32_t] c_values
+        cdef int32_t v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionInt32(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_int64(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[int64_t] c_values
+        cdef int64_t v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionInt64(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_time32(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[int32_t] c_values
+        cdef int32_t v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionTime32(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_time64(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[int64_t] c_values
+        cdef int64_t v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionTime64(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_date32(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[int32_t] c_values
+        cdef int32_t v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionDate32(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_date64(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[int64_t] c_values
+        cdef int64_t v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionDate64(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_timestamp(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[int64_t] c_values
+        cdef int64_t v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionTimeStamp(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_binary(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[c_string] c_values
+        cdef c_string v
+        for v in values:
+            c_values.insert(v)
+        r = TreeExprBuilder_MakeInExpressionString(node.node, c_values)
+        return Node.create(r)
+
+    def _make_in_expression_string(self, Node node, values):
+        cdef shared_ptr[CNode] r
+        cdef c_unordered_set[c_string] c_values
+        cdef c_string _v
+        for v in values:
+            _v = v.encode('UTF-8')
+            c_values.insert(_v)
+        r = TreeExprBuilder_MakeInExpressionString(node.node, c_values)
+        return Node.create(r)
+
+    def make_in_expression(self, Node node, values, dtype):
+        cdef DataType type = _as_type(dtype)
+        if type.id == _Type_INT32:
+            return self._make_in_expression_int32(node, values)
+        elif type.id == _Type_INT64:
+            return self._make_in_expression_int64(node, values)
+        elif type.id == _Type_TIME32:
+            return self._make_in_expression_time32(node, values)
+        elif type.id == _Type_TIME64:
+            return self._make_in_expression_time64(node, values)
+        elif type.id == _Type_TIMESTAMP:
+            return self._make_in_expression_timestamp(node, values)
+        elif type.id == _Type_DATE32:
+            return self._make_in_expression_date32(node, values)
+        elif type.id == _Type_DATE64:
+            return self._make_in_expression_date64(node, values)
+        elif type.id == _Type_BINARY:
+            return self._make_in_expression_binary(node, values)
+        elif type.id == _Type_STRING:
+            return self._make_in_expression_string(node, values)
+        else:
+            raise TypeError("Data type " + str(dtype) + " not supported.")
+
     def make_condition(self, Node condition):
         cdef shared_ptr[CCondition] r = TreeExprBuilder_MakeCondition(
             condition.node)
diff --git a/python/pyarrow/includes/libgandiva.pxd b/python/pyarrow/includes/libgandiva.pxd
index 6e98e89..fc73872 100644
--- a/python/pyarrow/includes/libgandiva.pxd
+++ b/python/pyarrow/includes/libgandiva.pxd
@@ -17,6 +17,10 @@
 
 # distutils: language = c++
 
+from libcpp.string cimport string as c_string
+from libcpp.unordered_set cimport unordered_set as c_unordered_set
+from libc.stdint cimport int64_t, int32_t, uint8_t, uintptr_t
+
 from pyarrow.includes.common cimport *
 from pyarrow.includes.libarrow cimport *
 
@@ -122,10 +126,52 @@ cdef extern from "gandiva/tree_expr_builder.h" namespace "gandiva" nogil:
             shared_ptr[CNode] condition, shared_ptr[CNode] this_node,
             shared_ptr[CNode] else_node, shared_ptr[CDataType] return_type)
 
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeAnd \
+        "gandiva::TreeExprBuilder::MakeAnd"(const CNodeVector& children)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeOr \
+        "gandiva::TreeExprBuilder::MakeOr"(const CNodeVector& children)
+
     cdef shared_ptr[CCondition] TreeExprBuilder_MakeCondition \
         "gandiva::TreeExprBuilder::MakeCondition"(
             shared_ptr[CNode] condition)
 
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionInt32 \
+        "gandiva::TreeExprBuilder::MakeInExpressionInt32"(
+            shared_ptr[CNode] node, const c_unordered_set[int32_t]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionInt64 \
+        "gandiva::TreeExprBuilder::MakeInExpressionInt64"(
+            shared_ptr[CNode] node, const c_unordered_set[int64_t]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionTime32 \
+        "gandiva::TreeExprBuilder::MakeInExpressionTime32"(
+            shared_ptr[CNode] node, const c_unordered_set[int32_t]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionTime64 \
+        "gandiva::TreeExprBuilder::MakeInExpressionTime64"(
+            shared_ptr[CNode] node, const c_unordered_set[int64_t]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionDate32 \
+        "gandiva::TreeExprBuilder::MakeInExpressionDate32"(
+            shared_ptr[CNode] node, const c_unordered_set[int32_t]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionDate64 \
+        "gandiva::TreeExprBuilder::MakeInExpressionDate64"(
+            shared_ptr[CNode] node, const c_unordered_set[int64_t]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionTimeStamp \
+        "gandiva::TreeExprBuilder::MakeInExpressionTimeStamp"(
+            shared_ptr[CNode] node, const c_unordered_set[int64_t]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionString \
+        "gandiva::TreeExprBuilder::MakeInExpressionString"(
+            shared_ptr[CNode] node, const c_unordered_set[c_string]& values)
+
+    cdef shared_ptr[CNode] TreeExprBuilder_MakeInExpressionBinary \
+        "gandiva::TreeExprBuilder::MakeInExpressionBinary"(
+            shared_ptr[CNode] node, const c_unordered_set[c_string]& values)
+
     cdef CStatus Projector_Make \
         "gandiva::Projector::Make"(
             shared_ptr[CSchema] schema, const CExpressionVector& children,
diff --git a/python/pyarrow/tests/test_gandiva.py b/python/pyarrow/tests/test_gandiva.py
index dd94ecd..fa99b99 100644
--- a/python/pyarrow/tests/test_gandiva.py
+++ b/python/pyarrow/tests/test_gandiva.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import datetime
 import pytest
 
 import pyarrow as pa
@@ -101,6 +102,143 @@ def test_filter():
 
 
 @pytest.mark.gandiva
+def test_in_expr():
+    import pyarrow.gandiva as gandiva
+
+    arr = pa.array([u"ga", u"an", u"nd", u"di", u"iv", u"va"])
+    table = pa.Table.from_arrays([arr], ["a"])
+
+    # string
+    builder = gandiva.TreeExprBuilder()
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    cond = builder.make_in_expression(node_a, [u"an", u"nd"], pa.string())
+    condition = builder.make_condition(cond)
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [1, 2]
+
+    # int32
+    arr = pa.array([3, 1, 4, 1, 5, 9, 2, 6, 5, 4])
+    table = pa.Table.from_arrays([arr.cast(pa.int32())], ["a"])
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    cond = builder.make_in_expression(node_a, [1, 5], pa.int32())
+    condition = builder.make_condition(cond)
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [1, 3, 4, 8]
+
+    # int64
+    arr = pa.array([3, 1, 4, 1, 5, 9, 2, 6, 5, 4])
+    table = pa.Table.from_arrays([arr], ["a"])
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    cond = builder.make_in_expression(node_a, [1, 5], pa.int64())
+    condition = builder.make_condition(cond)
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [1, 3, 4, 8]
+
+
+@pytest.mark.skip(reason="Gandiva C++ did not have *real* binary, "
+                         "time and date support.")
+def test_in_expr_todo():
+    import pyarrow.gandiva as gandiva
+    # TODO: Implement reasonable support for timestamp, time & date.
+    # Current exceptions:
+    # pyarrow.lib.ArrowException: ExpressionValidationError:
+    # Evaluation expression for IN clause returns XXXX values are of typeXXXX
+
+    # binary
+    arr = pa.array([b"ga", b"an", b"nd", b"di", b"iv", b"va"])
+    table = pa.Table.from_arrays([arr], ["a"])
+
+    builder = gandiva.TreeExprBuilder()
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    cond = builder.make_in_expression(node_a, [b'an', b'nd'], pa.binary())
+    condition = builder.make_condition(cond)
+
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [1, 2]
+
+    # timestamp
+    datetime_1 = datetime.datetime.utcfromtimestamp(1542238951.621877)
+    datetime_2 = datetime.datetime.utcfromtimestamp(1542238911.621877)
+    datetime_3 = datetime.datetime.utcfromtimestamp(1542238051.621877)
+
+    arr = pa.array([datetime_1, datetime_2, datetime_3])
+    table = pa.Table.from_arrays([arr], ["a"])
+
+    builder = gandiva.TreeExprBuilder()
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    cond = builder.make_in_expression(node_a, [datetime_2], pa.timestamp('ms'))
+    condition = builder.make_condition(cond)
+
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [1]
+
+    # time
+    time_1 = datetime_1.time()
+    time_2 = datetime_2.time()
+    time_3 = datetime_3.time()
+
+    arr = pa.array([time_1, time_2, time_3])
+    table = pa.Table.from_arrays([arr], ["a"])
+
+    builder = gandiva.TreeExprBuilder()
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    cond = builder.make_in_expression(node_a, [time_2], pa.time64('ms'))
+    condition = builder.make_condition(cond)
+
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [1]
+
+    # date
+    date_1 = datetime_1.date()
+    date_2 = datetime_2.date()
+    date_3 = datetime_3.date()
+
+    arr = pa.array([date_1, date_2, date_3])
+    table = pa.Table.from_arrays([arr], ["a"])
+
+    builder = gandiva.TreeExprBuilder()
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    cond = builder.make_in_expression(node_a, [date_2], pa.date32())
+    condition = builder.make_condition(cond)
+
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [1]
+
+
+@pytest.mark.gandiva
+def test_boolean():
+    import pyarrow.gandiva as gandiva
+
+    df = pd.DataFrame({"a": [1., 31., 46., 3., 57., 44., 22.],
+                       "b": [5., 45., 36., 73., 83., 23., 76.]})
+    table = pa.Table.from_pandas(df)
+
+    builder = gandiva.TreeExprBuilder()
+    node_a = builder.make_field(table.schema.field_by_name("a"))
+    node_b = builder.make_field(table.schema.field_by_name("b"))
+    fifty = builder.make_literal(50.0, pa.float64())
+    eleven = builder.make_literal(11.0, pa.float64())
+
+    cond_1 = builder.make_function("less_than", [node_a, fifty], pa.bool_())
+    cond_2 = builder.make_function("greater_than", [node_a, node_b],
+                                   pa.bool_())
+    cond_3 = builder.make_function("less_than", [node_b, eleven], pa.bool_())
+    cond = builder.make_or([builder.make_and([cond_1, cond_2]), cond_3])
+    condition = builder.make_condition(cond)
+
+    filter = gandiva.make_filter(table.schema, condition)
+    result = filter.evaluate(table.to_batches()[0], pa.default_memory_pool())
+    assert list(result.to_array()) == [0, 2, 5]
+
+
+@pytest.mark.gandiva
 def test_literals():
     import pyarrow.gandiva as gandiva