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

#include "builtins.h"
H
Haojun Liao 已提交
17
#include "builtinsimpl.h"
18
#include "scalar.h"
19
#include "taoserror.h"
H
Haojun Liao 已提交
20
#include "tdatablock.h"
21 22 23 24 25 26 27 28

int32_t stubCheckAndGetResultType(SFunctionNode* pFunc);

const SBuiltinFuncDefinition funcMgtBuiltins[] = {
  {
    .name = "count",
    .type = FUNCTION_TYPE_COUNT,
    .classification = FUNC_MGT_AGG_FUNC,
H
Haojun Liao 已提交
29 30 31 32
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getCountFuncEnv,
    .initFunc     = functionSetup,
    .processFunc  = countFunction,
H
Haojun Liao 已提交
33
    .finalizeFunc = functionFinalize
34
  },
X
Xiaoyu Wang 已提交
35 36 37 38
  {
    .name = "sum",
    .type = FUNCTION_TYPE_SUM,
    .classification = FUNC_MGT_AGG_FUNC,
H
Haojun Liao 已提交
39 40 41 42
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getSumFuncEnv,
    .initFunc     = functionSetup,
    .processFunc  = sumFunction,
H
Haojun Liao 已提交
43
    .finalizeFunc = functionFinalize
X
Xiaoyu Wang 已提交
44
  },
45 46 47
  {
    .name = "min",
    .type = FUNCTION_TYPE_MIN,
48
    .classification = FUNC_MGT_AGG_FUNC,
49 50 51 52
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getMinmaxFuncEnv,
    .initFunc     = minFunctionSetup,
    .processFunc  = minFunction,
H
Haojun Liao 已提交
53
    .finalizeFunc = functionFinalize
54 55 56 57
  },
  {
    .name = "max",
    .type = FUNCTION_TYPE_MAX,
58
    .classification = FUNC_MGT_AGG_FUNC,
59 60 61 62
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getMinmaxFuncEnv,
    .initFunc     = maxFunctionSetup,
    .processFunc  = maxFunction,
H
Haojun Liao 已提交
63
    .finalizeFunc = functionFinalize
64
  },
H
Haojun Liao 已提交
65
  {
H
Haojun Liao 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    .name = "stddev",
    .type = FUNCTION_TYPE_STDDEV,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getStddevFuncEnv,
    .initFunc     = stddevFunctionSetup,
    .processFunc  = stddevFunction,
    .finalizeFunc = stddevFinalize
  },
  {
    .name = "percentile",
    .type = FUNCTION_TYPE_PERCENTILE,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getPercentileFuncEnv,
    .initFunc     = percentileFunctionSetup,
    .processFunc  = percentileFunction,
    .finalizeFunc = percentileFinalize
  },
  {
    .name = "apercentile",
    .type = FUNCTION_TYPE_APERCENTILE,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getMinmaxFuncEnv,
    .initFunc     = maxFunctionSetup,
    .processFunc  = maxFunction,
    .finalizeFunc = functionFinalize
  },
  {
    .name = "top",
    .type = FUNCTION_TYPE_TOP,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getMinmaxFuncEnv,
    .initFunc     = maxFunctionSetup,
    .processFunc  = maxFunction,
    .finalizeFunc = functionFinalize
  },
  {
    .name = "bottom",
    .type = FUNCTION_TYPE_BOTTOM,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getMinmaxFuncEnv,
    .initFunc     = maxFunctionSetup,
    .processFunc  = maxFunction,
    .finalizeFunc = functionFinalize
  },
  {
    .name = "spread",
    .type = FUNCTION_TYPE_SPREAD,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getMinmaxFuncEnv,
    .initFunc     = maxFunctionSetup,
    .processFunc  = maxFunction,
    .finalizeFunc = functionFinalize
  },
  {
    .name = "last_row",
    .type = FUNCTION_TYPE_LAST_ROW,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getMinmaxFuncEnv,
    .initFunc     = maxFunctionSetup,
    .processFunc  = maxFunction,
    .finalizeFunc = functionFinalize
H
Haojun Liao 已提交
134
  },
H
Haojun Liao 已提交
135 136 137 138 139 140 141 142
  {
    .name = "first",
    .type = FUNCTION_TYPE_FIRST,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getFirstLastFuncEnv,
    .initFunc     = functionSetup,
    .processFunc  = firstFunction,
H
Haojun Liao 已提交
143
    .finalizeFunc = functionFinalize
H
Haojun Liao 已提交
144 145 146 147 148 149 150 151 152
  },
  {
    .name = "last",
    .type = FUNCTION_TYPE_LAST,
    .classification = FUNC_MGT_AGG_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getFirstLastFuncEnv,
    .initFunc     = functionSetup,
    .processFunc  = lastFunction,
H
Haojun Liao 已提交
153
    .finalizeFunc = functionFinalize
H
Haojun Liao 已提交
154
  },
H
Haojun Liao 已提交
155 156 157 158 159 160 161 162 163 164
  {
    .name = "diff",
    .type = FUNCTION_TYPE_DIFF,
    .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getDiffFuncEnv,
    .initFunc     = diffFunctionSetup,
    .processFunc  = diffFunction,
    .finalizeFunc = functionFinalize
  },
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
  {
    .name = "abs",
    .type = FUNCTION_TYPE_ABS,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = absFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "log",
    .type = FUNCTION_TYPE_LOG,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = logFunction,
    .finalizeFunc = NULL
  },
  {
G
Ganlin Zhao 已提交
186
    .name = "pow",
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    .type = FUNCTION_TYPE_POW,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = powFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "sqrt",
    .type = FUNCTION_TYPE_SQRT,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = sqrtFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "ceil",
    .type = FUNCTION_TYPE_CEIL,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = ceilFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "floor",
    .type = FUNCTION_TYPE_FLOOR,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = floorFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "round",
    .type = FUNCTION_TYPE_ROUND,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = roundFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "sin",
    .type = FUNCTION_TYPE_SIN,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = sinFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "cos",
    .type = FUNCTION_TYPE_COS,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = cosFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "tan",
    .type = FUNCTION_TYPE_TAN,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = tanFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "asin",
    .type = FUNCTION_TYPE_ASIN,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = asinFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "acos",
    .type = FUNCTION_TYPE_ACOS,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = acosFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "atan",
    .type = FUNCTION_TYPE_ATAN,
    .classification = FUNC_MGT_SCALAR_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = atanFunction,
    .finalizeFunc = NULL
  },
G
Ganlin Zhao 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
  {
    .name = "length",
    .type = FUNCTION_TYPE_LENGTH,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = lengthFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "char_length",
    .type = FUNCTION_TYPE_CHAR_LENGTH,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = charLengthFunction,
    .finalizeFunc = NULL
  },
315 316 317 318
  {
    .name = "concat",
    .type = FUNCTION_TYPE_CONCAT,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
H
Haojun Liao 已提交
319 320 321
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
G
Ganlin Zhao 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    .sprocessFunc = concatFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "concat_ws",
    .type = FUNCTION_TYPE_CONCAT_WS,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = concatWsFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "lower",
    .type = FUNCTION_TYPE_LOWER,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = lowerFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "upper",
    .type = FUNCTION_TYPE_UPPER,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = upperFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "ltrim",
    .type = FUNCTION_TYPE_LTRIM,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = ltrimFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "rtrim",
    .type = FUNCTION_TYPE_RTRIM,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = rtrimFunction,
    .finalizeFunc = NULL
  },
  {
    .name = "substr",
    .type = FUNCTION_TYPE_SUBSTR,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = substrFunction,
383
    .finalizeFunc = NULL
384 385 386 387 388 389
  },
  {
    .name = "_rowts",
    .type = FUNCTION_TYPE_ROWTS,
    .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
H
Haojun Liao 已提交
390
    .getEnvFunc   = getTimePseudoFuncEnv,
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
    .initFunc     = NULL,
    .sprocessFunc = NULL,
    .finalizeFunc = NULL
  },
  {
    .name = "tbname",
    .type = FUNCTION_TYPE_TBNAME,
    .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = NULL,
    .initFunc     = NULL,
    .sprocessFunc = NULL,
    .finalizeFunc = NULL
  },
  {
    .name = "_qstartts",
    .type = FUNCTION_TYPE_QSTARTTS,
408
    .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
409
    .checkFunc    = stubCheckAndGetResultType,
410
    .getEnvFunc   = getTimePseudoFuncEnv,
411
    .initFunc     = NULL,
412
    .sprocessFunc = qStartTsFunction,
413 414 415 416 417
    .finalizeFunc = NULL
  },
  {
    .name = "_qendts",
    .type = FUNCTION_TYPE_QENDTS,
418
    .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
419
    .checkFunc    = stubCheckAndGetResultType,
420
    .getEnvFunc   = getTimePseudoFuncEnv,
421
    .initFunc     = NULL,
422
    .sprocessFunc = qEndTsFunction,
423 424 425 426
    .finalizeFunc = NULL
  },
  {
    .name = "_wstartts",
427
    .type = FUNCTION_TYPE_WSTARTTS,
428 429
    .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
430
    .getEnvFunc   = getTimePseudoFuncEnv,
431
    .initFunc     = NULL,
432
    .sprocessFunc = winStartTsFunction,
433 434 435 436 437 438 439
    .finalizeFunc = NULL
  },
  {
    .name = "_wendts",
    .type = FUNCTION_TYPE_QENDTS,
    .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
440
    .getEnvFunc   = getTimePseudoFuncEnv,
441
    .initFunc     = NULL,
442
    .sprocessFunc = winEndTsFunction,
443 444 445 446 447 448 449
    .finalizeFunc = NULL
  },
  {
    .name = "_wduration",
    .type = FUNCTION_TYPE_WDURATION,
    .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
450
    .getEnvFunc   = getTimePseudoFuncEnv,
451
    .initFunc     = NULL,
452
    .sprocessFunc = winDurFunction,
453
    .finalizeFunc = NULL
X
Xiaoyu Wang 已提交
454 455 456 457 458 459 460 461 462 463
  },
  {
    .name = "now",
    .type = FUNCTION_TYPE_NOW,
    .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
    .checkFunc    = stubCheckAndGetResultType,
    .getEnvFunc   = getTimePseudoFuncEnv,
    .initFunc     = NULL,
    .sprocessFunc = winDurFunction,
    .finalizeFunc = NULL
464 465 466
  }
};

