Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ed7e81f1
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ed7e81f1
编写于
9月 09, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-1393] opt last_row query with tags filter conditions.
上级
0755ec1f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
50 deletion
+47
-50
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+47
-50
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
ed7e81f1
...
...
@@ -92,7 +92,6 @@ static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQueryS
static
int32_t
tsRewriteFieldNameIfNecessary
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
setAlterTableInfo
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
);
static
int32_t
validateSqlFunctionInStreamSql
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
arithmeticExprToString
(
tSQLExpr
*
pExpr
,
char
**
exprString
);
static
int32_t
validateFunctionsInIntervalOrGroupbyQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
validateArithmeticSQLExpr
(
SSqlCmd
*
pCmd
,
tSQLExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
);
static
int32_t
validateEp
(
char
*
ep
);
...
...
@@ -103,6 +102,7 @@ static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killTy
static
bool
validateOneTags
(
SSqlCmd
*
pCmd
,
TAOS_FIELD
*
pTagField
);
static
bool
hasTimestampForPointInterpQuery
(
SQueryInfo
*
pQueryInfo
);
static
bool
hasNormalColumnFilter
(
SQueryInfo
*
pQueryInfo
);
static
int32_t
parseLimitClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
SQuerySQL
*
pQuerySql
,
SSqlObj
*
pSql
);
static
int32_t
parseCreateDBOptions
(
SSqlCmd
*
pCmd
,
SCreateDBInfo
*
pCreateDbSql
);
...
...
@@ -1330,7 +1330,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
/*
* transfer sql functions that need secondary merge into another format
* in dealing with
metric
queries such as: count/first/last
* in dealing with
super table
queries such as: count/first/last
*/
if
(
isSTable
)
{
tscTansformSQLFuncForSTableQuery
(
pQueryInfo
);
...
...
@@ -1515,16 +1515,16 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
static
int32_t
setExprInfoForFunctions
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSchema
*
pSchema
,
SConvertFunc
cvtFunc
,
char
*
aliasName
,
int32_t
resColIdx
,
SColumnIndex
*
pColIndex
)
{
const
char
*
msg1
=
"not support column types"
;
int16_t
type
=
0
;
int16_t
bytes
=
0
;
char
columnName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
const
char
*
msg1
=
"not support column types"
;
char
columnName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
int32_t
functionID
=
cvtFunc
.
execFuncId
;
if
(
functionID
==
TSDB_FUNC_SPREAD
)
{
if
(
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_NCHAR
||
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_BOOL
)
{
int32_t
t1
=
pSchema
[
pColIndex
->
columnIndex
].
type
;
if
(
t1
==
TSDB_DATA_TYPE_BINARY
||
t1
==
TSDB_DATA_TYPE_NCHAR
||
t1
==
TSDB_DATA_TYPE_BOOL
)
{
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
-
1
;
}
else
{
...
...
@@ -1541,8 +1541,7 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
}
else
{
getRevisedName
(
columnName
,
cvtFunc
.
originFuncId
,
sizeof
(
columnName
)
-
1
,
pSchema
[
pColIndex
->
columnIndex
].
name
);
}
SSqlExpr
*
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
functionID
,
pColIndex
,
type
,
bytes
,
bytes
,
false
);
tstrncpy
(
pExpr
->
aliasName
,
columnName
,
sizeof
(
pExpr
->
aliasName
));
...
...
@@ -1783,10 +1782,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if
(
changeFunctionID
(
optr
,
&
functionID
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg9
);
}
// NOTE: has time range condition or normal column filter condition, the last_row query will be transferred to last query
SConvertFunc
cvtFunc
=
{.
originFuncId
=
functionID
,
.
execFuncId
=
functionID
};
if
(
functionID
==
TSDB_FUNC_LAST_ROW
&&
TSWINDOW_IS_EQUAL
(
pQueryInfo
->
window
,
TSWINDOW_INITIALIZER
))
{
if
(
functionID
==
TSDB_FUNC_LAST_ROW
&&
((
!
TSWINDOW_IS_EQUAL
(
pQueryInfo
->
window
,
TSWINDOW_INITIALIZER
))
||
(
hasNormalColumnFilter
(
pQueryInfo
))
))
{
cvtFunc
.
execFuncId
=
TSDB_FUNC_LAST
;
}
if
(
!
requireAllFields
)
{
if
(
pItem
->
pNode
->
pParam
->
nExpr
<
1
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
...
...
@@ -3204,19 +3206,6 @@ int32_t doArithmeticExprToString(tSQLExpr* pExpr, char** exprString) {
return
TSDB_CODE_SUCCESS
;
}
static
UNUSED_FUNC
int32_t
arithmeticExprToString
(
tSQLExpr
*
pExpr
,
char
**
str
)
{
char
*
start
=
*
str
;
int32_t
code
=
doArithmeticExprToString
(
pExpr
,
str
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
// remove out the parenthesis
int32_t
len
=
(
int32_t
)
strlen
(
start
);
memmove
(
start
,
start
+
1
,
len
-
2
);
start
[
len
-
2
]
=
0
;
}
return
code
;
}
static
int32_t
validateSQLExpr
(
SSqlCmd
*
pCmd
,
tSQLExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
)
{
if
(
pExpr
->
nSQLOptr
==
TK_ID
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
...
...
@@ -3615,7 +3604,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
}
static
void
doCompactQueryExpr
(
tSQLExpr
**
pExpr
)
{
if
(
*
pExpr
==
NULL
||
isExprDirectParentOfLeaf
t
Node
(
*
pExpr
))
{
if
(
*
pExpr
==
NULL
||
isExprDirectParentOfLeafNode
(
*
pExpr
))
{
return
;
}
...
...
@@ -3975,7 +3964,6 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
const
char
*
msg2
=
"invalid filter expression"
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
pQueryInfo
->
window
=
TSWINDOW_INITIALIZER
;
// tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space
SStringBuilder
sb
;
memset
(
&
sb
,
0
,
sizeof
(
sb
));
...
...
@@ -6109,11 +6097,27 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return
TSDB_CODE_TSC_INVALID_SQL
;
}
int32_t
joinQuery
=
(
pQuerySql
->
from
!=
NULL
&&
pQuerySql
->
from
->
nExpr
>
2
);
// set where info
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
if
(
pQuerySql
->
pWhere
)
{
pQueryInfo
->
window
=
TSWINDOW_INITIALIZER
;
if
(
pQuerySql
->
pWhere
!=
NULL
)
{
if
(
parseWhereClause
(
pQueryInfo
,
&
pQuerySql
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
pQuerySql
->
pWhere
=
NULL
;
if
(
tinfo
.
precision
==
TSDB_TIME_PRECISION_MILLI
)
{
pQueryInfo
->
window
.
skey
=
pQueryInfo
->
window
.
skey
/
1000
;
pQueryInfo
->
window
.
ekey
=
pQueryInfo
->
window
.
ekey
/
1000
;
}
}
else
{
// set the time rang
if
(
pQuerySql
->
from
->
nExpr
>
2
)
{
// it is a join query, no wher clause is not allowed.
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"condition missing for join query "
);
}
}
int32_t
joinQuery
=
(
pQuerySql
->
from
!=
NULL
&&
pQuerySql
->
from
->
nExpr
>
2
);
if
(
parseSelectClause
(
pCmd
,
index
,
pQuerySql
->
pSelection
,
isSTable
,
joinQuery
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -6133,26 +6137,6 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return
TSDB_CODE_TSC_INVALID_SQL
;
}
// set where info
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
if
(
pQuerySql
->
pWhere
!=
NULL
)
{
if
(
parseWhereClause
(
pQueryInfo
,
&
pQuerySql
->
pWhere
,
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
pQuerySql
->
pWhere
=
NULL
;
if
(
tinfo
.
precision
==
TSDB_TIME_PRECISION_MILLI
)
{
pQueryInfo
->
window
.
skey
=
pQueryInfo
->
window
.
skey
/
1000
;
pQueryInfo
->
window
.
ekey
=
pQueryInfo
->
window
.
ekey
/
1000
;
}
}
else
{
// set the time rang
pQueryInfo
->
window
=
TSWINDOW_INITIALIZER
;
if
(
pQuerySql
->
from
->
nExpr
>
2
)
{
// it is a join query, no wher clause is not allowed.
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"condition missing for join query "
);
}
}
// user does not specified the query time window, twa is not allowed in such case.
if
((
pQueryInfo
->
window
.
skey
==
INT64_MIN
||
pQueryInfo
->
window
.
ekey
==
INT64_MAX
||
(
pQueryInfo
->
window
.
ekey
==
INT64_MAX
/
1000
&&
tinfo
.
precision
==
TSDB_TIME_PRECISION_MILLI
))
&&
tscIsTWAQuery
(
pQueryInfo
))
{
...
...
@@ -6303,7 +6287,8 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
(
*
pExpr
)
->
_node
.
optr
=
getBinaryExprOptr
(
&
t
);
assert
((
*
pExpr
)
->
_node
.
optr
!=
0
);
// check for dividing by 0
if
((
*
pExpr
)
->
_node
.
optr
==
TSDB_BINARY_OP_DIVIDE
)
{
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
pRight
->
pVal
->
nType
==
TSDB_DATA_TYPE_INT
&&
pRight
->
pVal
->
i64Key
==
0
)
{
...
...
@@ -6316,7 +6301,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
// NOTE: binary|nchar data allows the >|< type filter
if
((
*
pExpr
)
->
_node
.
optr
!=
TSDB_RELATION_EQUAL
&&
(
*
pExpr
)
->
_node
.
optr
!=
TSDB_RELATION_NOT_EQUAL
)
{
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
pRight
!=
NULL
&&
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
pRight
->
pVal
->
nType
==
TSDB_DATA_TYPE_BOOL
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -6326,3 +6311,15 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
return
TSDB_CODE_SUCCESS
;
}
bool
hasNormalColumnFilter
(
SQueryInfo
*
pQueryInfo
)
{
size_t
numOfCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumn
*
pCol
=
taosArrayGetP
(
pQueryInfo
->
colList
,
i
);
if
(
pCol
->
numOfFilters
>
0
)
{
return
true
;
}
}
return
false
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录