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

taosdata / TDengine / #4727

08 Sep 2025 08:43AM UTC coverage: 59.125% (+0.01%) from 59.112%
#4727

push

travis-ci

web-flow
Merge pull request #32881 from taosdata/enh/add-new-windows-ci

fix(ci): update workflow reference to use new Windows CI YAML

135884 of 292179 branches covered (46.51%)

Branch coverage included in aggregate %.

204671 of 283811 relevant lines covered (72.12%)

29258962.23 hits per line

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

58.21
/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() {
4,674✔
35
  gFunMgtService.pFuncNameHashTable =
4,674✔
36
      taosHashInit(funcMgtBuiltinsNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
4,674✔
37
  if (NULL == gFunMgtService.pFuncNameHashTable) {
4,674!
38
    initFunctionCode = terrno;
×
39
    return;
×
40
  }
41

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

51
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
2,147,483,647✔
52
  if (fmIsUserDefinedFunc(funcId)) {
2,147,483,647✔
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,480✔
56
  }
57
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
2,147,483,647!
58
    return false;
254,084,910✔
59
  }
60
  return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
2,147,483,647✔
61
}
62

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

68
int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen) {
779,520✔
69
  if (NULL != gFunMgtService.pFuncNameHashTable) {
779,520!
70
    void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
779,555✔
71
    if (NULL != pVal) {
779,645✔
72
      pFunc->funcId = *(int32_t*)pVal;
779,593✔
73
      pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
779,593✔
74
      return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
779,593✔
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,376✔
89
  if (NULL != funcMgtBuiltins[pFunc->funcId].estimateReturnRowsFunc) {
1,376✔
90
    return funcMgtBuiltins[pFunc->funcId].estimateReturnRowsFunc(pFunc);
971✔
91
  }
92
  return (fmIsIndefiniteRowsFunc(pFunc->funcId) || fmIsMultiRowsFunc(pFunc->funcId)) ? FUNC_RETURN_ROWS_INDEFINITE
405!
93
                                                                                     : FUNC_RETURN_ROWS_NORMAL;
405!
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) {
315,189✔
101
  void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc, strlen(pFunc));
315,189✔
102
  if (NULL != pVal) {
315,155✔
103
    return funcMgtBuiltins[*(int32_t*)pVal].type;
315,135✔
104
  }
105
  return FUNCTION_TYPE_UDF;
20✔
106
}
107

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

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

123
  const char* name = funcMgtBuiltins[funcId].name;
4,710,100✔
124
  if ((strcmp(name, "_group_key") == 0) || (strcmp(name, "_select_value") == 0)) {
4,710,100✔
125
    return FUNC_DATA_REQUIRED_NOT_LOAD;
368,798✔
126
    ;
127
  }
128

129
  if (funcMgtBuiltins[funcId].dynDataRequiredFunc == NULL) {
4,341,302✔
130
    return FUNC_DATA_REQUIRED_DATA_LOAD;
4,297,833✔
131
  } else {
132
    return funcMgtBuiltins[funcId].dynDataRequiredFunc(pRes, pBlockInfo);
43,469✔
133
  }
134
}
135

136
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) {
17,002,062✔
137
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
17,002,062!
138
    return TSDB_CODE_FAILED;
×
139
  }
140
  pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc;
17,012,671✔
141
  pFpSet->init = funcMgtBuiltins[funcId].initFunc;
17,012,671✔
142
  pFpSet->process = funcMgtBuiltins[funcId].processFunc;
17,012,671✔
143
  pFpSet->finalize = funcMgtBuiltins[funcId].finalizeFunc;
17,012,671✔
144
  pFpSet->combine = funcMgtBuiltins[funcId].combineFunc;
17,012,671✔
145
  pFpSet->processFuncByRow = funcMgtBuiltins[funcId].processFuncByRow;
17,012,671✔
146
  pFpSet->cleanup = funcMgtBuiltins[funcId].cleanupFunc;
17,012,671✔
147
  return TSDB_CODE_SUCCESS;
17,012,671✔
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) {
19,501,691✔
166
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
19,501,691!
167
    return TSDB_CODE_FAILED;
1,855✔
168
  }
169
  pFpSet->process = funcMgtBuiltins[funcId].sprocessFunc;
19,500,364✔
170
  pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc;
19,500,364✔
171
  return TSDB_CODE_SUCCESS;
