From bb1a615c46034c83679e63185fc606aa6ac183b3 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Sun, 8 Mar 2020 16:39:25 +0800 Subject: [PATCH] add query module, remove some functions from utility and tsclient module --- src/CMakeLists.txt | 1 + src/client/CMakeLists.txt | 3 +- src/client/inc/tscSQLParser.h | 380 +------- src/client/inc/tsclient.h | 1 + src/{util => client}/src/tcache.c | 0 src/client/src/tscParseInsert.c | 4 +- src/client/src/tscSchemaUtil.c | 2 +- src/client/src/tscUtil.c | 6 +- src/dnode/CMakeLists.txt | 1 + src/inc/taosdef.h | 14 - src/{util/inc/tsqldef.h => inc/ttokendef.h} | 0 src/kit/shell/CMakeLists.txt | 1 + src/kit/shell/src/shellEngine.c | 1 + src/kit/taosdump/CMakeLists.txt | 1 + src/mnode/CMakeLists.txt | 1 + src/mnode/src/mgmtChildTable.c | 3 - src/mnode/src/mgmtNormalTable.c | 4 - src/mnode/src/mgmtSuperTable.c | 2 - src/plugins/http/CMakeLists.txt | 1 + src/plugins/monitor/CMakeLists.txt | 1 + src/plugins/monitor/src/monitorSystem.c | 6 +- src/query/CMakeLists.txt | 13 + src/query/inc/qsqlparser.h | 336 +++++++ src/query/inc/qsqltype.h | 97 ++ src/{ => query}/inc/sql.y | 0 src/{util => query}/inc/tast.h | 6 +- src/{util => query}/inc/tcache.h | 0 src/{util => query}/inc/textbuffer.h | 0 src/{util => query}/inc/thistogram.h | 0 src/{util => query}/inc/tinterpolation.h | 0 src/{util => query}/inc/tlosertree.h | 0 src/{ => query}/inc/tresultBuf.h | 15 + .../inc/tscSyntaxtreefunction.h | 0 src/{util => query}/inc/tsqlfunction.h | 1 + src/query/inc/tvariant.h | 55 ++ src/{client => query}/src/sql.c | 11 +- src/{util => query}/src/textbuffer.c | 0 src/{util => query}/src/thistogram.c | 0 src/{util => query}/src/tinterpolation.c | 0 src/{util => query}/src/tlosertree.c | 0 src/{util => query}/src/tpercentile.c | 0 src/{util => query}/src/tresultBuf.c | 0 src/{client => query}/src/tscAst.c | 550 +++++------ src/{client => query}/src/tscSQLParserImpl.c | 5 +- .../src/tscSyntaxtreefunction.c | 1 - src/{util => query}/src/ttokenizer.c | 8 +- src/query/src/tvariant.c | 851 +++++++++++++++++ src/util/inc/sskiplist.h | 2 + src/util/inc/tstoken.h | 2 +- src/util/inc/ttypes.h | 48 +- src/util/src/sskiplist.c | 4 + src/util/src/ttypes.c | 853 +----------------- src/vnode/detail/src/vnodeSupertableQuery.c | 2 +- 53 files changed, 1723 insertions(+), 1570 deletions(-) rename src/{util => client}/src/tcache.c (100%) rename src/{util/inc/tsqldef.h => inc/ttokendef.h} (100%) create mode 100644 src/query/CMakeLists.txt create mode 100644 src/query/inc/qsqlparser.h create mode 100644 src/query/inc/qsqltype.h rename src/{ => query}/inc/sql.y (100%) rename src/{util => query}/inc/tast.h (98%) rename src/{util => query}/inc/tcache.h (100%) rename src/{util => query}/inc/textbuffer.h (100%) rename src/{util => query}/inc/thistogram.h (100%) rename src/{util => query}/inc/tinterpolation.h (100%) rename src/{util => query}/inc/tlosertree.h (100%) rename src/{ => query}/inc/tresultBuf.h (78%) rename src/{client => query}/inc/tscSyntaxtreefunction.h (100%) rename src/{util => query}/inc/tsqlfunction.h (99%) create mode 100644 src/query/inc/tvariant.h rename src/{client => query}/src/sql.c (99%) rename src/{util => query}/src/textbuffer.c (100%) rename src/{util => query}/src/thistogram.c (100%) rename src/{util => query}/src/tinterpolation.c (100%) rename src/{util => query}/src/tlosertree.c (100%) rename src/{util => query}/src/tpercentile.c (100%) rename src/{util => query}/src/tresultBuf.c (100%) rename src/{client => query}/src/tscAst.c (68%) rename src/{client => query}/src/tscSQLParserImpl.c (99%) rename src/{client => query}/src/tscSyntaxtreefunction.c (99%) rename src/{util => query}/src/ttokenizer.c (99%) create mode 100644 src/query/src/tvariant.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34768b00df..81df1196f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,4 +11,5 @@ ADD_SUBDIRECTORY(sdb) ADD_SUBDIRECTORY(mnode) ADD_SUBDIRECTORY(vnode) ADD_SUBDIRECTORY(dnode) +ADD_SUBDIRECTORY(query) #ADD_SUBDIRECTORY(connector/jdbc) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 55d6cb251c..827c65435d 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(jni) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) AUX_SOURCE_DIRECTORY(src SRC) @@ -14,7 +15,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) # set the static lib name ADD_LIBRARY(taos_static STATIC ${SRC}) - TARGET_LINK_LIBRARIES(taos_static trpc tutil pthread m rt) + TARGET_LINK_LIBRARIES(taos_static query trpc tutil pthread m rt) SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static") SET_TARGET_PROPERTIES(taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) diff --git a/src/client/inc/tscSQLParser.h b/src/client/inc/tscSQLParser.h index 0e4ad279dc..87c193de75 100644 --- a/src/client/inc/tscSQLParser.h +++ b/src/client/inc/tscSQLParser.h @@ -22,69 +22,10 @@ extern "C" { #include "taos.h" #include "taosmsg.h" -#include "tsqldef.h" +#include "ttokendef.h" #include "ttypes.h" - -enum _sql_cmd { - TSDB_SQL_SELECT = 1, - TSDB_SQL_FETCH, - TSDB_SQL_INSERT, - - TSDB_SQL_MGMT, // the SQL below is for mgmt node - TSDB_SQL_CREATE_DB, - TSDB_SQL_CREATE_TABLE, - TSDB_SQL_DROP_DB, - TSDB_SQL_DROP_TABLE, - TSDB_SQL_CREATE_ACCT, - TSDB_SQL_CREATE_USER, //10 - TSDB_SQL_DROP_ACCT, - TSDB_SQL_DROP_USER, - TSDB_SQL_ALTER_USER, - TSDB_SQL_ALTER_ACCT, - TSDB_SQL_ALTER_TABLE, - TSDB_SQL_ALTER_DB, - TSDB_SQL_CREATE_MNODE, - TSDB_SQL_DROP_MNODE, - TSDB_SQL_CREATE_DNODE, - TSDB_SQL_DROP_DNODE, // 20 - TSDB_SQL_CFG_DNODE, - TSDB_SQL_CFG_MNODE, - TSDB_SQL_SHOW, - TSDB_SQL_RETRIEVE, - TSDB_SQL_KILL_QUERY, - TSDB_SQL_KILL_STREAM, - TSDB_SQL_KILL_CONNECTION, - - TSDB_SQL_READ, // SQL below is for read operation - TSDB_SQL_CONNECT, - TSDB_SQL_USE_DB, // 30 - TSDB_SQL_META, - TSDB_SQL_METRIC, - TSDB_SQL_MULTI_META, - TSDB_SQL_HB, - - TSDB_SQL_LOCAL, // SQL below for client local - TSDB_SQL_DESCRIBE_TABLE, - TSDB_SQL_RETRIEVE_METRIC, - TSDB_SQL_METRIC_JOIN_RETRIEVE, - TSDB_SQL_RETRIEVE_TAGS, - - /* - * build empty result instead of accessing dnode to fetch result - * reset the client cache - */ - TSDB_SQL_RETRIEVE_EMPTY_RESULT, //40 - - TSDB_SQL_RESET_CACHE, - TSDB_SQL_SERV_STATUS, - TSDB_SQL_CURRENT_DB, - TSDB_SQL_SERV_VERSION, - TSDB_SQL_CLI_VERSION, - TSDB_SQL_CURRENT_USER, - TSDB_SQL_CFG_LOCAL, - - TSDB_SQL_MAX //48 -}; +#include "tvariant.h" +#include "qsqlparser.h" enum { TSQL_NODE_TYPE_EXPR = 0x1, @@ -96,321 +37,6 @@ enum { #define NORMAL_ARITHMETIC 1 #define AGG_ARIGHTMEIC 2 -extern char tTokenTypeSwitcher[13]; - -#define toTSDBType(x) \ - do { \ - if ((x) >= tListLen(tTokenTypeSwitcher)) { \ - (x) = TSDB_DATA_TYPE_BINARY; \ - } else { \ - (x) = tTokenTypeSwitcher[(x)]; \ - } \ - } while (0) - -typedef struct SLimitVal { - int64_t limit; - int64_t offset; -} SLimitVal; - -typedef struct SOrderVal { - uint32_t order; - int32_t orderColId; -} SOrderVal; - -typedef struct tVariantListItem { - tVariant pVar; - uint8_t sortOrder; -} tVariantListItem; - -typedef struct tVariantList { - int32_t nExpr; /* Number of expressions on the list */ - int32_t nAlloc; /* Number of entries allocated below */ - tVariantListItem *a; /* One entry for each expression */ -} tVariantList; - -typedef struct tFieldList { - int32_t nField; - int32_t nAlloc; - TAOS_FIELD *p; -} tFieldList; - -// create table operation type -enum TSQL_TYPE { - TSQL_CREATE_TABLE = 0x1, - TSQL_CREATE_STABLE = 0x2, - TSQL_CREATE_TABLE_FROM_STABLE = 0x3, - TSQL_CREATE_STREAM = 0x4, -}; - -typedef struct SQuerySQL { - struct tSQLExprList *pSelection; // select clause - tVariantList * from; // from clause - struct tSQLExpr * pWhere; // where clause [optional] - tVariantList * pGroupby; // groupby clause, only for tags[optional] - tVariantList * pSortOrder; // orderby [optional] - SSQLToken interval; // interval [optional] - SSQLToken sliding; // sliding window [optional] - SLimitVal limit; // limit offset [optional] - SLimitVal slimit; // group limit offset [optional] - tVariantList * fillType; // fill type[optional] - SSQLToken selectToken; // sql string -} SQuerySQL; - -typedef struct SCreateTableSQL { - struct SSQLToken name; // meter name, create table [meterName] xxx - bool existCheck; - - int8_t type; // create normal table/from super table/ stream - struct { - tFieldList *pTagColumns; // for normal table, pTagColumns = NULL; - tFieldList *pColumns; - } colInfo; - - struct { - SSQLToken stableName; // super table name, for using clause - tVariantList *pTagVals; // create by using metric, tag value - STagData tagdata; - } usingInfo; - - SQuerySQL *pSelect; -} SCreateTableSQL; - -typedef struct SAlterTableSQL { - SSQLToken name; - int16_t type; - STagData tagData; - - tFieldList * pAddColumns; - tVariantList *varList; // set t=val or: change src dst -} SAlterTableSQL; - -typedef struct SCreateDBInfo { - SSQLToken dbname; - int32_t replica; - int32_t cacheBlockSize; - int32_t tablesPerVnode; - int32_t daysPerFile; - int32_t rowPerFileBlock; - - float numOfAvgCacheBlocks; - int32_t numOfBlocksPerTable; - - int64_t commitTime; - int32_t commitLog; - int32_t compressionLevel; - SSQLToken precision; - - tVariantList *keep; -} SCreateDBInfo; - -typedef struct SCreateAcctSQL { - int32_t maxUsers; - int32_t maxDbs; - int32_t maxTimeSeries; - int32_t maxStreams; - int32_t maxPointsPerSecond; - int64_t maxStorage; - int64_t maxQueryTime; - int32_t maxConnections; - SSQLToken stat; -} SCreateAcctSQL; - -typedef struct SShowInfo { - uint8_t showType; - SSQLToken prefix; - SSQLToken pattern; -} SShowInfo; - -typedef struct SUserInfo { - SSQLToken user; - SSQLToken passwd; -// bool hasPasswd; - - SSQLToken privilege; -// bool hasPrivilege; - - int16_t type; -} SUserInfo; - -typedef struct tDCLSQL { - int32_t nTokens; /* Number of expressions on the list */ - int32_t nAlloc; /* Number of entries allocated below */ - SSQLToken *a; /* one entry for element */ - bool existsCheck; - - union { - SCreateDBInfo dbOpt; - SCreateAcctSQL acctOpt; - SShowInfo showOpt; - SSQLToken ip; - }; - - SUserInfo user; - -} tDCLSQL; - -typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause - SQuerySQL **pClause; - int32_t numOfClause; -} SSubclauseInfo; - -typedef struct SSqlInfo { - int32_t type; - bool valid; - - union { - SCreateTableSQL *pCreateTableInfo; - SAlterTableSQL * pAlterInfo; - tDCLSQL * pDCLInfo; - }; - - SSubclauseInfo subclauseInfo; - char pzErrMsg[256]; -} SSqlInfo; - -typedef struct tSQLExpr { - /* - * for single operand: - * TK_ALL - * TK_ID - * TK_SUM - * TK_AVG - * TK_MIN - * TK_MAX - * TK_FIRST - * TK_LAST - * TK_BOTTOM - * TK_TOP - * TK_STDDEV - * TK_PERCENTILE - * - * for binary operand: - * TK_LESS - * TK_LARGE - * TK_EQUAL etc... - */ - uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr) - - // the full sql string of function(col, param), which is actually the raw - // field name, since the function name is kept in nSQLOptr already - SSQLToken operand; - struct tSQLExprList *pParam; // function parameters - - SSQLToken colInfo; // field id - tVariant val; // value only for string, float, int - - struct tSQLExpr *pLeft; // left child - struct tSQLExpr *pRight; // right child -} tSQLExpr; - -// used in select clause. select from xxx -typedef struct tSQLExprItem { - tSQLExpr *pNode; // The list of expressions - char * aliasName; // alias name, null-terminated string -} tSQLExprItem; - -typedef struct tSQLExprList { - int32_t nExpr; /* Number of expressions on the list */ - int32_t nAlloc; /* Number of entries allocated below */ - tSQLExprItem *a; /* One entry for each expression */ -} tSQLExprList; - -typedef struct tSQLExprListList { - int32_t nList; /* Number of expressions on the list */ - int32_t nAlloc; /* Number of entries allocated below */ - tSQLExprList **a; /* one entry for each row */ -} tSQLExprListList; - -#define ParseTOKENTYPE SSQLToken - -void *ParseAlloc(void *(*mallocProc)(size_t)); - -/** - * - * @param yyp The parser - * @param yymajor The major token code number - * @param yyminor The value for the token - */ -void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *); - -/** - * - * @param p The parser to be deleted - * @param freeProc Function used to reclaim memory - */ -void ParseFree(void *p, void (*freeProc)(void *)); - -tVariantList *tVariantListAppend(tVariantList *pList, tVariant *pVar, uint8_t sortOrder); - -tVariantList *tVariantListInsert(tVariantList *pList, tVariant *pVar, uint8_t sortOrder, int32_t index); - -tVariantList *tVariantListAppendToken(tVariantList *pList, SSQLToken *pAliasToken, uint8_t sortOrder); -void tVariantListDestroy(tVariantList *pList); - -tFieldList *tFieldListAppend(tFieldList *pList, TAOS_FIELD *pField); - -void tFieldListDestroy(tFieldList *pList); - -tSQLExpr *tSQLExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optType); - -void tSQLExprDestroy(tSQLExpr *); - -tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken *pToken); - -void tSQLExprListDestroy(tSQLExprList *pList); - -SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, - tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval, - SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit); - -SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pMetricName, - tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type); - -void tSQLExprNodeDestroy(tSQLExpr *pExpr); -tSQLExpr *tSQLExprNodeClone(tSQLExpr *pExpr); - -SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type); - -tSQLExprListList *tSQLListListAppend(tSQLExprListList *pList, tSQLExprList *pExprList); - -void destroyAllSelectClause(SSubclauseInfo *pSql); -void doDestroyQuerySql(SQuerySQL *pSql); - -SSqlInfo * setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SSQLToken *pMeterName, int32_t type); -SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo); - -SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause); - -void setCreatedMeterName(SSqlInfo *pInfo, SSQLToken *pMeterName, SSQLToken *pIfNotExists); - -void SQLInfoDestroy(SSqlInfo *pInfo); - -void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...); -void setDropDBTableInfo(SSqlInfo *pInfo, int32_t type, SSQLToken* pToken, SSQLToken* existsCheck); -void setShowOptions(SSqlInfo *pInfo, int32_t type, SSQLToken* prefix, SSQLToken* pPatterns); - -tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken); - -void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists); - -void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo); -void setCreateUserSQL(SSqlInfo *pInfo, SSQLToken *pName, SSQLToken *pPasswd); -void setKillSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *ip); -void setAlterUserSQL(SSqlInfo *pInfo, int16_t type, SSQLToken *pName, SSQLToken* pPwd, SSQLToken *pPrivilege); - -void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo); - -// prefix show db.tables; -void setDBName(SSQLToken *pCpxName, SSQLToken *pDB); - -tSQLExpr *tSQLExprIdValueCreate(SSQLToken *pToken, int32_t optType); - -tSQLExpr *tSQLExprCreateFunction(tSQLExprList *pList, SSQLToken *pFuncToken, SSQLToken *endToken, int32_t optType); - -void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType); - -void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *pToken); - int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pSql); #ifdef __cplusplus diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 7e3b54545a..8394924caf 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -31,6 +31,7 @@ extern "C" { #include "tsqlfunction.h" #include "tutil.h" #include "trpc.h" +#include "qsqltype.h" #define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows) diff --git a/src/util/src/tcache.c b/src/client/src/tcache.c similarity index 100% rename from src/util/src/tcache.c rename to src/client/src/tcache.c diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 59dc708e99..b54600f641 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -18,13 +18,13 @@ #define _XOPEN_SOURCE -#include "os.h" #include "hash.h" +#include "os.h" #include "tscSecondaryMerge.h" #include "tscUtil.h" #include "tschemautil.h" #include "tsclient.h" -#include "tsqldef.h" +#include "ttokendef.h" #include "ttypes.h" #include "tlog.h" diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index 605b77a796..250e296e53 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -16,7 +16,7 @@ #include "os.h" #include "taosmsg.h" #include "tschemautil.h" -#include "tsqldef.h" +#include "ttokendef.h" #include "ttypes.h" #include "tutil.h" diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 2a5af0473c..ae31637f4c 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -13,10 +13,11 @@ * along with this program. If not, see . */ -#include "os.h" #include "tscUtil.h" #include "hash.h" +#include "os.h" #include "taosmsg.h" +#include "tast.h" #include "tcache.h" #include "tkey.h" #include "tmd5.h" @@ -25,9 +26,8 @@ #include "tscSecondaryMerge.h" #include "tschemautil.h" #include "tsclient.h" -#include "tsqldef.h" #include "ttimer.h" -#include "tast.h" +#include "ttokendef.h" /* * the detailed information regarding metric meta key is: diff --git a/src/dnode/CMakeLists.txt b/src/dnode/CMakeLists.txt index af84071849..ae9f386f46 100644 --- a/src/dnode/CMakeLists.txt +++ b/src/dnode/CMakeLists.txt @@ -5,6 +5,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(src SRC) diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index d3c8edee44..7a8cd28428 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -196,20 +196,6 @@ extern "C" { #define TSDB_MAX_NCHAR_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE) #define PRIMARYKEY_TIMESTAMP_COL_INDEX 0 -#define TSDB_DATA_BOOL_NULL 0x02 -#define TSDB_DATA_TINYINT_NULL 0x80 -#define TSDB_DATA_SMALLINT_NULL 0x8000 -#define TSDB_DATA_INT_NULL 0x80000000 -#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L - -#define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN -#define TSDB_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN -#define TSDB_DATA_NCHAR_NULL 0xFFFFFFFF -#define TSDB_DATA_BINARY_NULL 0xFF - -#define TSDB_DATA_NULL_STR "NULL" -#define TSDB_DATA_NULL_STR_L "null" - #define TSDB_MAX_RPC_THREADS 5 #define TSDB_QUERY_TYPE_NON_TYPE 0x00U // none type diff --git a/src/util/inc/tsqldef.h b/src/inc/ttokendef.h similarity index 100% rename from src/util/inc/tsqldef.h rename to src/inc/ttokendef.h diff --git a/src/kit/shell/CMakeLists.txt b/src/kit/shell/CMakeLists.txt index 20a740dee9..73bee20c73 100644 --- a/src/kit/shell/CMakeLists.txt +++ b/src/kit/shell/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 22af4ca5c3..a4a589d55c 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -21,6 +21,7 @@ #include "shellCommand.h" #include "ttime.h" #include "tutil.h" +#include "ttypes.h" #include "taoserror.h" #include diff --git a/src/kit/taosdump/CMakeLists.txt b/src/kit/taosdump/CMakeLists.txt index 0ff54200ce..a15b0ff552 100644 --- a/src/kit/taosdump/CMakeLists.txt +++ b/src/kit/taosdump/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/mnode/CMakeLists.txt b/src/mnode/CMakeLists.txt index acf8b15f22..16dbbcb740 100644 --- a/src/mnode/CMakeLists.txt +++ b/src/mnode/CMakeLists.txt @@ -5,6 +5,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/mnode/src/mgmtChildTable.c b/src/mnode/src/mgmtChildTable.c index 02771b19c9..1bc4305438 100644 --- a/src/mnode/src/mgmtChildTable.c +++ b/src/mnode/src/mgmtChildTable.c @@ -16,12 +16,9 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taosmsg.h" -#include "tast.h" -#include "textbuffer.h" #include "tschemautil.h" #include "tscompression.h" #include "tskiplist.h" -#include "tsqlfunction.h" #include "ttime.h" #include "tstatus.h" #include "tutil.h" diff --git a/src/mnode/src/mgmtNormalTable.c b/src/mnode/src/mgmtNormalTable.c index aaabe0bcac..fddb47cb7e 100644 --- a/src/mnode/src/mgmtNormalTable.c +++ b/src/mnode/src/mgmtNormalTable.c @@ -16,12 +16,8 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taosmsg.h" -#include "tast.h" -#include "textbuffer.h" -#include "tschemautil.h" #include "tscompression.h" #include "tskiplist.h" -#include "tsqlfunction.h" #include "ttime.h" #include "tstatus.h" #include "tutil.h" diff --git a/src/mnode/src/mgmtSuperTable.c b/src/mnode/src/mgmtSuperTable.c index 6a74f7616d..2fb4129e75 100644 --- a/src/mnode/src/mgmtSuperTable.c +++ b/src/mnode/src/mgmtSuperTable.c @@ -16,8 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taosmsg.h" -#include "tast.h" -#include "textbuffer.h" #include "tschemautil.h" #include "tscompression.h" #include "tskiplist.h" diff --git a/src/plugins/http/CMakeLists.txt b/src/plugins/http/CMakeLists.txt index 7044f5d09d..57ca4ca9f0 100644 --- a/src/plugins/http/CMakeLists.txt +++ b/src/plugins/http/CMakeLists.txt @@ -5,6 +5,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/plugins/monitor/CMakeLists.txt b/src/plugins/monitor/CMakeLists.txt index 6bc41d2b3e..c409f28b20 100644 --- a/src/plugins/monitor/CMakeLists.txt +++ b/src/plugins/monitor/CMakeLists.txt @@ -5,6 +5,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(./src SRC) diff --git a/src/plugins/monitor/src/monitorSystem.c b/src/plugins/monitor/src/monitorSystem.c index 5a42d66493..4fb3ba2f5b 100644 --- a/src/plugins/monitor/src/monitorSystem.c +++ b/src/plugins/monitor/src/monitorSystem.c @@ -13,11 +13,9 @@ * along with this program. If not, see . */ +#include "os.h" + #include "monitor.h" -#include -#include -#include -#include #include "dnode.h" #include "monitorSystem.h" #include "tsclient.h" diff --git a/src/query/CMakeLists.txt b/src/query/CMakeLists.txt new file mode 100644 index 0000000000..c0ded1dafb --- /dev/null +++ b/src/query/CMakeLists.txt @@ -0,0 +1,13 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(TDengine) + +INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(inc) + +IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) + AUX_SOURCE_DIRECTORY(src SRC) + ADD_LIBRARY(query ${SRC}) + TARGET_LINK_LIBRARIES(query util m rt) +ENDIF () \ No newline at end of file diff --git a/src/query/inc/qsqlparser.h b/src/query/inc/qsqlparser.h new file mode 100644 index 0000000000..7a1322be10 --- /dev/null +++ b/src/query/inc/qsqlparser.h @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_QASTDEF_H +#define TDENGINE_QASTDEF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "taos.h" +#include "taosmsg.h" +#include "tstoken.h" +#include "tvariant.h" + +#define ParseTOKENTYPE SSQLToken +extern char tTokenTypeSwitcher[13]; + +#define toTSDBType(x) \ + do { \ + if ((x) >= tListLen(tTokenTypeSwitcher)) { \ + (x) = TSDB_DATA_TYPE_BINARY; \ + } else { \ + (x) = tTokenTypeSwitcher[(x)]; \ + } \ + } while (0) + +typedef struct tFieldList { + int32_t nField; + int32_t nAlloc; + TAOS_FIELD *p; +} tFieldList; + +typedef struct SLimitVal { + int64_t limit; + int64_t offset; +} SLimitVal; + +typedef struct SOrderVal { + uint32_t order; + int32_t orderColId; +} SOrderVal; + +typedef struct tVariantListItem { + tVariant pVar; + uint8_t sortOrder; +} tVariantListItem; + +typedef struct tVariantList { + int32_t nExpr; /* Number of expressions on the list */ + int32_t nAlloc; /* Number of entries allocated below */ + tVariantListItem *a; /* One entry for each expression */ +} tVariantList; + +typedef struct SQuerySQL { + struct tSQLExprList *pSelection; // select clause + tVariantList * from; // from clause + struct tSQLExpr * pWhere; // where clause [optional] + tVariantList * pGroupby; // groupby clause, only for tags[optional] + tVariantList * pSortOrder; // orderby [optional] + SSQLToken interval; // interval [optional] + SSQLToken sliding; // sliding window [optional] + SLimitVal limit; // limit offset [optional] + SLimitVal slimit; // group limit offset [optional] + tVariantList * fillType; // fill type[optional] + SSQLToken selectToken; // sql string +} SQuerySQL; + +typedef struct SCreateTableSQL { + struct SSQLToken name; // meter name, create table [meterName] xxx + bool existCheck; + + int8_t type; // create normal table/from super table/ stream + struct { + tFieldList *pTagColumns; // for normal table, pTagColumns = NULL; + tFieldList *pColumns; + } colInfo; + + struct { + SSQLToken stableName; // super table name, for using clause + tVariantList *pTagVals; // create by using metric, tag value + STagData tagdata; + } usingInfo; + + SQuerySQL *pSelect; +} SCreateTableSQL; + +typedef struct SAlterTableSQL { + SSQLToken name; + int16_t type; + STagData tagData; + + tFieldList * pAddColumns; + tVariantList *varList; // set t=val or: change src dst +} SAlterTableSQL; + +typedef struct SCreateDBInfo { + SSQLToken dbname; + int32_t replica; + int32_t cacheBlockSize; + int32_t tablesPerVnode; + int32_t daysPerFile; + int32_t rowPerFileBlock; + + float numOfAvgCacheBlocks; + int32_t numOfBlocksPerTable; + + int64_t commitTime; + int32_t commitLog; + int32_t compressionLevel; + SSQLToken precision; + + tVariantList *keep; +} SCreateDBInfo; + +typedef struct SCreateAcctSQL { + int32_t maxUsers; + int32_t maxDbs; + int32_t maxTimeSeries; + int32_t maxStreams; + int32_t maxPointsPerSecond; + int64_t maxStorage; + int64_t maxQueryTime; + int32_t maxConnections; + SSQLToken stat; +} SCreateAcctSQL; + +typedef struct SShowInfo { + uint8_t showType; + SSQLToken prefix; + SSQLToken pattern; +} SShowInfo; + +typedef struct SUserInfo { + SSQLToken user; + SSQLToken passwd; + SSQLToken privilege; + int16_t type; +} SUserInfo; + +typedef struct tDCLSQL { + int32_t nTokens; /* Number of expressions on the list */ + int32_t nAlloc; /* Number of entries allocated below */ + SSQLToken *a; /* one entry for element */ + bool existsCheck; + + union { + SCreateDBInfo dbOpt; + SCreateAcctSQL acctOpt; + SShowInfo showOpt; + SSQLToken ip; + }; + + SUserInfo user; + +} tDCLSQL; + +typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause + SQuerySQL **pClause; + int32_t numOfClause; +} SSubclauseInfo; + +typedef struct SSqlInfo { + int32_t type; + bool valid; + + union { + SCreateTableSQL *pCreateTableInfo; + SAlterTableSQL * pAlterInfo; + tDCLSQL * pDCLInfo; + }; + + SSubclauseInfo subclauseInfo; + char pzErrMsg[256]; +} SSqlInfo; + +typedef struct tSQLExpr { + /* + * for single operand: + * TK_ALL + * TK_ID + * TK_SUM + * TK_AVG + * TK_MIN + * TK_MAX + * TK_FIRST + * TK_LAST + * TK_BOTTOM + * TK_TOP + * TK_STDDEV + * TK_PERCENTILE + * + * for binary operand: + * TK_LESS + * TK_LARGE + * TK_EQUAL etc... + */ + uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr) + + // the full sql string of function(col, param), which is actually the raw + // field name, since the function name is kept in nSQLOptr already + SSQLToken operand; + struct tSQLExprList *pParam; // function parameters + + SSQLToken colInfo; // field id + tVariant val; // value only for string, float, int + + struct tSQLExpr *pLeft; // left child + struct tSQLExpr *pRight; // right child +} tSQLExpr; + +// used in select clause. select from xxx +typedef struct tSQLExprItem { + tSQLExpr *pNode; // The list of expressions + char * aliasName; // alias name, null-terminated string +} tSQLExprItem; + +typedef struct tSQLExprList { + int32_t nExpr; /* Number of expressions on the list */ + int32_t nAlloc; /* Number of entries allocated below */ + tSQLExprItem *a; /* One entry for each expression */ +} tSQLExprList; + +typedef struct tSQLExprListList { + int32_t nList; /* Number of expressions on the list */ + int32_t nAlloc; /* Number of entries allocated below */ + tSQLExprList **a; /* one entry for each row */ +} tSQLExprListList; + + +/** + * + * @param yyp The parser + * @param yymajor The major token code number + * @param yyminor The value for the token + */ +void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *); + +/** + * + * @param p The parser to be deleted + * @param freeProc Function used to reclaim memory + */ +void ParseFree(void *p, void (*freeProc)(void *)); + +tVariantList *tVariantListAppend(tVariantList *pList, tVariant *pVar, uint8_t sortOrder); + +tVariantList *tVariantListInsert(tVariantList *pList, tVariant *pVar, uint8_t sortOrder, int32_t index); + +tVariantList *tVariantListAppendToken(tVariantList *pList, SSQLToken *pAliasToken, uint8_t sortOrder); +void tVariantListDestroy(tVariantList *pList); + +tFieldList *tFieldListAppend(tFieldList *pList, TAOS_FIELD *pField); + +void tFieldListDestroy(tFieldList *pList); + +tSQLExpr *tSQLExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optType); + +void tSQLExprDestroy(tSQLExpr *); + +tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken *pToken); + +void tSQLExprListDestroy(tSQLExprList *pList); + +SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, + tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval, + SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit); + +SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pMetricName, + tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type); + +void tSQLExprNodeDestroy(tSQLExpr *pExpr); +tSQLExpr *tSQLExprNodeClone(tSQLExpr *pExpr); + +SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type); + +tSQLExprListList *tSQLListListAppend(tSQLExprListList *pList, tSQLExprList *pExprList); + +void destroyAllSelectClause(SSubclauseInfo *pSql); +void doDestroyQuerySql(SQuerySQL *pSql); + +SSqlInfo * setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SSQLToken *pMeterName, int32_t type); +SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo); + +SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause); + +void setCreatedMeterName(SSqlInfo *pInfo, SSQLToken *pMeterName, SSQLToken *pIfNotExists); + +void SQLInfoDestroy(SSqlInfo *pInfo); + +void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...); +void setDropDBTableInfo(SSqlInfo *pInfo, int32_t type, SSQLToken* pToken, SSQLToken* existsCheck); +void setShowOptions(SSqlInfo *pInfo, int32_t type, SSQLToken* prefix, SSQLToken* pPatterns); + +tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken); + +void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists); + +void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo); +void setCreateUserSQL(SSqlInfo *pInfo, SSQLToken *pName, SSQLToken *pPasswd); +void setKillSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *ip); +void setAlterUserSQL(SSqlInfo *pInfo, int16_t type, SSQLToken *pName, SSQLToken* pPwd, SSQLToken *pPrivilege); + +void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo); + +// prefix show db.tables; +void setDBName(SSQLToken *pCpxName, SSQLToken *pDB); + +tSQLExpr *tSQLExprIdValueCreate(SSQLToken *pToken, int32_t optType); + +tSQLExpr *tSQLExprCreateFunction(tSQLExprList *pList, SSQLToken *pFuncToken, SSQLToken *endToken, int32_t optType); + +void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType); + +void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *pToken); + + +void *ParseAlloc(void *(*mallocProc)(size_t)); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_QASTDEF_H diff --git a/src/query/inc/qsqltype.h b/src/query/inc/qsqltype.h new file mode 100644 index 0000000000..5d85ab4b80 --- /dev/null +++ b/src/query/inc/qsqltype.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_QSQLCMD_H +#define TDENGINE_QSQLCMD_H + +#ifdef __cplusplus +extern "C" { +#endif + +enum _sql_type { + TSDB_SQL_SELECT = 1, + TSDB_SQL_FETCH, + TSDB_SQL_INSERT, + + TSDB_SQL_MGMT, // the SQL below is for mgmt node + TSDB_SQL_CREATE_DB, + TSDB_SQL_CREATE_TABLE, + TSDB_SQL_DROP_DB, + TSDB_SQL_DROP_TABLE, + TSDB_SQL_CREATE_ACCT, + TSDB_SQL_CREATE_USER, // 10 + TSDB_SQL_DROP_ACCT, + TSDB_SQL_DROP_USER, + TSDB_SQL_ALTER_USER, + TSDB_SQL_ALTER_ACCT, + TSDB_SQL_ALTER_TABLE, + TSDB_SQL_ALTER_DB, + TSDB_SQL_CREATE_MNODE, + TSDB_SQL_DROP_MNODE, + TSDB_SQL_CREATE_DNODE, + TSDB_SQL_DROP_DNODE, // 20 + TSDB_SQL_CFG_DNODE, + TSDB_SQL_CFG_MNODE, + TSDB_SQL_SHOW, + TSDB_SQL_RETRIEVE, + TSDB_SQL_KILL_QUERY, + TSDB_SQL_KILL_STREAM, + TSDB_SQL_KILL_CONNECTION, + + TSDB_SQL_READ, // SQL below is for read operation + TSDB_SQL_CONNECT, + TSDB_SQL_USE_DB, // 30 + TSDB_SQL_META, + TSDB_SQL_METRIC, + TSDB_SQL_MULTI_META, + TSDB_SQL_HB, + + TSDB_SQL_LOCAL, // SQL below for client local + TSDB_SQL_DESCRIBE_TABLE, + TSDB_SQL_RETRIEVE_METRIC, + TSDB_SQL_METRIC_JOIN_RETRIEVE, + TSDB_SQL_RETRIEVE_TAGS, + + /* + * build empty result instead of accessing dnode to fetch result + * reset the client cache + */ + TSDB_SQL_RETRIEVE_EMPTY_RESULT, // 40 + + TSDB_SQL_RESET_CACHE, + TSDB_SQL_SERV_STATUS, + TSDB_SQL_CURRENT_DB, + TSDB_SQL_SERV_VERSION, + TSDB_SQL_CLI_VERSION, + TSDB_SQL_CURRENT_USER, + TSDB_SQL_CFG_LOCAL, + + TSDB_SQL_MAX // 48 +}; + + +// create table operation type +enum TSQL_TYPE { + TSQL_CREATE_TABLE = 0x1, + TSQL_CREATE_STABLE = 0x2, + TSQL_CREATE_TABLE_FROM_STABLE = 0x3, + TSQL_CREATE_STREAM = 0x4, +}; + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_QSQLCMD_H diff --git a/src/inc/sql.y b/src/query/inc/sql.y similarity index 100% rename from src/inc/sql.y rename to src/query/inc/sql.y diff --git a/src/util/inc/tast.h b/src/query/inc/tast.h similarity index 98% rename from src/util/inc/tast.h rename to src/query/inc/tast.h index aa5cfa2d70..3cb483a91b 100644 --- a/src/util/inc/tast.h +++ b/src/query/inc/tast.h @@ -20,13 +20,11 @@ extern "C" { #endif -#include -#include -#include +#include "os.h" #include "taosmsg.h" #include "ttypes.h" -#include "os.h" +#include "tvariant.h" struct tSQLBinaryExpr; struct SSchema; diff --git a/src/util/inc/tcache.h b/src/query/inc/tcache.h similarity index 100% rename from src/util/inc/tcache.h rename to src/query/inc/tcache.h diff --git a/src/util/inc/textbuffer.h b/src/query/inc/textbuffer.h similarity index 100% rename from src/util/inc/textbuffer.h rename to src/query/inc/textbuffer.h diff --git a/src/util/inc/thistogram.h b/src/query/inc/thistogram.h similarity index 100% rename from src/util/inc/thistogram.h rename to src/query/inc/thistogram.h diff --git a/src/util/inc/tinterpolation.h b/src/query/inc/tinterpolation.h similarity index 100% rename from src/util/inc/tinterpolation.h rename to src/query/inc/tinterpolation.h diff --git a/src/util/inc/tlosertree.h b/src/query/inc/tlosertree.h similarity index 100% rename from src/util/inc/tlosertree.h rename to src/query/inc/tlosertree.h diff --git a/src/inc/tresultBuf.h b/src/query/inc/tresultBuf.h similarity index 78% rename from src/inc/tresultBuf.h rename to src/query/inc/tresultBuf.h index b99c44e73f..8f30ff7c61 100644 --- a/src/inc/tresultBuf.h +++ b/src/query/inc/tresultBuf.h @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + #ifndef TDENGINE_VNODEQUERYUTIL_H #define TDENGINE_VNODEQUERYUTIL_H diff --git a/src/client/inc/tscSyntaxtreefunction.h b/src/query/inc/tscSyntaxtreefunction.h similarity index 100% rename from src/client/inc/tscSyntaxtreefunction.h rename to src/query/inc/tscSyntaxtreefunction.h diff --git a/src/util/inc/tsqlfunction.h b/src/query/inc/tsqlfunction.h similarity index 99% rename from src/util/inc/tsqlfunction.h rename to src/query/inc/tsqlfunction.h index b423589672..dc5f284efa 100644 --- a/src/util/inc/tsqlfunction.h +++ b/src/query/inc/tsqlfunction.h @@ -25,6 +25,7 @@ extern "C" { #include "trpc.h" #include "ttypes.h" +#include "tvariant.h" #define TSDB_FUNC_INVALID_ID -1 #define TSDB_FUNC_COUNT 0 diff --git a/src/query/inc/tvariant.h b/src/query/inc/tvariant.h new file mode 100644 index 0000000000..f54a3a4348 --- /dev/null +++ b/src/query/inc/tvariant.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_TVARIANT_H +#define TDENGINE_TVARIANT_H + +#ifdef __cplusplus +extern "C" { +#endif + +// variant, each number/string/field_id has a corresponding struct during parsing sql +typedef struct tVariant { + uint32_t nType; + int32_t nLen; // only used for string, for number, it is useless + union { + int64_t i64Key; + double dKey; + char * pz; + wchar_t *wpz; + }; +} tVariant; + +void tVariantCreate(tVariant *pVar, SSQLToken *token); + +void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type); + +void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t type); + +void tVariantDestroy(tVariant *pV); + +void tVariantAssign(tVariant *pDst, const tVariant *pSrc); + +int32_t tVariantToString(tVariant *pVar, char *dst); + +int32_t tVariantDump(tVariant *pVariant, char *payload, char type); + +int32_t tVariantTypeSetType(tVariant *pVariant, char type); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_TVARIANT_H diff --git a/src/client/src/sql.c b/src/query/src/sql.c similarity index 99% rename from src/client/src/sql.c rename to src/query/src/sql.c index 54df3e3669..f1dce997fe 100644 --- a/src/client/src/sql.c +++ b/src/query/src/sql.c @@ -25,13 +25,18 @@ #include /************ Begin %include sections from the grammar ************************/ +#include +#include #include #include #include -#include -#include -#include "tscSQLParser.h" +#include "qsqlparser.h" +#include "tstoken.h" #include "tutil.h" +#include "tvariant.h" +#include "ttokendef.h" +#include "qsqltype.h" + /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols ** in a format understandable to "makeheaders". This section is blank unless diff --git a/src/util/src/textbuffer.c b/src/query/src/textbuffer.c similarity index 100% rename from src/util/src/textbuffer.c rename to src/query/src/textbuffer.c diff --git a/src/util/src/thistogram.c b/src/query/src/thistogram.c similarity index 100% rename from src/util/src/thistogram.c rename to src/query/src/thistogram.c diff --git a/src/util/src/tinterpolation.c b/src/query/src/tinterpolation.c similarity index 100% rename from src/util/src/tinterpolation.c rename to src/query/src/tinterpolation.c diff --git a/src/util/src/tlosertree.c b/src/query/src/tlosertree.c similarity index 100% rename from src/util/src/tlosertree.c rename to src/query/src/tlosertree.c diff --git a/src/util/src/tpercentile.c b/src/query/src/tpercentile.c similarity index 100% rename from src/util/src/tpercentile.c rename to src/query/src/tpercentile.c diff --git a/src/util/src/tresultBuf.c b/src/query/src/tresultBuf.c similarity index 100% rename from src/util/src/tresultBuf.c rename to src/query/src/tresultBuf.c diff --git a/src/client/src/tscAst.c b/src/query/src/tscAst.c similarity index 68% rename from src/client/src/tscAst.c rename to src/query/src/tscAst.c index 17e7667445..70fda9bd93 100644 --- a/src/client/src/tscAst.c +++ b/src/query/src/tscAst.c @@ -14,19 +14,19 @@ */ #include "os.h" +#include "sskiplist.h" +#include "taosdef.h" #include "taosmsg.h" #include "tast.h" #include "tlog.h" -#include "tscSQLParser.h" #include "tscSyntaxtreefunction.h" #include "tschemautil.h" -#include "taosdef.h" -#include "sskiplist.h" -#include "tsqldef.h" #include "tsqlfunction.h" #include "tstoken.h" +#include "ttokendef.h" #include "ttypes.h" #include "tutil.h" +#include "qsqlparser.h" /* * @@ -468,182 +468,182 @@ void tSQLBinaryExprDestroy(tSQLBinaryExpr **pExpr, void (*fp)(void *)) { *pExpr = NULL; } -static void setInitialValueForRangeQueryCondition(tSKipListQueryCond *q, int8_t type) { - q->lowerBndRelOptr = TSDB_RELATION_LARGE; - q->upperBndRelOptr = TSDB_RELATION_LESS; - - switch (type) { - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_BIGINT: { - q->upperBnd.nType = TSDB_DATA_TYPE_BIGINT; - q->lowerBnd.nType = TSDB_DATA_TYPE_BIGINT; - - q->upperBnd.i64Key = INT64_MAX; - q->lowerBnd.i64Key = INT64_MIN; - break; - }; - case TSDB_DATA_TYPE_FLOAT: - case TSDB_DATA_TYPE_DOUBLE: { - q->upperBnd.nType = TSDB_DATA_TYPE_DOUBLE; - q->lowerBnd.nType = TSDB_DATA_TYPE_DOUBLE; - q->upperBnd.dKey = DBL_MAX; - q->lowerBnd.dKey = -DBL_MIN; - break; - }; - case TSDB_DATA_TYPE_NCHAR: - case TSDB_DATA_TYPE_BINARY: { - q->upperBnd.nType = type; - q->upperBnd.pz = NULL; - q->upperBnd.nLen = -1; - - q->lowerBnd.nType = type; - q->lowerBnd.pz = NULL; - q->lowerBnd.nLen = -1; - } - } -} - -static void tSQLDoFilterInitialResult(tSkipList *pSkipList, bool (*fp)(), tQueryInfo *queryColInfo, - tQueryResultset *result) { - // primary key filter, search according to skiplist - if (queryColInfo->colIdx == 0 && queryColInfo->optr != TSDB_RELATION_LIKE) { - tSKipListQueryCond q; - setInitialValueForRangeQueryCondition(&q, queryColInfo->q.nType); - - switch (queryColInfo->optr) { - case TSDB_RELATION_EQUAL: { - result->num = - tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, INCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes); - break; - } - case TSDB_RELATION_NOT_EQUAL: { - result->num = - tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, EXCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes); - break; - } - case TSDB_RELATION_LESS_EQUAL: { - tVariantAssign(&q.upperBnd, &queryColInfo->q); - q.upperBndRelOptr = queryColInfo->optr; - result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); - break; - } - case TSDB_RELATION_LESS: { - tVariantAssign(&q.upperBnd, &queryColInfo->q); - result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); - break; - } - case TSDB_RELATION_LARGE: { - tVariantAssign(&q.lowerBnd, &queryColInfo->q); - result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); - break; - } - case TSDB_RELATION_LARGE_EQUAL: { - tVariantAssign(&q.lowerBnd, &queryColInfo->q); - q.lowerBndRelOptr = queryColInfo->optr; - result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); - break; - } - default: - pTrace("skiplist:%p, unsupport query operator:%d", pSkipList, queryColInfo->optr); - } - - tSkipListDestroyKey(&q.upperBnd); - tSkipListDestroyKey(&q.lowerBnd); - } else { - /* - * Brutal force scan the whole skiplit to find the appropriate result, - * since the filter is not applied to indexed column. - */ - result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, queryColInfo); - } -} +//static void setInitialValueForRangeQueryCondition(tSKipListQueryCond *q, int8_t type) { +// q->lowerBndRelOptr = TSDB_RELATION_LARGE; +// q->upperBndRelOptr = TSDB_RELATION_LESS; +// +// switch (type) { +// case TSDB_DATA_TYPE_BOOL: +// case TSDB_DATA_TYPE_TINYINT: +// case TSDB_DATA_TYPE_SMALLINT: +// case TSDB_DATA_TYPE_INT: +// case TSDB_DATA_TYPE_BIGINT: { +// q->upperBnd.nType = TSDB_DATA_TYPE_BIGINT; +// q->lowerBnd.nType = TSDB_DATA_TYPE_BIGINT; +// +// q->upperBnd.i64Key = INT64_MAX; +// q->lowerBnd.i64Key = INT64_MIN; +// break; +// }; +// case TSDB_DATA_TYPE_FLOAT: +// case TSDB_DATA_TYPE_DOUBLE: { +// q->upperBnd.nType = TSDB_DATA_TYPE_DOUBLE; +// q->lowerBnd.nType = TSDB_DATA_TYPE_DOUBLE; +// q->upperBnd.dKey = DBL_MAX; +// q->lowerBnd.dKey = -DBL_MIN; +// break; +// }; +// case TSDB_DATA_TYPE_NCHAR: +// case TSDB_DATA_TYPE_BINARY: { +// q->upperBnd.nType = type; +// q->upperBnd.pz = NULL; +// q->upperBnd.nLen = -1; +// +// q->lowerBnd.nType = type; +// q->lowerBnd.pz = NULL; +// q->lowerBnd.nLen = -1; +// } +// } +//} + +//static void tSQLDoFilterInitialResult(tSkipList *pSkipList, bool (*fp)(), tQueryInfo *queryColInfo, +// tQueryResultset *result) { +// // primary key filter, search according to skiplist +// if (queryColInfo->colIdx == 0 && queryColInfo->optr != TSDB_RELATION_LIKE) { +// tSKipListQueryCond q; +// setInitialValueForRangeQueryCondition(&q, queryColInfo->q.nType); +// +// switch (queryColInfo->optr) { +// case TSDB_RELATION_EQUAL: { +// result->num = +// tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, INCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes); +// break; +// } +// case TSDB_RELATION_NOT_EQUAL: { +// result->num = +// tSkipListPointQuery(pSkipList, &queryColInfo->q, 1, EXCLUDE_POINT_QUERY, (tSkipListNode ***)&result->pRes); +// break; +// } +// case TSDB_RELATION_LESS_EQUAL: { +// tVariantAssign(&q.upperBnd, &queryColInfo->q); +// q.upperBndRelOptr = queryColInfo->optr; +// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); +// break; +// } +// case TSDB_RELATION_LESS: { +// tVariantAssign(&q.upperBnd, &queryColInfo->q); +// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); +// break; +// } +// case TSDB_RELATION_LARGE: { +// tVariantAssign(&q.lowerBnd, &queryColInfo->q); +// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); +// break; +// } +// case TSDB_RELATION_LARGE_EQUAL: { +// tVariantAssign(&q.lowerBnd, &queryColInfo->q); +// q.lowerBndRelOptr = queryColInfo->optr; +// result->num = tSkipListQuery(pSkipList, &q, (tSkipListNode ***)&result->pRes); +// break; +// } +// default: +// pTrace("skiplist:%p, unsupport query operator:%d", pSkipList, queryColInfo->optr); +// } +// +// tSkipListDestroyKey(&q.upperBnd); +// tSkipListDestroyKey(&q.lowerBnd); +// } else { +// /* +// * Brutal force scan the whole skiplit to find the appropriate result, +// * since the filter is not applied to indexed column. +// */ +// result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, queryColInfo); +// } +//} /* * qsort comparator * sort the result to ensure meters with the same gid is grouped together */ -static int32_t compareByAddr(const void *pLeft, const void *pRight) { - int64_t p1 = (int64_t) * ((tSkipListNode **)pLeft); - int64_t p2 = (int64_t) * ((tSkipListNode **)pRight); - - DEFAULT_COMP(p1, p2); -} +//static int32_t compareByAddr(const void *pLeft, const void *pRight) { +// int64_t p1 = (int64_t) * ((tSkipListNode **)pLeft); +// int64_t p2 = (int64_t) * ((tSkipListNode **)pRight); +// +// DEFAULT_COMP(p1, p2); +//} int32_t merge(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *pFinalRes) { - assert(pFinalRes->pRes == 0); - - pFinalRes->pRes = calloc((size_t)(pLeft->num + pRight->num), POINTER_BYTES); - pFinalRes->num = 0; - - // sort according to address - tSkipListNode **pLeftNodes = (tSkipListNode **)pLeft->pRes; - qsort(pLeftNodes, pLeft->num, sizeof(pLeft->pRes[0]), compareByAddr); - - tSkipListNode **pRightNodes = (tSkipListNode **)pRight->pRes; - qsort(pRightNodes, pRight->num, sizeof(pRight->pRes[0]), compareByAddr); - - int32_t i = 0, j = 0; - - // merge two sorted arrays in O(n) time - while (i < pLeft->num && j < pRight->num) { - int64_t ret = (int64_t)pLeftNodes[i] - (int64_t)pRightNodes[j]; - - if (ret < 0) { - pFinalRes->pRes[pFinalRes->num++] = pLeftNodes[i++]; - } else if (ret > 0) { - pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j++]; - } else { // pNode->key > pkey[i] - pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j++]; - i++; - } - } - - while (i < pLeft->num) { - pFinalRes->pRes[pFinalRes->num++] = pLeftNodes[i++]; - } - - while (j < pRight->num) { - pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j++]; - } - - return pFinalRes->num; +// assert(pFinalRes->pRes == 0); +// +// pFinalRes->pRes = calloc((size_t)(pLeft->num + pRight->num), POINTER_BYTES); +// pFinalRes->num = 0; +// +// // sort according to address +// tSkipListNode **pLeftNodes = (tSkipListNode **)pLeft->pRes; +// qsort(pLeftNodes, pLeft->num, sizeof(pLeft->pRes[0]), compareByAddr); +// +// tSkipListNode **pRightNodes = (tSkipListNode **)pRight->pRes; +// qsort(pRightNodes, pRight->num, sizeof(pRight->pRes[0]), compareByAddr); +// +// int32_t i = 0, j = 0; +// +// // merge two sorted arrays in O(n) time +// while (i < pLeft->num && j < pRight->num) { +// int64_t ret = (int64_t)pLeftNodes[i] - (int64_t)pRightNodes[j]; +// +// if (ret < 0) { +// pFinalRes->pRes[pFinalRes->num++] = pLeftNodes[i++]; +// } else if (ret > 0) { +// pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j++]; +// } else { // pNode->key > pkey[i] +// pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j++]; +// i++; +// } +// } +// +// while (i < pLeft->num) { +// pFinalRes->pRes[pFinalRes->num++] = pLeftNodes[i++]; +// } +// +// while (j < pRight->num) { +// pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j++]; +// } +// +// return pFinalRes->num; } int32_t intersect(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResultset *pFinalRes) { - int64_t num = MIN(pLeft->num, pRight->num); - - assert(pFinalRes->pRes == 0); - - pFinalRes->pRes = calloc(num, POINTER_BYTES); - pFinalRes->num = 0; - - // sort according to address - tSkipListNode **pLeftNodes = (tSkipListNode **)pLeft->pRes; - qsort(pLeftNodes, pLeft->num, sizeof(pLeft->pRes[0]), compareByAddr); - - tSkipListNode **pRightNodes = (tSkipListNode **)pRight->pRes; - qsort(pRightNodes, pRight->num, sizeof(pRight->pRes[0]), compareByAddr); - - int32_t i = 0, j = 0; - // merge two sorted arrays in O(n) time - while (i < pLeft->num && j < pRight->num) { - int64_t ret = (int64_t)pLeftNodes[i] - (int64_t)pRightNodes[j]; - - if (ret < 0) { - i++; - } else if (ret > 0) { - j++; - } else { // pNode->key > pkey[i] - pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j]; - i++; - j++; - } - } - - return pFinalRes->num; +// int64_t num = MIN(pLeft->num, pRight->num); +// +// assert(pFinalRes->pRes == 0); +// +// pFinalRes->pRes = calloc(num, POINTER_BYTES); +// pFinalRes->num = 0; +// +// // sort according to address +// tSkipListNode **pLeftNodes = (tSkipListNode **)pLeft->pRes; +// qsort(pLeftNodes, pLeft->num, sizeof(pLeft->pRes[0]), compareByAddr); +// +// tSkipListNode **pRightNodes = (tSkipListNode **)pRight->pRes; +// qsort(pRightNodes, pRight->num, sizeof(pRight->pRes[0]), compareByAddr); +// +// int32_t i = 0, j = 0; +// // merge two sorted arrays in O(n) time +// while (i < pLeft->num && j < pRight->num) { +// int64_t ret = (int64_t)pLeftNodes[i] - (int64_t)pRightNodes[j]; +// +// if (ret < 0) { +// i++; +// } else if (ret > 0) { +// j++; +// } else { // pNode->key > pkey[i] +// pFinalRes->pRes[pFinalRes->num++] = pRightNodes[j]; +// i++; +// j++; +// } +// } +// +// return pFinalRes->num; } /* @@ -719,113 +719,113 @@ static void tSQLBinaryTraverseOnResult(tSQLBinaryExpr *pExpr, tQueryResultset *p pResult->num = n; } -static void tSQLBinaryTraverseOnSkipList(tSQLBinaryExpr *pExpr, tQueryResultset *pResult, tSkipList *pSkipList, - SBinaryFilterSupp *param) { - int32_t n = 0; - SSkipListIterator iter = {0}; - - int32_t ret = tSkipListIteratorReset(pSkipList, &iter); - assert(ret == 0); - - pResult->pRes = calloc(pSkipList->nSize, POINTER_BYTES); - - while (tSkipListIteratorNext(&iter)) { - tSkipListNode *pNode = tSkipListIteratorGet(&iter); - if (filterItem(pExpr, pNode, param)) { - pResult->pRes[n++] = pNode; - } - } - - pResult->num = n; -} +//static void tSQLBinaryTraverseOnSkipList(tSQLBinaryExpr *pExpr, tQueryResultset *pResult, tSkipList *pSkipList, +// SBinaryFilterSupp *param) { +// int32_t n = 0; +// SSkipListIterator iter = {0}; +// +// int32_t ret = tSkipListIteratorReset(pSkipList, &iter); +// assert(ret == 0); +// +// pResult->pRes = calloc(pSkipList->nSize, POINTER_BYTES); +// +// while (tSkipListIteratorNext(&iter)) { +// tSkipListNode *pNode = tSkipListIteratorGet(&iter); +// if (filterItem(pExpr, pNode, param)) { +// pResult->pRes[n++] = pNode; +// } +// } +// +// pResult->num = n; +//} // post-root order traverse syntax tree -void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExpr, tSkipList *pSkipList, tQueryResultset *result, - SBinaryFilterSupp *param) { - if (pExpr == NULL) { - return; - } - - tSQLSyntaxNode *pLeft = pExpr->pLeft; - tSQLSyntaxNode *pRight = pExpr->pRight; - - // recursive traverse left child branch - if (pLeft->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_EXPR) { - uint8_t weight = pLeft->pExpr->filterOnPrimaryKey + pRight->pExpr->filterOnPrimaryKey; - - if (weight == 0 && result->num > 0 && pSkipList == NULL) { - /** - * Perform the filter operation based on the initial filter result, which is obtained from filtering from index. - * Since no index presented, the filter operation is done by scan all elements in the result set. - * - * if the query is a high selectivity filter, only small portion of meters are retrieved. - */ - tSQLBinaryTraverseOnResult(pExpr, result, param); - } else if (weight == 0) { - /** - * apply the hierarchical expression to every node in skiplist for find the qualified nodes - */ - assert(result->num == 0); - tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param); - } else if (weight == 2 || (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_OR)) { - tQueryResultset rLeft = {0}; - tQueryResultset rRight = {0}; - - tSQLBinaryExprTraverse(pLeft->pExpr, pSkipList, &rLeft, param); - tSQLBinaryExprTraverse(pRight->pExpr, pSkipList, &rRight, param); - - if (pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) { // CROSS - intersect(&rLeft, &rRight, result); - } else if (pExpr->nSQLBinaryOptr == TSDB_RELATION_OR) { // or - merge(&rLeft, &rRight, result); - } else { - assert(false); - } - - free(rLeft.pRes); - free(rRight.pRes); - } else { - /* - * (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here - * - * first, we filter results based on the skiplist index, which is the initial filter stage, - * then, we conduct the secondary filter operation based on the result from the initial filter stage. - */ - assert(pExpr->nSQLBinaryOptr == TSDB_RELATION_AND); - - tSQLBinaryExpr *pFirst = NULL; - tSQLBinaryExpr *pSecond = NULL; - if (pLeft->pExpr->filterOnPrimaryKey == 1) { - pFirst = pLeft->pExpr; - pSecond = pRight->pExpr; - } else { - pFirst = pRight->pExpr; - pSecond = pLeft->pExpr; - } - - assert(pFirst != pSecond && pFirst != NULL && pSecond != NULL); - - // we filter the result based on the skiplist index in the first place - tSQLBinaryExprTraverse(pFirst, pSkipList, result, param); - - /* - * recursively perform the filter operation based on the initial results, - * So, we do not set the skiplist index as a parameter - */ - tSQLBinaryExprTraverse(pSecond, NULL, result, param); - } - } else { // column project - assert(pLeft->nodeType == TSQL_NODE_COL && pRight->nodeType == TSQL_NODE_VALUE); - - param->setupInfoFn(pExpr, param->pExtInfo); - if (pSkipList == NULL) { - tSQLListTraverseOnResult(pExpr, param->fp, result); - } else { - assert(result->num == 0); - tSQLDoFilterInitialResult(pSkipList, param->fp, pExpr->info, result); - } - } -} +//void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExpr, tSkipList *pSkipList, tQueryResultset *result, +// SBinaryFilterSupp *param) { +// if (pExpr == NULL) { +// return; +// } +// +// tSQLSyntaxNode *pLeft = pExpr->pLeft; +// tSQLSyntaxNode *pRight = pExpr->pRight; +// +// // recursive traverse left child branch +// if (pLeft->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_EXPR) { +// uint8_t weight = pLeft->pExpr->filterOnPrimaryKey + pRight->pExpr->filterOnPrimaryKey; +// +// if (weight == 0 && result->num > 0 && pSkipList == NULL) { +// /** +// * Perform the filter operation based on the initial filter result, which is obtained from filtering from index. +// * Since no index presented, the filter operation is done by scan all elements in the result set. +// * +// * if the query is a high selectivity filter, only small portion of meters are retrieved. +// */ +// tSQLBinaryTraverseOnResult(pExpr, result, param); +// } else if (weight == 0) { +// /** +// * apply the hierarchical expression to every node in skiplist for find the qualified nodes +// */ +// assert(result->num == 0); +// tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param); +// } else if (weight == 2 || (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_OR)) { +// tQueryResultset rLeft = {0}; +// tQueryResultset rRight = {0}; +// +// tSQLBinaryExprTraverse(pLeft->pExpr, pSkipList, &rLeft, param); +// tSQLBinaryExprTraverse(pRight->pExpr, pSkipList, &rRight, param); +// +// if (pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) { // CROSS +// intersect(&rLeft, &rRight, result); +// } else if (pExpr->nSQLBinaryOptr == TSDB_RELATION_OR) { // or +// merge(&rLeft, &rRight, result); +// } else { +// assert(false); +// } +// +// free(rLeft.pRes); +// free(rRight.pRes); +// } else { +// /* +// * (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here +// * +// * first, we filter results based on the skiplist index, which is the initial filter stage, +// * then, we conduct the secondary filter operation based on the result from the initial filter stage. +// */ +// assert(pExpr->nSQLBinaryOptr == TSDB_RELATION_AND); +// +// tSQLBinaryExpr *pFirst = NULL; +// tSQLBinaryExpr *pSecond = NULL; +// if (pLeft->pExpr->filterOnPrimaryKey == 1) { +// pFirst = pLeft->pExpr; +// pSecond = pRight->pExpr; +// } else { +// pFirst = pRight->pExpr; +// pSecond = pLeft->pExpr; +// } +// +// assert(pFirst != pSecond && pFirst != NULL && pSecond != NULL); +// +// // we filter the result based on the skiplist index in the first place +// tSQLBinaryExprTraverse(pFirst, pSkipList, result, param); +// +// /* +// * recursively perform the filter operation based on the initial results, +// * So, we do not set the skiplist index as a parameter +// */ +// tSQLBinaryExprTraverse(pSecond, NULL, result, param); +// } +// } else { // column project +// assert(pLeft->nodeType == TSQL_NODE_COL && pRight->nodeType == TSQL_NODE_VALUE); +// +// param->setupInfoFn(pExpr, param->pExtInfo); +// if (pSkipList == NULL) { +// tSQLListTraverseOnResult(pExpr, param->fp, result); +// } else { +// assert(result->num == 0); +//// tSQLDoFilterInitialResult(pSkipList, param->fp, pExpr->info, result); +// } +// } +//} void tSQLBinaryExprCalcTraverse(tSQLBinaryExpr *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order, char *(*getSourceDataBlock)(void *, char *, int32_t)) { diff --git a/src/client/src/tscSQLParserImpl.c b/src/query/src/tscSQLParserImpl.c similarity index 99% rename from src/client/src/tscSQLParserImpl.c rename to src/query/src/tscSQLParserImpl.c index 17e1c6f457..0a76b867f2 100644 --- a/src/client/src/tscSQLParserImpl.c +++ b/src/query/src/tscSQLParserImpl.c @@ -13,13 +13,16 @@ * along with this program. If not, see . */ +#include #include "os.h" +#include "qsqlparser.h" #include "taosmsg.h" #include "tglobalcfg.h" #include "tlog.h" -#include "tscSQLParser.h" #include "tstoken.h" #include "ttime.h" +#include "ttokendef.h" +#include "ttypes.h" #include "tutil.h" int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { diff --git a/src/client/src/tscSyntaxtreefunction.c b/src/query/src/tscSyntaxtreefunction.c similarity index 99% rename from src/client/src/tscSyntaxtreefunction.c rename to src/query/src/tscSyntaxtreefunction.c index 1d82b0f239..3fe43d9c1e 100644 --- a/src/client/src/tscSyntaxtreefunction.c +++ b/src/query/src/tscSyntaxtreefunction.c @@ -16,7 +16,6 @@ #include "os.h" #include "tscSyntaxtreefunction.h" -#include "tscSQLParser.h" #include "ttypes.h" #include "tutil.h" diff --git a/src/util/src/ttokenizer.c b/src/query/src/ttokenizer.c similarity index 99% rename from src/util/src/ttokenizer.c rename to src/query/src/ttokenizer.c index 7cbb4552b4..c53debcb45 100644 --- a/src/util/src/ttokenizer.c +++ b/src/query/src/ttokenizer.c @@ -13,14 +13,14 @@ * along with this program. If not, see . */ -#include "os.h" +#include "hash.h" #include "hashutil.h" +#include "os.h" #include "shash.h" -#include "tutil.h" -#include "tsqldef.h" #include "tstoken.h" +#include "ttokendef.h" #include "ttypes.h" -#include "hash.h" +#include "tutil.h" // All the keywords of the SQL language are stored in a hash table typedef struct SKeyword { diff --git a/src/query/src/tvariant.c b/src/query/src/tvariant.c new file mode 100644 index 0000000000..8c8887ca2e --- /dev/null +++ b/src/query/src/tvariant.c @@ -0,0 +1,851 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "hash.h" +#include "hashutil.h" +#include "os.h" +#include "shash.h" +#include "tstoken.h" +#include "ttokendef.h" +#include "ttypes.h" +#include "tutil.h" +#include "tvariant.h" +#include "ttypes.h" +#include "taos.h" + +// todo support scientific expression number and oct number +void tVariantCreate(tVariant *pVar, SSQLToken *token) { tVariantCreateFromString(pVar, token->z, token->n, token->type); } + +void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type) { + memset(pVar, 0, sizeof(tVariant)); + + switch (type) { + case TSDB_DATA_TYPE_BOOL: { + int32_t k = strncasecmp(pz, "true", 4); + if (k == 0) { + pVar->i64Key = TSDB_TRUE; + } else { + assert(strncasecmp(pz, "false", 5) == 0); + pVar->i64Key = TSDB_FALSE; + } + break; + } + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_INT: + pVar->i64Key = strtoll(pz, NULL, 10); + break; + case TSDB_DATA_TYPE_DOUBLE: + case TSDB_DATA_TYPE_FLOAT: + pVar->dKey = strtod(pz, NULL); + break; + case TSDB_DATA_TYPE_BINARY: { + pVar->pz = strndup(pz, len); + pVar->nLen = strdequote(pVar->pz); + break; + } + + default: { // nType == 0 means the null value + type = TSDB_DATA_TYPE_NULL; + } + } + + pVar->nType = type; +} + +/** + * create tVariant from binary string, not ascii data + * @param pVar + * @param pz + * @param len + * @param type + */ +void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t type) { + switch (type) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: { + pVar->i64Key = GET_INT8_VAL(pz); + break; + } + case TSDB_DATA_TYPE_SMALLINT: { + pVar->i64Key = GET_INT16_VAL(pz); + break; + } + case TSDB_DATA_TYPE_INT: { + pVar->i64Key = GET_INT32_VAL(pz); + break; + } + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TIMESTAMP: { + pVar->i64Key = GET_INT64_VAL(pz); + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + pVar->dKey = GET_DOUBLE_VAL(pz); + break; + } + case TSDB_DATA_TYPE_FLOAT: { + pVar->dKey = GET_FLOAT_VAL(pz); + break; + } + case TSDB_DATA_TYPE_NCHAR: { // here we get the nchar length from raw binary bits length + pVar->nLen = len / TSDB_NCHAR_SIZE; + pVar->wpz = calloc(1, (pVar->nLen + 1) * TSDB_NCHAR_SIZE); + + wcsncpy(pVar->wpz, (wchar_t *)pz, pVar->nLen); + pVar->wpz[pVar->nLen] = 0; + + break; + } + case TSDB_DATA_TYPE_BINARY: { + pVar->pz = strndup(pz, len); + pVar->nLen = strdequote(pVar->pz); + + break; + } + + default: + pVar->i64Key = GET_INT32_VAL(pVar); + } + + pVar->nType = type; +} + +void tVariantDestroy(tVariant *pVar) { + if (pVar == NULL) return; + + if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) { + tfree(pVar->pz); + pVar->nLen = 0; + } +} + +void tVariantAssign(tVariant *pDst, const tVariant *pSrc) { + if (pSrc == NULL || pDst == NULL) return; + + *pDst = *pSrc; + + if (pSrc->nType == TSDB_DATA_TYPE_BINARY || pSrc->nType == TSDB_DATA_TYPE_NCHAR) { + int32_t len = pSrc->nLen + 1; + if (pSrc->nType == TSDB_DATA_TYPE_NCHAR) { + len = len * TSDB_NCHAR_SIZE; + } + + pDst->pz = calloc(1, len); + memcpy(pDst->pz, pSrc->pz, len); + } +} + +int32_t tVariantToString(tVariant *pVar, char *dst) { + if (pVar == NULL || dst == NULL) return 0; + + switch (pVar->nType) { + case TSDB_DATA_TYPE_BINARY: { + int32_t len = sprintf(dst, "\'%s\'", pVar->pz); + assert(len <= pVar->nLen + sizeof("\'") * 2); // two more chars + return len; + } + + case TSDB_DATA_TYPE_NCHAR: { + dst[0] = '\''; + taosUcs4ToMbs(pVar->wpz, (wcslen(pVar->wpz) + 1) * TSDB_NCHAR_SIZE, dst + 1); + int32_t len = strlen(dst); + dst[len] = '\''; + dst[len + 1] = 0; + return len + 1; + } + + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_INT: + return sprintf(dst, "%d", (int32_t)pVar->i64Key); + + case TSDB_DATA_TYPE_BIGINT: + return sprintf(dst, "%" PRId64, pVar->i64Key); + + case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_DOUBLE: + return sprintf(dst, "%.9lf", pVar->dKey); + + default: + return 0; + } +} + +#if 0 +static int32_t doConvertToInteger(tVariant *pVariant, char *pDest, int32_t type, bool releaseVariantPtr) { + if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + setNull(pDest, type, tDataTypeDesc[type].nSize); + return 0; + } + + if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { + *((int64_t *)pDest) = pVariant->i64Key; + } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { + if ((pVariant->dKey < INT64_MIN) || (pVariant->dKey > INT64_MAX)) { + return -1; + } + + *((int64_t *)pDest) = (int64_t)pVariant->dKey; + } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + errno = 0; + char *endPtr = NULL; + + SSQLToken token = {0}; + token.n = tSQLGetToken(pVariant->pz, &token.type); + + if (token.type == TK_MINUS || token.type == TK_PLUS) { + token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); + } + + if (token.type == TK_FLOAT) { + double v = strtod(pVariant->pz, &endPtr); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { + return -1; + } + + if ((v < INT64_MIN) || (v > INT64_MAX)) { + return -1; + } + + *((int64_t *)pDest) = (int64_t)v; + } else if (token.type == TK_INTEGER) { + int64_t val = strtoll(pVariant->pz, &endPtr, 10); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if (errno == ERANGE) { + return -1; // data overflow + } + + *((int64_t *)pDest) = val; + } else if (token.type == TK_NULL) { + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + setNull(pDest, type, tDataTypeDesc[type].nSize); + } else { + return -1; + } + + } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { + errno = 0; + wchar_t *endPtr = NULL; + + SSQLToken token = {0}; + token.n = tSQLGetToken(pVariant->pz, &token.type); + + if (token.type == TK_MINUS || token.type == TK_PLUS) { + token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); + } + + if (token.type == TK_FLOAT) { + double v = wcstod(pVariant->wpz, &endPtr); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { + return -1; + } + + if ((v < INT64_MIN) || (v > INT64_MAX)) { + return -1; + } + + *((int64_t *)pDest) = (int64_t)v; + } else if (token.type == TK_NULL) { + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + setNull(pDest, type, tDataTypeDesc[type].nSize); + } else { + int64_t val = wcstoll(pVariant->wpz, &endPtr, 10); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if (errno == ERANGE) { + return -1; // data overflow + } + + *((int64_t *)pDest) = val; + } + } + + return 0; +} +#endif +static FORCE_INLINE int32_t convertToBoolImpl(char *pStr, int32_t len) { + if ((strncasecmp(pStr, "true", len) == 0) && (len == 4)) { + return TSDB_TRUE; + } else if ((strncasecmp(pStr, "false", len) == 0) && (len == 5)) { + return TSDB_FALSE; + } else if (strcasecmp(pStr, TSDB_DATA_NULL_STR_L) == 0) { + return TSDB_DATA_BOOL_NULL; + } else { + return -1; + } +} + +static FORCE_INLINE int32_t wcsconvertToBoolImpl(wchar_t *pstr, int32_t len) { + if ((wcsncasecmp(pstr, L"true", len) == 0) && (len == 4)) { + return TSDB_TRUE; + } else if (wcsncasecmp(pstr, L"false", len) == 0 && (len == 5)) { + return TSDB_FALSE; + } else { + return -1; + } +} + +static int32_t toBinary(tVariant *pVariant, char **pDest, int32_t *pDestSize) { + const int32_t INITIAL_ALLOC_SIZE = 20; + char * pBuf = NULL; + + if (*pDest == pVariant->pz) { + pBuf = calloc(1, INITIAL_ALLOC_SIZE); + } + + if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { + size_t newSize = pVariant->nLen * TSDB_NCHAR_SIZE; + if (pBuf != NULL) { + if (newSize > INITIAL_ALLOC_SIZE) { + pBuf = realloc(pBuf, newSize + 1); + } + + taosUcs4ToMbs(pVariant->wpz, newSize, pBuf); + free(pVariant->wpz); + + /* terminated string */ + pBuf[newSize] = 0; + } else { + taosUcs4ToMbs(pVariant->wpz, newSize, *pDest); + } + + } else { + if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { + sprintf(pBuf == NULL ? *pDest : pBuf, "%" PRId64, pVariant->i64Key); + } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { + sprintf(pBuf == NULL ? *pDest : pBuf, "%lf", pVariant->dKey); + } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { + sprintf(pBuf == NULL ? *pDest : pBuf, "%s", (pVariant->i64Key == TSDB_TRUE) ? "TRUE" : "FALSE"); + } else if (pVariant->nType == 0) { // null data + setNull(pBuf == NULL ? *pDest : pBuf, TSDB_DATA_TYPE_BINARY, 0); + } + } + + if (pBuf != NULL) { + *pDest = pBuf; + } + + *pDestSize = strlen(*pDest); + return 0; +} + +static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) { + char tmpBuf[40] = {0}; + + char * pDst = tmpBuf; + int32_t nLen = 0; + + if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { + nLen = sprintf(pDst, "%" PRId64, pVariant->i64Key); + } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { + nLen = sprintf(pDst, "%lf", pVariant->dKey); + } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + pDst = pVariant->pz; + nLen = pVariant->nLen; + } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { + nLen = sprintf(pDst, "%s", (pVariant->i64Key == TSDB_TRUE) ? "TRUE" : "FALSE"); + } + + if (*pDest == pVariant->pz) { + wchar_t *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE); + taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE); + + // free the binary buffer in the first place + if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + free(pVariant->wpz); + } + + pVariant->wpz = pWStr; + *pDestSize = wcslen(pVariant->wpz); + + // shrink the allocate memory, no need to check here. + char* tmp = realloc(pVariant->wpz, (*pDestSize + 1)*TSDB_NCHAR_SIZE); + assert(tmp != NULL); + + pVariant->wpz = (wchar_t *)tmp; + } else { + taosMbsToUcs4(pDst, nLen, *pDest, (nLen + 1) * TSDB_NCHAR_SIZE); + } + + return 0; +} + +static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *value) { + SSQLToken stoken = {.z = pStr, .n = len}; + + if (TK_ILLEGAL == isValidNumber(&stoken)) { + return -1; + } + + *value = strtod(pStr, NULL); + + return 0; +} + +static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result, int32_t type, int64_t lowBnd, + int64_t upperBnd, bool releaseVariantPtr) { + if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + setNull((char *)result, type, tDataTypeDesc[type].nSize); + return 0; + } + + if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { + *result = pVariant->i64Key; + } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { + *result = (int64_t)pVariant->dKey; + } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + errno = 0; + char *endPtr = NULL; + + SSQLToken token = {0}; + token.n = tSQLGetToken(pVariant->pz, &token.type); + + if (token.type == TK_MINUS || token.type == TK_PLUS) { + token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); + } + + if (token.type == TK_NULL) { + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + setNull((char *)result, type, tDataTypeDesc[type].nSize); + return 0; + } + + SSQLToken sToken = {.z = pVariant->pz, .n = pVariant->nLen}; + if (TK_ILLEGAL == isValidNumber(&sToken)) { + return -1; + } + + if (token.type == TK_FLOAT) { + double v = strtod(pVariant->pz, &endPtr); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { + return -1; + } + + *result = (int64_t)v; + } else if (token.type == TK_INTEGER) { + int64_t val = strtoll(pVariant->pz, &endPtr, 10); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if (errno == ERANGE) { + return -1; // data overflow + } + + *result = val; + } else { + return -1; + } + } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { + errno = 0; + wchar_t *endPtr = NULL; + + SSQLToken token = {0}; + token.n = tSQLGetToken(pVariant->pz, &token.type); + + if (token.type == TK_MINUS || token.type == TK_PLUS) { + token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); + } + + if (token.type == TK_FLOAT) { + double v = wcstod(pVariant->wpz, &endPtr); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { + return -1; + } + + *result = (int64_t)v; + } else if (token.type == TK_NULL) { + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + setNull((char *)result, type, tDataTypeDesc[type].nSize); + return 0; + } else { + int64_t val = wcstoll(pVariant->wpz, &endPtr, 10); + if (releaseVariantPtr) { + free(pVariant->pz); + pVariant->nLen = 0; + } + + if (errno == ERANGE) { + return -1; // data overflow + } + + *result = val; + } + } + + if ((*result <= lowBnd) || (*result > upperBnd)) { + return -1; + } + + return 0; +} + +static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) { + if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { + *pDest = pVariant->i64Key; // in order to be compatible to null of bool + } else if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { + *pDest = ((pVariant->i64Key != 0) ? TSDB_TRUE : TSDB_FALSE); + } else if (pVariant->nType == TSDB_DATA_TYPE_FLOAT || pVariant->nType == TSDB_DATA_TYPE_DOUBLE) { + *pDest = ((pVariant->dKey != 0) ? TSDB_TRUE : TSDB_FALSE); + } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + int32_t ret = 0; + if ((ret = convertToBoolImpl(pVariant->pz, pVariant->nLen)) < 0) { + return ret; + } + + *pDest = ret; + } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { + int32_t ret = 0; + if ((ret = wcsconvertToBoolImpl(pVariant->wpz, pVariant->nLen)) < 0) { + return ret; + } + *pDest = ret; + } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + *pDest = TSDB_DATA_BOOL_NULL; + } + + assert(*pDest == TSDB_TRUE || *pDest == TSDB_FALSE || *pDest == TSDB_DATA_BOOL_NULL); + return 0; +} + +/* + * transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType + * to column type defined in schema + * + * todo handle the return value + */ +int32_t tVariantDump(tVariant *pVariant, char *payload, char type) { + if (pVariant == NULL || (pVariant->nType != 0 && !isValidDataType(pVariant->nType, pVariant->nLen))) { + return -1; + } + + errno = 0; // reset global error code + + switch (type) { + case TSDB_DATA_TYPE_BOOL: { + int64_t dst = 0; + if (convertToBool(pVariant, &dst) < 0) { + return -1; + } + *(int8_t *)payload = (int8_t)dst; + break; + } + + case TSDB_DATA_TYPE_TINYINT: { + int64_t result = 0; + if (convertToInteger(pVariant, &result, type, INT8_MIN, INT8_MAX, false) < 0) { + return -1; + } + + *((int8_t *)payload) = (int8_t)result; + break; + } + + case TSDB_DATA_TYPE_SMALLINT: { + int64_t result = 0; + if (convertToInteger(pVariant, &result, type, INT16_MIN, INT16_MAX, false) < 0) { + return -1; + } + + *((int16_t *)payload) = (int16_t)result; + break; + } + + case TSDB_DATA_TYPE_INT: { + int64_t result = 0; + if (convertToInteger(pVariant, &result, type, INT32_MIN, INT32_MAX, false) < 0) { + return -1; + } + + *((int32_t *)payload) = (int32_t)result; + break; + } + + case TSDB_DATA_TYPE_BIGINT: { + int64_t result = 0; + if (convertToInteger(pVariant, &result, type, INT64_MIN, INT64_MAX, false) < 0) { + return -1; + } + + *((int64_t *)payload) = (int64_t)result; + break; + } + + case TSDB_DATA_TYPE_FLOAT: { + if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + if (strncasecmp(TSDB_DATA_NULL_STR_L, pVariant->pz, pVariant->nLen) == 0 && + strlen(TSDB_DATA_NULL_STR_L) == pVariant->nLen) { + *((int32_t *)payload) = TSDB_DATA_FLOAT_NULL; + return 0; + } else { + double value; + int32_t ret; + ret = convertToDouble(pVariant->pz, pVariant->nLen, &value); + if ((errno == ERANGE && (float)value == -1) || (ret != 0)) { + return -1; + } + +#ifdef _TD_ARM_32_ + //memcpy(&payload, &value, sizeof(float)); + float fv = (float)value; + SET_FLOAT_VAL_ALIGN(payload, &fv); +#else + *((float *)payload) = (float)value; +#endif + } + } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { +#ifdef _TD_ARM_32_ + //memcpy(&payload, &pVariant->i64Key, sizeof(float)); + float fv = (float)pVariant->i64Key; + SET_FLOAT_VAL_ALIGN(payload, &fv); +#else + *((float *)payload) = pVariant->i64Key; +#endif + } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { +#ifdef _TD_ARM_32_ + //memcpy(&payload, &pVariant->dKey, sizeof(float)); + float fv = (float)pVariant->dKey; + SET_FLOAT_VAL_ALIGN(payload, &fv); +#else + *((float *)payload) = (float)pVariant->dKey; +#endif + } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + *((int32_t *)payload) = TSDB_DATA_FLOAT_NULL; + return 0; + } + +#ifdef _TD_ARM_32_ + float fv = GET_FLOAT_VAL(payload); + if (isinf(fv) || isnan(fv) || fv > FLT_MAX || fv < -FLT_MAX) { + return -1; + } +#else + if (isinf(*((float *)payload)) || isnan(*((float *)payload)) || *((float *)payload) > FLT_MAX || + *((float *)payload) < -FLT_MAX) { + return -1; + } +#endif + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + if (strncasecmp(TSDB_DATA_NULL_STR_L, pVariant->pz, pVariant->nLen) == 0 && + strlen(TSDB_DATA_NULL_STR_L) == pVariant->nLen) { + *((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL; + return 0; + } else { + double value = 0; + int32_t ret; + ret = convertToDouble(pVariant->pz, pVariant->nLen, &value); + if ((errno == ERANGE && value == -1) || (ret != 0)) { + return -1; + } + +#ifdef _TD_ARM_32_ + SET_DOUBLE_VAL_ALIGN(payload, &value); +#else + *((double *)payload) = value; +#endif + } + } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { +#ifdef _TD_ARM_32_ + double dv = (double)(pVariant->i64Key); + SET_DOUBLE_VAL_ALIGN(payload, &dv); +#else + *((double *)payload) = pVariant->i64Key; +#endif + } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { +#ifdef _TD_ARM_32_ + double dv = (double)(pVariant->dKey); + SET_DOUBLE_VAL_ALIGN(payload, &dv); +#else + *((double *)payload) = pVariant->dKey; +#endif + } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + *((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL; + return 0; + } + +#ifdef _TD_ARM_32_ + double dv = GET_DOUBLE_VAL(payload); + if (isinf(dv) || isnan(dv) || dv > DBL_MAX || dv < -DBL_MAX) { + return -1; + } +#else + if (isinf(*((double *)payload)) || isnan(*((double *)payload)) || *((double *)payload) > DBL_MAX || + *((double *)payload) < -DBL_MAX) { + return -1; + } +#endif + break; + } + + case TSDB_DATA_TYPE_BINARY: { + if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + *payload = TSDB_DATA_BINARY_NULL; + } else { + if (pVariant->nType != TSDB_DATA_TYPE_BINARY) { + toBinary(pVariant, &payload, &pVariant->nLen); + } else { + strncpy(payload, pVariant->pz, pVariant->nLen); + } + } + break; + } + case TSDB_DATA_TYPE_TIMESTAMP: { + if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + *((int64_t *)payload) = TSDB_DATA_BIGINT_NULL; + } else { + *((int64_t *)payload) = pVariant->i64Key; + } + break; + } + case TSDB_DATA_TYPE_NCHAR: { + if (pVariant->nType == TSDB_DATA_TYPE_NULL) { + *(uint32_t *)payload = TSDB_DATA_NCHAR_NULL; + } else { + if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { + toNchar(pVariant, &payload, &pVariant->nLen); + } else { + wcsncpy((wchar_t *)payload, pVariant->wpz, pVariant->nLen); + } + } + break; + } + } + + return 0; +} + +/* + * In variant, bool/smallint/tinyint/int/bigint share the same attribution of + * structure, also ignore the convert the type required + * + * It is actually the bigint/binary/bool/nchar type transfer + */ +int32_t tVariantTypeSetType(tVariant *pVariant, char type) { + if (pVariant == NULL || pVariant->nType == 0) { // value is not set + return 0; + } + + switch (type) { + case TSDB_DATA_TYPE_BOOL: { // bool + if (convertToBool(pVariant, &pVariant->i64Key) < 0) { + return -1; + } + + pVariant->nType = type; + break; + } + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_SMALLINT: { + convertToInteger(pVariant, &(pVariant->i64Key), type, INT64_MIN, INT64_MAX, true); + pVariant->nType = TSDB_DATA_TYPE_BIGINT; + break; + } + case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_DOUBLE: { + if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { + errno = 0; + double v = strtod(pVariant->pz, NULL); + if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { + free(pVariant->pz); + return -1; + } + + free(pVariant->pz); + pVariant->dKey = v; + } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { + errno = 0; + double v = wcstod(pVariant->wpz, NULL); + if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { + free(pVariant->pz); + return -1; + } + + free(pVariant->pz); + pVariant->dKey = v; + } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { + pVariant->dKey = pVariant->i64Key; + } + + pVariant->nType = TSDB_DATA_TYPE_DOUBLE; + break; + } + case TSDB_DATA_TYPE_BINARY: { + if (pVariant->nType != TSDB_DATA_TYPE_BINARY) { + toBinary(pVariant, &pVariant->pz, &pVariant->nLen); + } + pVariant->nType = type; + break; + } + case TSDB_DATA_TYPE_NCHAR: { + if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { + toNchar(pVariant, &pVariant->pz, &pVariant->nLen); + } + pVariant->nType = type; + break; + } + } + + return 0; +} + + diff --git a/src/util/inc/sskiplist.h b/src/util/inc/sskiplist.h index 28300a69b4..2f300fa4ea 100644 --- a/src/util/inc/sskiplist.h +++ b/src/util/inc/sskiplist.h @@ -12,6 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +#if 0 #ifndef TBASE_TSKIPLIST_H #define TBASE_TSKIPLIST_H @@ -203,3 +204,4 @@ tSkipListNode *tSkipListIteratorGet(SSkipListIterator *iter); #endif #endif // TBASE_TSKIPLIST_H +#endif \ No newline at end of file diff --git a/src/util/inc/tstoken.h b/src/util/inc/tstoken.h index 3ecf28aa2a..13190e800d 100644 --- a/src/util/inc/tstoken.h +++ b/src/util/inc/tstoken.h @@ -20,7 +20,7 @@ extern "C" { #endif -#include +#include "os.h" #define TK_SPACE 200 #define TK_COMMENT 201 diff --git a/src/util/inc/ttypes.h b/src/util/inc/ttypes.h index db6490f840..a099f3fa7c 100644 --- a/src/util/inc/ttypes.h +++ b/src/util/inc/ttypes.h @@ -35,14 +35,28 @@ extern "C" { #define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*) -typedef struct tDataDescriptor { +#define TSDB_DATA_BOOL_NULL 0x02 +#define TSDB_DATA_TINYINT_NULL 0x80 +#define TSDB_DATA_SMALLINT_NULL 0x8000 +#define TSDB_DATA_INT_NULL 0x80000000 +#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L + +#define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN +#define TSDB_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN +#define TSDB_DATA_NCHAR_NULL 0xFFFFFFFF +#define TSDB_DATA_BINARY_NULL 0xFF + +#define TSDB_DATA_NULL_STR "NULL" +#define TSDB_DATA_NULL_STR_L "null" + +typedef struct tDataTypeDescriptor { int16_t nType; int16_t nameLen; int32_t nSize; char * aName; -} tDataDescriptor; +} tDataTypeDescriptor; -extern tDataDescriptor tDataTypeDesc[11]; +extern tDataTypeDescriptor tDataTypeDesc[11]; bool isValidDataType(int32_t type, int32_t length); bool isNull(const char *val, int32_t type); @@ -53,34 +67,6 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems); void assignVal(char *val, const char *src, int32_t len, int32_t type); void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); -// variant, each number/string/field_id has a corresponding struct during parsing sql -typedef struct tVariant { - uint32_t nType; - int32_t nLen; // only used for string, for number, it is useless - union { - int64_t i64Key; - double dKey; - char * pz; - wchar_t *wpz; - }; -} tVariant; - -void tVariantCreate(tVariant *pVar, SSQLToken *token); - -void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type); - -void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t type); - -void tVariantDestroy(tVariant *pV); - -void tVariantAssign(tVariant *pDst, const tVariant *pSrc); - -int32_t tVariantToString(tVariant *pVar, char *dst); - -int32_t tVariantDump(tVariant *pVariant, char *payload, char type); - -int32_t tVariantTypeSetType(tVariant *pVariant, char type); - #ifdef __cplusplus } #endif diff --git a/src/util/src/sskiplist.c b/src/util/src/sskiplist.c index 47948e1660..cba38e9bed 100644 --- a/src/util/src/sskiplist.c +++ b/src/util/src/sskiplist.c @@ -12,6 +12,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + +#if 0 #include "os.h" #include "tlog.h" @@ -842,3 +844,5 @@ int32_t tSkipListPointQuery(tSkipList *pSkipList, tSkipListKey *pKey, int32_t nu return retLen; } } + +#endif \ No newline at end of file diff --git a/src/util/src/ttypes.c b/src/util/src/ttypes.c index 86fa7cd5f8..5fd679dccf 100644 --- a/src/util/src/ttypes.c +++ b/src/util/src/ttypes.c @@ -12,14 +12,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +#include "ttypes.h" #include "os.h" #include "taos.h" #include "taosdef.h" -#include "tsqldef.h" -#include "ttypes.h" +#include "ttokendef.h" #include "tutil.h" -tDataDescriptor tDataTypeDesc[11] = { +tDataTypeDescriptor tDataTypeDesc[11] = { {TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE"}, {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL"}, {TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT"}, @@ -61,829 +61,6 @@ bool isValidDataType(int32_t type, int32_t length) { return true; } -// todo support scientific expression number and oct number -void tVariantCreate(tVariant *pVar, SSQLToken *token) { tVariantCreateFromString(pVar, token->z, token->n, token->type); } - -void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type) { - memset(pVar, 0, sizeof(tVariant)); - - switch (type) { - case TSDB_DATA_TYPE_BOOL: { - int32_t k = strncasecmp(pz, "true", 4); - if (k == 0) { - pVar->i64Key = TSDB_TRUE; - } else { - assert(strncasecmp(pz, "false", 5) == 0); - pVar->i64Key = TSDB_FALSE; - } - break; - } - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_INT: - pVar->i64Key = strtoll(pz, NULL, 10); - break; - case TSDB_DATA_TYPE_DOUBLE: - case TSDB_DATA_TYPE_FLOAT: - pVar->dKey = strtod(pz, NULL); - break; - case TSDB_DATA_TYPE_BINARY: { - pVar->pz = strndup(pz, len); - pVar->nLen = strdequote(pVar->pz); - break; - } - - default: { // nType == 0 means the null value - type = TSDB_DATA_TYPE_NULL; - } - } - - pVar->nType = type; -} - -/** - * create tVariant from binary string, not ascii data - * @param pVar - * @param pz - * @param len - * @param type - */ -void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t type) { - switch (type) { - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: { - pVar->i64Key = GET_INT8_VAL(pz); - break; - } - case TSDB_DATA_TYPE_SMALLINT: { - pVar->i64Key = GET_INT16_VAL(pz); - break; - } - case TSDB_DATA_TYPE_INT: { - pVar->i64Key = GET_INT32_VAL(pz); - break; - } - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TIMESTAMP: { - pVar->i64Key = GET_INT64_VAL(pz); - break; - } - case TSDB_DATA_TYPE_DOUBLE: { - pVar->dKey = GET_DOUBLE_VAL(pz); - break; - } - case TSDB_DATA_TYPE_FLOAT: { - pVar->dKey = GET_FLOAT_VAL(pz); - break; - } - case TSDB_DATA_TYPE_NCHAR: { // here we get the nchar length from raw binary bits length - pVar->nLen = len / TSDB_NCHAR_SIZE; - pVar->wpz = calloc(1, (pVar->nLen + 1) * TSDB_NCHAR_SIZE); - - wcsncpy(pVar->wpz, (wchar_t *)pz, pVar->nLen); - pVar->wpz[pVar->nLen] = 0; - - break; - } - case TSDB_DATA_TYPE_BINARY: { - pVar->pz = strndup(pz, len); - pVar->nLen = strdequote(pVar->pz); - - break; - } - - default: - pVar->i64Key = GET_INT32_VAL(pVar); - } - - pVar->nType = type; -} - -void tVariantDestroy(tVariant *pVar) { - if (pVar == NULL) return; - - if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) { - tfree(pVar->pz); - pVar->nLen = 0; - } -} - -void tVariantAssign(tVariant *pDst, const tVariant *pSrc) { - if (pSrc == NULL || pDst == NULL) return; - - *pDst = *pSrc; - - if (pSrc->nType == TSDB_DATA_TYPE_BINARY || pSrc->nType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = pSrc->nLen + 1; - if (pSrc->nType == TSDB_DATA_TYPE_NCHAR) { - len = len * TSDB_NCHAR_SIZE; - } - - pDst->pz = calloc(1, len); - memcpy(pDst->pz, pSrc->pz, len); - } -} - -int32_t tVariantToString(tVariant *pVar, char *dst) { - if (pVar == NULL || dst == NULL) return 0; - - switch (pVar->nType) { - case TSDB_DATA_TYPE_BINARY: { - int32_t len = sprintf(dst, "\'%s\'", pVar->pz); - assert(len <= pVar->nLen + sizeof("\'") * 2); // two more chars - return len; - } - - case TSDB_DATA_TYPE_NCHAR: { - dst[0] = '\''; - taosUcs4ToMbs(pVar->wpz, (wcslen(pVar->wpz) + 1) * TSDB_NCHAR_SIZE, dst + 1); - int32_t len = strlen(dst); - dst[len] = '\''; - dst[len + 1] = 0; - return len + 1; - } - - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_INT: - return sprintf(dst, "%d", (int32_t)pVar->i64Key); - - case TSDB_DATA_TYPE_BIGINT: - return sprintf(dst, "%" PRId64, pVar->i64Key); - - case TSDB_DATA_TYPE_FLOAT: - case TSDB_DATA_TYPE_DOUBLE: - return sprintf(dst, "%.9lf", pVar->dKey); - - default: - return 0; - } -} - -#if 0 -static int32_t doConvertToInteger(tVariant *pVariant, char *pDest, int32_t type, bool releaseVariantPtr) { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - setNull(pDest, type, tDataTypeDesc[type].nSize); - return 0; - } - - if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - *((int64_t *)pDest) = pVariant->i64Key; - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { - if ((pVariant->dKey < INT64_MIN) || (pVariant->dKey > INT64_MAX)) { - return -1; - } - - *((int64_t *)pDest) = (int64_t)pVariant->dKey; - } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - errno = 0; - char *endPtr = NULL; - - SSQLToken token = {0}; - token.n = tSQLGetToken(pVariant->pz, &token.type); - - if (token.type == TK_MINUS || token.type == TK_PLUS) { - token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); - } - - if (token.type == TK_FLOAT) { - double v = strtod(pVariant->pz, &endPtr); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - return -1; - } - - if ((v < INT64_MIN) || (v > INT64_MAX)) { - return -1; - } - - *((int64_t *)pDest) = (int64_t)v; - } else if (token.type == TK_INTEGER) { - int64_t val = strtoll(pVariant->pz, &endPtr, 10); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if (errno == ERANGE) { - return -1; // data overflow - } - - *((int64_t *)pDest) = val; - } else if (token.type == TK_NULL) { - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - setNull(pDest, type, tDataTypeDesc[type].nSize); - } else { - return -1; - } - - } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - errno = 0; - wchar_t *endPtr = NULL; - - SSQLToken token = {0}; - token.n = tSQLGetToken(pVariant->pz, &token.type); - - if (token.type == TK_MINUS || token.type == TK_PLUS) { - token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); - } - - if (token.type == TK_FLOAT) { - double v = wcstod(pVariant->wpz, &endPtr); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - return -1; - } - - if ((v < INT64_MIN) || (v > INT64_MAX)) { - return -1; - } - - *((int64_t *)pDest) = (int64_t)v; - } else if (token.type == TK_NULL) { - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - setNull(pDest, type, tDataTypeDesc[type].nSize); - } else { - int64_t val = wcstoll(pVariant->wpz, &endPtr, 10); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if (errno == ERANGE) { - return -1; // data overflow - } - - *((int64_t *)pDest) = val; - } - } - - return 0; -} -#endif -static FORCE_INLINE int32_t convertToBoolImpl(char *pStr, int32_t len) { - if ((strncasecmp(pStr, "true", len) == 0) && (len == 4)) { - return TSDB_TRUE; - } else if ((strncasecmp(pStr, "false", len) == 0) && (len == 5)) { - return TSDB_FALSE; - } else if (strcasecmp(pStr, TSDB_DATA_NULL_STR_L) == 0) { - return TSDB_DATA_BOOL_NULL; - } else { - return -1; - } -} - -static FORCE_INLINE int32_t wcsconvertToBoolImpl(wchar_t *pstr, int32_t len) { - if ((wcsncasecmp(pstr, L"true", len) == 0) && (len == 4)) { - return TSDB_TRUE; - } else if (wcsncasecmp(pstr, L"false", len) == 0 && (len == 5)) { - return TSDB_FALSE; - } else { - return -1; - } -} - -static int32_t toBinary(tVariant *pVariant, char **pDest, int32_t *pDestSize) { - const int32_t INITIAL_ALLOC_SIZE = 20; - char * pBuf = NULL; - - if (*pDest == pVariant->pz) { - pBuf = calloc(1, INITIAL_ALLOC_SIZE); - } - - if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - size_t newSize = pVariant->nLen * TSDB_NCHAR_SIZE; - if (pBuf != NULL) { - if (newSize > INITIAL_ALLOC_SIZE) { - pBuf = realloc(pBuf, newSize + 1); - } - - taosUcs4ToMbs(pVariant->wpz, newSize, pBuf); - free(pVariant->wpz); - - /* terminated string */ - pBuf[newSize] = 0; - } else { - taosUcs4ToMbs(pVariant->wpz, newSize, *pDest); - } - - } else { - if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - sprintf(pBuf == NULL ? *pDest : pBuf, "%" PRId64, pVariant->i64Key); - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { - sprintf(pBuf == NULL ? *pDest : pBuf, "%lf", pVariant->dKey); - } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { - sprintf(pBuf == NULL ? *pDest : pBuf, "%s", (pVariant->i64Key == TSDB_TRUE) ? "TRUE" : "FALSE"); - } else if (pVariant->nType == 0) { // null data - setNull(pBuf == NULL ? *pDest : pBuf, TSDB_DATA_TYPE_BINARY, 0); - } - } - - if (pBuf != NULL) { - *pDest = pBuf; - } - - *pDestSize = strlen(*pDest); - return 0; -} - -static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) { - char tmpBuf[40] = {0}; - - char * pDst = tmpBuf; - int32_t nLen = 0; - - if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - nLen = sprintf(pDst, "%" PRId64, pVariant->i64Key); - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { - nLen = sprintf(pDst, "%lf", pVariant->dKey); - } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - pDst = pVariant->pz; - nLen = pVariant->nLen; - } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { - nLen = sprintf(pDst, "%s", (pVariant->i64Key == TSDB_TRUE) ? "TRUE" : "FALSE"); - } - - if (*pDest == pVariant->pz) { - wchar_t *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE); - taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE); - - // free the binary buffer in the first place - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - free(pVariant->wpz); - } - - pVariant->wpz = pWStr; - *pDestSize = wcslen(pVariant->wpz); - - // shrink the allocate memory, no need to check here. - char* tmp = realloc(pVariant->wpz, (*pDestSize + 1)*TSDB_NCHAR_SIZE); - assert(tmp != NULL); - - pVariant->wpz = (wchar_t *)tmp; - } else { - taosMbsToUcs4(pDst, nLen, *pDest, (nLen + 1) * TSDB_NCHAR_SIZE); - } - - return 0; -} - -static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *value) { - SSQLToken stoken = {.z = pStr, .n = len}; - - if (TK_ILLEGAL == isValidNumber(&stoken)) { - return -1; - } - - *value = strtod(pStr, NULL); - - return 0; -} - -static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result, int32_t type, int64_t lowBnd, - int64_t upperBnd, bool releaseVariantPtr) { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - setNull((char *)result, type, tDataTypeDesc[type].nSize); - return 0; - } - - if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - *result = pVariant->i64Key; - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { - *result = (int64_t)pVariant->dKey; - } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - errno = 0; - char *endPtr = NULL; - - SSQLToken token = {0}; - token.n = tSQLGetToken(pVariant->pz, &token.type); - - if (token.type == TK_MINUS || token.type == TK_PLUS) { - token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); - } - - if (token.type == TK_NULL) { - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - setNull((char *)result, type, tDataTypeDesc[type].nSize); - return 0; - } - - SSQLToken sToken = {.z = pVariant->pz, .n = pVariant->nLen}; - if (TK_ILLEGAL == isValidNumber(&sToken)) { - return -1; - } - - if (token.type == TK_FLOAT) { - double v = strtod(pVariant->pz, &endPtr); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - return -1; - } - - *result = (int64_t)v; - } else if (token.type == TK_INTEGER) { - int64_t val = strtoll(pVariant->pz, &endPtr, 10); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if (errno == ERANGE) { - return -1; // data overflow - } - - *result = val; - } else { - return -1; - } - } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - errno = 0; - wchar_t *endPtr = NULL; - - SSQLToken token = {0}; - token.n = tSQLGetToken(pVariant->pz, &token.type); - - if (token.type == TK_MINUS || token.type == TK_PLUS) { - token.n = tSQLGetToken(pVariant->pz + token.n, &token.type); - } - - if (token.type == TK_FLOAT) { - double v = wcstod(pVariant->wpz, &endPtr); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - return -1; - } - - *result = (int64_t)v; - } else if (token.type == TK_NULL) { - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - setNull((char *)result, type, tDataTypeDesc[type].nSize); - return 0; - } else { - int64_t val = wcstoll(pVariant->wpz, &endPtr, 10); - if (releaseVariantPtr) { - free(pVariant->pz); - pVariant->nLen = 0; - } - - if (errno == ERANGE) { - return -1; // data overflow - } - - *result = val; - } - } - - if ((*result <= lowBnd) || (*result > upperBnd)) { - return -1; - } - - return 0; -} - -static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) { - if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { - *pDest = pVariant->i64Key; // in order to be compatible to null of bool - } else if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - *pDest = ((pVariant->i64Key != 0) ? TSDB_TRUE : TSDB_FALSE); - } else if (pVariant->nType == TSDB_DATA_TYPE_FLOAT || pVariant->nType == TSDB_DATA_TYPE_DOUBLE) { - *pDest = ((pVariant->dKey != 0) ? TSDB_TRUE : TSDB_FALSE); - } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - int32_t ret = 0; - if ((ret = convertToBoolImpl(pVariant->pz, pVariant->nLen)) < 0) { - return ret; - } - - *pDest = ret; - } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - int32_t ret = 0; - if ((ret = wcsconvertToBoolImpl(pVariant->wpz, pVariant->nLen)) < 0) { - return ret; - } - *pDest = ret; - } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *pDest = TSDB_DATA_BOOL_NULL; - } - - assert(*pDest == TSDB_TRUE || *pDest == TSDB_FALSE || *pDest == TSDB_DATA_BOOL_NULL); - return 0; -} - -/* - * transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType - * to column type defined in schema - * - * todo handle the return value - */ -int32_t tVariantDump(tVariant *pVariant, char *payload, char type) { - if (pVariant == NULL || (pVariant->nType != 0 && !isValidDataType(pVariant->nType, pVariant->nLen))) { - return -1; - } - - errno = 0; // reset global error code - - switch (type) { - case TSDB_DATA_TYPE_BOOL: { - int64_t dst = 0; - if (convertToBool(pVariant, &dst) < 0) { - return -1; - } - *(int8_t *)payload = (int8_t)dst; - break; - } - - case TSDB_DATA_TYPE_TINYINT: { - int64_t result = 0; - if (convertToInteger(pVariant, &result, type, INT8_MIN, INT8_MAX, false) < 0) { - return -1; - } - - *((int8_t *)payload) = (int8_t)result; - break; - } - - case TSDB_DATA_TYPE_SMALLINT: { - int64_t result = 0; - if (convertToInteger(pVariant, &result, type, INT16_MIN, INT16_MAX, false) < 0) { - return -1; - } - - *((int16_t *)payload) = (int16_t)result; - break; - } - - case TSDB_DATA_TYPE_INT: { - int64_t result = 0; - if (convertToInteger(pVariant, &result, type, INT32_MIN, INT32_MAX, false) < 0) { - return -1; - } - - *((int32_t *)payload) = (int32_t)result; - break; - } - - case TSDB_DATA_TYPE_BIGINT: { - int64_t result = 0; - if (convertToInteger(pVariant, &result, type, INT64_MIN, INT64_MAX, false) < 0) { - return -1; - } - - *((int64_t *)payload) = (int64_t)result; - break; - } - - case TSDB_DATA_TYPE_FLOAT: { - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - if (strncasecmp(TSDB_DATA_NULL_STR_L, pVariant->pz, pVariant->nLen) == 0 && - strlen(TSDB_DATA_NULL_STR_L) == pVariant->nLen) { - *((int32_t *)payload) = TSDB_DATA_FLOAT_NULL; - return 0; - } else { - double value; - int32_t ret; - ret = convertToDouble(pVariant->pz, pVariant->nLen, &value); - if ((errno == ERANGE && (float)value == -1) || (ret != 0)) { - return -1; - } - -#ifdef _TD_ARM_32_ - //memcpy(&payload, &value, sizeof(float)); - float fv = (float)value; - SET_FLOAT_VAL_ALIGN(payload, &fv); -#else - *((float *)payload) = (float)value; -#endif - } - } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { -#ifdef _TD_ARM_32_ - //memcpy(&payload, &pVariant->i64Key, sizeof(float)); - float fv = (float)pVariant->i64Key; - SET_FLOAT_VAL_ALIGN(payload, &fv); -#else - *((float *)payload) = pVariant->i64Key; -#endif - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { -#ifdef _TD_ARM_32_ - //memcpy(&payload, &pVariant->dKey, sizeof(float)); - float fv = (float)pVariant->dKey; - SET_FLOAT_VAL_ALIGN(payload, &fv); -#else - *((float *)payload) = (float)pVariant->dKey; -#endif - } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *((int32_t *)payload) = TSDB_DATA_FLOAT_NULL; - return 0; - } - -#ifdef _TD_ARM_32_ - float fv = GET_FLOAT_VAL(payload); - if (isinf(fv) || isnan(fv) || fv > FLT_MAX || fv < -FLT_MAX) { - return -1; - } -#else - if (isinf(*((float *)payload)) || isnan(*((float *)payload)) || *((float *)payload) > FLT_MAX || - *((float *)payload) < -FLT_MAX) { - return -1; - } -#endif - break; - } - case TSDB_DATA_TYPE_DOUBLE: { - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - if (strncasecmp(TSDB_DATA_NULL_STR_L, pVariant->pz, pVariant->nLen) == 0 && - strlen(TSDB_DATA_NULL_STR_L) == pVariant->nLen) { - *((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL; - return 0; - } else { - double value = 0; - int32_t ret; - ret = convertToDouble(pVariant->pz, pVariant->nLen, &value); - if ((errno == ERANGE && value == -1) || (ret != 0)) { - return -1; - } - -#ifdef _TD_ARM_32_ - SET_DOUBLE_VAL_ALIGN(payload, &value); -#else - *((double *)payload) = value; -#endif - } - } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { -#ifdef _TD_ARM_32_ - double dv = (double)(pVariant->i64Key); - SET_DOUBLE_VAL_ALIGN(payload, &dv); -#else - *((double *)payload) = pVariant->i64Key; -#endif - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { -#ifdef _TD_ARM_32_ - double dv = (double)(pVariant->dKey); - SET_DOUBLE_VAL_ALIGN(payload, &dv); -#else - *((double *)payload) = pVariant->dKey; -#endif - } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL; - return 0; - } - -#ifdef _TD_ARM_32_ - double dv = GET_DOUBLE_VAL(payload); - if (isinf(dv) || isnan(dv) || dv > DBL_MAX || dv < -DBL_MAX) { - return -1; - } -#else - if (isinf(*((double *)payload)) || isnan(*((double *)payload)) || *((double *)payload) > DBL_MAX || - *((double *)payload) < -DBL_MAX) { - return -1; - } -#endif - break; - } - - case TSDB_DATA_TYPE_BINARY: { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *payload = TSDB_DATA_BINARY_NULL; - } else { - if (pVariant->nType != TSDB_DATA_TYPE_BINARY) { - toBinary(pVariant, &payload, &pVariant->nLen); - } else { - strncpy(payload, pVariant->pz, pVariant->nLen); - } - } - break; - } - case TSDB_DATA_TYPE_TIMESTAMP: { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *((int64_t *)payload) = TSDB_DATA_BIGINT_NULL; - } else { - *((int64_t *)payload) = pVariant->i64Key; - } - break; - } - case TSDB_DATA_TYPE_NCHAR: { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *(uint32_t *)payload = TSDB_DATA_NCHAR_NULL; - } else { - if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { - toNchar(pVariant, &payload, &pVariant->nLen); - } else { - wcsncpy((wchar_t *)payload, pVariant->wpz, pVariant->nLen); - } - } - break; - } - } - - return 0; -} - -/* - * In variant, bool/smallint/tinyint/int/bigint share the same attribution of - * structure, also ignore the convert the type required - * - * It is actually the bigint/binary/bool/nchar type transfer - */ -int32_t tVariantTypeSetType(tVariant *pVariant, char type) { - if (pVariant == NULL || pVariant->nType == 0) { // value is not set - return 0; - } - - switch (type) { - case TSDB_DATA_TYPE_BOOL: { // bool - if (convertToBool(pVariant, &pVariant->i64Key) < 0) { - return -1; - } - - pVariant->nType = type; - break; - } - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: { - convertToInteger(pVariant, &(pVariant->i64Key), type, INT64_MIN, INT64_MAX, true); - pVariant->nType = TSDB_DATA_TYPE_BIGINT; - break; - } - case TSDB_DATA_TYPE_FLOAT: - case TSDB_DATA_TYPE_DOUBLE: { - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - errno = 0; - double v = strtod(pVariant->pz, NULL); - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - free(pVariant->pz); - return -1; - } - - free(pVariant->pz); - pVariant->dKey = v; - } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - errno = 0; - double v = wcstod(pVariant->wpz, NULL); - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - free(pVariant->pz); - return -1; - } - - free(pVariant->pz); - pVariant->dKey = v; - } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - pVariant->dKey = pVariant->i64Key; - } - - pVariant->nType = TSDB_DATA_TYPE_DOUBLE; - break; - } - case TSDB_DATA_TYPE_BINARY: { - if (pVariant->nType != TSDB_DATA_TYPE_BINARY) { - toBinary(pVariant, &pVariant->pz, &pVariant->nLen); - } - pVariant->nType = type; - break; - } - case TSDB_DATA_TYPE_NCHAR: { - if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { - toNchar(pVariant, &pVariant->pz, &pVariant->nLen); - } - pVariant->nType = type; - break; - } - } - - return 0; -} - bool isNull(const char *val, int32_t type) { switch (type) { case TSDB_DATA_TYPE_BOOL: @@ -976,21 +153,21 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { break; } case TSDB_DATA_TYPE_FLOAT: { - #ifdef _TD_ARM_32_ +#ifdef _TD_ARM_32_ float fv = GET_FLOAT_VAL(src); SET_FLOAT_VAL_ALIGN(val, &fv); - #else +#else *((float *)val) = GET_FLOAT_VAL(src); - #endif +#endif break; }; case TSDB_DATA_TYPE_DOUBLE: { - #ifdef _TD_ARM_32_ +#ifdef _TD_ARM_32_ double dv = GET_DOUBLE_VAL(src); SET_DOUBLE_VAL_ALIGN(val, &dv); - #else +#else *((double *)val) = GET_DOUBLE_VAL(src); - #endif +#endif break; }; case TSDB_DATA_TYPE_TIMESTAMP: @@ -1024,13 +201,13 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size) { char tmpBuf[4096] = {0}; - + switch (type) { case TSDB_DATA_TYPE_INT: { SWAP(*(int32_t *)(pLeft), *(int32_t *)(pRight), int32_t); break; } - + case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: { SWAP(*(int64_t *)(pLeft), *(int64_t *)(pRight), int64_t); @@ -1044,18 +221,18 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size) { SWAP(*(int16_t *)(pLeft), *(int16_t *)(pRight), int16_t); break; } - + case TSDB_DATA_TYPE_FLOAT: { SWAP(*(float *)(pLeft), *(float *)(pRight), float); break; } - + case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: { SWAP(*(int8_t *)(pLeft), *(int8_t *)(pRight), int8_t); break; } - + default: { assert(size <= 4096); memcpy(tmpBuf, pLeft, size); @@ -1064,4 +241,4 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size) { break; } } -} +} \ No newline at end of file diff --git a/src/vnode/detail/src/vnodeSupertableQuery.c b/src/vnode/detail/src/vnodeSupertableQuery.c index 74f96aa1a8..038577bd8d 100644 --- a/src/vnode/detail/src/vnodeSupertableQuery.c +++ b/src/vnode/detail/src/vnodeSupertableQuery.c @@ -726,7 +726,7 @@ static int32_t mgmtFilterMeterByIndex(STabObj* pMetric, tQueryResultset* pRes, c .setupInfoFn = (__do_filter_suppl_fn_t)filterPrepare, .pExtInfo = &s}; - tSQLBinaryExprTraverse(pExpr, pMetric->pSkipList, pRes, &supp); +// tSQLBinaryExprTraverse(pExpr, pMetric->pSkipList, pRes, &supp); tSQLBinaryExprDestroy(&pExpr, tSQLListTraverseDestroyInfo); } -- GitLab