-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-39301: [Archery][CI][Integration] Add nanoarrow to archery + integration setup #39302
Merged
paleolimbot
merged 26 commits into
apache:main
from
paleolimbot:archery-nanoarrow-integration
May 10, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
33ea71f
add nanoarrow to archery + integration setup
paleolimbot e31977d
lint
paleolimbot 70c33cc
checkout nanoarrow
paleolimbot 52a40c0
make build dir
paleolimbot 9f19d63
maybe fix integration build
paleolimbot 47b1af5
disable ipc tests for now
paleolimbot 3f89eae
fix lint
paleolimbot 971f1b9
maybe fix build script
paleolimbot 969d1b9
actually build nanoarrow...
paleolimbot 881324c
pull custom nanoarrow for testing
paleolimbot 3071890
temporarily don't check actual error message content
paleolimbot 2a2f4ca
make it easier to test path locally, reenable output
paleolimbot baca6d6
fix nanoarrow ref
paleolimbot 3b05466
use branch to check fixes
paleolimbot 6a16449
bump
paleolimbot 9dc9c3c
skip for types not supported by nanoarrow
paleolimbot ce9985f
bump again
paleolimbot 2d7ebf5
bump
paleolimbot b9adfec
bump again
paleolimbot c676a59
fix
paleolimbot c3ac179
fix again
paleolimbot 08dd7fd
skip rust on purpose
paleolimbot 6f2077c
order lists alphabetically
paleolimbot e9bfe06
whitespace
paleolimbot 11e6e04
whoops
paleolimbot d5bdda2
update default
paleolimbot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# 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. | ||
|
||
set -e | ||
|
||
arrow_dir=${1} | ||
source_dir=${1}/nanoarrow | ||
build_dir=${2}/nanoarrow | ||
|
||
# This file is used to build the nanoarrow binaries needed for the archery | ||
# integration tests. Testing of the nanoarrow implementation in normal CI is handled | ||
# by github workflows in the arrow-nanoarrow repository. | ||
|
||
if [ "${ARCHERY_INTEGRATION_WITH_NANOARROW}" -eq "0" ]; then | ||
echo "=====================================================================" | ||
echo "Not building nanoarrow" | ||
echo "=====================================================================" | ||
exit 0; | ||
elif [ ! -d "${source_dir}" ]; then | ||
echo "=====================================================================" | ||
echo "The nanoarrow source is missing. Please clone the arrow-nanoarrow repository" | ||
echo "to arrow/nanoarrow before running the integration tests:" | ||
echo " git clone https://github.com/apache/arrow-nanoarrow.git path/to/arrow/nanoarrow" | ||
echo "=====================================================================" | ||
exit 1; | ||
fi | ||
|
||
set -x | ||
|
||
mkdir -p ${build_dir} | ||
pushd ${build_dir} | ||
|
||
cmake ${source_dir} -DNANOARROW_BUILD_INTEGRATION_TESTS=ON | ||
cmake --build . | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# 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 functools | ||
import os | ||
|
||
from . import cdata | ||
from .tester import Tester, CDataExporter, CDataImporter | ||
from ..utils.source import ARROW_ROOT_DEFAULT | ||
|
||
|
||
_NANOARROW_PATH = os.environ.get( | ||
"ARROW_NANOARROW_PATH", | ||
os.path.join(ARROW_ROOT_DEFAULT, "nanoarrow/cdata"), | ||
) | ||
|
||
_INTEGRATION_DLL = os.path.join( | ||
_NANOARROW_PATH, "libnanoarrow_c_data_integration" + cdata.dll_suffix | ||
) | ||
|
||
|
||
class NanoarrowTester(Tester): | ||
PRODUCER = False | ||
CONSUMER = False | ||
FLIGHT_SERVER = False | ||
FLIGHT_CLIENT = False | ||
C_DATA_SCHEMA_EXPORTER = True | ||
C_DATA_ARRAY_EXPORTER = True | ||
C_DATA_SCHEMA_IMPORTER = True | ||
C_DATA_ARRAY_IMPORTER = True | ||
|
||
name = "nanoarrow" | ||
|
||
def validate(self, json_path, arrow_path, quirks=None): | ||
raise NotImplementedError() | ||
|
||
def json_to_file(self, json_path, arrow_path): | ||
raise NotImplementedError() | ||
|
||
def stream_to_file(self, stream_path, file_path): | ||
raise NotImplementedError() | ||
|
||
def file_to_stream(self, file_path, stream_path): | ||
raise NotImplementedError() | ||
|
||
def make_c_data_exporter(self): | ||
return NanoarrowCDataExporter(self.debug, self.args) | ||
|
||
def make_c_data_importer(self): | ||
return NanoarrowCDataImporter(self.debug, self.args) | ||
|
||
|
||
_nanoarrow_c_data_entrypoints = """ | ||
const char* nanoarrow_CDataIntegration_ExportSchemaFromJson( | ||
const char* json_path, struct ArrowSchema* out); | ||
|
||
const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson( | ||
const char* json_path, struct ArrowSchema* schema); | ||
|
||
const char* nanoarrow_CDataIntegration_ExportBatchFromJson( | ||
const char* json_path, int num_batch, struct ArrowArray* out); | ||
|
||
const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson( | ||
const char* json_path, int num_batch, struct ArrowArray* batch); | ||
|
||
int64_t nanoarrow_BytesAllocated(void); | ||
""" | ||
|
||
|
||
@functools.lru_cache | ||
def _load_ffi(ffi, lib_path=_INTEGRATION_DLL): | ||
ffi.cdef(_nanoarrow_c_data_entrypoints) | ||
dll = ffi.dlopen(lib_path) | ||
return dll | ||
|
||
|
||
class _CDataBase: | ||
def __init__(self, debug, args): | ||
self.debug = debug | ||
self.args = args | ||
self.ffi = cdata.ffi() | ||
self.dll = _load_ffi(self.ffi) | ||
|
||
def _check_nanoarrow_error(self, na_error): | ||
""" | ||
Check a `const char*` error return from an integration entrypoint. | ||
|
||
A null means success, a non-empty string is an error message. | ||
The string is statically allocated on the nanoarrow side and does not | ||
need to be released. | ||
""" | ||
assert self.ffi.typeof(na_error) is self.ffi.typeof("const char*") | ||
if na_error != self.ffi.NULL: | ||
error = self.ffi.string(na_error).decode("utf8", errors="replace") | ||
raise RuntimeError(f"nanoarrow C Data Integration call failed: {error}") | ||
|
||
|
||
class NanoarrowCDataExporter(CDataExporter, _CDataBase): | ||
def export_schema_from_json(self, json_path, c_schema_ptr): | ||
na_error = self.dll.nanoarrow_CDataIntegration_ExportSchemaFromJson( | ||
str(json_path).encode(), c_schema_ptr | ||
) | ||
self._check_nanoarrow_error(na_error) | ||
|
||
def export_batch_from_json(self, json_path, num_batch, c_array_ptr): | ||
na_error = self.dll.nanoarrow_CDataIntegration_ExportBatchFromJson( | ||
str(json_path).encode(), num_batch, c_array_ptr | ||
) | ||
self._check_nanoarrow_error(na_error) | ||
|
||
@property | ||
def supports_releasing_memory(self): | ||
return True | ||
|
||
def record_allocation_state(self): | ||
return self.dll.nanoarrow_BytesAllocated() | ||
|
||
|
||
class NanoarrowCDataImporter(CDataImporter, _CDataBase): | ||
def import_schema_and_compare_to_json(self, json_path, c_schema_ptr): | ||
na_error = self.dll.nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson( | ||
str(json_path).encode(), c_schema_ptr | ||
) | ||
self._check_nanoarrow_error(na_error) | ||
|
||
def import_batch_and_compare_to_json(self, json_path, num_batch, c_array_ptr): | ||
na_error = self.dll.nanoarrow_CDataIntegration_ImportBatchAndCompareToJson( | ||
str(json_path).encode(), num_batch, c_array_ptr | ||
) | ||
self._check_nanoarrow_error(na_error) | ||
|
||
@property | ||
def supports_releasing_memory(self): | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we clone nanoarrow inside the
arrow
repoARROW_ROOT_DEFAULT
would never be the correct path here as it will include thearrow
folder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted to do this interactively that is basically what you would have to do (I've tried this and it does work)...this is the approach used by the Rust tester that I copied here. In docker-compose.yml this is overridden such that the build happens elsewhere.