• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3660

15 Mar 2025 09:06AM UTC coverage: 62.039% (-1.3%) from 63.314%
#3660

push

travis-ci

web-flow
feat(stream): support stream processing for virtual tables (#30144)

* enh: add client processing

* enh: add mnode vtables processing

* enh: add mnode vtable processing

* enh: add normal child vtable support

* fix: compile issues

* fix: compile issues

* fix: create stream issues

* fix: multi stream scan issue

* fix: remove debug info

* fix: agg task and task level issues

* fix: correct task output type

* fix: split vtablescan from agg

* fix: memory leak issues

* fix: add limitations

* Update 09-error-code.md

* Update 09-error-code.md

* fix: remove usless case

* feat(stream): extract original table data in source scan task

Implemented functionality in the source task to extract data
corresponding to the virtual table from the original table using WAL.
The extracted data is then sent to the downstream merge task for further
processing.

* feat(stream): multi-way merge using loser tree in virtual merge task

Implemented multi-way merge in the merge task using a loser tree to
combine data from multiple original table into a single virtual table.
The merged virtual table data is then pushed downstream for further
processing.  Introduced memory limit handling during the merge process
with configurable behavior when the memory limit is reached.

* fix(test): remove useless cases

---------

Co-authored-by: dapan1121 <wpan@taosdata.com>
Co-authored-by: Pan Wei <72057773+dapan1121@users.noreply.github.com>

154078 of 317582 branches covered (48.52%)

Branch coverage included in aggregate %.

313 of 2391 new or added lines in 34 files covered. (13.09%)

26134 existing lines in 205 files now uncovered.

240261 of 318051 relevant lines covered (75.54%)

16655189.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.93
/source/libs/parser/src/parAuthenticator.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "catalog.h"
17
#include "cmdnodes.h"
18
#include "parInt.h"
19

20
typedef struct SAuthCxt {
21
  SParseContext*   pParseCxt;
22
  SParseMetaCache* pMetaCache;
23
  int32_t          errCode;
24
} SAuthCxt;
25

26
typedef struct SSelectAuthCxt {
27
  SAuthCxt*    pAuthCxt;
28
  SSelectStmt* pSelect;
29
} SSelectAuthCxt;
30

31
typedef struct SAuthRewriteCxt {
32
  STableNode* pTarget;
33
} SAuthRewriteCxt;
34

35
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt);
36

37
static int32_t setUserAuthInfo(SParseContext* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
2,791✔
38
                               bool isView, bool effective, SUserAuthInfo* pAuth) {
39
  if (effective) {
2,791✔
40
    snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pEffectiveUser ? pCxt->pEffectiveUser : "");
68!
41
  } else {
42
    snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pUser);
2,723✔
43
  }
44

45
  if (NULL == pTabName) {
2,791✔
46
    int32_t code = tNameSetDbName(&pAuth->tbName, pCxt->acctId, pDbName, strlen(pDbName));
249✔
47
    if (TSDB_CODE_SUCCESS != code) return code;
249!
48
  } else {
49
    toName(pCxt->acctId, pDbName, pTabName, &pAuth->tbName);
2,542✔
50
  }
51
  pAuth->type = type;
2,791✔
52
  pAuth->isView = isView;
2,791✔
53
  return TSDB_CODE_SUCCESS;
2,791✔
54
}
55

56
static int32_t checkAuthImpl(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond,
1,087,209✔
57
                             bool isView, bool effective) {
58
  SParseContext* pParseCxt = pCxt->pParseCxt;
1,087,209✔
59
  if (pParseCxt->isSuperUser) {
1,087,209✔
60
    return TSDB_CODE_SUCCESS;
1,084,427✔
61
  }
62

63
  AUTH_RES_TYPE auth_res_type = isView ? AUTH_RES_VIEW : AUTH_RES_BASIC;
2,782✔
64
  SUserAuthInfo authInfo = {0};
2,782✔
65
  int32_t       code = setUserAuthInfo(pCxt->pParseCxt, pDbName, pTabName, type, isView, effective, &authInfo);
2,782✔
66
  if (TSDB_CODE_SUCCESS != code) return code;
2,791!
67
  SUserAuthRes authRes = {0};
2,791✔
68
  if (NULL != pCxt->pMetaCache) {
2,791✔
69
    code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
2,028✔
70
#ifdef TD_ENTERPRISE
71
    if (isView && TSDB_CODE_PAR_INTERNAL_ERROR == code) {
2,028✔
72
      authInfo.isView = false;
100✔
73
      code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
100✔
74
    }
75
#endif
76
  } else {
77
    SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter,
763✔
78
                             .requestId = pParseCxt->requestId,
763✔
79
                             .requestObjRefId = pParseCxt->requestRid,
763✔
80
                             .mgmtEps = pParseCxt->mgmtEpSet};
81
    code = catalogChkAuth(pParseCxt->pCatalog, &conn, &authInfo, &authRes);
763✔
82
  }
