tscalar.c 14.9 KB
Newer Older
D
dapan1121 已提交
1 2 3
#include "nodes.h"
#include "tscalar.h"

D
dapan1121 已提交
4
int32_t sclGetOperatorParamNum(EOperatorType type) {
D
dapan1121 已提交
5
  if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type) {
D
dapan1121 已提交
6 7 8 9 10 11
    return 1;
  }

  return 2;
}

D
dapan1121 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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
void sclFreeRes(SHashObj *res) {
  SScalarParam *p = NULL;
  void *pIter = taosHashIterate(res, NULL);
  while (pIter) {
    p = (SScalarParam *)pIter;

    if (p) {
      tfree(p->data);
    }
    
    pIter = taosHashIterate(res, pIter);
  }
  
  taosHashCleanup(res);
}

void sclFreeParam(SScalarParam *param) {
  tfree(param->data);
}

int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t *rowNum) {
  switch (nodeType(node)) {
    case QUERY_NODE_VALUE: {
      SValueNode *valueNode = (SValueNode *)node;
      param->data = nodesGetValueFromNode(valueNode);
      param->num = 1;
      param->type = valueNode->node.resType.type;
      param->bytes = valueNode->node.resType.bytes;
      
      break;
    }
    case QUERY_NODE_COLUMN_REF: {
      if (NULL == ctx) {
        sclError("invalid node type for constant calculating, type:%d, ctx:%p", nodeType(node), ctx);
        SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
      }
      
      SColumnRef *ref = (SColumnRef *)node;
      if (ref->slotId >= taosArrayGetSize(ctx->pSrc->pDataBlock)) {
        sclError("column ref slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, taosArrayGetSize(ctx->pSrc->pDataBlock));
        SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
      }

      SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(ctx->pSrc->pDataBlock, ref->slotId);
      param->data = columnData->pData;
      param->num = ctx->pSrc->info.rows;
      param->type = columnData->info.type;
      param->bytes = columnData->info.bytes;
      
      break;
    }
    case QUERY_NODE_LOGIC_CONDITION:
    case QUERY_NODE_OPERATOR: {
      if (NULL == ctx) {
        sclError("invalid node type for constant calculating, type:%d, ctx:%p", nodeType(node), ctx);
        SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
      }

      SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES);
      if (NULL == res) {
        sclError("no result for node, type:%d, node:%p", nodeType(node), node);
        SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
      }

      *param = *res;
      
      break;
    }
  }

  if (param->num > *rowNum) {
    if (1 != param->num) && (1 < *rowNum) {
      sclError("different row nums, rowNum:%d, newRowNum:%d", *rowNum, param->num);
      SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
    }
    
    *rowNum = param->num;
  }

  return TSDB_CODE_SUCCESS;
}

int32_t sclParamMoveNext(SScalarParam *params, int32_t num) {
  SScalarParam *param = NULL;
  
  for (int32_t i = 0; i < num; ++i) {
    param = params + i;
    
    if (1 == param->num) {
      continue;
    }

    if (IS_VAR_DATA_TYPE(param->type)) {
      param->data = (char *)(param->data) + varDataTLen(param->data);
    } else {
      param->data = (char *)(param->data) + tDataTypes[param->type].bytes;
    }
  }

  return TSDB_CODE_SUCCESS;
}

int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarCtx *ctx, int32_t *rowNum) {
  int32_t code = 0;
  *pParams = calloc(pParamList->length, sizeof(SScalarParam));
D
dapan1121 已提交
117
  if (NULL == *pParams) {
D
dapan1121 已提交
118 119
    sclError("calloc %d failed", pParamList->length * sizeof(SScalarParam));
    SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
D
dapan1121 已提交
120 121
  }

D
dapan1121 已提交
122 123
  SListCell *cell = pParamList->pHead;
  for (int32_t i = 0; i < pParamList->length; ++i) {
D
dapan1121 已提交
124 125
    if (NULL == cell || NULL == cell->pNode) {
      sclError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode);
D
dapan1121 已提交
126
      SCL_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT);
D
dapan1121 已提交
127 128
    }