19,500,364✔
172
}
173

174
bool fmIsAggFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_AGG_FUNC); }
30,495,783✔
175

176
bool fmIsScalarFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); }
3,524,998✔
177

178
bool fmIsVectorFunc(int32_t funcId) { return !fmIsScalarFunc(funcId) && !fmIsPseudoColumnFunc(funcId); }
1,001,061✔
179

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

182
bool fmIsSelectFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_FUNC); }
69,835,575✔
183

184
bool fmIsTimelineFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_TIMELINE_FUNC); }
1,009,948✔
185

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

188
bool fmIsPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PSEUDO_COLUMN_FUNC); }
66,927,986✔
189

190
bool fmIsScanPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCAN_PC_FUNC); }
32,232,361✔
191

192
bool fmIsWindowPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_WINDOW_PC_FUNC); }
25,988,798✔
193

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

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

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

200
bool fmIsIndefiniteRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INDEFINITE_ROWS_FUNC); }
18,462,317✔
201

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

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

210
bool fmIsMultiResFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_RES_FUNC); }
1,063,170✔
211

212
bool fmIsRepeatScanFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_REPEAT_SCAN_FUNC); }
4,596,087✔
213

214
bool fmIsUserDefinedFunc(int32_t funcId) { return funcId > FUNC_UDF_ID_START; }
2,147,483,647✔
215

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

218
bool fmIsIntervalInterpoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INTERVAL_INTERPO_FUNC); }
80,762,480✔
219

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

222
bool fmIsImplicitTsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IMPLICIT_TS_FUNC); }
103,439,695✔
223

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

226
bool fmIsMultiRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_ROWS_FUNC); }
1,010,676✔
227

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

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

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

234
bool fmIsInterpFunc(int32_t funcId) {
1,450,631✔
235
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
1,450,631!
236
    return false;
43✔
237
  }
238
  return FUNCTION_TYPE_INTERP == funcMgtBuiltins[funcId].type;
1,450,588✔
239
}
240

241
bool fmIsInterpPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INTERP_PC_FUNC); }
1,010,943✔
242

243
bool fmIsForecastFunc(int32_t funcId) {
1,009,401✔
244
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
1,009,401!
245
    return false;
46✔
246
  }
247
  return FUNCTION_TYPE_FORECAST == funcMgtBuiltins[funcId].type;
1,009,355✔
248
}
249

250
bool fmIsForecastPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORECAST_PC_FUNC); }
1,010,769✔
251

252
bool fmIsLastRowFunc(int32_t funcId) {
45,399✔
253
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
45,399!
254
    return false;
×
255
  }
256
  return FUNCTION_TYPE_LAST_ROW == funcMgtBuiltins[funcId].type;
45,402✔
257
}
258

259
bool fmIsLastFunc(int32_t funcId) {
9✔
260
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
9!
261
    return false;
×
262
  }
263
  return FUNCTION_TYPE_LAST == funcMgtBuiltins[funcId].type;
9✔
264
}
265

266
bool fmIsNotNullOutputFunc(int32_t funcId) {
24,939,563✔
267
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
24,939,563!
268
    return false;
×
269
  }
270
  return FUNCTION_TYPE_LAST == funcMgtBuiltins[funcId].type ||
49,436,250✔
271
         FUNCTION_TYPE_LAST_PARTIAL == funcMgtBuiltins[funcId].type ||
24,485,888✔
272
         FUNCTION_TYPE_LAST_MERGE == funcMgtBuiltins[funcId].type ||
22,689,855✔
273
         FUNCTION_TYPE_FIRST == funcMgtBuiltins[funcId].type ||
21,798,543✔
274
         FUNCTION_TYPE_FIRST_PARTIAL == funcMgtBuiltins[funcId].type ||
21,413,987✔
275
         FUNCTION_TYPE_FIRST_MERGE == funcMgtBuiltins[funcId].type ||
20,770,028✔
276
         FUNCTION_TYPE_COUNT == funcMgtBuiltins[funcId].type ||
20,446,970✔
277
         FUNCTION_TYPE_HYPERLOGLOG == funcMgtBuiltins[funcId].type ||
15,901,691✔
278
         FUNCTION_TYPE_HYPERLOGLOG_PARTIAL == funcMgtBuiltins[funcId].type ||
