Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3bcd669f
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3bcd669f
编写于
7月 16, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add statecount function scalar version
上级
790cecf1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
152 addition
and
0 deletion
+152
-0
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+1
-0
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+150
-0
未找到文件。
include/libs/scalar/scalar.h
浏览文件 @
3bcd669f
...
...
@@ -114,6 +114,7 @@ int32_t mavgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam
int32_t
hllScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
csumScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
diffScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
stateCountScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
#ifdef __cplusplus
}
...
...
source/libs/function/src/builtins.c
浏览文件 @
3bcd669f
...
...
@@ -2419,6 +2419,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
getEnvFunc
=
getStateFuncEnv
,
.
initFunc
=
functionSetup
,
.
processFunc
=
stateCountFunction
,
.
sprocessFunc
=
stateCountScalarFunction
,
.
finalizeFunc
=
NULL
},
{
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
3bcd669f
...
...
@@ -2427,3 +2427,153 @@ int32_t hllScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
int32_t
csumScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
return
sumScalarFunction
(
pInput
,
inputNum
,
pOutput
);
}
typedef
enum
{
STATE_OPER_INVALID
=
0
,
STATE_OPER_LT
,
STATE_OPER_GT
,
STATE_OPER_LE
,
STATE_OPER_GE
,
STATE_OPER_NE
,
STATE_OPER_EQ
,
}
EStateOperType
;
#define STATE_COMP(_op, _lval, _rval, _rtype) STATE_COMP_IMPL(_op, _lval, GET_STATE_VAL(_rval, _rtype))
#define GET_STATE_VAL(_val, _type) ((_type == TSDB_DATA_TYPE_BIGINT) ? (*(int64_t *)_val) : (*(double *)_val))
#define STATE_COMP_IMPL(_op, _lval, _rval) \
do { \
switch (_op) { \
case STATE_OPER_LT: \
return ((_lval) < (_rval)); \
break; \
case STATE_OPER_GT: \
return ((_lval) > (_rval)); \
break; \
case STATE_OPER_LE: \
return ((_lval) <= (_rval)); \
break; \
case STATE_OPER_GE: \
return ((_lval) >= (_rval)); \
break; \
case STATE_OPER_NE: \
return ((_lval) != (_rval)); \
break; \
case STATE_OPER_EQ: \
return ((_lval) == (_rval)); \
break; \
default: \
break; \
} \
} while (0)
static
int8_t
getStateOpType
(
char
*
opStr
)
{
int8_t
opType
;
if
(
strcasecmp
(
opStr
,
"LT"
)
==
0
)
{
opType
=
STATE_OPER_LT
;
}
else
if
(
strcasecmp
(
opStr
,
"GT"
)
==
0
)
{
opType
=
STATE_OPER_GT
;
}
else
if
(
strcasecmp
(
opStr
,
"LE"
)
==
0
)
{
opType
=
STATE_OPER_LE
;
}
else
if
(
strcasecmp
(
opStr
,
"GE"
)
==
0
)
{
opType
=
STATE_OPER_GE
;
}
else
if
(
strcasecmp
(
opStr
,
"NE"
)
==
0
)
{
opType
=
STATE_OPER_NE
;
}
else
if
(
strcasecmp
(
opStr
,
"EQ"
)
==
0
)
{
opType
=
STATE_OPER_EQ
;
}
else
{
opType
=
STATE_OPER_INVALID
;
}
return
opType
;
}
static
bool
checkStateOp
(
int8_t
op
,
SColumnInfoData
*
pCol
,
int32_t
index
,
SScalarParam
*
pCondParam
)
{
char
*
data
=
colDataGetData
(
pCol
,
index
);
char
*
param
=
pCondParam
->
columnData
->
pData
;
int32_t
paramType
=
GET_PARAM_TYPE
(
pCondParam
);
switch
(
pCol
->
info
.
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
v
=
*
(
int8_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
uint8_t
v
=
*
(
uint8_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
v
=
*
(
int16_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
uint16_t
v
=
*
(
uint16_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
v
=
*
(
int32_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_UINT
:
{
uint32_t
v
=
*
(
uint32_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
v
=
*
(
int64_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
uint64_t
v
=
*
(
uint64_t
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
v
=
*
(
float
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
v
=
*
(
double
*
)
data
;
STATE_COMP
(
op
,
v
,
param
,
paramType
);
break
;
}
default:
{
ASSERT
(
0
);
}
}
return
false
;
}
int32_t
stateCountScalarFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
int8_t
op
=
getStateOpType
(
varDataVal
(
pInput
[
1
].
columnData
->
pData
));
int64_t
count
=
0
;
for
(
int32_t
i
=
0
;
i
<
pInput
->
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInputData
,
i
))
{
colDataAppendNULL
(
pOutputData
,
i
);
continue
;
}
bool
ret
=
checkStateOp
(
op
,
pInputData
,
i
,
&
pInput
[
2
]);
int64_t
out
=
-
1
;
if
(
ret
)
{
out
=
++
count
;
}
else
{
count
=
0
;
}
colDataAppend
(
pOutputData
,
i
,
(
char
*
)
&
out
,
false
);
}
pOutput
->
numOfRows
=
pInput
->
numOfRows
;
return
TSDB_CODE_SUCCESS
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录