Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add expr and fix bugs #198

Closed
wants to merge 1 commit into from
Closed

add expr and fix bugs #198

wants to merge 1 commit into from

Conversation

2149
Copy link
Contributor

@2149 2149 commented Jul 28, 2021

What changes were proposed in this pull request?

add expr:
inet_aton、inet_ntoa、inet6_aton、inet6_ntoa、is_ipv4、 is_ipv6、is_ipv4_mapped、is_ipv6_mapped

fix bugs:
[PASS_BY_VALUE]
src/sql/engine/expr/ob_expr_operator.cpp
[FLOATING_POINT_EQUALITY]
src/sql/engine/expr/ob_expr_mod.cpp
[CHECKED_RETURN]
src/sql/engine/expr/ob_expr_operator.cpp
[UNINIT_CTOR]
src/sql/engine/expr/ob_sql_expression.h
[DEADCODE]
src/sql/engine/expr/ob_expr_operator.cpp

Why are the changes needed?

Will break the compatibility? How if so?

Does this PR introduce any user-facing change?

How was this patch tested?

add test file: test/mysql_test/test_suite/expr/t/expr_inet.test
add result file:test/mysql_test/test_suite/expr/r/mysql/expr_inet.result

Checklist

  • I've run the tests to see all new and existing tests pass.
  • If this Pull Request resolves an issue, I linked to the issue in the text above.
  • I've informed the technical writer about the documentation change if necessary.

src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
@2149 2149 force-pushed the xxl_temp branch 2 times, most recently from bf9747d to bf11551 Compare July 28, 2021 08:18
src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
LOG_WARN("ip format invalid", K(ret));
} else if (dst + 2 > ipv6addr_end) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("ip format invalid", K(ret));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以多打印些有用的信息出来,比如 dst 和 ipv6addr_end,下同。

