lidavidm commented on a change in pull request #12672: URL: https://github.com/apache/arrow/pull/12672#discussion_r836415184
########## File path: 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 Review comment: I'm not sure we need this? What we should do is add a case for `engine` to `pyarrow/tests/conftest.py`. ########## File path: 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 + --------- Review comment: ```suggestion Parameters ---------- ``` ########## File path: 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 Review comment: ```suggestion Execute a Substrait plan and return results as a RecordBatchReader. ``` ########## File path: 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 + output_schema: expected output schema Review comment: ```suggestion output_schema: Schema The expected output schema. ``` ########## File path: python/examples/substrait/query_execution_example.py ########## @@ -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. Review comment: So I'm not sure it makes sense to have this file at all - again, nothing runs these examples. ########## File path: python/CMakeLists.txt ########## @@ -69,6 +69,7 @@ endif() if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") option(PYARROW_BUILD_CUDA "Build the PyArrow CUDA support" OFF) option(PYARROW_BUILD_FLIGHT "Build the PyArrow Flight integration" OFF) + option(PYARROW_BUILD_ENGINE "Build the PyArrow Substrait integration" OFF) Review comment: Is `engine` meant to be specific to Substrait, or are we going to use it for the query engine as a whole? ########## File path: cpp/examples/arrow/engine_substrait_example.cc ########## @@ -0,0 +1,128 @@ +// 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. Review comment: I'm not sure the example adds much to this PR, we can save it for the cookbook? (We can move the code into the issue comments to make sure we have it around or something.) ########## File path: 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 + output_schema: expected output schema Review comment: Though, again, IMO it is really user-unfriendly to require the user to know the result schema. ########## File path: 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 Review comment: Unused import? ########## File path: 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 + output_schema: expected output schema + """ + + cdef: + CResult[shared_ptr[CRecordBatchReader]] c_res_reader + shared_ptr[CRecordBatchReader] c_reader + shared_ptr[CSchema] c_schema + c_string c_plan + RecordBatchReader reader + + c_plan = plan Review comment: `tobytes(plan)`? and IIRC it should work to just `GetRecordBatchReader(tobytes(plan), ...)` without having to explicitly allocate a `c_string` ########## File path: 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: Just use an f-string or `str.replace` to be idiomatic in Python. ########## File path: 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)) + + schema = pa.schema({"foo": pa.binary()}) + + reader = run_query(query, schema) + + res = reader.read_all() + + assert res.schema == schema + assert res.num_rows > 0 Review comment: I think this assertion isn't useful with the below one ########## File path: 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: Please describe the argument. Is this JSON? 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]
