Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
497a0e3b
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看板
提交
497a0e3b
编写于
3月 16, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-2859]refactor.
上级
9ff85c61
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
358 addition
and
299 deletion
+358
-299
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+23
-24
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+1
-1
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+32
-8
src/query/inc/sql.y
src/query/inc/sql.y
+13
-17
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+48
-5
src/query/src/sql.c
src/query/src/sql.c
+241
-244
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
497a0e3b
...
...
@@ -6374,12 +6374,12 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
S
Array
*
pSrcMeterName
=
pInfo
->
pCreateTableInfo
->
pSelect
->
from
;
if
(
p
SrcMeterName
==
NULL
||
taosArrayGetSize
(
pSrcMeterName
)
==
0
)
{
S
FromInfo
*
pFromInfo
=
pInfo
->
pCreateTableInfo
->
pSelect
->
from
;
if
(
p
FromInfo
==
NULL
||
taosArrayGetSize
(
pFromInfo
->
tableList
)
==
0
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
tVariantListItem
*
p1
=
taosArrayGet
(
p
SrcMeterName
,
0
);
tVariantListItem
*
p1
=
taosArrayGet
(
p
FromInfo
->
tableList
,
0
);
SStrToken
srcToken
=
{.
z
=
p1
->
pVar
.
pz
,
.
n
=
p1
->
pVar
.
nLen
,
.
type
=
TK_STRING
};
if
(
tscValidateName
(
&
srcToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
...
...
@@ -6498,7 +6498,7 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
}
int32_t
doValidateSqlNode
(
SSqlObj
*
pSql
,
SQuerySqlNode
*
pQuerySqlNode
,
int32_t
index
)
{
assert
(
pQuerySqlNode
!=
NULL
&&
(
pQuerySqlNode
->
from
==
NULL
||
taosArrayGetSize
(
pQuerySqlNode
->
from
)
>
0
));
assert
(
pQuerySqlNode
!=
NULL
&&
(
pQuerySqlNode
->
from
==
NULL
||
taosArrayGetSize
(
pQuerySqlNode
->
from
->
tableList
)
>
0
));
const
char
*
msg0
=
"invalid table name"
;
const
char
*
msg1
=
"point interpolation query needs timestamp"
;
...
...
@@ -6539,60 +6539,59 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i
return
doLocalQueryProcess
(
pCmd
,
pQueryInfo
,
pQuerySqlNode
);
}
size_t
fromSize
=
taosArrayGetSize
(
pQuerySqlNode
->
from
);
if
(
fromSize
>
TSDB_MAX_JOIN_TABLE_NUM
*
2
)
{
size_t
fromSize
=
taosArrayGetSize
(
pQuerySqlNode
->
from
->
tableList
);
if
(
fromSize
>
TSDB_MAX_JOIN_TABLE_NUM
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
pQueryInfo
->
command
=
TSDB_SQL_SELECT
;
if
(
fromSize
>
4
)
{
if
(
fromSize
>
2
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
// set all query tables, which are maybe more than one.
for
(
int32_t
i
=
0
;
i
<
fromSize
;
)
{
tVariantListItem
*
item
=
taosArrayGet
(
pQuerySqlNode
->
from
,
i
);
tVariant
*
pTableItem
=
&
item
->
pVar
;
STableNamePair
*
item
=
taosArrayGet
(
pQuerySqlNode
->
from
->
tableList
,
i
);
SStrToken
*
pTableItem
=
&
item
->
name
;
if
(
pTableItem
->
nT
ype
!=
TSDB_DATA_TYPE_BINARY
)
{
if
(
pTableItem
->
t
ype
!=
TSDB_DATA_TYPE_BINARY
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg0
);
}
pTableItem
->
n
Len
=
strdequote
(
pTableItem
->
p
z
);
pTableItem
->
n
=
strdequote
(
pTableItem
->
z
);
SStrToken
tableName
=
{.
z
=
pTableItem
->
pz
,
.
n
=
pTableItem
->
nLe
n
,
.
type
=
TK_STRING
};
SStrToken
tableName
=
{.
z
=
pTableItem
->
z
,
.
n
=
pTableItem
->
n
,
.
type
=
TK_STRING
};
if
(
tscValidateName
(
&
tableName
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg0
);
}
if
(
pQueryInfo
->
numOfTables
<=
i
/
2
)
{
// more than one table
if
(
pQueryInfo
->
numOfTables
<=
i
)
{
// more than one table
tscAddEmptyMetaInfo
(
pQueryInfo
);
}
STableMetaInfo
*
pTableMetaInfo1
=
tscGetMetaInfo
(
pQueryInfo
,
i
/
2
);
SStrToken
t
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
n
=
pTableItem
->
n
Len
,
.
z
=
pTableItem
->
p
z
};
SStrToken
t
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
n
=
pTableItem
->
n
,
.
z
=
pTableItem
->
z
};
code
=
tscSetTableFullName
(
pTableMetaInfo1
,
&
t
,
pSql
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
tVariantListItem
*
p1
=
taosArrayGet
(
pQuerySqlNode
->
from
,
i
+
1
)
;
if
(
p1
->
pVar
.
nT
ype
!=
TSDB_DATA_TYPE_BINARY
)
{
SStrToken
*
aliasName
=
&
item
->
aliasName
;
if
(
aliasName
->
t
ype
!=
TSDB_DATA_TYPE_BINARY
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
SStrToken
aliasName
=
{.
z
=
p1
->
pVar
.
pz
,
.
n
=
p1
->
pVar
.
nLen
,
.
type
=
TK_STRING
};
if
(
tscValidateName
(
&
aliasName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
TPARSER_HAS_TOKEN
(
*
aliasName
)
&&
tscValidateName
(
aliasName
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
// has no table alias name
if
(
memcmp
(
pTableItem
->
pz
,
p1
->
pVar
.
pz
,
p1
->
pVar
.
nLen
)
==
0
)
{
strncpy
(
pTableMetaInfo1
->
aliasName
,
tNameGetTableName
(
&
pTableMetaInfo1
->
name
),
tListLen
(
pTableMetaInfo
->
aliasName
));
if
(
!
TPARSER_HAS_TOKEN
(
*
aliasName
)
)
{
strncpy
(
pTableMetaInfo1
->
aliasName
,
tNameGetTableName
(
&
pTableMetaInfo1
->
name
),
tListLen
(
pTableMetaInfo
1
->
aliasName
));
}
else
{
tstrncpy
(
pTableMetaInfo1
->
aliasName
,
p1
->
pVar
.
p
z
,
sizeof
(
pTableMetaInfo1
->
aliasName
));
tstrncpy
(
pTableMetaInfo1
->
aliasName
,
aliasName
->
z
,
sizeof
(
pTableMetaInfo1
->
aliasName
));
}
code
=
tscGetTableMeta
(
pSql
,
pTableMetaInfo1
);
...
...
@@ -6603,7 +6602,7 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i
i
+=
2
;
}
assert
(
pQueryInfo
->
numOfTables
==
taosArrayGetSize
(
pQuerySqlNode
->
from
)
/
2
);
assert
(
pQueryInfo
->
numOfTables
==
taosArrayGetSize
(
pQuerySqlNode
->
from
->
tableList
)
/
2
);
bool
isSTable
=
false
;
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
...
...
@@ -6637,12 +6636,12 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i
pQueryInfo
->
window
.
ekey
=
pQueryInfo
->
window
.
ekey
/
1000
;
}
}
else
{
// set the time rang
if
(
taosArrayGetSize
(
pQuerySqlNode
->
from
)
>
2
)
{
// it is a join query, no wher
clause is not allowed.
if
(
taosArrayGetSize
(
pQuerySqlNode
->
from
->
tableList
)
>
1
)
{
// it is a join query, no where
clause is not allowed.
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"condition missing for join query "
);
}
}
int32_t
joinQuery
=
(
pQuerySqlNode
->
from
!=
NULL
&&
taosArrayGetSize
(
pQuerySqlNode
->
from
)
>
2
);
int32_t
joinQuery
=
(
pQuerySqlNode
->
from
!=
NULL
&&
taosArrayGetSize
(
pQuerySqlNode
->
from
->
tableList
)
>
1
);
int32_t
timeWindowQuery
=
(
TPARSER_HAS_TOKEN
(
pQuerySqlNode
->
interval
.
interval
)
||
TPARSER_HAS_TOKEN
(
pQuerySqlNode
->
sessionVal
.
gap
));
...
...
src/client/src/tscUtil.c
浏览文件 @
497a0e3b
...
...
@@ -1159,7 +1159,7 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
}
SSqlExpr
*
tscSqlExprAppend
(
SQueryInfo
*
pQueryInfo
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
int16_t
type
,
int16_t
size
,
int16_t
resColId
,
int16_t
interSize
,
bool
isTagCol
)
{
int16_t
size
,
int16_t
resColId
,
int16_t
interSize
,
bool
isTagCol
)
{
SSqlExpr
*
pExpr
=
doCreateSqlExpr
(
pQueryInfo
,
functionId
,
pColIndex
,
type
,
size
,
resColId
,
interSize
,
isTagCol
);
taosArrayPush
(
pQueryInfo
->
exprList
,
&
pExpr
);
return
pExpr
;
...
...
src/query/inc/qSqlparser.h
浏览文件 @
497a0e3b
...
...
@@ -39,6 +39,11 @@ enum SQL_NODE_TYPE {
SQL_NODE_EXPR
=
4
,
};
enum
SQL_NODE_FROM_TYPE
{
SQL_NODE_FROM_SUBQUERY
=
1
,
SQL_NODE_FROM_NAMELIST
=
2
,
};
extern
char
tTokenTypeSwitcher
[
13
];
#define toTSDBType(x) \
...
...
@@ -78,12 +83,14 @@ typedef struct SSessionWindowVal {
SStrToken
gap
;
}
SSessionWindowVal
;
struct
SFromInfo
;
typedef
struct
SQuerySqlNode
{
struct
SArray
*
pSelectList
;
// select clause
SArray
*
from
;
// from clause
SArray<SQuerySqlNode>
struct
SFromInfo
*
from
;
// from clause
SArray<SQuerySqlNode>
struct
tSqlExpr
*
pWhere
;
// where clause [optional]
SArray
*
pGroupby
;
// groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray
*
pSortOrder
;
// orderby [optional], SArray<tVariantListItem>
SArray
*
pSortOrder
;
// orderby [optional],
SArray<tVariantListItem>
SArray
*
fillType
;
// fill type[optional], SArray<tVariantListItem>
SIntervalVal
interval
;
// (interval, interval_offset) [optional]
SSessionWindowVal
sessionVal
;
// session window [optional]
...
...
@@ -93,6 +100,24 @@ typedef struct SQuerySqlNode {
SStrToken
sqlstr
;
// sql string in select clause
}
SQuerySqlNode
;
typedef
struct
STableNamePair
{
SStrToken
name
;
SStrToken
aliasName
;
}
STableNamePair
;
typedef
struct
SSubclauseInfo
{
// "UNION" multiple select sub-clause
SQuerySqlNode
**
pClause
;
int32_t
numOfClause
;
}
SSubclauseInfo
;
typedef
struct
SFromInfo
{
int32_t
type
;
// nested query|table name list
union
{
SSubclauseInfo
*
pNode
;
SArray
*
tableList
;
// SArray<STableNamePair>
};
}
SFromInfo
;
typedef
struct
SCreatedTableInfo
{
SStrToken
name
;
// table name token
SStrToken
stableName
;
// super table name token , for using clause
...
...
@@ -188,11 +213,6 @@ typedef struct SMiscInfo {
};
}
SMiscInfo
;
typedef
struct
SSubclauseInfo
{
// "UNION" multiple select sub-clause
SQuerySqlNode
**
pClause
;
int32_t
numOfClause
;
}
SSubclauseInfo
;
typedef
struct
SSqlInfo
{
int32_t
type
;
bool
valid
;
...
...
@@ -233,6 +253,10 @@ SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
SArray
*
tVariantListInsert
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
);
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pAliasToken
,
uint8_t
sortOrder
);
SFromInfo
*
setTableNameList
(
SFromInfo
*
pFromInfo
,
SStrToken
*
pName
,
SStrToken
*
pAlias
);
SFromInfo
*
setSubquery
(
SFromInfo
*
pFromInfo
,
SQuerySqlNode
*
pSqlNode
);
void
*
destroyFromInfo
(
SFromInfo
*
pFromInfo
);
// sql expr leaf node
tSqlExpr
*
tSqlExprCreateIdValue
(
SStrToken
*
pToken
,
int32_t
optrType
);
tSqlExpr
*
tSqlExprCreateFunction
(
SArray
*
pParam
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
);
...
...
@@ -246,7 +270,7 @@ void tSqlExprDestroy(tSqlExpr *pExpr);
SArray
*
tSqlExprListAppend
(
SArray
*
pList
,
tSqlExpr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
);
void
tSqlExprListDestroy
(
SArray
*
pList
);
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
S
Array
*
pFrom
,
tSqlExpr
*
pWhere
,
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
S
FromInfo
*
pFrom
,
tSqlExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
ps
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pgLimit
);
...
...
src/query/inc/sql.y
浏览文件 @
497a0e3b
无法预览此类型文件
src/query/src/qSqlParser.c
浏览文件 @
497a0e3b
...
...
@@ -443,6 +443,49 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int
return
pList
;
}
SFromInfo
*
setTableNameList
(
SFromInfo
*
pFromInfo
,
SStrToken
*
pName
,
SStrToken
*
pAlias
)
{
if
(
pFromInfo
==
NULL
)
{
pFromInfo
=
calloc
(
1
,
sizeof
(
SFromInfo
));
pFromInfo
->
tableList
=
taosArrayInit
(
4
,
sizeof
(
STableNamePair
));
}
pFromInfo
->
type
=
SQL_NODE_FROM_NAMELIST
;
STableNamePair
p
=
{.
name
=
*
pName
};
if
(
pAlias
!=
NULL
)
{
p
.
aliasName
=
*
pAlias
;
}
else
{
TPARSER_SET_NONE_TOKEN
(
p
.
aliasName
);
}
taosArrayPush
(
pFromInfo
->
tableList
,
&
p
);
return
pFromInfo
;
}
SFromInfo
*
setSubquery
(
SFromInfo
*
pFromInfo
,
SQuerySqlNode
*
pSqlNode
)
{
if
(
pFromInfo
==
NULL
)
{
pFromInfo
=
calloc
(
1
,
sizeof
(
SFromInfo
));
}
pFromInfo
->
type
=
SQL_NODE_FROM_SUBQUERY
;
pFromInfo
->
pNode
->
pClause
[
pFromInfo
->
pNode
->
numOfClause
-
1
]
=
pSqlNode
;
return
pFromInfo
;
}
void
*
destroyFromInfo
(
SFromInfo
*
pFromInfo
)
{
assert
(
pFromInfo
!=
NULL
);
if
(
pFromInfo
->
type
==
SQL_NODE_FROM_NAMELIST
)
{
taosArrayDestroy
(
pFromInfo
->
tableList
);
}
else
{
destroyAllSelectClause
(
pFromInfo
->
pNode
);
}
tfree
(
pFromInfo
);
return
NULL
;
}
void
tSetDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
)
{
pCpxName
->
type
=
pDb
->
type
;
pCpxName
->
z
=
pDb
->
z
;
...
...
@@ -582,9 +625,10 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
/*
* extract the select info out of sql string
*/
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SArray
*
pFrom
,
tSqlExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
psLimit
)
{
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SFromInfo
*
pFrom
,
tSqlExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
psLimit
)
{
assert
(
pSelectList
!=
NULL
);
SQuerySqlNode
*
pSqlNode
=
calloc
(
1
,
sizeof
(
SQuerySqlNode
));
...
...
@@ -668,8 +712,7 @@ void destroyQuerySqlNode(SQuerySqlNode *pQuerySql) {
taosArrayDestroyEx
(
pQuerySql
->
pGroupby
,
freeVariant
);
pQuerySql
->
pGroupby
=
NULL
;
taosArrayDestroyEx
(
pQuerySql
->
from
,
freeVariant
);
pQuerySql
->
from
=
NULL
;
pQuerySql
->
from
=
destroyFromInfo
(
pQuerySql
->
from
);
taosArrayDestroyEx
(
pQuerySql
->
fillType
,
freeVariant
);
pQuerySql
->
fillType
=
NULL
;
...
...
src/query/src/sql.c
浏览文件 @
497a0e3b
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录