83
  if (TSDB_CODE_SUCCESS == code && NULL != pCond) {
2,791!
84
    *pCond = authRes.pCond[auth_res_type];
1,600✔
85
  }
86
  return TSDB_CODE_SUCCESS == code ? (authRes.pass[auth_res_type] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
2,791✔
87
                                   : code;
2,791!
88
}
89

90
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
1,086,488✔
91
  return checkAuthImpl(pCxt, pDbName, pTabName, type, pCond, false, false);
1,086,488✔
92
}
93

94
static int32_t checkEffectiveAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
44✔
95
                                  SNode** pCond) {
96
  return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, false, true);
44✔
97
}
98

99
static int32_t checkViewAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
667✔
100
  return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, true, false);
667✔
101
}
102

103
static int32_t checkViewEffectiveAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
24✔
104
                                      SNode** pCond) {
105
  return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, true, true);
24✔
106
}
107

108
static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
208,006✔
109
  return TSDB_CODE_SUCCESS == authQuery(pCxt, pStmt) ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
208,006!
110
}
111

112
static int32_t mergeStableTagCond(SNode** pWhere, SNode* pTagCond) {
×
113
  SLogicConditionNode* pLogicCond = NULL;
×
114
  int32_t              code = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&pLogicCond);
×
115
  if (NULL == pLogicCond) {
×
116
    return code;
×
117
  }
118
  pLogicCond->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
119
  pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
×
120
  pLogicCond->condType = LOGIC_COND_TYPE_AND;
×
121
  code = nodesListMakeStrictAppend(&pLogicCond->pParameterList, pTagCond);
×
122
  if (TSDB_CODE_SUCCESS == code) {
×
123
    code = nodesListMakeAppend(&pLogicCond->pParameterList, *pWhere);
×
124
  }
125
  if (TSDB_CODE_SUCCESS == code) {
×
126
    *pWhere = (SNode*)pLogicCond;
×
127
  } else {
128
    nodesDestroyNode((SNode*)pLogicCond);
×
129
  }
130
  return code;
×
131
}
132

133
EDealRes rewriteAuthTable(SNode* pNode, void* pContext) {
63✔
134
  if (QUERY_NODE_COLUMN == nodeType(pNode)) {
63✔
135
    SColumnNode*     pCol = (SColumnNode*)pNode;
21✔
136
    SAuthRewriteCxt* pCxt = (SAuthRewriteCxt*)pContext;
21✔
137
    tstrncpy(pCol->tableName, pCxt->pTarget->tableName, TSDB_TABLE_NAME_LEN);
21✔
138
    tstrncpy(pCol->tableAlias, pCxt->pTarget->tableAlias, TSDB_TABLE_NAME_LEN);
21✔
139
  }
140

141
  return DEAL_RES_CONTINUE;
63✔
142
}
143

144
static int32_t rewriteAppendStableTagCond(SNode** pWhere, SNode* pTagCond, STableNode* pTable) {
21✔
145
  SNode*  pTagCondCopy = NULL;
21✔
146
  int32_t code = nodesCloneNode(pTagCond, &pTagCondCopy);
21✔
147
  if (NULL == pTagCondCopy) {
21!
148
    return code;
×
149
  }
150

151
  SAuthRewriteCxt cxt = {.pTarget = pTable};
21✔
152
  nodesWalkExpr(pTagCondCopy, rewriteAuthTable, &cxt);
21✔
153

154
  if (NULL == *pWhere) {
21!
155
    *pWhere = pTagCondCopy;
21✔
156
    return TSDB_CODE_SUCCESS;
21✔
157
  }
158

159
  if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pWhere) &&
×
160
      LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pWhere)->condType) {
×
161
    return nodesListStrictAppend(((SLogicConditionNode*)*pWhere)->pParameterList, pTagCondCopy);
×
162
  }
