Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ef4d75f4
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
ef4d75f4
编写于
4月 12, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add to_iso8601 function
TD-14243
上级
b9f5237d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
92 addition
and
0 deletion
+92
-0
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+3
-0
include/util/tdef.h
include/util/tdef.h
+5
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+13
-0
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+71
-0
未找到文件。
include/libs/scalar/scalar.h
浏览文件 @
ef4d75f4
...
...
@@ -73,6 +73,9 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
/* Conversion functions */
int32_t
castFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
/* Time related functions */
int32_t
toISO8601Function
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
int32_t
winStartTsFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
...
...
include/util/tdef.h
浏览文件 @
ef4d75f4
...
...
@@ -94,6 +94,11 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_TIME_PRECISION_MICRO_STR "us"
#define TSDB_TIME_PRECISION_NANO_STR "ns"
#define TSDB_TIME_PRECISION_SEC_DIGITS 10
#define TSDB_TIME_PRECISION_MILLI_DIGITS 13
#define TSDB_TIME_PRECISION_MICRO_DIGITS 16
#define TSDB_TIME_PRECISION_NANO_DIGITS 19
#define TSDB_INFORMATION_SCHEMA_DB "information_schema"
#define TSDB_INS_TABLE_DNODES "dnodes"
#define TSDB_INS_TABLE_MNODES "mnodes"
...
...
source/libs/function/src/builtins.c
浏览文件 @
ef4d75f4
...
...
@@ -393,6 +393,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
castFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"to_iso8601"
,
.
type
=
FUNCTION_TYPE_TO_ISO8601
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
,
.
checkFunc
=
checkAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
toISO8601Function
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"_rowts"
,
.
type
=
FUNCTION_TYPE_ROWTS
,
...
...
@@ -609,6 +619,9 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) {
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
paraBytes
,
.
type
=
paraType
};
break
;
}
case
FUNCTION_TYPE_TO_ISO8601
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
64
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
case
FUNCTION_TYPE_TBNAME
:
{
// todo
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
ef4d75f4
...
...
@@ -801,6 +801,77 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
return
TSDB_CODE_SUCCESS
;
}
int32_t
toISO8601Function
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
if
(
type
!=
TSDB_DATA_TYPE_BIGINT
&&
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
TSDB_CODE_FAILED
;
}
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
char
*
input
=
pInput
[
0
].
columnData
->
pData
;
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
char
fraction
[
20
]
=
{
0
};
bool
hasFraction
=
false
;
NUM_TO_STRING
(
type
,
input
,
sizeof
(
fraction
),
fraction
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
fraction
);
char
buf
[
64
]
=
{
0
};
int64_t
timeVal
;
GET_TYPED_DATA
(
timeVal
,
int64_t
,
type
,
input
);
if
(
tsDigits
>
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
/
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
(
1000
*
1000
);
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
(
1000
*
1000
*
1000
);
}
else
{
assert
(
0
);
}
hasFraction
=
true
;
memmove
(
fraction
,
fraction
+
TSDB_TIME_PRECISION_SEC_DIGITS
,
TSDB_TIME_PRECISION_SEC_DIGITS
);
}
struct
tm
*
tmInfo
=
localtime
((
const
time_t
*
)
&
timeVal
);
strftime
(
buf
,
sizeof
(
buf
),
"%Y-%m-%dT%H:%M:%S%z"
,
tmInfo
);
int32_t
len
=
(
int32_t
)
strlen
(
buf
);
if
(
hasFraction
)
{
int32_t
fracLen
=
(
int32_t
)
strlen
(
fraction
)
+
1
;
char
*
tzInfo
=
strchr
(
buf
,
'+'
);
if
(
tzInfo
)
{
memmove
(
tzInfo
+
fracLen
,
tzInfo
,
strlen
(
tzInfo
));
}
else
{
tzInfo
=
strchr
(
buf
,
'-'
);
memmove
(
tzInfo
+
fracLen
,
tzInfo
,
strlen
(
tzInfo
));
}
char
tmp
[
32
];
sprintf
(
tmp
,
".%s"
,
fraction
);
memcpy
(
tzInfo
,
tmp
,
fracLen
);
len
+=
fracLen
;
}
memmove
(
buf
+
VARSTR_HEADER_SIZE
,
buf
,
len
);
varDataSetLen
(
buf
,
len
);
colDataAppend
(
pOutput
->
columnData
,
i
,
buf
,
false
);
input
+=
tDataTypes
[
type
].
bytes
;
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录