D
dapan1121 已提交
129 130 131 132
    SCL_ERR_JRET(sclInitParam(cell->pNode, &pParams[i], ctx, rowNum));
    
    cell = cell->pNext;
  }
D
dapan1121 已提交
133

D
dapan1121 已提交
134
  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
135

D
dapan1121 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
_return:

  tfree(*pParams);
  SCL_RET(code);
}

int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScalarCtx *ctx, int32_t *rowNum) {
  int32_t code = 0;
  int32_t paramNum = sclGetOperatorParamNum(node->opType);
  if (NULL == node->pLeft || (paramNum == 2 && NULL == node->pRight)) {
    sclError("invalid operation node, left:%p, right:%p", node->pLeft, node->pRight);
    SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
  }
  
  *pParams = calloc(paramNum, sizeof(SScalarParam));
  if (NULL == *pParams) {
    sclError("calloc %d failed", paramNum * sizeof(SScalarParam));
    SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }

  SCL_ERR_JRET(sclInitParam(node->pLeft, &pParams[0], ctx, rowNum));
  if (paramNum > 1) {
    SCL_ERR_JRET(sclInitParam(node->pRight, &pParams[1], ctx, rowNum));
D
dapan1121 已提交
159 160 161
  }

  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
162 163 164 165 166

_return:

  tfree(*pParams);
  SCL_RET(code);
D
dapan1121 已提交
167 168
}

D
dapan1121 已提交
169 170

int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) {
D
dapan1121 已提交
171 172
  if (NULL == node->pParameterList || node->pParameterList->length <= 0) {
    sclError("invalid function parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0);
D
dapan1121 已提交
173
    SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
D
dapan1121 已提交
174 175 176 177 178 179
  }

  SScalarFuncExecFuncs ffpSet = {0};
  int32_t code = fmGetScalarFuncExecFuncs(node->funcId, &ffpSet);
  if (code) {
    sclError("fmGetFuncExecFuncs failed, funcId:%d, code:%s", node->funcId, tstrerror(code));
D
dapan1121 已提交
180
    SCL_ERR_RET(code);
D
dapan1121 已提交
181 182
  }

D
dapan1121 已提交
183 184 185 186 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
  SScalarParam *params = NULL;
  int32_t rowNum = 0;
  SCL_ERR_RET(sclInitParamList(&params, node->pParameterList, ctx, &rowNum));

  output->type = node->node.resType.type;
  output->data = calloc(rowNum, sizeof(tDataTypes[output->type].bytes));
  if (NULL == output->data) {
    sclError("calloc %d failed", (int32_t)rowNum * sizeof(tDataTypes[output->type].bytes));
    SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }

  for (int32_t i = 0; i < rowNum; ++i) {
    code = (*ffpSet.process)(params, node->pParameterList->length, output);
    if (code) {
      sclError("scalar function exec failed, funcId:%d, code:%s", node->funcId, tstrerror(code));
      SCL_ERR_JRET(code);    
    }

    sclParamMoveNext(output, 1);
    sclParamMoveNext(params, node->pParameterList->length);
  }

  return TSDB_CODE_SUCCESS;

_return:

  tfree(params);
  SCL_RET(code);
}


int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *output) {
  if (NULL == node->pParameterList || node->pParameterList->length <= 0) {
    sclError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0);
    SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
  }

  if (TSDB_DATA_TYPE_BOOL != node->node.resType.type) {
    sclError("invalid logic resType, type:%d", node->node.resType.type);
    SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
D
dapan1121 已提交
223 224
  }

D
dapan1121 已提交
225 226 227 228 229 230 231 232
  if (LOGIC_COND_TYPE_NOT == node->condType && node->pParameterList->length > 1) {
    sclError("invalid NOT operation parameter number, paramNum:%d", node->pParameterList->length);
    SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
  }

  SScalarParam *params = NULL;
  int32_t rowNum = 0;
  int32_t code = 0;
D
dapan1121 已提交
233
  
