westonpace commented on code in PR #12672: URL: https://github.com/apache/arrow/pull/12672#discussion_r860004189
########## python/pyarrow/_substrait.pyx: ########## @@ -0,0 +1,85 @@ +# 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 serialized plan (Buffer) + or a JSON plan. + """ + + 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 = ExecuteJsonPlan(c_str_plan) + elif isinstance(plan, Buffer): Review Comment: I agree with David here. I think it's fine to expose the json->buffer method internally as this is useful for testing. However, I don't think we want to officially support running JSON plans in the public API. So if we receive bytes we should either reject or, ideally, assume the bytes represent a binary plan and convert it to a buffer and use ExecuteSerializedPlan. In the tests you can get rid of `test_run_query` and just rely on `test_run_query_in_bytes` (which does not need or exercise `ExecuteJsonPlan`). I think you could then even get rid of `ExecuteJsonPlan`. If a customer wants to use a JSON plan they could still stumble across `pa._substrait._parse_json_plan`. This is clearly hidden/internal but I think we want to discourage this path anyways so I think that's ok. -- 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]
