Skip to content

Commit cc96d0a

Browse files
Rijin-Nashkrisknish112022
authored andcommitted
[native] Add Arrow Flight Connector
The native Arrow Flight connector can be used to connect to any Arrow Flight enabled Data Source. The metadata layer is handled by the Presto coordinator and does not need to be re-implemented in C++. Any Java connector that inherits from `presto-base-arrow-flight` can use this connector as it's counterpart for the Prestissimo layer. Different Arrow-Flight enabled data sources can differ in authentication styles. A plugin-style interface is provided to handle such cases with custom authentication code by extending `arrow_flight::auth::Authenticator`. RFC: https://github.com/prestodb/rfcs/blob/main/RFC-0004-arrow-flight-connector.md#prestissimo-implementation Co-authored-by: Ashwin Kumar <[email protected]> Co-authored-by: Rijin-N <[email protected]> Co-authored-by: Nischay Yadav <[email protected]>
1 parent 83e9709 commit cc96d0a

File tree

68 files changed

+3416
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3416
-70
lines changed

presto-native-execution/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ option(PRESTO_ENABLE_TESTING "Enable tests" ON)
6363

6464
option(PRESTO_ENABLE_JWT "Enable JWT (JSON Web Token) authentication" OFF)
6565

66+
option(PRESTO_ENABLE_ARROW_FLIGHT_CONNECTOR "Enable Arrow Flight connector" OFF)
67+
6668
# Set all Velox options below
6769
add_compile_definitions(FOLLY_HAVE_INT128_T=1)
6870

presto-native-execution/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ follow these steps:
115115
* For development, use `make debug` to build a non-optimized debug version.
116116
* Use `make unittest` to build and run tests.
117117

