diff --git a/src/sql/engine/table/ob_external_table_access_service.cpp b/src/sql/engine/table/ob_external_table_access_service.cpp index f5f46e86a9..37a2025eaf 100644 --- a/src/sql/engine/table/ob_external_table_access_service.cpp +++ b/src/sql/engine/table/ob_external_table_access_service.cpp @@ -24,6 +24,10 @@ namespace oceanbase { +namespace common { +extern const char *OB_STORAGE_ACCESS_TYPES_STR[]; +} + using namespace share::schema; using namespace common; using namespace share; @@ -243,16 +247,6 @@ int ObExternalDataAccessDriver::get_file_list(const ObString &path, LOG_WARN("ObExternalDataAccessDriver not init", K(ret)); } else if (!pattern.empty() && OB_FAIL(filter.init(pattern, regexp_vars))) { LOG_WARN("fail to init filter", K(ret)); - } else if (get_storage_type() == OB_STORAGE_OSS - || get_storage_type() == OB_STORAGE_COS) { - ObExternalFileListArrayOpWithFilter file_op(file_urls, pattern.empty() ? NULL : &filter, allocator); - if (OB_FAIL(device_handle_->scan_dir(to_cstring(path), file_op))) { - LOG_WARN("scan dir failed", K(ret)); - if (get_storage_type() == OB_STORAGE_OSS) { - ret = OB_OSS_ERROR; - LOG_WARN("scan oss dir failed", K(ret)); - } - } } else if (get_storage_type() == OB_STORAGE_FILE) { ObSEArray file_dirs; bool is_dir = false; @@ -281,23 +275,11 @@ int ObExternalDataAccessDriver::get_file_list(const ObString &path, LOG_WARN("too many files and dirs to visit", K(ret)); } } - } - return ret; -} - -int ObExternalDataAccessDriver::resolve_storage_type(const ObString &location, ObStorageType &device_type) -{ - int ret = OB_SUCCESS; - - if (location.prefix_match_ci(OB_OSS_PREFIX)) { - device_type = OB_STORAGE_OSS; - } else if (location.prefix_match_ci(OB_COS_PREFIX)) { - device_type = OB_STORAGE_COS; - } else if (location.prefix_match_ci(OB_FILE_PREFIX)) { - device_type = OB_STORAGE_FILE; } else { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("Not supported location type", K(ret), K(location)); + ObExternalFileListArrayOpWithFilter file_op(file_urls, pattern.empty() ? NULL : &filter, allocator); + if (OB_FAIL(device_handle_->scan_dir(to_cstring(path), file_op))) { + LOG_WARN("scan dir failed", K(ret)); + } } return ret; } @@ -314,7 +296,7 @@ int ObExternalDataAccessDriver::init(const ObString &location, const ObString &a iod_opts_.opts_ = opts_; iod_opts_.opt_cnt_ = 0; - if (OB_FAIL(resolve_storage_type(location, device_type))) { + if (OB_FAIL(get_storage_type_from_path(location, device_type))) { LOG_WARN("fail to resove storage type", K(ret)); } else { storage_type_ = device_type; diff --git a/src/sql/engine/table/ob_external_table_access_service.h b/src/sql/engine/table/ob_external_table_access_service.h index af72feb75d..f2b8c75610 100644 --- a/src/sql/engine/table/ob_external_table_access_service.h +++ b/src/sql/engine/table/ob_external_table_access_service.h @@ -49,7 +49,6 @@ public: const ObExprRegexpSessionVariables ®exp_vars, common::ObIArray &file_urls, common::ObIAllocator &allocator); - static int resolve_storage_type(const ObString &location, common::ObStorageType &device_type); common::ObStorageType get_storage_type() { return storage_type_; } void close(); diff --git a/src/sql/ob_sql_utils.cpp b/src/sql/ob_sql_utils.cpp index 62d620ba42..f6987a4f45 100644 --- a/src/sql/ob_sql_utils.cpp +++ b/src/sql/ob_sql_utils.cpp @@ -5379,8 +5379,7 @@ void ObSQLUtils::adjust_time_by_ntp_offset(int64_t &dst_timeout_ts) bool ObSQLUtils::is_external_files_on_local_disk(const ObString &url) { - return url.prefix_match_ci(OB_FILE_PREFIX) || - (!url.prefix_match_ci(OB_OSS_PREFIX) && !url.prefix_match_ci(OB_COS_PREFIX)); + return url.prefix_match_ci(OB_FILE_PREFIX); } int ObSQLUtils::split_remote_object_storage_url(ObString &url, ObBackupStorageInfo &storage_info) diff --git a/src/sql/resolver/ddl/ob_ddl_resolver.cpp b/src/sql/resolver/ddl/ob_ddl_resolver.cpp index dc4d615f44..cfe0b1284c 100644 --- a/src/sql/resolver/ddl/ob_ddl_resolver.cpp +++ b/src/sql/resolver/ddl/ob_ddl_resolver.cpp @@ -1096,6 +1096,40 @@ int ObDDLResolver::add_storing_column(const ObString &column_name, return ret; } + +int ObDDLResolver::resolve_file_prefix(ObString &url, ObSqlString &prefix_str, common::ObStorageType &device_type) { + int ret = OB_SUCCESS; + ObString tmp_url; + ObArenaAllocator allocator; + OZ (ob_write_string(allocator, url, tmp_url)); + ObCharset::caseup(CS_TYPE_UTF8MB4_GENERAL_CI, tmp_url); + device_type = common::ObStorageType::OB_STORAGE_MAX_TYPE; + ObString tmp_prefix = tmp_url.split_on(':'); + OZ (ob_write_string(allocator, tmp_prefix, tmp_prefix, true)); + if (!tmp_prefix.empty()) { + OZ (get_storage_type_from_name(tmp_prefix.ptr(), device_type)); + } + if (device_type == common::ObStorageType::OB_STORAGE_MAX_TYPE) { + device_type = common::ObStorageType::OB_STORAGE_FILE; + if (url.empty()) { + ret = OB_DIR_NOT_EXIST; + LOG_USER_ERROR(OB_DIR_NOT_EXIST); + } + } else { + const char *ts = get_storage_type_str(device_type); + url += (strlen(ts) + 3); + } + if (OB_SUCC(ret)) { + ObString prefix; + const char *ts = get_storage_type_str(device_type); + CK (params_.allocator_ != NULL); + OZ (ob_write_string(*params_.allocator_, ObString(ts), prefix)); + ObCharset::casedn(CS_TYPE_UTF8MB4_GENERAL_CI, prefix); + OZ (prefix_str.append(prefix)); + OZ (prefix_str.append("://")); + } + return ret; +} int ObDDLResolver::resolve_table_option(const ParseNode *option_node, const bool is_index_option) { int ret = OB_SUCCESS; @@ -2270,30 +2304,11 @@ int ObDDLResolver::resolve_table_option(const ParseNode *option_node, const bool } else { ObString url = ObString(string_node->str_len_, string_node->str_value_).trim_space_only(); ObSqlString tmp_location; + ObSqlString prefix; ObBackupStorageInfo storage_info; char storage_info_buf[OB_MAX_BACKUP_STORAGE_INFO_LENGTH] = { 0 }; - - if (url.prefix_match_ci(OB_OSS_PREFIX)) { - url += strlen(OB_OSS_PREFIX); - storage_info.device_type_ = OB_STORAGE_OSS; - OZ (tmp_location.append(OB_OSS_PREFIX)); - } else if (url.prefix_match_ci(OB_COS_PREFIX)) { - url += strlen(OB_COS_PREFIX); - storage_info.device_type_ = OB_STORAGE_COS; - OZ (tmp_location.append(OB_COS_PREFIX)); - } else if (url.prefix_match_ci(OB_FILE_PREFIX)) { - url += strlen(OB_FILE_PREFIX); - storage_info.device_type_ = OB_STORAGE_FILE; - OZ (tmp_location.append(OB_FILE_PREFIX)); - } else { - storage_info.device_type_ = OB_STORAGE_FILE; - if (url.empty()) { - ret = OB_DIR_NOT_EXIST; - LOG_USER_ERROR(OB_DIR_NOT_EXIST); - } - OZ (tmp_location.append(OB_FILE_PREFIX)); - } - + OZ (resolve_file_prefix(url, prefix, storage_info.device_type_)); + OZ (tmp_location.append(prefix.string())); url = url.trim_space_only(); if (OB_STORAGE_FILE != storage_info.device_type_) { diff --git a/src/sql/resolver/ddl/ob_ddl_resolver.h b/src/sql/resolver/ddl/ob_ddl_resolver.h index 3986fe9cc5..5135a953dd 100644 --- a/src/sql/resolver/ddl/ob_ddl_resolver.h +++ b/src/sql/resolver/ddl/ob_ddl_resolver.h @@ -573,6 +573,7 @@ protected: const bool is_create_table_as = false, const bool is_external_table = false, const bool allow_has_default = true); + int resolve_file_prefix(ObString &url, ObSqlString &prefix_str, common::ObStorageType &device_type); int resolve_uk_name_from_column_attribute( ParseNode *attrs_node, common::ObString &uk_name);