sclvector.c 46.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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 "os.h"

H
Haojun Liao 已提交
18
#include "filter.h"
D
dapan1121 已提交
19
#include "filterInt.h"
D
dapan1121 已提交
20
#include "query.h"
H
Haojun Liao 已提交
21
#include "querynodes.h"
D
dapan1121 已提交
22
#include "sclInt.h"
H
Haojun Liao 已提交
23 24 25 26
#include "sclvector.h"
#include "tcompare.h"
#include "tdatablock.h"
#include "ttypes.h"
27

D
dapan1121 已提交
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
typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index);

int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) {
  return (int64_t)*((int8_t *)src + index);
}
int64_t getVectorBigintValue_UTINYINT(void *src, int32_t index) {
  return (int64_t)*((uint8_t *)src + index);
}
int64_t getVectorBigintValue_SMALLINT(void *src, int32_t index) {
  return (int64_t)*((int16_t *)src + index);
}
int64_t getVectorBigintValue_USMALLINT(void *src, int32_t index) {
  return (int64_t)*((uint16_t *)src + index);
}
int64_t getVectorBigintValue_INT(void *src, int32_t index) {
  return (int64_t)*((int32_t *)src + index);
}
int64_t getVectorBigintValue_UINT(void *src, int32_t index) {
  return (int64_t)*((uint32_t *)src + index);
}
int64_t getVectorBigintValue_BIGINT(void *src, int32_t index) {
  return (int64_t)*((int64_t *)src + index);
}
int64_t getVectorBigintValue_UBIGINT(void *src, int32_t index) {
  return (int64_t)*((uint64_t *)src + index);
}
int64_t getVectorBigintValue_FLOAT(void *src, int32_t index) {
  return (int64_t)*((float *)src + index);
}
int64_t getVectorBigintValue_DOUBLE(void *src, int32_t index) {
  return (int64_t)*((double *)src + index);
}
D
dapan1121 已提交
60 61
_getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
    _getBigintValue_fn_t p = NULL;
D
dapan1121 已提交
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
    if(srcType==TSDB_DATA_TYPE_TINYINT) {
        p = getVectorBigintValue_TINYINT;
    }else if(srcType==TSDB_DATA_TYPE_UTINYINT) {
        p = getVectorBigintValue_UTINYINT;
    }else if(srcType==TSDB_DATA_TYPE_SMALLINT) {
        p = getVectorBigintValue_SMALLINT;
    }else if(srcType==TSDB_DATA_TYPE_USMALLINT) {
        p = getVectorBigintValue_USMALLINT;
    }else if(srcType==TSDB_DATA_TYPE_INT) {
        p = getVectorBigintValue_INT;
    }else if(srcType==TSDB_DATA_TYPE_UINT) {
        p = getVectorBigintValue_UINT;
    }else if(srcType==TSDB_DATA_TYPE_BIGINT) {
        p = getVectorBigintValue_BIGINT;
    }else if(srcType==TSDB_DATA_TYPE_UBIGINT) {
        p = getVectorBigintValue_UBIGINT;
    }else if(srcType==TSDB_DATA_TYPE_FLOAT) {
        p = getVectorBigintValue_FLOAT;
    }else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
        p = getVectorBigintValue_DOUBLE;
    }else {
        assert(0);
    }
    return p;
}

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
typedef void* (*_getValueAddr_fn_t)(void *src, int32_t index);

void* getVectorValueAddr_TINYINT(void *src, int32_t index) {
  return (void*)((int8_t *)src + index);
}
void* getVectorValueAddr_UTINYINT(void *src, int32_t index) {
  return (void*)((uint8_t *)src + index);
}
void* getVectorValueAddr_SMALLINT(void *src, int32_t index) {
  return (void*)((int16_t *)src + index);
}
void* getVectorValueAddr_USMALLINT(void *src, int32_t index) {
  return (void*)((uint16_t *)src + index);
}
void* getVectorValueAddr_INT(void *src, int32_t index) {
  return (void*)((int32_t *)src + index);
}
void* getVectorValueAddr_UINT(void *src, int32_t index) {
  return (void*)((uint32_t *)src + index);
}
void* getVectorValueAddr_BIGINT(void *src, int32_t index) {
  return (void*)((int64_t *)src + index);
}
void* getVectorValueAddr_UBIGINT(void *src, int32_t index) {
  return (void*)((uint64_t *)src + index);
}
void* getVectorValueAddr_FLOAT(void *src, int32_t index) {
  return (void*)((float *)src + index);
}
void* getVectorValueAddr_DOUBLE(void *src, int32_t index) {
  return (void*)((double *)src + index);
}
D
dapan1121 已提交
120 121 122 123
void* getVectorValueAddr_default(void *src, int32_t index) {
  return src;
}
void* getVectorValueAddr_VAR(void *src, int32_t index) {
H
Haojun Liao 已提交
124
  return colDataGetData((SColumnInfoData *)src, index);
D
dapan1121 已提交
125
}
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

_getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
    _getValueAddr_fn_t p = NULL;
    if(srcType==TSDB_DATA_TYPE_TINYINT) {
        p = getVectorValueAddr_TINYINT;
    }else if(srcType==TSDB_DATA_TYPE_UTINYINT) {
        p = getVectorValueAddr_UTINYINT;
    }else if(srcType==TSDB_DATA_TYPE_SMALLINT) {
        p = getVectorValueAddr_SMALLINT;
    }else if(srcType==TSDB_DATA_TYPE_USMALLINT) {
        p = getVectorValueAddr_USMALLINT;
    }else if(srcType==TSDB_DATA_TYPE_INT) {
        p = getVectorValueAddr_INT;
    }else if(srcType==TSDB_DATA_TYPE_UINT) {
        p = getVectorValueAddr_UINT;
    }else if(srcType==TSDB_DATA_TYPE_BIGINT) {
        p = getVectorValueAddr_BIGINT;
    }else if(srcType==TSDB_DATA_TYPE_UBIGINT) {
        p = getVectorValueAddr_UBIGINT;
    }else if(srcType==TSDB_DATA_TYPE_FLOAT) {
        p = getVectorValueAddr_FLOAT;
    }else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
        p = getVectorValueAddr_DOUBLE;