65,297,302✔
279
         FUNCTION_TYPE_HYPERLOGLOG_MERGE == funcMgtBuiltins[funcId].type;
15,861,052✔
280
}
281

282
bool fmIsSelectValueFunc(int32_t funcId) {
1,163,015✔
283
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
1,163,015!
284
    return false;
×
285
  }
286
  return FUNCTION_TYPE_SELECT_VALUE == funcMgtBuiltins[funcId].type;
1,163,015✔
287
}
288

289
bool fmIsGroupKeyFunc(int32_t funcId) {
590,757,763✔
290
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
590,757,763!
291
    return false;
×
292
  }
293
  return FUNCTION_TYPE_GROUP_KEY == funcMgtBuiltins[funcId].type;
590,774,373✔
294
}
295

296
bool fmisSelectGroupConstValueFunc(int32_t funcId) {
10✔
297
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
10!
298
    return false;
×
299
  }
300
  return FUNCTION_TYPE_GROUP_CONST_VALUE == funcMgtBuiltins[funcId].type;
10✔
301
}
302

303
bool fmIsElapsedFunc(int32_t funcId) {
48,697,959✔
304
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
48,697,959!
305
    return false;
×
306
  }
307
  return FUNCTION_TYPE_ELAPSED == funcMgtBuiltins[funcId].type;
48,698,501✔
308
}
309

310
bool fmIsBlockDistFunc(int32_t funcId) {
692,574✔
311
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
692,574!
312
    return false;
×
313
  }
314
  return FUNCTION_TYPE_BLOCK_DIST == funcMgtBuiltins[funcId].type;
692,687✔
315
}
316

317
bool fmIsDBUsageFunc(int32_t funcId) {
692,589✔
318
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
692,589!
319
    return false;
×
320
  }
321
  return FUNCTION_TYPE_DB_USAGE == funcMgtBuiltins[funcId].type;
692,604✔
322
}
323

324
bool fmIsProcessByRowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PROCESS_BY_ROW); }
5,379,147✔
325

326
bool fmIsIgnoreNullFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IGNORE_NULL_FUNC); }
12✔
327

328
void fmFuncMgtDestroy() {
4,675✔
329
  void* m = gFunMgtService.pFuncNameHashTable;
4,675✔
330
  if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
4,675!
331
    taosHashCleanup(m);
4,674✔
332
  }
333
}
4,675✔
334

335
#ifdef BUILD_NO_CALL
336
int32_t fmSetInvertFunc(int32_t funcId, SFuncExecFuncs* pFpSet) {
337
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
338
    return TSDB_CODE_FAILED;
339
  }
340
  pFpSet->process = funcMgtBuiltins[funcId].invertFunc;
341
  return TSDB_CODE_SUCCESS;
342
}
343

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

352
bool fmIsInvertible(int32_t funcId) {
353
  bool res = false;
354
  switch (funcMgtBuiltins[funcId].type) {
355
    case FUNCTION_TYPE_COUNT:
356
    case FUNCTION_TYPE_SUM:
357
    case FUNCTION_TYPE_STDDEV:
358
    case FUNCTION_TYPE_AVG:
359
    case FUNCTION_TYPE_WSTART:
360
    case FUNCTION_TYPE_WEND:
361
    case FUNCTION_TYPE_WDURATION:
362
      res = true;
363
      break;
364
    default:
365
      break;
366
  }
367
  return res;
368
}
369
#endif
370

371
// function has same input/output type
372
bool fmIsSameInOutType(int32_t funcId) {
14,754✔
373
  bool res = false;
14,754✔
374
  switch (funcMgtBuiltins[funcId].type) {
14,754✔
375
    case FUNCTION_TYPE_MAX:
6,250✔
376
    case FUNCTION_TYPE_MIN:
377
    case FUNCTION_TYPE_TOP:
378
    case FUNCTION_TYPE_BOTTOM:
379
    case FUNCTION_TYPE_FIRST:
380
    case FUNCTION_TYPE_LAST:
381
    case FUNCTION_TYPE_SAMPLE:
382
    case FUNCTION_TYPE_TAIL:
383
    case FUNCTION_TYPE_UNIQUE:
384
      res = true;
6,250✔
385
      break;
6,250✔
386
    default:
8,504✔
387
      break;
8,504✔
388
  }
389
  return res;
14,754✔
390
}
391