X
Xiaoyu Wang 已提交
467
const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
468 469

int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
H
Haojun Liao 已提交
470
  switch(pFunc->funcType) {
471
    case FUNCTION_TYPE_WDURATION:
H
Haojun Liao 已提交
472
    case FUNCTION_TYPE_COUNT: {
X
Xiaoyu Wang 已提交
473 474
      pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT};
      break;
H
Haojun Liao 已提交
475 476
    }

477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
    case FUNCTION_TYPE_SUM: {
      SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
      int32_t paraType = pParam->node.resType.type;

      int32_t resType  = 0;
      if (IS_SIGNED_NUMERIC_TYPE(paraType)) {
        resType = TSDB_DATA_TYPE_BIGINT;
      } else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) {
        resType = TSDB_DATA_TYPE_UBIGINT;
      } else if (IS_FLOAT_TYPE(paraType)) {
        resType = TSDB_DATA_TYPE_DOUBLE;
      } else {
        ASSERT(0);
      }

      pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType };
      break;
    }
H
Haojun Liao 已提交
495 496

    case FUNCTION_TYPE_DIFF:
H
Haojun Liao 已提交
497 498
    case FUNCTION_TYPE_FIRST:
    case FUNCTION_TYPE_LAST:
499 500 501 502 503
    case FUNCTION_TYPE_MIN:
    case FUNCTION_TYPE_MAX: {
      SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
      int32_t paraType = pParam->node.resType.type;
      pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType };
H
Haojun Liao 已提交
504
      break;
505
    }
H
Haojun Liao 已提交
506

H
Haojun Liao 已提交
507
    case FUNCTION_TYPE_ROWTS:
508
    case FUNCTION_TYPE_QSTARTTS:
H
Haojun Liao 已提交
509 510 511
    case FUNCTION_TYPE_QENDTS:
    case FUNCTION_TYPE_WSTARTTS:
    case FUNCTION_TYPE_WENDTS:{
512
      pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP};
X
Xiaoyu Wang 已提交
513
      break;
514
    }
515

G
Ganlin Zhao 已提交
516 517 518 519
    case FUNCTION_TYPE_ABS:
    case FUNCTION_TYPE_CEIL:
    case FUNCTION_TYPE_FLOOR:
    case FUNCTION_TYPE_ROUND: {
520 521 522 523 524 525
      SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
      int32_t paraType = pParam->node.resType.type;
      pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType };
      break;
    }

H
Haojun Liao 已提交
526
    case FUNCTION_TYPE_PERCENTILE:
H
Haojun Liao 已提交
527
    case FUNCTION_TYPE_STDDEV:
G
Ganlin Zhao 已提交
528 529 530 531 532 533 534 535 536 537 538 539
    case FUNCTION_TYPE_SIN:
    case FUNCTION_TYPE_COS:
    case FUNCTION_TYPE_TAN:
    case FUNCTION_TYPE_ASIN:
    case FUNCTION_TYPE_ACOS:
    case FUNCTION_TYPE_ATAN:
    case FUNCTION_TYPE_SQRT:
    case FUNCTION_TYPE_LOG:
    case FUNCTION_TYPE_POW: {
      pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE };
      break;
    }
