-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
[native] Add support for REST based remote function #23568
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -21,8 +21,16 @@ | |
#include "velox/vector/ComplexVector.h" | ||
#include "velox/vector/ConstantVector.h" | ||
#include "velox/vector/FlatVector.h" | ||
#ifdef PRESTO_ENABLE_REMOTE_FUNCTIONS | ||
#include "presto_cpp/main/JsonSignatureParser.h" | ||
#include "velox/expression/FunctionSignature.h" | ||
#include "velox/functions/remote/client/Remote.h" | ||
#endif | ||
|
||
using namespace facebook::velox::core; | ||
#ifdef PRESTO_ENABLE_REMOTE_FUNCTIONS | ||
using facebook::velox::functions::remote::PageFormat; | ||
#endif | ||
using facebook::velox::TypeKind; | ||
|
||
namespace facebook::presto { | ||
|
@@ -127,6 +135,61 @@ std::string getFunctionName(const protocol::SqlFunctionId& functionId) { | |
|
||
} // namespace | ||
|
||
#ifdef PRESTO_ENABLE_REMOTE_FUNCTIONS | ||
TypedExprPtr VeloxExprConverter::registerRestRemoteFunction( | ||
const protocol::RestFunctionHandle& restFunctionHandle, | ||
const std::vector<TypedExprPtr>& args, | ||
const velox::TypePtr& returnType) const { | ||
const auto* systemConfig = SystemConfig::instance(); | ||
|
||
velox::functions::RemoteVectorFunctionMetadata metadata; | ||
const auto& serdeName = systemConfig->remoteFunctionServerSerde(); | ||
if (serdeName == "presto_page") { | ||
metadata.serdeFormat = PageFormat::PRESTO_PAGE; | ||
} else { | ||
VELOX_FAIL( | ||
"presto_page serde is expected by remote function server but got : '{}'", | ||
serdeName); | ||
} | ||
metadata.location = systemConfig->remoteFunctionRestUrl(); | ||
metadata.functionId = restFunctionHandle.functionId; | ||
metadata.version = restFunctionHandle.version; | ||
|
||
const auto& prestoSignature = restFunctionHandle.signature; | ||
velox::exec::FunctionSignatureBuilder signatureBuilder; | ||
|
||
for (const auto& typeVar : prestoSignature.typeVariableConstraints) { | ||
signatureBuilder.typeVariable(typeVar.name); | ||
} | ||
|
||
for (const auto& longVar : prestoSignature.longVariableConstraints) { | ||
signatureBuilder.integerVariable(longVar.name); | ||
} | ||
|
||
signatureBuilder.returnType(prestoSignature.returnType); | ||
|
||
for (const auto& argType : prestoSignature.argumentTypes) { | ||
signatureBuilder.argumentType(argType); | ||
} | ||
|
||
if (prestoSignature.variableArity) { | ||
signatureBuilder.variableArity(); | ||
} | ||
|
||
auto signature = signatureBuilder.build(); | ||
std::vector<velox::exec::FunctionSignaturePtr> veloxSignatures = {signature}; | ||
|
||
velox::functions::registerRemoteFunction( | ||
getFunctionName(restFunctionHandle.functionId), | ||
veloxSignatures, | ||
metadata, | ||
false); | ||
|
||
return std::make_shared<CallTypedExpr>( | ||
returnType, args, getFunctionName(restFunctionHandle.functionId)); | ||
} | ||
#endif | ||
|
||
velox::variant VeloxExprConverter::getConstantValue( | ||
const velox::TypePtr& type, | ||
const protocol::Block& block) const { | ||
|
@@ -504,10 +567,22 @@ TypedExprPtr VeloxExprConverter::toVeloxExpr( | |
pexpr.functionHandle)) { | ||
auto args = toVeloxExpr(pexpr.arguments); | ||
auto returnType = typeParser_->parse(pexpr.returnType); | ||
|
||
return std::make_shared<CallTypedExpr>( | ||
returnType, args, getFunctionName(sqlFunctionHandle->functionId)); | ||
} | ||
#ifdef PRESTO_ENABLE_REMOTE_FUNCTIONS | ||
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. Can we move this logic to a separate function, say 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. Thanks for the feedback, I have made the improvements |
||
else if ( | ||
auto restFunctionHandle = | ||
std::dynamic_pointer_cast<protocol::RestFunctionHandle>( | ||
pexpr.functionHandle)) { | ||
// Defer to our new helper function for restFunctionHandle. | ||
auto args = toVeloxExpr(pexpr.arguments); | ||
auto returnType = typeParser_->parse(pexpr.returnType); | ||
|
||
return registerRestRemoteFunction(*restFunctionHandle, args, returnType); | ||
} | ||
#endif | ||
VELOX_FAIL("Unsupported function handle: {}", pexpr.functionHandle->_type); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,7 @@ AbstractClasses: | |
- { name: BuiltInFunctionHandle, key: $static } | ||
- { name: SqlFunctionHandle, key: native } | ||
- { name: SqlFunctionHandle, key: json_file } | ||
- { name: RestFunctionHandle, key: rest } | ||
|
||
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. Nit: revert this newline removal. 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. reverted back the changes, Is there a need of two empty line? |
||
|
||
JavaClasses: | ||
|
@@ -192,6 +193,7 @@ JavaClasses: | |
- presto-main/src/main/java/com/facebook/presto/execution/buffer/BufferState.java | ||
- presto-main/src/main/java/com/facebook/presto/metadata/BuiltInFunctionHandle.java | ||
- presto-spi/src/main/java/com/facebook/presto/spi/function/SqlFunctionHandle.java | ||
- presto-spi/src/main/java/com/facebook/presto/spi/function/RestFunctionHandle.java | ||
- presto-hdfs-core/src/main/java/com/facebook/presto/hive/CacheQuotaRequirement.java | ||
- presto-hdfs-core/src/main/java/com/facebook/presto/hive/CacheQuotaScope.java | ||
- presto-spi/src/main/java/com/facebook/presto/spi/relation/CallExpression.java | ||
|
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.
Maybe extract this into a separate function?