diff --git a/velox/core/PlanNode.h b/velox/core/PlanNode.h index dc5ca3477a6a5..af84e3e1d3b70 100644 --- a/velox/core/PlanNode.h +++ b/velox/core/PlanNode.h @@ -18,7 +18,7 @@ #include "velox/connectors/Connector.h" #include "velox/core/Expressions.h" -#include "velox/vector/arrow/Bridge.h" +#include "velox/vector/arrow/c/Bridge.h" namespace facebook::velox::core { diff --git a/velox/exec/ArrowStream.h b/velox/exec/ArrowStream.h index 62783f56788d6..43744b243f502 100644 --- a/velox/exec/ArrowStream.h +++ b/velox/exec/ArrowStream.h @@ -16,7 +16,7 @@ #include "velox/core/PlanNode.h" #include "velox/exec/Operator.h" -#include "velox/vector/arrow/Abi.h" +#include "velox/vector/arrow/c/abi.h" namespace facebook::velox::exec { diff --git a/velox/vector/arrow/CMakeLists.txt b/velox/vector/arrow/CMakeLists.txt index 31038b1a41f5c..d1258790f5b9e 100644 --- a/velox/vector/arrow/CMakeLists.txt +++ b/velox/vector/arrow/CMakeLists.txt @@ -11,11 +11,5 @@ # 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. -add_library(velox_arrow_bridge Bridge.cpp) -target_link_libraries(velox_arrow_bridge velox_memory velox_type velox_buffer - velox_exception) - -if(VELOX_BUILD_TESTING AND VELOX_ENABLE_ARROW) - add_subdirectory(tests) -endif() +add_subdirectory(c) diff --git a/velox/vector/arrow/Bridge.cpp b/velox/vector/arrow/c/Bridge.cpp similarity index 99% rename from velox/vector/arrow/Bridge.cpp rename to velox/vector/arrow/c/Bridge.cpp index eace024776ba6..a6842fd72670b 100644 --- a/velox/vector/arrow/Bridge.cpp +++ b/velox/vector/arrow/c/Bridge.cpp @@ -14,8 +14,7 @@ * limitations under the License. */ -#include "velox/vector/arrow/Bridge.h" - +#include "velox/vector/arrow/c/Bridge.h" #include "velox/buffer/Buffer.h" #include "velox/common/base/BitUtil.h" #include "velox/common/base/Exceptions.h" diff --git a/velox/vector/arrow/Bridge.h b/velox/vector/arrow/c/Bridge.h similarity index 85% rename from velox/vector/arrow/Bridge.h rename to velox/vector/arrow/c/Bridge.h index cfdf30f34066c..80005ee9382fe 100644 --- a/velox/vector/arrow/Bridge.h +++ b/velox/vector/arrow/c/Bridge.h @@ -18,17 +18,14 @@ #include "velox/common/memory/Memory.h" #include "velox/vector/BaseVector.h" +#include "velox/vector/arrow/c/abi.h" -/// These 2 definitions should be included by user from either -/// 1. or -/// 2. "velox/vector/arrow/Abi.h" struct ArrowArray; struct ArrowSchema; namespace facebook::velox { - -/// Export a generic Velox Vector to an ArrowArray, as defined by Arrow's C data -/// interface: +/// Export a generic Velox Vector to an ArrowArray, as defined by Arrow's C +/// data interface: /// /// https://arrow.apache.org/docs/format/CDataInterface.html /// @@ -36,13 +33,13 @@ namespace facebook::velox { /// heap or stack), and after usage, the standard REQUIRES the client to call /// the release() function (or memory will leak). /// -/// After exporting, the ArrowArray will hold ownership to the underlying Vector -/// being referenced, so the consumer does not need to explicitly hold on to the -/// input Vector shared_ptr. +/// After exporting, the ArrowArray will hold ownership to the underlying +/// Vector being referenced, so the consumer does not need to explicitly hold +/// on to the input Vector shared_ptr. /// /// The function takes a memory pool where allocations will be made (in cases -/// where the conversion is not zero-copy, e.g. for strings) and throws in case -/// the conversion is not implemented yet. +/// where the conversion is not zero-copy, e.g. for strings) and throws in +/// case the conversion is not implemented yet. /// /// Example usage: /// @@ -81,10 +78,10 @@ void exportToArrow(const TypePtr& type, ArrowSchema& arrowSchema); /// Import an ArrowSchema into a Velox Type object. /// -/// This function does the exact opposite of the function above. TypePtr carries -/// all buffers they need to represent types, so after this function returns, -/// the client is free to release any buffers associated with the input -/// ArrowSchema object. +/// This function does the exact opposite of the function above. TypePtr +/// carries all buffers they need to represent types, so after this function +/// returns, the client is free to release any buffers associated with the +/// input ArrowSchema object. /// /// The function throws in case there was no valid conversion available. /// @@ -105,8 +102,8 @@ TypePtr importFromArrow(const ArrowSchema& arrowSchema); /// both (buffer and type). A memory pool is also required, since all vectors /// carry a pointer to it, but not really used in most cases - unless the /// conversion itself requires a new allocation. In most cases no new -/// allocations are required, unless for arrays of varchars (or varbinaries) and -/// complex types written out of order. +/// allocations are required, unless for arrays of varchars (or varbinaries) +/// and complex types written out of order. /// /// The new Velox vector returned contains only references to the underlying /// buffers, so it's the client's responsibility to ensure the buffer's @@ -132,14 +129,14 @@ VectorPtr importFromArrowAsViewer( /// ownership over the input data. /// /// Similar to importFromArrowAsViewer but the ownership of arrowSchema and -/// arrowArray will be taken over. Specifically, the returned Vector will own a -/// copy of arrowSchema and arrowArray. -/// -/// The inputs arrowSchema and arrowArray will be marked as released by setting -/// their release callback to nullptr -/// (https://arrow.apache.org/docs/format/CDataInterface.html). Afterwards, the -/// returned Vector will be responsible for calling the release callbacks when -/// destructed. +/// arrowArray will be taken over. Specifically, the returned Vector will own +/// a copy of arrowSchema and arrowArray. +/// +/// The inputs arrowSchema and arrowArray will be marked as released by +/// setting their release callback to nullptr +/// (https://arrow.apache.org/docs/format/CDataInterface.html). Afterwards, +/// the returned Vector will be responsible for calling the release callbacks +/// when destructed. VectorPtr importFromArrowAsOwner( ArrowSchema& arrowSchema, ArrowArray& arrowArray, diff --git a/velox/vector/arrow/c/CMakeLists.txt b/velox/vector/arrow/c/CMakeLists.txt new file mode 100644 index 0000000000000..a4975d6f570cd --- /dev/null +++ b/velox/vector/arrow/c/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# Licensed 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. +add_library(velox_arrow_bridge Bridge.cpp) + +target_link_libraries(velox_arrow_bridge velox_memory velox_type velox_buffer + velox_exception) + +if(${VELOX_BUILD_TESTING}) + add_subdirectory(tests) +endif() diff --git a/velox/vector/arrow/Abi.h b/velox/vector/arrow/c/abi.h similarity index 100% rename from velox/vector/arrow/Abi.h rename to velox/vector/arrow/c/abi.h diff --git a/velox/vector/arrow/tests/ArrowBridgeArrayTest.cpp b/velox/vector/arrow/c/tests/ArrowBridgeArrayTest.cpp similarity index 99% rename from velox/vector/arrow/tests/ArrowBridgeArrayTest.cpp rename to velox/vector/arrow/c/tests/ArrowBridgeArrayTest.cpp index e1f21e59917ef..6168d9994ec65 100644 --- a/velox/vector/arrow/tests/ArrowBridgeArrayTest.cpp +++ b/velox/vector/arrow/c/tests/ArrowBridgeArrayTest.cpp @@ -19,7 +19,7 @@ #include "velox/common/base/Nulls.h" #include "velox/core/QueryCtx.h" -#include "velox/vector/arrow/Bridge.h" +#include "velox/vector/arrow/c/Bridge.h" #include "velox/vector/tests/VectorMaker.h" namespace { diff --git a/velox/vector/arrow/tests/ArrowBridgeSchemaTest.cpp b/velox/vector/arrow/c/tests/ArrowBridgeSchemaTest.cpp similarity index 99% rename from velox/vector/arrow/tests/ArrowBridgeSchemaTest.cpp rename to velox/vector/arrow/c/tests/ArrowBridgeSchemaTest.cpp index fc7685c980cf9..97e433cfd0c4f 100644 --- a/velox/vector/arrow/tests/ArrowBridgeSchemaTest.cpp +++ b/velox/vector/arrow/c/tests/ArrowBridgeSchemaTest.cpp @@ -20,7 +20,7 @@ #include #include "velox/common/base/Nulls.h" -#include "velox/vector/arrow/Bridge.h" +#include "velox/vector/arrow/c/Bridge.h" namespace { diff --git a/velox/vector/arrow/tests/CMakeLists.txt b/velox/vector/arrow/c/tests/CMakeLists.txt similarity index 100% rename from velox/vector/arrow/tests/CMakeLists.txt rename to velox/vector/arrow/c/tests/CMakeLists.txt