[FEAT MERGE] OB Support XMLType
Co-authored-by: simonjoylet <simonjoylet@gmail.com>
This commit is contained in:
@ -1088,6 +1088,8 @@ int ObRawExprPrinter::print(ObAggFunRawExpr *expr)
|
||||
SET_SYMBOL_IF_EMPTY("json_arrayagg");
|
||||
case T_FUN_JSON_OBJECTAGG:
|
||||
SET_SYMBOL_IF_EMPTY("json_objectagg");
|
||||
case T_FUN_ORA_XMLAGG:
|
||||
SET_SYMBOL_IF_EMPTY("xmlagg");
|
||||
case T_FUN_PL_AGG_UDF:{
|
||||
if (type == T_FUN_PL_AGG_UDF) {
|
||||
if (OB_ISNULL(expr->get_pl_agg_udf_expr()) ||
|
||||
@ -2514,6 +2516,7 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_FUN_SYS_XMLCAST:
|
||||
case T_FUN_SYS_TREAT:
|
||||
case T_FUN_SYS_CAST: {
|
||||
if (2 != expr->get_param_count()) {
|
||||
@ -2522,10 +2525,11 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr)
|
||||
} else if (expr->has_flag(IS_INNER_ADDED_EXPR)) {
|
||||
PRINT_EXPR(expr->get_param_expr(0));
|
||||
} else {
|
||||
bool is_treat = T_FUN_SYS_TREAT == expr_type;
|
||||
if (OB_SUCC(ret)) {
|
||||
if (is_treat) {
|
||||
if (T_FUN_SYS_TREAT == expr_type) {
|
||||
DATA_PRINTF("treat(");
|
||||
} else if (T_FUN_SYS_XMLCAST == expr_type) {
|
||||
DATA_PRINTF("xmlcast(");
|
||||
} else {
|
||||
DATA_PRINTF("cast(");
|
||||
}
|
||||
@ -3058,6 +3062,36 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_FUN_SYS_XMLPARSE : {
|
||||
if (OB_FAIL(print_xml_parse_expr(expr))) {
|
||||
LOG_WARN("print xml_parse expr failed", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_FUN_SYS_XML_ELEMENT : {
|
||||
if (OB_FAIL(print_xml_element_expr(expr))) {
|
||||
LOG_WARN("print xml_element expr failed", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_FUN_SYS_XML_ATTRIBUTES : {
|
||||
if (OB_FAIL(print_xml_attributes_expr(expr))) {
|
||||
LOG_WARN("print xml_attributes expr failed", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_FUN_ORA_XMLAGG: {
|
||||
if (OB_FAIL(print_xml_agg_expr(expr))) {
|
||||
LOG_WARN("print xml_parse expr failed", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_FUN_SYS_XML_SERIALIZE: {
|
||||
if (OB_FAIL(print_xml_serialize_expr(expr))) {
|
||||
LOG_WARN("print xmlserialize expr failed", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_FUN_SYS_REGEXP_LIKE: {
|
||||
if (OB_UNLIKELY(expr->get_param_count() < 2 || expr->get_param_count() > 3)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -3103,6 +3137,9 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr)
|
||||
func_name = "ora_decode";
|
||||
}
|
||||
}
|
||||
if (T_FUN_SYS_XML_EXTRACT == expr->get_expr_type()) {
|
||||
func_name = "extract";
|
||||
}
|
||||
if (T_FUN_UDF == expr->get_expr_type()) {
|
||||
PRINT_QUOT;
|
||||
DATA_PRINTF("%.*s", LEN_AND_PTR(func_name));
|
||||
@ -4231,5 +4268,325 @@ int ObRawExprPrinter::print_cast_type(ObRawExpr *expr)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRawExprPrinter::print_xml_parse_expr(ObSysFunRawExpr *expr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(4 != expr->get_param_count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected param count of expr to type", K(ret), KPC(expr));
|
||||
} else {
|
||||
DATA_PRINTF("xmlparse(");
|
||||
if (!static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().is_int()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("doc type value isn't int value");
|
||||
} else {
|
||||
int64_t type = static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().get_int();
|
||||
switch (type) {
|
||||
case 0:
|
||||
DATA_PRINTF("DOCUMENT ");
|
||||
break;
|
||||
case 1:
|
||||
DATA_PRINTF("CONTENT ");
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid doc type value", K(type), K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
PRINT_EXPR(expr->get_param_expr(1));
|
||||
if (!static_cast<ObConstRawExpr*>(expr->get_param_expr(2))->get_value().is_int()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("doc type value isn't int value");
|
||||
} else {
|
||||
int64_t format_type = static_cast<ObConstRawExpr*>(expr->get_param_expr(2))->get_value().get_int();
|
||||
switch (format_type) {
|
||||
case 0:
|
||||
// do nothing
|
||||
break;
|
||||
case 1:
|
||||
DATA_PRINTF(" WELLFORMED");
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid format type value", K(format_type), K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
DATA_PRINTF(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRawExprPrinter::print_xml_serialize_expr(ObSysFunRawExpr *expr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(10 != expr->get_param_count())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("unexpected param count of expr", K(ret), KPC(expr));
|
||||
} else {
|
||||
DATA_PRINTF("xmlserialize(");
|
||||
// doc_type
|
||||
if (!static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().is_int()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("doc type value isn't int value");
|
||||
} else {
|
||||
int64_t type = static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().get_int();
|
||||
switch (type) {
|
||||
case 0:
|
||||
DATA_PRINTF("DOCUMENT ");
|
||||
break;
|
||||
case 1:
|
||||
DATA_PRINTF("CONTENT ");
|
||||
break;
|
||||
default:
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid doc type value", K(type), K(ret));
|
||||
}
|
||||
}
|
||||
// value_expr
|
||||
PRINT_EXPR(expr->get_param_expr(1));
|
||||
// [as datatype]
|
||||
if (OB_SUCC(ret)) {
|
||||
DATA_PRINTF(" as ");
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(print_cast_type(expr->get_param_expr(2)))) {
|
||||
LOG_WARN("fail to print cast_type", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
// [encoding charset]
|
||||
if (OB_SUCC(ret)) {
|
||||
ObExprOperatorType expr_type = expr->get_param_expr(3)->get_expr_type();
|
||||
int64_t encoding_opt = static_cast<ObConstRawExpr*>(expr->get_param_expr(3))->get_value().get_int();
|
||||
if (expr_type == T_INT) {
|
||||
if (encoding_opt == 0) {
|
||||
} else if (encoding_opt == 1) {
|
||||
DATA_PRINTF(" encoding ");
|
||||
PRINT_EXPR(expr->get_param_expr(4));
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid encoding opt value", K(encoding_opt), K(ret));
|
||||
}
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid expr type", K(ret), K(expr_type), K(encoding_opt));
|
||||
}
|
||||
}
|
||||
// [version string literal]
|
||||
if (OB_SUCC(ret)) {
|
||||
ObExprOperatorType expr_type = expr->get_param_expr(5)->get_expr_type();
|
||||
int64_t version_opt = static_cast<ObConstRawExpr*>(expr->get_param_expr(5))->get_value().get_int();
|
||||
if (expr_type == T_INT) {
|
||||
if (version_opt == 0) {
|
||||
} else if (version_opt == 1) {
|
||||
DATA_PRINTF(" version ");
|
||||
PRINT_EXPR(expr->get_param_expr(6));
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid version opt value", K(version_opt), K(ret));
|
||||
}
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid expr type", K(ret), K(expr_type), K(version_opt));
|
||||
}
|
||||
}
|
||||
// [indent]
|
||||
if (OB_SUCC(ret)) {
|
||||
ObExprOperatorType expr_type_1 = expr->get_param_expr(7)->get_expr_type();
|
||||
ObExprOperatorType expr_type_2 = expr->get_param_expr(8)->get_expr_type();
|
||||
int64_t indent_type = static_cast<ObConstRawExpr*>(expr->get_param_expr(5))->get_value().get_int();
|
||||
int64_t value = static_cast<ObConstRawExpr*>(expr->get_param_expr(6))->get_value().get_int();
|
||||
if (expr_type_1 == T_INT && expr_type_2 == T_INT) {
|
||||
if (indent_type == 0) {
|
||||
} else if (indent_type == 1) {
|
||||
DATA_PRINTF(" no indent ");
|
||||
} else if (indent_type == 2) {
|
||||
DATA_PRINTF(" indent ");
|
||||
} else if (indent_type == 3) {
|
||||
DATA_PRINTF(" indent size = %ld", value);
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid indent value", K(value), K(ret));
|
||||
}
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid indent type", K(ret), K(expr_type_1), K(expr_type_2));
|
||||
}
|
||||
}
|
||||
|
||||
// [hide|show] defaults
|
||||
if (OB_SUCC(ret)) {
|
||||
ObExprOperatorType expr_type = expr->get_param_expr(9)->get_expr_type();
|
||||
int64_t value = static_cast<ObConstRawExpr*>(expr->get_param_expr(9))->get_value().get_int();
|
||||
if (expr_type == T_INT) {
|
||||
if (value == 0) {
|
||||
} else if (value == 1) {
|
||||
DATA_PRINTF(" hide defaults ");
|
||||
} else if (value == 2) {
|
||||
DATA_PRINTF(" show defaults ");
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid indent value", K(value), K(ret));
|
||||
}
|
||||
} else {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid expr type", K(expr_type), K(ret));
|
||||
}
|
||||
}
|
||||
DATA_PRINTF(")");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObRawExprPrinter::print_xml_element_expr(ObSysFunRawExpr *expr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(3 > expr->get_param_count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected param count of expr", K(ret), KPC(expr));
|
||||
} else {
|
||||
DATA_PRINTF("xmlelement(");
|
||||
if (!static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().is_int()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("doc type value isn't int value");
|
||||
} else {
|
||||
int64_t type = static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().get_int();
|
||||
switch (type) {
|
||||
case 0:
|
||||
DATA_PRINTF("NOENTITYESCAPING ");
|
||||
break;
|
||||
case 1:
|
||||
DATA_PRINTF("ENTITYESCAPING ");
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid doc type value", K(type), K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
int64_t format_type = 0;
|
||||
if (!static_cast<ObConstRawExpr*>(expr->get_param_expr(1))->get_value().is_int()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("doc type value isn't int value");
|
||||
} else {
|
||||
format_type = static_cast<ObConstRawExpr*>(expr->get_param_expr(1))->get_value().get_int();
|
||||
switch (format_type) {
|
||||
case 0:
|
||||
DATA_PRINTF("NAME ");
|
||||
break;
|
||||
case 1:
|
||||
DATA_PRINTF("EVALNAME ");
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid format type value", K(format_type), K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
int64_t cur_pos = *pos_;
|
||||
PRINT_EXPR(expr->get_param_expr(2));
|
||||
int64_t new_pos = *pos_;
|
||||
|
||||
if (OB_SUCC(ret) && format_type == 0) {
|
||||
if (buf_[cur_pos] == '\'') {
|
||||
buf_[cur_pos] = ' ';
|
||||
}
|
||||
if (buf_[new_pos - 1] == '\'') {
|
||||
buf_[new_pos - 1] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 3; i < expr->get_param_count() && OB_SUCC(ret); i++) {
|
||||
DATA_PRINTF(",");
|
||||
PRINT_EXPR(expr->get_param_expr(i));
|
||||
}
|
||||
DATA_PRINTF(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRawExprPrinter::print_xml_agg_expr(ObSysFunRawExpr *expr)
|
||||
{
|
||||
UNUSED(expr);
|
||||
int ret = OB_NOT_IMPLEMENT; // ToDo: @gehao, implement soom later
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRawExprPrinter::print_xml_attributes_expr(ObSysFunRawExpr *expr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(3 > expr->get_param_count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected param count of expr", K(ret), KPC(expr));
|
||||
} else if (OB_UNLIKELY(expr->get_param_count() % 2 != 0)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected param count of expr", K(ret), KPC(expr));
|
||||
} else {
|
||||
DATA_PRINTF("xmlattributes(");
|
||||
if (!static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().is_int()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("doc type value isn't int value");
|
||||
} else {
|
||||
int64_t type = static_cast<ObConstRawExpr*>(expr->get_param_expr(0))->get_value().get_int();
|
||||
switch (type) {
|
||||
case 0:
|
||||
DATA_PRINTF("NOENTITYESCAPING ");
|
||||
break;
|
||||
case 1:
|
||||
DATA_PRINTF("ENTITYESCAPING ");
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid doc type value", K(type), K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
if (!static_cast<ObConstRawExpr*>(expr->get_param_expr(1))->get_value().is_int()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("doc type value isn't int value");
|
||||
} else {
|
||||
int64_t format_type = static_cast<ObConstRawExpr*>(expr->get_param_expr(1))->get_value().get_int();
|
||||
switch (format_type) {
|
||||
case 0:
|
||||
DATA_PRINTF("NOSCHEMACHECK ");
|
||||
break;
|
||||
case 1:
|
||||
DATA_PRINTF("SCHEMACHECK ");
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid format type value", K(format_type), K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
for (int i = 2; i < expr->get_param_count() && OB_SUCC(ret); i += 2) {
|
||||
if (i > 2) {
|
||||
DATA_PRINTF(",");
|
||||
}
|
||||
PRINT_EXPR(expr->get_param_expr(i));
|
||||
ObString attr_key = static_cast<ObConstRawExpr*>(expr->get_param_expr(i + 1))->get_value().get_string();
|
||||
if (!attr_key.empty()) {
|
||||
// While the result obtained during anti-spelling has been parsed,
|
||||
// so adding all double quotes can achieve the desired result
|
||||
DATA_PRINTF(" as \"%.*s\"", LEN_AND_PTR(attr_key));
|
||||
}
|
||||
}
|
||||
DATA_PRINTF(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} //end of namespace sql
|
||||
} //end of namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user