Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
0e98a4ea
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0e98a4ea
编写于
11月 27, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2129]<fix>: fix bug in twa calculation.
上级
36b47a79
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
343 addition
and
68 deletion
+343
-68
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+40
-20
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+8
-3
src/query/inc/tsqlfunction.h
src/query/inc/tsqlfunction.h
+12
-7
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+282
-36
src/query/src/qUtil.c
src/query/src/qUtil.c
+1
-2
未找到文件。
src/client/src/tscFunctionImpl.c
浏览文件 @
0e98a4ea
...
...
@@ -64,13 +64,13 @@
} \
} while (0);
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
do {
\
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) {
\
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i];
\
aAggs[TSDB_FUNC_TAG].xFunction(__ctx);
\
} \
} while
(0);
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx)
\
do {
\
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) {
\
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
}
\
} while
(0);
void
noop1
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
))
{}
void
noop2
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
),
int32_t
UNUSED_PARAM
(
index
))
{}
...
...
@@ -3625,11 +3625,10 @@ static bool twa_function_setup(SQLFunctionCtx *pCtx) {
}
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
pInfo
->
lastKey
=
INT64_MIN
;
pInfo
->
type
=
pCtx
->
inputType
;
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
pInfo
->
lastKey
=
INT64_MIN
;
pInfo
->
win
=
TSWINDOW_INITIALIZER
;
return
true
;
}
...
...
@@ -3640,10 +3639,24 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t index, int32_t si
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pInfo
->
lastKey
==
INT64_MIN
)
{
pInfo
->
lastKey
=
pCtx
->
nStartQueryTimestamp
;
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
assert
(
pCtx
->
start
.
key
<
primaryKey
[
index
]
&&
pInfo
->
lastKey
==
INT64_MIN
);
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
));
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
start
.
val
)
/
2
)
*
(
primaryKey
[
index
]
-
pCtx
->
start
.
key
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
notNullElems
++
;
}
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
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pInfo
->
lastKey
;
notNullElems
++
;
}
...
...
@@ -3732,6 +3745,14 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t index, int32_t si
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
;
return
notNullElems
;
}
...
...
@@ -3751,7 +3772,7 @@ static void twa_function(SQLFunctionCtx *pCtx) {
return
;
}
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
0
,
pCtx
->
size
);
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
pCtx
->
startOffset
,
pCtx
->
size
);
SET_VAL
(
pCtx
,
notNullElems
,
1
);
if
(
notNullElems
>
0
)
{
...
...
@@ -3795,8 +3816,7 @@ static void twa_func_merge(SQLFunctionCtx *pCtx) {
numOfNotNull
++
;
pBuf
->
dOutput
+=
pInput
->
dOutput
;
pBuf
->
SKey
=
pInput
->
SKey
;
pBuf
->
EKey
=
pInput
->
EKey
;
pBuf
->
win
=
pInput
->
win
;
pBuf
->
lastKey
=
pInput
->
lastKey
;
}
...
...
@@ -3824,17 +3844,17 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) {
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
(
STwaInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
assert
(
pInfo
->
EKey
>
=
pInfo
->
lastKey
&&
pInfo
->
hasResult
==
pResInfo
->
hasResult
);
assert
(
pInfo
->
win
.
ekey
=
=
pInfo
->
lastKey
&&
pInfo
->
hasResult
==
pResInfo
->
hasResult
);
if
(
pInfo
->
hasResult
!=
DATA_SET_FLAG
)
{
setNull
(
pCtx
->
aOutputBuf
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
return
;
}
if
(
pInfo
->
SKey
==
pInfo
->
EK
ey
)
{
if
(
pInfo
->
win
.
ekey
==
pInfo
->
win
.
sk
ey
)
{
*
(
double
*
)
pCtx
->
aOutputBuf
=
pInfo
->
lastValue
;
}
else
{
*
(
double
*
)
pCtx
->
aOutputBuf
=
pInfo
->
dOutput
/
(
pInfo
->
EKey
-
pInfo
->
SK
ey
);
*
(
double
*
)
pCtx
->
aOutputBuf
=
pInfo
->
dOutput
/
(
pInfo
->
win
.
ekey
-
pInfo
->
win
.
sk
ey
);
}
GET_RES_INFO
(
pCtx
)
->
numOfRes
=
1
;
...
...
src/query/inc/qExecutor.h
浏览文件 @
0e98a4ea
...
...
@@ -63,9 +63,11 @@ typedef struct SSqlGroupbyExpr {
typedef
struct
SResultRow
{
int32_t
pageId
;
// pageId & rowId is the position of current result in disk-based output buffer
int32_t
rowId
:
15
;
bool
closed
:
1
;
// this result status: closed or opened
uint16_t
numOfRows
;
// number of rows of current time window
int32_t
rowId
:
29
;
// row index in buffer page
bool
startInterp
;
// the time window start timestamp has done the interpolation already.
bool
endInterp
;
// the time window end timestamp has done the interpolation already.
bool
closed
;
// this result status: closed or opened
uint32_t
numOfRows
;
// number of rows of current time window
SResultRowCellInfo
*
pCellInfo
;
// For each result column, there is a resultInfo
union
{
STimeWindow
win
;
char
*
key
;};
// start key of current time window
}
SResultRow
;
...
...
@@ -187,6 +189,7 @@ typedef struct SQueryRuntimeEnv {
bool
topBotQuery
;
// false
bool
groupbyNormalCol
;
// denote if this is a groupby normal column query
bool
hasTagResults
;
// if there are tag values in final result or not
bool
timeWindowInterpo
;
// if the time window start/end required interpolation
int32_t
interBufSize
;
// intermediate buffer sizse
int32_t
prevGroupId
;
// previous executed group id
SDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
...
...
@@ -195,6 +198,8 @@ typedef struct SQueryRuntimeEnv {
SResultRowPool
*
pool
;
// window result object pool
int32_t
*
rowCellInfoOffset
;
// offset value for each row result cell info
char
**
prevRow
;
char
**
nextRow
;
}
SQueryRuntimeEnv
;
enum
{
...
...
src/query/inc/tsqlfunction.h
浏览文件 @
0e98a4ea
...
...
@@ -152,6 +152,11 @@ typedef struct SResultRowCellInfo {
uint32_t
numOfRes
;
// num of output result in current buffer
}
SResultRowCellInfo
;
typedef
struct
SPoint1
{
int64_t
key
;
double
val
;
}
SPoint1
;
#define GET_ROWCELL_INTERBUF(_c) ((void*) ((char*)(_c) + sizeof(SResultRowCellInfo)))
struct
SQLFunctionCtx
;
...
...
@@ -194,6 +199,8 @@ typedef struct SQLFunctionCtx {
SResultRowCellInfo
*
resultInfo
;
SExtTagsInfo
tagInfo
;
SPoint1
start
;
SPoint1
end
;
}
SQLFunctionCtx
;
typedef
struct
SQLAggFuncElem
{
...
...
@@ -243,13 +250,11 @@ enum {
};
typedef
struct
STwaInfo
{
TSKEY
lastKey
;
int8_t
hasResult
;
// flag to denote has value
int16_t
type
;
// source data type
TSKEY
SKey
;
TSKEY
EKey
;
double
dOutput
;
double
lastValue
;
TSKEY
lastKey
;
int8_t
hasResult
;
// flag to denote has value
double
dOutput
;
double
lastValue
;
STimeWindow
win
;
}
STwaInfo
;
/* global sql function array */
...
...
src/query/src/qExecutor.c
浏览文件 @
0e98a4ea
此差异已折叠。
点击以展开。
src/query/src/qUtil.c
浏览文件 @
0e98a4ea
...
...
@@ -389,8 +389,7 @@ uint64_t getResultInfoUId(SQueryRuntimeEnv* pRuntimeEnv) {
}
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
((
pQuery
->
checkBuffer
==
1
&&
pQuery
->
interval
.
interval
==
0
)
||
isPointInterpoQuery
(
pQuery
)
||
pRuntimeEnv
->
groupbyNormalCol
)
{
if
(
pQuery
->
interval
.
interval
==
0
||
isPointInterpoQuery
(
pQuery
)
||
pRuntimeEnv
->
groupbyNormalCol
)
{
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录