163

164
  return mergeStableTagCond(pWhere, pTagCondCopy);
×
165
}
166

167
static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
12,108,554✔
168
  SSelectAuthCxt* pCxt = pContext;
12,108,554✔
169
  SAuthCxt*       pAuthCxt = pCxt->pAuthCxt;
12,108,554✔
170
  bool            isView = false;
12,108,554✔
171
  if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
12,108,554✔
172
    SNode*      pTagCond = NULL;
905,504✔
173
    STableNode* pTable = (STableNode*)pNode;
905,504✔
174
#ifdef TD_ENTERPRISE
175
    SName name = {0};
905,504✔
176
    toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name);
905,504✔
177
    STableMeta* pTableMeta = NULL;
905,511✔
178
    toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name);
905,511✔
179
    int32_t code = getTargetMetaImpl(
905,514✔
180
        pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, &name, &pTableMeta, true);
181
    if (TSDB_CODE_SUCCESS == code && TSDB_VIEW_TABLE == pTableMeta->tableType) {
905,493✔
182
      isView = true;
479✔
183
    }
184
    taosMemoryFree(pTableMeta);
905,493!
185
#endif
186
    if (!isView) {
905,506✔
187
      pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
905,027✔
188
      if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
905,029✔
189
        pAuthCxt->errCode = checkEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
44✔
190
      }
191
      if (TSDB_CODE_SUCCESS == pAuthCxt->errCode && NULL != pTagCond) {
905,029✔
192
        pAuthCxt->errCode = rewriteAppendStableTagCond(&pCxt->pSelect->pWhere, pTagCond, pTable);
21✔
193
      }
194
    } else {
195
      pAuthCxt->errCode = checkViewAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
479✔
196
      if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
479✔
197
        pAuthCxt->errCode = checkViewEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
24✔
198
      }
199
    }
200
    return TSDB_CODE_SUCCESS == pAuthCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
905,508✔
201
  } else if (QUERY_NODE_TEMP_TABLE == nodeType(pNode)) {
11,203,050✔
202
    return authSubquery(pAuthCxt, ((STempTableNode*)pNode)->pSubquery);
208,006✔
203
  }
204
  return DEAL_RES_CONTINUE;
10,995,044✔
205
}
206

207
static int32_t authSelect(SAuthCxt* pCxt, SSelectStmt* pSelect) {
1,112,010✔
208
  SSelectAuthCxt cxt = {.pAuthCxt = pCxt, .pSelect = pSelect};
1,112,010✔
209
  nodesWalkSelectStmt(pSelect, SQL_CLAUSE_FROM, authSelectImpl, &cxt);
1,112,010✔
210
  return pCxt->errCode;
1,112,017✔
211
}
212

213
static int32_t authSetOperator(SAuthCxt* pCxt, SSetOperator* pSetOper) {
65,980✔
214
  int32_t code = authQuery(pCxt, pSetOper->pLeft);
65,980✔
215
  if (TSDB_CODE_SUCCESS == code) {
65,980!
216
    code = authQuery(pCxt, pSetOper->pRight);
65,980✔
217
  }
218
  return code;
65,980✔
219
}
220

221
static int32_t authDropUser(SAuthCxt* pCxt, SDropUserStmt* pStmt) {
169✔
222
  if (!pCxt->pParseCxt->isSuperUser || 0 == strcmp(pStmt->userName, TSDB_DEFAULT_USER)) {
169!
223
    return TSDB_CODE_PAR_PERMISSION_DENIED;
1✔
224
  }
225
  return TSDB_CODE_SUCCESS;
168✔
226
}
227

228
static int32_t authDelete(SAuthCxt* pCxt, SDeleteStmt* pDelete) {
64,544✔
229
  SNode*      pTagCond = NULL;
64,544✔
230
  STableNode* pTable = (STableNode*)pDelete->pFromTable;
64,544✔
231
  int32_t     code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
64,544✔
232
  if (TSDB_CODE_SUCCESS == code && NULL != pTagCond) {
64,542!
233
    code = rewriteAppendStableTagCond(&pDelete->pWhere, pTagCond, pTable);
×
234
  }
235
  return code;
64,542✔
236
}
237

238
static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
124✔
239
  SNode*      pTagCond = NULL;
124✔
240
  STableNode* pTable = (STableNode*)pInsert->pTable;
