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

taosdata / TDengine / #4756

25 Sep 2025 05:58AM UTC coverage: 58.829% (+0.2%) from 58.63%
#4756

push

travis-ci

web-flow
enh: taos command line support '-uroot' on windows (#33055)

135574 of 293169 branches covered (46.24%)

Branch coverage included in aggregate %.

204395 of 284720 relevant lines covered (71.79%)

18747092.16 hits per line

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

57.95
/source/libs/function/src/functionMgt.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 "functionMgt.h"
17

18
#include "builtins.h"
19
#include "builtinsimpl.h"
20
#include "functionMgtInt.h"
21
#include "taos.h"
22
#include "taoserror.h"
23
#include "thash.h"
24
#include "tudf.h"
25

26
typedef struct SFuncMgtService {
27
  SHashObj* pFuncNameHashTable;
28
} SFuncMgtService;
29

30
static SFuncMgtService gFunMgtService;
31
static TdThreadOnce    functionHashTableInit = PTHREAD_ONCE_INIT;
32
static int32_t         initFunctionCode = 0;
33

34
static void doInitFunctionTable() {
2,934✔
35
  gFunMgtService.pFuncNameHashTable =
2,934✔
36
      taosHashInit(funcMgtBuiltinsNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
2,934✔
37
  if (NULL == gFunMgtService.pFuncNameHashTable) {
2,934!
38
    initFunctionCode = terrno;
×
39
    return;
×
40
  }
41

42
  for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
557,460✔
43
    if (TSDB_CODE_SUCCESS != taosHashPut(gFunMgtService.pFuncNameHashTable, funcMgtBuiltins[i].name,
554,526!
44
                                         strlen(funcMgtBuiltins[i].name), &i, sizeof(int32_t))) {
554,526✔
45
      initFunctionCode = terrno;
×
46
      return;
×
47
    }
48
  }
49
}
50

51
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
1,038,547,752✔
52
  if (fmIsUserDefinedFunc(funcId)) {
1,038,547,752✔
53
    return FUNC_MGT_AGG_FUNC == classification
54
               ? FUNC_AGGREGATE_UDF_ID == funcId
55
               : (FUNC_MGT_SCALAR_FUNC == classification ? FUNC_SCALAR_UDF_ID == funcId : false);
5,483✔
56
  }
57
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
1,038,309,409!
58
    return false;
134,795,908✔
59
  }
60
  return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
903,513,501✔
61
}
62

63
int32_t fmFuncMgtInit() {
2,934✔
64
  (void)taosThreadOnce(&functionHashTableInit, doInitFunctionTable);
2,934✔
65
  return initFunctionCode;
2,934✔
66
}
67

68
int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen) {
382,449✔
69
  if (NULL != gFunMgtService.pFuncNameHashTable) {
382,449!
70
    void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
382,469✔
71
    if (NULL != pVal) {
382,488✔
72
      pFunc->funcId = *(int32_t*)pVal;
382,436✔
73
      pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
382,436✔
74
      return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
382,436✔
75
    }
76
    return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
52✔
77
  }
78
  for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
×
79
    if (0 == strcmp(funcMgtBuiltins[i].name, pFunc->functionName)) {
×
80
      pFunc->funcId = i;
×
81
      pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
×
82
      return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
×
83
    }
84
  }
85
  return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
×
86
}
87

88
EFuncReturnRows fmGetFuncReturnRows(SFunctionNode* pFunc) {
1,109✔
89
  if (NULL != funcMgtBuiltins[pFunc->funcId].estimateReturnRowsFunc) {
1,109✔
90
    return funcMgtBuiltins[pFunc->funcId].estimateReturnRowsFunc(pFunc);
799✔
91
  }
92
  return (fmIsIndefiniteRowsFunc(pFunc->funcId) || fmIsMultiRowsFunc(pFunc->funcId)) ? FUNC_RETURN_ROWS_INDEFINITE
310!
93
                                                                                     : FUNC_RETURN_ROWS_NORMAL;
310!
94
}
95

96
bool fmIsBuiltinFunc(const char* pFunc) {
24✔
97
  return NULL != taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc, strlen(pFunc));
24✔
98
}
99

100
EFunctionType fmGetFuncType(const char* pFunc) {
147,045✔
101
  void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc, strlen(pFunc));
147,045✔
102
  if (NULL != pVal) {
147,006✔
103
    return funcMgtBuiltins[*(int32_t*)pVal].type;
146,965✔
104
  }
105
  return FUNCTION_TYPE_UDF;
41✔
106
}
107

108
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
110,688✔
109
  if (fmIsUserDefinedFunc(pFunc->funcId) || pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
110,688!
110
    return FUNC_DATA_REQUIRED_DATA_LOAD;
×
111
  }
112
  if (NULL == funcMgtBuiltins[pFunc->funcId].dataRequiredFunc) {
110,736!
113
    return FUNC_DATA_REQUIRED_DATA_LOAD;
×
114
  }
115
  return funcMgtBuiltins[pFunc->funcId].dataRequiredFunc(pFunc, pTimeWindow);
110,736✔
116
}
117

118
EFuncDataRequired fmFuncDynDataRequired(int32_t funcId, void* pRes, SDataBlockInfo* pBlockInfo) {
2,288,718✔
119
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
2,288,718!
120
    return FUNC_DATA_REQUIRED_DATA_LOAD;
3✔
121
  }
122

123
  const char* name = funcMgtBuiltins[funcId].name;
2,288,720✔
124
  if ((strcmp(name, "_group_key") == 0) || (strcmp(name, "_select_value") == 0)) {
2,288,720✔
125
    return FUNC_DATA_REQUIRED_NOT_LOAD;
153,877✔
126
    ;
127
  }
128

