Skip to content

Commit

Permalink
[native] Add row expression optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsatya committed Dec 11, 2024
1 parent 004ee32 commit b244385
Show file tree
Hide file tree
Showing 14 changed files with 1,595 additions and 24 deletions.
2 changes: 2 additions & 0 deletions presto-native-execution/presto_cpp/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_subdirectory(operators)
add_subdirectory(types)
add_subdirectory(http)
add_subdirectory(common)
add_subdirectory(expression)
add_subdirectory(thrift)

add_library(
Expand Down Expand Up @@ -51,6 +52,7 @@ target_link_libraries(
presto_http
presto_operators
presto_velox_conversion
presto_expression_optimizer
velox_aggregates
velox_caching
velox_common_base
Expand Down
20 changes: 20 additions & 0 deletions presto-native-execution/presto_cpp/main/PrestoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,26 @@ void PrestoServer::registerSidecarEndpoints() {
proxygen::ResponseHandler* downstream) {
http::sendOkResponse(downstream, getFunctionsMetadata());
});
rowExpressionOptimizer_ =
std::make_unique<expression::RowExpressionOptimizer>();
httpServer_->registerPost(
"/v1/expressions",
[&](proxygen::HTTPMessage* message,
const std::vector<std::unique_ptr<folly::IOBuf>>& body,
proxygen::ResponseHandler* downstream) {
json::array_t inputRowExpressions =
json::parse(util::extractMessageBody(body));
auto result =
rowExpressionOptimizer_->optimize(message, inputRowExpressions);
if (result.second) {
VELOX_USER_CHECK(
result.first.is_array(),
"Output json should be an array of row expressions");
http::sendOkResponse(downstream, result.first);
} else {
http::sendErrorResponse(downstream, result.first);
}
});
httpServer_->registerPost(
"/v1/velox/plan",
[server = this](
Expand Down
2 changes: 2 additions & 0 deletions presto-native-execution/presto_cpp/main/PrestoServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "presto_cpp/main/PeriodicHeartbeatManager.h"
#include "presto_cpp/main/PrestoExchangeSource.h"
#include "presto_cpp/main/PrestoServerOperations.h"
#include "presto_cpp/main/expression/RowExpressionOptimizer.h"
#include "presto_cpp/main/types/VeloxPlanValidator.h"
#include "velox/common/caching/AsyncDataCache.h"
#include "velox/common/memory/MemoryAllocator.h"
Expand Down Expand Up @@ -288,6 +289,7 @@ class PrestoServer {
std::string address_;
std::string nodeLocation_;
folly::SSLContextPtr sslContext_;
std::unique_ptr<expression::RowExpressionOptimizer> rowExpressionOptimizer_;
};

} // namespace facebook::presto
32 changes: 32 additions & 0 deletions presto-native-execution/presto_cpp/main/expression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.
add_library(presto_expression_optimizer RowExpressionOptimizer.cpp)

target_link_libraries(
presto_expression_optimizer
presto_type_converter
presto_types
presto_protocol
presto_http
velox_coverage_util
velox_parse_expression
velox_parse_parser
velox_presto_serializer
velox_serialization
velox_type_parser
${FOLLY_WITH_DEPENDENCIES})

if(PRESTO_ENABLE_TESTING)
add_subdirectory(tests)
endif()
Loading

0 comments on commit b244385

Please sign in to comment.