Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit b78f7a5

Browse files
committed
Create PyVelox package and move type dependencies over.
1 parent 6d6af07 commit b78f7a5

File tree

13 files changed

+309
-239
lines changed

13 files changed

+309
-239
lines changed

csrc/velox/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ endif()
9191
# set_target_properties(_torcharrow PROPERTIES CXX_VISIBILITY_PRESET default)
9292
add_subdirectory(velox)
9393
add_subdirectory(functions)
94+
add_subdirectory(pyvelox)
9495

9596

9697
# Link with Velox:

csrc/velox/column.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "velox/vector/FlatVector.h"
2525
#include "velox/vector/arrow/Abi.h"
2626
#include "velox/vector/arrow/Bridge.h"
27+
#include <iostream>
2728

2829
// TODO: Move uses of static variables into .cpp. Static variables are local to
2930
// the compilation units so every file that includes this header will have its
@@ -313,6 +314,7 @@ class BaseColumn {
313314

314315
explicit BaseColumn(velox::TypePtr type)
315316
: _offset(0), _length(0), _nullCount(0) {
317+
std::cout<<"In basecolumn..\n";
316318
_delegate = velox::BaseVector::create(type, 0, pool_);
317319
}
318320

csrc/velox/lib.cpp

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <velox/common/memory/Memory.h>
1313
#include <velox/type/Type.h>
1414
#include <velox/vector/TypeAliases.h>
15-
#include <iostream>
1615
#include <memory>
1716

1817
#include "bindings.h"
@@ -23,10 +22,9 @@
2322
#include "velox/buffer/StringViewBufferHolder.h"
2423
#include "velox/common/base/Exceptions.h"
2524
#include "velox/functions/prestosql/registration/RegistrationFunctions.h"
26-
#include "velox/type/Type.h"
27-
#include "velox/vector/TypeAliases.h"
2825
#include "velox/vector/arrow/Abi.h"
2926
#include "velox/vector/arrow/Bridge.h"
27+
#include <iostream>
3028

3129
#ifdef USE_TORCH
3230
#include <torch/csrc/utils/pybind.h> // @manual
@@ -136,12 +134,6 @@ py::class_<SimpleColumn<T>, BaseColumn> declareSimpleType(
136134
});
137135

138136
using I = typename velox::TypeTraits<kind>::ImplType;
139-
py::class_<I, velox::Type, std::shared_ptr<I>>(
140-
m,
141-
(std::string("VeloxType_") + velox::TypeTraits<kind>::name).c_str(),
142-
// TODO: Move the Koksi binding of Velox type to OSS
143-
py::module_local())
144-
.def(py::init());
145137