129
  if (funcMgtBuiltins[funcId].dynDataRequiredFunc == NULL) {
2,134,843✔
130
    return FUNC_DATA_REQUIRED_DATA_LOAD;
2,114,648✔
131
  } else {
132
    return funcMgtBuiltins[funcId].dynDataRequiredFunc(pRes, pBlockInfo);
20,195✔
133
  }
134
}
135

136
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) {
6,408,190✔
137
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
6,408,190!
138
    return TSDB_CODE_FAILED;
838✔
139
  }
140
  pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc;
6,410,856✔
141
  pFpSet->init = funcMgtBuiltins[funcId].initFunc;
6,410,856✔
142
  pFpSet->process = funcMgtBuiltins[funcId].processFunc;
6,410,856✔
143
  pFpSet->finalize = funcMgtBuiltins[funcId].finalizeFunc;
6,410,856✔
144
  pFpSet->combine = funcMgtBuiltins[funcId].combineFunc;
6,410,856✔
145
  pFpSet->processFuncByRow = funcMgtBuiltins[funcId].processFuncByRow;
6,410,856✔
146
  pFpSet->cleanup = funcMgtBuiltins[funcId].cleanupFunc;
6,410,856✔
147
  return TSDB_CODE_SUCCESS;
6,410,856✔
148
}
149

150
int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) {
85✔
151
#ifdef USE_UDF
152
  if (!fmIsUserDefinedFunc(funcId)) {
85!
153
    return TSDB_CODE_FAILED;
×
154
  }
155
  pFpSet->getEnv = udfAggGetEnv;
85✔
156
  pFpSet->init = udfAggInit;
85✔
157
  pFpSet->process = udfAggProcess;
85✔
158
  pFpSet->finalize = udfAggFinalize;
85✔
159
  return TSDB_CODE_SUCCESS;
85✔
160
#else
161
  TAOS_RETURN(TSDB_CODE_OPS_NOT_SUPPORT);
162
#endif
163
}
164

165
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet) {
11,259,333✔
166
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
11,259,333!
167
    return TSDB_CODE_FAILED;
×
168
  }
169
  pFpSet->process = funcMgtBuiltins[funcId].sprocessFunc;
11,260,946✔
170
  pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc;
11,260,946✔
171
  return TSDB_CODE_SUCCESS;
11,260,946✔
172
}
173

174
bool fmIsAggFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_AGG_FUNC); }
13,224,564✔
175

176
bool fmIsScalarFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); }
1,852,470✔
177

178
bool fmIsVectorFunc(int32_t funcId) { return !fmIsScalarFunc(funcId) && !fmIsPseudoColumnFunc(funcId); }
521,120✔
179

180
bool fmIsSelectColsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_COLS_FUNC); }
44,121✔
181

182
bool fmIsSelectFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_FUNC); }
26,855,895✔
183

184
bool fmIsTimelineFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_TIMELINE_FUNC); }
460,745✔
185

186
bool fmIsDateTimeFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_DATETIME_FUNC); }
310,749✔
187

188
bool fmIsPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PSEUDO_COLUMN_FUNC); }
27,428,900✔
189

190
bool fmIsScanPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCAN_PC_FUNC); }
14,584,521✔
191

192
bool fmIsWindowPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_WINDOW_PC_FUNC); }
10,102,457✔
193

194
bool fmIsWindowClauseFunc(int32_t funcId) { return fmIsAggFunc(funcId) || fmIsWindowPseudoColumnFunc(funcId); }
7,996✔
195

196
bool fmIsStreamWindowClauseFunc(int32_t funcId) { return fmIsWindowClauseFunc(funcId) || fmIsPlaceHolderFunc(funcId); }
448✔
197

198
bool fmIsStreamVectorFunc(int32_t funcId) { return fmIsVectorFunc(funcId) || fmIsPlaceHolderFunc(funcId); }
8!
199

200
bool fmIsIndefiniteRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INDEFINITE_ROWS_FUNC); }
8,518,582✔
201

202
bool fmIsSpecialDataRequiredFunc(int32_t funcId) {
226,273✔
203
  return isSpecificClassifyFunc(funcId, FUNC_MGT_SPECIAL_DATA_REQUIRED);
226,273✔
204
}
205

206
bool fmIsDynamicScanOptimizedFunc(int32_t funcId) {
62,108✔
207
  return isSpecificClassifyFunc(funcId, FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED);
62,108✔
208
}
209

210
bool fmIsMultiResFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_RES_FUNC); }
504,675✔
211

212
bool fmIsRepeatScanFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_REPEAT_SCAN_FUNC); }
2,103,540✔
213

214
bool fmIsUserDefinedFunc(int32_t funcId) { return funcId > FUNC_UDF_ID_START; }
1,074,498,225✔
215

216
bool fmIsForbidFillFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_FILL_FUNC); }
310,845✔
217

218
bool fmIsIntervalInterpoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INTERVAL_INTERPO_FUNC); }
25,159,576✔
219

220
bool fmIsSystemInfoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SYSTEM_INFO_FUNC); }
311,112✔
221

222
bool fmIsImplicitTsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IMPLICIT_TS_FUNC); }
53,431,481✔
223

224
bool fmIsClientPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_CLIENT_PC_FUNC); }
311,053✔
225

226
bool fmIsMultiRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_ROWS_FUNC); }
461,238✔
227

228
bool fmIsKeepOrderFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_KEEP_ORDER_FUNC); }
133,482✔
229

230
bool fmIsCumulativeFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_CUMULATIVE_FUNC); }
44,321✔
231

232
bool fmIsForbidSysTableFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_SYSTABLE_FUNC); }
310,795✔
233

234
bool fmIsInterpFunc(int32_t funcId) {
647,269✔
235
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
647,269!
236
    return false;
71✔
237
  }
238
  return FUNCTION_TYPE_INTERP == funcMgtBuiltins[funcId].type;
647,198✔
239
}
240

