Skip to content

Commit ac40d91

Browse files
YDB FQ: support Managed Greenplum (#5090)
1 parent 94bdfdb commit ac40d91

File tree

3 files changed

+120
-2
lines changed

3 files changed

+120
-2
lines changed

ydb/core/fq/libs/actors/database_resolver.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,44 @@ class TDatabaseResolver: public TActor<TDatabaseResolver>
419419

420420
endpoint = mdbEndpointGenerator->ToEndpoint(params);
421421

422+
return TDatabaseDescription{"", endpoint.first, endpoint.second, "", useTls};
423+
};
424+
Parsers[NYql::EDatabaseType::Greenplum] = [](
425+
NJson::TJsonValue& databaseInfo,
426+
const NYql::IMdbEndpointGenerator::TPtr& mdbEndpointGenerator,
427+
bool useTls,
428+
NConnector::NApi::EProtocol protocol
429+
) {
430+
NYql::IMdbEndpointGenerator::TEndpoint endpoint;
431+
TString aliveHost;
432+
433+
for (const auto& host : databaseInfo.GetMap().at("hosts").GetArraySafe()) {
434+
const auto& hostMap = host.GetMap();
435+
436+
if (hostMap.at("health").GetString() != "ALIVE"){
437+
// Host is not alive, skip it
438+
continue;
439+
440+
}
441+
442+
// If the host is alive, add it to the list of alive hosts
443+
aliveHost = hostMap.at("name").GetString();
444+
break;
445+
}
446+
447+
if (aliveHost == "") {
448+
ythrow TCodeLineException(TIssuesIds::INTERNAL_ERROR) << "No ALIVE Greenplum hosts found";
449+
}
450+
451+
NYql::IMdbEndpointGenerator::TParams params = {
452+
.DatabaseType = NYql::EDatabaseType::Greenplum,
453+
.MdbHost = aliveHost,
454+
.UseTls = useTls,
455+
.Protocol = protocol,
456+
};
457+
458+
endpoint = mdbEndpointGenerator->ToEndpoint(params);
459+
422460
return TDatabaseDescription{"", endpoint.first, endpoint.second, "", useTls};
423461
};
424462
}
@@ -500,13 +538,20 @@ class TDatabaseResolver: public TActor<TDatabaseResolver>
500538
url = TUrlBuilder(ev->Get()->YdbMvpEndpoint + "/database")
501539
.AddUrlParam("databaseId", databaseId)
502540
.Build();
503-
} else if (IsIn({NYql::EDatabaseType::ClickHouse, NYql::EDatabaseType::PostgreSQL }, databaseType)) {
541+
} else if (IsIn({NYql::EDatabaseType::ClickHouse, NYql::EDatabaseType::PostgreSQL}, databaseType)) {
504542
YQL_ENSURE(ev->Get()->MdbGateway, "empty MDB Gateway");
505543
url = TUrlBuilder(
506544
ev->Get()->MdbGateway + "/managed-" + NYql::DatabaseTypeLowercase(databaseType) + "/v1/clusters/")
507545
.AddPathComponent(databaseId)
508546
.AddPathComponent("hosts")
509547
.Build();
548+
} else if (NYql::EDatabaseType::Greenplum == databaseType) {
549+
YQL_ENSURE(ev->Get()->MdbGateway, "empty MDB Gateway");
550+
url = TUrlBuilder(
551+
ev->Get()->MdbGateway + "/managed-" + NYql::DatabaseTypeLowercase(databaseType) + "/v1/clusters/")
552+
.AddPathComponent(databaseId)
553+
.AddPathComponent("master-hosts")
554+
.Build();
510555
}
511556

512557
NHttp::THttpOutgoingRequestPtr httpRequest = NHttp::THttpOutgoingRequest::CreateRequestGet(url);

