Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e9673320
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e9673320
编写于
8月 31, 2020
作者:
B
Bomin Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
td-1099: natual interval in stream and bug fix
上级
1afed4c0
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
149 addition
and
80 deletion
+149
-80
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+3
-1
src/client/src/tscProfile.c
src/client/src/tscProfile.c
+2
-2
src/client/src/tscStream.c
src/client/src/tscStream.c
+59
-41
src/common/inc/tname.h
src/common/inc/tname.h
+2
-0
src/common/src/tname.c
src/common/src/tname.c
+56
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+5
-32
src/query/src/qFill.c
src/query/src/qFill.c
+22
-4
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
e9673320
...
...
@@ -367,6 +367,8 @@ typedef struct SSqlStream {
uint32_t
streamId
;
char
listed
;
bool
isProject
;
char
intervalTimeUnit
;
char
slidingTimeUnit
;
int16_t
precision
;
int64_t
num
;
// number of computing count
...
...
@@ -380,7 +382,7 @@ typedef struct SSqlStream {
int64_t
ctime
;
// stream created time
int64_t
stime
;
// stream next executed time
int64_t
etime
;
// stream end query time, when time is larger then etime, the stream will be closed
int64_t
interval
;
int64_t
interval
Time
;
int64_t
slidingTime
;
void
*
pTimer
;
...
...
src/client/src/tscProfile.c
浏览文件 @
e9673320
...
...
@@ -259,11 +259,11 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
pSdesc
->
num
=
htobe64
(
pStream
->
num
);
pSdesc
->
useconds
=
htobe64
(
pStream
->
useconds
);
pSdesc
->
stime
=
htobe64
(
pStream
->
stime
-
pStream
->
interval
);
pSdesc
->
stime
=
htobe64
(
pStream
->
stime
-
pStream
->
interval
Time
);
pSdesc
->
ctime
=
htobe64
(
pStream
->
ctime
);
pSdesc
->
slidingTime
=
htobe64
(
pStream
->
slidingTime
);
pSdesc
->
interval
=
htobe64
(
pStream
->
interval
);
pSdesc
->
interval
=
htobe64
(
pStream
->
interval
Time
);
pHeartbeat
->
numOfStreams
++
;
pSdesc
++
;
...
...
src/client/src/tscStream.c
浏览文件 @
e9673320
...
...
@@ -46,22 +46,23 @@ static bool isProjectStream(SQueryInfo* pQueryInfo) {
return
true
;
}
static
int64_t
tscGetRetryDelayTime
(
int64_t
slidingTime
,
int16_t
prec
)
{
static
int64_t
tscGetRetryDelayTime
(
SSqlStream
*
pStream
,
int64_t
slidingTime
,
int16_t
prec
)
{
float
retryRangeFactor
=
0
.
3
f
;
int64_t
retryDelta
=
(
int64_t
)(
tsStreamCompRetryDelay
*
retryRangeFactor
);
retryDelta
=
((
rand
()
%
retryDelta
)
+
tsStreamCompRetryDelay
)
*
1000L
;
if
(
pStream
->
intervalTimeUnit
!=
'n'
&&
pStream
->
intervalTimeUnit
!=
'y'
)
{
// change to ms
if
(
prec
==
TSDB_TIME_PRECISION_MICRO
)
{
slidingTime
=
slidingTime
/
1000
;
}
int64_t
retryDelta
=
(
int64_t
)(
tsStreamCompRetryDelay
*
retryRangeFactor
);
retryDelta
=
((
rand
()
%
retryDelta
)
+
tsStreamCompRetryDelay
)
*
1000L
;
if
(
slidingTime
<
retryDelta
)
{
return
slidingTime
;
}
else
{
return
retryDelta
;
}
}
return
retryDelta
;
}
static
void
tscProcessStreamLaunchQuery
(
SSchedMsg
*
pMsg
)
{
...
...
@@ -86,7 +87,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
// failed to get meter/metric meta, retry in 10sec.
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
->
slidingTime
,
pStream
->
precision
);
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
,
pStream
->
slidingTime
,
pStream
->
precision
);
tscDebug
(
"%p stream:%p,get metermeta failed, retry in %"
PRId64
"ms"
,
pStream
->
pSql
,
pStream
,
retryDelayTime
);
tscSetRetryTimer
(
pStream
,
pSql
,
retryDelayTime
);
...
...
@@ -131,13 +132,17 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
}
if
(
etime
>
pStream
->
etime
)
{
etime
=
pStream
->
etime
;
}
else
if
(
pStream
->
intervalTimeUnit
!=
'y'
&&
pStream
->
intervalTimeUnit
!=
'n'
)
{
etime
=
pStream
->
stime
+
(
etime
-
pStream
->
stime
)
/
pStream
->
intervalTime
*
pStream
->
intervalTime
;
}
else
{
etime
=
pStream
->
stime
+
(
etime
-
pStream
->
stime
)
/
pStream
->
interval
*
pStream
->
interval
;
etime
=
taosGetIntervalStartTimestamp
(
etime
,
pStream
->
slidingTime
,
pStream
->
intervalTime
,
pStream
->
slidingTimeUnit
,
pStream
->
precision
)
;
}
pQueryInfo
->
window
.
ekey
=
etime
;
if
(
pQueryInfo
->
window
.
skey
>=
pQueryInfo
->
window
.
ekey
)
{
int64_t
timer
=
pStream
->
slidingTime
;
if
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
if
(
pStream
->
intervalTimeUnit
==
'y'
||
pStream
->
intervalTimeUnit
==
'n'
)
{
timer
=
86400
*
1000l
;
}
else
if
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
timer
/=
1000l
;
}
tscSetRetryTimer
(
pStream
,
pSql
,
timer
);
...
...
@@ -157,7 +162,7 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
static
void
tscProcessStreamQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
SSqlStream
*
pStream
=
(
SSqlStream
*
)
param
;
if
(
tres
==
NULL
||
numOfRows
<
0
)
{
int64_t
retryDelay
=
tscGetRetryDelayTime
(
pStream
->
slidingTime
,
pStream
->
precision
);
int64_t
retryDelay
=
tscGetRetryDelayTime
(
pStream
,
pStream
->
slidingTime
,
pStream
->
precision
);
tscError
(
"%p stream:%p, query data failed, code:0x%08x, retry in %"
PRId64
"ms"
,
pStream
->
pSql
,
pStream
,
numOfRows
,
retryDelay
);
...
...
@@ -218,7 +223,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
SSqlObj
*
pSql
=
(
SSqlObj
*
)
res
;
if
(
pSql
==
NULL
||
numOfRows
<
0
)
{
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
->
slidingTime
,
pStream
->
precision
);
int64_t
retryDelayTime
=
tscGetRetryDelayTime
(
pStream
,
pStream
->
slidingTime
,
pStream
->
precision
);
tscError
(
"%p stream:%p, retrieve data failed, code:0x%08x, retry in %"
PRId64
"ms"
,
pSql
,
pStream
,
numOfRows
,
retryDelayTime
);
tscSetRetryTimer
(
pStream
,
pStream
->
pSql
,
retryDelayTime
);
...
...
@@ -241,8 +246,12 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
}
if
(
!
pStream
->
isProject
)
{
if
(
pStream
->
intervalTimeUnit
==
'y'
||
pStream
->
intervalTimeUnit
==
'n'
)
{
pStream
->
stime
=
taosAddNatualInterval
(
pStream
->
stime
,
pStream
->
slidingTime
,
pStream
->
slidingTimeUnit
,
pStream
->
precision
);
}
else
{
pStream
->
stime
+=
pStream
->
slidingTime
;
}
}
// actually only one row is returned. this following is not necessary
taos_fetch_rows_a
(
res
,
tscProcessStreamRetrieveResult
,
pStream
);
}
else
{
// numOfRows == 0, all data has been retrieved
...
...
@@ -301,7 +310,7 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
now
+
timer
,
timer
,
delay
,
pStream
->
stime
,
etime
);
}
else
{
tscDebug
(
"%p stream:%p, next start at %"
PRId64
", in %"
PRId64
"ms. delay:%"
PRId64
"ms qrange %"
PRId64
"-%"
PRId64
,
pStream
->
pSql
,
pStream
,
pStream
->
stime
,
timer
,
delay
,
pStream
->
stime
-
pStream
->
interval
,
pStream
->
stime
-
1
);
pStream
->
stime
,
timer
,
delay
,
pStream
->
stime
-
pStream
->
interval
Time
,
pStream
->
stime
-
1
);
}
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
...
...
@@ -311,23 +320,26 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
}
static
int64_t
getLaunchTimeDelay
(
const
SSqlStream
*
pStream
)
{
int64_t
delayDelta
=
(
int64_t
)(
pStream
->
slidingTime
*
tsStreamComputDelayRatio
);
int64_t
maxDelay
=
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
tsMaxStreamComputDelay
*
1000L
:
tsMaxStreamComputDelay
;
int64_t
delayDelta
=
maxDelay
;
if
(
pStream
->
intervalTimeUnit
!=
'n'
&&
pStream
->
intervalTimeUnit
!=
'y'
)
{
delayDelta
=
pStream
->
slidingTime
*
tsStreamComputDelayRatio
;
if
(
delayDelta
>
maxDelay
)
{
delayDelta
=
maxDelay
;
}
int64_t
remainTimeWindow
=
pStream
->
slidingTime
-
delayDelta
;
if
(
maxDelay
>
remainTimeWindow
)
{
maxDelay
=
(
int64_t
)(
remainTimeWindow
/
1
.
5
f
);
}
}
int64_t
currentDelay
=
(
rand
()
%
maxDelay
);
// a random number
currentDelay
+=
delayDelta
;
if
(
pStream
->
intervalTimeUnit
!=
'n'
&&
pStream
->
intervalTimeUnit
!=
'y'
)
{
assert
(
currentDelay
<
pStream
->
slidingTime
);
}
return
currentDelay
;
}
...
...
@@ -354,7 +366,8 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
return
;
}
}
else
{
if
((
pStream
->
stime
-
pStream
->
interval
)
>=
pStream
->
etime
)
{
int64_t
stime
=
taosGetIntervalStartTimestamp
(
pStream
->
stime
-
1
,
pStream
->
intervalTime
,
pStream
->
intervalTime
,
pStream
->
intervalTimeUnit
,
pStream
->
precision
);
if
(
stime
>=
pStream
->
etime
)
{
tscDebug
(
"%p stream:%p, stime:%"
PRId64
" is larger than end time: %"
PRId64
", stop the stream"
,
pStream
->
pSql
,
pStream
,
pStream
->
stime
,
pStream
->
etime
);
// TODO : How to terminate stream here
...
...
@@ -387,24 +400,24 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
if
(
pQueryInfo
->
intervalTime
<
minIntervalTime
)
{
if
(
pQueryInfo
->
intervalTime
Unit
!=
'n'
&&
pQueryInfo
->
intervalTimeUnit
!=
'y'
&&
pQueryInfo
->
intervalTime
<
minIntervalTime
)
{
tscWarn
(
"%p stream:%p, original sample interval:%ld too small, reset to:%"
PRId64
,
pSql
,
pStream
,
pQueryInfo
->
intervalTime
,
minIntervalTime
);
pQueryInfo
->
intervalTime
=
minIntervalTime
;
}
pStream
->
interval
=
pQueryInfo
->
intervalTime
;
// it shall be derived from sql string
pStream
->
intervalTimeUnit
=
pQueryInfo
->
intervalTimeUnit
;
pStream
->
intervalTime
=
pQueryInfo
->
intervalTime
;
// it shall be derived from sql string
if
(
pQueryInfo
->
slidingTime
=
=
0
)
{
if
(
pQueryInfo
->
slidingTime
<
=
0
)
{
pQueryInfo
->
slidingTime
=
pQueryInfo
->
intervalTime
;
pQueryInfo
->
slidingTimeUnit
=
pQueryInfo
->
intervalTimeUnit
;
}
int64_t
minSlidingTime
=
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
tsMinSlidingTime
*
1000L
:
tsMinSlidingTime
;
if
(
pQueryInfo
->
slidingTime
==
-
1
)
{
pQueryInfo
->
slidingTime
=
pQueryInfo
->
intervalTime
;
}
else
if
(
pQueryInfo
->
slidingTime
<
minSlidingTime
)
{
if
(
pQueryInfo
->
intervalTimeUnit
!=
'n'
&&
pQueryInfo
->
intervalTimeUnit
!=
'y'
&&
pQueryInfo
->
slidingTime
<
minSlidingTime
)
{
tscWarn
(
"%p stream:%p, original sliding value:%"
PRId64
" too small, reset to:%"
PRId64
,
pSql
,
pStream
,
pQueryInfo
->
slidingTime
,
minSlidingTime
);
...
...
@@ -418,6 +431,7 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
pQueryInfo
->
slidingTime
=
pQueryInfo
->
intervalTime
;
}
pStream
->
slidingTimeUnit
=
pQueryInfo
->
slidingTimeUnit
;
pStream
->
slidingTime
=
pQueryInfo
->
slidingTime
;
if
(
pStream
->
isProject
)
{
...
...
@@ -431,7 +445,7 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
if
(
pStream
->
isProject
)
{
// no data in table, flush all data till now to destination meter, 10sec delay
pStream
->
interval
=
tsProjectExecInterval
;
pStream
->
interval
Time
=
tsProjectExecInterval
;
pStream
->
slidingTime
=
tsProjectExecInterval
;
if
(
stime
!=
0
)
{
// first projection start from the latest event timestamp
...
...
@@ -442,11 +456,15 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
}
}
else
{
// timewindow based aggregation stream
if
(
stime
==
0
)
{
// no data in meter till now
stime
=
((
int64_t
)
taosGetTimestamp
(
pStream
->
precision
)
/
pStream
->
interval
)
*
pStream
->
interval
;
stime
-=
pStream
->
interval
;
stime
=
pQueryInfo
->
window
.
skey
;
if
(
stime
==
INT64_MIN
)
{
stime
=
(
int64_t
)
taosGetTimestamp
(
pStream
->
precision
);
stime
=
taosGetIntervalStartTimestamp
(
stime
,
pStream
->
intervalTime
,
pStream
->
intervalTime
,
pStream
->
intervalTimeUnit
,
pStream
->
precision
);
stime
=
taosGetIntervalStartTimestamp
(
stime
-
1
,
pStream
->
intervalTime
,
pStream
->
intervalTime
,
pStream
->
intervalTimeUnit
,
pStream
->
precision
);
tscWarn
(
"%p stream:%p, last timestamp:0, reset to:%"
PRId64
,
pSql
,
pStream
,
stime
);
}
}
else
{
int64_t
newStime
=
(
stime
/
pStream
->
interval
)
*
pStream
->
interval
;
int64_t
newStime
=
taosGetIntervalStartTimestamp
(
stime
,
pStream
->
intervalTime
,
pStream
->
intervalTime
,
pStream
->
intervalTimeUnit
,
pStream
->
precision
)
;
if
(
newStime
!=
stime
)
{
tscWarn
(
"%p stream:%p, last timestamp:%"
PRId64
", reset to:%"
PRId64
,
pSql
,
pStream
,
stime
,
newStime
);
stime
=
newStime
;
...
...
@@ -516,7 +534,7 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
taosTmrReset
(
tscProcessStreamTimer
,
(
int32_t
)
starttime
,
pStream
,
tscTmr
,
&
pStream
->
pTimer
);
tscDebug
(
"%p stream:%p is opened, query on:%s, interval:%"
PRId64
", sliding:%"
PRId64
", first launched in:%"
PRId64
", sql:%s"
,
pSql
,
pStream
,
pTableMetaInfo
->
name
,
pStream
->
interval
,
pStream
->
slidingTime
,
starttime
,
pSql
->
sqlstr
);
pStream
,
pTableMetaInfo
->
name
,
pStream
->
interval
Time
,
pStream
->
slidingTime
,
starttime
,
pSql
->
sqlstr
);
}
TAOS_STREAM
*
taos_open_stream
(
TAOS
*
taos
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
...
...
src/common/inc/tname.h
浏览文件 @
e9673320
...
...
@@ -35,6 +35,8 @@ bool tscValidateTableNameLength(size_t len);
SColumnFilterInfo
*
tscFilterInfoClone
(
const
SColumnFilterInfo
*
src
,
int32_t
numOfFilters
);
int64_t
taosAddNatualInterval
(
int64_t
key
,
int64_t
intervalTime
,
char
timeUnit
,
int16_t
precision
);
int32_t
taosCountNatualInterval
(
int64_t
skey
,
int64_t
ekey
,
int64_t
intervalTime
,
char
timeUnit
,
int16_t
precision
);
int64_t
taosGetIntervalStartTimestamp
(
int64_t
startTime
,
int64_t
slidingTime
,
int64_t
intervalTime
,
char
timeUnit
,
int16_t
precision
);
#endif // TDENGINE_NAME_H
src/common/src/tname.c
浏览文件 @
e9673320
...
...
@@ -100,6 +100,62 @@ SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numO
return
pFilter
;
}
int64_t
taosAddNatualInterval
(
int64_t
key
,
int64_t
intervalTime
,
char
timeUnit
,
int16_t
precision
)
{
key
/=
1000
;
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
key
/=
1000
;
}
struct
tm
tm
;
time_t
t
=
(
time_t
)
key
;
localtime_r
(
&
t
,
&
tm
);
if
(
timeUnit
==
'y'
)
{
intervalTime
*=
12
;
}
int
mon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
+
intervalTime
;
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
key
=
mktime
(
&
tm
)
*
1000L
;
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
key
*=
1000L
;
}
return
key
;
}
int32_t
taosCountNatualInterval
(
int64_t
skey
,
int64_t
ekey
,
int64_t
intervalTime
,
char
timeUnit
,
int16_t
precision
)
{
skey
/=
1000
;
ekey
/=
1000
;
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
skey
/=
1000
;
ekey
/=
1000
;
}
if
(
ekey
<
skey
)
{
int64_t
tmp
=
ekey
;
ekey
=
skey
;
skey
=
tmp
;
}
struct
tm
tm
;
time_t
t
=
(
time_t
)
skey
;
localtime_r
(
&
t
,
&
tm
);
int
smon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
;
t
=
(
time_t
)
ekey
;
localtime_r
(
&
t
,
&
tm
);
int
emon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
;
if
(
timeUnit
==
'y'
)
{
intervalTime
*=
12
;
}
return
(
emon
-
smon
)
/
(
int32_t
)
intervalTime
;
}
int64_t
taosGetIntervalStartTimestamp
(
int64_t
startTime
,
int64_t
slidingTime
,
int64_t
intervalTime
,
char
timeUnit
,
int16_t
precision
)
{
if
(
slidingTime
==
0
)
{
return
startTime
;
...
...
src/query/src/qExecutor.c
浏览文件 @
e9673320
...
...
@@ -137,33 +137,6 @@ static void finalizeQueryResult(SQueryRuntimeEnv *pRuntimeEnv);
#define QUERY_IS_INTERVAL_QUERY(_q) ((_q)->intervalTime > 0)
static
int64_t
addNatualInterval
(
int64_t
key
,
int64_t
intervalTime
,
char
intervalTimeUnit
,
int
precision
)
{
key
/=
1000
;
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
key
/=
1000
;
}
struct
tm
tm
;
time_t
t
=
(
time_t
)
key
;
localtime_r
(
&
t
,
&
tm
);
if
(
intervalTimeUnit
==
'y'
)
{
intervalTime
*=
12
;
}
int
mon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
+
intervalTime
;
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
key
=
mktime
(
&
tm
)
*
1000L
;
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
key
*=
1000L
;
}
return
key
;
}
static
void
getNextTimeWindow
(
SQuery
*
pQuery
,
STimeWindow
*
tw
)
{
int32_t
factor
=
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
if
(
pQuery
->
intervalTimeUnit
!=
'n'
&&
pQuery
->
intervalTimeUnit
!=
'y'
)
{
...
...
@@ -528,7 +501,7 @@ static STimeWindow getActiveTimeWindow(SWindowResInfo *pWindowResInfo, int64_t t
if
(
pWindowResInfo
->
curIndex
==
-
1
)
{
// the first window, from the previous stored value
w
.
skey
=
pWindowResInfo
->
prevSKey
;
if
(
pQuery
->
intervalTimeUnit
==
'n'
||
pQuery
->
intervalTimeUnit
==
'y'
)
{
w
.
ekey
=
a
ddNatualInterval
(
w
.
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
w
.
ekey
=
taosA
ddNatualInterval
(
w
.
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
}
else
{
w
.
ekey
=
w
.
skey
+
pQuery
->
intervalTime
-
1
;
}
...
...
@@ -541,7 +514,7 @@ static STimeWindow getActiveTimeWindow(SWindowResInfo *pWindowResInfo, int64_t t
if
(
w
.
skey
>
ts
||
w
.
ekey
<
ts
)
{
if
(
pQuery
->
intervalTimeUnit
==
'n'
||
pQuery
->
intervalTimeUnit
==
'y'
)
{
w
.
skey
=
taosGetIntervalStartTimestamp
(
ts
,
pQuery
->
slidingTime
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
);
w
.
ekey
=
a
ddNatualInterval
(
w
.
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
w
.
ekey
=
taosA
ddNatualInterval
(
w
.
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
}
else
{
int64_t
st
=
w
.
skey
;
...
...
@@ -883,7 +856,7 @@ static int32_t getNextQualifiedWindow(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow
TSKEY
next
=
primaryKeys
[
startPos
];
if
(
pQuery
->
intervalTimeUnit
==
'n'
||
pQuery
->
intervalTimeUnit
==
'y'
)
{
pNext
->
skey
=
taosGetIntervalStartTimestamp
(
next
,
pQuery
->
slidingTime
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
);
pNext
->
ekey
=
a
ddNatualInterval
(
pNext
->
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
pNext
->
ekey
=
taosA
ddNatualInterval
(
pNext
->
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
}
else
{
pNext
->
ekey
+=
((
next
-
pNext
->
ekey
+
pQuery
->
slidingTime
-
1
)
/
pQuery
->
slidingTime
)
*
pQuery
->
slidingTime
;
pNext
->
skey
=
pNext
->
ekey
-
pQuery
->
intervalTime
+
1
;
...
...
@@ -892,7 +865,7 @@ static int32_t getNextQualifiedWindow(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow
TSKEY
next
=
primaryKeys
[
startPos
];
if
(
pQuery
->
intervalTimeUnit
==
'n'
||
pQuery
->
intervalTimeUnit
==
'y'
)
{
pNext
->
skey
=
taosGetIntervalStartTimestamp
(
next
,
pQuery
->
slidingTime
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
);
pNext
->
ekey
=
a
ddNatualInterval
(
pNext
->
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
pNext
->
ekey
=
taosA
ddNatualInterval
(
pNext
->
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
}
else
{
pNext
->
skey
-=
((
pNext
->
skey
-
next
+
pQuery
->
slidingTime
-
1
)
/
pQuery
->
slidingTime
)
*
pQuery
->
slidingTime
;
pNext
->
ekey
=
pNext
->
skey
+
pQuery
->
intervalTime
-
1
;
...
...
@@ -1880,7 +1853,7 @@ void getAlignQueryTimeWindow(SQuery *pQuery, int64_t key, int64_t keyFirst, int6
assert
(
keyLast
-
keyFirst
<
pQuery
->
intervalTime
);
win
->
ekey
=
INT64_MAX
;
}
else
if
(
pQuery
->
intervalTimeUnit
==
'n'
||
pQuery
->
intervalTimeUnit
==
'y'
)
{
win
->
ekey
=
a
ddNatualInterval
(
win
->
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
win
->
ekey
=
taosA
ddNatualInterval
(
win
->
skey
,
pQuery
->
intervalTime
,
pQuery
->
intervalTimeUnit
,
pQuery
->
precision
)
-
1
;
}
else
{
win
->
ekey
=
win
->
skey
+
pQuery
->
intervalTime
-
1
;
}
...
...
src/query/src/qFill.c
浏览文件 @
e9673320
...
...
@@ -179,14 +179,22 @@ int64_t getFilledNumOfRes(SFillInfo* pFillInfo, TSKEY ekey, int32_t maxNumOfRows
if
(
numOfRows
>
0
)
{
// still fill gap within current data block, not generating data after the result set.
TSKEY
lastKey
=
tsList
[
pFillInfo
->
numOfRows
-
1
];
if
(
pFillInfo
->
slidingUnit
!=
'y'
&&
pFillInfo
->
slidingUnit
!=
'n'
)
{
numOfRes
=
(
int64_t
)(
ABS
(
lastKey
-
pFillInfo
->
start
)
/
pFillInfo
->
slidingTime
)
+
1
;
}
else
{
numOfRes
=
taosCountNatualInterval
(
lastKey
,
pFillInfo
->
start
,
pFillInfo
->
slidingTime
,
pFillInfo
->
slidingUnit
,
pFillInfo
->
precision
)
+
1
;
}
assert
(
numOfRes
>=
numOfRows
);
}
else
{
// reach the end of data
if
((
ekey1
<
pFillInfo
->
start
&&
FILL_IS_ASC_FILL
(
pFillInfo
))
||
(
ekey1
>
pFillInfo
->
start
&&
!
FILL_IS_ASC_FILL
(
pFillInfo
)))
{
return
0
;
}
else
{
// the numOfRes rows are all filled with specified policy
}
// the numOfRes rows are all filled with specified policy
if
(
pFillInfo
->
slidingUnit
!=
'y'
&&
pFillInfo
->
slidingUnit
!=
'n'
)
{
numOfRes
=
(
ABS
(
ekey1
-
pFillInfo
->
start
)
/
pFillInfo
->
slidingTime
)
+
1
;
}
else
{
numOfRes
=
taosCountNatualInterval
(
ekey1
,
pFillInfo
->
start
,
pFillInfo
->
slidingTime
,
pFillInfo
->
slidingUnit
,
pFillInfo
->
precision
)
+
1
;
}
}
...
...
@@ -366,7 +374,12 @@ static void doFillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t* nu
setTagsValue
(
pFillInfo
,
data
,
*
num
);
}
// TODO natual sliding time
if
(
pFillInfo
->
slidingUnit
!=
'n'
&&
pFillInfo
->
slidingUnit
!=
'y'
)
{
pFillInfo
->
start
+=
(
pFillInfo
->
slidingTime
*
step
);
}
else
{
pFillInfo
->
start
=
taosAddNatualInterval
(
pFillInfo
->
start
,
pFillInfo
->
slidingTime
*
step
,
pFillInfo
->
slidingUnit
,
pFillInfo
->
precision
);
}
pFillInfo
->
numOfCurrent
++
;
(
*
num
)
+=
1
;
...
...
@@ -473,7 +486,12 @@ int32_t generateDataBlockImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t nu
// set the tag value for final result
setTagsValue
(
pFillInfo
,
data
,
num
);
// TODO natual sliding time
if
(
pFillInfo
->
slidingUnit
!=
'n'
&&
pFillInfo
->
slidingUnit
!=
'y'
)
{
pFillInfo
->
start
+=
(
pFillInfo
->
slidingTime
*
step
);
}
else
{
pFillInfo
->
start
=
taosAddNatualInterval
(
pFillInfo
->
start
,
pFillInfo
->
slidingTime
*
step
,
pFillInfo
->
slidingUnit
,
pFillInfo
->
precision
);
}
pFillInfo
->
rowIdx
+=
1
;
pFillInfo
->
numOfCurrent
+=
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录