D
dapan1121 已提交
149 150 151 152
    }else if(srcType==TSDB_DATA_TYPE_BINARY) {
        p = getVectorValueAddr_VAR;
    }else if(srcType==TSDB_DATA_TYPE_NCHAR) {
        p = getVectorValueAddr_VAR;
153
    }else {
D
dapan1121 已提交
154
        p = getVectorValueAddr_default;
155 156 157 158
    }
    return p;
}

159
static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex) {
D
dapan1121 已提交
160
  int64_t value = strtoll(buf, NULL, 10);
161
  colDataAppendInt64(pOut->columnData, rowIndex, &value);
D
dapan1121 已提交
162 163
}

164
static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex) {
D
dapan1121 已提交
165
  uint64_t value = strtoull(buf, NULL, 10);
166
  colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*) &value);
D
dapan1121 已提交
167 168
}

169
static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex) {
D
dapan 已提交
170
  double value = strtod(buf, NULL);
171
  colDataAppendDouble(pOut->columnData, rowIndex, &value);
172 173 174 175 176
}

static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex) {
  int64_t value = strtoll(buf, NULL, 10);
  bool v = (value != 0)? true:false;
177
  colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v);
D
dapan1121 已提交
178 179
}

H
Haojun Liao 已提交
180
int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) {
181
  int32_t bufSize = pIn->columnData->info.bytes;
H
Haojun Liao 已提交
182
  char *tmp = taosMemoryMalloc(bufSize);
183

D
dapan1121 已提交
184
  _bufConverteFunc func = NULL;
185 186 187
  if (TSDB_DATA_TYPE_BOOL == outType) {
    func = varToBool;
  } else if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType) {
D
dapan 已提交
188
    func = varToSigned;
D
dapan1121 已提交
189
  } else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) {
D
dapan 已提交
190
    func = varToUnsigned;
D
dapan1121 已提交
191
  } else if (IS_FLOAT_TYPE(outType)) {
D
dapan 已提交
192
    func = varToFloat;
D
dapan1121 已提交
193
  } else {
D
dapan 已提交
194
    sclError("invalid convert outType:%d", outType);
D
dapan1121 已提交
195 196
    return TSDB_CODE_QRY_APP_ERROR;
  }
197 198

  pOut->numOfRows = pIn->numOfRows;
199 200
  for (int32_t i = 0; i < pIn->numOfRows; ++i) {
    if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) {
201
      colDataAppendNULL(pOut->columnData, i);
D
dapan1121 已提交
202 203
      continue;
    }
D
dapan 已提交
204

205
    char* data = colDataGetData(pIn->columnData, i);
D
dapan 已提交
206
    if (TSDB_DATA_TYPE_BINARY == inType) {
207 208
      memcpy(tmp, varDataVal(data), varDataLen(data));
      tmp[varDataLen(data)] = 0;
D
dapan 已提交
209
    } else {
210
      ASSERT (varDataLen(data) <= bufSize);
D
dapan 已提交
211
      
212
      int len = taosUcs4ToMbs((TdUcs4*)varDataVal(data), varDataLen(data), tmp);
D
dapan 已提交
213 214
      if (len < 0){
        sclError("castConvert taosUcs4ToMbs error 1");
wafwerar's avatar
wafwerar 已提交
215
        taosMemoryFreeClear(tmp);
D
dapan 已提交
216 217 218 219
        return TSDB_CODE_QRY_APP_ERROR;
      }
      
      tmp[len] = 0;
D
dapan1121 已提交
220 221
    }
    
222
    (*func)(tmp, pOut, i);
D
dapan1121 已提交
223 224
  }
  
wafwerar's avatar
wafwerar 已提交
225
  taosMemoryFreeClear(tmp);
D
dapan 已提交
226
  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
227
}
D
dapan1121 已提交
228

229
// TODO opt performance
H
Haojun Liao 已提交
230
int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) {
231 232
  SColumnInfoData* pInputCol  = pIn->columnData;
  SColumnInfoData* pOutputCol = pOut->columnData;
H
Haojun Liao 已提交
233 234

  int16_t inType   = pInputCol->info.type;
235
  int16_t outType  = pOutputCol->info.type;
D
dapan1121 已提交
236

237
  if (IS_VAR_DATA_TYPE(inType)) {
D
dapan 已提交
238 239 240
    return vectorConvertFromVarData(pIn, pOut, inType, outType);
  }
  
D
dapan1121 已提交
241
  switch (outType) {
242 243 244
    case TSDB_DATA_TYPE_BOOL: {
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
245
          colDataAppendNULL(pOutputCol, i);
246 247 248 249
          continue;
        }

        bool value = 0;
D
dapan1121 已提交
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
        GET_TYPED_DATA(value, bool, inType, colDataGetData(pInputCol, i));
        colDataAppendInt8(pOutputCol, i, (int8_t *)&value);
      }
      break;
    }
    case TSDB_DATA_TYPE_TINYINT: {
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
          colDataAppendNULL(pOutputCol, i);
          continue;
        }

        int8_t value = 0;
        GET_TYPED_DATA(value, int8_t, inType, colDataGetData(pInputCol, i));
        colDataAppendInt8(pOutputCol, i, (int8_t *)&value);
      }
      break;
    }
    case TSDB_DATA_TYPE_SMALLINT:{
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
          colDataAppendNULL(pOutputCol, i);
          continue;
        }

        int16_t value = 0;
        GET_TYPED_DATA(value, int16_t, inType, colDataGetData(pInputCol, i));
        colDataAppendInt16(pOutputCol, i, (int16_t *)&value);
      }
      break;
    }
    case TSDB_DATA_TYPE_INT:{
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
          colDataAppendNULL(pOutputCol, i);
          continue;
        }

        int32_t value = 0;
        GET_TYPED_DATA(value, int32_t, inType, colDataGetData(pInputCol, i));
        colDataAppendInt32(pOutputCol, i, (int32_t *)&value);
291 292 293
      }
      break;
    }
D
dapan1121 已提交
294
    case TSDB_DATA_TYPE_BIGINT:
295
    case TSDB_DATA_TYPE_TIMESTAMP: {
296 297
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
298
          colDataAppendNULL(pOutputCol, i);
D
dapan 已提交
299
          continue;
D
dapan1121 已提交
300
        }
D
dapan 已提交
301 302

        int64_t value = 0;
303
        GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i));
D
dapan1121 已提交
304
        colDataAppendInt64(pOutputCol, i, (int64_t *)&value);
D
dapan1121 已提交
305 306
      }
      break;