392
bool fmIsConstantResFunc(SFunctionNode* pFunc) {
1,090✔
393
  SNode* pNode;
394
  FOREACH(pNode, pFunc->pParameterList) {
1,090!
395
    if (nodeType(pNode) != QUERY_NODE_VALUE) {
×
396
      return false;
×
397
    }
398
  }
399
  return true;
1,090✔
400
}
401

402
bool fmIsSkipScanCheckFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SKIP_SCAN_CHECK_FUNC); }
134,756✔
403

404
bool fmIsPrimaryKeyFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PRIMARY_KEY_FUNC); }
369,234✔
405

406
bool fmIsPlaceHolderFunc(int32_t funcId) {return isSpecificClassifyFunc(funcId, FUNC_MGT_PLACE_HOLDER_FUNC); }
1,992,253,505✔
407

408
void getLastCacheDataType(SDataType* pType, int32_t pkBytes) {
10,464✔
409
  // TODO: do it later.
410
  pType->bytes = getFirstLastInfoSize(pType->bytes, pkBytes) + VARSTR_HEADER_SIZE;
10,464✔
411
  pType->type = TSDB_DATA_TYPE_BINARY;
10,464✔
412
}
10,464✔
413

414
static int32_t getFuncInfo(SFunctionNode* pFunc) {
47,870✔
415
  char msg[128] = {0};
47,870✔
416
  return fmGetFuncInfo(pFunc, msg, sizeof(msg));
47,870✔
417
}
418

419
int32_t createFunction(const char* pName, SNodeList* pParameterList, SFunctionNode** ppFunc) {
3,610✔
420
  int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc);
3,610✔
421
  if (NULL == *ppFunc) {
3,610!
422
    return code;
×
423
  }
424
  (void)snprintf((*ppFunc)->functionName, sizeof((*ppFunc)->functionName), "%s", pName);
3,610✔
425
  (*ppFunc)->pParameterList = pParameterList;
3,610✔
426
  code = getFuncInfo((*ppFunc));
3,610✔
427
  if (TSDB_CODE_SUCCESS != code) {
3,610!
428
    (*ppFunc)->pParameterList = NULL;
×
429
    nodesDestroyNode((SNode*)*ppFunc);
×
430
    *ppFunc = NULL;
×
431
    return code;
×
432
  }
433
  return code;
3,610✔
434
}
435

436
static void resetOutputChangedFunc(SFunctionNode *pFunc, const SFunctionNode* pSrcFunc) {
44,260✔
437
  if (funcMgtBuiltins[pFunc->funcId].type == FUNCTION_TYPE_LAST_MERGE) {
44,260✔
438
    pFunc->node.resType = pSrcFunc->node.resType;
25,945✔
439
    return;
25,945✔
440
  }
441
}
442

443
int32_t createFunctionWithSrcFunc(const char* pName, const SFunctionNode* pSrcFunc, SNodeList* pParameterList, SFunctionNode** ppFunc) {
44,260✔
444
  int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc);
44,260✔
445
  if (NULL == *ppFunc) {
44,264!
446
    return code;
×
447
  }
448

449
  (*ppFunc)->hasPk = pSrcFunc->hasPk;
44,264✔
450
  (*ppFunc)->pkBytes = pSrcFunc->pkBytes;
44,264✔
451
  (*ppFunc)->pSrcFuncRef = pSrcFunc;
44,264✔
452

453
  (void)snprintf((*ppFunc)->functionName, sizeof((*ppFunc)->functionName), "%s", pName);
44,264✔
454
  (*ppFunc)->pParameterList = pParameterList;
44,264✔
455
  code = getFuncInfo((*ppFunc));
44,264✔
456
  if (TSDB_CODE_SUCCESS != code) {
44,260!
457
    (*ppFunc)->pParameterList = NULL;
×
458
    nodesDestroyNode((SNode*)*ppFunc);
×
459
    *ppFunc = NULL;
×
460
    return code;
×
461
  }
462
  resetOutputChangedFunc(*ppFunc, pSrcFunc);
44,260✔
463
  (*ppFunc)->node.relatedTo = pSrcFunc->node.relatedTo;
44,259✔
464
  (*ppFunc)->node.bindExprID = pSrcFunc->node.bindExprID;
44,259✔
465
  return code;
44,259✔
466
}
467

