Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
78327d55
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
78327d55
编写于
9月 07, 2021
作者:
A
AlexDuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
client interface is done
上级
17d698c1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
15 deletion
+48
-15
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+26
-6
src/query/inc/qAggMain.h
src/query/inc/qAggMain.h
+4
-0
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+18
-9
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
78327d55
...
...
@@ -2457,6 +2457,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const
char
*
msg10
=
"derivative duration should be greater than 1 Second"
;
const
char
*
msg11
=
"third parameter in derivative should be 0 or 1"
;
const
char
*
msg12
=
"parameter is out of range [1, 100]"
;
const
char
*
msg13
=
"third parameter should be 0 or 1"
;
switch
(
functionId
)
{
case
TSDB_FUNC_COUNT
:
{
...
...
@@ -2790,8 +2791,16 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case
TSDB_FUNC_PERCT
:
case
TSDB_FUNC_APERCT
:
{
// 1. valid the number of parameters
if
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
||
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
2
)
{
/* no parameters or more than one parameter for function */
bool
valid
=
true
;
if
(
pItem
->
pNode
->
Expr
.
paramList
==
NULL
)
{
valid
=
false
;
}
else
if
(
functionId
==
TSDB_FUNC_APERCT
)
{
size_t
cnt
=
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
);
if
(
cnt
!=
2
&&
cnt
!=
3
)
valid
=
false
;
}
else
{
if
(
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
!=
2
)
valid
=
false
;
}
if
(
!
valid
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -2837,16 +2846,14 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
SExprInfo
*
pExpr
=
NULL
;
if
(
functionId
==
TSDB_FUNC_PERCT
||
functionId
==
TSDB_FUNC_APERCT
)
{
// param1 double
tVariantDump
(
pVariant
,
val
,
TSDB_DATA_TYPE_DOUBLE
,
true
);
double
dp
=
GET_DOUBLE_VAL
(
val
);
if
(
dp
<
0
||
dp
>
TOP_BOTTOM_QUERY_LIMIT
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
getResultDataInfo
(
pSchema
->
type
,
pSchema
->
bytes
,
functionId
,
0
,
&
resultType
,
&
resultSize
,
&
interResult
,
0
,
false
,
pUdfInfo
);
/*
* sql function transformation
* for dp = 0, it is actually min,
...
...
@@ -2854,9 +2861,22 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
*/
tscInsertPrimaryTsSourceColumn
(
pQueryInfo
,
pTableMetaInfo
->
pTableMeta
->
id
.
uid
);
colIndex
+=
1
;
// the first column is ts
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionId
,
&
index
,
resultType
,
resultSize
,
getNewResColId
(
pCmd
),
interResult
,
false
);
tscExprAddParams
(
&
pExpr
->
base
,
val
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
// param2 int32
if
(
taosArrayGetSize
(
pItem
->
pNode
->
Expr
.
paramList
)
==
3
)
{
if
(
pParamElem
[
2
].
pNode
!=
NULL
)
{
pVariant
=
&
pParamElem
[
2
].
pNode
->
value
;
tVariantDump
(
pVariant
,
val
,
TSDB_DATA_TYPE_INT
,
true
);
int32_t
algo
=
GET_INT32_VAL
(
val
);
if
(
algo
<
0
||
algo
>
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg13
);
}
tscExprAddParams
(
&
pExpr
->
base
,
val
,
TSDB_DATA_TYPE_INT
,
sizeof
(
int32_t
));
}
}
}
else
{
tVariantDump
(
pVariant
,
val
,
TSDB_DATA_TYPE_BIGINT
,
true
);
...
...
src/query/inc/qAggMain.h
浏览文件 @
78327d55
...
...
@@ -106,6 +106,10 @@ extern "C" {
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
#define TOP_BOTTOM_QUERY_LIMIT 100
// apercentile(arg1,agr2,arg3) param arg3 value is below:
#define ALGO_DEFAULT 0
#define ALGO_TDIGEST 1
enum
{
MASTER_SCAN
=
0x0u
,
REVERSE_SCAN
=
0x1u
,
...
...
src/query/src/qAggMain.c
浏览文件 @
78327d55
...
...
@@ -2451,7 +2451,7 @@ static bool tdigest_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo *pResultInfo)
// new TDigest
SAPercentileInfo
*
pAPerc
=
getAPerctInfo
(
pCtx
);
int
compression
=
5
;
int
compression
=
5
00
;
if
(
pAPerc
)
{
if
(
pAPerc
->
pTDigest
==
NULL
)
{
pAPerc
->
pTDigest
=
tdigestNew
(
compression
);
...
...
@@ -2486,7 +2486,7 @@ static void tdigest_do(SQLFunctionCtx *pCtx) {
tdigestAdd
(
pAPerc
->
pTDigest
,
v
,
w
);
}
tdigestCompress
(
pAPerc
->
pTDigest
);
//
tdigestCompress(pAPerc->pTDigest);
if
(
!
pCtx
->
hasNull
)
{
assert
(
pCtx
->
size
==
notNullElems
);
...
...
@@ -2519,7 +2519,7 @@ static void tdigest_finalizer(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
currentStage
==
MERGE_STAGE
)
{
if
(
pResInfo
->
hasResult
==
DATA_SET_FLAG
)
{
// check for null
double
res
=
tdigestQuantile
(
pAPerc
->
pTDigest
,
q
);
double
res
=
tdigestQuantile
(
pAPerc
->
pTDigest
,
q
/
100
);
memcpy
(
pCtx
->
pOutput
,
&
res
,
sizeof
(
double
));
}
else
{
setNull
(
pCtx
->
pOutput
,
pCtx
->
outputType
,
pCtx
->
outputBytes
);
...
...
@@ -2527,7 +2527,7 @@ static void tdigest_finalizer(SQLFunctionCtx *pCtx) {
}
}
else
{
if
(
pAPerc
->
pTDigest
->
size
>
0
)
{
double
res
=
tdigestQuantile
(
pAPerc
->
pTDigest
,
q
);
double
res
=
tdigestQuantile
(
pAPerc
->
pTDigest
,
q
/
100
);
memcpy
(
pCtx
->
pOutput
,
&
res
,
sizeof
(
double
));
}
else
{
// no need to free
setNull
(
pCtx
->
pOutput
,
pCtx
->
outputType
,
pCtx
->
outputBytes
);
...
...
@@ -2542,10 +2542,18 @@ static void tdigest_finalizer(SQLFunctionCtx *pCtx) {
}
//////////////////////////////////////////////////////////////////////////////////
int32_t
getAlgo
(
SQLFunctionCtx
*
pCtx
)
{
if
(
pCtx
->
numOfParams
!=
2
){
return
ALGO_DEFAULT
;
}
if
(
pCtx
->
param
[
1
].
nType
!=
TSDB_DATA_TYPE_INT
)
{
return
ALGO_DEFAULT
;
}
return
(
int32_t
)
pCtx
->
param
[
1
].
i64
;
}
int
algo
=
1
;
static
bool
apercentile_function_setup
(
SQLFunctionCtx
*
pCtx
,
SResultRowCellInfo
*
pResultInfo
)
{
if
(
algo
==
1
)
{
if
(
getAlgo
(
pCtx
)
==
ALGO_TDIGEST
)
{
return
tdigest_setup
(
pCtx
,
pResultInfo
);
}
...
...
@@ -2561,7 +2569,7 @@ static bool apercentile_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo
}
static
void
apercentile_function
(
SQLFunctionCtx
*
pCtx
)
{
if
(
algo
==
1
)
{
if
(
getAlgo
(
pCtx
)
==
ALGO_TDIGEST
)
{
tdigest_do
(
pCtx
);
return
;
}
...
...
@@ -2598,7 +2606,7 @@ static void apercentile_function(SQLFunctionCtx *pCtx) {
}
static
void
apercentile_func_merge
(
SQLFunctionCtx
*
pCtx
)
{
if
(
algo
==
1
)
{
if
(
getAlgo
(
pCtx
)
==
ALGO_TDIGEST
)
{
tdigest_merge
(
pCtx
);
return
;
}
...
...
@@ -2632,8 +2640,9 @@ static void apercentile_func_merge(SQLFunctionCtx *pCtx) {
SET_VAL
(
pCtx
,
1
,
1
);
}
static
void
apercentile_finalizer
(
SQLFunctionCtx
*
pCtx
)
{
if
(
algo
==
1
)
{
if
(
getAlgo
(
pCtx
)
==
ALGO_TDIGEST
)
{
tdigest_finalizer
(
pCtx
);
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录