fix: add query sql

This commit is contained in:
dapan1121 2023-09-20 19:30:40 +08:00
parent 6b87d97989
commit cc08a5ee87
7 changed files with 3075 additions and 4181 deletions

View File

@ -3905,11 +3905,13 @@ typedef struct {
typedef struct {
char name[TSDB_VIEW_NAME_LEN];
char dbFName[TSDB_DB_FNAME_LEN];
char* querySql;
char* sql;
int8_t orReplace;
int8_t precision;
int32_t numOfCols;
SSchema* pSchema;
SRWLatch lock;
} SCMCreateViewReq;
typedef struct {
@ -3920,14 +3922,16 @@ int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateVie
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
void tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
typedef struct {
char dbFName[TSDB_DB_FNAME_LEN];
char viewName[TSDB_VIEW_NAME_LEN];
char* sql;
int8_t igNotExists;
} SCMDropViewReq;
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
void tFreeSCMDropViewReq(SCMDropViewReq* pReq);
#pragma pack(pop)

View File

@ -216,148 +216,149 @@
#define TK_BUFSIZE 197
#define TK_LANGUAGE 198
#define TK_REPLACE 199
#define TK_STREAM 200
#define TK_INTO 201
#define TK_PAUSE 202
#define TK_RESUME 203
#define TK_TRIGGER 204
#define TK_AT_ONCE 205
#define TK_WINDOW_CLOSE 206
#define TK_IGNORE 207
#define TK_EXPIRED 208
#define TK_FILL_HISTORY 209
#define TK_UPDATE 210
#define TK_SUBTABLE 211
#define TK_UNTREATED 212
#define TK_KILL 213
#define TK_CONNECTION 214
#define TK_TRANSACTION 215
#define TK_BALANCE 216
#define TK_VGROUP 217
#define TK_LEADER 218
#define TK_MERGE 219
#define TK_REDISTRIBUTE 220
#define TK_SPLIT 221
#define TK_DELETE 222
#define TK_INSERT 223
#define TK_NULL 224
#define TK_NK_QUESTION 225
#define TK_NK_ARROW 226
#define TK_ROWTS 227
#define TK_QSTART 228
#define TK_QEND 229
#define TK_QDURATION 230
#define TK_WSTART 231
#define TK_WEND 232
#define TK_WDURATION 233
#define TK_IROWTS 234
#define TK_ISFILLED 235
#define TK_CAST 236
#define TK_NOW 237
#define TK_TODAY 238
#define TK_TIMEZONE 239
#define TK_CLIENT_VERSION 240
#define TK_SERVER_VERSION 241
#define TK_SERVER_STATUS 242
#define TK_CURRENT_USER 243
#define TK_CASE 244
#define TK_WHEN 245
#define TK_THEN 246
#define TK_ELSE 247
#define TK_BETWEEN 248
#define TK_IS 249
#define TK_NK_LT 250
#define TK_NK_GT 251
#define TK_NK_LE 252
#define TK_NK_GE 253
#define TK_NK_NE 254
#define TK_MATCH 255
#define TK_NMATCH 256
#define TK_CONTAINS 257
#define TK_IN 258
#define TK_JOIN 259
#define TK_INNER 260
#define TK_SELECT 261
#define TK_NK_HINT 262
#define TK_DISTINCT 263
#define TK_WHERE 264
#define TK_PARTITION 265
#define TK_BY 266
#define TK_SESSION 267
#define TK_STATE_WINDOW 268
#define TK_EVENT_WINDOW 269
#define TK_SLIDING 270
#define TK_FILL 271
#define TK_VALUE 272
#define TK_VALUE_F 273
#define TK_NONE 274
#define TK_PREV 275
#define TK_NULL_F 276
#define TK_LINEAR 277
#define TK_NEXT 278
#define TK_HAVING 279
#define TK_RANGE 280
#define TK_EVERY 281
#define TK_ORDER 282
#define TK_SLIMIT 283
#define TK_SOFFSET 284
#define TK_LIMIT 285
#define TK_OFFSET 286
#define TK_ASC 287
#define TK_NULLS 288
#define TK_ABORT 289
#define TK_AFTER 290
#define TK_ATTACH 291
#define TK_BEFORE 292
#define TK_BEGIN 293
#define TK_BITAND 294
#define TK_BITNOT 295
#define TK_BITOR 296
#define TK_BLOCKS 297
#define TK_CHANGE 298
#define TK_COMMA 299
#define TK_CONCAT 300
#define TK_CONFLICT 301
#define TK_COPY 302
#define TK_DEFERRED 303
#define TK_DELIMITERS 304
#define TK_DETACH 305
#define TK_DIVIDE 306
#define TK_DOT 307
#define TK_EACH 308
#define TK_FAIL 309
#define TK_FILE 310
#define TK_FOR 311
#define TK_GLOB 312
#define TK_ID 313
#define TK_IMMEDIATE 314
#define TK_IMPORT 315
#define TK_INITIALLY 316
#define TK_INSTEAD 317
#define TK_ISNULL 318
#define TK_KEY 319
#define TK_MODULES 320
#define TK_NK_BITNOT 321
#define TK_NK_SEMI 322
#define TK_NOTNULL 323
#define TK_OF 324
#define TK_PLUS 325
#define TK_PRIVILEGE 326
#define TK_RAISE 327
#define TK_RESTRICT 328
#define TK_ROW 329
#define TK_SEMI 330
#define TK_STAR 331
#define TK_STATEMENT 332
#define TK_STRICT 333
#define TK_STRING 334
#define TK_TIMES 335
#define TK_VALUES 336
#define TK_VARIABLE 337
#define TK_VIEW 338
#define TK_VIEW 200
#define TK_STREAM 201
#define TK_INTO 202
#define TK_PAUSE 203
#define TK_RESUME 204
#define TK_TRIGGER 205
#define TK_AT_ONCE 206
#define TK_WINDOW_CLOSE 207
#define TK_IGNORE 208
#define TK_EXPIRED 209
#define TK_FILL_HISTORY 210
#define TK_UPDATE 211
#define TK_SUBTABLE 212
#define TK_UNTREATED 213
#define TK_KILL 214
#define TK_CONNECTION 215
#define TK_TRANSACTION 216
#define TK_BALANCE 217
#define TK_VGROUP 218
#define TK_LEADER 219
#define TK_MERGE 220
#define TK_REDISTRIBUTE 221
#define TK_SPLIT 222
#define TK_DELETE 223
#define TK_INSERT 224
#define TK_NULL 225
#define TK_NK_QUESTION 226
#define TK_NK_ARROW 227
#define TK_ROWTS 228
#define TK_QSTART 229
#define TK_QEND 230
#define TK_QDURATION 231
#define TK_WSTART 232
#define TK_WEND 233
#define TK_WDURATION 234
#define TK_IROWTS 235
#define TK_ISFILLED 236
#define TK_CAST 237
#define TK_NOW 238
#define TK_TODAY 239
#define TK_TIMEZONE 240
#define TK_CLIENT_VERSION 241
#define TK_SERVER_VERSION 242
#define TK_SERVER_STATUS 243
#define TK_CURRENT_USER 244
#define TK_CASE 245
#define TK_WHEN 246
#define TK_THEN 247
#define TK_ELSE 248
#define TK_BETWEEN 249
#define TK_IS 250
#define TK_NK_LT 251
#define TK_NK_GT 252
#define TK_NK_LE 253
#define TK_NK_GE 254
#define TK_NK_NE 255
#define TK_MATCH 256
#define TK_NMATCH 257
#define TK_CONTAINS 258
#define TK_IN 259
#define TK_JOIN 260
#define TK_INNER 261
#define TK_SELECT 262
#define TK_NK_HINT 263
#define TK_DISTINCT 264
#define TK_WHERE 265
#define TK_PARTITION 266
#define TK_BY 267
#define TK_SESSION 268
#define TK_STATE_WINDOW 269
#define TK_EVENT_WINDOW 270
#define TK_SLIDING 271
#define TK_FILL 272
#define TK_VALUE 273
#define TK_VALUE_F 274
#define TK_NONE 275
#define TK_PREV 276
#define TK_NULL_F 277
#define TK_LINEAR 278
#define TK_NEXT 279
#define TK_HAVING 280
#define TK_RANGE 281
#define TK_EVERY 282
#define TK_ORDER 283
#define TK_SLIMIT 284
#define TK_SOFFSET 285
#define TK_LIMIT 286
#define TK_OFFSET 287
#define TK_ASC 288
#define TK_NULLS 289
#define TK_ABORT 290
#define TK_AFTER 291
#define TK_ATTACH 292
#define TK_BEFORE 293
#define TK_BEGIN 294
#define TK_BITAND 295
#define TK_BITNOT 296
#define TK_BITOR 297
#define TK_BLOCKS 298
#define TK_CHANGE 299
#define TK_COMMA 300
#define TK_CONCAT 301
#define TK_CONFLICT 302
#define TK_COPY 303
#define TK_DEFERRED 304
#define TK_DELIMITERS 305
#define TK_DETACH 306
#define TK_DIVIDE 307
#define TK_DOT 308
#define TK_EACH 309
#define TK_FAIL 310
#define TK_FILE 311
#define TK_FOR 312
#define TK_GLOB 313
#define TK_ID 314
#define TK_IMMEDIATE 315
#define TK_IMPORT 316
#define TK_INITIALLY 317
#define TK_INSTEAD 318
#define TK_ISNULL 319
#define TK_KEY 320
#define TK_MODULES 321
#define TK_NK_BITNOT 322
#define TK_NK_SEMI 323
#define TK_NOTNULL 324
#define TK_OF 325
#define TK_PLUS 326
#define TK_PRIVILEGE 327
#define TK_RAISE 328
#define TK_RESTRICT 329
#define TK_ROW 330
#define TK_SEMI 331
#define TK_STAR 332
#define TK_STATEMENT 333
#define TK_STRICT 334
#define TK_STRING 335
#define TK_TIMES 336
#define TK_VALUES 337
#define TK_VARIABLE 338
#define TK_WAL 339
#define TK_NK_SPACE 600
#define TK_NK_COMMENT 601
#define TK_NK_ILLEGAL 602

View File

@ -8433,6 +8433,7 @@ int32_t tSerializeSCMCreateViewReq(void *buf, int32_t bufLen, const SCMCreateVie
if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
if (tEncodeI8(&encoder, pReq->orReplace) < 0) return -1;
if (tEncodeI8(&encoder, pReq->precision) < 0) return -1;
if (tEncodeI32(&encoder, pReq->numOfCols) < 0) return -1;
@ -8455,12 +8456,13 @@ int32_t tDeserializeSCMCreateViewReq(void *buf, int32_t bufLen, SCMCreateViewReq
if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1;
if (tDecodeCStrAlloc(&decoder, &pReq->sql) < 0) return -1;
if (tDecodeI8(&decoder, &pReq->orReplace) < 0) return -1;
if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->numOfCols) < 0) return -1;
if (pReq->numOfCols > 0) {
pReq->pSchema = taosArrayInit(pReq->numOfCols, sizeof(SSchema));
pReq->pSchema = taosMemoryCalloc(pReq->numOfCols, sizeof(SSchema));
if (pReq->pSchema == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@ -8486,4 +8488,9 @@ void tFreeSCMCreateViewReq(SCMCreateViewReq* pReq) {
taosMemoryFree(pReq->pSchema);
}
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
void tFreeSCMDropViewReq(SCMDropViewReq* pReq);

View File

@ -48,14 +48,13 @@ void mndCleanupView(SMnode *pMnode) {
}
static int32_t mndProcessCreateViewReq(SRpcMsg *pReq) {
SCMCreateViewReq createViewReq = {0};
#ifndef TD_ENTERPRISE
return TSDB_CODE_OPS_NOT_SUPPORT;
#else
SCMCreateViewReq createViewReq = {0};
if (tDeserializeSCMCreateViewReq(pReq->pCont, pReq->contLen, &createViewReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
return -1;
}
mInfo("start to create view:%s, sql:%s", createViewReq.name, createViewReq.sql);
@ -68,14 +67,15 @@ static int32_t mndProcessDropViewReq(SRpcMsg *pReq) {
#ifndef TD_ENTERPRISE
return TSDB_CODE_OPS_NOT_SUPPORT;
#else
if (tDeserializeSCMDropViewReq(pReq->pCont, pReq->contLen, &createViewReq) != 0) {
SCMDropViewReq dropViewReq = {0};
if (tDeserializeSCMDropViewReq(pReq->pCont, pReq->contLen, &dropViewReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
return -1;
}
mInfo("start to drop view:%s, sql:%s", createViewReq.name, createViewReq.sql);
mInfo("start to drop view:%s, sql:%s", dropViewReq.viewName, dropViewReq.sql);
return mndProcessDropViewReqImpl(&createViewReq, pReq);
return mndProcessDropViewReqImpl(&dropViewReq, pReq);
#endif
}

View File

@ -623,8 +623,8 @@ or_replace_opt(A) ::= .
or_replace_opt(A) ::= OR REPLACE. { A = true; }
/************************************************ create/drop view **************************************************/
cmd ::= CREATE or_replace_opt(A) VIEW full_view_name(B) col_list_opt(C) AS query_or_subquery(D).
{ pCxt->pRootNode = createCreateViewStmt(pCxt, A, B, C, D); }
cmd ::= CREATE or_replace_opt(A) VIEW full_view_name(B) col_list_opt(C) AS(D) query_or_subquery(E).
{ pCxt->pRootNode = createCreateViewStmt(pCxt, A, B, C, &D, E); }
cmd ::= DROP VIEW exists_opt(A) full_view_name(B). { pCxt->pRootNode = createDropViewStmt(pCxt, A, B); }
full_view_name(A) ::= view_name(B). { A = createViewNode(pCxt, NULL, &B, NULL); }

View File

@ -2162,7 +2162,7 @@ SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, con
return (SNode*)pStmt;
}
SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pView, SNodeList* pCols, SNode* pQuery) {
SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pView, SNodeList* pCols, const SToken* pAs, SNode* pQuery) {
CHECK_PARSER_STATUS(pCxt);
SCreateViewStmt* pStmt = (SCreateViewStmt*)nodesMakeNode(QUERY_NODE_CREATE_VIEW_STMT);
CHECK_OUT_OF_MEM(pStmt);

File diff suppressed because it is too large Load Diff