468
static int32_t createColumnByFunc(const SFunctionNode* pFunc, SColumnNode** ppCol) {
29,506✔
469
  int32_t code = nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)ppCol);
29,506✔
470
  if (NULL == *ppCol) {
29,508!
471
    return code;
×
472
  }
473
  tstrncpy((*ppCol)->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
29,508✔
474
  (*ppCol)->node.resType = pFunc->node.resType;
29,508✔
475
  return TSDB_CODE_SUCCESS;
29,508✔
476
}
477

478
bool fmIsDistExecFunc(int32_t funcId) {
331,781✔
479
  if (fmIsUserDefinedFunc(funcId)) {
331,781!
480
    return false;
×
481
  }
482
  if (!fmIsVectorFunc(funcId)) {
331,933✔
483
    return true;
535✔
484
  }
485
  return (NULL != funcMgtBuiltins[funcId].pPartialFunc && NULL != funcMgtBuiltins[funcId].pMergeFunc);
331,403!
486
}
487

488
static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNode** pPartialFunc) {
14,753✔
489
  SNodeList* pParameterList = NULL;
14,753✔
490
  int32_t    code = nodesCloneList(pSrcFunc->pParameterList, &pParameterList);
14,753✔
491
  if (NULL == pParameterList) {
14,753!
492
    return code;
×
493
  }
494
  code =
495
      createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pPartialFunc, pSrcFunc, pParameterList, pPartialFunc);
14,753✔
496
  if (TSDB_CODE_SUCCESS != code) {
14,754!
497
    nodesDestroyList(pParameterList);
×
498
    return code;
×
499
  }
500
  (*pPartialFunc)->hasOriginalFunc = true;
14,755✔
501
  (*pPartialFunc)->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId;
14,755!
502
  char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0};
14,755✔
503

504
  int32_t len = tsnprintf(name, sizeof(name), "%s.%p", (*pPartialFunc)->functionName, pSrcFunc);
14,755✔
505
  if (taosHashBinary(name, len) < 0) {
14,753!
506
    return TSDB_CODE_FAILED;
×
507
  }
508
  tstrncpy((*pPartialFunc)->node.aliasName, name, TSDB_COL_NAME_LEN);
14,753✔
509
  return TSDB_CODE_SUCCESS;
14,753✔
510
}
511

512
static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
29,508✔
513
                                   SNodeList** pParameterList) {
514
  SNode*  pRes = NULL;
29,508✔
515
  int32_t code = createColumnByFunc(pPartialFunc, (SColumnNode**)&pRes);
29,508✔
516
  if (TSDB_CODE_SUCCESS != code) {
29,508!
517
    return code;
×
518
  }
519
  if (NULL != funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc) {
29,508✔
520
    return funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc(pSrcFunc->pParameterList, pRes, pParameterList);
6✔
521
  } else {
522
    return nodesListMakeStrictAppend(pParameterList, pRes);
29,502✔
523
  }
524
}
525

526
static int32_t createMidFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
14,753✔
527
                                 SFunctionNode** pMidFunc) {
528
  SNodeList*     pParameterList = NULL;
14,753✔
529
  SFunctionNode* pFunc = NULL;
14,753✔
530

531
  int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
14,753✔
532
  if (TSDB_CODE_SUCCESS == code) {
14,755!
533
    if(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc != NULL){
14,755✔
534
      code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc, pSrcFunc, pParameterList, &pFunc);
62✔
535
    }else{
536
      code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pSrcFunc, pParameterList, &pFunc);
14,693✔
537
    }
538
  }
539
  if (TSDB_CODE_SUCCESS == code) {
14,755✔
540
    tstrncpy(pFunc->node.aliasName, pPartialFunc->node.aliasName, TSDB_COL_NAME_LEN);
14,753✔
541
  }
542

543
  if (TSDB_CODE_SUCCESS == code) {
14,755!
544
    *pMidFunc = pFunc;
14,755✔
545
  } else {
546
    nodesDestroyList(pParameterList);
×
547
  }
548
  return code;
14,755✔
549
}
550

551
static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
14,755✔
552
                                   SFunctionNode** pMergeFunc) {
553
  SNodeList*     pParameterList = NULL;
14,755✔
554
  SFunctionNode* pFunc = NULL;
14,755✔
555

556
  int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
14,755✔
557
  if (TSDB_CODE_SUCCESS == code) {
14,754!
558
    code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pSrcFunc, pParameterList, &pFunc);
14,754✔
559
  }
