Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9ff4b302
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看板
未验证
提交
9ff4b302
编写于
4月 10, 2022
作者:
M
Minglei Jin
提交者:
GitHub
4月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11110 from taosdata/fix/TS-1210-2.4
[TS-1210]<feature>: added Bitwise AND feature
上级
16792f15
1ce9c70c
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
1759 addition
and
1836 deletion
+1759
-1836
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+24
-3
src/common/src/tarithoperator.c
src/common/src/tarithoperator.c
+273
-1
src/common/src/texpr.c
src/common/src/texpr.c
+182
-5
src/inc/taosdef.h
src/inc/taosdef.h
+2
-1
src/query/inc/sql.y
src/query/inc/sql.y
+1
-0
src/query/src/sql.c
src/query/src/sql.c
+1277
-1826
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
9ff4b302
...
...
@@ -282,6 +282,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) {
return
TSDB_BINARY_OP_DIVIDE
;
case
TK_REM
:
return
TSDB_BINARY_OP_REMAINDER
;
case
TK_BITAND
:
return
TSDB_BINARY_OP_BITAND
;
case
TK_LIKE
:
return
TSDB_RELATION_LIKE
;
case
TK_MATCH
:
...
...
@@ -10251,6 +10253,23 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
}
}
if
(
pSqlExpr
->
tokenId
==
TK_BITAND
&&
pSqlExpr
->
pLeft
!=
NULL
&&
pSqlExpr
->
pRight
!=
NULL
)
{
// for example: col type is "bool" but expr "col & 1" received
uint8_t
colType
=
pLeft
->
pSchema
->
type
;
SStrToken
*
exprToken
=
&
pSqlExpr
->
pRight
->
exprToken
;
if
(
pSqlExpr
->
pLeft
->
type
==
SQL_NODE_TABLE_COLUMN
&&
pSqlExpr
->
pRight
->
type
==
SQL_NODE_VALUE
)
{
if
(
colType
==
TSDB_DATA_TYPE_BOOL
)
{
if
((
exprToken
->
n
!=
4
||
strncasecmp
(
exprToken
->
z
,
"true"
,
4
))
&&
(
exprToken
->
n
!=
5
||
strncasecmp
(
exprToken
->
z
,
"false"
,
5
)))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
else
if
(
IS_SIGNED_NUMERIC_TYPE
(
colType
)
||
IS_UNSIGNED_NUMERIC_TYPE
(
colType
))
{
if
((
exprToken
->
n
==
4
&&
strncasecmp
(
exprToken
->
z
,
"true"
,
4
)
==
0
)
||
(
exprToken
->
n
==
5
||
strncasecmp
(
exprToken
->
z
,
"false"
,
5
)
==
0
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
}
if
(
pSqlExpr
->
pRight
!=
NULL
)
{
int32_t
ret
=
exprTreeFromSqlExpr
(
pCmd
,
&
pRight
,
pSqlExpr
->
pRight
,
pQueryInfo
,
pCols
,
uid
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -10288,12 +10307,14 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
if
(
pLeft
->
_node
.
optr
==
TSDB_RELATION_ARROW
){
pLeft
=
pLeft
->
_node
.
pLeft
;
}
if
(
pRight
->
pVal
->
nType
==
TSDB_DATA_TYPE_BOOL
&&
pLeft
->
nodeType
==
TSQL_NODE_COL
&&
(
pLeft
->
pSchema
->
type
==
TSDB_DATA_TYPE_BOOL
||
pLeft
->
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
))
{
if
(
pRight
->
pVal
->
nType
==
TSDB_DATA_TYPE_BOOL
&&
pLeft
->
nodeType
==
TSQL_NODE_COL
)
{
if
(((
*
pExpr
)
->
_node
.
optr
!=
TSDB_BINARY_OP_BITAND
&&
pLeft
->
pSchema
->
type
==
TSDB_DATA_TYPE_BOOL
)
||
pLeft
->
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
}
}
else
if
(
pSqlExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
if
(
TSDB_FUNC_IS_SCALAR
(
pSqlExpr
->
functionId
))
{
...
...
src/common/src/tarithoperator.c
浏览文件 @
9ff4b302
...
...
@@ -123,6 +123,9 @@ _arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) {
typedef
void
*
(
*
_arithmetic_getVectorValueAddr_fn_t
)(
void
*
src
,
int32_t
index
);
void
*
getVectorValueAddr_BOOL
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
bool
*
)
src
+
index
);
}
void
*
getVectorValueAddr_TINYINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
int8_t
*
)
src
+
index
);
}
...
...
@@ -156,7 +159,9 @@ void* getVectorValueAddr_DOUBLE(void *src, int32_t index) {
_arithmetic_getVectorValueAddr_fn_t
getVectorValueAddrFn
(
int32_t
srcType
)
{
_arithmetic_getVectorValueAddr_fn_t
p
=
NULL
;
if
(
srcType
==
TSDB_DATA_TYPE_TINYINT
)
{
if
(
srcType
==
TSDB_DATA_TYPE_BOOL
)
{
p
=
getVectorValueAddr_BOOL
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_TINYINT
)
{
p
=
getVectorValueAddr_TINYINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_UTINYINT
)
{
p
=
getVectorValueAddr_UTINYINT
;
...
...
@@ -398,6 +403,271 @@ void vectorRemainder(void *left, int32_t len1, int32_t _left_type, void *right,
}
}
void
vectorBitand
(
void
*
left
,
int32_t
len1
,
int32_t
_left_type
,
void
*
right
,
int32_t
len2
,
int32_t
_right_type
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
(
_ord
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
len1
,
len2
)
-
1
;
int32_t
step
=
(
_ord
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
char
*
output
=
out
;
_arithmetic_getVectorValueAddr_fn_t
getVectorValueAddrFnLeft
=
getVectorValueAddrFn
(
_left_type
);
_arithmetic_getVectorValueAddr_fn_t
getVectorValueAddrFnRight
=
getVectorValueAddrFn
(
_right_type
);
if
(
len1
==
(
len2
))
{
for
(;
i
>=
0
&&
i
<
(
len2
);
i
+=
step
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
left
,
i
),
_left_type
)
||
isNull
(
getVectorValueAddrFnRight
(
right
,
i
),
_right_type
))
{
switch
(
_left_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
*
(
bool
*
)
output
=
TSDB_DATA_BOOL_NULL
;
output
+=
sizeof
(
bool
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
output
=
TSDB_DATA_TINYINT_NULL
;
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
output
=
TSDB_DATA_SMALLINT_NULL
;
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
output
=
TSDB_DATA_INT_NULL
;
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
output
=
TSDB_DATA_BIGINT_NULL
;
output
+=
sizeof
(
int64_t
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
output
=
TSDB_DATA_UTINYINT_NULL
;
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
output
=
TSDB_DATA_USMALLINT_NULL
;
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
output
=
TSDB_DATA_UINT_NULL
;
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
output
=
TSDB_DATA_UBIGINT_NULL
;
output
+=
sizeof
(
int64_t
);
break
;
}
continue
;
}
switch
(
_left_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
*
(
bool
*
)
output
=
(
*
((
bool
*
)
left
+
i
))
&
(
*
((
bool
*
)
right
+
i
));
output
+=
sizeof
(
bool
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
output
=
(
*
((
int8_t
*
)
left
+
i
))
&
(
*
((
int8_t
*
)
right
+
i
));
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
output
=
(
*
((
int16_t
*
)
left
+
i
))
&
(
*
((
int16_t
*
)
right
+
i
));
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
output
=
(
*
((
int32_t
*
)
left
+
i
))
&
(
*
((
int32_t
*
)
right
+
i
));
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
output
=
(
*
((
int64_t
*
)
left
+
i
))
&
(
*
((
int64_t
*
)
right
+
i
));
output
+=
sizeof
(
int64_t
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
output
=
(
*
((
uint8_t
*
)
left
+
i
))
&
(
*
((
uint8_t
*
)
right
+
i
));
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
output
=
(
*
((
uint16_t
*
)
left
+
i
))
&
(
*
((
uint16_t
*
)
right
+
i
));
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
output
=
(
*
((
uint32_t
*
)
left
+
i
))
&
(
*
((
uint32_t
*
)
right
+
i
));
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
output
=
(
*
((
uint64_t
*
)
left
+
i
))
&
(
*
((
uint64_t
*
)
right
+
i
));
output
+=
sizeof
(
int64_t
);
break
;
}
}
}
else
if
(
len1
==
1
)
{
for
(;
i
>=
0
&&
i
<
(
len2
);
i
+=
step
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
left
,
0
),
_left_type
)
||
isNull
(
getVectorValueAddrFnRight
(
right
,
i
),
_right_type
))
{
switch
(
_left_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
*
(
bool
*
)
output
=
TSDB_DATA_BOOL_NULL
;
output
+=
sizeof
(
bool
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
output
=
TSDB_DATA_TINYINT_NULL
;
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
output
=
TSDB_DATA_SMALLINT_NULL
;
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
output
=
TSDB_DATA_INT_NULL
;
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
output
=
TSDB_DATA_BIGINT_NULL
;
output
+=
sizeof
(
int64_t
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
output
=
TSDB_DATA_UTINYINT_NULL
;
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
output
=
TSDB_DATA_USMALLINT_NULL
;
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
output
=
TSDB_DATA_UINT_NULL
;
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
output
=
TSDB_DATA_UBIGINT_NULL
;
output
+=
sizeof
(
int64_t
);
break
;
}
continue
;
}
switch
(
_left_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
*
(
bool
*
)
output
=
(
*
(
bool
*
)
left
)
&
(
*
((
bool
*
)
right
+
i
));
output
+=
sizeof
(
bool
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
output
=
(
*
(
int8_t
*
)
left
)
&
(
*
((
int8_t
*
)
right
+
i
));
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
output
=
(
*
(
int16_t
*
)
left
)
&
(
*
((
int16_t
*
)
right
+
i
));
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
output
=
(
*
(
int32_t
*
)
left
)
&
(
*
((
int32_t
*
)
right
+
i
));
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
output
=
(
*
(
int64_t
*
)
left
)
&
(
*
((
int64_t
*
)
right
+
i
));
output
+=
sizeof
(
int64_t
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
output
=
(
*
(
uint8_t
*
)
left
)
&
(
*
((
uint8_t
*
)
right
+
i
));
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
output
=
(
*
(
uint16_t
*
)
left
)
&
(
*
((
uint16_t
*
)
right
+
i
));
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
output
=
(
*
(
uint32_t
*
)
left
)
&
(
*
((
uint32_t
*
)
right
+
i
));
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
output
=
(
*
(
uint64_t
*
)
left
)
&
(
*
((
uint64_t
*
)
right
+
i
));
output
+=
sizeof
(
int64_t
);
break
;
}
}
}
else
if
((
len2
)
==
1
)
{
for
(;
i
>=
0
&&
i
<
len1
;
i
+=
step
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
left
,
i
),
_left_type
)
||
isNull
(
getVectorValueAddrFnRight
(
right
,
0
),
_right_type
))
{
switch
(
_left_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
*
(
bool
*
)
output
=
TSDB_DATA_BOOL_NULL
;
output
+=
sizeof
(
bool
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
output
=
TSDB_DATA_TINYINT_NULL
;
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
output
=
TSDB_DATA_SMALLINT_NULL
;
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
output
=
TSDB_DATA_INT_NULL
;
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
output
=
TSDB_DATA_BIGINT_NULL
;
output
+=
sizeof
(
int64_t
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
output
=
TSDB_DATA_UTINYINT_NULL
;
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
output
=
TSDB_DATA_USMALLINT_NULL
;
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
output
=
TSDB_DATA_UINT_NULL
;
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
output
=
TSDB_DATA_UBIGINT_NULL
;
output
+=
sizeof
(
int64_t
);
break
;
}
continue
;
}
switch
(
_left_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
*
(
bool
*
)
output
=
(
*
((
bool
*
)
left
+
i
))
&
(
*
(
bool
*
)
right
);
output
+=
sizeof
(
bool
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
*
(
int8_t
*
)
output
=
(
*
((
int8_t
*
)
left
+
i
))
&
(
*
(
int8_t
*
)
right
);
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
(
int16_t
*
)
output
=
(
*
((
int16_t
*
)
left
+
i
))
&
(
*
(
int16_t
*
)
right
);
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_INT
:
*
(
int32_t
*
)
output
=
(
*
((
int32_t
*
)
left
+
i
))
&
(
*
(
int32_t
*
)
right
);
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
(
int64_t
*
)
output
=
(
*
((
int64_t
*
)
left
+
i
))
&
(
*
(
int64_t
*
)
right
);
output
+=
sizeof
(
int64_t
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
output
=
(
*
((
uint8_t
*
)
left
+
i
))
&
(
*
(
uint8_t
*
)
right
);
output
+=
sizeof
(
int8_t
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
output
=
(
*
((
uint16_t
*
)
left
+
i
))
&
(
*
(
uint16_t
*
)
right
);
output
+=
sizeof
(
int16_t
);
break
;
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
output
=
(
*
((
uint32_t
*
)
left
+
i
))
&
(
*
(
uint32_t
*
)
right
);
output
+=
sizeof
(
int32_t
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
output
=
(
*
((
uint64_t
*
)
left
+
i
))
&
(
*
(
uint64_t
*
)
right
);
output
+=
sizeof
(
int64_t
);
break
;
}
}
}
}
_arithmetic_operator_fn_t
getArithmeticOperatorFn
(
int32_t
arithmeticOptr
)
{
switch
(
arithmeticOptr
)
{
case
TSDB_BINARY_OP_ADD
:
...
...
@@ -410,6 +680,8 @@ _arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr) {
return
vectorDivide
;
case
TSDB_BINARY_OP_REMAINDER
:
return
vectorRemainder
;
case
TSDB_BINARY_OP_BITAND
:
return
vectorBitand
;
default:
assert
(
0
);
return
NULL
;
...
...
src/common/src/texpr.c
浏览文件 @
9ff4b302
...
...
@@ -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
:
...
...
@@ -85,17 +86,184 @@ 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
||
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_REMAINDER
)
{
int16_t
leftType
=
pExpr
->
_node
.
pLeft
->
resultType
;
int16_t
rightType
=
pExpr
->
_node
.
pRight
->
resultType
;
if
(
!
IS_NUMERIC_TYPE
(
leftType
)
||
!
IS_NUMERIC_TYPE
(
rightType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
resultType
=
TSDB_DATA_TYPE_DOUBLE
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_BITAND
)
{
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
;
}
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
<
-
32768
||
sVal
>
32767
)
{
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
>
255
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
if
(
uVal
>
65535
)
{
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
<
-
32768
||
sVal
>
32767
)
{
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
>
255
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
_node
.
pLeft
->
pVal
->
nLen
=
1
;
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
if
(
uVal
>
65535
)
{
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
=
resultType
;
pExpr
->
resultBytes
=
tDataTypes
[
resultType
].
bytes
;
}
return
TSDB_CODE_SUCCESS
;
}
else
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -490,7 +658,15 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI
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
;
}
else
{
if
(
pExpr
->
_node
.
optr
==
TSDB_BINARY_OP_BITAND
)
{
output
->
type
=
leftType
;
// rightType must be the same as leftType
}
else
{
output
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
}
}
output
->
bytes
=
tDataTypes
[
output
->
type
].
bytes
;
tfree
(
ltmp
);
...
...
@@ -1724,4 +1900,5 @@ tScalarFunctionInfo aScalarFunctions[] = {
"cast"
,
vectorMathFunc
},
};
src/inc/taosdef.h
浏览文件 @
9ff4b302
...
...
@@ -176,10 +176,11 @@ do { \
#define TSDB_BINARY_OP_MULTIPLY 32
#define TSDB_BINARY_OP_DIVIDE 33
#define TSDB_BINARY_OP_REMAINDER 34
#define TSDB_BINARY_OP_BITAND 35
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_
REMAINDER
))
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_
BITAND
))
#define TS_PATH_DELIMITER_LEN 1
...
...
src/query/inc/sql.y
浏览文件 @
9ff4b302
...
...
@@ -786,6 +786,7 @@ expr(A) ::= expr(X) MINUS expr(Y). {A = tSqlExprCreate(X, Y, TK_MINUS); }
expr(A) ::= expr(X) STAR expr(Y). {A = tSqlExprCreate(X, Y, TK_STAR); }
expr(A) ::= expr(X) SLASH expr(Y). {A = tSqlExprCreate(X, Y, TK_DIVIDE);}
expr(A) ::= expr(X) REM expr(Y). {A = tSqlExprCreate(X, Y, TK_REM); }
expr(A) ::= expr(X) BITAND expr(Y). {A = tSqlExprCreate(X, Y, TK_BITAND);}
// like expression
expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
...
...
src/query/src/sql.c
浏览文件 @
9ff4b302
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录