[CP] bugfix select column_default value from information_schema.columns core

This commit is contained in:
obdev
2024-02-07 11:31:01 +00:00
committed by ob-robot
parent f94c982ed9
commit 080c1da397
3 changed files with 63 additions and 7 deletions

View File

@ -19,6 +19,7 @@
#include "lib/geo/ob_geo_utils.h"
#include "share/schema/ob_schema_getter_guard.h"
#include "share/inner_table/ob_inner_table_schema.h"
#include "share/ob_lob_access_utils.h"
#include "sql/session/ob_sql_session_info.h"
#include "sql/parser/ob_parser.h"
#include "sql/resolver/dml/ob_select_resolver.h"
@ -536,19 +537,25 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const ObString &database_name,
}
case COLUMN_DEFAULT: {
casted_cell.reset();
cells[cell_idx].reset();
const ObObj *res_cell = NULL;
ObObj def_obj = column_schema->get_cur_default_value();
ObObjType column_type = ObMaxType;
const ObColumnSchemaV2 *tmp_column_schema = NULL;
if (OB_ISNULL(table_schema_) ||
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id))) {
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id)) ||
OB_ISNULL(allocator_)) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "table or column schema is null", KR(ret), KP(table_schema_), KP(tmp_column_schema));
SERVER_LOG(WARN, "table or column schema or or allocator is null", KR(ret), KP(table_schema_), KP(tmp_column_schema), KP(allocator_));
} else if (FALSE_IT(column_type = tmp_column_schema->get_meta_type().get_type())) {
} else if (IS_DEFAULT_NOW_OBJ(def_obj)) {
ObObj def_now_obj;
def_now_obj.set_string(column_type, ObString::make_string(N_UPPERCASE_CUR_TIMESTAMP));
cells[cell_idx] = def_now_obj;
if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(def_now_obj, *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(def_now_obj));
} else {
cells[cell_idx] = def_now_obj;
}
} else if (def_obj.is_bit() || ob_is_enum_or_set_type(def_obj.get_type())) {
char *buf = NULL;
int64_t buf_len = number::ObNumber::MAX_PRINTABLE_SIZE;
@ -569,6 +576,10 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const ObString &database_name,
cells[cell_idx].set_string(column_type, ObString(static_cast<int32_t>(pos), buf));
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(cells[cell_idx], *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(cells[cell_idx]));
}
} else {
if (OB_FAIL(ObObjCaster::to_type(column_type, cast_ctx,
def_obj,
@ -977,21 +988,27 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const common::ObString &database_na
}
case COLUMN_DEFAULT: {
casted_cell.reset();
cells[cell_idx].reset();
const ObObj *res_cell = NULL;
ColumnItem column_item;
ObObjType column_type = ObMaxType;
const ObColumnSchemaV2 *tmp_column_schema = NULL;
if (OB_ISNULL(table_schema_) ||
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id))) {
OB_ISNULL(tmp_column_schema = table_schema_->get_column_schema(col_id)) ||
OB_ISNULL(allocator_)) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "table or column schema is null", KR(ret), KP(table_schema_), KP(tmp_column_schema));
SERVER_LOG(WARN, "table or column schema or allocator is null", KR(ret), KP(table_schema_), KP(tmp_column_schema), KP(allocator_));
} else if (FALSE_IT(column_type = tmp_column_schema->get_meta_type().get_type())) {
} else if (OB_FAIL(ObResolverUtils::resolve_default_value_and_expr_from_select_item(select_item, column_item, select_stmt))) {
SERVER_LOG(WARN, "failed to resolve default value", K(ret));
} else if (IS_DEFAULT_NOW_OBJ(column_item.default_value_)) {
ObObj def_now_obj;
def_now_obj.set_string(column_type, ObString::make_string(N_UPPERCASE_CUR_TIMESTAMP));
cells[cell_idx] = def_now_obj;
if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(def_now_obj, *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(def_now_obj));
} else {
cells[cell_idx] = def_now_obj;
}
} else if (column_item.default_value_.is_bit() || ob_is_enum_or_set_type(column_item.default_value_.get_type())) {
char *buf = NULL;
int64_t buf_len = number::ObNumber::MAX_PRINTABLE_SIZE;
@ -1016,6 +1033,10 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const common::ObString &database_na
cells[cell_idx].set_string(column_type, ObString(static_cast<int32_t>(pos), buf));
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(ObTextStringResult::ob_convert_obj_temporay_lob(cells[cell_idx], *allocator_))) {
SERVER_LOG(WARN, "convert lob type obj fail", K(ret), K(cells[cell_idx]));
}
} else {
if (OB_FAIL(ObObjCaster::to_type(column_type, cast_ctx,
column_item.default_value_,