560
  if (TSDB_CODE_SUCCESS == code) {
14,754!
561
    pFunc->hasOriginalFunc = true;
14,754✔
562
    pFunc->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId;
14,754!
563
    // overwrite function restype set by translate function
564
    if (fmIsSameInOutType(pSrcFunc->funcId)) {
14,754✔
565
      pFunc->node.resType = pSrcFunc->node.resType;
6,250✔
566
    }
567
    tstrncpy(pFunc->node.aliasName, pSrcFunc->node.aliasName, TSDB_COL_NAME_LEN);
14,754✔
568
  }
569

570
  if (TSDB_CODE_SUCCESS == code) {
14,754!
571
    *pMergeFunc = pFunc;
14,754✔
572
  } else {
573
    nodesDestroyList(pParameterList);
×
574
  }
575
  return code;
14,754✔
576
}
577

578
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc,
14,753✔
579
                        SFunctionNode** pMergeFunc) {
580
  if (!fmIsDistExecFunc(pFunc->funcId)) {
14,753!
581
    return TSDB_CODE_FAILED;
×
582
  }
583

584
  int32_t code = createPartialFunction(pFunc, pPartialFunc);
14,755✔
585
  if (TSDB_CODE_SUCCESS == code && pMidFunc) {
14,752!
586
    code = createMidFunction(pFunc, *pPartialFunc, pMidFunc);
14,753✔
587
  }
588
  if (TSDB_CODE_SUCCESS == code) {
14,753!
589
    code = createMergeFunction(pFunc, *pPartialFunc, pMergeFunc);
14,755✔
590
  }
591

592
  if (TSDB_CODE_SUCCESS != code) {
14,751!
593
    nodesDestroyNode((SNode*)*pPartialFunc);
×
594
    if (pMidFunc) nodesDestroyNode((SNode*)*pMidFunc);
×
595
    nodesDestroyNode((SNode*)*pMergeFunc);
×
596
  }
597

598
  return code;
14,753✔
599
}
600

601
char* fmGetFuncName(int32_t funcId) {
×
602
  if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
×
603
    return taosStrdup("invalid function");
×
604
  }
605
  return taosStrdup(funcMgtBuiltins[funcId].name);
×
606
}
607

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

626
bool fmIsTSMASupportedFunc(func_id_t funcId) {
×
627
  return isSpecificClassifyFunc(funcId, FUNC_MGT_TSMA_FUNC);
×
628
}
629

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

656
static int32_t fmCreateStateMergeFunc(SFunctionNode* pFunc, SFunctionNode** pStateMergeFunc) {
×
657
  if (funcMgtBuiltins[pFunc->funcId].pMergeFunc) {
×
658
    SNodeList* pParams = NULL;
×
659
    int32_t    code = nodesCloneList(pFunc->pParameterList, &pParams);
×
660
    if (!pParams) return code;
×
661
    code = createFunctionWithSrcFunc(funcMgtBuiltins[pFunc->funcId].pMergeFunc, pFunc, pParams, pStateMergeFunc);
×
662
    if (TSDB_CODE_SUCCESS != code) {
×
663
      nodesDestroyList(pParams);
×
664
      return code;
×
665
    }
666
    tstrncpy((*pStateMergeFunc)->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
×
667
    tstrncpy((*pStateMergeFunc)->node.userAlias, pFunc->node.userAlias, TSDB_COL_NAME_LEN);
×
668
  }
669
  return TSDB_CODE_SUCCESS;
×
670
}
671

672
int32_t fmCreateStateMergeFuncs(SNodeList* pFuncs) {
×
673
  int32_t code;
674
  SNode*  pNode;
675
  char    buf[128] = {0};
×
676
  FOREACH(pNode, pFuncs) {
×
677
    SFunctionNode* pFunc = (SFunctionNode*)pNode;
×
678
    if (fmIsTSMASupportedFunc(pFunc->funcId)) {
×
679
      SFunctionNode* pNewFunc = NULL;
×
680
      code = fmCreateStateMergeFunc(pFunc, &pNewFunc);
×
681
      if (code) {
×
682
        // error
683
        break;
×
684
      } else if (!pNewFunc) {
×
685
        // no state merge func
686
        continue;
×
687
      } else {
688
        REPLACE_NODE(pNewFunc);
×
689
        nodesDestroyNode(pNode);
×
690
      }
691
    }
692
  }
693
  return code;
×
694
}
695

696
int32_t fmGetFuncId(const char* name) {
8,624✔
697
  if (NULL != gFunMgtService.pFuncNameHashTable) {
8,624!
698
    void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, name, strlen(name));
8,624✔
699
    if (NULL != pVal) {
8,624!
700
      return *(int32_t*)pVal;
8,624✔
701
    }
702
    return -1;
×
703
  }
704
  for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
×
705
    if (0 == strcmp(funcMgtBuiltins[i].name, name)) {
×
706
      return i;
×
707
    }
708
  }