124✔
241
  // todo check tag condition for subtable
242
  int32_t code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
124✔
243
  if (TSDB_CODE_SUCCESS == code) {
124!
244
    code = authQuery(pCxt, pInsert->pQuery);
124✔
245
  }
246
  return code;
124✔
247
}
248

249
static int32_t authShowTables(SAuthCxt* pCxt, SShowStmt* pStmt) {
1,668✔
250
  return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, NULL, AUTH_TYPE_READ_OR_WRITE, NULL);
1,668✔
251
}
252

253
static int32_t authShowVtables(SAuthCxt* pCxt, SShowStmt* pStmt) {
87✔
254
  return authShowTables(pCxt, pStmt);
87✔
255
}
256

UNCOV
257
static int32_t authShowUsage(SAuthCxt* pCxt, SShowStmt* pStmt) {
×
UNCOV
258
  return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, NULL, AUTH_TYPE_READ_OR_WRITE, NULL);
×
259
}
260

261
static int32_t authShowCreateTable(SAuthCxt* pCxt, SShowCreateTableStmt* pStmt) {
208✔
262
  SNode* pTagCond = NULL;
208✔
263
  // todo check tag condition for subtable
264
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ, &pTagCond);
208✔
265
}
266

UNCOV
267
static int32_t authShowCreateView(SAuthCxt* pCxt, SShowCreateViewStmt* pStmt) {
×
268
#ifndef TD_ENTERPRISE
269
  return TSDB_CODE_OPS_NOT_SUPPORT;
270
#endif
271

UNCOV
272
  return TSDB_CODE_SUCCESS;
×
273
}
274

275
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
19,143✔
276
  SNode* pTagCond = NULL;
19,143✔
277
  // todo check tag condition for subtable
278
  return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, &pTagCond);
19,143✔
279
}
280

281
static int32_t authCreateVTable(SAuthCxt* pCxt, SCreateVTableStmt* pStmt) {
178✔
282
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL));
178✔
283
  SNode  *pCol = NULL;
162✔
284
  FOREACH(pCol, pStmt->pCols) {
1,892!
285
    SColumnDefNode *pColDef = (SColumnDefNode*)pCol;
1,742✔
286
    if (NULL == pColDef) {
1,742!
UNCOV
287
      PAR_ERR_RET(TSDB_CODE_PAR_INVALID_COLUMN);
×
288
    }
289
    SColumnOptions *pOptions = (SColumnOptions*)pColDef->pOptions;
1,742✔
290
    if (pOptions && pOptions->hasRef) {
1,742!
291
      PAR_ERR_RET(checkAuth(pCxt, pOptions->refDb, pOptions->refTable, AUTH_TYPE_READ, NULL));
945✔
292
    }
293
  }
294
  return TSDB_CODE_SUCCESS;
150✔
295
}
296

297
static int32_t authCreateVSubTable(SAuthCxt* pCxt, SCreateVSubTableStmt* pStmt) {
154✔
298
  int32_t   code = TSDB_CODE_SUCCESS;
154✔
299
  SNode     *pNode = NULL;
154✔
300
  SNodeList* pTmpList = pStmt->pSpecificColRefs ? pStmt->pSpecificColRefs : pStmt->pColRefs;
154✔
301
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL));
154✔
302
  if (NULL == pTmpList) {
138✔
303
    // no column reference
304
    return TSDB_CODE_SUCCESS;
1✔
305
  }
306

307
  FOREACH(pNode, pTmpList) {
831!
308
    SColumnRefNode *pColRef = (SColumnRefNode*)pNode;
706✔
309
    if (NULL == pColRef) {
706!
UNCOV
310
      PAR_ERR_RET(TSDB_CODE_PAR_INVALID_COLUMN);
×
311
    }
312
    PAR_ERR_RET(checkAuth(pCxt, pColRef->refDbName, pColRef->refTableName, AUTH_TYPE_READ, NULL));
706✔
313
  }
314
  return code;
125✔
315
}
316

317
static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
49,352✔
318
  int32_t code = TSDB_CODE_SUCCESS;
49,352✔
319
  SNode*  pNode = NULL;
