Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b22fdf1
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
5b22fdf1
编写于
12月 04, 2020
作者:
H
haojun Liao
提交者:
GitHub
12月 04, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4442 from taosdata/feature/query
[TD-2236]<fix>: fix bugs in groupby normal colunms + last query
上级
991cbc7d
0fad15eb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
24 deletion
+83
-24
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+45
-24
tests/script/general/parser/groupby.sim
tests/script/general/parser/groupby.sim
+38
-0
未找到文件。
src/client/src/tscFunctionImpl.c
浏览文件 @
5b22fdf1
...
...
@@ -54,8 +54,8 @@
#define DO_UPDATE_TAG_COLUMNS(ctx, ts) \
do { \
for (int32_t
i = 0; i < (ctx)->tagInfo.numOfTagCols; ++
i) { \
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
for (int32_t
_i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_
i) { \
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[
_
i]; \
if (__ctx->functionId == TSDB_FUNC_TS_DUMMY) { \
__ctx->tag.i64Key = (ts); \
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
...
...
@@ -66,8 +66,8 @@
#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]; \
for (int32_t
_i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_
i) { \
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[
_
i]; \
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
} \
} while (0);
...
...
@@ -305,7 +305,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
}
else
if
(
functionId
==
TSDB_FUNC_FIRST
||
functionId
==
TSDB_FUNC_LAST
)
{
*
type
=
(
int16_t
)
dataType
;
*
bytes
=
(
int16_t
)
dataBytes
;
*
interBytes
=
dataBytes
;
*
interBytes
=
(
int16_t
)(
dataBytes
+
sizeof
(
SFirstLastInfo
))
;
}
else
if
(
functionId
==
TSDB_FUNC_SPREAD
)
{
*
type
=
(
int16_t
)
TSDB_DATA_TYPE_DOUBLE
;
*
bytes
=
sizeof
(
double
);
...
...
@@ -1169,8 +1169,8 @@ static int32_t minmax_merge_impl(SQLFunctionCtx *pCtx, int32_t bytes, char *outp
if
((
*
(
int32_t
*
)
output
<
v
)
^
isMin
)
{
*
(
int32_t
*
)
output
=
v
;
for
(
int32_t
i
=
0
;
i
<
pCtx
->
tagInfo
.
numOfTagCols
;
++
i
)
{
SQLFunctionCtx
*
__ctx
=
pCtx
->
tagInfo
.
pTagCtxList
[
i
];
for
(
int32_t
j
=
0
;
j
<
pCtx
->
tagInfo
.
numOfTagCols
;
++
j
)
{
SQLFunctionCtx
*
__ctx
=
pCtx
->
tagInfo
.
pTagCtxList
[
j
];
aAggs
[
TSDB_FUNC_TAG
].
xFunction
(
__ctx
);
}
...
...
@@ -1679,16 +1679,35 @@ static void last_function_f(SQLFunctionCtx *pCtx, int32_t index) {
if
(
pCtx
->
hasNull
&&
isNull
(
pData
,
pCtx
->
inputType
))
{
return
;
}
SET_VAL
(
pCtx
,
1
,
1
);
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
);
TSKEY
ts
=
pCtx
->
ptsList
[
index
];
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
ts
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
pResInfo
->
complete
=
true
;
// set query completed
// the scan order is not the required order, ignore it
if
(
pCtx
->
order
!=
pCtx
->
param
[
0
].
i64Key
)
{
return
;
}
if
(
pCtx
->
order
==
TSDB_ORDER_DESC
)
{
SET_VAL
(
pCtx
,
1
,
1
);
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
);
TSKEY
ts
=
pCtx
->
ptsList
[
index
];
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
ts
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
pResInfo
->
complete
=
true
;
// set query completed
}
else
{
// in case of ascending order check, all data needs to be checked
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
TSKEY
ts
=
pCtx
->
ptsList
[
index
];
char
*
buf
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pResInfo
->
hasResult
!=
DATA_SET_FLAG
||
(
*
(
TSKEY
*
)
buf
)
<
ts
)
{
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
);
*
(
TSKEY
*
)
buf
=
ts
;
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
ts
);
}
}
}
static
void
last_data_assign_impl
(
SQLFunctionCtx
*
pCtx
,
char
*
pData
,
int32_t
index
)
{
...
...
@@ -1711,7 +1730,7 @@ static void last_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t ind
static
void
last_dist_function
(
SQLFunctionCtx
*
pCtx
)
{
/*
* 1. for scan data i
n asc order, no need to check data
* 1. for scan data i
s not the required order
* 2. for data blocks that are not loaded, no need to check data
*/
if
(
pCtx
->
order
!=
pCtx
->
param
[
0
].
i64Key
)
{
...
...
@@ -2447,7 +2466,7 @@ static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
static
void
percentile_function
(
SQLFunctionCtx
*
pCtx
)
{
int32_t
notNullElems
=
0
;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
// the first stage, only acquire the min/max value
...
...
@@ -2548,12 +2567,14 @@ static void percentile_finalizer(SQLFunctionCtx *pCtx) {
double
v
=
pCtx
->
param
[
0
].
nType
==
TSDB_DATA_TYPE_INT
?
pCtx
->
param
[
0
].
i64Key
:
pCtx
->
param
[
0
].
dKey
;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
tMemBucket
*
pMemBucket
=
((
SPercentileInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
))
->
pMemBucket
;
if
(
pMemBucket
->
total
>
0
)
{
// check for null
*
(
double
*
)
pCtx
->
aOutputBuf
=
getPercentile
(
pMemBucket
,
v
);
}
else
{
SPercentileInfo
*
ppInfo
=
(
SPercentileInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
)
;
tMemBucket
*
pMemBucket
=
ppInfo
->
pMemBucket
;
if
(
pMemBucket
==
NULL
||
pMemBucket
->
total
==
0
)
{
// check for null
assert
(
ppInfo
->
numOfElems
==
0
);
setNull
(
pCtx
->
aOutputBuf
,
pCtx
->
outputType
,
pCtx
->
outputBytes
);
}
else
{
*
(
double
*
)
pCtx
->
aOutputBuf
=
getPercentile
(
pMemBucket
,
v
);
}
tMemBucketDestroy
(
pMemBucket
);
...
...
tests/script/general/parser/groupby.sim
浏览文件 @
5b22fdf1
...
...
@@ -606,6 +606,44 @@ sql insert into t1 values ('2020-03-27 04:21:16.000', 1)('2020-03-27 04:31:17.00
sql insert into t2 values ('2020-03-27 04:11:16.000', 1)('2020-03-27 04:11:17.000', 2) ('2020-03-27 04:11:18.000', 3) ('2020-03-27 04:11:19.000', 4) ;
sql insert into t2 values ('2020-03-27 04:21:16.000', 1)('2020-03-27 04:31:17.000', 2) ('2020-03-27 04:51:18.000', 3) ('2020-03-27 05:10:19.000', 4) ;
print =================>td-2236
sql select first(ts),last(ts) from t1 group by c;
if $rows != 4 then
return -1
endi
if $data00 != @20-03-27 04:11:16.000@ then
return -1
endi
if $data01 != @20-03-27 04:21:16.000@ then
return -1
endi
if $data10 != @20-03-27 04:11:17.000@ then
return -1
endi
if $data11 != @20-03-27 04:31:17.000@ then
return -1
endi
if $data20 != @20-03-27 04:11:18.000@ then
return -1
endi
if $data21 != @20-03-27 04:51:18.000@ then
return -1
endi
if $data30 != @20-03-27 04:11:19.000@ then
return -1
endi
if $data31 != @20-03-27 05:10:19.000@ then
return -1
endi
#sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2;
#if $rows != 40 then
# return -1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录