709
  return -1;
×
710
}
711

712
bool fmIsMyStateFunc(int32_t funcId, int32_t stateFuncId) {
×
713
  const SBuiltinFuncDefinition* pFunc = &funcMgtBuiltins[funcId];
×
714
  const SBuiltinFuncDefinition* pStateFunc = &funcMgtBuiltins[stateFuncId];
×
715
  if (!pFunc->pStateFunc) {
×
716
    return false;
×
717
  }
718
  if (strcmp(pFunc->pStateFunc, pStateFunc->name) == 0) return true;
×
719
  int32_t stateMergeFuncId = fmGetFuncId(pFunc->pStateFunc);
×
720
  if (stateMergeFuncId == -1) {
×
721
    return false;
×
722
  }
723
  const SBuiltinFuncDefinition* pStateMergeFunc = &funcMgtBuiltins[stateMergeFuncId];
×
724
  return strcmp(pStateFunc->name, pStateMergeFunc->pMergeFunc) == 0;
×
725
}
726

727
bool fmIsCountLikeFunc(int32_t funcId) {
1,359,628✔
728
  return isSpecificClassifyFunc(funcId, FUNC_MGT_COUNT_LIKE_FUNC);
1,359,628✔
729
}
730

731
bool fmIsRowTsOriginFunc(int32_t funcId) {
873✔
732
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
873!
733
    return false;
×
734
  }
735
  return FUNCTION_TYPE_IROWTS_ORIGIN == funcMgtBuiltins[funcId].type;
873✔
736
}
737

738
bool fmIsGroupIdFunc(int32_t funcId) {
×
739
  if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
×
740
    return false;
×
741
  }
742
  return FUNCTION_TYPE_GROUP_ID == funcMgtBuiltins[funcId].type;
×
743
}
744

745
const void* fmGetStreamPesudoFuncVal(int32_t funcId, const SStreamRuntimeFuncInfo* pStreamRuntimeFuncInfo) {
819,899✔
746
  SSTriggerCalcParam *pParams = taosArrayGet(pStreamRuntimeFuncInfo->pStreamPesudoFuncVals, pStreamRuntimeFuncInfo->curIdx);
819,899✔
747
  switch (funcMgtBuiltins[funcId].type) {
819,899!
748
    case FUNCTION_TYPE_TPREV_TS:
2✔
749
      return &pParams->prevTs;
2✔
750
    case FUNCTION_TYPE_TCURRENT_TS:
13,013✔
751
      return &pParams->currentTs;
13,013✔
752
    case FUNCTION_TYPE_TNEXT_TS:
×
753
      return &pParams->nextTs;
×
754
    case FUNCTION_TYPE_TWSTART:
528,223✔
755
      return &pParams->wstart;
528,223✔
756
    case FUNCTION_TYPE_TWEND:
263,370✔
757
      return &pParams->wend;
263,370✔
758
    case FUNCTION_TYPE_TWDURATION:
×
759
      return &pParams->wduration;
×
760
    case FUNCTION_TYPE_TWROWNUM:
199✔
761
      return &pParams->wrownum;
199✔
762
    case FUNCTION_TYPE_TPREV_LOCALTIME:
1✔
763
      return &pParams->prevLocalTime;
1✔
764
    case FUNCTION_TYPE_TLOCALTIME:
146✔
765
      return &pParams->triggerTime;
146✔
766
    case FUNCTION_TYPE_TNEXT_LOCALTIME:
1✔
767
      return &pParams->nextLocalTime;
1✔
768
    case FUNCTION_TYPE_TGRPID:
232✔
769
      return &pStreamRuntimeFuncInfo->groupId;
232✔
770
    case FUNCTION_TYPE_PLACEHOLDER_COLUMN:
1,705✔
771
      return pStreamRuntimeFuncInfo->pStreamPartColVals;
1,705✔
772
    case FUNCTION_TYPE_PLACEHOLDER_TBNAME:
13,008✔
773
      return pStreamRuntimeFuncInfo->pStreamPartColVals;
13,008✔
774
    default:
×
775
      break;
×
776
  }
777
  return NULL;
×
778
}
779

