This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create PyVelox package and move type dependencies over.
- Loading branch information
Showing
6 changed files
with
171 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
if(${CREATE_PYVELOX_MODULE}) | ||
|
||
# Define our Python module: | ||
pybind11_add_module( | ||
_pyvelox | ||
MODULE | ||
NO_EXTRAS # TODO: LTO crashes GCC9.2. File issues to pybind11 | ||
pyvelox.cpp | ||
pyvelox.h | ||
) | ||
|
||
# Link with Velox: | ||
target_link_libraries(_pyvelox PRIVATE | ||
velox_type | ||
) | ||
|
||
install( | ||
TARGETS _pyvelox | ||
LIBRARY DESTINATION . | ||
) | ||
else() | ||
add_library(pyvelox pyvelox.cpp pyvelox.h) | ||
target_link_libraries( | ||
pyvelox | ||
velox_type | ||
pybind11::module) | ||
endif() | ||
|
Empty file.
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,111 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "pyvelox.h" | ||
|
||
|
||
namespace facebook::pyvelox { | ||
namespace py = pybind11; | ||
|
||
template <velox::TypeKind kind> | ||
void declareType(py::module& m) { | ||
using I = typename velox::TypeTraits<kind>::ImplType; | ||
py::class_<I, velox::Type, std::shared_ptr<I>>( | ||
m, | ||
(std::string("VeloxType_") + velox::TypeTraits<kind>::name).c_str()) | ||
.def(py::init()); | ||
} | ||
|
||
void addVeloxBindings(py::module& m) { | ||
py::enum_<velox::TypeKind>( | ||
m, | ||
"TypeKind", | ||
py::module_local()) | ||
.value("BOOLEAN", velox::TypeKind::BOOLEAN) | ||
.value("TINYINT", velox::TypeKind::TINYINT) | ||
.value("SMALLINT", velox::TypeKind::SMALLINT) | ||
.value("INTEGER", velox::TypeKind::INTEGER) | ||
.value("BIGINT", velox::TypeKind::BIGINT) | ||
.value("REAL", velox::TypeKind::REAL) | ||
.value("DOUBLE", velox::TypeKind::DOUBLE) | ||
.value("VARCHAR", velox::TypeKind::VARCHAR) | ||
.value("VARBINARY", velox::TypeKind::VARBINARY) | ||
.value("TIMESTAMP", velox::TypeKind::TIMESTAMP) | ||
.value("ARRAY", velox::TypeKind::ARRAY) | ||
.value("MAP", velox::TypeKind::MAP) | ||
.value("ROW", velox::TypeKind::ROW) | ||
.export_values(); | ||
|
||
py::class_<velox::Type, std::shared_ptr<facebook::velox::Type>>( | ||
m, | ||
"VeloxType") | ||
.def("kind", &velox::Type::kind) | ||
.def("kind_name", &velox::Type::kindName); | ||
|
||
declareType<velox::TypeKind::BIGINT>(m); | ||
declareType<velox::TypeKind::BOOLEAN>(m); | ||
declareType<velox::TypeKind::TINYINT>(m); | ||
declareType<velox::TypeKind::SMALLINT>(m); | ||
declareType<velox::TypeKind::INTEGER>(m); | ||
declareType<velox::TypeKind::REAL>(m); | ||
declareType<velox::TypeKind::DOUBLE>(m); | ||
declareType<velox::TypeKind::VARCHAR>(m); | ||
declareType<velox::TypeKind::VARBINARY>(m); | ||
declareType<velox::TypeKind::TIMESTAMP>(m); | ||
|
||
using I = typename velox::TypeTraits<velox::TypeKind::ARRAY>::ImplType; | ||
py::class_<I, velox::Type, std::shared_ptr<I>>( | ||
m, | ||
"VeloxArrayType") | ||
.def(py::init<velox::TypePtr>()) | ||
.def("element_type", &velox::ArrayType::elementType); | ||
|
||
using J = typename velox::FixedSizeArrayType; | ||
py::class_<J, velox::Type, std::shared_ptr<J>>( | ||
m, "VeloxFixedArrayType") | ||
.def(py::init<int, velox::TypePtr>()) | ||
.def("element_type", &velox::FixedSizeArrayType::elementType) | ||
.def("fixed_width", &velox::FixedSizeArrayType::fixedElementsWidth); | ||
|
||
using M = typename velox::TypeTraits<velox::TypeKind::MAP>::ImplType; | ||
py::class_<M, velox::Type, std::shared_ptr<M>>( | ||
m, | ||
"VeloxMapType") | ||
.def(py::init<velox::TypePtr, velox::TypePtr>()) | ||
.def("key_type", &velox::MapType::keyType) | ||
.def("value_type", &velox::MapType::valueType); | ||
|
||
using R = typename velox::TypeTraits<velox::TypeKind::ROW>::ImplType; | ||
|
||
py::class_<R, velox::Type, std::shared_ptr<R>>( | ||
m, | ||
"VeloxRowType") | ||
.def(py::init< | ||
std::vector<std::string>&&, | ||
std::vector<std::shared_ptr<const velox::Type>>&&>()) | ||
.def("size", &R::size) | ||
.def("get_child_idx", &R::getChildIdx) | ||
.def("contains_child", &R::containsChild) | ||
.def("name_of", &R::nameOf) | ||
.def("child_at", &R::childAt); | ||
} | ||
|
||
#ifdef CREATE_PYVELOX_MODULE | ||
PYBIND11_MODULE(_pyvelox, m) { | ||
m.doc() = R"pbdoc( | ||
PyVelox native code module | ||
----------------------- | ||
)pbdoc"; | ||
|
||
addVeloxBindings(m); | ||
|
||
m.attr("__version__") = "dev"; | ||
} | ||
#endif | ||
} | ||
|
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,19 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <pybind11/stl_bind.h> | ||
#include <velox/type/Type.h> | ||
|
||
namespace facebook::pyvelox { | ||
|
||
void addVeloxBindings(pybind11::module& m); | ||
} |