Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yiicenne
TDengine
提交
dcb0bc49
TDengine
项目概览
yiicenne
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dcb0bc49
编写于
12月 01, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2129]
上级
ab1a8746
变更
2
展开全部
显示空白变更内容
内联
并排
Showing
2 changed file
with
391 addition
and
160 deletion
+391
-160
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+172
-46
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+219
-114
未找到文件。
src/client/src/tscFunctionImpl.c
浏览文件 @
dcb0bc49
...
...
@@ -426,8 +426,7 @@ static void count_function_f(SQLFunctionCtx *pCtx, int32_t index) {
}
SET_VAL
(
pCtx
,
1
,
1
);
*
((
int64_t
*
)
pCtx
->
aOutputBuf
)
+=
1
;
*
((
int64_t
*
)
pCtx
->
aOutputBuf
)
+=
pCtx
->
size
;
// do not need it actually
SResultRowCellInfo
*
pInfo
=
GET_RES_INFO
(
pCtx
);
...
...
@@ -3632,114 +3631,119 @@ static bool twa_function_setup(SQLFunctionCtx *pCtx) {
return
true
;
}
static
int32_t
twa_function_impl
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
,
int32_t
size
)
{
static
int32_t
twa_function_impl
(
SQLFunctionCtx
*
pCtx
,
int32_t
tsIndex
,
int32_t
index
,
int32_t
size
)
{
int32_t
notNullElems
=
0
;
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
i
=
index
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pCtx
->
order
);
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
assert
(
pCtx
->
start
.
key
<
primaryKey
[
index
]
&&
pInfo
->
lastKey
==
INT64_MIN
);
assert
((
pCtx
->
start
.
key
<
primaryKey
[
tsIndex
+
i
]
&&
pCtx
->
order
==
TSDB_ORDER_ASC
)
||
(
pCtx
->
start
.
key
>
primaryKey
[
tsIndex
+
i
]
&&
pCtx
->
order
==
TSDB_ORDER_DESC
));
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
));
assert
(
pInfo
->
lastKey
==
INT64_MIN
);
pInfo
->
lastKey
=
primaryKey
[
tsIndex
+
i
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
start
.
val
)
/
2
)
*
(
pInfo
->
lastKey
-
pCtx
->
start
.
key
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
notNullElems
++
;
i
+=
1
;
i
+=
step
;
}
else
if
(
pInfo
->
lastKey
==
INT64_MIN
)
{
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
));
pInfo
->
lastKey
=
primaryKey
[
tsIndex
+
i
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pInfo
->
lastKey
;
notNullElems
++
;
i
+=
1
;
i
+=
step
;
}
// calculate the value of
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
val
=
(
int8_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int8_t
*
val
=
(
int8_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
val
=
(
int16_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int16_t
*
val
=
(
int16_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
val
=
(
int32_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int32_t
*
val
=
(
int32_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
val
=
(
int64_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int64_t
*
val
=
(
int64_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
(
double
)
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
val
=
(
float
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
float
*
val
=
(
float
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
val
=
(
double
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
double
*
val
=
(
double
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
...
...
@@ -3764,16 +3768,13 @@ static void twa_function(SQLFunctionCtx *pCtx) {
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
// skip null value
int32_t
i
=
0
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pCtx
->
order
);
int32_t
i
=
(
pCtx
->
order
==
TSDB_ORDER_ASC
)
?
0
:
(
pCtx
->
size
-
1
);
while
(
pCtx
->
hasNull
&&
i
<
pCtx
->
size
&&
isNull
((
char
*
)
data
+
pCtx
->
inputBytes
*
i
,
pCtx
->
inputType
))
{
i
++
;
i
+=
step
;
}
if
(
i
>=
pCtx
->
size
)
{
return
;
}
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
pCtx
->
startOffset
,
pCtx
->
size
);
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
pCtx
->
startOffset
,
i
,
pCtx
->
size
);
SET_VAL
(
pCtx
,
notNullElems
,
1
);
if
(
notNullElems
>
0
)
{
...
...
@@ -3791,11 +3792,136 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
return
;
}
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
index
,
1
);
int32_t
notNullElems
=
0
;
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
i
=
pCtx
->
startOffset
;
int32_t
size
=
pCtx
->
size
;
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
assert
(
pInfo
->
lastKey
==
INT64_MIN
);
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
start
.
val
)
/
2
)
*
(
pInfo
->
lastKey
-
pCtx
->
start
.
key
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
notNullElems
++
;
i
+=
1
;
}
else
if
(
pInfo
->
lastKey
==
INT64_MIN
)
{
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pInfo
->
lastKey
;
notNullElems
++
;
i
+=
1
;
}
// calculate the value of
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
val
=
(
int8_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
val
=
(
int16_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
val
=
(
int32_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
val
=
(
int64_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
(
double
)
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
val
=
(
float
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
val
=
(
double
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
default:
assert
(
0
);
}
// the last interpolated time window value
if
(
pCtx
->
end
.
key
!=
INT64_MIN
)
{
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
end
.
val
)
/
2
)
*
(
pCtx
->
end
.
key
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
pCtx
->
end
.
val
;
pInfo
->
lastKey
=
pCtx
->
end
.
key
;
}
pInfo
->
win
.
ekey
=
pInfo
->
lastKey
;
SET_VAL
(
pCtx
,
notNullElems
,
1
);
if
(
notNullElems
>
0
)
{
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
}
if
(
pCtx
->
stableQuery
)
{
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
memcpy
(
pCtx
->
aOutputBuf
,
GET_ROWCELL_INTERBUF
(
pResInfo
),
sizeof
(
STwaInfo
));
}
}
...
...
src/query/src/qExecutor.c
浏览文件 @
dcb0bc49
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录