780
int32_t fmGetStreamPesudoFuncEnv(int32_t funcId, SNodeList* pParamNodes, SFuncExecEnv *pEnv) {
11,862✔
781
  if (NULL == pParamNodes || pParamNodes->length < 1) {
11,862!
782
    uError("invalid stream pesudo func param list %p", pParamNodes);
×
783
    return TSDB_CODE_INTERNAL_ERROR;
×
784
  }
785

786
  int32_t firstParamType = nodeType(nodesListGetNode(pParamNodes, 0));
11,862✔
787
  if (QUERY_NODE_VALUE != firstParamType) {
11,862!
788
    uError("invalid stream pesudo func first param type %d", firstParamType);
×
789
    return TSDB_CODE_INTERNAL_ERROR;
×
790
  }
791

792
  SValueNode* pResDesc = (SValueNode*)nodesListGetNode(pParamNodes, 0);
11,862✔
793
  pEnv->calcMemSize = pResDesc->node.resType.bytes;
11,862✔
794

795
  return TSDB_CODE_SUCCESS;
11,862✔
796
}
797

798
int32_t fmSetStreamPseudoFuncParamVal(int32_t funcId, SNodeList* pParamNodes, const SStreamRuntimeFuncInfo* pStreamRuntimeInfo) {
819,907✔
799
  if (!pStreamRuntimeInfo) {
819,907✔
800
    uError("internal error, should have pVals for stream pseudo funcs");
8!
801
    return TSDB_CODE_INTERNAL_ERROR;
8✔
802
  }
803
  int32_t code = 0;
819,899✔
804
  SArray *pVals1 = NULL, *pVals2 = NULL;
819,899✔
805
  SNode* pFirstParam = nodesListGetNode(pParamNodes, 0);
819,899✔
806
  if (nodeType(pFirstParam) != QUERY_NODE_VALUE) {
819,899!
807
    uError("invalid param node type: %d for func: %d", nodeType(pFirstParam), funcId);
×
808
    return TSDB_CODE_INTERNAL_ERROR;
×
809
  }
810

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

866
        (void)memcpy(varDataVal(((SValueNode*)pFirstParam)->datum.p), pValue->data.pData, pValue->data.nData);
13,008✔
867
        varDataLen(((SValueNode*)pFirstParam)->datum.p) = pValue->data.nData;
13,008✔
868
        break;
13,008✔
869
      }
870
    }
871
  } else if (LIST_LENGTH(pParamNodes) == 1) {
1,609,909!
872
    // twstart, twend
873
    const void* pVal = fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
804,955✔
874
    if (!pVal) {
804,955!
875
      uError("failed to set stream pseudo func param val, NULL val for funcId: %d", funcId);
×
876
      return TSDB_CODE_INTERNAL_ERROR;
×
877
    }
878
    code = nodesSetValueNodeValue((SValueNode*)pFirstParam, (void*)pVal);
804,955✔
879
    if (code != 0) {
804,955!
880
      uError("failed to set value node value: %s", tstrerror(code));
×
881
      return code;
×
882
    }
883
  } else {
884
    SNode* pSecondParam = nodesListGetNode(pParamNodes, 1);
×
885
    if (nodeType(pSecondParam) != QUERY_NODE_VALUE) {
×
886
      uError("invalid param node type: %d for func: %d", nodeType(pSecondParam), funcId);
×
887
      return TSDB_CODE_INTERNAL_ERROR;
×
888
    }
889
    int32_t idx = ((SValueNode*)pSecondParam)->datum.i;
×
890
    const SValue* pVal = taosArrayGet(pVals2, idx);
×
891
    code = nodesSetValueNodeValue((SValueNode*)pFirstParam, VALUE_GET_DATUM(pVal, pFirstParam->type));
×
892
  }
893
  return code;
819,900✔
894
}
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