Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b355e2b3
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看板
提交
b355e2b3
编写于
4月 13, 2022
作者:
G
Ganlin Zhao
提交者:
Ganlin Zhao
4月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add today()/today() + duration in insert clause
TD-14243
上级
8572bd2a
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
51 addition
and
15 deletion
+51
-15
include/common/ttime.h
include/common/ttime.h
+19
-0
include/os/osTime.h
include/os/osTime.h
+4
-0
source/client/src/tmq.c
source/client/src/tmq.c
+1
-1
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+1
-1
source/common/src/ttime.c
source/common/src/ttime.c
+5
-5
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+2
-2
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+4
-2
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+1
-1
source/os/src/osTime.c
source/os/src/osTime.c
+11
-0
tests/test/c/tmqDemo.c
tests/test/c/tmqDemo.c
+1
-1
tests/tsim/src/simExe.c
tests/tsim/src/simExe.c
+1
-1
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+1
-1
未找到文件。
include/common/ttime.h
浏览文件 @
b355e2b3
...
...
@@ -40,6 +40,7 @@ extern "C" {
* @return timestamp decided by global conf variable, tsTimePrecision
* if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond.
* precision == TSDB_TIME_PRECISION_MILLI, it returns timestamp in millisecond.
* precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond.
*/
static
FORCE_INLINE
int64_t
taosGetTimestamp
(
int32_t
precision
)
{
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
...
...
@@ -51,6 +52,24 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) {
}
}
/*
* @return timestamp of today at 00:00:00 in given precision
* if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond.
* precision == TSDB_TIME_PRECISION_MILLI, it returns timestamp in millisecond.
* precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond.
*/
static
FORCE_INLINE
int64_t
taosGetTimestampToday
(
int32_t
precision
)
{
int64_t
factor
=
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
1000000
:
1000000000
;
time_t
t
=
taosTime
(
NULL
);
struct
tm
*
tm
=
taosLocalTime
(
&
t
,
NULL
);
tm
->
tm_hour
=
0
;
tm
->
tm_min
=
0
;
tm
->
tm_sec
=
0
;
return
(
int64_t
)
taosMktime
(
tm
)
*
factor
;
}
int64_t
taosTimeAdd
(
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
unit
,
int32_t
precision
);
...
...
include/os/osTime.h
浏览文件 @
b355e2b3
...
...
@@ -27,9 +27,11 @@ extern "C" {
#ifndef ALLOW_FORBID_FUNC
#define strptime STRPTIME_FUNC_TAOS_FORBID
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
#define localtime LOCALTIME_FUNC_TAOS_FORBID
#define localtime_s LOCALTIMES_FUNC_TAOS_FORBID
#define localtime_r LOCALTIMER_FUNC_TAOS_FORBID
#define time TIME_FUNC_TAOS_FORBID
#define mktime MKTIME_FUNC_TAOS_FORBID
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
...
...
@@ -82,6 +84,8 @@ static FORCE_INLINE int64_t taosGetTimestampNs() {
char
*
taosStrpTime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
);
struct
tm
*
taosLocalTime
(
const
time_t
*
timep
,
struct
tm
*
result
);
time_t
taosTime
(
time_t
*
t
);
time_t
taosMktime
(
struct
tm
*
timep
);
#ifdef __cplusplus
}
...
...
source/client/src/tmq.c
浏览文件 @
b355e2b3
...
...
@@ -764,7 +764,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
}
}
struct
tm
*
ptm
=
localtime
(
&
tt
);
struct
tm
*
ptm
=
taosLocalTime
(
&
tt
,
NULL
);
size_t
pos
=
strftime
(
buf
,
35
,
"%Y-%m-%d %H:%M:%S"
,
ptm
);
if
(
precision
==
TSDB_TIME_PRECISION_NANO
)
{
...
...
source/common/src/tdatablock.c
浏览文件 @
b355e2b3
...
...
@@ -1368,7 +1368,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
}
}
struct
tm
*
ptm
=
localtime
(
&
tt
);
struct
tm
*
ptm
=
taosLocalTime
(
&
tt
,
NULL
);
size_t
pos
=
strftime
(
buf
,
35
,
"%Y-%m-%d %H:%M:%S"
,
ptm
);
if
(
precision
==
TSDB_TIME_PRECISION_NANO
)
{
...
...
source/common/src/ttime.c
浏览文件 @
b355e2b3
...
...
@@ -70,7 +70,7 @@ void deltaToUtcInitOnce() {
struct
tm
tm
=
{
0
};
(
void
)
taosStrpTime
(
"1970-01-01 00:00:00"
,
(
const
char
*
)(
"%Y-%m-%d %H:%M:%S"
),
&
tm
);
m_deltaUtc
=
(
int64_t
)
m
ktime
(
&
tm
);
m_deltaUtc
=
(
int64_t
)
taosM
ktime
(
&
tm
);
// printf("====delta:%lld\n\n", seconds);
}
...
...
@@ -344,7 +344,7 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) {
}
/* mktime will be affected by TZ, set by using taos_options */
int64_t
seconds
=
m
ktime
(
&
tm
);
int64_t
seconds
=
taosM
ktime
(
&
tm
);
int64_t
fraction
=
0
;
...
...
@@ -539,7 +539,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
return
(
int64_t
)(
m
ktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
return
(
int64_t
)(
taosM
ktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
}
int32_t
taosTimeCountInterval
(
int64_t
skey
,
int64_t
ekey
,
int64_t
interval
,
char
unit
,
int32_t
precision
)
{
...
...
@@ -598,7 +598,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
tm
.
tm_mon
=
mon
%
12
;
}
start
=
(
int64_t
)(
m
ktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
start
=
(
int64_t
)(
taosM
ktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
}
else
{
int64_t
delta
=
t
-
pInterval
->
interval
;
int32_t
factor
=
(
delta
>=
0
)
?
1
:
-
1
;
...
...
@@ -745,7 +745,7 @@ void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision)
assert
(
false
);
}
ptm
=
localtime
(
&
quot
);
ptm
=
taosLocalTime
(
&
quot
,
NULL
);
int32_t
length
=
(
int32_t
)
strftime
(
ts
,
40
,
"%Y-%m-%dT%H:%M:%S"
,
ptm
);
length
+=
snprintf
(
ts
+
length
,
fractionLen
,
format
,
mod
);
length
+=
(
int32_t
)
strftime
(
ts
+
length
,
40
-
length
,
"%z"
,
ptm
);
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
b355e2b3
...
...
@@ -173,12 +173,12 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o
int
mon
=
(
int
)(
tm
.
tm_year
*
12
+
tm
.
tm_mon
+
interval
*
factor
);
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
tw
->
skey
=
convertTimePrecision
((
int64_t
)
m
ktime
(
&
tm
)
*
1000L
,
TSDB_TIME_PRECISION_MILLI
,
precision
);
tw
->
skey
=
convertTimePrecision
((
int64_t
)
taosM
ktime
(
&
tm
)
*
1000L
,
TSDB_TIME_PRECISION_MILLI
,
precision
);
mon
=
(
int
)(
mon
+
interval
);
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
tw
->
ekey
=
convertTimePrecision
((
int64_t
)
m
ktime
(
&
tm
)
*
1000L
,
TSDB_TIME_PRECISION_MILLI
,
precision
);
tw
->
ekey
=
convertTimePrecision
((
int64_t
)
taosM
ktime
(
&
tm
)
*
1000L
,
TSDB_TIME_PRECISION_MILLI
,
precision
);
tw
->
ekey
-=
1
;
}
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
b355e2b3
...
...
@@ -312,6 +312,8 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
if
(
pToken
->
type
==
TK_NOW
)
{
ts
=
taosGetTimestamp
(
timePrec
);
}
else
if
(
pToken
->
type
==
TK_TODAY
)
{
ts
=
taosGetTimestampToday
(
timePrec
);
}
else
if
(
pToken
->
type
==
TK_NK_INTEGER
)
{
bool
isSigned
=
false
;
toInteger
(
pToken
->
z
,
pToken
->
n
,
10
,
&
ts
,
&
isSigned
);
...
...
@@ -376,8 +378,8 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
}
static
FORCE_INLINE
int32_t
checkAndTrimValue
(
SToken
*
pToken
,
uint32_t
type
,
char
*
tmpTokenBuf
,
SMsgBuf
*
pMsgBuf
)
{
if
((
pToken
->
type
!=
TK_NOW
&&
pToken
->
type
!=
TK_
NK_INTEGER
&&
pToken
->
type
!=
TK_NK_STRING
&&
pToken
->
type
!=
TK_NK_FLOAT
&&
pToken
->
type
!=
TK_NK_BOOL
&&
pToken
->
type
!=
TK_NULL
&&
pToken
->
type
!=
TK_NK_HEX
&&
pToken
->
type
!=
TK_NK_OCT
&&
pToken
->
type
!=
TK_NK_BIN
)
||
if
((
pToken
->
type
!=
TK_NOW
&&
pToken
->
type
!=
TK_
TODAY
&&
pToken
->
type
!=
TK_NK_INTEGER
&&
pToken
->
type
!=
TK_NK_STRING
&&
pToken
->
type
!=
TK_NK_FLOAT
&&
pToken
->
type
!=
TK_N
K_BOOL
&&
pToken
->
type
!=
TK_N
ULL
&&
pToken
->
type
!=
TK_NK_HEX
&&
pToken
->
type
!=
TK_NK_OCT
&&
pToken
->
type
!=
TK_NK_BIN
)
||
(
pToken
->
n
==
0
)
||
(
pToken
->
type
==
TK_NK_RP
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"invalid data or symbol"
,
pToken
->
z
);
}
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
b355e2b3
...
...
@@ -841,7 +841,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
memmove
(
fraction
,
fraction
+
TSDB_TIME_PRECISION_SEC_DIGITS
,
TSDB_TIME_PRECISION_SEC_DIGITS
);
}
struct
tm
*
tmInfo
=
localtime
((
const
time_t
*
)
&
timeVal
);
struct
tm
*
tmInfo
=
taosLocalTime
((
const
time_t
*
)
&
timeVal
,
NULL
);
strftime
(
buf
,
sizeof
(
buf
),
"%Y-%m-%dT%H:%M:%S%z"
,
tmInfo
);
int32_t
len
=
(
int32_t
)
strlen
(
buf
);
...
...
source/os/src/osTime.c
浏览文件 @
b355e2b3
...
...
@@ -406,7 +406,18 @@ FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
#endif
}
time_t
taosTime
(
time_t
*
t
)
{
return
time
(
t
);
}
time_t
taosMktime
(
struct
tm
*
timep
)
{
return
mktime
(
timep
);
}
struct
tm
*
taosLocalTime
(
const
time_t
*
timep
,
struct
tm
*
result
)
{
if
(
result
==
NULL
)
{
return
localtime
(
timep
);
}
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
localtime_s
(
result
,
timep
);
#else
...
...
tests/test/c/tmqDemo.c
浏览文件 @
b355e2b3
...
...
@@ -596,7 +596,7 @@ void printParaIntoFile() {
g_fp
=
pFile
;
time_t
tTime
=
taosGetTimestampSec
();
struct
tm
tm
=
*
localtime
(
&
tTime
);
struct
tm
tm
=
*
taosLocalTime
(
&
tTime
,
NULL
);
taosFprintfFile
(
pFile
,
"###################################################################
\n
"
);
taosFprintfFile
(
pFile
,
"# configDir: %s
\n
"
,
configDir
);
...
...
tests/tsim/src/simExe.c
浏览文件 @
b355e2b3
...
...
@@ -678,7 +678,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
if
(
tt
<
0
)
tt
=
0
;
#endif
tp
=
localtime
(
&
tt
);
tp
=
taosLocalTime
(
&
tt
,
NULL
);
strftime
(
timeStr
,
64
,
"%y-%m-%d %H:%M:%S"
,
tp
);
if
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
{
sprintf
(
value
,
"%s.%03d"
,
timeStr
,
(
int32_t
)(
*
((
int64_t
*
)
row
[
i
])
%
1000
));
...
...
tools/shell/src/shellEngine.c
浏览文件 @
b355e2b3
...
...
@@ -452,7 +452,7 @@ static char *formatTimestamp(char *buf, int64_t val, int precision) {
}
}
struct
tm
*
ptm
=
localtime
(
&
tt
);
struct
tm
*
ptm
=
taosLocalTime
(
&
tt
,
NULL
);
size_t
pos
=
strftime
(
buf
,
35
,
"%Y-%m-%d %H:%M:%S"
,
ptm
);
if
(
precision
==
TSDB_TIME_PRECISION_NANO
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录