241
bool fmIsInterpPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INTERP_PC_FUNC); }
461,510✔
242

243
bool fmIsForecastFunc(int32_t funcId) {
460,228✔
244
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
460,228!
245
    return false;
74✔
246
  }
247
  return FUNCTION_TYPE_FORECAST == funcMgtBuiltins[funcId].type;
460,154✔
248
}
249

250
bool fmIsForecastPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORECAST_PC_FUNC); }
461,377✔
251

252
bool fmIsImputationFunc(int32_t funcId) {
×
253
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
×
254
    return false;
×
255
  }
256

257
  return FUNCTION_TYPE_IMPUTATION == funcMgtBuiltins[funcId].type;
×
258
}
259

260
bool fmIsLastRowFunc(int32_t funcId) {
42,708✔
261
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
42,708!
262
    return false;
×
263
  }
264
  return FUNCTION_TYPE_LAST_ROW == funcMgtBuiltins[funcId].type;
42,712✔
265
}
266

267
bool fmIsLastFunc(int32_t funcId) {
5✔
268
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
5!
269
    return false;
×
270
  }
271
  return FUNCTION_TYPE_LAST == funcMgtBuiltins[funcId].type;
5✔
272
}
273

274
bool fmIsNotNullOutputFunc(int32_t funcId) {
9,600,055✔
275
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
9,600,055!
276
    return false;
×
277
  }
278
  return FUNCTION_TYPE_LAST == funcMgtBuiltins[funcId].type ||
19,002,715✔
279
         FUNCTION_TYPE_LAST_PARTIAL == funcMgtBuiltins[funcId].type ||
9,399,719✔
280
         FUNCTION_TYPE_LAST_MERGE == funcMgtBuiltins[funcId].type ||
8,792,880✔
281
         FUNCTION_TYPE_FIRST == funcMgtBuiltins[funcId].type ||
8,492,571✔
282
         FUNCTION_TYPE_FIRST_PARTIAL == funcMgtBuiltins[funcId].type ||
8,343,821✔
283
         FUNCTION_TYPE_FIRST_MERGE == funcMgtBuiltins[funcId].type ||
8,118,978✔
284
         FUNCTION_TYPE_COUNT == funcMgtBuiltins[funcId].type ||
8,006,049✔
285
         FUNCTION_TYPE_HYPERLOGLOG == funcMgtBuiltins[funcId].type ||
6,217,057✔
286
         FUNCTION_TYPE_HYPERLOGLOG_PARTIAL == funcMgtBuiltins[funcId].type ||
25,187,507✔
287
         FUNCTION_TYPE_HYPERLOGLOG_MERGE == funcMgtBuiltins[funcId].type;
6,184,792✔
288
}
289

290
bool fmIsSelectValueFunc(int32_t funcId) {
763,847✔
291
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
763,847!
292
    return false;
×
293
  }
294
  return FUNCTION_TYPE_SELECT_VALUE == funcMgtBuiltins[funcId].type;
763,847✔
295
}
296

297
bool fmIsGroupKeyFunc(int32_t funcId) {
242,354,127✔
298
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
242,354,127!
299
    return false;
×
300
  }
301
  return FUNCTION_TYPE_GROUP_KEY == funcMgtBuiltins[funcId].type;
242,359,870✔
302
}
303

304
bool fmisSelectGroupConstValueFunc(int32_t funcId) {
10✔
305
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
10!
306
    return false;
×
307
  }
308
  return FUNCTION_TYPE_GROUP_CONST_VALUE == funcMgtBuiltins[funcId].type;
10✔
309
}
310

311
bool fmIsElapsedFunc(int32_t funcId) {
14,846,974✔
312
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
14,846,974!
313
    return false;
×
314
  }
315
  return FUNCTION_TYPE_ELAPSED == funcMgtBuiltins[funcId].type;
14,847,141✔
316
}
317

318
bool fmIsBlockDistFunc(int32_t funcId) {
310,727✔
319
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
310,727!
320
    return false;
38✔
321
  }
322
  return FUNCTION_TYPE_BLOCK_DIST == funcMgtBuiltins[funcId].type;
310,689✔
323
}
324

325
bool fmIsDBUsageFunc(int32_t funcId) {
310,751✔
326
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
310,751!
327
    return false;
11✔
328
  }
329
  return FUNCTION_TYPE_DB_USAGE == funcMgtBuiltins[funcId].type;
310,740✔
330
}
331

332
bool fmIsProcessByRowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PROCESS_BY_ROW); }
1,978,911✔
333

334
bool fmIsIgnoreNullFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IGNORE_NULL_FUNC); }
12✔
335

336
void fmFuncMgtDestroy() {
2,935✔
337
  void* m = gFunMgtService.pFuncNameHashTable;
2,935✔
338
  if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
2,935!
339
    taosHashCleanup(m);
2,934✔
340
  }
341
}
2,935✔
342

343
#ifdef BUILD_NO_CALL
344
int32_t fmSetInvertFunc(int32_t funcId, SFuncExecFuncs* pFpSet) {
345
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
346
    return TSDB_CODE_FAILED;
347
  }
348
  pFpSet->process = funcMgtBuiltins[funcId].invertFunc;
349
  return TSDB_CODE_SUCCESS;
350
}
351

352
int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet) {
353
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
354
    return TSDB_CODE_FAILED;
355
  }
356
  pFpSet->process = funcMgtBuiltins[funcId].processFunc;
357
  return TSDB_CODE_SUCCESS;
358
}
359

360
bool fmIsInvertible(int32_t funcId) {
361
  bool res = false;
362
  switch (funcMgtBuiltins[funcId].type) {
363
    case FUNCTION_TYPE_COUNT:
364
    case FUNCTION_TYPE_SUM:
365
    case FUNCTION_TYPE_STDDEV:
366
    case FUNCTION_TYPE_AVG:
367
    case FUNCTION_TYPE_WSTART:
368
    case FUNCTION_TYPE_WEND:
369
    case FUNCTION_TYPE_WDURATION:
370
      res = true;
371
      break;
372
    default:
373
      break;
374
  }
375
  return res;
376
}
377
#endif
378