307
    }
D
dapan1121 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320 321 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
    case TSDB_DATA_TYPE_UTINYINT:{
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
          colDataAppendNULL(pOutputCol, i);
          continue;
        }
        
        uint8_t value = 0;
        GET_TYPED_DATA(value, uint8_t, inType, colDataGetData(pInputCol, i));
        colDataAppendInt8(pOutputCol, i, (int8_t *)&value);
      }
      break;
    }
    case TSDB_DATA_TYPE_USMALLINT:{
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
          colDataAppendNULL(pOutputCol, i);
          continue;
        }
        
        uint16_t value = 0;
        GET_TYPED_DATA(value, uint16_t, inType, colDataGetData(pInputCol, i));
        colDataAppendInt16(pOutputCol, i, (int16_t *)&value);
      }
      break;
    }
    case TSDB_DATA_TYPE_UINT:{
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
          colDataAppendNULL(pOutputCol, i);
          continue;
        }
        
        uint32_t value = 0;
        GET_TYPED_DATA(value, uint32_t, inType, colDataGetData(pInputCol, i));
        colDataAppendInt32(pOutputCol, i, (int32_t *)&value);
      }
      break;
    }
    case TSDB_DATA_TYPE_UBIGINT: {
348 349
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
350
          colDataAppendNULL(pOutputCol, i);
D
dapan 已提交
351
          continue;
D
dapan1121 已提交
352 353
        }
        
D
dapan 已提交
354
        uint64_t value = 0;
355
        GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i));
356
        colDataAppendInt64(pOutputCol, i, (int64_t*)&value);
D
dapan1121 已提交
357 358
      }
      break;
D
dapan1121 已提交
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    }
    case TSDB_DATA_TYPE_FLOAT:{
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
          colDataAppendNULL(pOutputCol, i);
          continue;
        }
        
        float value = 0;
        GET_TYPED_DATA(value, float, inType, colDataGetData(pInputCol, i));
        colDataAppendFloat(pOutputCol, i, (float*)&value);
      }
      break;  
    }
    case TSDB_DATA_TYPE_DOUBLE: {
374 375
      for (int32_t i = 0; i < pIn->numOfRows; ++i) {
        if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
376
          colDataAppendNULL(pOutputCol, i);
D
dapan 已提交
377
          continue;
D
dapan1121 已提交
378 379
        }
        
D
dapan 已提交
380
        double value = 0;
381
        GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i));
D
dapan1121 已提交
382
        colDataAppendDouble(pOutputCol, i, (double*)&value);
D
dapan1121 已提交
383
      }
D
dapan1121 已提交
384 385
      break;  
    }
D
dapan1121 已提交
386
    default:
D
dapan1121 已提交
387
      sclError("invalid convert output type:%d", outType);
D
dapan1121 已提交
388 389 390 391 392 393 394
      return TSDB_CODE_QRY_APP_ERROR;
  }

  return TSDB_CODE_SUCCESS;
}

int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = {
H
Haojun Liao 已提交
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
/*         NULL BOOL TINY SMAL INT  BIG  FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG VARB JSON DECI BLOB */
/*NULL*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
/*BOOL*/   0,   0,   0,   3,   4,   5,   6,   7,   7,   9,   7,   0,   12,  13,  14,  7,   0,   0,   0,
/*TINY*/   0,   0,   0,   3,   4,   5,   6,   7,   7,   9,   7,   3,   4,   5,   7,   7,   0,   0,   0,
/*SMAL*/   0,   0,   0,   0,   4,   5,   6,   7,   7,   9,   7,   3,   4,   5,   7,   7,   0,   0,   0,
/*INT */   0,   0,   0,   0,   0,   5,   6,   7,   7,   9,   7,   4,   4,   5,   7,   7,   0,   0,   0,
/*BIGI*/   0,   0,   0,   0,   0,   0,   6,   7,   7,   0,   7,   5,   5,   5,   7,   7,   0,   0,   0,
/*FLOA*/   0,   0,   0,   0,   0,   0,   0,   7,   7,   6,   7,   6,   6,   6,   6,   7,   0,   0,   0,
/*DOUB*/   0,   0,   0,   0,   0,   0,   0,   0,   7,   7,   7,   7,   7,   7,   7,   7,   0,   0,   0,
/*VARC*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   7,   0,   7,   7,   7,   7,   0,   0,   0,   0,
/*TIME*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   7,   9,   9,   9,   7,   7,   0,   0,   0,
/*NCHA*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   7,   7,   7,   7,   0,   0,   0,   0,
/*UTIN*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   12,  13,  14,  7,   0,   0,   0,
/*USMA*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   13,  14,  7,   0,   0,   0,
/*UINT*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   14,  7,   0,   0,   0,
/*UBIG*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   7,   0,   0,   0,
/*VARB*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
/*JSON*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
/*DECI*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
/*BLOB*/   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0
D
dapan1121 已提交
415 416
};

D
dapan1121 已提交
417 418 419 420 421 422 423 424 425 426 427 428
int32_t vectorGetConvertType(int32_t type1, int32_t type2) {
  if (type1 == type2) {
    return 0;
  }

  if (type1 < type2) {
    return gConvertTypes[type1][type2];
  }

  return gConvertTypes[type2][type1];
}

