Fix external table bugs
This commit is contained in:
		| @ -329,10 +329,12 @@ int ObDCLResolver::mask_password_for_users(ObIAllocator *allocator, | ||||
|   return ret; | ||||
| } | ||||
|  | ||||
| int ObDCLResolver::mask_password_for_passwd_node(ObIAllocator *allocator, | ||||
| int ObDCLResolver::mask_password_for_passwd_node( | ||||
|     ObIAllocator *allocator, | ||||
|     const common::ObString &src, | ||||
|     const ParseNode *passwd_node, | ||||
|     common::ObString &masked_sql) | ||||
|     common::ObString &masked_sql, | ||||
|     bool skip_enclosed_char) | ||||
| { | ||||
|   int ret = OB_SUCCESS; | ||||
|   const ObString::obstr_size_t src_len = src.length(); | ||||
| @ -351,9 +353,14 @@ int ObDCLResolver::mask_password_for_passwd_node(ObIAllocator *allocator, | ||||
|     ret = OB_SIZE_OVERFLOW; | ||||
|     LOG_WARN("last column overflow", K(src_len), K(passwd_node->stmt_loc_.last_column_), K(ret)); | ||||
|   } else { | ||||
|     uint64_t pwd_len = passwd_node->stmt_loc_.last_column_ - | ||||
|                         passwd_node->stmt_loc_.first_column_ + 1; | ||||
|     MEMSET(tmp_sql.ptr() + passwd_node->stmt_loc_.first_column_, password_mask_, pwd_len); | ||||
|     int64_t start_pos = passwd_node->stmt_loc_.first_column_; | ||||
|     int64_t end_pos = passwd_node->stmt_loc_.last_column_ + 1; | ||||
|     if (skip_enclosed_char && end_pos - start_pos >= 2) { | ||||
|       start_pos += 1; | ||||
|       end_pos -= 1; | ||||
|     } | ||||
|     uint64_t pwd_len = end_pos - start_pos; | ||||
|     MEMSET(tmp_sql.ptr() + start_pos, password_mask_, pwd_len); | ||||
|   } | ||||
|   if (OB_SUCC(ret)) { | ||||
|     masked_sql = tmp_sql; | ||||
| @ -461,4 +468,4 @@ int ObDCLResolver::check_dcl_on_inner_user(const ObItemType &type, | ||||
|     LOG_USER_ERROR(OB_NOT_SUPPORTED, "modify on reserved user"); | ||||
|   } | ||||
|   return ret; | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -28,6 +28,11 @@ public: | ||||
|   virtual ~ObDCLResolver() | ||||
|   { | ||||
|   } | ||||
|   static int mask_password_for_passwd_node(ObIAllocator *allocator, | ||||
|                                            const common::ObString &src, | ||||
|                                            const ParseNode *passwd_node, | ||||
|                                            common::ObString &masked_sql, | ||||
|                                            bool skip_enclosed_char = false); | ||||
| protected: | ||||
|   int check_and_convert_name(common::ObString &db, common::ObString &table); | ||||
|   int check_password_strength(common::ObString &password, common::ObString &user_name); | ||||
| @ -57,10 +62,6 @@ protected: | ||||
|                                      const ParseNode *users, | ||||
|                                      int64_t pwd_idx, | ||||
|                                      common::ObString &masked_sql); | ||||
|   static int mask_password_for_passwd_node(ObIAllocator *allocator, | ||||
|                                            const common::ObString &src, | ||||
|                                            const ParseNode *passwd_node, | ||||
|                                            common::ObString &masked_sql); | ||||
|   enum ObPasswordPolicy {LOW = 0, MEDIUM}; | ||||
|   static const char password_mask_ = '*'; | ||||
| private: | ||||
|  | ||||
| @ -200,6 +200,14 @@ int ObAlterTableResolver::resolve(const ParseNode &parse_tree) | ||||
|     if (OB_SUCC(ret)) { | ||||
|       alter_table_stmt->set_tenant_id(table_schema_->get_tenant_id()); | ||||
|       alter_table_stmt->set_table_id(table_schema_->get_table_id()); | ||||
|       if (table_schema_->is_external_table()) { | ||||
|         ObTableSchema &alter_schema = alter_table_stmt->get_alter_table_schema(); | ||||
|         alter_schema.set_table_type(table_schema_->get_table_type()); | ||||
|         OZ (alter_schema.set_external_file_format(table_schema_->get_external_file_format())); | ||||
|         OZ (alter_schema.set_external_file_location(table_schema_->get_external_file_location())); | ||||
|         OZ (alter_schema.set_external_file_location_access_info(table_schema_->get_external_file_location_access_info())); | ||||
|         OZ (alter_schema.set_external_file_pattern(table_schema_->get_external_file_pattern())); | ||||
|       } | ||||
|     } | ||||
|     //resolve action list | ||||
|     if (OB_SUCCESS == ret && NULL != parse_tree.children_[ACTION_LIST]){ | ||||
|  | ||||
| @ -51,15 +51,18 @@ int ObCreateTableLikeResolver::resolve(const ParseNode &parse_tree) | ||||
|     //resolve temporary option | ||||
|     if (OB_SUCC(ret)) { | ||||
|       if (NULL != parse_tree.children_[0]) { | ||||
|         if (T_TEMPORARY != parse_tree.children_[0]->type_) { | ||||
|         if (T_TEMPORARY == parse_tree.children_[0]->type_) { | ||||
|           is_temporary_table = true; | ||||
|         } else if (T_EXTERNAL == parse_tree.children_[0]->type_) { | ||||
|           ret = OB_NOT_SUPPORTED; | ||||
|           LOG_USER_ERROR(OB_NOT_SUPPORTED, "create external table like"); | ||||
|         } else { | ||||
|           ret = OB_INVALID_ARGUMENT; | ||||
|           SQL_RESV_LOG(WARN, "invalid argument.", | ||||
|                        K(ret), K(parse_tree.children_[0]->type_)); | ||||
|         } else { | ||||
|           is_temporary_table = true; | ||||
|         } | ||||
|       } | ||||
|       if (is_temporary_table) { | ||||
|       if (OB_SUCC(ret) && is_temporary_table) { | ||||
|         char create_host_str[OB_MAX_HOST_NAME_LENGTH]; | ||||
|         MYADDR.ip_port_to_string(create_host_str, OB_MAX_HOST_NAME_LENGTH); | ||||
|         if (OB_ISNULL(allocator_)) { | ||||
|  | ||||
| @ -74,5 +74,33 @@ const ObColumnSchemaV2 *ObCreateTableStmt::get_column_schema(const ObString &col | ||||
|   return create_table_arg_.schema_.get_column_schema(column_name); | ||||
| } | ||||
|  | ||||
| int ObCreateTableStmt::get_first_stmt(ObString &first_stmt) | ||||
| { | ||||
|   int ret = OB_SUCCESS; | ||||
|  | ||||
|   if (EXTERNAL_TABLE == get_table_type()) { | ||||
|     first_stmt = get_masked_sql(); | ||||
|   } else { | ||||
|     if (OB_FAIL(ObStmt::get_first_stmt(first_stmt))) { | ||||
|       LOG_WARN("fail to get first stmt", K(ret)); | ||||
|     } | ||||
|   } | ||||
|   if (OB_SUCC(ret)) { | ||||
|     if (OB_ISNULL(get_query_ctx())) { | ||||
|       ret = OB_ERR_UNEXPECTED; | ||||
|       LOG_WARN("query ctx is null", K(ret)); | ||||
|     } else if (OB_FAIL(ObCharset::charset_convert(allocator_, | ||||
|                                                   first_stmt, | ||||
|                                                   get_query_ctx()->get_sql_stmt_coll_type(), | ||||
|                                                   ObCharset::get_system_collation(), | ||||
|                                                   first_stmt))) { | ||||
|       LOG_WARN("fail to convert charset", K(ret), K(first_stmt), | ||||
|                "stmt collation type", get_query_ctx()->get_sql_stmt_coll_type()); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return ret; | ||||
| } | ||||
|  | ||||
| } // namespace sql | ||||
| } // namespace oceanbase | ||||
|  | ||||
| @ -29,6 +29,7 @@ public: | ||||
|   ObCreateTableStmt(); | ||||
|   virtual ~ObCreateTableStmt(); | ||||
|  | ||||
|   int get_first_stmt(ObString &first_stmt) override; | ||||
|   void set_if_not_exists(const bool if_not_exists); | ||||
|   uint64_t get_table_id() const; | ||||
|   const common::ObString &get_table_name() const; | ||||
| @ -75,6 +76,9 @@ public: | ||||
|   ObSelectStmt *get_view_define() { return view_define_; } | ||||
|   void set_sequence_ddl_arg(const obrpc::ObSequenceDDLArg sequence_ddl_arg); | ||||
|   const obrpc::ObSequenceDDLArg &get_sequence_ddl_arg() const; | ||||
|   void set_masked_sql(const common::ObString &masked_sql) { masked_sql_ = masked_sql; } | ||||
|   common::ObString get_masked_sql() const { return masked_sql_; } | ||||
|   ObTableType get_table_type() const { return create_table_arg_.schema_.get_table_type(); } | ||||
|   INHERIT_TO_STRING_KV("ObTableStmt", ObTableStmt, K_(stmt_type), K_(create_table_arg), K_(index_arg_list)); | ||||
| private: | ||||
|   int set_table_id(ObStmtResolver &ctx, const uint64_t table_id); | ||||
| @ -83,6 +87,7 @@ private: | ||||
|   bool is_view_stmt_; | ||||
|   share::schema::ObStmtNeedPrivs::NeedPrivs view_need_privs_; | ||||
|   common::ObSArray<obrpc::ObCreateIndexArg> index_arg_list_; | ||||
|   common::ObString masked_sql_; | ||||
|   //common::ObSEArray<ObRawExpr *, OB_DEFAULT_ARRAY_SIZE, common::ModulePageAllocator, true> partition_fun_expr_; // for range fun expr | ||||
|   //common::ObSEArray<ObRawExpr *, OB_DEFAULT_ARRAY_SIZE, common::ModulePageAllocator, true> range_values_exprs_; //range partition expr | ||||
|   // for future use: create table xxx as select ...... | ||||
|  | ||||
| @ -39,6 +39,7 @@ | ||||
| #include "sql/optimizer/ob_optimizer_util.h" | ||||
| #include "sql/engine/cmd/ob_load_data_parser.h" | ||||
| #include "sql/resolver/cmd/ob_load_data_stmt.h" | ||||
| #include "sql/resolver/dcl/ob_dcl_resolver.h" | ||||
|  | ||||
| #include "sql/engine/expr/ob_expr_lob_utils.h" | ||||
| namespace oceanbase | ||||
| @ -1946,12 +1947,12 @@ int ObDDLResolver::resolve_table_option(const ParseNode *option_node, const bool | ||||
|       } | ||||
|       case T_EXTERNAL_FILE_LOCATION: { | ||||
|         ParseNode *string_node = NULL; | ||||
|         ObTableSchema *schema = NULL; | ||||
|         if (stmt::T_CREATE_TABLE != stmt_->get_stmt_type()) { | ||||
|           ret = OB_ERR_UNEXPECTED; //TODO-EXTERNAL-TABLE add new error code | ||||
|           ret = OB_ERR_UNEXPECTED; | ||||
|           LOG_WARN("invalid file format option", K(ret)); | ||||
|         } else { | ||||
|           ObCreateTableArg &arg = static_cast<ObCreateTableStmt*>(stmt_)->get_create_table_arg(); | ||||
|           ObCreateTableStmt *create_table_stmt = static_cast<ObCreateTableStmt*>(stmt_); | ||||
|           ObCreateTableArg &arg = create_table_stmt->get_create_table_arg(); | ||||
|           if (!arg.schema_.is_external_table()) { | ||||
|             ret = OB_NOT_SUPPORTED; | ||||
|             LOG_USER_ERROR(OB_NOT_SUPPORTED, "location option"); | ||||
| @ -1995,6 +1996,21 @@ int ObDDLResolver::resolve_table_option(const ParseNode *option_node, const bool | ||||
|             OZ (arg.schema_.set_external_file_location(tmp_location.string())); | ||||
|             OZ (arg.schema_.set_external_file_location_access_info(storage_info_buf)); | ||||
|           } | ||||
|  | ||||
|           if (OB_SUCC(ret)) { | ||||
|             if (OB_ISNULL(params_.session_info_)) { | ||||
|               ret = OB_ERR_UNEXPECTED; | ||||
|             } else { | ||||
|               ObString cur_sql = params_.session_info_->get_current_query_string(); | ||||
|               ObString masked_sql; | ||||
|               if (OB_FAIL(ObDCLResolver::mask_password_for_passwd_node( | ||||
|                             params_.allocator_, cur_sql, string_node, masked_sql, true))) { | ||||
|                 LOG_WARN("fail to gen masked sql", K(ret)); | ||||
|               } else { | ||||
|                 create_table_stmt->set_masked_sql(masked_sql); | ||||
|               } | ||||
|             } | ||||
|           } | ||||
|         } | ||||
|         break; | ||||
|       } | ||||
|  | ||||
| @ -45,8 +45,9 @@ public: | ||||
|   virtual int get_first_stmt(common::ObString &first_stmt); | ||||
|   void set_parallelism(const int64_t parallelism) { parallelism_ = parallelism; } | ||||
|   int64_t &get_parallelism() { return parallelism_; } | ||||
| private: | ||||
| protected: | ||||
|   ObArenaAllocator allocator_; | ||||
| private: | ||||
|   int64_t parallelism_; | ||||
|   DISALLOW_COPY_AND_ASSIGN(ObDDLStmt); | ||||
| }; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 wjhh2008
					wjhh2008