提交 ae625d31 编写于 作者: H Haojun Liao

refactor: remove redundant codes and do some internal refactor.

上级 a43ccdf5
......@@ -340,12 +340,8 @@ typedef struct tDataTypeDescriptor {
} tDataTypeDescriptor;
extern tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX];
bool isValidDataType(int32_t type);
void setVardataNull(void *val, int32_t type);
//void setNull(void *val, int32_t type, int32_t bytes);
//void setNullN(void *val, int32_t type, int32_t bytes, int32_t numOfElems);
void assignVal(char *val, const char *src, int32_t len, int32_t type);
void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type);
void *getDataMin(int32_t type);
......
......@@ -244,8 +244,7 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
* 2013-04-12T15:52:01.123+0800
*/
int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim) {
int64_t factor =
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
int64_t factor = TSDB_TICK_PER_SECOND(timePrec);
int64_t tzOffset = 0;
struct tm tm = {0};
......@@ -339,8 +338,8 @@ static FORCE_INLINE bool validateTm(struct tm* pTm) {
return true;
}
int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePrec, char delim) {
*time = 0;
int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) {
*utime = 0;
struct tm tm = {0};
char* str;
......@@ -378,15 +377,12 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePr
}
}
int64_t factor =
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
*time = factor * seconds + fraction;
*utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction;
return 0;
}
int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t timePrec, char delim) {
*time = 0;
int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) {
*utime = 0;
struct tm tm = {0};
tm.tm_isdst = -1;
......@@ -411,7 +407,6 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t tim
int64_t seconds = taosMktime(&tm);
int64_t fraction = 0;
if (*str == '.') {
/* parse the second fraction part */
if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) {
......@@ -419,9 +414,7 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t tim
}
}
int64_t factor =
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
*time = factor * seconds + fraction;
*utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction;
return 0;
}
......@@ -437,58 +430,61 @@ char getPrecisionUnit(int32_t precision) {
}
}
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) {
assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO ||
int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPrecision) {
ASSERT(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO ||
fromPrecision == TSDB_TIME_PRECISION_NANO);
assert(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO ||
ASSERT(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO ||
toPrecision == TSDB_TIME_PRECISION_NANO);
double tempResult = (double)time;
double tempResult = (double)utime;
switch (fromPrecision) {
case TSDB_TIME_PRECISION_MILLI: {
switch (toPrecision) {
case TSDB_TIME_PRECISION_MILLI:
return time;
return utime;
case TSDB_TIME_PRECISION_MICRO:
tempResult *= 1000;
time *= 1000;
utime *= 1000;
goto end_;
case TSDB_TIME_PRECISION_NANO:
tempResult *= 1000000;
time *= 1000000;
utime *= 1000000;
goto end_;
}
} // end from milli
case TSDB_TIME_PRECISION_MICRO: {
switch (toPrecision) {
case TSDB_TIME_PRECISION_MILLI:
return time / 1000;
return utime / 1000;
case TSDB_TIME_PRECISION_MICRO:
return time;
return utime;
case TSDB_TIME_PRECISION_NANO:
tempResult *= 1000;
time *= 1000;
utime *= 1000;
goto end_;
}
} // end from micro
case TSDB_TIME_PRECISION_NANO: {
switch (toPrecision) {
case TSDB_TIME_PRECISION_MILLI:
return time / 1000000;
return utime / 1000000;
case TSDB_TIME_PRECISION_MICRO:
return time / 1000;
return utime / 1000;
case TSDB_TIME_PRECISION_NANO:
return time;
return utime;
}
} // end from nano
default: {
assert(0);
return time; // only to pass windows compilation
return utime; // only to pass windows compilation
}
} // end switch fromPrecision
end_:
if (tempResult >= (double)INT64_MAX) return INT64_MAX;
if (tempResult <= (double)INT64_MIN) return INT64_MIN; // INT64_MIN means NULL
return time;
return utime;
}
// !!!!notice:there are precision problems, double lose precison if time is too large, for example:
......
......@@ -16,7 +16,6 @@
#define _DEFAULT_SOURCE
#include "ttypes.h"
#include "tcompression.h"
#include "trow.h"
const int32_t TYPE_BYTES[16] = {
-1, // TSDB_DATA_TYPE_NULL
......@@ -86,18 +85,6 @@ FORCE_INLINE void *getDataMax(int32_t type) {
bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type < TSDB_DATA_TYPE_MAX; }
void setVardataNull(void *val, int32_t type) {
if (type == TSDB_DATA_TYPE_BINARY) {
varDataSetLen(val, sizeof(int8_t));
*(uint8_t *)varDataVal(val) = TSDB_DATA_BINARY_NULL;
} else if (type == TSDB_DATA_TYPE_NCHAR) {
varDataSetLen(val, sizeof(int32_t));
*(uint32_t *)varDataVal(val) = TSDB_DATA_NCHAR_NULL;
} else {
assert(0);
}
}
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
void assignVal(char *val, const char *src, int32_t len, int32_t type) {
......
......@@ -1178,9 +1178,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData);
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
int64_t factor =
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
int64_t factor = TSDB_TICK_PER_SECOND(timePrec);
int64_t unit = timeUnit * 1000 / factor;
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
......@@ -1372,9 +1370,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
}
int64_t factor =
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
int64_t factor = TSDB_TICK_PER_SECOND(timePrec);
int32_t numOfRows = 0;
for (int32_t i = 0; i < inputNum; ++i) {
if (pInput[i].numOfRows > numOfRows) {
......
......@@ -1426,57 +1426,6 @@ void vectorAssign(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut,
pOut->numOfQualified = pRight->numOfQualified * pOut->numOfRows;
}
void vectorConcat(SScalarParam *pLeft, SScalarParam *pRight, void *out, int32_t _ord) {
#if 0
int32_t len = pLeft->bytes + pRight->bytes;
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
char *output = (char *)out;
if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && 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, pLeftCol->info.type) || isNull(right, pRight->info.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->numOfRows == 1) {
for (; i >= 0 && i < pRight->numOfRows; i += step, output += len) {
char *right = POINTER_SHIFT(pRight->data, pRight->bytes * i);
if (isNull(pLeft->data, pLeftCol->info.type) || isNull(right, pRight->info.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->numOfRows == 1) {
for (; i >= 0 && i < pLeft->numOfRows; i += step, output += len) {
char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i);
if (isNull(left, pLeftCol->info.type) || isNull(pRight->data, pRight->info.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));
}
}
#endif
}
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册