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


##########
python/pyarrow/_engine.pyx:
##########
@@ -0,0 +1,81 @@
+# 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
+
+from pyarrow import Buffer
+from pyarrow.lib cimport *
+from pyarrow.includes.libarrow cimport *
+
+
+def run_query(plan):
+    """
+    Executes a substrait plan and returns a RecordBatchReader.
+
+    Parameters
+    ----------
+    plan : bytes or Buffer
+        Substrait Plan can be fed as a encoded string in utf-8
+        as a JSON string or as an Arrow Buffer. 
+    """
+
+    cdef:
+        CResult[shared_ptr[CRecordBatchReader]] c_res_reader
+        shared_ptr[CRecordBatchReader] c_reader
+        RecordBatchReader reader
+        c_string c_str_plan
+        shared_ptr[CBuffer] c_buf_plan
+
+    if isinstance(plan, bytes):
+        c_str_plan = plan
+        c_res_reader = GetRecordBatchReader(c_str_plan)
+    elif isinstance(plan, Buffer):
+        c_buf_plan = pyarrow_unwrap_buffer(plan)
+        c_res_reader = GetRecordBatchReader(c_buf_plan)
+    else:
+        raise ValueError("Expected bytes or pyarrow.Buffer")
+
+    c_reader = GetResultValue(c_res_reader)
+
+    reader = RecordBatchReader.__new__(RecordBatchReader)
+    reader.reader = c_reader
+    return reader
+
+
+def get_buffer_from_json(plan):
+    """
+    Returns Buffer object by converting substrait plan in 
+    JSON.
+
+    Parameter
+    ---------
+    plan: byte
+        Substrait plan as a bytes.
+    """

Review Comment:
   My main point over the past month has been that "bytes" or "buffer" is not 
an appropriate descriptor for what we are doing here, we should say "JSON plan" 
or "serialized plan" or something like that. The fix here should be to write 
fewer words, not more.
   
   ```python
   def parse_json_plan(json: bytes) -> pyarrow.Buffer:
       """
       Parse a JSON plan into equivalent serialized Protobuf.
       """
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to