D
dapan1121 已提交
429
int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) {
430
  if (pLeft->pHashFilter != NULL || pRight->pHashFilter != NULL) {
D
dapan1121 已提交
431 432 433
    return TSDB_CODE_SUCCESS;
  }

434 435 436
  int32_t leftType  = GET_PARAM_TYPE(pLeft);
  int32_t rightType = GET_PARAM_TYPE(pRight);
  if (leftType == rightType) {
D
dapan1121 已提交
437 438 439
    return TSDB_CODE_SUCCESS;
  }

D
dapan1121 已提交
440 441
  SScalarParam *param1 = NULL, *paramOut1 = NULL; 
  SScalarParam *param2 = NULL, *paramOut2 = NULL;
D
dapan1121 已提交
442 443
  int32_t code = 0;
  
444
  if (leftType < rightType) {
D
dapan1121 已提交
445 446 447 448 449 450 451 452 453 454 455
    param1 = pLeft;
    param2 = pRight;
    paramOut1 = pLeftOut;
    paramOut2 = pRightOut;
  } else {
    param1 = pRight;
    param2 = pLeft;
    paramOut1 = pRightOut;
    paramOut2 = pLeftOut;
  }

456
  int8_t type = vectorGetConvertType(GET_PARAM_TYPE(param1), GET_PARAM_TYPE(param2));
D
dapan1121 已提交
457 458 459 460
  if (0 == type) {
    return TSDB_CODE_SUCCESS;
  }

461 462 463 464 465 466 467
  if (type != GET_PARAM_TYPE(param1)) {
    SDataType t = {.type = type, .bytes = tDataTypes[type].bytes};
    paramOut1->numOfRows = param1->numOfRows;

    paramOut1->columnData = createColumnInfoData(&t, param1->numOfRows);
    if (paramOut1->columnData == NULL) {
      return terrno;
D
dapan1121 已提交
468
    }
469

D
dapan1121 已提交
470 471
    code = vectorConvertImpl(param1, paramOut1);
    if (code) {
H
Haojun Liao 已提交
472
//      taosMemoryFreeClear(paramOut1->data);
D
dapan1121 已提交
473 474 475 476
      return code;
    }
  }
  
477 478 479 480 481 482 483 484 485
  if (type != GET_PARAM_TYPE(param2)) {
    SDataType t = {.type = type, .bytes = tDataTypes[type].bytes};
    paramOut2->numOfRows = param2->numOfRows;

    paramOut2->columnData = createColumnInfoData(&t, param2->numOfRows);
    if (paramOut2->columnData == NULL) {
      return terrno;
    }

D
dapan1121 已提交
486 487 488 489 490 491 492 493 494
    code = vectorConvertImpl(param2, paramOut2);
    if (code) {
      return code;
    }
  }

  return TSDB_CODE_SUCCESS;
}

H
Haojun Liao 已提交
495 496 497 498 499 500
enum {
  VECTOR_DO_CONVERT = 0x1,
  VECTOR_UN_CONVERT = 0x2,
};

static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SScalarParam* pParam, int32_t type) {
501 502 503
  SColumnInfoData* pCol = pParam->columnData;

  if (IS_VAR_DATA_TYPE(pCol->info.type)) {
H
Haojun Liao 已提交
504
    pDest->numOfRows = pParam->numOfRows;
505 506

    SDataType t = {.type = type, .bytes = tDataTypes[type].bytes};
H
Haojun Liao 已提交
507 508
    pDest->columnData = createColumnInfoData(&t, pParam->numOfRows);
    if (pDest->columnData == NULL) {
509 510
      sclError("malloc %d failed", (int32_t)(pParam->numOfRows * sizeof(double)));
      return TSDB_CODE_OUT_OF_MEMORY;
D
dapan1121 已提交
511 512
    }

H
Haojun Liao 已提交
513
    int32_t code = vectorConvertImpl(pParam, pDest);
514 515
    if (code != TSDB_CODE_SUCCESS) {
      return code;
D
dapan1121 已提交
516
    }
517

H
Haojun Liao 已提交
518 519 520
    *convert = VECTOR_DO_CONVERT;
  } else {
    *convert = VECTOR_UN_CONVERT;
D
dapan1121 已提交
521
  }
522 523 524 525 526 527 528 529 530 531 532 533

  return TSDB_CODE_SUCCESS;
}

// TODO not correct for descending order scan
static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);

  double *output = (double *)pOutputCol->pData;

  if (colDataIsNull_f(pRightCol->nullbitmap, 0)) {  // Set pLeft->numOfRows NULL value
534
    colDataAppendNNULL(pOutputCol, 0, numOfRows);
535 536
  } else {
    for (; i >= 0 && i < numOfRows; i += step, output += 1) {
537
      *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, 0);
D
dapan1121 已提交
538
    }
539 540 541
    pOutputCol->hasNull = pLeftCol->hasNull;
    if (pOutputCol->hasNull) {
      memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
D
dapan1121 已提交
542 543
    }
  }
544
}
D
dapan1121 已提交
545

H
Haojun Liao 已提交
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert) {
  SScalarParam convertParam = {0};

  int32_t code = doConvertHelper(&convertParam, doConvert, pInput, TSDB_DATA_TYPE_DOUBLE);
  if (code != TSDB_CODE_SUCCESS) {
    terrno = code;
    return NULL;
  }

  if (*doConvert == VECTOR_DO_CONVERT) {
    return convertParam.columnData;
  } else {
    return pInput->columnData;
  }
}

static void doReleaseVec(SColumnInfoData* pCol, int32_t type) {
  if (type == VECTOR_DO_CONVERT) {
    colDataDestroy(pCol);
  }
}

568 569 570 571 572 573
void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;

  int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;

574 575
  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);

H
Haojun Liao 已提交
576 577 578
  int32_t leftConvert = 0, rightConvert = 0;
  SColumnInfoData *pLeftCol   = doVectorConvert(pLeft, &leftConvert);
  SColumnInfoData *pRightCol  = doVectorConvert(pRight, &rightConvert);
579

580 581 582 583 584 585
  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);

  double *output = (double *)pOutputCol->pData;
  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
586
      *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, i);
587 588 589 590 591 592 593
    }

    pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
    if (pOutputCol->hasNull) {
      int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
      for (int32_t j = 0; j < numOfBitLen; ++j) {
        pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
D
dapan1121 已提交
594
      }
595
    }
D
dapan1121 已提交
596

597 598 599 600 601
  } else if (pLeft->numOfRows == 1) {
    vectorMathAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
  } else if (pRight->numOfRows == 1) {
    vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
  }
H
Haojun Liao 已提交
602 603 604

  doReleaseVec(pLeftCol, leftConvert);
  doReleaseVec(pRightCol, rightConvert);
605
}
D
dapan1121 已提交
606

607 608 609 610 611 612 613 614
// TODO not correct for descending order scan
static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);

  double *output = (double *)pOutputCol->pData;

  if (colDataIsNull_f(pRightCol->nullbitmap, 0)) {  // Set pLeft->numOfRows NULL value
615
    colDataAppendNNULL(pOutputCol, 0, numOfRows);
616 617
  } else {
    for (; i >= 0 && i < numOfRows; i += step, output += 1) {
618
      *output = (getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, 0)) * factor;
D
dapan1121 已提交
619
    }
620 621 622 623 624 625
    pOutputCol->hasNull = pLeftCol->hasNull;
    if (pOutputCol->hasNull) {
      memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
    }
  }
}
D
dapan1121 已提交
626

