提交 9487c1b9 编写于 作者: H Haojun Liao

[TD-1978]

上级 2b9a3b1e
此差异已折叠。
...@@ -35,10 +35,6 @@ bool tscValidateTableNameLength(size_t len); ...@@ -35,10 +35,6 @@ bool tscValidateTableNameLength(size_t len);
SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters); SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters);
/**
* get the schema for the "tbname" column. it is a built column
* @return
*/
SSchema tscGetTbnameColumnSchema(); SSchema tscGetTbnameColumnSchema();
#endif // TDENGINE_NAME_H #endif // TDENGINE_NAME_H
...@@ -74,8 +74,6 @@ typedef struct tExprNode { ...@@ -74,8 +74,6 @@ typedef struct tExprNode {
}; };
} tExprNode; } tExprNode;
void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param); void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param);
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order, void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
...@@ -87,6 +85,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond); ...@@ -87,6 +85,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond);
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree); void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)); void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
extern "C" { extern "C" {
#endif #endif
#include <tstrbuild.h>
#include "taos.h" #include "taos.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tstoken.h" #include "tstoken.h"
#include "tstrbuild.h"
#include "tvariant.h" #include "tvariant.h"
#define ParseTOKENTYPE SStrToken #define ParseTOKENTYPE SStrToken
...@@ -37,12 +37,6 @@ extern char tTokenTypeSwitcher[13]; ...@@ -37,12 +37,6 @@ extern char tTokenTypeSwitcher[13];
(x) = tTokenTypeSwitcher[(x)]; \ (x) = tTokenTypeSwitcher[(x)]; \
} \ } \
} while (0) } while (0)
typedef struct tFieldList {
int32_t nField;
int32_t nAlloc;
TAOS_FIELD *p;
} tFieldList;
typedef struct SLimitVal { typedef struct SLimitVal {
int64_t limit; int64_t limit;
...@@ -59,12 +53,6 @@ typedef struct tVariantListItem { ...@@ -59,12 +53,6 @@ typedef struct tVariantListItem {
uint8_t sortOrder; uint8_t sortOrder;
} tVariantListItem; } tVariantListItem;
typedef struct tVariantList {
int32_t nExpr; /* Number of expressions on the list */
int32_t nAlloc; /* Number of entries allocated below */
tVariantListItem *a; /* One entry for each expression */
} tVariantList;
typedef struct SIntervalVal { typedef struct SIntervalVal {
SStrToken interval; SStrToken interval;
SStrToken offset; SStrToken offset;
...@@ -72,16 +60,16 @@ typedef struct SIntervalVal { ...@@ -72,16 +60,16 @@ typedef struct SIntervalVal {
typedef struct SQuerySQL { typedef struct SQuerySQL {
struct tSQLExprList *pSelection; // select clause struct tSQLExprList *pSelection; // select clause
tVariantList * from; // from clause SArray * from; // from clause SArray<tVariantListItem>
struct tSQLExpr * pWhere; // where clause [optional] struct tSQLExpr * pWhere; // where clause [optional]
tVariantList * pGroupby; // groupby clause, only for tags[optional] SArray * pGroupby; // groupby clause, only for tags[optional], SArray<tVariantListItem>
tVariantList * pSortOrder; // orderby [optional] SArray * pSortOrder; // orderby [optional], SArray<tVariantListItem>
SStrToken interval; // interval [optional] SStrToken interval; // interval [optional]
SStrToken offset; // offset window [optional] SStrToken offset; // offset window [optional]
SStrToken sliding; // sliding window [optional] SStrToken sliding; // sliding window [optional]
SLimitVal limit; // limit offset [optional] SLimitVal limit; // limit offset [optional]
SLimitVal slimit; // group limit offset [optional] SLimitVal slimit; // group limit offset [optional]
tVariantList * fillType; // fill type[optional] SArray * fillType; // fill type[optional], SArray<tVariantListItem>
SStrToken selectToken; // sql string SStrToken selectToken; // sql string
} SQuerySQL; } SQuerySQL;
...@@ -91,26 +79,25 @@ typedef struct SCreateTableSQL { ...@@ -91,26 +79,25 @@ typedef struct SCreateTableSQL {
int8_t type; // create normal table/from super table/ stream int8_t type; // create normal table/from super table/ stream
struct { struct {
tFieldList *pTagColumns; // for normal table, pTagColumns = NULL; SArray *pTagColumns; // SArray<TAOS_FIELD>
tFieldList *pColumns; SArray *pColumns; // SArray<TAOS_FIELD>
} colInfo; } colInfo;
struct { struct {
SStrToken stableName; // super table name, for using clause SStrToken stableName; // super table name, for using clause
tVariantList *pTagVals; // create by using metric, tag value SArray *pTagVals; // create by using metric, tag value
STagData tagdata; STagData tagdata;
} usingInfo; } usingInfo;
SQuerySQL *pSelect; SQuerySQL *pSelect;
} SCreateTableSQL; } SCreateTableSQL;
typedef struct SAlterTableSQL { typedef struct SAlterTableSQL {
SStrToken name; SStrToken name;
int16_t type; int16_t type;
STagData tagData; STagData tagData;
SArray *pAddColumns; // SArray<TAOS_FIELD>
tFieldList * pAddColumns; SArray *varList; // set t=val or: change src dst, SArray<tVariantListItem>
tVariantList *varList; // set t=val or: change src dst
} SAlterTableSQL; } SAlterTableSQL;
typedef struct SCreateDBInfo { typedef struct SCreateDBInfo {
...@@ -130,7 +117,7 @@ typedef struct SCreateDBInfo { ...@@ -130,7 +117,7 @@ typedef struct SCreateDBInfo {
SStrToken precision; SStrToken precision;
bool ignoreExists; bool ignoreExists;
tVariantList *keep; SArray *keep;
} SCreateDBInfo; } SCreateDBInfo;
typedef struct SCreateAcctSQL { typedef struct SCreateAcctSQL {
...@@ -168,7 +155,7 @@ typedef struct tDCLSQL { ...@@ -168,7 +155,7 @@ typedef struct tDCLSQL {
SCreateDBInfo dbOpt; SCreateDBInfo dbOpt;
SCreateAcctSQL acctOpt; SCreateAcctSQL acctOpt;
SShowInfo showOpt; SShowInfo showOpt;
SStrToken ip; SStrToken ip;
}; };
SUserInfo user; SUserInfo user;
...@@ -181,33 +168,32 @@ typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause ...@@ -181,33 +168,32 @@ typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
} SSubclauseInfo; } SSubclauseInfo;
typedef struct SSqlInfo { typedef struct SSqlInfo {
int32_t type; int32_t type;
bool valid; bool valid;
union { union {
SCreateTableSQL *pCreateTableInfo; SCreateTableSQL *pCreateTableInfo;
SAlterTableSQL * pAlterInfo; SAlterTableSQL *pAlterInfo;
tDCLSQL * pDCLInfo; tDCLSQL *pDCLInfo;
}; };
SSubclauseInfo subclauseInfo; SSubclauseInfo subclauseInfo;
char pzErrMsg[256]; char pzErrMsg[256];
} SSqlInfo; } SSqlInfo;
typedef struct tSQLExpr { typedef struct tSQLExpr {
// TK_FUNCTION: sql function, TK_LE: less than(binary expr) uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
uint32_t nSQLOptr;
// the full sql string of function(col, param), which is actually the raw // the full sql string of function(col, param), which is actually the raw
// field name, since the function name is kept in nSQLOptr already // field name, since the function name is kept in nSQLOptr already
SStrToken operand; SStrToken operand;
SStrToken colInfo; // field id SStrToken colInfo; // field id
tVariant val; // value only for string, float, int tVariant val; // value only for string, float, int
SStrToken token; // original sql expr string
struct tSQLExpr *pLeft; // left child struct tSQLExpr *pLeft; // left child
struct tSQLExpr *pRight; // right child struct tSQLExpr *pRight; // right child
struct tSQLExprList *pParam; // function parameters struct tSQLExprList *pParam; // function parameters
SStrToken token; // original sql expr string
} tSQLExpr; } tSQLExpr;
// used in select clause. select <tSQLExprList> from xxx // used in select clause. select <tSQLExprList> from xxx
...@@ -238,16 +224,9 @@ void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *); ...@@ -238,16 +224,9 @@ void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
*/ */
void ParseFree(void *p, void (*freeProc)(void *)); void ParseFree(void *p, void (*freeProc)(void *));
tVariantList *tVariantListAppend(tVariantList *pList, tVariant *pVar, uint8_t sortOrder); SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
tVariantList *tVariantListInsert(tVariantList *pList, tVariant *pVar, uint8_t sortOrder, int32_t index); SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
tVariantList *tVariantListAppendToken(tVariantList *pList, SStrToken *pAliasToken, uint8_t sortOrder);
void tVariantListDestroy(tVariantList *pList);
tFieldList *tFieldListAppend(tFieldList *pList, TAOS_FIELD *pField);
void tFieldListDestroy(tFieldList *pList);
tSQLExpr *tSQLExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optType); tSQLExpr *tSQLExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optType);
...@@ -257,17 +236,16 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken ...@@ -257,17 +236,16 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken
void tSQLExprListDestroy(tSQLExprList *pList); void tSQLExprListDestroy(tSQLExprList *pList);
SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
tVariantList *pGroupby, tVariantList *pSortOrder, SIntervalVal *pInterval, SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
SStrToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit); SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrToken *pMetricName, SCreateTableSQL *tSetCreateSQLElems(SArray *pCols, SArray *pTags, SStrToken *pMetricName,
tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type); SArray *pTagVals, SQuerySQL *pSelect, int32_t type);
void tSQLExprNodeDestroy(tSQLExpr *pExpr); void tSQLExprNodeDestroy(tSQLExpr *pExpr);
tSQLExpr *tSQLExprNodeClone(tSQLExpr *pExpr);
SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type); SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, SArray *pCols, SArray *pVals, int32_t type);
void destroyAllSelectClause(SSubclauseInfo *pSql); void destroyAllSelectClause(SSubclauseInfo *pSql);
void doDestroyQuerySql(SQuerySQL *pSql); void doDestroyQuerySql(SQuerySQL *pSql);
......
...@@ -223,8 +223,8 @@ acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K ...@@ -223,8 +223,8 @@ acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K
Y.stat = M; Y.stat = M;
} }
%type keep {tVariantList*} %type keep {SArray*}
%destructor keep {tVariantListDestroy($$);} %destructor keep {taosArrayDestroy($$);}
keep(Y) ::= KEEP tagitemlist(X). { Y = X; } keep(Y) ::= KEEP tagitemlist(X). { Y = X; }
cache(Y) ::= CACHE INTEGER(X). { Y = X; } cache(Y) ::= CACHE INTEGER(X). { Y = X; }
...@@ -324,10 +324,10 @@ create_table_args(A) ::= AS select(S). { ...@@ -324,10 +324,10 @@ create_table_args(A) ::= AS select(S). {
} }
%type column{TAOS_FIELD} %type column{TAOS_FIELD}
%type columnlist{tFieldList*} %type columnlist{SArray*}
%destructor columnlist {tFieldListDestroy($$);} %destructor columnlist {taosArrayDestroy($$);}
columnlist(A) ::= columnlist(X) COMMA column(Y). {A = tFieldListAppend(X, &Y); } columnlist(A) ::= columnlist(X) COMMA column(Y). {A = taosArrayPush(X, &Y); }
columnlist(A) ::= column(X). {A = tFieldListAppend(NULL, &X);} columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(A, &X);}
// The information used for a column is the name and type of column: // The information used for a column is the name and type of column:
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x) // tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
...@@ -335,8 +335,8 @@ column(A) ::= ids(X) typename(Y). { ...@@ -335,8 +335,8 @@ column(A) ::= ids(X) typename(Y). {
tSQLSetColumnInfo(&A, &X, &Y); tSQLSetColumnInfo(&A, &X, &Y);
} }
%type tagitemlist {tVariantList*} %type tagitemlist {SArray*}
%destructor tagitemlist {tVariantListDestroy($$);} %destructor tagitemlist {taosArrayDestroy($$);}
%type tagitem {tVariant} %type tagitem {tVariant}
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); } tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); }
...@@ -429,11 +429,11 @@ as(X) ::= ids(Y). { X = Y; } ...@@ -429,11 +429,11 @@ as(X) ::= ids(Y). { X = Y; }
as(X) ::= . { X.n = 0; } as(X) ::= . { X.n = 0; }
// A complete FROM clause. // A complete FROM clause.
%type from {tVariantList*} %type from {SArray*}
// current not support query from no-table // current not support query from no-table
from(A) ::= FROM tablelist(X). {A = X;} from(A) ::= FROM tablelist(X). {A = X;}
%type tablelist {tVariantList*} %type tablelist {SArray*}
tablelist(A) ::= ids(X) cpxName(Y). { tablelist(A) ::= ids(X) cpxName(Y). {
toTSDBType(X.type); toTSDBType(X.type);
X.n += Y.n; X.n += Y.n;
...@@ -473,15 +473,15 @@ interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N.interval = E; N.offset.n = 0; ...@@ -473,15 +473,15 @@ interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N.interval = E; N.offset.n = 0;
interval_opt(N) ::= INTERVAL LP tmvar(E) COMMA tmvar(O) RP. {N.interval = E; N.offset = O;} interval_opt(N) ::= INTERVAL LP tmvar(E) COMMA tmvar(O) RP. {N.interval = E; N.offset = O;}
interval_opt(N) ::= . {memset(&N, 0, sizeof(N));} interval_opt(N) ::= . {memset(&N, 0, sizeof(N));}
%type fill_opt {tVariantList*} %type fill_opt {SArray*}
%destructor fill_opt {tVariantListDestroy($$);} %destructor fill_opt {taosArrayDestroy($$);}
fill_opt(N) ::= . {N = 0; } fill_opt(N) ::= . {N = 0; }
fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP. { fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP. {
tVariant A = {0}; tVariant A = {0};
toTSDBType(Y.type); toTSDBType(Y.type);
tVariantCreate(&A, &Y); tVariantCreate(&A, &Y);
tVariantListInsert(X, &A, -1, 0); taosArrayPush(X, &A);
N = X; N = X;
} }
...@@ -494,11 +494,11 @@ fill_opt(N) ::= FILL LP ID(Y) RP. { ...@@ -494,11 +494,11 @@ fill_opt(N) ::= FILL LP ID(Y) RP. {
sliding_opt(K) ::= SLIDING LP tmvar(E) RP. {K = E; } sliding_opt(K) ::= SLIDING LP tmvar(E) RP. {K = E; }
sliding_opt(K) ::= . {K.n = 0; K.z = NULL; K.type = 0; } sliding_opt(K) ::= . {K.n = 0; K.z = NULL; K.type = 0; }
%type orderby_opt {tVariantList*} %type orderby_opt {SArray*}
%destructor orderby_opt {tVariantListDestroy($$);} %destructor orderby_opt {taosArrayDestroy($$);}
%type sortlist {tVariantList*} %type sortlist {SArray*}
%destructor sortlist {tVariantListDestroy($$);} %destructor sortlist {taosArrayDestroy($$);}
%type sortitem {tVariant} %type sortitem {tVariant}
%destructor sortitem {tVariantDestroy(&$$);} %destructor sortitem {tVariantDestroy(&$$);}
...@@ -528,10 +528,10 @@ sortorder(A) ::= DESC. {A = TSDB_ORDER_DESC;} ...@@ -528,10 +528,10 @@ sortorder(A) ::= DESC. {A = TSDB_ORDER_DESC;}
sortorder(A) ::= . {A = TSDB_ORDER_ASC;} //default is descend order sortorder(A) ::= . {A = TSDB_ORDER_ASC;} //default is descend order
//group by clause //group by clause
%type groupby_opt {tVariantList*} %type groupby_opt {SArray*}
%destructor groupby_opt {tVariantListDestroy($$);} %destructor groupby_opt {taosArrayDestroy($$);}
%type grouplist {tVariantList*} %type grouplist {SArray*}
%destructor grouplist {tVariantListDestroy($$);} %destructor grouplist {taosArrayDestroy($$);}
groupby_opt(A) ::= . {A = 0;} groupby_opt(A) ::= . {A = 0;}
groupby_opt(A) ::= GROUP BY grouplist(X). {A = X;} groupby_opt(A) ::= GROUP BY grouplist(X). {A = X;}
...@@ -654,7 +654,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). { ...@@ -654,7 +654,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n; X.n += F.n;
toTSDBType(A.type); toTSDBType(A.type);
tVariantList* K = tVariantListAppendToken(NULL, &A, -1); SArray* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
...@@ -670,7 +670,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). { ...@@ -670,7 +670,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
X.n += Z.n; X.n += Z.n;
toTSDBType(Y.type); toTSDBType(Y.type);
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1); SArray* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
...@@ -680,7 +680,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). { ...@@ -680,7 +680,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
X.n += F.n; X.n += F.n;
toTSDBType(Y.type); toTSDBType(Y.type);
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1); SArray* A = tVariantListAppendToken(NULL, &Y, -1);
toTSDBType(Z.type); toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1); A = tVariantListAppendToken(A, &Z, -1);
...@@ -693,7 +693,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). { ...@@ -693,7 +693,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
X.n += F.n; X.n += F.n;
toTSDBType(Y.type); toTSDBType(Y.type);
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1); SArray* A = tVariantListAppendToken(NULL, &Y, -1);
A = tVariantListAppend(A, &Z, -1); A = tVariantListAppend(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
......
...@@ -15,11 +15,9 @@ ...@@ -15,11 +15,9 @@
#include "os.h" #include "os.h"
#include "qSqlparser.h" #include "qSqlparser.h"
#include "queryLog.h"
#include "taosdef.h" #include "taosdef.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tcmdtype.h" #include "tcmdtype.h"
#include "tglobal.h"
#include "tstoken.h" #include "tstoken.h"
#include "tstrbuild.h" #include "tstrbuild.h"
#include "ttokendef.h" #include "ttokendef.h"
...@@ -314,130 +312,56 @@ void tSQLExprDestroy(tSQLExpr *pExpr) { ...@@ -314,130 +312,56 @@ void tSQLExprDestroy(tSQLExpr *pExpr) {
tSQLExprNodeDestroy(pExpr); tSQLExprNodeDestroy(pExpr);
} }
static void *tVariantListExpand(tVariantList *pList) { SArray *tVariantListAppendToken(SArray *pList, SStrToken *pToken, uint8_t order) {
if (pList->nAlloc <= pList->nExpr) { //
int32_t newSize = (pList->nAlloc << 1) + 4;
void *ptr = realloc(pList->a, newSize * sizeof(pList->a[0]));
if (ptr == 0) {
return NULL;
}
pList->nAlloc = newSize;
pList->a = ptr;
}
assert(pList->a != 0);
return pList;
}
tVariantList *tVariantListAppend(tVariantList *pList, tVariant *pVar, uint8_t sortOrder) {
if (pList == NULL) { if (pList == NULL) {
pList = calloc(1, sizeof(tVariantList)); pList = taosArrayInit(4, sizeof(tVariantListItem));
}
if (tVariantListExpand(pList) == NULL) {
return pList;
} }
if (pVar) { if (pToken) {
tVariantListItem *pItem = &pList->a[pList->nExpr++]; tVariantListItem item = {0};
/* tVariantCreate(&item.pVar, pToken);
* Here we do not employ the assign function, since we need the pz attribute of structure item.sortOrder = order;
* , which is the point to char string, to free it!
*
* Otherwise, the original pointer may be lost, which causes memory leak.
*/
memcpy(pItem, pVar, sizeof(tVariant));
pItem->sortOrder = sortOrder;
}
return pList;
}
tVariantList *tVariantListInsert(tVariantList *pList, tVariant *pVar, uint8_t sortOrder, int32_t index) {
if (pList == NULL || index >= pList->nExpr) {
return tVariantListAppend(NULL, pVar, sortOrder);
}
if (tVariantListExpand(pList) == NULL) {
return pList;
}
if (pVar) {
memmove(&pList->a[index + 1], &pList->a[index], sizeof(tVariantListItem) * (pList->nExpr - index));
tVariantListItem *pItem = &pList->a[index];
/*
* Here we do not employ the assign function, since we need the pz attribute of structure
* , which is the point to char string, to free it!
*
* Otherwise, the original pointer may be lost, which causes memory leak.
*/
memcpy(pItem, pVar, sizeof(tVariant));
pItem->sortOrder = sortOrder;
pList->nExpr++; taosArrayPush(pList, &item);
} }
return pList; return pList;
} }
void tVariantListDestroy(tVariantList *pList) { SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder) {
if (pList == NULL) return;
for (int32_t i = 0; i < pList->nExpr; ++i) {
tVariantDestroy(&pList->a[i].pVar);
}
free(pList->a);
free(pList);
}
tVariantList *tVariantListAppendToken(tVariantList *pList, SStrToken *pToken, uint8_t sortOrder) {
if (pList == NULL) { if (pList == NULL) {
pList = calloc(1, sizeof(tVariantList)); pList = taosArrayInit(4, sizeof(tVariantListItem));
} }
if (tVariantListExpand(pList) == NULL) { if (pVar == NULL) {
return pList; return pList;
} }
if (pToken) { /*
tVariant t = {0}; * Here we do not employ the assign function, since we need the pz attribute of structure
tVariantCreate(&t, pToken); * , which is the point to char string, to free it!
*
* Otherwise, the original pointer may be lost, which causes memory leak.
*/
tVariantListItem item = {0};
item.pVar = *pVar;
item.sortOrder = sortOrder;
tVariantListItem *pItem = &pList->a[pList->nExpr++]; taosArrayPush(pList, &item);
memcpy(pItem, &t, sizeof(tVariant));
pItem->sortOrder = sortOrder;
}
return pList; return pList;
} }
tFieldList *tFieldListAppend(tFieldList *pList, TAOS_FIELD *pField) { SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index) {
if (pList == NULL) pList = calloc(1, sizeof(tFieldList)); if (pList == NULL || pVar == NULL || index >= taosArrayGetSize(pList)) {
return tVariantListAppend(NULL, pVar, sortOrder);
if (pList->nAlloc <= pList->nField) { //
pList->nAlloc = (pList->nAlloc << 1) + 4;
pList->p = realloc(pList->p, pList->nAlloc * sizeof(pList->p[0]));
if (pList->p == 0) {
pList->nField = pList->nAlloc = 0;
return pList;
}
}
assert(pList->p != 0);
if (pField) {
struct TAOS_FIELD *pItem = (struct TAOS_FIELD *)&pList->p[pList->nField++];
memcpy(pItem, pField, sizeof(TAOS_FIELD));
} }
return pList;
}
void tFieldListDestroy(tFieldList *pList) { tVariantListItem item = {0};
if (pList == NULL) return; item.pVar = *pVar;
item.sortOrder = sortOrder;
free(pList->p); taosArrayInsert(pList, index, &item);
free(pList); return pList;
} }
void setDBName(SStrToken *pCpxName, SStrToken *pDB) { void setDBName(SStrToken *pCpxName, SStrToken *pDB) {
...@@ -499,9 +423,9 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SStrToken *type) { ...@@ -499,9 +423,9 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
/* /*
* extract the select info out of sql string * extract the select info out of sql string
*/ */
SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
tVariantList *pGroupby, tVariantList *pSortOrder, SIntervalVal *pInterval, SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
SStrToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) { SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) {
assert(pSelection != NULL); assert(pSelection != NULL);
SQuerySQL *pQuery = calloc(1, sizeof(SQuerySQL)); SQuerySQL *pQuery = calloc(1, sizeof(SQuerySQL));
...@@ -535,6 +459,11 @@ SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, ...@@ -535,6 +459,11 @@ SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection,
return pQuery; return pQuery;
} }
void freeVariant(void *pItem) {
tVariantListItem* p = (tVariantListItem*) pItem;
tVariantDestroy(&p->pVar);
}
void doDestroyQuerySql(SQuerySQL *pQuerySql) { void doDestroyQuerySql(SQuerySQL *pQuerySql) {
if (pQuerySql == NULL) { if (pQuerySql == NULL) {
return; return;
...@@ -547,17 +476,18 @@ void doDestroyQuerySql(SQuerySQL *pQuerySql) { ...@@ -547,17 +476,18 @@ void doDestroyQuerySql(SQuerySQL *pQuerySql) {
tSQLExprDestroy(pQuerySql->pWhere); tSQLExprDestroy(pQuerySql->pWhere);
pQuerySql->pWhere = NULL; pQuerySql->pWhere = NULL;
tVariantListDestroy(pQuerySql->pSortOrder); taosArrayDestroyEx(pQuerySql->pSortOrder, freeVariant);
pQuerySql->pSortOrder = NULL; pQuerySql->pSortOrder = NULL;
tVariantListDestroy(pQuerySql->pGroupby); taosArrayDestroyEx(pQuerySql->pGroupby, freeVariant);
pQuerySql->pGroupby = NULL; pQuerySql->pGroupby = NULL;
tVariantListDestroy(pQuerySql->from); taosArrayDestroyEx(pQuerySql->from, freeVariant);
pQuerySql->from = NULL; pQuerySql->from = NULL;
tVariantListDestroy(pQuerySql->fillType); taosArrayDestroyEx(pQuerySql->fillType, freeVariant);
pQuerySql->fillType = NULL;
free(pQuerySql); free(pQuerySql);
} }
...@@ -574,8 +504,8 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) { ...@@ -574,8 +504,8 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) {
taosTFree(pClause->pClause); taosTFree(pClause->pClause);
} }
SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrToken *pStableName, SCreateTableSQL *tSetCreateSQLElems(SArray *pCols, SArray *pTags, SStrToken *pStableName,
tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type) { SArray *pTagVals, SQuerySQL *pSelect, int32_t type) {
SCreateTableSQL *pCreate = calloc(1, sizeof(SCreateTableSQL)); SCreateTableSQL *pCreate = calloc(1, sizeof(SCreateTableSQL));
switch (type) { switch (type) {
...@@ -607,7 +537,7 @@ SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrTo ...@@ -607,7 +537,7 @@ SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrTo
return pCreate; return pCreate;
} }
SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type) { SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, SArray *pCols, SArray *pVals, int32_t type) {
SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL)); SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL));
pAlterTable->name = *pMeterName; pAlterTable->name = *pMeterName;
...@@ -637,14 +567,14 @@ void SQLInfoDestroy(SSqlInfo *pInfo) { ...@@ -637,14 +567,14 @@ void SQLInfoDestroy(SSqlInfo *pInfo) {
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo; SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
doDestroyQuerySql(pCreateTableInfo->pSelect); doDestroyQuerySql(pCreateTableInfo->pSelect);
tFieldListDestroy(pCreateTableInfo->colInfo.pColumns); taosArrayDestroy(pCreateTableInfo->colInfo.pColumns);
tFieldListDestroy(pCreateTableInfo->colInfo.pTagColumns); taosArrayDestroy(pCreateTableInfo->colInfo.pTagColumns);
tVariantListDestroy(pCreateTableInfo->usingInfo.pTagVals); taosArrayDestroyEx(pCreateTableInfo->usingInfo.pTagVals, freeVariant);
taosTFree(pInfo->pCreateTableInfo); taosTFree(pInfo->pCreateTableInfo);
} else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) {
tVariantListDestroy(pInfo->pAlterInfo->varList); taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeVariant);
tFieldListDestroy(pInfo->pAlterInfo->pAddColumns); taosArrayDestroy(pInfo->pAlterInfo->pAddColumns);
taosTFree(pInfo->pAlterInfo); taosTFree(pInfo->pAlterInfo);
} else { } else {
...@@ -653,7 +583,7 @@ void SQLInfoDestroy(SSqlInfo *pInfo) { ...@@ -653,7 +583,7 @@ void SQLInfoDestroy(SSqlInfo *pInfo) {
} }
if (pInfo->pDCLInfo != NULL && pInfo->type == TSDB_SQL_CREATE_DB) { if (pInfo->pDCLInfo != NULL && pInfo->type == TSDB_SQL_CREATE_DB) {
tVariantListDestroy(pInfo->pDCLInfo->dbOpt.keep); taosArrayDestroyEx(pInfo->pDCLInfo->dbOpt.keep, freeVariant);
} }
taosTFree(pInfo->pDCLInfo); taosTFree(pInfo->pDCLInfo);
......
...@@ -115,9 +115,8 @@ typedef union { ...@@ -115,9 +115,8 @@ typedef union {
int64_t yy271; int64_t yy271;
tVariant yy312; tVariant yy312;
SIntervalVal yy314; SIntervalVal yy314;
SArray* yy347;
SCreateTableSQL* yy374; SCreateTableSQL* yy374;
tFieldList* yy449;
tVariantList* yy494;
} YYMINORTYPE; } YYMINORTYPE;
#ifndef YYSTACKDEPTH #ifndef YYSTACKDEPTH
#define YYSTACKDEPTH 100 #define YYSTACKDEPTH 100
...@@ -1361,18 +1360,14 @@ static void yy_destructor( ...@@ -1361,18 +1360,14 @@ static void yy_destructor(
/********* Begin destructor definitions ***************************************/ /********* Begin destructor definitions ***************************************/
case 226: /* keep */ case 226: /* keep */
case 227: /* tagitemlist */ case 227: /* tagitemlist */
case 243: /* columnlist */
case 251: /* fill_opt */ case 251: /* fill_opt */
case 253: /* groupby_opt */ case 253: /* groupby_opt */
case 254: /* orderby_opt */ case 254: /* orderby_opt */
case 264: /* sortlist */ case 264: /* sortlist */
case 268: /* grouplist */ case 268: /* grouplist */
{ {
tVariantListDestroy((yypminor->yy494)); taosArrayDestroy((yypminor->yy347));
}
break;
case 243: /* columnlist */
{
tFieldListDestroy((yypminor->yy449));
} }
break; break;
case 244: /* select */ case 244: /* select */
...@@ -2228,7 +2223,7 @@ static void yy_reduce( ...@@ -2228,7 +2223,7 @@ static void yy_reduce(
yymsp[-8].minor.yy73 = yylhsminor.yy73; yymsp[-8].minor.yy73 = yylhsminor.yy73;
break; break;
case 72: /* keep ::= KEEP tagitemlist */ case 72: /* keep ::= KEEP tagitemlist */
{ yymsp[-1].minor.yy494 = yymsp[0].minor.yy494; } { yymsp[-1].minor.yy347 = yymsp[0].minor.yy347; }
break; break;
case 73: /* cache ::= CACHE INTEGER */ case 73: /* cache ::= CACHE INTEGER */
case 74: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==74); case 74: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==74);
...@@ -2303,7 +2298,7 @@ static void yy_reduce( ...@@ -2303,7 +2298,7 @@ static void yy_reduce(
break; break;
case 98: /* db_optr ::= db_optr keep */ case 98: /* db_optr ::= db_optr keep */
case 102: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==102); case 102: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==102);
{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.keep = yymsp[0].minor.yy494; } { yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.keep = yymsp[0].minor.yy347; }
yymsp[-1].minor.yy158 = yylhsminor.yy158; yymsp[-1].minor.yy158 = yylhsminor.yy158;
break; break;
case 99: /* alter_db_optr ::= */ case 99: /* alter_db_optr ::= */
...@@ -2346,20 +2341,20 @@ static void yy_reduce( ...@@ -2346,20 +2341,20 @@ static void yy_reduce(
break; break;
case 113: /* create_table_args ::= LP columnlist RP */ case 113: /* create_table_args ::= LP columnlist RP */
{ {
yymsp[-2].minor.yy374 = tSetCreateSQLElems(yymsp[-1].minor.yy449, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE); yymsp[-2].minor.yy374 = tSetCreateSQLElems(yymsp[-1].minor.yy347, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE);
setSQLInfo(pInfo, yymsp[-2].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE); setSQLInfo(pInfo, yymsp[-2].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE);
} }
break; break;
case 114: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ case 114: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */
{ {
yymsp[-6].minor.yy374 = tSetCreateSQLElems(yymsp[-5].minor.yy449, yymsp[-1].minor.yy449, NULL, NULL, NULL, TSQL_CREATE_STABLE); yymsp[-6].minor.yy374 = tSetCreateSQLElems(yymsp[-5].minor.yy347, yymsp[-1].minor.yy347, NULL, NULL, NULL, TSQL_CREATE_STABLE);
setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE); setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE);
} }
break; break;
case 115: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ case 115: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */
{ {
yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n;
yymsp[-6].minor.yy374 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy494, NULL, TSQL_CREATE_TABLE_FROM_STABLE); yymsp[-6].minor.yy374 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy347, NULL, TSQL_CREATE_TABLE_FROM_STABLE);
setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE); setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE);
} }
break; break;
...@@ -2370,12 +2365,12 @@ static void yy_reduce( ...@@ -2370,12 +2365,12 @@ static void yy_reduce(
} }
break; break;
case 117: /* columnlist ::= columnlist COMMA column */ case 117: /* columnlist ::= columnlist COMMA column */
{yylhsminor.yy449 = tFieldListAppend(yymsp[-2].minor.yy449, &yymsp[0].minor.yy181); } {yylhsminor.yy347 = taosArrayPush(yymsp[-2].minor.yy347, &yymsp[0].minor.yy181); }
yymsp[-2].minor.yy449 = yylhsminor.yy449; yymsp[-2].minor.yy347 = yylhsminor.yy347;
break; break;
case 118: /* columnlist ::= column */ case 118: /* columnlist ::= column */
{yylhsminor.yy449 = tFieldListAppend(NULL, &yymsp[0].minor.yy181);} {yylhsminor.yy347 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy347, &yymsp[0].minor.yy181);}
yymsp[0].minor.yy449 = yylhsminor.yy449; yymsp[0].minor.yy347 = yylhsminor.yy347;
break; break;
case 119: /* column ::= ids typename */ case 119: /* column ::= ids typename */
{ {
...@@ -2384,12 +2379,12 @@ static void yy_reduce( ...@@ -2384,12 +2379,12 @@ static void yy_reduce(
yymsp[-1].minor.yy181 = yylhsminor.yy181; yymsp[-1].minor.yy181 = yylhsminor.yy181;
break; break;
case 120: /* tagitemlist ::= tagitemlist COMMA tagitem */ case 120: /* tagitemlist ::= tagitemlist COMMA tagitem */
{ yylhsminor.yy494 = tVariantListAppend(yymsp[-2].minor.yy494, &yymsp[0].minor.yy312, -1); } { yylhsminor.yy347 = tVariantListAppend(yymsp[-2].minor.yy347, &yymsp[0].minor.yy312, -1); }
yymsp[-2].minor.yy494 = yylhsminor.yy494; yymsp[-2].minor.yy347 = yylhsminor.yy347;
break; break;
case 121: /* tagitemlist ::= tagitem */ case 121: /* tagitemlist ::= tagitem */
{ yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1); } { yylhsminor.yy347 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1); }
yymsp[0].minor.yy494 = yylhsminor.yy494; yymsp[0].minor.yy347 = yylhsminor.yy347;
break; break;
case 122: /* tagitem ::= INTEGER */ case 122: /* tagitem ::= INTEGER */
case 123: /* tagitem ::= FLOAT */ yytestcase(yyruleno==123); case 123: /* tagitem ::= FLOAT */ yytestcase(yyruleno==123);
...@@ -2416,7 +2411,7 @@ static void yy_reduce( ...@@ -2416,7 +2411,7 @@ static void yy_reduce(
break; break;
case 131: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ case 131: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
{ {
yylhsminor.yy150 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy224, yymsp[-9].minor.yy494, yymsp[-8].minor.yy66, yymsp[-4].minor.yy494, yymsp[-3].minor.yy494, &yymsp[-7].minor.yy314, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy494, &yymsp[0].minor.yy188, &yymsp[-1].minor.yy188); yylhsminor.yy150 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy224, yymsp[-9].minor.yy347, yymsp[-8].minor.yy66, yymsp[-4].minor.yy347, yymsp[-3].minor.yy347, &yymsp[-7].minor.yy314, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy347, &yymsp[0].minor.yy188, &yymsp[-1].minor.yy188);
} }
yymsp[-11].minor.yy150 = yylhsminor.yy150; yymsp[-11].minor.yy150 = yylhsminor.yy150;
break; break;
...@@ -2475,45 +2470,45 @@ static void yy_reduce( ...@@ -2475,45 +2470,45 @@ static void yy_reduce(
{ yymsp[1].minor.yy0.n = 0; } { yymsp[1].minor.yy0.n = 0; }
break; break;
case 145: /* from ::= FROM tablelist */ case 145: /* from ::= FROM tablelist */
{yymsp[-1].minor.yy494 = yymsp[0].minor.yy494;} {yymsp[-1].minor.yy347 = yymsp[0].minor.yy347;}
break; break;
case 146: /* tablelist ::= ids cpxName */ case 146: /* tablelist ::= ids cpxName */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
yylhsminor.yy494 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); yylhsminor.yy347 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[-1].minor.yy0, -1); // table alias name yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[-1].minor.yy0, -1); // table alias name
} }
yymsp[-1].minor.yy494 = yylhsminor.yy494; yymsp[-1].minor.yy347 = yylhsminor.yy347;
break; break;
case 147: /* tablelist ::= ids cpxName ids */ case 147: /* tablelist ::= ids cpxName ids */
{ {
toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[-2].minor.yy0.type);
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n;
yylhsminor.yy494 = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); yylhsminor.yy347 = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[0].minor.yy0, -1); yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[0].minor.yy0, -1);
} }
yymsp[-2].minor.yy494 = yylhsminor.yy494; yymsp[-2].minor.yy347 = yylhsminor.yy347;
break; break;
case 148: /* tablelist ::= tablelist COMMA ids cpxName */ case 148: /* tablelist ::= tablelist COMMA ids cpxName */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
yylhsminor.yy494 = tVariantListAppendToken(yymsp[-3].minor.yy494, &yymsp[-1].minor.yy0, -1); yylhsminor.yy347 = tVariantListAppendToken(yymsp[-3].minor.yy347, &yymsp[-1].minor.yy0, -1);
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[-1].minor.yy0, -1); yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[-1].minor.yy0, -1);
} }
yymsp[-3].minor.yy494 = yylhsminor.yy494; yymsp[-3].minor.yy347 = yylhsminor.yy347;
break; break;
case 149: /* tablelist ::= tablelist COMMA ids cpxName ids */ case 149: /* tablelist ::= tablelist COMMA ids cpxName ids */
{ {
toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[-2].minor.yy0.type);
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n;
yylhsminor.yy494 = tVariantListAppendToken(yymsp[-4].minor.yy494, &yymsp[-2].minor.yy0, -1); yylhsminor.yy347 = tVariantListAppendToken(yymsp[-4].minor.yy347, &yymsp[-2].minor.yy0, -1);
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[0].minor.yy0, -1); yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[0].minor.yy0, -1);
} }
yymsp[-4].minor.yy494 = yylhsminor.yy494; yymsp[-4].minor.yy347 = yylhsminor.yy347;
break; break;
case 150: /* tmvar ::= VARIABLE */ case 150: /* tmvar ::= VARIABLE */
{yylhsminor.yy0 = yymsp[0].minor.yy0;} {yylhsminor.yy0 = yymsp[0].minor.yy0;}
...@@ -2529,7 +2524,7 @@ static void yy_reduce( ...@@ -2529,7 +2524,7 @@ static void yy_reduce(
{memset(&yymsp[1].minor.yy314, 0, sizeof(yymsp[1].minor.yy314));} {memset(&yymsp[1].minor.yy314, 0, sizeof(yymsp[1].minor.yy314));}
break; break;
case 154: /* fill_opt ::= */ case 154: /* fill_opt ::= */
{yymsp[1].minor.yy494 = 0; } {yymsp[1].minor.yy347 = 0; }
break; break;
case 155: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ case 155: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{ {
...@@ -2537,14 +2532,14 @@ static void yy_reduce( ...@@ -2537,14 +2532,14 @@ static void yy_reduce(
toTSDBType(yymsp[-3].minor.yy0.type); toTSDBType(yymsp[-3].minor.yy0.type);
tVariantCreate(&A, &yymsp[-3].minor.yy0); tVariantCreate(&A, &yymsp[-3].minor.yy0);
tVariantListInsert(yymsp[-1].minor.yy494, &A, -1, 0); tVariantListInsert(yymsp[-1].minor.yy347, &A, -1, 0);
yymsp[-5].minor.yy494 = yymsp[-1].minor.yy494; yymsp[-5].minor.yy347 = yymsp[-1].minor.yy347;
} }
break; break;
case 156: /* fill_opt ::= FILL LP ID RP */ case 156: /* fill_opt ::= FILL LP ID RP */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-3].minor.yy494 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); yymsp[-3].minor.yy347 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
} }
break; break;
case 157: /* sliding_opt ::= SLIDING LP tmvar RP */ case 157: /* sliding_opt ::= SLIDING LP tmvar RP */
...@@ -2555,23 +2550,23 @@ static void yy_reduce( ...@@ -2555,23 +2550,23 @@ static void yy_reduce(
break; break;
case 159: /* orderby_opt ::= */ case 159: /* orderby_opt ::= */
case 167: /* groupby_opt ::= */ yytestcase(yyruleno==167); case 167: /* groupby_opt ::= */ yytestcase(yyruleno==167);
{yymsp[1].minor.yy494 = 0;} {yymsp[1].minor.yy347 = 0;}
break; break;
case 160: /* orderby_opt ::= ORDER BY sortlist */ case 160: /* orderby_opt ::= ORDER BY sortlist */
case 168: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==168); case 168: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==168);
{yymsp[-2].minor.yy494 = yymsp[0].minor.yy494;} {yymsp[-2].minor.yy347 = yymsp[0].minor.yy347;}
break; break;
case 161: /* sortlist ::= sortlist COMMA item sortorder */ case 161: /* sortlist ::= sortlist COMMA item sortorder */
{ {
yylhsminor.yy494 = tVariantListAppend(yymsp[-3].minor.yy494, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82); yylhsminor.yy347 = tVariantListAppend(yymsp[-3].minor.yy347, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82);
} }
yymsp[-3].minor.yy494 = yylhsminor.yy494; yymsp[-3].minor.yy347 = yylhsminor.yy347;
break; break;
case 162: /* sortlist ::= item sortorder */ case 162: /* sortlist ::= item sortorder */
{ {
yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82); yylhsminor.yy347 = tVariantListAppend(NULL, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82);
} }
yymsp[-1].minor.yy494 = yylhsminor.yy494; yymsp[-1].minor.yy347 = yylhsminor.yy347;
break; break;
case 163: /* item ::= ids cpxName */ case 163: /* item ::= ids cpxName */
{ {
...@@ -2593,15 +2588,15 @@ static void yy_reduce( ...@@ -2593,15 +2588,15 @@ static void yy_reduce(
break; break;
case 169: /* grouplist ::= grouplist COMMA item */ case 169: /* grouplist ::= grouplist COMMA item */
{ {
yylhsminor.yy494 = tVariantListAppend(yymsp[-2].minor.yy494, &yymsp[0].minor.yy312, -1); yylhsminor.yy347 = tVariantListAppend(yymsp[-2].minor.yy347, &yymsp[0].minor.yy312, -1);
} }
yymsp[-2].minor.yy494 = yylhsminor.yy494; yymsp[-2].minor.yy347 = yylhsminor.yy347;
break; break;
case 170: /* grouplist ::= item */ case 170: /* grouplist ::= item */
{ {
yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1); yylhsminor.yy347 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1);
} }
yymsp[0].minor.yy494 = yylhsminor.yy494; yymsp[0].minor.yy347 = yylhsminor.yy347;
break; break;
case 171: /* having_opt ::= */ case 171: /* having_opt ::= */
case 181: /* where_opt ::= */ yytestcase(yyruleno==181); case 181: /* where_opt ::= */ yytestcase(yyruleno==181);
...@@ -2771,7 +2766,7 @@ static void yy_reduce( ...@@ -2771,7 +2766,7 @@ static void yy_reduce(
case 221: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ case 221: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{ {
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy449, NULL, TSDB_ALTER_TABLE_ADD_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy347, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; break;
...@@ -2780,7 +2775,7 @@ static void yy_reduce( ...@@ -2780,7 +2775,7 @@ static void yy_reduce(
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
tVariantList* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1); SArray* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
...@@ -2789,7 +2784,7 @@ static void yy_reduce( ...@@ -2789,7 +2784,7 @@ static void yy_reduce(
case 223: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ case 223: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{ {
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy449, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy347, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; break;
...@@ -2798,7 +2793,7 @@ static void yy_reduce( ...@@ -2798,7 +2793,7 @@ static void yy_reduce(
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1); SArray* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
...@@ -2809,7 +2804,7 @@ static void yy_reduce( ...@@ -2809,7 +2804,7 @@ static void yy_reduce(
yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n;
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); SArray* A = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1); A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1);
...@@ -2823,7 +2818,7 @@ static void yy_reduce( ...@@ -2823,7 +2818,7 @@ static void yy_reduce(
yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n;
toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[-2].minor.yy0.type);
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
A = tVariantListAppend(A, &yymsp[0].minor.yy312, -1); A = tVariantListAppend(A, &yymsp[0].minor.yy312, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
......
...@@ -70,6 +70,13 @@ void* taosArrayGet(const SArray* pArray, size_t index); ...@@ -70,6 +70,13 @@ void* taosArrayGet(const SArray* pArray, size_t index);
*/ */
void* taosArrayGetP(const SArray* pArray, size_t index); void* taosArrayGetP(const SArray* pArray, size_t index);
/**
* get the last element in the array list
* @param pArray
* @return
*/
void* taosArrayGetLast(const SArray* pArray);
/** /**
* return the size of array * return the size of array
* @param pArray * @param pArray
...@@ -117,6 +124,13 @@ void taosArrayClear(SArray* pArray); ...@@ -117,6 +124,13 @@ void taosArrayClear(SArray* pArray);
*/ */
void taosArrayDestroy(SArray* pArray); void taosArrayDestroy(SArray* pArray);
/**
*
* @param pArray
* @param fp
*/
void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*));
/** /**
* sort the array * sort the array
* @param pArray * @param pArray
......
...@@ -99,6 +99,10 @@ void* taosArrayGetP(const SArray* pArray, size_t index) { ...@@ -99,6 +99,10 @@ void* taosArrayGetP(const SArray* pArray, size_t index) {
return *(void**)d; return *(void**)d;
} }
void* taosArrayGetLast(const SArray* pArray) {
return TARRAY_GET_ELEM(pArray, pArray->size - 1);
}
size_t taosArrayGetSize(const SArray* pArray) { return pArray->size; } size_t taosArrayGetSize(const SArray* pArray) { return pArray->size; }
void* taosArrayInsert(SArray* pArray, size_t index, void* pData) { void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
...@@ -189,6 +193,18 @@ void taosArrayDestroy(SArray* pArray) { ...@@ -189,6 +193,18 @@ void taosArrayDestroy(SArray* pArray) {
free(pArray); free(pArray);
} }
void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*)) {
if (fp == NULL) {
return taosArrayDestroy(pArray);
}
for(int32_t i = 0; i < pArray->size; ++i) {
fp(TARRAY_GET_ELEM(pArray, i));
}
taosArrayDestroy(pArray);
}
void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*)) { void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*)) {
assert(pArray != NULL); assert(pArray != NULL);
assert(compar != NULL); assert(compar != NULL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册