Skip to content

Commit 458231d

Browse files
Merge 2bcc7af into 32ef7a0
2 parents 32ef7a0 + 2bcc7af commit 458231d

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,42 @@ 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+
NYql::IMdbEndpointGenerator::TEndpoint endpoint;
430+
TString aliveHost;
431+
432+
for (const auto& host : databaseInfo.GetMap().at("hosts").GetArraySafe()) {
433+
const auto& hostMap = host.GetMap();
434+
435+
if (hostMap.at("health").GetString() != "ALIVE" || hostMap.at("type").GetString() != "MASTER") {
436+
// Host is not alive or not master, skip it
437+
continue;
438+
}
439+
440+
// If the host is alive, add it to the list of alive hosts
441+
aliveHost = hostMap.at("name").GetString();
442+
break;
443+
}
444+
445+
if (aliveHost == "") {
446+
ythrow TCodeLineException(TIssuesIds::INTERNAL_ERROR) << "No ALIVE Greenplum hosts found";
447+
}
448+
449+
NYql::IMdbEndpointGenerator::TParams params = {
450+
.DatabaseType = NYql::EDatabaseType::Greenplum,
451+
.MdbHost = aliveHost,
452+
.UseTls = useTls,
453+
.Protocol = protocol,
454+
};
455+
456+
endpoint = mdbEndpointGenerator->ToEndpoint(params);
457+
422458
return TDatabaseDescription{"", endpoint.first, endpoint.second, "", useTls};
423459
};
424460
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,38 @@ 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+
}
477509

478510
Y_UNIT_TEST(DataStreams_PermissionDenied) {
479511
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)