379
// function has same input/output type
380
bool fmIsSameInOutType(int32_t funcId) {
14,556✔
381
  bool res = false;
14,556✔
382
  switch (funcMgtBuiltins[funcId].type) {
14,556✔
383
    case FUNCTION_TYPE_MAX:
6,227✔
384
    case FUNCTION_TYPE_MIN:
385
    case FUNCTION_TYPE_TOP:
386
    case FUNCTION_TYPE_BOTTOM:
387
    case FUNCTION_TYPE_FIRST:
388
    case FUNCTION_TYPE_LAST:
389
    case FUNCTION_TYPE_SAMPLE:
390
    case FUNCTION_TYPE_TAIL:
391
    case FUNCTION_TYPE_UNIQUE:
392
      res = true;
6,227✔
393
      break;
6,227✔
394
    default:
8,329✔
395
      break;
8,329✔
396
  }
397
  return res;
14,556✔
398
}
399

400
bool fmIsConstantResFunc(SFunctionNode* pFunc) {
685✔
401
  SNode* pNode;
402
  FOREACH(pNode, pFunc->pParameterList) {
685!
403
    if (nodeType(pNode) != QUERY_NODE_VALUE) {
×
404
      return false;
×
405
    }
406
  }
407
  return true;
685✔
408
}
409

410
bool fmIsSkipScanCheckFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SKIP_SCAN_CHECK_FUNC); }
62,093✔
411

412
bool fmIsPrimaryKeyFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PRIMARY_KEY_FUNC); }
203,995✔
413

414
bool fmIsPlaceHolderFunc(int32_t funcId) {return isSpecificClassifyFunc(funcId, FUNC_MGT_PLACE_HOLDER_FUNC); }
849,434,719✔
415

416
void getLastCacheDataType(SDataType* pType, int32_t pkBytes) {
10,464✔
417
  // TODO: do it later.
418
  pType->bytes = getFirstLastInfoSize(pType->bytes, pkBytes) + VARSTR_HEADER_SIZE;
10,464✔
419
  pType->type = TSDB_DATA_TYPE_BINARY;
10,464✔
420
}
10,464✔
421

422
static int32_t getFuncInfo(SFunctionNode* pFunc) {
45,105✔
423
  char msg[128] = {0};
45,105✔
424
  return fmGetFuncInfo(pFunc, msg, sizeof(msg));
45,105✔
425
}
426

427
int32_t createFunction(const char* pName, SNodeList* pParameterList, SFunctionNode** ppFunc) {
1,434✔
428
  int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc);
1,434✔
429
  if (NULL == *ppFunc) {
1,434!
430
    return code;
×
431
  }
432
  (void)snprintf((*ppFunc)->functionName, sizeof((*ppFunc)->functionName), "%s", pName);
1,434✔
433
  (*ppFunc)->pParameterList = pParameterList;
1,434✔
434
  code = getFuncInfo((*ppFunc));
1,434✔
435
  if (TSDB_CODE_SUCCESS != code) {
1,434!
436
    (*ppFunc)->pParameterList = NULL;
×
437
    nodesDestroyNode((SNode*)*ppFunc);
×
438
    *ppFunc = NULL;
×
439
    return code;
×
440
  }
441
  return code;
1,434✔
442
}
443

444
static void resetOutputChangedFunc(SFunctionNode *pFunc, const SFunctionNode* pSrcFunc) {
43,664✔
445
  if (funcMgtBuiltins[pFunc->funcId].type == FUNCTION_TYPE_LAST_MERGE) {
43,664✔
446
    pFunc->node.resType = pSrcFunc->node.resType;
25,928✔
447
    return;
25,928✔
448
  }
449
}
450

451
int32_t createFunctionWithSrcFunc(const char* pName, const SFunctionNode* pSrcFunc, SNodeList* pParameterList, SFunctionNode** ppFunc) {
43,669✔
452
  int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc);
43,669✔
453
  if (NULL == *ppFunc) {
43,671!
454
    return code;
×
455
  }
456

457
  (*ppFunc)->hasPk = pSrcFunc->hasPk;
43,671✔
458
  (*ppFunc)->pkBytes = pSrcFunc->pkBytes;
43,671✔
459
  (*ppFunc)->pSrcFuncRef = pSrcFunc;
43,671✔
460

461
  (void)snprintf((*ppFunc)->functionName, sizeof((*ppFunc)->functionName), "%s", pName);
43,671✔
462
  (*ppFunc)->pParameterList = pParameterList;
43,671✔
463
  code = getFuncInfo((*ppFunc));
43,671✔
464
  if (TSDB_CODE_SUCCESS != code) {
43,665!
465
    (*ppFunc)->pParameterList = NULL;
×
466
    nodesDestroyNode((SNode*)*ppFunc);
×
467
    *ppFunc = NULL;
×
468
    return code;
×
469
  }
470
  resetOutputChangedFunc(*ppFunc, pSrcFunc);
43,665✔
471
  (*ppFunc)->node.relatedTo = pSrcFunc->node.relatedTo;
43,664✔
472
  (*ppFunc)->node.bindExprID = pSrcFunc->node.bindExprID;
43,664✔
473
  return code;
43,664✔
474
}
475

476
static int32_t createColumnByFunc(const SFunctionNode* pFunc, SColumnNode** ppCol) {
29,112✔
477
  int32_t code = nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)ppCol);
29,112✔
478
  if (NULL == *ppCol) {
29,112!
479
    return code;
×
480
  }
481
  tstrncpy((*ppCol)->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
29,112✔
482
  (*ppCol)->node.resType = pFunc->node.resType;
29,112✔
483
  return TSDB_CODE_SUCCESS;
29,112✔
484
}
485