627 628
void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;
D
dapan1121 已提交
629

630 631
  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);

632 633
  int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
D
dapan1121 已提交
634

H
Haojun Liao 已提交
635 636 637
  int32_t leftConvert = 0, rightConvert = 0;
  SColumnInfoData *pLeftCol   = doVectorConvert(pLeft, &leftConvert);
  SColumnInfoData *pRightCol  = doVectorConvert(pRight, &rightConvert);
638

639 640 641 642 643 644
  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);

  double *output = (double *)pOutputCol->pData;
  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
645
      *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, i);
D
dapan1121 已提交
646 647
    }

648 649 650 651 652
    pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
    if (pOutputCol->hasNull) {
      int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
      for (int32_t j = 0; j < numOfBitLen; ++j) {
        pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
D
dapan1121 已提交
653 654 655
      }
    }

656 657 658 659 660
  } else if (pLeft->numOfRows == 1) {
    vectorMathSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i);
  } else if (pRight->numOfRows == 1) {
    vectorMathSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
  }
H
Haojun Liao 已提交
661 662 663

  doReleaseVec(pLeftCol,  leftConvert);
  doReleaseVec(pRightCol, rightConvert);
D
dapan1121 已提交
664 665
}

666 667 668 669
// TODO not correct for descending order scan
static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
D
dapan1121 已提交
670

671
  double *output = (double *)pOutputCol->pData;
D
dapan1121 已提交
672

673
  if (colDataIsNull_f(pRightCol->nullbitmap, 0)) {  // Set pLeft->numOfRows NULL value
674
    colDataAppendNNULL(pOutputCol, 0, numOfRows);
675 676
  } else {
    for (; i >= 0 && i < numOfRows; i += step, output += 1) {
677
      *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, 0);
678 679 680 681 682 683
    }
    pOutputCol->hasNull = pLeftCol->hasNull;
    if (pOutputCol->hasNull) {
      memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
    }
  }
D
dapan1121 已提交
684 685
}

686 687
void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;
688
  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
689 690 691 692

  int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;

H
Haojun Liao 已提交
693 694 695
  int32_t leftConvert = 0, rightConvert = 0;
  SColumnInfoData *pLeftCol   = doVectorConvert(pLeft, &leftConvert);
  SColumnInfoData *pRightCol  = doVectorConvert(pRight, &rightConvert);
696 697 698 699 700 701 702

  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);

  double *output = (double *)pOutputCol->pData;
  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
703
      *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, i);
704 705 706 707 708 709 710 711 712 713 714 715 716 717
    }

    pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
    if (pOutputCol->hasNull) {
      int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
      for (int32_t j = 0; j < numOfBitLen; ++j) {
        pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
      }
    }

  } else if (pLeft->numOfRows == 1) {
    vectorMathMultiplyHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
  } else if (pRight->numOfRows == 1) {
    vectorMathMultiplyHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
D
dapan1121 已提交
718
  }
H
Haojun Liao 已提交
719 720 721

  doReleaseVec(pLeftCol, leftConvert);
  doReleaseVec(pRightCol, rightConvert);
D
dapan1121 已提交
722 723
}

724 725
void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;
726
  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
D
dapan1121 已提交
727

728 729 730
  int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;

H
Haojun Liao 已提交
731 732 733
  int32_t leftConvert = 0, rightConvert = 0;
  SColumnInfoData *pLeftCol  = doVectorConvert(pLeft, &leftConvert);
  SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
734

735 736 737 738 739 740
  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);

  double *output = (double *)pOutputCol->pData;
  if (pLeft->numOfRows == pRight->numOfRows) {  // check for the 0 value
    for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
741
      *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, i);
742 743 744 745 746 747 748 749 750 751 752 753
    }

    pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
    if (pOutputCol->hasNull) {
      int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
      for (int32_t j = 0; j < numOfBitLen; ++j) {
        pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
      }
    }

  } else if (pLeft->numOfRows == 1) {
    if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) {  // Set pLeft->numOfRows NULL value
754
      colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows);
755 756
    } else {
      for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) {
757
        *output = getVectorDoubleValueFnLeft(pLeftCol->pData, 0) / getVectorDoubleValueFnRight(pRightCol->pData, i);
758 759 760 761 762 763 764 765
      }
      pOutputCol->hasNull = pRightCol->hasNull;
      if (pOutputCol->hasNull) {
        memcpy(pOutputCol->nullbitmap, pRightCol->nullbitmap, BitmapLen(pRight->numOfRows));
      }
    }
  } else if (pRight->numOfRows == 1) {
    if (colDataIsNull_f(pRightCol->nullbitmap, 0)) {  // Set pLeft->numOfRows NULL value
766
      colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows);
767 768
    } else {
      for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) {
769
        *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, 0);
770 771 772 773 774 775 776
      }
      pOutputCol->hasNull = pLeftCol->hasNull;
      if (pOutputCol->hasNull) {
        memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(pLeft->numOfRows));
      }
    }
  }
H
Haojun Liao 已提交
777 778 779

  doReleaseVec(pLeftCol,  leftConvert);
  doReleaseVec(pRightCol, rightConvert);
D
dapan1121 已提交
780 781
}

782 783
void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;
784
  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
785 786 787

  int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
D
dapan1121 已提交
788

H
Haojun Liao 已提交
789 790 791
  int32_t leftConvert = 0, rightConvert = 0;
  SColumnInfoData *pLeftCol  = doVectorConvert(pLeft, &leftConvert);
  SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
792

793 794 795 796 797 798 799 800 801
  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);
  _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);

  double *output = (double *)pOutputCol->pData;
  double zero = 0.0;

  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
      if (colDataIsNull_f(pLeftCol->nullbitmap, i) || colDataIsNull_f(pRightCol->nullbitmap, i)) {
802
        colDataAppendNULL(pOutputCol, i);
803 804 805 806 807
        continue;
      }

      double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i);
      double rx = getVectorDoubleValueFnRight(pRightCol->pData, i);
H
Haojun Liao 已提交
808
      if (isnan(lx) || isinf(lx) || isnan(rx) || isinf(rx)) {
809
        colDataAppendNULL(pOutputCol, i);
810 811 812
        continue;
      }

813
      *output = lx - ((int64_t)(lx / rx)) * rx;
814 815 816
    }
  } else if (pLeft->numOfRows == 1) {
    double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, 0);
