Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
59219933
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看板
提交
59219933
编写于
11月 01, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-10564] support unary scalar function.
上级
bc82a32b
变更
16
展开全部
隐藏空白更改
内联
并排
Showing
16 changed file
with
874 addition
and
626 deletion
+874
-626
include/util/tcompression.h
include/util/tcompression.h
+1
-1
include/util/tdef.h
include/util/tdef.h
+7
-15
include/util/tskiplist.h
include/util/tskiplist.h
+1
-1
source/libs/executor/src/tarithoperator.c
source/libs/executor/src/tarithoperator.c
+0
-411
source/libs/function/inc/tbinoperator.h
source/libs/function/inc/tbinoperator.h
+6
-6
source/libs/function/inc/texpr.h
source/libs/function/inc/texpr.h
+0
-3
source/libs/function/inc/tscalarfunction.h
source/libs/function/inc/tscalarfunction.h
+11
-3
source/libs/function/inc/tunaryoperator.h
source/libs/function/inc/tunaryoperator.h
+32
-0
source/libs/function/src/taggfunction.c
source/libs/function/src/taggfunction.c
+1
-1
source/libs/function/src/tbinoperator.c
source/libs/function/src/tbinoperator.c
+484
-0
source/libs/function/src/texpr.c
source/libs/function/src/texpr.c
+0
-173
source/libs/function/src/tscalarfunction.c
source/libs/function/src/tscalarfunction.c
+161
-2
source/libs/function/src/tunaryoperator.c
source/libs/function/src/tunaryoperator.c
+167
-0
source/libs/parser/src/parserUtil.c
source/libs/parser/src/parserUtil.c
+1
-9
source/util/src/thash.c
source/util/src/thash.c
+1
-0
source/util/src/thashutil.c
source/util/src/thashutil.c
+1
-1
未找到文件。
include/util/tcompression.h
浏览文件 @
59219933
...
...
@@ -20,7 +20,7 @@
extern
"C"
{
#endif
#include "t
def
.h"
#include "t
aos
.h"
#include "tutil.h"
#define COMP_OVERFLOW_BYTES 2
...
...
include/util/tdef.h
浏览文件 @
59219933
...
...
@@ -134,6 +134,13 @@ do { \
#define TSDB_BINARY_OP_REMAINDER 4004
#define TSDB_BINARY_OP_CONCAT 4005
#define TSDB_UNARY_OP_CEIL 4500
#define TSDB_UNARY_OP_FLOOR 4501
#define TSDB_UNARY_OP_ABS 4502
#define TSDB_UNARY_OP_ROUND 4503
#define TSDB_UNARY_OP_LEN 4600
#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))
...
...
@@ -366,21 +373,6 @@ do { \
#define TSDB_MAX_DISKS_PER_TIER 16
#define TSDB_MAX_DISKS (TSDB_MAX_TIERS * TSDB_MAX_DISKS_PER_TIER)
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
#define TSDB_DATA_TYPE_BINARY 8 // string
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
enum
{
TRANS_STAT_INIT
=
0
,
TRANS_STAT_EXECUTING
,
TRANS_STAT_EXECUTED
,
TRANS_STAT_ROLLBACKING
,
TRANS_STAT_ROLLBACKED
};
enum
{
TRANS_OPER_INIT
=
0
,
TRANS_OPER_EXECUTE
,
TRANS_OPER_ROLLBACK
};
...
...
include/util/tskiplist.h
浏览文件 @
59219933
...
...
@@ -21,7 +21,7 @@ extern "C" {
#endif
#include "os.h"
//#include "tdef
.h"
#include "taos
.h"
#include "tarray.h"
#include "tfunctional.h"
...
...
source/libs/executor/src/tarithoperator.c
已删除
100644 → 0
浏览文件 @
bc82a32b
此差异已折叠。
点击以展开。
source/libs/
executor/inc/tarith
operator.h
→
source/libs/
function/inc/tbin
operator.h
浏览文件 @
59219933
...
...
@@ -13,20 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_COMMON_
QARITHMETIC
OPERATOR_H_
#define _TD_COMMON_
QARITHMETIC
OPERATOR_H_
#ifndef _TD_COMMON_
BIN_SCALAR_
OPERATOR_H_
#define _TD_COMMON_
BIN_SCALAR_
OPERATOR_H_
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
void
(
*
_arithmetic_operator_fn_t
)(
void
*
left
,
int32_t
numLeft
,
int32_t
leftType
,
void
*
right
,
int32_t
numRight
,
int32_t
rightType
,
void
*
output
,
int32_t
order
);
#include "tscalarfunction.h"
_arithmetic_operator_fn_t
getArithmeticOperatorFn
(
int32_t
arithmeticOptr
);
typedef
void
(
*
_bin_scalar_fn_t
)(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
void
*
output
,
int32_t
order
);
_bin_scalar_fn_t
getBinScalarOperatorFn
(
int32_t
binOperator
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_COMMON_
QARITHMETIC
OPERATOR_H_*/
#endif
/*_TD_COMMON_
BIN_SCALAR_
OPERATOR_H_*/
source/libs/function/inc/texpr.h
浏览文件 @
59219933
...
...
@@ -65,9 +65,6 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond);
bool
exprTreeApplyFilter
(
tExprNode
*
pExpr
,
const
void
*
pItem
,
SExprTraverseSupp
*
param
);
void
arithmeticTreeTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
char
*
(
*
cb
)(
void
*
,
const
char
*
,
int32_t
));
void
buildFilterSetFromBinary
(
void
**
q
,
const
char
*
buf
,
int32_t
len
);
#ifdef __cplusplus
...
...
source/libs/function/inc/tscalarfunction.h
浏览文件 @
59219933
...
...
@@ -21,14 +21,22 @@ extern "C" {
#include "function.h"
typedef
struct
SScalarFuncParam
{
void
*
data
;
int32_t
num
;
int32_t
type
;
int32_t
bytes
;
}
SScalarFuncParam
;
extern
struct
SScalarFunctionInfo
scalarFunc
[
1
];
#define FUNCTION_CEIL 38
#define FUNCTION_FLOOR 39
#define FUNCTION_ROUND 40
#define FUNCTION_MAVG 41
#define FUNCTION_CSUM 42
#define FUNCCTION_CONCAT 43
#define FUNCTION_CONCAT 41
int32_t
evaluateExprNodeTree
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
SScalarFuncParam
*
pOutput
,
void
*
param
,
char
*
(
*
getSourceDataBlock
)(
void
*
,
const
char
*
,
int32_t
));
#ifdef __cplusplus
}
...
...
source/libs/function/inc/tunaryoperator.h
0 → 100644
浏览文件 @
59219933
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_COMMON_UNARY_SCALAR_OPERATOR_H_
#define _TD_COMMON_UNARY_SCALAR_OPERATOR_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#include "tscalarfunction.h"
typedef
void
(
*
_unary_scalar_fn_t
)(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pOutput
);
_unary_scalar_fn_t
getUnaryScalarOperatorFn
(
int32_t
binOperator
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/
source/libs/function/src/taggfunction.c
浏览文件 @
59219933
...
...
@@ -3197,7 +3197,7 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
GET_RES_INFO
(
pCtx
)
->
numOfRes
+=
pCtx
->
size
;
SArithmeticSupport
*
sas
=
(
SArithmeticSupport
*
)
pCtx
->
param
[
1
].
pz
;
//
arithmeticTreeTravers
e(sas->pExprInfo->pExpr, pCtx->size, pCtx->pOutput, sas, pCtx->order, getArithColumnData);
//
evaluateExprNodeTre
e(sas->pExprInfo->pExpr, pCtx->size, pCtx->pOutput, sas, pCtx->order, getArithColumnData);
}
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
...
...
source/libs/function/src/tbinoperator.c
0 → 100644
浏览文件 @
59219933
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "ttypes.h"
#include "tbinoperator.h"
#include "tcompare.h"
//GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i]));
void
calc_i32_i32_add
(
void
*
left
,
void
*
right
,
int32_t
numLeft
,
int32_t
numRight
,
void
*
output
,
int32_t
order
)
{
int32_t
*
pLeft
=
(
int32_t
*
)
left
;
int32_t
*
pRight
=
(
int32_t
*
)
right
;
double
*
pOutput
=
(
double
*
)
output
;
int32_t
i
=
(
order
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
numLeft
,
numRight
)
-
1
;
int32_t
step
=
(
order
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
if
(
numLeft
==
numRight
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
if
(
isNull
((
char
*
)
&
(
pLeft
[
i
]),
TSDB_DATA_TYPE_INT
)
||
isNull
((
char
*
)
&
(
pRight
[
i
]),
TSDB_DATA_TYPE_INT
))
{
SET_DOUBLE_NULL
(
pOutput
);
continue
;
}
*
pOutput
=
(
double
)
pLeft
[
i
]
+
pRight
[
i
];
}
}
else
if
(
numLeft
==
1
)
{
for
(;
i
>=
0
&&
i
<
numRight
;
i
+=
step
,
pOutput
+=
1
)
{
if
(
isNull
((
char
*
)(
pLeft
),
TSDB_DATA_TYPE_INT
)
||
isNull
((
char
*
)
&
(
pRight
[
i
]),
TSDB_DATA_TYPE_INT
))
{
SET_DOUBLE_NULL
(
pOutput
);
continue
;
}
*
pOutput
=
(
double
)
pLeft
[
0
]
+
pRight
[
i
];
}
}
else
if
(
numRight
==
1
)
{
for
(;
i
>=
0
&&
i
<
numLeft
;
i
+=
step
,
pOutput
+=
1
)
{
if
(
isNull
((
char
*
)
&
(
pLeft
[
i
]),
TSDB_DATA_TYPE_INT
)
||
isNull
((
char
*
)(
pRight
),
TSDB_DATA_TYPE_INT
))
{
SET_DOUBLE_NULL
(
pOutput
);
continue
;
}
*
pOutput
=
(
double
)
pLeft
[
i
]
+
pRight
[
0
];
}
}
}
typedef
double
(
*
_getDoubleValue_fn_t
)(
void
*
src
,
int32_t
index
);
double
getVectorDoubleValue_TINYINT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
int8_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_UTINYINT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
uint8_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_SMALLINT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
int16_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_USMALLINT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
uint16_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_INT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
int32_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_UINT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
uint32_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_BIGINT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
int64_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_UBIGINT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
uint64_t
*
)
src
+
index
);
}
double
getVectorDoubleValue_FLOAT
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
float
*
)
src
+
index
);
}
double
getVectorDoubleValue_DOUBLE
(
void
*
src
,
int32_t
index
)
{
return
(
double
)
*
((
double
*
)
src
+
index
);
}
_getDoubleValue_fn_t
getVectorDoubleValueFn
(
int32_t
srcType
)
{
_getDoubleValue_fn_t
p
=
NULL
;
if
(
srcType
==
TSDB_DATA_TYPE_TINYINT
)
{
p
=
getVectorDoubleValue_TINYINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_UTINYINT
)
{
p
=
getVectorDoubleValue_UTINYINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_SMALLINT
)
{
p
=
getVectorDoubleValue_SMALLINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_USMALLINT
)
{
p
=
getVectorDoubleValue_USMALLINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_INT
)
{
p
=
getVectorDoubleValue_INT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_UINT
)
{
p
=
getVectorDoubleValue_UINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_BIGINT
)
{
p
=
getVectorDoubleValue_BIGINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_UBIGINT
)
{
p
=
getVectorDoubleValue_UBIGINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_FLOAT
)
{
p
=
getVectorDoubleValue_FLOAT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_DOUBLE
)
{
p
=
getVectorDoubleValue_DOUBLE
;
}
else
{
assert
(
0
);
}
return
p
;
}
typedef
void
*
(
*
_getValueAddr_fn_t
)(
void
*
src
,
int32_t
index
);
void
*
getVectorValueAddr_TINYINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
int8_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_UTINYINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
uint8_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_SMALLINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
int16_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_USMALLINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
uint16_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_INT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
int32_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_UINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
uint32_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_BIGINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
int64_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_UBIGINT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
uint64_t
*
)
src
+
index
);
}
void
*
getVectorValueAddr_FLOAT
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
float
*
)
src
+
index
);
}
void
*
getVectorValueAddr_DOUBLE
(
void
*
src
,
int32_t
index
)
{
return
(
void
*
)((
double
*
)
src
+
index
);
}
_getValueAddr_fn_t
getVectorValueAddrFn
(
int32_t
srcType
)
{
_getValueAddr_fn_t
p
=
NULL
;
if
(
srcType
==
TSDB_DATA_TYPE_TINYINT
)
{
p
=
getVectorValueAddr_TINYINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_UTINYINT
)
{
p
=
getVectorValueAddr_UTINYINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_SMALLINT
)
{
p
=
getVectorValueAddr_SMALLINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_USMALLINT
)
{
p
=
getVectorValueAddr_USMALLINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_INT
)
{
p
=
getVectorValueAddr_INT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_UINT
)
{
p
=
getVectorValueAddr_UINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_BIGINT
)
{
p
=
getVectorValueAddr_BIGINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_UBIGINT
)
{
p
=
getVectorValueAddr_UBIGINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_FLOAT
)
{
p
=
getVectorValueAddr_FLOAT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_DOUBLE
)
{
p
=
getVectorValueAddr_DOUBLE
;
}
else
{
assert
(
0
);
}
return
p
;
}
void
vectorAdd
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
double
*
output
=
(
double
*
)
out
;
_getValueAddr_fn_t
getVectorValueAddrFnLeft
=
getVectorValueAddrFn
(
pLeft
->
type
);
_getValueAddr_fn_t
getVectorValueAddrFnRight
=
getVectorValueAddrFn
(
pRight
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeft
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRight
->
type
);
if
(
pLeft
->
num
==
pRight
->
num
)
{
for
(;
i
<
pRight
->
num
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
+
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pLeft
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
0
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
0
)
+
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pRight
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
0
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
+
getVectorDoubleValueFnRight
(
pRight
->
data
,
0
));
}
}
}
void
vectorSub
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
double
*
output
=
(
double
*
)
out
;
_getValueAddr_fn_t
getVectorValueAddrFnLeft
=
getVectorValueAddrFn
(
pLeft
->
type
);
_getValueAddr_fn_t
getVectorValueAddrFnRight
=
getVectorValueAddrFn
(
pRight
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeft
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRight
->
type
);
if
(
pLeft
->
num
==
pRight
->
num
)
{
for
(;
i
<
pRight
->
num
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
-
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pLeft
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
0
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
0
)
-
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pRight
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
0
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
-
getVectorDoubleValueFnRight
(
pRight
->
data
,
0
));
}
}
}
void
vectorMultiply
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
double
*
output
=
(
double
*
)
out
;
_getValueAddr_fn_t
getVectorValueAddrFnLeft
=
getVectorValueAddrFn
(
pLeft
->
type
);
_getValueAddr_fn_t
getVectorValueAddrFnRight
=
getVectorValueAddrFn
(
pRight
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeft
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRight
->
type
);
if
(
pLeft
->
num
==
pRight
->
num
)
{
for
(;
i
<
pRight
->
num
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
*
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pLeft
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
0
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
0
)
*
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pRight
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
0
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
*
getVectorDoubleValueFnRight
(
pRight
->
data
,
0
));
}
}
}
void
vectorDivide
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
double
*
output
=
(
double
*
)
out
;
_getValueAddr_fn_t
getVectorValueAddrFnLeft
=
getVectorValueAddrFn
(
pLeft
->
type
);
_getValueAddr_fn_t
getVectorValueAddrFnRight
=
getVectorValueAddrFn
(
pRight
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeft
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRight
->
type
);
if
(
pLeft
->
num
==
pRight
->
num
)
{
for
(;
i
<
pRight
->
num
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
/
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pLeft
->
num
==
1
)
{
double
left
=
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
0
);
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
&
left
,
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
left
/
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
}
}
else
if
(
pRight
->
num
==
1
)
{
double
right
=
getVectorDoubleValueFnRight
(
pRight
->
data
,
0
);
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
&
right
,
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
SET_DOUBLE_VAL
(
output
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
/
right
);
}
}
}
void
vectorRemainder
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
double
*
output
=
(
double
*
)
out
;
_getValueAddr_fn_t
getVectorValueAddrFnLeft
=
getVectorValueAddrFn
(
pLeft
->
type
);
_getValueAddr_fn_t
getVectorValueAddrFnRight
=
getVectorValueAddrFn
(
pRight
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeft
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRight
->
type
);
if
(
pLeft
->
num
==
pRight
->
num
)
{
for
(;
i
<
pRight
->
num
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
double
v
,
u
=
0
.
0
;
GET_TYPED_DATA
(
v
,
double
,
pRight
->
type
,
getVectorValueAddrFnRight
(
pRight
->
data
,
i
));
if
(
getComparFunc
(
TSDB_DATA_TYPE_DOUBLE
,
0
)(
&
v
,
&
u
)
==
0
)
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
double
left
=
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
);
double
right
=
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
);
SET_DOUBLE_VAL
(
output
,
left
-
((
int64_t
)(
left
/
right
))
*
right
);
}
}
else
if
(
pLeft
->
num
==
1
)
{
double
left
=
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
0
);
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
&
left
,
pLeft
->
type
)
||
isNull
(
getVectorValueAddrFnRight
(
pRight
->
data
,
i
),
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
double
v
,
u
=
0
.
0
;
GET_TYPED_DATA
(
v
,
double
,
pRight
->
type
,
getVectorValueAddrFnRight
(
pRight
->
data
,
i
));
if
(
getComparFunc
(
TSDB_DATA_TYPE_DOUBLE
,
0
)(
&
v
,
&
u
)
==
0
)
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
double
right
=
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
);
SET_DOUBLE_VAL
(
output
,
left
-
((
int64_t
)(
left
/
right
))
*
right
);
}
}
else
if
(
pRight
->
num
==
1
)
{
double
right
=
getVectorDoubleValueFnRight
(
pRight
->
data
,
0
);
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
,
output
+=
1
)
{
if
(
isNull
(
getVectorValueAddrFnLeft
(
pLeft
->
data
,
i
),
pLeft
->
type
)
||
isNull
(
&
right
,
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
double
v
,
u
=
0
.
0
;
GET_TYPED_DATA
(
v
,
double
,
pRight
->
type
,
getVectorValueAddrFnRight
(
pRight
->
data
,
0
));
if
(
getComparFunc
(
TSDB_DATA_TYPE_DOUBLE
,
0
)(
&
v
,
&
u
)
==
0
)
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
double
left
=
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
);
SET_DOUBLE_VAL
(
output
,
left
-
((
int64_t
)(
left
/
right
))
*
right
);
}
}
}
void
vectorConcat
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
len
=
pLeft
->
bytes
+
pRight
->
bytes
;
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
MAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
char
*
output
=
(
char
*
)
out
;
if
(
pLeft
->
num
==
pRight
->
num
)
{
for
(;
i
<
pRight
->
num
&&
i
>=
0
;
i
+=
step
,
output
+=
len
)
{
char
*
left
=
POINTER_SHIFT
(
pLeft
->
data
,
pLeft
->
bytes
*
i
);
char
*
right
=
POINTER_SHIFT
(
pRight
->
data
,
pRight
->
bytes
*
i
);
if
(
isNull
(
left
,
pLeft
->
type
)
||
isNull
(
right
,
pRight
->
type
))
{
setVardataNull
(
output
,
TSDB_DATA_TYPE_BINARY
);
continue
;
}
// todo define a macro
memcpy
(
varDataVal
(
output
),
varDataVal
(
left
),
varDataLen
(
left
));
memcpy
(
varDataVal
(
output
)
+
varDataLen
(
left
),
varDataVal
(
right
),
varDataLen
(
right
));
varDataSetLen
(
output
,
varDataLen
(
left
)
+
varDataLen
(
right
));
}
}
else
if
(
pLeft
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
,
output
+=
len
)
{
char
*
right
=
POINTER_SHIFT
(
pRight
->
data
,
pRight
->
bytes
*
i
);
if
(
isNull
(
pLeft
->
data
,
pLeft
->
type
)
||
isNull
(
right
,
pRight
->
type
))
{
setVardataNull
(
output
,
TSDB_DATA_TYPE_BINARY
);
continue
;
}
memcpy
(
varDataVal
(
output
),
varDataVal
(
pLeft
->
data
),
varDataLen
(
pLeft
->
data
));
memcpy
(
varDataVal
(
output
)
+
varDataLen
(
pLeft
->
data
),
varDataVal
(
right
),
varDataLen
(
right
));
varDataSetLen
(
output
,
varDataLen
(
pLeft
->
data
)
+
varDataLen
(
right
));
}
}
else
if
(
pRight
->
num
==
1
)
{
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
,
output
+=
len
)
{
char
*
left
=
POINTER_SHIFT
(
pLeft
->
data
,
pLeft
->
bytes
*
i
);
if
(
isNull
(
left
,
pLeft
->
type
)
||
isNull
(
pRight
->
data
,
pRight
->
type
))
{
SET_DOUBLE_NULL
(
output
);
continue
;
}
memcpy
(
varDataVal
(
output
),
varDataVal
(
left
),
varDataLen
(
pRight
->
data
));
memcpy
(
varDataVal
(
output
)
+
varDataLen
(
left
),
varDataVal
(
pRight
->
data
),
varDataLen
(
pRight
->
data
));
varDataSetLen
(
output
,
varDataLen
(
left
)
+
varDataLen
(
pRight
->
data
));
}
}
}
_bin_scalar_fn_t
getBinScalarOperatorFn
(
int32_t
binFunctionId
)
{
switch
(
binFunctionId
)
{
case
TSDB_BINARY_OP_ADD
:
return
vectorAdd
;
case
TSDB_BINARY_OP_SUBTRACT
:
return
vectorSub
;
case
TSDB_BINARY_OP_MULTIPLY
:
return
vectorMultiply
;
case
TSDB_BINARY_OP_DIVIDE
:
return
vectorDivide
;
case
TSDB_BINARY_OP_REMAINDER
:
return
vectorRemainder
;
case
TSDB_BINARY_OP_CONCAT
:
return
vectorConcat
;
default:
assert
(
0
);
return
NULL
;
}
}
source/libs/function/src/texpr.c
浏览文件 @
59219933
...
...
@@ -25,7 +25,6 @@
#include "thash.h"
#include "tskiplist.h"
#include "texpr.h"
//#include "tarithoperator.h"
#include "tvariant.h"
//static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) {
...
...
@@ -41,71 +40,6 @@
// }
//}
static
void
reverseCopy
(
char
*
dest
,
const
char
*
src
,
int16_t
type
,
int32_t
numOfRows
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:{
int8_t
*
p
=
(
int8_t
*
)
dest
;
int8_t
*
pSrc
=
(
int8_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:{
int16_t
*
p
=
(
int16_t
*
)
dest
;
int16_t
*
pSrc
=
(
int16_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
{
int32_t
*
p
=
(
int32_t
*
)
dest
;
int32_t
*
pSrc
=
(
int32_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
{
int64_t
*
p
=
(
int64_t
*
)
dest
;
int64_t
*
pSrc
=
(
int64_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
dest
;
float
*
pSrc
=
(
float
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
dest
;
double
*
pSrc
=
(
double
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
default:
assert
(
0
);
}
}
static
void
doExprTreeDestroy
(
tExprNode
**
pExpr
,
void
(
*
fp
)(
void
*
));
void
tExprTreeDestroy
(
tExprNode
*
pNode
,
void
(
*
fp
)(
void
*
))
{
...
...
@@ -182,114 +116,7 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp
return
param
->
nodeFilterFn
(
pItem
,
pExpr
->
_node
.
info
);
}
void
arithmeticTreeTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
char
*
(
*
getSourceDataBlock
)(
void
*
,
const
char
*
,
int32_t
))
{
if
(
pExprs
==
NULL
)
{
return
;
}
#if 0
tExprNode *pLeft = pExprs->_node.pLeft;
tExprNode *pRight = pExprs->_node.pRight;
/* the left output has result from the left child syntax tree */
char *pLeftOutput = (char*)malloc(sizeof(int64_t) * numOfRows);
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE) {
arithmeticTreeTraverse(pLeft, numOfRows, pLeftOutput, param, order, getSourceDataBlock);
}
// the right output has result from the right child syntax tree
char *pRightOutput = malloc(sizeof(int64_t) * numOfRows);
char *pdata = malloc(sizeof(int64_t) * numOfRows);
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) {
arithmeticTreeTraverse(pRight, numOfRows, pRightOutput, param, order, getSourceDataBlock);
}
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE) {
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) {
/*
* exprLeft + exprRight
* the type of returned value of one expression is always double float precious
*/
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
} else if (pRight->nodeType == TEXPR_COL_NODE) { // exprLeft + columnRight
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
// set input buffer
char *pInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pdata, pInputData, pRight->pSchema->type, numOfRows);
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pdata, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
} else {
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pInputData, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
}
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // exprLeft + 12
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
}
} else if (pLeft->nodeType == TEXPR_COL_NODE) {
// column data specified on left-hand-side
char *pLeftInputData = getSourceDataBlock(param, pLeft->pSchema->name, pLeft->pSchema->colId);
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) { // columnLeft + expr2
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pdata, pLeftInputData, pLeft->pSchema->type, numOfRows);
OperatorFn(pdata, numOfRows, pLeft->pSchema->type, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
} else {
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
}
} else if (pRight->nodeType == TEXPR_COL_NODE) { // columnLeft + columnRight
// column data specified on right-hand-side
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
// both columns are descending order, do not reverse the source data
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, pRightInputData, numOfRows, pRight->pSchema->type, pOutput, order);
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // columnLeft + 12
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pdata, pLeftInputData, pLeft->pSchema->type, numOfRows);
OperatorFn(pdata, numOfRows, pLeft->pSchema->type, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
} else {
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
}
}
} else {
// column data specified on left-hand-side
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) { // 12 + expr2
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
} else if (pRight->nodeType == TEXPR_COL_NODE) { // 12 + columnRight
// column data specified on right-hand-side
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pdata, pRightInputData, pRight->pSchema->type, numOfRows);
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, pdata, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
} else {
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, pRightInputData, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
}
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // 12 + 12
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
}
}
tfree(pdata);
tfree(pLeftOutput);
tfree(pRightOutput);
#endif
}
static
void
exprTreeToBinaryImpl
(
SBufferWriter
*
bw
,
tExprNode
*
expr
)
{
tbufWriteUint8
(
bw
,
expr
->
nodeType
);
...
...
source/libs/function/src/tscalarfunction.c
浏览文件 @
59219933
#include "tscalarfunction.h"
#include "tbinoperator.h"
#include "tunaryoperator.h"
static
void
reverseCopy
(
char
*
dest
,
const
char
*
src
,
int16_t
type
,
int32_t
numOfRows
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:{
int8_t
*
p
=
(
int8_t
*
)
dest
;
int8_t
*
pSrc
=
(
int8_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:{
int16_t
*
p
=
(
int16_t
*
)
dest
;
int16_t
*
pSrc
=
(
int16_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
{
int32_t
*
p
=
(
int32_t
*
)
dest
;
int32_t
*
pSrc
=
(
int32_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
{
int64_t
*
p
=
(
int64_t
*
)
dest
;
int64_t
*
pSrc
=
(
int64_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
dest
;
float
*
pSrc
=
(
float
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
dest
;
double
*
pSrc
=
(
double
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
return
;
}
default:
assert
(
0
);
}
}
static
void
setScalarFuncParam
(
SScalarFuncParam
*
param
,
int32_t
type
,
int32_t
bytes
,
void
*
pInput
,
int32_t
numOfRows
)
{
param
->
bytes
=
bytes
;
param
->
type
=
type
;
param
->
num
=
numOfRows
;
param
->
data
=
pInput
;
}
int32_t
evaluateExprNodeTree
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
SScalarFuncParam
*
pOutput
,
void
*
param
,
char
*
(
*
getSourceDataBlock
)(
void
*
,
const
char
*
,
int32_t
))
{
if
(
pExprs
==
NULL
)
{
return
0
;
}
tExprNode
*
pLeft
=
pExprs
->
_node
.
pLeft
;
tExprNode
*
pRight
=
pExprs
->
_node
.
pRight
;
/* the left output has result from the left child syntax tree */
SScalarFuncParam
leftOutput
=
{
0
};
SScalarFuncParam
rightOutput
=
{
0
};
leftOutput
.
data
=
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
if
(
pLeft
->
nodeType
==
TEXPR_BINARYEXPR_NODE
||
pLeft
->
nodeType
==
TEXPR_UNARYEXPR_NODE
)
{
evaluateExprNodeTree
(
pLeft
,
numOfRows
,
&
leftOutput
,
param
,
getSourceDataBlock
);
}
// the right output has result from the right child syntax tree
rightOutput
.
data
=
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
if
(
pRight
->
nodeType
==
TEXPR_BINARYEXPR_NODE
)
{
evaluateExprNodeTree
(
pRight
,
numOfRows
,
&
rightOutput
,
param
,
getSourceDataBlock
);
}
if
(
pExprs
->
nodeType
==
TEXPR_BINARYEXPR_NODE
)
{
_bin_scalar_fn_t
OperatorFn
=
getBinScalarOperatorFn
(
pExprs
->
_node
.
optr
);
SScalarFuncParam
left
=
{
0
},
right
=
{
0
};
if
(
pLeft
->
nodeType
==
TEXPR_BINARYEXPR_NODE
||
pLeft
->
nodeType
==
TEXPR_UNARYEXPR_NODE
)
{
setScalarFuncParam
(
&
left
,
leftOutput
.
type
,
leftOutput
.
bytes
,
leftOutput
.
data
,
leftOutput
.
num
);
}
else
if
(
pLeft
->
nodeType
==
TEXPR_COL_NODE
)
{
SSchema
*
pschema
=
pLeft
->
pSchema
;
char
*
pLeftInputData
=
getSourceDataBlock
(
param
,
pschema
->
name
,
pschema
->
colId
);
setScalarFuncParam
(
&
right
,
pschema
->
type
,
pschema
->
bytes
,
pLeftInputData
,
numOfRows
);
}
else
if
(
pLeft
->
nodeType
==
TEXPR_VALUE_NODE
)
{
SVariant
*
pVar
=
pRight
->
pVal
;
setScalarFuncParam
(
&
left
,
pVar
->
nType
,
pVar
->
nLen
,
&
pVar
->
i
,
1
);
}
else
{
assert
(
0
);
}
if
(
pRight
->
nodeType
==
TEXPR_BINARYEXPR_NODE
||
pRight
->
nodeType
==
TEXPR_UNARYEXPR_NODE
)
{
setScalarFuncParam
(
&
right
,
rightOutput
.
type
,
rightOutput
.
bytes
,
rightOutput
.
data
,
rightOutput
.
num
);
}
else
if
(
pRight
->
nodeType
==
TEXPR_COL_NODE
)
{
// exprLeft + columnRight
SSchema
*
pschema
=
pRight
->
pSchema
;
char
*
pInputData
=
getSourceDataBlock
(
param
,
pschema
->
name
,
pschema
->
colId
);
setScalarFuncParam
(
&
right
,
pschema
->
type
,
pschema
->
bytes
,
pInputData
,
numOfRows
);
}
else
if
(
pRight
->
nodeType
==
TEXPR_VALUE_NODE
)
{
// exprLeft + 12
SVariant
*
pVar
=
pRight
->
pVal
;
setScalarFuncParam
(
&
right
,
pVar
->
nType
,
pVar
->
nLen
,
&
pVar
->
i
,
1
);
}
else
{
assert
(
0
);
}
OperatorFn
(
&
left
,
&
right
,
pOutput
->
data
,
TSDB_ORDER_ASC
);
// Set the result info
setScalarFuncParam
(
pOutput
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
),
pOutput
->
data
,
numOfRows
);
}
else
if
(
pExprs
->
nodeType
==
TEXPR_UNARYEXPR_NODE
)
{
_unary_scalar_fn_t
OperatorFn
=
getUnaryScalarOperatorFn
(
pExprs
->
_node
.
optr
);
SScalarFuncParam
left
=
{
0
};
if
(
pLeft
->
nodeType
==
TEXPR_BINARYEXPR_NODE
||
pLeft
->
nodeType
==
TEXPR_UNARYEXPR_NODE
)
{
setScalarFuncParam
(
&
left
,
leftOutput
.
type
,
leftOutput
.
bytes
,
leftOutput
.
data
,
leftOutput
.
num
);
}
else
if
(
pLeft
->
nodeType
==
TEXPR_COL_NODE
)
{
SSchema
*
pschema
=
pLeft
->
pSchema
;
char
*
pLeftInputData
=
getSourceDataBlock
(
param
,
pschema
->
name
,
pschema
->
colId
);
setScalarFuncParam
(
&
left
,
pschema
->
type
,
pschema
->
bytes
,
pLeftInputData
,
numOfRows
);
}
else
if
(
pLeft
->
nodeType
==
TEXPR_VALUE_NODE
)
{
SVariant
*
pVar
=
pLeft
->
pVal
;
setScalarFuncParam
(
&
left
,
pVar
->
nType
,
pVar
->
nLen
,
&
pVar
->
i
,
1
);
}
else
{
assert
(
0
);
}
OperatorFn
(
&
left
,
pOutput
);
}
tfree
(
leftOutput
.
data
);
tfree
(
rightOutput
.
data
);
return
0
;
}
SScalarFunctionInfo
scalarFunc
[
1
]
=
{
{
...
...
@@ -6,5 +167,3 @@ SScalarFunctionInfo scalarFunc[1] = {
},
};
source/libs/function/src/tunaryoperator.c
0 → 100644
浏览文件 @
59219933
#include "tunaryoperator.h"
static
void
assignBasicParaInfo
(
struct
SScalarFuncParam
*
dst
,
const
struct
SScalarFuncParam
*
src
)
{
dst
->
type
=
src
->
type
;
dst
->
bytes
=
src
->
bytes
;
dst
->
num
=
src
->
num
;
}
static
void
tceil
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pOutput
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
switch
(
pLeft
->
bytes
)
{
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
pLeft
->
data
;
float
*
out
=
(
float
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
ceilf
(
p
[
i
]);
}
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
pLeft
->
data
;
double
*
out
=
(
double
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
ceil
(
p
[
i
]);
}
}
default:
memcpy
(
pOutput
->
data
,
pLeft
->
data
,
pLeft
->
num
*
pLeft
->
bytes
);
}
}
static
void
tfloor
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pOutput
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
switch
(
pLeft
->
bytes
)
{
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
pLeft
->
data
;
float
*
out
=
(
float
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
floorf
(
p
[
i
]);
}
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
pLeft
->
data
;
double
*
out
=
(
double
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
floor
(
p
[
i
]);
}
}
default:
memcpy
(
pOutput
->
data
,
pLeft
->
data
,
pLeft
->
num
*
pLeft
->
bytes
);
}
}
static
void
_tabs
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pOutput
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
switch
(
pLeft
->
bytes
)
{
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
pLeft
->
data
;
float
*
out
=
(
float
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
(
p
[
i
]
>
0
)
?
p
[
i
]
:-
p
[
i
];
}
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
pLeft
->
data
;
double
*
out
=
(
double
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
(
p
[
i
]
>
0
)
?
p
[
i
]
:-
p
[
i
];
}
}
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
p
=
(
int8_t
*
)
pLeft
->
data
;
int8_t
*
out
=
(
int8_t
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
(
p
[
i
]
>
0
)
?
p
[
i
]
:-
p
[
i
];
}
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
p
=
(
int16_t
*
)
pLeft
->
data
;
int16_t
*
out
=
(
int16_t
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
(
p
[
i
]
>
0
)
?
p
[
i
]
:-
p
[
i
];
}
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
p
=
(
int32_t
*
)
pLeft
->
data
;
int32_t
*
out
=
(
int32_t
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
(
p
[
i
]
>
0
)
?
p
[
i
]
:-
p
[
i
];
}
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
p
=
(
int64_t
*
)
pLeft
->
data
;
int64_t
*
out
=
(
int64_t
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
(
p
[
i
]
>
0
)
?
p
[
i
]
:-
p
[
i
];
}
}
default:
memcpy
(
pOutput
->
data
,
pLeft
->
data
,
pLeft
->
num
*
pLeft
->
bytes
);
}
}
static
void
tround
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pOutput
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
switch
(
pLeft
->
bytes
)
{
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
pLeft
->
data
;
float
*
out
=
(
float
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
roundf
(
p
[
i
]);
}
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
pLeft
->
data
;
double
*
out
=
(
double
*
)
pOutput
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
round
(
p
[
i
]);
}
}
default:
memcpy
(
pOutput
->
data
,
pLeft
->
data
,
pLeft
->
num
*
pLeft
->
bytes
);
}
}
static
void
tlen
(
SScalarFuncParam
*
pLeft
,
SScalarFuncParam
*
pOutput
)
{
int64_t
*
out
=
(
int64_t
*
)
pOutput
->
data
;
char
*
s
=
pLeft
->
data
;
for
(
int32_t
i
=
0
;
i
<
pLeft
->
num
;
++
i
)
{
out
[
i
]
=
varDataLen
(
POINTER_SHIFT
(
s
,
i
*
pLeft
->
bytes
));
}
}
_unary_scalar_fn_t
getUnaryScalarOperatorFn
(
int32_t
operator
)
{
switch
(
operator
)
{
case
TSDB_UNARY_OP_CEIL
:
return
tceil
;
case
TSDB_UNARY_OP_FLOOR
:
return
tfloor
;
case
TSDB_UNARY_OP_ROUND
:
return
tround
;
case
TSDB_UNARY_OP_ABS
:
return
_tabs
;
case
TSDB_UNARY_OP_LEN
:
return
tlen
;
default:
assert
(
0
);
}
}
source/libs/parser/src/parserUtil.c
浏览文件 @
59219933
...
...
@@ -1175,14 +1175,6 @@ int32_t queryInfoCopy(SQueryStmtInfo* pQueryInfo, const SQueryStmtInfo* pSrc) {
goto
_error
;
}
// if (pQueryInfo->arithmeticOnAgg) {
// pQueryInfo->exprList1 = taosArrayInit(4, POINTER_BYTES);
// if (copyAllExprInfo(pQueryInfo->exprList1, pSrc->exprList1, true) != 0) {
// code = TSDB_CODE_TSC_OUT_OF_MEMORY;
// goto _error;
// }
// }
columnListCopyAll
(
pQueryInfo
->
colList
,
pSrc
->
colList
);
copyFieldInfo
(
&
pQueryInfo
->
fieldsInfo
,
&
pSrc
->
fieldsInfo
,
pQueryInfo
->
exprList
);
...
...
@@ -1615,9 +1607,9 @@ uint32_t convertRelationalOperator(SToken *pToken) {
return
TSDB_RELATION_OR
;
case
TK_EQ
:
return
TSDB_RELATION_EQUAL
;
case
TK_PLUS
:
return
TSDB_BINARY_OP_ADD
;
case
TK_MINUS
:
return
TSDB_BINARY_OP_SUBTRACT
;
case
TK_STAR
:
...
...
source/util/src/thash.c
浏览文件 @
59219933
...
...
@@ -16,6 +16,7 @@
#include "os.h"
#include "thash.h"
#include "ulog.h"
#include "taos.h"
#include "tdef.h"
#define EXT_SIZE 1024
...
...
source/util/src/thashutil.c
浏览文件 @
59219933
...
...
@@ -16,7 +16,7 @@
#include "os.h"
#include "thash.h"
#include "compare.h"
#include "t
def
.h"
#include "t
aos
.h"
#include "types.h"
#define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r)))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录