486
bool fmIsDistExecFunc(int32_t funcId) {
178,865✔
487
  if (fmIsUserDefinedFunc(funcId)) {
178,865!
488
    return false;
×
489
  }
490
  if (!fmIsVectorFunc(funcId)) {
178,916✔
491
    return true;
188✔
492
  }
493
  return (NULL != funcMgtBuiltins[funcId].pPartialFunc && NULL != funcMgtBuiltins[funcId].pMergeFunc);
178,732✔
494
}
495

496
static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNode** pPartialFunc) {
14,553✔
497
  SNodeList* pParameterList = NULL;
14,553✔
498
  int32_t    code = nodesCloneList(pSrcFunc->pParameterList, &pParameterList);
14,553✔
499
  if (NULL == pParameterList) {
14,557!
500
    return code;
×
501
  }
502
  code =
503
      createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pPartialFunc, pSrcFunc, pParameterList, pPartialFunc);
14,557✔
504
  if (TSDB_CODE_SUCCESS != code) {
14,556!
505
    nodesDestroyList(pParameterList);
×
506
    return code;
×
507
  }
508
  (*pPartialFunc)->hasOriginalFunc = true;
14,556✔
509
  (*pPartialFunc)->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId;
14,556!
510
  char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0};
14,556✔
511

512
  int32_t len = tsnprintf(name, sizeof(name), "%s.%p", (*pPartialFunc)->functionName, pSrcFunc);
14,556✔
513
  if (taosHashBinary(name, len) < 0) {
14,557!
514
    return TSDB_CODE_FAILED;
×
515
  }
516
  tstrncpy((*pPartialFunc)->node.aliasName, name, TSDB_COL_NAME_LEN);
14,557✔
517
  return TSDB_CODE_SUCCESS;
14,557✔
518
}
519

520
static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
29,112✔
521
                                   SNodeList** pParameterList) {
522
  SNode*  pRes = NULL;
29,112✔
523
  int32_t code = createColumnByFunc(pPartialFunc, (SColumnNode**)&pRes);
29,112✔
524
  if (TSDB_CODE_SUCCESS != code) {
29,113!
525
    return code;
×
526
  }
527
  if (NULL != funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc) {
29,113✔
528
    return funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc(pSrcFunc->pParameterList, pRes, pParameterList);
6✔
529
  } else {
530
    return nodesListMakeStrictAppend(pParameterList, pRes);
29,107✔
531
  }
532
}
533

534
static int32_t createMidFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
14,556✔
535
                                 SFunctionNode** pMidFunc) {
536
  SNodeList*     pParameterList = NULL;
14,556✔
537
  SFunctionNode* pFunc = NULL;
14,556✔
538

539
  int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
14,556✔
540
  if (TSDB_CODE_SUCCESS == code) {
14,557!
541
    if(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc != NULL){
14,557✔
542
      code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc, pSrcFunc, pParameterList, &pFunc);
61✔
543
    }else{
544
      code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pSrcFunc, pParameterList, &pFunc);
14,496✔
545
    }
546
  }
547
  if (TSDB_CODE_SUCCESS == code) {
14,556!
548
    tstrncpy(pFunc->node.aliasName, pPartialFunc->node.aliasName, TSDB_COL_NAME_LEN);
14,556✔
549
  }
550

551
  if (TSDB_CODE_SUCCESS == code) {
14,556!
552
    *pMidFunc = pFunc;
14,556✔
553
  } else {
554
    nodesDestroyList(pParameterList);
×
555
  }
556
  return code;
14,556✔
557
}
558

559
static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
14,556✔
560
                                   SFunctionNode** pMergeFunc) {
561
  SNodeList*     pParameterList = NULL;
14,556✔
562
  SFunctionNode* pFunc = NULL;
14,556✔
563

564
  int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
14,556✔
565
  if (TSDB_CODE_SUCCESS == code) {
14,556!
566
    code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pSrcFunc, pParameterList, &pFunc);
14,556✔
567
  }
568
  if (TSDB_CODE_SUCCESS == code) {
14,555!
569
    pFunc->hasOriginalFunc = true;
14,555✔
570
    pFunc->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId;
14,555!
571
    // overwrite function restype set by translate function
572
    if (fmIsSameInOutType(pSrcFunc->funcId)) {
14,555✔
573
      pFunc->node.resType = pSrcFunc->node.resType;
6,227✔
574
    }
575
    tstrncpy(pFunc->node.aliasName, pSrcFunc->node.aliasName, TSDB_COL_NAME_LEN);
14,556✔
576
  }
577

578
  if (TSDB_CODE_SUCCESS == code) {
14,556!
579
    *pMergeFunc = pFunc;
14,556✔
580
  } else {
581
    nodesDestroyList(pParameterList);
×
582
  }
583
  return code;
14,557✔
584
}
585

586
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc,
14,555✔
587
                        SFunctionNode** pMergeFunc) {
588
  if (!fmIsDistExecFunc(pFunc->funcId)) {
14,555!
589
    return TSDB_CODE_FAILED;
×
590
  }
591

592
  int32_t code = createPartialFunction(pFunc, pPartialFunc);
14,552✔
593
  if (TSDB_CODE_SUCCESS == code && pMidFunc) {
14,556!
594
    code = createMidFunction(pFunc, *pPartialFunc, pMidFunc);
14,556✔
595
  }
596
  if (TSDB_CODE_SUCCESS == code) {
14,556!
597
    code = createMergeFunction(pFunc, *pPartialFunc, pMergeFunc);
14,556✔
598
  }
599

600
  if (TSDB_CODE_SUCCESS != code) {
14,557!
601
    nodesDestroyNode((SNode*)*pPartialFunc);
×
602
    if (pMidFunc) nodesDestroyNode((SNode*)*pMidFunc);
×
603
    nodesDestroyNode((SNode*)*pMergeFunc);
×
604
  }
605

606
  return code;
14,557✔
607
}
608

