Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c0b36077
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,发现更多精彩内容 >>
提交
c0b36077
编写于
4月 12, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add to_unixtimestamp function
TD-14243
上级
ef4d75f4
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
76 addition
and
5 deletion
+76
-5
include/common/ttime.h
include/common/ttime.h
+1
-0
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+1
-1
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+1
-0
source/common/src/ttime.c
source/common/src/ttime.c
+25
-1
source/libs/function/inc/builtins.h
source/libs/function/inc/builtins.h
+1
-1
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+13
-0
source/libs/scalar/inc/sclInt.h
source/libs/scalar/inc/sclInt.h
+3
-2
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+31
-0
未找到文件。
include/common/ttime.h
浏览文件 @
c0b36077
...
...
@@ -64,6 +64,7 @@ char getPrecisionUnit(int32_t precision);
int64_t
convertTimePrecision
(
int64_t
time
,
int32_t
fromPrecision
,
int32_t
toPrecision
);
int64_t
convertTimeFromPrecisionToUnit
(
int64_t
time
,
int32_t
fromPrecision
,
char
toUnit
);
int32_t
convertStringToTimestamp
(
int16_t
type
,
char
*
inputData
,
int64_t
timePrec
,
int64_t
*
timeVal
);
void
taosFormatUtcTime
(
char
*
buf
,
int32_t
bufLen
,
int64_t
time
,
int32_t
precision
);
...
...
include/libs/function/functionMgt.h
浏览文件 @
c0b36077
...
...
@@ -85,8 +85,8 @@ typedef enum EFunctionType {
// conversion function
FUNCTION_TYPE_CAST
=
2000
,
FUNCTION_TYPE_TO_ISO8601
,
FUNCTION_TYPE_TO_UNIXTIMESTAMP
,
FUNCTION_TYPE_TO_JSON
,
FUNCTION_TYPE_UNIXTIMESTAMP
,
// date and time function
FUNCTION_TYPE_NOW
=
2500
,
...
...
include/libs/scalar/scalar.h
浏览文件 @
c0b36077
...
...
@@ -75,6 +75,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
/* Time related functions */
int32_t
toISO8601Function
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
toUnixtimestampFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
...
...
source/common/src/ttime.c
浏览文件 @
c0b36077
...
...
@@ -406,7 +406,31 @@ int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char
default:
{
return
-
1
;
}
}
}
}
int32_t
convertStringToTimestamp
(
int16_t
type
,
char
*
inputData
,
int64_t
timePrec
,
int64_t
*
timeVal
)
{
int32_t
charLen
=
varDataLen
(
inputData
);
char
*
newColData
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
)
{
newColData
=
taosMemoryCalloc
(
1
,
charLen
+
1
);
memcpy
(
newColData
,
varDataVal
(
inputData
),
charLen
);
taosParseTime
(
newColData
,
timeVal
,
charLen
,
(
int32_t
)
timePrec
,
0
);
taosMemoryFree
(
newColData
);
}
else
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
newColData
=
taosMemoryCalloc
(
1
,
charLen
/
TSDB_NCHAR_SIZE
+
1
);
int
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
inputData
),
charLen
,
newColData
);
if
(
len
<
0
){
taosMemoryFree
(
newColData
);
return
TSDB_CODE_FAILED
;
}
newColData
[
len
]
=
0
;
taosParseTime
(
newColData
,
timeVal
,
len
+
1
,
(
int32_t
)
timePrec
,
0
);
taosMemoryFree
(
newColData
);
}
else
{
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
getDuration
(
int64_t
val
,
char
unit
,
int64_t
*
result
,
int32_t
timePrecision
)
{
...
...
source/libs/function/inc/builtins.h
浏览文件 @
c0b36077
...
...
@@ -22,7 +22,7 @@ extern "C" {
#include "functionMgt.h"
#define FUNCTION_NAME_MAX_LENGTH
16
#define FUNCTION_NAME_MAX_LENGTH
32
#define FUNC_MGT_FUNC_CLASSIFICATION_MASK(n) (1 << n)
...
...
source/libs/function/src/builtins.c
浏览文件 @
c0b36077
...
...
@@ -403,6 +403,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
toISO8601Function
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"to_unixtimestamp"
,
.
type
=
FUNCTION_TYPE_TO_UNIXTIMESTAMP
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
,
.
checkFunc
=
checkAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
toUnixtimestampFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"_rowts"
,
.
type
=
FUNCTION_TYPE_ROWTS
,
...
...
@@ -622,6 +632,9 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) {
case
FUNCTION_TYPE_TO_ISO8601
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
64
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
case
FUNCTION_TYPE_TO_UNIXTIMESTAMP
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BIGINT
};
}
case
FUNCTION_TYPE_TBNAME
:
{
// todo
...
...
source/libs/scalar/inc/sclInt.h
浏览文件 @
c0b36077
...
...
@@ -46,8 +46,9 @@ typedef struct SScalarCtx {
int32_t
doConvertDataType
(
SValueNode
*
pValueNode
,
SScalarParam
*
out
);
SColumnInfoData
*
createColumnInfoData
(
SDataType
*
pType
,
int32_t
numOfRows
);
#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type)
#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes)
#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type)
#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes)
#define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision)
void
sclFreeParam
(
SScalarParam
*
param
);
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
c0b36077
#include "function.h"
#include "scalar.h"
#include "tdatablock.h"
#include "ttime.h"
#include "sclInt.h"
#include "sclvector.h"
...
...
@@ -872,6 +873,36 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
return
TSDB_CODE_SUCCESS
;
}
int32_t
toUnixtimestampFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
int32_t
timePrec
=
GET_PARAM_PRECISON
(
pInput
);
if
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
TSDB_CODE_FAILED
;
}
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
char
*
input
=
pInput
[
0
].
columnData
->
pData
+
pInput
[
0
].
columnData
->
varmeta
.
offset
[
0
];
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
int64_t
timeVal
=
0
;
convertStringToTimestamp
(
type
,
input
,
timePrec
,
&
timeVal
);
colDataAppend
(
pOutput
->
columnData
,
i
,
(
char
*
)
&
timeVal
,
false
);
input
+=
varDataTLen
(
input
);
}
pOutput
->
numOfRows
=
pInput
->
numOfRows
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
atanFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
return
doScalarFunctionUnique
(
pInput
,
inputNum
,
pOutput
,
atan
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录