146138
// Empty Column
147139
m.def("Column", [](std::shared_ptr<I> type) {
@@ -681,23 +673,12 @@ void declareArrayType(py::module& m) {
681673
.def("withElements", &ArrayColumn::withElements);
682674

683675
using I = typename velox::TypeTraits<velox::TypeKind::ARRAY>::ImplType;
684-
py::class_<I, velox::Type, std::shared_ptr<I>>(
685-
m,
686-
"VeloxArrayType",
687-
// TODO: Move the Koksi binding of Velox type to OSS
688-
py::module_local())
689-
.def(py::init<velox::TypePtr>())
690-
.def("element_type", &velox::ArrayType::elementType);
691-
692-
using J = typename velox::FixedSizeArrayType;
693-
py::class_<J, velox::Type, std::shared_ptr<J>>(
694-
m, "VeloxFixedArrayType", py::module_local())
695-
.def(py::init<int, velox::TypePtr>())
696-
.def("element_type", &velox::FixedSizeArrayType::elementType)
697-
.def("fixed_width", &velox::FixedSizeArrayType::fixedElementsWidth);
676+
677+
using J = typename velox::FixedSizeArrayType;
698678

699679
// Empty Column
700680
m.def("Column", [](std::shared_ptr<I> type) {
681+
std::cout<<"In array column..\n";
701682
return std::make_unique<ArrayColumn>(type);
702683
});
703684
m.def("Column", [](std::shared_ptr<J> type) {
@@ -737,14 +718,6 @@ void declareMapType(py::module& m) {
737718
.def("slice", &MapColumn::slice);
738719

739720
using I = typename velox::TypeTraits<velox::TypeKind::MAP>::ImplType;
740-
py::class_<I, velox::Type, std::shared_ptr<I>>(
741-
m,
742-
"VeloxMapType",
743-
// TODO: Move the Koksi binding of Velox type to OSS
744-
py::module_local())
745-
.def(py::init<velox::TypePtr, velox::TypePtr>())
746-
.def("key_type", &velox::MapType::keyType)
747-
.def("value_type", &velox::MapType::valueType);
748721

749722
m.def("Column", [](std::shared_ptr<I> type) {
750723
return std::make_unique<MapColumn>(type);
@@ -772,19 +745,6 @@ void declareRowType(py::module& m) {
772745
});
773746

774747
using I = typename velox::TypeTraits<velox::TypeKind::ROW>::ImplType;
775-
py::class_<I, velox::Type, std::shared_ptr<I>>(
776-
m,
777-
"VeloxRowType",
778-
// TODO: Move the Koksi binding of Velox type to OSS
779-
py::module_local())
780-
.def(py::init<
781-
std::vector<std::string>&&,
782-
std::vector<std::shared_ptr<const velox::Type>>&&>())
783-
.def("size", &I::size)
784-
.def("get_child_idx", &I::getChildIdx)
785-
.def("contains_child", &I::containsChild)
786-
.def("name_of", &I::nameOf)
787-
.def("child_at", &I::childAt);
788748
m.def("Column", [](std::shared_ptr<I> type) {
789749
return std::make_unique<RowColumn>(type);
790750
});
@@ -833,32 +793,6 @@ PYBIND11_MODULE(_torcharrow, m) {
833793
.def_property_readonly("length", &BaseColumn::getLength)
834794
.def("__len__", &BaseColumn::getLength);
835795

836-
py::enum_<velox::TypeKind>(
837-
m,
838-
"TypeKind", // TODO: Move the Koksi binding of Velox type to OSS
839-
py::module_local())
840-
.value("BOOLEAN", velox::TypeKind::BOOLEAN)
841-
.value("TINYINT", velox::TypeKind::TINYINT)
842-
.value("SMALLINT", velox::TypeKind::SMALLINT)
843-
.value("INTEGER", velox::TypeKind::INTEGER)
844-
.value("BIGINT", velox::TypeKind::BIGINT)
845-
.value("REAL", velox::TypeKind::REAL)
846-
.value("DOUBLE", velox::TypeKind::DOUBLE)
847-
.value("VARCHAR", velox::TypeKind::VARCHAR)
848-
.value("VARBINARY", velox::TypeKind::VARBINARY)
849-
.value("TIMESTAMP", velox::TypeKind::TIMESTAMP)
850-
.value("ARRAY", velox::TypeKind::ARRAY)
851-
.value("MAP", velox::TypeKind::MAP)
852-
.value("ROW", velox::TypeKind::ROW)
853-
.export_values();
854-
855-
py::class_<velox::Type, std::shared_ptr<velox::Type>>(
856-
m,
857-
"VeloxType",
858-
// TODO: Move the Koksi binding of Velox type to OSS
859-
py::module_local())
860-
.def("kind", &velox::Type::kind)
861-
.def("kind_name", &velox::Type::kindName);
862796

863797
declareIntegralType<velox::TypeKind::BIGINT>(m);
864798
declareIntegralType<velox::TypeKind::INTEGER>(m);

csrc/velox/pyvelox/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# Define our Python module:
3+
pybind11_add_module(
4+
_pyvelox
5+
MODULE
6+
NO_EXTRAS # TODO: LTO crashes GCC9.2. File issues to pybind11
7+
pyvelox.cpp
8+
)
9+
10+
# Link with Velox:
11+
target_link_libraries(_pyvelox PRIVATE
12+
velox_type
13+
)
14+
15+
install(
16+
TARGETS _pyvelox
17+
LIBRARY DESTINATION .
18+
)

csrc/velox/pyvelox/__init__.py

Whitespace-only changes.

csrc/velox/pyvelox/pyvelox.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include <pybind11/pybind11.h>
10+
#include <pybind11/stl.h>
11+
#include <pybind11/stl_bind.h>
12+
#include <velox/type/Type.h>
13+
14+
15+
namespace facebook::pyvelox {
16+
namespace py = pybind11;
17+
18+
template <velox::TypeKind kind>
19+
void declareType(py::module& m) {
20+
using I = typename velox::TypeTraits<kind>::ImplType;
21+
py::class_<I, velox::Type, std::shared_ptr<I>>(
22+
m,
23+
(std::string("VeloxType_") + velox::TypeTraits<kind>::name).c_str())
24+
.def(py::init());
25+
}
26+
27+
PYBIND11_MODULE(_pyvelox, m) {
28+
m.doc() = R"pbdoc(
29+
PyVelox native code module
30+
-----------------------
31+
)pbdoc";
32+
33+
py::enum_<velox::TypeKind>(
34+
m,
35+
"TypeKind",
36+
py::module_local())
37+
.value("BOOLEAN", velox::TypeKind::BOOLEAN)
38+
.value("TINYINT", velox::TypeKind::TINYINT)
39+
.value("SMALLINT", velox::TypeKind::SMALLINT)
40+
.value("INTEGER", velox::TypeKind::INTEGER)
41+
.value("BIGINT", velox::TypeKind::BIGINT)
42+
.value("REAL", velox::TypeKind::REAL)
43+
.value("DOUBLE", velox::TypeKind::DOUBLE)
44+
.value("VARCHAR", velox::TypeKind::VARCHAR)
45+
.value("VARBINARY", velox::TypeKind::VARBINARY)
46+
.value("TIMESTAMP", velox::TypeKind::TIMESTAMP)
47+
.value("ARRAY", velox::TypeKind::ARRAY)
48+
.value("MAP", velox::TypeKind::MAP)
49+
.value("ROW", velox::TypeKind::ROW)
50+
.export_values();
51+
52+
py::class_<velox::Type, std::shared_ptr<facebook::velox::Type>>(
53+
m,
54+
"Type")
55+
.def("kind", &velox::Type::kind)
56+
.def("kind_name", &velox::Type::kindName);
57+
58+
declareType<velox::TypeKind::BIGINT>(m);
59+
declareType<velox::TypeKind::BOOLEAN>(m);
60+
declareType<velox::TypeKind::TINYINT>(m);
61+
declareType<velox::TypeKind::SMALLINT>(m);
62+
declareType<velox::TypeKind::INTEGER>(m);
63+
declareType<velox::TypeKind::REAL>(m);
64+
declareType<velox::TypeKind::DOUBLE>(m);
65+
declareType<velox::TypeKind::VARCHAR>(m);
66+
declareType<velox::TypeKind::VARBINARY>(m);
67+
declareType<velox::TypeKind::TIMESTAMP>(m);
68+
69+
using I = typename velox::TypeTraits<velox::TypeKind::ARRAY>::ImplType;
70+
py::class_<I, velox::Type, std::shared_ptr<I>>(
71+
m,
72+
"VeloxArrayType")
73+
.def(py::init<velox::TypePtr>())
74+
.def("element_type", &velox::ArrayType::elementType);
75+
76+
using J = typename velox::FixedSizeArrayType;
77+
py::class_<J, velox::Type, std::shared_ptr<J>>(
78+
m, "VeloxFixedArrayType")
79+
.def(py::init<int, velox::TypePtr>())
80+
.def("element_type", &velox::FixedSizeArrayType::elementType)
81+
.def("fixed_width", &velox::FixedSizeArrayType::fixedElementsWidth);
82+
83+
using M = typename velox::TypeTraits<velox::TypeKind::MAP>::ImplType;
84+
py::class_<M, velox::Type, std::shared_ptr<M>>(
85+
m,
86+
"VeloxMapType")
87+
.def(py::init<velox::TypePtr, velox::TypePtr>())
88+
.def("key_type", &velox::MapType::keyType)
89+
.def("value_type", &velox::MapType::valueType);
90+
91+
using R = typename velox::TypeTraits<velox::TypeKind::ROW>::ImplType;
92+
93+
py::class_<R, velox::Type, std::shared_ptr<R>>(
94+
m,
95+
"VeloxRowType")
96+
.def(py::init<
97+
std::vector<std::string>&&,
98+
std::vector<std::shared_ptr<const velox::Type>>&&>())
99+
.def("size", &R::size)
100+
.def("get_child_idx", &R::getChildIdx)
101+
.def("contains_child", &R::containsChild)
102+
.def("name_of", &R::nameOf)
103+
.def("child_at", &R::childAt);
104+
105+
m.attr("__version__") = "dev";
106+
}
107+
}
108+

0 commit comments

Comments
 (0)