[td-10564] support unary scalar function.
This commit is contained in:
parent
bc82a32ba2
commit
5921993336
|
@ -20,7 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tdef.h"
|
||||
#include "taos.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define COMP_OVERFLOW_BYTES 2
|
||||
|
|
|
@ -134,6 +134,13 @@ do { \
|
|||
#define TSDB_BINARY_OP_REMAINDER 4004
|
||||
#define TSDB_BINARY_OP_CONCAT 4005
|
||||
|
||||
#define TSDB_UNARY_OP_CEIL 4500
|
||||
#define TSDB_UNARY_OP_FLOOR 4501
|
||||
#define TSDB_UNARY_OP_ABS 4502
|
||||
#define TSDB_UNARY_OP_ROUND 4503
|
||||
|
||||
#define TSDB_UNARY_OP_LEN 4600
|
||||
|
||||
|
||||
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
|
||||
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER))
|
||||
|
@ -366,21 +373,6 @@ do { \
|
|||
#define TSDB_MAX_DISKS_PER_TIER 16
|
||||
#define TSDB_MAX_DISKS (TSDB_MAX_TIERS * TSDB_MAX_DISKS_PER_TIER)
|
||||
|
||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
||||
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||
|
||||
enum { TRANS_STAT_INIT = 0, TRANS_STAT_EXECUTING, TRANS_STAT_EXECUTED, TRANS_STAT_ROLLBACKING, TRANS_STAT_ROLLBACKED };
|
||||
enum { TRANS_OPER_INIT = 0, TRANS_OPER_EXECUTE, TRANS_OPER_ROLLBACK };
|
||||
|
|
|
@ -21,7 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "os.h"
|
||||
//#include "tdef.h"
|
||||
#include "taos.h"
|
||||
#include "tarray.h"
|
||||
#include "tfunctional.h"
|
||||
|
||||
|
|
|
@ -1,411 +0,0 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
#include "ttypes.h"
|
||||
#include "tarithoperator.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
//GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[i]));
|
||||
|
||||
void calc_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRight, void *output, int32_t order) {
|
||||
int32_t *pLeft = (int32_t *)left;
|
||||
int32_t *pRight = (int32_t *)right;
|
||||
double * pOutput = (double *)output;
|
||||
|
||||
int32_t i = (order == TSDB_ORDER_ASC) ? 0 : MAX(numLeft, numRight) - 1;
|
||||
int32_t step = (order == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += 1) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
SET_DOUBLE_NULL(pOutput);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] + pRight[i];
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += 1) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
SET_DOUBLE_NULL(pOutput);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[0] + pRight[i];
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += 1) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
SET_DOUBLE_NULL(pOutput);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[i] + pRight[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef double (*_arithmetic_getVectorDoubleValue_fn_t)(void *src, int32_t index);
|
||||
|
||||
double getVectorDoubleValue_TINYINT(void *src, int32_t index) {
|
||||
return (double)*((int8_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_UTINYINT(void *src, int32_t index) {
|
||||
return (double)*((uint8_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_SMALLINT(void *src, int32_t index) {
|
||||
return (double)*((int16_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_USMALLINT(void *src, int32_t index) {
|
||||
return (double)*((uint16_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_INT(void *src, int32_t index) {
|
||||
return (double)*((int32_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_UINT(void *src, int32_t index) {
|
||||
return (double)*((uint32_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_BIGINT(void *src, int32_t index) {
|
||||
return (double)*((int64_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_UBIGINT(void *src, int32_t index) {
|
||||
return (double)*((uint64_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_FLOAT(void *src, int32_t index) {
|
||||
return (double)*((float *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_DOUBLE(void *src, int32_t index) {
|
||||
return (double)*((double *)src + index);
|
||||
}
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) {
|
||||
_arithmetic_getVectorDoubleValue_fn_t p = NULL;
|
||||
if(srcType==TSDB_DATA_TYPE_TINYINT) {
|
||||
p = getVectorDoubleValue_TINYINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_UTINYINT) {
|
||||
p = getVectorDoubleValue_UTINYINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_SMALLINT) {
|
||||
p = getVectorDoubleValue_SMALLINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_USMALLINT) {
|
||||
p = getVectorDoubleValue_USMALLINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_INT) {
|
||||
p = getVectorDoubleValue_INT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_UINT) {
|
||||
p = getVectorDoubleValue_UINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_BIGINT) {
|
||||
p = getVectorDoubleValue_BIGINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_UBIGINT) {
|
||||
p = getVectorDoubleValue_UBIGINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_FLOAT) {
|
||||
p = getVectorDoubleValue_FLOAT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
|
||||
p = getVectorDoubleValue_DOUBLE;
|
||||
}else {
|
||||
assert(0);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
typedef void* (*_arithmetic_getVectorValueAddr_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);
|
||||
}
|
||||
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
|
||||
_arithmetic_getVectorValueAddr_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;
|
||||
}else {
|
||||
assert(0);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void vectorAdd(void *left, int32_t len1, int32_t _left_type, void *right, int32_t len2, int32_t _right_type, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
double *output=(double*)out;
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(_left_type);
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(_right_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(_left_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(_right_type);
|
||||
|
||||
if ((len1) == (len2)) {
|
||||
for (; i < (len2) && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) + getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len1) == 1) {
|
||||
for (; i >= 0 && i < (len2); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,0), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,0) + getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len2) == 1) {
|
||||
for (; i >= 0 && i < (len1); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,0), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) + getVectorDoubleValueFnRight(right,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
void vectorSub(void *left, int32_t len1, int32_t _left_type, void *right, int32_t len2, int32_t _right_type, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
double *output=(double*)out;
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(_left_type);
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(_right_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(_left_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(_right_type);
|
||||
|
||||
if ((len1) == (len2)) {
|
||||
for (; i < (len2) && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) - getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len1) == 1) {
|
||||
for (; i >= 0 && i < (len2); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,0), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,0) - getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len2) == 1) {
|
||||
for (; i >= 0 && i < (len1); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,0), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) - getVectorDoubleValueFnRight(right,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
void vectorMultiply(void *left, int32_t len1, int32_t _left_type, void *right, int32_t len2, int32_t _right_type, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
double *output=(double*)out;
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(_left_type);
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(_right_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(_left_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(_right_type);
|
||||
|
||||
if ((len1) == (len2)) {
|
||||
for (; i < (len2) && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) * getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len1) == 1) {
|
||||
for (; i >= 0 && i < (len2); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,0), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,0) * getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len2) == 1) {
|
||||
for (; i >= 0 && i < (len1); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,0), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) * getVectorDoubleValueFnRight(right,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
void vectorDivide(void *left, int32_t len1, int32_t _left_type, void *right, int32_t len2, int32_t _right_type, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
double *output=(double*)out;
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(_left_type);
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(_right_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(_left_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(_right_type);
|
||||
|
||||
if ((len1) == (len2)) {
|
||||
for (; i < (len2) && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, _right_type, getVectorValueAddrFnRight(right,i));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) /getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len1) == 1) {
|
||||
for (; i >= 0 && i < (len2); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,0), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, _right_type, getVectorValueAddrFnRight(right,i));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,0) /getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len2) == 1) {
|
||||
for (; i >= 0 && i < (len1); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,0), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, _right_type, getVectorValueAddrFnRight(right,0));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) /getVectorDoubleValueFnRight(right,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
void vectorRemainder(void *left, int32_t len1, int32_t _left_type, void *right, int32_t len2, int32_t _right_type, void *out, int32_t _ord) {
|
||||
int32_t i = (_ord == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1;
|
||||
int32_t step = (_ord == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
double *output=(double*)out;
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(_left_type);
|
||||
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(_right_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(_left_type);
|
||||
_arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(_right_type);
|
||||
|
||||
if (len1 == (len2)) {
|
||||
for (; i >= 0 && i < (len2); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, _right_type, getVectorValueAddrFnRight(right,i));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) - ((int64_t)(getVectorDoubleValueFnLeft(left,i) / getVectorDoubleValueFnRight(right,i))) * getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if (len1 == 1) {
|
||||
for (; i >= 0 && i < (len2); i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,0), _left_type) || isNull(getVectorValueAddrFnRight(right,i), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, _right_type, getVectorValueAddrFnRight(right,i));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,0) - ((int64_t)(getVectorDoubleValueFnLeft(left,0) / getVectorDoubleValueFnRight(right,i))) * getVectorDoubleValueFnRight(right,i));
|
||||
}
|
||||
} else if ((len2) == 1) {
|
||||
for (; i >= 0 && i < len1; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(left,i), _left_type) || isNull(getVectorValueAddrFnRight(right,0), _right_type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, _right_type, getVectorValueAddrFnRight(right,0));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(left,i) - ((int64_t)(getVectorDoubleValueFnLeft(left,i) / getVectorDoubleValueFnRight(right,0))) * getVectorDoubleValueFnRight(right,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr) {
|
||||
switch (arithmeticOptr) {
|
||||
case TSDB_BINARY_OP_ADD:
|
||||
return vectorAdd;
|
||||
case TSDB_BINARY_OP_SUBTRACT:
|
||||
return vectorSub;
|
||||
case TSDB_BINARY_OP_MULTIPLY:
|
||||
return vectorMultiply;
|
||||
case TSDB_BINARY_OP_DIVIDE:
|
||||
return vectorDivide;
|
||||
case TSDB_BINARY_OP_REMAINDER:
|
||||
return vectorRemainder;
|
||||
default:
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
}
|
|
@ -13,20 +13,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_COMMON_QARITHMETICOPERATOR_H_
|
||||
#define _TD_COMMON_QARITHMETICOPERATOR_H_
|
||||
#ifndef _TD_COMMON_BIN_SCALAR_OPERATOR_H_
|
||||
#define _TD_COMMON_BIN_SCALAR_OPERATOR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t leftType, void *right, int32_t numRight,
|
||||
int32_t rightType, void *output, int32_t order);
|
||||
#include "tscalarfunction.h"
|
||||
|
||||
_arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr);
|
||||
typedef void (*_bin_scalar_fn_t)(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *output, int32_t order);
|
||||
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_QARITHMETICOPERATOR_H_*/
|
||||
#endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/
|
|
@ -65,9 +65,6 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond);
|
|||
|
||||
bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param);
|
||||
|
||||
void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*cb)(void *, const char*, int32_t));
|
||||
|
||||
void buildFilterSetFromBinary(void **q, const char *buf, int32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -21,14 +21,22 @@ extern "C" {
|
|||
|
||||
#include "function.h"
|
||||
|
||||
typedef struct SScalarFuncParam {
|
||||
void* data;
|
||||
int32_t num;
|
||||
int32_t type;
|
||||
int32_t bytes;
|
||||
} SScalarFuncParam;
|
||||
|
||||
extern struct SScalarFunctionInfo scalarFunc[1];
|
||||
|
||||
#define FUNCTION_CEIL 38
|
||||
#define FUNCTION_FLOOR 39
|
||||
#define FUNCTION_ROUND 40
|
||||
#define FUNCTION_MAVG 41
|
||||
#define FUNCTION_CSUM 42
|
||||
#define FUNCCTION_CONCAT 43
|
||||
#define FUNCTION_CONCAT 41
|
||||
|
||||
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput,
|
||||
void* param, char* (*getSourceDataBlock)(void*, const char*, int32_t));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_COMMON_UNARY_SCALAR_OPERATOR_H_
|
||||
#define _TD_COMMON_UNARY_SCALAR_OPERATOR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tscalarfunction.h"
|
||||
|
||||
typedef void (*_unary_scalar_fn_t)(SScalarFuncParam *pLeft, SScalarFuncParam* pOutput);
|
||||
_unary_scalar_fn_t getUnaryScalarOperatorFn(int32_t binOperator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/
|
|
@ -3197,7 +3197,7 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
|
|||
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
|
||||
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
||||
|
||||
// arithmeticTreeTraverse(sas->pExprInfo->pExpr, pCtx->size, pCtx->pOutput, sas, pCtx->order, getArithColumnData);
|
||||
// evaluateExprNodeTree(sas->pExprInfo->pExpr, pCtx->size, pCtx->pOutput, sas, pCtx->order, getArithColumnData);
|
||||
}
|
||||
|
||||
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
|
||||
|
|
|
@ -0,0 +1,484 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
#include "ttypes.h"
|
||||
#include "tbinoperator.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
//GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i]));
|
||||
|
||||
void calc_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRight, void *output, int32_t order) {
|
||||
int32_t *pLeft = (int32_t *)left;
|
||||
int32_t *pRight = (int32_t *)right;
|
||||
double * pOutput = (double *)output;
|
||||
|
||||
int32_t i = (order == TSDB_ORDER_ASC) ? 0 : MAX(numLeft, numRight) - 1;
|
||||
int32_t step = (order == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
if (numLeft == numRight) {
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += 1) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
SET_DOUBLE_NULL(pOutput);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[i] + pRight[i];
|
||||
}
|
||||
} else if (numLeft == 1) {
|
||||
for (; i >= 0 && i < numRight; i += step, pOutput += 1) {
|
||||
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
|
||||
SET_DOUBLE_NULL(pOutput);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pOutput = (double)pLeft[0] + pRight[i];
|
||||
}
|
||||
} else if (numRight == 1) {
|
||||
for (; i >= 0 && i < numLeft; i += step, pOutput += 1) {
|
||||
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
|
||||
SET_DOUBLE_NULL(pOutput);
|
||||
continue;
|
||||
}
|
||||
*pOutput = (double)pLeft[i] + pRight[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef double (*_getDoubleValue_fn_t)(void *src, int32_t index);
|
||||
|
||||
double getVectorDoubleValue_TINYINT(void *src, int32_t index) {
|
||||
return (double)*((int8_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_UTINYINT(void *src, int32_t index) {
|
||||
return (double)*((uint8_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_SMALLINT(void *src, int32_t index) {
|
||||
return (double)*((int16_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_USMALLINT(void *src, int32_t index) {
|
||||
return (double)*((uint16_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_INT(void *src, int32_t index) {
|
||||
return (double)*((int32_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_UINT(void *src, int32_t index) {
|
||||
return (double)*((uint32_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_BIGINT(void *src, int32_t index) {
|
||||
return (double)*((int64_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_UBIGINT(void *src, int32_t index) {
|
||||
return (double)*((uint64_t *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_FLOAT(void *src, int32_t index) {
|
||||
return (double)*((float *)src + index);
|
||||
}
|
||||
double getVectorDoubleValue_DOUBLE(void *src, int32_t index) {
|
||||
return (double)*((double *)src + index);
|
||||
}
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) {
|
||||
_getDoubleValue_fn_t p = NULL;
|
||||
if(srcType==TSDB_DATA_TYPE_TINYINT) {
|
||||
p = getVectorDoubleValue_TINYINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_UTINYINT) {
|
||||
p = getVectorDoubleValue_UTINYINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_SMALLINT) {
|
||||
p = getVectorDoubleValue_SMALLINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_USMALLINT) {
|
||||
p = getVectorDoubleValue_USMALLINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_INT) {
|
||||
p = getVectorDoubleValue_INT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_UINT) {
|
||||
p = getVectorDoubleValue_UINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_BIGINT) {
|
||||
p = getVectorDoubleValue_BIGINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_UBIGINT) {
|
||||
p = getVectorDoubleValue_UBIGINT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_FLOAT) {
|
||||
p = getVectorDoubleValue_FLOAT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
|
||||
p = getVectorDoubleValue_DOUBLE;
|
||||
}else {
|
||||
assert(0);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
_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;
|
||||
}else {
|
||||
assert(0);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void vectorAdd(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type);
|
||||
|
||||
if (pLeft->num == pRight->num) {
|
||||
for (; i < pRight->num && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) + getVectorDoubleValueFnRight(pRight->data, i));
|
||||
}
|
||||
} else if (pLeft->num == 1) {
|
||||
for (; i >= 0 && i < pRight->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data, 0) + getVectorDoubleValueFnRight(pRight->data,i));
|
||||
}
|
||||
} else if (pRight->num == 1) {
|
||||
for (; i >= 0 && i < pLeft->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) + getVectorDoubleValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vectorSub(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type);
|
||||
|
||||
if (pLeft->num == pRight->num) {
|
||||
for (; i < pRight->num && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) - getVectorDoubleValueFnRight(pRight->data, i));
|
||||
}
|
||||
} else if (pLeft->num == 1) {
|
||||
for (; i >= 0 && i < pRight->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data, 0) - getVectorDoubleValueFnRight(pRight->data,i));
|
||||
}
|
||||
} else if (pRight->num == 1) {
|
||||
for (; i >= 0 && i < pLeft->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) - getVectorDoubleValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
void vectorMultiply(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type);
|
||||
|
||||
if (pLeft->num == pRight->num) {
|
||||
for (; i < pRight->num && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) * getVectorDoubleValueFnRight(pRight->data, i));
|
||||
}
|
||||
} else if (pLeft->num == 1) {
|
||||
for (; i >= 0 && i < pRight->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data, 0) * getVectorDoubleValueFnRight(pRight->data,i));
|
||||
}
|
||||
} else if (pRight->num == 1) {
|
||||
for (; i >= 0 && i < pLeft->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) * getVectorDoubleValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vectorDivide(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type);
|
||||
|
||||
if (pLeft->num == pRight->num) {
|
||||
for (; i < pRight->num && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) / getVectorDoubleValueFnRight(pRight->data, i));
|
||||
}
|
||||
} else if (pLeft->num == 1) {
|
||||
double left = getVectorDoubleValueFnLeft(pLeft->data, 0);
|
||||
|
||||
for (; i >= 0 && i < pRight->num; i += step, output += 1) {
|
||||
if (isNull(&left, pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
SET_DOUBLE_VAL(output,left / getVectorDoubleValueFnRight(pRight->data,i));
|
||||
}
|
||||
} else if (pRight->num == 1) {
|
||||
double right = getVectorDoubleValueFnRight(pRight->data, 0);
|
||||
|
||||
for (; i >= 0 && i < pLeft->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(&right, pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) / right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vectorRemainder(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
double * output = (double *)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type);
|
||||
|
||||
if (pLeft->num == pRight->num) {
|
||||
for (; i < pRight->num && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, pRight->type, getVectorValueAddrFnRight(pRight->data, i));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
double left = getVectorDoubleValueFnLeft(pLeft->data, i);
|
||||
double right = getVectorDoubleValueFnRight(pRight->data, i);
|
||||
SET_DOUBLE_VAL(output, left - ((int64_t)(left / right)) * right);
|
||||
}
|
||||
} else if (pLeft->num == 1) {
|
||||
double left = getVectorDoubleValueFnLeft(pLeft->data, 0);
|
||||
|
||||
for (; i >= 0 && i < pRight->num; i += step, output += 1) {
|
||||
if (isNull(&left, pLeft->type) ||
|
||||
isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, pRight->type, getVectorValueAddrFnRight(pRight->data, i));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
double right = getVectorDoubleValueFnRight(pRight->data, i);
|
||||
SET_DOUBLE_VAL(output, left - ((int64_t)(left / right)) * right);
|
||||
}
|
||||
} else if (pRight->num == 1) {
|
||||
double right = getVectorDoubleValueFnRight(pRight->data, 0);
|
||||
|
||||
for (; i >= 0 && i < pLeft->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(&right, pRight->type)) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v, u = 0.0;
|
||||
GET_TYPED_DATA(v, double, pRight->type, getVectorValueAddrFnRight(pRight->data, 0));
|
||||
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
|
||||
SET_DOUBLE_NULL(output);
|
||||
continue;
|
||||
}
|
||||
|
||||
double left = getVectorDoubleValueFnLeft(pLeft->data, i);
|
||||
SET_DOUBLE_VAL(output, left - ((int64_t)(left / right)) * right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vectorConcat(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t len = pLeft->bytes + pRight->bytes;
|
||||
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
char *output = (char *)out;
|
||||
if (pLeft->num == pRight->num) {
|
||||
for (; i < pRight->num && i >= 0; i += step, output += len) {
|
||||
char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i);
|
||||
char* right = POINTER_SHIFT(pRight->data, pRight->bytes * i);
|
||||
|
||||
if (isNull(left, pLeft->type) || isNull(right, pRight->type)) {
|
||||
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));
|
||||
}
|
||||
} else if (pLeft->num == 1) {
|
||||
for (; i >= 0 && i < pRight->num; i += step, output += len) {
|
||||
char *right = POINTER_SHIFT(pRight->data, pRight->bytes * i);
|
||||
if (isNull(pLeft->data, pLeft->type) || isNull(right, pRight->type)) {
|
||||
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));
|
||||
}
|
||||
} else if (pRight->num == 1) {
|
||||
for (; i >= 0 && i < pLeft->num; i += step, output += len) {
|
||||
char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i);
|
||||
if (isNull(left, pLeft->type) || isNull(pRight->data, pRight->type)) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
|
||||
switch (binFunctionId) {
|
||||
case TSDB_BINARY_OP_ADD:
|
||||
return vectorAdd;
|
||||
case TSDB_BINARY_OP_SUBTRACT:
|
||||
return vectorSub;
|
||||
case TSDB_BINARY_OP_MULTIPLY:
|
||||
return vectorMultiply;
|
||||
case TSDB_BINARY_OP_DIVIDE:
|
||||
return vectorDivide;
|
||||
case TSDB_BINARY_OP_REMAINDER:
|
||||
return vectorRemainder;
|
||||
case TSDB_BINARY_OP_CONCAT:
|
||||
return vectorConcat;
|
||||
default:
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@
|
|||
#include "thash.h"
|
||||
#include "tskiplist.h"
|
||||
#include "texpr.h"
|
||||
//#include "tarithoperator.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
//static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) {
|
||||
|
@ -41,71 +40,6 @@
|
|||
// }
|
||||
//}
|
||||
|
||||
static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows) {
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT:{
|
||||
int8_t* p = (int8_t*) dest;
|
||||
int8_t* pSrc = (int8_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:{
|
||||
int16_t* p = (int16_t*) dest;
|
||||
int16_t* pSrc = (int16_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
int32_t* p = (int32_t*) dest;
|
||||
int32_t* pSrc = (int32_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
int64_t* p = (int64_t*) dest;
|
||||
int64_t* pSrc = (int64_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) dest;
|
||||
float* pSrc = (float*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) dest;
|
||||
double* pSrc = (double*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *));
|
||||
|
||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
|
||||
|
@ -182,114 +116,7 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp
|
|||
return param->nodeFilterFn(pItem, pExpr->_node.info);
|
||||
}
|
||||
|
||||
void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*getSourceDataBlock)(void *, const char*, int32_t)) {
|
||||
if (pExprs == NULL) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
tExprNode *pLeft = pExprs->_node.pLeft;
|
||||
tExprNode *pRight = pExprs->_node.pRight;
|
||||
|
||||
/* the left output has result from the left child syntax tree */
|
||||
char *pLeftOutput = (char*)malloc(sizeof(int64_t) * numOfRows);
|
||||
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE) {
|
||||
arithmeticTreeTraverse(pLeft, numOfRows, pLeftOutput, param, order, getSourceDataBlock);
|
||||
}
|
||||
|
||||
// the right output has result from the right child syntax tree
|
||||
char *pRightOutput = malloc(sizeof(int64_t) * numOfRows);
|
||||
char *pdata = malloc(sizeof(int64_t) * numOfRows);
|
||||
|
||||
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) {
|
||||
arithmeticTreeTraverse(pRight, numOfRows, pRightOutput, param, order, getSourceDataBlock);
|
||||
}
|
||||
|
||||
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE) {
|
||||
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) {
|
||||
/*
|
||||
* exprLeft + exprRight
|
||||
* the type of returned value of one expression is always double float precious
|
||||
*/
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
|
||||
|
||||
} else if (pRight->nodeType == TEXPR_COL_NODE) { // exprLeft + columnRight
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
|
||||
// set input buffer
|
||||
char *pInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pInputData, pRight->pSchema->type, numOfRows);
|
||||
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pdata, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pInputData, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
|
||||
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // exprLeft + 12
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
} else if (pLeft->nodeType == TEXPR_COL_NODE) {
|
||||
// column data specified on left-hand-side
|
||||
char *pLeftInputData = getSourceDataBlock(param, pLeft->pSchema->name, pLeft->pSchema->colId);
|
||||
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) { // columnLeft + expr2
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pLeftInputData, pLeft->pSchema->type, numOfRows);
|
||||
OperatorFn(pdata, numOfRows, pLeft->pSchema->type, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
|
||||
} else if (pRight->nodeType == TEXPR_COL_NODE) { // columnLeft + columnRight
|
||||
// column data specified on right-hand-side
|
||||
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
|
||||
// both columns are descending order, do not reverse the source data
|
||||
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, pRightInputData, numOfRows, pRight->pSchema->type, pOutput, order);
|
||||
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // columnLeft + 12
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pLeftInputData, pLeft->pSchema->type, numOfRows);
|
||||
OperatorFn(pdata, numOfRows, pLeft->pSchema->type, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// column data specified on left-hand-side
|
||||
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) { // 12 + expr2
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pOutput, TSDB_ORDER_ASC);
|
||||
|
||||
} else if (pRight->nodeType == TEXPR_COL_NODE) { // 12 + columnRight
|
||||
// column data specified on right-hand-side
|
||||
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pRightInputData, pRight->pSchema->type, numOfRows);
|
||||
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, pdata, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, pRightInputData, numOfRows, pRight->pSchema->type, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
|
||||
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // 12 + 12
|
||||
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExprs->_node.optr);
|
||||
OperatorFn(&pLeft->pVal->i, 1, pLeft->pVal->nType, &pRight->pVal->i, 1, pRight->pVal->nType, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(pdata);
|
||||
tfree(pLeftOutput);
|
||||
tfree(pRightOutput);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
|
||||
tbufWriteUint8(bw, expr->nodeType);
|
||||
|
|
|
@ -1,4 +1,165 @@
|
|||
#include "tscalarfunction.h"
|
||||
#include "tbinoperator.h"
|
||||
#include "tunaryoperator.h"
|
||||
|
||||
static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows) {
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT:{
|
||||
int8_t* p = (int8_t*) dest;
|
||||
int8_t* pSrc = (int8_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:{
|
||||
int16_t* p = (int16_t*) dest;
|
||||
int16_t* pSrc = (int16_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
int32_t* p = (int32_t*) dest;
|
||||
int32_t* pSrc = (int32_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
int64_t* p = (int64_t*) dest;
|
||||
int64_t* pSrc = (int64_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) dest;
|
||||
float* pSrc = (float*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) dest;
|
||||
double* pSrc = (double*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void setScalarFuncParam(SScalarFuncParam* param, int32_t type, int32_t bytes, void* pInput, int32_t numOfRows) {
|
||||
param->bytes = bytes;
|
||||
param->type = type;
|
||||
param->num = numOfRows;
|
||||
param->data = pInput;
|
||||
}
|
||||
|
||||
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param,
|
||||
char* (*getSourceDataBlock)(void*, const char*, int32_t)) {
|
||||
if (pExprs == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tExprNode* pLeft = pExprs->_node.pLeft;
|
||||
tExprNode* pRight = pExprs->_node.pRight;
|
||||
|
||||
/* the left output has result from the left child syntax tree */
|
||||
SScalarFuncParam leftOutput = {0};
|
||||
SScalarFuncParam rightOutput = {0};
|
||||
|
||||
leftOutput.data = malloc(sizeof(int64_t) * numOfRows);
|
||||
|
||||
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) {
|
||||
evaluateExprNodeTree(pLeft, numOfRows, &leftOutput, param, getSourceDataBlock);
|
||||
}
|
||||
|
||||
// the right output has result from the right child syntax tree
|
||||
rightOutput.data = malloc(sizeof(int64_t) * numOfRows);
|
||||
|
||||
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE) {
|
||||
evaluateExprNodeTree(pRight, numOfRows, &rightOutput, param, getSourceDataBlock);
|
||||
}
|
||||
|
||||
if (pExprs->nodeType == TEXPR_BINARYEXPR_NODE) {
|
||||
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(pExprs->_node.optr);
|
||||
|
||||
SScalarFuncParam left = {0}, right = {0};
|
||||
|
||||
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) {
|
||||
setScalarFuncParam(&left, leftOutput.type, leftOutput.bytes, leftOutput.data, leftOutput.num);
|
||||
} else if (pLeft->nodeType == TEXPR_COL_NODE) {
|
||||
SSchema* pschema = pLeft->pSchema;
|
||||
char* pLeftInputData = getSourceDataBlock(param, pschema->name, pschema->colId);
|
||||
setScalarFuncParam(&right, pschema->type, pschema->bytes, pLeftInputData, numOfRows);
|
||||
} else if (pLeft->nodeType == TEXPR_VALUE_NODE) {
|
||||
SVariant* pVar = pRight->pVal;
|
||||
setScalarFuncParam(&left, pVar->nType, pVar->nLen, &pVar->i, 1);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE || pRight->nodeType == TEXPR_UNARYEXPR_NODE) {
|
||||
setScalarFuncParam(&right, rightOutput.type, rightOutput.bytes, rightOutput.data, rightOutput.num);
|
||||
} else if (pRight->nodeType == TEXPR_COL_NODE) { // exprLeft + columnRight
|
||||
SSchema* pschema = pRight->pSchema;
|
||||
char* pInputData = getSourceDataBlock(param, pschema->name, pschema->colId);
|
||||
setScalarFuncParam(&right, pschema->type, pschema->bytes, pInputData, numOfRows);
|
||||
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // exprLeft + 12
|
||||
SVariant* pVar = pRight->pVal;
|
||||
setScalarFuncParam(&right, pVar->nType, pVar->nLen, &pVar->i, 1);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
OperatorFn(&left, &right, pOutput->data, TSDB_ORDER_ASC);
|
||||
|
||||
// Set the result info
|
||||
setScalarFuncParam(pOutput, TSDB_DATA_TYPE_DOUBLE, sizeof(double), pOutput->data, numOfRows);
|
||||
} else if (pExprs->nodeType == TEXPR_UNARYEXPR_NODE) {
|
||||
_unary_scalar_fn_t OperatorFn = getUnaryScalarOperatorFn(pExprs->_node.optr);
|
||||
SScalarFuncParam left = {0};
|
||||
|
||||
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) {
|
||||
setScalarFuncParam(&left, leftOutput.type, leftOutput.bytes, leftOutput.data, leftOutput.num);
|
||||
} else if (pLeft->nodeType == TEXPR_COL_NODE) {
|
||||
SSchema* pschema = pLeft->pSchema;
|
||||
char* pLeftInputData = getSourceDataBlock(param, pschema->name, pschema->colId);
|
||||
setScalarFuncParam(&left, pschema->type, pschema->bytes, pLeftInputData, numOfRows);
|
||||
} else if (pLeft->nodeType == TEXPR_VALUE_NODE) {
|
||||
SVariant* pVar = pLeft->pVal;
|
||||
setScalarFuncParam(&left, pVar->nType, pVar->nLen, &pVar->i, 1);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
OperatorFn(&left, pOutput);
|
||||
}
|
||||
|
||||
tfree(leftOutput.data);
|
||||
tfree(rightOutput.data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SScalarFunctionInfo scalarFunc[1] = {
|
||||
{
|
||||
|
@ -6,5 +167,3 @@ SScalarFunctionInfo scalarFunc[1] = {
|
|||
},
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
#include "tunaryoperator.h"
|
||||
|
||||
static void assignBasicParaInfo(struct SScalarFuncParam* dst, const struct SScalarFuncParam* src) {
|
||||
dst->type = src->type;
|
||||
dst->bytes = src->bytes;
|
||||
dst->num = src->num;
|
||||
}
|
||||
|
||||
static void tceil(SScalarFuncParam *pLeft, SScalarFuncParam* pOutput) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = ceilf(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*)pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = ceil(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
static void tfloor(SScalarFuncParam *pLeft, SScalarFuncParam* pOutput) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = floorf(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*) pOutput->data;
|
||||
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = floor(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
static void _tabs(SScalarFuncParam *pLeft, SScalarFuncParam* pOutput) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
int8_t* p = (int8_t*) pLeft->data;
|
||||
int8_t* out = (int8_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
int16_t* p = (int16_t*) pLeft->data;
|
||||
int16_t* out = (int16_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
int32_t* p = (int32_t*) pLeft->data;
|
||||
int32_t* out = (int32_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
int64_t* p = (int64_t*) pLeft->data;
|
||||
int64_t* out = (int64_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
static void tround(SScalarFuncParam *pLeft, SScalarFuncParam* pOutput) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = roundf(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = round(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
static void tlen(SScalarFuncParam *pLeft, SScalarFuncParam* pOutput) {
|
||||
int64_t* out = (int64_t*) pOutput->data;
|
||||
char* s = pLeft->data;
|
||||
|
||||
for(int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = varDataLen(POINTER_SHIFT(s, i * pLeft->bytes));
|
||||
}
|
||||
}
|
||||
|
||||
_unary_scalar_fn_t getUnaryScalarOperatorFn(int32_t operator) {
|
||||
switch(operator) {
|
||||
case TSDB_UNARY_OP_CEIL:
|
||||
return tceil;
|
||||
case TSDB_UNARY_OP_FLOOR:
|
||||
return tfloor;
|
||||
case TSDB_UNARY_OP_ROUND:
|
||||
return tround;
|
||||
case TSDB_UNARY_OP_ABS:
|
||||
return _tabs;
|
||||
case TSDB_UNARY_OP_LEN:
|
||||
return tlen;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
|
@ -1175,14 +1175,6 @@ int32_t queryInfoCopy(SQueryStmtInfo* pQueryInfo, const SQueryStmtInfo* pSrc) {
|
|||
goto _error;
|
||||
}
|
||||
|
||||
// if (pQueryInfo->arithmeticOnAgg) {
|
||||
// pQueryInfo->exprList1 = taosArrayInit(4, POINTER_BYTES);
|
||||
// if (copyAllExprInfo(pQueryInfo->exprList1, pSrc->exprList1, true) != 0) {
|
||||
// code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
// goto _error;
|
||||
// }
|
||||
// }
|
||||
|
||||
columnListCopyAll(pQueryInfo->colList, pSrc->colList);
|
||||
copyFieldInfo(&pQueryInfo->fieldsInfo, &pSrc->fieldsInfo, pQueryInfo->exprList);
|
||||
|
||||
|
@ -1615,9 +1607,9 @@ uint32_t convertRelationalOperator(SToken *pToken) {
|
|||
return TSDB_RELATION_OR;
|
||||
case TK_EQ:
|
||||
return TSDB_RELATION_EQUAL;
|
||||
|
||||
case TK_PLUS:
|
||||
return TSDB_BINARY_OP_ADD;
|
||||
|
||||
case TK_MINUS:
|
||||
return TSDB_BINARY_OP_SUBTRACT;
|
||||
case TK_STAR:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "os.h"
|
||||
#include "thash.h"
|
||||
#include "ulog.h"
|
||||
#include "taos.h"
|
||||
#include "tdef.h"
|
||||
|
||||
#define EXT_SIZE 1024
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "os.h"
|
||||
#include "thash.h"
|
||||
#include "compare.h"
|
||||
#include "tdef.h"
|
||||
#include "taos.h"
|
||||
#include "types.h"
|
||||
|
||||
#define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r)))
|
||||
|
|
Loading…
Reference in New Issue