Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8ba6ddf8
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看板
提交
8ba6ddf8
编写于
4月 13, 2022
作者:
P
plum-lihui
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of github.com:taosdata/TDengine into 3.0
上级
0076463d
c1eefc9a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
218 addition
and
0 deletion
+218
-0
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+16
-0
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+201
-0
未找到文件。
include/libs/scalar/scalar.h
浏览文件 @
8ba6ddf8
...
...
@@ -76,6 +76,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
);
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
8ba6ddf8
...
...
@@ -413,6 +413,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
toUnixtimestampFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"timetruncate"
,
.
type
=
FUNCTION_TYPE_TIMETRUNCATE
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
,
.
checkFunc
=
checkAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
timeTruncateFunction
,
.
finalizeFunc
=
NULL
},
{
.
name
=
"_rowts"
,
.
type
=
FUNCTION_TYPE_ROWTS
,
...
...
@@ -631,9 +641,15 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) {
}
case
FUNCTION_TYPE_TO_ISO8601
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
64
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
break
;
}
case
FUNCTION_TYPE_TO_UNIXTIMESTAMP
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BIGINT
};
break
;
}
case
FUNCTION_TYPE_TIMETRUNCATE
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
};
break
;
}
case
FUNCTION_TYPE_TBNAME
:
{
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
8ba6ddf8
...
...
@@ -903,6 +903,207 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
return
TSDB_CODE_SUCCESS
;
}
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
&
pInput
[
0
]);
int32_t
timePrec
=
GET_PARAM_PRECISON
(
&
pInput
[
0
]);
if
(
inputNum
!=
2
)
{
return
TSDB_CODE_FAILED
;
}
if
(
type
!=
TSDB_DATA_TYPE_BIGINT
&&
type
!=
TSDB_DATA_TYPE_TIMESTAMP
&&
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
TSDB_CODE_FAILED
;
}
if
(
GET_PARAM_TYPE
(
&
pInput
[
1
])
!=
TSDB_DATA_TYPE_BIGINT
)
{
//time_unit
return
TSDB_CODE_FAILED
;
}
int64_t
timeUnit
,
timeVal
=
0
;
GET_TYPED_DATA
(
timeUnit
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
1
]),
pInput
[
1
].
columnData
->
pData
);
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
char
*
input
=
NULL
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
input
=
pInput
[
0
].
columnData
->
pData
+
pInput
[
0
].
columnData
->
varmeta
.
offset
[
0
];
}
else
{
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
;
}
if
(
IS_VAR_DATA_TYPE
(
type
))
{
/* datetime format strings */
convertStringToTimestamp
(
type
,
input
,
TSDB_TIME_PRECISION_NANO
,
&
timeVal
);
//If converted value is less than 10digits in second, use value in second instead
int64_t
timeValSec
=
timeVal
/
1000000000
;
if
(
timeValSec
<
1000000000
)
{
timeVal
=
timeValSec
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_BIGINT
)
{
/* unix timestamp */
GET_TYPED_DATA
(
timeVal
,
int64_t
,
type
,
input
);
}
else
if
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
/* timestamp column*/
GET_TYPED_DATA
(
timeVal
,
int64_t
,
type
,
input
);
int64_t
timeValSec
=
timeVal
/
factor
;
if
(
timeValSec
<
1000000000
)
{
timeVal
=
timeValSec
;
}
}
char
buf
[
20
]
=
{
0
};
NUM_TO_STRING
(
TSDB_DATA_TYPE_BIGINT
,
&
timeVal
,
sizeof
(
buf
),
buf
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
buf
);
timeUnit
=
timeUnit
*
1000
/
factor
;
switch
(
timeUnit
)
{
case
0
:
{
/* 1u */
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000
*
1000
;
//} else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) {
// //timeVal = timeVal / 1000;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
;
}
else
{
timeVal
=
timeVal
*
1
;
}
break
;
}
case
1
:
{
/* 1a */
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
*
1
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
*
1000000
;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
){
timeVal
=
timeVal
*
factor
;
}
else
{
assert
(
0
);
}
break
;
}
case
1000
:
{
/* 1s */
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
/
1000
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
*
1000000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000000
*
1000000000
;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
;
}
else
{
assert
(
0
);
}
break
;
}
case
60000
:
{
/* 1m */
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
/
1000
/
60
*
60
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
/
60
*
60
*
1000000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000000
/
60
*
60
*
1000000000
;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
/
factor
/
60
*
60
*
factor
;
}
else
{
assert
(
0
);
}
break
;
}
case
3600000
:
{
/* 1h */
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
/
1000
/
3600
*
3600
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
/
3600
*
3600
*
1000000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000000
/
3600
*
3600
*
1000000000
;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
/
factor
/
3600
*
3600
*
factor
;
}
else
{
assert
(
0
);
}
break
;
}
case
86400000
:
{
/* 1d */
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
/
1000
/
86400
*
86400
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
/
86400
*
86400
*
1000000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000000
/
86400
*
86400
*
1000000000
;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
/
factor
/
86400
*
86400
*
factor
;
}
else
{
assert
(
0
);
}
break
;
}
case
604800000
:
{
/* 1w */
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
/
1000
/
604800
*
604800
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
/
604800
*
604800
*
1000000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000000
/
604800
*
604800
*
1000000000
;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
/
factor
/
604800
*
604800
*
factor
;
}
else
{
assert
(
0
);
}
break
;
}
default:
{
timeVal
=
timeVal
*
1
;
break
;
}
}
//truncate the timestamp to db precision
switch
(
timePrec
)
{
case
TSDB_TIME_PRECISION_MILLI
:
{
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
/
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000000
;
}
break
;
}
case
TSDB_TIME_PRECISION_MICRO
:
{
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
=
timeVal
/
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
*
1000
;
}
break
;
}
case
TSDB_TIME_PRECISION_NANO
:
{
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
=
timeVal
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
=
timeVal
*
1000000
;
}
break
;
}
}
colDataAppend
(
pOutput
->
columnData
,
i
,
(
char
*
)
&
timeVal
,
false
);
if
(
IS_VAR_DATA_TYPE
(
type
))
{
input
+=
varDataTLen
(
input
);
}
else
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录