diff --git a/include/common/common.h b/include/common/common.h new file mode 100644 index 0000000000..fb66902019 --- /dev/null +++ b/include/common/common.h @@ -0,0 +1,39 @@ +/* + * 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_COMMON_H +#define TDENGINE_COMMON_H + +#include "taosdef.h" + +typedef struct STimeWindow { + TSKEY skey; + TSKEY ekey; +} STimeWindow; + +typedef struct { + int32_t dataLen; + char name[TSDB_TABLE_FNAME_LEN]; + char *data; +} STagData; + +typedef struct SSchema { + uint8_t type; + char name[TSDB_COL_NAME_LEN]; + int16_t colId; + int16_t bytes; +} SSchema; + +#endif // TDENGINE_COMMON_H diff --git a/include/client/taos.h b/include/common/taos.h similarity index 97% rename from include/client/taos.h rename to include/common/taos.h index edb1552b81..6fa30737e7 100644 --- a/include/client/taos.h +++ b/include/common/taos.h @@ -172,10 +172,6 @@ DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList); DLL_EXPORT int taos_insert_lines(TAOS* taos, char* lines[], int numLines); -DLL_EXPORT int taos_insert_telnet_lines(TAOS* taos, char* lines[], int numLines); - -DLL_EXPORT int taos_insert_json_payload(TAOS* taos, char* payload); - #ifdef __cplusplus } #endif diff --git a/include/common/taosdef.h b/include/common/taosdef.h index bae3dcf5e6..9b2bb89793 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -28,28 +28,28 @@ extern "C" { #define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX)) typedef enum { - TAOS_QTYPE_RPC = 0, - TAOS_QTYPE_FWD = 1, - TAOS_QTYPE_WAL = 2, - TAOS_QTYPE_CQ = 3, - TAOS_QTYPE_QUERY = 4 + TAOS_QTYPE_RPC = 1, + TAOS_QTYPE_FWD = 2, + TAOS_QTYPE_WAL = 3, + TAOS_QTYPE_CQ = 4, + TAOS_QTYPE_QUERY = 5 } EQType; typedef enum { - TSDB_SUPER_TABLE = 0, // super table - TSDB_CHILD_TABLE = 1, // table created from super table - TSDB_NORMAL_TABLE = 2, // ordinary table - TSDB_STREAM_TABLE = 3, // table created from stream computing - TSDB_TEMP_TABLE = 4, // temp table created by nest query - TSDB_TABLE_MAX = 5 + TSDB_SUPER_TABLE = 1, // super table + TSDB_CHILD_TABLE = 2, // table created from super table + TSDB_NORMAL_TABLE = 3, // ordinary table + TSDB_STREAM_TABLE = 4, // table created from stream computing + TSDB_TEMP_TABLE = 5, // temp table created by nest query + TSDB_TABLE_MAX = 6 } ETableType; typedef enum { - TSDB_MOD_MNODE = 0, - TSDB_MOD_HTTP = 1, - TSDB_MOD_MONITOR = 2, - TSDB_MOD_MQTT = 3, - TSDB_MOD_MAX = 4 + TSDB_MOD_MNODE = 1, + TSDB_MOD_HTTP = 2, + TSDB_MOD_MONITOR = 3, + TSDB_MOD_MQTT = 4, + TSDB_MOD_MAX = 5 } EModuleType; typedef enum { diff --git a/include/common/tname.h b/include/common/tname.h index 5809d09b15..18526f54d4 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -13,108 +13,25 @@ * along with this program. If not, see . */ -#ifndef _TD_COMMON_NAME_H_ -#define _TD_COMMON_NAME_H_ - -#include "os.h" -#include "taosmsg.h" -#include "ttoken.h" -#include "tvariant.h" - -typedef struct SDataStatis { - int16_t colId; - int64_t sum; - int64_t max; - int64_t min; - int16_t maxIndex; - int16_t minIndex; - int16_t numOfNull; -} SDataStatis; - -typedef struct SColumnInfoData { - SColumnInfo info; - char* pData; // the corresponding block data in memory -} SColumnInfoData; - -typedef struct SResPair { - TSKEY key; - double avg; -} SResPair; - -// the structure for sql function in select clause -typedef struct SSqlExpr { - char aliasName[TSDB_COL_NAME_LEN]; // as aliasName - char token[TSDB_COL_NAME_LEN]; // original token - SColIndex colInfo; - uint64_t uid; // table uid, todo refactor use the pointer - - int16_t functionId; // function id in aAgg array - - int16_t resType; // return value type - int16_t resBytes; // length of return value - int32_t interBytes; // inter result buffer size - - int16_t colType; // table column type - int16_t colBytes; // table column bytes - - int16_t numOfParams; // argument value of each function - tVariant param[3]; // parameters are not more than 3 - int32_t offset; // sub result column value of arithmetic expression. - int16_t resColId; // result column id - - SColumnFilterList flist; -} SSqlExpr; - -typedef struct SExprInfo { - SSqlExpr base; - struct tExprNode *pExpr; -} SExprInfo; +#ifndef TDENGINE_TNAME_H +#define TDENGINE_TNAME_H #define TSDB_DB_NAME_T 1 #define TSDB_TABLE_NAME_T 2 -#define T_NAME_ACCT 0x1u -#define T_NAME_DB 0x2u -#define T_NAME_TABLE 0x4u +#define T_NAME_ACCT 0x1u +#define T_NAME_DB 0x2u +#define T_NAME_TABLE 0x4u typedef struct SName { uint8_t type; //db_name_t, table_name_t - char acctId[TSDB_ACCT_ID_LEN]; - char dbname[TSDB_DB_NAME_LEN]; - char tname[TSDB_TABLE_NAME_LEN]; + char acctId[TSDB_ACCT_ID_LEN]; + char dbname[TSDB_DB_NAME_LEN]; + char tname[TSDB_TABLE_NAME_LEN]; } SName; -void extractTableName(const char *tableId, char *name); - -char* extractDBName(const char *tableId, char *name); - -size_t tableIdPrefix(const char* name, char* prefix, int32_t len); - -void extractTableNameFromToken(SStrToken *pToken, SStrToken* pTable); - -SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const char* name); - -bool tscValidateTableNameLength(size_t len); - -SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFilters); - -SSchema* tGetTbnameColumnSchema(); - -/** - * check if the schema is valid or not, including following aspects: - * 1. number of columns - * 2. column types - * 3. column length - * 4. column names - * 5. total length - * - * @param pSchema - * @param numOfCols - * @return - */ -bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); - int32_t tNameExtractFullName(const SName* name, char* dst); + int32_t tNameLen(const SName* name); SName* tNameDup(const SName* name); @@ -124,6 +41,7 @@ bool tIsValidName(const SName* name); const char* tNameGetTableName(const SName* name); int32_t tNameGetDbName(const SName* name, char* dst); + int32_t tNameGetFullDbName(const SName* name, char* dst); bool tNameIsEmpty(const SName* name); @@ -134,6 +52,8 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type); int32_t tNameSetAcctId(SName* dst, const char* acct); -int32_t tNameSetDbName(SName* dst, const char* acct, SStrToken* dbToken); +#if 0 +int32_t tNameSetDbName(SName* dst, const char* acct, SToken* dbToken); +#endif -#endif /*_TD_COMMON_NAME_H_*/ +#endif // TDENGINE_TNAME_H diff --git a/include/common/ttype.h b/include/common/ttypes.h similarity index 85% rename from include/common/ttype.h rename to include/common/ttypes.h index 941ad7ae84..6fe6e11d05 100644 --- a/include/common/ttype.h +++ b/include/common/ttypes.h @@ -1,5 +1,5 @@ -#ifndef _TD_COMMON_TYPE_H_ -#define _TD_COMMON_TYPE_H_ +#ifndef TDENGINE_TTYPE_H +#define TDENGINE_TTYPE_H #ifdef __cplusplus extern "C" { @@ -7,6 +7,43 @@ extern "C" { #include "taosdef.h" +// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR +typedef int32_t VarDataOffsetT; +typedef int16_t VarDataLenT; // maxVarDataLen: 32767 +typedef uint16_t TDRowLenT; // not including overhead: 0 ~ 65535 +typedef uint32_t TDRowTLenT; // total length, including overhead + +typedef struct tstr { + VarDataLenT len; + char data[]; +} tstr; + +#pragma pack(push, 1) +typedef struct { + VarDataLenT len; + uint8_t data; +} SBinaryNullT; + +typedef struct { + VarDataLenT len; + uint32_t data; +} SNCharNullT; +#pragma pack(pop) + +#define VARSTR_HEADER_SIZE sizeof(VarDataLenT) + +#define varDataLen(v) ((VarDataLenT *)(v))[0] +#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v)) +#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE)) +#define varDataCopy(dst, v) memcpy((dst), (void*) (v), varDataTLen(v)) +#define varDataLenByData(v) (*(VarDataLenT *)(((char*)(v)) - VARSTR_HEADER_SIZE)) +#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT) (_len)) +#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR)) + +#define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0])) +#define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v)) + + // this data type is internally used only in 'in' query to hold the values #define TSDB_DATA_TYPE_POINTER_ARRAY (1000) #define TSDB_DATA_TYPE_VALUE_ARRAY (1001) @@ -168,7 +205,6 @@ void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type); void* getDataMin(int32_t type); void* getDataMax(int32_t type); -int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned); #define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL) @@ -176,4 +212,4 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo } #endif -#endif /*_TD_COMMON_TYPE_H_*/ +#endif // TDENGINE_TTYPE_H diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index de37807cf6..1af3e16f20 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -20,6 +20,90 @@ extern "C" { #endif +#include "os.h" +#include "thash.h" +#include "tarray.h" +#include "taosdef.h" +#include "transport.h" +#include "common.h" + +struct SCatalog; + +typedef struct SMetaReq { + char clusterId[TSDB_CLUSTER_ID_LEN]; + SArray *pTableName; // table full name + SArray *pVgroup; // vgroup id + SArray *pUdf; // udf name + bool qNodeEpset; // valid qnode +} SMetaReq; + +typedef struct SMetaData { + SArray *pTableMeta; // tableMeta + SArray *pVgroupInfo; // vgroupInfo list + SArray *pUdfList; // udf info list + SEpSet *pEpSet; // qnode epset list +} SMetaData; + +typedef struct STableComInfo { + uint8_t numOfTags; // the number of tags in schema + uint8_t precision; // the number of precision + int16_t numOfColumns; // the number of columns + int32_t rowSize; // row size of the schema +} STableComInfo; + +/* + * ASSERT(sizeof(SCTableMeta) == 24) + * ASSERT(tableType == TSDB_CHILD_TABLE) + * The cached child table meta info. For each child table, 24 bytes are required to keep the essential table info. + */ +typedef struct SCTableMeta { + int32_t vgId:24; + int8_t tableType; + uint32_t tid; + uint64_t uid; + uint64_t suid; +} SCTableMeta; + +/* + * Note that the first 24 bytes of STableMeta are identical to SCTableMeta, it is safe to cast a STableMeta to be a SCTableMeta. + */ +typedef struct STableMeta { + int32_t vgId:24; + int8_t tableType; + uint32_t tid; + uint64_t uid; + uint64_t suid; + // if the table is TSDB_CHILD_TABLE, the following information is acquired from the corresponding super table meta info + int16_t sversion; + int16_t tversion; + STableComInfo tableInfo; + SSchema schema[]; +} STableMeta; + +/** + * Catalog service object, which is utilized to hold tableMeta (meta/vgroupInfo/udfInfo) at the client-side. + * There is ONLY one SCatalog object for one process space, and this function returns a singleton. + * @param pMgmtEps + * @return + */ +struct SCatalog* getCatalogHandle(const SEpSet* pMgmtEps); + +/** + * Get the required meta data from mnode. + * Note that this is a synchronized API and is also thread-safety. + * @param pCatalog + * @param pMetaReq + * @param pMetaData + * @return + */ +int32_t catalogGetMetaData(struct SCatalog* pCatalog, const SMetaReq* pMetaReq, SMetaData* pMetaData); + +/** + * Destroy catalog service handle + * @param pCatalog + */ +void destroyCatalog(struct SCatalog* pCatalog); + #ifdef __cplusplus } #endif diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 15416724c6..c3c7d740f7 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -20,6 +20,170 @@ extern "C" { #endif +typedef void* qinfo_t; + +/** + * create the qinfo object according to QueryTableMsg + * @param tsdb + * @param pQueryTableMsg + * @param qinfo + * @return + */ +int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableInfo* pQueryTableMsg, qinfo_t* qinfo, uint64_t qId); + +/** + * the main query execution function, including query on both table and multiple tables, + * which are decided according to the tag or table name query conditions + * + * @param qinfo + * @return + */ +bool qTableQuery(qinfo_t qinfo, uint64_t *qId); + +/** + * Retrieve the produced results information, if current query is not paused or completed, + * this function will be blocked to wait for the query execution completed or paused, + * in which case enough results have been produced already. + * + * @param qinfo + * @return + */ +int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContext); + +/** + * + * Retrieve the actual results to fill the response message payload. + * Note that this function must be executed after qRetrieveQueryResultInfo is invoked. + * + * @param qinfo qinfo object + * @param pRsp response message + * @param contLen payload length + * @return + */ +int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec); + +/** + * return the transporter context (RPC) + * @param qinfo + * @return + */ +void* qGetResultRetrieveMsg(qinfo_t qinfo); + +/** + * kill the ongoing query and free the query handle and corresponding resources automatically + * @param qinfo qhandle + * @return + */ +int32_t qKillQuery(qinfo_t qinfo); + +/** + * return whether query is completed or not + * @param qinfo + * @return + */ +int32_t qIsQueryCompleted(qinfo_t qinfo); + +/** + * destroy query info structure + * @param qHandle + */ +void qDestroyQueryInfo(qinfo_t qHandle); + +/** + * Get the queried table uid + * @param qHandle + * @return + */ +int64_t qGetQueriedTableUid(qinfo_t qHandle); + +/** + * Extract the qualified table id list, and than pass them to the TSDB driver to load the required table data blocks. + * + * @param iter the table iterator to traverse all tables belongs to a super table, or an invert index + * @return + */ +int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t tagCondLen, SArray* pTableIdList); + +/** + * Create the table group according to the group by tags info + * @param pTableIdList + * @param skey + * @param groupInfo + * @param groupByIndex + * @param numOfIndex + * @return + */ +int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGroupInfo groupInfo, SColIndex* groupByIndex, int32_t numOfIndex); + +/** + * Update the table id list of a given query. + * @param uid child table uid + * @param type operation type: ADD|DROP + * @return + */ +int32_t qUpdateQueriedTableIdList(qinfo_t qinfo, int64_t uid, int32_t type); + +//================================================================================================ +// query handle management +/** + * Query handle mgmt object + * @param vgId + * @return + */ +void* qOpenQueryMgmt(int32_t vgId); + +/** + * broadcast the close information and wait for all query stop. + * @param pExecutor + */ +void qQueryMgmtNotifyClosed(void* pExecutor); + +/** + * Re-open the query handle management module when opening the vnode again. + * @param pExecutor + */ +void qQueryMgmtReOpen(void *pExecutor); + +/** + * Close query mgmt and clean up resources. + * @param pExecutor + */ +void qCleanupQueryMgmt(void* pExecutor); + +/** + * Add the query into the query mgmt object + * @param pMgmt + * @param qId + * @param qInfo + * @return + */ +void** qRegisterQInfo(void* pMgmt, uint64_t qId, void *qInfo); + +/** + * acquire the query handle according to the key from query mgmt object. + * @param pMgmt + * @param key + * @return + */ +void** qAcquireQInfo(void* pMgmt, uint64_t key); + +/** + * release the query handle and decrease the reference count in cache + * @param pMgmt + * @param pQInfo + * @param freeHandle + * @return + */ +void** qReleaseQInfo(void* pMgmt, void* pQInfo); + +/** + * De-register the query handle from the management module and free it immediately. + * @param pMgmt + * @param pQInfo + * @return + */ +void** qDeregisterQInfo(void* pMgmt, void* pQInfo); + #ifdef __cplusplus } #endif diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 082dd4bcdd..4890dd674a 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -20,6 +20,192 @@ extern "C" { #endif +#include "catalog.h" +#include "common.h" +#include "tname.h" + +typedef struct SInterval { + int32_t tz; // query client timezone + char intervalUnit; + char slidingUnit; + char offsetUnit; + int64_t interval; + int64_t sliding; + int64_t offset; +} SInterval; + +typedef struct SSessionWindow { + int64_t gap; // gap between two session window(in microseconds) + int32_t primaryColId; // primary timestamp column +} SSessionWindow; + +typedef struct SGroupbyExpr { + int16_t tableIndex; + SArray* columnInfo; // SArray, group by columns information + int16_t orderIndex; // order by column index + int16_t orderType; // order by type: asc/desc +} SGroupbyExpr; + +typedef struct SField { + char name[TSDB_COL_NAME_LEN]; + uint8_t type; + int16_t bytes; +} SField; + +typedef struct SFieldInfo { + int16_t numOfOutput; // number of column in result + SField *final; + SArray *internalField; // SArray +} SFieldInfo; + +typedef struct SLimit { + int64_t limit; + int64_t offset; +} SLimit; + +typedef struct SOrder { + uint32_t order; + int32_t orderColId; +} SOrder; + +typedef struct SCond { + uint64_t uid; + int32_t len; // length of tag query condition data + char * cond; +} SCond; + +typedef struct SJoinNode { + uint64_t uid; + int16_t tagColId; + SArray* tsJoin; + SArray* tagJoin; +} SJoinNode; + +typedef struct SJoinInfo { + bool hasJoin; + SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM]; +} SJoinInfo; + +typedef struct STagCond { + int16_t relType; // relation between tbname list and query condition, including : TK_AND or TK_OR + SCond tbnameCond; // tbname query condition, only support tbname query condition on one table + SJoinInfo joinInfo; // join condition, only support two tables join currently + SArray *pCond; // for different table, the query condition must be seperated +} STagCond; + +typedef struct STableMetaInfo { + STableMeta *pTableMeta; // table meta, cached in client side and acquired by name + uint32_t tableMetaSize; + size_t tableMetaCapacity; + SVgroupsInfo *vgroupList; + SArray *pVgroupTables; // SArray + + /* + * 1. keep the vgroup index during the multi-vnode super table projection query + * 2. keep the vgroup index for multi-vnode insertion + */ + int32_t vgroupIndex; + SName name; + char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql + SArray *tagColList; // SArray, involved tag columns +} STableMetaInfo; + +typedef struct SQueryStmtInfo { + int16_t command; // the command may be different for each subclause, so keep it seperately. + uint32_t type; // query/insert type + STimeWindow window; // the whole query time window + SInterval interval; // tumble time window + SSessionWindow sessionWindow; // session time window + SGroupbyExpr groupbyExpr; // groupby tags info + SArray * colList; // SArray + SFieldInfo fieldsInfo; + SArray * exprList; // SArray + SArray * exprList1; // final exprlist in case of arithmetic expression exists + SLimit limit; + SLimit slimit; + STagCond tagCond; + SArray * colCond; + SOrder order; + int16_t numOfTables; + int16_t curTableIdx; + STableMetaInfo **pTableMetaInfo; + struct STSBuf *tsBuf; + + int16_t fillType; // final result fill type + int64_t * fillVal; // default value for fill + int32_t numOfFillVal; // fill value size + + char * msg; // pointer to the pCmd->payload to keep error message temporarily + int64_t clauseLimit; // limit for current sub clause + + int64_t prjOffset; // offset value in the original sql expression, only applied at client side + int64_t vgroupLimit; // table limit in case of super table projection query + global order + limit + + int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX + bool distinct; // distinct tag or not + bool onlyHasTagCond; + int32_t bufLen; + char* buf; + SArray *pUdfInfo; + + struct SQueryStmtInfo *sibling; // sibling + SArray *pUpstream; // SArray + struct SQueryStmtInfo *pDownstream; + int32_t havingFieldNum; + bool stableQuery; + bool groupbyColumn; + bool simpleAgg; + bool arithmeticOnAgg; + bool projectionQuery; + bool hasFilter; + bool onlyTagQuery; + bool orderProjectQuery; + bool stateWindow; + bool globalMerge; + bool multigroupResult; +} SQueryStmtInfo; + +struct SInsertStmtInfo; + +/** + * True will be returned if the input sql string is insert, false otherwise. + * @param pStr sql string + * @param length length of the sql string + * @return + */ +bool qIsInsertSql(const char* pStr, size_t length); + +/** + * Parse the sql statement and then return the SQueryStmtInfo as the result of bounded AST. + * @param pSql sql string + * @param length length of the sql string + * @param id operator id, generated by uuid generator + * @param msg extended error message if exists. + * @return error code + */ +int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo** pQueryInfo, int64_t id, char* msg); + +/** + * Parse the insert sql statement. + * @param pStr sql string + * @param length length of the sql string + * @param pInsertParam data in binary format to submit to vnode directly. + * @param id operator id, generated by uuid generator. + * @param msg extended error message if exists to help avoid the problem in sql statement. + * @return + */ +int32_t qParseInsertSql(const char* pStr, size_t length, struct SInsertStmtInfo** pInsertInfo, int64_t id, char* msg); + +/** + * Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that + * involved in the subscribe procedure. + * @param pSql + * @param length + * @param pConvertSql + * @return + */ +int32_t qParserConvertSql(const char* pStr, size_t length, char** pConvertSql); + #ifdef __cplusplus } #endif diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 6de7a59653..cbd9b6f89e 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -20,6 +20,96 @@ extern "C" { #endif +#define QUERY_TYPE_MERGE 1 +#define QUERY_TYPE_PARTIAL 2 + +struct SEpSet; +struct SQueryNode; +struct SQueryPhyNode; +struct SQueryStmtInfo; + +typedef struct SSubquery { + int64_t queryId; // the subquery id created by qnode + int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL + int32_t level; // the execution level of current subquery, starting from 0. + SArray *pUpstream; // the upstream,from which to fetch the result + struct SQueryPhyNode *pNode; // physical plan of current subquery +} SSubquery; + +typedef struct SQueryJob { + SArray **pSubqueries; + int32_t numOfLevels; + int32_t currentLevel; +} SQueryJob; + + +/** + * Optimize the query execution plan, currently not implement yet. + * @param pQueryNode + * @return + */ +int32_t qOptimizeQueryPlan(struct SQueryNode* pQueryNode); + +/** + * Create the query plan according to the bound AST, which is in the form of pQueryInfo + * @param pQueryInfo + * @param pQueryNode + * @return + */ +int32_t qCreateQueryPlan(const struct SQueryStmtInfo* pQueryInfo, struct SQueryNode* pQueryNode); + +/** + * Convert the query plan to string, in order to display it in the shell. + * @param pQueryNode + * @return + */ +int32_t qQueryPlanToString(struct SQueryNode* pQueryNode, char** str); + +/** + * Restore the SQL statement according to the logic query plan. + * @param pQueryNode + * @param sql + * @return + */ +int32_t qQueryPlanToSql(struct SQueryNode* pQueryNode, char** sql); + +/** + * Create the physical plan for the query, according to the logic plan. + * @param pQueryNode + * @param pPhyNode + * @return + */ +int32_t qCreatePhysicalPlan(struct SQueryNode* pQueryNode, struct SEpSet* pQnode, struct SQueryPhyNode *pPhyNode); + +/** + * Convert to physical plan to string to enable to print it out in the shell. + * @param pPhyNode + * @param str + * @return + */ +int32_t qPhyPlanToString(struct SQueryPhyNode *pPhyNode, char** str); + +/** + * Destroy the query plan object. + * @return + */ +void* qDestroyQueryPlan(struct SQueryNode* pQueryNode); + +/** + * Destroy the physical plan. + * @param pQueryPhyNode + * @return + */ +void* qDestroyQueryPhyPlan(struct SQueryPhyNode* pQueryPhyNode); + +/** + * Create the query job from the physical execution plan + * @param pPhyNode + * @param pJob + * @return + */ +int32_t qCreateQueryJob(const struct SQueryPhyNode* pPhyNode, struct SQueryJob** pJob); + #ifdef __cplusplus } #endif diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index 205d88970f..d9653046cf 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -20,6 +20,32 @@ extern "C" { #endif +struct SQueryJob; + +/** + * Process the query job, generated according to the query physical plan. + * This is a synchronized API, and is also thread-safety. + * @param pJob + * @return + */ +int32_t qProcessQueryJob(struct SQueryJob* pJob); + +/** + * The SSqlObj should not be here???? + * @param pSql + * @param pVgroupId + * @param pRetVgroupId + * @return + */ +//SArray* qGetInvolvedVgroupIdList(struct SSqlObj* pSql, SArray* pVgroupId, SArray* pRetVgroupId); + +/** + * Cancel query job + * @param pJob + * @return + */ +int32_t qKillQueryJob(struct SQueryJob* pJob); + #ifdef __cplusplus } #endif diff --git a/include/libs/transport/transport.h b/include/libs/transport/transport.h index 2733108825..e7660e4d66 100644 --- a/include/libs/transport/transport.h +++ b/include/libs/transport/transport.h @@ -20,6 +20,24 @@ extern "C" { #endif +typedef void* SEpSet; + +typedef struct SEpAddr { + char fqdn[TSDB_FQDN_LEN]; + uint16_t port; +} SEpAddr; + +typedef struct SVgroup { + int32_t vgId; + int8_t numOfEps; + SEpAddr epAddr[TSDB_MAX_REPLICA]; +} SVgroup; + +typedef struct SVgroupsInfo { + int32_t numOfVgroups; + SVgroup vgroups[]; +} SVgroupsInfo; + #ifdef __cplusplus } #endif diff --git a/include/os/os.h b/include/os/os.h index 447df9d65c..e5731c79c7 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -39,6 +39,11 @@ extern "C" { #include #include #include +#include +#include +#include +#include +#include #include "osAtomic.h" #include "osDef.h" diff --git a/include/util/hashfunc.h b/include/util/hashfunc.h deleted file mode 100644 index 3992d8b02e..0000000000 --- a/include/util/hashfunc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 _TD_UTIL_HASHFUNC_H -#define _TD_UTIL_HASHFUNC_H - -#include "os.h" - -typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); - -typedef int32_t (*_equal_fn_t)(const void *a, const void *b, size_t sz); - -/** - * murmur hash algorithm - * @key usually string - * @len key length - * @seed hash seed - * @out an int32 value - */ -uint32_t MurmurHash3_32(const char *key, uint32_t len); - -/** - * - * @param key - * @param len - * @return - */ -uint32_t taosIntHash_32(const char *key, uint32_t len); -uint32_t taosIntHash_64(const char *key, uint32_t len); - - -int32_t taosFloatEqual(const void *a, const void *b, size_t sz); -int32_t taosDoubleEqual(const void *a,const void *b, size_t sz); - -_hash_fn_t taosGetDefaultHashFunction(int32_t type); - -_equal_fn_t taosGetDefaultEqualFunction(int32_t type); - -#endif /*_TD_UTIL_HASHFUNC_H*/ diff --git a/include/util/tcache.h b/include/util/tcache.h index f0bf78cd92..11f9044d28 100644 --- a/include/util/tcache.h +++ b/include/util/tcache.h @@ -22,7 +22,7 @@ extern "C" { #include "os.h" #include "tlockfree.h" -#include "hash.h" +#include "thash.h" #if defined(_TD_ARM_32) #define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT diff --git a/include/util/hash.h b/include/util/thash.h similarity index 69% rename from include/util/hash.h rename to include/util/thash.h index 5c723be106..d5038802c0 100644 --- a/include/util/hash.h +++ b/include/util/thash.h @@ -13,30 +13,53 @@ * along with this program. If not, see . */ -#ifndef _TD_UTIL_HASH_H -#define _TD_UTIL_HASH_H +#ifndef TDENGINE_HASH_H +#define TDENGINE_HASH_H #ifdef __cplusplus extern "C" { #endif #include "tarray.h" -#include "hashfunc.h" #include "tlockfree.h" +typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); +typedef int32_t (*_equal_fn_t)(const void*, const void*, uint32_t len); +typedef void (*_hash_before_fn_t)(void *); +typedef void (*_hash_free_fn_t)(void *); + #define HASH_MAX_CAPACITY (1024 * 1024 * 16) #define HASH_DEFAULT_LOAD_FACTOR (0.75) + #define HASH_INDEX(v, c) ((v) & ((c)-1)) -typedef void (*_hash_free_fn_t)(void *param); +/** + * murmur hash algorithm + * @key usually string + * @len key length + * @seed hash seed + * @out an int32 value + */ +uint32_t MurmurHash3_32(const char *key, uint32_t len); + +/** + * + * @param key + * @param len + * @return + */ +uint32_t taosIntHash_32(const char *key, uint32_t len); +uint32_t taosIntHash_64(const char *key, uint32_t len); + +_hash_fn_t taosGetDefaultHashFunction(int32_t type); typedef struct SHashNode { struct SHashNode *next; uint32_t hashVal; // the hash value of key uint32_t dataLen; // length of data uint32_t keyLen; // length of the key + uint16_t count; // reference count int8_t removed; // flag to indicate removed - int8_t count; // reference count char data[]; } SHashNode; @@ -57,11 +80,13 @@ typedef struct SHashEntry { typedef struct SHashObj { SHashEntry **hashList; - size_t capacity; // number of slots - size_t size; // number of elements in hash table + uint32_t capacity; // number of slots + uint32_t size; // number of elements in hash table + _hash_fn_t hashFp; // hash function _hash_free_fn_t freeFp; // hash node free callback function - _equal_fn_t equalFp; // equal function + _equal_fn_t equalFp; // equal function + _hash_before_fn_t callbackFp; // function invoked before return the value to caller SRWLatch lock; // read-write spin lock SHashLockTypeE type; // lock type @@ -79,15 +104,6 @@ typedef struct SHashObj { */ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTypeE type); - -/** - * set equal func of the hash table - * @param pHashObj - * @param equalFp - * @return - */ -void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp); - /** * return the size of hash table * @param pHashObj @@ -117,26 +133,15 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen); /** - * apply the udf before return the result + * Clone the result to destination buffer * @param pHashObj * @param key * @param keyLen - * @param fp - * @param d + * @param destBuf * @return */ -void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void* d); +void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* destBuf); -/** - * @param pHashObj - * @param key - * @param keyLen - * @param fp - * @param d - * @param sz - * @return - */ -void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz); /** * remove item with the specified key * @param pHashObj @@ -145,37 +150,57 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo */ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen); -int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLen, void* data, size_t dsize); - -int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), void *param); - +/** + * Clear the hash table. + * @param pHashObj + */ void taosHashClear(SHashObj *pHashObj); /** - * clean up hash table + * Clean up hash table and release all allocated resources. * @param handle */ void taosHashCleanup(SHashObj *pHashObj); /** - * + * Get the max overflow link list length * @param pHashObj * @return */ int32_t taosHashGetMaxOverflowLinkLength(const SHashObj *pHashObj); +/** + * Get the hash table size + * @param pHashObj + * @return + */ size_t taosHashGetMemSize(const SHashObj *pHashObj); +/** + * Create the hash table iterator + * @param pHashObj + * @param p + * @return + */ void *taosHashIterate(SHashObj *pHashObj, void *p); +/** + * Cancel the hash table iterator + * @param pHashObj + * @param p + */ void taosHashCancelIterate(SHashObj *pHashObj, void *p); -void *taosHashGetDataKey(SHashObj *pHashObj, void *data); - -uint32_t taosHashGetDataKeyLen(SHashObj *pHashObj, void *data); +/** + * Get the corresponding key information for a given data in hash table + * @param pHashObj + * @param data + * @return + */ +int32_t taosHashGetKey(SHashObj *pHashObj, void *data, void** key, size_t* keyLen); #ifdef __cplusplus } #endif -#endif /*_TD_UTIL_HASH_H*/ +#endif // TDENGINE_HASH_H diff --git a/source/client/src/client.c b/source/client/src/client.c index 6dea4a4e57..77c4aa1b2d 100644 --- a/source/client/src/client.c +++ b/source/client/src/client.c @@ -11,4 +11,11 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +//#include "taos.h" + +//TAOS_RES *taos_query(TAOS *taos, const char *sql) { +// +//} + diff --git a/source/common/src/ttypes.c b/source/common/src/ttypes.c index 08bfc2e9aa..bec8793b72 100644 --- a/source/common/src/ttypes.c +++ b/source/common/src/ttypes.c @@ -12,27 +12,27 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "os.h" -#include "ttype.h" -#include "ttokendef.h" -#include "tscompression.h" +#include "taos.h" +#include "os.h" +#include "ttypes.h" +#include "tcompression.h" const int32_t TYPE_BYTES[15] = { -1, // TSDB_DATA_TYPE_NULL - sizeof(int8_t), // TSDB_DATA_TYPE_BOOL - sizeof(int8_t), // TSDB_DATA_TYPE_TINYINT - sizeof(int16_t), // TSDB_DATA_TYPE_SMALLINT - sizeof(int32_t), // TSDB_DATA_TYPE_INT + CHAR_BYTES, // TSDB_DATA_TYPE_BOOL + CHAR_BYTES, // TSDB_DATA_TYPE_TINYINT + SHORT_BYTES, // TSDB_DATA_TYPE_SMALLINT + INT_BYTES, // TSDB_DATA_TYPE_INT sizeof(int64_t), // TSDB_DATA_TYPE_BIGINT - sizeof(float), // TSDB_DATA_TYPE_FLOAT - sizeof(double), // TSDB_DATA_TYPE_DOUBLE + FLOAT_BYTES, // TSDB_DATA_TYPE_FLOAT + DOUBLE_BYTES, // TSDB_DATA_TYPE_DOUBLE sizeof(VarDataOffsetT), // TSDB_DATA_TYPE_BINARY sizeof(TSKEY), // TSDB_DATA_TYPE_TIMESTAMP sizeof(VarDataOffsetT), // TSDB_DATA_TYPE_NCHAR - sizeof(uint8_t), // TSDB_DATA_TYPE_UTINYINT - sizeof(uint16_t), // TSDB_DATA_TYPE_USMALLINT - sizeof(uint32_t), // TSDB_DATA_TYPE_UINT + CHAR_BYTES, // TSDB_DATA_TYPE_UTINYINT + SHORT_BYTES, // TSDB_DATA_TYPE_USMALLINT + INT_BYTES, // TSDB_DATA_TYPE_UINT sizeof(uint64_t), // TSDB_DATA_TYPE_UBIGINT }; @@ -58,7 +58,7 @@ static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, i *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (data[i] == TSDB_DATA_BOOL_NULL) { @@ -78,7 +78,7 @@ static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) { @@ -100,7 +100,7 @@ static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) { @@ -124,7 +124,7 @@ static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, in *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) { @@ -147,7 +147,7 @@ static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, in *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) { @@ -171,7 +171,7 @@ static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, in *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) { @@ -193,7 +193,7 @@ static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, in *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) { @@ -217,7 +217,7 @@ static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, in *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) { @@ -239,7 +239,7 @@ static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, in *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) { @@ -264,7 +264,7 @@ static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int6 *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if ((*(uint32_t*)&(data[i])) == TSDB_DATA_FLOAT_NULL) { @@ -300,7 +300,7 @@ static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int6 *minIndex = 0; *maxIndex = 0; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if ((*(uint64_t*)&(data[i])) == TSDB_DATA_DOUBLE_NULL) { @@ -330,7 +330,7 @@ static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int6 static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { const char* data = pData; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (isNull(data, TSDB_DATA_TYPE_BINARY)) { @@ -350,7 +350,7 @@ static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, in static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { const char* data = pData; - ASSERT(numOfRow <= INT16_MAX); + assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { if (isNull(data, TSDB_DATA_TYPE_NCHAR)) { @@ -426,7 +426,6 @@ FORCE_INLINE void* getDataMax(int32_t type) { } } - bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_UBIGINT; } @@ -445,6 +444,8 @@ void setVardataNull(void* val, int32_t type) { void setNull(void *val, int32_t type, int32_t bytes) { setNullN(val, type, bytes, 1); } +#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) + void setNullN(void *val, int32_t type, int32_t bytes, int32_t numOfElems) { switch (type) { case TSDB_DATA_TYPE_BOOL: @@ -532,11 +533,6 @@ static uint64_t nullBigIntu = TSDB_DATA_UBIGINT_NULL; static SBinaryNullT nullBinary = {1, TSDB_DATA_BINARY_NULL}; static SNCharNullT nullNchar = {4, TSDB_DATA_NCHAR_NULL}; -// static union { -// tstr str; -// char pad[sizeof(tstr) + 4]; -// } nullBinary = {.str = {.len = 1}}, nullNchar = {.str = {.len = 4}}; - static const void *nullValues[] = { &nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt, &nullFloat, &nullDouble, &nullBinary, &nullBigInt, &nullNchar, @@ -634,6 +630,13 @@ void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type) { } } +#define SWAP(a, b, c) \ + do { \ + typeof(a) __tmp = (a); \ + (a) = (b); \ + (b) = __tmp; \ + } while (0) + void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf) { switch (type) { @@ -679,49 +682,3 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf } } } - -int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned) { - errno = 0; - int32_t ret = 0; - - char* endPtr = NULL; - if (type == TK_FLOAT) { - double v = strtod(z, &endPtr); - if ((errno == ERANGE && v == HUGE_VALF) || isinf(v) || isnan(v)) { - ret = -1; - } else if ((issigned && (v < INT64_MIN || v > INT64_MAX)) || ((!issigned) && (v < 0 || v > UINT64_MAX))) { - ret = -1; - } else { - *value = (int64_t) round(v); - } - - errno = 0; - return ret; - } - - int32_t radix = 10; - if (type == TK_HEX) { - radix = 16; - } else if (type == TK_BIN) { - radix = 2; - } - - // the string may be overflow according to errno - if (!issigned) { - const char *p = z; - while(*p != 0 && *p == ' ') p++; - if (*p != 0 && *p == '-') { return -1;} - - *value = strtoull(z, &endPtr, radix); - } else { - *value = strtoll(z, &endPtr, radix); - } - - // not a valid integer number, return error - if (endPtr - z != n || errno == ERANGE) { - ret = -1; - } - - errno = 0; - return ret; -} diff --git a/source/libs/catalog/CMakeLists.txt b/source/libs/catalog/CMakeLists.txt index ae331bf392..ff3e62700a 100644 --- a/source/libs/catalog/CMakeLists.txt +++ b/source/libs/catalog/CMakeLists.txt @@ -4,4 +4,9 @@ target_include_directories( catalog PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/catalog" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + catalog + PRIVATE os util common transport ) \ No newline at end of file diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index f6f8a61faf..5b50bbff4c 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -20,6 +20,13 @@ extern "C" { #endif +#include "catalog.h" + +typedef struct SCatalog { + void *pMsgSender; // used to send messsage to mnode to fetch necessary metadata + SHashObj *pData; // items cached for each cluster, the hash key is the cluster-id, returned by mgmt node +} SCatalog; + #ifdef __cplusplus } #endif diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 6dea4a4e57..c553e1bfbf 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -11,4 +11,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +#include "catalogInt.h" diff --git a/include/common/tarithoperator.h b/source/libs/executor/inc/tarithoperator.h similarity index 100% rename from include/common/tarithoperator.h rename to source/libs/executor/inc/tarithoperator.h diff --git a/source/libs/executor/src/tarithoperator.h b/source/libs/executor/src/tarithoperator.h new file mode 100644 index 0000000000..e47cb5c1cb --- /dev/null +++ b/source/libs/executor/src/tarithoperator.h @@ -0,0 +1,32 @@ +/* + * 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 _TD_COMMON_QARITHMETICOPERATOR_H_ +#define _TD_COMMON_QARITHMETICOPERATOR_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t leftType, void *right, int32_t numRight, + int32_t rightType, void *output, int32_t order); + +_arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_COMMON_QARITHMETICOPERATOR_H_*/ diff --git a/source/libs/parser/CMakeLists.txt b/source/libs/parser/CMakeLists.txt index e69de29bb2..8f6d8d2880 100644 --- a/source/libs/parser/CMakeLists.txt +++ b/source/libs/parser/CMakeLists.txt @@ -0,0 +1,12 @@ +aux_source_directory(src PARSER_SRC) +add_library(parser ${PARSER_SRC}) +target_include_directories( + parser + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/parser" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + parser + PRIVATE os util common catalog transport +) \ No newline at end of file diff --git a/source/libs/parser/inc/astGenerator.h b/source/libs/parser/inc/astGenerator.h new file mode 100644 index 0000000000..b6d7545f3b --- /dev/null +++ b/source/libs/parser/inc/astGenerator.h @@ -0,0 +1,360 @@ +/* + * 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_ASTGENERATOR_H +#define TDENGINE_ASTGENERATOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ttoken.h" +#include "tvariant.h" +#include "parser.h" + +#define ParseTOKENTYPE SToken + +#define NON_ARITHMEIC_EXPR 0 +#define NORMAL_ARITHMETIC 1 +#define AGG_ARIGHTMEIC 2 + +enum SQL_NODE_TYPE { + SQL_NODE_TABLE_COLUMN= 1, + SQL_NODE_SQLFUNCTION = 2, + SQL_NODE_VALUE = 3, + SQL_NODE_EXPR = 4, +}; + +enum SQL_NODE_FROM_TYPE { + SQL_NODE_FROM_SUBQUERY = 1, + SQL_NODE_FROM_TABLELIST = 2, +}; + +//enum SQL_EXPR_FLAG { +// EXPR_FLAG_TS_ERROR = 1, +// EXPR_FLAG_NS_TIMESTAMP = 2, +// EXPR_FLAG_TIMESTAMP_VAR = 3, +//}; + +extern char tTokenTypeSwitcher[13]; + +#define toTSDBType(x) \ + do { \ + if ((x) >= tListLen(tTokenTypeSwitcher)) { \ + (x) = TSDB_DATA_TYPE_BINARY; \ + } else { \ + (x) = tTokenTypeSwitcher[(x)]; \ + } \ + } while (0) + +#define TPARSER_HAS_TOKEN(_t) ((_t).n > 0) +#define TPARSER_SET_NONE_TOKEN(_t) ((_t).n = 0) + +typedef struct SListItem { + SVariant pVar; + uint8_t sortOrder; +} SListItem; + +typedef struct SIntervalVal { + int32_t token; + SToken interval; + SToken offset; +} SIntervalVal; + +typedef struct SSessionWindowVal { + SToken col; + SToken gap; +} SSessionWindowVal; + +typedef struct SWindowStateVal { + SToken col; +} SWindowStateVal; + +struct SRelationInfo; + +typedef struct SSqlNode { + struct SArray *pSelNodeList; // select clause + struct SRelationInfo *from; // from clause SArray + struct tSqlExpr *pWhere; // where clause [optional] + SArray *pGroupby; // groupby clause, only for tags[optional], SArray + SArray *pSortOrder; // orderby [optional], SArray + SArray *fillType; // fill type[optional], SArray + SIntervalVal interval; // (interval, interval_offset) [optional] + SSessionWindowVal sessionVal; // session window [optional] + SWindowStateVal windowstateVal; // window_state(col) [optional] + SToken sliding; // sliding window [optional] + SLimit limit; // limit offset [optional] + SLimit slimit; // group limit offset [optional] + SToken sqlstr; // sql string in select clause + struct tSqlExpr *pHaving; // having clause [optional] +} SSqlNode; + +typedef struct SRelElementPair { + union { + SToken tableName; + SArray *pSubquery; + }; + + SToken aliasName; +} SRelElementPair; + +typedef struct SRelationInfo { + int32_t type; // nested query|table name list + SArray *list; // SArray +} SRelationInfo; + +typedef struct SCreatedTableInfo { + SToken name; // table name token + SToken stableName; // super table name token , for using clause + SArray *pTagNames; // create by using super table, tag name + SArray *pTagVals; // create by using super table, tag value + char *fullname; // table full name + STagData tagdata; // true tag data, super table full name is in STagData + int8_t igExist; // ignore if exists +} SCreatedTableInfo; + +typedef struct SCreateTableSql { + SToken name; // table name, create table [name] xxx + int8_t type; // create normal table/from super table/ stream + bool existCheck; + + struct { + SArray *pTagColumns; // SArray + SArray *pColumns; // SArray + } colInfo; + + SArray *childTableInfo; // SArray + SSqlNode *pSelect; +} SCreateTableSql; + +typedef struct SAlterTableInfo { + SToken name; + int16_t tableType; + int16_t type; + STagData tagData; + SArray *pAddColumns; // SArray + SArray *varList; // set t=val or: change src dst, SArray +} SAlterTableInfo; + +typedef struct SCreateDbInfo { + SToken dbname; + int32_t replica; + int32_t cacheBlockSize; + int32_t maxTablesPerVnode; + int32_t numOfBlocks; + int32_t daysPerFile; + int32_t minRowsPerBlock; + int32_t maxRowsPerBlock; + int32_t fsyncPeriod; + int64_t commitTime; + int32_t walLevel; + int32_t quorum; + int32_t compressionLevel; + SToken precision; + bool ignoreExists; + int8_t update; + int8_t cachelast; + SArray *keep; + int8_t dbType; + int16_t partitions; +} SCreateDbInfo; + +typedef struct SCreateFuncInfo { + SToken name; + SToken path; + int32_t type; + int32_t bufSize; + SField output; +} SCreateFuncInfo; + +typedef struct SCreateAcctInfo { + int32_t maxUsers; + int32_t maxDbs; + int32_t maxTimeSeries; + int32_t maxStreams; + int32_t maxPointsPerSecond; + int64_t maxStorage; + int64_t maxQueryTime; + int32_t maxConnections; + SToken stat; +} SCreateAcctInfo; + +typedef struct SShowInfo { + uint8_t showType; + SToken prefix; + SToken pattern; +} SShowInfo; + +typedef struct SUserInfo { + SToken user; + SToken passwd; + SToken privilege; + int16_t type; +} SUserInfo; + +typedef struct SMiscInfo { + SArray *a; // SArray + bool existsCheck; + int16_t dbType; + int16_t tableType; + SUserInfo user; + union { + SCreateDbInfo dbOpt; + SCreateAcctInfo acctOpt; + SCreateFuncInfo funcOpt; + SShowInfo showOpt; + SToken id; + }; +} SMiscInfo; + +typedef struct SSqlInfo { + int32_t type; + bool valid; + SArray *list; // todo refactor + char msg[256]; + SArray *funcs; + union { + SCreateTableSql *pCreateTableInfo; + SAlterTableInfo *pAlterInfo; + SMiscInfo *pMiscInfo; + }; +} SSqlInfo; + +typedef struct tSqlExpr { + uint16_t type; // sql node type + uint32_t tokenId; // TK_LE: less than(binary expr) + + // The complete string of the function(col, param), and the function name is kept in exprToken + struct { + SToken operand; + struct SArray *paramList; // function parameters list + } Expr; + + SToken columnName; // table column info + SVariant value; // the use input value + SToken exprToken; // original sql expr string or function name of sql function + struct tSqlExpr *pLeft; // the left child + struct tSqlExpr *pRight; // the 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 + bool distinct; +} tSqlExprItem; + +SArray *tListItemAppend(SArray *pList, SVariant *pVar, uint8_t sortOrder); +SArray *tListItemInsert(SArray *pList, SVariant *pVar, uint8_t sortOrder, int32_t index); +SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrder); + +SRelationInfo *setTableNameList(SRelationInfo *pRelationInfo, SToken *pName, SToken *pAlias); +void * destroyRelationInfo(SRelationInfo *pFromInfo); +SRelationInfo *addSubquery(SRelationInfo *pRelationInfo, SArray *pSub, SToken *pAlias); + +// sql expr leaf node +tSqlExpr *tSqlExprCreateIdValue(SToken *pToken, int32_t optrType); +tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SToken *pFuncToken, SToken *endToken, int32_t optType); +SArray * tAppendFuncName(SArray *pList, SToken *pToken); + +tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType); +tSqlExpr *tSqlExprClone(tSqlExpr *pSrc); +void tSqlExprCompact(tSqlExpr **pExpr); +bool tSqlExprIsLeaf(tSqlExpr *pExpr); +bool tSqlExprIsParentOfLeaf(tSqlExpr *pExpr); +void tSqlExprDestroy(tSqlExpr *pExpr); +SArray * tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SToken *pDistinct, SToken *pToken); +void tSqlExprListDestroy(SArray *pList); + +SSqlNode *tSetQuerySqlNode(SToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, + SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps, + SWindowStateVal *pw, SToken *pSliding, SArray *pFill, SLimit *pLimit, SLimit *pgLimit, tSqlExpr *pHaving); +int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right); + +SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type); + +SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, + int16_t tableTable); +SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken, + SToken *igExists); + +void destroyAllSqlNode(SArray *pSqlNode); +void destroySqlNode(SSqlNode *pSql); +void freeCreateTableInfo(void* p); + +SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, int32_t type); +SArray *setSubclause(SArray *pList, void *pSqlNode); +SArray *appendSelectClause(SArray *pList, void *pSubclause); + +void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists); + +void SqlInfoDestroy(SSqlInfo *pInfo); + +void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...); +void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SToken* pToken, SToken* existsCheck,int16_t dbType,int16_t tableType); +void setShowOptions(SSqlInfo *pInfo, int32_t type, SToken* prefix, SToken* pPatterns); + +void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SToken *pToken, SCreateDbInfo *pDB, SToken *pIgExists); + +void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SToken *pName, SToken *pPwd, SCreateAcctInfo *pAcctInfo); +void setCreateUserSql(SSqlInfo *pInfo, SToken *pName, SToken *pPasswd); +void setKillSql(SSqlInfo *pInfo, int32_t type, SToken *ip); +void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SToken *pName, SToken* pPwd, SToken *pPrivilege); + +void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam); + +void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo); +void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo); + +// prefix show db.tables; +void tSetDbName(SToken *pCpxName, SToken *pDb); + +void tSetColumnInfo(struct SField *pField, SToken *pName, struct SField *pType); +void tSetColumnType(struct SField *pField, SToken *type); + +/** + * The main parse function. + * @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 *); + +/** + * Free the allocated resources in case of failure. + * @param p The parser to be deleted + * @param freeProc Function used to reclaim memory + */ +void ParseFree(void *p, void (*freeProc)(void *)); + +/** + * Allocated callback function. + * @param mallocProc The parser allocator + * @return + */ +void *ParseAlloc(void *(*mallocProc)(size_t)); + +/** + * + * @param str sql string + * @return sql ast + */ +SSqlInfo genAST(const char *str); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_ASTGENERATOR_H diff --git a/source/libs/parser/inc/insertParser.h b/source/libs/parser/inc/insertParser.h new file mode 100644 index 0000000000..49e678cd54 --- /dev/null +++ b/source/libs/parser/inc/insertParser.h @@ -0,0 +1,19 @@ +/* + * 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_INSERTPARSER_H +#define TDENGINE_INSERTPARSER_H + +#endif // TDENGINE_INSERTPARSER_H diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h index 2c76f1bb96..ce1504b4e2 100644 --- a/source/libs/parser/inc/parserInt.h +++ b/source/libs/parser/inc/parserInt.h @@ -20,6 +20,40 @@ extern "C" { #endif +#include "catalog.h" +#include "tname.h" +#include "astGenerator.h" + +struct SSqlNode; + +typedef struct SInsertStmtInfo { + SHashObj *pTableBlockHashList; // data block for each table + SArray *pDataBlocks; // SArray. Merged submit block for each vgroup + int8_t schemaAttached; // denote if submit block is built with table schema or not + uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert + uint32_t insertType; // insert data from [file|sql statement| bound statement] + char *sql; // current sql statement position +} SInsertStmtInfo; + +/** + * Validate the sql info, according to the corresponding metadata info from catalog. + * @param pCatalog + * @param pSqlInfo + * @param pQueryInfo a bounded AST with essential meta data from local buffer or mgmt node + * @param id + * @param msg + * @return + */ +int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQueryStmtInfo* pQueryInfo, int64_t id, char* msg); + +/** + * + * @param pSqlNode + * @param pMetaInfo + * @return + */ +int32_t qParserExtractRequestedMetaInfo(const struct SSqlNode* pSqlNode, SMetaReq* pMetaInfo); + #ifdef __cplusplus } #endif diff --git a/source/libs/parser/inc/parserUtil.h b/source/libs/parser/inc/parserUtil.h new file mode 100644 index 0000000000..4e6af0a901 --- /dev/null +++ b/source/libs/parser/inc/parserUtil.h @@ -0,0 +1,28 @@ +/* + * 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_PARSERUTIL_H +#define TDENGINE_PARSERUTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_PARSERUTIL_H diff --git a/source/libs/parser/inc/ttoken.h b/source/libs/parser/inc/ttoken.h new file mode 100644 index 0000000000..bacabe299e --- /dev/null +++ b/source/libs/parser/inc/ttoken.h @@ -0,0 +1,185 @@ +/* + * 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_TTOKEN_H +#define TDENGINE_TTOKEN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "os.h" +#include "ttokendef.h" + +// used to denote the minimum unite in sql parsing +typedef struct SToken { + uint32_t n; + uint32_t type; + char *z; +} SToken; + +/** + * check if it is a number or not + * @param pToken + * @return + */ +#define isNumber(tk) \ +((tk)->type == TK_INTEGER || (tk)->type == TK_FLOAT || (tk)->type == TK_HEX || (tk)->type == TK_BIN) + +/** + * tokenizer for sql string + * @param z + * @param tokenType + * @return + */ +uint32_t tGetToken(char *z, uint32_t *tokenType); + +/** + * enhanced tokenizer for sql string. + * + * @param str + * @param i + * @param isPrevOptr + * @return + */ +SToken tStrGetToken(char *str, int32_t *i, bool isPrevOptr); + +/** + * check if it is a keyword or not + * @param z + * @param len + * @return + */ +bool taosIsKeyWordToken(const char *z, int32_t len); + +/** + * check if it is a token or not + * @param pToken + * @return token type, if it is not a number, TK_ILLEGAL will return + */ +static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { + const char* z = pToken->z; + int32_t type = TK_ILLEGAL; + + uint32_t i = 0; + for(; i < pToken->n; ++i) { + switch (z[i]) { + case '+': + case '-': { + break; + } + + case '.': { + /* + * handle the the float number with out integer part + * .123 + * .123e4 + */ + if (!isdigit(z[i+1])) { + return TK_ILLEGAL; + } + + for (i += 2; isdigit(z[i]); i++) { + } + + if ((z[i] == 'e' || z[i] == 'E') && + (isdigit(z[i + 1]) || ((z[i + 1] == '+' || z[i + 1] == '-') && isdigit(z[i + 2])))) { + i += 2; + while (isdigit(z[i])) { + i++; + } + } + + type = TK_FLOAT; + goto _end; + } + + case '0': { + char next = z[i + 1]; + if (next == 'b') { // bin number + type = TK_BIN; + for (i += 2; (z[i] == '0' || z[i] == '1'); ++i) { + } + + goto _end; + } else if (next == 'x') { //hex number + type = TK_HEX; + for (i += 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) { + } + + goto _end; + } + } + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': { + type = TK_INTEGER; + for (; isdigit(z[i]); i++) { + } + + int32_t seg = 0; + while (z[i] == '.' && isdigit(z[i + 1])) { + i += 2; + + while (isdigit(z[i])) { + i++; + } + + seg++; + type = TK_FLOAT; + } + + if (seg > 1) { + return TK_ILLEGAL; + } + + if ((z[i] == 'e' || z[i] == 'E') && + (isdigit(z[i + 1]) || ((z[i + 1] == '+' || z[i + 1] == '-') && isdigit(z[i + 2])))) { + i += 2; + while (isdigit(z[i])) { + i++; + } + + type = TK_FLOAT; + } + + goto _end; + } + default: + return TK_ILLEGAL; + } + } + + _end: + return (i < pToken->n)? TK_ILLEGAL:type; +} + +void taosCleanupKeywordsTable(); + +SToken tscReplaceStrToken(char **str, SToken *token, const char* newToken); + +SToken taosTokenDup(SToken* pToken, char* buf, int32_t len); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_TTOKEN_H diff --git a/source/libs/parser/inc/ttokendef.h b/source/libs/parser/inc/ttokendef.h new file mode 100644 index 0000000000..9b0ad2cf13 --- /dev/null +++ b/source/libs/parser/inc/ttokendef.h @@ -0,0 +1,228 @@ +/* + * 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_TTOKENDEF_H +#define TDENGINE_TTOKENDEF_H + +#define TK_ID 1 +#define TK_BOOL 2 +#define TK_TINYINT 3 +#define TK_SMALLINT 4 +#define TK_INTEGER 5 +#define TK_BIGINT 6 +#define TK_FLOAT 7 +#define TK_DOUBLE 8 +#define TK_STRING 9 +#define TK_TIMESTAMP 10 +#define TK_BINARY 11 +#define TK_NCHAR 12 +#define TK_OR 13 +#define TK_AND 14 +#define TK_NOT 15 +#define TK_EQ 16 +#define TK_NE 17 +#define TK_ISNULL 18 +#define TK_NOTNULL 19 +#define TK_IS 20 +#define TK_LIKE 21 +#define TK_MATCH 22 +#define TK_NMATCH 23 +#define TK_GLOB 24 +#define TK_BETWEEN 25 +#define TK_IN 26 +#define TK_GT 27 +#define TK_GE 28 +#define TK_LT 29 +#define TK_LE 30 +#define TK_BITAND 31 +#define TK_BITOR 32 +#define TK_LSHIFT 33 +#define TK_RSHIFT 34 +#define TK_PLUS 35 +#define TK_MINUS 36 +#define TK_DIVIDE 37 +#define TK_TIMES 38 +#define TK_STAR 39 +#define TK_SLASH 40 +#define TK_REM 41 +#define TK_CONCAT 42 +#define TK_UMINUS 43 +#define TK_UPLUS 44 +#define TK_BITNOT 45 +#define TK_SHOW 46 +#define TK_DATABASES 47 +#define TK_TOPICS 48 +#define TK_FUNCTIONS 49 +#define TK_MNODES 50 +#define TK_DNODES 51 +#define TK_ACCOUNTS 52 +#define TK_USERS 53 +#define TK_MODULES 54 +#define TK_QUERIES 55 +#define TK_CONNECTIONS 56 +#define TK_STREAMS 57 +#define TK_VARIABLES 58 +#define TK_SCORES 59 +#define TK_GRANTS 60 +#define TK_VNODES 61 +#define TK_DOT 62 +#define TK_CREATE 63 +#define TK_TABLE 64 +#define TK_STABLE 65 +#define TK_DATABASE 66 +#define TK_TABLES 67 +#define TK_STABLES 68 +#define TK_VGROUPS 69 +#define TK_DROP 70 +#define TK_TOPIC 71 +#define TK_FUNCTION 72 +#define TK_DNODE 73 +#define TK_USER 74 +#define TK_ACCOUNT 75 +#define TK_USE 76 +#define TK_DESCRIBE 77 +#define TK_DESC 78 +#define TK_ALTER 79 +#define TK_PASS 80 +#define TK_PRIVILEGE 81 +#define TK_LOCAL 82 +#define TK_COMPACT 83 +#define TK_LP 84 +#define TK_RP 85 +#define TK_IF 86 +#define TK_EXISTS 87 +#define TK_AS 88 +#define TK_OUTPUTTYPE 89 +#define TK_AGGREGATE 90 +#define TK_BUFSIZE 91 +#define TK_PPS 92 +#define TK_TSERIES 93 +#define TK_DBS 94 +#define TK_STORAGE 95 +#define TK_QTIME 96 +#define TK_CONNS 97 +#define TK_STATE 98 +#define TK_COMMA 99 +#define TK_KEEP 100 +#define TK_CACHE 101 +#define TK_REPLICA 102 +#define TK_QUORUM 103 +#define TK_DAYS 104 +#define TK_MINROWS 105 +#define TK_MAXROWS 106 +#define TK_BLOCKS 107 +#define TK_CTIME 108 +#define TK_WAL 109 +#define TK_FSYNC 110 +#define TK_COMP 111 +#define TK_PRECISION 112 +#define TK_UPDATE 113 +#define TK_CACHELAST 114 +#define TK_PARTITIONS 115 +#define TK_UNSIGNED 116 +#define TK_TAGS 117 +#define TK_USING 118 +#define TK_NULL 119 +#define TK_NOW 120 +#define TK_SELECT 121 +#define TK_UNION 122 +#define TK_ALL 123 +#define TK_DISTINCT 124 +#define TK_FROM 125 +#define TK_VARIABLE 126 +#define TK_INTERVAL 127 +#define TK_EVERY 128 +#define TK_SESSION 129 +#define TK_STATE_WINDOW 130 +#define TK_FILL 131 +#define TK_SLIDING 132 +#define TK_ORDER 133 +#define TK_BY 134 +#define TK_ASC 135 +#define TK_GROUP 136 +#define TK_HAVING 137 +#define TK_LIMIT 138 +#define TK_OFFSET 139 +#define TK_SLIMIT 140 +#define TK_SOFFSET 141 +#define TK_WHERE 142 +#define TK_RESET 143 +#define TK_QUERY 144 +#define TK_SYNCDB 145 +#define TK_ADD 146 +#define TK_COLUMN 147 +#define TK_MODIFY 148 +#define TK_TAG 149 +#define TK_CHANGE 150 +#define TK_SET 151 +#define TK_KILL 152 +#define TK_CONNECTION 153 +#define TK_STREAM 154 +#define TK_COLON 155 +#define TK_ABORT 156 +#define TK_AFTER 157 +#define TK_ATTACH 158 +#define TK_BEFORE 159 +#define TK_BEGIN 160 +#define TK_CASCADE 161 +#define TK_CLUSTER 162 +#define TK_CONFLICT 163 +#define TK_COPY 164 +#define TK_DEFERRED 165 +#define TK_DELIMITERS 166 +#define TK_DETACH 167 +#define TK_EACH 168 +#define TK_END 169 +#define TK_EXPLAIN 170 +#define TK_FAIL 171 +#define TK_FOR 172 +#define TK_IGNORE 173 +#define TK_IMMEDIATE 174 +#define TK_INITIALLY 175 +#define TK_INSTEAD 176 +#define TK_KEY 177 +#define TK_OF 178 +#define TK_RAISE 179 +#define TK_REPLACE 180 +#define TK_RESTRICT 181 +#define TK_ROW 182 +#define TK_STATEMENT 183 +#define TK_TRIGGER 184 +#define TK_VIEW 185 +#define TK_IPTOKEN 186 +#define TK_SEMI 187 +#define TK_NONE 188 +#define TK_PREV 189 +#define TK_LINEAR 190 +#define TK_IMPORT 191 +#define TK_TBNAME 192 +#define TK_JOIN 193 +#define TK_INSERT 194 +#define TK_INTO 195 +#define TK_VALUES 196 + + +#define TK_SPACE 300 +#define TK_COMMENT 301 +#define TK_ILLEGAL 302 +#define TK_HEX 303 // hex number 0x123 +#define TK_OCT 304 // oct number +#define TK_BIN 305 // bin format data 0b111 +#define TK_FILE 306 +#define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query + +#endif + + diff --git a/source/libs/parser/inc/tvariant.h b/source/libs/parser/inc/tvariant.h new file mode 100644 index 0000000000..4eb3120a79 --- /dev/null +++ b/source/libs/parser/inc/tvariant.h @@ -0,0 +1,66 @@ +/* + * 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 + +#include "tarray.h" +#include "ttoken.h" + +// variant, each number/string/field_id has a corresponding struct during parsing sql +typedef struct SVariant { + uint32_t nType; + int32_t nLen; // only used for string, for number, it is useless + union { + int64_t i64; + uint64_t u64; + double d; + char *pz; + wchar_t *wpz; + SArray *arr; // only for 'in' query to hold value list, not value for a field + }; +} SVariant; + +bool taosVariantIsValid(SVariant *pVar); + +void taosVariantCreate(SVariant *pVar, SToken *token); + +void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type); + +void taosVariantDestroy(SVariant *pV); + +void taosVariantAssign(SVariant *pDst, const SVariant *pSrc); + +int32_t taosVariantCompare(const SVariant* p1, const SVariant* p2); + +int32_t taosVariantToString(SVariant *pVar, char *dst); + +int32_t taosVariantDump(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix); + +#if 0 +int32_t taosVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, char *extInfo); +#endif + +int32_t taosVariantTypeSetType(SVariant *pVariant, char type); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_TVARIANT_H diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c new file mode 100644 index 0000000000..74642ea811 --- /dev/null +++ b/source/libs/parser/src/astGenerator.c @@ -0,0 +1,507 @@ +/* + * 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 "os.h" +#include "taos.h" +#include "astGenerator.h" + +int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned) { + errno = 0; + int32_t ret = 0; + + char* endPtr = NULL; + if (type == TK_FLOAT) { + double v = strtod(z, &endPtr); + if ((errno == ERANGE && v == HUGE_VALF) || isinf(v) || isnan(v)) { + ret = -1; + } else if ((issigned && (v < INT64_MIN || v > INT64_MAX)) || ((!issigned) && (v < 0 || v > UINT64_MAX))) { + ret = -1; + } else { + *value = (int64_t) round(v); + } + + errno = 0; + return ret; + } + + int32_t radix = 10; + if (type == TK_HEX) { + radix = 16; + } else if (type == TK_BIN) { + radix = 2; + } + + // the string may be overflow according to errno + if (!issigned) { + const char *p = z; + while(*p != 0 && *p == ' ') p++; + if (*p != 0 && *p == '-') { return -1;} + + *value = strtoull(z, &endPtr, radix); + } else { + *value = strtoll(z, &endPtr, radix); + } + + // not a valid integer number, return error + if (endPtr - z != n || errno == ERANGE) { + ret = -1; + } + + errno = 0; + return ret; +} + +SArray *tListItemAppend(SArray *pList, SVariant *pVar, uint8_t sortOrder) { + if (pList == NULL) { + pList = taosArrayInit(4, sizeof(SListItem)); + } + + if (pVar == NULL) { + return pList; + } + + /* + * Here we do not employ the assign function, since we need the pz attribute of structure , which is the point to char string. + * Otherwise, the original pointer may be lost, which causes memory leak. + */ + SListItem item; + item.pVar = *pVar; + item.sortOrder = sortOrder; + + taosArrayPush(pList, &item); + return pList; +} + +SArray *tListItemInsert(SArray *pList, SVariant *pVar, uint8_t sortOrder, int32_t index) { + if (pList == NULL || pVar == NULL || index >= taosArrayGetSize(pList)) { + return tListItemAppend(pList, pVar, sortOrder); + } + + SListItem item; + item.pVar = *pVar; + item.sortOrder = sortOrder; + + taosArrayInsert(pList, index, &item); + return pList; +} + +SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrder) { + if (pList == NULL) { + pList = taosArrayInit(4, sizeof(SListItem)); + } + + if (pAliasToken) { + SListItem item; + taosVariantCreate(&item.pVar, pAliasToken); + item.sortOrder = sortOrder; + + taosArrayPush(pList, &item); + } + + return pList; +} + +SRelationInfo *setTableNameList(SRelationInfo *pRelationInfo, SToken *pName, SToken *pAlias) { + if (pRelationInfo == NULL) { + pRelationInfo = calloc(1, sizeof(SRelationInfo)); + pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair)); + } + + pRelationInfo->type = SQL_NODE_FROM_TABLELIST; + SRelElementPair p = {.tableName = *pName}; + if (pAlias != NULL) { + p.aliasName = *pAlias; + } else { + TPARSER_SET_NONE_TOKEN(p.aliasName); + } + + taosArrayPush(pRelationInfo->list, &p); + return pRelationInfo; +} + +void *destroyRelationInfo(SRelationInfo *pRelationInfo) { + if (pRelationInfo == NULL) { + return NULL; + } + + if (pRelationInfo->type == SQL_NODE_FROM_TABLELIST) { + taosArrayDestroy(pRelationInfo->list); + } else { + size_t size = taosArrayGetSize(pRelationInfo->list); + for(int32_t i = 0; i < size; ++i) { + SArray* pa = taosArrayGetP(pRelationInfo->list, i); + destroyAllSqlNode(pa); + } + taosArrayDestroy(pRelationInfo->list); + } + + tfree(pRelationInfo); + return NULL; +} + +SRelationInfo *addSubquery(SRelationInfo *pRelationInfo, SArray *pSub, SToken *pAlias) { + if (pRelationInfo == NULL) { + pRelationInfo = calloc(1, sizeof(SRelationInfo)); + pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair)); + } + + pRelationInfo->type = SQL_NODE_FROM_SUBQUERY; + + SRelElementPair p = {.pSubquery = pSub}; + if (pAlias != NULL) { + p.aliasName = *pAlias; + } else { + TPARSER_SET_NONE_TOKEN(p.aliasName); + } + + taosArrayPush(pRelationInfo->list, &p); + return pRelationInfo; +} + +// sql expr leaf node +// todo Evalute the value during the validation process of AST. +tSqlExpr *tSqlExprCreateIdValue(SToken *pToken, int32_t optrType) { + tSqlExpr *pSqlExpr = calloc(1, sizeof(tSqlExpr)); + + if (pToken != NULL) { + pSqlExpr->exprToken = *pToken; + } + + if (optrType == TK_NULL) { +// if (pToken) { +// pToken->type = TSDB_DATA_TYPE_NULL; +// tVariantCreate(&pSqlExpr->value, pToken); +// } + pSqlExpr->tokenId = optrType; + pSqlExpr->type = SQL_NODE_VALUE; + } else if (optrType == TK_INTEGER || optrType == TK_STRING || optrType == TK_FLOAT || optrType == TK_BOOL) { +// if (pToken) { +// toTSDBType(pToken->type); +// tVariantCreate(&pSqlExpr->value, pToken); +// } + pSqlExpr->tokenId = optrType; + pSqlExpr->type = SQL_NODE_VALUE; + } else if (optrType == TK_NOW) { + // use nanosecond by default TODO set value after getting database precision +// pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_NANO); +// pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT; + pSqlExpr->tokenId = TK_TIMESTAMP; // TK_TIMESTAMP used to denote the time value is in microsecond + pSqlExpr->type = SQL_NODE_VALUE; +// pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP; + } else if (optrType == TK_VARIABLE) { + // use nanosecond by default + // TODO set value after getting database precision +// if (pToken) { +// char unit = 0; +// int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64, &unit, TSDB_TIME_PRECISION_NANO); +// if (ret != TSDB_CODE_SUCCESS) { +// terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR; +// } +// } + +// pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP; +// pSqlExpr->flags |= 1 << EXPR_FLAG_TIMESTAMP_VAR; +// pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT; + pSqlExpr->tokenId = TK_TIMESTAMP; + pSqlExpr->type = SQL_NODE_VALUE; + } else { + // Here it must be the column name (tk_id) if it is not a number or string. + assert(optrType == TK_ID || optrType == TK_ALL); + if (pToken != NULL) { + pSqlExpr->columnName = *pToken; + } + + pSqlExpr->tokenId = optrType; + pSqlExpr->type = SQL_NODE_TABLE_COLUMN; + } + + return pSqlExpr; +} + +tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SToken *pFuncToken, SToken *endToken, int32_t optType) { + if (pFuncToken == NULL) { + return NULL; + } + + tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr)); + pExpr->tokenId = optType; + pExpr->type = SQL_NODE_SQLFUNCTION; + pExpr->Expr.paramList = pParam; + + int32_t len = (int32_t)((endToken->z + endToken->n) - pFuncToken->z); + pExpr->Expr.operand = (*pFuncToken); + + pExpr->exprToken.n = len; + pExpr->exprToken.z = pFuncToken->z; + pExpr->exprToken.type = pFuncToken->type; + + return pExpr; +} + +SArray *tAppendFuncName(SArray *pList, SToken *pToken) { + assert(pList != NULL && pToken != NULL); + taosArrayPush(pList, pToken); + return pList; +} + +tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) { + tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr)); + pExpr->type = SQL_NODE_EXPR; + + if (pLeft != NULL && pRight != NULL && (optrType != TK_IN)) { + char* endPos = pRight->exprToken.z + pRight->exprToken.n; + pExpr->exprToken.z = pLeft->exprToken.z; + pExpr->exprToken.n = (uint32_t)(endPos - pExpr->exprToken.z); + pExpr->exprToken.type = pLeft->exprToken.type; + } + + if ((pLeft != NULL && pRight != NULL) && + (optrType == TK_PLUS || optrType == TK_MINUS || optrType == TK_STAR || optrType == TK_DIVIDE || optrType == TK_REM)) { + /* + * if a exprToken is noted as the TK_TIMESTAMP, the time precision is microsecond + * Otherwise, the time precision is adaptive, determined by the time precision from databases. + */ + if ((pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_INTEGER) || + (pLeft->tokenId == TK_TIMESTAMP && pRight->tokenId == TK_TIMESTAMP)) { + pExpr->value.nType = TSDB_DATA_TYPE_BIGINT; + pExpr->tokenId = pLeft->tokenId; + pExpr->type = SQL_NODE_VALUE; + + switch (optrType) { + case TK_PLUS: { + pExpr->value.i64 = pLeft->value.i64 + pRight->value.i64; + break; + } + + case TK_MINUS: { + pExpr->value.i64 = pLeft->value.i64 - pRight->value.i64; + break; + } + case TK_STAR: { + pExpr->value.i64 = pLeft->value.i64 * pRight->value.i64; + break; + } + case TK_DIVIDE: { + pExpr->tokenId = TK_FLOAT; + pExpr->value.nType = TSDB_DATA_TYPE_DOUBLE; + pExpr->value.d = (double)pLeft->value.i64 / pRight->value.i64; + break; + } + case TK_REM: { + pExpr->value.i64 = pLeft->value.i64 % pRight->value.i64; + break; + } + } + + tSqlExprDestroy(pLeft); + tSqlExprDestroy(pRight); + } else if ((pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_INTEGER) || + (pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_FLOAT) || + (pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_FLOAT)) { + pExpr->value.nType = TSDB_DATA_TYPE_DOUBLE; + pExpr->tokenId = TK_FLOAT; + pExpr->type = SQL_NODE_VALUE; + + double left = (pLeft->value.nType == TSDB_DATA_TYPE_DOUBLE) ? pLeft->value.d : pLeft->value.i64; + double right = (pRight->value.nType == TSDB_DATA_TYPE_DOUBLE) ? pRight->value.d : pRight->value.i64; + + switch (optrType) { + case TK_PLUS: { + pExpr->value.d = left + right; + break; + } + case TK_MINUS: { + pExpr->value.d = left - right; + break; + } + case TK_STAR: { + pExpr->value.d = left * right; + break; + } + case TK_DIVIDE: { + pExpr->value.d = left / right; + break; + } + case TK_REM: { + pExpr->value.d = left - ((int64_t)(left / right)) * right; + break; + } + } + + tSqlExprDestroy(pLeft); + tSqlExprDestroy(pRight); + + } else { + pExpr->tokenId = optrType; + pExpr->pLeft = pLeft; + pExpr->pRight = pRight; + } + } else if (optrType == TK_IN) { + pExpr->tokenId = optrType; + pExpr->pLeft = pLeft; + + tSqlExpr *pRSub = calloc(1, sizeof(tSqlExpr)); + pRSub->tokenId = TK_SET; // TODO refactor ..... + pRSub->Expr.paramList = (SArray *)pRight; + + pExpr->pRight = pRSub; + } else { + pExpr->tokenId = optrType; + pExpr->pLeft = pLeft; + + if (pLeft != NULL && pRight == NULL) { + pRight = calloc(1, sizeof(tSqlExpr)); + } + + pExpr->pRight = pRight; + } + + return pExpr; +} + +tSqlExpr *tSqlExprClone(tSqlExpr *pSrc); +void tSqlExprCompact(tSqlExpr **pExpr); +bool tSqlExprIsLeaf(tSqlExpr *pExpr); +bool tSqlExprIsParentOfLeaf(tSqlExpr *pExpr); +void tSqlExprDestroy(tSqlExpr *pExpr); +SArray * tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SToken *pDistinct, SToken *pToken); +void tSqlExprListDestroy(SArray *pList); + +SSqlNode *tSetQuerySqlNode(SToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, + SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps, + SWindowStateVal *pw, SToken *pSliding, SArray *pFill, SLimit *pLimit, SLimit *pgLimit, tSqlExpr *pHaving); +int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right); + +SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type); + +SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, + int16_t tableTable); +SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken, + SToken *igExists); + +void destroyAllSqlNode(SArray *pSqlNode); +void destroySqlNode(SSqlNode *pSql); +void freeCreateTableInfo(void* p); + +SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, int32_t type); +SArray *setSubclause(SArray *pList, void *pSqlNode); +SArray *appendSelectClause(SArray *pList, void *pSubclause); + +void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists); + +void SqlInfoDestroy(SSqlInfo *pInfo); + +void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...); +void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SToken* pToken, SToken* existsCheck,int16_t dbType,int16_t tableType); +void setShowOptions(SSqlInfo *pInfo, int32_t type, SToken* prefix, SToken* pPatterns); + +void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SToken *pToken, SCreateDbInfo *pDB, SToken *pIgExists); + +void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SToken *pName, SToken *pPwd, SCreateAcctInfo *pAcctInfo); +void setCreateUserSql(SSqlInfo *pInfo, SToken *pName, SToken *pPasswd); +void setKillSql(SSqlInfo *pInfo, int32_t type, SToken *ip); +void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SToken *pName, SToken* pPwd, SToken *pPrivilege); + +void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam); + +void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo); +void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo); + +// prefix show db.tables; +void tSetDbName(SToken *pCpxName, SToken *pDb); + +void tSetColumnInfo(struct SField *pField, SToken *pName, struct SField *pType); +void tSetColumnType(struct SField *pField, SToken *type); + +/** + * + * @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 *)); + +/** + * + * @param mallocProc The parser allocator + * @return + */ +void *ParseAlloc(void *(*mallocProc)(size_t)); + +SSqlInfo genAST(const char *pStr) { + void *pParser = ParseAlloc(malloc); + + SSqlInfo sqlInfo = {0}; + + sqlInfo.valid = true; + sqlInfo.funcs = taosArrayInit(4, sizeof(SToken)); + + int32_t i = 0; + while (1) { + SToken t0 = {0}; + + if (pStr[i] == 0) { + Parse(pParser, 0, t0, &sqlInfo); + goto abort_parse; + } + + t0.n = tGetToken((char *)&pStr[i], &t0.type); + t0.z = (char *)(pStr + i); + i += t0.n; + + switch (t0.type) { + case TK_SPACE: + case TK_COMMENT: { + break; + } + case TK_SEMI: { + Parse(pParser, 0, t0, &sqlInfo); + goto abort_parse; + } + + case TK_QUESTION: + case TK_ILLEGAL: { + snprintf(sqlInfo.msg, tListLen(sqlInfo.msg), "unrecognized token: \"%s\"", t0.z); + sqlInfo.valid = false; + goto abort_parse; + } + + case TK_HEX: + case TK_OCT: + case TK_BIN: { + snprintf(sqlInfo.msg, tListLen(sqlInfo.msg), "unsupported token: \"%s\"", t0.z); + sqlInfo.valid = false; + goto abort_parse; + } + + default: + Parse(pParser, t0.type, t0, &sqlInfo); + if (sqlInfo.valid == false) { + goto abort_parse; + } + } + } + +abort_parse: + ParseFree(pParser, free); + return sqlInfo; +} diff --git a/source/libs/parser/src/astValidate.c b/source/libs/parser/src/astValidate.c new file mode 100644 index 0000000000..7718dc0758 --- /dev/null +++ b/source/libs/parser/src/astValidate.c @@ -0,0 +1,26 @@ +/* + * 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 "parserInt.h" + +int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQueryStmtInfo* pQueryInfo, int64_t id, char* msg) { + //1. if it is a query, get the meta info and continue. + + + +// qParserExtractRequestedMetaInfo(pInfo->) + return 0; +} diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 6dea4a4e57..be1d93ecf8 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -11,4 +11,45 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +#include "parserInt.h" +#include "ttoken.h" +#include "astGenerator.h" + +bool qIsInsertSql(const char* pStr, size_t length) { + return false; +} + +int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo** pQueryInfo, int64_t id, char* msg) { + *pQueryInfo = calloc(1, sizeof(SQueryStmtInfo)); + if (*pQueryInfo == NULL) { + return -1; // set correct error code. + } + + SSqlInfo info = genAST(pStr); + if (!info.valid) { + strcpy(msg, info.msg); + return -1; // set correct error code. + } + + struct SCatalog* pCatalog = getCatalogHandle(NULL); + int32_t code = qParserValidateSqlNode(pCatalog, &info, *pQueryInfo, id, msg); + if (code != 0) { + return code; + } + + return 0; +} + +int32_t qParseInsertSql(const char* pStr, size_t length, struct SInsertStmtInfo** pInsertInfo, int64_t id, char* msg) { + return 0; +} + +int32_t qParserConvertSql(const char* pStr, size_t length, char** pConvertSql) { + return 0; +} + +int32_t qParserExtractRequestedMetaInfo(const struct SSqlNode* pSqlNode, SMetaReq* pMetaInfo) { + return 0; +} \ No newline at end of file diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp index e69de29bb2..6dea4a4e57 100644 --- a/source/libs/parser/test/parserTests.cpp +++ b/source/libs/parser/test/parserTests.cpp @@ -0,0 +1,14 @@ +/* + * 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 . + */ \ No newline at end of file diff --git a/source/libs/planner/CMakeLists.txt b/source/libs/planner/CMakeLists.txt index 8b3eb96c14..b00d92336d 100644 --- a/source/libs/planner/CMakeLists.txt +++ b/source/libs/planner/CMakeLists.txt @@ -4,4 +4,9 @@ target_include_directories( planner PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/planner" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + planner + PRIVATE os util common catalog parser transport ) \ No newline at end of file diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index 4005508ed7..fc08951c92 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -20,6 +20,39 @@ extern "C" { #endif +#include "common.h" +#include "tarray.h" +#include "planner.h" + +typedef struct SQueryNodeBasicInfo { + int32_t type; + char *name; +} SQueryNodeBasicInfo; + +typedef struct SQueryTableInfo { + char *tableName; + uint64_t uid; + int32_t tid; +} SQueryTableInfo; + +typedef struct SQueryNode { + SQueryNodeBasicInfo info; + SQueryTableInfo tableInfo; + SSchema *pSchema; // the schema of the input SSDatablock + int32_t numOfCols; // number of input columns + struct SExprInfo *pExpr; // the query functions or sql aggregations + int32_t numOfOutput; // number of result columns, which is also the number of pExprs + void *pExtInfo; // additional information + // previous operator to generated result for current node to process + // in case of join, multiple prev nodes exist. + SArray *pPrevNodes; // upstream nodes + struct SQueryNode *nextNode; +} SQueryNode; + +typedef struct SQueryPhyNode { + +} SQueryPhyNode; + #ifdef __cplusplus } #endif diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 6dea4a4e57..8e72fb2758 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -11,4 +11,44 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +#include "os.h" +#include "plannerInt.h" +#include "parser.h" + +int32_t qOptimizeQueryPlan(struct SQueryNode* pQueryNode) { + return 0; +} + +int32_t qCreateQueryPlan(const struct SQueryStmtInfo* pQueryInfo, struct SQueryNode* pQueryNode) { + return 0; +} + +int32_t qQueryPlanToString(struct SQueryNode* pQueryNode, char** str) { + return 0; +} + +int32_t qQueryPlanToSql(struct SQueryNode* pQueryNode, char** sql) { + return 0; +} + +int32_t qCreatePhysicalPlan(struct SQueryNode* pQueryNode, struct SEpSet* pQnode, struct SQueryPhyNode *pPhyNode) { + return 0; +} + +int32_t qPhyPlanToString(struct SQueryPhyNode *pPhyNode, char** str) { + return 0; +} + +void* qDestroyQueryPlan(struct SQueryNode* pQueryNode) { + return NULL; +} + +void* qDestroyQueryPhyPlan(struct SQueryPhyNode* pQueryPhyNode) { + return NULL; +} + +int32_t qCreateQueryJob(const struct SQueryPhyNode* pPhyNode, struct SQueryJob** pJob) { + return 0; +} \ No newline at end of file diff --git a/source/libs/scheduler/CMakeLists.txt b/source/libs/scheduler/CMakeLists.txt index e69de29bb2..770a6b02c2 100644 --- a/source/libs/scheduler/CMakeLists.txt +++ b/source/libs/scheduler/CMakeLists.txt @@ -0,0 +1,13 @@ +aux_source_directory(src SCHEDULER_SRC) +add_library(scheduler ${SCHEDULER_SRC}) + +target_include_directories( + scheduler + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/scheduler" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + scheduler + PRIVATE os util planner +) \ No newline at end of file diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index 3e2cf2d37f..b1b128e200 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -20,6 +20,17 @@ extern "C" { #endif +#include "os.h" +#include "tarray.h" +#include "planner.h" +#include "scheduler.h" + +typedef struct SQuery { + SArray **pSubquery; + int32_t numOfLevels; + int32_t currentLevel; +} SQuery; + #ifdef __cplusplus } #endif diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 6dea4a4e57..37f6240f9b 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -11,4 +11,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +#include "schedulerInt.h" \ No newline at end of file diff --git a/source/util/src/tbuffer.c b/source/util/src/tbuffer.c index c06d1e59bd..7c1eeaaf4f 100644 --- a/source/util/src/tbuffer.c +++ b/source/util/src/tbuffer.c @@ -16,7 +16,7 @@ #include "os.h" #include "tbuffer.h" #include "exception.h" -#include "taoserror.h" +//#include "taoserror.h" typedef union Un4B { uint32_t ui; @@ -41,7 +41,7 @@ static_assert(sizeof(Un8B) == sizeof(double), "sizeof(Un8B) must equal to sizeof size_t tbufSkip(SBufferReader* buf, size_t size) { if( (buf->pos + size) > buf->size ) { - THROW( TSDB_CODE_COM_MEMORY_CORRUPTED ); + THROW( -1 ); } size_t old = buf->pos; buf->pos += size; @@ -73,7 +73,7 @@ const char* tbufReadString( SBufferReader* buf, size_t* len ) { const char* ret = buf->data + buf->pos; tbufSkip( buf, l + 1 ); if( ret[l] != 0 ) { - THROW( TSDB_CODE_COM_MEMORY_CORRUPTED ); + THROW( -1 ); } if( len != NULL ) { *len = l; @@ -228,7 +228,7 @@ void tbufEnsureCapacity( SBufferWriter* buf, size_t size ) { char* data = (*buf->allocator)( buf->data, nsize ); // TODO: the exception should be thrown by the allocator function if( data == NULL ) { - THROW( TSDB_CODE_COM_OUT_OF_MEMORY ); + THROW( -1 ); } buf->data = data; buf->size = nsize; diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index 0c9a1a18ad..bcfd2fc072 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -19,8 +19,6 @@ #include "ttimer.h" #include "tutil.h" #include "tcache.h" -#include "hash.h" -#include "hashfunc.h" static FORCE_INLINE void __cache_wr_lock(SCacheObj *pCacheObj) { #if defined(LINUX) @@ -245,7 +243,8 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v } else { // duplicated key exists while (1) { SCacheDataNode* p = NULL; - int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, key, keyLen, (void*) &p, sizeof(void*)); +// int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, key, keyLen, (void*) &p, sizeof(void*)); + int32_t ret = taosHashRemove(pCacheObj->pHashTable, key, keyLen); // add to trashcan if (ret == 0) { @@ -305,7 +304,8 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen } SCacheDataNode* ptNode = NULL; - taosHashGetClone(pCacheObj->pHashTable, key, keyLen, incRefFn, &ptNode); + taosHashGetClone(pCacheObj->pHashTable, key, keyLen, &ptNode); +// taosHashGetClone(pCacheObj->pHashTable, key, keyLen, incRefFn, &ptNode); void* pData = (ptNode != NULL)? ptNode->data:NULL; @@ -528,7 +528,7 @@ static bool travHashTableEmptyFn(void* param, void* data) { void taosCacheEmpty(SCacheObj *pCacheObj) { SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = NULL, .time = taosGetTimestampMs()}; - taosHashCondTraverse(pCacheObj->pHashTable, travHashTableEmptyFn, &sup); +// taosHashCondTraverse(pCacheObj->pHashTable, travHashTableEmptyFn, &sup); taosTrashcanEmpty(pCacheObj, false); } diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index 1f47ae6be1..282de17c1b 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -19,7 +19,7 @@ #include "tcompare.h" #include "ulog.h" -#include "hash.h" +#include "thash.h" #include "regex.h" #include "os.h" #include "tdef.h" diff --git a/source/util/src/hash.c b/source/util/src/thash.c similarity index 97% rename from source/util/src/hash.c rename to source/util/src/thash.c index 72d293a0e9..1bf6634cd4 100644 --- a/source/util/src/hash.c +++ b/source/util/src/thash.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "hash.h" +#include "thash.h" #include "ulog.h" #include "tdef.h" @@ -24,7 +24,7 @@ #define DO_FREE_HASH_NODE(_n) \ do { \ - tfree(_n); \ + tfree(_n); \ } while (0) #define FREE_HASH_NODE(_h, _n) \ @@ -47,7 +47,6 @@ static FORCE_INLINE void __rd_lock(void *lock, int32_t type) { if (type == HASH_NO_LOCK) { return; } - taosRLockLatch(lock); } @@ -296,8 +295,9 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da } void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen) { - return taosHashGetClone(pHashObj, key, keyLen, NULL, NULL); + return taosHashGetClone(pHashObj, key, keyLen, NULL); } + //TODO(yihaoDeng), merge with taosHashGetClone void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz) { if (taosHashTableEmpty(pHashObj) || keyLen == 0 || key == NULL) { @@ -361,7 +361,7 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo return data; } -void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void* d) { +void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* d) { if (taosHashTableEmpty(pHashObj) || keyLen == 0 || key == NULL) { return NULL; } @@ -395,8 +395,8 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void SHashNode *pNode = doSearchInEntryList(pHashObj, pe, key, keyLen, hashVal); if (pNode != NULL) { - if (fp != NULL) { - fp(GET_HASH_NODE_DATA(pNode)); + if (pHashObj->callbackFp != NULL) { + pHashObj->callbackFp(GET_HASH_NODE_DATA(pNode)); } if (d != NULL) { @@ -414,11 +414,7 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void return data; } -int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) { - return taosHashRemoveWithData(pHashObj, key, keyLen, NULL, 0); -} - -int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t dsize) { +int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, void *data, size_t dsize*/) { if (pHashObj == NULL || taosHashTableEmpty(pHashObj)) { return -1; } @@ -449,7 +445,7 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe SHashNode *prevNode = NULL; while (pNode) { - if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) && pNode->removed == 0) + if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) && pNode->removed == 0) break; prevNode = pNode; @@ -467,14 +463,14 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe } else { pe->next = pNode->next; } - - if (data) memcpy(data, GET_HASH_NODE_DATA(pNode), dsize); + +// if (data) memcpy(data, GET_HASH_NODE_DATA(pNode), dsize); pe->num--; atomic_sub_fetch_64(&pHashObj->size, 1); FREE_HASH_NODE(pHashObj, pNode); } - } + } if (pHashObj->type == HASH_ENTRY_LOCK) { taosWUnLockLatch(&pe->latch); diff --git a/source/util/src/thashutil.c b/source/util/src/thashutil.c index 7f1262e265..6b89cf700e 100644 --- a/source/util/src/thashutil.c +++ b/source/util/src/thashutil.c @@ -14,10 +14,9 @@ */ #include "os.h" -#include "hashfunc.h" +#include "thash.h" #include "tcompare.h" #include "tdef.h" -#include "tutil.h" #define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r))) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index b87ec92ff1..7f57c7d5c9 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include +#include #include "os.h" #include "qPlan.h" #include "qTableMeta.h" diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index a6158906a7..44dae0aed1 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -14,35 +14,34 @@ */ #define _DEFAULT_SOURCE -#include "os.h" -#include "taosmsg.h" -#include "tutil.h" -#include "taoserror.h" -#include "taosmsg.h" -#include "tscompression.h" -#include "tname.h" -#include "tidpool.h" -#include "tglobal.h" -#include "tcompare.h" -#include "tdataformat.h" -#include "tgrant.h" -#include "tqueue.h" +#include "mnodeTable.h" +#include "dnode.h" #include "hash.h" #include "mnode.h" -#include "dnode.h" -#include "mnodeDef.h" -#include "mnodeInt.h" #include "mnodeAcct.h" #include "mnodeDb.h" +#include "mnodeDef.h" #include "mnodeDnode.h" +#include "mnodeFunc.h" +#include "mnodeInt.h" +#include "mnodePeer.h" +#include "mnodeRead.h" #include "mnodeSdb.h" #include "mnodeShow.h" -#include "mnodeTable.h" #include "mnodeVgroup.h" #include "mnodeWrite.h" -#include "mnodeRead.h" -#include "mnodePeer.h" -#include "mnodeFunc.h" +#include "os.h" +#include "taoserror.h" +#include "taosmsg.h" +#include "tcompare.h" +#include "tcompression.h" +#include "tdataformat.h" +#include "tglobal.h" +#include "tgrant.h" +#include "tidpool.h" +#include "tname.h" +#include "tqueue.h" +#include "tutil.h" #define ALTER_CTABLE_RETRY_TIMES 3 #define CREATE_CTABLE_RETRY_TIMES 10 diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 54a5423219..ec576eec8b 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -19,17 +19,17 @@ #include "exception.h" #include "hash.h" -#include "texpr.h" #include "qExecutor.h" #include "qResultbuf.h" +#include "qScript.h" #include "qUtil.h" #include "queryLog.h" -#include "tlosertree.h" -#include "ttype.h" #include "tcompare.h" -#include "tscompression.h" -#include "qScript.h" +#include "tcompression.h" +#include "texpr.h" +#include "tlosertree.h" #include "tscLog.h" +#include "ttype.h" #define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN) #define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN) diff --git a/src/query/src/qResultbuf.c b/src/query/src/qResultbuf.c index 63eba51d6b..3724362e29 100644 --- a/src/query/src/qResultbuf.c +++ b/src/query/src/qResultbuf.c @@ -1,10 +1,10 @@ #include "qResultbuf.h" -#include "stddef.h" -#include "tscompression.h" #include "hash.h" #include "qExtbuffer.h" #include "queryLog.h" +#include "stddef.h" #include "taoserror.h" +#include "tcompression.h" #define GET_DATA_PAYLOAD(_p) ((char *)(_p)->pData + POINTER_BYTES) #define NO_IN_MEM_AVAILABLE_PAGES(_b) (listNEles((_b)->lruList) >= (_b)->inMemPages) diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index 4cf05dd2c7..92ca841272 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -1,8 +1,8 @@ #include "qTsbuf.h" -#include "taoserror.h" -#include "tscompression.h" -#include "tutil.h" #include "queryLog.h" +#include "taoserror.h" +#include "tcompression.h" +#include "tutil.h" static int32_t getDataStartOffset(); static void TSBufUpdateGroupInfo(STSBuf* pTSBuf, int32_t index, STSGroupBlockInfo* pBlockInfo); diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index bc27e094db..f52d6de5d2 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -19,10 +19,10 @@ #include "qExecutor.h" #include "qUtil.h" -#include "tbuffer.h" -#include "tlosertree.h" #include "queryLog.h" -#include "tscompression.h" +#include "tbuffer.h" +#include "tcompression.h" +#include "tlosertree.h" typedef struct SCompSupporter { STableQueryInfo **pTableQueryInfo; diff --git a/src/tsdb/inc/tsdbint.h b/src/tsdb/inc/tsdbint.h index 80e9297579..2354269c6e 100644 --- a/src/tsdb/inc/tsdbint.h +++ b/src/tsdb/inc/tsdbint.h @@ -26,20 +26,20 @@ // #include // #include +#include "hash.h" #include "os.h" -#include "tlog.h" #include "taosdef.h" #include "taoserror.h" -#include "tchecksum.h" -#include "tskiplist.h" -#include "tdataformat.h" -#include "tcoding.h" -#include "tscompression.h" -#include "tlockfree.h" -#include "tlist.h" -#include "hash.h" #include "tarray.h" +#include "tchecksum.h" +#include "tcoding.h" +#include "tcompression.h" +#include "tdataformat.h" #include "tfs.h" +#include "tlist.h" +#include "tlockfree.h" +#include "tlog.h" +#include "tskiplist.h" #include "tsocket.h" #include "tsdb.h"