Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cc672cfa
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看板
提交
cc672cfa
编写于
3月 03, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix time related function using taosParseTime generate random output
上级
2447894d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
56 deletion
+30
-56
src/common/src/texpr.c
src/common/src/texpr.c
+30
-56
未找到文件。
src/common/src/texpr.c
浏览文件 @
cc672cfa
...
@@ -2228,6 +2228,31 @@ void vectorMathFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
...
@@ -2228,6 +2228,31 @@ void vectorMathFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
free
(
inputData
);
free
(
inputData
);
}
}
void
convertStringToTimestamp
(
int16_t
type
,
char
*
inputData
,
int64_t
timePrec
,
int64_t
*
timeVal
)
{
if
(
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
charLen
=
varDataLen
(
inputData
);
char
*
newColData
=
calloc
(
1
,
charLen
+
1
);
memcpy
(
newColData
,
varDataVal
(
inputData
),
charLen
);
taosParseTime
(
newColData
,
timeVal
,
charLen
,
timePrec
,
0
);
tfree
(
newColData
);
}
else
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
charLen
=
varDataLen
(
inputData
);
char
*
newColData
=
calloc
(
1
,
charLen
/
TSDB_NCHAR_SIZE
+
1
);
int
len
=
taosUcs4ToMbs
(
varDataVal
(
inputData
),
charLen
,
newColData
);
if
(
len
<
0
){
uError
(
"convertStringToTimestamp taosUcs4ToMbs error"
);
tfree
(
newColData
);
return
;
}
newColData
[
len
]
=
0
;
taosParseTime
(
newColData
,
timeVal
,
len
+
1
,
timePrec
,
0
);
tfree
(
newColData
);
}
else
{
uError
(
"input type should be binary/nchar string"
);
return
;
}
}
void
vectorTimeFunc
(
int16_t
functionId
,
tExprOperandInfo
*
pInputs
,
int32_t
numInputs
,
tExprOperandInfo
*
pOutput
,
int32_t
order
)
{
void
vectorTimeFunc
(
int16_t
functionId
,
tExprOperandInfo
*
pInputs
,
int32_t
numInputs
,
tExprOperandInfo
*
pOutput
,
int32_t
order
)
{
for
(
int
i
=
0
;
i
<
numInputs
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numInputs
;
++
i
)
{
assert
(
pInputs
[
i
].
numOfRows
==
1
||
pInputs
[
i
].
numOfRows
==
pOutput
->
numOfRows
);
assert
(
pInputs
[
i
].
numOfRows
==
1
||
pInputs
[
i
].
numOfRows
==
pOutput
->
numOfRows
);
...
@@ -2331,25 +2356,7 @@ void vectorTimeFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
...
@@ -2331,25 +2356,7 @@ void vectorTimeFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
int64_t
timeVal
=
0
;
int64_t
timeVal
=
0
;
int64_t
timePrec
;
int64_t
timePrec
;
GET_TYPED_DATA
(
timePrec
,
int64_t
,
pInputs
[
1
].
type
,
inputData
[
1
]);
GET_TYPED_DATA
(
timePrec
,
int64_t
,
pInputs
[
1
].
type
,
inputData
[
1
]);
if
(
pInputs
[
0
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
convertStringToTimestamp
(
pInputs
[
0
].
type
,
inputData
[
0
],
timePrec
,
&
timeVal
);
int32_t
charLen
=
varDataLen
(
inputData
[
0
]);
char
*
newColData
=
calloc
(
1
,
charLen
+
1
);
memcpy
(
newColData
,
varDataVal
(
inputData
[
0
]),
charLen
);
taosParseTime
(
newColData
,
&
timeVal
,
charLen
,
timePrec
,
0
);
tfree
(
newColData
);
}
else
{
int32_t
charLen
=
varDataLen
(
inputData
[
0
]);
char
*
newColData
=
calloc
(
1
,
charLen
/
TSDB_NCHAR_SIZE
+
1
);
int
len
=
taosUcs4ToMbs
(
varDataVal
(
inputData
[
0
]),
charLen
,
newColData
);
if
(
len
<
0
){
uError
(
"vectorTimeFunc taosUcs4ToMbs error"
);
tfree
(
newColData
);
return
;
}
newColData
[
len
]
=
0
;
taosParseTime
(
newColData
,
&
timeVal
,
len
+
1
,
timePrec
,
0
);
tfree
(
newColData
);
}
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
timeVal
);
SET_TYPED_DATA
(
outputData
,
pOutput
->
type
,
timeVal
);
break
;
break
;
...
@@ -2372,25 +2379,7 @@ void vectorTimeFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
...
@@ -2372,25 +2379,7 @@ void vectorTimeFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
if
(
pInputs
[
0
].
type
==
TSDB_DATA_TYPE_BINARY
||
if
(
pInputs
[
0
].
type
==
TSDB_DATA_TYPE_BINARY
||
pInputs
[
0
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
/* datetime format strings */
pInputs
[
0
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
/* datetime format strings */
if
(
pInputs
[
0
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
convertStringToTimestamp
(
pInputs
[
0
].
type
,
inputData
[
0
],
TSDB_TIME_PRECISION_NANO
,
&
timeVal
);
int32_t
charLen
=
varDataLen
(
inputData
[
0
]);
char
*
newColData
=
calloc
(
1
,
charLen
+
1
);
memcpy
(
newColData
,
varDataVal
(
inputData
[
0
]),
charLen
);
taosParseTime
(
newColData
,
&
timeVal
,
charLen
,
TSDB_TIME_PRECISION_NANO
,
0
);
tfree
(
newColData
);
}
else
{
int32_t
charLen
=
varDataLen
(
inputData
[
0
]);
char
*
newColData
=
calloc
(
1
,
charLen
/
TSDB_NCHAR_SIZE
+
1
);
int
len
=
taosUcs4ToMbs
(
varDataVal
(
inputData
[
0
]),
charLen
,
newColData
);
if
(
len
<
0
){
uError
(
"vectorTimeFunc taosUcs4ToMbs error"
);
tfree
(
newColData
);
return
;
}
newColData
[
len
]
=
0
;
taosParseTime
(
newColData
,
&
timeVal
,
len
+
1
,
TSDB_TIME_PRECISION_NANO
,
0
);
tfree
(
newColData
);
}
//If converted value is less than 10digits in second, use value in second instead
//If converted value is less than 10digits in second, use value in second instead
int64_t
timeValSec
=
timeVal
/
1000000000
;
int64_t
timeValSec
=
timeVal
/
1000000000
;
if
(
timeValSec
<
1000000000
)
{
if
(
timeValSec
<
1000000000
)
{
...
@@ -2567,24 +2556,9 @@ void vectorTimeFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
...
@@ -2567,24 +2556,9 @@ void vectorTimeFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numIn
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_BINARY
||
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_BINARY
||
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_NCHAR
);
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_NCHAR
);
if
(
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
/* datetime format strings */
if
(
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_BINARY
||
int32_t
charLen
=
varDataLen
(
inputData
[
j
]);
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
/* datetime format strings */
char
*
newColData
=
calloc
(
1
,
charLen
+
1
);
convertStringToTimestamp
(
pInputs
[
j
].
type
,
inputData
[
j
],
TSDB_TIME_PRECISION_NANO
,
&
timeVal
[
j
]);
memcpy
(
newColData
,
varDataVal
(
inputData
[
j
]),
charLen
);
taosParseTime
(
newColData
,
&
timeVal
[
j
],
charLen
,
TSDB_TIME_PRECISION_NANO
,
0
);
tfree
(
newColData
);
}
else
if
(
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
charLen
=
varDataLen
(
inputData
[
j
]);
char
*
newColData
=
calloc
(
1
,
charLen
/
TSDB_NCHAR_SIZE
+
1
);
int
len
=
taosUcs4ToMbs
(
varDataVal
(
inputData
[
j
]),
charLen
,
newColData
);
if
(
len
<
0
){
uError
(
"vectorTimeFunc taosUcs4ToMbs error"
);
tfree
(
newColData
);
return
;
}
newColData
[
len
]
=
0
;
taosParseTime
(
newColData
,
&
timeVal
[
j
],
len
+
1
,
TSDB_TIME_PRECISION_NANO
,
0
);
tfree
(
newColData
);
}
else
if
(
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_BIGINT
||
}
else
if
(
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_BIGINT
||
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
/* unix timestamp or ts column*/
pInputs
[
j
].
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
/* unix timestamp or ts column*/
GET_TYPED_DATA
(
timeVal
[
j
],
int64_t
,
pInputs
[
j
].
type
,
inputData
[
j
]);
GET_TYPED_DATA
(
timeVal
[
j
],
int64_t
,
pInputs
[
j
].
type
,
inputData
[
j
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录