feat: sql system info function 'database()', 'client_version()', 'server_version()', 'server_status()', 'current_user()' and 'user()'
This commit is contained in:
parent
ed4b2dec17
commit
ae076af4f1
|
@ -16,251 +16,255 @@
|
||||||
#ifndef _TD_COMMON_TOKEN_H_
|
#ifndef _TD_COMMON_TOKEN_H_
|
||||||
#define _TD_COMMON_TOKEN_H_
|
#define _TD_COMMON_TOKEN_H_
|
||||||
|
|
||||||
#define TK_OR 1
|
#define TK_OR 1
|
||||||
#define TK_AND 2
|
#define TK_AND 2
|
||||||
#define TK_UNION 3
|
#define TK_UNION 3
|
||||||
#define TK_ALL 4
|
#define TK_ALL 4
|
||||||
#define TK_MINUS 5
|
#define TK_MINUS 5
|
||||||
#define TK_EXCEPT 6
|
#define TK_EXCEPT 6
|
||||||
#define TK_INTERSECT 7
|
#define TK_INTERSECT 7
|
||||||
#define TK_NK_BITAND 8
|
#define TK_NK_BITAND 8
|
||||||
#define TK_NK_BITOR 9
|
#define TK_NK_BITOR 9
|
||||||
#define TK_NK_LSHIFT 10
|
#define TK_NK_LSHIFT 10
|
||||||
#define TK_NK_RSHIFT 11
|
#define TK_NK_RSHIFT 11
|
||||||
#define TK_NK_PLUS 12
|
#define TK_NK_PLUS 12
|
||||||
#define TK_NK_MINUS 13
|
#define TK_NK_MINUS 13
|
||||||
#define TK_NK_STAR 14
|
#define TK_NK_STAR 14
|
||||||
#define TK_NK_SLASH 15
|
#define TK_NK_SLASH 15
|
||||||
#define TK_NK_REM 16
|
#define TK_NK_REM 16
|
||||||
#define TK_NK_CONCAT 17
|
#define TK_NK_CONCAT 17
|
||||||
#define TK_CREATE 18
|
#define TK_CREATE 18
|
||||||
#define TK_ACCOUNT 19
|
#define TK_ACCOUNT 19
|
||||||
#define TK_NK_ID 20
|
#define TK_NK_ID 20
|
||||||
#define TK_PASS 21
|
#define TK_PASS 21
|
||||||
#define TK_NK_STRING 22
|
#define TK_NK_STRING 22
|
||||||
#define TK_ALTER 23
|
#define TK_ALTER 23
|
||||||
#define TK_PPS 24
|
#define TK_PPS 24
|
||||||
#define TK_TSERIES 25
|
#define TK_TSERIES 25
|
||||||
#define TK_STORAGE 26
|
#define TK_STORAGE 26
|
||||||
#define TK_STREAMS 27
|
#define TK_STREAMS 27
|
||||||
#define TK_QTIME 28
|
#define TK_QTIME 28
|
||||||
#define TK_DBS 29
|
#define TK_DBS 29
|
||||||
#define TK_USERS 30
|
#define TK_USERS 30
|
||||||
#define TK_CONNS 31
|
#define TK_CONNS 31
|
||||||
#define TK_STATE 32
|
#define TK_STATE 32
|
||||||
#define TK_USER 33
|
#define TK_USER 33
|
||||||
#define TK_ENABLE 34
|
#define TK_ENABLE 34
|
||||||
#define TK_NK_INTEGER 35
|
#define TK_NK_INTEGER 35
|
||||||
#define TK_SYSINFO 36
|
#define TK_SYSINFO 36
|
||||||
#define TK_DROP 37
|
#define TK_DROP 37
|
||||||
#define TK_GRANT 38
|
#define TK_GRANT 38
|
||||||
#define TK_ON 39
|
#define TK_ON 39
|
||||||
#define TK_TO 40
|
#define TK_TO 40
|
||||||
#define TK_REVOKE 41
|
#define TK_REVOKE 41
|
||||||
#define TK_FROM 42
|
#define TK_FROM 42
|
||||||
#define TK_NK_COMMA 43
|
#define TK_NK_COMMA 43
|
||||||
#define TK_READ 44
|
#define TK_READ 44
|
||||||
#define TK_WRITE 45
|
#define TK_WRITE 45
|
||||||
#define TK_NK_DOT 46
|
#define TK_NK_DOT 46
|
||||||
#define TK_DNODE 47
|
#define TK_DNODE 47
|
||||||
#define TK_PORT 48
|
#define TK_PORT 48
|
||||||
#define TK_DNODES 49
|
#define TK_DNODES 49
|
||||||
#define TK_NK_IPTOKEN 50
|
#define TK_NK_IPTOKEN 50
|
||||||
#define TK_LOCAL 51
|
#define TK_LOCAL 51
|
||||||
#define TK_QNODE 52
|
#define TK_QNODE 52
|
||||||
#define TK_BNODE 53
|
#define TK_BNODE 53
|
||||||
#define TK_SNODE 54
|
#define TK_SNODE 54
|
||||||
#define TK_MNODE 55
|
#define TK_MNODE 55
|
||||||
#define TK_DATABASE 56
|
#define TK_DATABASE 56
|
||||||
#define TK_USE 57
|
#define TK_USE 57
|
||||||
#define TK_IF 58
|
#define TK_IF 58
|
||||||
#define TK_NOT 59
|
#define TK_NOT 59
|
||||||
#define TK_EXISTS 60
|
#define TK_EXISTS 60
|
||||||
#define TK_BUFFER 61
|
#define TK_BUFFER 61
|
||||||
#define TK_CACHELAST 62
|
#define TK_CACHELAST 62
|
||||||
#define TK_COMP 63
|
#define TK_COMP 63
|
||||||
#define TK_DURATION 64
|
#define TK_DURATION 64
|
||||||
#define TK_NK_VARIABLE 65
|
#define TK_NK_VARIABLE 65
|
||||||
#define TK_FSYNC 66
|
#define TK_FSYNC 66
|
||||||
#define TK_MAXROWS 67
|
#define TK_MAXROWS 67
|
||||||
#define TK_MINROWS 68
|
#define TK_MINROWS 68
|
||||||
#define TK_KEEP 69
|
#define TK_KEEP 69
|
||||||
#define TK_PAGES 70
|
#define TK_PAGES 70
|
||||||
#define TK_PAGESIZE 71
|
#define TK_PAGESIZE 71
|
||||||
#define TK_PRECISION 72
|
#define TK_PRECISION 72
|
||||||
#define TK_REPLICA 73
|
#define TK_REPLICA 73
|
||||||
#define TK_STRICT 74
|
#define TK_STRICT 74
|
||||||
#define TK_WAL 75
|
#define TK_WAL 75
|
||||||
#define TK_VGROUPS 76
|
#define TK_VGROUPS 76
|
||||||
#define TK_SINGLE_STABLE 77
|
#define TK_SINGLE_STABLE 77
|
||||||
#define TK_RETENTIONS 78
|
#define TK_RETENTIONS 78
|
||||||
#define TK_SCHEMALESS 79
|
#define TK_SCHEMALESS 79
|
||||||
#define TK_NK_COLON 80
|
#define TK_NK_COLON 80
|
||||||
#define TK_TABLE 81
|
#define TK_TABLE 81
|
||||||
#define TK_NK_LP 82
|
#define TK_NK_LP 82
|
||||||
#define TK_NK_RP 83
|
#define TK_NK_RP 83
|
||||||
#define TK_STABLE 84
|
#define TK_STABLE 84
|
||||||
#define TK_ADD 85
|
#define TK_ADD 85
|
||||||
#define TK_COLUMN 86
|
#define TK_COLUMN 86
|
||||||
#define TK_MODIFY 87
|
#define TK_MODIFY 87
|
||||||
#define TK_RENAME 88
|
#define TK_RENAME 88
|
||||||
#define TK_TAG 89
|
#define TK_TAG 89
|
||||||
#define TK_SET 90
|
#define TK_SET 90
|
||||||
#define TK_NK_EQ 91
|
#define TK_NK_EQ 91
|
||||||
#define TK_USING 92
|
#define TK_USING 92
|
||||||
#define TK_TAGS 93
|
#define TK_TAGS 93
|
||||||
#define TK_COMMENT 94
|
#define TK_COMMENT 94
|
||||||
#define TK_BOOL 95
|
#define TK_BOOL 95
|
||||||
#define TK_TINYINT 96
|
#define TK_TINYINT 96
|
||||||
#define TK_SMALLINT 97
|
#define TK_SMALLINT 97
|
||||||
#define TK_INT 98
|
#define TK_INT 98
|
||||||
#define TK_INTEGER 99
|
#define TK_INTEGER 99
|
||||||
#define TK_BIGINT 100
|
#define TK_BIGINT 100
|
||||||
#define TK_FLOAT 101
|
#define TK_FLOAT 101
|
||||||
#define TK_DOUBLE 102
|
#define TK_DOUBLE 102
|
||||||
#define TK_BINARY 103
|
#define TK_BINARY 103
|
||||||
#define TK_TIMESTAMP 104
|
#define TK_TIMESTAMP 104
|
||||||
#define TK_NCHAR 105
|
#define TK_NCHAR 105
|
||||||
#define TK_UNSIGNED 106
|
#define TK_UNSIGNED 106
|
||||||
#define TK_JSON 107
|
#define TK_JSON 107
|
||||||
#define TK_VARCHAR 108
|
#define TK_VARCHAR 108
|
||||||
#define TK_MEDIUMBLOB 109
|
#define TK_MEDIUMBLOB 109
|
||||||
#define TK_BLOB 110
|
#define TK_BLOB 110
|
||||||
#define TK_VARBINARY 111
|
#define TK_VARBINARY 111
|
||||||
#define TK_DECIMAL 112
|
#define TK_DECIMAL 112
|
||||||
#define TK_MAX_DELAY 113
|
#define TK_MAX_DELAY 113
|
||||||
#define TK_WATERMARK 114
|
#define TK_WATERMARK 114
|
||||||
#define TK_ROLLUP 115
|
#define TK_ROLLUP 115
|
||||||
#define TK_TTL 116
|
#define TK_TTL 116
|
||||||
#define TK_SMA 117
|
#define TK_SMA 117
|
||||||
#define TK_FIRST 118
|
#define TK_FIRST 118
|
||||||
#define TK_LAST 119
|
#define TK_LAST 119
|
||||||
#define TK_SHOW 120
|
#define TK_SHOW 120
|
||||||
#define TK_DATABASES 121
|
#define TK_DATABASES 121
|
||||||
#define TK_TABLES 122
|
#define TK_TABLES 122
|
||||||
#define TK_STABLES 123
|
#define TK_STABLES 123
|
||||||
#define TK_MNODES 124
|
#define TK_MNODES 124
|
||||||
#define TK_MODULES 125
|
#define TK_MODULES 125
|
||||||
#define TK_QNODES 126
|
#define TK_QNODES 126
|
||||||
#define TK_FUNCTIONS 127
|
#define TK_FUNCTIONS 127
|
||||||
#define TK_INDEXES 128
|
#define TK_INDEXES 128
|
||||||
#define TK_ACCOUNTS 129
|
#define TK_ACCOUNTS 129
|
||||||
#define TK_APPS 130
|
#define TK_APPS 130
|
||||||
#define TK_CONNECTIONS 131
|
#define TK_CONNECTIONS 131
|
||||||
#define TK_LICENCE 132
|
#define TK_LICENCE 132
|
||||||
#define TK_GRANTS 133
|
#define TK_GRANTS 133
|
||||||
#define TK_QUERIES 134
|
#define TK_QUERIES 134
|
||||||
#define TK_SCORES 135
|
#define TK_SCORES 135
|
||||||
#define TK_TOPICS 136
|
#define TK_TOPICS 136
|
||||||
#define TK_VARIABLES 137
|
#define TK_VARIABLES 137
|
||||||
#define TK_BNODES 138
|
#define TK_BNODES 138
|
||||||
#define TK_SNODES 139
|
#define TK_SNODES 139
|
||||||
#define TK_CLUSTER 140
|
#define TK_CLUSTER 140
|
||||||
#define TK_TRANSACTIONS 141
|
#define TK_TRANSACTIONS 141
|
||||||
#define TK_DISTRIBUTED 142
|
#define TK_DISTRIBUTED 142
|
||||||
#define TK_CONSUMERS 143
|
#define TK_CONSUMERS 143
|
||||||
#define TK_SUBSCRIPTIONS 144
|
#define TK_SUBSCRIPTIONS 144
|
||||||
#define TK_LIKE 145
|
#define TK_LIKE 145
|
||||||
#define TK_INDEX 146
|
#define TK_INDEX 146
|
||||||
#define TK_FUNCTION 147
|
#define TK_FUNCTION 147
|
||||||
#define TK_INTERVAL 148
|
#define TK_INTERVAL 148
|
||||||
#define TK_TOPIC 149
|
#define TK_TOPIC 149
|
||||||
#define TK_AS 150
|
#define TK_AS 150
|
||||||
#define TK_WITH 151
|
#define TK_WITH 151
|
||||||
#define TK_META 152
|
#define TK_META 152
|
||||||
#define TK_CONSUMER 153
|
#define TK_CONSUMER 153
|
||||||
#define TK_GROUP 154
|
#define TK_GROUP 154
|
||||||
#define TK_DESC 155
|
#define TK_DESC 155
|
||||||
#define TK_DESCRIBE 156
|
#define TK_DESCRIBE 156
|
||||||
#define TK_RESET 157
|
#define TK_RESET 157
|
||||||
#define TK_QUERY 158
|
#define TK_QUERY 158
|
||||||
#define TK_CACHE 159
|
#define TK_CACHE 159
|
||||||
#define TK_EXPLAIN 160
|
#define TK_EXPLAIN 160
|
||||||
#define TK_ANALYZE 161
|
#define TK_ANALYZE 161
|
||||||
#define TK_VERBOSE 162
|
#define TK_VERBOSE 162
|
||||||
#define TK_NK_BOOL 163
|
#define TK_NK_BOOL 163
|
||||||
#define TK_RATIO 164
|
#define TK_RATIO 164
|
||||||
#define TK_NK_FLOAT 165
|
#define TK_NK_FLOAT 165
|
||||||
#define TK_COMPACT 166
|
#define TK_COMPACT 166
|
||||||
#define TK_VNODES 167
|
#define TK_VNODES 167
|
||||||
#define TK_IN 168
|
#define TK_IN 168
|
||||||
#define TK_OUTPUTTYPE 169
|
#define TK_OUTPUTTYPE 169
|
||||||
#define TK_AGGREGATE 170
|
#define TK_AGGREGATE 170
|
||||||
#define TK_BUFSIZE 171
|
#define TK_BUFSIZE 171
|
||||||
#define TK_STREAM 172
|
#define TK_STREAM 172
|
||||||
#define TK_INTO 173
|
#define TK_INTO 173
|
||||||
#define TK_TRIGGER 174
|
#define TK_TRIGGER 174
|
||||||
#define TK_AT_ONCE 175
|
#define TK_AT_ONCE 175
|
||||||
#define TK_WINDOW_CLOSE 176
|
#define TK_WINDOW_CLOSE 176
|
||||||
#define TK_KILL 177
|
#define TK_KILL 177
|
||||||
#define TK_CONNECTION 178
|
#define TK_CONNECTION 178
|
||||||
#define TK_TRANSACTION 179
|
#define TK_TRANSACTION 179
|
||||||
#define TK_BALANCE 180
|
#define TK_BALANCE 180
|
||||||
#define TK_VGROUP 181
|
#define TK_VGROUP 181
|
||||||
#define TK_MERGE 182
|
#define TK_MERGE 182
|
||||||
#define TK_REDISTRIBUTE 183
|
#define TK_REDISTRIBUTE 183
|
||||||
#define TK_SPLIT 184
|
#define TK_SPLIT 184
|
||||||
#define TK_SYNCDB 185
|
#define TK_SYNCDB 185
|
||||||
#define TK_DELETE 186
|
#define TK_DELETE 186
|
||||||
#define TK_NULL 187
|
#define TK_NULL 187
|
||||||
#define TK_NK_QUESTION 188
|
#define TK_NK_QUESTION 188
|
||||||
#define TK_NK_ARROW 189
|
#define TK_NK_ARROW 189
|
||||||
#define TK_ROWTS 190
|
#define TK_ROWTS 190
|
||||||
#define TK_TBNAME 191
|
#define TK_TBNAME 191
|
||||||
#define TK_QSTARTTS 192
|
#define TK_QSTARTTS 192
|
||||||
#define TK_QENDTS 193
|
#define TK_QENDTS 193
|
||||||
#define TK_WSTARTTS 194
|
#define TK_WSTARTTS 194
|
||||||
#define TK_WENDTS 195
|
#define TK_WENDTS 195
|
||||||
#define TK_WDURATION 196
|
#define TK_WDURATION 196
|
||||||
#define TK_CAST 197
|
#define TK_CAST 197
|
||||||
#define TK_NOW 198
|
#define TK_NOW 198
|
||||||
#define TK_TODAY 199
|
#define TK_TODAY 199
|
||||||
#define TK_TIMEZONE 200
|
#define TK_TIMEZONE 200
|
||||||
#define TK_COUNT 201
|
#define TK_CLIENT_VERSION 201
|
||||||
#define TK_LAST_ROW 202
|
#define TK_SERVER_VERSION 202
|
||||||
#define TK_BETWEEN 203
|
#define TK_SERVER_STATUS 203
|
||||||
#define TK_IS 204
|
#define TK_CURRENT_USER 204
|
||||||
#define TK_NK_LT 205
|
#define TK_COUNT 205
|
||||||
#define TK_NK_GT 206
|
#define TK_LAST_ROW 206
|
||||||
#define TK_NK_LE 207
|
#define TK_BETWEEN 207
|
||||||
#define TK_NK_GE 208
|
#define TK_IS 208
|
||||||
#define TK_NK_NE 209
|
#define TK_NK_LT 209
|
||||||
#define TK_MATCH 210
|
#define TK_NK_GT 210
|
||||||
#define TK_NMATCH 211
|
#define TK_NK_LE 211
|
||||||
#define TK_CONTAINS 212
|
#define TK_NK_GE 212
|
||||||
#define TK_JOIN 213
|
#define TK_NK_NE 213
|
||||||
#define TK_INNER 214
|
#define TK_MATCH 214
|
||||||
#define TK_SELECT 215
|
#define TK_NMATCH 215
|
||||||
#define TK_DISTINCT 216
|
#define TK_CONTAINS 216
|
||||||
#define TK_WHERE 217
|
#define TK_JOIN 217
|
||||||
#define TK_PARTITION 218
|
#define TK_INNER 218
|
||||||
#define TK_BY 219
|
#define TK_SELECT 219
|
||||||
#define TK_SESSION 220
|
#define TK_DISTINCT 220
|
||||||
#define TK_STATE_WINDOW 221
|
#define TK_WHERE 221
|
||||||
#define TK_SLIDING 222
|
#define TK_PARTITION 222
|
||||||
#define TK_FILL 223
|
#define TK_BY 223
|
||||||
#define TK_VALUE 224
|
#define TK_SESSION 224
|
||||||
#define TK_NONE 225
|
#define TK_STATE_WINDOW 225
|
||||||
#define TK_PREV 226
|
#define TK_SLIDING 226
|
||||||
#define TK_LINEAR 227
|
#define TK_FILL 227
|
||||||
#define TK_NEXT 228
|
#define TK_VALUE 228
|
||||||
#define TK_HAVING 229
|
#define TK_NONE 229
|
||||||
#define TK_RANGE 230
|
#define TK_PREV 230
|
||||||
#define TK_EVERY 231
|
#define TK_LINEAR 231
|
||||||
#define TK_ORDER 232
|
#define TK_NEXT 232
|
||||||
#define TK_SLIMIT 233
|
#define TK_HAVING 233
|
||||||
#define TK_SOFFSET 234
|
#define TK_RANGE 234
|
||||||
#define TK_LIMIT 235
|
#define TK_EVERY 235
|
||||||
#define TK_OFFSET 236
|
#define TK_ORDER 236
|
||||||
#define TK_ASC 237
|
#define TK_SLIMIT 237
|
||||||
#define TK_NULLS 238
|
#define TK_SOFFSET 238
|
||||||
#define TK_ID 239
|
#define TK_LIMIT 239
|
||||||
#define TK_NK_BITNOT 240
|
#define TK_OFFSET 240
|
||||||
#define TK_INSERT 241
|
#define TK_ASC 241
|
||||||
#define TK_VALUES 242
|
#define TK_NULLS 242
|
||||||
#define TK_IMPORT 243
|
#define TK_ID 243
|
||||||
#define TK_NK_SEMI 244
|
#define TK_NK_BITNOT 244
|
||||||
#define TK_FILE 245
|
#define TK_INSERT 245
|
||||||
|
#define TK_VALUES 246
|
||||||
|
#define TK_IMPORT 247
|
||||||
|
#define TK_NK_SEMI 248
|
||||||
|
#define TK_FILE 249
|
||||||
|
|
||||||
#define TK_NK_SPACE 300
|
#define TK_NK_SPACE 300
|
||||||
#define TK_NK_COMMENT 301
|
#define TK_NK_COMMENT 301
|
||||||
|
|
|
@ -105,7 +105,7 @@ typedef enum EFunctionType {
|
||||||
// system function
|
// system function
|
||||||
FUNCTION_TYPE_DATABASE = 3000,
|
FUNCTION_TYPE_DATABASE = 3000,
|
||||||
FUNCTION_TYPE_CLIENT_VERSION,
|
FUNCTION_TYPE_CLIENT_VERSION,
|
||||||
FUNCTION_TYPE_SERVER_SERSION,
|
FUNCTION_TYPE_SERVER_VERSION,
|
||||||
FUNCTION_TYPE_SERVER_STATUS,
|
FUNCTION_TYPE_SERVER_STATUS,
|
||||||
FUNCTION_TYPE_CURRENT_USER,
|
FUNCTION_TYPE_CURRENT_USER,
|
||||||
FUNCTION_TYPE_USER,
|
FUNCTION_TYPE_USER,
|
||||||
|
@ -193,6 +193,7 @@ bool fmIsForbidGroupByFunc(int32_t funcId);
|
||||||
bool fmIsIntervalInterpoFunc(int32_t funcId);
|
bool fmIsIntervalInterpoFunc(int32_t funcId);
|
||||||
bool fmIsInterpFunc(int32_t funcId);
|
bool fmIsInterpFunc(int32_t funcId);
|
||||||
bool fmIsLastRowFunc(int32_t funcId);
|
bool fmIsLastRowFunc(int32_t funcId);
|
||||||
|
bool fmIsSystemInfoFunc(int32_t funcId);
|
||||||
|
|
||||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ typedef struct SValueNode {
|
||||||
bool isDuration;
|
bool isDuration;
|
||||||
bool translate;
|
bool translate;
|
||||||
bool notReserved;
|
bool notReserved;
|
||||||
|
bool isNull;
|
||||||
int16_t placeholderNo;
|
int16_t placeholderNo;
|
||||||
union {
|
union {
|
||||||
bool b;
|
bool b;
|
||||||
|
|
|
@ -48,7 +48,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
|
||||||
// @pSource one execution location of this group of datasource subplans
|
// @pSource one execution location of this group of datasource subplans
|
||||||
int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
|
int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
|
||||||
|
|
||||||
int32_t qClearSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId);
|
void qClearSubplanExecutionNode(SSubplan* pSubplan);
|
||||||
|
|
||||||
// Convert to subplan to string for the scheduler to send to the executor
|
// Convert to subplan to string for the scheduler to send to the executor
|
||||||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen);
|
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen);
|
||||||
|
|
|
@ -727,6 +727,8 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
||||||
.schemalessType = pTscObj->schemalessType,
|
.schemalessType = pTscObj->schemalessType,
|
||||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||||
.async = true,
|
.async = true,
|
||||||
|
.svrVer = pTscObj->sVer,
|
||||||
|
.nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes)
|
||||||
};
|
};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,31 @@
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
|
|
||||||
extern SConfig *tsCfg;
|
extern SConfig* tsCfg;
|
||||||
|
|
||||||
|
static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) {
|
||||||
|
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||||
|
*pRsp = taosMemoryCalloc(1, rspSize);
|
||||||
|
if (NULL == *pRsp) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*pRsp)->useconds = 0;
|
||||||
|
(*pRsp)->completed = 1;
|
||||||
|
(*pRsp)->precision = 0;
|
||||||
|
(*pRsp)->compressed = 0;
|
||||||
|
(*pRsp)->compLen = 0;
|
||||||
|
(*pRsp)->numOfRows = htonl(pBlock->info.rows);
|
||||||
|
(*pRsp)->numOfCols = htonl(numOfCols);
|
||||||
|
|
||||||
|
int32_t len = 0;
|
||||||
|
blockCompressEncode(pBlock, (*pRsp)->data, &len, numOfCols, false);
|
||||||
|
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||||
|
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t getSchemaBytes(const SSchema* pSchema) {
|
static int32_t getSchemaBytes(const SSchema* pSchema) {
|
||||||
switch (pSchema->type) {
|
switch (pSchema->type) {
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
case TSDB_DATA_TYPE_BINARY:
|
||||||
|
@ -89,33 +113,13 @@ static int32_t execDescribe(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
SSDataBlock* pBlock = buildDescResultDataBlock();
|
SSDataBlock* pBlock = buildDescResultDataBlock();
|
||||||
setDescResultIntoDataBlock(pBlock, numOfRows, pDesc->pMeta);
|
setDescResultIntoDataBlock(pBlock, numOfRows, pDesc->pMeta);
|
||||||
|
|
||||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
return buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
|
||||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
|
||||||
if (NULL == *pRsp) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*pRsp)->useconds = 0;
|
|
||||||
(*pRsp)->completed = 1;
|
|
||||||
(*pRsp)->precision = 0;
|
|
||||||
(*pRsp)->compressed = 0;
|
|
||||||
(*pRsp)->compLen = 0;
|
|
||||||
(*pRsp)->numOfRows = htonl(numOfRows);
|
|
||||||
(*pRsp)->numOfCols = htonl(DESCRIBE_RESULT_COLS);
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, DESCRIBE_RESULT_COLS, false);
|
|
||||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
|
||||||
|
|
||||||
blockDataDestroy(pBlock);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t execResetQueryCache() { return catalogClearCache(); }
|
static int32_t execResetQueryCache() { return catalogClearCache(); }
|
||||||
|
|
||||||
|
|
||||||
static SSDataBlock* buildCreateDBResultDataBlock() {
|
static SSDataBlock* buildCreateDBResultDataBlock() {
|
||||||
SSDataBlock* pBlock = createDataBlock();
|
SSDataBlock* pBlock = createDataBlock();
|
||||||
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_COLS, 1);
|
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_COLS, 1);
|
||||||
blockDataAppendColInfo(pBlock, &infoData);
|
blockDataAppendColInfo(pBlock, &infoData);
|
||||||
|
|
||||||
|
@ -149,14 +153,14 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buildRetension(SArray *pRetension) {
|
char* buildRetension(SArray* pRetension) {
|
||||||
size_t size = taosArrayGetSize(pRetension);
|
size_t size = taosArrayGetSize(pRetension);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *p1 = taosMemoryCalloc(1, 100);
|
char* p1 = taosMemoryCalloc(1, 100);
|
||||||
SRetention *p = taosArrayGet(pRetension, 0);
|
SRetention* p = taosArrayGet(pRetension, 0);
|
||||||
|
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
|
|
||||||
|
@ -185,8 +189,7 @@ char *buildRetension(SArray *pRetension) {
|
||||||
return p1;
|
return p1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbFName, SDbCfgInfo* pCfg) {
|
||||||
static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, SDbCfgInfo* pCfg) {
|
|
||||||
blockDataEnsureCapacity(pBlock, 1);
|
blockDataEnsureCapacity(pBlock, 1);
|
||||||
pBlock->info.rows = 1;
|
pBlock->info.rows = 1;
|
||||||
|
|
||||||
|
@ -198,7 +201,7 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, S
|
||||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||||
char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
|
char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
char *prec = NULL;
|
char* prec = NULL;
|
||||||
switch (pCfg->precision) {
|
switch (pCfg->precision) {
|
||||||
case TSDB_TIME_PRECISION_MILLI:
|
case TSDB_TIME_PRECISION_MILLI:
|
||||||
prec = TSDB_TIME_PRECISION_MILLI_STR;
|
prec = TSDB_TIME_PRECISION_MILLI_STR;
|
||||||
|
@ -214,15 +217,16 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, S
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *retentions = buildRetension(pCfg->pRetensions);
|
char* retentions = buildRetension(pCfg->pRetensions);
|
||||||
|
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s` BUFFER %d CACHELAST %d COMP %d DURATION %dm "
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE,
|
||||||
"FSYNC %d MAXROWS %d MINROWS %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d "
|
"CREATE DATABASE `%s` BUFFER %d CACHELAST %d COMP %d DURATION %dm "
|
||||||
"STRICT %d WAL %d VGROUPS %d SINGLE_STABLE %d",
|
"FSYNC %d MAXROWS %d MINROWS %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d "
|
||||||
dbFName, pCfg->buffer, pCfg->cacheLastRow, pCfg->compression, pCfg->daysPerFile,
|
"STRICT %d WAL %d VGROUPS %d SINGLE_STABLE %d",
|
||||||
pCfg->fsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2,
|
dbFName, pCfg->buffer, pCfg->cacheLastRow, pCfg->compression, pCfg->daysPerFile, pCfg->fsyncPeriod,
|
||||||
pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->strict, pCfg->walLevel, pCfg->numOfVgroups,
|
pCfg->maxRows, pCfg->minRows, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2, pCfg->pages,
|
||||||
1 == pCfg->numOfStables);
|
pCfg->pageSize, prec, pCfg->replications, pCfg->strict, pCfg->walLevel, pCfg->numOfVgroups,
|
||||||
|
1 == pCfg->numOfStables);
|
||||||
|
|
||||||
if (retentions) {
|
if (retentions) {
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", retentions);
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", retentions);
|
||||||
|
@ -230,35 +234,14 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, S
|
||||||
}
|
}
|
||||||
|
|
||||||
(varDataLen(buf2)) = len;
|
(varDataLen(buf2)) = len;
|
||||||
|
|
||||||
colDataAppend(pCol2, 0, buf2, false);
|
colDataAppend(pCol2, 0, buf2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
SSDataBlock* pBlock = buildCreateDBResultDataBlock();
|
SSDataBlock* pBlock = buildCreateDBResultDataBlock();
|
||||||
setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->pCfg);
|
setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->pCfg);
|
||||||
|
return buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp);
|
||||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
|
||||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
|
||||||
if (NULL == *pRsp) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*pRsp)->useconds = 0;
|
|
||||||
(*pRsp)->completed = 1;
|
|
||||||
(*pRsp)->precision = 0;
|
|
||||||
(*pRsp)->compressed = 0;
|
|
||||||
(*pRsp)->compLen = 0;
|
|
||||||
(*pRsp)->numOfRows = htonl(1);
|
|
||||||
(*pRsp)->numOfCols = htonl(SHOW_CREATE_DB_RESULT_COLS);
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, SHOW_CREATE_DB_RESULT_COLS, false);
|
|
||||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
|
||||||
|
|
||||||
blockDataDestroy(pBlock);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* buildCreateTbResultDataBlock() {
|
static SSDataBlock* buildCreateTbResultDataBlock() {
|
||||||
|
@ -276,14 +259,14 @@ static SSDataBlock* buildCreateTbResultDataBlock() {
|
||||||
void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
|
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
|
||||||
SSchema* pSchema = pCfg->pSchemas + i;
|
SSchema* pSchema = pCfg->pSchemas + i;
|
||||||
char type[32];
|
char type[32];
|
||||||
sprintf(type, "%s", tDataTypes[pSchema->type].name);
|
sprintf(type, "%s", tDataTypes[pSchema->type].name);
|
||||||
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type) {
|
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type) {
|
||||||
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||||
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
||||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE));
|
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,19 +274,18 @@ void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
|
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
|
||||||
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
|
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
|
||||||
char type[32];
|
char type[32];
|
||||||
sprintf(type, "%s", tDataTypes[pSchema->type].name);
|
sprintf(type, "%s", tDataTypes[pSchema->type].name);
|
||||||
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type) {
|
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type) {
|
||||||
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||||
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
||||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE));
|
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
|
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
|
||||||
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
|
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
|
||||||
|
@ -311,13 +293,12 @@ void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
SArray *pTagVals = NULL;
|
SArray* pTagVals = NULL;
|
||||||
STag *pTag = (STag*)pCfg->pTags;
|
STag* pTag = (STag*)pCfg->pTags;
|
||||||
|
|
||||||
if (pCfg->pTags && pTag->flags & TD_TAG_JSON) {
|
if (pCfg->pTags && pTag->flags & TD_TAG_JSON) {
|
||||||
char *pJson = parseTagDatatoJson(pTag);
|
char* pJson = parseTagDatatoJson(pTag);
|
||||||
if (pJson) {
|
if (pJson) {
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
|
||||||
taosMemoryFree(pJson);
|
taosMemoryFree(pJson);
|
||||||
|
@ -325,8 +306,8 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tTagToValArray((const STag *)pCfg->pTags, &pTagVals);
|
int32_t code = tTagToValArray((const STag*)pCfg->pTags, &pTagVals);
|
||||||
if (code) {
|
if (code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -339,20 +320,20 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", ");
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j >= valueNum) {
|
if (j >= valueNum) {
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL");
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, j);
|
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
|
||||||
if (pSchema->colId > pTagVal->cid) {
|
if (pSchema->colId > pTagVal->cid) {
|
||||||
qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
|
qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
|
||||||
taosArrayDestroy(pTagVals);
|
taosArrayDestroy(pTagVals);
|
||||||
return TSDB_CODE_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
} else if (pSchema->colId == pTagVal->cid) {
|
} else if (pSchema->colId == pTagVal->cid) {
|
||||||
char type = pTagVal->type;
|
char type = pTagVal->type;
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(type)) {
|
if (IS_VAR_DATA_TYPE(type)) {
|
||||||
dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen);
|
dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen);
|
||||||
|
@ -364,7 +345,6 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
} else {
|
} else {
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL");
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (type == TSDB_DATA_TYPE_BINARY) {
|
if (type == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
@ -372,7 +352,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
if (num) {
|
if (num) {
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", ");
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf + VARSTR_HEADER_SIZE + *len, pTagVal->pData, pTagVal->nData);
|
memcpy(buf + VARSTR_HEADER_SIZE + *len, pTagVal->pData, pTagVal->nData);
|
||||||
*len += pTagVal->nData;
|
*len += pTagVal->nData;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +377,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
|
|
||||||
taosArrayDestroy(pTagVals);
|
taosArrayDestroy(pTagVals);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendTableOptions(char* buf, int32_t* len, STableCfg* pCfg) {
|
void appendTableOptions(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
|
@ -426,7 +406,7 @@ void appendTableOptions(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, " ROLLUP(");
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, " ROLLUP(");
|
||||||
for (int32_t i = 0; i < funcNum; ++i) {
|
for (int32_t i = 0; i < funcNum; ++i) {
|
||||||
char* pFunc = taosArrayGet(pCfg->pFuncs, i);
|
char* pFunc = taosArrayGet(pCfg->pFuncs, i);
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s%s", ((i > 0) ? ", " : ""), pFunc);
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s%s", ((i > 0) ? ", " : ""), pFunc);
|
||||||
}
|
}
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ")");
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ")");
|
||||||
}
|
}
|
||||||
|
@ -436,7 +416,7 @@ void appendTableOptions(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char *tbName, STableCfg* pCfg) {
|
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char* tbName, STableCfg* pCfg) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
blockDataEnsureCapacity(pBlock, 1);
|
blockDataEnsureCapacity(pBlock, 1);
|
||||||
pBlock->info.rows = 1;
|
pBlock->info.rows = 1;
|
||||||
|
@ -454,7 +434,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char *tbName,
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE STABLE `%s` (", tbName);
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE STABLE `%s` (", tbName);
|
||||||
appendColumnFields(buf2, &len, pCfg);
|
appendColumnFields(buf2, &len, pCfg);
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS (");
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS (");
|
||||||
appendTagFields(buf2, &len, pCfg);
|
appendTagFields(buf2, &len, pCfg);
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")");
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")");
|
||||||
appendTableOptions(buf2, &len, pCfg);
|
appendTableOptions(buf2, &len, pCfg);
|
||||||
} else if (TSDB_CHILD_TABLE == pCfg->tableType) {
|
} else if (TSDB_CHILD_TABLE == pCfg->tableType) {
|
||||||
|
@ -474,40 +454,19 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char *tbName,
|
||||||
}
|
}
|
||||||
|
|
||||||
varDataLen(buf2) = len;
|
varDataLen(buf2) = len;
|
||||||
|
|
||||||
colDataAppend(pCol2, 0, buf2, false);
|
colDataAppend(pCol2, 0, buf2, false);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
SSDataBlock* pBlock = buildCreateTbResultDataBlock();
|
SSDataBlock* pBlock = buildCreateTbResultDataBlock();
|
||||||
int32_t code = setCreateTBResultIntoDataBlock(pBlock, pStmt->tableName, pStmt->pCfg);
|
int32_t code = setCreateTBResultIntoDataBlock(pBlock, pStmt->tableName, pStmt->pCfg);
|
||||||
if (code) {
|
if (code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
return buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
|
||||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
|
||||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
|
||||||
if (NULL == *pRsp) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*pRsp)->useconds = 0;
|
|
||||||
(*pRsp)->completed = 1;
|
|
||||||
(*pRsp)->precision = 0;
|
|
||||||
(*pRsp)->compressed = 0;
|
|
||||||
(*pRsp)->compLen = 0;
|
|
||||||
(*pRsp)->numOfRows = htonl(1);
|
|
||||||
(*pRsp)->numOfCols = htonl(SHOW_CREATE_TB_RESULT_COLS);
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, SHOW_CREATE_TB_RESULT_COLS, false);
|
|
||||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
|
||||||
|
|
||||||
blockDataDestroy(pBlock);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
|
@ -516,17 +475,17 @@ static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt, SRetrieveTableR
|
||||||
terrno = TSDB_CODE_TSC_NOT_STABLE_ERROR;
|
terrno = TSDB_CODE_TSC_NOT_STABLE_ERROR;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return execShowCreateTable(pStmt, pRsp);
|
return execShowCreateTable(pStmt, pRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
|
static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
|
||||||
if (cfgSetItem(tsCfg, pStmt->config, pStmt->value, CFG_STYPE_ALTER_CMD)) {
|
if (cfgSetItem(tsCfg, pStmt->config, pStmt->value, CFG_STYPE_ALTER_CMD)) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosSetCfg(tsCfg, pStmt->config)) {
|
if (taosSetCfg(tsCfg, pStmt->config)) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -551,21 +510,20 @@ static SSDataBlock* buildLocalVariablesResultDataBlock() {
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t setLocalVariablesResultIntoDataBlock(SSDataBlock* pBlock) {
|
int32_t setLocalVariablesResultIntoDataBlock(SSDataBlock* pBlock) {
|
||||||
int32_t numOfCfg = taosArrayGetSize(tsCfg->array);
|
int32_t numOfCfg = taosArrayGetSize(tsCfg->array);
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
blockDataEnsureCapacity(pBlock, numOfCfg);
|
blockDataEnsureCapacity(pBlock, numOfCfg);
|
||||||
|
|
||||||
for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) {
|
for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) {
|
||||||
SConfigItem *pItem = taosArrayGet(tsCfg->array, i);
|
SConfigItem* pItem = taosArrayGet(tsCfg->array, i);
|
||||||
|
|
||||||
char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
|
char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
|
STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, c++);
|
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, c++);
|
||||||
colDataAppend(pColInfo, i, name, false);
|
colDataAppend(pColInfo, i, name, false);
|
||||||
|
|
||||||
char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
|
char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
int32_t valueLen = 0;
|
int32_t valueLen = 0;
|
||||||
cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen);
|
cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen);
|
||||||
varDataSetLen(value, valueLen);
|
varDataSetLen(value, valueLen);
|
||||||
|
@ -575,42 +533,70 @@ int32_t setLocalVariablesResultIntoDataBlock(SSDataBlock* pBlock) {
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pBlock->info.rows = numOfRows;
|
pBlock->info.rows = numOfRows;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
||||||
SSDataBlock* pBlock = buildLocalVariablesResultDataBlock();
|
SSDataBlock* pBlock = buildLocalVariablesResultDataBlock();
|
||||||
int32_t code = setLocalVariablesResultIntoDataBlock(pBlock);
|
int32_t code = setLocalVariablesResultIntoDataBlock(pBlock);
|
||||||
if (code) {
|
if (code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
return buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
|
||||||
|
}
|
||||||
|
|
||||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** pOutput) {
|
||||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
if (NULL == *pRsp) {
|
if (NULL == pBlock) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*pRsp)->useconds = 0;
|
pBlock->pDataBlock = taosArrayInit(LIST_LENGTH(pProjects), sizeof(SColumnInfoData));
|
||||||
(*pRsp)->completed = 1;
|
|
||||||
(*pRsp)->precision = 0;
|
|
||||||
(*pRsp)->compressed = 0;
|
|
||||||
(*pRsp)->compLen = 0;
|
|
||||||
(*pRsp)->numOfRows = htonl(pBlock->info.rows);
|
|
||||||
(*pRsp)->numOfCols = htonl(SHOW_LOCAL_VARIABLES_RESULT_COLS);
|
|
||||||
|
|
||||||
int32_t len = 0;
|
SNode* pProj = NULL;
|
||||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, SHOW_LOCAL_VARIABLES_RESULT_COLS, false);
|
FOREACH(pProj, pProjects) {
|
||||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
SColumnInfoData infoData = {0};
|
||||||
|
infoData.info.type = ((SExprNode*)pProj)->resType.type;
|
||||||
blockDataDestroy(pBlock);
|
infoData.info.bytes = ((SExprNode*)pProj)->resType.bytes;
|
||||||
|
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||||
|
}
|
||||||
|
*pOutput = pBlock;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
||||||
|
int32_t numOfCols = LIST_LENGTH(pProjects);
|
||||||
|
blockDataEnsureCapacity(pBlock, 1);
|
||||||
|
|
||||||
|
int32_t index = 0;
|
||||||
|
SNode* pProj = NULL;
|
||||||
|
FOREACH(pProj, pProjects) {
|
||||||
|
if (((SValueNode*)pProj)->isNull) {
|
||||||
|
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true);
|
||||||
|
} else {
|
||||||
|
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pBlock->info.rows = 1;
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** pRsp) {
|
||||||
|
SSDataBlock* pBlock = NULL;
|
||||||
|
int32_t code = createSelectResultDataBlock(pSelect->pProjectionList, &pBlock);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = buildSelectResultDataBlock(pSelect->pProjectionList, pBlock);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
switch (nodeType(pStmt)) {
|
switch (nodeType(pStmt)) {
|
||||||
case QUERY_NODE_DESCRIBE_STMT:
|
case QUERY_NODE_DESCRIBE_STMT:
|
||||||
|
@ -627,6 +613,8 @@ int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
return execAlterLocal((SAlterLocalStmt*)pStmt);
|
return execAlterLocal((SAlterLocalStmt*)pStmt);
|
||||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||||
return execShowLocalVariables(pRsp);
|
return execShowLocalVariables(pRsp);
|
||||||
|
case QUERY_NODE_SELECT_STMT:
|
||||||
|
return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ extern "C" {
|
||||||
#define FUNC_MGT_FORBID_STREAM_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(17)
|
#define FUNC_MGT_FORBID_STREAM_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(17)
|
||||||
#define FUNC_MGT_FORBID_WINDOW_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(18)
|
#define FUNC_MGT_FORBID_WINDOW_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(18)
|
||||||
#define FUNC_MGT_FORBID_GROUP_BY_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(19)
|
#define FUNC_MGT_FORBID_GROUP_BY_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(19)
|
||||||
|
#define FUNC_MGT_SYSTEM_INFO_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(20)
|
||||||
|
|
||||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||||
|
|
||||||
|
|
|
@ -1539,6 +1539,36 @@ static int32_t translateGroupKey(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t translateDatabaseFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = TSDB_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateClientVersionFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = TSDB_VERSION_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateServerVersionFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = TSDB_VERSION_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateServerStatusFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes, .type = TSDB_DATA_TYPE_INT};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateCurrentUserFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = TSDB_USER_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateUserFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = TSDB_USER_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
|
@ -2546,6 +2576,42 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.pPartialFunc = "_group_key",
|
.pPartialFunc = "_group_key",
|
||||||
.pMergeFunc = "_group_key"
|
.pMergeFunc = "_group_key"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "database",
|
||||||
|
.type = FUNCTION_TYPE_DATABASE,
|
||||||
|
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||||
|
.translateFunc = translateDatabaseFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "client_version",
|
||||||
|
.type = FUNCTION_TYPE_CLIENT_VERSION,
|
||||||
|
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||||
|
.translateFunc = translateClientVersionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "server_version",
|
||||||
|
.type = FUNCTION_TYPE_SERVER_VERSION,
|
||||||
|
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||||
|
.translateFunc = translateServerVersionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "server_status",
|
||||||
|
.type = FUNCTION_TYPE_SERVER_STATUS,
|
||||||
|
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||||
|
.translateFunc = translateServerStatusFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "current_user",
|
||||||
|
.type = FUNCTION_TYPE_CURRENT_USER,
|
||||||
|
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||||
|
.translateFunc = translateCurrentUserFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "user",
|
||||||
|
.type = FUNCTION_TYPE_USER,
|
||||||
|
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||||
|
.translateFunc = translateUserFunc,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,8 @@ bool fmIsForbidWindowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId
|
||||||
|
|
||||||
bool fmIsForbidGroupByFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_GROUP_BY_FUNC); }
|
bool fmIsForbidGroupByFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_GROUP_BY_FUNC); }
|
||||||
|
|
||||||
|
bool fmIsSystemInfoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SYSTEM_INFO_FUNC); }
|
||||||
|
|
||||||
bool fmIsInterpFunc(int32_t funcId) {
|
bool fmIsInterpFunc(int32_t funcId) {
|
||||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -685,6 +685,12 @@ literal_func(A) ::= NOW(B).
|
||||||
noarg_func(A) ::= NOW(B). { A = B; }
|
noarg_func(A) ::= NOW(B). { A = B; }
|
||||||
noarg_func(A) ::= TODAY(B). { A = B; }
|
noarg_func(A) ::= TODAY(B). { A = B; }
|
||||||
noarg_func(A) ::= TIMEZONE(B). { A = B; }
|
noarg_func(A) ::= TIMEZONE(B). { A = B; }
|
||||||
|
noarg_func(A) ::= DATABASE(B). { A = B; }
|
||||||
|
noarg_func(A) ::= CLIENT_VERSION(B). { A = B; }
|
||||||
|
noarg_func(A) ::= SERVER_VERSION(B). { A = B; }
|
||||||
|
noarg_func(A) ::= SERVER_STATUS(B). { A = B; }
|
||||||
|
noarg_func(A) ::= CURRENT_USER(B). { A = B; }
|
||||||
|
noarg_func(A) ::= USER(B). { A = B; }
|
||||||
|
|
||||||
%type star_func { SToken }
|
%type star_func { SToken }
|
||||||
%destructor star_func { }
|
%destructor star_func { }
|
||||||
|
|
|
@ -29,213 +29,217 @@ typedef struct SKeyword {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
// keywords in sql string
|
// keywords in sql string
|
||||||
static SKeyword keywordTable[] = {
|
static SKeyword keywordTable[] = {
|
||||||
{"ACCOUNT", TK_ACCOUNT},
|
{"ACCOUNT", TK_ACCOUNT},
|
||||||
{"ACCOUNTS", TK_ACCOUNTS},
|
{"ACCOUNTS", TK_ACCOUNTS},
|
||||||
{"ADD", TK_ADD},
|
{"ADD", TK_ADD},
|
||||||
{"AGGREGATE", TK_AGGREGATE},
|
{"AGGREGATE", TK_AGGREGATE},
|
||||||
{"ALL", TK_ALL},
|
{"ALL", TK_ALL},
|
||||||
{"ALTER", TK_ALTER},
|
{"ALTER", TK_ALTER},
|
||||||
{"ANALYZE", TK_ANALYZE},
|
{"ANALYZE", TK_ANALYZE},
|
||||||
{"AND", TK_AND},
|
{"AND", TK_AND},
|
||||||
{"APPS", TK_APPS},
|
{"APPS", TK_APPS},
|
||||||
{"AS", TK_AS},
|
{"AS", TK_AS},
|
||||||
{"ASC", TK_ASC},
|
{"ASC", TK_ASC},
|
||||||
{"AT_ONCE", TK_AT_ONCE},
|
{"AT_ONCE", TK_AT_ONCE},
|
||||||
{"BALANCE", TK_BALANCE},
|
{"BALANCE", TK_BALANCE},
|
||||||
{"BETWEEN", TK_BETWEEN},
|
{"BETWEEN", TK_BETWEEN},
|
||||||
{"BINARY", TK_BINARY},
|
{"BINARY", TK_BINARY},
|
||||||
{"BIGINT", TK_BIGINT},
|
{"BIGINT", TK_BIGINT},
|
||||||
{"BNODE", TK_BNODE},
|
{"BNODE", TK_BNODE},
|
||||||
{"BNODES", TK_BNODES},
|
{"BNODES", TK_BNODES},
|
||||||
{"BOOL", TK_BOOL},
|
{"BOOL", TK_BOOL},
|
||||||
{"BUFFER", TK_BUFFER},
|
{"BUFFER", TK_BUFFER},
|
||||||
{"BUFSIZE", TK_BUFSIZE},
|
{"BUFSIZE", TK_BUFSIZE},
|
||||||
{"BY", TK_BY},
|
{"BY", TK_BY},
|
||||||
{"CACHE", TK_CACHE},
|
{"CACHE", TK_CACHE},
|
||||||
{"CACHELAST", TK_CACHELAST},
|
{"CACHELAST", TK_CACHELAST},
|
||||||
{"CAST", TK_CAST},
|
{"CAST", TK_CAST},
|
||||||
{"CLUSTER", TK_CLUSTER},
|
{"CLIENT_VERSION", TK_CLIENT_VERSION},
|
||||||
{"COLUMN", TK_COLUMN},
|
{"CLUSTER", TK_CLUSTER},
|
||||||
{"COMMENT", TK_COMMENT},
|
{"COLUMN", TK_COLUMN},
|
||||||
{"COMP", TK_COMP},
|
{"COMMENT", TK_COMMENT},
|
||||||
{"COMPACT", TK_COMPACT},
|
{"COMP", TK_COMP},
|
||||||
{"CONNS", TK_CONNS},
|
{"COMPACT", TK_COMPACT},
|
||||||
{"CONNECTION", TK_CONNECTION},
|
{"CONNS", TK_CONNS},
|
||||||
{"CONNECTIONS", TK_CONNECTIONS},
|
{"CONNECTION", TK_CONNECTION},
|
||||||
{"CONSUMER", TK_CONSUMER},
|
{"CONNECTIONS", TK_CONNECTIONS},
|
||||||
{"CONSUMERS", TK_CONSUMERS},
|
{"CONSUMER", TK_CONSUMER},
|
||||||
{"COUNT", TK_COUNT},
|
{"CONSUMERS", TK_CONSUMERS},
|
||||||
{"CREATE", TK_CREATE},
|
{"CONTAINS", TK_CONTAINS},
|
||||||
{"CONTAINS", TK_CONTAINS},
|
{"COUNT", TK_COUNT},
|
||||||
{"DATABASE", TK_DATABASE},
|
{"CREATE", TK_CREATE},
|
||||||
{"DATABASES", TK_DATABASES},
|
{"CURRENT_USER", TK_CURRENT_USER},
|
||||||
{"DBS", TK_DBS},
|
{"DATABASE", TK_DATABASE},
|
||||||
{"DELETE", TK_DELETE},
|
{"DATABASES", TK_DATABASES},
|
||||||
{"DESC", TK_DESC},
|
{"DBS", TK_DBS},
|
||||||
{"DESCRIBE", TK_DESCRIBE},
|
{"DELETE", TK_DELETE},
|
||||||
{"DISTINCT", TK_DISTINCT},
|
{"DESC", TK_DESC},
|
||||||
{"DISTRIBUTED", TK_DISTRIBUTED},
|
{"DESCRIBE", TK_DESCRIBE},
|
||||||
{"DNODE", TK_DNODE},
|
{"DISTINCT", TK_DISTINCT},
|
||||||
{"DNODES", TK_DNODES},
|
{"DISTRIBUTED", TK_DISTRIBUTED},
|
||||||
{"DOUBLE", TK_DOUBLE},
|
{"DNODE", TK_DNODE},
|
||||||
{"DROP", TK_DROP},
|
{"DNODES", TK_DNODES},
|
||||||
{"DURATION", TK_DURATION},
|
{"DOUBLE", TK_DOUBLE},
|
||||||
{"ENABLE", TK_ENABLE},
|
{"DROP", TK_DROP},
|
||||||
{"EXISTS", TK_EXISTS},
|
{"DURATION", TK_DURATION},
|
||||||
{"EXPLAIN", TK_EXPLAIN},
|
{"ENABLE", TK_ENABLE},
|
||||||
{"EVERY", TK_EVERY},
|
{"EXISTS", TK_EXISTS},
|
||||||
{"FILL", TK_FILL},
|
{"EXPLAIN", TK_EXPLAIN},
|
||||||
{"FIRST", TK_FIRST},
|
{"EVERY", TK_EVERY},
|
||||||
{"FLOAT", TK_FLOAT},
|
{"FILL", TK_FILL},
|
||||||
{"FROM", TK_FROM},
|
{"FIRST", TK_FIRST},
|
||||||
{"FSYNC", TK_FSYNC},
|
{"FLOAT", TK_FLOAT},
|
||||||
{"FUNCTION", TK_FUNCTION},
|
{"FROM", TK_FROM},
|
||||||
{"FUNCTIONS", TK_FUNCTIONS},
|
{"FSYNC", TK_FSYNC},
|
||||||
{"GRANT", TK_GRANT},
|
{"FUNCTION", TK_FUNCTION},
|
||||||
{"GRANTS", TK_GRANTS},
|
{"FUNCTIONS", TK_FUNCTIONS},
|
||||||
{"GROUP", TK_GROUP},
|
{"GRANT", TK_GRANT},
|
||||||
{"HAVING", TK_HAVING},
|
{"GRANTS", TK_GRANTS},
|
||||||
{"IF", TK_IF},
|
{"GROUP", TK_GROUP},
|
||||||
{"IMPORT", TK_IMPORT},
|
{"HAVING", TK_HAVING},
|
||||||
{"IN", TK_IN},
|
{"IF", TK_IF},
|
||||||
{"INDEX", TK_INDEX},
|
{"IMPORT", TK_IMPORT},
|
||||||
{"INDEXES", TK_INDEXES},
|
{"IN", TK_IN},
|
||||||
{"INNER", TK_INNER},
|
{"INDEX", TK_INDEX},
|
||||||
{"INT", TK_INT},
|
{"INDEXES", TK_INDEXES},
|
||||||
{"INSERT", TK_INSERT},
|
{"INNER", TK_INNER},
|
||||||
{"INTEGER", TK_INTEGER},
|
{"INT", TK_INT},
|
||||||
{"INTERVAL", TK_INTERVAL},
|
{"INSERT", TK_INSERT},
|
||||||
{"INTO", TK_INTO},
|
{"INTEGER", TK_INTEGER},
|
||||||
{"IS", TK_IS},
|
{"INTERVAL", TK_INTERVAL},
|
||||||
{"JOIN", TK_JOIN},
|
{"INTO", TK_INTO},
|
||||||
{"JSON", TK_JSON},
|
{"IS", TK_IS},
|
||||||
{"KEEP", TK_KEEP},
|
{"JOIN", TK_JOIN},
|
||||||
{"KILL", TK_KILL},
|
{"JSON", TK_JSON},
|
||||||
{"LAST", TK_LAST},
|
{"KEEP", TK_KEEP},
|
||||||
{"LAST_ROW", TK_LAST_ROW},
|
{"KILL", TK_KILL},
|
||||||
{"LICENCE", TK_LICENCE},
|
{"LAST", TK_LAST},
|
||||||
{"LIKE", TK_LIKE},
|
{"LAST_ROW", TK_LAST_ROW},
|
||||||
{"LIMIT", TK_LIMIT},
|
{"LICENCE", TK_LICENCE},
|
||||||
{"LINEAR", TK_LINEAR},
|
{"LIKE", TK_LIKE},
|
||||||
{"LOCAL", TK_LOCAL},
|
{"LIMIT", TK_LIMIT},
|
||||||
{"MATCH", TK_MATCH},
|
{"LINEAR", TK_LINEAR},
|
||||||
{"MAXROWS", TK_MAXROWS},
|
{"LOCAL", TK_LOCAL},
|
||||||
{"MAX_DELAY", TK_MAX_DELAY},
|
{"MATCH", TK_MATCH},
|
||||||
{"MERGE", TK_MERGE},
|
{"MAXROWS", TK_MAXROWS},
|
||||||
{"META", TK_META},
|
{"MAX_DELAY", TK_MAX_DELAY},
|
||||||
{"MINROWS", TK_MINROWS},
|
{"MERGE", TK_MERGE},
|
||||||
{"MINUS", TK_MINUS},
|
{"META", TK_META},
|
||||||
{"MNODE", TK_MNODE},
|
{"MINROWS", TK_MINROWS},
|
||||||
{"MNODES", TK_MNODES},
|
{"MINUS", TK_MINUS},
|
||||||
{"MODIFY", TK_MODIFY},
|
{"MNODE", TK_MNODE},
|
||||||
{"MODULES", TK_MODULES},
|
{"MNODES", TK_MNODES},
|
||||||
{"NCHAR", TK_NCHAR},
|
{"MODIFY", TK_MODIFY},
|
||||||
{"NEXT", TK_NEXT},
|
{"MODULES", TK_MODULES},
|
||||||
{"NMATCH", TK_NMATCH},
|
{"NCHAR", TK_NCHAR},
|
||||||
{"NONE", TK_NONE},
|
{"NEXT", TK_NEXT},
|
||||||
{"NOT", TK_NOT},
|
{"NMATCH", TK_NMATCH},
|
||||||
{"NOW", TK_NOW},
|
{"NONE", TK_NONE},
|
||||||
{"NULL", TK_NULL},
|
{"NOT", TK_NOT},
|
||||||
{"NULLS", TK_NULLS},
|
{"NOW", TK_NOW},
|
||||||
{"OFFSET", TK_OFFSET},
|
{"NULL", TK_NULL},
|
||||||
{"ON", TK_ON},
|
{"NULLS", TK_NULLS},
|
||||||
{"OR", TK_OR},
|
{"OFFSET", TK_OFFSET},
|
||||||
{"ORDER", TK_ORDER},
|
{"ON", TK_ON},
|
||||||
{"OUTPUTTYPE", TK_OUTPUTTYPE},
|
{"OR", TK_OR},
|
||||||
{"PARTITION", TK_PARTITION},
|
{"ORDER", TK_ORDER},
|
||||||
{"PASS", TK_PASS},
|
{"OUTPUTTYPE", TK_OUTPUTTYPE},
|
||||||
{"PAGES", TK_PAGES},
|
{"PARTITION", TK_PARTITION},
|
||||||
{"PAGESIZE", TK_PAGESIZE},
|
{"PASS", TK_PASS},
|
||||||
{"PORT", TK_PORT},
|
{"PAGES", TK_PAGES},
|
||||||
{"PPS", TK_PPS},
|
{"PAGESIZE", TK_PAGESIZE},
|
||||||
{"PRECISION", TK_PRECISION},
|
{"PORT", TK_PORT},
|
||||||
// {"PRIVILEGE", TK_PRIVILEGE},
|
{"PPS", TK_PPS},
|
||||||
{"PREV", TK_PREV},
|
{"PRECISION", TK_PRECISION},
|
||||||
{"QNODE", TK_QNODE},
|
// {"PRIVILEGE", TK_PRIVILEGE},
|
||||||
{"QNODES", TK_QNODES},
|
{"PREV", TK_PREV},
|
||||||
{"QTIME", TK_QTIME},
|
{"QNODE", TK_QNODE},
|
||||||
{"QUERIES", TK_QUERIES},
|
{"QNODES", TK_QNODES},
|
||||||
{"QUERY", TK_QUERY},
|
{"QTIME", TK_QTIME},
|
||||||
{"RANGE", TK_RANGE},
|
{"QUERIES", TK_QUERIES},
|
||||||
{"RATIO", TK_RATIO},
|
{"QUERY", TK_QUERY},
|
||||||
{"READ", TK_READ},
|
{"RANGE", TK_RANGE},
|
||||||
{"REDISTRIBUTE", TK_REDISTRIBUTE},
|
{"RATIO", TK_RATIO},
|
||||||
{"RENAME", TK_RENAME},
|
{"READ", TK_READ},
|
||||||
{"REPLICA", TK_REPLICA},
|
{"REDISTRIBUTE", TK_REDISTRIBUTE},
|
||||||
{"RESET", TK_RESET},
|
{"RENAME", TK_RENAME},
|
||||||
{"RETENTIONS", TK_RETENTIONS},
|
{"REPLICA", TK_REPLICA},
|
||||||
{"REVOKE", TK_REVOKE},
|
{"RESET", TK_RESET},
|
||||||
{"ROLLUP", TK_ROLLUP},
|
{"RETENTIONS", TK_RETENTIONS},
|
||||||
{"SCHEMALESS", TK_SCHEMALESS},
|
{"REVOKE", TK_REVOKE},
|
||||||
{"SCORES", TK_SCORES},
|
{"ROLLUP", TK_ROLLUP},
|
||||||
{"SELECT", TK_SELECT},
|
{"SCHEMALESS", TK_SCHEMALESS},
|
||||||
{"SESSION", TK_SESSION},
|
{"SCORES", TK_SCORES},
|
||||||
{"SET", TK_SET},
|
{"SELECT", TK_SELECT},
|
||||||
{"SHOW", TK_SHOW},
|
{"SERVER_STATUS", TK_SERVER_STATUS},
|
||||||
{"SINGLE_STABLE", TK_SINGLE_STABLE},
|
{"SERVER_VERSION", TK_SERVER_VERSION},
|
||||||
{"SLIDING", TK_SLIDING},
|
{"SESSION", TK_SESSION},
|
||||||
{"SLIMIT", TK_SLIMIT},
|
{"SET", TK_SET},
|
||||||
{"SMA", TK_SMA},
|
{"SHOW", TK_SHOW},
|
||||||
{"SMALLINT", TK_SMALLINT},
|
{"SINGLE_STABLE", TK_SINGLE_STABLE},
|
||||||
{"SNODE", TK_SNODE},
|
{"SLIDING", TK_SLIDING},
|
||||||
{"SNODES", TK_SNODES},
|
{"SLIMIT", TK_SLIMIT},
|
||||||
{"SOFFSET", TK_SOFFSET},
|
{"SMA", TK_SMA},
|
||||||
{"SPLIT", TK_SPLIT},
|
{"SMALLINT", TK_SMALLINT},
|
||||||
{"STABLE", TK_STABLE},
|
{"SNODE", TK_SNODE},
|
||||||
{"STABLES", TK_STABLES},
|
{"SNODES", TK_SNODES},
|
||||||
{"STATE", TK_STATE},
|
{"SOFFSET", TK_SOFFSET},
|
||||||
{"STATE_WINDOW", TK_STATE_WINDOW},
|
{"SPLIT", TK_SPLIT},
|
||||||
{"STORAGE", TK_STORAGE},
|
{"STABLE", TK_STABLE},
|
||||||
{"STREAM", TK_STREAM},
|
{"STABLES", TK_STABLES},
|
||||||
{"STREAMS", TK_STREAMS},
|
{"STATE", TK_STATE},
|
||||||
{"STRICT", TK_STRICT},
|
{"STATE_WINDOW", TK_STATE_WINDOW},
|
||||||
{"SUBSCRIPTIONS", TK_SUBSCRIPTIONS},
|
{"STORAGE", TK_STORAGE},
|
||||||
{"SYNCDB", TK_SYNCDB},
|
{"STREAM", TK_STREAM},
|
||||||
{"SYSINFO", TK_SYSINFO},
|
{"STREAMS", TK_STREAMS},
|
||||||
{"TABLE", TK_TABLE},
|
{"STRICT", TK_STRICT},
|
||||||
{"TABLES", TK_TABLES},
|
{"SUBSCRIPTIONS", TK_SUBSCRIPTIONS},
|
||||||
{"TAG", TK_TAG},
|
{"SYNCDB", TK_SYNCDB},
|
||||||
{"TAGS", TK_TAGS},
|
{"SYSINFO", TK_SYSINFO},
|
||||||
{"TBNAME", TK_TBNAME},
|
{"TABLE", TK_TABLE},
|
||||||
{"TIMESTAMP", TK_TIMESTAMP},
|
{"TABLES", TK_TABLES},
|
||||||
{"TIMEZONE", TK_TIMEZONE},
|
{"TAG", TK_TAG},
|
||||||
{"TINYINT", TK_TINYINT},
|
{"TAGS", TK_TAGS},
|
||||||
{"TO", TK_TO},
|
{"TBNAME", TK_TBNAME},
|
||||||
{"TODAY", TK_TODAY},
|
{"TIMESTAMP", TK_TIMESTAMP},
|
||||||
{"TOPIC", TK_TOPIC},
|
{"TIMEZONE", TK_TIMEZONE},
|
||||||
{"TOPICS", TK_TOPICS},
|
{"TINYINT", TK_TINYINT},
|
||||||
{"TRANSACTION", TK_TRANSACTION},
|
{"TO", TK_TO},
|
||||||
{"TRANSACTIONS", TK_TRANSACTIONS},
|
{"TODAY", TK_TODAY},
|
||||||
{"TRIGGER", TK_TRIGGER},
|
{"TOPIC", TK_TOPIC},
|
||||||
{"TSERIES", TK_TSERIES},
|
{"TOPICS", TK_TOPICS},
|
||||||
{"TTL", TK_TTL},
|
{"TRANSACTION", TK_TRANSACTION},
|
||||||
{"UNION", TK_UNION},
|
{"TRANSACTIONS", TK_TRANSACTIONS},
|
||||||
{"UNSIGNED", TK_UNSIGNED},
|
{"TRIGGER", TK_TRIGGER},
|
||||||
{"USE", TK_USE},
|
{"TSERIES", TK_TSERIES},
|
||||||
{"USER", TK_USER},
|
{"TTL", TK_TTL},
|
||||||
{"USERS", TK_USERS},
|
{"UNION", TK_UNION},
|
||||||
{"USING", TK_USING},
|
{"UNSIGNED", TK_UNSIGNED},
|
||||||
{"VALUE", TK_VALUE},
|
{"USE", TK_USE},
|
||||||
{"VALUES", TK_VALUES},
|
{"USER", TK_USER},
|
||||||
{"VARCHAR", TK_VARCHAR},
|
{"USERS", TK_USERS},
|
||||||
{"VARIABLES", TK_VARIABLES},
|
{"USING", TK_USING},
|
||||||
{"VERBOSE", TK_VERBOSE},
|
{"VALUE", TK_VALUE},
|
||||||
{"VGROUP", TK_VGROUP},
|
{"VALUES", TK_VALUES},
|
||||||
{"VGROUPS", TK_VGROUPS},
|
{"VARCHAR", TK_VARCHAR},
|
||||||
{"VNODES", TK_VNODES},
|
{"VARIABLES", TK_VARIABLES},
|
||||||
{"WAL", TK_WAL},
|
{"VERBOSE", TK_VERBOSE},
|
||||||
{"WATERMARK", TK_WATERMARK},
|
{"VGROUP", TK_VGROUP},
|
||||||
{"WHERE", TK_WHERE},
|
{"VGROUPS", TK_VGROUPS},
|
||||||
{"WINDOW_CLOSE", TK_WINDOW_CLOSE},
|
{"VNODES", TK_VNODES},
|
||||||
{"WITH", TK_WITH},
|
{"WAL", TK_WAL},
|
||||||
{"WRITE", TK_WRITE},
|
{"WATERMARK", TK_WATERMARK},
|
||||||
{"_C0", TK_ROWTS},
|
{"WHERE", TK_WHERE},
|
||||||
{"_QENDTS", TK_QENDTS},
|
{"WINDOW_CLOSE", TK_WINDOW_CLOSE},
|
||||||
{"_QSTARTTS", TK_QSTARTTS},
|
{"WITH", TK_WITH},
|
||||||
{"_ROWTS", TK_ROWTS},
|
{"WRITE", TK_WRITE},
|
||||||
{"_WDURATION", TK_WDURATION},
|
{"_C0", TK_ROWTS},
|
||||||
{"_WENDTS", TK_WENDTS},
|
{"_QENDTS", TK_QENDTS},
|
||||||
{"_WSTARTTS", TK_WSTARTTS},
|
{"_QSTARTTS", TK_QSTARTTS},
|
||||||
|
{"_ROWTS", TK_ROWTS},
|
||||||
|
{"_WDURATION", TK_WDURATION},
|
||||||
|
{"_WENDTS", TK_WENDTS},
|
||||||
|
{"_WSTARTTS", TK_WSTARTTS},
|
||||||
// {"ID", TK_ID},
|
// {"ID", TK_ID},
|
||||||
// {"STRING", TK_STRING},
|
// {"STRING", TK_STRING},
|
||||||
// {"EQ", TK_EQ},
|
// {"EQ", TK_EQ},
|
||||||
|
|
|
@ -35,8 +35,7 @@ typedef struct STranslateContext {
|
||||||
SArray* pNsLevel; // element is SArray*, the element of this subarray is STableNode*
|
SArray* pNsLevel; // element is SArray*, the element of this subarray is STableNode*
|
||||||
int32_t currLevel;
|
int32_t currLevel;
|
||||||
ESqlClause currClause;
|
ESqlClause currClause;
|
||||||
SSelectStmt* pCurrSelectStmt;
|
SNode* pCurrStmt;
|
||||||
SSetOperator* pCurrSetOperator;
|
|
||||||
SCmdMsgInfo* pCmdMsg;
|
SCmdMsgInfo* pCmdMsg;
|
||||||
SHashObj* pDbs;
|
SHashObj* pDbs;
|
||||||
SHashObj* pTables;
|
SHashObj* pTables;
|
||||||
|
@ -397,6 +396,34 @@ static void destroyTranslateContext(STranslateContext* pCxt) {
|
||||||
taosHashCleanup(pCxt->pTables);
|
taosHashCleanup(pCxt->pTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isSelectStmt(SNode* pCurrStmt) {
|
||||||
|
return NULL != pCurrStmt && QUERY_NODE_SELECT_STMT == nodeType(pCurrStmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isSetOperator(SNode* pCurrStmt) {
|
||||||
|
return NULL != pCurrStmt && QUERY_NODE_SET_OPERATOR == nodeType(pCurrStmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SNodeList* getProjectListFromCurrStmt(SNode* pCurrStmt) {
|
||||||
|
if (isSelectStmt(pCurrStmt)) {
|
||||||
|
return ((SSelectStmt*)pCurrStmt)->pProjectionList;
|
||||||
|
}
|
||||||
|
if (isSetOperator(pCurrStmt)) {
|
||||||
|
return ((SSetOperator*)pCurrStmt)->pProjectionList;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t getPrecisionFromCurrStmt(SNode* pCurrStmt, uint8_t defaultVal) {
|
||||||
|
if (isSelectStmt(pCurrStmt)) {
|
||||||
|
return ((SSelectStmt*)pCurrStmt)->precision;
|
||||||
|
}
|
||||||
|
if (isSetOperator(pCurrStmt)) {
|
||||||
|
return ((SSetOperator*)pCurrStmt)->precision;
|
||||||
|
}
|
||||||
|
return defaultVal;
|
||||||
|
}
|
||||||
|
|
||||||
static bool isAliasColumn(const SNode* pNode) {
|
static bool isAliasColumn(const SNode* pNode) {
|
||||||
return (QUERY_NODE_COLUMN == nodeType(pNode) && ('\0' == ((SColumnNode*)pNode)->tableAlias[0]));
|
return (QUERY_NODE_COLUMN == nodeType(pNode) && ('\0' == ((SColumnNode*)pNode)->tableAlias[0]));
|
||||||
}
|
}
|
||||||
|
@ -426,7 +453,8 @@ static bool isVectorFunc(const SNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isDistinctOrderBy(STranslateContext* pCxt) {
|
static bool isDistinctOrderBy(STranslateContext* pCxt) {
|
||||||
return (SQL_CLAUSE_ORDER_BY == pCxt->currClause && pCxt->pCurrSelectStmt->isDistinct);
|
return (SQL_CLAUSE_ORDER_BY == pCxt->currClause && isSelectStmt(pCxt->pCurrStmt) &&
|
||||||
|
((SSelectStmt*)pCxt->pCurrStmt)->isDistinct);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool belongTable(const char* currentDb, const SColumnNode* pCol, const STableNode* pTable) {
|
static bool belongTable(const char* currentDb, const SColumnNode* pCol, const STableNode* pTable) {
|
||||||
|
@ -646,7 +674,7 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
if (isInternalPk) {
|
if (isInternalPk) {
|
||||||
if (NULL != pCxt->pCurrSelectStmt && NULL != pCxt->pCurrSelectStmt->pWindow) {
|
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
||||||
}
|
}
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_INTERNAL_PK);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_INTERNAL_PK);
|
||||||
|
@ -657,18 +685,8 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SNodeList* getProjectListFromCxt(STranslateContext* pCxt) {
|
|
||||||
if (NULL != pCxt->pCurrSelectStmt) {
|
|
||||||
return pCxt->pCurrSelectStmt->pProjectionList;
|
|
||||||
} else if (NULL != pCxt->pCurrSetOperator) {
|
|
||||||
return pCxt->pCurrSetOperator->pProjectionList;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** pCol, bool* pFound) {
|
static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** pCol, bool* pFound) {
|
||||||
SNodeList* pProjectionList = getProjectListFromCxt(pCxt);
|
SNodeList* pProjectionList = getProjectListFromCurrStmt(pCxt->pCurrStmt);
|
||||||
SNode* pNode;
|
SNode* pNode;
|
||||||
FOREACH(pNode, pProjectionList) {
|
FOREACH(pNode, pProjectionList) {
|
||||||
SExprNode* pExpr = (SExprNode*)pNode;
|
SExprNode* pExpr = (SExprNode*)pNode;
|
||||||
|
@ -690,7 +708,7 @@ static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** p
|
||||||
}
|
}
|
||||||
|
|
||||||
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||||
if (NULL != pCxt->pCurrSelectStmt && NULL == pCxt->pCurrSelectStmt->pFromTable) {
|
if (isSelectStmt(pCxt->pCurrStmt) && NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) {
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,7 +726,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||||
res = translateColumnUseAlias(pCxt, pCol, &found);
|
res = translateColumnUseAlias(pCxt, pCol, &found);
|
||||||
}
|
}
|
||||||
if (DEAL_RES_ERROR != res && !found) {
|
if (DEAL_RES_ERROR != res && !found) {
|
||||||
if (NULL != pCxt->pCurrSetOperator) {
|
if (isSetOperator(pCxt->pCurrStmt)) {
|
||||||
res = generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
res = generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
||||||
} else {
|
} else {
|
||||||
res = translateColumnWithoutPrefix(pCxt, pCol);
|
res = translateColumnWithoutPrefix(pCxt, pCol);
|
||||||
|
@ -760,9 +778,9 @@ static int32_t parseBoolFromValueNode(STranslateContext* pCxt, SValueNode* pVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SDataType targetDt) {
|
static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SDataType targetDt) {
|
||||||
uint8_t precision = (NULL != pCxt->pCurrSelectStmt ? pCxt->pCurrSelectStmt->precision : targetDt.precision);
|
uint8_t precision = getPrecisionFromCurrStmt(pCxt->pCurrStmt, targetDt.precision);
|
||||||
pVal->node.resType.precision = precision;
|
pVal->node.resType.precision = precision;
|
||||||
if (pVal->placeholderNo > 0) {
|
if (pVal->placeholderNo > 0 || pVal->isNull) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
if (pVal->isDuration) {
|
if (pVal->isDuration) {
|
||||||
|
@ -1102,6 +1120,8 @@ static bool hasInvalidFuncNesting(SNodeList* pParameterList) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
|
// the time precision of the function execution environment
|
||||||
|
pFunc->node.resType.precision = getPrecisionFromCurrStmt(pCxt->pCurrStmt, TSDB_TIME_PRECISION_MILLI);
|
||||||
int32_t code = fmGetFuncInfo(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
int32_t code = fmGetFuncInfo(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
||||||
if (TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION == code) {
|
if (TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION == code) {
|
||||||
code = getUdfInfo(pCxt, pFunc);
|
code = getUdfInfo(pCxt, pFunc);
|
||||||
|
@ -1119,7 +1139,7 @@ static int32_t translateAggFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||||
}
|
}
|
||||||
if (NULL != pCxt->pCurrSelectStmt && pCxt->pCurrSelectStmt->hasIndefiniteRowsFunc) {
|
if (isSelectStmt(pCxt->pCurrStmt) && ((SSelectStmt*)pCxt->pCurrStmt)->hasIndefiniteRowsFunc) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1134,7 +1154,8 @@ static int32_t translateScanPseudoColumnFunc(STranslateContext* pCxt, SFunctionN
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (0 == LIST_LENGTH(pFunc->pParameterList)) {
|
if (0 == LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
if (QUERY_NODE_REAL_TABLE != nodeType(pCxt->pCurrSelectStmt->pFromTable)) {
|
if (!isSelectStmt(pCxt->pCurrStmt) ||
|
||||||
|
QUERY_NODE_REAL_TABLE != nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1152,8 +1173,8 @@ static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNod
|
||||||
if (!fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
if (!fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (SQL_CLAUSE_SELECT != pCxt->currClause || pCxt->pCurrSelectStmt->hasIndefiniteRowsFunc ||
|
if (!isSelectStmt(pCxt->pCurrStmt) || SQL_CLAUSE_SELECT != pCxt->currClause ||
|
||||||
pCxt->pCurrSelectStmt->hasAggFuncs) {
|
((SSelectStmt*)pCxt->pCurrStmt)->hasIndefiniteRowsFunc || ((SSelectStmt*)pCxt->pCurrStmt)->hasAggFuncs) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||||
}
|
}
|
||||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||||
|
@ -1162,13 +1183,20 @@ static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNod
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool hasFillClause(SNode* pCurrStmt) {
|
||||||
|
if (!isSelectStmt(pCurrStmt)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SSelectStmt* pSelect = (SSelectStmt*)pCurrStmt;
|
||||||
|
return NULL != pSelect->pWindow && QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow) &&
|
||||||
|
NULL != ((SIntervalWindowNode*)pSelect->pWindow)->pFill;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateForbidFillFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
static int32_t translateForbidFillFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
if (!fmIsForbidFillFunc(pFunc->funcId)) {
|
if (!fmIsForbidFillFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (NULL != pCxt->pCurrSelectStmt->pWindow &&
|
if (hasFillClause(pCxt->pCurrStmt)) {
|
||||||
QUERY_NODE_INTERVAL_WINDOW == nodeType(pCxt->pCurrSelectStmt->pWindow) &&
|
|
||||||
NULL != ((SIntervalWindowNode*)pCxt->pCurrSelectStmt->pWindow)->pFill) {
|
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC, pFunc->functionName);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC, pFunc->functionName);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1178,7 +1206,7 @@ static int32_t translateWindowPseudoColumnFunc(STranslateContext* pCxt, SFunctio
|
||||||
if (!fmIsWindowPseudoColumnFunc(pFunc->funcId)) {
|
if (!fmIsWindowPseudoColumnFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (NULL == pCxt->pCurrSelectStmt->pWindow) {
|
if (!isSelectStmt(pCxt->pCurrStmt) || NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1188,7 +1216,7 @@ static int32_t translateForbidWindowFunc(STranslateContext* pCxt, SFunctionNode*
|
||||||
if (!fmIsForbidWindowFunc(pFunc->funcId)) {
|
if (!fmIsForbidWindowFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (NULL != pCxt->pCurrSelectStmt->pWindow) {
|
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WINDOW_NOT_ALLOWED_FUNC, pFunc->functionName);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WINDOW_NOT_ALLOWED_FUNC, pFunc->functionName);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1208,14 +1236,15 @@ static int32_t translateForbidGroupByFunc(STranslateContext* pCxt, SFunctionNode
|
||||||
if (!fmIsForbidGroupByFunc(pFunc->funcId)) {
|
if (!fmIsForbidGroupByFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (NULL != pCxt->pCurrSelectStmt->pGroupByList) {
|
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pGroupByList) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUP_BY_NOT_ALLOWED_FUNC, pFunc->functionName);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUP_BY_NOT_ALLOWED_FUNC, pFunc->functionName);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
|
||||||
if (NULL != pSelect) {
|
if (NULL != pCurrStmt && QUERY_NODE_SELECT_STMT == nodeType(pCurrStmt)) {
|
||||||
|
SSelectStmt* pSelect = (SSelectStmt*)pCurrStmt;
|
||||||
pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId);
|
pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId);
|
||||||
pSelect->hasRepeatScanFuncs = pSelect->hasRepeatScanFuncs ? true : fmIsRepeatScanFunc(pFunc->funcId);
|
pSelect->hasRepeatScanFuncs = pSelect->hasRepeatScanFuncs ? true : fmIsRepeatScanFunc(pFunc->funcId);
|
||||||
pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId);
|
pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId);
|
||||||
|
@ -1226,41 +1255,138 @@ static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
static int32_t rewriteSystemInfoFuncImpl(STranslateContext* pCxt, char* pLiteral, SNode** pNode) {
|
||||||
|
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
|
if (NULL == pVal) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
strcpy(pVal->node.aliasName, ((SExprNode*)*pNode)->aliasName);
|
||||||
|
pVal->node.resType = ((SExprNode*)*pNode)->resType;
|
||||||
|
if (NULL == pLiteral) {
|
||||||
|
pVal->isNull = true;
|
||||||
|
} else {
|
||||||
|
pVal->literal = pLiteral;
|
||||||
|
}
|
||||||
|
if (DEAL_RES_ERROR != translateValue(pCxt, pVal)) {
|
||||||
|
*pNode = (SNode*)pVal;
|
||||||
|
} else {
|
||||||
|
nodesDestroyNode((SNode*)pVal);
|
||||||
|
}
|
||||||
|
return pCxt->errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteDatabaseFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
|
char* pCurrDb = NULL;
|
||||||
|
if (NULL != pCxt->pParseCxt->db) {
|
||||||
|
pCurrDb = taosMemoryStrDup((void*)pCxt->pParseCxt->db);
|
||||||
|
if (NULL == pCurrDb) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rewriteSystemInfoFuncImpl(pCxt, pCurrDb, pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
|
char* pVer = taosMemoryStrDup((void*)version);
|
||||||
|
if (NULL == pVer) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
return rewriteSystemInfoFuncImpl(pCxt, pVer, pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteServerVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
|
char* pVer = taosMemoryStrDup((void*)pCxt->pParseCxt->svrVer);
|
||||||
|
if (NULL == pVer) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
return rewriteSystemInfoFuncImpl(pCxt, pVer, pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteServerStatusFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
|
if (pCxt->pParseCxt->nodeOffline) {
|
||||||
|
return TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
}
|
||||||
|
char* pStatus = taosMemoryStrDup((void*)"1");
|
||||||
|
return rewriteSystemInfoFuncImpl(pCxt, pStatus, pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteUserFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
|
char userConn[TSDB_USER_LEN + 1 + TSDB_FQDN_LEN] = {0}; // format 'user@host'
|
||||||
|
int32_t len = snprintf(userConn, sizeof(userConn), "%s@", pCxt->pParseCxt->pUser);
|
||||||
|
taosGetFqdn(userConn + len);
|
||||||
|
char* pUserConn = taosMemoryStrDup((void*)userConn);
|
||||||
|
if (NULL == pUserConn) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
return rewriteSystemInfoFuncImpl(pCxt, pUserConn, pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteSystemInfoFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
|
switch (((SFunctionNode*)*pNode)->funcType) {
|
||||||
|
case FUNCTION_TYPE_DATABASE:
|
||||||
|
return rewriteDatabaseFunc(pCxt, pNode);
|
||||||
|
case FUNCTION_TYPE_CLIENT_VERSION:
|
||||||
|
return rewriteClentVersionFunc(pCxt, pNode);
|
||||||
|
case FUNCTION_TYPE_SERVER_VERSION:
|
||||||
|
return rewriteServerVersionFunc(pCxt, pNode);
|
||||||
|
case FUNCTION_TYPE_SERVER_STATUS:
|
||||||
|
return rewriteServerStatusFunc(pCxt, pNode);
|
||||||
|
case FUNCTION_TYPE_CURRENT_USER:
|
||||||
|
case FUNCTION_TYPE_USER:
|
||||||
|
return rewriteUserFunc(pCxt, pNode);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateNoramlFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
|
int32_t code = translateAggFunc(pCxt, pFunc);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateScanPseudoColumnFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateIndefiniteRowsFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateForbidFillFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateWindowPseudoColumnFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateForbidWindowFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateForbidStreamFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateForbidGroupByFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
setFuncClassification(pCxt->pCurrStmt, pFunc);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateFunctionImpl(STranslateContext* pCxt, SFunctionNode** pFunc) {
|
||||||
|
if (fmIsSystemInfoFunc((*pFunc)->funcId)) {
|
||||||
|
return rewriteSystemInfoFunc(pCxt, (SNode**)pFunc);
|
||||||
|
}
|
||||||
|
return translateNoramlFunction(pCxt, *pFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode** pFunc) {
|
||||||
SNode* pParam = NULL;
|
SNode* pParam = NULL;
|
||||||
FOREACH(pParam, pFunc->pParameterList) {
|
FOREACH(pParam, (*pFunc)->pParameterList) {
|
||||||
if (isMultiResFunc(pParam)) {
|
if (isMultiResFunc(pParam)) {
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pParam)->aliasName);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pParam)->aliasName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pCxt->errCode = getFuncInfo(pCxt, pFunc);
|
pCxt->errCode = getFuncInfo(pCxt, *pFunc);
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
pCxt->errCode = translateAggFunc(pCxt, pFunc);
|
pCxt->errCode = translateFunctionImpl(pCxt, pFunc);
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
pCxt->errCode = translateScanPseudoColumnFunc(pCxt, pFunc);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
pCxt->errCode = translateIndefiniteRowsFunc(pCxt, pFunc);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
pCxt->errCode = translateForbidFillFunc(pCxt, pFunc);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
pCxt->errCode = translateWindowPseudoColumnFunc(pCxt, pFunc);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
pCxt->errCode = translateForbidWindowFunc(pCxt, pFunc);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
pCxt->errCode = translateForbidStreamFunc(pCxt, pFunc);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
pCxt->errCode = translateForbidGroupByFunc(pCxt, pFunc);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
|
||||||
setFuncClassification(pCxt->pCurrSelectStmt, pFunc);
|
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1285,7 +1411,7 @@ static EDealRes doTranslateExpr(SNode** pNode, void* pContext) {
|
||||||
case QUERY_NODE_OPERATOR:
|
case QUERY_NODE_OPERATOR:
|
||||||
return translateOperator(pCxt, (SOperatorNode**)pNode);
|
return translateOperator(pCxt, (SOperatorNode**)pNode);
|
||||||
case QUERY_NODE_FUNCTION:
|
case QUERY_NODE_FUNCTION:
|
||||||
return translateFunction(pCxt, (SFunctionNode*)*pNode);
|
return translateFunction(pCxt, (SFunctionNode**)pNode);
|
||||||
case QUERY_NODE_LOGIC_CONDITION:
|
case QUERY_NODE_LOGIC_CONDITION:
|
||||||
return translateLogicCond(pCxt, (SLogicConditionNode*)*pNode);
|
return translateLogicCond(pCxt, (SLogicConditionNode*)*pNode);
|
||||||
case QUERY_NODE_TEMP_TABLE:
|
case QUERY_NODE_TEMP_TABLE:
|
||||||
|
@ -1308,9 +1434,9 @@ static int32_t translateExprList(STranslateContext* pCxt, SNodeList* pList) {
|
||||||
|
|
||||||
static SNodeList* getGroupByList(STranslateContext* pCxt) {
|
static SNodeList* getGroupByList(STranslateContext* pCxt) {
|
||||||
if (isDistinctOrderBy(pCxt)) {
|
if (isDistinctOrderBy(pCxt)) {
|
||||||
return pCxt->pCurrSelectStmt->pProjectionList;
|
return ((SSelectStmt*)pCxt->pCurrStmt)->pProjectionList;
|
||||||
}
|
}
|
||||||
return pCxt->pCurrSelectStmt->pGroupByList;
|
return ((SSelectStmt*)pCxt->pCurrStmt)->pGroupByList;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SNode* getGroupByNode(SNode* pNode) {
|
static SNode* getGroupByNode(SNode* pNode) {
|
||||||
|
@ -1348,7 +1474,7 @@ static EDealRes rewriteColToSelectValFunc(STranslateContext* pCxt, SNode** pNode
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
*pNode = (SNode*)pFunc;
|
*pNode = (SNode*)pFunc;
|
||||||
pCxt->pCurrSelectStmt->hasSelectValFunc = true;
|
((SSelectStmt*)pCxt->pCurrStmt)->hasSelectValFunc = true;
|
||||||
} else {
|
} else {
|
||||||
nodesDestroyNode((SNode*)pFunc);
|
nodesDestroyNode((SNode*)pFunc);
|
||||||
}
|
}
|
||||||
|
@ -1378,7 +1504,7 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SNode* pPartKey = NULL;
|
SNode* pPartKey = NULL;
|
||||||
FOREACH(pPartKey, pCxt->pTranslateCxt->pCurrSelectStmt->pPartitionByList) {
|
FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) {
|
||||||
if (nodesEqualNode(pPartKey, *pNode)) {
|
if (nodesEqualNode(pPartKey, *pNode)) {
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
|
@ -1463,7 +1589,7 @@ static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) {
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
SNode* pPartKey = NULL;
|
SNode* pPartKey = NULL;
|
||||||
FOREACH(pPartKey, pCxt->pTranslateCxt->pCurrSelectStmt->pPartitionByList) {
|
FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) {
|
||||||
if (nodesEqualNode(pPartKey, pNode)) {
|
if (nodesEqualNode(pPartKey, pNode)) {
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
|
@ -1627,7 +1753,8 @@ static uint8_t getStmtPrecision(SNode* pStmt) {
|
||||||
|
|
||||||
static bool stmtIsSingleTable(SNode* pStmt) {
|
static bool stmtIsSingleTable(SNode* pStmt) {
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
return ((STableNode*)((SSelectStmt*)pStmt)->pFromTable)->singleTable;
|
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
||||||
|
return NULL == pSelect->pFromTable || ((STableNode*)pSelect->pFromTable)->singleTable;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1655,8 +1782,8 @@ static int32_t setTableIndex(STranslateContext* pCxt, SName* pName, SRealTableNo
|
||||||
if (pCxt->createStream || QUERY_SMA_OPTIMIZE_DISABLE == tsQuerySmaOptimize) {
|
if (pCxt->createStream || QUERY_SMA_OPTIMIZE_DISABLE == tsQuerySmaOptimize) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (NULL != pCxt->pCurrSelectStmt && NULL != pCxt->pCurrSelectStmt->pWindow &&
|
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pWindow &&
|
||||||
QUERY_NODE_INTERVAL_WINDOW == nodeType(pCxt->pCurrSelectStmt->pWindow)) {
|
QUERY_NODE_INTERVAL_WINDOW == nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pWindow)) {
|
||||||
return getTableIndex(pCxt, pName, &pRealTable->pSmaIndexes);
|
return getTableIndex(pCxt, pName, &pRealTable->pSmaIndexes);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -2369,7 +2496,7 @@ static EDealRes rewriteSeletcValueFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
nodesDestroyNode(*pNode);
|
nodesDestroyNode(*pNode);
|
||||||
*pNode = (SNode*)pFirst;
|
*pNode = (SNode*)pFirst;
|
||||||
pCxt->errCode = fmGetFuncInfo(pFirst, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
pCxt->errCode = fmGetFuncInfo(pFirst, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
||||||
pCxt->pCurrSelectStmt->hasAggFuncs = true;
|
((SSelectStmt*)pCxt->pCurrStmt)->hasAggFuncs = true;
|
||||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR;
|
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2408,13 +2535,13 @@ static int32_t replaceOrderByAlias(STranslateContext* pCxt, SNodeList* pProjecti
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateSelectWithoutFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t translateSelectWithoutFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
pCxt->pCurrSelectStmt = pSelect;
|
pCxt->pCurrStmt = (SNode*)pSelect;
|
||||||
pCxt->currClause = SQL_CLAUSE_SELECT;
|
pCxt->currClause = SQL_CLAUSE_SELECT;
|
||||||
return translateExprList(pCxt, pSelect->pProjectionList);
|
return translateExprList(pCxt, pSelect->pProjectionList);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
pCxt->pCurrSelectStmt = pSelect;
|
pCxt->pCurrStmt = (SNode*)pSelect;
|
||||||
int32_t code = translateFrom(pCxt, pSelect->pFromTable);
|
int32_t code = translateFrom(pCxt, pSelect->pFromTable);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
pSelect->precision = ((STableNode*)pSelect->pFromTable)->precision;
|
pSelect->precision = ((STableNode*)pSelect->pFromTable)->precision;
|
||||||
|
@ -2538,8 +2665,7 @@ static int32_t translateSetOperOrderBy(STranslateContext* pCxt, SSetOperator* pS
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
if (other) {
|
if (other) {
|
||||||
pCxt->currClause = SQL_CLAUSE_ORDER_BY;
|
pCxt->currClause = SQL_CLAUSE_ORDER_BY;
|
||||||
pCxt->pCurrSelectStmt = NULL;
|
pCxt->pCurrStmt = (SNode*)pSetOperator;
|
||||||
pCxt->pCurrSetOperator = pSetOperator;
|
|
||||||
code = translateExprList(pCxt, pSetOperator->pOrderByList);
|
code = translateExprList(pCxt, pSetOperator->pOrderByList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4419,12 +4545,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
|
|
||||||
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
|
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
++(pCxt->currLevel);
|
++(pCxt->currLevel);
|
||||||
ESqlClause currClause = pCxt->currClause;
|
ESqlClause currClause = pCxt->currClause;
|
||||||
SSelectStmt* pCurrStmt = pCxt->pCurrSelectStmt;
|
SNode* pCurrStmt = pCxt->pCurrStmt;
|
||||||
int32_t code = translateQuery(pCxt, pNode);
|
int32_t code = translateQuery(pCxt, pNode);
|
||||||
--(pCxt->currLevel);
|
--(pCxt->currLevel);
|
||||||
pCxt->currClause = currClause;
|
pCxt->currClause = currClause;
|
||||||
pCxt->pCurrSelectStmt = pCurrStmt;
|
pCxt->pCurrStmt = pCurrStmt;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5876,6 +6002,11 @@ static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
switch (nodeType(pQuery->pRoot)) {
|
switch (nodeType(pQuery->pRoot)) {
|
||||||
case QUERY_NODE_SELECT_STMT:
|
case QUERY_NODE_SELECT_STMT:
|
||||||
|
if (NULL == ((SSelectStmt*)pQuery->pRoot)->pFromTable) {
|
||||||
|
pQuery->execMode = QUERY_EXEC_MODE_LOCAL;
|
||||||
|
pQuery->haveResultSet = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case QUERY_NODE_SET_OPERATOR:
|
case QUERY_NODE_SET_OPERATOR:
|
||||||
case QUERY_NODE_EXPLAIN_STMT:
|
case QUERY_NODE_EXPLAIN_STMT:
|
||||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -423,6 +423,18 @@ TEST_F(ParserSelectTest, withoutFrom) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("SELECT 1");
|
run("SELECT 1");
|
||||||
|
|
||||||
|
run("SELECT DATABASE()");
|
||||||
|
|
||||||
|
run("SELECT CLIENT_VERSION()");
|
||||||
|
|
||||||
|
run("SELECT SERVER_VERSION()");
|
||||||
|
|
||||||
|
run("SELECT SERVER_STATUS()");
|
||||||
|
|
||||||
|
run("SELECT CURRENT_USER()");
|
||||||
|
|
||||||
|
run("SELECT USER()");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ParserTest
|
} // namespace ParserTest
|
||||||
|
|
|
@ -203,6 +203,7 @@ class ParserTestBaseImpl {
|
||||||
pCxt->pMsg = stmtEnv_.msgBuf_.data();
|
pCxt->pMsg = stmtEnv_.msgBuf_.data();
|
||||||
pCxt->msgLen = stmtEnv_.msgBuf_.max_size();
|
pCxt->msgLen = stmtEnv_.msgBuf_.max_size();
|
||||||
pCxt->async = async;
|
pCxt->async = async;
|
||||||
|
pCxt->svrVer = "3.0.0.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
void doParse(SParseContext* pCxt, SQuery** pQuery) {
|
void doParse(SParseContext* pCxt, SQuery** pQuery) {
|
||||||
|
|
|
@ -276,7 +276,8 @@ static int32_t pushDownCondOptAppendCond(SNode** pCond, SNode** pAdditionalCond)
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCond)) {
|
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCond) &&
|
||||||
|
LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pCond)->condType) {
|
||||||
code = nodesListAppend(((SLogicConditionNode*)*pCond)->pParameterList, *pAdditionalCond);
|
code = nodesListAppend(((SLogicConditionNode*)*pCond)->pParameterList, *pAdditionalCond);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pAdditionalCond = NULL;
|
*pAdditionalCond = NULL;
|
||||||
|
@ -1083,6 +1084,11 @@ static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo refact: just to mask compilation warnings
|
||||||
|
static void partTagsSetAlias(char* pAlias, int32_t len, const char* pTableAlias, const char* pColName) {
|
||||||
|
snprintf(pAlias, len, "%s.%s", pTableAlias, pColName);
|
||||||
|
}
|
||||||
|
|
||||||
static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
|
static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
if (NULL == pFunc) {
|
if (NULL == pFunc) {
|
||||||
|
@ -1092,7 +1098,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
|
||||||
strcpy(pFunc->functionName, pFuncName);
|
strcpy(pFunc->functionName, pFuncName);
|
||||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||||
sprintf(pFunc->node.aliasName, "%s.%s", pCol->tableAlias, pCol->colName);
|
partTagsSetAlias(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), pCol->tableAlias, pCol->colName);
|
||||||
} else {
|
} else {
|
||||||
strcpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName);
|
strcpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName);
|
||||||
}
|
}
|
||||||
|
@ -1464,9 +1470,9 @@ static SNode* rewriteUniqueOptCreateFirstFunc(SFunctionNode* pSelectValue, SNode
|
||||||
|
|
||||||
strcpy(pFunc->functionName, "first");
|
strcpy(pFunc->functionName, "first");
|
||||||
if (NULL != pSelectValue) {
|
if (NULL != pSelectValue) {
|
||||||
sprintf(pFunc->node.aliasName, "%s", pSelectValue->node.aliasName);
|
strcpy(pFunc->node.aliasName, pSelectValue->node.aliasName);
|
||||||
} else {
|
} else {
|
||||||
sprintf(pFunc->node.aliasName, "%s.%p", pFunc->functionName, pFunc);
|
snprintf(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), "%s.%p", pFunc->functionName, pFunc);
|
||||||
}
|
}
|
||||||
int32_t code = nodesListMakeStrictAppend(&pFunc->pParameterList, nodesCloneNode(pCol));
|
int32_t code = nodesListMakeStrictAppend(&pFunc->pParameterList, nodesCloneNode(pCol));
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
|
|
@ -85,11 +85,23 @@ int32_t qSetSubplanExecutionNode(SSubplan* subplan, int32_t groupId, SDownstream
|
||||||
return setSubplanExecutionNode(subplan->pNode, groupId, pSource);
|
return setSubplanExecutionNode(subplan->pNode, groupId, pSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qClearSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId) {
|
static void clearSubplanExecutionNode(SPhysiNode* pNode) {
|
||||||
// todo
|
if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == nodeType(pNode)) {
|
||||||
return TSDB_CODE_FAILED;
|
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pNode;
|
||||||
|
NODES_DESTORY_LIST(pExchange->pSrcEndPoints);
|
||||||
|
} else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == nodeType(pNode)) {
|
||||||
|
SMergePhysiNode* pMerge = (SMergePhysiNode*)pNode;
|
||||||
|
pMerge->numOfChannels = LIST_LENGTH(pMerge->node.pChildren);
|
||||||
|
SNode* pChild = NULL;
|
||||||
|
FOREACH(pChild, pMerge->node.pChildren) { NODES_DESTORY_LIST(((SExchangePhysiNode*)pChild)->pSrcEndPoints); }
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* pChild = NULL;
|
||||||
|
FOREACH(pChild, pNode->pChildren) { clearSubplanExecutionNode((SPhysiNode*)pChild); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void qClearSubplanExecutionNode(SSubplan* pSubplan) { clearSubplanExecutionNode(pSubplan->pNode); }
|
||||||
|
|
||||||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) {
|
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) {
|
||||||
if (SUBPLAN_TYPE_MODIFY == pSubplan->subplanType && NULL == pSubplan->pNode) {
|
if (SUBPLAN_TYPE_MODIFY == pSubplan->subplanType && NULL == pSubplan->pNode) {
|
||||||
SDataInserterNode* insert = (SDataInserterNode*)pSubplan->pDataSink;
|
SDataInserterNode* insert = (SDataInserterNode*)pSubplan->pDataSink;
|
||||||
|
|
|
@ -310,6 +310,7 @@ class PlannerTestBaseImpl {
|
||||||
cxt.sqlLen = stmtEnv_.sql_.length();
|
cxt.sqlLen = stmtEnv_.sql_.length();
|
||||||
cxt.pMsg = stmtEnv_.msgBuf_.data();
|
cxt.pMsg = stmtEnv_.msgBuf_.data();
|
||||||
cxt.msgLen = stmtEnv_.msgBuf_.max_size();
|
cxt.msgLen = stmtEnv_.msgBuf_.max_size();
|
||||||
|
cxt.svrVer = "3.0.0.0";
|
||||||
|
|
||||||
DO_WITH_THROW(qParseSql, &cxt, pQuery);
|
DO_WITH_THROW(qParseSql, &cxt, pQuery);
|
||||||
if (prepare) {
|
if (prepare) {
|
||||||
|
|
Loading…
Reference in New Issue