49,352✔
320
  FOREACH(pNode, pStmt->pSubTables) {
132,949!
321
    if (pNode->type == QUERY_NODE_CREATE_SUBTABLE_CLAUSE) {
83,602!
322
      SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
83,602✔
323
      code = checkAuth(pCxt, pClause->dbName, NULL, AUTH_TYPE_WRITE, NULL);
83,602✔
324
      if (TSDB_CODE_SUCCESS != code) {
83,598✔
325
        break;
1✔
326
      }
327
    } else {
UNCOV
328
      SCreateSubTableFromFileClause* pClause = (SCreateSubTableFromFileClause*)pNode;
×
UNCOV
329
      code = checkAuth(pCxt, pClause->useDbName, NULL, AUTH_TYPE_WRITE, NULL);
×
UNCOV
330
      if (TSDB_CODE_SUCCESS != code) {
×
UNCOV
331
        break;
×
332
      }
333
    }
334
  }
335
  return code;
49,348✔
336
}
337

338
static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) {
3,218✔
339
  int32_t code = TSDB_CODE_SUCCESS;
3,218✔
340
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
3,218✔
341
    return TSDB_CODE_PAR_PERMISSION_DENIED;
2✔
342
  }
343
  SNode* pNode = NULL;
3,216✔
344
  FOREACH(pNode, pStmt->pTables) {
7,348!
345
    SDropTableClause* pClause = (SDropTableClause*)pNode;
4,132✔
346
    code = checkAuth(pCxt, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, NULL);
4,132✔
347
    if (TSDB_CODE_SUCCESS != code) {
4,132!
UNCOV
348
      break;
×
349
    }
350
  }
351
  return code;
3,216✔
352
}
353

354
static int32_t authDropStable(SAuthCxt* pCxt, SDropSuperTableStmt* pStmt) {
324✔
355
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
324✔
356
    return TSDB_CODE_PAR_PERMISSION_DENIED;
1✔
357
  }
358
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
323✔
359
}
360

361
static int32_t authDropVtable(SAuthCxt* pCxt, SDropVirtualTableStmt* pStmt) {
54✔
362
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
54!
UNCOV
363
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
364
  }
365
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
54✔
366
}
367

368
static int32_t authAlterTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
4,843✔
369
  SNode* pTagCond = NULL;
4,843✔
370
  // todo check tag condition for subtable
371
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
4,843✔
372
}
373

374
static int32_t authAlterVTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
424✔
375
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL));
424✔
376
  if (pStmt->alterType == TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF ||
360✔
377
      pStmt->alterType == TSDB_ALTER_TABLE_ALTER_COLUMN_REF) {
315✔
378
    PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, pStmt->refTableName, AUTH_TYPE_READ, NULL));
142✔
379
  }
380
  PAR_RET(TSDB_CODE_SUCCESS);
334!
381
}
382

383
static int32_t authCreateView(SAuthCxt* pCxt, SCreateViewStmt* pStmt) {
274✔
384
#ifndef TD_ENTERPRISE
385
  return TSDB_CODE_OPS_NOT_SUPPORT;
386
#endif
387
  return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL);
274✔
388
}
389

390
static int32_t authDropView(SAuthCxt* pCxt, SDropViewStmt* pStmt) {
188✔
391
#ifndef TD_ENTERPRISE
392
  return TSDB_CODE_OPS_NOT_SUPPORT;
393
#endif
394
  return checkViewAuth(pCxt, pStmt->dbName, pStmt->viewName, AUTH_TYPE_ALTER, NULL);
188✔
395
}
396