H
Haojun Liao 已提交
817
    if (colDataIsNull_f(pLeftCol->nullbitmap, 0) || isnan(lx) || isinf(lx)) {  // Set pLeft->numOfRows NULL value
818
      colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows);
819 820 821
    } else {
      for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) {
        if (colDataIsNull_f(pRightCol->nullbitmap, i)) {
822
          colDataAppendNULL(pOutputCol, i);
823 824 825 826
          continue;
        }

        double rx = getVectorDoubleValueFnRight(pRightCol->pData, i);
H
Haojun Liao 已提交
827
        if (isnan(rx) || isinf(rx) || FLT_EQUAL(rx, 0)) {
828
          colDataAppendNULL(pOutputCol, i);
829 830 831
          continue;
        }

832
        *output = lx - ((int64_t)(lx / rx)) * rx;
833 834 835 836
      }
    }
  } else if (pRight->numOfRows == 1) {
    double rx = getVectorDoubleValueFnRight(pRightCol->pData, 0);
H
Haojun Liao 已提交
837
    if (colDataIsNull_f(pRightCol->nullbitmap, 0) || FLT_EQUAL(rx, 0)) {  // Set pLeft->numOfRows NULL value
838
      colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows);
839 840
    } else {
      for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) {
H
Haojun Liao 已提交
841
        if (colDataIsNull_f(pLeftCol->nullbitmap, i)) {
842
          colDataAppendNULL(pOutputCol, i);
843 844 845
          continue;
        }

H
Haojun Liao 已提交
846 847
        double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i);
        if (isnan(lx) || isinf(lx)) {
848
          colDataAppendNULL(pOutputCol, i);
849 850 851
          continue;
        }

852
        *output = lx - ((int64_t)(lx / rx)) * rx;
853 854 855
      }
    }
  }
H
Haojun Liao 已提交
856 857 858

  doReleaseVec(pLeftCol, leftConvert);
  doReleaseVec(pRightCol, rightConvert);
859 860
}

D
dapan1121 已提交
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;

  pOut->numOfRows = pLeft->numOfRows;

  int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : (pLeft->numOfRows - 1);
  int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;

  int32_t leftConvert = 0;
  SColumnInfoData *pLeftCol   = doVectorConvert(pLeft, &leftConvert);

  _getDoubleValue_fn_t getVectorDoubleValueFnLeft  = getVectorDoubleValueFn(pLeftCol->info.type);

  double *output = (double *)pOutputCol->pData;
  for (; i < pLeft->numOfRows && i >= 0; i += step, output += 1) {
    *output = - getVectorDoubleValueFnLeft(pLeftCol->pData, i);
  }

  pOutputCol->hasNull = pLeftCol->hasNull;
  if (pOutputCol->hasNull) {
    memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(pLeft->numOfRows));
  }

  doReleaseVec(pLeftCol,  leftConvert);
}

D
dapan1121 已提交
887
void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
888
#if 0
889 890
  int32_t len = pLeft->bytes + pRight->bytes;

891
  int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
892 893 894
  int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;

  char *output = (char *)out;
895 896
  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step, output += len) {
897 898 899
      char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i);
      char* right = POINTER_SHIFT(pRight->data, pRight->bytes * i);

H
Haojun Liao 已提交
900
      if (isNull(left, pLeftCol->info.type) || isNull(right, pRight->info.type)) {
901 902 903 904 905 906 907 908 909
        setVardataNull(output, TSDB_DATA_TYPE_BINARY);
        continue;
      }

      // todo define a macro
      memcpy(varDataVal(output), varDataVal(left), varDataLen(left));
      memcpy(varDataVal(output) + varDataLen(left), varDataVal(right), varDataLen(right));
      varDataSetLen(output, varDataLen(left) + varDataLen(right));
    }
910 911
  } else if (pLeft->numOfRows == 1) {
    for (; i >= 0 && i < pRight->numOfRows; i += step, output += len) {
912
      char *right = POINTER_SHIFT(pRight->data, pRight->bytes * i);
H
Haojun Liao 已提交
913
      if (isNull(pLeft->data, pLeftCol->info.type) || isNull(right, pRight->info.type)) {
914 915 916 917 918 919 920 921
        setVardataNull(output, TSDB_DATA_TYPE_BINARY);
        continue;
      }

      memcpy(varDataVal(output), varDataVal(pLeft->data), varDataLen(pLeft->data));
      memcpy(varDataVal(output) + varDataLen(pLeft->data), varDataVal(right), varDataLen(right));
      varDataSetLen(output, varDataLen(pLeft->data) + varDataLen(right));
    }
922 923
  } else if (pRight->numOfRows == 1) {
    for (; i >= 0 && i < pLeft->numOfRows; i += step, output += len) {
924
      char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i);
H
Haojun Liao 已提交
925
      if (isNull(left, pLeftCol->info.type) || isNull(pRight->data, pRight->info.type)) {
926 927 928 929 930 931 932 933 934
        SET_DOUBLE_NULL(output);
        continue;
      }

      memcpy(varDataVal(output), varDataVal(left), varDataLen(pRight->data));
      memcpy(varDataVal(output) + varDataLen(left), varDataVal(pRight->data), varDataLen(pRight->data));
      varDataSetLen(output, varDataLen(left) + varDataLen(pRight->data));
    }
  }
935
#endif
936 937
}

938 939 940
static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
  _getBigintValue_fn_t getVectorBigintValueFnLeft  = getVectorBigintValueFn(pLeftCol->info.type);
  _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
D
dapan1121 已提交
941

942
  double *output = (double *)pOutputCol->pData;
D
dapan1121 已提交
943

944
  if (colDataIsNull_f(pRightCol->nullbitmap, 0)) {  // Set pLeft->numOfRows NULL value
945
    colDataAppendNNULL(pOutputCol, 0, numOfRows);
946 947
  } else {
    for (; i >= 0 && i < numOfRows; i += step, output += 1) {
948
      *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, 0);
D
dapan1121 已提交
949
    }
950 951 952
    pOutputCol->hasNull = pLeftCol->hasNull;
    if (pOutputCol->hasNull) {
      memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
D
dapan1121 已提交
953 954
    }
  }
955
}
D
dapan1121 已提交
956

957 958
void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;
959
  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
D
dapan 已提交
960

961 962
  int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
D
dapan1121 已提交
963

