forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Arrow - Velox conversion support (facebookincubator#4450)
Summary: This PR introduces PyVelox functions for the conversion of Arrow Arrays to Velox Vectors and vice-versa. Pull Request resolved: facebookincubator#4450 Reviewed By: bikramSingh91 Differential Revision: D46570398 Pulled By: kgpai fbshipit-source-id: cf0557ad26a568f10866683e59cfa2bd79040579
- Loading branch information
1 parent
5f663d5
commit 8e95993
Showing
8 changed files
with
146 additions
and
5 deletions.
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
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 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "conversion.h" | ||
#include <velox/vector/arrow/Abi.h> | ||
#include <velox/vector/arrow/Bridge.h> | ||
#include "context.h" | ||
|
||
namespace facebook::velox::py { | ||
|
||
namespace py = pybind11; | ||
|
||
void addConversionBindings(py::module& m, bool asModuleLocalDefinitions) { | ||
m.def("export_to_arrow", [](VectorPtr& inputVector) { | ||
auto arrowArray = std::make_unique<ArrowArray>(); | ||
auto pool_ = PyVeloxContext::getSingletonInstance().pool(); | ||
facebook::velox::exportToArrow(inputVector, *arrowArray, pool_); | ||
|
||
auto arrowSchema = std::make_unique<ArrowSchema>(); | ||
facebook::velox::exportToArrow(inputVector, *arrowSchema); | ||
|
||
py::module arrow_module = py::module::import("pyarrow"); | ||
py::object array_class = arrow_module.attr("Array"); | ||
return array_class.attr("_import_from_c")( | ||
reinterpret_cast<uintptr_t>(arrowArray.get()), | ||
reinterpret_cast<uintptr_t>(arrowSchema.get())); | ||
}); | ||
|
||
m.def("import_from_arrow", [](py::object inputArrowArray) { | ||
auto arrowArray = std::make_unique<ArrowArray>(); | ||
auto arrowSchema = std::make_unique<ArrowSchema>(); | ||
inputArrowArray.attr("_export_to_c")( | ||
reinterpret_cast<uintptr_t>(arrowArray.get()), | ||
reinterpret_cast<uintptr_t>(arrowSchema.get())); | ||
auto pool_ = PyVeloxContext::getSingletonInstance().pool(); | ||
return importFromArrowAsOwner(*arrowSchema, *arrowArray, pool_); | ||
}); | ||
} | ||
} // namespace facebook::velox::py |
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,34 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace facebook::velox::py { | ||
|
||
namespace py = pybind11; | ||
|
||
/// Adds bindings for arrow-velox conversion functions to module m. | ||
/// | ||
/// @param m Module to add bindings to. | ||
/// @param asModuleLocalDefinitions If true then these bindings are only | ||
/// visible inside the module. Refer to | ||
/// https://pybind11.readthedocs.io/en/stable/advanced/classes.html#module-local-class-bindings | ||
/// for further details. | ||
void addConversionBindings(py::module& m, bool asModuleLocalDefinitions = true); | ||
|
||
} // namespace facebook::velox::py |
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