397
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
1,496,258✔
398
  switch (nodeType(pStmt)) {
1,496,258✔
399
    case QUERY_NODE_SET_OPERATOR:
65,980✔
400
      return authSetOperator(pCxt, (SSetOperator*)pStmt);
65,980✔
401
    case QUERY_NODE_SELECT_STMT:
1,112,016✔
402
      return authSelect(pCxt, (SSelectStmt*)pStmt);
1,112,016✔
403
    case QUERY_NODE_DROP_USER_STMT:
169✔
404
      return authDropUser(pCxt, (SDropUserStmt*)pStmt);
169✔
405
    case QUERY_NODE_DELETE_STMT:
64,545✔
406
      return authDelete(pCxt, (SDeleteStmt*)pStmt);
64,545✔
407
    case QUERY_NODE_INSERT_STMT:
124✔
408
      return authInsert(pCxt, (SInsertStmt*)pStmt);
124✔
409
    case QUERY_NODE_CREATE_TABLE_STMT:
19,143✔
410
      return authCreateTable(pCxt, (SCreateTableStmt*)pStmt);
19,143✔
411
    case QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT:
178✔
412
      return authCreateVTable(pCxt, (SCreateVTableStmt*)pStmt);
178✔
413
    case QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT:
154✔
414
      return authCreateVSubTable(pCxt, (SCreateVSubTableStmt*)pStmt);
154✔
415
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
49,352✔
416
      return authCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
49,352✔
417
    case QUERY_NODE_DROP_TABLE_STMT:
3,218✔
418
      return authDropTable(pCxt, (SDropTableStmt*)pStmt);
3,218✔
419
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
324✔
420
      return authDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
324✔
421
    case QUERY_NODE_DROP_VIRTUAL_TABLE_STMT:
54✔
422
      return authDropVtable(pCxt, (SDropVirtualTableStmt*)pStmt);
54✔
423
    case QUERY_NODE_ALTER_TABLE_STMT:
4,843✔
424
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
425
      return authAlterTable(pCxt, (SAlterTableStmt*)pStmt);
4,843✔
426
    case QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT:
424✔
427
      return authAlterVTable(pCxt, (SAlterTableStmt*)pStmt);
424✔
428
    case QUERY_NODE_SHOW_DNODES_STMT:
1,305✔
429
    case QUERY_NODE_SHOW_MNODES_STMT:
430
    case QUERY_NODE_SHOW_MODULES_STMT:
431
    case QUERY_NODE_SHOW_QNODES_STMT:
432
    case QUERY_NODE_SHOW_ANODES_STMT:
433
    case QUERY_NODE_SHOW_ANODES_FULL_STMT:
434
    case QUERY_NODE_SHOW_SNODES_STMT:
435
    case QUERY_NODE_SHOW_BNODES_STMT:
436
    case QUERY_NODE_SHOW_CLUSTER_STMT:
437
    case QUERY_NODE_SHOW_LICENCES_STMT:
438
    case QUERY_NODE_SHOW_VGROUPS_STMT:
439
    case QUERY_NODE_SHOW_DB_ALIVE_STMT:
440
    case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
441
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
442
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
443
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
444
    case QUERY_NODE_SHOW_VNODES_STMT:
445
    case QUERY_NODE_SHOW_SCORES_STMT:
446
    case QUERY_NODE_SHOW_USERS_STMT:
447
    case QUERY_NODE_SHOW_USERS_FULL_STMT:
448
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
449
    case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
450
    case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
451
    case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT:
452
    case QUERY_NODE_SHOW_ARBGROUPS_STMT:
453
    case QUERY_NODE_SHOW_ENCRYPTIONS_STMT:
454
    case QUERY_NODE_SHOW_USAGE_STMT:
455
      return !pCxt->pParseCxt->enableSysInfo ? TSDB_CODE_PAR_PERMISSION_DENIED : TSDB_CODE_SUCCESS;
1,305✔
456
    case QUERY_NODE_SHOW_TABLES_STMT:
1,581✔
457
    case QUERY_NODE_SHOW_STABLES_STMT:
458
      return authShowTables(pCxt, (SShowStmt*)pStmt);
1,581✔
459
    case QUERY_NODE_SHOW_VTABLES_STMT:
87✔
460
      return authShowVtables(pCxt, (SShowStmt*)pStmt);
87✔
461
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
208✔
462
    case QUERY_NODE_SHOW_CREATE_VTABLE_STMT:
463
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
464
      return authShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
208✔
465
      //    case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
466
      //      return authShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
467
    case QUERY_NODE_CREATE_VIEW_STMT:
274✔
468
      return authCreateView(pCxt, (SCreateViewStmt*)pStmt);
274✔
469
    case QUERY_NODE_DROP_VIEW_STMT:
188✔
470
      return authDropView(pCxt, (SDropViewStmt*)pStmt);
188✔
471
    default:
172,091✔
472
      break;
172,091✔
473
  }
474

475
  return TSDB_CODE_SUCCESS;
172,091✔
476
}
477

478
int32_t authenticate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
1,156,156✔
479
  SAuthCxt cxt = {.pParseCxt = pParseCxt, .pMetaCache = pMetaCache, .errCode = TSDB_CODE_SUCCESS};
1,156,156✔
480
  return authQuery(&cxt, pQuery->pRoot);
1,156,156✔
481
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc