Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3fb2ca51
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看板
未验证
提交
3fb2ca51
编写于
6月 16, 2021
作者:
H
haojun Liao
提交者:
GitHub
6月 16, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6503 from taosdata/feature/query
Feature/query
上级
b547a130
52d33843
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
57 addition
and
34 deletion
+57
-34
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+0
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+20
-4
src/client/src/tscSystem.c
src/client/src/tscSystem.c
+10
-2
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+2
-20
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+6
-6
tests/script/general/parser/function.sim
tests/script/general/parser/function.sim
+5
-1
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+14
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
3fb2ca51
...
...
@@ -123,7 +123,6 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
*/
bool
tscIsPointInterpQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsTWAQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsDiffQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsSessionWindowQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsSecondStageQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tsIsArithmeticQueryOnAggResult
(
SQueryInfo
*
pQueryInfo
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
3fb2ca51
...
...
@@ -1795,7 +1795,6 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
assert
(
pSelNodeList
!=
NULL
&&
pCmd
!=
NULL
);
const
char
*
msg1
=
"too many items in selection clause"
;
const
char
*
msg2
=
"functions or others can not be mixed up"
;
const
char
*
msg3
=
"not support query expression"
;
const
char
*
msg4
=
"only support distinct one tag"
;
...
...
@@ -2724,6 +2723,8 @@ void getColumnName(tSqlExprItem* pItem, char* resultFieldName, char* rawName, in
strncpy
(
rawName
,
pItem
->
pNode
->
token
.
z
,
len
);
if
(
pItem
->
aliasName
!=
NULL
)
{
int32_t
aliasNameLen
=
(
int32_t
)
strlen
(
pItem
->
aliasName
);
len
=
(
aliasNameLen
<
nameLength
)
?
aliasNameLen
:
nameLength
;
strncpy
(
resultFieldName
,
pItem
->
aliasName
,
len
);
}
else
{
strncpy
(
resultFieldName
,
rawName
,
len
);
...
...
@@ -3075,7 +3076,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo)
}
}
if
(
tscIsTWAQuery
(
pQueryInfo
)
||
tscIsDiffQuery
(
pQueryInfo
))
{
if
(
tscIsTWAQuery
(
pQueryInfo
)
||
tscIsDiff
Deriv
Query
(
pQueryInfo
))
{
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
==
0
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
true
;
...
...
@@ -7736,6 +7737,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
const
char
*
msg4
=
"interval query not supported, since the result of sub query not include valid timestamp column"
;
const
char
*
msg5
=
"only tag query not compatible with normal column filter"
;
const
char
*
msg6
=
"not support stddev/percentile in outer query yet"
;
const
char
*
msg7
=
"drivative requires timestamp column exists in subquery"
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -7785,11 +7787,27 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
}
}
// todo derivate funtion requires ts column exists in subquery
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
0
);
if
(
tscNumOfExprs
(
pQueryInfo
)
>
1
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
1
);
if
(
pExpr
->
base
.
functionId
==
TSDB_FUNC_DERIVATIVE
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
}
// validate the query filter condition info
if
(
pSqlNode
->
pWhere
!=
NULL
)
{
if
(
validateWhereNode
(
pQueryInfo
,
&
pSqlNode
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
pTableMeta
->
tableInfo
.
precision
==
TSDB_TIME_PRECISION_MILLI
)
{
pQueryInfo
->
window
.
skey
=
pQueryInfo
->
window
.
skey
/
1000
;
pQueryInfo
->
window
.
ekey
=
pQueryInfo
->
window
.
ekey
/
1000
;
}
}
// validate the interval info
...
...
@@ -7810,7 +7828,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
}
// set order by info
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
if
(
validateOrderbyNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
tscGetTableSchema
(
pTableMeta
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -7961,7 +7978,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
pQueryInfo
->
arithmeticOnAgg
=
tsIsArithmeticQueryOnAggResult
(
pQueryInfo
);
pQueryInfo
->
orderProjectQuery
=
tscOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
);
// pQueryInfo->diffQuery = tscIsDiffQuery(pQueryInfo);
SExprInfo
**
p
=
NULL
;
int32_t
numOfExpr
=
0
;
...
...
src/client/src/tscSystem.c
浏览文件 @
3fb2ca51
...
...
@@ -288,16 +288,24 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
if
(
strlen
(
tsLocale
)
==
0
)
{
// locale does not set yet
char
*
defaultLocale
=
setlocale
(
LC_CTYPE
,
""
);
// The locale of the current OS does not be set correctly, so the default locale cannot be acquired.
// The launch of current system will abort soon.
if
(
defaultLocale
==
NULL
)
{
tscError
(
"failed to get default locale, please set the correct locale in current OS"
);
return
-
1
;
}
tstrncpy
(
tsLocale
,
defaultLocale
,
TSDB_LOCALE_LEN
);
}
// set the user specified locale
char
*
locale
=
setlocale
(
LC_CTYPE
,
pStr
);
if
(
locale
!=
NULL
)
{
if
(
locale
!=
NULL
)
{
// failed to set the user specified locale
tscInfo
(
"locale set, prev locale:%s, new locale:%s"
,
tsLocale
,
locale
);
cfg
->
cfgStatus
=
TAOS_CFG_CSTATUS_OPTION
;
}
else
{
// set the user
-specified localed
failed, use default LC_CTYPE as current locale
}
else
{
// set the user
specified locale
failed, use default LC_CTYPE as current locale
locale
=
setlocale
(
LC_CTYPE
,
tsLocale
);
tscInfo
(
"failed to set locale:%s, current locale:%s"
,
pStr
,
tsLocale
);
}
...
...
src/client/src/tscUtil.c
浏览文件 @
3fb2ca51
...
...
@@ -460,24 +460,6 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
return
false
;
}
bool
tscIsDiffQuery
(
SQueryInfo
*
pQueryInfo
)
{
size_t
num
=
tscNumOfExprs
(
pQueryInfo
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SExprInfo
*
pExpr
=
tscExprGet
(
pQueryInfo
,
i
);
int32_t
f
=
pExpr
->
base
.
functionId
;
if
(
pExpr
==
NULL
||
f
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
}
if
(
f
==
TSDB_FUNC_DIFF
||
f
==
TSDB_FUNC_DERIVATIVE
)
{
return
true
;
}
}
return
false
;
}
bool
tscIsSessionWindowQuery
(
SQueryInfo
*
pQueryInfo
)
{
return
pQueryInfo
->
sessionWindow
.
gap
>
0
;
}
...
...
@@ -516,7 +498,7 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
return
false
;
}
if
(
tscIsDiffQuery
(
pQueryInfo
))
{
if
(
tscIsDiff
Deriv
Query
(
pQueryInfo
))
{
return
false
;
}
...
...
@@ -4260,7 +4242,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
pQueryAttr
->
hasTagResults
=
hasTagValOutput
(
pQueryInfo
);
pQueryAttr
->
stabledev
=
isStabledev
(
pQueryInfo
);
pQueryAttr
->
tsCompQuery
=
isTsCompQuery
(
pQueryInfo
);
pQueryAttr
->
diffQuery
=
tscIsDiffQuery
(
pQueryInfo
);
pQueryAttr
->
diffQuery
=
tscIsDiff
Deriv
Query
(
pQueryInfo
);
pQueryAttr
->
simpleAgg
=
isSimpleAggregateRv
(
pQueryInfo
);
pQueryAttr
->
needReverseScan
=
tscNeedReverseScan
(
pQueryInfo
);
pQueryAttr
->
stableQuery
=
QUERY_IS_STABLE_QUERY
(
pQueryInfo
->
type
);
...
...
src/query/src/qAggMain.c
浏览文件 @
3fb2ca51
...
...
@@ -3662,7 +3662,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
!=
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
*
pOutput
=
(
int32_t
)(
pData
[
i
]
-
pCtx
->
param
[
1
].
i64
);
// direct previous may be null
*
pTimestamp
=
tsList
[
i
]
;
*
pTimestamp
=
(
tsList
!=
NULL
)
?
tsList
[
i
]
:
0
;
pOutput
+=
1
;
pTimestamp
+=
1
;
}
...
...
@@ -3684,7 +3684,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
!=
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
i64
;
// direct previous may be null
*
pTimestamp
=
tsList
[
i
]
;
*
pTimestamp
=
(
tsList
!=
NULL
)
?
tsList
[
i
]
:
0
;
pOutput
+=
1
;
pTimestamp
+=
1
;
}
...
...
@@ -3706,7 +3706,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
!=
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
*
pOutput
=
pData
[
i
]
-
pCtx
->
param
[
1
].
dKey
;
// direct previous may be null
*
pTimestamp
=
tsList
[
i
]
;
*
pTimestamp
=
(
tsList
!=
NULL
)
?
tsList
[
i
]
:
0
;
pOutput
+=
1
;
pTimestamp
+=
1
;
}
...
...
@@ -3728,7 +3728,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
!=
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
*
pOutput
=
(
float
)(
pData
[
i
]
-
pCtx
->
param
[
1
].
dKey
);
// direct previous may be null
*
pTimestamp
=
tsList
[
i
]
;
*
pTimestamp
=
(
tsList
!=
NULL
)
?
tsList
[
i
]
:
0
;
pOutput
+=
1
;
pTimestamp
+=
1
;
}
...
...
@@ -3750,7 +3750,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
!=
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
*
pOutput
=
(
int16_t
)(
pData
[
i
]
-
pCtx
->
param
[
1
].
i64
);
// direct previous may be null
*
pTimestamp
=
tsList
[
i
]
;
*
pTimestamp
=
(
tsList
!=
NULL
)
?
tsList
[
i
]
:
0
;
pOutput
+=
1
;
pTimestamp
+=
1
;
}
...
...
@@ -3773,7 +3773,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if
(
pCtx
->
param
[
1
].
nType
!=
INITIAL_VALUE_NOT_ASSIGNED
)
{
// initial value is not set yet
*
pOutput
=
(
int8_t
)(
pData
[
i
]
-
pCtx
->
param
[
1
].
i64
);
// direct previous may be null
*
pTimestamp
=
tsList
[
i
]
;
*
pTimestamp
=
(
tsList
!=
NULL
)
?
tsList
[
i
]
:
0
;
pOutput
+=
1
;
pTimestamp
+=
1
;
}
...
...
tests/script/general/parser/function.sim
浏览文件 @
3fb2ca51
...
...
@@ -1080,6 +1080,8 @@ sql insert into t1 values('2020-1-1 1:1:10', 20000);
sql_error select derivative(k, 1s, 0) from m1;
sql_error select derivative(k, 1s, 0) from m1 group by a;
sql_error select derivative(f1, 1s, 0) from (select k from t1);
sql select derivative(k, 1s, 0) from m1 group by tbname
if $rows != 12 then
return -1
...
...
@@ -1119,4 +1121,6 @@ endi
if $data92 != t1 then
return -1
endi
\ No newline at end of file
endi
sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s));
tests/script/general/parser/nestquery.sim
浏览文件 @
3fb2ca51
...
...
@@ -273,4 +273,18 @@ if $data03 != @20-09-15 00:00:00.000@ then
return -1
endi
sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0);
sql select diff(val) from (select c1 val from nest_tb0);
if $rows != 9999 then
return -1
endi
if $data00 != @70-01-01 08:00:00.000@ then
return -1
endi
if $data01 != 1 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录