Skip to content

Commit

Permalink
Merge pull request #22718 from taosdata/fix/TD-26126
Browse files Browse the repository at this point in the history
fix:support length function for varbinary
  • Loading branch information
hjxilinx committed Sep 5, 2023
2 parents 0517358 + 43ebdd9 commit 6dabf70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/en/12-taos-sql/10-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ CONCAT_WS(separator_expr, expr1, expr2 [, expr] ...)
LENGTH(expr)
```

**Description**: The length in bytes of a string
**Description**: The length in bytes

**Return value type**: Bigint

**Applicable data types**: VARCHAR and NCHAR fields or columns
**Applicable data types**: VARCHAR and NCHAR and VARBINARY

**Nested query**: It can be used in both the outer query and inner query in a nested query.

Expand Down
4 changes: 2 additions & 2 deletions docs/zh/12-taos-sql/10-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ CONCAT_WS(separator_expr, expr1, expr2 [, expr] ...)
LENGTH(expr)
```

**功能说明**以字节计数的字符串长度
**功能说明**以字节计数的长度

**返回结果类型**:BIGINT。

**适用数据类型**输入参数是 VARCHAR 类型或者 NCHAR 类型的字符串或者列
**适用数据类型**:VARCHAR, NCHAR, VARBINARY

**嵌套子查询支持**:适用于内层查询和外层查询。

Expand Down
4 changes: 0 additions & 4 deletions source/libs/function/src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,10 +1839,6 @@ static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
}

if (TSDB_DATA_TYPE_VARBINARY == ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type) {
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
}

pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
return TSDB_CODE_SUCCESS;
}
Expand Down
10 changes: 5 additions & 5 deletions utils/test/c/varbinary_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ void varbinary_sql_test() {
taos_free_result(pRes);

// string function test, not support
pRes = taos_query(taos, "select length(c2) from stb");
ASSERT(taos_errno(pRes) != 0);
taos_free_result(pRes);

pRes = taos_query(taos, "select ltrim(c2) from stb");
ASSERT(taos_errno(pRes) != 0);
taos_free_result(pRes);
Expand Down Expand Up @@ -190,7 +186,7 @@ void varbinary_sql_test() {
ASSERT(taos_errno(pRes) != 0);
taos_free_result(pRes);

// support first/last/last_row/count/hyperloglog/sample/tail/mode
// support first/last/last_row/count/hyperloglog/sample/tail/mode/length
pRes = taos_query(taos, "select first(c2) from stb");
ASSERT(taos_errno(pRes) == 0);
taos_free_result(pRes);
Expand All @@ -207,6 +203,10 @@ void varbinary_sql_test() {
ASSERT(taos_errno(pRes) == 0);
taos_free_result(pRes);

pRes = taos_query(taos, "select length(c2) from stb where c2 = '\\x7F8290'");
ASSERT(taos_errno(pRes) == 0);
taos_free_result(pRes);

pRes = taos_query(taos, "select cast(t2 as varbinary(16)) from stb order by ts");
while ((row = taos_fetch_row(pRes)) != NULL) {
int32_t* length = taos_fetch_lengths(pRes);
Expand Down

0 comments on commit 6dabf70

Please sign in to comment.