D
dapan1121 已提交
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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
  SCL_ERR_RET(sclInitParamList(&params, node->pParameterList, ctx, &rowNum));

  output->type = node->node.resType.type;
  output->data = calloc(rowNum, sizeof(bool));
  if (NULL == output->data) {
    sclError("calloc %d failed", (int32_t)rowNum * sizeof(bool));
    SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }
  
  bool value = false;

  for (int32_t i = 0; i < rowNum; ++i) {
    for (int32_t m = 0; m < node->pParameterList->length; ++m) {
      GET_TYPED_DATA(value, bool, params[m].type, params[m].data);
      
      if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) {
        break;
      } else if (LOGIC_COND_TYPE_OR == node->condType && value) {
        break;
      } else if (LOGIC_COND_TYPE_NOT == node->condType) {
        value = !value;
      }
    }

    *(bool *)output->data = value;

    sclParamMoveNext(output, 1);    
    sclParamMoveNext(params, node->pParameterList->length);
  }

  return TSDB_CODE_SUCCESS;

_return:

  tfree(params);
  CTG_RET(code);
}

int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *output) {
  SScalarParam *params = NULL;
  int32_t rowNum = 0;
  int32_t code = 0;
  
  SCL_ERR_RET(sclInitOperatorParams(&params, node, ctx, &rowNum));

  output->type = node->node.resType.type;
  output->data = calloc(rowNum, sizeof(tDataTypes[output->type].bytes));
  if (NULL == output->data) {
    sclError("calloc %d failed", (int32_t)rowNum * sizeof(tDataTypes[output->type].bytes));
    SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }

  _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType);

  int32_t paramNum = sclGetOperatorParamNum(node->opType);
  SScalarParam* pLeft = &params[0];
  SScalarParam* pRight = paramNum > 1 ? &params[1] : NULL;

  for (int32_t i = 0; i < rowNum; ++i) {

    OperatorFn(pLeft, pRight, output->data, TSDB_ORDER_ASC);

    sclParamMoveNext(output, 1);    
    sclParamMoveNext(pLeft, 1);
    if (pRight) {
      sclParamMoveNext(pRight, 1);
    }
  }

  return TSDB_CODE_SUCCESS;

_return:

  tfree(params);
  CTG_RET(code);
}