src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
int ret = OB_SUCCESS;
if (OB_FAIL(expr.eval_param_value(ctx))) {
LOG_WARN("is_ipv6 expr eval param value failed", K(ret));
} else if (ObVarcharType != expr.args_[0]->datum_meta_.type_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObCharType 也设成 0 吗?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 text 数据类型类型也试下?

src/sql/engine/expr/ob_expr_inet.cpp Outdated Show resolved Hide resolved
src/sql/engine/expr/ob_expr_inet.h Outdated Show resolved Hide resolved
@2149 2149 force-pushed the xxl_temp branch 3 times, most recently from 21a310d to 92ad7f4 Compare July 29, 2021 03:33
LOG_WARN("ip format invalid, too short or too long", K(ret), K(len));
} else if (OB_ISNULL(str) || OB_ISNULL(ipv4addr)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("ip str or ipv4addr dst is null", K(ret));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K(str) 和 K(ipv4addr),不然不知道是哪个出错了,下同。

CK(expr.res_buf_len_ >= MAX_IP_ADDR_LENGTH);
if (OB_FAIL(ret)) {
LOG_WARN("result buf size greater than MAX_IP_ADDR_LENGTH", K(ret));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里逻辑还是不对,吞错误码的问题没解决。

CK(expr.res_buf_len_ >= MAX_IP_ADDR_LENGTH);
if (OB_FAIL(ret)) {
} else {
  // xxx
}

LOG_WARN("ip format invalid, end with x:", K(ret), K(i));
} else if (dst + 2 > ipv6addr_end) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("ip format invalid", K(ret), K(i), K(dst - (char *) ipv6addr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这里 K(dst - (char *) ipv6addr) 有点儿奇怪

return ret;
}

int ObExprInetCommon::str_to_ipv6(int len, const char *str, in6_addr *ipv6addr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果接口里从头到尾都只有一种特定的错误码 OB_INVALID_ARGUMENT,其实可以返回 void 类型,然后加一个 bool & is_ip_format_valid 参数记录是否格式非法。尽量不要让上层依赖特定错误码。

LOG_WARN("fail to convert ip to int", K(ret), K(m_text));
}
}
if (OB_INVALID_ARGUMENT == ret) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里别依赖错误码了,还有这段代码是不是应该放到 if (OB_FAIL(ob_inet_aton(expr_datum, m_text))) 的花括号里面?下同。

const char *result = ip_str.ptr();
const char *ip = ip_binary.ptr();
if (OB_ISNULL(ip) || OB_ISNULL(result)) {
is_ip_format_invalid = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

走到这里是因为 ip_format_invalid ?

if (!ob_is_varbinary_type(expr.args_[0]->datum_meta_.type_,expr.args_[0]->datum_meta_.cs_type_)) {
is_ip_format_invalid = true;
LOG_WARN("ip format invalid", K(ret), K(text));
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段逻辑这样写吧

if (!ob_is_varbinary_type(expr.args_[0]->datum_meta_.type_,expr.args_[0]->datum_meta_.cs_type_)) {
  is_ip_format_invalid = true;
  LOG_WARN("ip format invalid", K(ret), K(text));
} else if (FALSE_IT(ObExprInetCommon::ip_to_str(text.get_string(), is_ip_format_invalid, ip_str))) {
} else if (is_ip_format_invalid) {
  xxx
} else {
  expr_datum.set_string(ip_str);
}

}
}
} else {
expr_datum.set_string(str_result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有点儿奇怪,str_result 和 expr_datum.get_string() 里的 ptr 不是本来就一直是同一个指针吗?为啥还要来回 set?

if (text.is_null()) {
expr_datum.set_null();
} else {
ObString str_result = expr_datum.get_string();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expr_datum 表示计算结果,一般不需要调 get 接口,最后算出结果后 set_string 就好了。

LOG_WARN("ip format invalid", K(ip));
} else {
char *result_buf = str_result.ptr();
if (OB_ISNULL(result_buf)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉如果 result_buf 是 nullptr 的话,说明给计算结果未被 set 前的 ObString 里的 ptr 地址是非法的,和 ip_format 是否是 invalid 没关系吧?

is_ip_format_invalid = true;
LOG_WARN("ip format invalid, end with '.'", K(i));
} else {
byte_addr[dotcnt] = (unsigned char) byte;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里内存的使用太诡异了,感觉可能会把内存给写乱的。可以参考下 ObExprConcat::eval_concat 是咋处理 string 类型结果的内存的。

@2149 2149 force-pushed the xxl_temp branch 3 times, most recently from 580acd2 to 74a18d2 Compare August 2, 2021 13:15
ObSQLUtils::get_default_cast_mode(session->get_stmt_type(), session, cast_mode);
if (OB_FAIL(calc(result, text, *expr_ctx.calc_buf_, cast_mode))) {
LOG_WARN("fail to calc", K(ret));
} else if (OB_LIKELY(!result.is_null())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接 ob_unlikely 就好了

inet_aton inet_ntoa inet6_aton inet6_ntoa
is_ipv4 is_ipv6 is_ipv4_mapped is_ipv6_mapped

fix:
[PASS_BY_VALUE]
/data/1/xiaoma/open_source/oceanbase/src/sql/engine/expr/ob_expr_operator.cpp
[FLOATING_POINT_EQUALITY]
/data/1/xiaoma/open_source/oceanbase/src/sql/engine/expr/ob_expr_mod.cpp
[CHECKED_RETURN]
/data/1/xiaoma/open_source/oceanbase/src/sql/engine/expr/ob_expr_operator.cpp
[UNINIT_CTOR]
/data/1/xiaoma/open_source/oceanbase/src/sql/engine/expr/ob_sql_expression.h
[DEADCODE]
/data/1/xiaoma/open_source/oceanbase/src/sql/engine/expr/ob_expr_operator.cpp
@LINxiansheng
Copy link
Contributor

merged.
Thanks for your contributions.
f8b7575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants