Skip to content

YDB FQ: support Oracle as an external data source #6723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9 changes: 7 additions & 2 deletions ydb/core/external_sources/external_data_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct TExternalDataSource : public IExternalSource {
}

bool IsRDBMSDataSource(const TProtoStringType& sourceType) const {
return IsIn({"Greenplum", "PostgreSQL", "MySQL", "MsSQLServer", "Clickhouse"}, sourceType);
return IsIn({"Greenplum", "PostgreSQL", "MySQL", "MsSQLServer", "ClickHouse", "Oracle"}, sourceType);
}

virtual void ValidateExternalDataSource(const TString& externalDataSourceDescription) const override {
Expand All @@ -53,10 +53,15 @@ struct TExternalDataSource : public IExternalSource {
ythrow TExternalSourceException() << "Unsupported property: " << key;
}

if (IsRDBMSDataSource(proto.GetSourceType()) && !proto.GetProperties().GetProperties().contains("database_name")){
if (IsRDBMSDataSource(proto.GetSourceType()) && !proto.GetProperties().GetProperties().contains("database_name")) {
ythrow TExternalSourceException() << proto.GetSourceType() << " source must provide database_name";
}

// oracle must have property service_name
if (proto.GetSourceType() == "Oracle" && !proto.GetProperties().GetProperties().contains("service_name")) {
ythrow TExternalSourceException() << proto.GetSourceType() << " source must provide service_name";
}

ValidateHostname(HostnamePatterns, proto.GetLocation());
}

Expand Down
4 changes: 4 additions & 0 deletions ydb/core/external_sources/external_source_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ IExternalSourceFactory::TPtr CreateExternalSourceFactory(const std::vector<TStri
{
ToString(NYql::EDatabaseType::MsSQLServer),
CreateExternalDataSource(TString{NYql::GenericProviderName}, {"BASIC"}, {"database_name", "use_tls"}, hostnamePatternsRegEx)
},
{
ToString(NYql::EDatabaseType::Oracle),
CreateExternalDataSource(TString{NYql::GenericProviderName}, {"BASIC"}, {"database_name", "use_tls", "service_name"}, hostnamePatternsRegEx)
}});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void FillCreateExternalDataSourceDesc(NKikimrSchemeOp::TExternalDataSourceDescri
"database_id", // managed YDB
"use_tls",
"schema", // managed PG
"service_name", // oracle
};

