bugfix : dot notation input with *

This commit is contained in:
obdev
2023-02-24 15:33:31 +00:00
committed by ob-robot
parent 80ac15ef69
commit a10ab13369
4 changed files with 60 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -1100,6 +1100,7 @@ DEFINE_ORACLE_ERROR(OB_ERR_INVALID_DEFAULT_VALUE_PROVIDED, -5486, -1, "42000", "
DEFINE_ORACLE_ERROR(OB_ERR_PATH_EXPRESSION_NOT_LITERAL, -5487, -1, "42000", "path expression not a literal", 40454, "path expression not a literal");
DEFINE_PLS_ERROR_EXT(OB_ERR_INVALID_ARGUMENT_FOR_JSON_CALL, -5488, -1, "HY000", "invalid argument for JSON call", "invalid argument for %s call", 185, "invalid argument for JSON call", "invalid argument for %s call");
DEFINE_ERROR(OB_ERR_SCHEMA_HISTORY_EMPTY, -5489, -1, "HY000", "Schema history is empty");
DEFINE_ORACLE_ERROR(OB_ERR_TABLE_NAME_NOT_IN_LIST, -5490, -1, "42000", "table name not in FROM list", 964, "table name not in FROM list"));
DEFINE_ERROR_EXT(OB_ERR_SP_ALREADY_EXISTS, -5541, ER_SP_ALREADY_EXISTS, "42000", "procedure/function already exists", "%s %.*s already exists");

View File

@ -824,6 +824,7 @@ constexpr int OB_ERR_INVALID_DEFAULT_VALUE_PROVIDED = -5486;
constexpr int OB_ERR_PATH_EXPRESSION_NOT_LITERAL = -5487;
constexpr int OB_ERR_INVALID_ARGUMENT_FOR_JSON_CALL = -5488;
constexpr int OB_ERR_SCHEMA_HISTORY_EMPTY = -5489;
constexpr int OB_ERR_TABLE_NAME_NOT_IN_LIST = -5490;
constexpr int OB_ERR_SP_ALREADY_EXISTS = -5541;
constexpr int OB_ERR_SP_DOES_NOT_EXIST = -5542;
constexpr int OB_ERR_SP_UNDECLARED_VAR = -5543;
@ -2685,6 +2686,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
#define OB_ERR_PATH_EXPRESSION_NOT_LITERAL__USER_ERROR_MSG "path expression not a literal"
#define OB_ERR_INVALID_ARGUMENT_FOR_JSON_CALL__USER_ERROR_MSG "invalid argument for %s call"
#define OB_ERR_SCHEMA_HISTORY_EMPTY__USER_ERROR_MSG "Schema history is empty"
#define OB_ERR_TABLE_NAME_NOT_IN_LIST__USER_ERROR_MSG "table name not in FROM list"
#define OB_ERR_SP_ALREADY_EXISTS__USER_ERROR_MSG "%s %.*s already exists"
#define OB_ERR_SP_DOES_NOT_EXIST__USER_ERROR_MSG "%s %.*s.%.*s does not exist"
#define OB_ERR_SP_UNDECLARED_VAR__USER_ERROR_MSG "Undeclared variable: %.*s"
@ -4711,6 +4713,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
#define OB_ERR_PATH_EXPRESSION_NOT_LITERAL__ORA_USER_ERROR_MSG "ORA-40454: path expression not a literal"
#define OB_ERR_INVALID_ARGUMENT_FOR_JSON_CALL__ORA_USER_ERROR_MSG "PLS-00185: invalid argument for %s call"
#define OB_ERR_SCHEMA_HISTORY_EMPTY__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5489, Schema history is empty"
#define OB_ERR_TABLE_NAME_NOT_IN_LIST__ORA_USER_ERROR_MSG "ORA-00964: table name not in FROM list"
#define OB_ERR_SP_ALREADY_EXISTS__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5541, %s %.*s already exists"
#define OB_ERR_SP_DOES_NOT_EXIST__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5542, %s %.*s.%.*s does not exist"
#define OB_ERR_SP_UNDECLARED_VAR__ORA_USER_ERROR_MSG "PLS-00201: identifier '%.*s' must be declared"
@ -5746,7 +5749,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
#define OB_ERR_DATA_TOO_LONG_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-12899: value too large for column %.*s (actual: %ld, maximum: %ld)"
#define OB_ERR_INVALID_DATE_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-01861: Incorrect datetime value for column '%.*s' at row %ld"
extern int g_all_ob_errnos[2022];
extern int g_all_ob_errnos[2023];
const char *ob_error_name(const int oberr);
const char* ob_error_cause(const int oberr);

View File

