未验证 提交 57f42f25 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #8834 from taosdata/feature/TD-6140

[TD-6140][New Feature] cast functions in SQL
......@@ -42,7 +42,7 @@ int32_t tscHandleInsertRetry(SSqlObj* parent, SSqlObj* child);
void tscBuildResFromSubqueries(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);
......
......@@ -35,12 +35,12 @@ extern "C" {
#define UTIL_TABLE_IS_CHILD_TABLE(metaInfo) \
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_CHILD_TABLE))
#define UTIL_TABLE_IS_NORMAL_TABLE(metaInfo) \
(!(UTIL_TABLE_IS_SUPER_TABLE(metaInfo) || UTIL_TABLE_IS_CHILD_TABLE(metaInfo)))
#define UTIL_TABLE_IS_TMP_TABLE(metaInfo) \
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_TEMP_TABLE))
#define UTIL_TABLE_IS_NORMAL_TABLE(metaInfo) \
(!(UTIL_TABLE_IS_SUPER_TABLE(metaInfo) || UTIL_TABLE_IS_CHILD_TABLE(metaInfo) || UTIL_TABLE_IS_TMP_TABLE(metaInfo)))
#define UTIL_GET_VGROUPMAP(pSql) \
(pSql->pTscObj->pClusterInfo->vgroupMap)
......@@ -364,7 +364,7 @@ bool subAndCheckDone(SSqlObj *pSql, SSqlObj *pParentSql, int idx);
bool tscSetSqlOwner(SSqlObj* pSql);
void tscClearSqlOwner(SSqlObj* pSql);
int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize);
int32_t doScalarExprCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize);
char* serializeTagData(STagData* pTagData, char* pMsg);
int32_t copyTagData(STagData* dst, const STagData* src);
......
......@@ -499,6 +499,8 @@ bool tscHasReachLimitation(SQueryInfo *pQueryInfo, SSqlRes *pRes);
void tscSetBoundColumnInfo(SParsedDataColInfo *pColInfo, SSchema *pSchema, int32_t numOfCols);
char *tscGetErrorMsgPayload(SSqlCmd *pCmd);
int32_t tscGetErrorMsgLength(SSqlCmd* pCmd);
int32_t tscErrorMsgWithCode(int32_t code, char* dstBuffer, const char* errMsg, const char* sql);
int32_t tscInvalidOperationMsg(char *msg, const char *additionalInfo, const char *sql);
......
......@@ -608,6 +608,7 @@ static void doMergeResultImpl(SMultiwayMergeInfo* pInfo, SQLFunctionCtx *pCtx, i
SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1);
doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_MERGE);
} else {
assert(!TSDB_FUNC_IS_SCALAR(functionId));
aAggs[functionId].mergeFunc(&pCtx[j]);
}
}
......@@ -624,6 +625,7 @@ static void doFinalizeResultImpl(SMultiwayMergeInfo* pInfo, SQLFunctionCtx *pCtx
SUdfInfo* pUdfInfo = taosArrayGet(pInfo->udfInfo, -1 * functionId - 1);
doInvokeUdf(pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE);
} else {
assert(!TSDB_FUNC_IS_SCALAR(functionId));
aAggs[functionId].xFinalize(&pCtx[j]);
}
}
......@@ -663,8 +665,10 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD
if (pCtx[j].functionId < 0) {
continue;
}
aAggs[pCtx[j].functionId].init(&pCtx[j], pCtx[j].resultInfo);
{
assert(!TSDB_FUNC_IS_SCALAR(pCtx[j].functionId));
aAggs[pCtx[j].functionId].init(&pCtx[j], pCtx[j].resultInfo);
}
}
doMergeResultImpl(pInfo, pCtx, numOfExpr, i, addrPtr);
......@@ -706,12 +710,12 @@ SGlobalMerger* tscInitResObjForLocalQuery(int32_t numOfRes, int32_t rowLen, uint
}
// todo remove it
int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize) {
int32_t doScalarExprCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize) {
int32_t maxRowSize = MAX(rowSize, finalRowSize);
char* pbuf = calloc(1, (size_t)(pOutput->num * maxRowSize));
size_t size = tscNumOfFields(pQueryInfo);
SArithmeticSupport arithSup = {0};
SScalarExprSupport arithSup = {0};
// todo refactor
arithSup.offset = 0;
......@@ -732,7 +736,10 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
// calculate the result from several other columns
if (pSup->pExpr->pExpr != NULL) {
arithSup.pExprInfo = pSup->pExpr;
arithmeticTreeTraverse(arithSup.pExprInfo->pExpr, (int32_t) pOutput->num, pbuf + pOutput->num*offset, &arithSup, TSDB_ORDER_ASC, getArithmeticInputSrc);
tExprOperandInfo output;
output.data = pbuf + pOutput->num*offset;
exprTreeNodeTraverse(arithSup.pExprInfo->pExpr, (int32_t)pOutput->num, &output, &arithSup, TSDB_ORDER_ASC,
getScalarExprInputSrc);
} else {
SExprInfo* pExpr = pSup->pExpr;
memcpy(pbuf + pOutput->num * offset, pExpr->base.offset * pOutput->num + pOutput->data, (size_t)(pExpr->base.resBytes * pOutput->num));
......@@ -904,8 +911,10 @@ SSDataBlock* doGlobalAggregate(void* param, bool* newgroup) {
clearOutputBuf(&pAggInfo->binfo, &pAggInfo->bufCapacity);
continue;
}
aAggs[pCtx->functionId].init(pCtx, pCtx->resultInfo);
{
assert(!TSDB_FUNC_IS_SCALAR(pCtx->functionId));
aAggs[pCtx->functionId].init(pCtx, pCtx->resultInfo);
}
}
}
......
......@@ -702,6 +702,7 @@ static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas, SSmlLinesInfo*
if (code == TSDB_CODE_SUCCESS) {
pointSchema->precision = dbSchema.precision;
size_t pointTagSize = taosArrayGetSize(pointSchema->tags);
size_t pointFieldSize = taosArrayGetSize(pointSchema->fields);
......
此差异已折叠。
......@@ -3621,7 +3621,7 @@ static void doBuildResFromSubqueries(SSqlObj* pSql) {
finalRowSize += pField->bytes;
}
doArithmeticCalculate(pQueryInfo, pFilePage, rowSize, finalRowSize);
doScalarExprCalculate(pQueryInfo, pFilePage, rowSize, finalRowSize);
pRes->data = pFilePage->data;
tscSetResRawPtr(pRes, pQueryInfo, pRes->dataConverted);
......@@ -3660,8 +3660,8 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
}
}
char *getArithmeticInputSrc(void *param, const char *name, int32_t colId) {
SArithmeticSupport *pSupport = (SArithmeticSupport *) param;
char * getScalarExprInputSrc(void *param, const char *name, int32_t colId) {
SScalarExprSupport*pSupport = (SScalarExprSupport*) param;
int32_t index = -1;
SExprInfo* pExpr = NULL;
......
......@@ -287,13 +287,11 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
functionId != TSDB_FUNC_TAGPRJ &&
functionId != TSDB_FUNC_TAG &&
functionId != TSDB_FUNC_TS &&
functionId != TSDB_FUNC_ARITHM &&
functionId != TSDB_FUNC_SCALAR_EXPR &&
functionId != TSDB_FUNC_TS_COMP &&
functionId != TSDB_FUNC_TS_DUMMY &&
functionId != TSDB_FUNC_TID_TAG &&
functionId != TSDB_FUNC_CEIL &&
functionId != TSDB_FUNC_FLOOR &&
functionId != TSDB_FUNC_ROUND) {
!TSDB_FUNC_IS_SCALAR(functionId)) {
return false;
}
}
......@@ -330,8 +328,8 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) {
}
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_DERIVATIVE) {
f != TSDB_FUNC_TS && f != TSDB_FUNC_SCALAR_EXPR && f != TSDB_FUNC_DIFF &&
f != TSDB_FUNC_DERIVATIVE && !TSDB_FUNC_IS_SCALAR(f)) {
return false;
}
}
......@@ -680,6 +678,10 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
continue;
}
if (TSDB_FUNC_IS_SCALAR(functionId)) {
continue;
}
if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) {
continue;
}
......@@ -4475,6 +4477,8 @@ bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) {
char* tscGetErrorMsgPayload(SSqlCmd* pCmd) { return pCmd->payload; }
int32_t tscGetErrorMsgLength(SSqlCmd* pCmd) { return (int32_t)strlen(pCmd->payload); }
/**
* If current vnode query does not return results anymore (pRes->numOfRows == 0), try the next vnode if exists,
* while multi-vnode super table projection query and the result does not reach the limitation.
......@@ -4917,7 +4921,7 @@ int32_t createProjectionExpr(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaI
strncpy(pse->aliasName, pSource->base.aliasName, tListLen(pse->aliasName));
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->functionId = TSDB_FUNC_PRJ;
pse->colInfo.colId = pSource->base.resColId;
......@@ -4961,16 +4965,17 @@ int32_t createProjectionExpr(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaI
pse->colInfo.colId = pSource->base.colInfo.colId;
pse->colType = pSource->base.colType;
pse->colBytes = pSource->base.colBytes;
pse->resBytes = sizeof(double);
pse->resType = TSDB_DATA_TYPE_DOUBLE;
pse->functionId = pSource->base.functionId;
pse->numOfParams = pSource->base.numOfParams;
for (int32_t j = 0; j < pSource->base.numOfParams; ++j) {
tVariantAssign(&pse->param[j], &pSource->base.param[j]);
buildArithmeticExprFromMsg(px, NULL);
buildScalarExprFromMsg(px, NULL);
}
pse->resBytes = px->pExpr->resultBytes;
pse->resType = px->pExpr->resultType;
}
}
......@@ -5163,9 +5168,9 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
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) {
buildArithmeticExprFromMsg(&pQueryAttr->pExpr1[i], NULL);
buildScalarExprFromMsg(&pQueryAttr->pExpr1[i], NULL);
}
}
}
......
......@@ -25,6 +25,7 @@ typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t l
_arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr);
#ifdef __cplusplus
}
#endif
......
......@@ -41,6 +41,55 @@ struct SSchema;
#define QUERY_COND_REL_PREFIX_MATCH_LEN 6
#define QUERY_COND_REL_PREFIX_NMATCH_LEN 7
#define TSDB_FUNC_FLAG_SCALAR 0x4000
#define TSDB_FUNC_IS_SCALAR(id) ((((id) > 0)) && (((id) & TSDB_FUNC_FLAG_SCALAR) != 0))
#define TSDB_FUNC_SCALAR_INDEX(id) ((id) & ~TSDB_FUNC_FLAG_SCALAR)
///////////////////////////////////////////
// SCALAR FUNCTIONS
#define TSDB_FUNC_SCALAR_POW (TSDB_FUNC_FLAG_SCALAR | 0x0000)
#define TSDB_FUNC_SCALAR_LOG (TSDB_FUNC_FLAG_SCALAR | 0x0001)
#define TSDB_FUNC_SCALAR_ABS (TSDB_FUNC_FLAG_SCALAR | 0x0002)
#define TSDB_FUNC_SCALAR_ACOS (TSDB_FUNC_FLAG_SCALAR | 0x0003)
#define TSDB_FUNC_SCALAR_ASIN (TSDB_FUNC_FLAG_SCALAR | 0x0004)
#define TSDB_FUNC_SCALAR_ATAN (TSDB_FUNC_FLAG_SCALAR | 0x0005)
#define TSDB_FUNC_SCALAR_COS (TSDB_FUNC_FLAG_SCALAR | 0x0006)
#define TSDB_FUNC_SCALAR_SIN (TSDB_FUNC_FLAG_SCALAR | 0x0007)
#define TSDB_FUNC_SCALAR_TAN (TSDB_FUNC_FLAG_SCALAR | 0x0008)
#define TSDB_FUNC_SCALAR_SQRT (TSDB_FUNC_FLAG_SCALAR | 0x0009)
#define TSDB_FUNC_SCALAR_CEIL (TSDB_FUNC_FLAG_SCALAR | 0x000A)
#define TSDB_FUNC_SCALAR_FLOOR (TSDB_FUNC_FLAG_SCALAR | 0x000B)
#define TSDB_FUNC_SCALAR_ROUND (TSDB_FUNC_FLAG_SCALAR | 0x000C)
#define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x000D)
#define TSDB_FUNC_SCALAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x000E)
#define TSDB_FUNC_SCALAR_CONCAT_WS (TSDB_FUNC_FLAG_SCALAR | 0x000F)
#define TSDB_FUNC_SCALAR_CHAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x0010)
#define TSDB_FUNC_SCALAR_CAST (TSDB_FUNC_FLAG_SCALAR | 0x0011)
#define TSDB_FUNC_SCALAR_MAX_NUM 18
#define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16
typedef struct {
int16_t type;
int16_t bytes;
int16_t numOfRows;
char* data;
} tExprOperandInfo;
typedef void (*_expr_scalar_function_t)(int16_t functionId, tExprOperandInfo* pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order);
_expr_scalar_function_t getExprScalarFunction(uint16_t scalar);
typedef struct tScalarFunctionInfo{
int16_t functionId; // scalar function id & ~TSDB_FUNC_FLAG_SCALAR == index
char name[TSDB_FUNC_SCALAR_NAME_MAX_LEN];
_expr_scalar_function_t scalarFunc;
} tScalarFunctionInfo;
/* global scalar sql functions array */
extern struct tScalarFunctionInfo aScalarFunctions[TSDB_FUNC_SCALAR_MAX_NUM];
typedef bool (*__result_filter_fn_t)(const void *, void *);
typedef void (*__do_filter_suppl_fn_t)(void *, void *);
......@@ -49,6 +98,8 @@ enum {
TSQL_NODE_EXPR = 0x1,
TSQL_NODE_COL = 0x2,
TSQL_NODE_VALUE = 0x4,
TSQL_NODE_FUNC = 0x8,
TSQL_NODE_TYPE = 0x10
};
/**
......@@ -74,8 +125,19 @@ typedef struct tExprNode {
} _node;
struct SSchema *pSchema;
tVariant *pVal;
struct {
int16_t functionId;
int32_t numChildren;
struct tExprNode **pChildren;
} _func;
TAOS_FIELD *pType;
};
int16_t resultType;
int16_t resultBytes;
} tExprNode;
typedef struct SExprTraverseSupp {
......@@ -86,6 +148,8 @@ typedef struct SExprTraverseSupp {
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
int32_t exprTreeValidateTree(char* msgbuf, tExprNode *pExpr);
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
tExprNode* exprTreeFromBinary(const void* data, size_t size);
tExprNode* exprdup(tExprNode* pTree);
......@@ -94,8 +158,8 @@ void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
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 exprTreeNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandInfo *output, void *param, int32_t order,
char *(*getSourceDataBlock)(void *, const char*, int32_t));
void buildFilterSetFromBinary(void **q, const char *buf, int32_t len);
......
......@@ -19,6 +19,7 @@
#include "tutil.h"
#include "tarithoperator.h"
#include "tcompare.h"
#include "texpr.h"
//GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[i]));
......
此差异已折叠。
......@@ -16,6 +16,7 @@
#ifndef TDENGINE_TTOKENDEF_H
#define TDENGINE_TTOKENDEF_H
#define TK_ID 1
#define TK_BOOL 2
#define TK_TINYINT 3
......@@ -59,164 +60,164 @@
#define TK_STAR 41
#define TK_SLASH 42
#define TK_REM 43
#define TK_CONCAT 44
#define TK_UMINUS 45
#define TK_UPLUS 46
#define TK_BITNOT 47
#define TK_ARROW 48
#define TK_SHOW 49
#define TK_DATABASES 50
#define TK_TOPICS 51
#define TK_FUNCTIONS 52
#define TK_MNODES 53
#define TK_DNODES 54
#define TK_ACCOUNTS 55
#define TK_USERS 56
#define TK_MODULES 57
#define TK_QUERIES 58
#define TK_CONNECTIONS 59
#define TK_STREAMS 60
#define TK_VARIABLES 61
#define TK_SCORES 62
#define TK_GRANTS 63
#define TK_VNODES 64
#define TK_DOT 65
#define TK_CREATE 66
#define TK_TABLE 67
#define TK_STABLE 68
#define TK_DATABASE 69
#define TK_TABLES 70
#define TK_STABLES 71
#define TK_VGROUPS 72
#define TK_DROP 73
#define TK_TOPIC 74
#define TK_FUNCTION 75
#define TK_DNODE 76
#define TK_USER 77
#define TK_ACCOUNT 78
#define TK_USE 79
#define TK_DESCRIBE 80
#define TK_DESC 81
#define TK_ALTER 82
#define TK_PASS 83
#define TK_PRIVILEGE 84
#define TK_LOCAL 85
#define TK_COMPACT 86
#define TK_LP 87
#define TK_RP 88
#define TK_IF 89
#define TK_EXISTS 90
#define TK_AS 91
#define TK_OUTPUTTYPE 92
#define TK_AGGREGATE 93
#define TK_BUFSIZE 94
#define TK_PPS 95
#define TK_TSERIES 96
#define TK_DBS 97
#define TK_STORAGE 98
#define TK_QTIME 99
#define TK_CONNS 100
#define TK_STATE 101
#define TK_COMMA 102
#define TK_KEEP 103
#define TK_CACHE 104
#define TK_REPLICA 105
#define TK_QUORUM 106
#define TK_DAYS 107
#define TK_MINROWS 108
#define TK_MAXROWS 109
#define TK_BLOCKS 110
#define TK_CTIME 111
#define TK_WAL 112
#define TK_FSYNC 113
#define TK_COMP 114
#define TK_PRECISION 115
#define TK_UPDATE 116
#define TK_CACHELAST 117
#define TK_PARTITIONS 118
#define TK_UNSIGNED 119
#define TK_TAGS 120
#define TK_USING 121
#define TK_NULL 122
#define TK_NOW 123
#define TK_SELECT 124
#define TK_UNION 125
#define TK_ALL 126
#define TK_DISTINCT 127
#define TK_FROM 128
#define TK_VARIABLE 129
#define TK_RANGE 130
#define TK_INTERVAL 131
#define TK_EVERY 132
#define TK_SESSION 133
#define TK_STATE_WINDOW 134
#define TK_FILL 135
#define TK_SLIDING 136
#define TK_ORDER 137
#define TK_BY 138
#define TK_ASC 139
#define TK_GROUP 140
#define TK_HAVING 141
#define TK_LIMIT 142
#define TK_OFFSET 143
#define TK_SLIMIT 144
#define TK_SOFFSET 145
#define TK_WHERE 146
#define TK_RESET 147
#define TK_QUERY 148
#define TK_SYNCDB 149
#define TK_ADD 150
#define TK_COLUMN 151
#define TK_MODIFY 152
#define TK_TAG 153
#define TK_CHANGE 154
#define TK_SET 155
#define TK_KILL 156
#define TK_CONNECTION 157
#define TK_STREAM 158
#define TK_COLON 159
#define TK_ABORT 160
#define TK_AFTER 161
#define TK_ATTACH 162
#define TK_BEFORE 163
#define TK_BEGIN 164
#define TK_CASCADE 165
#define TK_CLUSTER 166
#define TK_CONFLICT 167
#define TK_COPY 168
#define TK_DEFERRED 169
#define TK_DELIMITERS 170
#define TK_DETACH 171
#define TK_EACH 172
#define TK_END 173
#define TK_EXPLAIN 174
#define TK_FAIL 175
#define TK_FOR 176
#define TK_IGNORE 177
#define TK_IMMEDIATE 178
#define TK_INITIALLY 179
#define TK_INSTEAD 180
#define TK_KEY 181
#define TK_OF 182
#define TK_RAISE 183
#define TK_REPLACE 184
#define TK_RESTRICT 185
#define TK_ROW 186
#define TK_STATEMENT 187
#define TK_TRIGGER 188
#define TK_VIEW 189
#define TK_IPTOKEN 190
#define TK_SEMI 191
#define TK_NONE 192
#define TK_PREV 193
#define TK_LINEAR 194
#define TK_IMPORT 195
#define TK_TBNAME 196
#define TK_JOIN 197
#define TK_INSERT 198
#define TK_INTO 199
#define TK_VALUES 200
#define TK_FILE 201
#define TK_UMINUS 44
#define TK_UPLUS 45
#define TK_BITNOT 46
#define TK_ARROW 47
#define TK_SHOW 48
#define TK_DATABASES 49
#define TK_TOPICS 50
#define TK_FUNCTIONS 51
#define TK_MNODES 52
#define TK_DNODES 53
#define TK_ACCOUNTS 54
#define TK_USERS 55
#define TK_MODULES 56
#define TK_QUERIES 57
#define TK_CONNECTIONS 58
#define TK_STREAMS 59
#define TK_VARIABLES 60
#define TK_SCORES 61
#define TK_GRANTS 62
#define TK_VNODES 63
#define TK_DOT 64
#define TK_CREATE 65
#define TK_TABLE 66
#define TK_STABLE 67
#define TK_DATABASE 68
#define TK_TABLES 69
#define TK_STABLES 70
#define TK_VGROUPS 71
#define TK_DROP 72
#define TK_TOPIC 73
#define TK_FUNCTION 74
#define TK_DNODE 75
#define TK_USER 76
#define TK_ACCOUNT 77
#define TK_USE 78
#define TK_DESCRIBE 79
#define TK_DESC 80
#define TK_ALTER 81
#define TK_PASS 82
#define TK_PRIVILEGE 83
#define TK_LOCAL 84
#define TK_COMPACT 85
#define TK_LP 86
#define TK_RP 87
#define TK_IF 88
#define TK_EXISTS 89
#define TK_AS 90
#define TK_OUTPUTTYPE 91
#define TK_AGGREGATE 92
#define TK_BUFSIZE 93
#define TK_PPS 94
#define TK_TSERIES 95
#define TK_DBS 96
#define TK_STORAGE 97
#define TK_QTIME 98
#define TK_CONNS 99
#define TK_STATE 100
#define TK_COMMA 101
#define TK_KEEP 102
#define TK_CACHE 103
#define TK_REPLICA 104
#define TK_QUORUM 105
#define TK_DAYS 106
#define TK_MINROWS 107
#define TK_MAXROWS 108
#define TK_BLOCKS 109
#define TK_CTIME 110
#define TK_WAL 111
#define TK_FSYNC 112
#define TK_COMP 113
#define TK_PRECISION 114
#define TK_UPDATE 115
#define TK_CACHELAST 116
#define TK_PARTITIONS 117
#define TK_UNSIGNED 118
#define TK_TAGS 119
#define TK_USING 120
#define TK_NULL 121
#define TK_NOW 122
#define TK_SELECT 123
#define TK_UNION 124
#define TK_ALL 125
#define TK_DISTINCT 126
#define TK_FROM 127
#define TK_VARIABLE 128
#define TK_RANGE 129
#define TK_INTERVAL 130
#define TK_EVERY 131
#define TK_SESSION 132
#define TK_STATE_WINDOW 133
#define TK_FILL 134
#define TK_SLIDING 135
#define TK_ORDER 136
#define TK_BY 137
#define TK_ASC 138
#define TK_GROUP 139
#define TK_HAVING 140
#define TK_LIMIT 141
#define TK_OFFSET 142
#define TK_SLIMIT 143
#define TK_SOFFSET 144
#define TK_WHERE 145
#define TK_RESET 146
#define TK_QUERY 147
#define TK_SYNCDB 148
#define TK_ADD 149
#define TK_COLUMN 150
#define TK_MODIFY 151
#define TK_TAG 152
#define TK_CHANGE 153
#define TK_SET 154
#define TK_KILL 155
#define TK_CONNECTION 156
#define TK_STREAM 157
#define TK_COLON 158
#define TK_ABORT 159
#define TK_AFTER 160
#define TK_ATTACH 161
#define TK_BEFORE 162
#define TK_BEGIN 163
#define TK_CASCADE 164
#define TK_CLUSTER 165
#define TK_CONFLICT 166
#define TK_COPY 167
#define TK_DEFERRED 168
#define TK_DELIMITERS 169
#define TK_DETACH 170
#define TK_EACH 171
#define TK_END 172
#define TK_EXPLAIN 173
#define TK_FAIL 174
#define TK_FOR 175
#define TK_IGNORE 176
#define TK_IMMEDIATE 177
#define TK_INITIALLY 178
#define TK_INSTEAD 179
#define TK_KEY 180
#define TK_OF 181
#define TK_RAISE 182
#define TK_REPLACE 183
#define TK_RESTRICT 184
#define TK_ROW 185
#define TK_STATEMENT 186
#define TK_TRIGGER 187
#define TK_VIEW 188
#define TK_IPTOKEN 189
#define TK_SEMI 190
#define TK_NONE 191
#define TK_PREV 192
#define TK_LINEAR 193
#define TK_IMPORT 194
#define TK_TBNAME 195
#define TK_JOIN 196
#define TK_INSERT 197
#define TK_INTO 198
#define TK_VALUES 199
#define TK_FILE 200
#define TK_SPACE 300
......
......@@ -166,6 +166,42 @@ typedef struct {
} \
} while (0)
#define NUM_TO_STRING(_inputType, _input, _outputBytes, _output) \
do { \
switch (_inputType) { \
case TSDB_DATA_TYPE_TINYINT: \
snprintf(_output, (int32_t)(_outputBytes), "%d", *(int8_t *)(_input)); \
break; \
case TSDB_DATA_TYPE_UTINYINT: \
snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint8_t *)(_input)); \
break; \
case TSDB_DATA_TYPE_SMALLINT: \
snprintf(_output, (int32_t)(_outputBytes), "%d", *(int16_t *)(_input)); \
break; \
case TSDB_DATA_TYPE_USMALLINT: \
snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint16_t *)(_input)); \
break; \
case TSDB_DATA_TYPE_BIGINT: \
snprintf(_output, (int32_t)(_outputBytes), "%" PRId64, *(int64_t *)(_input)); \
break; \
case TSDB_DATA_TYPE_UBIGINT: \
snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \
break; \
case TSDB_DATA_TYPE_FLOAT: \
snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
break; \
case TSDB_DATA_TYPE_DOUBLE: \
snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
break; \
case TSDB_DATA_TYPE_UINT: \
snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \
break; \
default: \
snprintf(_output, (int32_t)(_outputBytes), "%d", *(int32_t *)(_input)); \
break; \
} \
} while (0)
#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT)
#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT)
#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE)
......
......@@ -646,7 +646,7 @@ static void shellPrintNChar(const char *str, int length, int width) {
static void printField(const char* val, TAOS_FIELD* field, int width, int32_t length, int precision) {
if (val == NULL) {
int w = width;
if (field->type < TSDB_DATA_TYPE_TINYINT || field->type > TSDB_DATA_TYPE_DOUBLE) {
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_NCHAR || field->type == TSDB_DATA_TYPE_TIMESTAMP) {
w = 0;
}
w = printf("%*s", w, TSDB_DATA_NULL_STR);
......
......@@ -23,6 +23,7 @@ extern "C" {
#include "os.h"
#include "tname.h"
#include "texpr.h"
#include "taosdef.h"
#include "trpc.h"
#include "tvariant.h"
......@@ -56,7 +57,7 @@ extern "C" {
#define TSDB_FUNC_PRJ 21
#define TSDB_FUNC_TAGPRJ 22
#define TSDB_FUNC_ARITHM 23
#define TSDB_FUNC_SCALAR_EXPR 23
#define TSDB_FUNC_DIFF 24
#define TSDB_FUNC_FIRST_DST 25
......@@ -69,17 +70,13 @@ extern "C" {
#define TSDB_FUNC_TID_TAG 31
#define TSDB_FUNC_DERIVATIVE 32
#define TSDB_FUNC_CEIL 33
#define TSDB_FUNC_FLOOR 34
#define TSDB_FUNC_ROUND 35
#define TSDB_FUNC_CSUM 33
#define TSDB_FUNC_MAVG 34
#define TSDB_FUNC_SAMPLE 35
#define TSDB_FUNC_CSUM 36
#define TSDB_FUNC_MAVG 37
#define TSDB_FUNC_SAMPLE 38
#define TSDB_FUNC_BLKINFO 36
#define TSDB_FUNC_BLKINFO 39
#define TSDB_FUNC_ELAPSED 40
#define TSDB_FUNC_ELAPSED 37
///////////////////////////////////////////
// the following functions is not implemented.
......@@ -95,7 +92,6 @@ extern "C" {
#define TSDB_FUNCSTATE_OF 0x10u // outer forward
#define TSDB_FUNCSTATE_NEED_TS 0x20u // timestamp is required during query processing
#define TSDB_FUNCSTATE_SELECTIVITY 0x40u // selectivity functions, can exists along with tag columns
#define TSDB_FUNCSTATE_SCALAR 0x80u
#define TSDB_BASE_FUNC_SO TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF
#define TSDB_BASE_FUNC_MO TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF
......@@ -130,14 +126,14 @@ enum {
#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)
typedef struct SArithmeticSupport {
typedef struct SScalarExprSupport {
SExprInfo *pExprInfo;
int32_t numOfCols;
SColumnInfo *colList;
void *exprList; // client side used
int32_t offset;
char** data;
} SArithmeticSupport;
} SScalarExprSupport;
typedef struct SQLPreAggVal {
bool isSet; // statistics info set or not
......@@ -236,7 +232,6 @@ int32_t isValidFunction(const char* name, int32_t len);
#define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0)
#define IS_SINGLEOUTPUT(x) (((x)&TSDB_FUNCSTATE_SO) != 0)
#define IS_OUTER_FORWARD(x) (((x)&TSDB_FUNCSTATE_OF) != 0)
#define IS_SCALAR_FUNCTION(x) (((x)&TSDB_FUNCSTATE_SCALAR) != 0)
// determine the real data need to calculated the result
enum {
......@@ -258,7 +253,7 @@ void blockDistInfoToBinary(STableBlockDist* pDist, struct SBufferWriter* bw);
void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDist* pDist);
/* global sql function array */
extern struct SAggFunctionInfo aAggs[];
extern struct SAggFunctionInfo aAggs[40];
extern int32_t functionCompatList[]; // compatible check array list
......@@ -275,11 +270,11 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const cha
static FORCE_INLINE void initResultInfo(SResultRowCellInfo *pResInfo, int32_t bufLen) {
pResInfo->initialized = true; // the this struct has been initialized flag
pResInfo->complete = false;
pResInfo->hasResult = false;
pResInfo->numOfRes = 0;
memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen);
}
......
......@@ -311,7 +311,7 @@ typedef struct SQueryRuntimeEnv {
STSCursor cur;
char* tagVal; // tag value of current data block
SArithmeticSupport *sasArray;
SScalarExprSupport*sasArray;
SSDataBlock *outputBuf;
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
......@@ -686,7 +686,7 @@ void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters);
STableQueryInfo *createTableQueryInfo(SQueryAttr* pQueryAttr, void* pTable, bool groupbyColumn, STimeWindow win, void* buf);
STableQueryInfo* createTmpTableQueryInfo(STimeWindow win);
int32_t buildArithmeticExprFromMsg(SExprInfo *pArithExprInfo, void *pQueryMsg);
int32_t buildScalarExprFromMsg(SExprInfo * pExprInfo, void *pQueryMsg);
bool isQueryKilled(SQInfo *pQInfo);
int32_t checkForQueryBuf(size_t numOfTables);
......@@ -717,4 +717,5 @@ int32_t getMaximumIdleDurationSec();
void doInvokeUdf(SUdfInfo* pUdfInfo, SQLFunctionCtx *pCtx, int32_t idx, int32_t type);
int32_t getColumnDataFromId(void *param, int32_t id, void **data);
void qInfoLogSSDataBlock(SSDataBlock* block, char* location);
#endif // TDENGINE_QEXECUTOR_H
......@@ -33,7 +33,7 @@ typedef struct MinMaxEntry {
union {
double dMaxVal;
int64_t i64MaxVal;
int64_t u64MaxVal;
uint64_t u64MaxVal;
};
} MinMaxEntry;
......
......@@ -28,15 +28,17 @@ extern "C" {
#define ParseTOKENTYPE SStrToken
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
#define SQLEXPR_TYPE_UNASSIGNED 0
#define SQLEXPR_TYPE_SCALAR 1
#define SQLEXPR_TYPE_AGG 2
#define SQLEXPR_TYPE_VALUE 3
enum SQL_NODE_TYPE {
SQL_NODE_TABLE_COLUMN= 1,
SQL_NODE_SQLFUNCTION = 2,
SQL_NODE_VALUE = 3,
SQL_NODE_EXPR = 4,
SQL_NODE_DATA_TYPE = 5,
};
enum SQL_NODE_FROM_TYPE {
......@@ -271,6 +273,7 @@ typedef struct tSqlExpr {
int32_t functionId; // function id, todo remove it
SStrToken columnName; // table column info
TAOS_FIELD dataType; // data type
tVariant value; // the use input value
SStrToken exprToken; // original sql expr string
uint32_t flags; // todo remove it
......@@ -300,6 +303,7 @@ SRelationInfo *addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrT
tSqlExpr *tSqlExprCreateTimestamp(SStrToken *pToken, int32_t optrType);
tSqlExpr *tSqlExprCreateIdValue(SSqlInfo* pInfo, SStrToken *pToken, int32_t optrType);
tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
tSqlExpr *tSqlExprCreateFuncWithParams(SSqlInfo *pInfo, tSqlExpr* col, TAOS_FIELD *colType, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
SArray *tStrTokenAppend(SArray *pList, SStrToken *pToken);
tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType);
......
......@@ -17,7 +17,6 @@
%left PLUS MINUS.
%left DIVIDE TIMES.
%left STAR SLASH REM.
%left CONCAT.
%right UMINUS UPLUS BITNOT.
%right ARROW.
......@@ -751,6 +750,9 @@ expr(A) ::= ID(X) LP exprlist(Y) RP(E). { tStrTokenAppend(pInfo->funcs, &X); A =
// for parsing sql functions with wildcard for parameters. e.g., count(*)/first(*)/last(*) operation
expr(A) ::= ID(X) LP STAR RP(Y). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(NULL, &X, &Y, X.type); }
// for parsing sql function CAST(column as typename)
expr(A) ::= ID(X) LP expr(B) AS typename(C) RP(Y). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFuncWithParams(pInfo, B, &C, &X, &Y, X.type); }
// is (not) null expression
expr(A) ::= expr(X) IS NULL. {A = tSqlExprCreate(X, NULL, TK_ISNULL);}
expr(A) ::= expr(X) IS NOT NULL. {A = tSqlExprCreate(X, NULL, TK_NOTNULL);}
......
......@@ -217,11 +217,12 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return TSDB_CODE_TSC_INVALID_OPERATION;
}
assert(!TSDB_FUNC_IS_SCALAR(functionId));
assert(functionId != TSDB_FUNC_SCALAR_EXPR);
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_TAG || functionId == TSDB_FUNC_INTERP || functionId == TSDB_FUNC_CEIL ||
functionId == TSDB_FUNC_FLOOR || functionId == TSDB_FUNC_ROUND)
functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_INTERP)
{
*type = (int16_t)dataType;
*bytes = dataBytes;
......@@ -259,13 +260,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
*interBytes = 0;
return TSDB_CODE_SUCCESS;
}
if (functionId == TSDB_FUNC_ARITHM) {
*type = TSDB_DATA_TYPE_DOUBLE;
*bytes = sizeof(double);
*interBytes = 0;
return TSDB_CODE_SUCCESS;
}
if (functionId == TSDB_FUNC_TS_COMP) {
*type = TSDB_DATA_TYPE_BINARY;
......@@ -495,6 +490,18 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
// TODO use hash table
int32_t isValidFunction(const char* name, int32_t len) {
for (int32_t i = 0; i < TSDB_FUNC_SCALAR_MAX_NUM; ++i) {
int32_t nameLen = (int32_t) strlen(aScalarFunctions[i].name);
if (len != nameLen) {
continue;
}
if (strncasecmp(aScalarFunctions[i].name, name, len) == 0) {
return aScalarFunctions[i].functionId;
}
}
for(int32_t i = 0; i <= TSDB_FUNC_ELAPSED; ++i) {
int32_t nameLen = (int32_t) strlen(aAggs[i].name);
if (len != nameLen) {
......@@ -505,7 +512,6 @@ int32_t isValidFunction(const char* name, int32_t len) {
return i;
}
}
return -1;
}
......@@ -3400,8 +3406,8 @@ static void diff_function(SQLFunctionCtx *pCtx) {
}
}
char *getArithColumnData(void *param, const char* name, int32_t colId) {
SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
char *getScalarExprColumnData(void *param, const char* name, int32_t colId) {
SScalarExprSupport *pSupport = (SScalarExprSupport *)param;
int32_t index = -1;
for (int32_t i = 0; i < pSupport->numOfCols; ++i) {
......@@ -3415,11 +3421,12 @@ char *getArithColumnData(void *param, const char* name, int32_t colId) {
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;
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
arithmeticTreeTraverse(sas->pExprInfo->pExpr, pCtx->size, pCtx->pOutput, sas, pCtx->order, getArithColumnData);
SScalarExprSupport *sas = (SScalarExprSupport *)pCtx->param[1].pz;
tExprOperandInfo output;
output.data = pCtx->pOutput;
exprTreeNodeTraverse(sas->pExprInfo->pExpr, pCtx->size, &output, sas, pCtx->order, getScalarExprColumnData);
}
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
......@@ -4431,185 +4438,6 @@ void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) {
doFinalizer(pCtx);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define CFR_SET_VAL(type, data, pCtx, func, i, step) \
do { \
type *pData = (type *) data; \
type *pOutput = (type *) pCtx->pOutput; \
\
for (; i < pCtx->size && i >= 0; i += step) { \
if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { \
*pOutput++ = pData[i]; \
} else { \
*pOutput++ = (type)func((double)pData[i]); \
} \
} \
} while (0)
static void ceil_function(SQLFunctionCtx *pCtx) {
void *data = GET_INPUT_DATA_LIST(pCtx);
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1;
switch (pCtx->inputType) {
case TSDB_DATA_TYPE_INT: {
CFR_SET_VAL(int32_t, data, pCtx, ceil, i, step);
break;
};
case TSDB_DATA_TYPE_UINT: {
CFR_SET_VAL(uint32_t, data, pCtx, ceil, i, step);
break;
};
case TSDB_DATA_TYPE_BIGINT: {
CFR_SET_VAL(int64_t, data, pCtx, ceil, i, step);
break;
}
case TSDB_DATA_TYPE_UBIGINT: {
CFR_SET_VAL(uint64_t, data, pCtx, ceil, i, step);
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
CFR_SET_VAL(double, data, pCtx, ceil, i, step);
break;
}
case TSDB_DATA_TYPE_FLOAT: {
CFR_SET_VAL(float, data, pCtx, ceil, i, step);
break;
}
case TSDB_DATA_TYPE_SMALLINT: {
CFR_SET_VAL(int16_t, data, pCtx, ceil, i, step);
break;
}
case TSDB_DATA_TYPE_USMALLINT: {
CFR_SET_VAL(uint16_t, data, pCtx, ceil, i, step);
break;
}
case TSDB_DATA_TYPE_TINYINT: {
CFR_SET_VAL(int8_t, data, pCtx, ceil, i, step);
break;
}
case TSDB_DATA_TYPE_UTINYINT: {
CFR_SET_VAL(uint8_t, data, pCtx, ceil, i, step);
break;
}
default:
qError("error input type");
}
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
}
static void floor_function(SQLFunctionCtx *pCtx) {
void *data = GET_INPUT_DATA_LIST(pCtx);
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1;
switch (pCtx->inputType) {
case TSDB_DATA_TYPE_INT: {
CFR_SET_VAL(int32_t, data, pCtx, floor, i, step);
break;
};
case TSDB_DATA_TYPE_UINT: {
CFR_SET_VAL(uint32_t, data, pCtx, floor, i, step);
break;
};
case TSDB_DATA_TYPE_BIGINT: {
CFR_SET_VAL(int64_t, data, pCtx, floor, i, step);
break;
}
case TSDB_DATA_TYPE_UBIGINT: {
CFR_SET_VAL(uint64_t, data, pCtx, floor, i, step);
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
CFR_SET_VAL(double, data, pCtx, floor, i, step);
break;
}
case TSDB_DATA_TYPE_FLOAT: {
CFR_SET_VAL(float, data, pCtx, floor, i, step);
break;
}
case TSDB_DATA_TYPE_SMALLINT: {
CFR_SET_VAL(int16_t, data, pCtx, floor, i, step);
break;
}
case TSDB_DATA_TYPE_USMALLINT: {
CFR_SET_VAL(uint16_t, data, pCtx, floor, i, step);
break;
}
case TSDB_DATA_TYPE_TINYINT: {
CFR_SET_VAL(int8_t, data, pCtx, floor, i, step);
break;
}
case TSDB_DATA_TYPE_UTINYINT: {
CFR_SET_VAL(uint8_t, data, pCtx, floor, i, step);
break;
}
default:
qError("error input type");
}
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
}
static void round_function(SQLFunctionCtx *pCtx) {
void *data = GET_INPUT_DATA_LIST(pCtx);
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1;
switch (pCtx->inputType) {
case TSDB_DATA_TYPE_INT: {
CFR_SET_VAL(int32_t, data, pCtx, round, i, step);
break;
};
case TSDB_DATA_TYPE_UINT: {
CFR_SET_VAL(uint32_t, data, pCtx, round, i, step);
break;
};
case TSDB_DATA_TYPE_BIGINT: {
CFR_SET_VAL(int64_t, data, pCtx, round, i, step);
break;
}
case TSDB_DATA_TYPE_UBIGINT: {
CFR_SET_VAL(uint64_t, data, pCtx, round, i, step);
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
CFR_SET_VAL(double, data, pCtx, round, i, step);
break;
}
case TSDB_DATA_TYPE_FLOAT: {
CFR_SET_VAL(float, data, pCtx, round, i, step);
break;
}
case TSDB_DATA_TYPE_SMALLINT: {
CFR_SET_VAL(int16_t, data, pCtx, round, i, step);
break;
}
case TSDB_DATA_TYPE_USMALLINT: {
CFR_SET_VAL(uint16_t, data, pCtx, round, i, step);
break;
}
case TSDB_DATA_TYPE_TINYINT: {
CFR_SET_VAL(int8_t, data, pCtx, round, i, step);
break;
}
case TSDB_DATA_TYPE_UTINYINT: {
CFR_SET_VAL(uint8_t, data, pCtx, round, i, step);
break;
}
default:
qError("error input type");
}
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
}
#undef CFR_SET_VAL
//////////////////////////////////////////////////////////////////////////////////
//cumulative_sum function
......@@ -5069,13 +4897,13 @@ int32_t functionCompatList[] = {
4, -1, -1, 1, 1, 1, 1, 1, 1, -1,
// tag, colprj, tagprj, arithm, diff, first_dist, last_dist, stddev_dst, interp rate, irate
1, 1, 1, 1, -1, 1, 1, 1, 5, 1, 1,
// tid_tag, deriv, ceil, floor, round, csum, mavg, sample,
6, 8, 1, 1, 1, -1, -1, -1,
// tid_tag, deriv, csum, mavg, sample,
6, 8, -1, -1, -1,
// block_info, elapsed
7, 1
};
SAggFunctionInfo aAggs[] = {{
SAggFunctionInfo aAggs[40] = {{
// 0, count function does not invoke the finalize function
"count",
TSDB_FUNC_COUNT,
......@@ -5357,11 +5185,11 @@ SAggFunctionInfo aAggs[] = {{
{
// 23
"arithmetic",
TSDB_FUNC_ARITHM,
TSDB_FUNC_ARITHM,
TSDB_FUNC_SCALAR_EXPR,
TSDB_FUNC_SCALAR_EXPR,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
function_setup,
arithmetic_function,
scalar_expr_function,
doFinalizer,
copy_function,
dataBlockRequired,
......@@ -5474,41 +5302,8 @@ SAggFunctionInfo aAggs[] = {{
noop1,
dataBlockRequired,
},
{// 33
"ceil",
TSDB_FUNC_CEIL,
TSDB_FUNC_CEIL,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SCALAR,
function_setup,
ceil_function,
doFinalizer,
noop1,
dataBlockRequired
},
{// 34
"floor",
TSDB_FUNC_FLOOR,
TSDB_FUNC_FLOOR,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SCALAR,
function_setup,
floor_function,
doFinalizer,
noop1,
dataBlockRequired
},
{// 35
"round",
TSDB_FUNC_ROUND,
TSDB_FUNC_ROUND,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SCALAR,
function_setup,
round_function,
doFinalizer,
noop1,
dataBlockRequired
},
{
// 36
// 33
"csum",
TSDB_FUNC_CSUM,
TSDB_FUNC_INVALID_ID,
......@@ -5520,7 +5315,7 @@ SAggFunctionInfo aAggs[] = {{
dataBlockRequired,
},
{
// 37
// 34
"mavg",
TSDB_FUNC_MAVG,
TSDB_FUNC_INVALID_ID,
......@@ -5532,7 +5327,7 @@ SAggFunctionInfo aAggs[] = {{
dataBlockRequired,
},
{
// 38
// 35
"sample",
TSDB_FUNC_SAMPLE,
TSDB_FUNC_SAMPLE,
......@@ -5544,7 +5339,7 @@ SAggFunctionInfo aAggs[] = {{
dataBlockRequired,
},
{
// 39
// 36
"_block_dist",
TSDB_FUNC_BLKINFO,
TSDB_FUNC_BLKINFO,
......@@ -5556,7 +5351,7 @@ SAggFunctionInfo aAggs[] = {{
dataBlockRequired,
},
{
// 40
// 37
"elapsed",
TSDB_FUNC_ELAPSED,
TSDB_FUNC_ELAPSED,
......
......@@ -414,6 +414,10 @@ static bool isSelectivityWithTagsQuery(SQLFunctionCtx *pCtx, int32_t numOfOutput
for (int32_t i = 0; i < numOfOutput; ++i) {
int32_t functId = pCtx[i].functionId;
if (TSDB_FUNC_IS_SCALAR(functId)) {
continue;
}
if (functId == TSDB_FUNC_TAG_DUMMY || functId == TSDB_FUNC_TS_DUMMY) {
hasTags = true;
continue;
......@@ -433,13 +437,14 @@ static bool isScalarWithTagsQuery(SQLFunctionCtx *pCtx, int32_t numOfOutput) {
for (int32_t i = 0; i < numOfOutput; ++i) {
int32_t functId = pCtx[i].functionId;
if (functId == TSDB_FUNC_TAG_DUMMY || functId == TSDB_FUNC_TS_DUMMY) {
hasTags = true;
if (TSDB_FUNC_IS_SCALAR(functId)) {
numOfScalar++;
continue;
}
if ((aAggs[functId].status & TSDB_FUNCSTATE_SCALAR) != 0) {
numOfScalar++;
if (functId == TSDB_FUNC_TAG_DUMMY || functId == TSDB_FUNC_TS_DUMMY) {
hasTags = true;
continue;
}
}
......@@ -974,8 +979,10 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
if (functionId < 0) { // load the script and exec, pRuntimeEnv->pUdfInfo
SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo;
doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL);
} else {
} else if (!TSDB_FUNC_IS_SCALAR(functionId)){
aAggs[functionId].xFunction(&pCtx[k]);
} else {
assert(0);
}
}
......@@ -1116,7 +1123,7 @@ static TSKEY getStartTsKey(SQueryAttr* pQueryAttr, STimeWindow* win, const TSKEY
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->pExprInfo = pExprInfo;
if (sas->colList) {
......@@ -1152,8 +1159,8 @@ static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SQLFunctionCtx* pC
}
void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order) {
if (pCtx[0].functionId == TSDB_FUNC_ARITHM) {
SArithmeticSupport* pSupport = (SArithmeticSupport*) pCtx[0].param[1].pz;
if (pCtx[0].functionId == TSDB_FUNC_SCALAR_EXPR) {
SScalarExprSupport* pSupport = (SScalarExprSupport*) pCtx[0].param[1].pz;
if (pSupport->colList == NULL) {
doSetInputDataBlock(pOperator, pCtx, pBlock, order);
} else {
......@@ -1176,8 +1183,8 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx,
setBlockStatisInfo(&pCtx[i], pBlock, &pOperator->pExpr[i].base.colInfo);
if (pCtx[i].functionId == TSDB_FUNC_ARITHM) {
setArithParams((SArithmeticSupport*)pCtx[i].param[1].pz, &pOperator->pExpr[i], pBlock);
if (pCtx[i].functionId == TSDB_FUNC_SCALAR_EXPR) {
setArithParams((SScalarExprSupport*)pCtx[i].param[1].pz, &pOperator->pExpr[i], pBlock);
} else {
SColIndex* pCol = &pOperator->pExpr[i].base.colInfo;
if (TSDB_COL_IS_NORMAL_COL(pCol->flag) || (pCtx[i].functionId == TSDB_FUNC_BLKINFO) ||
......@@ -1190,10 +1197,9 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx,
pCtx[i].colId = p->info.colId;
assert(p->info.colId == pColIndex->colId && pCtx[i].inputType == p->info.type);
if (pCtx[i].functionId < 0) {
if (pCtx[i].functionId < 0 || TSDB_FUNC_IS_SCALAR(pCtx[i].functionId)) {
SColumnInfoData* tsInfo = taosArrayGet(pBlock->pDataBlock, 0);
pCtx[i].ptsList = (int64_t*) tsInfo->pData;
pCtx[i].ptsList = (int64_t*)tsInfo->pData;
continue;
}
......@@ -1234,8 +1240,10 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SQLFunction
if (functionId < 0) {
SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo;
doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL);
} else {
} else if (!TSDB_FUNC_IS_SCALAR(functionId)){
aAggs[functionId].xFunction(&pCtx[k]);
} else {
assert(0);
}
}
}
......@@ -1255,8 +1263,10 @@ static void projectApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx
// load the script and exec
SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo;
doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL);
} else {
} else if (!TSDB_FUNC_IS_SCALAR(pCtx[k].functionId)) {
aAggs[pCtx[k].functionId].xFunction(&pCtx[k]);
} else {
assert(0);
}
}
}
......@@ -1855,11 +1865,14 @@ static int32_t setCtxTagColumnInfo(SQLFunctionCtx *pCtx, int32_t numOfOutput) {
for (int32_t i = 0; i < numOfOutput; ++i) {
int32_t functionId = pCtx[i].functionId;
if (functionId < 0 || TSDB_FUNC_IS_SCALAR(functionId)) {
continue;
}
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) {
tagLen += pCtx[i].outputBytes;
pTagCtx[num++] = &pCtx[i];
} else if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0 || (aAggs[functionId].status & TSDB_FUNCSTATE_SCALAR) != 0) {
} else if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) {
p = &pCtx[i];
} else if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG) {
// tag function may be the group by tag column
......@@ -1972,7 +1985,7 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr
pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT;
pCtx->param[2].i64 = pQueryAttr->window.ekey;
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];
}
}
......@@ -2023,7 +2036,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
// 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->sasArray = calloc(pQueryAttr->numOfOutput, sizeof(SArithmeticSupport));
pRuntimeEnv->sasArray = calloc(pQueryAttr->numOfOutput, sizeof(SScalarExprSupport));
if (pRuntimeEnv->sasArray == NULL || pRuntimeEnv->pResultRowHashTable == NULL || pRuntimeEnv->keyBuf == NULL ||
pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL) {
......@@ -2198,7 +2211,13 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
}
case OP_Order: {
pRuntimeEnv->proot = createOrderOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput, &pQueryAttr->order);
if (pQueryAttr->pExpr2 != NULL) {
pRuntimeEnv->proot = createOrderOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr2,
pQueryAttr->numOfExpr2, &pQueryAttr->order);
} else {
pRuntimeEnv->proot = createOrderOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1,
pQueryAttr->numOfOutput, &pQueryAttr->order);
}
break;
}
......@@ -2955,7 +2974,7 @@ static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSData
int32_t colId = pTableScanInfo->pExpr[i].base.colInfo.colId;
// group by + first/last should not apply the first/last block filter
if (functionId < 0) {
if (functionId < 0 || TSDB_FUNC_IS_SCALAR(functionId)) {
status |= BLK_DATA_ALL_NEEDED;
return status;
} else {
......@@ -3665,8 +3684,10 @@ void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size) {
if (pCtx[j].functionId < 0) { // todo udf initialization
continue;
} else {
} else if (!TSDB_FUNC_IS_SCALAR(pCtx[j].functionId)) {
aAggs[pCtx[j].functionId].init(&pCtx[j], pCtx[j].resultInfo);
} else {
assert(0);
}
}
}
......@@ -3725,8 +3746,10 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResult
pCtx[j].startTs = buf->win.skey;
if (pCtx[j].functionId < 0) {
doInvokeUdf(pRuntimeEnv->pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE);
} else {
} else if (!TSDB_FUNC_IS_SCALAR(pCtx[j].functionId)) {
aAggs[pCtx[j].functionId].xFinalize(&pCtx[j]);
} else {
assert(0);
}
}
......@@ -3742,8 +3765,10 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResult
for (int32_t j = 0; j < numOfOutput; ++j) {
if (pCtx[j].functionId < 0) {
doInvokeUdf(pRuntimeEnv->pUdfInfo, &pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE);
} else {
} else if (!TSDB_FUNC_IS_SCALAR(pCtx[j].functionId)) {
aAggs[pCtx[j].functionId].xFinalize(&pCtx[j]);
} else {
assert(0);
}
}
}
......@@ -3831,9 +3856,6 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
offset += pCtx[i].outputBytes;
int32_t functionId = pCtx[i].functionId;
if (functionId < 0) {
continue;
}
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF ||
functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_SAMPLE) {
......@@ -3841,7 +3863,13 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
}
if (!pResInfo->initialized) {
aAggs[functionId].init(&pCtx[i], pResInfo);
if (functionId < 0 ) {
doInvokeUdf(pRuntimeEnv->pUdfInfo, &pCtx[i], 0, TSDB_UDF_FUNC_INIT);
} else if (!TSDB_FUNC_IS_SCALAR(functionId)) {
aAggs[functionId].init(&pCtx[i], pResInfo);
} else {
assert(0);
}
}
}
}
......@@ -5544,8 +5572,8 @@ SOperatorInfo *createOrderOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
for(int32_t i = 0; i < numOfOutput; ++i) {
SColumnInfoData col = {{0}};
col.info.colId = pExpr[i].base.colInfo.colId;
col.info.bytes = pExpr[i].base.colBytes;
col.info.type = pExpr[i].base.colType;
col.info.bytes = pExpr[i].base.resBytes;
col.info.type = pExpr[i].base.resType;
taosArrayPush(pDataBlock->pDataBlock, &col);
if (col.info.colId == pOrderVal->orderColId) {
......@@ -5767,7 +5795,15 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
break;
} else { // init output buffer for a new group data
for (int32_t j = 0; j < pOperator->numOfOutput; ++j) {
aAggs[pInfo->pCtx[j].functionId].xFinalize(&pInfo->pCtx[j]);
int16_t functionId = pInfo->pCtx[j].functionId;
if (functionId < 0 ) {
SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo;
doInvokeUdf(pUdfInfo, &pInfo->pCtx[j], 0, TSDB_UDF_FUNC_FINALIZE);
} else if (!TSDB_FUNC_IS_SCALAR(functionId)) {
aAggs[pInfo->pCtx[j].functionId].xFinalize(&pInfo->pCtx[j]);
} else {
assert(0);
}
}
initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfOutput);
}
......@@ -8261,7 +8297,7 @@ int32_t cloneExprFilterInfo(SColumnFilterInfo **dst, SColumnFilterInfo* src, int
return TSDB_CODE_SUCCESS;
}
int32_t buildArithmeticExprFromMsg(SExprInfo *pExprInfo, void *pQueryMsg) {
int32_t buildScalarExprFromMsg(SExprInfo *pExprInfo, void *pQueryMsg) {
qDebug("qmsg:%p create arithmetic expr from binary", pQueryMsg);
tExprNode* pExprNode = NULL;
......@@ -8474,16 +8510,13 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp
int16_t bytes = 0;
// parse the arithmetic expression
if (pExprs[i].base.functionId == TSDB_FUNC_ARITHM) {
code = buildArithmeticExprFromMsg(&pExprs[i], pMsg);
if (pExprs[i].base.functionId == TSDB_FUNC_SCALAR_EXPR) {
code = buildScalarExprFromMsg(&pExprs[i], pMsg);
if (code != TSDB_CODE_SUCCESS) {
tfree(pExprs);
return code;
}
type = TSDB_DATA_TYPE_DOUBLE;
bytes = tDataTypes[type].bytes;
} else if (pExprs[i].base.functionId == TSDB_FUNC_BLKINFO) {
SSchema s = {.type=TSDB_DATA_TYPE_BINARY, .bytes=TSDB_MAX_BINARY_LEN};
type = s.type;
......@@ -8537,14 +8570,14 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp
}
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)) {
tfree(pExprs);
return TSDB_CODE_QRY_INVALID_MSG;
}
// todo remove it
if (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) {
tfree(pExprs);
return TSDB_CODE_QRY_INVALID_MSG;
......@@ -8613,31 +8646,32 @@ int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg* pQueryMsg, int32_t nu
int16_t bytes = 0;
// parse the arithmetic expression
if (pExprs[i].base.functionId == TSDB_FUNC_ARITHM) {
code = buildArithmeticExprFromMsg(&pExprs[i], pQueryMsg);
if (pExprs[i].base.functionId == TSDB_FUNC_SCALAR_EXPR) {
code = buildScalarExprFromMsg(&pExprs[i], pQueryMsg);
if (code != TSDB_CODE_SUCCESS) {
tfree(pExprs);
return code;
}
type = TSDB_DATA_TYPE_DOUBLE;
bytes = tDataTypes[type].bytes;
pExprs[i].base.resBytes = pExprs[i].pExpr->resultBytes;
pExprs[i].base.resType = pExprs[i].pExpr->resultType;
pExprs[i].base.interBytes = 0;
} else {
int32_t index = pExprs[i].base.colInfo.colIndex;
assert(prevExpr[index].base.resColId == pExprs[i].base.colInfo.colId);
type = prevExpr[index].base.resType;
type = prevExpr[index].base.resType;
bytes = prevExpr[index].base.resBytes;
}
int32_t param = (int32_t)pExprs[i].base.param[0].i64;
if (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) {
tfree(pExprs);
return TSDB_CODE_QRY_INVALID_MSG;
int32_t param = (int32_t)pExprs[i].base.param[0].i64;
if (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) {
tfree(pExprs);
return TSDB_CODE_QRY_INVALID_MSG;
}
}
assert(isValidDataType(pExprs[i].base.resType));
}
......@@ -8757,7 +8791,7 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) {
for (int32_t k = 0; k < pQueryAttr->numOfOutput; ++k) {
SSqlExpr *pSqlExprMsg = &pQueryAttr->pExpr1[k].base;
if (pSqlExprMsg->functionId == TSDB_FUNC_ARITHM) {
if (pSqlExprMsg->functionId == TSDB_FUNC_SCALAR_EXPR) {
continue;
}
......@@ -9406,4 +9440,3 @@ void freeQueryAttr(SQueryAttr* pQueryAttr) {
filterFreeInfo(pQueryAttr->pFilters);
}
}
......@@ -74,7 +74,7 @@ static int32_t setBoundingBox(MinMaxEntry* range, int16_t type, double minval, d
}
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)){
range->u64MinVal = (uint64_t) minval;
if ((uint64_t)maxval > UINT64_MAX) {
if (maxval > UINT64_MAX) {
range->u64MaxVal = UINT64_MAX;
} else {
range->u64MaxVal = (uint64_t) maxval;
......@@ -146,7 +146,7 @@ int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) {
}
int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) {
int64_t v = 0;
uint64_t v = 0;
GET_TYPED_DATA(v, uint64_t, pBucket->type, value);
int32_t index = -1;
......@@ -162,8 +162,8 @@ int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) {
index = (int32_t) (delta % pBucket->numOfSlots);
} else {
double slotSpan = (double)span / pBucket->numOfSlots;
index = (int32_t)((v - pBucket->range.u64MinVal) / slotSpan);
if (v == pBucket->range.u64MaxVal) {
index = (int32_t)(((double)v - pBucket->range.u64MinVal) / slotSpan);
if (index == pBucket->numOfSlots) {
index -= 1;
}
}
......@@ -194,7 +194,7 @@ int32_t tBucketDoubleHash(tMemBucket *pBucket, const void *value) {
} else {
double slotSpan = span / pBucket->numOfSlots;
index = (int32_t)((v - pBucket->range.dMinVal) / slotSpan);
if (v == pBucket->range.dMaxVal) {
if (index == pBucket->numOfSlots) {
index -= 1;
}
}
......
......@@ -567,6 +567,10 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
} else if (pQueryAttr->pointInterpQuery) {
op = OP_TimeEvery;
taosArrayPush(plan, &op);
if (pQueryAttr->pExpr2 != NULL) {
op = OP_Project;
taosArrayPush(plan, &op);
}
} else if (pQueryAttr->interval.interval > 0) {
if (pQueryAttr->stableQuery) {
op = OP_MultiTableTimeInterval;
......@@ -691,7 +695,6 @@ SArray* createGlobalMergePlan(SQueryAttr* pQueryAttr) {
op = OP_Filter;
taosArrayPush(plan, &op);
}
if (pQueryAttr->pExpr2 != NULL) {
op = OP_Project;
taosArrayPush(plan, &op);
......
......@@ -178,6 +178,14 @@ tSqlExpr *tSqlExprCreateIdValue(SSqlInfo* pInfo, SStrToken *pToken, int32_t optr
pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pSqlExpr->tokenId = TK_TIMESTAMP;
pSqlExpr->type = SQL_NODE_VALUE;
} else if (optrType == TK_AS) {
// Here it must be column type
if (pToken != NULL) {
pSqlExpr->dataType = *(TAOS_FIELD *)pToken;
}
pSqlExpr->tokenId = optrType;
pSqlExpr->type = SQL_NODE_DATA_TYPE;
} else {
// Here it must be the column name (tk_id) if it is not a number or string.
assert(optrType == TK_ID || optrType == TK_ALL);
......@@ -275,6 +283,25 @@ tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToke
return pExpr;
}
tSqlExpr *tSqlExprCreateFuncWithParams(SSqlInfo *pInfo, tSqlExpr* col, TAOS_FIELD *colType, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType) {
if (colType == NULL || col == NULL) {
return NULL;
}
if (NULL == col) {
return NULL;
}
tSqlExpr* ctype = tSqlExprCreateIdValue(pInfo, (SStrToken *)colType, TK_AS);
SArray *exprList = tSqlExprListAppend(0,col,0, 0);
tSqlExprListAppend(exprList,ctype,0, 0);
return tSqlExprCreateFunction(exprList, pFuncToken, endToken, optType);
}
/*
* create binary expression in this procedure
* if the expr is arithmetic, calculate the result and set it to tSqlExpr Object
......@@ -391,7 +418,7 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pExpr->tokenId = optrType;
pExpr->pLeft = pLeft;
pExpr->pRight = pRight;
pExpr->type = SQL_NODE_TABLE_COLUMN;
pExpr->type = SQL_NODE_EXPR;
} else {
pExpr->tokenId = optrType;
pExpr->pLeft = pLeft;
......@@ -825,6 +852,10 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
pField->bytes = (int16_t)bytes;
}
} else {
if (type->type > 0) {
pField->type = -1;
}
}
}
......
此差异已折叠。
......@@ -73,7 +73,6 @@ static SKeyword keywordTable[] = {
{"STAR", TK_STAR},
{"SLASH", TK_SLASH},
{"REM ", TK_REM},
{"CONCAT", TK_CONCAT},
{"UMINUS", TK_UMINUS},
{"UPLUS", TK_UPLUS},
{"BITNOT", TK_BITNOT},
......@@ -400,9 +399,6 @@ uint32_t tGetToken(char* z, uint32_t* tokenId) {
if (z[1] != '|') {
*tokenId = TK_BITOR;
return 1;
} else {
*tokenId = TK_CONCAT;
return 2;
}
}
case ',': {
......
......@@ -30,7 +30,7 @@ class TDTestCase:
print("==============step1")
tdSql.execute(
"CREATE TABLE IF NOT EXISTS ampere (ts TIMESTAMP(8),ampere DOUBLE(8)) TAGS (device_name BINARY(50),build_id BINARY(50),project_id BINARY(50),alias BINARY(50))")
"CREATE TABLE IF NOT EXISTS ampere (ts TIMESTAMP,ampere DOUBLE) TAGS (device_name BINARY(50),build_id BINARY(50),project_id BINARY(50),alias BINARY(50))")
tdSql.execute("insert into d1001 using ampere tags('test', '2', '2', '2') VALUES (now, 123)")
tdSql.execute("ALTER TABLE ampere ADD TAG variable_id BINARY(50)")
......
......@@ -38,6 +38,11 @@ run general/compute/stddev.sim
run general/compute/sum.sim
run general/compute/top.sim
run general/compute/block_dist.sim
run general/compute/math_funcs.sim
run general/compute/string_funcs.sim
run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/compute/table_group.sim
run general/db/alter_option.sim
run general/db/alter_tables_d2.sim
......@@ -140,6 +145,7 @@ run general/parser/groupby.sim
run general/parser/top_groupby.sim
run general/parser/tags_dynamically_specifiy.sim
run general/parser/set_tag_vals.sim
run general/parser/scalar_expression.sim
#unsupport run general/parser/repeatAlter.sim
#unsupport run general/parser/slimit_alter_tags.sim
run general/parser/precision_ns.sim
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
sleep 100
sql connect
sql use db;
sql select cast(stb1.c4 as binary(10)),cast(stba.c5 as binary(10)) from stb1,stba where stb1.t1=stba.t1 and stb1.ts=stba.ts;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data11 != 2 then
return -1
endi
if $data20 != 2 then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data31 != 4 then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data41 != 5 then
return -1
endi
if $data50 != 2147483647 then
return -1
endi
if $data51 != 6 then
return -1
endi
if $data60 != -214748364 then
return -1
endi
if $data61 != 7 then
return -1
endi
sql select cast(c4 as binary(10)) as a from stb1 union all select cast(c5 as binary(10)) as a from stba;
if $rows != 44 then
return -1
endi
sql select cast(c2 as bigint) from stba;
if $rows != 30 then
return -1
endi
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -20,4 +20,9 @@ run general/compute/stddev.sim
run general/compute/sum.sim
run general/compute/top.sim
run general/compute/block_dist.sim
run general/compute/math_funcs.sim
run general/compute/string_funcs.sim
run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/compute/table_group.sim
此差异已折叠。
......@@ -38,6 +38,11 @@ run general/compute/stddev.sim
run general/compute/sum.sim
run general/compute/top.sim
run general/compute/block_dist.sim
run general/compute/math_funcs.sim
run general/compute/string_funcs.sim
run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/compute/table_group.sim
run general/db/alter_option.sim
run general/db/alter_tables_d2.sim
......@@ -141,6 +146,7 @@ run general/parser/tags_dynamically_specifiy.sim
run general/parser/set_tag_vals.sim
run general/parser/repeatAlter.sim
run general/parser/precision_ns.sim
run general/parser/scalar_expression.sim
##unsupport run general/parser/slimit_alter_tags.sim
run general/stable/disk.sim
run general/stable/dnode3.sim
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册