609
char* fmGetFuncName(int32_t funcId) {
×
610
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
×
611
    return taosStrdup("invalid function");
×
612
  }
613
  return taosStrdup(funcMgtBuiltins[funcId].name);
×
614
}
615

616
/// @param [out] pStateFunc, not changed if error occured or no need to create state func
617
/// @retval 0 for succ, otherwise err occured
618
static int32_t fmCreateStateFunc(const SFunctionNode* pFunc, SFunctionNode** pStateFunc) {
×
619
  if (funcMgtBuiltins[pFunc->funcId].pStateFunc) {
×
620
    SNodeList* pParams = NULL;
×
621
    int32_t    code = nodesCloneList(pFunc->pParameterList, &pParams);
×
622
    if (!pParams) return code;
×
623
    code = createFunction(funcMgtBuiltins[pFunc->funcId].pStateFunc, pParams, pStateFunc);
×
624
    if (TSDB_CODE_SUCCESS != code) {
×
625
      nodesDestroyList(pParams);
×
626
      return code;
×
627
    }
628
    tstrncpy((*pStateFunc)->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
×
629
    tstrncpy((*pStateFunc)->node.userAlias, pFunc->node.userAlias, TSDB_COL_NAME_LEN);
×
630
  }
631
  return TSDB_CODE_SUCCESS;
×
632
}
633

634
bool fmIsTSMASupportedFunc(func_id_t funcId) {
×
635
  return isSpecificClassifyFunc(funcId, FUNC_MGT_TSMA_FUNC);
×
636
}
637

638
int32_t fmCreateStateFuncs(SNodeList* pFuncs) {
×
639
  int32_t code;
640
  SNode*  pNode;
641
  char    buf[128] = {0};
×
642
  FOREACH(pNode, pFuncs) {
×
643
    SFunctionNode* pFunc = (SFunctionNode*)pNode;
×
644
    code = fmGetFuncInfo(pFunc, buf, 128);
×
645
    if (code) break;
×
646
    if (fmIsTSMASupportedFunc(pFunc->funcId)) {
×
647
      SFunctionNode* pNewFunc = NULL;
×
648
      code = fmCreateStateFunc(pFunc, &pNewFunc);
×
649
      if (code) {
×
650
        // error
651
        break;
×
652
      } else if (!pNewFunc) {
×
653
        // no need state func
654
        continue;
×
655
      } else {
656
        REPLACE_NODE(pNewFunc);
×
657
        nodesDestroyNode(pNode);
×
658
      }
659
    }
660
  }
661
  return code;
×
662
}
663

664
static int32_t fmCreateStateMergeFunc(SFunctionNode* pFunc, SFunctionNode** pStateMergeFunc) {
×
665
  if (funcMgtBuiltins[pFunc->funcId].pMergeFunc) {
×
666
    SNodeList* pParams = NULL;
×
667
    int32_t    code = nodesCloneList(pFunc->pParameterList, &pParams);
×
668
    if (!pParams) return code;
×
669
    code = createFunctionWithSrcFunc(funcMgtBuiltins[pFunc->funcId].pMergeFunc, pFunc, pParams, pStateMergeFunc);
×
670
    if (TSDB_CODE_SUCCESS != code) {
×
671
      nodesDestroyList(pParams);
×
672
      return code;
×
673
    }
674
    tstrncpy((*pStateMergeFunc)->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
×
675
    tstrncpy((*pStateMergeFunc)->node.userAlias, pFunc->node.userAlias, TSDB_COL_NAME_LEN);
×
676
  }
677
  return TSDB_CODE_SUCCESS;
×
678
}
679

680
int32_t fmCreateStateMergeFuncs(SNodeList* pFuncs) {
×
681
  int32_t code;
682
  SNode*  pNode;
683
  char    buf[128] = {0};
×
684
  FOREACH(pNode, pFuncs) {
×
685
    SFunctionNode* pFunc = (SFunctionNode*)pNode;
×
686
    if (fmIsTSMASupportedFunc(pFunc->funcId)) {
×
687
      SFunctionNode* pNewFunc = NULL;
×
688
      code = fmCreateStateMergeFunc(pFunc, &pNewFunc);
×
689
      if (code) {
×
690
        // error
691
        break;
×
692
      } else if (!pNewFunc) {
×
693
        // no state merge func
694
        continue;
×
695
      } else {
696
        REPLACE_NODE(pNewFunc);
×
697
        nodesDestroyNode(pNode);
×
698
      }
699
    }
700
  }
701
  return code;
×
702
}
703

704
int32_t fmGetFuncId(const char* name) {
3,308✔
705
  if (NULL != gFunMgtService.pFuncNameHashTable) {
3,308!
706
    void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, name, strlen(name));
3,308✔
707
    if (NULL != pVal) {
3,308!
708
      return *(int32_t*)pVal;
3,308✔
709
    }
710
    return -1;
×
711
  }
712
  for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
×
713
    if (0 == strcmp(funcMgtBuiltins[i].name, name)) {
×
714
      return i;
×
715
    }
716
  }
717
  return -1;
×
718
}
719

720
bool fmIsMyStateFunc(int32_t funcId, int32_t stateFuncId) {
×
721
  const SBuiltinFuncDefinition* pFunc = &funcMgtBuiltins[funcId];
×
722
  const SBuiltinFuncDefinition* pStateFunc = &funcMgtBuiltins[stateFuncId];
×
723
  if (!pFunc->pStateFunc) {
×
724
    return false;
×
725
  }
726
  if (strcmp(pFunc->pStateFunc, pStateFunc->name) == 0) return true;
×
727
  int32_t stateMergeFuncId = fmGetFuncId(pFunc->pStateFunc);
×
728
  if (stateMergeFuncId == -1) {
×
729
    return false;
×
730
  }
731
  const SBuiltinFuncDefinition* pStateMergeFunc = &funcMgtBuiltins[stateMergeFuncId];
×
732
  return strcmp(pStateFunc->name, pStateMergeFunc->pMergeFunc) == 0;
×
733
}
734