@ -2491,6 +2491,7 @@ int ObSelectResolver::resolve_star(const ParseNode *node)
{
int ret = OB_SUCCESS;
ObSelectStmt *select_stmt = get_select_stmt();
const share::schema::ObTableSchema *table_schema = NULL;
if (OB_ISNULL(node) || OB_ISNULL(session_info_)
|| OB_ISNULL(select_stmt) || OB_ISNULL(params_.expr_factory_)) {
@ -2546,6 +2547,9 @@ int ObSelectResolver::resolve_star(const ParseNode *node)
}
} else if (node->type_ == T_COLUMN_REF && node->children_[2]->type_ == T_STAR) {
ObQualifiedName column_ref;
bool is_json_wildcard_column = false; // special input : tab_name.column_name.*
bool is_column_name_equal = false;
const TableItem* tab_item = NULL;
ObNameCaseMode case_mode = OB_NAME_CASE_INVALID;
if (OB_FAIL(session_info_->get_name_case_mode(case_mode))) {
LOG_WARN("fail to get name case mode", K(ret));
@ -2558,30 +2562,57 @@ int ObSelectResolver::resolve_star(const ParseNode *node)
column_ref.tbl_name_, table_items))) {
LOG_WARN("get all matched table failed", K(ret));
} else if (table_items.count() <= 0) {
ret = OB_SUCCESS;
ObString db_name;
if (lib::is_oracle_mode() && OB_FAIL(select_stmt->get_all_table_item_by_tname(session_info_, db_name,
column_ref.database_name_, table_items))) {
LOG_WARN("get all matched table failed", K(ret));
} else if (lib::is_mysql_mode() || table_items.count() <= 0) {
ret = OB_ERR_BAD_TABLE;
} else {
is_json_wildcard_column = true;
}
if (ret != 0) { // according to oracle , need cover error code
ret = OB_ERR_BAD_TABLE;
ObString table_name = concat_table_name(column_ref.database_name_, column_ref.tbl_name_);
LOG_USER_ERROR(OB_ERR_BAD_TABLE, table_name.length(), table_name.ptr());
}
}
for (int64_t i = 0; OB_SUCC(ret) && i < table_items.count(); ++i) {
target_list.reset();
if (OB_ISNULL(table_items.at(i))) {
tab_item = table_items.at(i);
if (OB_ISNULL(tab_item)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(table_items.at(i)), K(ret));
} else if (OB_FAIL(expand_target_list(*table_items.at(i), target_list))) {
LOG_WARN("resolve table columns failed", K(ret), K(table_items.at(i)), K(i));
LOG_WARN("get unexpected null", K(tab_item), K(ret));
} else if (OB_FAIL(expand_target_list(*tab_item, target_list))) {
LOG_WARN("resolve table columns failed", K(ret), K(tab_item), K(i));
} else if (is_json_wildcard_column) {
if (OB_FAIL(schema_checker_->get_table_schema(session_info_->get_effective_tenant_id(), tab_item->ref_id_, table_schema))) {
ret = OB_TABLE_NOT_EXIST;
LOG_WARN("get table schema failed", K_(tab_item->table_name), K(tab_item->ref_id_), K(ret));
} else if (OB_ISNULL(table_schema)) {
ret = OB_TABLE_NOT_EXIST;
LOG_WARN("get table schema failed", K_(tab_item->table_name), K(tab_item->ref_id_), K(ret));
} else if (OB_NOT_NULL(table_schema->get_column_schema(column_ref.tbl_name_))
&& !table_schema->get_column_schema(column_ref.tbl_name_)->is_json()) {
ret = OB_ERR_TABLE_NAME_NOT_IN_LIST;
LOG_WARN("table name not in from list", K(ret), K(column_ref.tbl_name_));
}
}
for (int64_t j = 0; OB_SUCC(ret) && j < target_list.count(); ++j) {
if (OB_FAIL(select_stmt->add_select_item(target_list.at(j)))) {
is_column_name_equal = is_json_wildcard_column & (0 != column_ref.tbl_name_.case_compare(target_list.at(j).alias_name_));
if (!is_column_name_equal && OB_FAIL(select_stmt->add_select_item(target_list.at(j)))) {
LOG_WARN("add select item to select stmt failed", K(ret));
} else if (is_only_full_group_by_on(session_info_->get_sql_mode())) {
//如果是only full group by,所有target list中的列都必须检查是否满足group约束
if (OB_FAIL(standard_group_checker_.add_unsettled_column(target_list.at(j).expr_))) {
if (is_column_name_equal) { // target column not equal with current column without judge
} else if (OB_FAIL(standard_group_checker_.add_unsettled_column(target_list.at(j).expr_))) {
LOG_WARN("add unsettled column failed", K(ret));
} else if (OB_FAIL(standard_group_checker_.add_unsettled_expr(target_list.at(j).expr_))) {
LOG_WARN("add unsettled expr to standard group checker failed", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_SUCC(ret) && !is_column_name_equal) {
ret = column_namespace_checker_.check_column_existence_in_using_clause(
table_items.at(i)->table_id_, target_list.at(j).expr_name_);
}