[native] Dynamically Linked Library in Presto CPP#24330
[native] Dynamically Linked Library in Presto CPP#24330aditi-pandit merged 1 commit intoprestodb:masterfrom
Conversation
|
|
| ${GFLAGS_LIBRARIES} | ||
| pthread) | ||
| pthread | ||
| velox_dynamic_function_loader) |
There was a problem hiding this comment.
Move this before the velox_encode library.
| presto_link_job_pool) | ||
|
|
||
| add_executable(presto_server PrestoMain.cpp) | ||
| target_link_options(presto_server BEFORE PUBLIC "-Wl,-export-dynamic") |
There was a problem hiding this comment.
Can we add a comment here why we need these flags?
| const fs::path path(systemConfig->pluginDir()); | ||
| PRESTO_STARTUP_LOG(INFO) << path; | ||
| std::error_code | ||
| ec; // For using the non-throwing overloads of functions below. |
There was a problem hiding this comment.
We don;t need this comment here and so can fix up the odd formatting.
| void PrestoServer::registerDynamicFunctions() { | ||
| auto systemConfig = SystemConfig::instance(); | ||
| if (!systemConfig->pluginDir().empty()) { | ||
| // if it is a valid directory, traverse and call dynamic function loader |
There was a problem hiding this comment.
Please make sure the comments are full sentences beginning with capitalization etc.
| auto dirEntryPath = dirEntry.path(); | ||
| if (!fs::is_directory(dirEntry, ec) && | ||
| extensions.find(dirEntryPath.extension()) != extensions.end()) { | ||
| facebook::velox::loadDynamicLibrary(dirEntryPath.c_str()); |
There was a problem hiding this comment.
facebook is not needed here because we are already in the facebook namespace.
steveburnett
left a comment
There was a problem hiding this comment.
Thanks for the doc! A few minor formatting and phrasing suggestions.
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
steveburnett
left a comment
There was a problem hiding this comment.
Thanks for the documentation! I really liked your including the setup steps on plugin.rst. Some minor suggestions for formatting and phrasing but looks good overall.
presto-native-execution/presto_cpp/main/dynamic_registry/README.md
Outdated
Show resolved
Hide resolved
presto-docs/src/main/sphinx/presto_cpp/plugin/function_plugin.rst
Outdated
Show resolved
Hide resolved
presto-docs/src/main/sphinx/presto_cpp/plugin/function_plugin.rst
Outdated
Show resolved
Hide resolved
presto-docs/src/main/sphinx/presto_cpp/plugin/function_plugin.rst
Outdated
Show resolved
Hide resolved
|
Thanks @steveburnett please take another look, I've made the changes. I'm not sure about the tone on the intro to UDFs i have on function_plugin.rst, would appreciate another set of eyes there. |
steveburnett
left a comment
There was a problem hiding this comment.
Thanks for the revision! Nice work, your unordered list of UDF benefits was great and the format fixes in the README look good.
I made a couple of small suggestions about the intro to UDFs, let me know what you think.
presto-docs/src/main/sphinx/presto_cpp/plugin/function_plugin.rst
Outdated
Show resolved
Hide resolved
presto-docs/src/main/sphinx/presto_cpp/plugin/function_plugin.rst
Outdated
Show resolved
Hide resolved
steveburnett
left a comment
There was a problem hiding this comment.
I should have noticed this spelling nit earlier! After I found this one, I did a complete review of the doc in this PR and found no other errors so I think this is the last one.
presto-docs/src/main/sphinx/presto_cpp/plugin/function_plugin.rst
Outdated
Show resolved
Hide resolved
| * Once defined, easily reusable and called multiple times just like built in functions. | ||
| * Shorter compile times. | ||
|
|
||
| 1. To create the UDF, create a new C++ file named ``ExampleFunction.cpp`` in the same format as this example: |
There was a problem hiding this comment.
This reads like you can only use the name ExampleFunction.cpp. You can say something like
"Create a new C++ file for your UDF. We are using a c++ file named `ExampleFunction.cpp`` for the examples below."
There was a problem hiding this comment.
good catch! thank you!
To create the UDF, create a new C++ file in the same format as the below example file named
ExampleFunction.cpp
hope this conveys the message!! lmk what you think
| } | ||
| } | ||
|
|
||
| Note: The ``int64_t`` return type and the ``Varchar`` input type can be changed as needed. Additional or no arguments may be specified as well. For more examples, see the `examples <https://github.com/soumiiow/presto/tree/dylib_new/presto-native-execution/presto_cpp/main/dynamic_registry/examples>`_. |
There was a problem hiding this comment.
Add a link saying that the functions follow Velox scalar function API. Please follow https://facebookincubator.github.io/velox/develop/scalar-functions.html for more details on how to write scalar functions.
| void PrestoServer::registerDynamicFunctions() { | ||
| std::error_code | ||
| ec; // For using the non-throwing overloads of functions below. | ||
| auto systemConfig = SystemConfig::instance(); |
| for (const auto& dirEntry : | ||
| std::filesystem::directory_iterator(pluginDir)) { | ||
| if (isSharedLibrary(dirEntry.path())) { | ||
| PRESTO_STARTUP_LOG(INFO) |
There was a problem hiding this comment.
Please add the library name in the info message.
| } // namespace facebook::velox::common::dynamicRegistry | ||
|
|
||
| extern "C" { | ||
|
|
There was a problem hiding this comment.
Nit: the other files have no empty line here.
| }; | ||
|
|
||
| extern "C" { | ||
| void registerExtensions() { |
There was a problem hiding this comment.
Should we mention it that this name is required in the note below? It is mentioned in the examples.
We could say something like:
The function
registerExtensionsis the entry point to execute the registration of the UDF and cannot be changed.
There was a problem hiding this comment.
i like this, ill add this as a comment for all example files!
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| add_subdirectory(examples) |
There was a problem hiding this comment.
We need to add a CMake flag PRESTO_ENABLE_EXAMPLES to guard this
There was a problem hiding this comment.
will add this here, but i'm wondering should this be able enabled/disabled in presto-native-execution/CMakelists.txt like so:
set(PRESTO_ENABLE_EXAMPLES OFF CACHE BOOL "Enable Presto examples")
presto-native-execution/presto_cpp/main/dynamic_registry/CMakeLists.txt
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,122 @@ | |||
| /* | |||
There was a problem hiding this comment.
Is this test being run? I don't see it being added to any test executable.
There was a problem hiding this comment.
sorry meant to leave this file out! i mustve picked up this change as i was switching my branches around
| endif() | ||
|
|
||
| set(PRESTO_ENABLE_EXAMPLES | ||
| ON |
|
|
||
| void PrestoServer::registerDynamicFunctions() { | ||
| std::error_code | ||
| ec; // For using the non-throwing overloads of functions below. |
There was a problem hiding this comment.
// For using the non-throwing overloads of functions below.
std::error_code ec;
aditi-pandit
left a comment
There was a problem hiding this comment.
Thanks @soumiiow for the iterations.
|
@soumiiow : Can you rebase ? |
|
@steveburnett can you please re-review the doc changes? |
steveburnett
left a comment
There was a problem hiding this comment.
Looks good! A formatting nit, and a suggestion that I think makes the steps more clear.
steveburnett
left a comment
There was a problem hiding this comment.
A single formatting nit, nothing else!
steveburnett
left a comment
There was a problem hiding this comment.
LGTM! (docs)
Pull updated branch, new local doc build, looks great. No problems found.
Thanks for your patience!
steveburnett
left a comment
There was a problem hiding this comment.
LGMT! (docs)
Pull updated branch, new local doc build, everything looks good.
|
@soumiiow : Can you change the commit title to that of this PR ? Presto PRs are not merged like Velox PRs. |
Description
Depends on facebookincubator/velox#11439 in the Velox space
and based off of the following PR: https://github.com/facebookincubator/velox/pull/1005/files
Motivation and Context
Having these changes will enable users to register custom functions dynamically without requiring a fork of Prestissimo.
Impact
This extends Prestissimo functionality to include dynamic loading of functions, types, connectors, etc.
Test Plan
Unit tested. and Manually end to end tested the changes.
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.
If release note is NOT required, use: