You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/05/09 14:40:09 UTC

[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #13075: ARROW-16467: [Python] Add helper function _exec_plan._filter_table to filter tables based on Expression

jorisvandenbossche commented on code in PR #13075:
URL: https://github.com/apache/arrow/pull/13075#discussion_r868086017


##########
python/pyarrow/tests/test_exec_plan.py:
##########
@@ -190,3 +191,35 @@ def test_table_join_keys_order():
         "colVals_l": ["a", "b", "f", None],
         "colVals_r": ["A", "B", None, "Z"],
     })
+
+
+@pytest.mark.parametrize("use_datasets", [False, True])
+def test_filter_table(use_datasets):
+    t = pa.table({
+        "a": [1, 2, 3, 4, 5],
+        "b": [10, 20, 30, 40, 50]
+    })
+    if use_datasets:
+        t = ds.dataset([t])
+
+    result = ep._filter_table(
+        t, (pc.field("a") <= pc.scalar(3)) & (pc.field("b") == pc.scalar(20)),
+        output_type=pa.Table if not use_datasets else ds.InMemoryDataset
+    )
+    if use_datasets:
+        result = result.to_table()
+    assert result == pa.table({
+        "a": [2],
+        "b": [20]
+    })
+
+    result = ep._filter_table(
+        t, pc.field("b") > pc.scalar(30),
+        output_type=pa.Table if not use_datasets else ds.InMemoryDataset
+    )
+    if use_datasets:
+        result = result.to_table()
+    assert result == pa.table({
+        "a": [4, 5],
+        "b": [40, 50]
+    })

Review Comment:
   Maybe add a small check that ensures a proper error is raised (and eg no segfault) if 1) passing an expressions that doesn't return a boolean value, 2) passing an expression referencing a non-existing field name



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org