EDealRes sclRewriteFunction(SNode** pNode, void* pContext) {
  SFunctionNode *node = (SFunctionNode *)*pNode;
  SScalarParam output = {0};
  
  *(int32_t *)pContext = sclExecFuncion(node, NULL, &output);
  if (*(int32_t *)pContext) {
D
dapan1121 已提交
318 319 320 321 322 323
    return DEAL_RES_ERROR;
  }

  SValueNode *res = nodesMakeNode(QUERY_NODE_VALUE);
  if (NULL == res) {
    sclError("make value node failed");
D
dapan1121 已提交
324
    sclFreeParam(&output);
D
dapan1121 已提交
325 326 327 328 329 330 331 332 333 334 335
    *(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY;
    return DEAL_RES_ERROR;
  }

  res->node.resType = node->node.resType;

  SET_TYPED_DATA(nodesGetValueFromNode(res), output.type, output.data);

  nodesDestroyNode(*pNode);
  *pNode = (SNode*)res;

D
dapan1121 已提交
336
  sclFreeParam(&output);
D
dapan1121 已提交
337 338 339 340 341 342

  return DEAL_RES_CONTINUE;
}

EDealRes sclRewriteLogic(SNode** pNode, void* pContext) {
  SLogicConditionNode *node = (SLogicConditionNode *)*pNode;
D
dapan1121 已提交
343
  SScalarParam output = {0};
D
dapan1121 已提交
344

D
dapan1121 已提交
345 346
  *(int32_t *)pContext = sclExecLogic(node, NULL, &output);
  if (*(int32_t *)pContext) {
D
dapan1121 已提交
347 348 349 350 351 352
    return DEAL_RES_ERROR;
  }

  SValueNode *res = nodesMakeNode(QUERY_NODE_VALUE);
  if (NULL == res) {
    sclError("make value node failed");
D
dapan1121 已提交
353
    sclFreeParam(&output);    
D
dapan1121 已提交
354 355 356 357 358 359
    *(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY;
    return DEAL_RES_ERROR;
  }

  res->node.resType = node->node.resType;

D
dapan1121 已提交
360
  SET_TYPED_DATA(nodesGetValueFromNode(res), res->node.resType.type, output.data);
D
dapan1121 已提交
361 362 363 364

  nodesDestroyNode(*pNode);
  *pNode = (SNode*)res;

D
dapan1121 已提交
365 366
  sclFreeParam(&output);

D
dapan1121 已提交
367 368 369 370
  return DEAL_RES_CONTINUE;
}

EDealRes sclRewriteOperator(SNode** pNode, void* pContext) {
D
dapan1121 已提交
371 372
  SOperatorNode *node = (SOperatorNode *)*pNode;
  SScalarParam output = {0};
D
dapan1121 已提交
373

D
dapan1121 已提交
374 375
  *(int32_t *)pContext = sclExecOperator(node, NULL, &output);
  if (*(int32_t *)pContext) {
D
dapan1121 已提交
376 377 378 379 380
    return DEAL_RES_ERROR;
  }

  SValueNode *res = nodesMakeNode(QUERY_NODE_VALUE);
  if (NULL == res) {
D
dapan1121 已提交
381 382
    sclError("make value node failed");    
    sclFreeParam(&output);    
D
dapan1121 已提交
383 384 385 386
    *(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY;
    return DEAL_RES_ERROR;
  }

D
dapan1121 已提交
387
  res->node.resType = node->node.resType;
D
dapan1121 已提交
388

D
dapan1121 已提交
389
  SET_TYPED_DATA(nodesGetValueFromNode(res), res->node.resType.type, output.data);
D
dapan1121 已提交
390 391 392 393

  nodesDestroyNode(*pNode);
  *pNode = (SNode*)res;

D
dapan1121 已提交
394 395
  sclFreeParam(&output);    

D
dapan1121 已提交
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
  return DEAL_RES_CONTINUE;
}


EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
  if (QUERY_NODE_VALUE == nodeType(*pNode)) {
    return DEAL_RES_CONTINUE;
  }

  if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
    return sclRewriteFunction(pNode, pContext);
  }

  if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) {
    return sclRewriteLogic(pNode, pContext);
  }

D
dapan1121 已提交
413 414
  if (QUERY_NODE_OPERATOR == nodeType(*pNode)) {
    return sclRewriteOperator(pNode, pContext);
D
dapan1121 已提交
415 416
  }  
  
D
dapan1121 已提交
417 418 419 420 421
  sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode));
  
  *(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
  
  return DEAL_RES_ERROR;
D
dapan1121 已提交
422 423
}

D
dapan1121 已提交
424 425 426 427 428 429 430 431 432

EDealRes sclWalkFunction(SNode** pNode, void* pContext) {
  SScalarCtx *ctx = (SScalarCtx *)pContext;
  SFunctionNode *node = (SFunctionNode *)*pNode;
  SScalarParam output = {0};
  
  ctx->code = sclExecFuncion(node, ctx, &output);
  if (ctx->code) {
    return DEAL_RES_ERROR;
D
dapan1121 已提交
433 434
  }

D
dapan1121 已提交
435 436 437
  if (taosHashPut(ctx->pRes, pNode, POINTER_BYTES, &output, sizeof(output))) {
    ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
    return DEAL_RES_ERROR;
D
dapan1121 已提交
438 439
  }

D
dapan1121 已提交
440 441 442 443 444 445 446 447 448 449 450 451
  return DEAL_RES_CONTINUE;
}


EDealRes sclWalkLogic(SNode** pNode, void* pContext) {
  SScalarCtx *ctx = (SScalarCtx *)pContext;
  SLogicConditionNode *node = (SLogicConditionNode *)*pNode;
  SScalarParam output = {0};
  
  ctx->code = sclExecLogic(node, ctx, &output);
  if (ctx->code) {
    return DEAL_RES_ERROR;
D
dapan1121 已提交
452 453
  }

D
dapan1121 已提交
454 455
  if (taosHashPut(ctx->pRes, pNode, POINTER_BYTES, &output, sizeof(output))) {
    ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
D
dapan1121 已提交
456
    return DEAL_RES_ERROR;
D
dapan1121 已提交
457 458 459 460 461 462 463 464 465 466
  }

  return DEAL_RES_CONTINUE;
}