118+
#### Arrow Flight Connector
119+
To enable Arrow Flight connector support, add to the extra cmake flags:
120+
`EXTRA_CMAKE_FLAGS = -DPRESTO_ENABLE_ARROW_FLIGHT_CONNECTOR=ON`
121+
122+
The Arrow Flight connector requires the Arrow Flight library. You can install this dependency
123+
by running the following script from the `presto/presto-native-execution` directory:
124+
125+
`./scripts/setup-adapters.sh arrow_flight`
126+
118127
### Makefile Targets
119128
A reminder of the available Makefile targets can be obtained using `make help`
120129
```

presto-native-execution/presto_cpp/main/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_subdirectory(types)
1414
add_subdirectory(http)
1515
add_subdirectory(common)
1616
add_subdirectory(thrift)
17+
add_subdirectory(connectors)
1718

1819
add_library(
1920
presto_server_lib
@@ -29,7 +30,6 @@ add_library(
2930
QueryContextManager.cpp
3031
ServerOperation.cpp
3132
SignalHandler.cpp
32-
SystemConnector.cpp
3333
SessionProperties.cpp
3434
TaskManager.cpp
3535
TaskResource.cpp
@@ -48,6 +48,7 @@ target_link_libraries(
4848
presto_common
4949
presto_exception
5050
presto_function_metadata
51+
presto_connector
5152
presto_http
5253
presto_operators
5354
presto_velox_conversion

presto-native-execution/presto_cpp/main/PrestoServer.cpp

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include "presto_cpp/main/PeriodicMemoryChecker.h"
2222
#include "presto_cpp/main/PeriodicTaskManager.h"
2323
#include "presto_cpp/main/SignalHandler.h"
24-
#include "presto_cpp/main/SystemConnector.h"
2524
#include "presto_cpp/main/TaskResource.h"
2625
#include "presto_cpp/main/common/ConfigReader.h"
2726
#include "presto_cpp/main/common/Counters.h"
2827
#include "presto_cpp/main/common/Utils.h"
28+
#include "presto_cpp/main/connectors/Registration.h"
29+
#include "presto_cpp/main/connectors/SystemConnector.h"
2930
#include "presto_cpp/main/http/HttpConstants.h"
3031
#include "presto_cpp/main/http/filters/AccessLogFilter.h"
3132
#include "presto_cpp/main/http/filters/HttpEndpointLatencyFilter.h"
@@ -48,13 +49,11 @@
4849
#include "velox/common/memory/MmapAllocator.h"
4950
#include "velox/common/memory/SharedArbitrator.h"
5051
#include "velox/connectors/Connector.h"
51-
#include "velox/connectors/hive/HiveConnector.h"
5252
#include "velox/connectors/hive/HiveDataSink.h"
5353
#include "velox/connectors/hive/storage_adapters/abfs/RegisterAbfsFileSystem.h"
5454
#include "velox/connectors/hive/storage_adapters/gcs/RegisterGcsFileSystem.h"
5555
#include "velox/connectors/hive/storage_adapters/hdfs/RegisterHdfsFileSystem.h"
5656
#include "velox/connectors/hive/storage_adapters/s3fs/RegisterS3FileSystem.h"
57-
#include "velox/connectors/tpch/TpchConnector.h"
5857
#include "velox/dwio/dwrf/RegisterDwrfReader.h"
5958
#include "velox/dwio/dwrf/RegisterDwrfWriter.h"
6059
#include "velox/dwio/parquet/RegisterParquetReader.h"
@@ -87,7 +86,6 @@ constexpr char const* kHttps = "https";
8786
constexpr char const* kTaskUriFormat =
8887
"{}://{}:{}"; // protocol, address and port
8988
constexpr char const* kConnectorName = "connector.name";
90-
constexpr char const* kHiveHadoop2ConnectorName = "hive-hadoop2";
9189

9290
protocol::NodeState convertNodeState(presto::NodeState nodeState) {
9391
switch (nodeState) {
@@ -253,33 +251,9 @@ void PrestoServer::run() {
253251
registerMemoryArbitrators();
254252
registerShuffleInterfaceFactories();
255253
registerCustomOperators();
256-
registerConnectorFactories();
257-
258-
// Register Velox connector factory for iceberg.
259-
// The iceberg catalog is handled by the hive connector factory.
260-
velox::connector::registerConnectorFactory(
261-
std::make_shared<velox::connector::hive::HiveConnectorFactory>(
262-
"iceberg"));
263-
264-
registerPrestoToVeloxConnector(
265-
std::make_unique<HivePrestoToVeloxConnector>("hive"));
266-
registerPrestoToVeloxConnector(
267-
std::make_unique<HivePrestoToVeloxConnector>("hive-hadoop2"));
268-
registerPrestoToVeloxConnector(
269-
std::make_unique<IcebergPrestoToVeloxConnector>("iceberg"));
270-
registerPrestoToVeloxConnector(
271-
std::make_unique<TpchPrestoToVeloxConnector>("tpch"));
272-
// Presto server uses system catalog or system schema in other catalogs
273-
// in different places in the code. All these resolve to the SystemConnector.
274-
// Depending on where the operator or column is used, different prefixes can
275-
// be used in the naming. So the protocol class is mapped
276-
// to all the different prefixes for System tables/columns.
277-
registerPrestoToVeloxConnector(
278-
std::make_unique<SystemPrestoToVeloxConnector>("$system"));
279-
registerPrestoToVeloxConnector(
280-
std::make_unique<SystemPrestoToVeloxConnector>("system"));
281-
registerPrestoToVeloxConnector(
282-
std::make_unique<SystemPrestoToVeloxConnector>("$system@system"));
254+
255+
// Register Presto connector factories and connectors
256+
presto::registerConnectors();
283257

284258
velox::exec::OutputBufferManager::initialize({});
285259
initializeVeloxMemory();
@@ -1164,24 +1138,6 @@ PrestoServer::getAdditionalHttpServerFilters() {
11641138
return filters;
11651139
}
11661140

1167-
void PrestoServer::registerConnectorFactories() {
1168-
// These checks for connector factories can be removed after we remove the
1169-
// registrations from the Velox library.
1170-
if (!velox::connector::hasConnectorFactory(
1171-
velox::connector::hive::HiveConnectorFactory::kHiveConnectorName)) {
1172-
velox::connector::registerConnectorFactory(
1173-
std::make_shared<velox::connector::hive::HiveConnectorFactory>());
1174-
velox::connector::registerConnectorFactory(
1175-
std::make_shared<velox::connector::hive::HiveConnectorFactory>(
1176-
kHiveHadoop2ConnectorName));
1177-
}
1178-
if (!velox::connector::hasConnectorFactory(
1179-
velox::connector::tpch::TpchConnectorFactory::kTpchConnectorName)) {
1180-
velox::connector::registerConnectorFactory(
1181-
std::make_shared<velox::connector::tpch::TpchConnectorFactory>());
1182-
}
1183-
}
1184-
11851141
std::vector<std::string> PrestoServer::registerConnectors(
11861142
const fs::path& configDirectoryPath) {
11871143
static const std::string kPropertiesExtension = ".properties";

presto-native-execution/presto_cpp/main/PrestoServer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ class PrestoServer {
146146

147147
virtual void unregisterFileReadersAndWriters();
148148

149-
virtual void registerConnectorFactories();
150-
151149
/// Invoked by presto shutdown procedure to unregister connectors.
152150
virtual void unregisterConnectors();
153151

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
add_library(presto_connector Registration.cpp PrestoToVeloxConnector.cpp
13+
SystemConnector.cpp)
14+
15+
if(PRESTO_ENABLE_ARROW_FLIGHT_CONNECTOR)
16+
add_subdirectory(arrow_flight)
17+
target_link_libraries(presto_connector presto_flight_connector)
18+
endif()

presto-native-execution/presto_cpp/main/types/PrestoToVeloxConnector.cpp renamed to presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
* limitations under the License.
1313
*/
1414

15-
#include "presto_cpp/main/types/PrestoToVeloxConnector.h"
15+
#include "presto_cpp/main/connectors/PrestoToVeloxConnector.h"
1616
#include "presto_cpp/presto_protocol/connector/hive/HiveConnectorProtocol.h"
1717
#include "presto_cpp/presto_protocol/connector/iceberg/IcebergConnectorProtocol.h"
1818
#include "presto_cpp/presto_protocol/connector/tpch/TpchConnectorProtocol.h"
1919

20-
#include <velox/type/fbhive/HiveTypeParser.h>
20+
#include <velox/velox/type/fbhive/HiveTypeParser.h>
2121
#include "velox/connectors/hive/HiveConnector.h"
2222
#include "velox/connectors/hive/HiveConnectorSplit.h"
2323
#include "velox/connectors/hive/HiveDataSink.h"

presto-native-execution/presto_cpp/main/types/PrestoToVeloxConnector.h renamed to presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
#pragma once
1515

16-
#include "PrestoToVeloxExpr.h"
16+
#include "presto_cpp/main/types/PrestoToVeloxExpr.h"
1717
#include "presto_cpp/main/types/TypeParser.h"
1818
#include "presto_cpp/presto_protocol/connector/hive/presto_protocol_hive.h"
1919
#include "presto_cpp/presto_protocol/core/ConnectorProtocol.h"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
#include "presto_cpp/main/connectors/Registration.h"
15+
#include "presto_cpp/main/connectors/SystemConnector.h"
16+
17+
#ifdef PRESTO_ENABLE_ARROW_FLIGHT_CONNECTOR
18+
#include "presto_cpp/main/connectors/arrow_flight/ArrowFlightConnector.h"
19+
#include "presto_cpp/main/connectors/arrow_flight/ArrowPrestoToVeloxConnector.h"
20+
#endif
21+
22+
#include "velox/connectors/hive/HiveConnector.h"
23+
#include "velox/connectors/tpch/TpchConnector.h"
24+
25+
namespace facebook::presto {
26+
namespace {
27+
28+
constexpr char const* kHiveHadoop2ConnectorName = "hive-hadoop2";
29+
constexpr char const* kIcebergConnectorName = "iceberg";
30+
31+
void registerConnectorFactories() {
32+
// These checks for connector factories can be removed after we remove the
33+
// registrations from the Velox library.
34+
if (!velox::connector::hasConnectorFactory(
35+
velox::connector::hive::HiveConnectorFactory::kHiveConnectorName)) {
36+
velox::connector::registerConnectorFactory(
37+
std::make_shared<velox::connector::hive::HiveConnectorFactory>());
38+
velox::connector::registerConnectorFactory(
39+
std::make_shared<velox::connector::hive::HiveConnectorFactory>(
40+
kHiveHadoop2ConnectorName));
41+
}
42+
if (!velox::connector::hasConnectorFactory(
43+
velox::connector::tpch::TpchConnectorFactory::kTpchConnectorName)) {
44+
velox::connector::registerConnectorFactory(
45+
std::make_shared<velox::connector::tpch::TpchConnectorFactory>());
46+
}
47+
48+
// Register Velox connector factory for iceberg.
49+
// The iceberg catalog is handled by the hive connector factory.
50+
if (!velox::connector::hasConnectorFactory(kIcebergConnectorName)) {
51+
velox::connector::registerConnectorFactory(
52+
std::make_shared<velox::connector::hive::HiveConnectorFactory>(
53+
kIcebergConnectorName));
54+
}
55+
56+
#ifdef PRESTO_ENABLE_ARROW_FLIGHT_CONNECTOR
57+
if (!velox::connector::hasConnectorFactory(
58+
ArrowFlightConnectorFactory::kArrowFlightConnectorName)) {
59+
velox::connector::registerConnectorFactory(
60+
std::make_shared<ArrowFlightConnectorFactory>());
61+
}
62+
#endif
63+
}
64+
} // namespace
65+
66+
void registerConnectors() {
67+
registerConnectorFactories();
68+
69+
registerPrestoToVeloxConnector(std::make_unique<HivePrestoToVeloxConnector>(
70+
velox::connector::hive::HiveConnectorFactory::kHiveConnectorName));
71+
registerPrestoToVeloxConnector(
72+
std::make_unique<HivePrestoToVeloxConnector>(kHiveHadoop2ConnectorName));
73+
registerPrestoToVeloxConnector(
74+
std::make_unique<IcebergPrestoToVeloxConnector>(kIcebergConnectorName));
75+
registerPrestoToVeloxConnector(std::make_unique<TpchPrestoToVeloxConnector>(
76+
velox::connector::tpch::TpchConnectorFactory::kTpchConnectorName));
77+
78+
// Presto server uses system catalog or system schema in other catalogs
79+
// in different places in the code. All these resolve to the SystemConnector.
80+
// Depending on where the operator or column is used, different prefixes can
81+
// be used in the naming. So the protocol class is mapped
82+
// to all the different prefixes for System tables/columns.
83+
registerPrestoToVeloxConnector(
84+
std::make_unique<SystemPrestoToVeloxConnector>("$system"));
85+
registerPrestoToVeloxConnector(
86+
std::make_unique<SystemPrestoToVeloxConnector>("system"));
87+
registerPrestoToVeloxConnector(
88+
std::make_unique<SystemPrestoToVeloxConnector>("$system@system"));
89+
90+
#ifdef PRESTO_ENABLE_ARROW_FLIGHT_CONNECTOR
91+
registerPrestoToVeloxConnector(std::make_unique<ArrowPrestoToVeloxConnector>(
92+
ArrowFlightConnectorFactory::kArrowFlightConnectorName));
93+
#endif
94+
}
95+
} // namespace facebook::presto
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
#pragma once
15+
16+
namespace facebook::presto {
17+
18+
void registerConnectors();
19+
20+
} // namespace facebook::presto

presto-native-execution/presto_cpp/main/SystemConnector.cpp renamed to presto-native-execution/presto_cpp/main/connectors/SystemConnector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
#include "presto_cpp/main/SystemConnector.h"
14+
#include "presto_cpp/main/connectors/SystemConnector.h"
1515
#include "presto_cpp/main/PrestoTask.h"
1616
#include "presto_cpp/main/TaskManager.h"
1717

presto-native-execution/presto_cpp/main/SystemConnector.h renamed to presto-native-execution/presto_cpp/main/connectors/SystemConnector.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
*/
1414
#pragma once
1515

16-
#include "presto_cpp/main/SystemSplit.h"
17-
#include "presto_cpp/main/types/PrestoToVeloxConnector.h"
16+
#include "presto_cpp/main/connectors/PrestoToVeloxConnector.h"
17+
#include "presto_cpp/main/connectors/SystemSplit.h"
1818

1919
#include "velox/connectors/Connector.h"
2020

2121
namespace facebook::presto {
22-
2322
class TaskManager;
2423

2524
class SystemColumnHandle : public velox::connector::ColumnHandle {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
#include "presto_cpp/main/connectors/arrow_flight/ArrowFlightConfig.h"
15+
16+
namespace facebook::presto {
17+
18+
std::string ArrowFlightConfig::authenticatorName() {
19+
return config_->get<std::string>(kAuthenticatorName, "none");
20+
}
21+
22+
std::optional<std::string> ArrowFlightConfig::defaultServerHostname() {
23+
return static_cast<std::optional<std::string>>(
24+
config_->get<std::string>(kDefaultServerHost));
25+
}
26+
27+
std::optional<uint16_t> ArrowFlightConfig::defaultServerPort() {
28+
return static_cast<std::optional<uint16_t>>(
29+
config_->get<uint16_t>(kDefaultServerPort));
30+
}
31+
32+
bool ArrowFlightConfig::defaultServerSslEnabled() {
33+
return config_->get<bool>(kDefaultServerSslEnabled, false);
34+
}
35+
36+
bool ArrowFlightConfig::serverVerify() {
37+
return config_->get<bool>(kServerVerify, true);
38+
}
39+
40+
std::optional<std::string> ArrowFlightConfig::serverSslCertificate() {
41+
return static_cast<std::optional<std::string>>(
42+
config_->get<std::string>(kServerSslCertificate));
43+
}
44+
45+
} // namespace facebook::presto

0 commit comments

Comments
 (0)