Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
070f6040
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看板
提交
070f6040
编写于
5月 25, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: sql command 'drop cgroup'
上级
1ea2eec5
变更
26
展开全部
隐藏空白更改
内联
并排
Showing
26 changed file
with
3416 addition
and
3155 deletion
+3416
-3155
include/common/tmsg.h
include/common/tmsg.h
+1
-0
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-0
include/common/ttokendef.h
include/common/ttokendef.h
+162
-160
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+8
-0
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+1
-1
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+2
-0
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+2
-0
include/util/tdef.h
include/util/tdef.h
+6
-3
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+18
-14
source/common/src/tmsg.c
source/common/src/tmsg.c
+4
-1
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+4
-4
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+3
-0
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+111
-109
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+4
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+6
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+125
-30
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+5
-5
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+8
-6
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+137
-74
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+2727
-2704
source/libs/parser/test/parInitialCTest.cpp
source/libs/parser/test/parInitialCTest.cpp
+6
-1
source/libs/parser/test/parInitialDTest.cpp
source/libs/parser/test/parInitialDTest.cpp
+32
-2
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+2
-2
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+4
-3
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+35
-35
source/libs/planner/test/planSubqueryTest.cpp
source/libs/planner/test/planSubqueryTest.cpp
+2
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
070f6040
...
...
@@ -696,6 +696,7 @@ typedef struct {
int8_t
replications
;
int8_t
strict
;
int8_t
cacheLastRow
;
int8_t
schemaless
;
int8_t
ignoreExist
;
int32_t
numOfRetensions
;
SArray
*
pRetensions
;
// SRetention
...
...
include/common/tmsgdef.h
浏览文件 @
070f6040
...
...
@@ -144,6 +144,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_TOPIC
,
"mnode-create-topic"
,
SMCreateTopicReq
,
SMCreateTopicRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_TOPIC
,
"mnode-alter-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_TOPIC
,
"mnode-drop-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_CGROUP
,
"mnode-drop-cgroup"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SUBSCRIBE
,
"mnode-subscribe"
,
SCMSubscribeReq
,
SCMSubscribeRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_ASK_EP
,
"mnode-mq-ask-ep"
,
SMqAskEpReq
,
SMqAskEpRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_TIMER
,
"mnode-mq-tmr"
,
SMTimerReq
,
NULL
)
...
...
include/common/ttokendef.h
浏览文件 @
070f6040
...
...
@@ -93,166 +93,168 @@
#define TK_VGROUPS 75
#define TK_SINGLE_STABLE 76
#define TK_RETENTIONS 77
#define TK_NK_COLON 78
#define TK_TABLE 79
#define TK_NK_LP 80
#define TK_NK_RP 81
#define TK_STABLE 82
#define TK_ADD 83
#define TK_COLUMN 84
#define TK_MODIFY 85
#define TK_RENAME 86
#define TK_TAG 87
#define TK_SET 88
#define TK_NK_EQ 89
#define TK_USING 90
#define TK_TAGS 91
#define TK_COMMENT 92
#define TK_BOOL 93
#define TK_TINYINT 94
#define TK_SMALLINT 95
#define TK_INT 96
#define TK_INTEGER 97
#define TK_BIGINT 98
#define TK_FLOAT 99
#define TK_DOUBLE 100
#define TK_BINARY 101
#define TK_TIMESTAMP 102
#define TK_NCHAR 103
#define TK_UNSIGNED 104
#define TK_JSON 105
#define TK_VARCHAR 106
#define TK_MEDIUMBLOB 107
#define TK_BLOB 108
#define TK_VARBINARY 109
#define TK_DECIMAL 110
#define TK_DELAY 111
#define TK_FILE_FACTOR 112
#define TK_NK_FLOAT 113
#define TK_ROLLUP 114
#define TK_TTL 115
#define TK_SMA 116
#define TK_SHOW 117
#define TK_DATABASES 118
#define TK_TABLES 119
#define TK_STABLES 120
#define TK_MNODES 121
#define TK_MODULES 122
#define TK_QNODES 123
#define TK_FUNCTIONS 124
#define TK_INDEXES 125
#define TK_ACCOUNTS 126
#define TK_APPS 127
#define TK_CONNECTIONS 128
#define TK_LICENCE 129
#define TK_GRANTS 130
#define TK_QUERIES 131
#define TK_SCORES 132
#define TK_TOPICS 133
#define TK_VARIABLES 134
#define TK_BNODES 135
#define TK_SNODES 136
#define TK_CLUSTER 137
#define TK_TRANSACTIONS 138
#define TK_LIKE 139
#define TK_INDEX 140
#define TK_FULLTEXT 141
#define TK_FUNCTION 142
#define TK_INTERVAL 143
#define TK_TOPIC 144
#define TK_AS 145
#define TK_WITH 146
#define TK_SCHEMA 147
#define TK_DESC 148
#define TK_DESCRIBE 149
#define TK_RESET 150
#define TK_QUERY 151
#define TK_CACHE 152
#define TK_EXPLAIN 153
#define TK_ANALYZE 154
#define TK_VERBOSE 155
#define TK_NK_BOOL 156
#define TK_RATIO 157
#define TK_COMPACT 158
#define TK_VNODES 159
#define TK_IN 160
#define TK_OUTPUTTYPE 161
#define TK_AGGREGATE 162
#define TK_BUFSIZE 163
#define TK_STREAM 164
#define TK_INTO 165
#define TK_TRIGGER 166
#define TK_AT_ONCE 167
#define TK_WINDOW_CLOSE 168
#define TK_WATERMARK 169
#define TK_KILL 170
#define TK_CONNECTION 171
#define TK_TRANSACTION 172
#define TK_MERGE 173
#define TK_VGROUP 174
#define TK_REDISTRIBUTE 175
#define TK_SPLIT 176
#define TK_SYNCDB 177
#define TK_NULL 178
#define TK_NK_QUESTION 179
#define TK_NK_ARROW 180
#define TK_ROWTS 181
#define TK_TBNAME 182
#define TK_QSTARTTS 183
#define TK_QENDTS 184
#define TK_WSTARTTS 185
#define TK_WENDTS 186
#define TK_WDURATION 187
#define TK_CAST 188
#define TK_NOW 189
#define TK_TODAY 190
#define TK_TIMEZONE 191
#define TK_COUNT 192
#define TK_FIRST 193
#define TK_LAST 194
#define TK_LAST_ROW 195
#define TK_BETWEEN 196
#define TK_IS 197
#define TK_NK_LT 198
#define TK_NK_GT 199
#define TK_NK_LE 200
#define TK_NK_GE 201
#define TK_NK_NE 202
#define TK_MATCH 203
#define TK_NMATCH 204
#define TK_CONTAINS 205
#define TK_JOIN 206
#define TK_INNER 207
#define TK_SELECT 208
#define TK_DISTINCT 209
#define TK_WHERE 210
#define TK_PARTITION 211
#define TK_BY 212
#define TK_SESSION 213
#define TK_STATE_WINDOW 214
#define TK_SLIDING 215
#define TK_FILL 216
#define TK_VALUE 217
#define TK_NONE 218
#define TK_PREV 219
#define TK_LINEAR 220
#define TK_NEXT 221
#define TK_GROUP 222
#define TK_HAVING 223
#define TK_ORDER 224
#define TK_SLIMIT 225
#define TK_SOFFSET 226
#define TK_LIMIT 227
#define TK_OFFSET 228
#define TK_ASC 229
#define TK_NULLS 230
#define TK_ID 231
#define TK_NK_BITNOT 232
#define TK_INSERT 233
#define TK_VALUES 234
#define TK_IMPORT 235
#define TK_NK_SEMI 236
#define TK_FILE 237
#define TK_SCHEMALESS 78
#define TK_NK_COLON 79
#define TK_TABLE 80
#define TK_NK_LP 81
#define TK_NK_RP 82
#define TK_STABLE 83
#define TK_ADD 84
#define TK_COLUMN 85
#define TK_MODIFY 86
#define TK_RENAME 87
#define TK_TAG 88
#define TK_SET 89
#define TK_NK_EQ 90
#define TK_USING 91
#define TK_TAGS 92
#define TK_COMMENT 93
#define TK_BOOL 94
#define TK_TINYINT 95
#define TK_SMALLINT 96
#define TK_INT 97
#define TK_INTEGER 98
#define TK_BIGINT 99
#define TK_FLOAT 100
#define TK_DOUBLE 101
#define TK_BINARY 102
#define TK_TIMESTAMP 103
#define TK_NCHAR 104
#define TK_UNSIGNED 105
#define TK_JSON 106
#define TK_VARCHAR 107
#define TK_MEDIUMBLOB 108
#define TK_BLOB 109
#define TK_VARBINARY 110
#define TK_DECIMAL 111
#define TK_DELAY 112
#define TK_FILE_FACTOR 113
#define TK_NK_FLOAT 114
#define TK_ROLLUP 115
#define TK_TTL 116
#define TK_SMA 117
#define TK_SHOW 118
#define TK_DATABASES 119
#define TK_TABLES 120
#define TK_STABLES 121
#define TK_MNODES 122
#define TK_MODULES 123
#define TK_QNODES 124
#define TK_FUNCTIONS 125
#define TK_INDEXES 126
#define TK_ACCOUNTS 127
#define TK_APPS 128
#define TK_CONNECTIONS 129
#define TK_LICENCE 130
#define TK_GRANTS 131
#define TK_QUERIES 132
#define TK_SCORES 133
#define TK_TOPICS 134
#define TK_VARIABLES 135
#define TK_BNODES 136
#define TK_SNODES 137
#define TK_CLUSTER 138
#define TK_TRANSACTIONS 139
#define TK_LIKE 140
#define TK_INDEX 141
#define TK_FULLTEXT 142
#define TK_FUNCTION 143
#define TK_INTERVAL 144
#define TK_TOPIC 145
#define TK_AS 146
#define TK_CGROUP 147
#define TK_WITH 148
#define TK_SCHEMA 149
#define TK_DESC 150
#define TK_DESCRIBE 151
#define TK_RESET 152
#define TK_QUERY 153
#define TK_CACHE 154
#define TK_EXPLAIN 155
#define TK_ANALYZE 156
#define TK_VERBOSE 157
#define TK_NK_BOOL 158
#define TK_RATIO 159
#define TK_COMPACT 160
#define TK_VNODES 161
#define TK_IN 162
#define TK_OUTPUTTYPE 163
#define TK_AGGREGATE 164
#define TK_BUFSIZE 165
#define TK_STREAM 166
#define TK_INTO 167
#define TK_TRIGGER 168
#define TK_AT_ONCE 169
#define TK_WINDOW_CLOSE 170
#define TK_WATERMARK 171
#define TK_KILL 172
#define TK_CONNECTION 173
#define TK_TRANSACTION 174
#define TK_MERGE 175
#define TK_VGROUP 176
#define TK_REDISTRIBUTE 177
#define TK_SPLIT 178
#define TK_SYNCDB 179
#define TK_NULL 180
#define TK_NK_QUESTION 181
#define TK_NK_ARROW 182
#define TK_ROWTS 183
#define TK_TBNAME 184
#define TK_QSTARTTS 185
#define TK_QENDTS 186
#define TK_WSTARTTS 187
#define TK_WENDTS 188
#define TK_WDURATION 189
#define TK_CAST 190
#define TK_NOW 191
#define TK_TODAY 192
#define TK_TIMEZONE 193
#define TK_COUNT 194
#define TK_FIRST 195
#define TK_LAST 196
#define TK_LAST_ROW 197
#define TK_BETWEEN 198
#define TK_IS 199
#define TK_NK_LT 200
#define TK_NK_GT 201
#define TK_NK_LE 202
#define TK_NK_GE 203
#define TK_NK_NE 204
#define TK_MATCH 205
#define TK_NMATCH 206
#define TK_CONTAINS 207
#define TK_JOIN 208
#define TK_INNER 209
#define TK_SELECT 210
#define TK_DISTINCT 211
#define TK_WHERE 212
#define TK_PARTITION 213
#define TK_BY 214
#define TK_SESSION 215
#define TK_STATE_WINDOW 216
#define TK_SLIDING 217
#define TK_FILL 218
#define TK_VALUE 219
#define TK_NONE 220
#define TK_PREV 221
#define TK_LINEAR 222
#define TK_NEXT 223
#define TK_GROUP 224
#define TK_HAVING 225
#define TK_ORDER 226
#define TK_SLIMIT 227
#define TK_SOFFSET 228
#define TK_LIMIT 229
#define TK_OFFSET 230
#define TK_ASC 231
#define TK_NULLS 232
#define TK_ID 233
#define TK_NK_BITNOT 234
#define TK_INSERT 235
#define TK_VALUES 236
#define TK_IMPORT 237
#define TK_NK_SEMI 238
#define TK_FILE 239
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
...
...
include/libs/nodes/cmdnodes.h
浏览文件 @
070f6040
...
...
@@ -50,6 +50,7 @@ typedef struct SDatabaseOptions {
int32_t
numOfVgroups
;
int8_t
singleStable
;
SNodeList
*
pRetentions
;
int8_t
schemaless
;
}
SDatabaseOptions
;
typedef
struct
SCreateDatabaseStmt
{
...
...
@@ -260,6 +261,13 @@ typedef struct SDropTopicStmt {
bool
ignoreNotExists
;
}
SDropTopicStmt
;
typedef
struct
SDropCGroupStmt
{
ENodeType
type
;
char
topicName
[
TSDB_TABLE_NAME_LEN
];
char
cgroup
[
TSDB_CGROUP_LEN
];
bool
ignoreNotExists
;
}
SDropCGroupStmt
;
typedef
struct
SAlterLocalStmt
{
ENodeType
type
;
char
config
[
TSDB_DNODE_CONFIG_LEN
];
...
...
include/libs/nodes/nodes.h
浏览文件 @
070f6040
...
...
@@ -131,6 +131,7 @@ typedef enum ENodeType {
QUERY_NODE_DROP_MNODE_STMT
,
QUERY_NODE_CREATE_TOPIC_STMT
,
QUERY_NODE_DROP_TOPIC_STMT
,
QUERY_NODE_DROP_CGROUP_STMT
,
QUERY_NODE_ALTER_LOCAL_STMT
,
QUERY_NODE_EXPLAIN_STMT
,
QUERY_NODE_DESCRIBE_STMT
,
...
...
@@ -242,7 +243,6 @@ typedef struct SNodeList {
#define SNodeptr void*
int32_t
nodesNodeSize
(
ENodeType
type
);
SNodeptr
nodesMakeNode
(
ENodeType
type
);
void
nodesDestroyNode
(
SNodeptr
pNode
);
...
...
include/libs/nodes/plannodes.h
浏览文件 @
070f6040
...
...
@@ -31,6 +31,7 @@ typedef struct SLogicNode {
SNodeList
*
pChildren
;
struct
SLogicNode
*
pParent
;
int32_t
optimizedFlag
;
uint8_t
precision
;
}
SLogicNode
;
typedef
enum
EScanType
{
SCAN_TYPE_TAG
=
1
,
SCAN_TYPE_TABLE
,
SCAN_TYPE_SYSTEM_TABLE
,
SCAN_TYPE_STREAM
}
EScanType
;
...
...
@@ -61,6 +62,7 @@ typedef struct SJoinLogicNode {
SLogicNode
node
;
EJoinType
joinType
;
SNode
*
pOnConditions
;
bool
isSingleTableJoin
;
}
SJoinLogicNode
;
typedef
struct
SAggLogicNode
{
...
...
include/libs/nodes/querynodes.h
浏览文件 @
070f6040
...
...
@@ -132,6 +132,7 @@ typedef struct STableNode {
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
bool
singleTable
;
}
STableNode
;
struct
STableMeta
;
...
...
@@ -242,6 +243,7 @@ typedef struct SSelectStmt {
bool
hasAggFuncs
;
bool
hasRepeatScanFuncs
;
bool
hasIndefiniteRowsFunc
;
bool
hasSelectFunc
;
bool
hasSelectValFunc
;
}
SSelectStmt
;
...
...
include/util/tdef.h
浏览文件 @
070f6040
...
...
@@ -334,9 +334,12 @@ typedef enum ELogicConditionType {
#define TSDB_DB_STREAM_MODE_OFF 0
#define TSDB_DB_STREAM_MODE_ON 1
#define TSDB_DEFAULT_DB_STREAM_MODE 0
#define TSDB_DB_SINGLE_STABLE_ON 0
#define TSDB_DB_SINGLE_STABLE_OFF 1
#define TSDB_DEFAULT_DB_SINGLE_STABLE 0
#define TSDB_DB_SINGLE_STABLE_ON 1
#define TSDB_DB_SINGLE_STABLE_OFF 0
#define TSDB_DEFAULT_DB_SINGLE_STABLE TSDB_DB_SINGLE_STABLE_OFF
#define TSDB_DB_SCHEMALESS_ON 1
#define TSDB_DB_SCHEMALESS_OFF 0
#define TSDB_DEFAULT_DB_SCHEMALESS TSDB_DB_SCHEMALESS_OFF
#define TSDB_MIN_ROLLUP_FILE_FACTOR 0
#define TSDB_MAX_ROLLUP_FILE_FACTOR 1
...
...
source/common/src/tdatablock.c
浏览文件 @
070f6040
...
...
@@ -275,8 +275,10 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, in
doBitmapMerge
(
pColumnInfoData
,
numOfRow1
,
pSource
,
numOfRow2
);
int32_t
offset
=
pColumnInfoData
->
info
.
bytes
*
numOfRow1
;
memcpy
(
pColumnInfoData
->
pData
+
offset
,
pSource
->
pData
,
pSource
->
info
.
bytes
*
numOfRow2
);
if
(
pSource
->
pData
)
{
int32_t
offset
=
pColumnInfoData
->
info
.
bytes
*
numOfRow1
;
memcpy
(
pColumnInfoData
->
pData
+
offset
,
pSource
->
pData
,
pSource
->
info
.
bytes
*
numOfRow2
);
}
}
return
numOfRow1
+
numOfRow2
;
...
...
@@ -319,14 +321,16 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p
pColumnInfoData
->
nullbitmap
=
tmp
;
memcpy
(
pColumnInfoData
->
nullbitmap
,
pSource
->
nullbitmap
,
BitmapLen
(
numOfRows
));
int32_t
newSize
=
numOfRows
*
pColumnInfoData
->
info
.
bytes
;
tmp
=
taosMemoryRealloc
(
pColumnInfoData
->
pData
,
newSize
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
pColumnInfoData
->
pData
)
{
int32_t
newSize
=
numOfRows
*
pColumnInfoData
->
info
.
bytes
;
tmp
=
taosMemoryRealloc
(
pColumnInfoData
->
pData
,
newSize
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pColumnInfoData
->
pData
=
tmp
;
memcpy
(
pColumnInfoData
->
pData
,
pSource
->
pData
,
pSource
->
info
.
bytes
*
numOfRows
);
pColumnInfoData
->
pData
=
tmp
;
memcpy
(
pColumnInfoData
->
pData
,
pSource
->
pData
,
pSource
->
info
.
bytes
*
numOfRows
);
}
}
pColumnInfoData
->
hasNull
=
pSource
->
hasNull
;
...
...
@@ -350,7 +354,7 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex)
return
-
1
;
}
int32_t
index
=
(
tsColumnIndex
==
-
1
)
?
0
:
tsColumnIndex
;
int32_t
index
=
(
tsColumnIndex
==
-
1
)
?
0
:
tsColumnIndex
;
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
index
);
if
(
pColInfoData
->
info
.
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
0
;
...
...
@@ -605,8 +609,8 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) {
}
int32_t
blockDataFromBuf1
(
SSDataBlock
*
pBlock
,
const
char
*
buf
,
size_t
capacity
)
{
pBlock
->
info
.
rows
=
*
(
int32_t
*
)
buf
;
pBlock
->
info
.
groupId
=
*
(
uint64_t
*
)
(
buf
+
sizeof
(
int32_t
));
pBlock
->
info
.
rows
=
*
(
int32_t
*
)
buf
;
pBlock
->
info
.
groupId
=
*
(
uint64_t
*
)(
buf
+
sizeof
(
int32_t
));
int32_t
numOfCols
=
pBlock
->
info
.
numOfCols
;
const
char
*
pStart
=
buf
+
sizeof
(
uint32_t
)
+
sizeof
(
uint64_t
);
...
...
@@ -675,7 +679,7 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
return
sizeof
(
int32_t
)
+
sizeof
(
uint64_t
)
+
pBlock
->
info
.
numOfCols
*
sizeof
(
int32_t
);
}
double
blockDataGetSerialRowSize
(
const
SSDataBlock
*
pBlock
)
{
double
blockDataGetSerialRowSize
(
const
SSDataBlock
*
pBlock
)
{
ASSERT
(
pBlock
!=
NULL
);
double
rowSize
=
0
;
...
...
@@ -1238,7 +1242,7 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) {
// the true value must be less than the value of nRows
int32_t
additional
=
0
;
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
additional
+=
nRows
*
sizeof
(
int32_t
);
...
...
source/common/src/tmsg.c
浏览文件 @
070f6040
...
...
@@ -1675,6 +1675,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
if
(
tEncodeI8
(
&
encoder
,
pReq
->
replications
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pReq
->
strict
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pReq
->
cacheLastRow
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pReq
->
schemaless
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pReq
->
ignoreExist
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pReq
->
numOfRetensions
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
numOfRetensions
;
++
i
)
{
...
...
@@ -1715,6 +1716,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq)
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
replications
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
strict
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
cacheLastRow
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
schemaless
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
ignoreExist
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pReq
->
numOfRetensions
)
<
0
)
return
-
1
;
pReq
->
pRetensions
=
taosArrayInit
(
pReq
->
numOfRetensions
,
sizeof
(
SRetention
));
...
...
@@ -3347,7 +3349,8 @@ int32_t tDeserializeSExplainRsp(void *buf, int32_t bufLen, SExplainRsp *pRsp) {
if
(
tDecodeDouble
(
&
decoder
,
&
pRsp
->
subplanInfo
[
i
].
totalCost
)
<
0
)
return
-
1
;
if
(
tDecodeU64
(
&
decoder
,
&
pRsp
->
subplanInfo
[
i
].
numOfRows
)
<
0
)
return
-
1
;
if
(
tDecodeU32
(
&
decoder
,
&
pRsp
->
subplanInfo
[
i
].
verboseLen
)
<
0
)
return
-
1
;
if
(
tDecodeBinary
(
&
decoder
,
(
uint8_t
**
)
&
pRsp
->
subplanInfo
[
i
].
verboseInfo
,
&
pRsp
->
subplanInfo
[
i
].
verboseLen
)
<
0
)
return
-
1
;
if
(
tDecodeBinary
(
&
decoder
,
(
uint8_t
**
)
&
pRsp
->
subplanInfo
[
i
].
verboseInfo
,
&
pRsp
->
subplanInfo
[
i
].
verboseLen
)
<
0
)
return
-
1
;
}
tEndDecode
(
&
decoder
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
070f6040
...
...
@@ -190,14 +190,14 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t
if
(
nodeType
(
pParamNode
)
!=
QUERY_NODE_VALUE
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SValueNode
*
pValue
=
(
SValueNode
*
)
pParamNode
;
if
(
pValue
->
datum
.
i
<
0
||
pValue
->
datum
.
i
>
100
)
{
return
invaildFuncParaValueErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
pValue
->
notReserved
=
true
;
if
(
3
==
paraNum
)
{
SNode
*
pPara3
=
nodesListGetNode
(
pFunc
->
pParameterList
,
2
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pPara3
)
||
!
validAperventileAlgo
((
SValueNode
*
)
pPara3
))
{
...
...
@@ -837,7 +837,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"top"
,
.
type
=
FUNCTION_TYPE_TOP
,
.
classification
=
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
classification
=
FUNC_MGT_
AGG_FUNC
|
FUNC_MGT_
SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
translateFunc
=
translateTop
,
.
getEnvFunc
=
getTopBotFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -847,7 +847,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"bottom"
,
.
type
=
FUNCTION_TYPE_BOTTOM
,
.
classification
=
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
classification
=
FUNC_MGT_
AGG_FUNC
|
FUNC_MGT_
SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
translateFunc
=
translateBottom
,
.
getEnvFunc
=
getTopBotFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
070f6040
...
...
@@ -191,6 +191,7 @@ static SNode* tableNodeCopy(const STableNode* pSrc, STableNode* pDst) {
COPY_CHAR_ARRAY_FIELD
(
tableName
);
COPY_CHAR_ARRAY_FIELD
(
tableAlias
);
COPY_SCALAR_FIELD
(
precision
);
COPY_SCALAR_FIELD
(
singleTable
);
return
(
SNode
*
)
pDst
;
}
...
...
@@ -326,6 +327,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
COPY_SCALAR_FIELD
(
sliding
);
COPY_SCALAR_FIELD
(
intervalUnit
);
COPY_SCALAR_FIELD
(
slidingUnit
);
CLONE_NODE_FIELD
(
pTagCond
);
return
(
SNode
*
)
pDst
;
}
...
...
@@ -333,6 +335,7 @@ static SNode* logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) {
COPY_BASE_OBJECT_FIELD
(
node
,
logicNodeCopy
);
COPY_SCALAR_FIELD
(
joinType
);
CLONE_NODE_FIELD
(
pOnConditions
);
COPY_SCALAR_FIELD
(
isSingleTableJoin
);
return
(
SNode
*
)
pDst
;
}
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
070f6040
...
...
@@ -21,149 +21,160 @@
#include "taoserror.h"
#include "thash.h"
int32_t
nodesNodeSize
(
ENodeType
type
)
{
static
SNode
*
makeNode
(
ENodeType
type
,
size_t
size
)
{
SNode
*
p
=
taosMemoryCalloc
(
1
,
size
);
if
(
NULL
==
p
)
{
return
NULL
;
}
setNodeType
(
p
,
type
);
return
p
;
}
SNodeptr
nodesMakeNode
(
ENodeType
type
)
{
switch
(
type
)
{
case
QUERY_NODE_COLUMN
:
return
sizeof
(
SColumnNode
);
return
makeNode
(
type
,
sizeof
(
SColumnNode
)
);
case
QUERY_NODE_VALUE
:
return
sizeof
(
SValueNode
);
return
makeNode
(
type
,
sizeof
(
SValueNode
)
);
case
QUERY_NODE_OPERATOR
:
return
sizeof
(
SOperatorNode
);
return
makeNode
(
type
,
sizeof
(
SOperatorNode
)
);
case
QUERY_NODE_LOGIC_CONDITION
:
return
sizeof
(
SLogicConditionNode
);
return
makeNode
(
type
,
sizeof
(
SLogicConditionNode
)
);
case
QUERY_NODE_FUNCTION
:
return
sizeof
(
SFunctionNode
);
return
makeNode
(
type
,
sizeof
(
SFunctionNode
)
);
case
QUERY_NODE_REAL_TABLE
:
return
sizeof
(
SRealTableNode
);
return
makeNode
(
type
,
sizeof
(
SRealTableNode
)
);
case
QUERY_NODE_TEMP_TABLE
:
return
sizeof
(
STempTableNode
);
return
makeNode
(
type
,
sizeof
(
STempTableNode
)
);
case
QUERY_NODE_JOIN_TABLE
:
return
sizeof
(
SJoinTableNode
);
return
makeNode
(
type
,
sizeof
(
SJoinTableNode
)
);
case
QUERY_NODE_GROUPING_SET
:
return
sizeof
(
SGroupingSetNode
);
return
makeNode
(
type
,
sizeof
(
SGroupingSetNode
)
);
case
QUERY_NODE_ORDER_BY_EXPR
:
return
sizeof
(
SOrderByExprNode
);
return
makeNode
(
type
,
sizeof
(
SOrderByExprNode
)
);
case
QUERY_NODE_LIMIT
:
return
sizeof
(
SLimitNode
);
return
makeNode
(
type
,
sizeof
(
SLimitNode
)
);
case
QUERY_NODE_STATE_WINDOW
:
return
sizeof
(
SStateWindowNode
);
return
makeNode
(
type
,
sizeof
(
SStateWindowNode
)
);
case
QUERY_NODE_SESSION_WINDOW
:
return
sizeof
(
SSessionWindowNode
);
return
makeNode
(
type
,
sizeof
(
SSessionWindowNode
)
);
case
QUERY_NODE_INTERVAL_WINDOW
:
return
sizeof
(
SIntervalWindowNode
);
return
makeNode
(
type
,
sizeof
(
SIntervalWindowNode
)
);
case
QUERY_NODE_NODE_LIST
:
return
sizeof
(
SNodeListNode
);
return
makeNode
(
type
,
sizeof
(
SNodeListNode
)
);
case
QUERY_NODE_FILL
:
return
sizeof
(
SFillNode
);
return
makeNode
(
type
,
sizeof
(
SFillNode
)
);
case
QUERY_NODE_RAW_EXPR
:
return
sizeof
(
SRawExprNode
);
return
makeNode
(
type
,
sizeof
(
SRawExprNode
)
);
case
QUERY_NODE_TARGET
:
return
sizeof
(
STargetNode
);
return
makeNode
(
type
,
sizeof
(
STargetNode
)
);
case
QUERY_NODE_DATABLOCK_DESC
:
return
sizeof
(
SDataBlockDescNode
);
return
makeNode
(
type
,
sizeof
(
SDataBlockDescNode
)
);
case
QUERY_NODE_SLOT_DESC
:
return
sizeof
(
SSlotDescNode
);
return
makeNode
(
type
,
sizeof
(
SSlotDescNode
)
);
case
QUERY_NODE_COLUMN_DEF
:
return
sizeof
(
SColumnDefNode
);
return
makeNode
(
type
,
sizeof
(
SColumnDefNode
)
);
case
QUERY_NODE_DOWNSTREAM_SOURCE
:
return
sizeof
(
SDownstreamSourceNode
);
return
makeNode
(
type
,
sizeof
(
SDownstreamSourceNode
)
);
case
QUERY_NODE_DATABASE_OPTIONS
:
return
sizeof
(
SDatabaseOptions
);
return
makeNode
(
type
,
sizeof
(
SDatabaseOptions
)
);
case
QUERY_NODE_TABLE_OPTIONS
:
return
sizeof
(
STableOptions
);
return
makeNode
(
type
,
sizeof
(
STableOptions
)
);
case
QUERY_NODE_INDEX_OPTIONS
:
return
sizeof
(
SIndexOptions
);
return
makeNode
(
type
,
sizeof
(
SIndexOptions
)
);
case
QUERY_NODE_EXPLAIN_OPTIONS
:
return
sizeof
(
SExplainOptions
);
return
makeNode
(
type
,
sizeof
(
SExplainOptions
)
);
case
QUERY_NODE_STREAM_OPTIONS
:
return
sizeof
(
SStreamOptions
);
return
makeNode
(
type
,
sizeof
(
SStreamOptions
)
);
case
QUERY_NODE_TOPIC_OPTIONS
:
return
sizeof
(
STopicOptions
);
return
makeNode
(
type
,
sizeof
(
STopicOptions
)
);
case
QUERY_NODE_LEFT_VALUE
:
return
sizeof
(
SLeftValueNode
);
return
makeNode
(
type
,
sizeof
(
SLeftValueNode
)
);
case
QUERY_NODE_SET_OPERATOR
:
return
sizeof
(
SSetOperator
);
return
makeNode
(
type
,
sizeof
(
SSetOperator
)
);
case
QUERY_NODE_SELECT_STMT
:
return
sizeof
(
SSelectStmt
);
return
makeNode
(
type
,
sizeof
(
SSelectStmt
)
);
case
QUERY_NODE_VNODE_MODIF_STMT
:
return
sizeof
(
SVnodeModifOpStmt
);
return
makeNode
(
type
,
sizeof
(
SVnodeModifOpStmt
)
);
case
QUERY_NODE_CREATE_DATABASE_STMT
:
return
sizeof
(
SCreateDatabaseStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateDatabaseStmt
)
);
case
QUERY_NODE_DROP_DATABASE_STMT
:
return
sizeof
(
SDropDatabaseStmt
);
return
makeNode
(
type
,
sizeof
(
SDropDatabaseStmt
)
);
case
QUERY_NODE_ALTER_DATABASE_STMT
:
return
sizeof
(
SAlterDatabaseStmt
);
return
makeNode
(
type
,
sizeof
(
SAlterDatabaseStmt
)
);
case
QUERY_NODE_CREATE_TABLE_STMT
:
return
sizeof
(
SCreateTableStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateTableStmt
)
);
case
QUERY_NODE_CREATE_SUBTABLE_CLAUSE
:
return
sizeof
(
SCreateSubTableClause
);
return
makeNode
(
type
,
sizeof
(
SCreateSubTableClause
)
);
case
QUERY_NODE_CREATE_MULTI_TABLE_STMT
:
return
sizeof
(
SCreateMultiTableStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateMultiTableStmt
)
);
case
QUERY_NODE_DROP_TABLE_CLAUSE
:
return
sizeof
(
SDropTableClause
);
return
makeNode
(
type
,
sizeof
(
SDropTableClause
)
);
case
QUERY_NODE_DROP_TABLE_STMT
:
return
sizeof
(
SDropTableStmt
);
return
makeNode
(
type
,
sizeof
(
SDropTableStmt
)
);
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
return
sizeof
(
SDropSuperTableStmt
);
return
makeNode
(
type
,
sizeof
(
SDropSuperTableStmt
)
);
case
QUERY_NODE_ALTER_TABLE_STMT
:
return
sizeof
(
SAlterTableStmt
);
return
makeNode
(
type
,
sizeof
(
SAlterTableStmt
)
);
case
QUERY_NODE_CREATE_USER_STMT
:
return
sizeof
(
SCreateUserStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateUserStmt
)
);
case
QUERY_NODE_ALTER_USER_STMT
:
return
sizeof
(
SAlterUserStmt
);
return
makeNode
(
type
,
sizeof
(
SAlterUserStmt
)
);
case
QUERY_NODE_DROP_USER_STMT
:
return
sizeof
(
SDropUserStmt
);
return
makeNode
(
type
,
sizeof
(
SDropUserStmt
)
);
case
QUERY_NODE_USE_DATABASE_STMT
:
return
sizeof
(
SUseDatabaseStmt
);
return
makeNode
(
type
,
sizeof
(
SUseDatabaseStmt
)
);
case
QUERY_NODE_CREATE_DNODE_STMT
:
return
sizeof
(
SCreateDnodeStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateDnodeStmt
)
);
case
QUERY_NODE_DROP_DNODE_STMT
:
return
sizeof
(
SDropDnodeStmt
);
return
makeNode
(
type
,
sizeof
(
SDropDnodeStmt
)
);
case
QUERY_NODE_ALTER_DNODE_STMT
:
return
sizeof
(
SAlterDnodeStmt
);
return
makeNode
(
type
,
sizeof
(
SAlterDnodeStmt
)
);
case
QUERY_NODE_CREATE_INDEX_STMT
:
return
sizeof
(
SCreateIndexStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateIndexStmt
)
);
case
QUERY_NODE_DROP_INDEX_STMT
:
return
sizeof
(
SDropIndexStmt
);
return
makeNode
(
type
,
sizeof
(
SDropIndexStmt
)
);
case
QUERY_NODE_CREATE_QNODE_STMT
:
case
QUERY_NODE_CREATE_BNODE_STMT
:
case
QUERY_NODE_CREATE_SNODE_STMT
:
case
QUERY_NODE_CREATE_MNODE_STMT
:
return
sizeof
(
SCreateComponentNodeStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateComponentNodeStmt
)
);
case
QUERY_NODE_DROP_QNODE_STMT
:
case
QUERY_NODE_DROP_BNODE_STMT
:
case
QUERY_NODE_DROP_SNODE_STMT
:
case
QUERY_NODE_DROP_MNODE_STMT
:
return
sizeof
(
SDropComponentNodeStmt
);
return
makeNode
(
type
,
sizeof
(
SDropComponentNodeStmt
)
);
case
QUERY_NODE_CREATE_TOPIC_STMT
:
return
sizeof
(
SCreateTopicStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateTopicStmt
)
);
case
QUERY_NODE_DROP_TOPIC_STMT
:
return
sizeof
(
SDropTopicStmt
);
return
makeNode
(
type
,
sizeof
(
SDropTopicStmt
));
case
QUERY_NODE_DROP_CGROUP_STMT
:
return
makeNode
(
type
,
sizeof
(
SDropCGroupStmt
));
case
QUERY_NODE_EXPLAIN_STMT
:
return
sizeof
(
SExplainStmt
);
return
makeNode
(
type
,
sizeof
(
SExplainStmt
)
);
case
QUERY_NODE_DESCRIBE_STMT
:
return
sizeof
(
SDescribeStmt
);
return
makeNode
(
type
,
sizeof
(
SDescribeStmt
)
);
case
QUERY_NODE_RESET_QUERY_CACHE_STMT
:
return
sizeof
(
SNode
);
return
makeNode
(
type
,
sizeof
(
SNode
)
);
case
QUERY_NODE_COMPACT_STMT
:
break
;
case
QUERY_NODE_CREATE_FUNCTION_STMT
:
return
sizeof
(
SCreateFunctionStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateFunctionStmt
)
);
case
QUERY_NODE_DROP_FUNCTION_STMT
:
return
sizeof
(
SDropFunctionStmt
);
return
makeNode
(
type
,
sizeof
(
SDropFunctionStmt
)
);
case
QUERY_NODE_CREATE_STREAM_STMT
:
return
sizeof
(
SCreateStreamStmt
);
return
makeNode
(
type
,
sizeof
(
SCreateStreamStmt
)
);
case
QUERY_NODE_DROP_STREAM_STMT
:
return
sizeof
(
SDropStreamStmt
);
return
makeNode
(
type
,
sizeof
(
SDropStreamStmt
)
);
case
QUERY_NODE_MERGE_VGROUP_STMT
:
case
QUERY_NODE_REDISTRIBUTE_VGROUP_STMT
:
case
QUERY_NODE_SPLIT_VGROUP_STMT
:
case
QUERY_NODE_SYNCDB_STMT
:
break
;
case
QUERY_NODE_GRANT_STMT
:
return
sizeof
(
SGrantStmt
);
return
makeNode
(
type
,
sizeof
(
SGrantStmt
)
);
case
QUERY_NODE_REVOKE_STMT
:
return
sizeof
(
SRevokeStmt
);
return
makeNode
(
type
,
sizeof
(
SRevokeStmt
)
);
case
QUERY_NODE_SHOW_DNODES_STMT
:
case
QUERY_NODE_SHOW_MNODES_STMT
:
case
QUERY_NODE_SHOW_MODULES_STMT
:
...
...
@@ -194,89 +205,80 @@ int32_t nodesNodeSize(ENodeType type) {
case
QUERY_NODE_SHOW_CREATE_TABLE_STMT
:
case
QUERY_NODE_SHOW_CREATE_STABLE_STMT
:
case
QUERY_NODE_SHOW_TRANSACTIONS_STMT
:
return
sizeof
(
SShowStmt
);
return
makeNode
(
type
,
sizeof
(
SShowStmt
)
);
case
QUERY_NODE_KILL_CONNECTION_STMT
:
case
QUERY_NODE_KILL_QUERY_STMT
:
case
QUERY_NODE_KILL_TRANSACTION_STMT
:
return
sizeof
(
SKillStmt
);
return
makeNode
(
type
,
sizeof
(
SKillStmt
)
);
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
return
sizeof
(
SScanLogicNode
);
return
makeNode
(
type
,
sizeof
(
SScanLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
return
sizeof
(
SJoinLogicNode
);
return
makeNode
(
type
,
sizeof
(
SJoinLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_AGG
:
return
sizeof
(
SAggLogicNode
);
return
makeNode
(
type
,
sizeof
(
SAggLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
return
sizeof
(
SProjectLogicNode
);
return
makeNode
(
type
,
sizeof
(
SProjectLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_VNODE_MODIF
:
return
sizeof
(
SVnodeModifLogicNode
);
return
makeNode
(
type
,
sizeof
(
SVnodeModifLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_EXCHANGE
:
return
sizeof
(
SExchangeLogicNode
);
return
makeNode
(
type
,
sizeof
(
SExchangeLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_WINDOW
:
return
sizeof
(
SWindowLogicNode
);
return
makeNode
(
type
,
sizeof
(
SWindowLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_FILL
:
return
sizeof
(
SFillLogicNode
);
return
makeNode
(
type
,
sizeof
(
SFillLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_SORT
:
return
sizeof
(
SSortLogicNode
);
return
makeNode
(
type
,
sizeof
(
SSortLogicNode
)
);
case
QUERY_NODE_LOGIC_PLAN_PARTITION
:
return
sizeof
(
SPartitionLogicNode
);
return
makeNode
(
type
,
sizeof
(
SPartitionLogicNode
)
);
case
QUERY_NODE_LOGIC_SUBPLAN
:
return
sizeof
(
SLogicSubplan
);
return
makeNode
(
type
,
sizeof
(
SLogicSubplan
)
);
case
QUERY_NODE_LOGIC_PLAN
:
return
sizeof
(
SQueryLogicPlan
);
return
makeNode
(
type
,
sizeof
(
SQueryLogicPlan
)
);
case
QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN
:
return
sizeof
(
STagScanPhysiNode
);
return
makeNode
(
type
,
sizeof
(
STagScanPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
return
sizeof
(
STableScanPhysiNode
);
return
makeNode
(
type
,
sizeof
(
STableScanPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN
:
return
sizeof
(
STableSeqScanPhysiNode
);
return
makeNode
(
type
,
sizeof
(
STableSeqScanPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
return
sizeof
(
SStreamScanPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SStreamScanPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN
:
return
sizeof
(
SSystemTableScanPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SSystemTableScanPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
return
sizeof
(
SProjectPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SProjectPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
return
sizeof
(
SJoinPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SJoinPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_AGG
:
return
sizeof
(
SAggPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SAggPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_EXCHANGE
:
return
sizeof
(
SExchangePhysiNode
);
return
makeNode
(
type
,
sizeof
(
SExchangePhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
return
sizeof
(
SSortPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SSortPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_INTERVAL
:
return
sizeof
(
SIntervalPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SIntervalPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL
:
return
sizeof
(
SStreamIntervalPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SStreamIntervalPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_FILL
:
return
sizeof
(
SFillPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SFillPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW
:
return
sizeof
(
SSessionWinodwPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SSessionWinodwPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW
:
return
sizeof
(
SStateWinodwPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SStateWinodwPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_PARTITION
:
return
sizeof
(
SPartitionPhysiNode
);
return
makeNode
(
type
,
sizeof
(
SPartitionPhysiNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_DISPATCH
:
return
sizeof
(
SDataDispatcherNode
);
return
makeNode
(
type
,
sizeof
(
SDataDispatcherNode
)
);
case
QUERY_NODE_PHYSICAL_PLAN_INSERT
:
return
sizeof
(
SDataInserterNode
);
return
makeNode
(
type
,
sizeof
(
SDataInserterNode
)
);
case
QUERY_NODE_PHYSICAL_SUBPLAN
:
return
sizeof
(
SSubplan
);
return
makeNode
(
type
,
sizeof
(
SSubplan
)
);
case
QUERY_NODE_PHYSICAL_PLAN
:
return
sizeof
(
SQueryPlan
);
return
makeNode
(
type
,
sizeof
(
SQueryPlan
)
);
default:
break
;
}
nodesError
(
"nodesMakeNode unknown node = %s"
,
nodesNodeName
(
type
));
return
0
;
}
SNodeptr
nodesMakeNode
(
ENodeType
type
)
{
SNode
*
p
=
taosMemoryCalloc
(
1
,
nodesNodeSize
(
type
));
if
(
NULL
==
p
)
{
return
NULL
;
}
setNodeType
(
p
,
type
);
return
p
;
return
NULL
;
}
static
void
destroyVgDataBlockArray
(
SArray
*
pArray
)
{
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
070f6040
...
...
@@ -53,7 +53,8 @@ typedef enum EDatabaseOptionType {
DB_OPTION_WAL
,
DB_OPTION_VGROUPS
,
DB_OPTION_SINGLE_STABLE
,
DB_OPTION_RETENTIONS
DB_OPTION_RETENTIONS
,
DB_OPTION_SCHEMALESS
}
EDatabaseOptionType
;
typedef
enum
ETableOptionType
{
...
...
@@ -169,6 +170,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt);
SNode
*
createCreateTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pTopicName
,
SNode
*
pQuery
,
const
SToken
*
pSubscribeDbName
,
SNode
*
pOptions
);
SNode
*
createDropTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pTopicName
);
SNode
*
createDropCGroupStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pCGroupId
,
const
SToken
*
pTopicName
);
SNode
*
createAlterLocalStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
SNode
*
createDefaultExplainOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setExplainVerbose
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
const
SToken
*
pVal
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
070f6040
...
...
@@ -180,6 +180,7 @@ db_options(A) ::= db_options(B) WAL NK_INTEGER(C).
db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); }
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); }
db_options(A) ::= db_options(B) RETENTIONS retention_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, C); }
db_options(A) ::= db_options(B) SCHEMALESS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SCHEMALESS, &C); }
alter_db_options(A) ::= alter_db_option(B). { A = createAlterDatabaseOptions(pCxt); A = setAlterDatabaseOption(pCxt, A, &B); }
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setAlterDatabaseOption(pCxt, B, &C); }
...
...
@@ -407,6 +408,7 @@ cmd ::= CREATE TOPIC not_exists_opt(A)
cmd ::= CREATE TOPIC not_exists_opt(A)
topic_name(B) topic_options(D) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C, D); }
cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); }
cmd ::= DROP CGROUP exists_opt(A) cgroup_name(B) ON topic_name(C). { pCxt->pRootNode = createDropCGroupStmt(pCxt, A, &B, &C); }
topic_options(A) ::= . { A = createTopicOptions(pCxt); }
topic_options(A) ::= topic_options(B) WITH TABLE. { ((STopicOptions*)B)->withTable = true; A = B; }
...
...
@@ -565,6 +567,10 @@ topic_name(A) ::= NK_ID(B).
%destructor stream_name { }
stream_name(A) ::= NK_ID(B). { A = B; }
%type cgroup_name { SToken }
%destructor cgroup_name { }
cgroup_name(A) ::= NK_ID(B). { A = B; }
/************************************************ expression **********************************************************/
expression(A) ::= literal(B). { A = B; }
expression(A) ::= pseudo_column(B). { A = B; }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
070f6040
此差异已折叠。
点击以展开。
source/libs/parser/src/parCalcConst.c
浏览文件 @
070f6040
...
...
@@ -176,11 +176,11 @@ static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
}
int32_t
code
=
scalarCalculateConstants
(
pProject
,
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
QUERY_NODE_VALUE
==
nodeType
(
pNew
)
&&
NULL
!=
pAssociation
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
QUERY_NODE_VALUE
==
nodeType
(
*
pNew
)
&&
NULL
!=
pAssociation
)
{
int32_t
size
=
taosArrayGetSize
(
pAssociation
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SNode
**
pCol
=
taosArrayGet
(
pAssociation
,
i
);
*
pCol
=
nodesCloneNode
(
pNew
);
SNode
**
pCol
=
taosArrayGet
P
(
pAssociation
,
i
);
*
pCol
=
nodesCloneNode
(
*
pNew
);
if
(
NULL
==
*
pCol
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -233,9 +233,9 @@ static int32_t calcConstGroupBy(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
}
static
int32_t
calcConstSelect
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
int32_t
code
=
calcConst
Projections
(
pCxt
,
pSelect
,
subquery
);
int32_t
code
=
calcConst
FromTable
(
pCxt
,
pSelect
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConst
FromTable
(
pCxt
,
pSelect
);
code
=
calcConst
Projections
(
pCxt
,
pSelect
,
subquery
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstSelectCondition
(
pCxt
,
pSelect
,
&
pSelect
->
pWhere
);
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
070f6040
...
...
@@ -53,6 +53,7 @@ static SKeyword keywordTable[] = {
{
"CACHE"
,
TK_CACHE
},
{
"CACHELAST"
,
TK_CACHELAST
},
{
"CAST"
,
TK_CAST
},
{
"CGROUP"
,
TK_CGROUP
},
{
"CLUSTER"
,
TK_CLUSTER
},
{
"COLUMN"
,
TK_COLUMN
},
{
"COMMENT"
,
TK_COMMENT
},
...
...
@@ -156,6 +157,7 @@ static SKeyword keywordTable[] = {
{
"REVOKE"
,
TK_REVOKE
},
{
"ROLLUP"
,
TK_ROLLUP
},
{
"SCHEMA"
,
TK_SCHEMA
},
{
"SCHEMALESS"
,
TK_SCHEMALESS
},
{
"SCORES"
,
TK_SCORES
},
{
"SELECT"
,
TK_SELECT
},
{
"SESSION"
,
TK_SESSION
},
...
...
@@ -605,12 +607,12 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
}
return
i
;
}
case
'['
:
{
for
(
i
=
1
;
z
[
i
]
&&
z
[
i
-
1
]
!=
']'
;
i
++
)
{
}
*
tokenId
=
TK_NK_ID
;
return
i
;
}
//
case '[': {
//
for (i = 1; z[i] && z[i - 1] != ']'; i++) {
//
}
//
*tokenId = TK_NK_ID;
//
return i;
//
}
case
'T'
:
case
't'
:
case
'F'
:
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
070f6040
...
...
@@ -342,12 +342,14 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
}
}
static
void
setColumnInfoByExpr
(
const
STableNode
*
pTable
,
SExprNode
*
pExpr
,
SColumnNode
*
pCol
)
{
static
void
setColumnInfoByExpr
(
const
STableNode
*
pTable
,
SExprNode
*
pExpr
,
SColumnNode
**
pColRef
)
{
SColumnNode
*
pCol
=
*
pColRef
;
pCol
->
pProjectRef
=
(
SNode
*
)
pExpr
;
if
(
NULL
==
pExpr
->
pAssociation
)
{
pExpr
->
pAssociation
=
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
);
}
taosArrayPush
(
pExpr
->
pAssociation
,
&
pCol
);
taosArrayPush
(
pExpr
->
pAssociation
,
&
pCol
Ref
);
if
(
NULL
!=
pTable
)
{
strcpy
(
pCol
->
tableAlias
,
pTable
->
tableAlias
);
}
else
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pExpr
))
{
...
...
@@ -385,7 +387,7 @@ static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* p
if
(
NULL
==
pCol
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_OUT_OF_MEMORY
);
}
setColumnInfoByExpr
(
pTable
,
(
SExprNode
*
)
pNode
,
pCol
);
setColumnInfoByExpr
(
pTable
,
(
SExprNode
*
)
pNode
,
&
pCol
);
nodesListAppend
(
pList
,
(
SNode
*
)
pCol
);
}
}
...
...
@@ -425,8 +427,9 @@ static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) {
return
isPrimaryKeyImpl
(
pTable
,
pExpr
);
}
static
bool
findAndSetColumn
(
SColumnNode
*
pCol
,
const
STableNode
*
pTable
)
{
bool
found
=
false
;
static
bool
findAndSetColumn
(
SColumnNode
**
pColRef
,
const
STableNode
*
pTable
)
{
SColumnNode
*
pCol
=
*
pColRef
;
bool
found
=
false
;
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
const
STableMeta
*
pMeta
=
((
SRealTableNode
*
)
pTable
)
->
pMeta
;
if
(
isInternalPrimaryKey
(
pCol
))
{
...
...
@@ -448,7 +451,7 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
SExprNode
*
pExpr
=
(
SExprNode
*
)
pNode
;
if
(
0
==
strcmp
(
pCol
->
colName
,
pExpr
->
aliasName
)
||
(
isPrimaryKey
((
STempTableNode
*
)
pTable
,
pNode
)
&&
isInternalPrimaryKey
(
pCol
)))
{
setColumnInfoByExpr
(
pTable
,
pExpr
,
pCol
);
setColumnInfoByExpr
(
pTable
,
pExpr
,
pCol
Ref
);
found
=
true
;
break
;
}
...
...
@@ -457,36 +460,36 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
return
found
;
}
static
EDealRes
translateColumnWithPrefix
(
STranslateContext
*
pCxt
,
SColumnNode
*
pCol
)
{
static
EDealRes
translateColumnWithPrefix
(
STranslateContext
*
pCxt
,
SColumnNode
*
*
pCol
)
{
SArray
*
pTables
=
taosArrayGetP
(
pCxt
->
pNsLevel
,
pCxt
->
currLevel
);
size_t
nums
=
taosArrayGetSize
(
pTables
);
bool
foundTable
=
false
;
for
(
size_t
i
=
0
;
i
<
nums
;
++
i
)
{
STableNode
*
pTable
=
taosArrayGetP
(
pTables
,
i
);
if
(
belongTable
(
pCxt
->
pParseCxt
->
db
,
pCol
,
pTable
))
{
if
(
belongTable
(
pCxt
->
pParseCxt
->
db
,
(
*
pCol
)
,
pTable
))
{
foundTable
=
true
;
if
(
findAndSetColumn
(
pCol
,
pTable
))
{
break
;
}
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_COLUMN
,
pCol
->
colName
);
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_COLUMN
,
(
*
pCol
)
->
colName
);
}
}
if
(
!
foundTable
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
,
pCol
->
tableAlias
);
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
,
(
*
pCol
)
->
tableAlias
);
}
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
translateColumnWithoutPrefix
(
STranslateContext
*
pCxt
,
SColumnNode
*
pCol
)
{
static
EDealRes
translateColumnWithoutPrefix
(
STranslateContext
*
pCxt
,
SColumnNode
*
*
pCol
)
{
SArray
*
pTables
=
taosArrayGetP
(
pCxt
->
pNsLevel
,
pCxt
->
currLevel
);
size_t
nums
=
taosArrayGetSize
(
pTables
);
bool
found
=
false
;
bool
isInternalPk
=
isInternalPrimaryKey
(
pCol
);
bool
isInternalPk
=
isInternalPrimaryKey
(
*
pCol
);
for
(
size_t
i
=
0
;
i
<
nums
;
++
i
)
{
STableNode
*
pTable
=
taosArrayGetP
(
pTables
,
i
);
if
(
findAndSetColumn
(
pCol
,
pTable
))
{
if
(
found
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
,
pCol
->
colName
);
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
,
(
*
pCol
)
->
colName
);
}
found
=
true
;
if
(
isInternalPk
)
{
...
...
@@ -501,18 +504,18 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
}
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_INTERNAL_PK
);
}
else
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_COLUMN
,
pCol
->
colName
);
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_COLUMN
,
(
*
pCol
)
->
colName
);
}
}
return
DEAL_RES_CONTINUE
;
}
static
bool
translateColumnUseAlias
(
STranslateContext
*
pCxt
,
SColumnNode
*
pCol
)
{
static
bool
translateColumnUseAlias
(
STranslateContext
*
pCxt
,
SColumnNode
*
*
pCol
)
{
SNodeList
*
pProjectionList
=
pCxt
->
pCurrStmt
->
pProjectionList
;
SNode
*
pNode
;
FOREACH
(
pNode
,
pProjectionList
)
{
SExprNode
*
pExpr
=
(
SExprNode
*
)
pNode
;
if
(
0
==
strcmp
(
pCol
->
colName
,
pExpr
->
aliasName
))
{
if
(
0
==
strcmp
(
(
*
pCol
)
->
colName
,
pExpr
->
aliasName
))
{
setColumnInfoByExpr
(
NULL
,
pExpr
,
pCol
);
return
true
;
}
...
...
@@ -520,14 +523,14 @@ static bool translateColumnUseAlias(STranslateContext* pCxt, SColumnNode* pCol)
return
false
;
}
static
EDealRes
translateColumn
(
STranslateContext
*
pCxt
,
SColumnNode
*
pCol
)
{
static
EDealRes
translateColumn
(
STranslateContext
*
pCxt
,
SColumnNode
*
*
pCol
)
{
// count(*)/first(*)/last(*) and so on
if
(
0
==
strcmp
(
pCol
->
colName
,
"*"
))
{
if
(
0
==
strcmp
(
(
*
pCol
)
->
colName
,
"*"
))
{
return
DEAL_RES_CONTINUE
;
}
EDealRes
res
=
DEAL_RES_CONTINUE
;
if
(
'\0'
!=
pCol
->
tableAlias
[
0
])
{
if
(
'\0'
!=
(
*
pCol
)
->
tableAlias
[
0
])
{
res
=
translateColumnWithPrefix
(
pCxt
,
pCol
);
}
else
{
bool
found
=
false
;
...
...
@@ -870,6 +873,55 @@ static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc) {
return
fmGetFuncInfo
(
&
param
,
pFunc
);
}
static
int32_t
translateAggFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
if
(
beforeHaving
(
pCxt
->
currClause
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
}
if
(
hasInvalidFuncNesting
(
pFunc
->
pParameterList
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
}
if
(
pCxt
->
pCurrStmt
->
hasIndefiniteRowsFunc
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
}
if
(
isCountStar
(
pFunc
))
{
return
rewriteCountStar
(
pCxt
,
pFunc
);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateScanPseudoColumnFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
if
(
0
==
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
if
(
QUERY_NODE_REAL_TABLE
!=
nodeType
(
pCxt
->
pCurrStmt
->
pFromTable
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TBNAME
);
}
}
else
{
SValueNode
*
pVal
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
STableNode
*
pTable
=
NULL
;
pCxt
->
errCode
=
findTable
(
pCxt
,
pVal
->
literal
,
&
pTable
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
(
NULL
==
pTable
||
QUERY_NODE_REAL_TABLE
!=
nodeType
(
pTable
)))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TBNAME
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateIndefiniteRowsFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
if
(
SQL_CLAUSE_SELECT
!=
pCxt
->
currClause
||
pCxt
->
pCurrStmt
->
hasIndefiniteRowsFunc
||
pCxt
->
pCurrStmt
->
hasAggFuncs
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
}
if
(
hasInvalidFuncNesting
(
pFunc
->
pParameterList
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
}
return
TSDB_CODE_SUCCESS
;
}
static
void
setFuncClassification
(
SSelectStmt
*
pSelect
,
SFunctionNode
*
pFunc
)
{
pSelect
->
hasAggFuncs
=
pSelect
->
hasAggFuncs
?
true
:
fmIsAggFunc
(
pFunc
->
funcId
);
pSelect
->
hasRepeatScanFuncs
=
pSelect
->
hasRepeatScanFuncs
?
true
:
fmIsRepeatScanFunc
(
pFunc
->
funcId
);
pSelect
->
hasIndefiniteRowsFunc
=
pSelect
->
hasIndefiniteRowsFunc
?
true
:
fmIsIndefiniteRowsFunc
(
pFunc
->
funcId
);
}
static
EDealRes
translateFunction
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
SNode
*
pParam
=
NULL
;
FOREACH
(
pParam
,
pFunc
->
pParameterList
)
{
...
...
@@ -880,48 +932,16 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
pCxt
->
errCode
=
getFuncInfo
(
pCxt
,
pFunc
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
fmIsAggFunc
(
pFunc
->
funcId
))
{
if
(
beforeHaving
(
pCxt
->
currClause
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
}
if
(
hasInvalidFuncNesting
(
pFunc
->
pParameterList
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
}
if
(
pCxt
->
pCurrStmt
->
hasIndefiniteRowsFunc
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
}
pCxt
->
pCurrStmt
->
hasAggFuncs
=
true
;
if
(
isCountStar
(
pFunc
))
{
pCxt
->
errCode
=
rewriteCountStar
(
pCxt
,
pFunc
);
}
if
(
fmIsRepeatScanFunc
(
pFunc
->
funcId
))
{
pCxt
->
pCurrStmt
->
hasRepeatScanFuncs
=
true
;
}
pCxt
->
errCode
=
translateAggFunc
(
pCxt
,
pFunc
);
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
fmIsScanPseudoColumnFunc
(
pFunc
->
funcId
))
{
if
(
0
==
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
if
(
QUERY_NODE_REAL_TABLE
!=
nodeType
(
pCxt
->
pCurrStmt
->
pFromTable
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_TBNAME
);
}
}
else
{
SValueNode
*
pVal
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
STableNode
*
pTable
=
NULL
;
pCxt
->
errCode
=
findTable
(
pCxt
,
pVal
->
literal
,
&
pTable
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
(
NULL
==
pTable
||
QUERY_NODE_REAL_TABLE
!=
nodeType
(
pTable
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_TBNAME
);
}
}
pCxt
->
errCode
=
translateScanPseudoColumnFunc
(
pCxt
,
pFunc
);
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
fmIsIndefiniteRowsFunc
(
pFunc
->
funcId
))
{
if
(
SQL_CLAUSE_SELECT
!=
pCxt
->
currClause
||
pCxt
->
pCurrStmt
->
hasIndefiniteRowsFunc
||
pCxt
->
pCurrStmt
->
hasAggFuncs
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
}
if
(
hasInvalidFuncNesting
(
pFunc
->
pParameterList
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
}
pCxt
->
pCurrStmt
->
hasIndefiniteRowsFunc
=
true
;
pCxt
->
errCode
=
translateIndefiniteRowsFunc
(
pCxt
,
pFunc
);
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
setFuncClassification
(
pCxt
->
pCurrStmt
,
pFunc
);
}
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_CONTINUE
:
DEAL_RES_ERROR
;
}
...
...
@@ -936,34 +956,34 @@ static EDealRes translateLogicCond(STranslateContext* pCxt, SLogicConditionNode*
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
doTranslateExpr
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
doTranslateExpr
(
SNode
*
*
pNode
,
void
*
pContext
)
{
STranslateContext
*
pCxt
=
(
STranslateContext
*
)
pContext
;
switch
(
nodeType
(
pNode
))
{
switch
(
nodeType
(
*
pNode
))
{
case
QUERY_NODE_COLUMN
:
return
translateColumn
(
pCxt
,
(
SColumnNode
*
)
pNode
);
return
translateColumn
(
pCxt
,
(
SColumnNode
*
*
)
pNode
);
case
QUERY_NODE_VALUE
:
return
translateValue
(
pCxt
,
(
SValueNode
*
)
pNode
);
return
translateValue
(
pCxt
,
(
SValueNode
*
)
*
pNode
);
case
QUERY_NODE_OPERATOR
:
return
translateOperator
(
pCxt
,
(
SOperatorNode
*
)
pNode
);
return
translateOperator
(
pCxt
,
(
SOperatorNode
*
)
*
pNode
);
case
QUERY_NODE_FUNCTION
:
return
translateFunction
(
pCxt
,
(
SFunctionNode
*
)
pNode
);
return
translateFunction
(
pCxt
,
(
SFunctionNode
*
)
*
pNode
);
case
QUERY_NODE_LOGIC_CONDITION
:
return
translateLogicCond
(
pCxt
,
(
SLogicConditionNode
*
)
pNode
);
return
translateLogicCond
(
pCxt
,
(
SLogicConditionNode
*
)
*
pNode
);
case
QUERY_NODE_TEMP_TABLE
:
return
translateExprSubquery
(
pCxt
,
((
STempTableNode
*
)
pNode
)
->
pSubquery
);
return
translateExprSubquery
(
pCxt
,
((
STempTableNode
*
)
*
pNode
)
->
pSubquery
);
default:
break
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
translateExpr
(
STranslateContext
*
pCxt
,
SNode
*
pNode
)
{
nodes
Walk
ExprPostOrder
(
pNode
,
doTranslateExpr
,
pCxt
);
static
int32_t
translateExpr
(
STranslateContext
*
pCxt
,
SNode
*
*
pNode
)
{
nodes
Rewrite
ExprPostOrder
(
pNode
,
doTranslateExpr
,
pCxt
);
return
pCxt
->
errCode
;
}
static
int32_t
translateExprList
(
STranslateContext
*
pCxt
,
SNodeList
*
pList
)
{
nodes
Walk
ExprsPostOrder
(
pList
,
doTranslateExpr
,
pCxt
);
nodes
Rewrite
ExprsPostOrder
(
pList
,
doTranslateExpr
,
pCxt
);
return
pCxt
->
errCode
;
}
...
...
@@ -1238,12 +1258,31 @@ static uint8_t getStmtPrecision(SNode* pStmt) {
return
0
;
}
static
bool
stmtIsSingleTable
(
SNode
*
pStmt
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
return
((
STableNode
*
)((
SSelectStmt
*
)
pStmt
)
->
pFromTable
)
->
singleTable
;
}
return
false
;
}
static
uint8_t
getJoinTablePrecision
(
SJoinTableNode
*
pJoinTable
)
{
uint8_t
lp
=
((
STableNode
*
)
pJoinTable
->
pLeft
)
->
precision
;
uint8_t
rp
=
((
STableNode
*
)
pJoinTable
->
pRight
)
->
precision
;
return
(
lp
>
rp
?
rp
:
lp
);
}
static
bool
joinTableIsSingleTable
(
SJoinTableNode
*
pJoinTable
)
{
return
(((
STableNode
*
)
pJoinTable
->
pLeft
)
->
singleTable
&&
((
STableNode
*
)
pJoinTable
->
pRight
)
->
singleTable
);
}
static
bool
isSingleTable
(
SRealTableNode
*
pRealTable
)
{
int8_t
tableType
=
pRealTable
->
pMeta
->
tableType
;
if
(
TSDB_SYSTEM_TABLE
==
tableType
)
{
return
0
!=
strcmp
(
pRealTable
->
table
.
tableName
,
TSDB_INS_TABLE_USER_TABLES
);
}
return
(
TSDB_CHILD_TABLE
==
tableType
||
TSDB_NORMAL_TABLE
==
tableType
);
}
static
int32_t
translateTable
(
STranslateContext
*
pCxt
,
SNode
*
pTable
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pTable
))
{
...
...
@@ -1262,6 +1301,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
code
=
setTableVgroupList
(
pCxt
,
&
name
,
pRealTable
);
}
pRealTable
->
table
.
precision
=
pRealTable
->
pMeta
->
tableInfo
.
precision
;
pRealTable
->
table
.
singleTable
=
isSingleTable
(
pRealTable
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
addNamespace
(
pCxt
,
pRealTable
);
}
...
...
@@ -1272,6 +1312,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
code
=
translateSubquery
(
pCxt
,
pTempTable
->
pSubquery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pTempTable
->
table
.
precision
=
getStmtPrecision
(
pTempTable
->
pSubquery
);
pTempTable
->
table
.
singleTable
=
stmtIsSingleTable
(
pTempTable
->
pSubquery
);
code
=
addNamespace
(
pCxt
,
pTempTable
);
}
break
;
...
...
@@ -1284,7 +1325,8 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pJoinTable
->
table
.
precision
=
getJoinTablePrecision
(
pJoinTable
);
code
=
translateExpr
(
pCxt
,
pJoinTable
->
pOnCond
);
pJoinTable
->
table
.
singleTable
=
joinTableIsSingleTable
(
pJoinTable
);
code
=
translateExpr
(
pCxt
,
&
pJoinTable
->
pOnCond
);
}
break
;
}
...
...
@@ -1517,7 +1559,7 @@ static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pPro
if
(
NULL
==
pCol
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_OUT_OF_MEMORY
);
}
setColumnInfoByExpr
(
NULL
,
(
SExprNode
*
)
nodesListGetNode
(
pProjectionList
,
pos
-
1
),
pCol
);
setColumnInfoByExpr
(
NULL
,
(
SExprNode
*
)
nodesListGetNode
(
pProjectionList
,
pos
-
1
),
&
pCol
);
((
SOrderByExprNode
*
)
pNode
)
->
pExpr
=
(
SNode
*
)
pCol
;
nodesDestroyNode
(
pExpr
);
}
...
...
@@ -1563,7 +1605,7 @@ static int32_t translateHaving(STranslateContext* pCxt, SSelectStmt* pSelect) {
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
);
}
pCxt
->
currClause
=
SQL_CLAUSE_HAVING
;
int32_t
code
=
translateExpr
(
pCxt
,
pSelect
->
pHaving
);
int32_t
code
=
translateExpr
(
pCxt
,
&
pSelect
->
pHaving
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkExprForGroupBy
(
pCxt
,
&
pSelect
->
pHaving
);
}
...
...
@@ -1811,7 +1853,7 @@ static int32_t translateWindow(STranslateContext* pCxt, SSelectStmt* pSelect) {
return
TSDB_CODE_SUCCESS
;
}
pCxt
->
currClause
=
SQL_CLAUSE_WINDOW
;
int32_t
code
=
translateExpr
(
pCxt
,
pSelect
->
pWindow
);
int32_t
code
=
translateExpr
(
pCxt
,
&
pSelect
->
pWindow
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkWindow
(
pCxt
,
pSelect
);
}
...
...
@@ -1825,7 +1867,7 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SNodeList* pPartiti
static
int32_t
translateWhere
(
STranslateContext
*
pCxt
,
SNode
*
pWhere
)
{
pCxt
->
currClause
=
SQL_CLAUSE_WHERE
;
return
translateExpr
(
pCxt
,
pWhere
);
return
translateExpr
(
pCxt
,
&
pWhere
);
}
static
int32_t
translateFrom
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
...
...
@@ -1857,7 +1899,7 @@ static int32_t createPrimaryKeyColByTable(STranslateContext* pCxt, STableNode* p
}
pCol
->
colId
=
PRIMARYKEY_TIMESTAMP_COL_ID
;
strcpy
(
pCol
->
colName
,
PK_TS_COL_INTERNAL_NAME
);
if
(
!
findAndSetColumn
(
pCol
,
pTable
))
{
if
(
!
findAndSetColumn
(
&
pCol
,
pTable
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TIMELINE_FUNC
);
}
*
pPrimaryKey
=
(
SNode
*
)
pCol
;
...
...
@@ -2075,6 +2117,7 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
pReq
->
replications
=
pStmt
->
pOptions
->
replica
;
pReq
->
strict
=
pStmt
->
pOptions
->
strict
;
pReq
->
cacheLastRow
=
pStmt
->
pOptions
->
cachelast
;
pReq
->
schemaless
=
pStmt
->
pOptions
->
schemaless
;
pReq
->
ignoreExist
=
pStmt
->
ignoreExists
;
return
buildCreateDbRetentions
(
pStmt
->
pOptions
->
pRetentions
,
pReq
);
}
...
...
@@ -2274,6 +2317,9 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkDbRetentionsOption
(
pCxt
,
pOptions
->
pRetentions
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkDbEnumOption
(
pCxt
,
"schemaless"
,
pOptions
->
schemaless
,
TSDB_DB_SCHEMALESS_ON
,
TSDB_DB_SCHEMALESS_OFF
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkOptionsDependency
(
pCxt
,
pDbName
,
pOptions
);
}
...
...
@@ -3267,6 +3313,18 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt
return
buildCmdMsg
(
pCxt
,
TDMT_MND_DROP_TOPIC
,
(
FSerializeFunc
)
tSerializeSMDropTopicReq
,
&
dropReq
);
}
static
int32_t
translateDropCGroup
(
STranslateContext
*
pCxt
,
SDropCGroupStmt
*
pStmt
)
{
SMDropCgroupReq
dropReq
=
{
0
};
SName
name
;
tNameSetDbName
(
&
name
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
topicName
,
strlen
(
pStmt
->
topicName
));
tNameGetFullDbName
(
&
name
,
dropReq
.
topic
);
dropReq
.
igNotExists
=
pStmt
->
ignoreNotExists
;
strcpy
(
dropReq
.
cgroup
,
pStmt
->
cgroup
);
return
buildCmdMsg
(
pCxt
,
TDMT_MND_DROP_CGROUP
,
(
FSerializeFunc
)
tSerializeSMDropCgroupReq
,
&
dropReq
);
}
static
int32_t
translateAlterLocal
(
STranslateContext
*
pCxt
,
SAlterLocalStmt
*
pStmt
)
{
// todo
return
TSDB_CODE_SUCCESS
;
...
...
@@ -3326,6 +3384,8 @@ static int32_t buildCreateStreamReq(STranslateContext* pCxt, SCreateStreamStmt*
pReq
->
igExists
=
pStmt
->
ignoreExists
;
SName
name
;
// tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName));
// tNameGetFullDbName(&name, pReq->name);
tNameExtractFullName
(
toName
(
pCxt
->
pParseCxt
->
acctId
,
pCxt
->
pParseCxt
->
db
,
pStmt
->
streamName
,
&
name
),
pReq
->
name
);
if
(
'\0'
!=
pStmt
->
targetTabName
[
0
])
{
...
...
@@ -3550,6 +3610,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case
QUERY_NODE_DROP_TOPIC_STMT
:
code
=
translateDropTopic
(
pCxt
,
(
SDropTopicStmt
*
)
pNode
);
break
;
case
QUERY_NODE_DROP_CGROUP_STMT
:
code
=
translateDropCGroup
(
pCxt
,
(
SDropCGroupStmt
*
)
pNode
);
break
;
case
QUERY_NODE_ALTER_LOCAL_STMT
:
code
=
translateAlterLocal
(
pCxt
,
(
SAlterLocalStmt
*
)
pNode
);
break
;
...
...
source/libs/parser/src/sql.c
浏览文件 @
070f6040
此差异已折叠。
点击以展开。
source/libs/parser/test/parInitialCTest.cpp
浏览文件 @
070f6040
...
...
@@ -90,6 +90,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
expect
.
walLevel
=
TSDB_DEFAULT_WAL_LEVEL
;
expect
.
numOfVgroups
=
TSDB_DEFAULT_VN_PER_DB
;
expect
.
numOfStables
=
TSDB_DEFAULT_DB_SINGLE_STABLE
;
expect
.
schemaless
=
TSDB_DEFAULT_DB_SCHEMALESS
;
};
auto
setDbBufferFunc
=
[
&
](
int32_t
buffer
)
{
expect
.
buffer
=
buffer
;
};
...
...
@@ -124,6 +125,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
taosArrayPush
(
expect
.
pRetensions
,
&
retention
);
++
expect
.
numOfRetensions
;
};
auto
setDbSchemalessFunc
=
[
&
](
int8_t
schemaless
)
{
expect
.
schemaless
=
schemaless
;
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_CREATE_DATABASE_STMT
);
...
...
@@ -149,6 +151,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
ASSERT_EQ
(
req
.
replications
,
expect
.
replications
);
ASSERT_EQ
(
req
.
strict
,
expect
.
strict
);
ASSERT_EQ
(
req
.
cacheLastRow
,
expect
.
cacheLastRow
);
ASSERT_EQ
(
req
.
schemaless
,
expect
.
schemaless
);
ASSERT_EQ
(
req
.
ignoreExist
,
expect
.
ignoreExist
);
ASSERT_EQ
(
req
.
numOfRetensions
,
expect
.
numOfRetensions
);
if
(
expect
.
numOfRetensions
>
0
)
{
...
...
@@ -188,6 +191,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
setDbWalLevelFunc
(
2
);
setDbVgroupsFunc
(
100
);
setDbSingleStableFunc
(
1
);
setDbSchemalessFunc
(
1
);
run
(
"CREATE DATABASE IF NOT EXISTS wxy_db "
"BUFFER 64 "
"CACHELAST 2 "
...
...
@@ -205,7 +209,8 @@ TEST_F(ParserInitialCTest, createDatabase) {
"STRICT 1 "
"WAL 2 "
"VGROUPS 100 "
"SINGLE_STABLE 1 "
);
"SINGLE_STABLE 1 "
"SCHEMALESS 1"
);
setCreateDbReqFunc
(
"wxy_db"
,
1
);
setDbDaysFunc
(
100
);
...
...
source/libs/parser/test/parInitialDTest.cpp
浏览文件 @
070f6040
...
...
@@ -19,7 +19,7 @@ using namespace std;
namespace
ParserTest
{
class
ParserInitialDTest
:
public
Parser
TestBase
{};
class
ParserInitialDTest
:
public
Parser
DdlTest
{};
// todo delete
// todo desc
...
...
@@ -29,7 +29,37 @@ class ParserInitialDTest : public ParserTestBase {};
TEST_F
(
ParserInitialDTest
,
dropBnode
)
{
useDb
(
"root"
,
"test"
);
run
(
"drop bnode on dnode 1"
);
run
(
"DROP BNODE ON DNODE 1"
);
}
// DROP CGROUP [ IF EXISTS ] cgroup_name ON topic_name
TEST_F
(
ParserInitialDTest
,
dropCGroup
)
{
useDb
(
"root"
,
"test"
);
SMDropCgroupReq
expect
=
{
0
};
auto
setDropCgroupReqFunc
=
[
&
](
const
char
*
pTopicName
,
const
char
*
pCGroupName
,
int8_t
igNotExists
=
0
)
{
memset
(
&
expect
,
0
,
sizeof
(
SMDropCgroupReq
));
snprintf
(
expect
.
topic
,
sizeof
(
expect
.
topic
),
"0.%s"
,
pTopicName
);
strcpy
(
expect
.
cgroup
,
pCGroupName
);
expect
.
igNotExists
=
igNotExists
;
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_DROP_CGROUP_STMT
);
SMDropCgroupReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSMDropCgroupReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
ASSERT_EQ
(
std
::
string
(
req
.
topic
),
std
::
string
(
expect
.
topic
));
ASSERT_EQ
(
std
::
string
(
req
.
cgroup
),
std
::
string
(
expect
.
cgroup
));
ASSERT_EQ
(
req
.
igNotExists
,
expect
.
igNotExists
);
});
setDropCgroupReqFunc
(
"tp1"
,
"cg1"
);
run
(
"DROP CGROUP cg1 ON tp1"
);
setDropCgroupReqFunc
(
"tp1"
,
"cg1"
,
1
);
run
(
"DROP CGROUP IF EXISTS cg1 ON tp1"
);
}
// todo drop database
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
070f6040
...
...
@@ -121,13 +121,13 @@ TEST_F(ParserSelectTest, selectFunc) {
run
(
"SELECT MAX(c1), c2 FROM t1 STATE_WINDOW(c3)"
);
}
TEST_F
(
ParserSelectTest
,
nonstd
Func
)
{
TEST_F
(
ParserSelectTest
,
IndefiniteRows
Func
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT DIFF(c1) FROM t1"
);
}
TEST_F
(
ParserSelectTest
,
nonstd
FuncSemanticCheck
)
{
TEST_F
(
ParserSelectTest
,
IndefiniteRows
FuncSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT DIFF(c1), c2 FROM t1"
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
,
PARSER_STAGE_TRANSLATE
);
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
070f6040
...
...
@@ -321,6 +321,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
}
pJoin
->
joinType
=
pJoinTable
->
joinType
;
pJoin
->
isSingleTableJoin
=
pJoinTable
->
table
.
singleTable
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -418,7 +419,7 @@ static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr)
}
static
int32_t
createAggLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
if
(
!
pSelect
->
hasAggFuncs
&&
!
pSelect
->
hasIndefiniteRowsFunc
&&
NULL
==
pSelect
->
pGroupByList
)
{
if
(
!
pSelect
->
hasAggFuncs
&&
NULL
==
pSelect
->
pGroupByList
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -442,8 +443,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
code
=
rewriteExprForSelect
(
pAgg
->
pGroupKeys
,
pSelect
,
SQL_CLAUSE_GROUP_BY
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
(
pSelect
->
hasAggFuncs
||
pSelect
->
hasIndefiniteRowsFunc
)
)
{
code
=
nodesCollectFuncs
(
pSelect
,
SQL_CLAUSE_GROUP_BY
,
fmIs
Vector
Func
,
&
pAgg
->
pAggFuncs
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
pSelect
->
hasAggFuncs
)
{
code
=
nodesCollectFuncs
(
pSelect
,
SQL_CLAUSE_GROUP_BY
,
fmIs
Agg
Func
,
&
pAgg
->
pAggFuncs
);
}
// rewrite the expression in subsequent clauses
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
070f6040
...
...
@@ -18,7 +18,6 @@
#define SPLIT_FLAG_MASK(n) (1 << n)
#define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0)
#define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1)
#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask)
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
...
...
@@ -42,7 +41,8 @@ typedef struct SStsInfo {
}
SStsInfo
;
typedef
struct
SCtjInfo
{
SScanLogicNode
*
pScan
;
SJoinLogicNode
*
pJoin
;
SLogicNode
*
pSplitNode
;
SLogicSubplan
*
pSubplan
;
}
SCtjInfo
;
...
...
@@ -58,7 +58,7 @@ typedef struct SUnInfo {
typedef
bool
(
*
FSplFindSplitNode
)(
SLogicSubplan
*
pSubplan
,
void
*
pInfo
);
static
SLogicSubplan
*
splCreateS
canSubplan
(
SSplitContext
*
pCxt
,
SScanLogicNode
*
pScan
,
int32_t
flag
)
{
static
SLogicSubplan
*
splCreateS
ubplan
(
SSplitContext
*
pCxt
,
SLogicNode
*
pNode
,
int32_t
flag
)
{
SLogicSubplan
*
pSubplan
=
nodesMakeNode
(
QUERY_NODE_LOGIC_SUBPLAN
);
if
(
NULL
==
pSubplan
)
{
return
NULL
;
...
...
@@ -66,35 +66,37 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
pSubplan
->
id
.
queryId
=
pCxt
->
queryId
;
pSubplan
->
id
.
groupId
=
pCxt
->
groupId
;
pSubplan
->
subplanType
=
SUBPLAN_TYPE_SCAN
;
pSubplan
->
pNode
=
(
SLogicNode
*
)
nodesCloneNode
(
pScan
);
TSWAP
(
pSubplan
->
pVgroupList
,
((
SScanLogicNode
*
)
pSubplan
->
pNode
)
->
pVgroupList
);
pSubplan
->
pNode
=
(
SLogicNode
*
)
nodesCloneNode
(
pNode
);
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
))
{
TSWAP
(
pSubplan
->
pVgroupList
,
((
SScanLogicNode
*
)
pSubplan
->
pNode
)
->
pVgroupList
);
}
SPLIT_FLAG_SET_MASK
(
pSubplan
->
splitFlag
,
flag
);
return
pSubplan
;
}
static
int32_t
splCreateExchangeNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
S
ScanLogicNode
*
pScan
,
static
int32_t
splCreateExchangeNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
S
LogicNode
*
pSplitNode
,
ESubplanType
subplanType
)
{
SExchangeLogicNode
*
pExchange
=
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_EXCHANGE
);
if
(
NULL
==
pExchange
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pExchange
->
srcGroupId
=
pCxt
->
groupId
;
pExchange
->
precision
=
pS
can
->
pMeta
->
tableInfo
.
precision
;
pExchange
->
node
.
pTargets
=
nodesCloneList
(
pS
can
->
node
.
pTargets
);
pExchange
->
precision
=
pS
plitNode
->
precision
;
pExchange
->
node
.
pTargets
=
nodesCloneList
(
pS
plitNode
->
pTargets
);
if
(
NULL
==
pExchange
->
node
.
pTargets
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pSubplan
->
subplanType
=
SUBPLAN_TYPE_MERGE
;
pSubplan
->
subplanType
=
subplanType
;
if
(
NULL
==
pS
can
->
node
.
pParent
)
{
if
(
NULL
==
pS
plitNode
->
pParent
)
{
pSubplan
->
pNode
=
(
SLogicNode
*
)
pExchange
;
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pNode
;
FOREACH
(
pNode
,
pS
can
->
node
.
pParent
->
pChildren
)
{
if
(
nodesEqualNode
(
pNode
,
pS
can
))
{
FOREACH
(
pNode
,
pS
plitNode
->
pParent
->
pChildren
)
{
if
(
nodesEqualNode
(
pNode
,
pS
plitNode
))
{
REPLACE_NODE
(
pExchange
);
nodesDestroyNode
(
pNode
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -148,33 +150,31 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_STS
,
(
FSplFindSplitNode
)
stsFindSplitNode
,
&
info
))
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_STS
));
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateSubplan
(
pCxt
,
(
SLogicNode
*
)
info
.
pScan
,
SPLIT_FLAG_STS
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
,
SUBPLAN_TYPE_MERGE
);
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
(
SLogicNode
*
)
info
.
pScan
,
SUBPLAN_TYPE_MERGE
);
}
++
(
pCxt
->
groupId
);
pCxt
->
split
=
true
;
return
code
;
}
static
bool
ctjIsSingleTable
(
int8_t
tableType
)
{
return
(
TSDB_CHILD_TABLE
==
tableType
||
TSDB_NORMAL_TABLE
==
tableType
);
static
bool
needSplit
(
SJoinLogicNode
*
pJoin
)
{
if
(
!
pJoin
->
isSingleTableJoin
)
{
return
false
;
}
return
QUERY_NODE_LOGIC_PLAN_EXCHANGE
!=
nodeType
(
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_EXCHANGE
!=
nodeType
(
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
));
}
static
SLogicNode
*
ctjMatchByNode
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_JOIN
==
nodeType
(
pNode
))
{
SLogicNode
*
pLeft
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
);
SLogicNode
*
pRight
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
1
);
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pLeft
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pLeft
)
->
pMeta
->
tableType
)
&&
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pRight
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pRight
)
->
pMeta
->
tableType
))
{
return
pRight
;
}
static
SJoinLogicNode
*
ctjMatchByNode
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_JOIN
==
nodeType
(
pNode
)
&&
needSplit
((
SJoinLogicNode
*
)
pNode
))
{
return
(
SJoinLogicNode
*
)
pNode
;
}
SNode
*
pChild
;
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
SLogicNode
*
pSplitNode
=
ctjMatchByNode
((
SLogicNode
*
)
pChild
);
S
Join
LogicNode
*
pSplitNode
=
ctjMatchByNode
((
SLogicNode
*
)
pChild
);
if
(
NULL
!=
pSplitNode
)
{
return
pSplitNode
;
}
...
...
@@ -183,23 +183,23 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) {
}
static
bool
ctjFindSplitNode
(
SLogicSubplan
*
pSubplan
,
SCtjInfo
*
pInfo
)
{
SLogicNode
*
pSplitNode
=
ctjMatchByNode
(
pSubplan
->
pNode
);
if
(
NULL
!=
pSplitNode
)
{
pInfo
->
pScan
=
(
SScanLogicNode
*
)
pSplitNode
;
SJoinLogicNode
*
pJoin
=
ctjMatchByNode
(
pSubplan
->
pNode
);
if
(
NULL
!=
pJoin
)
{
pInfo
->
pJoin
=
pJoin
;
pInfo
->
pSplitNode
=
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
);
pInfo
->
pSubplan
=
pSubplan
;
}
return
NULL
!=
p
SplitNode
;
return
NULL
!=
p
Join
;
}
static
int32_t
ctjSplit
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
)
{
SCtjInfo
info
=
{
0
};
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_CTJ
,
(
FSplFindSplitNode
)
ctjFindSplitNode
,
&
info
))
{
if
(
!
splMatch
(
pCxt
,
pSubplan
,
0
,
(
FSplFindSplitNode
)
ctjFindSplitNode
,
&
info
))
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_CTJ
));
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateSubplan
(
pCxt
,
info
.
pSplitNode
,
0
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pS
can
,
info
.
pSubplan
->
subplanType
);
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pS
plitNode
,
info
.
pSubplan
->
subplanType
);
}
++
(
pCxt
->
groupId
);
pCxt
->
split
=
true
;
...
...
source/libs/planner/test/planSubqueryTest.cpp
浏览文件 @
070f6040
...
...
@@ -26,6 +26,8 @@ TEST_F(PlanSubqeuryTest, basic) {
run
(
"SELECT * FROM (SELECT * FROM t1)"
);
run
(
"SELECT LAST(c1) FROM (SELECT * FROM t1)"
);
run
(
"SELECT c1 FROM (SELECT TODAY() AS c1 FROM t1)"
);
}
TEST_F
(
PlanSubqeuryTest
,
doubleGroupBy
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录