EDealRes sclWalkOperator(SNode** pNode, void* pContext) {
  SScalarCtx *ctx = (SScalarCtx *)pContext;
  SOperatorNode *node = (SOperatorNode *)*pNode;
  SScalarParam output = {0};
D
dapan1121 已提交
467
  
D
dapan1121 已提交
468 469
  ctx->code = sclExecOperator(node, ctx, &output);
  if (ctx->code) {
D
dapan1121 已提交
470 471
    return DEAL_RES_ERROR;
  }
D
dapan1121 已提交
472

D
dapan1121 已提交
473 474
  if (taosHashPut(ctx->pRes, pNode, POINTER_BYTES, &output, sizeof(output))) {
    ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
D
dapan1121 已提交
475 476 477
    return DEAL_RES_ERROR;
  }

D
dapan1121 已提交
478 479 480 481 482 483 484
  return DEAL_RES_CONTINUE;
}


EDealRes sclCalcWalker(SNode** pNode, void* pContext) {
  if (QUERY_NODE_VALUE == nodeType(*pNode)) {
    return DEAL_RES_CONTINUE;
D
dapan1121 已提交
485 486
  }

D
dapan1121 已提交
487 488 489
  if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
    return sclWalkFunction(pNode, pContext);
  }
D
dapan1121 已提交
490

D
dapan1121 已提交
491 492 493
  if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) {
    return sclWalkLogic(pNode, pContext);
  }
D
dapan1121 已提交
494

D
dapan1121 已提交
495 496
  if (QUERY_NODE_OPERATOR == nodeType(*pNode)) {
    return sclWalkOperator(pNode, pContext);
D
dapan1121 已提交
497
  }
D
dapan1121 已提交
498

D
dapan1121 已提交
499
  sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode));
D
dapan1121 已提交
500

D
dapan1121 已提交
501 502 503 504 505
  SScalarCtx *ctx = (SScalarCtx *)pContext;
  
  ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
  
  return DEAL_RES_ERROR;
D
dapan1121 已提交
506 507
}

D
dapan1121 已提交
508 509


D
dapan1121 已提交
510 511 512 513 514 515 516
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
  if (NULL == pNode) {
    SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
  }

  int32_t code = 0;
  
D
dapan1121 已提交
517 518 519 520 521 522 523 524 525 526 527 528
  nodesRewriteNodePostOrder(&pNode, sclConstantsRewriter, (void *)&code);

  if (code) {
    nodesDestroyNode(pNode);
    SCL_ERR_RET(code);
  }

  *pRes = pNode;

  SCL_RET(code);
}

D
dapan1121 已提交
529 530
int32_t scalarCalculate(SNode *pNode, SSDataBlock *pSrc, SScalarParam *pDst) {
  if (NULL == pNode || NULL == pSrc || NULL == pDst) {
D
dapan1121 已提交
531 532 533 534
    SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
  }

  int32_t code = 0;
D
dapan1121 已提交
535 536 537 538 539 540 541
  SScalarCtx ctx = {.code = 0, .pSrc = pSrc};
  
  ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
  if (NULL == ctx.pRes) {
    sclError("taosHashInit failed, num:%d", SCL_DEFAULT_OP_NUM);
    SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }
D
dapan1121 已提交
542
  
D
dapan1121 已提交
543
  nodesWalkNodePostOrder(&pNode, sclCalcWalker, (void *)&ctx);
D
dapan1121 已提交
544

D
dapan1121 已提交
545
  if (ctx.code) {
D
dapan1121 已提交
546
    nodesDestroyNode(pNode);
D
dapan1121 已提交
547 548
    sclFreeRes(ctx.pRes);
    SCL_ERR_RET(ctx.code);
D
dapan1121 已提交
549 550
  }

D
dapan1121 已提交
551 552 553 554 555 556 557
  SScalarParam *res = taosHashGet(ctx.pRes, &pNode, POINTER_BYTES);
  if (NULL == res) {
    sclError("no res for calculating, node:%d, type:%d", pNode, nodeType(pNode));
    SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
  }
  
  *pDst = *res;
D
dapan1121 已提交
558

D
dapan1121 已提交
559 560 561
  nodesDestroyNode(pNode);

  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
562 563 564 565
}