H
Haojun Liao 已提交
964 965 966
  int32_t leftConvert = 0, rightConvert = 0;
  SColumnInfoData *pLeftCol   = doVectorConvert(pLeft, &leftConvert);
  SColumnInfoData *pRightCol  = doVectorConvert(pRight, &rightConvert);
D
dapan1121 已提交
967

H
Haojun Liao 已提交
968 969
  _getBigintValue_fn_t getVectorBigintValueFnLeft  = getVectorBigintValueFn(pLeftCol->info.type);
  _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
D
dapan1121 已提交
970

971 972 973
  int64_t *output = (int64_t *)pOutputCol->pData;
  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
974
      *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, i);
D
dapan1121 已提交
975
    }
D
dapan1121 已提交
976

977 978 979 980 981 982
    pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
    if (pOutputCol->hasNull) {
      int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
      for (int32_t j = 0; j < numOfBitLen; ++j) {
        pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] & pRightCol->nullbitmap[j];
      }
D
dapan1121 已提交
983
    }
D
dapan1121 已提交
984

985 986 987 988 989
  } else if (pLeft->numOfRows == 1) {
    vectorBitAndHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
  } else if (pRight->numOfRows == 1) {
    vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
  }
H
Haojun Liao 已提交
990 991 992

  doReleaseVec(pLeftCol,  leftConvert);
  doReleaseVec(pRightCol, rightConvert);
D
dapan1121 已提交
993 994
}

995 996 997
static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
  _getBigintValue_fn_t getVectorBigintValueFnLeft  = getVectorBigintValueFn(pLeftCol->info.type);
  _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
D
dapan1121 已提交
998

999
  int64_t *output = (int64_t *)pOutputCol->pData;
D
dapan1121 已提交
1000

1001
  if (colDataIsNull_f(pRightCol->nullbitmap, 0)) {  // Set pLeft->numOfRows NULL value
1002
    colDataAppendNNULL(pOutputCol, 0, numOfRows);
1003
  } else {
1004
    int64_t rx = getVectorBigintValueFnRight(pRightCol->pData, 0);
1005
    for (; i >= 0 && i < numOfRows; i += step, output += 1) {
1006
      *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) | rx;
D
dapan1121 已提交
1007
    }
1008 1009 1010
    pOutputCol->hasNull = pLeftCol->hasNull;
    if (pOutputCol->hasNull) {
      memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
D
dapan1121 已提交
1011 1012
    }
  }
1013
}
D
dapan1121 已提交
1014

1015 1016
void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  SColumnInfoData *pOutputCol = pOut->columnData;
1017
  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
D
dapan1121 已提交
1018

1019 1020
  int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
D
dapan1121 已提交
1021

H
Haojun Liao 已提交
1022 1023 1024
  int32_t leftConvert = 0, rightConvert = 0;
  SColumnInfoData *pLeftCol   = doVectorConvert(pLeft, &leftConvert);
  SColumnInfoData *pRightCol  = doVectorConvert(pRight, &rightConvert);
D
dapan1121 已提交
1025

H
Haojun Liao 已提交
1026 1027
  _getBigintValue_fn_t getVectorBigintValueFnLeft  = getVectorBigintValueFn(pLeftCol->info.type);
  _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
D
dapan 已提交
1028

1029 1030 1031
  int64_t *output = (int64_t *)pOutputCol->pData;
  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
1032
      *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) | getVectorBigintValueFnRight(pRightCol->pData, i);
1033
    }
D
dapan1121 已提交
1034

1035 1036 1037 1038 1039 1040
    pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
    if (pOutputCol->hasNull) {
      int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
      for (int32_t j = 0; j < numOfBitLen; ++j) {
        pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
      }
D
dapan1121 已提交
1041
    }
1042 1043 1044 1045
  } else if (pLeft->numOfRows == 1) {
    vectorBitOrHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
  } else if (pRight->numOfRows == 1) {
    vectorBitOrHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
D
dapan1121 已提交
1046
  }
H
Haojun Liao 已提交
1047 1048 1049

  doReleaseVec(pLeftCol,  leftConvert);
  doReleaseVec(pRightCol, rightConvert);
D
dapan1121 已提交
1050 1051
}

1052 1053 1054 1055 1056 1057 1058 1059 1060
void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
  int32_t       i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
  int32_t       step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
  __compar_fn_t fp = filterGetCompFunc(GET_PARAM_TYPE(pLeft), optr);

  pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);

  if (pRight->pHashFilter != NULL) {
    for (; i >= 0 && i < pLeft->numOfRows; i += step) {
1061
      if (colDataIsNull_s(pLeft->columnData, i)) {
D
dapan1121 已提交
1062 1063 1064
        continue;
      }

1065 1066
      char *pLeftData = colDataGetData(pLeft->columnData, i);
      bool  res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter);
1067
      colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
1068
    }
1069
    return;
1070
  }
D
dapan 已提交
1071

1072 1073
  if (pLeft->numOfRows == pRight->numOfRows) {
    for (; i < pRight->numOfRows && i >= 0; i += step) {
1074
      if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) {
1075
        continue;  // TODO set null or ignore
D
dapan1121 已提交
1076 1077
      }

1078
      char *pLeftData = colDataGetData(pLeft->columnData, i);
1079
      char *pRightData = colDataGetData(pRight->columnData, i);
1080
      bool  res = filterDoCompare(fp, optr, pLeftData, pRightData);
1081
      colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
D
dapan1121 已提交
1082
    }
1083
  } else if (pRight->numOfRows == 1) {
1084 1085 1086 1087
    char *pRightData = colDataGetData(pRight->columnData, 0);
    ASSERT(pLeft->pHashFilter == NULL);

    for (; i >= 0 && i < pLeft->numOfRows; i += step) {
1088
      if (colDataIsNull_s(pLeft->columnData, i)) {
1089 1090 1091 1092 1093
        continue;
      }

      char *pLeftData = colDataGetData(pLeft->columnData, i);
      bool  res = filterDoCompare(fp, optr, pLeftData, pRightData);
1094
      colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
1095 1096 1097 1098
    }
  } else if (pLeft->numOfRows == 1) {
    char *pLeftData = colDataGetData(pLeft->columnData, 0);
    for (; i >= 0 && i < pRight->numOfRows; i += step) {
1099
      if (colDataIsNull_s(pRight->columnData, i)) {
1100 1101 1102 1103 1104
        continue;
      }

      char *pRightData = colDataGetData(pLeft->columnData, i);
      bool  res = filterDoCompare(fp, optr, pLeftData, pRightData);
1105
      colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
1106
    }
D
dapan1121 已提交
1107 1108 1109
  }
}

