lidavidm commented on code in PR #3018: URL: https://github.com/apache/arrow-adbc/pull/3018#discussion_r2165162927
########## docs/source/cpp/recipe_driver/driver_example_manifest.py: ########## @@ -0,0 +1,66 @@ +# 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. + +# RECIPE STARTS HERE +#: After verifying the basic driver functionality, we can use the +#: ``adbc_driver_manager`` Python package's built-in dbapi implementation +#: to expose a ready-to-go Pythonic database API. This is also useful for +#: high-level testing! +#: +#: First, we'll import pathlib for a few path calculations and the +#: ``adbc_driver_manager``'s ``dbapi`` module: +from pathlib import Path + +from adbc_driver_manager import dbapi + + +#: Next, we'll define a ``connect()`` function that wraps ``dbapi.connect()`` +#: with the location the .toml manifest file which points to the shared library +#: we built using ``cmake`` in the previous section. +#: For the purposes of our tutorial, this will be in current directory. +def connect(uri: str): + # we can point to the manifest file directly + manifest_file = Path(".") / "driver_example.toml" + if manifest_file.exists(): + return dbapi.connect( + driver=str(manifest_file.resolve()), db_kwargs={"uri": uri} + ) + + # alternatively, it can look for the manifest file in the user's config + # directory ($HOME/.config/adbc/driver_example.toml) or the system's + # config directory (/etc/adbc/driver_example.toml) + return dbapi.connect(driver="driver_example", db_kwargs={"uri": uri}) + + +#: Next, we can give our driver a go! The two pieces we implemented in the driver +#: were the "bulk ingest" feature and "select all from", so let's see if it works! +if __name__ == "__main__": + import os + + import pyarrow + + with connect(uri=Path(__file__).parent.as_uri()) as con: + data = pyarrow.table({"col": [1, 2, 3]}) + with con.cursor() as cur: + cur.adbc_ingest("example.arrows", data, mode="create") + + with con.cursor() as cur: + cur.execute("SELECT * FROM example.arrows") + print(cur.fetchall()) + # Output: [(1,), (2,), (3,)] + + os.unlink(Path(__file__).parent / "example.arrows") Review Comment: Might as well use Path to do this since it's already imported ########## docs/source/cpp/recipe_driver/get_arch.cmake: ########## @@ -0,0 +1,66 @@ +# 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. + +if(WIN32) + set(OS "windows") +elseif(APPLE) + set(OS "osx") +else() + if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(OS "freebsd") + else() + set(OS "linux") + endif() +endif() + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64)$") + set(ARCH "amd64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i386|i486|i586|i686)$") + set(ARCH "x86") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv8b|armv8l|aarch64|arm64|AARCH64|ARM64)$") + set(ARCH "arm64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7l|armhf|arm)$") + set(ARCH "arm") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(ppc|ppc64|ppcle|ppc64le)$") + set(ARCH "powerpc") +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set(ARCH "riscv") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390|s390x)$") + set(ARCH "s390x") +else() + message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") +endif() + +include(CheckCSourceRuns) + +check_c_source_runs([=[ +#include <stdlib.h> +#if defined(__GLIBC__) +#error "GLIBC detected" +#elif defined(__MUSL__) +int main(void) { return EXIT_SUCCESS; } +#else +#error "Neither GLIBC nor Musl detected" +#endif + ]=] + IS_MUSL) + +if(MINGW) + set(EXTRA "_mingw") +elseif(IS_MUSL) + set(EXTRA "_musl") +endif() Review Comment: Presumably you can skip this on macOS? -- 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-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org