Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dc266954
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
dc266954
编写于
4月 10, 2022
作者:
X
xywang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(query): enhanced bitwise and function
[TS-1210]
上级
7e0bbd6a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
161 addition
and
10 deletion
+161
-10
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+1
-3
src/common/src/texpr.c
src/common/src/texpr.c
+160
-7
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
dc266954
...
...
@@ -10124,8 +10124,8 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_VALUE
;
(
*
pExpr
)
->
pVal
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariantAssign
((
*
pExpr
)
->
pVal
,
&
pSqlExpr
->
value
);
tVariant
value
=
pSqlExpr
->
value
;
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
pQueryInfo
->
curTableIdx
)
->
pTableMeta
;
if
(
pCols
!=
NULL
)
{
size_t
colSize
=
taosArrayGetSize
(
pCols
);
...
...
@@ -10134,14 +10134,12 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
SColIndex
*
idx
=
taosArrayGet
(
pCols
,
colSize
-
1
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
idx
->
colIndex
);
value
.
nType
=
pSchema
->
type
;
// convert time by precision
if
(
pSchema
!=
NULL
&&
TSDB_DATA_TYPE_TIMESTAMP
==
pSchema
->
type
&&
TSDB_DATA_TYPE_BINARY
==
(
*
pExpr
)
->
pVal
->
nType
)
{
ret
=
setColumnFilterInfoForTimestamp
(
pCmd
,
pQueryInfo
,
(
*
pExpr
)
->
pVal
);
}
}
}
tVariantAssign
((
*
pExpr
)
->
pVal
,
&
value
);
return
ret
;
}
else
if
(
pSqlExpr
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
// column name, normal column arithmetic expression
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
...
...
src/common/src/texpr.c
浏览文件 @
dc266954
...
...
@@ -23,6 +23,7 @@
#include "tarray.h"
#include "tbuffer.h"
#include "tcompare.h"
#include "tglobal.h"
#include "tsdb.h"
#include "tskiplist.h"
#include "texpr.h"
...
...
@@ -47,7 +48,7 @@ static int32_t exprInvalidOperationMsg(char *msgbuf, const char *msg) {
int32_t
exprTreeValidateFunctionNode
(
char
*
msgbuf
,
tExprNode
*
pExpr
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
//TODO: check child
s
for every function
//TODO: check child
ren
for every function
switch
(
pExpr
->
_func
.
functionId
)
{
case
TSDB_FUNC_SCALAR_POW
:
case
TSDB_FUNC_SCALAR_LOG
:
...
...
@@ -87,6 +88,7 @@ int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) {
int32_t
exprTreeValidateExprNode
(
tExprNode
*
pExpr
)
{
int16_t
leftType
=
pExpr
->
_node
.
pLeft
->
resultType
;
int16_t
rightType
=
pExpr
->
_node
.
pRight
->
resultType
;
int16_t
resultType
=
leftType
;
if
(
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_ADD
||
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_SUBTRACT
||
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_MULTIPLY
||
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_DIVIDE
||
...
...
@@ -98,18 +100,168 @@ int32_t exprTreeValidateExprNode(tExprNode *pExpr) {
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_BITAND
)
{
if
((
leftType
!=
rightType
)
||
(
leftType
!=
TSDB_DATA_TYPE_BOOL
&&
!
IS_SIGNED_NUMERIC_TYPE
(
leftType
)
&&
!
IS_UNSIGNED_NUMERIC_TYPE
(
leftType
))
||
if
((
leftType
!=
TSDB_DATA_TYPE_BOOL
&&
!
IS_SIGNED_NUMERIC_TYPE
(
leftType
)
&&
!
IS_UNSIGNED_NUMERIC_TYPE
(
leftType
))
||
(
rightType
!=
TSDB_DATA_TYPE_BOOL
&&
!
IS_SIGNED_NUMERIC_TYPE
(
rightType
)
&&
!
IS_UNSIGNED_NUMERIC_TYPE
(
rightType
)))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
leftType
==
TSDB_DATA_TYPE_BOOL
)
{
uint8_t
schemaType
;
// now leftType and rightType are both numeric
if
(
pExpr
->
_node
.
pLeft
->
nodeType
==
TSQL_NODE_COL
&&
pExpr
->
_node
.
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
if
(
leftType
!=
rightType
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
else
if
(
pExpr
->
_node
.
pLeft
->
nodeType
==
TSQL_NODE_COL
)
{
if
(
pExpr
->
_node
.
pRight
->
nodeType
!=
TSQL_NODE_VALUE
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
{
schemaType
=
pExpr
->
_node
.
pLeft
->
pSchema
->
type
;
int64_t
sVal
=
pExpr
->
_node
.
pRight
->
pVal
->
i64
;
uint64_t
uVal
=
pExpr
->
_node
.
pRight
->
pVal
->
u64
;
switch
(
schemaType
)
{
case
TSDB_DATA_TYPE_BOOL
:
if
((
pExpr
->
_node
.
pRight
->
pVal
->
nType
!=
TSDB_DATA_TYPE_BOOL
)
||
(
pExpr
->
_node
.
pRight
->
pVal
->
i64
!=
0
&&
pExpr
->
_node
.
pRight
->
pVal
->
i64
!=
1
&&
pExpr
->
_node
.
pRight
->
pVal
->
i64
!=
TSDB_DATA_BOOL_NULL
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_TINYINT
:
if
(
sVal
<
-
128
||
sVal
>
127
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
if
(
sVal
<
-
65536
||
sVal
>
65535
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_INT
:
if
(
sVal
<
INT32_MIN
||
sVal
>
INT32_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_BIGINT
:
if
(
sVal
<
INT64_MIN
||
sVal
>
INT64_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
if
(
uVal
>
128
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
if
(
uVal
>
65536
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_UINT
:
if
(
uVal
>
UINT32_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
if
(
uVal
>
UINT64_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
}
pExpr
->
_node
.
pRight
->
pSchema
->
type
=
schemaType
;
pExpr
->
_node
.
pRight
->
pVal
->
nType
=
schemaType
;
pExpr
->
_node
.
pRight
->
resultType
=
schemaType
;
pExpr
->
_node
.
pRight
->
resultBytes
=
tDataTypes
[
schemaType
].
bytes
;
}
}
else
{
if
(
pExpr
->
_node
.
pLeft
->
nodeType
!=
TSQL_NODE_VALUE
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
{
schemaType
=
pExpr
->
_node
.
pRight
->
pSchema
->
type
;
int64_t
sVal
=
pExpr
->
_node
.
pLeft
->
pVal
->
i64
;
uint64_t
uVal
=
pExpr
->
_node
.
pLeft
->
pVal
->
u64
;
switch
(
schemaType
)
{
case
TSDB_DATA_TYPE_BOOL
:
if
((
pExpr
->
_node
.
pLeft
->
pVal
->
nType
!=
TSDB_DATA_TYPE_BOOL
)
||
(
pExpr
->
_node
.
pLeft
->
pVal
->
i64
!=
0
&&
pExpr
->
_node
.
pLeft
->
pVal
->
i64
!=
1
&&
pExpr
->
_node
.
pLeft
->
pVal
->
i64
!=
TSDB_DATA_BOOL_NULL
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
1
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
if
(
sVal
<
-
128
||
sVal
>
127
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
1
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
if
(
sVal
<
-
65536
||
sVal
>
65535
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
2
;
break
;
case
TSDB_DATA_TYPE_INT
:
if
(
sVal
<
INT32_MIN
||
sVal
>
INT32_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
4
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
if
(
sVal
<
INT64_MIN
||
sVal
>
INT64_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
8
;
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
if
(
uVal
>
128
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
1
;
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
if
(
uVal
>
65536
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
2
;
break
;
case
TSDB_DATA_TYPE_UINT
:
if
(
uVal
>
UINT32_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
4
;
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
if
(
uVal
>
UINT64_MAX
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
8
;
break
;
}
pExpr
->
_node
.
pLeft
->
pSchema
->
type
=
schemaType
;
pExpr
->
_node
.
pLeft
->
pVal
->
nType
=
schemaType
;
pExpr
->
_node
.
pLeft
->
resultType
=
schemaType
;
pExpr
->
_node
.
pLeft
->
resultBytes
=
tDataTypes
[
schemaType
].
bytes
;
}
resultType
=
schemaType
;
}
if
(
resultType
==
TSDB_DATA_TYPE_BOOL
)
{
pExpr
->
resultType
=
TSDB_DATA_TYPE_BOOL
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
;
}
else
{
pExpr
->
resultType
=
lef
tType
;
pExpr
->
resultBytes
=
tDataTypes
[
lef
tType
].
bytes
;
pExpr
->
resultType
=
resul
tType
;
pExpr
->
resultBytes
=
tDataTypes
[
resul
tType
].
bytes
;
}
return
TSDB_CODE_SUCCESS
;
}
else
{
...
...
@@ -504,7 +656,7 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI
_arithmetic_operator_fn_t
OperatorFn
=
getArithmeticOperatorFn
(
pExpr
->
_node
.
optr
);
OperatorFn
(
leftIn
,
leftNum
,
leftType
,
rightIn
,
rightNum
,
rightType
,
output
->
data
,
fnOrder
);
output
->
numOfRows
=
MAX
(
leftNum
,
rightNum
);
if
(
leftType
==
TSDB_DATA_TYPE_TIMESTAMP
||
rightType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
output
->
type
=
TSDB_DATA_TYPE_BIGINT
;
...
...
@@ -513,7 +665,7 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI
output
->
type
=
leftType
;
// rightType must be the same as leftType
}
else
{
output
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
}
}
}
output
->
bytes
=
tDataTypes
[
output
->
type
].
bytes
;
...
...
@@ -1748,4 +1900,5 @@ tScalarFunctionInfo aScalarFunctions[] = {
"cast"
,
vectorMathFunc
},
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录