-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial support for WebAssembly in user-defined functions (UDF) #9108
Changes from all commits
46c6603
4e952df
4caf57f
5e6fa47
83f46e6
78afd51
62e8c89
4959136
41b94d3
6c4a71c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ | |
#include "user_types_metadata.hh" | ||
|
||
#include "index/target_parser.hh" | ||
#include "lua.hh" | ||
#include "lang/lua.hh" | ||
|
||
#include "db/query_context.hh" | ||
#include "serializer.hh" | ||
|
@@ -1548,12 +1548,26 @@ static shared_ptr<cql3::functions::user_function> create_func(database& db, cons | |
|
||
auto arg_names = get_list<sstring>(row, "argument_names"); | ||
auto body = row.get_nonnull<sstring>("body"); | ||
lua::runtime_config cfg = lua::make_runtime_config(db.get_config()); | ||
auto bitcode = lua::compile(cfg, arg_names, body); | ||
auto language = row.get_nonnull<sstring>("language"); | ||
if (language == "lua") { | ||
lua::runtime_config cfg = lua::make_runtime_config(db.get_config()); | ||
cql3::functions::user_function::context ctx = cql3::functions::user_function::lua_context { | ||
.bitcode = lua::compile(cfg, arg_names, body), | ||
.cfg = cfg, | ||
}; | ||
|
||
return ::make_shared<cql3::functions::user_function>(std::move(name), std::move(arg_types), std::move(arg_names), | ||
std::move(body), row.get_nonnull<sstring>("language"), std::move(return_type), | ||
row.get_nonnull<bool>("called_on_null_input"), std::move(bitcode), std::move(cfg)); | ||
return ::make_shared<cql3::functions::user_function>(std::move(name), std::move(arg_types), std::move(arg_names), | ||
std::move(body), language, std::move(return_type), | ||
row.get_nonnull<bool>("called_on_null_input"), std::move(ctx)); | ||
} else if (language == "xwasm") { | ||
wasm::context ctx{db.wasm_engine(), name.name}; | ||
wasm::compile(ctx, arg_names, body); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it seems we have two functions checking if language=="lua" or "wasm" and compiling things, and a third place checking if it is neither and printing an error... Could we create just one function that does this, and all three locations will call it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could have a scripting_engine class and derive lua_scripting_engine and wasm_scripting_engine. But I'm fine with waiting a bit to understand what that class wants to look like first. |
||
return ::make_shared<cql3::functions::user_function>(std::move(name), std::move(arg_types), std::move(arg_names), | ||
std::move(body), language, std::move(return_type), | ||
row.get_nonnull<bool>("called_on_null_input"), std::move(ctx)); | ||
} else { | ||
throw std::runtime_error(format("Unsupported language for UDF: {}", language)); | ||
} | ||
} | ||
|
||
static shared_ptr<cql3::functions::user_aggregate> create_aggregate(database& db, const query::result_set_row& row) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: why an old-style C pointer instead of some C++ type like unique_ptr or shared_ptr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a non-owning pointer. I don't want the database to be the owner of this wasm engine in order to not make it a hard dependency. Instead, if the programmer is interested in providing the wasm engine, he can do so with a simple setter method.