ydb/core/fq/libs/actors/ut/database_resolver_ut.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,69 @@ Y_UNIT_TEST_SUITE(TDatabaseResolverTests) {
474474
issues
475475
);
476476
}
477+
Y_UNIT_TEST(Greenplum_MasterNode) {
478+
Test(
479+
NYql::EDatabaseType::Greenplum,
480+
NYql::NConnector::NApi::EProtocol::NATIVE,
481+
"https://mdb.api.cloud.yandex.net:443/managed-greenplum/v1/clusters/etn021us5r9rhld1vgbh/master-hosts",
482+
"200",
483+
R"({
484+
"hosts": [
485+
{
486+
"resources": {
487+
"resourcePresetId": "s3-c8-m32",
488+
"diskSize": "395136991232",
489+
"diskTypeId": "local-ssd"
490+
},
491+
"assignPublicIp": false,
492+
"name": "rc1d-51jc89m9q72vcdkn.mdb.yandexcloud.net",
493+
"clusterId": "c9qfrvbs21vo0a56s5hm",
494+
"zoneId": "ru-central1-d",
495+
"type": "MASTER",
496+
"health": "ALIVE",
497+
"subnetId": "fl8vtt2td9qbtlqdj5ji"
498+
}
499+
]
500+
})",
501+
NYql::TDatabaseResolverResponse::TDatabaseDescription{
502+
TString{""},
503+
TString{"rc1d-51jc89m9q72vcdkn.db.yandex.net"},
504+
6432,
505+
TString(""),
506+
true},
507+
{});
508+
}
509+
510+
Y_UNIT_TEST(Greenplum_PermissionDenied) {
511+
NYql::TIssues issues{
512+
NYql::TIssue(
513+
TStringBuilder{} << MakeErrorPrefix(
514+
"mdb.api.cloud.yandex.net:443",
515+
"/managed-greenplum/v1/clusters/etn021us5r9rhld1vgbh/master-hosts",
516+
"etn021us5r9rhld1vgbh",
517+
NYql::EDatabaseType::Greenplum)
518+
<< NoPermissionStr)};
519+
520+
Test(
521+
NYql::EDatabaseType::Greenplum,
522+
NYql::NConnector::NApi::EProtocol::NATIVE,
523+
"https://mdb.api.cloud.yandex.net:443/managed-greenplum/v1/clusters/etn021us5r9rhld1vgbh/master-hosts",
524+
"403",
525+
R"(
526+
{
527+
"code": 7,
528+
"message": "Permission denied",
529+
"details": [
530+
{
531+
"@type": "type.googleapis.com/google.rpc.RequestInfo",
532+
"requestId": "a943c092-d596-4e0e-ae7b-1f67f9d8164e"
533+
}
534+
]
535+
}
536+
)",
537+
NYql::TDatabaseResolverResponse::TDatabaseDescription{},
538+
issues);
539+
}
477540

478541
Y_UNIT_TEST(DataStreams_PermissionDenied) {
479542
NYql::TIssues issues{

ydb/core/fq/libs/db_id_async_resolver_impl/mdb_endpoint_generator.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace NFq {
1616
// Managed PostgreSQL provides the only port both for secure and insecure connections
1717
constexpr ui32 POSTGRESQL_PORT = 6432;
1818

19+
constexpr ui32 GREENPLUM_PORT = 6432;
20+
1921
// TMdbEndpointGeneratorLegacy implements behavior required by YQL legacy ClickHouse provider
2022
class TMdbEndpointGeneratorLegacy: public NYql::IMdbEndpointGenerator {
2123
TEndpoint ToEndpoint(const NYql::IMdbEndpointGenerator::TParams& params) const override {
@@ -71,7 +73,15 @@ namespace NFq {
7173
case NYql::NConnector::NApi::EProtocol::NATIVE:
7274
return TEndpoint(fixedHost, POSTGRESQL_PORT);
7375
default:
74-
ythrow yexception() << "Unexpected protocol for PostgreSQL: " << NYql::NConnector::NApi::EProtocol_Name(params.Protocol);
76+
ythrow yexception() << "Unexpected protocol for PostgreSQL " << NYql::NConnector::NApi::EProtocol_Name(params.Protocol);
77+
}
78+
case NYql::EDatabaseType::Greenplum:
79+
// https://cloud.yandex.ru/docs/managed-postgresql/operations/connect
80+
switch (params.Protocol) {
81+
case NYql::NConnector::NApi::EProtocol::NATIVE:
82+
return TEndpoint(fixedHost, GREENPLUM_PORT);
83+
default:
84+
ythrow yexception() << "Unexpected protocol for Greenplum: " << NYql::NConnector::NApi::EProtocol_Name(params.Protocol);
7585
}
7686
default:
7787
ythrow yexception() << "Unexpected database type: " << ToString(params.DatabaseType);

0 commit comments

Comments
 (0)