Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5c12f455
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5c12f455
编写于
11月 11, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
select count(table1.*) + count(table2.*) from table1, tabl2 when join_condition
上级
6d9a8ab0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
385 addition
and
166 deletion
+385
-166
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+20
-19
src/common/inc/texpr.h
src/common/inc/texpr.h
+11
-3
src/common/src/texpr.c
src/common/src/texpr.c
+354
-144
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
5c12f455
...
...
@@ -4292,10 +4292,12 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
int32_t
*
childrenTypes
=
calloc
(
numChildren
,
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
;
i
<
numChildren
;
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pExpr
->
Expr
.
paramList
,
i
);
code
=
validateSQLExprItem
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
childrenTypes
+
i
,
uid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
free
(
childrenTypes
);
return
code
;
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
code
=
validateSQLExprItem
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
childrenTypes
+
i
,
uid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
free
(
childrenTypes
);
return
code
;
}
}
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
)
&&
...
...
@@ -4305,20 +4307,19 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
{
bool
allChildValue
=
true
;
bool
anyChildScalar
=
false
;
bool
anyChildAgg
=
false
;
for
(
int
i
=
0
;
i
<
numChildren
;
++
i
)
{
assert
(
childrenTypes
[
i
]
!=
SQLEXPR_TYPE_UNASSIGNED
);
allChildValue
=
allChildValue
&&
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_VALUE
);
anyChildScalar
=
anyChildScalar
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_SCALAR
);
anyChildAgg
=
anyChildAgg
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_AGG
);
}
if
(
anyChildAgg
&&
anyChildScalar
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
bool
allChildValue
=
true
;
bool
anyChildScalar
=
false
;
bool
anyChildAgg
=
false
;
for
(
int
i
=
0
;
i
<
numChildren
;
++
i
)
{
assert
(
childrenTypes
[
i
]
!=
SQLEXPR_TYPE_UNASSIGNED
);
allChildValue
=
allChildValue
&&
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_VALUE
);
anyChildScalar
=
anyChildScalar
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_SCALAR
);
anyChildAgg
=
anyChildAgg
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_AGG
);
}
if
(
anyChildAgg
&&
anyChildScalar
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
anyChildAgg
)
{
*
type
=
SQLEXPR_TYPE_AGG
;
}
else
if
(
allChildValue
)
{
...
...
@@ -4331,14 +4332,14 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
}
free
(
childrenTypes
);
//end if param list is not null
}
else
{
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
*
type
=
SQLEXPR_TYPE_SCALAR
;
}
else
{
*
type
=
SQLEXPR_TYPE_AGG
;
}
}
}
// else param list is null
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
...
...
src/common/inc/texpr.h
浏览文件 @
5c12f455
...
...
@@ -49,9 +49,17 @@ struct SSchema;
// SCALAR FUNCTIONS
#define TSDB_FUNC_SCALAR_POW (TSDB_FUNC_FLAG_SCALAR | 0x0000)
#define TSDB_FUNC_SCALAR_LOG (TSDB_FUNC_FLAG_SCALAR | 0x0001)
#define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x0002)
#define TSDB_FUNC_SCALAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x0003)
#define TSDB_FUNC_SCALAR_MAX_NUM 4
#define TSDB_FUNC_SCALAR_ABS (TSDB_FUNC_FLAG_SCALAR | 0x0002)
#define TSDB_FUNC_SCALAR_ACOS (TSDB_FUNC_FLAG_SCALAR | 0x0003)
#define TSDB_FUNC_SCALAR_ASIN (TSDB_FUNC_FLAG_SCALAR | 0x0004)
#define TSDB_FUNC_SCALAR_ATAN (TSDB_FUNC_FLAG_SCALAR | 0x0005)
#define TSDB_FUNC_SCALAR_COS (TSDB_FUNC_FLAG_SCALAR | 0x0006)
#define TSDB_FUNC_SCALAR_SIN (TSDB_FUNC_FLAG_SCALAR | 0x0007)
#define TSDB_FUNC_SCALAR_TAN (TSDB_FUNC_FLAG_SCALAR | 0x0008)
#define TSDB_FUNC_SCALAR_SQRT (TSDB_FUNC_FLAG_SCALAR | 0x0009)
#define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x000A)
#define TSDB_FUNC_SCALAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x000B)
#define TSDB_FUNC_SCALAR_MAX_NUM 12
#define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16
typedef
struct
{
...
...
src/common/src/texpr.c
浏览文件 @
5c12f455
...
...
@@ -28,127 +28,31 @@
#include "texpr.h"
#include "tarithoperator.h"
static
int32_t
exprValidateMathNode
(
tExprNode
*
pExpr
);
static
int32_t
exprValidateStringConcatNode
(
tExprNode
*
pExpr
);
static
int32_t
exprValidateStringLengthNode
(
tExprNode
*
pExpr
);
int32_t
exprTreeValidateFunctionNode
(
tExprNode
*
pExpr
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
//TODO: check childs for every function
switch
(
pExpr
->
_func
.
functionId
)
{
case
TSDB_FUNC_SCALAR_POW
:
case
TSDB_FUNC_SCALAR_LOG
:
{
if
(
pExpr
->
_func
.
numChildren
!=
2
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
tExprNode
*
child1
=
pExpr
->
_func
.
pChildren
[
0
];
tExprNode
*
child2
=
pExpr
->
_func
.
pChildren
[
1
];
if
(
child2
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
!
IS_NUMERIC_TYPE
(
child2
->
pVal
->
nType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
child2
->
resultType
=
(
int16_t
)
child2
->
pVal
->
nType
;
child2
->
resultBytes
=
(
int16_t
)
tDataTypes
[
child2
->
resultType
].
bytes
;
}
else
if
(
!
IS_NUMERIC_TYPE
(
child2
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
!
IS_NUMERIC_TYPE
(
child1
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
resultType
=
TSDB_DATA_TYPE_DOUBLE
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
break
;
case
TSDB_FUNC_SCALAR_LOG
:
case
TSDB_FUNC_SCALAR_ABS
:
case
TSDB_FUNC_SCALAR_ACOS
:
case
TSDB_FUNC_SCALAR_ASIN
:
case
TSDB_FUNC_SCALAR_ATAN
:
case
TSDB_FUNC_SCALAR_COS
:
case
TSDB_FUNC_SCALAR_SIN
:
case
TSDB_FUNC_SCALAR_TAN
:
case
TSDB_FUNC_SCALAR_SQRT
:{
return
exprValidateMathNode
(
pExpr
);
}
case
TSDB_FUNC_SCALAR_CONCAT
:
{
if
(
pExpr
->
_func
.
numChildren
<
2
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
int16_t
prevResultType
=
TSDB_DATA_TYPE_NULL
;
int16_t
resultType
=
TSDB_DATA_TYPE_NULL
;
bool
resultTypeDeduced
=
false
;
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
if
(
child
->
nodeType
!=
TSQL_NODE_VALUE
)
{
resultType
=
child
->
resultType
;
if
(
!
IS_VAR_DATA_TYPE
(
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
!
resultTypeDeduced
)
{
resultTypeDeduced
=
true
;
}
else
{
if
(
resultType
!=
prevResultType
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
prevResultType
=
child
->
resultType
;
}
else
{
if
(
!
IS_VAR_DATA_TYPE
(
child
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
if
(
resultTypeDeduced
)
{
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
if
(
child
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
!
IS_VAR_DATA_TYPE
(
child
->
pVal
->
nType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
char
*
payload
=
malloc
(
child
->
pVal
->
nLen
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
);
tVariantDump
(
child
->
pVal
,
payload
,
resultType
,
true
);
int16_t
resultBytes
=
varDataTLen
(
payload
);
free
(
payload
);
child
->
resultType
=
resultType
;
child
->
resultBytes
=
(
int16_t
)(
resultBytes
);
}
}
}
else
{
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
assert
(
child
->
nodeType
==
TSQL_NODE_VALUE
)
;
resultType
=
child
->
resultType
;
for
(
int
j
=
i
+
1
;
j
<
pExpr
->
_func
.
numChildren
;
++
j
)
{
if
(
pExpr
->
_func
.
pChildren
[
j
]
->
resultType
!=
resultType
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
}
pExpr
->
resultType
=
resultType
;
int16_t
resultBytes
=
0
;
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
if
(
resultBytes
<=
resultBytes
+
child
->
resultBytes
-
VARSTR_HEADER_SIZE
)
{
resultBytes
+=
child
->
resultBytes
-
VARSTR_HEADER_SIZE
;
}
else
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
pExpr
->
resultBytes
=
resultBytes
+
VARSTR_HEADER_SIZE
;
break
;
return
exprValidateStringConcatNode
(
pExpr
);
}
case
TSDB_FUNC_SCALAR_LENGTH
:
{
if
(
pExpr
->
_func
.
numChildren
!=
1
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
tExprNode
*
child1
=
pExpr
->
_func
.
pChildren
[
0
];
if
(
child1
->
nodeType
==
TSQL_NODE_VALUE
)
{
child1
->
resultType
=
(
int16_t
)
child1
->
pVal
->
nType
;
child1
->
resultBytes
=
(
int16_t
)(
child1
->
pVal
->
nLen
+
VARSTR_HEADER_SIZE
);
}
if
(
!
IS_VAR_DATA_TYPE
(
child1
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
resultType
=
TSDB_DATA_TYPE_SMALLINT
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_SMALLINT
].
bytes
;
break
;
return
exprValidateStringLengthNode
(
pExpr
);
}
default:
...
...
@@ -961,49 +865,162 @@ tExprNode* exprdup(tExprNode* pNode) {
return
pCloned
;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// scalar functions
int32_t
exprValidateStringConcatNode
(
tExprNode
*
pExpr
)
{
if
(
pExpr
->
_func
.
numChildren
<
2
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
void
vectorPow
(
int16_t
functionId
,
tExprOperandInfo
*
pInputs
,
uint8_t
numInputs
,
tExprOperandInfo
*
pOutput
,
int32_t
order
)
{
assert
(
numInputs
==
2
);
assert
(
pInputs
[
1
].
numOfRows
==
1
&&
pInputs
[
0
].
numOfRows
>=
1
);
int
numOfRows
=
pInputs
[
0
].
numOfRows
;
int16_t
prevResultType
=
TSDB_DATA_TYPE_NULL
;
int16_t
resultType
=
TSDB_DATA_TYPE_NULL
;
bool
resultTypeDeduced
=
false
;
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
if
(
child
->
nodeType
!=
TSQL_NODE_VALUE
)
{
resultType
=
child
->
resultType
;
if
(
!
IS_VAR_DATA_TYPE
(
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
!
resultTypeDeduced
)
{
resultTypeDeduced
=
true
;
}
else
{
if
(
resultType
!=
prevResultType
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
prevResultType
=
child
->
resultType
;
}
else
{
if
(
!
IS_VAR_DATA_TYPE
(
child
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
double
base
=
0
;
GET_TYPED_DATA
(
base
,
double
,
pInputs
[
1
].
type
,
pInputs
[
1
].
data
);
if
(
resultTypeDeduced
)
{
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
if
(
child
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
!
IS_VAR_DATA_TYPE
(
child
->
pVal
->
nType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
char
*
payload
=
malloc
(
child
->
pVal
->
nLen
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
);
tVariantDump
(
child
->
pVal
,
payload
,
resultType
,
true
);
int16_t
resultBytes
=
varDataTLen
(
payload
);
free
(
payload
);
child
->
resultType
=
resultType
;
child
->
resultBytes
=
(
int16_t
)(
resultBytes
);
}
}
}
else
{
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
assert
(
child
->
nodeType
==
TSQL_NODE_VALUE
)
;
resultType
=
child
->
resultType
;
for
(
int
j
=
i
+
1
;
j
<
pExpr
->
_func
.
numChildren
;
++
j
)
{
if
(
pExpr
->
_func
.
pChildren
[
j
]
->
resultType
!=
resultType
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
}
for
(
int
i
=
0
;
i
<
numOfRows
;
++
i
)
{
char
*
pInputData
=
pInputs
[
0
].
data
+
i
*
pInputs
[
0
].
bytes
;
char
*
pOutputData
=
pOutput
->
data
+
i
*
pOutput
->
bytes
;
if
(
isNull
(
pInputData
,
pInputs
[
0
].
type
))
{
setNull
(
pOutputData
,
pOutput
->
type
,
pOutput
->
bytes
);
pExpr
->
resultType
=
resultType
;
int16_t
resultBytes
=
0
;
for
(
int32_t
i
=
0
;
i
<
pExpr
->
_func
.
numChildren
;
++
i
)
{
tExprNode
*
child
=
pExpr
->
_func
.
pChildren
[
i
];
if
(
resultBytes
<=
resultBytes
+
child
->
resultBytes
-
VARSTR_HEADER_SIZE
)
{
resultBytes
+=
child
->
resultBytes
-
VARSTR_HEADER_SIZE
;
}
else
{
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
pInputData
);
double
result
=
pow
(
v1
,
base
);
SET_TYPED_DATA
(
pOutputData
,
pOutput
->
type
,
result
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
pExpr
->
resultBytes
=
resultBytes
+
VARSTR_HEADER_SIZE
;
return
TSDB_CODE_SUCCESS
;
}
void
vectorLog
(
int16_t
functionId
,
tExprOperandInfo
*
pInputs
,
uint8_t
numInputs
,
tExprOperandInfo
*
pOutput
,
int32_t
orde
r
)
{
assert
(
numInputs
==
2
);
assert
(
pInputs
[
1
].
numOfRows
==
1
&&
pInputs
[
0
].
numOfRows
>=
1
)
;
int
numOfRows
=
pInputs
[
0
].
numOfRows
;
int32_t
exprValidateStringLengthNode
(
tExprNode
*
pExp
r
)
{
if
(
pExpr
->
_func
.
numChildren
!=
1
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
double
base
=
0
;
GET_TYPED_DATA
(
base
,
double
,
pInputs
[
1
].
type
,
pInputs
[
1
].
data
);
tExprNode
*
child1
=
pExpr
->
_func
.
pChildren
[
0
];
for
(
int
i
=
0
;
i
<
numOfRows
;
++
i
)
{
char
*
pInputData
=
pInputs
[
0
].
data
+
i
*
pInputs
[
0
].
bytes
;
char
*
pOutputData
=
pOutput
->
data
+
i
*
pOutput
->
bytes
;
if
(
isNull
(
pInputData
,
pInputs
[
0
].
type
))
{
setNull
(
pOutputData
,
pOutput
->
type
,
pOutput
->
bytes
);
}
else
{
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
pInputData
);
double
result
=
log
(
v1
)
/
log
(
base
);
SET_TYPED_DATA
(
pOutputData
,
pOutput
->
type
,
result
);
if
(
child1
->
nodeType
==
TSQL_NODE_VALUE
)
{
child1
->
resultType
=
(
int16_t
)
child1
->
pVal
->
nType
;
child1
->
resultBytes
=
(
int16_t
)(
child1
->
pVal
->
nLen
+
VARSTR_HEADER_SIZE
);
}
if
(
!
IS_VAR_DATA_TYPE
(
child1
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
resultType
=
TSDB_DATA_TYPE_SMALLINT
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_SMALLINT
].
bytes
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
exprValidateMathNode
(
tExprNode
*
pExpr
)
{
switch
(
pExpr
->
_func
.
functionId
)
{
case
TSDB_FUNC_SCALAR_POW
:
case
TSDB_FUNC_SCALAR_LOG
:
{
if
(
pExpr
->
_func
.
numChildren
!=
2
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
tExprNode
*
child1
=
pExpr
->
_func
.
pChildren
[
0
];
tExprNode
*
child2
=
pExpr
->
_func
.
pChildren
[
1
];
if
(
!
IS_NUMERIC_TYPE
(
child1
->
resultType
)
||
!
IS_NUMERIC_TYPE
(
child2
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
resultType
=
TSDB_DATA_TYPE_DOUBLE
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_FUNC_SCALAR_ABS
:
{
if
(
pExpr
->
_func
.
numChildren
!=
1
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
tExprNode
*
child1
=
pExpr
->
_func
.
pChildren
[
0
];
if
(
!
IS_NUMERIC_TYPE
(
child1
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
IS_SIGNED_NUMERIC_TYPE
(
child1
->
resultType
)
||
IS_UNSIGNED_NUMERIC_TYPE
(
child1
->
resultType
))
{
pExpr
->
resultType
=
TSDB_DATA_TYPE_UBIGINT
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_UBIGINT
].
bytes
;
}
else
if
(
IS_FLOAT_TYPE
(
child1
->
resultType
))
{
pExpr
->
resultType
=
TSDB_DATA_TYPE_DOUBLE
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
}
break
;
}
case
TSDB_FUNC_SCALAR_SQRT
:
case
TSDB_FUNC_SCALAR_ASIN
:
case
TSDB_FUNC_SCALAR_ACOS
:
case
TSDB_FUNC_SCALAR_ATAN
:
case
TSDB_FUNC_SCALAR_SIN
:
case
TSDB_FUNC_SCALAR_COS
:
case
TSDB_FUNC_SCALAR_TAN
:{
if
(
pExpr
->
_func
.
numChildren
!=
1
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
tExprNode
*
child1
=
pExpr
->
_func
.
pChildren
[
0
];
if
(
!
IS_NUMERIC_TYPE
(
child1
->
resultType
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
pExpr
->
resultType
=
TSDB_DATA_TYPE_DOUBLE
;
pExpr
->
resultBytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
break
;
}
default:
{
assert
(
false
);
break
;
}
}
return
TSDB_CODE_SUCCESS
;
}
void
vectorConcat
(
int16_t
functionId
,
tExprOperandInfo
*
pInputs
,
uint8_t
numInputs
,
tExprOperandInfo
*
pOutput
,
int32_t
order
)
{
...
...
@@ -1067,6 +1084,159 @@ void vectorLength(int16_t functionId, tExprOperandInfo *pInputs, uint8_t numInpu
}
}
}
void
vectorMathFunc
(
int16_t
functionId
,
tExprOperandInfo
*
pInputs
,
uint8_t
numInputs
,
tExprOperandInfo
*
pOutput
,
int32_t
order
)
{
for
(
int
i
=
0
;
i
<
numInputs
;
++
i
)
{
assert
(
pInputs
[
i
].
numOfRows
==
1
||
pInputs
[
i
].
numOfRows
==
pOutput
->
numOfRows
);
}
char
*
outputData
=
NULL
;
char
**
inputData
=
calloc
(
numInputs
,
sizeof
(
char
*
));
for
(
int
i
=
0
;
i
<
pOutput
->
numOfRows
;
++
i
)
{
for
(
int
j
=
0
;
j
<
numInputs
;
++
j
)
{
if
(
pInputs
[
j
].
numOfRows
==
1
)
{
inputData
[
j
]
=
pInputs
[
j
].
data
;
}
else
{
inputData
[
j
]
=
pInputs
[
j
].
data
+
i
*
pInputs
[
j
].
bytes
;
}
}
outputData
=
pOutput
->
data
+
i
*
pOutput
->
bytes
;
bool
hasNullInputs
=
false
;
for
(
int
j
=
0
;
j
<
numInputs
;
++
j
)
{
if
(
isNull
(
inputData
[
j
],
pInputs
[
j
].
type
))
{
hasNullInputs
=
true
;
setNull
(
outputData
,
pOutput
->
type
,
pOutput
->
bytes
);
}
}
if
(
!
hasNullInputs
)
{
switch
(
functionId
)
{
case
TSDB_FUNC_SCALAR_LOG
:
{
assert
(
numInputs
==
2
);
double
base
=
0
;
GET_TYPED_DATA
(
base
,
double
,
pInputs
[
1
].
type
,
inputData
[
1
]);
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
log
(
v1
)
/
log
(
base
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_POW
:{
assert
(
numInputs
==
2
);
double
base
=
0
;
GET_TYPED_DATA
(
base
,
double
,
pInputs
[
1
].
type
,
inputData
[
1
]);
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
pow
(
v1
,
base
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_ABS
:
{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
if
(
IS_SIGNED_NUMERIC_TYPE
(
pInputs
[
0
].
type
))
{
int64_t
v1
=
0
;
GET_TYPED_DATA
(
v1
,
int64_t
,
pInputs
[
0
].
type
,
inputData
[
0
]);
uint64_t
result
=
(
uint64_t
)(
llabs
(
v1
));
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pInputs
[
0
].
type
))
{
uint64_t
v1
=
0
;
GET_TYPED_DATA
(
v1
,
uint64_t
,
pInputs
[
0
].
type
,
inputData
[
0
]);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
v1
);
}
else
if
(
IS_FLOAT_TYPE
(
pInputs
[
0
].
type
))
{
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
fabs
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
}
break
;
}
case
TSDB_FUNC_SCALAR_SQRT
:
{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
sqrt
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_ASIN
:
{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
asin
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_ACOS
:
{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
acos
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_ATAN
:
{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
atan
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_SIN
:
{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
sin
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_COS
:
{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
cos
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
case
TSDB_FUNC_SCALAR_TAN
:{
assert
(
numInputs
==
1
);
assert
(
IS_NUMERIC_TYPE
(
pInputs
[
0
].
type
));
double
v1
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pInputs
[
0
].
type
,
inputData
[
0
]);
double
result
=
tan
(
v1
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
result
);
break
;
}
default:
{
assert
(
false
);
break
;
}
}
}
}
free
(
inputData
);
}
_expr_scalar_function_t
getExprScalarFunction
(
uint16_t
funcId
)
{
assert
(
TSDB_FUNC_IS_SCALAR
(
funcId
));
int16_t
scalaIdx
=
TSDB_FUNC_SCALAR_INDEX
(
funcId
);
...
...
@@ -1078,12 +1248,52 @@ tScalarFunctionInfo aScalarFunctions[] = {
{
TSDB_FUNC_SCALAR_POW
,
"pow"
,
vector
Pow
vector
MathFunc
},
{
TSDB_FUNC_SCALAR_LOG
,
"log"
,
vectorLog
vectorMathFunc
},
{
TSDB_FUNC_SCALAR_ABS
,
"abs"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_ACOS
,
"acos"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_ASIN
,
"asin"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_ATAN
,
"atan"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_COS
,
"cos"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_SIN
,
"sin"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_TAN
,
"tan"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_SQRT
,
"sqrt"
,
vectorMathFunc
,
},
{
TSDB_FUNC_SCALAR_CONCAT
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录