-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native] Add native endpoint for Velox plan conversion
This adds an endpoint to the native Presto server that will convert a Presto plan fragment to Velox. If the conversion is successful, the server will send an ok response. If it fails, the server will send an error response with a 422 status code as unprocessable. The error message will contain a PlanConversionFailureInfo struct with error type, code and message. See also #23649 RFC: https://github.com/prestodb/rfcs/blob/main/RFC-0008-plan-checker.md
- Loading branch information
1 parent
49c9b7e
commit 78df0d9
Showing
21 changed files
with
325 additions
and
43 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
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
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
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
77 changes: 77 additions & 0 deletions
77
presto-native-execution/presto_cpp/main/types/VeloxPlanConversion.cpp
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,77 @@ | ||
/* | ||
* 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 "presto_cpp/main/types/VeloxPlanConversion.h" | ||
#include "presto_cpp/main/common/Exception.h" | ||
#include "presto_cpp/main/types/PrestoToVeloxQueryPlan.h" | ||
#include "velox/core/QueryCtx.h" | ||
|
||
using namespace facebook::velox; | ||
|
||
namespace { | ||
|
||
facebook::presto::protocol::PlanConversionFailureInfo copyFailureInfo( | ||
const facebook::presto::protocol::ExecutionFailureInfo& failure) { | ||
facebook::presto::protocol::PlanConversionFailureInfo failureCopy; | ||
failureCopy.type = failure.type; | ||
failureCopy.message = failure.message; | ||
failureCopy.stack = failure.stack; | ||
failureCopy.errorCode = failure.errorCode; | ||
return failureCopy; | ||
} | ||
} // namespace | ||
|
||
namespace facebook::presto { | ||
|
||
protocol::PlanConversionResponse prestoToVeloxPlanConversion( | ||
const std::string& planFragmentJson, | ||
memory::MemoryPool* pool, | ||
const VeloxPlanValidator* planValidator) { | ||
protocol::PlanConversionResponse response; | ||
|
||
try { | ||
protocol::PlanFragment planFragment = json::parse(planFragmentJson); | ||
|
||
auto queryCtx = core::QueryCtx::create(); | ||
VeloxInteractiveQueryPlanConverter converter(queryCtx.get(), pool); | ||
|
||
// Create a taskId and empty TableWriteInfo needed for plan conversion. | ||
protocol::TaskId taskId = "velox-plan-conversion.0.0.0.0"; | ||
auto tableWriteInfo = std::make_shared<protocol::TableWriteInfo>(); | ||
|
||
// Attempt to convert the plan fragment to a Velox plan. | ||
if (auto writeNode = | ||
std::dynamic_pointer_cast<const protocol::TableWriterNode>( | ||
planFragment.root)) { | ||
// TableWriteInfo is not yet built at the planning stage, so we can not | ||
// fully convert a TableWriteNode and skip that node of the fragment. | ||
auto writeSourceNode = | ||
converter.toVeloxQueryPlan(writeNode->source, tableWriteInfo, taskId); | ||
planValidator->validatePlanFragment(core::PlanFragment(writeSourceNode)); | ||
} else { | ||
auto veloxPlan = | ||
converter.toVeloxQueryPlan(planFragment, tableWriteInfo, taskId); | ||
planValidator->validatePlanFragment(veloxPlan); | ||
} | ||
} catch (const VeloxException& e) { | ||
response.failures.emplace_back( | ||
copyFailureInfo(VeloxToPrestoExceptionTranslator::translate(e))); | ||
} catch (const std::exception& e) { | ||
response.failures.emplace_back( | ||
copyFailureInfo(VeloxToPrestoExceptionTranslator::translate(e))); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
} // namespace facebook::presto |
32 changes: 32 additions & 0 deletions
32
presto-native-execution/presto_cpp/main/types/VeloxPlanConversion.h
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,32 @@ | ||
/* | ||
* 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 "presto_cpp/main/types/VeloxPlanValidator.h" | ||
#include "presto_cpp/presto_protocol/core/presto_protocol_core.h" | ||
#include "velox/common/memory/MemoryPool.h" | ||
|
||
namespace facebook::presto { | ||
|
||
/// Convert a Presto plan fragment to a Velox Plan. If the conversion fails, | ||
/// the failure info will be included in the response. | ||
/// @param planFragmentJson string that will parse as protocol::PlanFragment. | ||
/// @param pool MemoryPool used during conversion. | ||
/// @param planValidator VeloxPlanValidator to validate the converted plan. | ||
protocol::PlanConversionResponse prestoToVeloxPlanConversion( | ||
const std::string& planFragmentJson, | ||
velox::memory::MemoryPool* pool, | ||
const VeloxPlanValidator* planValidator); | ||
|
||
} // namespace facebook::presto |
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
Oops, something went wrong.