zeroshade commented on code in PR #3876:
URL: https://github.com/apache/arrow-adbc/pull/3876#discussion_r2677896193
##########
go/adbc/drivermgr/adbc_driver_manager.cc:
##########
@@ -1857,20 +2218,188 @@ AdbcStatusCode
AdbcDriverManagerDatabaseSetInitFunc(struct AdbcDatabase* databas
return ADBC_STATUS_OK;
}
+AdbcStatusCode AdbcFilesystemProfileProvider(const char* profile_name,
+ const char*
additional_search_path_list,
+ struct AdbcConnectionProfile* out,
+ struct AdbcError* error) {
+ if (profile_name == nullptr || strlen(profile_name) == 0) {
+ SetError(error, "Profile name is empty");
+ return ADBC_STATUS_INVALID_ARGUMENT;
+ }
+
+ if (!out) {
+ SetError(error, "Output profile is null");
+ return ADBC_STATUS_INVALID_ARGUMENT;
+ }
+
+ std::memset(out, 0, sizeof(*out));
+ std::filesystem::path profile_path(profile_name);
+ if (profile_path.has_extension()) {
+ if (HasExtension(profile_path, ".toml")) {
+ if (!std::filesystem::exists(profile_path)) {
+ SetError(error, "Profile file does not exist: " +
profile_path.string());
+ return ADBC_STATUS_NOT_FOUND;
+ }
+
+ FilesystemProfile profile;
+ CHECK_STATUS(LoadProfileFile(profile_path, profile, error));
+ FilesystemProfile::populate_connection_profile(std::move(profile), out);
+ return ADBC_STATUS_OK;
+ }
+ }
+
+ if (profile_path.is_absolute()) {
+ profile_path.replace_extension(".toml");
+
+ FilesystemProfile profile;
+ CHECK_STATUS(LoadProfileFile(profile_path, profile, error));
+ FilesystemProfile::populate_connection_profile(std::move(profile), out);
+ return ADBC_STATUS_OK;
+ }
+
+ SearchPaths search_paths =
GetProfileSearchPaths(additional_search_path_list);
+ SearchPaths extra_debug_info;
+ for (const auto& [source, search_path] : search_paths) {
+ if (source == SearchPathSource::kRegistry || source ==
SearchPathSource::kUnset ||
+ source == SearchPathSource::kDoesNotExist ||
+ source == SearchPathSource::kDisabledAtCompileTime ||
+ source == SearchPathSource::kDisabledAtRunTime ||
+ source == SearchPathSource::kOtherError) {
+ continue;
+ }
+
+ std::filesystem::path full_path = search_path / profile_path;
+ full_path.replace_extension(".toml");
+ if (std::filesystem::exists(full_path)) {
+ OwnedError intermediate_error;
+
+ FilesystemProfile profile;
+ auto status = LoadProfileFile(full_path, profile,
&intermediate_error.error);
+ if (status == ADBC_STATUS_OK) {
+ FilesystemProfile::populate_connection_profile(std::move(profile),
out);
+ return ADBC_STATUS_OK;
+ } else if (status == ADBC_STATUS_INVALID_ARGUMENT) {
+ search_paths.insert(search_paths.end(), extra_debug_info.begin(),
+ extra_debug_info.end());
+ if (intermediate_error.error.message) {
+ std::string error_message = intermediate_error.error.message;
+ AddSearchPathsToError(search_paths, SearchPathType::kProfile,
error_message);
+ SetError(error, std::move(error_message));
+ }
+ return status;
+ }
+
+ std::string message = "found ";
+ message += full_path.string();
+ message += " but: ";
+ if (intermediate_error.error.message) {
+ message += intermediate_error.error.message;
+ } else {
+ message += "could not load the profile";
+ }
+ extra_debug_info.emplace_back(SearchPathSource::kOtherError,
std::move(message));
+ }
+ }
+
+ search_paths.insert(search_paths.end(), extra_debug_info.begin(),
+ extra_debug_info.end());
+ std::string error_message = "Profile not found: " +
std::string(profile_name);
+ AddSearchPathsToError(search_paths, SearchPathType::kProfile, error_message);
+ SetError(error, std::move(error_message));
+ return ADBC_STATUS_NOT_FOUND;
+}
+
+struct ProfileGuard {
+ AdbcConnectionProfile& profile;
+ ProfileGuard(AdbcConnectionProfile& profile) : profile(profile) {}
+ ~ProfileGuard() {
+ if (profile.release) {
+ profile.release(&profile);
+ }
+ }
+};
+
+AdbcStatusCode InternalInitializeProfile(TempDatabase* args,
+ const std::string_view profile,
+ struct AdbcError* error) {
+ if (!args->profile_provider) {
+ args->profile_provider = AdbcFilesystemProfileProvider;
+ }
+
+ AdbcConnectionProfile connection_profile;
Review Comment:
possibly, though the default does do a memset but it's better to zero it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]