forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for signature bindings in PyVelox (facebookincubator#4333)
Summary: Adding support for signature bindings will allow us to track changes in signatures across changes. This is required so we can diff changes in signatures during CI time. Pull Request resolved: facebookincubator#4333 Reviewed By: pedroerp Differential Revision: D44179392 Pulled By: kgpai fbshipit-source-id: eec405cc745222e18aa06e0ddc2912e880ee68f6
- Loading branch information
1 parent
2bde750
commit 3c62503
Showing
10 changed files
with
201 additions
and
8 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,79 @@ | ||
/* | ||
* 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 "signatures.h" // @manual | ||
#include "velox/functions/FunctionRegistry.h" | ||
#include "velox/functions/prestosql/registration/RegistrationFunctions.h" | ||
#include "velox/functions/sparksql/Register.h" | ||
|
||
namespace facebook::velox::py { | ||
|
||
namespace py = pybind11; | ||
|
||
void registerPrestoFunctions(const std::string& prefix) { | ||
facebook::velox::functions::prestosql::registerAllScalarFunctions(prefix); | ||
} | ||
|
||
void registerSparkFunctions(const std::string& prefix) { | ||
facebook::velox::functions::sparksql::registerFunctions(prefix); | ||
} | ||
|
||
void addSignatureBindings(py::module& m, bool asModuleLocalDefinitions) { | ||
// TypeSignature | ||
py::class_<exec::TypeSignature> typeSignature( | ||
m, "TypeSignature", py::module_local(asModuleLocalDefinitions)); | ||
typeSignature.def("__str__", &exec::TypeSignature::toString); | ||
typeSignature.def("base_name", &exec::TypeSignature::baseName); | ||
typeSignature.def("parameters", &exec::TypeSignature::parameters); | ||
|
||
// FunctionSignature | ||
py::class_<exec::FunctionSignature> functionSignature( | ||
m, "FunctionSignature", py::module_local(asModuleLocalDefinitions)); | ||
|
||
functionSignature.def("__str__", &exec::FunctionSignature::toString); | ||
functionSignature.def("return_type", &exec::FunctionSignature::returnType); | ||
functionSignature.def( | ||
"argument_types", &exec::FunctionSignature::argumentTypes); | ||
functionSignature.def( | ||
"variable_arity", &exec::FunctionSignature::variableArity); | ||
functionSignature.def("variables", &exec::FunctionSignature::variables); | ||
functionSignature.def( | ||
"constant_arguments", &exec::FunctionSignature::constantArguments); | ||
|
||
m.def( | ||
"clear_signatures", | ||
&clearFunctionRegistry, | ||
"Clears the function registry."); | ||
|
||
m.def( | ||
"register_spark_signatures", | ||
®isterSparkFunctions, | ||
"Adds Spark signatures to the function registry.", | ||
py::arg("prefix") = ""); | ||
|
||
m.def( | ||
"register_presto_signatures", | ||
®isterPrestoFunctions, | ||
"Adds Presto signatures to the function registry.", | ||
py::arg("prefix") = ""); | ||
|
||
m.def( | ||
"get_function_signatures", | ||
&getFunctionSignatures, | ||
py::return_value_policy::reference, | ||
"Returns a dictionary of the current signatures."); | ||
} | ||
} // 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,36 @@ | ||
/* | ||
* 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> | ||
#include <pybind11/stl.h> | ||
|
||
namespace facebook::velox::py { | ||
|
||
namespace py = pybind11; | ||
|
||
/// Adds Function signature bindings to module m. | ||
/// This adds bindings to select Presto and Spark function signatures. | ||
/// | ||
/// @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 addSignatureBindings(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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. | ||
|
||
import unittest | ||
|
||
import pyvelox.pyvelox as pv | ||
|
||
|
||
class TestFunctionSignatures(unittest.TestCase): | ||
def test_clear_signatures(self): | ||
pv.clear_signatures() | ||
signatures = pv.get_function_signatures() | ||
self.assertEqual(len(signatures), 0) | ||
|
||
def test_get_signatures(self): | ||
pv.register_presto_signatures() | ||
presto_signatures = pv.get_function_signatures() | ||
self.assertTrue(len(presto_signatures) > 0) | ||
|
||
pv.clear_signatures() | ||
pv.register_spark_signatures() | ||
spark_signatures = pv.get_function_signatures() | ||
self.assertTrue(len(spark_signatures) > 0) | ||
|
||
def test_function_signature(self): | ||
pv.clear_signatures() | ||
pv.register_presto_signatures() | ||
presto_signatures = pv.get_function_signatures() | ||
|
||
concat_signatures = presto_signatures["concat"] | ||
self.assertTrue(len(concat_signatures) > 0) | ||
self.assertEqual(str(concat_signatures[0].return_type()), "varchar") | ||
self.assertEqual(str(concat_signatures[0]), "(varchar,varchar...) -> varchar") | ||
|
||
def test_function_prefix(self): | ||
pv.clear_signatures() | ||
pv.register_presto_signatures("foo") | ||
presto_signatures = pv.get_function_signatures() | ||
|
||
concat_signatures = presto_signatures["fooconcat"] | ||
self.assertTrue(len(concat_signatures) > 0) | ||
|
||
pv.clear_signatures() | ||
pv.register_spark_signatures("bar") | ||
spark_signatures = pv.get_function_signatures() | ||
|
||
concat_signatures = spark_signatures["barconcat"] | ||
self.assertTrue(len(concat_signatures) > 0) |
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