D
dapan 已提交
1110
void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
D
dapan1121 已提交
1111 1112
  SScalarParam pLeftOut = {0}; 
  SScalarParam pRightOut = {0};
D
dapan1121 已提交
1113 1114 1115
  
  vectorConvert(pLeft, pRight, &pLeftOut, &pRightOut);

D
dapan1121 已提交
1116 1117
  SScalarParam *param1 = NULL; 
  SScalarParam *param2 = NULL;
D
dapan1121 已提交
1118

1119
  if (pLeftOut.columnData != NULL) {
D
dapan1121 已提交
1120 1121 1122 1123 1124
    param1 = &pLeftOut;
  } else {
    param1 = pLeft;
  }

1125
  if (pRightOut.columnData != NULL) {
D
dapan1121 已提交
1126 1127 1128 1129 1130
    param2 = &pRightOut;
  } else {
    param2 = pRight;
  }

D
dapan 已提交
1131
  vectorCompareImpl(param1, param2, pOut, _ord, optr);
D
dapan1121 已提交
1132 1133
  sclFreeParam(&pLeftOut);
  sclFreeParam(&pRightOut);  
D
dapan1121 已提交
1134 1135
}

D
dapan 已提交
1136 1137
void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_THAN);
D
dapan1121 已提交
1138 1139
}

D
dapan 已提交
1140 1141
void vectorGreaterEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_EQUAL);
D
dapan1121 已提交
1142 1143
}

D
dapan 已提交
1144 1145
void vectorLower(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_THAN);
D
dapan1121 已提交
1146 1147
}

D
dapan 已提交
1148 1149
void vectorLowerEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_EQUAL);
D
dapan1121 已提交
1150 1151
}

D
dapan 已提交
1152 1153
void vectorEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_EQUAL);
D
dapan1121 已提交
1154 1155
}

D
dapan 已提交
1156 1157
void vectorNotEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_EQUAL);
D
dapan1121 已提交
1158 1159
}

D
dapan 已提交
1160 1161
void vectorIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_IN);
D
dapan1121 已提交
1162 1163
}

D
dapan 已提交
1164 1165
void vectorNotIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_IN);
D
dapan1121 已提交
1166 1167
}

D
dapan 已提交
1168 1169
void vectorLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LIKE);
D
dapan1121 已提交
1170 1171
}

D
dapan 已提交
1172 1173
void vectorNotLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_LIKE);
D
dapan1121 已提交
1174 1175
}

D
dapan 已提交
1176 1177
void vectorMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_MATCH);
D
dapan1121 已提交
1178 1179
}

D
dapan 已提交
1180 1181
void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH);
D
dapan1121 已提交
1182 1183
}

D
dapan 已提交
1184
void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
1185
  for(int32_t i = 0; i < pLeft->numOfRows; ++i) {
1186 1187
    int8_t v = colDataIsNull_s(pLeft->columnData, i)? 1:0;
    colDataAppendInt8(pOut->columnData, i, &v);
D
dapan1121 已提交
1188
  }
1189
  pOut->numOfRows = pLeft->numOfRows;
D
dapan1121 已提交
1190 1191
}

D
dapan 已提交
1192
void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
1193
  for(int32_t i = 0; i < pLeft->numOfRows; ++i) {
1194 1195
    int8_t v = colDataIsNull_s(pLeft->columnData, i)? 0:1;
    colDataAppendInt8(pOut->columnData, i, &v);
D
dapan1121 已提交
1196
  }
1197
  pOut->numOfRows = pLeft->numOfRows;
D
dapan 已提交
1198
}
D
dapan1121 已提交
1199

D
dapan 已提交
1200 1201
void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
  vectorConvertImpl(pLeft, pOut);
D
dapan1121 已提交
1202 1203
}

1204 1205
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
  switch (binFunctionId) {
D
dapan1121 已提交
1206
    case OP_TYPE_ADD:
1207
      return vectorMathAdd;
D
dapan1121 已提交
1208
    case OP_TYPE_SUB:
1209
      return vectorMathSub;
D
dapan1121 已提交
1210
    case OP_TYPE_MULTI:
1211
      return vectorMathMultiply;
D
dapan1121 已提交
1212
    case OP_TYPE_DIV:
1213
      return vectorMathDivide;
D
dapan1121 已提交
1214
    case OP_TYPE_MOD:
1215
      return vectorMathRemainder;
D
dapan1121 已提交
1216 1217
    case OP_TYPE_MINUS:
      return vectorMathMinus;
D
dapan1121 已提交
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
    case OP_TYPE_GREATER_THAN:
      return vectorGreater;
    case OP_TYPE_GREATER_EQUAL:
      return vectorGreaterEqual;
    case OP_TYPE_LOWER_THAN:
      return vectorLower;
    case OP_TYPE_LOWER_EQUAL:
      return vectorLowerEqual;
    case OP_TYPE_EQUAL:
      return vectorEqual;
    case OP_TYPE_NOT_EQUAL:
      return vectorNotEqual;
    case OP_TYPE_IN:
      return vectorIn;
    case OP_TYPE_NOT_IN:
      return vectorNotIn;
    case OP_TYPE_LIKE:
      return vectorLike;
    case OP_TYPE_NOT_LIKE:
      return vectorNotLike;
    case OP_TYPE_MATCH:
      return vectorMatch;
    case OP_TYPE_NMATCH:
      return vectorNotMatch;
D
dapan1121 已提交
1242
    case OP_TYPE_IS_NULL:
D
dapan1121 已提交
1243
      return vectorIsNull;
D
dapan1121 已提交
1244
    case OP_TYPE_IS_NOT_NULL:
D
dapan1121 已提交
1245 1246 1247 1248 1249
      return vectorNotNull;
    case OP_TYPE_BIT_AND:
      return vectorBitAnd;
    case OP_TYPE_BIT_OR:
      return vectorBitOr;
D
dapan1121 已提交
1250 1251
    case OP_TYPE_IS_TRUE:
      return vectorIsTrue;
1252 1253 1254 1255
    default:
      assert(0);
      return NULL;
  }
D
dapan1121 已提交
1256
}