Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9a1da224
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9a1da224
编写于
8月 18, 2022
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: refactor taosTimeTruncate and taosTimeCountInterval
上级
d7f2d93a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
57 deletion
+32
-57
src/os/inc/osTime.h
src/os/inc/osTime.h
+1
-1
src/os/src/detail/osTime.c
src/os/src/detail/osTime.c
+28
-56
src/query/src/qFill.c
src/query/src/qFill.c
+3
-0
未找到文件。
src/os/inc/osTime.h
浏览文件 @
9a1da224
...
...
@@ -106,7 +106,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
int64_t
taosTimeSub
(
int64_t
t
,
int64_t
duration
,
char
unit
,
int32_t
precision
);
int64_t
taosTimeTruncate
(
int64_t
t
,
const
SInterval
*
pInterval
,
int32_t
precision
);
int32_t
taosTimeCountInterval
(
int64_t
skey
,
int64_t
ekey
,
int64_t
interval
,
char
u
nit
,
int32_t
precision
);
int32_t
taosTimeCountInterval
(
int64_t
skey
,
int64_t
ekey
,
int64_t
sliding
,
int64_t
slidingUnit
,
int64_t
intervalU
nit
,
int32_t
precision
);
int32_t
parseAbsoluteDuration
(
char
*
token
,
int32_t
tokenlen
,
int64_t
*
ts
,
char
*
unit
,
int32_t
timePrecision
);
int32_t
parseNatualDuration
(
const
char
*
token
,
int32_t
tokenLen
,
int64_t
*
duration
,
char
*
unit
,
int32_t
timePrecision
);
...
...
src/os/src/detail/osTime.c
浏览文件 @
9a1da224
...
...
@@ -565,23 +565,29 @@ int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) {
return
(
int64_t
)(
mktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
}
int32_t
taosTimeCountInterval
(
int64_t
skey
,
int64_t
ekey
,
int64_t
interval
,
char
unit
,
int32_t
precision
)
{
int64_t
taosTimeTzOffset
(
int64_t
intervalUnit
,
int32_t
precision
)
{
int64_t
tz_offset
=
0
;
if
(
intervalUnit
==
'd'
||
intervalUnit
==
'w'
)
{
#if defined(WINDOWS) && _MSC_VER >= 1900
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
int64_t
timezone
=
_timezone
;
#endif
tz_offset
=
-
1
*
timezone
*
TSDB_TICK_PER_SECOND
(
precision
);
}
return
tz_offset
;
}
int32_t
taosTimeCountInterval
(
int64_t
skey
,
int64_t
ekey
,
int64_t
sliding
,
int64_t
slidingUnit
,
int64_t
intervalUnit
,
int32_t
precision
)
{
if
(
ekey
<
skey
)
{
int64_t
tmp
=
ekey
;
ekey
=
skey
;
skey
=
tmp
;
}
#ifdef _MSC_VER
#if _MSC_VER >= 1900
int64_t
timezone
=
_timezone
;
#endif
#endif
int64_t
tz_offset
=
-
1
*
timezone
*
TSDB_TICK_PER_SECOND
(
precision
);
if
(
unit
!=
'n'
&&
unit
!=
'y'
)
{
return
(
int32_t
)((
ekey
+
tz_offset
)
/
interval
-
(
skey
+
tz_offset
)
/
interval
)
+
1
;
int64_t
tz_offset
=
taosTimeTzOffset
(
intervalUnit
,
precision
);
if
(
slidingUnit
!=
'n'
&&
slidingUnit
!=
'y'
)
{
return
(
int32_t
)((
ekey
+
tz_offset
)
/
sliding
-
(
skey
+
tz_offset
)
/
sliding
)
+
1
;
}
skey
/=
(
int64_t
)(
TSDB_TICK_PER_SECOND
(
precision
));
...
...
@@ -596,11 +602,11 @@ int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char
localtime_r
(
&
t
,
&
tm
);
int
emon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
;
if
(
u
nit
==
'y'
)
{
interval
*=
12
;
if
(
slidingU
nit
==
'y'
)
{
sliding
*=
12
;
}
return
(
int32_t
)(
emon
/
interval
-
smon
/
interval
)
+
1
;
return
(
int32_t
)(
emon
/
sliding
-
smon
/
sliding
)
+
1
;
}
int64_t
taosTimeTruncate
(
int64_t
t
,
const
SInterval
*
pInterval
,
int32_t
precision
)
{
...
...
@@ -622,56 +628,22 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
if
(
pInterval
->
slidingUnit
==
'y'
)
{
tm
.
tm_mon
=
0
;
tm
.
tm_year
=
(
int
)(
tm
.
tm_year
/
pInterval
->
sliding
*
pInterval
->
sliding
);
tm
.
tm_year
-=
(
int
)(
tm
.
tm_year
%
pInterval
->
sliding
);
}
else
{
int
mon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
;
mon
=
(
int
)(
mon
/
pInterval
->
sliding
*
pInterval
->
sliding
);
mon
-=
(
int
)(
mon
%
pInterval
->
sliding
);
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
}
start
=
(
int64_t
)(
mktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
}
else
{
int64_t
delta
=
t
-
pInterval
->
interval
;
int32_t
factor
=
(
delta
>=
0
)
?
1
:
-
1
;
start
=
(
delta
/
pInterval
->
sliding
+
factor
)
*
pInterval
->
sliding
;
if
(
pInterval
->
intervalUnit
==
'd'
||
pInterval
->
intervalUnit
==
'w'
)
{
/*
* here we revised the start time of day according to the local time zone,
* but in case of DST, the start time of one day need to be dynamically decided.
*/
// todo refactor to extract function that is available for Linux/Windows/Mac platform
#if defined(WINDOWS) && _MSC_VER >= 1900
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
int64_t
timezone
=
_timezone
;
int32_t
daylight
=
_daylight
;
char
**
tzname
=
_tzname
;
#endif
start
+=
(
int64_t
)(
timezone
*
TSDB_TICK_PER_SECOND
(
precision
));
}
int64_t
end
=
0
;
// not enough time range
if
(
start
<
0
||
INT64_MAX
-
start
>
pInterval
->
interval
-
1
)
{
end
=
start
+
pInterval
->
interval
-
1
;
while
(
end
<
t
&&
((
start
+
pInterval
->
sliding
)
<=
INT64_MAX
))
{
// move forward to the correct time window
start
+=
pInterval
->
sliding
;
if
(
start
<
0
||
INT64_MAX
-
start
>
pInterval
->
interval
-
1
)
{
end
=
start
+
pInterval
->
interval
-
1
;
}
else
{
end
=
INT64_MAX
;
break
;
}
}
}
else
{
end
=
INT64_MAX
;
}
// To avoid the overly complicated effect of DST on size of sliding windows, the DST(daylight saving time) is
// better to be respected by users' input and output for display only, maintaining the status quo.
// In this way, the size of sliding windows keeps unchanging during each cycle of processing of requests.
start
=
t
-
pInterval
->
interval
+
pInterval
->
sliding
;
int64_t
tz_offset
=
taosTimeTzOffset
(
pInterval
->
intervalUnit
,
precision
);
start
-=
(
start
+
tz_offset
)
%
pInterval
->
sliding
;
}
if
(
pInterval
->
offset
>
0
)
{
...
...
src/query/src/qFill.c
浏览文件 @
9a1da224
...
...
@@ -462,6 +462,7 @@ void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const SSDataBlock* pInput)
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
interval
.
intervalUnit
,
pFillInfo
->
precision
);
if
(
numOfRes
<
numOfRows
||
pFillInfo
->
currentKey
<
lastKey
)
{
// set currentKey max
...
...
@@ -502,6 +503,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
interval
.
intervalUnit
,
pFillInfo
->
precision
);
assert
(
numOfRes
>=
numOfRows
);
}
else
{
// reach the end of data
...
...
@@ -514,6 +516,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma
pFillInfo
->
currentKey
,
pFillInfo
->
interval
.
sliding
,
pFillInfo
->
interval
.
slidingUnit
,
pFillInfo
->
interval
.
intervalUnit
,
pFillInfo
->
precision
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录