735
bool fmIsCountLikeFunc(int32_t funcId) {
1,113,452✔
736
  return isSpecificClassifyFunc(funcId, FUNC_MGT_COUNT_LIKE_FUNC);
1,113,452✔
737
}
738

739
bool fmIsRowTsOriginFunc(int32_t funcId) {
873✔
740
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
873!
741
    return false;
×
742
  }
743
  return FUNCTION_TYPE_IROWTS_ORIGIN == funcMgtBuiltins[funcId].type;
873✔
744
}
745

746
bool fmIsGroupIdFunc(int32_t funcId) {
×
747
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
×
748
    return false;
×
749
  }
750
  return FUNCTION_TYPE_GROUP_ID == funcMgtBuiltins[funcId].type;
×
751
}
752

753
const void* fmGetStreamPesudoFuncVal(int32_t funcId, const SStreamRuntimeFuncInfo* pStreamRuntimeFuncInfo) {
813,693✔
754
  SSTriggerCalcParam *pParams = taosArrayGet(pStreamRuntimeFuncInfo->pStreamPesudoFuncVals, pStreamRuntimeFuncInfo->curIdx);
813,693✔
755
  switch (funcMgtBuiltins[funcId].type) {
813,693!
756
    case FUNCTION_TYPE_TPREV_TS:
×
757
      return &pParams->prevTs;
×
758
    case FUNCTION_TYPE_TCURRENT_TS:
12,198✔
759
      return &pParams->currentTs;
12,198✔
760
    case FUNCTION_TYPE_TNEXT_TS:
×
761
      return &pParams->nextTs;
×
762
    case FUNCTION_TYPE_TWSTART:
527,469✔
763
      return &pParams->wstart;
527,469✔
764
    case FUNCTION_TYPE_TWEND:
263,299✔
765
      return &pParams->wend;
263,299✔
766
    case FUNCTION_TYPE_TWDURATION:
×
767
      return &pParams->wduration;
×
768
    case FUNCTION_TYPE_TWROWNUM:
303✔
769
      return &pParams->wrownum;
303✔
770
    case FUNCTION_TYPE_TPREV_LOCALTIME:
1✔
771
      return &pParams->prevLocalTime;
1✔
772
    case FUNCTION_TYPE_TLOCALTIME:
145✔
773
      return &pParams->triggerTime;
145✔
774
    case FUNCTION_TYPE_TNEXT_LOCALTIME:
1✔
775
      return &pParams->nextLocalTime;
1✔
776
    case FUNCTION_TYPE_TGRPID:
162✔
777
      return &pStreamRuntimeFuncInfo->groupId;
162✔
778
    case FUNCTION_TYPE_PLACEHOLDER_COLUMN:
1,443✔
779
      return pStreamRuntimeFuncInfo->pStreamPartColVals;
1,443✔
780
    case FUNCTION_TYPE_PLACEHOLDER_TBNAME:
8,672✔
781
      return pStreamRuntimeFuncInfo->pStreamPartColVals;
8,672✔
782
    default:
×
783
      break;
×
784
  }
785
  return NULL;
×
786
}
787

788
int32_t fmGetStreamPesudoFuncEnv(int32_t funcId, SNodeList* pParamNodes, SFuncExecEnv *pEnv) {
8,528✔
789
  if (NULL == pParamNodes || pParamNodes->length < 1) {
8,528!
790
    uError("invalid stream pesudo func param list %p", pParamNodes);
×
791
    return TSDB_CODE_INTERNAL_ERROR;
×
792
  }
793

794
  int32_t firstParamType = nodeType(nodesListGetNode(pParamNodes, 0));
8,528✔
795
  if (QUERY_NODE_VALUE != firstParamType) {
8,529!
796
    uError("invalid stream pesudo func first param type %d", firstParamType);
×
797
    return TSDB_CODE_INTERNAL_ERROR;
×
798
  }
799

800
  SValueNode* pResDesc = (SValueNode*)nodesListGetNode(pParamNodes, 0);
8,529✔
801
  pEnv->calcMemSize = pResDesc->node.resType.bytes;
8,529✔
802

803
  return TSDB_CODE_SUCCESS;
8,529✔
804
}
805

