Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move arrow abi (#3)
Browse files Browse the repository at this point in the history
rui-mo authored and zhejiangxiaomai committed Jul 26, 2022
1 parent 6e075a2 commit 0f53935
Showing 10 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion velox/core/PlanNode.h
Original file line number Diff line number Diff line change
@@ -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 {

2 changes: 1 addition & 1 deletion velox/exec/ArrowStream.h
Original file line number Diff line number Diff line change
@@ -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 {

8 changes: 1 addition & 7 deletions velox/vector/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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"
47 changes: 22 additions & 25 deletions velox/vector/arrow/Bridge.h → velox/vector/arrow/c/Bridge.h
Original file line number Diff line number Diff line change
@@ -18,31 +18,28 @@

#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. <arrow/c/abi.h> 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
///
/// The output ArrowArray needs to be allocated by the consumer (either in the
/// 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,
21 changes: 21 additions & 0 deletions velox/vector/arrow/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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 {
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
#include <gtest/gtest.h>

#include "velox/common/base/Nulls.h"
#include "velox/vector/arrow/Bridge.h"
#include "velox/vector/arrow/c/Bridge.h"

namespace {

File renamed without changes.

0 comments on commit 0f53935

Please sign in to comment.