H
Haojun Liao 已提交
540

G
Ganlin Zhao 已提交
541 542 543 544 545 546
    case FUNCTION_TYPE_LENGTH:
    case FUNCTION_TYPE_CHAR_LENGTH: {
      pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT };
      break;
    }

547 548
    case FUNCTION_TYPE_CONCAT:
    case FUNCTION_TYPE_CONCAT_WS: {
549 550
      int32_t paraType, paraBytes = 0;
      for (int32_t i = 0; i < pFunc->pParameterList->length; ++i) {
551
        SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i);
552 553
        paraBytes += pParam->node.resType.bytes;
        paraType = pParam->node.resType.type;
554
      }
555
      pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType };
556
      break;
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
      //int32_t paraTypeFirst, totalBytes = 0, sepBytes = 0;
      //int32_t firstParamIndex = 0;
      //if (pFunc->funcType == FUNCTION_TYPE_CONCAT_WS) {
      //  firstParamIndex = 1;
      //  SColumnNode* pSep = nodesListGetNode(pFunc->pParameterList, 0);
      //  sepBytes = pSep->node.resType.type;
      //}
      //for (int32_t i = firstParamIndex; i < pFunc->pParameterList->length; ++i) {
      //  SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i);
      //  int32_t paraType = pParam->node.resType.type;
      //  if (i == firstParamIndex) {
      //    paraTypeFirst = paraType;
      //  }
      //  if (paraType != paraTypeFirst) {
      //    return TSDB_CODE_FAILED;
      //  }
      //  //TODO: for constants also needs numOfRows
      //  totalBytes += pParam->node.resType.bytes;
      //}
      ////TODO: need to get numOfRows to decide how much space separator needed. Currently set to 100.
      //totalBytes += sepBytes * (pFunc->pParameterList->length - 2) * 100;
      //pFunc->node.resType = (SDataType) { .bytes = totalBytes, .type = paraTypeFirst };
      //break;
580
    }
G
Ganlin Zhao 已提交
581 582 583 584 585 586
    case FUNCTION_TYPE_LOWER:
    case FUNCTION_TYPE_UPPER:
    case FUNCTION_TYPE_LTRIM:
    case FUNCTION_TYPE_RTRIM:
    case FUNCTION_TYPE_SUBSTR: {
      SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
587 588 589
      int32_t paraType  = pParam->node.resType.type;
      int32_t paraBytes = pParam->node.resType.bytes;
      pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType };
G
Ganlin Zhao 已提交
590 591 592
      break;
    }

593
    case FUNCTION_TYPE_TBNAME: {
G
Ganlin Zhao 已提交
594 595
      // todo
      break;
596
    }
G
Ganlin Zhao 已提交
597

X
Xiaoyu Wang 已提交
598 599 600
    case FUNCTION_TYPE_NOW:
      // todo
      break;
601 602
    default:
      ASSERT(0); // to found the fault ASAP.
H
Haojun Liao 已提交
603 604
  }

605 606
  return TSDB_CODE_SUCCESS;
}