“5832b6772c1c121e4c648bbd69dc2c266809b5d5”上不存在“source/dnode/mgmt/sm/src/smWorker.c”
提交 6d9a8ab0 编写于 作者: S shenglian zhou

change arithemtic to scalar expr

上级 7da31782
...@@ -42,7 +42,7 @@ int32_t tscHandleInsertRetry(SSqlObj* parent, SSqlObj* child); ...@@ -42,7 +42,7 @@ int32_t tscHandleInsertRetry(SSqlObj* parent, SSqlObj* child);
void tscBuildResFromSubqueries(SSqlObj *pSql); void tscBuildResFromSubqueries(SSqlObj *pSql);
TAOS_ROW doSetResultRowData(SSqlObj *pSql); TAOS_ROW doSetResultRowData(SSqlObj *pSql);
char *getArithmeticInputSrc(void *param, const char *name, int32_t colId); char *getScalarExprInputSrc(void *param, const char *name, int32_t colId);
void tscLockByThread(int64_t *lockedBy); void tscLockByThread(int64_t *lockedBy);
......
...@@ -713,7 +713,7 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_ ...@@ -713,7 +713,7 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
char* pbuf = calloc(1, (size_t)(pOutput->num * maxRowSize)); char* pbuf = calloc(1, (size_t)(pOutput->num * maxRowSize));
size_t size = tscNumOfFields(pQueryInfo); size_t size = tscNumOfFields(pQueryInfo);
SArithmeticSupport arithSup = {0}; SScalarExprSupport arithSup = {0};
// todo refactor // todo refactor
arithSup.offset = 0; arithSup.offset = 0;
...@@ -736,7 +736,8 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_ ...@@ -736,7 +736,8 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
arithSup.pExprInfo = pSup->pExpr; arithSup.pExprInfo = pSup->pExpr;
tExprOperandInfo output; tExprOperandInfo output;
output.data = pbuf + pOutput->num*offset; output.data = pbuf + pOutput->num*offset;
exprTreeNodeTraverse(arithSup.pExprInfo->pExpr, (int32_t) pOutput->num, &output, &arithSup, TSDB_ORDER_ASC, getArithmeticInputSrc); exprTreeNodeTraverse(arithSup.pExprInfo->pExpr, (int32_t)pOutput->num, &output, &arithSup, TSDB_ORDER_ASC,
getScalarExprInputSrc);
} else { } else {
SExprInfo* pExpr = pSup->pExpr; SExprInfo* pExpr = pSup->pExpr;
memcpy(pbuf + pOutput->num * offset, pExpr->base.offset * pOutput->num + pOutput->data, (size_t)(pExpr->base.resBytes * pOutput->num)); memcpy(pbuf + pOutput->num * offset, pExpr->base.offset * pOutput->num + pOutput->data, (size_t)(pExpr->base.resBytes * pOutput->num));
......
...@@ -1740,7 +1740,7 @@ void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t tableUid) { ...@@ -1740,7 +1740,7 @@ void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t tableUid) {
tscColumnListInsert(pQueryInfo->colList, PRIMARYKEY_TIMESTAMP_COL_INDEX, tableUid, &s); tscColumnListInsert(pQueryInfo->colList, PRIMARYKEY_TIMESTAMP_COL_INDEX, tableUid, &s);
} }
static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t exprIndex, tSqlExprItem* pItem, static int32_t handleScalarTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t exprIndex, tSqlExprItem* pItem,
SColumnList* columnList, bool finalResult) { SColumnList* columnList, bool finalResult) {
const char* msg2 = "invalid arithmetic expression in select clause"; const char* msg2 = "invalid arithmetic expression in select clause";
const char* msg3 = "tag columns can not be used in arithmetic expression"; const char* msg3 = "tag columns can not be used in arithmetic expression";
...@@ -1789,7 +1789,7 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e ...@@ -1789,7 +1789,7 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e
} }
SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_ARITHM, &index, pNode->resultType, pNode->resultBytes, SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_SCALAR_EXPR, &index, pNode->resultType, pNode->resultBytes,
getNewResColId(pCmd), 0, false); getNewResColId(pCmd), 0, false);
char* name = (pItem->aliasName != NULL)? pItem->aliasName:pItem->pNode->exprToken.z; char* name = (pItem->aliasName != NULL)? pItem->aliasName:pItem->pNode->exprToken.z;
...@@ -1826,7 +1826,7 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e ...@@ -1826,7 +1826,7 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t handleAggregateExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t exprIndex, tSqlExprItem* pItem, static int32_t handleAggTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t exprIndex, tSqlExprItem* pItem,
SColumnList* columnList, bool finalResult) { SColumnList* columnList, bool finalResult) {
const char* msg2 = "invalid arithmetic expression in select clause"; const char* msg2 = "invalid arithmetic expression in select clause";
...@@ -1851,7 +1851,7 @@ static int32_t handleAggregateExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_ ...@@ -1851,7 +1851,7 @@ static int32_t handleAggregateExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_
pExprInfo->base.interBytes = 0; pExprInfo->base.interBytes = 0;
pExprInfo->base.resType = TSDB_DATA_TYPE_DOUBLE; pExprInfo->base.resType = TSDB_DATA_TYPE_DOUBLE;
pExprInfo->base.functionId = TSDB_FUNC_ARITHM; pExprInfo->base.functionId = TSDB_FUNC_SCALAR_EXPR;
pExprInfo->base.numOfParams = 1; pExprInfo->base.numOfParams = 1;
pExprInfo->base.resColId = getNewResColId(pCmd); pExprInfo->base.resColId = getNewResColId(pCmd);
strncpy(pExprInfo->base.aliasName, aliasName, tListLen(pExprInfo->base.aliasName)); strncpy(pExprInfo->base.aliasName, aliasName, tListLen(pExprInfo->base.aliasName));
...@@ -1893,18 +1893,18 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t ...@@ -1893,18 +1893,18 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
const char* msg1 = "invalid column name, illegal column type, or columns in arithmetic expression from two tables"; const char* msg1 = "invalid column name, illegal column type, or columns in arithmetic expression from two tables";
SColumnList columnList = {0}; SColumnList columnList = {0};
int32_t arithmeticType = SQLEXPR_TYPE_UNASSIGNED; int32_t sqlExprType = SQLEXPR_TYPE_UNASSIGNED;
uint64_t uid; uint64_t uid;
if (validateSQLExprItem(pCmd, pItem->pNode, pQueryInfo, &columnList, &arithmeticType, &uid) != TSDB_CODE_SUCCESS) { if (validateSQLExprItem(pCmd, pItem->pNode, pQueryInfo, &columnList, &sqlExprType, &uid) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if (arithmeticType == SQLEXPR_TYPE_SCALAR) { if (sqlExprType == SQLEXPR_TYPE_SCALAR) {
code = handleScalarExpr(pCmd, pQueryInfo, exprIndex, pItem, &columnList, true); code = handleScalarTypeExpr(pCmd, pQueryInfo, exprIndex, pItem, &columnList, true);
} else { } else {
code = handleAggregateExpr(pCmd, pQueryInfo, exprIndex, pItem, &columnList, true); code = handleAggTypeExpr(pCmd, pQueryInfo, exprIndex, pItem, &columnList, true);
} }
return code; return code;
...@@ -3138,79 +3138,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -3138,79 +3138,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
case TSDB_FUNC_SCALAR_LOG:
case TSDB_FUNC_SCALAR_POW: {
// 1. valid the number of parameters
if (pItem->pNode->Expr.paramList == NULL || taosArrayGetSize(pItem->pNode->Expr.paramList) != 2) {
/* no parameters or more than one parameter for function */
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
tSqlExprItem* pParamElem = taosArrayGet(pItem->pNode->Expr.paramList, 0);
if (pParamElem->pNode->tokenId != TK_ID) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(&pParamElem->pNode->columnName, pQueryInfo, &index, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex);
// functions can not be applied to tags
if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
// 2. valid the column type
if (!IS_NUMERIC_TYPE(pSchema->type)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
// 3. valid the parameters
if (pParamElem[1].pNode->tokenId == TK_ID) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
int16_t resultType = pSchema->type;
int16_t resultSize = pSchema->bytes;
int32_t interResult = 0;
tVariant* pVariant = &pParamElem[1].pNode->value;
char val[8] = {0};
tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE, true);
SExprInfo* pExpr = NULL;
getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &resultType, &resultSize, &interResult, 0, false,
pUdfInfo);
pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), interResult, false);
tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double ));
memset(pExpr->base.aliasName, 0, tListLen(pExpr->base.aliasName));
getColumnName(pItem, pExpr->base.aliasName, pExpr->base.token,sizeof(pExpr->base.aliasName) - 1);
SColumnList ids = createColumnList(1, index.tableIndex, index.columnIndex);
if (finalResult) {
int32_t numOfOutput = tscNumOfFields(pQueryInfo);
insertResultField(pQueryInfo, numOfOutput, &ids, pExpr->base.resBytes, (int32_t)pExpr->base.resType,
pExpr->base.aliasName, pExpr);
} else {
assert(ids.num == 1);
tscColumnListInsert(pQueryInfo->colList, ids.ids[0].columnIndex, pExpr->base.uid, pSchema);
}
tscInsertPrimaryTsSourceColumn(pQueryInfo, pExpr->base.uid);
return TSDB_CODE_SUCCESS;
}
default: { default: {
assert(!TSDB_FUNC_IS_SCALAR(functionId));
pUdfInfo = isValidUdf(pQueryInfo->pUdfInfo, pItem->pNode->Expr.operand.z, pItem->pNode->Expr.operand.n); pUdfInfo = isValidUdf(pQueryInfo->pUdfInfo, pItem->pNode->Expr.operand.z, pItem->pNode->Expr.operand.n);
if (pUdfInfo == NULL) { if (pUdfInfo == NULL) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9);
...@@ -3763,7 +3692,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool ...@@ -3763,7 +3692,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool
++scalarFuncNum; ++scalarFuncNum;
} }
if (functionId == TSDB_FUNC_ARITHM) { if (functionId == TSDB_FUNC_SCALAR_EXPR) {
++scalarFuncNum; ++scalarFuncNum;
} }
...@@ -6730,7 +6659,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu ...@@ -6730,7 +6659,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu
int32_t f = pExpr->base.functionId; int32_t f = pExpr->base.functionId;
if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) ||
f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_SCALAR_EXPR || f == TSDB_FUNC_DERIVATIVE ||
f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG || f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG ||
f == TSDB_FUNC_CEIL || f == TSDB_FUNC_FLOOR || f == TSDB_FUNC_ROUND) f == TSDB_FUNC_CEIL || f == TSDB_FUNC_FLOOR || f == TSDB_FUNC_ROUND)
{ {
...@@ -7362,7 +7291,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { ...@@ -7362,7 +7291,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
int16_t functionId = pExpr->base.functionId; int16_t functionId = pExpr->base.functionId;
if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS || if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS ||
functionId == TSDB_FUNC_ARITHM || functionId == TSDB_FUNC_TS_DUMMY) { functionId == TSDB_FUNC_SCALAR_EXPR || functionId == TSDB_FUNC_TS_DUMMY) {
continue; continue;
} }
......
...@@ -3618,8 +3618,8 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) { ...@@ -3618,8 +3618,8 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
} }
} }
char *getArithmeticInputSrc(void *param, const char *name, int32_t colId) { char * getScalarExprInputSrc(void *param, const char *name, int32_t colId) {
SArithmeticSupport *pSupport = (SArithmeticSupport *) param; SScalarExprSupport*pSupport = (SScalarExprSupport*) param;
int32_t index = -1; int32_t index = -1;
SExprInfo* pExpr = NULL; SExprInfo* pExpr = NULL;
......
...@@ -266,7 +266,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { ...@@ -266,7 +266,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAGPRJ &&
functionId != TSDB_FUNC_TAG && functionId != TSDB_FUNC_TAG &&
functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_TS &&
functionId != TSDB_FUNC_ARITHM && functionId != TSDB_FUNC_SCALAR_EXPR &&
functionId != TSDB_FUNC_TS_COMP && functionId != TSDB_FUNC_TS_COMP &&
functionId != TSDB_FUNC_DIFF && functionId != TSDB_FUNC_DIFF &&
functionId != TSDB_FUNC_DERIVATIVE && functionId != TSDB_FUNC_DERIVATIVE &&
...@@ -314,7 +314,7 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) { ...@@ -314,7 +314,7 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) {
} }
if (f != TSDB_FUNC_PRJ && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_TAG && if (f != TSDB_FUNC_PRJ && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_TAG &&
f != TSDB_FUNC_TS && f != TSDB_FUNC_ARITHM && f != TSDB_FUNC_DIFF && f != TSDB_FUNC_TS && f != TSDB_FUNC_SCALAR_EXPR && f != TSDB_FUNC_DIFF &&
f != TSDB_FUNC_DERIVATIVE && !TSDB_FUNC_IS_SCALAR(f)) { f != TSDB_FUNC_DERIVATIVE && !TSDB_FUNC_IS_SCALAR(f)) {
return false; return false;
} }
...@@ -4815,7 +4815,7 @@ int32_t createProjectionExpr(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaI ...@@ -4815,7 +4815,7 @@ int32_t createProjectionExpr(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaI
strncpy(pse->aliasName, pSource->base.aliasName, tListLen(pse->aliasName)); strncpy(pse->aliasName, pSource->base.aliasName, tListLen(pse->aliasName));
strncpy(pse->token, pSource->base.token, tListLen(pse->token)); strncpy(pse->token, pSource->base.token, tListLen(pse->token));
if (pSource->base.functionId != TSDB_FUNC_ARITHM) { // this should be switched to projection query if (pSource->base.functionId != TSDB_FUNC_SCALAR_EXPR) { // this should be switched to projection query
pse->numOfParams = 0; // no params for projection query pse->numOfParams = 0; // no params for projection query
pse->functionId = TSDB_FUNC_PRJ; pse->functionId = TSDB_FUNC_PRJ;
pse->colInfo.colId = pSource->base.resColId; pse->colInfo.colId = pSource->base.resColId;
...@@ -5059,7 +5059,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt ...@@ -5059,7 +5059,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
SExprInfo* pExpr = tscExprGet(pQueryInfo, i); SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
tscExprAssign(&pQueryAttr->pExpr1[i], pExpr); tscExprAssign(&pQueryAttr->pExpr1[i], pExpr);
if (pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_ARITHM) { if (pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_SCALAR_EXPR) {
for (int32_t j = 0; j < pQueryAttr->pExpr1[i].base.numOfParams; ++j) { for (int32_t j = 0; j < pQueryAttr->pExpr1[i].base.numOfParams; ++j) {
buildArithmeticExprFromMsg(&pQueryAttr->pExpr1[i], NULL); buildArithmeticExprFromMsg(&pQueryAttr->pExpr1[i], NULL);
} }
......
...@@ -57,7 +57,7 @@ extern "C" { ...@@ -57,7 +57,7 @@ extern "C" {
#define TSDB_FUNC_PRJ 21 #define TSDB_FUNC_PRJ 21
#define TSDB_FUNC_TAGPRJ 22 #define TSDB_FUNC_TAGPRJ 22
#define TSDB_FUNC_ARITHM 23 #define TSDB_FUNC_SCALAR_EXPR 23
#define TSDB_FUNC_DIFF 24 #define TSDB_FUNC_DIFF 24
#define TSDB_FUNC_FIRST_DST 25 #define TSDB_FUNC_FIRST_DST 25
...@@ -129,14 +129,14 @@ enum { ...@@ -129,14 +129,14 @@ enum {
#define QUERY_IS_PROJECTION_QUERY(type) (((type)&TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) #define QUERY_IS_PROJECTION_QUERY(type) (((type)&TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0)
#define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0) #define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0)
typedef struct SArithmeticSupport { typedef struct SScalarExprSupport {
SExprInfo *pExprInfo; SExprInfo *pExprInfo;
int32_t numOfCols; int32_t numOfCols;
SColumnInfo *colList; SColumnInfo *colList;
void *exprList; // client side used void *exprList; // client side used
int32_t offset; int32_t offset;
char** data; char** data;
} SArithmeticSupport; } SScalarExprSupport;
typedef struct SQLPreAggVal { typedef struct SQLPreAggVal {
bool isSet; // statistics info set or not bool isSet; // statistics info set or not
......
...@@ -304,7 +304,7 @@ typedef struct SQueryRuntimeEnv { ...@@ -304,7 +304,7 @@ typedef struct SQueryRuntimeEnv {
STSCursor cur; STSCursor cur;
char* tagVal; // tag value of current data block char* tagVal; // tag value of current data block
SArithmeticSupport *sasArray; SScalarExprSupport*sasArray;
SSDataBlock *outputBuf; SSDataBlock *outputBuf;
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
......
...@@ -202,25 +202,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -202,25 +202,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
if (TSDB_FUNC_IS_SCALAR(functionId)) { assert(!TSDB_FUNC_IS_SCALAR(functionId));
switch (functionId) {
case TSDB_FUNC_SCALAR_POW: {
*type = TSDB_DATA_TYPE_DOUBLE;
*bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
break;
}
case TSDB_FUNC_SCALAR_LOG: {
*type = TSDB_DATA_TYPE_DOUBLE;
*bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
break;
}
default: {
qError("Illegal function id: %d", functionId);
return TSDB_CODE_TSC_INVALID_OPERATION;
}
}
return TSDB_CODE_SUCCESS;
}
if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG_DUMMY || if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG_DUMMY ||
functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TAGPRJ ||
...@@ -261,7 +243,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -261,7 +243,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == TSDB_FUNC_ARITHM) { if (functionId == TSDB_FUNC_SCALAR_EXPR) {
*type = TSDB_DATA_TYPE_DOUBLE; *type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double); *bytes = sizeof(double);
*interBytes = 0; *interBytes = 0;
...@@ -3402,8 +3384,8 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3402,8 +3384,8 @@ static void diff_function(SQLFunctionCtx *pCtx) {
} }
} }
char *getArithColumnData(void *param, const char* name, int32_t colId) { char *getScalarExprColumnData(void *param, const char* name, int32_t colId) {
SArithmeticSupport *pSupport = (SArithmeticSupport *)param; SScalarExprSupport *pSupport = (SScalarExprSupport *)param;
int32_t index = -1; int32_t index = -1;
for (int32_t i = 0; i < pSupport->numOfCols; ++i) { for (int32_t i = 0; i < pSupport->numOfCols; ++i) {
...@@ -3417,12 +3399,12 @@ char *getArithColumnData(void *param, const char* name, int32_t colId) { ...@@ -3417,12 +3399,12 @@ char *getArithColumnData(void *param, const char* name, int32_t colId) {
return pSupport->data[index] + pSupport->offset * pSupport->colList[index].bytes; return pSupport->data[index] + pSupport->offset * pSupport->colList[index].bytes;
} }
static void arithmetic_function(SQLFunctionCtx *pCtx) { static void scalar_expr_function(SQLFunctionCtx *pCtx) {
GET_RES_INFO(pCtx)->numOfRes += pCtx->size; GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz; SScalarExprSupport *sas = (SScalarExprSupport *)pCtx->param[1].pz;
tExprOperandInfo output; tExprOperandInfo output;
output.data = pCtx->pOutput; output.data = pCtx->pOutput;
exprTreeNodeTraverse(sas->pExprInfo->pExpr, pCtx->size, &output, sas, pCtx->order, getArithColumnData); exprTreeNodeTraverse(sas->pExprInfo->pExpr, pCtx->size, &output, sas, pCtx->order, getScalarExprColumnData);
} }
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \ #define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
...@@ -5380,11 +5362,11 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -5380,11 +5362,11 @@ SAggFunctionInfo aAggs[] = {{
{ {
// 23 // 23
"arithmetic", "arithmetic",
TSDB_FUNC_ARITHM, TSDB_FUNC_SCALAR_EXPR,
TSDB_FUNC_ARITHM, TSDB_FUNC_SCALAR_EXPR,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS, TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
function_setup, function_setup,
arithmetic_function, scalar_expr_function,
doFinalizer, doFinalizer,
copy_function, copy_function,
dataBlockRequired, dataBlockRequired,
......
...@@ -1192,7 +1192,7 @@ static TSKEY getStartTsKey(SQueryAttr* pQueryAttr, STimeWindow* win, const TSKEY ...@@ -1192,7 +1192,7 @@ static TSKEY getStartTsKey(SQueryAttr* pQueryAttr, STimeWindow* win, const TSKEY
return ts; return ts;
} }
static void setArithParams(SArithmeticSupport* sas, SExprInfo *pExprInfo, SSDataBlock* pSDataBlock) { static void setArithParams(SScalarExprSupport* sas, SExprInfo *pExprInfo, SSDataBlock* pSDataBlock) {
sas->numOfCols = (int32_t) pSDataBlock->info.numOfCols; sas->numOfCols = (int32_t) pSDataBlock->info.numOfCols;
sas->pExprInfo = pExprInfo; sas->pExprInfo = pExprInfo;
if (sas->colList != NULL) { if (sas->colList != NULL) {
...@@ -1225,8 +1225,8 @@ static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SQLFunctionCtx* pC ...@@ -1225,8 +1225,8 @@ static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SQLFunctionCtx* pC
} }
void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order) { void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order) {
if (pCtx[0].functionId == TSDB_FUNC_ARITHM) { if (pCtx[0].functionId == TSDB_FUNC_SCALAR_EXPR) {
SArithmeticSupport* pSupport = (SArithmeticSupport*) pCtx[0].param[1].pz; SScalarExprSupport* pSupport = (SScalarExprSupport*) pCtx[0].param[1].pz;
if (pSupport->colList == NULL) { if (pSupport->colList == NULL) {
doSetInputDataBlock(pOperator, pCtx, pBlock, order); doSetInputDataBlock(pOperator, pCtx, pBlock, order);
} else { } else {
...@@ -1249,8 +1249,8 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, ...@@ -1249,8 +1249,8 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx,
setBlockStatisInfo(&pCtx[i], pBlock, &pOperator->pExpr[i].base.colInfo); setBlockStatisInfo(&pCtx[i], pBlock, &pOperator->pExpr[i].base.colInfo);
if (pCtx[i].functionId == TSDB_FUNC_ARITHM) { if (pCtx[i].functionId == TSDB_FUNC_SCALAR_EXPR) {
setArithParams((SArithmeticSupport*)pCtx[i].param[1].pz, &pOperator->pExpr[i], pBlock); setArithParams((SScalarExprSupport*)pCtx[i].param[1].pz, &pOperator->pExpr[i], pBlock);
} else { } else {
SColIndex* pCol = &pOperator->pExpr[i].base.colInfo; SColIndex* pCol = &pOperator->pExpr[i].base.colInfo;
if (TSDB_COL_IS_NORMAL_COL(pCol->flag) || (pCtx[i].functionId == TSDB_FUNC_BLKINFO) || if (TSDB_COL_IS_NORMAL_COL(pCol->flag) || (pCtx[i].functionId == TSDB_FUNC_BLKINFO) ||
...@@ -2130,7 +2130,7 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr ...@@ -2130,7 +2130,7 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr
pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT; pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT;
pCtx->param[2].i64 = pQueryAttr->window.ekey; pCtx->param[2].i64 = pQueryAttr->window.ekey;
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT; pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
} else if (functionId == TSDB_FUNC_ARITHM) { } else if (functionId == TSDB_FUNC_SCALAR_EXPR) {
pCtx->param[1].pz = (char*) &pRuntimeEnv->sasArray[i]; pCtx->param[1].pz = (char*) &pRuntimeEnv->sasArray[i];
} }
} }
...@@ -2181,7 +2181,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf ...@@ -2181,7 +2181,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
// NOTE: pTableCheckInfo need to update the query time range and the lastKey info // NOTE: pTableCheckInfo need to update the query time range and the lastKey info
pRuntimeEnv->pTableRetrieveTsMap = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); pRuntimeEnv->pTableRetrieveTsMap = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
pRuntimeEnv->sasArray = calloc(pQueryAttr->numOfOutput, sizeof(SArithmeticSupport)); pRuntimeEnv->sasArray = calloc(pQueryAttr->numOfOutput, sizeof(SScalarExprSupport));
if (pRuntimeEnv->sasArray == NULL || pRuntimeEnv->pResultRowHashTable == NULL || pRuntimeEnv->keyBuf == NULL || if (pRuntimeEnv->sasArray == NULL || pRuntimeEnv->pResultRowHashTable == NULL || pRuntimeEnv->keyBuf == NULL ||
pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL) { pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL) {
...@@ -8195,7 +8195,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp ...@@ -8195,7 +8195,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp
int16_t bytes = 0; int16_t bytes = 0;
// parse the arithmetic expression // parse the arithmetic expression
if (pExprs[i].base.functionId == TSDB_FUNC_ARITHM) { if (pExprs[i].base.functionId == TSDB_FUNC_SCALAR_EXPR) {
code = buildArithmeticExprFromMsg(&pExprs[i], pMsg); code = buildArithmeticExprFromMsg(&pExprs[i], pMsg);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
...@@ -8255,14 +8255,14 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp ...@@ -8255,14 +8255,14 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp
} }
int32_t param = (int32_t)pExprs[i].base.param[0].i64; int32_t param = (int32_t)pExprs[i].base.param[0].i64;
if (pExprs[i].base.functionId > 0 && pExprs[i].base.functionId != TSDB_FUNC_ARITHM && if (pExprs[i].base.functionId > 0 && pExprs[i].base.functionId != TSDB_FUNC_SCALAR_EXPR &&
(type != pExprs[i].base.colType || bytes != pExprs[i].base.colBytes)) { (type != pExprs[i].base.colType || bytes != pExprs[i].base.colBytes)) {
tfree(pExprs); tfree(pExprs);
return TSDB_CODE_QRY_INVALID_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
// todo remove it // todo remove it
if (pExprs[i].base.functionId != TSDB_FUNC_ARITHM && getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].base.resType, &pExprs[i].base.resBytes, if (pExprs[i].base.functionId != TSDB_FUNC_SCALAR_EXPR && getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].base.resType, &pExprs[i].base.resBytes,
&pExprs[i].base.interBytes, 0, isSuperTable, pUdfInfo) != TSDB_CODE_SUCCESS) { &pExprs[i].base.interBytes, 0, isSuperTable, pUdfInfo) != TSDB_CODE_SUCCESS) {
tfree(pExprs); tfree(pExprs);
return TSDB_CODE_QRY_INVALID_MSG; return TSDB_CODE_QRY_INVALID_MSG;
...@@ -8331,7 +8331,7 @@ int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg* pQueryMsg, int32_t nu ...@@ -8331,7 +8331,7 @@ int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg* pQueryMsg, int32_t nu
int16_t bytes = 0; int16_t bytes = 0;
// parse the arithmetic expression // parse the arithmetic expression
if (pExprs[i].base.functionId == TSDB_FUNC_ARITHM) { if (pExprs[i].base.functionId == TSDB_FUNC_SCALAR_EXPR) {
code = buildArithmeticExprFromMsg(&pExprs[i], pQueryMsg); code = buildArithmeticExprFromMsg(&pExprs[i], pQueryMsg);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
...@@ -8475,7 +8475,7 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) { ...@@ -8475,7 +8475,7 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) {
for (int32_t k = 0; k < pQueryAttr->numOfOutput; ++k) { for (int32_t k = 0; k < pQueryAttr->numOfOutput; ++k) {
SSqlExpr *pSqlExprMsg = &pQueryAttr->pExpr1[k].base; SSqlExpr *pSqlExprMsg = &pQueryAttr->pExpr1[k].base;
if (pSqlExprMsg->functionId == TSDB_FUNC_ARITHM) { if (pSqlExprMsg->functionId == TSDB_FUNC_SCALAR_EXPR) {
continue; continue;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册