Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6c90a198
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
6c90a198
编写于
3月 17, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support the interpolation search for interval query
上级
2fc2fb16
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
497 addition
and
123 deletion
+497
-123
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+146
-57
src/inc/tinterpolation.h
src/inc/tinterpolation.h
+2
-0
src/inc/tsqlfunction.h
src/inc/tsqlfunction.h
+3
-3
src/system/detail/inc/vnodeRead.h
src/system/detail/inc/vnodeRead.h
+4
-7
src/system/detail/src/vnodeQueryImpl.c
src/system/detail/src/vnodeQueryImpl.c
+299
-56
src/util/src/tinterpolation.c
src/util/src/tinterpolation.c
+43
-0
未找到文件。
src/client/src/tscFunctionImpl.c
浏览文件 @
6c90a198
...
...
@@ -20,6 +20,7 @@
#include "thistogram.h"
#include "tinterpolation.h"
#include "tlog.h"
#include "tpercentile.h"
#include "tscJoinProcess.h"
#include "tscSyntaxtreefunction.h"
#include "tscompression.h"
...
...
@@ -27,7 +28,6 @@
#include "ttime.h"
#include "ttypes.h"
#include "tutil.h"
#include "tpercentile.h"
#define GET_INPUT_CHAR(x) (((char *)((x)->aInputElemBuf)) + ((x)->startOffset) * ((x)->inputBytes))
#define GET_INPUT_CHAR_INDEX(x, y) (GET_INPUT_CHAR(x) + (y) * (x)->inputBytes)
...
...
@@ -4104,8 +4104,6 @@ static void twa_function(SQLFunctionCtx *pCtx) {
if
(
pResInfo
->
superTableQ
)
{
memcpy
(
pCtx
->
aOutputBuf
,
pInfo
,
sizeof
(
STwaInfo
));
}
// pCtx->numOfIteratedElems += notNullElems;
}
static
void
twa_function_f
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
)
{
...
...
@@ -4138,7 +4136,6 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
pInfo
->
lastKey
=
primaryKey
[
index
];
setTWALastVal
(
pCtx
,
pData
,
0
,
pInfo
);
// pCtx->numOfIteratedElems += 1;
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
if
(
pResInfo
->
superTableQ
)
{
...
...
@@ -4403,10 +4400,8 @@ static double do_calc_rate(const SRateInfo* pRateInfo) {
}
}
int64_t
duration
=
pRateInfo
->
lastKey
-
pRateInfo
->
firstKey
;
duration
=
(
duration
+
500
)
/
1000
;
double
resultVal
=
((
double
)
diff
)
/
duration
;
double
duration
=
(
pRateInfo
->
lastKey
-
pRateInfo
->
firstKey
)
/
1000
;
double
resultVal
=
diff
/
duration
;
pTrace
(
"do_calc_rate() isIRate:%d firstKey:%"
PRId64
" lastKey:%"
PRId64
" firstValue:%f lastValue:%f CorrectionValue:%f resultVal:%f"
,
pRateInfo
->
isIRate
,
pRateInfo
->
firstKey
,
pRateInfo
->
lastKey
,
pRateInfo
->
firstValue
,
pRateInfo
->
lastValue
,
pRateInfo
->
CorrectionValue
,
resultVal
);
...
...
@@ -4447,62 +4442,156 @@ static void rate_function(SQLFunctionCtx *pCtx) {
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
pTrace
(
"%p rate_function() size:%d, hasNull:%d"
,
pCtx
,
pCtx
->
size
,
pCtx
->
hasNull
);
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
char
*
pData
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
if
(
pCtx
->
hasNull
&&
isNull
(
pData
,
pCtx
->
inputType
))
{
pTrace
(
"%p rate_function() index of null data:%d"
,
pCtx
,
i
);
continue
;
if
(
pCtx
->
order
==
TSQL_SO_ASC
)
{
// prev interpolation exists
if
(
pCtx
->
prev
.
key
!=
-
1
)
{
pRateInfo
->
firstValue
=
pCtx
->
prev
.
data
;
pRateInfo
->
firstKey
=
pCtx
->
prev
.
key
;
pCtx
->
prev
.
key
=
-
1
;
// clear the flag
}
notNullElems
++
;
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
char
*
pData
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
if
(
pCtx
->
hasNull
&&
isNull
(
pData
,
pCtx
->
inputType
))
{
pTrace
(
"%p rate_function() index of null data:%d"
,
pCtx
,
i
);
continue
;
}
double
v
=
0
;
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
v
=
(
double
)
GET_INT8_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
v
=
(
double
)
GET_INT16_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_INT
:
v
=
(
double
)
GET_INT32_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
v
=
(
double
)
GET_INT64_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
v
=
(
double
)
GET_FLOAT_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
v
=
(
double
)
GET_DOUBLE_VAL
(
pData
);
break
;
default:
assert
(
0
);
notNullElems
++
;
double
v
=
0
;
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
v
=
(
double
)
GET_INT8_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
v
=
(
double
)
GET_INT16_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_INT
:
v
=
(
double
)
GET_INT32_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
v
=
(
double
)
GET_INT64_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
v
=
(
double
)
GET_FLOAT_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
v
=
(
double
)
GET_DOUBLE_VAL
(
pData
);
break
;
default:
assert
(
0
);
}
if
((
-
DBL_MAX
==
pRateInfo
->
firstValue
)
||
(
INT64_MIN
==
pRateInfo
->
firstKey
))
{
pRateInfo
->
firstValue
=
v
;
pRateInfo
->
firstKey
=
primaryKey
[
i
];
pTrace
(
"firstValue:%f firstKey:%"
PRId64
,
pRateInfo
->
firstValue
,
pRateInfo
->
firstKey
);
}
if
(
-
DBL_MAX
==
pRateInfo
->
lastValue
)
{
pRateInfo
->
lastValue
=
v
;
}
else
if
(
v
<
pRateInfo
->
lastValue
)
{
pRateInfo
->
CorrectionValue
+=
pRateInfo
->
lastValue
;
pTrace
(
"CorrectionValue:%f"
,
pRateInfo
->
CorrectionValue
);
}
pRateInfo
->
lastValue
=
v
;
pRateInfo
->
lastKey
=
primaryKey
[
i
];
pTrace
(
"lastValue:%f lastKey:%"
PRId64
,
pRateInfo
->
lastValue
,
pRateInfo
->
lastKey
);
}
if
((
-
DBL_MAX
==
pRateInfo
->
firstValue
)
||
(
INT64_MIN
==
pRateInfo
->
firstKey
))
{
pRateInfo
->
firstValue
=
v
;
pRateInfo
->
firstKey
=
primaryKey
[
i
];
if
(
!
pCtx
->
hasNull
)
{
assert
(
pCtx
->
size
==
notNullElems
);
}
if
(
pCtx
->
next
.
key
!=
-
1
)
{
if
(
pCtx
->
next
.
data
<
pRateInfo
->
lastValue
)
{
pRateInfo
->
CorrectionValue
+=
pRateInfo
->
lastValue
;
pTrace
(
"CorrectionValue:%f"
,
pRateInfo
->
CorrectionValue
);
}
pRateInfo
->
lastValue
=
pCtx
->
next
.
data
;
pRateInfo
->
lastKey
=
pCtx
->
next
.
key
;
pCtx
->
next
.
key
=
-
1
;
}
}
else
{
if
(
pCtx
->
next
.
key
!=
-
1
)
{
pRateInfo
->
lastValue
=
pCtx
->
next
.
data
;
pRateInfo
->
lastKey
=
pCtx
->
next
.
key
;
pCtx
->
next
.
key
=
-
1
;
}
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
char
*
pData
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
if
(
pCtx
->
hasNull
&&
isNull
(
pData
,
pCtx
->
inputType
))
{
pTrace
(
"%p rate_function() index of null data:%d"
,
pCtx
,
i
);
continue
;
}
notNullElems
++
;
double
v
=
0
;
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
v
=
(
double
)
GET_INT8_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
v
=
(
double
)
GET_INT16_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_INT
:
v
=
(
double
)
GET_INT32_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
v
=
(
double
)
GET_INT64_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
v
=
(
double
)
GET_FLOAT_VAL
(
pData
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
v
=
(
double
)
GET_DOUBLE_VAL
(
pData
);
break
;
default:
assert
(
0
);
}
if
((
-
DBL_MAX
==
pRateInfo
->
lastValue
)
||
(
INT64_MIN
==
pRateInfo
->
lastKey
))
{
pRateInfo
->
lastValue
=
v
;
pRateInfo
->
lastKey
=
primaryKey
[
i
];
pTrace
(
"firstValue:%f firstKey:%"
PRId64
,
pRateInfo
->
lastValue
,
pRateInfo
->
lastKey
);
}
if
(
-
DBL_MAX
==
pRateInfo
->
firstValue
)
{
pRateInfo
->
firstValue
=
v
;
}
else
if
(
v
>
pRateInfo
->
firstValue
)
{
pRateInfo
->
CorrectionValue
+=
pRateInfo
->
firstValue
;
pTrace
(
"CorrectionValue:%f"
,
pRateInfo
->
CorrectionValue
);
}
pRateInfo
->
firstValue
=
v
;
pRateInfo
->
firstKey
=
primaryKey
[
i
];
pTrace
(
"firstValue:%f firstKey:%"
PRId64
,
pRateInfo
->
firstValue
,
pRateInfo
->
firstKey
);
}
if
(
-
DBL_MAX
==
pRateInfo
->
lastValue
)
{
pRateInfo
->
lastValue
=
v
;
}
else
if
(
v
<
pRateInfo
->
lastValue
)
{
pRateInfo
->
CorrectionValue
+=
pRateInfo
->
lastValue
;
pTrace
(
"CorrectionValue:%f"
,
pRateInfo
->
CorrectionValue
);
if
(
!
pCtx
->
hasNull
)
{
assert
(
pCtx
->
size
==
notNullElems
);
}
pRateInfo
->
lastValue
=
v
;
pRateInfo
->
lastKey
=
primaryKey
[
i
];
pTrace
(
"lastValue:%f lastKey:%"
PRId64
,
pRateInfo
->
lastValue
,
pRateInfo
->
lastKey
);
}
if
(
!
pCtx
->
hasNull
)
{
assert
(
pCtx
->
size
==
notNullElems
);
}
if
(
pCtx
->
prev
.
key
!=
-
1
)
{
if
(
pCtx
->
prev
.
data
>
pRateInfo
->
firstValue
)
{
pRateInfo
->
CorrectionValue
+=
pRateInfo
->
firstValue
;
pTrace
(
"CorrectionValue:%f"
,
pRateInfo
->
CorrectionValue
);
}
pRateInfo
->
firstValue
=
pCtx
->
prev
.
data
;
pRateInfo
->
firstKey
=
pCtx
->
prev
.
key
;
pCtx
->
prev
.
key
=
-
1
;
}
};
SET_VAL
(
pCtx
,
notNullElems
,
1
);
...
...
src/inc/tinterpolation.h
浏览文件 @
6c90a198
...
...
@@ -83,6 +83,8 @@ int32_t taosDoInterpoResult(SInterpolationInfo *pInterpoInfo, int16_t interpoTyp
int
taosDoLinearInterpolation
(
int32_t
type
,
SPoint
*
point1
,
SPoint
*
point2
,
SPoint
*
point
);
int
taosDoLinearInterpolationD
(
int32_t
type
,
SPoint
*
point1
,
SPoint
*
point2
,
SPoint
*
point
);
#ifdef __cplusplus
}
#endif
...
...
src/inc/tsqlfunction.h
浏览文件 @
6c90a198
...
...
@@ -169,7 +169,7 @@ typedef struct SExtTagsInfo {
typedef
struct
SBoundaryData
{
TSKEY
key
;
char
*
data
;
double
data
;
}
SBoundaryData
;
// sql function runtime context
...
...
@@ -200,8 +200,8 @@ typedef struct SQLFunctionCtx {
SResultInfo
*
resultInfo
;
SExtTagsInfo
tagInfo
;
SBoundaryData
beforeRow
;
// this value may be less or equalled to the start time of time window
SBoundaryData
afterRow
;
// this value may be greater or equalled to the end time of time window
SBoundaryData
prev
;
// this value may be less or equalled to the start time of time window
SBoundaryData
next
;
// this value may be greater or equalled to the end time of time window
}
SQLFunctionCtx
;
typedef
struct
SQLAggFuncElem
{
...
...
src/system/detail/inc/vnodeRead.h
浏览文件 @
6c90a198
...
...
@@ -172,15 +172,16 @@ typedef struct SQueryRuntimeEnv {
SWindowResInfo
windowResInfo
;
// require time stamp that are direct before/after query time window
bool
boundaryExternalTS
;
STSBuf
*
pTSBuf
;
STSCursor
cur
;
SQueryCostSummary
summary
;
bool
stableQuery
;
// is super table query or not
SQueryDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
bool
hasTimeWindow
;
char
**
lastRowInBlock
;
bool
interpoSearch
;
/*
* Temporarily hold the in-memory cache block info during scan cache blocks
* Here we do not use the cache block info from pMeterObj, simple because it may change anytime
...
...
@@ -188,10 +189,6 @@ typedef struct SQueryRuntimeEnv {
* So we keep a copy of the support structure as well as the cache block data itself.
*/
SCacheBlock
cacheBlock
;
SPointInterpoSupporter
*
pInterpoSupporter
;
bool
hasTimeWindow
;
bool
interpoSearch
;
}
SQueryRuntimeEnv
;
/* intermediate pos during multimeter query involves interval */
...
...
src/system/detail/src/vnodeQueryImpl.c
浏览文件 @
6c90a198
此差异已折叠。
点击以展开。
src/util/src/tinterpolation.c
浏览文件 @
6c90a198
...
...
@@ -191,6 +191,49 @@ int taosDoLinearInterpolation(int32_t type, SPoint* point1, SPoint* point2, SPoi
return
0
;
}
int
taosDoLinearInterpolationD
(
int32_t
type
,
SPoint
*
point1
,
SPoint
*
point2
,
SPoint
*
point
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_INT
:
{
*
(
double
*
)
point
->
val
=
doLinearInterpolationImpl
(
*
(
int32_t
*
)
point1
->
val
,
*
(
int32_t
*
)
point2
->
val
,
point1
->
key
,
point2
->
key
,
point
->
key
);
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
*
(
double
*
)
point
->
val
=
doLinearInterpolationImpl
(
*
(
float
*
)
point1
->
val
,
*
(
float
*
)
point2
->
val
,
point1
->
key
,
point2
->
key
,
point
->
key
);
break
;
};
case
TSDB_DATA_TYPE_DOUBLE
:
{
*
(
double
*
)
point
->
val
=
doLinearInterpolationImpl
(
*
(
double
*
)
point1
->
val
,
*
(
double
*
)
point2
->
val
,
point1
->
key
,
point2
->
key
,
point
->
key
);
break
;
};
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_BIGINT
:
{
*
(
double
*
)
point
->
val
=
doLinearInterpolationImpl
(
*
(
int64_t
*
)
point1
->
val
,
*
(
int64_t
*
)
point2
->
val
,
point1
->
key
,
point2
->
key
,
point
->
key
);
break
;
};
case
TSDB_DATA_TYPE_SMALLINT
:
{
*
(
double
*
)
point
->
val
=
doLinearInterpolationImpl
(
*
(
int16_t
*
)
point1
->
val
,
*
(
int16_t
*
)
point2
->
val
,
point1
->
key
,
point2
->
key
,
point
->
key
);
break
;
};
case
TSDB_DATA_TYPE_TINYINT
:
{
*
(
double
*
)
point
->
val
=
doLinearInterpolationImpl
(
*
(
int8_t
*
)
point1
->
val
,
*
(
int8_t
*
)
point2
->
val
,
point1
->
key
,
point2
->
key
,
point
->
key
);
break
;
};
default:
{
// TODO: Deal with interpolation with bool and strings and timestamp
return
-
1
;
}
}
return
0
;
}
static
char
*
getPos
(
char
*
data
,
int32_t
bytes
,
int32_t
index
)
{
return
data
+
index
*
bytes
;
}
static
void
setTagsValueInInterpolation
(
tFilePage
**
data
,
char
**
pTags
,
SColumnModel
*
pModel
,
int32_t
order
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录