for (const auto& property: properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ enum class EDatabaseType {
YT,
MySQL,
Greenplum,
MsSQLServer
MsSQLServer,
Oracle
};

inline EDatabaseType DatabaseTypeFromDataSourceKind(NConnector::NApi::EDataSourceKind dataSourceKind) {
Expand All @@ -34,6 +35,8 @@ inline EDatabaseType DatabaseTypeFromDataSourceKind(NConnector::NApi::EDataSourc
return EDatabaseType::Greenplum;
case NConnector::NApi::EDataSourceKind::MS_SQL_SERVER:
return EDatabaseType::MsSQLServer;
case NConnector::NApi::EDataSourceKind::ORACLE:
return EDatabaseType::Oracle;
default:
ythrow yexception() << "Unknown data source kind: " << NConnector::NApi::EDataSourceKind_Name(dataSourceKind);
}
Expand All @@ -53,6 +56,8 @@ inline NConnector::NApi::EDataSourceKind DatabaseTypeToDataSourceKind(EDatabaseT
return NConnector::NApi::EDataSourceKind::GREENPLUM;
case EDatabaseType::MsSQLServer:
return NConnector::NApi::EDataSourceKind::MS_SQL_SERVER;
case EDatabaseType::Oracle:
return NConnector::NApi::EDataSourceKind::ORACLE;
default:
ythrow yexception() << "Unknown database type: " << ToString(databaseType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace NYql::NDq {
args.MaxKeysInRequest);
};

for (auto& name : {"ClickHouseGeneric", "PostgreSqlGeneric", "YdbGeneric", "MySqlGeneric", "GreenplumGeneric", "MsSQLServerGeneric"}) {
for (auto& name : {"ClickHouseGeneric", "PostgreSqlGeneric", "YdbGeneric", "MySqlGeneric", "GreenplumGeneric", "MsSQLServerGeneric", "OracleGeneric"}) {
factory.RegisterSource<Generic::TSource>(name, readActorFactory);
factory.RegisterLookupSource<Generic::TLookupSource>(name, lookupActorFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ message TDataSourceInstance {
TClickhouseDataSourceOptions ch_options = 8;
TS3DataSourceOptions s3_options = 9;
TGreenplumDataSourceOptions gp_options = 10;
TOracleDataSourceOptions ora_options = 11;
TOracleDataSourceOptions oracle_options = 11;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ namespace NYql {
clusterConfig.mutable_datasourceoptions()->insert({TString("schema"), TString(it->second)});
}

void ParseServiceName(const THashMap<TString, TString>& properties,
NYql::TGenericClusterConfig& clusterConfig) {
auto it = properties.find("service_name");
if (it == properties.cend()) {
return;
}

if (!it->second) {
return;
}

clusterConfig.mutable_datasourceoptions()->insert({TString("service_name"), TString(it->second)});
}

void ParseMdbClusterId(const THashMap<TString, TString>& properties,
NYql::TGenericClusterConfig& clusterConfig) {
auto it = properties.find("mdb_cluster_id");
Expand Down Expand Up @@ -192,7 +206,7 @@ namespace NYql {
NYql::TGenericClusterConfig& clusterConfig) {
using namespace NConnector::NApi;

if (IsIn({EDataSourceKind::GREENPLUM, EDataSourceKind::YDB, EDataSourceKind::MYSQL, EDataSourceKind::MS_SQL_SERVER}, clusterConfig.GetKind())) {
if (IsIn({EDataSourceKind::GREENPLUM, EDataSourceKind::YDB, EDataSourceKind::MYSQL, EDataSourceKind::MS_SQL_SERVER, EDataSourceKind::ORACLE}, clusterConfig.GetKind())) {
clusterConfig.SetProtocol(EProtocol::NATIVE);
return;
}
Expand Down Expand Up @@ -268,6 +282,7 @@ namespace NYql {
ParseUseTLS(properties, clusterConfig);
ParseDatabaseName(properties, clusterConfig);
ParseSchema(properties, clusterConfig);
ParseServiceName(properties, clusterConfig);
ParseMdbClusterId(properties, clusterConfig);
ParseDatabaseId(properties, clusterConfig);
ParseSourceType(properties, clusterConfig);
Expand Down Expand Up @@ -396,6 +411,17 @@ namespace NYql {
}
}

// Oracle:
// * always set service_name for oracle;
if (clusterConfig.GetKind() == NConnector::NApi::ORACLE) {
if (!clusterConfig.GetDataSourceOptions().contains("service_name")) {
return ValidationError(
clusterConfig,
context,
"For Oracle databases you must set service, but you have not set it");
}
}

// check required fields
if (!clusterConfig.GetName()) {
return ValidationError(clusterConfig, context, "empty field 'Name'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace NYql {
return "GreenplumGeneric";
case NYql::NConnector::NApi::MS_SQL_SERVER:
return "MsSQLServerGeneric";
case NYql::NConnector::NApi::ORACLE:
return "OracleGeneric";
default:
ythrow yexception() << "Data source kind is unknown or not specified";
}
Expand Down Expand Up @@ -214,6 +216,9 @@ namespace NYql {
case NConnector::NApi::MS_SQL_SERVER:
properties["SourceType"] = "MsSQLServer";
break;
case NConnector::NApi::ORACLE:
properties["SourceType"] = "Oracle";
break;
case NConnector::NApi::DATA_SOURCE_KIND_UNSPECIFIED:
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ namespace NYql {
request.set_schema(schema);
}

void GetServiceName(NYql::NConnector::NApi::TOracleDataSourceOptions& request, const TGenericClusterConfig& clusterConfig) {
const auto it = clusterConfig.GetDataSourceOptions().find("service_name");
if (it != clusterConfig.GetDataSourceOptions().end()) {
request.set_service_name(it->second);
}
}

void FillDataSourceOptions(NConnector::NApi::TDescribeTableRequest& request, const TGenericClusterConfig& clusterConfig) {
const auto dataSourceKind = clusterConfig.GetKind();
switch (dataSourceKind) {
Expand All @@ -346,6 +353,10 @@ namespace NYql {
auto* options = request.mutable_data_source_instance()->mutable_pg_options();
SetSchema(*options, clusterConfig);
} break;
case NYql::NConnector::NApi::ORACLE: {
auto* options = request.mutable_data_source_instance()->mutable_oracle_options();
GetServiceName(*options, clusterConfig);
} break;

default:
ythrow yexception() << "Unexpected data source kind: '" << NYql::NConnector::NApi::EDataSourceKind_Name(dataSourceKind)
Expand Down
Loading