[FEAT MERGE]4_1_sql_feature
Co-authored-by: leslieyuchen <leslieyuchen@gmail.com> Co-authored-by: Charles0429 <xiezhenjiang@gmail.com> Co-authored-by: raywill <hustos@gmail.com>
This commit is contained in:
@ -13,7 +13,6 @@
|
||||
#define USING_LOG_PREFIX SQL
|
||||
#include "sql/ob_insert_stmt_printer.h"
|
||||
#include "sql/ob_sql_context.h"
|
||||
#include "sql/ob_select_stmt_printer.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
@ -29,11 +28,7 @@ void ObInsertStmtPrinter::init(char *buf, int64_t buf_len, int64_t *pos, ObInser
|
||||
int ObInsertStmtPrinter::do_print()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
if (OB_UNLIKELY(!is_inited_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("not inited!", K(ret));
|
||||
} else if (OB_ISNULL(stmt_)) {
|
||||
if (OB_ISNULL(stmt_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("stmt should not be NULL", K(ret));
|
||||
} else {
|
||||
@ -57,12 +52,9 @@ int ObInsertStmtPrinter::print()
|
||||
} else if (OB_UNLIKELY(!stmt_->is_insert_stmt())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("Not a valid insert stmt", K(stmt_->get_stmt_type()),K(ret));
|
||||
} else {
|
||||
const ObInsertStmt *insert_stmt = static_cast<const ObInsertStmt*>(stmt_);
|
||||
if (OB_FAIL(print_basic_stmt())) {
|
||||
LOG_WARN("fail to print basic stmt", K(ret), K(*stmt_));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
} else if (OB_FAIL(print_basic_stmt())) {
|
||||
LOG_WARN("fail to print basic stmt", K(ret), K(*stmt_));
|
||||
} else { /*do nothing*/ }
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -74,6 +66,9 @@ int ObInsertStmtPrinter::print_basic_stmt()
|
||||
if (OB_ISNULL(stmt_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("stmt_ should not be NULL", K(ret));
|
||||
} else if ((print_params_.force_print_cte_ || print_params_.print_with_cte_) &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else if (OB_FAIL(print_insert())) {
|
||||
LOG_WARN("fail to print select", K(ret), K(*stmt_));
|
||||
} else if (OB_FAIL(print_into())) {
|
||||
@ -97,7 +92,12 @@ int ObInsertStmtPrinter::print_insert()
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("stmt_ is NULL or buf_ is NULL or pos_ is NULL", K(ret));
|
||||
} else {
|
||||
DATA_PRINTF("insert ");
|
||||
const ObInsertStmt *insert_stmt = static_cast<const ObInsertStmt*>(stmt_);
|
||||
if (insert_stmt->is_replace()) {
|
||||
DATA_PRINTF("replace ");
|
||||
} else {
|
||||
DATA_PRINTF("insert ");
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(print_hint())) { // hint
|
||||
LOG_WARN("fail to print hint", K(ret), K(*stmt_));
|
||||
@ -136,9 +136,10 @@ int ObInsertStmtPrinter::print_into()
|
||||
// 临时表的隐藏列,不需要print。TODO 将临时表insert改写由resolver转移到改写阶段后,可以去掉本分支
|
||||
LOG_DEBUG("do not print column", K(*column));
|
||||
} else {
|
||||
DATA_PRINTF(" \"");
|
||||
PRINT_QUOT;
|
||||
PRINT_IDENT(column->get_column_name());
|
||||
DATA_PRINTF("\",");
|
||||
PRINT_QUOT;
|
||||
DATA_PRINTF(",");
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -168,14 +169,8 @@ int ObInsertStmtPrinter::print_values()
|
||||
if (OB_ISNULL(view) || OB_ISNULL(sub_select_stmt = view->ref_query_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("sub select stmt is null", K(ret), K(sub_select_stmt));
|
||||
} else {
|
||||
ObSelectStmtPrinter printer(
|
||||
buf_, buf_len_, pos_,
|
||||
static_cast<const ObSelectStmt*>(sub_select_stmt),
|
||||
schema_guard_, print_params_, NULL, false);
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("failed to print sub select printer", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(print_inline_view(sub_select_stmt, false, true))) {
|
||||
LOG_WARN("failed to print subquery", K(ret));
|
||||
}
|
||||
} else {
|
||||
if (insert_stmt->get_values_desc().empty()) {
|
||||
@ -216,31 +211,6 @@ int ObInsertStmtPrinter::print_values()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObInsertStmtPrinter::print_subquery(const ObInsertStmt *insert_stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(insert_stmt)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("insert_stmt is NULL", K(ret), K(insert_stmt));
|
||||
} else {
|
||||
const TableItem *table_item = insert_stmt->get_table_item(insert_stmt->get_table_size() - 1);
|
||||
const ObSelectStmt* sub_select_stmt = NULL;
|
||||
if (OB_ISNULL(table_item) || OB_UNLIKELY(!table_item->is_generated_table()) ||
|
||||
OB_ISNULL(sub_select_stmt = table_item->ref_query_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("sub select stmt is null", K(ret), K(table_item), K(sub_select_stmt));
|
||||
} else {
|
||||
ObSelectStmtPrinter printer(buf_, buf_len_, pos_,
|
||||
static_cast<const ObSelectStmt*>(sub_select_stmt),
|
||||
schema_guard_, print_params_, NULL, false, false, true);
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("failed to print sub select printer", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} //end of namespace sql
|
||||
} //end of namespace oceanbase
|
||||
|
||||
|
||||
Reference in New Issue
Block a user