提交 93b2a931 编写于 作者: X xywang

[TD-2573]<enhance>: optimized functionality for unsigned types

上级 039f20ac
...@@ -4233,61 +4233,38 @@ void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) { ...@@ -4233,61 +4233,38 @@ void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) {
doFinalizer(pCtx); doFinalizer(pCtx);
} }
void setTagCtxList(SQLFunctionCtx *pCtx) #define CFR_SET_VAL(type, data, pCtx, func, i, step, notNullElems) \
{ do { \
if (pCtx && pCtx->tagInfo.numOfTagCols > 0 && pCtx->ptsList) { type *pData = (type *) data; \
int32_t delta = 4; type *pOutput = (type *) pCtx->pOutput; \
void *data = GET_INPUT_DATA_LIST(pCtx); \
void *pData = data; for (; i < pCtx->size && i >= 0; i += step) { \
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { \
char **p = calloc(pCtx->tagInfo.numOfTagCols, POINTER_BYTES); continue; \
if (p == NULL) { } \
return; \
} *pOutput++ = (type) func((double) pData[i]); \
\
for (int32_t j = 0; j < pCtx->tagInfo.numOfTagCols; ++j) { notNullElems++; \
p[j] = pCtx->tagInfo.pTagCtxList[j]->pOutput; } \
} } while (0)
switch(pCtx->inputType) {
case TSDB_DATA_TYPE_INT:
delta = sizeof(int32_t);
break;
case TSDB_DATA_TYPE_TIMESTAMP:
case TSDB_DATA_TYPE_BIGINT:
delta = sizeof(int64_t);
break;
case TSDB_DATA_TYPE_DOUBLE:
delta = sizeof(double);
break;
case TSDB_DATA_TYPE_FLOAT:
delta = sizeof(float);
break;
case TSDB_DATA_TYPE_SMALLINT:
delta = sizeof(int16_t);
break;
case TSDB_DATA_TYPE_TINYINT:
delta = sizeof(int8_t);
break;
default:
free(p);
return;
}
for (int32_t j = 0; j < pCtx->size; ++j) {
if (pCtx->hasNull && isNull((const char*) ((char *) pData + j * delta), pCtx->inputType)) {
continue;
}
for (int32_t k = 0; k < pCtx->tagInfo.numOfTagCols; ++k) {
memcpy(p[k], &pCtx->ptsList[j], (size_t)pCtx->tagInfo.pTagCtxList[k]->outputBytes);
p[k] += pCtx->tagInfo.pTagCtxList[k]->outputBytes;
}
}
free(p); #define CFR_SET_VAL_DOUBLE(data, pCtx, func, i, step, notNullElems) \
} do { \
} double *pData = (double *) data; \
double *pOutput = (double *) pCtx->pOutput; \
\
for (; i < pCtx->size && i >= 0; i += step) { \
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { \
continue; \
} \
\
SET_DOUBLE_VAL(pOutput, func(pData[i])); \
pOutput++; \
\
notNullElems++; \
} \
} while (0)
static void ceil_function(SQLFunctionCtx *pCtx) { static void ceil_function(SQLFunctionCtx *pCtx) {
void *data = GET_INPUT_DATA_LIST(pCtx); void *data = GET_INPUT_DATA_LIST(pCtx);
...@@ -4299,101 +4276,43 @@ static void ceil_function(SQLFunctionCtx *pCtx) { ...@@ -4299,101 +4276,43 @@ static void ceil_function(SQLFunctionCtx *pCtx) {
switch (pCtx->inputType) { switch (pCtx->inputType) {
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t *pData = (int32_t *)data; CFR_SET_VAL(int32_t, data, pCtx, ceil, i, step, notNullElems);
int32_t *pOutput = (int32_t *)pCtx->pOutput; break;
};
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint32_t, data, pCtx, ceil, i, step, notNullElems);
continue;
}
*pOutput++ = (int32_t) ceil((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
}; };
case TSDB_DATA_TYPE_BIGINT: { case TSDB_DATA_TYPE_BIGINT: {
int64_t *pData = (int64_t *)data; CFR_SET_VAL(int64_t, data, pCtx, ceil, i, step, notNullElems);
int64_t *pOutput = (int64_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UBIGINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint64_t, data, pCtx, ceil, i, step, notNullElems);
continue;
}
*pOutput++ = (int64_t) ceil((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
double *pData = (double *)data; CFR_SET_VAL_DOUBLE(data, pCtx, ceil, i, step, notNullElems);
double *pOutput = (double *)pCtx->pOutput;
for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue;
}
SET_DOUBLE_VAL(pOutput, ceil(pData[i]));
pOutput++;
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
float *pData = (float *)data; CFR_SET_VAL(float, data, pCtx, ceil, i, step, notNullElems);
float *pOutput = (float *)pCtx->pOutput;
for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue;
}
*pOutput++ = (float) ceil((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t *pData = (int16_t *)data; CFR_SET_VAL(int16_t, data, pCtx, ceil, i, step, notNullElems);
int16_t *pOutput = (int16_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_USMALLINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint16_t, data, pCtx, ceil, i, step, notNullElems);
continue;
}
*pOutput++ = (int16_t) ceil((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t *pData = (int8_t *)data; CFR_SET_VAL(int8_t, data, pCtx, ceil, i, step, notNullElems);
int8_t *pOutput = (int8_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UTINYINT: {
if (pCtx->hasNull && isNull((char *)&pData[i], pCtx->inputType)) { CFR_SET_VAL(uint8_t, data, pCtx, ceil, i, step, notNullElems);
continue;
}
*pOutput++ = (int8_t) ceil((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
default: default:
...@@ -4420,101 +4339,43 @@ static void floor_function(SQLFunctionCtx *pCtx) { ...@@ -4420,101 +4339,43 @@ static void floor_function(SQLFunctionCtx *pCtx) {
switch (pCtx->inputType) { switch (pCtx->inputType) {
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t *pData = (int32_t *)data; CFR_SET_VAL(int32_t, data, pCtx, floor, i, step, notNullElems);
int32_t *pOutput = (int32_t *)pCtx->pOutput; break;
};
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint32_t, data, pCtx, floor, i, step, notNullElems);
continue;
}
*pOutput++ = (int32_t) floor((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
}; };
case TSDB_DATA_TYPE_BIGINT: { case TSDB_DATA_TYPE_BIGINT: {
int64_t *pData = (int64_t *)data; CFR_SET_VAL(int64_t, data, pCtx, floor, i, step, notNullElems);
int64_t *pOutput = (int64_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UBIGINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint64_t, data, pCtx, floor, i, step, notNullElems);
continue;
}
*pOutput++ = (int64_t) floor((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
double *pData = (double *)data; CFR_SET_VAL_DOUBLE(data, pCtx, floor, i, step, notNullElems);
double *pOutput = (double *)pCtx->pOutput;
for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue;
}
SET_DOUBLE_VAL(pOutput, floor(pData[i]));
pOutput++;
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
float *pData = (float *)data; CFR_SET_VAL(float, data, pCtx, floor, i, step, notNullElems);
float *pOutput = (float *)pCtx->pOutput;
for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue;
}
*pOutput++ = (float) floor((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t *pData = (int16_t *)data; CFR_SET_VAL(int16_t, data, pCtx, floor, i, step, notNullElems);
int16_t *pOutput = (int16_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_USMALLINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint16_t, data, pCtx, floor, i, step, notNullElems);
continue;
}
*pOutput++ = (int16_t) floor((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t *pData = (int8_t *)data; CFR_SET_VAL(int8_t, data, pCtx, floor, i, step, notNullElems);
int8_t *pOutput = (int8_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UTINYINT: {
if (pCtx->hasNull && isNull((char *)&pData[i], pCtx->inputType)) { CFR_SET_VAL(uint8_t, data, pCtx, floor, i, step, notNullElems);
continue;
}
*pOutput++ = (int8_t) floor((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
default: default:
...@@ -4541,101 +4402,43 @@ static void round_function(SQLFunctionCtx *pCtx) { ...@@ -4541,101 +4402,43 @@ static void round_function(SQLFunctionCtx *pCtx) {
switch (pCtx->inputType) { switch (pCtx->inputType) {
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t *pData = (int32_t *)data; CFR_SET_VAL(int32_t, data, pCtx, round, i, step, notNullElems);
int32_t *pOutput = (int32_t *)pCtx->pOutput; break;
};
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint32_t, data, pCtx, round, i, step, notNullElems);
continue;
}
*pOutput++ = (int32_t) round((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
}; };
case TSDB_DATA_TYPE_BIGINT: { case TSDB_DATA_TYPE_BIGINT: {
int64_t *pData = (int64_t *)data; CFR_SET_VAL(int64_t, data, pCtx, round, i, step, notNullElems);
int64_t *pOutput = (int64_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UBIGINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint64_t, data, pCtx, round, i, step, notNullElems);
continue;
}
*pOutput++ = (int64_t) round((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
double *pData = (double *)data; CFR_SET_VAL_DOUBLE(data, pCtx, round, i, step, notNullElems);
double *pOutput = (double *)pCtx->pOutput;
for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue;
}
SET_DOUBLE_VAL(pOutput, round(pData[i]));
pOutput++;
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
float *pData = (float *)data; CFR_SET_VAL(float, data, pCtx, round, i, step, notNullElems);
float *pOutput = (float *)pCtx->pOutput;
for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue;
}
*pOutput++ = (float) round((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t *pData = (int16_t *)data; CFR_SET_VAL(int16_t, data, pCtx, round, i, step, notNullElems);
int16_t *pOutput = (int16_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_USMALLINT: {
if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { CFR_SET_VAL(uint16_t, data, pCtx, round, i, step, notNullElems);
continue;
}
*pOutput++ = (int16_t) round((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t *pData = (int8_t *)data; CFR_SET_VAL(int8_t, data, pCtx, round, i, step, notNullElems);
int8_t *pOutput = (int8_t *)pCtx->pOutput; break;
}
for (; i < pCtx->size && i >= 0; i += step) { case TSDB_DATA_TYPE_UTINYINT: {
if (pCtx->hasNull && isNull((char *)&pData[i], pCtx->inputType)) { CFR_SET_VAL(uint8_t, data, pCtx, round, i, step, notNullElems);
continue;
}
*pOutput++ = (int8_t) round((double) pData[i]);
notNullElems++;
}
setTagCtxList(pCtx);
break; break;
} }
default: default:
...@@ -4652,6 +4455,9 @@ static void round_function(SQLFunctionCtx *pCtx) { ...@@ -4652,6 +4455,9 @@ static void round_function(SQLFunctionCtx *pCtx) {
} }
} }
#undef CFR_SET_VAL
#undef CFR_SET_VAL_DOUBLE
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
/* /*
* function compatible list. * function compatible list.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册