806
int32_t fmSetStreamPseudoFuncParamVal(int32_t funcId, SNodeList* pParamNodes, const SStreamRuntimeFuncInfo* pStreamRuntimeInfo) {
813,697✔
807
  if (!pStreamRuntimeInfo) {
813,697✔
808
    uError("internal error, should have pVals for stream pseudo funcs");
4!
809
    return TSDB_CODE_INTERNAL_ERROR;
4✔
810
  }
811
  int32_t code = 0;
813,693✔
812
  SArray *pVals1 = NULL, *pVals2 = NULL;
813,693✔
813
  SNode* pFirstParam = nodesListGetNode(pParamNodes, 0);
813,693✔
814
  if (nodeType(pFirstParam) != QUERY_NODE_VALUE) {
813,693!
815
    uError("invalid param node type: %d for func: %d", nodeType(pFirstParam), funcId);
×
816
    return TSDB_CODE_INTERNAL_ERROR;
×
817
  }
818

819
  int32_t t = funcMgtBuiltins[funcId].type;
813,693✔
820
  uDebug("set stream pseudo func param val, functype: %d, pStreamRuntimeInfo: %p", t, pStreamRuntimeInfo);
813,693!
821
  if (FUNCTION_TYPE_TGRPID == t) {
813,693✔
822
    SValue v = {0};
162✔
823
    v.type = TSDB_DATA_TYPE_BIGINT;
162✔
824
    v.val = *(int64_t*)fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
162✔
825
    
826
    code = nodesSetValueNodeValue((SValueNode*)pFirstParam, VALUE_GET_DATUM(&v, pFirstParam->type));
162!
827
    if (code != 0) {
162!
828
      uError("failed to set value node value: %s", tstrerror(code));
×
829
      return code;
×
830
    }
831
  } else if (FUNCTION_TYPE_PLACEHOLDER_COLUMN == t) {
813,531✔
832
    SNode* pSecondParam = nodesListGetNode(pParamNodes, 1);
1,443✔
833
    if (nodeType(pSecondParam) != QUERY_NODE_VALUE) {
1,443!
834
      uError("invalid param node type: %d for func: %d", nodeType(pSecondParam), funcId);
×
835
      return TSDB_CODE_INTERNAL_ERROR;
×
836
    }
837
    SArray* pVal = (SArray*)fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
1,443✔
838
    int32_t idx = ((SValueNode*)pSecondParam)->datum.i;
1,443✔
839
    if (idx - 1 < 0 || idx - 1 >= taosArrayGetSize(pVal)) {
1,443!
840
      uError("invalid idx: %d for func: %d, should be in [1, %d]", idx, funcId, (int32_t)taosArrayGetSize(pVal));
×
841
      return TSDB_CODE_INTERNAL_ERROR;
×
842
    }
843
    SStreamGroupValue* pValue = taosArrayGet(pVal, idx - 1);
1,443✔
844
    if (pValue == NULL) {
1,443!
845
      uError("invalid idx: %d for func: %d, should be in [1, %d]", idx, funcId, (int32_t)taosArrayGetSize(pVal));
×
846
      return TSDB_CODE_INTERNAL_ERROR;
×
847
    }
848
    if (!pValue->isNull){
1,443!
849
      if (pValue->data.type != ((SValueNode*)pFirstParam)->node.resType.type){
1,443!
850
        uError("invalid value type: %d for func: %d, should be: %d", pValue->data.type, funcId, ((SValueNode*)pFirstParam)->node.resType.type);
×
851
        return TSDB_CODE_INTERNAL_ERROR;
×
852
      }
853
      if (IS_VAR_DATA_TYPE(((SValueNode*)pFirstParam)->node.resType.type)) {
1,443!
854
        taosMemoryFree(((SValueNode*)pFirstParam)->datum.p);
1,018!
855
        ((SValueNode*)pFirstParam)->datum.p = taosMemoryCalloc(1, pValue->data.nData + VARSTR_HEADER_SIZE); 
1,018!
856
        memcpy(varDataVal(((SValueNode*)pFirstParam)->datum.p), pValue->data.pData, pValue->data.nData);
1,018✔
857
        varDataLen(((SValueNode*)pFirstParam)->datum.p) = pValue->data.nData;
1,018✔
858
      } else {
859
        code = nodesSetValueNodeValue((SValueNode*)pFirstParam, VALUE_GET_DATUM(&pValue->data, pValue->data.type));
425!
860
      }
861
    }
862
    ((SValueNode*)pFirstParam)->isNull = pValue->isNull;
1,443✔
863
  } else if (FUNCTION_TYPE_PLACEHOLDER_TBNAME == t) {
812,088✔
864
    SArray* pVal = (SArray*)fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
8,672✔
865
    for (int32_t i = 0; i < taosArrayGetSize(pVal); ++i) {
8,672!
866
      SStreamGroupValue* pValue = taosArrayGet(pVal, i);
8,672✔
867
      if (pValue != NULL && pValue->isTbname) {
8,672!
868
        taosMemoryFreeClear(((SValueNode*)pFirstParam)->datum.p);
8,672!
869
        ((SValueNode*)pFirstParam)->datum.p = taosMemoryCalloc(pValue->data.nData + VARSTR_HEADER_SIZE, 1);
8,672!
870
        if (NULL == ((SValueNode*)pFirstParam)->datum.p ) {
8,672!
871
          return terrno;
×
872
        }
873

874
        (void)memcpy(varDataVal(((SValueNode*)pFirstParam)->datum.p), pValue->data.pData, pValue->data.nData);
8,672✔
875
        varDataLen(((SValueNode*)pFirstParam)->datum.p) = pValue->data.nData;
8,672✔
876
        break;
8,672✔
877
      }
878
    }
879
  } else if (LIST_LENGTH(pParamNodes) == 1) {
1,606,832!
880
    // twstart, twend
881
    const void* pVal = fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
803,416✔
882
    if (!pVal) {
803,416!
883
      uError("failed to set stream pseudo func param val, NULL val for funcId: %d", funcId);
×
884
      return TSDB_CODE_INTERNAL_ERROR;
×
885
    }
886
    code = nodesSetValueNodeValue((SValueNode*)pFirstParam, (void*)pVal);
803,416✔
887
    if (code != 0) {
803,416!
888
      uError("failed to set value node value: %s", tstrerror(code));
×
889
      return code;
×
890
    }
891
  } else {
892
    SNode* pSecondParam = nodesListGetNode(pParamNodes, 1);
×
893
    if (nodeType(pSecondParam) != QUERY_NODE_VALUE) {
×
894
      uError("invalid param node type: %d for func: %d", nodeType(pSecondParam), funcId);
×
895
      return TSDB_CODE_INTERNAL_ERROR;
×
896
    }
897
    int32_t idx = ((SValueNode*)pSecondParam)->datum.i;
×
898
    const SValue* pVal = taosArrayGet(pVals2, idx);
×
899
    code = nodesSetValueNodeValue((SValueNode*)pFirstParam, VALUE_GET_DATUM(pVal, pFirstParam->type));
×
900
  }
901
  return code;
813,693✔
902
}
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