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/04/08 13:34:32 UTC

[GitHub] [arrow] lidavidm commented on a diff in pull request #12672: ARROW-15779: [Python] Create python bindings for Substrait consumer

lidavidm commented on code in PR #12672:
URL: https://github.com/apache/arrow/pull/12672#discussion_r846115787


##########
python/pyarrow/tests/test_substrait.py:
##########
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import os
+import pathlib
+from pyarrow.lib import tobytes
+import pyarrow.parquet as pq
+
+try:
+    from pyarrow import engine
+    from pyarrow.engine import (
+        run_query,
+    )
+except ImportError:
+    engine = None
+

Review Comment:
   We need a pytestmark to make pytest skip tests properly:
   
   https://github.com/apache/arrow/blob/0a78b20b681d0e50e117f2e14ca1490c08f16305/python/pyarrow/tests/test_flight.py#L54-L56



##########
python/pyarrow/_engine.pyx:
##########
@@ -0,0 +1,52 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# cython: language_level = 3
+
+import sys
+
+from pyarrow.lib cimport *
+from pyarrow.includes.libarrow cimport *
+
+
+def run_query(plan, output_schema):
+    """
+    executes a substrait plan and returns a RecordBatchReader
+
+    Paramters
+    ---------
+    plan : bytes

Review Comment:
   (The docstring still doesn't describe this parameter fully.)



##########
python/pyarrow/tests/test_substrait.py:
##########
@@ -0,0 +1,91 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import os
+import pathlib
+import pyarrow as pa
+from pyarrow.lib import tobytes
+import pyarrow.parquet as pq
+
+try:
+    from pyarrow import engine
+    from pyarrow.engine import (
+        run_query,
+    )
+except ImportError:
+    engine = None
+
+
+def test_import():
+    # So we see the ImportError somewhere
+    import pyarrow.engine  # noqa
+
+
+def resource_root():
+    """Get the path to the test resources directory."""
+    if not os.environ.get("PARQUET_TEST_DATA"):
+        raise RuntimeError("Test resources not found; set "
+                           "PARQUET_TEST_DATA to "
+                           "<repo root>/cpp/submodules/parquet-testing/data")
+    return pathlib.Path(os.environ["PARQUET_TEST_DATA"])
+
+
+def test_run_query():
+    filename = str(resource_root() / "binary.parquet")
+
+    query = """
+    {
+        "relations": [
+        {"rel": {
+            "read": {
+            "base_schema": {
+                "struct": {
+                "types": [
+                            {"binary": {}}
+                        ]
+                },
+                "names": [
+                        "foo"
+                        ]
+            },
+            "local_files": {
+                "items": [
+                {
+                    "uri_file": "file://FILENAME_PLACEHOLDER",
+                    "format": "FILE_FORMAT_PARQUET"
+                }
+                ]
+            }
+            }
+        }}
+        ]
+    }
+    """
+
+    query = tobytes(query.replace("FILENAME_PLACEHOLDER", filename))

Review Comment:
   ah, fair. replace is fine then.



-- 
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