Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
891c12cd
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看板
提交
891c12cd
编写于
11月 14, 2019
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TBASE-686]add test case
上级
cbb350b1
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
66 addition
and
75 deletion
+66
-75
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+12
-6
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+52
-68
src/os/linux/inc/os.h
src/os/linux/inc/os.h
+1
-0
src/system/detail/src/vnodeQueryImpl.c
src/system/detail/src/vnodeQueryImpl.c
+1
-1
未找到文件。
src/client/src/tscFunctionImpl.c
浏览文件 @
891c12cd
...
...
@@ -1482,7 +1482,9 @@ static void first_function_f(SQLFunctionCtx *pCtx, int32_t index) {
SET_VAL
(
pCtx
,
1
,
1
);
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
);
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
0
);
TSKEY
ts
=
pCtx
->
ptsList
[
index
];
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
ts
);
SResultInfo
*
pInfo
=
GET_RES_INFO
(
pCtx
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
...
...
@@ -1575,7 +1577,7 @@ static void first_dist_func_merge(SQLFunctionCtx *pCtx) {
SFirstLastInfo
*
pOutput
=
(
SFirstLastInfo
*
)(
pCtx
->
aOutputBuf
+
pCtx
->
inputBytes
);
if
(
pOutput
->
hasResult
!=
DATA_SET_FLAG
||
pInput
->
ts
<
pOutput
->
ts
)
{
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
+
sizeof
(
SFirstLastInfo
));
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
0
);
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
pInput
->
ts
);
}
}
...
...
@@ -1623,7 +1625,9 @@ static void last_function(SQLFunctionCtx *pCtx) {
}
memcpy
(
pCtx
->
aOutputBuf
,
data
,
pCtx
->
inputBytes
);
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
0
);
TSKEY
ts
=
pCtx
->
ptsList
[
i
];
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
ts
);
SResultInfo
*
pInfo
=
GET_RES_INFO
(
pCtx
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
...
...
@@ -1648,7 +1652,9 @@ static void last_function_f(SQLFunctionCtx *pCtx, int32_t index) {
SET_VAL
(
pCtx
,
1
,
1
);
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
);
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
0
);
TSKEY
ts
=
pCtx
->
ptsList
[
index
];
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
ts
);
SResultInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
...
...
@@ -1745,7 +1751,7 @@ static void last_dist_func_merge(SQLFunctionCtx *pCtx) {
if
(
pOutput
->
hasResult
!=
DATA_SET_FLAG
||
pOutput
->
ts
<
pInput
->
ts
)
{
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
+
sizeof
(
SFirstLastInfo
));
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
0
);
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
pInput
->
ts
);
}
}
...
...
@@ -1800,7 +1806,7 @@ static void last_row_function(SQLFunctionCtx *pCtx) {
pInfo1
->
ts
=
pCtx
->
param
[
0
].
i64Key
;
pInfo1
->
hasResult
=
DATA_SET_FLAG
;
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
0
);
DO_UPDATE_TAG_COLUMNS
(
pCtx
,
pInfo1
->
ts
);
}
SET_VAL
(
pCtx
,
pCtx
->
size
,
1
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
891c12cd
...
...
@@ -2806,59 +2806,6 @@ static bool functionCompatibleCheck(SSqlCmd* pCmd) {
}
}
// additional check for select aggfuntion(column), column1 from table_name group by(column1);
if
((
pCmd
->
type
&
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
==
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
{
bool
isAggFunc
=
false
;
for
(
int32_t
i
=
0
;
i
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
int16_t
functionId
=
tscSqlExprGet
(
pCmd
,
i
)
->
functionId
;
if
(
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_TAGPRJ
||
functionId
==
TSDB_FUNC_TS
||
functionId
==
TSDB_FUNC_ARITHM
)
{
continue
;
}
if
((
aAggs
[
functionId
].
nStatus
&
TSDB_FUNCSTATE_SELECTIVITY
)
==
0
)
{
isAggFunc
=
true
;
break
;
}
}
// TODO change the type, the type is not correct
if
(
isAggFunc
)
{
pCmd
->
type
&=
(
~
TSDB_QUERY_TYPE_PROJECTION_QUERY
);
// agg function mixed up with project query without group by exists
if
(
pCmd
->
groupbyExpr
.
numOfGroupCols
==
0
)
{
return
false
;
}
// get the project column
int32_t
numOfPrjColumn
=
0
;
for
(
int32_t
i
=
0
;
i
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pCmd
,
i
);
if
(
pExpr
->
functionId
==
TSDB_FUNC_PRJ
)
{
numOfPrjColumn
+=
1
;
bool
qualifiedCol
=
false
;
for
(
int32_t
j
=
0
;
j
<
pCmd
->
groupbyExpr
.
numOfGroupCols
;
++
j
)
{
if
(
pExpr
->
colInfo
.
colId
==
pCmd
->
groupbyExpr
.
columnInfo
[
j
].
colId
)
{
qualifiedCol
=
true
;
pExpr
->
param
[
0
].
i64Key
=
1
;
// limit the output to be 1 for each state value
pExpr
->
numOfParams
=
1
;
break
;
}
}
if
(
!
qualifiedCol
)
{
setErrMsg
(
pCmd
,
msg1
);
return
false
;
}
}
}
}
}
return
true
;
}
...
...
@@ -5416,6 +5363,27 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
}
}
static
void
doUpdateSqlFunctionForColPrj
(
SSqlCmd
*
pCmd
)
{
for
(
int32_t
i
=
0
;
i
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pCmd
,
i
);
if
(
pExpr
->
functionId
==
TSDB_FUNC_PRJ
)
{
bool
qualifiedCol
=
false
;
for
(
int32_t
j
=
0
;
j
<
pCmd
->
groupbyExpr
.
numOfGroupCols
;
++
j
)
{
if
(
pExpr
->
colInfo
.
colId
==
pCmd
->
groupbyExpr
.
columnInfo
[
j
].
colId
)
{
qualifiedCol
=
true
;
pExpr
->
param
[
0
].
i64Key
=
1
;
// limit the output to be 1 for each state value
pExpr
->
numOfParams
=
1
;
break
;
}
}
assert
(
qualifiedCol
);
}
}
}
static
bool
tagColumnInGroupby
(
SSqlGroupbyExpr
*
pGroupbyExpr
,
int16_t
columnId
)
{
for
(
int32_t
j
=
0
;
j
<
pGroupbyExpr
->
numOfGroupCols
;
++
j
)
{
if
(
columnId
==
pGroupbyExpr
->
columnInfo
[
j
].
colId
&&
pGroupbyExpr
->
columnInfo
[
j
].
flag
==
TSDB_COL_TAG
)
{
...
...
@@ -5480,6 +5448,7 @@ static void updateTagPrjFunction(SSqlCmd* pCmd) {
static
int32_t
checkUpdateTagPrjFunctions
(
SSqlCmd
*
pCmd
)
{
const
char
*
msg1
=
"only one selectivity function allowed in presence of tags function"
;
const
char
*
msg2
=
"functions not allowed"
;
const
char
*
msg3
=
"aggregation function should not be mixed up with projection"
;
bool
tagColExists
=
false
;
int16_t
numOfTimestamp
=
0
;
// primary timestamp column
...
...
@@ -5495,7 +5464,6 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
}
}
if
(
tagColExists
)
{
// check if the selectivity function exists
for
(
int32_t
i
=
0
;
i
<
pCmd
->
fieldsInfo
.
numOfOutputCols
;
++
i
)
{
int16_t
functionId
=
tscSqlExprGet
(
pCmd
,
i
)
->
functionId
;
if
(
functionId
==
TSDB_FUNC_TAGPRJ
||
functionId
==
TSDB_FUNC_PRJ
||
functionId
==
TSDB_FUNC_TS
)
{
...
...
@@ -5509,6 +5477,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
}
}
if
(
tagColExists
)
{
// check if the selectivity function exists
// When the tag projection function on tag column that is not in the group by clause, aggregation function and
// selectivity function exist in select clause is not allowed.
if
(
numOfAggregation
>
0
)
{
...
...
@@ -5521,6 +5490,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
*/
if
(
numOfSelectivity
==
1
)
{
doUpdateSqlFunctionForTagPrj
(
pCmd
);
doUpdateSqlFunctionForColPrj
(
pCmd
);
}
else
if
(
numOfSelectivity
>
1
)
{
/*
* If more than one selectivity functions exist, all the selectivity functions must be last_row.
...
...
@@ -5539,6 +5509,20 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
}
doUpdateSqlFunctionForTagPrj
(
pCmd
);
doUpdateSqlFunctionForColPrj
(
pCmd
);
}
}
else
{
if
((
pCmd
->
type
&
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
==
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
{
if
(
numOfAggregation
>
0
&&
pCmd
->
groupbyExpr
.
numOfGroupCols
==
0
)
{
setErrMsg
(
pCmd
,
msg3
);
return
TSDB_CODE_INVALID_SQL
;
}
if
(
numOfAggregation
>
0
||
numOfSelectivity
>
0
)
{
// clear the projection type flag
pCmd
->
type
&=
(
~
TSDB_QUERY_TYPE_PROJECTION_QUERY
);
doUpdateSqlFunctionForColPrj
(
pCmd
);
}
}
}
...
...
src/os/linux/inc/os.h
浏览文件 @
891c12cd
...
...
@@ -28,6 +28,7 @@ extern "C" {
#include <ctype.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <float.h>
#include <ifaddrs.h>
#include <limits.h>
...
...
src/system/detail/src/vnodeQueryImpl.c
浏览文件 @
891c12cd
...
...
@@ -1840,7 +1840,7 @@ static void setCtxTagColumnInfo(SQuery* pQuery, SQueryRuntimeEnv* pRuntimeEnv) {
// ts may be the required primary timestamp column
continue
;
}
else
{
assert
(
0
);
// the column may be the normal column, group by normal_column, the functionId is TSDB_FUNC_PRJ
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录