Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
c0ea91ef
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看板
提交
c0ea91ef
编写于
11月 20, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2090]
上级
d7e8b4c1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
26 deletion
+39
-26
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+15
-20
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+5
-5
tests/script/general/parser/groupby.sim
tests/script/general/parser/groupby.sim
+19
-1
未找到文件。
src/client/src/tscFunctionImpl.c
浏览文件 @
c0ea91ef
...
...
@@ -130,11 +130,11 @@ typedef struct STopBotInfo {
}
STopBotInfo
;
// leastsquares do not apply to super table
typedef
struct
SLeastsquareInfo
{
typedef
struct
SLeastsquare
s
Info
{
double
mat
[
2
][
3
];
double
startVal
;
int64_t
num
;
}
SLeastsquareInfo
;
}
SLeastsquare
s
Info
;
typedef
struct
SAPercentileInfo
{
SHistogramInfo
*
pHisto
;
...
...
@@ -316,7 +316,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
*
interBytes
=
(
int16_t
)
sizeof
(
SPercentileInfo
);
}
else
if
(
functionId
==
TSDB_FUNC_LEASTSQR
)
{
*
type
=
TSDB_DATA_TYPE_BINARY
;
*
bytes
=
TSDB_AVG_FUNCTION_INTER_BUFFER_SIZE
;
// string
*
bytes
=
MAX
(
TSDB_AVG_FUNCTION_INTER_BUFFER_SIZE
,
sizeof
(
SLeastsquaresInfo
))
;
// string
*
interBytes
=
*
bytes
;
}
else
if
(
functionId
==
TSDB_FUNC_FIRST_DST
||
functionId
==
TSDB_FUNC_LAST_DST
)
{
*
type
=
TSDB_DATA_TYPE_BINARY
;
...
...
@@ -2756,7 +2756,7 @@ static bool leastsquares_function_setup(SQLFunctionCtx *pCtx) {
}
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SLeastsquareInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SLeastsquare
s
Info
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
// 2*3 matrix
pInfo
->
startVal
=
pCtx
->
param
[
0
].
dKey
;
...
...
@@ -2783,7 +2783,7 @@ static bool leastsquares_function_setup(SQLFunctionCtx *pCtx) {
static
void
leastsquares_function
(
SQLFunctionCtx
*
pCtx
)
{
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SLeastsquareInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SLeastsquare
s
Info
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
double
(
*
param
)[
3
]
=
pInfo
->
mat
;
double
x
=
pInfo
->
startVal
;
...
...
@@ -2853,40 +2853,40 @@ static void leastsquares_function_f(SQLFunctionCtx *pCtx, int32_t index) {
return
;
}
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SLeastsquareInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SLeastsquare
s
Info
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
double
(
*
param
)[
3
]
=
pInfo
->
mat
;
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
p
=
pData
;
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
index
,
pCtx
->
param
[
1
].
dKey
);
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
0
,
pCtx
->
param
[
1
].
dKey
);
break
;
};
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
p
=
pData
;
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
index
,
pCtx
->
param
[
1
].
dKey
);
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
0
,
pCtx
->
param
[
1
].
dKey
);
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
p
=
pData
;
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
index
,
pCtx
->
param
[
1
].
dKey
);
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
0
,
pCtx
->
param
[
1
].
dKey
);
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
p
=
pData
;
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
index
,
pCtx
->
param
[
1
].
dKey
);
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
0
,
pCtx
->
param
[
1
].
dKey
);
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
pData
;
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
index
,
pCtx
->
param
[
1
].
dKey
);
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
0
,
pCtx
->
param
[
1
].
dKey
);
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
pData
;
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
index
,
pCtx
->
param
[
1
].
dKey
);
LEASTSQR_CAL
(
param
,
pInfo
->
startVal
,
p
,
0
,
pCtx
->
param
[
1
].
dKey
);
break
;
}
default:
...
...
@@ -2904,15 +2904,10 @@ static void leastsquares_function_f(SQLFunctionCtx *pCtx, int32_t index) {
static
void
leastsquares_finalizer
(
SQLFunctionCtx
*
pCtx
)
{
// no data in query
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SLeastsquareInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SLeastsquare
s
Info
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
if
(
pInfo
->
num
==
0
)
{
if
(
pCtx
->
outputType
==
TSDB_DATA_TYPE_BINARY
||
pCtx
->
outputType
==
TSDB_DATA_TYPE_NCHAR
)
{
setVardataNull
(
pCtx
->
aOutputBuf
,
pCtx
->
outputType
);
}
else
{
setNull
(
pCtx
->
aOutputBuf
,
pCtx
->
outputType
,
pCtx
->
outputBytes
);
}
setNull
(
pCtx
->
aOutputBuf
,
pCtx
->
outputType
,
pCtx
->
outputBytes
);
return
;
}
...
...
src/query/src/qExecutor.c
浏览文件 @
c0ea91ef
...
...
@@ -1257,7 +1257,7 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx
return
QUERY_IS_ASC_QUERY
(
pQuery
);
}
//
todo add comments
//
denote the order type
if
((
functionId
==
TSDB_FUNC_LAST_DST
||
functionId
==
TSDB_FUNC_LAST
))
{
return
pCtx
->
param
[
0
].
i64Key
==
pQuery
->
order
.
order
;
}
...
...
@@ -2419,7 +2419,7 @@ static void ensureOutputBufferSimple(SQueryRuntimeEnv* pRuntimeEnv, int32_t capa
assert
(
bytes
>
0
&&
capacity
>
0
);
char
*
tmp
=
realloc
(
pQuery
->
sdata
[
i
],
bytes
*
capacity
+
sizeof
(
tFilePage
));
if
(
tmp
==
NULL
)
{
// todo handle the oom
if
(
tmp
==
NULL
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
else
{
pQuery
->
sdata
[
i
]
=
(
tFilePage
*
)
tmp
;
...
...
@@ -2450,7 +2450,7 @@ static void ensureOutputBuffer(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo* pB
assert
(
bytes
>
0
&&
newSize
>
0
);
char
*
tmp
=
realloc
(
pQuery
->
sdata
[
i
],
bytes
*
newSize
+
sizeof
(
tFilePage
));
if
(
tmp
==
NULL
)
{
// todo handle the oom
if
(
tmp
==
NULL
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
else
{
memset
(
tmp
+
sizeof
(
tFilePage
)
+
bytes
*
pRec
->
rows
,
0
,
(
size_t
)((
newSize
-
pRec
->
rows
)
*
bytes
));
...
...
@@ -3343,11 +3343,11 @@ void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SResultRow
*
pRow
=
NULL
;
if
(
pRuntimeEnv
->
windowResInfo
.
size
==
0
)
{
//
if (pRuntimeEnv->windowResInfo.size == 0) {
int32_t
groupIndex
=
0
;
int32_t
uid
=
0
;
pRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
(
char
*
)
&
groupIndex
,
sizeof
(
groupIndex
),
true
,
uid
);
}
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
i
];
...
...
tests/script/general/parser/groupby.sim
浏览文件 @
c0ea91ef
...
...
@@ -534,7 +534,7 @@ if $data03 != 99.000000000 then
endi
print ============>td-1765
sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0
group by c8;
sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0 group by c8;
if $rows != 100 then
return -1
endi
...
...
@@ -579,6 +579,24 @@ if $data14 != 2886.607004772 then
return -1
endi
print ================>td-2090
sql select leastsquares(c2, 1, 1) from group_tb1 group by c8;
if $rows != 100 then
return -1
endi
if $data00 != @{slop:0.000000, intercept:0.000000}@ then
return -1
endi
if $data10 != @{slop:0.000000, intercept:1.000000}@ then
return -1
endi
if $data90 != @{slop:0.000000, intercept:9.000000}@ then
return -1
endi
#=========================== group by multi tags ======================
sql create table st (ts timestamp, c int) tags (t1 int, t2 int, t3 int, t4 int);
sql create table t1 using st tags(1, 1, 1, 1);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录