diff --git a/src/client/inc/tscSQLParser.h b/src/client/inc/tscSQLParser.h index 34faad525b6b5e8472403cb616c833cc57b78b0f..3a0cd41f23564fdff3ed05902f2a8355012d8a7c 100644 --- a/src/client/inc/tscSQLParser.h +++ b/src/client/inc/tscSQLParser.h @@ -21,17 +21,77 @@ extern "C" { #endif #include "taos.h" +#include "taosmsg.h" #include "tsqldef.h" #include "ttypes.h" -#include "taosmsg.h" + +enum _sql_cmd { + TSDB_SQL_SELECT = 1, + TSDB_SQL_FETCH, + TSDB_SQL_INSERT, + + TSDB_SQL_MGMT, // the SQL below is for mgmt node + TSDB_SQL_CREATE_DB, + TSDB_SQL_CREATE_TABLE, + TSDB_SQL_DROP_DB, + TSDB_SQL_DROP_TABLE, + TSDB_SQL_CREATE_ACCT, + TSDB_SQL_CREATE_USER, //10 + TSDB_SQL_DROP_ACCT, + TSDB_SQL_DROP_USER, + TSDB_SQL_ALTER_USER, + TSDB_SQL_ALTER_ACCT, + TSDB_SQL_ALTER_TABLE, + TSDB_SQL_ALTER_DB, + TSDB_SQL_CREATE_MNODE, + TSDB_SQL_DROP_MNODE, + TSDB_SQL_CREATE_DNODE, + TSDB_SQL_DROP_DNODE, // 20 + TSDB_SQL_CFG_DNODE, + TSDB_SQL_CFG_MNODE, + TSDB_SQL_SHOW, + TSDB_SQL_RETRIEVE, + TSDB_SQL_KILL_QUERY, + TSDB_SQL_KILL_STREAM, + TSDB_SQL_KILL_CONNECTION, + + TSDB_SQL_READ, // SQL below is for read operation + TSDB_SQL_CONNECT, + TSDB_SQL_USE_DB, // 30 + TSDB_SQL_META, + TSDB_SQL_METRIC, + TSDB_SQL_MULTI_META, + TSDB_SQL_HB, + + TSDB_SQL_LOCAL, // SQL below for client local + TSDB_SQL_DESCRIBE_TABLE, + TSDB_SQL_RETRIEVE_METRIC, + TSDB_SQL_METRIC_JOIN_RETRIEVE, + TSDB_SQL_RETRIEVE_TAGS, + /* + * build empty result instead of accessing dnode to fetch result + * reset the client cache + */ + TSDB_SQL_RETRIEVE_EMPTY_RESULT, //40 + + TSDB_SQL_RESET_CACHE, + TSDB_SQL_SERV_STATUS, + TSDB_SQL_CURRENT_DB, + TSDB_SQL_SERV_VERSION, + TSDB_SQL_CLI_VERSION, + TSDB_SQL_CURRENT_USER, + TSDB_SQL_CFG_LOCAL, + + TSDB_SQL_MAX //48 +}; #define MAX_TOKEN_LEN 30 // token type enum { - TSQL_NODE_TYPE_EXPR = 0x1, - TSQL_NODE_TYPE_ID = 0x2, - TSQL_NODE_TYPE_VALUE = 0x4, + TSQL_NODE_TYPE_EXPR = 0x1, + TSQL_NODE_TYPE_ID = 0x2, + TSQL_NODE_TYPE_VALUE = 0x4, }; extern char tTokenTypeSwitcher[13]; @@ -72,72 +132,12 @@ typedef struct tFieldList { TAOS_FIELD *p; } tFieldList; -// sql operation type +// create table operation type enum TSQL_TYPE { - TSQL_CREATE_NORMAL_METER = 0x01, - TSQL_CREATE_NORMAL_METRIC = 0x02, - TSQL_CREATE_METER_FROM_METRIC = 0x04, - TSQL_CREATE_STREAM = 0x08, - TSQL_QUERY_METER = 0x10, - TSQL_INSERT = 0x20, - - DROP_DNODE = 0x40, - DROP_DATABASE = 0x41, - DROP_TABLE = 0x42, - DROP_USER = 0x43, - DROP_ACCOUNT = 0x44, - - USE_DATABASE = 0x50, - - // show operation - SHOW_DATABASES = 0x60, - SHOW_TABLES = 0x61, - SHOW_STABLES = 0x62, - SHOW_MNODES = 0x63, - SHOW_DNODES = 0x64, - SHOW_ACCOUNTS = 0x65, - SHOW_USERS = 0x66, - SHOW_VGROUPS = 0x67, - SHOW_QUERIES = 0x68, - SHOW_STREAMS = 0x69, - SHOW_CONFIGS = 0x6a, - SHOW_SCORES = 0x6b, - SHOW_MODULES = 0x6c, - SHOW_CONNECTIONS = 0x6d, - SHOW_GRANTS = 0x6e, - SHOW_VNODES = 0x6f, - - // create dnode - CREATE_DNODE = 0x80, - CREATE_DATABASE = 0x81, - CREATE_USER = 0x82, - CREATE_ACCOUNT = 0x83, - - DESCRIBE_TABLE = 0x90, - - ALTER_USER_PASSWD = 0xA0, - ALTER_USER_PRIVILEGES = 0xA1, - ALTER_DNODE = 0xA2, - ALTER_LOCAL = 0xA3, - ALTER_DATABASE = 0xA4, - ALTER_ACCT = 0xA5, - - // reset operation - RESET_QUERY_CACHE = 0xB0, - - // alter tags - ALTER_TABLE_TAGS_ADD = 0xC0, - ALTER_TABLE_TAGS_DROP = 0xC1, - ALTER_TABLE_TAGS_CHG = 0xC2, - ALTER_TABLE_TAGS_SET = 0xC4, - - // alter table column - ALTER_TABLE_ADD_COLUMN = 0xD0, - ALTER_TABLE_DROP_COLUMN = 0xD1, - - KILL_QUERY = 0xD2, - KILL_STREAM = 0xD3, - KILL_CONNECTION = 0xD4, + TSQL_CREATE_TABLE = 0x1, + TSQL_CREATE_STABLE = 0x2, + TSQL_CREATE_TABLE_FROM_STABLE = 0x3, + TSQL_CREATE_STREAM = 0x4, }; typedef struct SQuerySQL { @@ -157,33 +157,31 @@ typedef struct SQuerySQL { typedef struct SCreateTableSQL { struct SSQLToken name; // meter name, create table [meterName] xxx bool existCheck; - + + int8_t type; // create normal table/from super table/ stream struct { tFieldList *pTagColumns; // for normal table, pTagColumns = NULL; tFieldList *pColumns; } colInfo; struct { - SSQLToken metricName; // metric name, for using clause + SSQLToken stableName; // super table name, for using clause tVariantList *pTagVals; // create by using metric, tag value + STagData tagdata; } usingInfo; SQuerySQL *pSelect; - } SCreateTableSQL; typedef struct SAlterTableSQL { SSQLToken name; + int16_t type; + STagData tagData; + tFieldList * pAddColumns; - SSQLToken dropTagToken; tVariantList *varList; // set t=val or: change src dst } SAlterTableSQL; -typedef struct SInsertSQL { - SSQLToken name; - struct tSQLExprListList *pValue; -} SInsertSQL; - typedef struct SCreateDBInfo { SSQLToken dbname; int32_t replica; @@ -204,41 +202,68 @@ typedef struct SCreateDBInfo { } SCreateDBInfo; typedef struct SCreateAcctSQL { - int32_t users; - int32_t dbs; - int32_t tseries; - int32_t streams; - int32_t pps; - int64_t storage; - int64_t qtime; - int32_t conns; + int32_t maxUsers; + int32_t maxDbs; + int32_t maxTimeSeries; + int32_t maxStreams; + int32_t maxPointsPerSecond; + int64_t maxStorage; + int64_t maxQueryTime; + int32_t maxConnections; SSQLToken stat; } SCreateAcctSQL; +typedef struct SShowInfo { + uint8_t showType; + SSQLToken prefix; + SSQLToken pattern; +} SShowInfo; + +typedef struct SUserInfo { + SSQLToken user; + SSQLToken passwd; +// bool hasPasswd; + + SSQLToken privilege; +// bool hasPrivilege; + + int16_t type; +} SUserInfo; + typedef struct tDCLSQL { int32_t nTokens; /* Number of expressions on the list */ int32_t nAlloc; /* Number of entries allocated below */ SSQLToken *a; /* one entry for element */ + bool existsCheck; union { SCreateDBInfo dbOpt; SCreateAcctSQL acctOpt; + SShowInfo showOpt; + SSQLToken ip; }; + + SUserInfo user; + } tDCLSQL; +typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause + SQuerySQL **pClause; + int32_t numOfClause; +} SSubclauseInfo; + typedef struct SSqlInfo { - int32_t sqlType; - bool validSql; + int32_t type; + bool valid; union { SCreateTableSQL *pCreateTableInfo; - SInsertSQL * pInsertInfo; SAlterTableSQL * pAlterInfo; - SQuerySQL * pQueryInfo; tDCLSQL * pDCLInfo; }; - char pzErrMsg[256]; + SSubclauseInfo subclauseInfo; + char pzErrMsg[256]; } SSqlInfo; typedef struct tSQLExpr { @@ -338,31 +363,40 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pMetricName, tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type); -void tSQLExprDestroy(tSQLExpr *); -void tSQLExprNodeDestroy(tSQLExpr *pExpr); + +void tSQLExprDestroy(tSQLExpr *); +void tSQLExprNodeDestroy(tSQLExpr *pExpr); tSQLExpr *tSQLExprNodeClone(tSQLExpr *pExpr); SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type); tSQLExprListList *tSQLListListAppend(tSQLExprListList *pList, tSQLExprList *pExprList); -void tSetInsertSQLElems(SSqlInfo *pInfo, SSQLToken *pName, tSQLExprListList *pList); +void destroyAllSelectClause(SSubclauseInfo *pSql); +void doDestroyQuerySql(SQuerySQL *pSql); -void destroyQuerySql(SQuerySQL *pSql); +SSqlInfo * setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SSQLToken *pMeterName, int32_t type); +SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo); -void setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SSQLToken *pMeterName, int32_t type); +SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause); void setCreatedMeterName(SSqlInfo *pInfo, SSQLToken *pMeterName, SSQLToken *pIfNotExists); void SQLInfoDestroy(SSqlInfo *pInfo); void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...); +void setDropDBTableInfo(SSqlInfo *pInfo, int32_t type, SSQLToken* pToken, SSQLToken* existsCheck); +void setShowOptions(SSqlInfo *pInfo, int32_t type, SSQLToken* prefix, SSQLToken* pPatterns); tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken); void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists); void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo); +void setCreateUserSQL(SSqlInfo *pInfo, SSQLToken *pName, SSQLToken *pPasswd); +void setKillSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *ip); +void setAlterUserSQL(SSqlInfo *pInfo, int16_t type, SSQLToken *pName, SSQLToken* pPwd, SSQLToken *pPrivilege); + void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo); // prefix show db.tables; diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index d1b8dcfed967ae79c7b94b66a8db3239c20d0d68..3fde949947e6f277305ab2439e06757644ab34d6 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -134,6 +134,7 @@ TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index); int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index); int32_t tscGetResRowLength(SSqlCmd* pCmd); void tscClearFieldInfo(SFieldInfo* pFieldInfo); +int32_t tscNumOfFields(SSqlCmd* pCmd); void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex); @@ -186,6 +187,7 @@ void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool remov SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* pMeterMeta, SMetricMeta* pMetricMeta, int16_t numOfTags, int16_t* tags); SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SSqlCmd* pCmd); +int32_t tscAddQueryInfo(SSqlCmd *pCmd); void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* keyStr, uint64_t uid); int tscGetMetricMeta(SSqlObj* pSql); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 6adf2f1be161bc73de1891175a56c9b34f26072f..cd43e4528dc7e2e977e4a169150852891abf717a 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -43,66 +43,6 @@ extern "C" { ((res->data + tscFieldInfoGetOffset(cmd, col) * res->numOfRows) + \ (1 - ord.order) * (res->numOfRows - 1) * tscFieldInfoGetField(cmd, col)->bytes) -enum _sql_cmd { - TSDB_SQL_SELECT, - TSDB_SQL_FETCH, - TSDB_SQL_INSERT, - - TSDB_SQL_MGMT, // the SQL below is for mgmt node - TSDB_SQL_CREATE_DB, - TSDB_SQL_CREATE_TABLE, - TSDB_SQL_DROP_DB, - TSDB_SQL_DROP_TABLE, - TSDB_SQL_CREATE_ACCT, - TSDB_SQL_CREATE_USER, - TSDB_SQL_DROP_ACCT, // 10 - TSDB_SQL_DROP_USER, - TSDB_SQL_ALTER_USER, - TSDB_SQL_ALTER_ACCT, - TSDB_SQL_ALTER_TABLE, - TSDB_SQL_ALTER_DB, - TSDB_SQL_CREATE_MNODE, - TSDB_SQL_DROP_MNODE, - TSDB_SQL_CREATE_DNODE, - TSDB_SQL_DROP_DNODE, - TSDB_SQL_CFG_DNODE, // 20 - TSDB_SQL_CFG_MNODE, - TSDB_SQL_SHOW, - TSDB_SQL_RETRIEVE, - TSDB_SQL_KILL_QUERY, - TSDB_SQL_KILL_STREAM, - TSDB_SQL_KILL_CONNECTION, - - TSDB_SQL_READ, // SQL below is for read operation - TSDB_SQL_CONNECT, - TSDB_SQL_USE_DB, - TSDB_SQL_META, // 30 - TSDB_SQL_METRIC, - TSDB_SQL_MULTI_META, - TSDB_SQL_HB, - - TSDB_SQL_LOCAL, // SQL below for client local - TSDB_SQL_DESCRIBE_TABLE, - TSDB_SQL_RETRIEVE_METRIC, - TSDB_SQL_METRIC_JOIN_RETRIEVE, - TSDB_SQL_RETRIEVE_TAGS, - /* - * build empty result instead of accessing dnode to fetch result - * reset the client cache - */ - TSDB_SQL_RETRIEVE_EMPTY_RESULT, - - TSDB_SQL_RESET_CACHE, // 40 - TSDB_SQL_SERV_STATUS, - TSDB_SQL_CURRENT_DB, - TSDB_SQL_SERV_VERSION, - TSDB_SQL_CLI_VERSION, - TSDB_SQL_CURRENT_USER, - TSDB_SQL_CFG_LOCAL, - - TSDB_SQL_MAX -}; - // forward declaration struct SSqlInfo; @@ -267,6 +207,28 @@ typedef struct SDataBlockList { STableDataBlocks **pData; } SDataBlockList; +typedef struct SQueryInfo { + char intervalTimeUnit; + + int64_t etime, stime; + int64_t nAggTimeInterval; // aggregation time interval + int64_t nSlidingTime; // sliding window in mseconds + SSqlGroupbyExpr groupbyExpr; // group by tags info + + SColumnBaseInfo colList; + SFieldInfo fieldsInfo; + SSqlExprInfo exprsInfo; + SLimitVal limit; + SLimitVal slimit; + STagCond tagCond; + int16_t interpoType; // interpolate type + int16_t numOfTables; + SMeterMetaInfo **pMeterInfo; + struct STSBuf * tsBuf; + // todo use dynamic allocated memory for defaultVal + int64_t defaultVal[TSDB_MAX_COLUMNS]; // default value for interpolation +} SQueryInfo; + typedef struct { SOrderVal order; int command; @@ -274,18 +236,12 @@ typedef struct { union { bool existsCheck; // check if the table exists - int8_t showType; // show command type + bool import; // import/insert type }; int8_t isInsertFromFile; // load data from file or not - bool import; // import/insert type uint8_t msgType; uint16_t type; // query type - char intervalTimeUnit; - int64_t etime, stime; - int64_t nAggTimeInterval; // aggregation time interval - int64_t nSlidingTime; // sliding window in mseconds - SSqlGroupbyExpr groupbyExpr; // group by tags info /* * use to keep short request msg and error msg, in such case, SSqlCmd->payload == SSqlCmd->ext; @@ -297,22 +253,32 @@ typedef struct { char * payload; int payloadLen; short numOfCols; - SColumnBaseInfo colList; - SFieldInfo fieldsInfo; - SSqlExprInfo exprsInfo; - SLimitVal limit; - SLimitVal slimit; int64_t globalLimit; - STagCond tagCond; - int16_t interpoType; // interpolate type - int16_t numOfTables; + + SQueryInfo *pQueryInfo; + int32_t numOfQueries; + +// char intervalTimeUnit; +// int64_t etime, stime; +// int64_t nAggTimeInterval; // aggregation time interval +// int64_t nSlidingTime; // sliding window in mseconds +// SSqlGroupbyExpr groupbyExpr; // group by tags info +// +// SColumnBaseInfo colList; +// SFieldInfo fieldsInfo; +// SSqlExprInfo exprsInfo; +// SLimitVal limit; +// SLimitVal slimit; +// STagCond tagCond; +// int16_t interpoType; // interpolate type +// int16_t numOfTables; +// SMeterMetaInfo **pMeterInfo; +// struct STSBuf * tsBuf; +// // todo use dynamic allocated memory for defaultVal +// int64_t defaultVal[TSDB_MAX_COLUMNS]; // default value for interpolation // submit data blocks branched according to vnode SDataBlockList * pDataBlocks; - SMeterMetaInfo **pMeterInfo; - struct STSBuf * tsBuf; - // todo use dynamic allocated memory for defaultVal - int64_t defaultVal[TSDB_MAX_COLUMNS]; // default value for interpolation // for parameter ('?') binding and batch processing int32_t batchSize; @@ -435,6 +401,8 @@ typedef struct { int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion); void tscInitMsgs(); +extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo); + void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle); int tscProcessSql(SSqlObj *pSql); diff --git a/src/client/src/sql.c b/src/client/src/sql.c index ffcdc4bc0e75811bf2e9460eb06e122cd8c1985a..73576a14fb4a63e4f92b61679bfed7a6cc70d269 100644 --- a/src/client/src/sql.c +++ b/src/client/src/sql.c @@ -22,8 +22,6 @@ ** The following is the concatenation of all %include directives from the ** input grammar file: */ -#pragma GCC diagnostic ignored "-Wunused-variable" - #include /************ Begin %include sections from the grammar ************************/ @@ -80,13 +78,15 @@ ** defined, then do no error processing. ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar +** YYNTOKEN Number of terminal symbols ** YY_MAX_SHIFT Maximum value for shift actions ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions -** YY_MIN_REDUCE Maximum value for reduce actions ** YY_ERROR_ACTION The yy_action[] code for syntax error ** YY_ACCEPT_ACTION The yy_action[] code for accept ** YY_NO_ACTION The yy_action[] code for no-op +** YY_MIN_REDUCE Minimum value for reduce actions +** YY_MAX_REDUCE Maximum value for reduce actions */ #ifndef INTERFACE # define INTERFACE 1 @@ -99,12 +99,12 @@ typedef union { int yyinit; ParseTOKENTYPE yy0; + SSubclauseInfo* yy117; SQuerySQL* yy138; SCreateAcctSQL yy155; SLimitVal yy162; int yy220; tVariant yy236; - tSQLExprListList* yy237; tSQLExpr* yy244; SCreateDBInfo yy262; tSQLExprList* yy284; @@ -122,22 +122,19 @@ typedef union { #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 -#define YYNSTATE 252 -#define YYNRULE 216 -#define YY_MAX_SHIFT 251 -#define YY_MIN_SHIFTREDUCE 403 -#define YY_MAX_SHIFTREDUCE 618 -#define YY_MIN_REDUCE 619 -#define YY_MAX_REDUCE 834 -#define YY_ERROR_ACTION 835 -#define YY_ACCEPT_ACTION 836 -#define YY_NO_ACTION 837 +#define YYNSTATE 241 +#define YYNRULE 213 +#define YYNTOKEN 197 +#define YY_MAX_SHIFT 240 +#define YY_MIN_SHIFTREDUCE 391 +#define YY_MAX_SHIFTREDUCE 603 +#define YY_ERROR_ACTION 604 +#define YY_ACCEPT_ACTION 605 +#define YY_NO_ACTION 606 +#define YY_MIN_REDUCE 607 +#define YY_MAX_REDUCE 819 /************* End control #defines *******************************************/ -/* The yyzerominor constant is used to initialize instances of -** YYMINORTYPE objects to zero. */ -static const YYMINORTYPE yyzerominor = { 0 }; - /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. ** @@ -165,9 +162,6 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. ** -** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE -** and YY_MAX_REDUCE - ** N == YY_ERROR_ACTION A syntax error has occurred. ** ** N == YY_ACCEPT_ACTION The parser accepts its input. @@ -175,21 +169,22 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** N == YY_NO_ACTION No such action. Denotes unused ** slots in the yy_action[] table. ** +** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE +** and YY_MAX_REDUCE +** ** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as +** Given state S and lookahead X, the action is computed as either: ** -** yy_action[ yy_shift_ofst[S] + X ] +** (A) N = yy_action[ yy_shift_ofst[S] + X ] +** (B) N = yy_default[S] ** -** If the index value yy_shift_ofst[S]+X is out of range or if the value -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] -** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. +** The (A) formula is preferred. The B formula is used instead if +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X. ** -** The formula above is for computing the action when the lookahead is +** The formulas above are for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after ** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. +** the yy_shift_ofst[] array. ** ** The following are the tables generated in this section: ** @@ -203,198 +198,209 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (531) +#define YY_ACTTAB_COUNT (516) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 443, 74, 78, 244, 85, 77, 153, 249, 444, 836, - /* 10 */ 251, 80, 43, 45, 7, 37, 38, 62, 111, 171, - /* 20 */ 31, 443, 443, 205, 41, 39, 42, 40, 241, 444, - /* 30 */ 444, 135, 36, 35, 10, 101, 34, 33, 32, 43, - /* 40 */ 45, 600, 37, 38, 156, 524, 135, 31, 135, 133, - /* 50 */ 205, 41, 39, 42, 40, 159, 601, 158, 601, 36, - /* 60 */ 35, 154, 514, 34, 33, 32, 404, 405, 406, 407, - /* 70 */ 408, 409, 410, 411, 412, 413, 414, 415, 250, 21, - /* 80 */ 43, 45, 172, 37, 38, 227, 226, 202, 31, 59, - /* 90 */ 21, 205, 41, 39, 42, 40, 34, 33, 32, 57, - /* 100 */ 36, 35, 550, 551, 34, 33, 32, 45, 232, 37, - /* 110 */ 38, 167, 132, 511, 31, 21, 21, 205, 41, 39, - /* 120 */ 42, 40, 168, 569, 511, 502, 36, 35, 134, 178, - /* 130 */ 34, 33, 32, 243, 37, 38, 186, 512, 183, 31, - /* 140 */ 532, 101, 205, 41, 39, 42, 40, 228, 233, 511, - /* 150 */ 511, 36, 35, 230, 229, 34, 33, 32, 17, 219, - /* 160 */ 242, 218, 217, 216, 215, 214, 213, 212, 211, 496, - /* 170 */ 139, 485, 486, 487, 488, 489, 490, 491, 492, 493, - /* 180 */ 494, 495, 163, 582, 11, 97, 573, 133, 576, 529, - /* 190 */ 579, 597, 163, 582, 166, 556, 573, 200, 576, 155, - /* 200 */ 579, 36, 35, 148, 220, 34, 33, 32, 21, 87, - /* 210 */ 86, 142, 514, 243, 160, 161, 101, 147, 204, 248, - /* 220 */ 247, 426, 514, 76, 160, 161, 163, 582, 530, 241, - /* 230 */ 573, 101, 576, 513, 579, 193, 41, 39, 42, 40, - /* 240 */ 242, 596, 510, 27, 36, 35, 49, 571, 34, 33, - /* 250 */ 32, 114, 115, 224, 65, 68, 505, 441, 160, 161, - /* 260 */ 124, 192, 518, 50, 188, 515, 499, 516, 498, 517, - /* 270 */ 555, 150, 128, 126, 245, 89, 88, 44, 450, 442, - /* 280 */ 61, 124, 124, 572, 595, 60, 581, 44, 575, 527, - /* 290 */ 578, 28, 18, 169, 170, 605, 581, 162, 606, 29, - /* 300 */ 541, 580, 29, 542, 47, 52, 599, 15, 151, 583, - /* 310 */ 14, 580, 574, 14, 577, 508, 73, 72, 507, 47, - /* 320 */ 53, 44, 22, 209, 522, 152, 523, 22, 140, 520, - /* 330 */ 581, 521, 9, 8, 2, 84, 83, 141, 143, 144, - /* 340 */ 145, 615, 146, 137, 131, 580, 138, 136, 531, 566, - /* 350 */ 98, 565, 164, 562, 561, 165, 231, 548, 547, 189, - /* 360 */ 112, 113, 519, 452, 110, 210, 129, 25, 191, 223, - /* 370 */ 225, 614, 70, 613, 611, 116, 470, 26, 23, 130, - /* 380 */ 439, 91, 79, 437, 81, 435, 434, 537, 194, 198, - /* 390 */ 173, 54, 125, 432, 431, 430, 428, 421, 525, 127, - /* 400 */ 425, 51, 423, 102, 46, 203, 103, 104, 95, 199, - /* 410 */ 201, 535, 197, 30, 536, 549, 195, 27, 222, 75, - /* 420 */ 234, 235, 236, 237, 207, 55, 238, 239, 240, 246, - /* 430 */ 149, 618, 63, 66, 175, 433, 174, 176, 177, 617, - /* 440 */ 180, 427, 119, 90, 118, 471, 117, 120, 122, 121, - /* 450 */ 123, 92, 509, 1, 24, 182, 107, 105, 106, 108, - /* 460 */ 109, 179, 181, 616, 184, 185, 12, 609, 190, 187, - /* 470 */ 13, 157, 96, 538, 99, 196, 58, 4, 19, 543, - /* 480 */ 100, 5, 584, 3, 20, 16, 206, 6, 208, 64, - /* 490 */ 483, 482, 481, 480, 479, 478, 477, 476, 474, 47, - /* 500 */ 447, 449, 67, 22, 504, 221, 503, 501, 56, 468, - /* 510 */ 466, 48, 458, 464, 69, 460, 462, 456, 454, 475, - /* 520 */ 71, 473, 82, 429, 445, 419, 417, 93, 619, 621, - /* 530 */ 94, + /* 0 */ 738, 431, 129, 147, 238, 10, 605, 240, 129, 432, + /* 10 */ 129, 151, 807, 40, 42, 19, 34, 35, 806, 150, + /* 20 */ 807, 28, 128, 431, 194, 38, 36, 39, 37, 133, + /* 30 */ 490, 432, 93, 33, 32, 97, 803, 31, 30, 29, + /* 40 */ 40, 42, 729, 34, 35, 148, 802, 159, 28, 715, + /* 50 */ 735, 194, 38, 36, 39, 37, 181, 97, 219, 218, + /* 60 */ 33, 32, 158, 718, 31, 30, 29, 392, 393, 394, + /* 70 */ 395, 396, 397, 398, 399, 400, 401, 402, 403, 239, + /* 80 */ 718, 40, 42, 182, 34, 35, 209, 230, 191, 28, + /* 90 */ 56, 19, 194, 38, 36, 39, 37, 31, 30, 29, + /* 100 */ 54, 33, 32, 801, 718, 31, 30, 29, 42, 517, + /* 110 */ 34, 35, 762, 16, 189, 28, 19, 19, 194, 38, + /* 120 */ 36, 39, 37, 160, 559, 715, 221, 33, 32, 145, + /* 130 */ 170, 31, 30, 29, 232, 34, 35, 178, 7, 175, + /* 140 */ 28, 59, 107, 194, 38, 36, 39, 37, 217, 222, + /* 150 */ 715, 715, 33, 32, 146, 716, 31, 30, 29, 15, + /* 160 */ 208, 231, 207, 206, 205, 204, 203, 202, 201, 200, + /* 170 */ 700, 19, 689, 690, 691, 692, 693, 694, 695, 696, + /* 180 */ 697, 698, 699, 155, 572, 431, 703, 563, 702, 566, + /* 190 */ 565, 569, 568, 432, 38, 36, 39, 37, 237, 236, + /* 200 */ 414, 11, 33, 32, 232, 714, 31, 30, 29, 110, + /* 210 */ 111, 213, 62, 65, 134, 152, 153, 155, 572, 193, + /* 220 */ 142, 563, 97, 566, 58, 569, 84, 83, 136, 163, + /* 230 */ 506, 231, 97, 503, 141, 504, 26, 505, 71, 75, + /* 240 */ 233, 82, 74, 124, 122, 234, 86, 85, 77, 152, + /* 250 */ 153, 155, 572, 520, 564, 563, 567, 566, 709, 569, + /* 260 */ 25, 161, 162, 46, 33, 32, 73, 154, 31, 30, + /* 270 */ 29, 645, 230, 561, 120, 540, 541, 761, 41, 180, + /* 280 */ 135, 47, 654, 152, 153, 120, 144, 57, 571, 646, + /* 290 */ 164, 49, 120, 216, 215, 531, 532, 589, 573, 44, + /* 300 */ 13, 12, 12, 570, 2, 137, 496, 50, 138, 562, + /* 310 */ 44, 495, 41, 139, 198, 20, 717, 510, 20, 511, + /* 320 */ 140, 508, 571, 509, 81, 80, 131, 70, 69, 127, + /* 330 */ 507, 9, 8, 132, 816, 130, 772, 570, 771, 156, + /* 340 */ 768, 767, 157, 220, 737, 754, 41, 94, 753, 108, + /* 350 */ 109, 106, 656, 199, 125, 23, 571, 212, 25, 214, + /* 360 */ 815, 67, 814, 730, 88, 812, 112, 527, 674, 24, + /* 370 */ 183, 570, 21, 126, 643, 187, 76, 641, 78, 639, + /* 380 */ 51, 638, 165, 728, 121, 48, 98, 636, 635, 634, + /* 390 */ 632, 43, 625, 123, 629, 99, 627, 192, 741, 742, + /* 400 */ 190, 188, 186, 184, 27, 755, 211, 72, 223, 224, + /* 410 */ 225, 226, 227, 228, 100, 196, 229, 52, 235, 603, + /* 420 */ 166, 167, 143, 169, 60, 63, 168, 637, 602, 171, + /* 430 */ 87, 172, 173, 174, 115, 631, 114, 675, 113, 116, + /* 440 */ 117, 119, 118, 89, 1, 713, 103, 101, 22, 102, + /* 450 */ 104, 105, 601, 176, 177, 594, 179, 92, 55, 528, + /* 460 */ 95, 149, 185, 4, 533, 5, 96, 61, 3, 17, + /* 470 */ 574, 471, 18, 14, 195, 6, 197, 470, 469, 468, + /* 480 */ 467, 466, 465, 464, 462, 44, 435, 64, 437, 66, + /* 490 */ 20, 210, 492, 491, 489, 53, 456, 45, 454, 446, + /* 500 */ 68, 452, 448, 450, 444, 442, 463, 461, 79, 417, + /* 510 */ 433, 90, 407, 91, 405, 607, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 1, 64, 65, 66, 67, 68, 199, 200, 9, 197, - /* 10 */ 198, 74, 13, 14, 96, 16, 17, 99, 100, 63, - /* 20 */ 21, 1, 1, 24, 25, 26, 27, 28, 78, 9, - /* 30 */ 9, 248, 33, 34, 248, 200, 37, 38, 39, 13, - /* 40 */ 14, 258, 16, 17, 217, 233, 248, 21, 248, 248, - /* 50 */ 24, 25, 26, 27, 28, 257, 258, 257, 258, 33, - /* 60 */ 34, 260, 235, 37, 38, 39, 45, 46, 47, 48, - /* 70 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 200, - /* 80 */ 13, 14, 126, 16, 17, 129, 130, 252, 21, 254, - /* 90 */ 200, 24, 25, 26, 27, 28, 37, 38, 39, 100, - /* 100 */ 33, 34, 111, 112, 37, 38, 39, 14, 200, 16, - /* 110 */ 17, 232, 248, 234, 21, 200, 200, 24, 25, 26, - /* 120 */ 27, 28, 232, 97, 234, 5, 33, 34, 248, 125, - /* 130 */ 37, 38, 39, 60, 16, 17, 132, 229, 134, 21, - /* 140 */ 200, 200, 24, 25, 26, 27, 28, 232, 232, 234, - /* 150 */ 234, 33, 34, 33, 34, 37, 38, 39, 85, 86, - /* 160 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 216, - /* 170 */ 248, 218, 219, 220, 221, 222, 223, 224, 225, 226, - /* 180 */ 227, 228, 1, 2, 44, 200, 5, 248, 7, 249, - /* 190 */ 9, 248, 1, 2, 217, 254, 5, 256, 7, 260, - /* 200 */ 9, 33, 34, 63, 217, 37, 38, 39, 200, 69, - /* 210 */ 70, 71, 235, 60, 33, 34, 200, 77, 37, 60, - /* 220 */ 61, 62, 235, 72, 33, 34, 1, 2, 37, 78, - /* 230 */ 5, 200, 7, 235, 9, 250, 25, 26, 27, 28, - /* 240 */ 87, 248, 234, 103, 33, 34, 101, 1, 37, 38, - /* 250 */ 39, 64, 65, 66, 67, 68, 231, 204, 33, 34, - /* 260 */ 207, 121, 2, 118, 124, 5, 218, 7, 220, 9, - /* 270 */ 254, 131, 64, 65, 66, 67, 68, 96, 204, 204, - /* 280 */ 236, 207, 207, 37, 248, 254, 105, 96, 5, 101, - /* 290 */ 7, 247, 104, 33, 34, 97, 105, 59, 97, 101, - /* 300 */ 97, 120, 101, 97, 101, 101, 97, 101, 248, 97, - /* 310 */ 101, 120, 5, 101, 7, 97, 127, 128, 97, 101, - /* 320 */ 116, 96, 101, 97, 5, 248, 7, 101, 248, 5, - /* 330 */ 105, 7, 127, 128, 96, 72, 73, 248, 248, 248, - /* 340 */ 248, 235, 248, 248, 248, 120, 248, 248, 200, 230, - /* 350 */ 200, 230, 230, 230, 230, 230, 230, 255, 255, 123, - /* 360 */ 200, 200, 102, 200, 237, 200, 200, 200, 259, 200, - /* 370 */ 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, - /* 380 */ 200, 59, 200, 200, 200, 200, 200, 105, 251, 251, - /* 390 */ 200, 115, 200, 200, 200, 200, 200, 200, 246, 200, - /* 400 */ 200, 117, 200, 245, 114, 109, 244, 243, 201, 108, - /* 410 */ 113, 201, 107, 119, 201, 201, 106, 103, 75, 84, - /* 420 */ 83, 49, 80, 82, 201, 201, 53, 81, 79, 75, - /* 430 */ 201, 5, 205, 205, 5, 201, 133, 133, 58, 5, - /* 440 */ 5, 201, 209, 202, 213, 215, 214, 212, 211, 210, - /* 450 */ 208, 202, 233, 206, 203, 58, 240, 242, 241, 239, - /* 460 */ 238, 133, 133, 5, 133, 58, 96, 86, 123, 125, - /* 470 */ 96, 1, 122, 97, 96, 96, 101, 110, 101, 97, - /* 480 */ 96, 110, 97, 96, 101, 96, 98, 96, 98, 72, - /* 490 */ 9, 5, 5, 5, 5, 1, 5, 5, 5, 101, - /* 500 */ 76, 58, 72, 101, 5, 15, 5, 97, 96, 5, - /* 510 */ 5, 16, 5, 5, 128, 5, 5, 5, 5, 5, - /* 520 */ 128, 5, 58, 58, 76, 59, 58, 21, 0, 261, - /* 530 */ 21, + /* 0 */ 201, 1, 250, 200, 201, 250, 198, 199, 250, 9, + /* 10 */ 250, 259, 260, 13, 14, 201, 16, 17, 260, 259, + /* 20 */ 260, 21, 250, 1, 24, 25, 26, 27, 28, 250, + /* 30 */ 5, 9, 201, 33, 34, 201, 250, 37, 38, 39, + /* 40 */ 13, 14, 234, 16, 17, 218, 250, 233, 21, 235, + /* 50 */ 251, 24, 25, 26, 27, 28, 248, 201, 33, 34, + /* 60 */ 33, 34, 218, 236, 37, 38, 39, 45, 46, 47, + /* 70 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + /* 80 */ 236, 13, 14, 252, 16, 17, 218, 78, 254, 21, + /* 90 */ 256, 201, 24, 25, 26, 27, 28, 37, 38, 39, + /* 100 */ 100, 33, 34, 250, 236, 37, 38, 39, 14, 101, + /* 110 */ 16, 17, 256, 105, 258, 21, 201, 201, 24, 25, + /* 120 */ 26, 27, 28, 233, 97, 235, 201, 33, 34, 250, + /* 130 */ 123, 37, 38, 39, 60, 16, 17, 130, 96, 132, + /* 140 */ 21, 99, 100, 24, 25, 26, 27, 28, 233, 233, + /* 150 */ 235, 235, 33, 34, 250, 230, 37, 38, 39, 85, + /* 160 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + /* 170 */ 217, 201, 219, 220, 221, 222, 223, 224, 225, 226, + /* 180 */ 227, 228, 229, 1, 2, 1, 219, 5, 221, 7, + /* 190 */ 5, 9, 7, 9, 25, 26, 27, 28, 60, 61, + /* 200 */ 62, 44, 33, 34, 60, 235, 37, 38, 39, 64, + /* 210 */ 65, 66, 67, 68, 250, 33, 34, 1, 2, 37, + /* 220 */ 63, 5, 201, 7, 237, 9, 69, 70, 71, 63, + /* 230 */ 2, 87, 201, 5, 77, 7, 249, 9, 64, 65, + /* 240 */ 66, 67, 68, 64, 65, 66, 67, 68, 74, 33, + /* 250 */ 34, 1, 2, 37, 5, 5, 7, 7, 232, 9, + /* 260 */ 103, 33, 34, 101, 33, 34, 72, 59, 37, 38, + /* 270 */ 39, 205, 78, 1, 208, 112, 113, 256, 96, 122, + /* 280 */ 250, 119, 205, 33, 34, 208, 129, 256, 106, 205, + /* 290 */ 124, 101, 208, 127, 128, 97, 97, 97, 97, 101, + /* 300 */ 101, 101, 101, 121, 96, 250, 97, 117, 250, 37, + /* 310 */ 101, 97, 96, 250, 97, 101, 236, 5, 101, 7, + /* 320 */ 250, 5, 106, 7, 72, 73, 250, 125, 126, 250, + /* 330 */ 102, 125, 126, 250, 236, 250, 231, 121, 231, 231, + /* 340 */ 231, 231, 231, 231, 201, 257, 96, 201, 257, 201, + /* 350 */ 201, 238, 201, 201, 201, 201, 106, 201, 103, 201, + /* 360 */ 201, 201, 201, 234, 59, 201, 201, 106, 201, 201, + /* 370 */ 253, 121, 201, 201, 201, 253, 201, 201, 201, 201, + /* 380 */ 116, 201, 201, 247, 201, 118, 246, 201, 201, 201, + /* 390 */ 201, 115, 201, 201, 201, 245, 201, 110, 202, 202, + /* 400 */ 114, 109, 108, 107, 120, 202, 75, 84, 83, 49, + /* 410 */ 80, 82, 53, 81, 244, 202, 79, 202, 75, 5, + /* 420 */ 131, 5, 202, 58, 206, 206, 131, 202, 5, 131, + /* 430 */ 203, 5, 131, 58, 210, 202, 214, 216, 215, 213, + /* 440 */ 211, 209, 212, 203, 207, 234, 241, 243, 204, 242, + /* 450 */ 240, 239, 5, 131, 58, 86, 123, 104, 101, 97, + /* 460 */ 96, 1, 96, 111, 97, 111, 96, 72, 96, 101, + /* 470 */ 97, 9, 101, 96, 98, 96, 98, 5, 5, 5, + /* 480 */ 5, 1, 5, 5, 5, 101, 76, 72, 58, 126, + /* 490 */ 101, 15, 5, 5, 97, 96, 5, 16, 5, 5, + /* 500 */ 126, 5, 5, 5, 5, 5, 5, 5, 58, 58, + /* 510 */ 76, 21, 59, 21, 58, 0, 261, 261, 261, 261, + /* 520 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 530 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 540 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 550 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 560 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 570 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 580 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 590 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 600 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 610 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 620 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 630 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 640 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 650 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 660 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 670 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 680 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 690 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 700 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, + /* 710 */ 261, 261, 261, }; -#define YY_SHIFT_USE_DFLT (-83) -#define YY_SHIFT_COUNT (251) -#define YY_SHIFT_MIN (-82) -#define YY_SHIFT_MAX (528) -static const short yy_shift_ofst[] = { - /* 0 */ 140, 73, 181, 225, 20, 20, 20, 20, 20, 20, - /* 10 */ -1, 21, 225, 225, 225, 260, 260, 260, 20, 20, - /* 20 */ 20, 20, 20, 151, 153, -50, -50, -83, 191, 225, - /* 30 */ 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, - /* 40 */ 225, 225, 225, 225, 225, 225, 225, 260, 260, 120, - /* 50 */ 120, 120, 120, 120, 120, -82, 120, 20, 20, -9, - /* 60 */ -9, 188, 20, 20, 20, 20, 20, 20, 20, 20, - /* 70 */ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - /* 80 */ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - /* 90 */ 20, 20, 20, 20, 20, 236, 322, 322, 322, 282, - /* 100 */ 282, 322, 276, 284, 290, 296, 297, 301, 305, 310, - /* 110 */ 294, 314, 322, 322, 343, 343, 322, 335, 337, 372, - /* 120 */ 342, 341, 373, 346, 349, 322, 354, 322, 354, -83, - /* 130 */ -83, 26, 67, 67, 67, 67, 67, 93, 118, 211, - /* 140 */ 211, 211, -63, 168, 168, 168, 168, 187, 208, -44, - /* 150 */ 4, 59, 59, 159, 198, 201, 203, 206, 209, 212, - /* 160 */ 283, 307, 246, 238, 145, 204, 218, 221, 226, 319, - /* 170 */ 324, 189, 205, 263, 426, 303, 429, 304, 380, 434, - /* 180 */ 328, 435, 329, 397, 458, 331, 407, 381, 344, 370, - /* 190 */ 374, 345, 350, 375, 376, 378, 470, 379, 382, 384, - /* 200 */ 377, 367, 383, 371, 385, 387, 389, 388, 391, 390, - /* 210 */ 417, 481, 486, 487, 488, 489, 494, 491, 492, 493, - /* 220 */ 398, 424, 490, 430, 443, 495, 386, 392, 402, 499, - /* 230 */ 501, 410, 412, 402, 504, 505, 507, 508, 510, 511, - /* 240 */ 512, 513, 514, 516, 464, 465, 448, 506, 509, 466, - /* 250 */ 468, 528, +#define YY_SHIFT_COUNT (240) +#define YY_SHIFT_MIN (0) +#define YY_SHIFT_MAX (515) +static const unsigned short int yy_shift_ofst[] = { + /* 0 */ 157, 74, 182, 250, 184, 184, 184, 184, 184, 184, + /* 10 */ 0, 22, 250, 228, 228, 228, 184, 184, 184, 184, + /* 20 */ 184, 194, 144, 9, 9, 516, 216, 250, 250, 250, + /* 30 */ 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, + /* 40 */ 250, 250, 250, 250, 228, 228, 25, 25, 25, 25, + /* 50 */ 25, 25, 42, 25, 184, 184, 163, 163, 8, 184, + /* 60 */ 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + /* 70 */ 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + /* 80 */ 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + /* 90 */ 184, 184, 255, 305, 305, 261, 261, 305, 264, 267, + /* 100 */ 276, 287, 286, 292, 294, 296, 284, 255, 305, 305, + /* 110 */ 331, 331, 305, 323, 325, 360, 330, 329, 359, 332, + /* 120 */ 337, 305, 343, 305, 343, 516, 516, 27, 68, 68, + /* 130 */ 68, 94, 119, 169, 169, 169, 174, 231, 231, 231, + /* 140 */ 231, 145, 179, 166, 7, 60, 60, 138, 198, 199, + /* 150 */ 200, 201, 185, 249, 272, 208, 162, 190, 209, 214, + /* 160 */ 217, 312, 316, 202, 206, 252, 414, 289, 416, 295, + /* 170 */ 365, 423, 298, 426, 301, 375, 447, 322, 396, 369, + /* 180 */ 333, 353, 357, 362, 364, 460, 366, 367, 370, 368, + /* 190 */ 352, 371, 354, 373, 372, 377, 376, 379, 378, 395, + /* 200 */ 462, 472, 473, 474, 475, 480, 477, 478, 479, 384, + /* 210 */ 410, 476, 415, 430, 481, 363, 374, 389, 487, 488, + /* 220 */ 397, 399, 389, 491, 493, 494, 496, 497, 498, 499, + /* 230 */ 500, 501, 502, 450, 451, 434, 490, 492, 453, 456, + /* 240 */ 515, }; -#define YY_REDUCE_USE_DFLT (-218) -#define YY_REDUCE_COUNT (130) -#define YY_REDUCE_MIN (-217) -#define YY_REDUCE_MAX (251) +#define YY_REDUCE_COUNT (126) +#define YY_REDUCE_MIN (-248) +#define YY_REDUCE_MAX (244) static const short yy_reduce_ofst[] = { - /* 0 */ -188, -47, -202, -200, -59, -165, -121, -110, -85, -84, - /* 10 */ -60, -193, -199, -61, -217, -173, -23, -13, -15, 16, - /* 20 */ 31, -92, 8, 53, 48, 74, 75, 44, -214, -136, - /* 30 */ -120, -78, -57, -7, 36, 60, 77, 80, 89, 90, - /* 40 */ 91, 92, 94, 95, 96, 98, 99, -2, 106, 119, - /* 50 */ 121, 122, 123, 124, 125, 25, 126, 148, 150, 102, - /* 60 */ 103, 127, 160, 161, 163, 165, 166, 167, 169, 170, - /* 70 */ 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, - /* 80 */ 182, 183, 184, 185, 186, 190, 192, 193, 194, 195, - /* 90 */ 196, 197, 199, 200, 202, 109, 207, 210, 213, 137, - /* 100 */ 138, 214, 152, 158, 162, 164, 215, 217, 216, 220, - /* 110 */ 222, 219, 223, 224, 227, 228, 229, 230, 232, 231, - /* 120 */ 233, 235, 239, 237, 242, 234, 241, 240, 249, 247, - /* 130 */ 251, + /* 0 */ -192, -47, -248, -240, -144, -166, -186, -110, -85, -84, + /* 10 */ -201, -197, -242, -173, -156, -132, -169, 21, 31, -75, + /* 20 */ -30, 66, -33, 77, 84, -13, -245, -228, -221, -214, + /* 30 */ -204, -147, -121, -96, -36, 30, 55, 58, 63, 70, + /* 40 */ 76, 79, 83, 85, 80, 98, 105, 107, 108, 109, + /* 50 */ 110, 111, 26, 112, 143, 146, 88, 91, 113, 148, + /* 60 */ 149, 151, 152, 153, 154, 156, 158, 159, 160, 161, + /* 70 */ 164, 165, 167, 168, 171, 172, 173, 175, 176, 177, + /* 80 */ 178, 180, 181, 183, 186, 187, 188, 189, 191, 192, + /* 90 */ 193, 195, 129, 196, 197, 117, 122, 203, 136, 140, + /* 100 */ 150, 170, 204, 207, 205, 210, 212, 211, 213, 215, + /* 110 */ 218, 219, 220, 221, 223, 222, 224, 226, 229, 230, + /* 120 */ 232, 225, 227, 233, 240, 237, 244, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 835, 667, 819, 819, 835, 835, 835, 835, 835, 835, - /* 10 */ 749, 634, 835, 835, 819, 835, 835, 835, 835, 835, - /* 20 */ 835, 835, 835, 669, 656, 669, 669, 744, 835, 835, - /* 30 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, - /* 40 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, - /* 50 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 768, - /* 60 */ 768, 742, 835, 835, 835, 835, 835, 835, 835, 835, - /* 70 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 654, - /* 80 */ 835, 652, 835, 835, 835, 835, 835, 835, 835, 835, - /* 90 */ 835, 835, 835, 835, 835, 835, 636, 636, 636, 835, - /* 100 */ 835, 636, 775, 779, 773, 761, 769, 760, 756, 755, - /* 110 */ 783, 835, 636, 636, 664, 664, 636, 685, 683, 681, - /* 120 */ 673, 679, 675, 677, 671, 636, 662, 636, 662, 700, - /* 130 */ 713, 835, 823, 824, 784, 818, 774, 802, 801, 814, - /* 140 */ 808, 807, 835, 806, 805, 804, 803, 835, 835, 835, - /* 150 */ 835, 810, 809, 835, 835, 835, 835, 835, 835, 835, - /* 160 */ 835, 835, 835, 786, 780, 776, 835, 835, 835, 835, - /* 170 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, - /* 180 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, - /* 190 */ 835, 820, 835, 750, 835, 835, 835, 835, 835, 835, - /* 200 */ 770, 835, 762, 835, 835, 835, 835, 835, 835, 722, - /* 210 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, - /* 220 */ 688, 835, 835, 835, 835, 835, 835, 835, 828, 835, - /* 230 */ 835, 835, 716, 826, 835, 835, 835, 835, 835, 835, - /* 240 */ 835, 835, 835, 835, 835, 835, 835, 640, 638, 835, - /* 250 */ 632, 835, + /* 0 */ 604, 655, 809, 809, 604, 604, 604, 604, 604, 604, + /* 10 */ 739, 622, 809, 604, 604, 604, 604, 604, 604, 604, + /* 20 */ 604, 657, 644, 657, 657, 734, 604, 604, 604, 604, + /* 30 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, + /* 40 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, + /* 50 */ 604, 604, 604, 604, 604, 604, 758, 758, 732, 604, + /* 60 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, + /* 70 */ 604, 604, 604, 604, 604, 604, 642, 604, 640, 604, + /* 80 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, + /* 90 */ 604, 604, 604, 624, 624, 604, 604, 624, 765, 769, + /* 100 */ 763, 751, 759, 750, 746, 745, 773, 604, 624, 624, + /* 110 */ 652, 652, 624, 673, 671, 669, 661, 667, 663, 665, + /* 120 */ 659, 624, 650, 624, 650, 688, 701, 604, 774, 808, + /* 130 */ 764, 792, 791, 804, 798, 797, 604, 796, 795, 794, + /* 140 */ 793, 604, 604, 604, 604, 800, 799, 604, 604, 604, + /* 150 */ 604, 604, 604, 604, 604, 776, 770, 766, 604, 604, + /* 160 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, + /* 170 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, + /* 180 */ 604, 731, 740, 604, 604, 604, 604, 604, 604, 760, + /* 190 */ 604, 752, 604, 604, 604, 604, 604, 604, 710, 604, + /* 200 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 676, + /* 210 */ 604, 604, 604, 604, 604, 604, 604, 813, 604, 604, + /* 220 */ 604, 704, 811, 604, 604, 604, 604, 604, 604, 604, + /* 230 */ 604, 604, 604, 604, 604, 604, 628, 626, 604, 620, + /* 240 */ 604, }; /********** End of lemon-generated parsing tables *****************************/ @@ -518,6 +524,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* COMMA => nothing */ 1, /* NULL => ID */ 0, /* SELECT => nothing */ + 0, /* UNION => nothing */ 0, /* FROM => nothing */ 0, /* VARIABLE => nothing */ 0, /* INTERVAL => nothing */ @@ -535,9 +542,6 @@ static const YYCODETYPE yyFallback[] = { 0, /* SOFFSET => nothing */ 0, /* WHERE => nothing */ 1, /* NOW => ID */ - 0, /* INSERT => nothing */ - 0, /* INTO => nothing */ - 0, /* VALUES => nothing */ 0, /* RESET => nothing */ 0, /* QUERY => nothing */ 0, /* ADD => nothing */ @@ -610,6 +614,9 @@ static const YYCODETYPE yyFallback[] = { 1, /* JOIN => ID */ 1, /* METRICS => ID */ 1, /* STABLE => ID */ + 1, /* INSERT => ID */ + 1, /* INTO => ID */ + 1, /* VALUES => ID */ }; #endif /* YYFALLBACK */ @@ -641,17 +648,21 @@ typedef struct yyStackEntry yyStackEntry; /* The state of the parser is completely contained in an instance of ** the following structure */ struct yyParser { - int yyidx; /* Index of top element in stack */ + yyStackEntry *yytos; /* Pointer to top element of the stack */ #ifdef YYTRACKMAXSTACKDEPTH - int yyidxMax; /* Maximum value of yyidx */ + int yyhwm; /* High-water mark of the stack */ #endif +#ifndef YYNOERRORRECOVERY int yyerrcnt; /* Shifts left before out of the error */ +#endif ParseARG_SDECL /* A place to hold %extra_argument */ #if YYSTACKDEPTH<=0 int yystksz; /* Current side of the stack */ yyStackEntry *yystack; /* The parser's stack */ + yyStackEntry yystk0; /* First stack entry */ #else yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ + yyStackEntry *yystackEnd; /* Last entry in the stack */ #endif }; typedef struct yyParser yyParser; @@ -688,78 +699,273 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ } #endif /* NDEBUG */ -#ifndef NDEBUG +#if defined(YYCOVERAGE) || !defined(NDEBUG) /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { - "$", "ID", "BOOL", "TINYINT", - "SMALLINT", "INTEGER", "BIGINT", "FLOAT", - "DOUBLE", "STRING", "TIMESTAMP", "BINARY", - "NCHAR", "OR", "AND", "NOT", - "EQ", "NE", "ISNULL", "NOTNULL", - "IS", "LIKE", "GLOB", "BETWEEN", - "IN", "GT", "GE", "LT", - "LE", "BITAND", "BITOR", "LSHIFT", - "RSHIFT", "PLUS", "MINUS", "DIVIDE", - "TIMES", "STAR", "SLASH", "REM", - "CONCAT", "UMINUS", "UPLUS", "BITNOT", - "SHOW", "DATABASES", "MNODES", "DNODES", - "ACCOUNTS", "USERS", "MODULES", "QUERIES", - "CONNECTIONS", "STREAMS", "CONFIGS", "SCORES", - "GRANTS", "VNODES", "IPTOKEN", "DOT", - "TABLES", "STABLES", "VGROUPS", "DROP", - "TABLE", "DATABASE", "DNODE", "USER", - "ACCOUNT", "USE", "DESCRIBE", "ALTER", - "PASS", "PRIVILEGE", "LOCAL", "IF", - "EXISTS", "CREATE", "PPS", "TSERIES", - "DBS", "STORAGE", "QTIME", "CONNS", - "STATE", "KEEP", "CACHE", "REPLICA", - "DAYS", "ROWS", "ABLOCKS", "TBLOCKS", - "CTIME", "CLOG", "COMP", "PRECISION", - "LP", "RP", "TAGS", "USING", - "AS", "COMMA", "NULL", "SELECT", - "FROM", "VARIABLE", "INTERVAL", "FILL", - "SLIDING", "ORDER", "BY", "ASC", - "DESC", "GROUP", "HAVING", "LIMIT", - "OFFSET", "SLIMIT", "SOFFSET", "WHERE", - "NOW", "INSERT", "INTO", "VALUES", - "RESET", "QUERY", "ADD", "COLUMN", - "TAG", "CHANGE", "SET", "KILL", - "CONNECTION", "COLON", "STREAM", "ABORT", - "AFTER", "ATTACH", "BEFORE", "BEGIN", - "CASCADE", "CLUSTER", "CONFLICT", "COPY", - "DEFERRED", "DELIMITERS", "DETACH", "EACH", - "END", "EXPLAIN", "FAIL", "FOR", - "IGNORE", "IMMEDIATE", "INITIALLY", "INSTEAD", - "MATCH", "KEY", "OF", "RAISE", - "REPLACE", "RESTRICT", "ROW", "STATEMENT", - "TRIGGER", "VIEW", "ALL", "COUNT", - "SUM", "AVG", "MIN", "MAX", - "FIRST", "LAST", "TOP", "BOTTOM", - "STDDEV", "PERCENTILE", "APERCENTILE", "LEASTSQUARES", - "HISTOGRAM", "DIFF", "SPREAD", "TWA", - "INTERP", "LAST_ROW", "SEMI", "NONE", - "PREV", "LINEAR", "IMPORT", "METRIC", - "TBNAME", "JOIN", "METRICS", "STABLE", - "error", "program", "cmd", "dbPrefix", - "ids", "cpxName", "ifexists", "alter_db_optr", - "acct_optr", "ifnotexists", "db_optr", "pps", - "tseries", "dbs", "streams", "storage", - "qtime", "users", "conns", "state", - "keep", "tagitemlist", "tables", "cache", - "replica", "days", "rows", "ablocks", - "tblocks", "ctime", "clog", "comp", - "prec", "typename", "signed", "create_table_args", - "columnlist", "select", "column", "tagitem", - "selcollist", "from", "where_opt", "interval_opt", - "fill_opt", "sliding_opt", "groupby_opt", "orderby_opt", - "having_opt", "slimit_opt", "limit_opt", "sclp", - "expr", "as", "tablelist", "tmvar", - "sortlist", "sortitem", "item", "sortorder", - "grouplist", "exprlist", "expritem", "insert_value_list", - "itemlist", + /* 0 */ "$", + /* 1 */ "ID", + /* 2 */ "BOOL", + /* 3 */ "TINYINT", + /* 4 */ "SMALLINT", + /* 5 */ "INTEGER", + /* 6 */ "BIGINT", + /* 7 */ "FLOAT", + /* 8 */ "DOUBLE", + /* 9 */ "STRING", + /* 10 */ "TIMESTAMP", + /* 11 */ "BINARY", + /* 12 */ "NCHAR", + /* 13 */ "OR", + /* 14 */ "AND", + /* 15 */ "NOT", + /* 16 */ "EQ", + /* 17 */ "NE", + /* 18 */ "ISNULL", + /* 19 */ "NOTNULL", + /* 20 */ "IS", + /* 21 */ "LIKE", + /* 22 */ "GLOB", + /* 23 */ "BETWEEN", + /* 24 */ "IN", + /* 25 */ "GT", + /* 26 */ "GE", + /* 27 */ "LT", + /* 28 */ "LE", + /* 29 */ "BITAND", + /* 30 */ "BITOR", + /* 31 */ "LSHIFT", + /* 32 */ "RSHIFT", + /* 33 */ "PLUS", + /* 34 */ "MINUS", + /* 35 */ "DIVIDE", + /* 36 */ "TIMES", + /* 37 */ "STAR", + /* 38 */ "SLASH", + /* 39 */ "REM", + /* 40 */ "CONCAT", + /* 41 */ "UMINUS", + /* 42 */ "UPLUS", + /* 43 */ "BITNOT", + /* 44 */ "SHOW", + /* 45 */ "DATABASES", + /* 46 */ "MNODES", + /* 47 */ "DNODES", + /* 48 */ "ACCOUNTS", + /* 49 */ "USERS", + /* 50 */ "MODULES", + /* 51 */ "QUERIES", + /* 52 */ "CONNECTIONS", + /* 53 */ "STREAMS", + /* 54 */ "CONFIGS", + /* 55 */ "SCORES", + /* 56 */ "GRANTS", + /* 57 */ "VNODES", + /* 58 */ "IPTOKEN", + /* 59 */ "DOT", + /* 60 */ "TABLES", + /* 61 */ "STABLES", + /* 62 */ "VGROUPS", + /* 63 */ "DROP", + /* 64 */ "TABLE", + /* 65 */ "DATABASE", + /* 66 */ "DNODE", + /* 67 */ "USER", + /* 68 */ "ACCOUNT", + /* 69 */ "USE", + /* 70 */ "DESCRIBE", + /* 71 */ "ALTER", + /* 72 */ "PASS", + /* 73 */ "PRIVILEGE", + /* 74 */ "LOCAL", + /* 75 */ "IF", + /* 76 */ "EXISTS", + /* 77 */ "CREATE", + /* 78 */ "PPS", + /* 79 */ "TSERIES", + /* 80 */ "DBS", + /* 81 */ "STORAGE", + /* 82 */ "QTIME", + /* 83 */ "CONNS", + /* 84 */ "STATE", + /* 85 */ "KEEP", + /* 86 */ "CACHE", + /* 87 */ "REPLICA", + /* 88 */ "DAYS", + /* 89 */ "ROWS", + /* 90 */ "ABLOCKS", + /* 91 */ "TBLOCKS", + /* 92 */ "CTIME", + /* 93 */ "CLOG", + /* 94 */ "COMP", + /* 95 */ "PRECISION", + /* 96 */ "LP", + /* 97 */ "RP", + /* 98 */ "TAGS", + /* 99 */ "USING", + /* 100 */ "AS", + /* 101 */ "COMMA", + /* 102 */ "NULL", + /* 103 */ "SELECT", + /* 104 */ "UNION", + /* 105 */ "FROM", + /* 106 */ "VARIABLE", + /* 107 */ "INTERVAL", + /* 108 */ "FILL", + /* 109 */ "SLIDING", + /* 110 */ "ORDER", + /* 111 */ "BY", + /* 112 */ "ASC", + /* 113 */ "DESC", + /* 114 */ "GROUP", + /* 115 */ "HAVING", + /* 116 */ "LIMIT", + /* 117 */ "OFFSET", + /* 118 */ "SLIMIT", + /* 119 */ "SOFFSET", + /* 120 */ "WHERE", + /* 121 */ "NOW", + /* 122 */ "RESET", + /* 123 */ "QUERY", + /* 124 */ "ADD", + /* 125 */ "COLUMN", + /* 126 */ "TAG", + /* 127 */ "CHANGE", + /* 128 */ "SET", + /* 129 */ "KILL", + /* 130 */ "CONNECTION", + /* 131 */ "COLON", + /* 132 */ "STREAM", + /* 133 */ "ABORT", + /* 134 */ "AFTER", + /* 135 */ "ATTACH", + /* 136 */ "BEFORE", + /* 137 */ "BEGIN", + /* 138 */ "CASCADE", + /* 139 */ "CLUSTER", + /* 140 */ "CONFLICT", + /* 141 */ "COPY", + /* 142 */ "DEFERRED", + /* 143 */ "DELIMITERS", + /* 144 */ "DETACH", + /* 145 */ "EACH", + /* 146 */ "END", + /* 147 */ "EXPLAIN", + /* 148 */ "FAIL", + /* 149 */ "FOR", + /* 150 */ "IGNORE", + /* 151 */ "IMMEDIATE", + /* 152 */ "INITIALLY", + /* 153 */ "INSTEAD", + /* 154 */ "MATCH", + /* 155 */ "KEY", + /* 156 */ "OF", + /* 157 */ "RAISE", + /* 158 */ "REPLACE", + /* 159 */ "RESTRICT", + /* 160 */ "ROW", + /* 161 */ "STATEMENT", + /* 162 */ "TRIGGER", + /* 163 */ "VIEW", + /* 164 */ "ALL", + /* 165 */ "COUNT", + /* 166 */ "SUM", + /* 167 */ "AVG", + /* 168 */ "MIN", + /* 169 */ "MAX", + /* 170 */ "FIRST", + /* 171 */ "LAST", + /* 172 */ "TOP", + /* 173 */ "BOTTOM", + /* 174 */ "STDDEV", + /* 175 */ "PERCENTILE", + /* 176 */ "APERCENTILE", + /* 177 */ "LEASTSQUARES", + /* 178 */ "HISTOGRAM", + /* 179 */ "DIFF", + /* 180 */ "SPREAD", + /* 181 */ "TWA", + /* 182 */ "INTERP", + /* 183 */ "LAST_ROW", + /* 184 */ "SEMI", + /* 185 */ "NONE", + /* 186 */ "PREV", + /* 187 */ "LINEAR", + /* 188 */ "IMPORT", + /* 189 */ "METRIC", + /* 190 */ "TBNAME", + /* 191 */ "JOIN", + /* 192 */ "METRICS", + /* 193 */ "STABLE", + /* 194 */ "INSERT", + /* 195 */ "INTO", + /* 196 */ "VALUES", + /* 197 */ "error", + /* 198 */ "program", + /* 199 */ "cmd", + /* 200 */ "dbPrefix", + /* 201 */ "ids", + /* 202 */ "cpxName", + /* 203 */ "ifexists", + /* 204 */ "alter_db_optr", + /* 205 */ "acct_optr", + /* 206 */ "ifnotexists", + /* 207 */ "db_optr", + /* 208 */ "pps", + /* 209 */ "tseries", + /* 210 */ "dbs", + /* 211 */ "streams", + /* 212 */ "storage", + /* 213 */ "qtime", + /* 214 */ "users", + /* 215 */ "conns", + /* 216 */ "state", + /* 217 */ "keep", + /* 218 */ "tagitemlist", + /* 219 */ "tables", + /* 220 */ "cache", + /* 221 */ "replica", + /* 222 */ "days", + /* 223 */ "rows", + /* 224 */ "ablocks", + /* 225 */ "tblocks", + /* 226 */ "ctime", + /* 227 */ "clog", + /* 228 */ "comp", + /* 229 */ "prec", + /* 230 */ "typename", + /* 231 */ "signed", + /* 232 */ "create_table_args", + /* 233 */ "columnlist", + /* 234 */ "select", + /* 235 */ "column", + /* 236 */ "tagitem", + /* 237 */ "selcollist", + /* 238 */ "from", + /* 239 */ "where_opt", + /* 240 */ "interval_opt", + /* 241 */ "fill_opt", + /* 242 */ "sliding_opt", + /* 243 */ "groupby_opt", + /* 244 */ "orderby_opt", + /* 245 */ "having_opt", + /* 246 */ "slimit_opt", + /* 247 */ "limit_opt", + /* 248 */ "union", + /* 249 */ "sclp", + /* 250 */ "expr", + /* 251 */ "as", + /* 252 */ "tablelist", + /* 253 */ "tmvar", + /* 254 */ "sortlist", + /* 255 */ "sortitem", + /* 256 */ "item", + /* 257 */ "sortorder", + /* 258 */ "grouplist", + /* 259 */ "exprlist", + /* 260 */ "expritem", }; -#endif /* NDEBUG */ +#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. @@ -886,125 +1092,132 @@ static const char *const yyRuleName[] = { /* 118 */ "tagitem ::= MINUS FLOAT", /* 119 */ "tagitem ::= PLUS INTEGER", /* 120 */ "tagitem ::= PLUS FLOAT", - /* 121 */ "cmd ::= select", - /* 122 */ "select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", - /* 123 */ "select ::= SELECT selcollist", - /* 124 */ "sclp ::= selcollist COMMA", - /* 125 */ "sclp ::=", - /* 126 */ "selcollist ::= sclp expr as", - /* 127 */ "selcollist ::= sclp STAR", - /* 128 */ "as ::= AS ids", - /* 129 */ "as ::= ids", - /* 130 */ "as ::=", - /* 131 */ "from ::= FROM tablelist", - /* 132 */ "tablelist ::= ids cpxName", - /* 133 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 134 */ "tmvar ::= VARIABLE", - /* 135 */ "interval_opt ::= INTERVAL LP tmvar RP", - /* 136 */ "interval_opt ::=", - /* 137 */ "fill_opt ::=", - /* 138 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 139 */ "fill_opt ::= FILL LP ID RP", - /* 140 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 141 */ "sliding_opt ::=", - /* 142 */ "orderby_opt ::=", - /* 143 */ "orderby_opt ::= ORDER BY sortlist", - /* 144 */ "sortlist ::= sortlist COMMA item sortorder", - /* 145 */ "sortlist ::= item sortorder", - /* 146 */ "item ::= ids cpxName", - /* 147 */ "sortorder ::= ASC", - /* 148 */ "sortorder ::= DESC", - /* 149 */ "sortorder ::=", - /* 150 */ "groupby_opt ::=", - /* 151 */ "groupby_opt ::= GROUP BY grouplist", - /* 152 */ "grouplist ::= grouplist COMMA item", - /* 153 */ "grouplist ::= item", - /* 154 */ "having_opt ::=", - /* 155 */ "having_opt ::= HAVING expr", - /* 156 */ "limit_opt ::=", - /* 157 */ "limit_opt ::= LIMIT signed", - /* 158 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 159 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 160 */ "slimit_opt ::=", - /* 161 */ "slimit_opt ::= SLIMIT signed", - /* 162 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 163 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 164 */ "where_opt ::=", - /* 165 */ "where_opt ::= WHERE expr", - /* 166 */ "expr ::= LP expr RP", - /* 167 */ "expr ::= ID", - /* 168 */ "expr ::= ID DOT ID", - /* 169 */ "expr ::= ID DOT STAR", - /* 170 */ "expr ::= INTEGER", - /* 171 */ "expr ::= MINUS INTEGER", - /* 172 */ "expr ::= PLUS INTEGER", - /* 173 */ "expr ::= FLOAT", - /* 174 */ "expr ::= MINUS FLOAT", - /* 175 */ "expr ::= PLUS FLOAT", - /* 176 */ "expr ::= STRING", - /* 177 */ "expr ::= NOW", - /* 178 */ "expr ::= VARIABLE", - /* 179 */ "expr ::= BOOL", - /* 180 */ "expr ::= ID LP exprlist RP", - /* 181 */ "expr ::= ID LP STAR RP", - /* 182 */ "expr ::= expr AND expr", - /* 183 */ "expr ::= expr OR expr", - /* 184 */ "expr ::= expr LT expr", - /* 185 */ "expr ::= expr GT expr", - /* 186 */ "expr ::= expr LE expr", - /* 187 */ "expr ::= expr GE expr", - /* 188 */ "expr ::= expr NE expr", - /* 189 */ "expr ::= expr EQ expr", - /* 190 */ "expr ::= expr PLUS expr", - /* 191 */ "expr ::= expr MINUS expr", - /* 192 */ "expr ::= expr STAR expr", - /* 193 */ "expr ::= expr SLASH expr", - /* 194 */ "expr ::= expr REM expr", - /* 195 */ "expr ::= expr LIKE expr", - /* 196 */ "expr ::= expr IN LP exprlist RP", - /* 197 */ "exprlist ::= exprlist COMMA expritem", - /* 198 */ "exprlist ::= expritem", - /* 199 */ "expritem ::= expr", - /* 200 */ "expritem ::=", - /* 201 */ "cmd ::= INSERT INTO cpxName insert_value_list", - /* 202 */ "insert_value_list ::= VALUES LP itemlist RP", - /* 203 */ "insert_value_list ::= insert_value_list VALUES LP itemlist RP", - /* 204 */ "itemlist ::= itemlist COMMA expr", - /* 205 */ "itemlist ::= expr", - /* 206 */ "cmd ::= RESET QUERY CACHE", - /* 207 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 208 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 209 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 210 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 211 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 212 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 213 */ "cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER", - /* 214 */ "cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER", - /* 215 */ "cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER", + /* 121 */ "select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", + /* 122 */ "union ::= select", + /* 123 */ "union ::= union UNION select", + /* 124 */ "cmd ::= union", + /* 125 */ "select ::= SELECT selcollist", + /* 126 */ "sclp ::= selcollist COMMA", + /* 127 */ "sclp ::=", + /* 128 */ "selcollist ::= sclp expr as", + /* 129 */ "selcollist ::= sclp STAR", + /* 130 */ "as ::= AS ids", + /* 131 */ "as ::= ids", + /* 132 */ "as ::=", + /* 133 */ "from ::= FROM tablelist", + /* 134 */ "tablelist ::= ids cpxName", + /* 135 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 136 */ "tmvar ::= VARIABLE", + /* 137 */ "interval_opt ::= INTERVAL LP tmvar RP", + /* 138 */ "interval_opt ::=", + /* 139 */ "fill_opt ::=", + /* 140 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 141 */ "fill_opt ::= FILL LP ID RP", + /* 142 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 143 */ "sliding_opt ::=", + /* 144 */ "orderby_opt ::=", + /* 145 */ "orderby_opt ::= ORDER BY sortlist", + /* 146 */ "sortlist ::= sortlist COMMA item sortorder", + /* 147 */ "sortlist ::= item sortorder", + /* 148 */ "item ::= ids cpxName", + /* 149 */ "sortorder ::= ASC", + /* 150 */ "sortorder ::= DESC", + /* 151 */ "sortorder ::=", + /* 152 */ "groupby_opt ::=", + /* 153 */ "groupby_opt ::= GROUP BY grouplist", + /* 154 */ "grouplist ::= grouplist COMMA item", + /* 155 */ "grouplist ::= item", + /* 156 */ "having_opt ::=", + /* 157 */ "having_opt ::= HAVING expr", + /* 158 */ "limit_opt ::=", + /* 159 */ "limit_opt ::= LIMIT signed", + /* 160 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 161 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 162 */ "slimit_opt ::=", + /* 163 */ "slimit_opt ::= SLIMIT signed", + /* 164 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 165 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 166 */ "where_opt ::=", + /* 167 */ "where_opt ::= WHERE expr", + /* 168 */ "expr ::= LP expr RP", + /* 169 */ "expr ::= ID", + /* 170 */ "expr ::= ID DOT ID", + /* 171 */ "expr ::= ID DOT STAR", + /* 172 */ "expr ::= INTEGER", + /* 173 */ "expr ::= MINUS INTEGER", + /* 174 */ "expr ::= PLUS INTEGER", + /* 175 */ "expr ::= FLOAT", + /* 176 */ "expr ::= MINUS FLOAT", + /* 177 */ "expr ::= PLUS FLOAT", + /* 178 */ "expr ::= STRING", + /* 179 */ "expr ::= NOW", + /* 180 */ "expr ::= VARIABLE", + /* 181 */ "expr ::= BOOL", + /* 182 */ "expr ::= ID LP exprlist RP", + /* 183 */ "expr ::= ID LP STAR RP", + /* 184 */ "expr ::= expr AND expr", + /* 185 */ "expr ::= expr OR expr", + /* 186 */ "expr ::= expr LT expr", + /* 187 */ "expr ::= expr GT expr", + /* 188 */ "expr ::= expr LE expr", + /* 189 */ "expr ::= expr GE expr", + /* 190 */ "expr ::= expr NE expr", + /* 191 */ "expr ::= expr EQ expr", + /* 192 */ "expr ::= expr PLUS expr", + /* 193 */ "expr ::= expr MINUS expr", + /* 194 */ "expr ::= expr STAR expr", + /* 195 */ "expr ::= expr SLASH expr", + /* 196 */ "expr ::= expr REM expr", + /* 197 */ "expr ::= expr LIKE expr", + /* 198 */ "expr ::= expr IN LP exprlist RP", + /* 199 */ "exprlist ::= exprlist COMMA expritem", + /* 200 */ "exprlist ::= expritem", + /* 201 */ "expritem ::= expr", + /* 202 */ "expritem ::=", + /* 203 */ "cmd ::= RESET QUERY CACHE", + /* 204 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 205 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 206 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 207 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 208 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 209 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 210 */ "cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER", + /* 211 */ "cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER", + /* 212 */ "cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER", }; #endif /* NDEBUG */ #if YYSTACKDEPTH<=0 /* -** Try to increase the size of the parser stack. +** Try to increase the size of the parser stack. Return the number +** of errors. Return 0 on success. */ -static void yyGrowStack(yyParser *p){ +static int yyGrowStack(yyParser *p){ int newSize; + int idx; yyStackEntry *pNew; newSize = p->yystksz*2 + 100; - pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; + if( p->yystack==&p->yystk0 ){ + pNew = malloc(newSize*sizeof(pNew[0])); + if( pNew ) pNew[0] = p->yystk0; + }else{ + pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + } if( pNew ){ p->yystack = pNew; - p->yystksz = newSize; + p->yytos = &p->yystack[idx]; #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", - yyTracePrompt, p->yystksz); + fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", + yyTracePrompt, p->yystksz, newSize); } #endif + p->yystksz = newSize; } + return pNew==0; } #endif @@ -1017,6 +1230,34 @@ static void yyGrowStack(yyParser *p){ # define YYMALLOCARGTYPE size_t #endif +/* Initialize a new parser that has already been allocated. +*/ +void ParseInit(void *yypParser){ + yyParser *pParser = (yyParser*)yypParser; +#ifdef YYTRACKMAXSTACKDEPTH + pParser->yyhwm = 0; +#endif +#if YYSTACKDEPTH<=0 + pParser->yytos = NULL; + pParser->yystack = NULL; + pParser->yystksz = 0; + if( yyGrowStack(pParser) ){ + pParser->yystack = &pParser->yystk0; + pParser->yystksz = 1; + } +#endif +#ifndef YYNOERRORRECOVERY + pParser->yyerrcnt = -1; +#endif + pParser->yytos = pParser->yystack; + pParser->yystack[0].stateno = 0; + pParser->yystack[0].major = 0; +#if YYSTACKDEPTH>0 + pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1]; +#endif +} + +#ifndef Parse_ENGINEALWAYSONSTACK /* ** This function allocates a new parser. ** The only argument is a pointer to a function which works like @@ -1032,19 +1273,11 @@ static void yyGrowStack(yyParser *p){ void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ yyParser *pParser; pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; -#ifdef YYTRACKMAXSTACKDEPTH - pParser->yyidxMax = 0; -#endif -#if YYSTACKDEPTH<=0 - pParser->yystack = NULL; - pParser->yystksz = 0; - yyGrowStack(pParser); -#endif - } + if( pParser ) ParseInit(pParser); return pParser; } +#endif /* Parse_ENGINEALWAYSONSTACK */ + /* The following function deletes the "minor type" or semantic value ** associated with a symbol. The symbol can be either a terminal @@ -1071,44 +1304,48 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 216: /* keep */ - case 217: /* tagitemlist */ - case 240: /* fill_opt */ - case 242: /* groupby_opt */ - case 243: /* orderby_opt */ - case 252: /* sortlist */ - case 256: /* grouplist */ + case 217: /* keep */ + case 218: /* tagitemlist */ + case 241: /* fill_opt */ + case 243: /* groupby_opt */ + case 244: /* orderby_opt */ + case 254: /* sortlist */ + case 258: /* grouplist */ { tVariantListDestroy((yypminor->yy480)); } break; - case 232: /* columnlist */ + case 233: /* columnlist */ { tFieldListDestroy((yypminor->yy421)); } break; - case 233: /* select */ + case 234: /* select */ { -destroyQuerySql((yypminor->yy138)); +doDestroyQuerySql((yypminor->yy138)); } break; - case 236: /* selcollist */ - case 247: /* sclp */ - case 257: /* exprlist */ - case 260: /* itemlist */ + case 237: /* selcollist */ + case 249: /* sclp */ + case 259: /* exprlist */ { tSQLExprListDestroy((yypminor->yy284)); } break; - case 238: /* where_opt */ - case 244: /* having_opt */ - case 248: /* expr */ - case 258: /* expritem */ + case 239: /* where_opt */ + case 245: /* having_opt */ + case 250: /* expr */ + case 260: /* expritem */ { tSQLExprDestroy((yypminor->yy244)); } break; - case 253: /* sortitem */ + case 248: /* union */ +{ +destroyAllSelectClause((yypminor->yy117)); +} + break; + case 255: /* sortitem */ { tVariantDestroy(&(yypminor->yy236)); } @@ -1126,8 +1363,9 @@ tVariantDestroy(&(yypminor->yy236)); */ static void yy_pop_parser_stack(yyParser *pParser){ yyStackEntry *yytos; - assert( pParser->yyidx>=0 ); - yytos = &pParser->yystack[pParser->yyidx--]; + assert( pParser->yytos!=0 ); + assert( pParser->yytos > pParser->yystack ); + yytos = pParser->yytos--; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", @@ -1138,6 +1376,18 @@ static void yy_pop_parser_stack(yyParser *pParser){ yy_destructor(pParser, yytos->major, &yytos->minor); } +/* +** Clear all secondary memory allocations from the parser +*/ +void ParseFinalize(void *p){ + yyParser *pParser = (yyParser*)p; + while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); +#if YYSTACKDEPTH<=0 + if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); +#endif +} + +#ifndef Parse_ENGINEALWAYSONSTACK /* ** Deallocate and destroy a parser. Destructors are called for ** all stack elements before shutting the parser down. @@ -1150,16 +1400,13 @@ void ParseFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ ){ - yyParser *pParser = (yyParser*)p; #ifndef YYPARSEFREENEVERNULL - if( pParser==0 ) return; -#endif - while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); -#if YYSTACKDEPTH<=0 - free(pParser->yystack); + if( p==0 ) return; #endif - (*freeProc)((void*)pParser); + ParseFinalize(p); + (*freeProc)(p); } +#endif /* Parse_ENGINEALWAYSONSTACK */ /* ** Return the peak depth of the stack for a parser. @@ -1167,7 +1414,44 @@ void ParseFree( #ifdef YYTRACKMAXSTACKDEPTH int ParseStackPeak(void *p){ yyParser *pParser = (yyParser*)p; - return pParser->yyidxMax; + return pParser->yyhwm; +} +#endif + +/* This array of booleans keeps track of the parser statement +** coverage. The element yycoverage[X][Y] is set when the parser +** is in state X and has a lookahead token Y. In a well-tested +** systems, every element of this matrix should end up being set. +*/ +#if defined(YYCOVERAGE) +static unsigned char yycoverage[YYNSTATE][YYNTOKEN]; +#endif + +/* +** Write into out a description of every state/lookahead combination that +** +** (1) has not been used by the parser, and +** (2) is not a syntax error. +** +** Return the number of missed state/lookahead combinations. +*/ +#if defined(YYCOVERAGE) +int ParseCoverage(FILE *out){ + int stateno, iLookAhead, i; + int nMissed = 0; + for(stateno=0; statenoyystack[pParser->yyidx].stateno; + int stateno = pParser->yytos->stateno; - if( stateno>=YY_MIN_REDUCE ) return stateno; + if( stateno>YY_MAX_SHIFT ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); +#if defined(YYCOVERAGE) + yycoverage[stateno][iLookAhead] = 1; +#endif do{ i = yy_shift_ofst[stateno]; - if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; + assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); assert( iLookAhead!=YYNOCODE ); + assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ + if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK - YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ - iLookAhead = iFallback; - continue; + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); } +#endif + assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ + iLookAhead = iFallback; + continue; + } #endif #ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( + { + int j = i - iLookAhead + YYWILDCARD; + if( #if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && + j>=0 && #endif #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j0 + ){ #ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", - yyTracePrompt, yyTokenName[iLookAhead], - yyTokenName[YYWILDCARD]); - } -#endif /* NDEBUG */ - return yy_action[j]; + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], + yyTokenName[YYWILDCARD]); } +#endif /* NDEBUG */ + return yy_action[j]; } -#endif /* YYWILDCARD */ } +#endif /* YYWILDCARD */ return yy_default[stateno]; }else{ return yy_action[i]; @@ -1254,7 +1540,6 @@ static int yy_find_reduce_action( assert( stateno<=YY_REDUCE_COUNT ); #endif i = yy_reduce_ofst[stateno]; - assert( i!=YY_REDUCE_USE_DFLT ); assert( iLookAhead!=YYNOCODE ); i += iLookAhead; #ifdef YYERRORSYMBOL @@ -1271,15 +1556,14 @@ static int yy_find_reduce_action( /* ** The following routine is called if the stack overflows. */ -static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ +static void yyStackOverflow(yyParser *yypParser){ ParseARG_FETCH; - yypParser->yyidx--; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will execute if the parser ** stack every overflows */ /******** Begin %stack_overflow code ******************************************/ @@ -1291,20 +1575,21 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ ** Print tracing information for a SHIFT action */ #ifndef NDEBUG -static void yyTraceShift(yyParser *yypParser, int yyNewState){ +static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){ if( yyTraceFILE ){ if( yyNewStateyystack[yypParser->yyidx].major], + fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n", + yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], yyNewState); }else{ - fprintf(yyTraceFILE,"%sShift '%s'\n", - yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]); + fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n", + yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], + yyNewState - YY_MIN_REDUCE); } } } #else -# define yyTraceShift(X,Y) +# define yyTraceShift(X,Y,Z) #endif /* @@ -1314,259 +1599,261 @@ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ int yyNewState, /* The new state to shift in */ int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ + ParseTOKENTYPE yyMinor /* The minor token to shift in */ ){ yyStackEntry *yytos; - yypParser->yyidx++; + yypParser->yytos++; #ifdef YYTRACKMAXSTACKDEPTH - if( yypParser->yyidx>yypParser->yyidxMax ){ - yypParser->yyidxMax = yypParser->yyidx; + if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); } #endif #if YYSTACKDEPTH>0 - if( yypParser->yyidx>=YYSTACKDEPTH ){ - yyStackOverflow(yypParser, yypMinor); + if( yypParser->yytos>yypParser->yystackEnd ){ + yypParser->yytos--; + yyStackOverflow(yypParser); return; } #else - if( yypParser->yyidx>=yypParser->yystksz ){ - yyGrowStack(yypParser); - if( yypParser->yyidx>=yypParser->yystksz ){ - yyStackOverflow(yypParser, yypMinor); + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ + if( yyGrowStack(yypParser) ){ + yypParser->yytos--; + yyStackOverflow(yypParser); return; } } #endif - yytos = &yypParser->yystack[yypParser->yyidx]; + if( yyNewState > YY_MAX_SHIFT ){ + yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; + } + yytos = yypParser->yytos; yytos->stateno = (YYACTIONTYPE)yyNewState; yytos->major = (YYCODETYPE)yyMajor; - yytos->minor = *yypMinor; - yyTraceShift(yypParser, yyNewState); + yytos->minor.yy0 = yyMinor; + yyTraceShift(yypParser, yyNewState, "Shift"); } /* The following table contains information about every rule that ** is used during the reduce. */ static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 197, 1 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 2 }, - { 198, 3 }, - { 199, 0 }, - { 199, 2 }, - { 201, 0 }, - { 201, 2 }, - { 198, 3 }, - { 198, 5 }, - { 198, 3 }, - { 198, 5 }, - { 198, 3 }, - { 198, 5 }, - { 198, 4 }, - { 198, 3 }, - { 198, 3 }, - { 198, 3 }, - { 198, 2 }, - { 198, 3 }, - { 198, 5 }, - { 198, 5 }, - { 198, 4 }, - { 198, 5 }, - { 198, 3 }, - { 198, 4 }, - { 198, 4 }, - { 198, 4 }, - { 198, 6 }, - { 200, 1 }, - { 200, 1 }, - { 202, 2 }, - { 202, 0 }, - { 205, 3 }, - { 205, 0 }, - { 198, 3 }, - { 198, 6 }, - { 198, 5 }, - { 198, 5 }, - { 207, 0 }, - { 207, 2 }, - { 208, 0 }, - { 208, 2 }, - { 209, 0 }, - { 209, 2 }, - { 210, 0 }, - { 210, 2 }, - { 211, 0 }, - { 211, 2 }, - { 212, 0 }, - { 212, 2 }, - { 213, 0 }, - { 213, 2 }, - { 214, 0 }, - { 214, 2 }, - { 215, 0 }, - { 215, 2 }, - { 204, 9 }, - { 216, 2 }, - { 218, 2 }, - { 219, 2 }, - { 220, 2 }, - { 221, 2 }, - { 222, 2 }, - { 223, 2 }, - { 224, 2 }, - { 225, 2 }, - { 226, 2 }, - { 227, 2 }, - { 228, 2 }, - { 206, 0 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 206, 2 }, - { 203, 0 }, - { 203, 2 }, - { 203, 2 }, - { 229, 1 }, - { 229, 4 }, - { 230, 1 }, - { 230, 2 }, - { 230, 2 }, - { 198, 6 }, - { 231, 3 }, - { 231, 7 }, - { 231, 7 }, - { 231, 2 }, - { 232, 3 }, - { 232, 1 }, - { 234, 2 }, - { 217, 3 }, - { 217, 1 }, - { 235, 1 }, - { 235, 1 }, - { 235, 1 }, - { 235, 1 }, - { 235, 1 }, - { 235, 2 }, - { 235, 2 }, - { 235, 2 }, - { 235, 2 }, - { 198, 1 }, - { 233, 12 }, - { 233, 2 }, - { 247, 2 }, - { 247, 0 }, - { 236, 3 }, - { 236, 2 }, - { 249, 2 }, - { 249, 1 }, - { 249, 0 }, - { 237, 2 }, - { 250, 2 }, - { 250, 4 }, - { 251, 1 }, - { 239, 4 }, - { 239, 0 }, - { 240, 0 }, - { 240, 6 }, - { 240, 4 }, - { 241, 4 }, - { 241, 0 }, - { 243, 0 }, - { 243, 3 }, - { 252, 4 }, - { 252, 2 }, - { 254, 2 }, - { 255, 1 }, - { 255, 1 }, - { 255, 0 }, - { 242, 0 }, - { 242, 3 }, - { 256, 3 }, - { 256, 1 }, - { 244, 0 }, - { 244, 2 }, - { 246, 0 }, - { 246, 2 }, - { 246, 4 }, - { 246, 4 }, - { 245, 0 }, - { 245, 2 }, - { 245, 4 }, - { 245, 4 }, - { 238, 0 }, - { 238, 2 }, - { 248, 3 }, - { 248, 1 }, - { 248, 3 }, - { 248, 3 }, - { 248, 1 }, - { 248, 2 }, - { 248, 2 }, - { 248, 1 }, - { 248, 2 }, - { 248, 2 }, - { 248, 1 }, - { 248, 1 }, - { 248, 1 }, - { 248, 1 }, - { 248, 4 }, - { 248, 4 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 3 }, - { 248, 5 }, - { 257, 3 }, - { 257, 1 }, - { 258, 1 }, - { 258, 0 }, - { 198, 4 }, - { 259, 4 }, - { 259, 5 }, - { 260, 3 }, - { 260, 1 }, - { 198, 3 }, - { 198, 7 }, - { 198, 7 }, - { 198, 7 }, - { 198, 7 }, - { 198, 8 }, - { 198, 9 }, - { 198, 5 }, - { 198, 7 }, - { 198, 7 }, + { 198, -1 }, /* (0) program ::= cmd */ + { 199, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 199, -2 }, /* (2) cmd ::= SHOW MNODES */ + { 199, -2 }, /* (3) cmd ::= SHOW DNODES */ + { 199, -2 }, /* (4) cmd ::= SHOW ACCOUNTS */ + { 199, -2 }, /* (5) cmd ::= SHOW USERS */ + { 199, -2 }, /* (6) cmd ::= SHOW MODULES */ + { 199, -2 }, /* (7) cmd ::= SHOW QUERIES */ + { 199, -2 }, /* (8) cmd ::= SHOW CONNECTIONS */ + { 199, -2 }, /* (9) cmd ::= SHOW STREAMS */ + { 199, -2 }, /* (10) cmd ::= SHOW CONFIGS */ + { 199, -2 }, /* (11) cmd ::= SHOW SCORES */ + { 199, -2 }, /* (12) cmd ::= SHOW GRANTS */ + { 199, -2 }, /* (13) cmd ::= SHOW VNODES */ + { 199, -3 }, /* (14) cmd ::= SHOW VNODES IPTOKEN */ + { 200, 0 }, /* (15) dbPrefix ::= */ + { 200, -2 }, /* (16) dbPrefix ::= ids DOT */ + { 202, 0 }, /* (17) cpxName ::= */ + { 202, -2 }, /* (18) cpxName ::= DOT ids */ + { 199, -3 }, /* (19) cmd ::= SHOW dbPrefix TABLES */ + { 199, -5 }, /* (20) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 199, -3 }, /* (21) cmd ::= SHOW dbPrefix STABLES */ + { 199, -5 }, /* (22) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 199, -3 }, /* (23) cmd ::= SHOW dbPrefix VGROUPS */ + { 199, -5 }, /* (24) cmd ::= DROP TABLE ifexists ids cpxName */ + { 199, -4 }, /* (25) cmd ::= DROP DATABASE ifexists ids */ + { 199, -3 }, /* (26) cmd ::= DROP DNODE IPTOKEN */ + { 199, -3 }, /* (27) cmd ::= DROP USER ids */ + { 199, -3 }, /* (28) cmd ::= DROP ACCOUNT ids */ + { 199, -2 }, /* (29) cmd ::= USE ids */ + { 199, -3 }, /* (30) cmd ::= DESCRIBE ids cpxName */ + { 199, -5 }, /* (31) cmd ::= ALTER USER ids PASS ids */ + { 199, -5 }, /* (32) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 199, -4 }, /* (33) cmd ::= ALTER DNODE IPTOKEN ids */ + { 199, -5 }, /* (34) cmd ::= ALTER DNODE IPTOKEN ids ids */ + { 199, -3 }, /* (35) cmd ::= ALTER LOCAL ids */ + { 199, -4 }, /* (36) cmd ::= ALTER LOCAL ids ids */ + { 199, -4 }, /* (37) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 199, -4 }, /* (38) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 199, -6 }, /* (39) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 201, -1 }, /* (40) ids ::= ID */ + { 201, -1 }, /* (41) ids ::= STRING */ + { 203, -2 }, /* (42) ifexists ::= IF EXISTS */ + { 203, 0 }, /* (43) ifexists ::= */ + { 206, -3 }, /* (44) ifnotexists ::= IF NOT EXISTS */ + { 206, 0 }, /* (45) ifnotexists ::= */ + { 199, -3 }, /* (46) cmd ::= CREATE DNODE IPTOKEN */ + { 199, -6 }, /* (47) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 199, -5 }, /* (48) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 199, -5 }, /* (49) cmd ::= CREATE USER ids PASS ids */ + { 208, 0 }, /* (50) pps ::= */ + { 208, -2 }, /* (51) pps ::= PPS INTEGER */ + { 209, 0 }, /* (52) tseries ::= */ + { 209, -2 }, /* (53) tseries ::= TSERIES INTEGER */ + { 210, 0 }, /* (54) dbs ::= */ + { 210, -2 }, /* (55) dbs ::= DBS INTEGER */ + { 211, 0 }, /* (56) streams ::= */ + { 211, -2 }, /* (57) streams ::= STREAMS INTEGER */ + { 212, 0 }, /* (58) storage ::= */ + { 212, -2 }, /* (59) storage ::= STORAGE INTEGER */ + { 213, 0 }, /* (60) qtime ::= */ + { 213, -2 }, /* (61) qtime ::= QTIME INTEGER */ + { 214, 0 }, /* (62) users ::= */ + { 214, -2 }, /* (63) users ::= USERS INTEGER */ + { 215, 0 }, /* (64) conns ::= */ + { 215, -2 }, /* (65) conns ::= CONNS INTEGER */ + { 216, 0 }, /* (66) state ::= */ + { 216, -2 }, /* (67) state ::= STATE ids */ + { 205, -9 }, /* (68) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 217, -2 }, /* (69) keep ::= KEEP tagitemlist */ + { 219, -2 }, /* (70) tables ::= TABLES INTEGER */ + { 220, -2 }, /* (71) cache ::= CACHE INTEGER */ + { 221, -2 }, /* (72) replica ::= REPLICA INTEGER */ + { 222, -2 }, /* (73) days ::= DAYS INTEGER */ + { 223, -2 }, /* (74) rows ::= ROWS INTEGER */ + { 224, -2 }, /* (75) ablocks ::= ABLOCKS ID */ + { 225, -2 }, /* (76) tblocks ::= TBLOCKS INTEGER */ + { 226, -2 }, /* (77) ctime ::= CTIME INTEGER */ + { 227, -2 }, /* (78) clog ::= CLOG INTEGER */ + { 228, -2 }, /* (79) comp ::= COMP INTEGER */ + { 229, -2 }, /* (80) prec ::= PRECISION STRING */ + { 207, 0 }, /* (81) db_optr ::= */ + { 207, -2 }, /* (82) db_optr ::= db_optr tables */ + { 207, -2 }, /* (83) db_optr ::= db_optr cache */ + { 207, -2 }, /* (84) db_optr ::= db_optr replica */ + { 207, -2 }, /* (85) db_optr ::= db_optr days */ + { 207, -2 }, /* (86) db_optr ::= db_optr rows */ + { 207, -2 }, /* (87) db_optr ::= db_optr ablocks */ + { 207, -2 }, /* (88) db_optr ::= db_optr tblocks */ + { 207, -2 }, /* (89) db_optr ::= db_optr ctime */ + { 207, -2 }, /* (90) db_optr ::= db_optr clog */ + { 207, -2 }, /* (91) db_optr ::= db_optr comp */ + { 207, -2 }, /* (92) db_optr ::= db_optr prec */ + { 207, -2 }, /* (93) db_optr ::= db_optr keep */ + { 204, 0 }, /* (94) alter_db_optr ::= */ + { 204, -2 }, /* (95) alter_db_optr ::= alter_db_optr replica */ + { 204, -2 }, /* (96) alter_db_optr ::= alter_db_optr tables */ + { 230, -1 }, /* (97) typename ::= ids */ + { 230, -4 }, /* (98) typename ::= ids LP signed RP */ + { 231, -1 }, /* (99) signed ::= INTEGER */ + { 231, -2 }, /* (100) signed ::= PLUS INTEGER */ + { 231, -2 }, /* (101) signed ::= MINUS INTEGER */ + { 199, -6 }, /* (102) cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ + { 232, -3 }, /* (103) create_table_args ::= LP columnlist RP */ + { 232, -7 }, /* (104) create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ + { 232, -7 }, /* (105) create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ + { 232, -2 }, /* (106) create_table_args ::= AS select */ + { 233, -3 }, /* (107) columnlist ::= columnlist COMMA column */ + { 233, -1 }, /* (108) columnlist ::= column */ + { 235, -2 }, /* (109) column ::= ids typename */ + { 218, -3 }, /* (110) tagitemlist ::= tagitemlist COMMA tagitem */ + { 218, -1 }, /* (111) tagitemlist ::= tagitem */ + { 236, -1 }, /* (112) tagitem ::= INTEGER */ + { 236, -1 }, /* (113) tagitem ::= FLOAT */ + { 236, -1 }, /* (114) tagitem ::= STRING */ + { 236, -1 }, /* (115) tagitem ::= BOOL */ + { 236, -1 }, /* (116) tagitem ::= NULL */ + { 236, -2 }, /* (117) tagitem ::= MINUS INTEGER */ + { 236, -2 }, /* (118) tagitem ::= MINUS FLOAT */ + { 236, -2 }, /* (119) tagitem ::= PLUS INTEGER */ + { 236, -2 }, /* (120) tagitem ::= PLUS FLOAT */ + { 234, -12 }, /* (121) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + { 248, -1 }, /* (122) union ::= select */ + { 248, -3 }, /* (123) union ::= union UNION select */ + { 199, -1 }, /* (124) cmd ::= union */ + { 234, -2 }, /* (125) select ::= SELECT selcollist */ + { 249, -2 }, /* (126) sclp ::= selcollist COMMA */ + { 249, 0 }, /* (127) sclp ::= */ + { 237, -3 }, /* (128) selcollist ::= sclp expr as */ + { 237, -2 }, /* (129) selcollist ::= sclp STAR */ + { 251, -2 }, /* (130) as ::= AS ids */ + { 251, -1 }, /* (131) as ::= ids */ + { 251, 0 }, /* (132) as ::= */ + { 238, -2 }, /* (133) from ::= FROM tablelist */ + { 252, -2 }, /* (134) tablelist ::= ids cpxName */ + { 252, -4 }, /* (135) tablelist ::= tablelist COMMA ids cpxName */ + { 253, -1 }, /* (136) tmvar ::= VARIABLE */ + { 240, -4 }, /* (137) interval_opt ::= INTERVAL LP tmvar RP */ + { 240, 0 }, /* (138) interval_opt ::= */ + { 241, 0 }, /* (139) fill_opt ::= */ + { 241, -6 }, /* (140) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 241, -4 }, /* (141) fill_opt ::= FILL LP ID RP */ + { 242, -4 }, /* (142) sliding_opt ::= SLIDING LP tmvar RP */ + { 242, 0 }, /* (143) sliding_opt ::= */ + { 244, 0 }, /* (144) orderby_opt ::= */ + { 244, -3 }, /* (145) orderby_opt ::= ORDER BY sortlist */ + { 254, -4 }, /* (146) sortlist ::= sortlist COMMA item sortorder */ + { 254, -2 }, /* (147) sortlist ::= item sortorder */ + { 256, -2 }, /* (148) item ::= ids cpxName */ + { 257, -1 }, /* (149) sortorder ::= ASC */ + { 257, -1 }, /* (150) sortorder ::= DESC */ + { 257, 0 }, /* (151) sortorder ::= */ + { 243, 0 }, /* (152) groupby_opt ::= */ + { 243, -3 }, /* (153) groupby_opt ::= GROUP BY grouplist */ + { 258, -3 }, /* (154) grouplist ::= grouplist COMMA item */ + { 258, -1 }, /* (155) grouplist ::= item */ + { 245, 0 }, /* (156) having_opt ::= */ + { 245, -2 }, /* (157) having_opt ::= HAVING expr */ + { 247, 0 }, /* (158) limit_opt ::= */ + { 247, -2 }, /* (159) limit_opt ::= LIMIT signed */ + { 247, -4 }, /* (160) limit_opt ::= LIMIT signed OFFSET signed */ + { 247, -4 }, /* (161) limit_opt ::= LIMIT signed COMMA signed */ + { 246, 0 }, /* (162) slimit_opt ::= */ + { 246, -2 }, /* (163) slimit_opt ::= SLIMIT signed */ + { 246, -4 }, /* (164) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 246, -4 }, /* (165) slimit_opt ::= SLIMIT signed COMMA signed */ + { 239, 0 }, /* (166) where_opt ::= */ + { 239, -2 }, /* (167) where_opt ::= WHERE expr */ + { 250, -3 }, /* (168) expr ::= LP expr RP */ + { 250, -1 }, /* (169) expr ::= ID */ + { 250, -3 }, /* (170) expr ::= ID DOT ID */ + { 250, -3 }, /* (171) expr ::= ID DOT STAR */ + { 250, -1 }, /* (172) expr ::= INTEGER */ + { 250, -2 }, /* (173) expr ::= MINUS INTEGER */ + { 250, -2 }, /* (174) expr ::= PLUS INTEGER */ + { 250, -1 }, /* (175) expr ::= FLOAT */ + { 250, -2 }, /* (176) expr ::= MINUS FLOAT */ + { 250, -2 }, /* (177) expr ::= PLUS FLOAT */ + { 250, -1 }, /* (178) expr ::= STRING */ + { 250, -1 }, /* (179) expr ::= NOW */ + { 250, -1 }, /* (180) expr ::= VARIABLE */ + { 250, -1 }, /* (181) expr ::= BOOL */ + { 250, -4 }, /* (182) expr ::= ID LP exprlist RP */ + { 250, -4 }, /* (183) expr ::= ID LP STAR RP */ + { 250, -3 }, /* (184) expr ::= expr AND expr */ + { 250, -3 }, /* (185) expr ::= expr OR expr */ + { 250, -3 }, /* (186) expr ::= expr LT expr */ + { 250, -3 }, /* (187) expr ::= expr GT expr */ + { 250, -3 }, /* (188) expr ::= expr LE expr */ + { 250, -3 }, /* (189) expr ::= expr GE expr */ + { 250, -3 }, /* (190) expr ::= expr NE expr */ + { 250, -3 }, /* (191) expr ::= expr EQ expr */ + { 250, -3 }, /* (192) expr ::= expr PLUS expr */ + { 250, -3 }, /* (193) expr ::= expr MINUS expr */ + { 250, -3 }, /* (194) expr ::= expr STAR expr */ + { 250, -3 }, /* (195) expr ::= expr SLASH expr */ + { 250, -3 }, /* (196) expr ::= expr REM expr */ + { 250, -3 }, /* (197) expr ::= expr LIKE expr */ + { 250, -5 }, /* (198) expr ::= expr IN LP exprlist RP */ + { 259, -3 }, /* (199) exprlist ::= exprlist COMMA expritem */ + { 259, -1 }, /* (200) exprlist ::= expritem */ + { 260, -1 }, /* (201) expritem ::= expr */ + { 260, 0 }, /* (202) expritem ::= */ + { 199, -3 }, /* (203) cmd ::= RESET QUERY CACHE */ + { 199, -7 }, /* (204) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 199, -7 }, /* (205) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 199, -7 }, /* (206) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 199, -7 }, /* (207) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 199, -8 }, /* (208) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 199, -9 }, /* (209) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 199, -5 }, /* (210) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ + { 199, -7 }, /* (211) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ + { 199, -7 }, /* (212) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -1574,27 +1861,66 @@ static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. +** +** The yyLookahead and yyLookaheadToken parameters provide reduce actions +** access to the lookahead token (if any). The yyLookahead will be YYNOCODE +** if the lookahead token has already been consumed. As this procedure is +** only called from one place, optimizing compilers will in-line it, which +** means that the extra parameters have no performance impact. */ static void yy_reduce( yyParser *yypParser, /* The parser */ - int yyruleno /* Number of the rule by which to reduce */ + unsigned int yyruleno, /* Number of the rule by which to reduce */ + int yyLookahead, /* Lookahead token, or YYNOCODE if none */ + ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ ){ int yygoto; /* The next state */ int yyact; /* The next action */ - YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ ParseARG_FETCH; - yymsp = &yypParser->yystack[yypParser->yyidx]; + (void)yyLookahead; + (void)yyLookaheadToken; + yymsp = yypParser->yytos; #ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 - && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ yysize = yyRuleInfo[yyruleno].nrhs; - fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, - yyRuleName[yyruleno], yymsp[-yysize].stateno); + if( yysize ){ + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + yyTracePrompt, + yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno); + }else{ + fprintf(yyTraceFILE, "%sReduce %d [%s].\n", + yyTracePrompt, yyruleno, yyRuleName[yyruleno]); + } } #endif /* NDEBUG */ - yygotominor = yyzerominor; + + /* Check that the stack is large enough to grow by a single entry + ** if the RHS of the rule is empty. This ensures that there is room + ** enough on the stack to push the LHS value */ + if( yyRuleInfo[yyruleno].nrhs==0 ){ +#ifdef YYTRACKMAXSTACKDEPTH + if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); + } +#endif +#if YYSTACKDEPTH>0 + if( yypParser->yytos>=yypParser->yystackEnd ){ + yyStackOverflow(yypParser); + return; + } +#else + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ + if( yyGrowStack(yypParser) ){ + yyStackOverflow(yypParser); + return; + } + yymsp = yypParser->yytos; + } +#endif + } switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example @@ -1606,167 +1932,174 @@ static void yy_reduce( ** break; */ /********** Begin reduce actions **********************************************/ + YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ {} break; case 1: /* cmd ::= SHOW DATABASES */ -{ setDCLSQLElems(pInfo, SHOW_DATABASES, 0);} +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);} break; case 2: /* cmd ::= SHOW MNODES */ -{ setDCLSQLElems(pInfo, SHOW_MNODES, 0);} +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);} break; case 3: /* cmd ::= SHOW DNODES */ -{ setDCLSQLElems(pInfo, SHOW_DNODES, 0);} +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);} break; case 4: /* cmd ::= SHOW ACCOUNTS */ -{ setDCLSQLElems(pInfo, SHOW_ACCOUNTS, 0);} +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);} break; case 5: /* cmd ::= SHOW USERS */ -{ setDCLSQLElems(pInfo, SHOW_USERS, 0);} +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);} break; case 6: /* cmd ::= SHOW MODULES */ -{ setDCLSQLElems(pInfo, SHOW_MODULES, 0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0); } break; case 7: /* cmd ::= SHOW QUERIES */ -{ setDCLSQLElems(pInfo, SHOW_QUERIES, 0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0); } break; case 8: /* cmd ::= SHOW CONNECTIONS */ -{ setDCLSQLElems(pInfo, SHOW_CONNECTIONS, 0);} +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);} break; case 9: /* cmd ::= SHOW STREAMS */ -{ setDCLSQLElems(pInfo, SHOW_STREAMS, 0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); } break; case 10: /* cmd ::= SHOW CONFIGS */ -{ setDCLSQLElems(pInfo, SHOW_CONFIGS, 0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONFIGS, 0, 0); } break; case 11: /* cmd ::= SHOW SCORES */ -{ setDCLSQLElems(pInfo, SHOW_SCORES, 0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); } break; case 12: /* cmd ::= SHOW GRANTS */ -{ setDCLSQLElems(pInfo, SHOW_GRANTS, 0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); } break; case 13: /* cmd ::= SHOW VNODES */ -{ setDCLSQLElems(pInfo, SHOW_VNODES, 0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); } break; case 14: /* cmd ::= SHOW VNODES IPTOKEN */ -{ setDCLSQLElems(pInfo, SHOW_VNODES, 1, &yymsp[0].minor.yy0); } +{ setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &yymsp[0].minor.yy0, 0); } break; case 15: /* dbPrefix ::= */ - case 43: /* ifexists ::= */ yytestcase(yyruleno==43); - case 45: /* ifnotexists ::= */ yytestcase(yyruleno==45); -{yygotominor.yy0.n = 0;} +{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.type = 0;} break; case 16: /* dbPrefix ::= ids DOT */ -{yygotominor.yy0 = yymsp[-1].minor.yy0; } +{yylhsminor.yy0 = yymsp[-1].minor.yy0; } + yymsp[-1].minor.yy0 = yylhsminor.yy0; break; case 17: /* cpxName ::= */ -{yygotominor.yy0.n = 0; } +{yymsp[1].minor.yy0.n = 0; } break; case 18: /* cpxName ::= DOT ids */ -{yygotominor.yy0 = yymsp[0].minor.yy0; yygotominor.yy0.n += 1; } +{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n += 1; } break; case 19: /* cmd ::= SHOW dbPrefix TABLES */ { - setDCLSQLElems(pInfo, SHOW_TABLES, 1, &yymsp[-1].minor.yy0); + setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &yymsp[-1].minor.yy0, 0); } break; case 20: /* cmd ::= SHOW dbPrefix TABLES LIKE ids */ { - setDCLSQLElems(pInfo, SHOW_TABLES, 2, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); + setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); } break; case 21: /* cmd ::= SHOW dbPrefix STABLES */ { - setDCLSQLElems(pInfo, SHOW_STABLES, 1, &yymsp[-1].minor.yy0); + setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &yymsp[-1].minor.yy0, 0); } break; case 22: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */ { SSQLToken token; setDBName(&token, &yymsp[-3].minor.yy0); - setDCLSQLElems(pInfo, SHOW_STABLES, 2, &token, &yymsp[0].minor.yy0); + setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &yymsp[0].minor.yy0); } break; case 23: /* cmd ::= SHOW dbPrefix VGROUPS */ { SSQLToken token; setDBName(&token, &yymsp[-1].minor.yy0); - setDCLSQLElems(pInfo, SHOW_VGROUPS, 1, &token); + setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0); } break; case 24: /* cmd ::= DROP TABLE ifexists ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - setDCLSQLElems(pInfo, DROP_TABLE, 2, &yymsp[-1].minor.yy0, &yymsp[-2].minor.yy0); + setDropDBTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &yymsp[-1].minor.yy0, &yymsp[-2].minor.yy0); } break; case 25: /* cmd ::= DROP DATABASE ifexists ids */ -{ setDCLSQLElems(pInfo, DROP_DATABASE, 2, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0); } +{ setDropDBTableInfo(pInfo, TSDB_SQL_DROP_DB, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0); } break; case 26: /* cmd ::= DROP DNODE IPTOKEN */ -{ setDCLSQLElems(pInfo, DROP_DNODE, 1, &yymsp[0].minor.yy0); } +{ setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER ids */ -{ setDCLSQLElems(pInfo, DROP_USER, 1, &yymsp[0].minor.yy0); } +{ setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &yymsp[0].minor.yy0); } break; case 28: /* cmd ::= DROP ACCOUNT ids */ -{ setDCLSQLElems(pInfo, DROP_ACCOUNT, 1, &yymsp[0].minor.yy0); } +{ setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &yymsp[0].minor.yy0); } break; case 29: /* cmd ::= USE ids */ -{ setDCLSQLElems(pInfo, USE_DATABASE, 1, &yymsp[0].minor.yy0);} +{ setDCLSQLElems(pInfo, TSDB_SQL_USE_DB, 1, &yymsp[0].minor.yy0);} break; case 30: /* cmd ::= DESCRIBE ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - setDCLSQLElems(pInfo, DESCRIBE_TABLE, 1, &yymsp[-1].minor.yy0); + setDCLSQLElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &yymsp[-1].minor.yy0); } break; case 31: /* cmd ::= ALTER USER ids PASS ids */ -{ setDCLSQLElems(pInfo, ALTER_USER_PASSWD, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } +{ setAlterUserSQL(pInfo, TSDB_ALTER_USER_PASSWD, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, NULL); } break; case 32: /* cmd ::= ALTER USER ids PRIVILEGE ids */ -{ setDCLSQLElems(pInfo, ALTER_USER_PRIVILEGES, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} +{ setAlterUserSQL(pInfo, TSDB_ALTER_USER_PRIVILEGES, &yymsp[-2].minor.yy0, NULL, &yymsp[0].minor.yy0);} break; case 33: /* cmd ::= ALTER DNODE IPTOKEN ids */ -{ setDCLSQLElems(pInfo, ALTER_DNODE, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } +{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 34: /* cmd ::= ALTER DNODE IPTOKEN ids ids */ -{ setDCLSQLElems(pInfo, ALTER_DNODE, 3, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } +{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 35: /* cmd ::= ALTER LOCAL ids */ -{ setDCLSQLElems(pInfo, ALTER_LOCAL, 1, &yymsp[0].minor.yy0); } +{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &yymsp[0].minor.yy0); } break; case 36: /* cmd ::= ALTER LOCAL ids ids */ -{ setDCLSQLElems(pInfo, ALTER_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } +{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 37: /* cmd ::= ALTER DATABASE ids alter_db_optr */ -{ SSQLToken t = {0}; setCreateDBSQL(pInfo, ALTER_DATABASE, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy262, &t);} +{ SSQLToken t = {0}; setCreateDBSQL(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy262, &t);} break; case 38: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ SSQLToken t = {0}; setCreateAcctSQL(pInfo, ALTER_ACCT, &yymsp[-1].minor.yy0, &t, &yymsp[0].minor.yy155);} +{ setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy155);} break; case 39: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSQL(pInfo, ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy155);} +{ setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy155);} break; case 40: /* ids ::= ID */ case 41: /* ids ::= STRING */ yytestcase(yyruleno==41); -{yygotominor.yy0 = yymsp[0].minor.yy0; } +{yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 42: /* ifexists ::= IF EXISTS */ - case 44: /* ifnotexists ::= IF NOT EXISTS */ yytestcase(yyruleno==44); -{yygotominor.yy0.n = 1;} +{yymsp[-1].minor.yy0.n = 1;} + break; + case 43: /* ifexists ::= */ + case 45: /* ifnotexists ::= */ yytestcase(yyruleno==45); +{yymsp[1].minor.yy0.n = 0;} + break; + case 44: /* ifnotexists ::= IF NOT EXISTS */ +{yymsp[-2].minor.yy0.n = 1;} break; case 46: /* cmd ::= CREATE DNODE IPTOKEN */ -{ setDCLSQLElems(pInfo, CREATE_DNODE, 1, &yymsp[0].minor.yy0);} +{ setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; case 47: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSQL(pInfo, CREATE_ACCOUNT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy155);} +{ setCreateAcctSQL(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy155);} break; case 48: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ -{ setCreateDBSQL(pInfo, CREATE_DATABASE, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy262, &yymsp[-2].minor.yy0);} +{ setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy262, &yymsp[-2].minor.yy0);} break; case 49: /* cmd ::= CREATE USER ids PASS ids */ -{ setDCLSQLElems(pInfo, CREATE_USER, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} +{ setCreateUserSQL(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; case 50: /* pps ::= */ case 52: /* tseries ::= */ yytestcase(yyruleno==52); @@ -1777,7 +2110,7 @@ static void yy_reduce( case 62: /* users ::= */ yytestcase(yyruleno==62); case 64: /* conns ::= */ yytestcase(yyruleno==64); case 66: /* state ::= */ yytestcase(yyruleno==66); -{yygotominor.yy0.n = 0; } +{yymsp[1].minor.yy0.n = 0; } break; case 51: /* pps ::= PPS INTEGER */ case 53: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==53); @@ -1788,23 +2121,24 @@ static void yy_reduce( case 63: /* users ::= USERS INTEGER */ yytestcase(yyruleno==63); case 65: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==65); case 67: /* state ::= STATE ids */ yytestcase(yyruleno==67); -{yygotominor.yy0 = yymsp[0].minor.yy0; } +{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 68: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yygotominor.yy155.users = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yygotominor.yy155.dbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yygotominor.yy155.tseries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yygotominor.yy155.streams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yygotominor.yy155.pps = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yygotominor.yy155.storage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yygotominor.yy155.qtime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yygotominor.yy155.conns = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yygotominor.yy155.stat = yymsp[0].minor.yy0; + yylhsminor.yy155.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy155.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy155.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy155.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy155.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy155.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy155.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy155.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy155.stat = yymsp[0].minor.yy0; } + yymsp[-8].minor.yy155 = yylhsminor.yy155; break; case 69: /* keep ::= KEEP tagitemlist */ -{ yygotominor.yy480 = yymsp[0].minor.yy480; } +{ yymsp[-1].minor.yy480 = yymsp[0].minor.yy480; } break; case 70: /* tables ::= TABLES INTEGER */ case 71: /* cache ::= CACHE INTEGER */ yytestcase(yyruleno==71); @@ -1817,67 +2151,84 @@ static void yy_reduce( case 78: /* clog ::= CLOG INTEGER */ yytestcase(yyruleno==78); case 79: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==79); case 80: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==80); -{ yygotominor.yy0 = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 81: /* db_optr ::= */ -{setDefaultCreateDbOption(&yygotominor.yy262);} +{setDefaultCreateDbOption(&yymsp[1].minor.yy262);} break; case 82: /* db_optr ::= db_optr tables */ case 96: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==96); -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.tablesPerVnode = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.tablesPerVnode = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 83: /* db_optr ::= db_optr cache */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 84: /* db_optr ::= db_optr replica */ case 95: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==95); -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 85: /* db_optr ::= db_optr days */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 86: /* db_optr ::= db_optr rows */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.rowPerFileBlock = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.rowPerFileBlock = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 87: /* db_optr ::= db_optr ablocks */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.numOfAvgCacheBlocks = strtod(yymsp[0].minor.yy0.z, NULL); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.numOfAvgCacheBlocks = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 88: /* db_optr ::= db_optr tblocks */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.numOfBlocksPerTable = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.numOfBlocksPerTable = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 89: /* db_optr ::= db_optr ctime */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 90: /* db_optr ::= db_optr clog */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.commitLog = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.commitLog = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 91: /* db_optr ::= db_optr comp */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 92: /* db_optr ::= db_optr prec */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.precision = yymsp[0].minor.yy0; } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 93: /* db_optr ::= db_optr keep */ -{ yygotominor.yy262 = yymsp[-1].minor.yy262; yygotominor.yy262.keep = yymsp[0].minor.yy480; } +{ yylhsminor.yy262 = yymsp[-1].minor.yy262; yylhsminor.yy262.keep = yymsp[0].minor.yy480; } + yymsp[-1].minor.yy262 = yylhsminor.yy262; break; case 94: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yygotominor.yy262);} +{ setDefaultCreateDbOption(&yymsp[1].minor.yy262);} break; case 97: /* typename ::= ids */ -{ tSQLSetColumnType (&yygotominor.yy397, &yymsp[0].minor.yy0); } +{ tSQLSetColumnType (&yylhsminor.yy397, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy397 = yylhsminor.yy397; break; case 98: /* typename ::= ids LP signed RP */ { yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy369; // negative value of name length - tSQLSetColumnType(&yygotominor.yy397, &yymsp[-3].minor.yy0); + tSQLSetColumnType(&yylhsminor.yy397, &yymsp[-3].minor.yy0); } + yymsp[-3].minor.yy397 = yylhsminor.yy397; break; case 99: /* signed ::= INTEGER */ - case 100: /* signed ::= PLUS INTEGER */ yytestcase(yyruleno==100); -{ yygotominor.yy369 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy369 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy369 = yylhsminor.yy369; + break; + case 100: /* signed ::= PLUS INTEGER */ +{ yymsp[-1].minor.yy369 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; case 101: /* signed ::= MINUS INTEGER */ -{ yygotominor.yy369 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +{ yymsp[-1].minor.yy369 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; case 102: /* cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ { @@ -1887,54 +2238,61 @@ static void yy_reduce( break; case 103: /* create_table_args ::= LP columnlist RP */ { - yygotominor.yy344 = tSetCreateSQLElems(yymsp[-1].minor.yy421, NULL, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METER); - setSQLInfo(pInfo, yygotominor.yy344, NULL, TSQL_CREATE_NORMAL_METER); + yymsp[-2].minor.yy344 = tSetCreateSQLElems(yymsp[-1].minor.yy421, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE); + setSQLInfo(pInfo, yymsp[-2].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE); } break; case 104: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ { - yygotominor.yy344 = tSetCreateSQLElems(yymsp[-5].minor.yy421, yymsp[-1].minor.yy421, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METRIC); - setSQLInfo(pInfo, yygotominor.yy344, NULL, TSQL_CREATE_NORMAL_METRIC); + yymsp[-6].minor.yy344 = tSetCreateSQLElems(yymsp[-5].minor.yy421, yymsp[-1].minor.yy421, NULL, NULL, NULL, TSQL_CREATE_STABLE); + setSQLInfo(pInfo, yymsp[-6].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE); } break; case 105: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; - yygotominor.yy344 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy480, NULL, TSQL_CREATE_METER_FROM_METRIC); - setSQLInfo(pInfo, yygotominor.yy344, NULL, TSQL_CREATE_METER_FROM_METRIC); + yymsp[-6].minor.yy344 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy480, NULL, TSQL_CREATE_TABLE_FROM_STABLE); + setSQLInfo(pInfo, yymsp[-6].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE); } break; case 106: /* create_table_args ::= AS select */ { - yygotominor.yy344 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy138, TSQL_CREATE_STREAM); - setSQLInfo(pInfo, yygotominor.yy344, NULL, TSQL_CREATE_STREAM); + yymsp[-1].minor.yy344 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy138, TSQL_CREATE_STREAM); + setSQLInfo(pInfo, yymsp[-1].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE); } break; case 107: /* columnlist ::= columnlist COMMA column */ -{yygotominor.yy421 = tFieldListAppend(yymsp[-2].minor.yy421, &yymsp[0].minor.yy397); } +{yylhsminor.yy421 = tFieldListAppend(yymsp[-2].minor.yy421, &yymsp[0].minor.yy397); } + yymsp[-2].minor.yy421 = yylhsminor.yy421; break; case 108: /* columnlist ::= column */ -{yygotominor.yy421 = tFieldListAppend(NULL, &yymsp[0].minor.yy397);} +{yylhsminor.yy421 = tFieldListAppend(NULL, &yymsp[0].minor.yy397);} + yymsp[0].minor.yy421 = yylhsminor.yy421; break; case 109: /* column ::= ids typename */ { - tSQLSetColumnInfo(&yygotominor.yy397, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy397); + tSQLSetColumnInfo(&yylhsminor.yy397, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy397); } + yymsp[-1].minor.yy397 = yylhsminor.yy397; break; case 110: /* tagitemlist ::= tagitemlist COMMA tagitem */ -{ yygotominor.yy480 = tVariantListAppend(yymsp[-2].minor.yy480, &yymsp[0].minor.yy236, -1); } +{ yylhsminor.yy480 = tVariantListAppend(yymsp[-2].minor.yy480, &yymsp[0].minor.yy236, -1); } + yymsp[-2].minor.yy480 = yylhsminor.yy480; break; case 111: /* tagitemlist ::= tagitem */ -{ yygotominor.yy480 = tVariantListAppend(NULL, &yymsp[0].minor.yy236, -1); } +{ yylhsminor.yy480 = tVariantListAppend(NULL, &yymsp[0].minor.yy236, -1); } + yymsp[0].minor.yy480 = yylhsminor.yy480; break; case 112: /* tagitem ::= INTEGER */ case 113: /* tagitem ::= FLOAT */ yytestcase(yyruleno==113); case 114: /* tagitem ::= STRING */ yytestcase(yyruleno==114); case 115: /* tagitem ::= BOOL */ yytestcase(yyruleno==115); -{toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yygotominor.yy236, &yymsp[0].minor.yy0); } +{toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy236, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy236 = yylhsminor.yy236; break; case 116: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yygotominor.yy236, &yymsp[0].minor.yy0); } +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy236, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy236 = yylhsminor.yy236; break; case 117: /* tagitem ::= MINUS INTEGER */ case 118: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==118); @@ -1944,308 +2302,359 @@ static void yy_reduce( yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yygotominor.yy236, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy236, &yymsp[-1].minor.yy0); +} + yymsp[-1].minor.yy236 = yylhsminor.yy236; + break; + case 121: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ +{ + yylhsminor.yy138 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy284, yymsp[-9].minor.yy480, yymsp[-8].minor.yy244, yymsp[-4].minor.yy480, yymsp[-3].minor.yy480, &yymsp[-7].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy480, &yymsp[0].minor.yy162, &yymsp[-1].minor.yy162); } + yymsp[-11].minor.yy138 = yylhsminor.yy138; break; - case 121: /* cmd ::= select */ + case 122: /* union ::= select */ { - setSQLInfo(pInfo, yymsp[0].minor.yy138, NULL, TSQL_QUERY_METER); + yylhsminor.yy117 = setSubclause(NULL, yymsp[0].minor.yy138); } + yymsp[0].minor.yy117 = yylhsminor.yy117; break; - case 122: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + case 123: /* union ::= union UNION select */ { - yygotominor.yy138 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy284, yymsp[-9].minor.yy480, yymsp[-8].minor.yy244, yymsp[-4].minor.yy480, yymsp[-3].minor.yy480, &yymsp[-7].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy480, &yymsp[0].minor.yy162, &yymsp[-1].minor.yy162); + yylhsminor.yy117 = appendSelectClause(yymsp[-2].minor.yy117, yymsp[0].minor.yy138); } + yymsp[-2].minor.yy117 = yylhsminor.yy117; break; - case 123: /* select ::= SELECT selcollist */ + case 124: /* cmd ::= union */ { - yygotominor.yy138 = tSetQuerySQLElems(&yymsp[-1].minor.yy0, yymsp[0].minor.yy284, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + setSQLInfo(pInfo, yymsp[0].minor.yy117, NULL, TSDB_SQL_SELECT); } break; - case 124: /* sclp ::= selcollist COMMA */ -{yygotominor.yy284 = yymsp[-1].minor.yy284;} + case 125: /* select ::= SELECT selcollist */ +{ + yylhsminor.yy138 = tSetQuerySQLElems(&yymsp[-1].minor.yy0, yymsp[0].minor.yy284, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +} + yymsp[-1].minor.yy138 = yylhsminor.yy138; break; - case 125: /* sclp ::= */ -{yygotominor.yy284 = 0;} + case 126: /* sclp ::= selcollist COMMA */ +{yylhsminor.yy284 = yymsp[-1].minor.yy284;} + yymsp[-1].minor.yy284 = yylhsminor.yy284; break; - case 126: /* selcollist ::= sclp expr as */ + case 127: /* sclp ::= */ +{yymsp[1].minor.yy284 = 0;} + break; + case 128: /* selcollist ::= sclp expr as */ { - yygotominor.yy284 = tSQLExprListAppend(yymsp[-2].minor.yy284, yymsp[-1].minor.yy244, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy284 = tSQLExprListAppend(yymsp[-2].minor.yy284, yymsp[-1].minor.yy244, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } + yymsp[-2].minor.yy284 = yylhsminor.yy284; break; - case 127: /* selcollist ::= sclp STAR */ + case 129: /* selcollist ::= sclp STAR */ { tSQLExpr *pNode = tSQLExprIdValueCreate(NULL, TK_ALL); - yygotominor.yy284 = tSQLExprListAppend(yymsp[-1].minor.yy284, pNode, 0); + yylhsminor.yy284 = tSQLExprListAppend(yymsp[-1].minor.yy284, pNode, 0); } + yymsp[-1].minor.yy284 = yylhsminor.yy284; + break; + case 130: /* as ::= AS ids */ +{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 128: /* as ::= AS ids */ - case 129: /* as ::= ids */ yytestcase(yyruleno==129); -{ yygotominor.yy0 = yymsp[0].minor.yy0; } + case 131: /* as ::= ids */ +{ yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 130: /* as ::= */ -{ yygotominor.yy0.n = 0; } + case 132: /* as ::= */ +{ yymsp[1].minor.yy0.n = 0; } break; - case 131: /* from ::= FROM tablelist */ - case 143: /* orderby_opt ::= ORDER BY sortlist */ yytestcase(yyruleno==143); - case 151: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==151); -{yygotominor.yy480 = yymsp[0].minor.yy480;} + case 133: /* from ::= FROM tablelist */ +{yymsp[-1].minor.yy480 = yymsp[0].minor.yy480;} break; - case 132: /* tablelist ::= ids cpxName */ -{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yygotominor.yy480 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);} + case 134: /* tablelist ::= ids cpxName */ +{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy480 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);} + yymsp[-1].minor.yy480 = yylhsminor.yy480; break; - case 133: /* tablelist ::= tablelist COMMA ids cpxName */ -{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yygotominor.yy480 = tVariantListAppendToken(yymsp[-3].minor.yy480, &yymsp[-1].minor.yy0, -1); } + case 135: /* tablelist ::= tablelist COMMA ids cpxName */ +{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy480 = tVariantListAppendToken(yymsp[-3].minor.yy480, &yymsp[-1].minor.yy0, -1); } + yymsp[-3].minor.yy480 = yylhsminor.yy480; break; - case 134: /* tmvar ::= VARIABLE */ -{yygotominor.yy0 = yymsp[0].minor.yy0;} + case 136: /* tmvar ::= VARIABLE */ +{yylhsminor.yy0 = yymsp[0].minor.yy0;} + yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 135: /* interval_opt ::= INTERVAL LP tmvar RP */ - case 140: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==140); -{yygotominor.yy0 = yymsp[-1].minor.yy0; } + case 137: /* interval_opt ::= INTERVAL LP tmvar RP */ + case 142: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==142); +{yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 136: /* interval_opt ::= */ - case 141: /* sliding_opt ::= */ yytestcase(yyruleno==141); -{yygotominor.yy0.n = 0; yygotominor.yy0.z = NULL; yygotominor.yy0.type = 0; } + case 138: /* interval_opt ::= */ + case 143: /* sliding_opt ::= */ yytestcase(yyruleno==143); +{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 137: /* fill_opt ::= */ -{yygotominor.yy480 = 0; } + case 139: /* fill_opt ::= */ +{yymsp[1].minor.yy480 = 0; } break; - case 138: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 140: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); tVariantCreate(&A, &yymsp[-3].minor.yy0); tVariantListInsert(yymsp[-1].minor.yy480, &A, -1, 0); - yygotominor.yy480 = yymsp[-1].minor.yy480; + yymsp[-5].minor.yy480 = yymsp[-1].minor.yy480; } break; - case 139: /* fill_opt ::= FILL LP ID RP */ + case 141: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yygotominor.yy480 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy480 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 142: /* orderby_opt ::= */ - case 150: /* groupby_opt ::= */ yytestcase(yyruleno==150); -{yygotominor.yy480 = 0;} + case 144: /* orderby_opt ::= */ + case 152: /* groupby_opt ::= */ yytestcase(yyruleno==152); +{yymsp[1].minor.yy480 = 0;} break; - case 144: /* sortlist ::= sortlist COMMA item sortorder */ + case 145: /* orderby_opt ::= ORDER BY sortlist */ + case 153: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==153); +{yymsp[-2].minor.yy480 = yymsp[0].minor.yy480;} + break; + case 146: /* sortlist ::= sortlist COMMA item sortorder */ { - yygotominor.yy480 = tVariantListAppend(yymsp[-3].minor.yy480, &yymsp[-1].minor.yy236, yymsp[0].minor.yy220); + yylhsminor.yy480 = tVariantListAppend(yymsp[-3].minor.yy480, &yymsp[-1].minor.yy236, yymsp[0].minor.yy220); } + yymsp[-3].minor.yy480 = yylhsminor.yy480; break; - case 145: /* sortlist ::= item sortorder */ + case 147: /* sortlist ::= item sortorder */ { - yygotominor.yy480 = tVariantListAppend(NULL, &yymsp[-1].minor.yy236, yymsp[0].minor.yy220); + yylhsminor.yy480 = tVariantListAppend(NULL, &yymsp[-1].minor.yy236, yymsp[0].minor.yy220); } + yymsp[-1].minor.yy480 = yylhsminor.yy480; break; - case 146: /* item ::= ids cpxName */ + case 148: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yygotominor.yy236, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy236, &yymsp[-1].minor.yy0); } + yymsp[-1].minor.yy236 = yylhsminor.yy236; break; - case 147: /* sortorder ::= ASC */ -{yygotominor.yy220 = TSQL_SO_ASC; } + case 149: /* sortorder ::= ASC */ +{yymsp[0].minor.yy220 = TSQL_SO_ASC; } break; - case 148: /* sortorder ::= DESC */ -{yygotominor.yy220 = TSQL_SO_DESC;} + case 150: /* sortorder ::= DESC */ +{yymsp[0].minor.yy220 = TSQL_SO_DESC;} break; - case 149: /* sortorder ::= */ -{yygotominor.yy220 = TSQL_SO_ASC;} + case 151: /* sortorder ::= */ +{yymsp[1].minor.yy220 = TSQL_SO_ASC;} break; - case 152: /* grouplist ::= grouplist COMMA item */ + case 154: /* grouplist ::= grouplist COMMA item */ { - yygotominor.yy480 = tVariantListAppend(yymsp[-2].minor.yy480, &yymsp[0].minor.yy236, -1); + yylhsminor.yy480 = tVariantListAppend(yymsp[-2].minor.yy480, &yymsp[0].minor.yy236, -1); } + yymsp[-2].minor.yy480 = yylhsminor.yy480; break; - case 153: /* grouplist ::= item */ + case 155: /* grouplist ::= item */ { - yygotominor.yy480 = tVariantListAppend(NULL, &yymsp[0].minor.yy236, -1); + yylhsminor.yy480 = tVariantListAppend(NULL, &yymsp[0].minor.yy236, -1); } + yymsp[0].minor.yy480 = yylhsminor.yy480; break; - case 154: /* having_opt ::= */ - case 164: /* where_opt ::= */ yytestcase(yyruleno==164); - case 200: /* expritem ::= */ yytestcase(yyruleno==200); -{yygotominor.yy244 = 0;} + case 156: /* having_opt ::= */ + case 166: /* where_opt ::= */ yytestcase(yyruleno==166); + case 202: /* expritem ::= */ yytestcase(yyruleno==202); +{yymsp[1].minor.yy244 = 0;} break; - case 155: /* having_opt ::= HAVING expr */ - case 165: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==165); - case 199: /* expritem ::= expr */ yytestcase(yyruleno==199); -{yygotominor.yy244 = yymsp[0].minor.yy244;} + case 157: /* having_opt ::= HAVING expr */ + case 167: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==167); +{yymsp[-1].minor.yy244 = yymsp[0].minor.yy244;} break; - case 156: /* limit_opt ::= */ - case 160: /* slimit_opt ::= */ yytestcase(yyruleno==160); -{yygotominor.yy162.limit = -1; yygotominor.yy162.offset = 0;} + case 158: /* limit_opt ::= */ + case 162: /* slimit_opt ::= */ yytestcase(yyruleno==162); +{yymsp[1].minor.yy162.limit = -1; yymsp[1].minor.yy162.offset = 0;} break; - case 157: /* limit_opt ::= LIMIT signed */ - case 161: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==161); -{yygotominor.yy162.limit = yymsp[0].minor.yy369; yygotominor.yy162.offset = 0;} + case 159: /* limit_opt ::= LIMIT signed */ + case 163: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==163); +{yymsp[-1].minor.yy162.limit = yymsp[0].minor.yy369; yymsp[-1].minor.yy162.offset = 0;} break; - case 158: /* limit_opt ::= LIMIT signed OFFSET signed */ - case 162: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==162); -{yygotominor.yy162.limit = yymsp[-2].minor.yy369; yygotominor.yy162.offset = yymsp[0].minor.yy369;} + case 160: /* limit_opt ::= LIMIT signed OFFSET signed */ + case 164: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==164); +{yymsp[-3].minor.yy162.limit = yymsp[-2].minor.yy369; yymsp[-3].minor.yy162.offset = yymsp[0].minor.yy369;} break; - case 159: /* limit_opt ::= LIMIT signed COMMA signed */ - case 163: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==163); -{yygotominor.yy162.limit = yymsp[0].minor.yy369; yygotominor.yy162.offset = yymsp[-2].minor.yy369;} + case 161: /* limit_opt ::= LIMIT signed COMMA signed */ + case 165: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==165); +{yymsp[-3].minor.yy162.limit = yymsp[0].minor.yy369; yymsp[-3].minor.yy162.offset = yymsp[-2].minor.yy369;} break; - case 166: /* expr ::= LP expr RP */ -{yygotominor.yy244 = yymsp[-1].minor.yy244; } + case 168: /* expr ::= LP expr RP */ +{yymsp[-2].minor.yy244 = yymsp[-1].minor.yy244; } break; - case 167: /* expr ::= ID */ -{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} + case 169: /* expr ::= ID */ +{yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 168: /* expr ::= ID DOT ID */ -{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} + case 170: /* expr ::= ID DOT ID */ +{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 169: /* expr ::= ID DOT STAR */ -{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} + case 171: /* expr ::= ID DOT STAR */ +{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 170: /* expr ::= INTEGER */ -{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} + case 172: /* expr ::= INTEGER */ +{yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 171: /* expr ::= MINUS INTEGER */ - case 172: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==172); -{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} + case 173: /* expr ::= MINUS INTEGER */ + case 174: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==174); +{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy244 = yylhsminor.yy244; break; - case 173: /* expr ::= FLOAT */ -{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} + case 175: /* expr ::= FLOAT */ +{yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 174: /* expr ::= MINUS FLOAT */ - case 175: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==175); -{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} + case 176: /* expr ::= MINUS FLOAT */ + case 177: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==177); +{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy244 = yylhsminor.yy244; break; - case 176: /* expr ::= STRING */ -{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} + case 178: /* expr ::= STRING */ +{yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 177: /* expr ::= NOW */ -{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } + case 179: /* expr ::= NOW */ +{yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 178: /* expr ::= VARIABLE */ -{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} + case 180: /* expr ::= VARIABLE */ +{yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 179: /* expr ::= BOOL */ -{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} + case 181: /* expr ::= BOOL */ +{yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 180: /* expr ::= ID LP exprlist RP */ + case 182: /* expr ::= ID LP exprlist RP */ { - yygotominor.yy244 = tSQLExprCreateFunction(yymsp[-1].minor.yy284, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); + yylhsminor.yy244 = tSQLExprCreateFunction(yymsp[-1].minor.yy284, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy244 = yylhsminor.yy244; break; - case 181: /* expr ::= ID LP STAR RP */ + case 183: /* expr ::= ID LP STAR RP */ { - yygotominor.yy244 = tSQLExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); + yylhsminor.yy244 = tSQLExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy244 = yylhsminor.yy244; break; - case 182: /* expr ::= expr AND expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_AND);} - break; - case 183: /* expr ::= expr OR expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_OR); } - break; - case 184: /* expr ::= expr LT expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LT);} + case 184: /* expr ::= expr AND expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_AND);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 185: /* expr ::= expr GT expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GT);} + case 185: /* expr ::= expr OR expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_OR); } + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 186: /* expr ::= expr LE expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LE);} + case 186: /* expr ::= expr LT expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LT);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 187: /* expr ::= expr GE expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GE);} + case 187: /* expr ::= expr GT expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GT);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 188: /* expr ::= expr NE expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_NE);} + case 188: /* expr ::= expr LE expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LE);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 189: /* expr ::= expr EQ expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_EQ);} + case 189: /* expr ::= expr GE expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GE);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 190: /* expr ::= expr PLUS expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_PLUS); } + case 190: /* expr ::= expr NE expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_NE);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 191: /* expr ::= expr MINUS expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_MINUS); } + case 191: /* expr ::= expr EQ expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_EQ);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 192: /* expr ::= expr STAR expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_STAR); } + case 192: /* expr ::= expr PLUS expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_PLUS); } + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 193: /* expr ::= expr SLASH expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_DIVIDE);} + case 193: /* expr ::= expr MINUS expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_MINUS); } + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 194: /* expr ::= expr REM expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_REM); } + case 194: /* expr ::= expr STAR expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_STAR); } + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 195: /* expr ::= expr LIKE expr */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LIKE); } + case 195: /* expr ::= expr SLASH expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_DIVIDE);} + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 196: /* expr ::= expr IN LP exprlist RP */ -{yygotominor.yy244 = tSQLExprCreate(yymsp[-4].minor.yy244, (tSQLExpr*)yymsp[-1].minor.yy284, TK_IN); } + case 196: /* expr ::= expr REM expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_REM); } + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 197: /* exprlist ::= exprlist COMMA expritem */ - case 204: /* itemlist ::= itemlist COMMA expr */ yytestcase(yyruleno==204); -{yygotominor.yy284 = tSQLExprListAppend(yymsp[-2].minor.yy284,yymsp[0].minor.yy244,0);} + case 197: /* expr ::= expr LIKE expr */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LIKE); } + yymsp[-2].minor.yy244 = yylhsminor.yy244; break; - case 198: /* exprlist ::= expritem */ - case 205: /* itemlist ::= expr */ yytestcase(yyruleno==205); -{yygotominor.yy284 = tSQLExprListAppend(0,yymsp[0].minor.yy244,0);} + case 198: /* expr ::= expr IN LP exprlist RP */ +{yylhsminor.yy244 = tSQLExprCreate(yymsp[-4].minor.yy244, (tSQLExpr*)yymsp[-1].minor.yy284, TK_IN); } + yymsp[-4].minor.yy244 = yylhsminor.yy244; break; - case 201: /* cmd ::= INSERT INTO cpxName insert_value_list */ -{ - tSetInsertSQLElems(pInfo, &yymsp[-1].minor.yy0, yymsp[0].minor.yy237); -} + case 199: /* exprlist ::= exprlist COMMA expritem */ +{yylhsminor.yy284 = tSQLExprListAppend(yymsp[-2].minor.yy284,yymsp[0].minor.yy244,0);} + yymsp[-2].minor.yy284 = yylhsminor.yy284; break; - case 202: /* insert_value_list ::= VALUES LP itemlist RP */ -{yygotominor.yy237 = tSQLListListAppend(NULL, yymsp[-1].minor.yy284);} + case 200: /* exprlist ::= expritem */ +{yylhsminor.yy284 = tSQLExprListAppend(0,yymsp[0].minor.yy244,0);} + yymsp[0].minor.yy284 = yylhsminor.yy284; break; - case 203: /* insert_value_list ::= insert_value_list VALUES LP itemlist RP */ -{yygotominor.yy237 = tSQLListListAppend(yymsp[-4].minor.yy237, yymsp[-1].minor.yy284);} + case 201: /* expritem ::= expr */ +{yylhsminor.yy244 = yymsp[0].minor.yy244;} + yymsp[0].minor.yy244 = yylhsminor.yy244; break; - case 206: /* cmd ::= RESET QUERY CACHE */ -{ setDCLSQLElems(pInfo, RESET_QUERY_CACHE, 0);} + case 203: /* cmd ::= RESET QUERY CACHE */ +{ setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 207: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 204: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy421, NULL, ALTER_TABLE_ADD_COLUMN); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_ADD_COLUMN); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy421, NULL, TSDB_ALTER_TABLE_ADD_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 208: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 205: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; toTSDBType(yymsp[0].minor.yy0.type); tVariantList* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, K, ALTER_TABLE_DROP_COLUMN); - setSQLInfo(pInfo, pAlterTable, NULL, 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); } break; - case 209: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 206: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy421, NULL, ALTER_TABLE_TAGS_ADD); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_ADD); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy421, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 210: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 207: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; toTSDBType(yymsp[0].minor.yy0.type); tVariantList* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, A, ALTER_TABLE_TAGS_DROP); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_DROP); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 211: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 208: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -2255,11 +2664,11 @@ static void yy_reduce( toTSDBType(yymsp[0].minor.yy0.type); A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-5].minor.yy0, NULL, A, ALTER_TABLE_TAGS_CHG); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_CHG); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 212: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 209: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -2267,48 +2676,40 @@ static void yy_reduce( tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); A = tVariantListAppend(A, &yymsp[0].minor.yy236, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, ALTER_TABLE_TAGS_SET); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_SET); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 213: /* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ -{yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_CONNECTION, 1, &yymsp[-2].minor.yy0);} + case 210: /* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ +{yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[-2].minor.yy0);} break; - case 214: /* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ -{yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_STREAM, 1, &yymsp[-4].minor.yy0);} + case 211: /* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ +{yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-4].minor.yy0);} break; - case 215: /* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ -{yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_QUERY, 1, &yymsp[-4].minor.yy0);} + case 212: /* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ +{yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-4].minor.yy0);} break; default: break; /********** End reduce actions ************************************************/ }; - assert( yyruleno>=0 && yyrulenoyyidx -= yysize; - yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); - if( yyact <= YY_MAX_SHIFTREDUCE ){ - if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; - /* If the reduce action popped at least - ** one element off the stack, then we can push the new element back - ** onto the stack here, and skip the stack overflow test in yy_shift(). - ** That gives a significant speed improvement. */ - if( yysize ){ - yypParser->yyidx++; - yymsp -= yysize-1; - yymsp->stateno = (YYACTIONTYPE)yyact; - yymsp->major = (YYCODETYPE)yygoto; - yymsp->minor = yygotominor; - yyTraceShift(yypParser, yyact); - }else{ - yy_shift(yypParser,yyact,yygoto,&yygotominor); - } - }else{ - assert( yyact == YY_ACCEPT_ACTION ); - yy_accept(yypParser); - } + yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto); + + /* There are no SHIFTREDUCE actions on nonterminals because the table + ** generator has simplified them to pure REDUCE actions. */ + assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) ); + + /* It is not possible for a REDUCE to be followed by an error */ + assert( yyact!=YY_ERROR_ACTION ); + + yymsp += yysize+1; + yypParser->yytos = yymsp; + yymsp->stateno = (YYACTIONTYPE)yyact; + yymsp->major = (YYCODETYPE)yygoto; + yyTraceShift(yypParser, yyact, "... then shift"); } /* @@ -2324,7 +2725,7 @@ static void yy_parse_failed( fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser fails */ /************ Begin %parse_failure code ***************************************/ @@ -2339,13 +2740,13 @@ static void yy_parse_failed( static void yy_syntax_error( yyParser *yypParser, /* The parser */ int yymajor, /* The major type of the error token */ - YYMINORTYPE yyminor /* The minor type of the error token */ + ParseTOKENTYPE yyminor /* The minor type of the error token */ ){ ParseARG_FETCH; -#define TOKEN (yyminor.yy0) +#define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ - pInfo->validSql = false; + pInfo->valid = false; int32_t outputBufLen = tListLen(pInfo->pzErrMsg); int32_t len = 0; @@ -2382,7 +2783,10 @@ static void yy_accept( fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif + assert( yypParser->yytos==yypParser->yystack ); /* Here code is inserted which will be executed whenever the ** parser accepts */ /*********** Begin %parse_accept code *****************************************/ @@ -2417,7 +2821,7 @@ void Parse( ParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; - int yyact; /* The parser action. */ + unsigned int yyact; /* The parser action. */ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ #endif @@ -2426,29 +2830,8 @@ void Parse( #endif yyParser *yypParser; /* The parser */ - /* (re)initialize the parser, if necessary */ yypParser = (yyParser*)yyp; - if( yypParser->yyidx<0 ){ -#if YYSTACKDEPTH<=0 - if( yypParser->yystksz <=0 ){ - /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ - yyminorunion = yyzerominor; - yyStackOverflow(yypParser, &yyminorunion); - return; - } -#endif - yypParser->yyidx = 0; - yypParser->yyerrcnt = -1; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInitialize. Empty stack. State 0\n", - yyTracePrompt); - } -#endif - } - yyminorunion.yy0 = yyminor; + assert( yypParser->yytos!=0 ); #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); #endif @@ -2456,21 +2839,34 @@ void Parse( #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]); + int stateno = yypParser->yytos->stateno; + if( stateno < YY_MIN_REDUCE ){ + fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno); + }else{ + fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE); + } } #endif do{ yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); - if( yyact <= YY_MAX_SHIFTREDUCE ){ - if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; - yy_shift(yypParser,yyact,yymajor,&yyminorunion); + if( yyact >= YY_MIN_REDUCE ){ + yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor); + }else if( yyact <= YY_MAX_SHIFTREDUCE ){ + yy_shift(yypParser,yyact,yymajor,yyminor); +#ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; +#endif yymajor = YYNOCODE; - }else if( yyact <= YY_MAX_REDUCE ){ - yy_reduce(yypParser,yyact-YY_MIN_REDUCE); + }else if( yyact==YY_ACCEPT_ACTION ){ + yypParser->yytos--; + yy_accept(yypParser); + return; }else{ assert( yyact == YY_ERROR_ACTION ); + yyminorunion.yy0 = yyminor; #ifdef YYERRORSYMBOL int yymx; #endif @@ -2500,9 +2896,9 @@ void Parse( ** */ if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor,yyminor); } - yymx = yypParser->yystack[yypParser->yyidx].major; + yymx = yypParser->yytos->major; if( yymx==YYERRORSYMBOL || yyerrorhit ){ #ifndef NDEBUG if( yyTraceFILE ){ @@ -2510,26 +2906,26 @@ void Parse( yyTracePrompt,yyTokenName[yymajor]); } #endif - yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); + yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); yymajor = YYNOCODE; }else{ - while( - yypParser->yyidx >= 0 && - yymx != YYERRORSYMBOL && - (yyact = yy_find_reduce_action( - yypParser->yystack[yypParser->yyidx].stateno, + while( yypParser->yytos >= yypParser->yystack + && yymx != YYERRORSYMBOL + && (yyact = yy_find_reduce_action( + yypParser->yytos->stateno, YYERRORSYMBOL)) >= YY_MIN_REDUCE ){ yy_pop_parser_stack(yypParser); } - if( yypParser->yyidx < 0 || yymajor==0 ){ + if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif yymajor = YYNOCODE; }else if( yymx!=YYERRORSYMBOL ){ - YYMINORTYPE u2; - u2.YYERRSYMDT = 0; - yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); + yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor); } } yypParser->yyerrcnt = 3; @@ -2542,7 +2938,7 @@ void Parse( ** Applications can set this macro (for example inside %include) if ** they intend to abandon the parse upon the first syntax error seen. */ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor, yyminor); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yymajor = YYNOCODE; @@ -2557,24 +2953,29 @@ void Parse( ** three input tokens have been successfully shifted. */ if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor, yyminor); } yypParser->yyerrcnt = 3; yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); if( yyendofinput ){ yy_parse_failed(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif } yymajor = YYNOCODE; #endif } - }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); + }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack ); #ifndef NDEBUG if( yyTraceFILE ){ - int i; + yyStackEntry *i; + char cDiv = '['; fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); - for(i=1; i<=yypParser->yyidx; i++) - fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ', - yyTokenName[yypParser->yystack[i].major]); + for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){ + fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]); + cDiv = ' '; + } fprintf(yyTraceFILE,"]\n"); } #endif diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 99b9b571d7ffe513e87206c5cd0c5d380318ca95..eab8545063b2e4a426bd11aa28f2c9ed12280a58 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -131,8 +131,8 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf } /* update the limit value according to current retrieval results */ - pCmd->limit.limit = pCmd->globalLimit - pRes->numOfTotal; - pCmd->limit.offset = pRes->offset; + pCmd->pQueryInfo->limit.limit = pCmd->globalLimit - pRes->numOfTotal; + pCmd->pQueryInfo->limit.offset = pRes->offset; if ((++(pMeterMetaInfo->vnodeIndex)) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { tscTrace("%p retrieve data from next vnode:%d", pSql, pMeterMetaInfo->vnodeIndex); @@ -282,7 +282,7 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) { } /* update the limit value according to current retrieval results */ - pCmd->limit.limit = pCmd->globalLimit - pRes->numOfTotal; + pCmd->pQueryInfo->limit.limit = pCmd->globalLimit - pRes->numOfTotal; if ((++pMeterMetaInfo->vnodeIndex) <= pMeterMetaInfo->pMetricMeta->numOfVnodes) { pSql->cmd.command = TSDB_SQL_SELECT; // reset flag to launch query first. @@ -407,7 +407,7 @@ void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows) assert(!pCmd->isInsertFromFile && pSql->signature == pSql); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - assert(pCmd->numOfTables == 1); + assert(pCmd->pQueryInfo->numOfTables == 1); SDataBlockList *pDataBlocks = pCmd->pDataBlocks; if (pDataBlocks == NULL || pMeterMetaInfo->vnodeIndex >= pDataBlocks->nSize) { diff --git a/src/client/src/tscJoinProcess.c b/src/client/src/tscJoinProcess.c index a94b308e87a784e55a01f2d19c0c7cba60b3beeb..bb6b14352d17755f7a302a8d4b3bc33be883437e 100644 --- a/src/client/src/tscJoinProcess.c +++ b/src/client/src/tscJoinProcess.c @@ -53,11 +53,11 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor *st = INT64_MAX; *et = INT64_MIN; - SLimitVal* pLimit = &pSql->cmd.limit; + SLimitVal* pLimit = &pSql->cmd.pQueryInfo->limit; int32_t order = pSql->cmd.order.order; - pSql->pSubs[0]->cmd.tsBuf = output1; - pSql->pSubs[1]->cmd.tsBuf = output2; + pSql->pSubs[0]->cmd.pQueryInfo->tsBuf = output1; + pSql->pSubs[1]->cmd.pQueryInfo->tsBuf = output2; tsBufResetPos(pSupporter1->pTSBuf); tsBufResetPos(pSupporter2->pTSBuf); @@ -113,7 +113,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor } // in case of stable query, limit/offset is not applied here - if (pLimit->offset == 0 || pSql->cmd.nAggTimeInterval > 0 || QUERY_IS_STABLE_QUERY(pSql->cmd.type)) { + if (pLimit->offset == 0 || pSql->cmd.pQueryInfo->nAggTimeInterval > 0 || QUERY_IS_STABLE_QUERY(pSql->cmd.type)) { tsBufAppend(output1, elem1.vnode, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts)); tsBufAppend(output2, elem2.vnode, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts)); } else { @@ -168,8 +168,8 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS pSupporter->pState = pState; pSupporter->subqueryIndex = index; - pSupporter->interval = pSql->cmd.nAggTimeInterval; - pSupporter->limit = pSql->cmd.limit; + pSupporter->interval = pSql->cmd.pQueryInfo->nAggTimeInterval; + pSupporter->limit = pSql->cmd.pQueryInfo->limit; SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, index); pSupporter->uid = pMeterMetaInfo->pMeterMeta->uid; @@ -211,8 +211,8 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) { */ bool needSecondaryQuery(SSqlObj* pSql) { SSqlCmd* pCmd = &pSql->cmd; - for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { - SColumnBase* pBase = tscColumnBaseInfoGet(&pCmd->colList, i); + for (int32_t i = 0; i < pCmd->pQueryInfo->colList.numOfCols; ++i) { + SColumnBase* pBase = tscColumnBaseInfoGet(&pCmd->pQueryInfo->colList, i); if (pBase->colIndex.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { return true; } @@ -272,25 +272,25 @@ int32_t tscLaunchSecondSubquery(SSqlObj* pSql) { tscFreeSqlCmdData(&pNew->cmd); pSql->pSubs[j++] = pNew; - pNew->cmd.tsBuf = pSub->cmd.tsBuf; - pSub->cmd.tsBuf = NULL; + pNew->cmd.pQueryInfo->tsBuf = pSub->cmd.pQueryInfo->tsBuf; + pSub->cmd.pQueryInfo->tsBuf = NULL; taos_free_result(pSub); // set the second stage sub query for join process pNew->cmd.type |= TSDB_QUERY_TYPE_JOIN_SEC_STAGE; - pNew->cmd.nAggTimeInterval = pSupporter->interval; - pNew->cmd.groupbyExpr = pSupporter->groupbyExpr; + pNew->cmd.pQueryInfo->nAggTimeInterval = pSupporter->interval; + pNew->cmd.pQueryInfo->groupbyExpr = pSupporter->groupbyExpr; - tscColumnBaseInfoCopy(&pNew->cmd.colList, &pSupporter->colList, 0); - tscTagCondCopy(&pNew->cmd.tagCond, &pSupporter->tagCond); + tscColumnBaseInfoCopy(&pNew->cmd.pQueryInfo->colList, &pSupporter->colList, 0); + tscTagCondCopy(&pNew->cmd.pQueryInfo->tagCond, &pSupporter->tagCond); - tscSqlExprCopy(&pNew->cmd.exprsInfo, &pSupporter->exprsInfo, pSupporter->uid); - tscFieldInfoCopyAll(&pSupporter->fieldsInfo, &pNew->cmd.fieldsInfo); + tscSqlExprCopy(&pNew->cmd.pQueryInfo->exprsInfo, &pSupporter->exprsInfo, pSupporter->uid); + tscFieldInfoCopyAll(&pSupporter->fieldsInfo, &pNew->cmd.pQueryInfo->fieldsInfo); // add the ts function for interval query if it is missing - if (pSupporter->exprsInfo.pExprs[0].functionId != TSDB_FUNC_TS && pNew->cmd.nAggTimeInterval > 0) { + if (pSupporter->exprsInfo.pExprs[0].functionId != TSDB_FUNC_TS && pNew->cmd.pQueryInfo->nAggTimeInterval > 0) { tscAddTimestampColumn(&pNew->cmd, TSDB_FUNC_TS, 0); } @@ -304,15 +304,15 @@ int32_t tscLaunchSecondSubquery(SSqlObj* pSql) { * When handling the projection query, the offset value will be modified for table-table join, which is changed * during the timestamp intersection. */ - pSupporter->limit = pSql->cmd.limit; - pNew->cmd.limit = pSupporter->limit; + pSupporter->limit = pSql->cmd.pQueryInfo->limit; + pNew->cmd.pQueryInfo->limit = pSupporter->limit; // fetch the join tag column if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) { SSqlExpr* pExpr = tscSqlExprGet(&pNew->cmd, 0); - assert(pNew->cmd.tagCond.joinInfo.hasJoin); + assert(pNew->cmd.pQueryInfo->tagCond.joinInfo.hasJoin); - int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pNew->cmd.tagCond, pMeterMetaInfo->pMeterMeta->uid); + int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pNew->cmd.pQueryInfo->tagCond, pMeterMetaInfo->pMeterMeta->uid); pExpr->param[0].i64Key = tagColIndex; pExpr->numOfParams = 1; } @@ -370,10 +370,10 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter // update the query time range according to the join results on timestamp static void updateQueryTimeRange(SSqlObj* pSql, int64_t st, int64_t et) { - assert(pSql->cmd.stime <= st && pSql->cmd.etime >= et); + assert(pSql->cmd.pQueryInfo->stime <= st && pSql->cmd.pQueryInfo->etime >= et); - pSql->cmd.stime = st; - pSql->cmd.etime = et; + pSql->cmd.pQueryInfo->stime = st; + pSql->cmd.pQueryInfo->etime = et; } static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { @@ -408,7 +408,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { tscTrace("%p create tmp file for ts block:%s", pSql, pBuf->path); pSupporter->pTSBuf = pBuf; } else { - assert(pSql->cmd.numOfTables == 1); // for subquery, only one metermetaInfo + assert(pSql->cmd.pQueryInfo->numOfTables == 1); // for subquery, only one metermetaInfo SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); tsBufMerge(pSupporter->pTSBuf, pBuf, pMeterMetaInfo->vnodeIndex); @@ -424,7 +424,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { } else if (numOfRows == 0) { // no data from this vnode anymore if (tscProjectionQueryOnMetric(&pParentSql->cmd)) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); - assert(pSql->cmd.numOfTables == 1); + assert(pSql->cmd.pQueryInfo->numOfTables == 1); // for projection query, need to try next vnode if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { @@ -480,7 +480,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { if (tscProjectionQueryOnMetric(&pSql->cmd) && numOfRows == 0) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); - assert(pSql->cmd.numOfTables == 1); + assert(pSql->cmd.pQueryInfo->numOfTables == 1); // for projection query, need to try next vnode if current vnode is exhausted if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { @@ -555,7 +555,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) { // wait for all subqueries completed pSupporter->pState->numOfTotal = numOfFetch; - assert(pRes1->numOfRows >= 0 && pCmd1->numOfTables == 1); + assert(pRes1->numOfRows >= 0 && pCmd1->pQueryInfo->numOfTables == 1); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd1, 0); @@ -589,13 +589,13 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { return; // the column transfer support struct has been built } - pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * pCmd->fieldsInfo.numOfOutputCols); + pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * pCmd->pQueryInfo->fieldsInfo.numOfOutputCols); - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo->fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); int32_t tableIndexOfSub = -1; - for (int32_t j = 0; j < pCmd->numOfTables; ++j) { + for (int32_t j = 0; j < pCmd->pQueryInfo->numOfTables; ++j) { SSqlObj* pSub = pSql->pSubs[j]; SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSub->cmd, 0); @@ -607,7 +607,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd; - for (int32_t k = 0; k < pSubCmd->exprsInfo.numOfExprs; ++k) { + for (int32_t k = 0; k < pSubCmd->pQueryInfo->exprsInfo.numOfExprs; ++k) { SSqlExpr* pSubExpr = tscSqlExprGet(pSubCmd, k); if (pExpr->functionId == pSubExpr->functionId && pExpr->colInfo.colId == pSubExpr->colInfo.colId) { pRes->pColumnIndex[i] = (SColumnIndex){.tableIndex = tableIndexOfSub, .columnIndex = k}; diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index ecd2f97e394f50c5aed16ab7dea10fa3b9138cdb..ec39faf87d76c43390c1b8c5c8adba01d17343d2 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -254,16 +254,16 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, pCmd->order.order = TSQL_SO_ASC; - tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, "Field", TSDB_COL_NAME_LEN); + tscFieldInfoSetValue(&pCmd->pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, "Field", TSDB_COL_NAME_LEN); rowLen += TSDB_COL_NAME_LEN; - tscFieldInfoSetValue(&pCmd->fieldsInfo, 1, TSDB_DATA_TYPE_BINARY, "Type", typeColLength); + tscFieldInfoSetValue(&pCmd->pQueryInfo->fieldsInfo, 1, TSDB_DATA_TYPE_BINARY, "Type", typeColLength); rowLen += typeColLength; - tscFieldInfoSetValue(&pCmd->fieldsInfo, 2, TSDB_DATA_TYPE_INT, "Length", sizeof(int32_t)); + tscFieldInfoSetValue(&pCmd->pQueryInfo->fieldsInfo, 2, TSDB_DATA_TYPE_INT, "Length", sizeof(int32_t)); rowLen += sizeof(int32_t); - tscFieldInfoSetValue(&pCmd->fieldsInfo, 3, TSDB_DATA_TYPE_BINARY, "Note", noteColLength); + tscFieldInfoSetValue(&pCmd->pQueryInfo->fieldsInfo, 3, TSDB_DATA_TYPE_BINARY, "Note", noteColLength); rowLen += noteColLength; return rowLen; @@ -321,7 +321,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) { for (int32_t j = 0; j < pSidList->numOfSids; ++j) { SMeterSidExtInfo *pSidExt = tscGetMeterSidInfo(pSidList, j); - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo->fieldsInfo.numOfOutputCols; ++k) { SColIndexEx *pColIndex = &tscSqlExprGet(pCmd, k)->colInfo; int16_t offsetId = pColIndex->colIdx; @@ -352,7 +352,7 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) { int32_t rowIdx = 0; for (int32_t i = 0; i < totalNumOfResults; ++i) { - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, i); if (pExpr->colInfo.colIdx == -1 && pExpr->functionId == TSDB_FUNC_COUNT) { @@ -444,7 +444,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa pCmd->numOfCols = 1; pCmd->order.order = TSQL_SO_ASC; - tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength); + tscFieldInfoSetValue(&pCmd->pQueryInfo[0].fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength); tscInitResObjForLocalQuery(pSql, 1, valueLength); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, 0); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 3dc93065eb72d237f241e4826f03b17d04dbc533..2f740faba35aef1a9ace02f4dd3e2e4cbdbf7e64 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -18,6 +18,7 @@ #define _XOPEN_SOURCE +#include #include "os.h" #include "ihash.h" #include "tscSecondaryMerge.h" @@ -953,7 +954,8 @@ int doParserInsertSql(SSqlObj *pSql, char *str) { } if ((NULL == pSql->asyncTblPos) && (NULL == pSql->pTableHashList)) { - pSql->pTableHashList = taosInitIntHash(128, POINTER_BYTES, taosHashInt); + pSql->pTableHashList = taosInitHashTable(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false); + pSql->cmd.pDataBlocks = tscCreateBlockArrayList(); if (NULL == pSql->pTableHashList || NULL == pSql->cmd.pDataBlocks) { code = TSDB_CODE_CLI_OUT_OF_MEMORY; @@ -1239,8 +1241,9 @@ int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion) { tscRemoveAllMeterMetaInfo(&pSql->cmd, false); if (NULL == pSql->asyncTblPos) { - tscTrace("continue parse sql: %s", pSql->asyncTblPos); tscCleanSqlCmd(&pSql->cmd); + } else { + tscTrace("continue parse sql: %s", pSql->asyncTblPos); } if (tscIsInsertOrImportData(pSql->sqlstr)) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 23143306e35cecc42793dd1dc7ae33d12594f646..aa7e40a79bbb8d16e2e331a05257df5e179855bc 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -70,7 +70,7 @@ static int32_t insertResultField(SSqlCmd* pCmd, int32_t outputIndex, SColumnList static int32_t changeFunctionID(int32_t optr, int16_t* functionId); static int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric); -static bool validateIpAddress(char* ip); +static bool validateIpAddress(const char* ip, size_t size); static bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd); static bool functionCompatibleCheck(SSqlCmd* pCmd); static void setColumnOffsetValueInResultset(SSqlCmd* pCmd); @@ -114,6 +114,11 @@ static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate); static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex); +static int32_t doCheckForCreateTable(SSqlObj* pSql, SSqlInfo* pInfo); +static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo); +static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo); +static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index); + /* * Used during parsing query sql. Since the query sql usually small in length, error position * is not needed in the final error message. @@ -126,7 +131,7 @@ static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) { assert(QUERY_IS_STABLE_QUERY(pCmd->type)); *queryOnMetricTags = true; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId != TSDB_FUNC_TAGPRJ && @@ -163,6 +168,30 @@ static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, tVariant* pVar) { return TSDB_CODE_SUCCESS; } +static int32_t handlePassword(SSqlCmd* pCmd, SSQLToken* pPwd) { + const char* msg1 = "password can not be empty"; + const char* msg2 = "name or password too long"; + const char* msg3 = "password needs single quote marks enclosed"; + + if (pPwd->type != TK_STRING) { + return invalidSqlErrMsg(pCmd, msg3); + } + + strdequote(pPwd->z); + strtrim(pPwd->z); // trim space before and after passwords + pPwd->n = strlen(pPwd->z); + + if (pPwd->n <= 0) { + return invalidSqlErrMsg(pCmd, msg1); + } + + if (pPwd->n > TSDB_PASSWORD_LEN) { + return invalidSqlErrMsg(pCmd, msg2); + } + + return TSDB_CODE_SUCCESS; +} + // todo handle memory leak in error handle function int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) { @@ -171,144 +200,100 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSqlCmd* pCmd = &(pSql->cmd); - if (!pInfo->validSql) { + if (!pInfo->valid) { return invalidSqlErrMsg(pCmd, pInfo->pzErrMsg); } SMeterMetaInfo* pMeterMetaInfo = tscAddEmptyMeterMetaInfo(pCmd); - - // transfer pInfo into select operation - switch (pInfo->sqlType) { - case DROP_TABLE: - case DROP_USER: - case DROP_ACCOUNT: - case DROP_DNODE: - case DROP_DATABASE: { - const char* msg = "param name too long"; + pCmd->command = pInfo->type; + int32_t code = 0; + + switch (pInfo->type) { + case TSDB_SQL_DROP_TABLE: + case TSDB_SQL_DROP_USER: + case TSDB_SQL_DROP_ACCT: + case TSDB_SQL_DROP_DNODE: + case TSDB_SQL_DROP_DB: { const char* msg1 = "invalid ip address"; const char* msg2 = "invalid name"; + const char* msg3 = "param name too long"; SSQLToken* pzName = &pInfo->pDCLInfo->a[0]; - if ((pInfo->sqlType != DROP_DNODE) && (tscValidateName(pzName) != TSDB_CODE_SUCCESS)) { + if ((pInfo->type != TSDB_SQL_DROP_DNODE) && (tscValidateName(pzName) != TSDB_CODE_SUCCESS)) { return invalidSqlErrMsg(pCmd, msg2); } - if (pInfo->sqlType == DROP_DATABASE) { - assert(pInfo->pDCLInfo->nTokens == 2); - - pCmd->command = TSDB_SQL_DROP_DB; - pCmd->existsCheck = (pInfo->pDCLInfo->a[1].n == 1); + if (pInfo->type == TSDB_SQL_DROP_DB) { + assert(pInfo->pDCLInfo->nTokens == 1); int32_t code = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pzName, NULL, NULL); if (code != TSDB_CODE_SUCCESS) { - invalidSqlErrMsg(pCmd, msg2); + return invalidSqlErrMsg(pCmd, msg2); } - return code; - } else if (pInfo->sqlType == DROP_TABLE) { - assert(pInfo->pDCLInfo->nTokens == 2); - - pCmd->existsCheck = (pInfo->pDCLInfo->a[1].n == 1); - pCmd->command = TSDB_SQL_DROP_TABLE; + } else if (pInfo->type == TSDB_SQL_DROP_TABLE) { + assert(pInfo->pDCLInfo->nTokens == 1); - int32_t ret = setMeterID(pSql, pzName, 0); - if (ret != TSDB_CODE_SUCCESS) { - invalidSqlErrMsg(pCmd, msg); + if (setMeterID(pSql, pzName, 0) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg3); } - return ret; - } else { - if (pzName->n > TSDB_USER_LEN) { - return invalidSqlErrMsg(pCmd, msg); + } else if (pInfo->type == TSDB_SQL_DROP_DNODE) { + if (!validateIpAddress(pzName->z, pzName->n)) { + return invalidSqlErrMsg(pCmd, msg1); } - if (pInfo->sqlType == DROP_USER) { - pCmd->command = TSDB_SQL_DROP_USER; - } else if (pInfo->sqlType == DROP_ACCOUNT) { - pCmd->command = TSDB_SQL_DROP_ACCT; - } else if (pInfo->sqlType == DROP_DNODE) { - pCmd->command = TSDB_SQL_DROP_DNODE; - const int32_t MAX_IP_ADDRESS_LEGNTH = 16; - - if (pzName->n > MAX_IP_ADDRESS_LEGNTH) { - return invalidSqlErrMsg(pCmd, msg1); - } - - char str[128] = {0}; - strncpy(str, pzName->z, pzName->n); - if (!validateIpAddress(str)) { - return invalidSqlErrMsg(pCmd, msg1); - } + strncpy(pMeterMetaInfo->name, pzName->z, pzName->n); + } else { // drop user + if (pzName->n > TSDB_USER_LEN) { + return invalidSqlErrMsg(pCmd, msg3); } strncpy(pMeterMetaInfo->name, pzName->z, pzName->n); - return TSDB_CODE_SUCCESS; } - } - case USE_DATABASE: { - pCmd->command = TSDB_SQL_USE_DB; + break; + } - SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; + case TSDB_SQL_USE_DB: { + const char* msg = "invalid db name"; + SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, "invalid db name"); - } - - if (pToken->n > TSDB_DB_NAME_LEN) { - const char* msg = "db name too long"; return invalidSqlErrMsg(pCmd, msg); } int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pToken, NULL, NULL); if (ret != TSDB_CODE_SUCCESS) { - return ret; + return invalidSqlErrMsg(pCmd, msg); } break; } - case RESET_QUERY_CACHE: { - pCmd->command = TSDB_SQL_RESET_CACHE; - break; + case TSDB_SQL_RESET_CACHE: { + return TSDB_CODE_SUCCESS; } - case SHOW_DATABASES: - case SHOW_TABLES: - case SHOW_STABLES: - case SHOW_MNODES: - case SHOW_DNODES: - case SHOW_ACCOUNTS: - case SHOW_USERS: - case SHOW_VGROUPS: - case SHOW_MODULES: - case SHOW_CONNECTIONS: - case SHOW_QUERIES: - case SHOW_STREAMS: - case SHOW_SCORES: - case SHOW_GRANTS: - case SHOW_CONFIGS: - case SHOW_VNODES: { - return setShowInfo(pSql, pInfo); - } - - case ALTER_DATABASE: - case CREATE_DATABASE: { - if (pInfo->sqlType == ALTER_DATABASE) { - pCmd->command = TSDB_SQL_ALTER_DB; - } else { - pCmd->command = TSDB_SQL_CREATE_DB; - pCmd->existsCheck = (pInfo->pDCLInfo->a[0].n == 1); + case TSDB_SQL_SHOW: { + if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; } + break; + } + + case TSDB_SQL_ALTER_DB: + case TSDB_SQL_CREATE_DB: { + const char* msg1 = "invalid db name"; + const char* msg2 = "name too long"; + SCreateDBInfo* pCreateDB = &(pInfo->pDCLInfo->dbOpt); if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) { - const char* msg3 = "invalid db name"; - return invalidSqlErrMsg(pCmd, msg3); + return invalidSqlErrMsg(pCmd, msg1); } int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL); if (ret != TSDB_CODE_SUCCESS) { - const char* msg2 = "name too long"; return invalidSqlErrMsg(pCmd, msg2); } @@ -319,168 +304,59 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { break; } - case CREATE_DNODE: { - // todo parse hostname - pCmd->command = TSDB_SQL_CREATE_DNODE; + case TSDB_SQL_CREATE_DNODE: { // todo parse hostname const char* msg = "invalid ip address"; - char ipAddr[64] = {0}; - const int32_t MAX_IP_ADDRESS_LENGTH = 16; - if (pInfo->pDCLInfo->nTokens > 1 || pInfo->pDCLInfo->a[0].n > MAX_IP_ADDRESS_LENGTH) { + if (pInfo->pDCLInfo->nTokens > 1) { return invalidSqlErrMsg(pCmd, msg); } - memcpy(ipAddr, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); - if (validateIpAddress(ipAddr) == false) { + SSQLToken* pIpAddr = &pInfo->pDCLInfo->a[0]; + if (!validateIpAddress(pIpAddr->z, pIpAddr->n)) { return invalidSqlErrMsg(pCmd, msg); } - strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); break; } - case CREATE_ACCOUNT: - case CREATE_USER: { - pCmd->command = (pInfo->sqlType == CREATE_USER) ? TSDB_SQL_CREATE_USER : TSDB_SQL_CREATE_ACCT; - assert(pInfo->pDCLInfo->nTokens >= 2); + case TSDB_SQL_CREATE_ACCT: + case TSDB_SQL_ALTER_ACCT: { + const char* msg1 = "invalid state option, available options[no, r, w, all]"; + const char* msg2 = "invalid user/account name"; + const char* msg3 = "name too long"; - if (pInfo->pDCLInfo->a[1].type != TK_STRING) { - const char* msg3 = "password needs single quote marks enclosed"; - return invalidSqlErrMsg(pCmd, msg3); - } + SSQLToken* pName = &pInfo->pDCLInfo->user.user; + SSQLToken* pPwd = &pInfo->pDCLInfo->user.passwd; - strdequote(pInfo->pDCLInfo->a[1].z); - strtrim(pInfo->pDCLInfo->a[1].z); // trim space before and after passwords - pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z); - - if (pInfo->pDCLInfo->a[1].n <= 0) { - const char* msg1 = "password can not be empty"; - return invalidSqlErrMsg(pCmd, msg1); - } - - if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { - const char* msg = "name or password too long"; - return invalidSqlErrMsg(pCmd, msg); - } - - if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { - const char* msg2 = "invalid user/account name"; - return invalidSqlErrMsg(pCmd, msg2); - } - - strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); // name - strncpy(pCmd->payload, pInfo->pDCLInfo->a[1].z, pInfo->pDCLInfo->a[1].n); // passwd - - if (pInfo->sqlType == CREATE_ACCOUNT) { - SCreateAcctSQL* pAcctOpt = &pInfo->pDCLInfo->acctOpt; - - pCmd->defaultVal[0] = pAcctOpt->users; - pCmd->defaultVal[1] = pAcctOpt->dbs; - pCmd->defaultVal[2] = pAcctOpt->tseries; - pCmd->defaultVal[3] = pAcctOpt->streams; - pCmd->defaultVal[4] = pAcctOpt->pps; - pCmd->defaultVal[5] = pAcctOpt->storage; - pCmd->defaultVal[6] = pAcctOpt->qtime; - pCmd->defaultVal[7] = pAcctOpt->conns; - - if (pAcctOpt->stat.n == 0) { - pCmd->defaultVal[8] = -1; - } else { - strdequote(pAcctOpt->stat.z); - pAcctOpt->stat.n = strlen(pAcctOpt->stat.z); - - if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) { - pCmd->defaultVal[8] = TSDB_VN_READ_ACCCESS; - } else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) { - pCmd->defaultVal[8] = TSDB_VN_WRITE_ACCCESS; - } else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) { - pCmd->defaultVal[8] = TSDB_VN_ALL_ACCCESS; - } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { - pCmd->defaultVal[8] = 0; - } else { - const char* msg4 = "invalid state option, available options[no, r, w, all]"; - return invalidSqlErrMsg(pCmd, msg4); - } - } - } - break; - } - case ALTER_ACCT: { - pCmd->command = TSDB_SQL_ALTER_ACCT; - int32_t num = pInfo->pDCLInfo->nTokens; - assert(num >= 1 && num <= 2); - - const char* msg = "password too long"; - - if (num == 2) { - if (pInfo->pDCLInfo->a[1].type != TK_STRING) { - const char* msg3 = "password needs single quote marks enclosed"; - return invalidSqlErrMsg(pCmd, msg3); - } - - strdequote(pInfo->pDCLInfo->a[1].z); - strtrim(pInfo->pDCLInfo->a[1].z); // trim space before and after passwords - pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z); - - if (pInfo->pDCLInfo->a[1].n <= 0) { - const char* msg1 = "password can not be empty"; - return invalidSqlErrMsg(pCmd, msg1); - } - - if (pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { - return invalidSqlErrMsg(pCmd, msg); - } - - strncpy(pCmd->payload, pInfo->pDCLInfo->a[1].z, pInfo->pDCLInfo->a[1].n); // passwd + if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; } - if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN) { - return invalidSqlErrMsg(pCmd, msg); + if (pName->n > TSDB_USER_LEN) { + return invalidSqlErrMsg(pCmd, msg3); } - if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { - const char* msg2 = "invalid user/account name"; + if (tscValidateName(pName) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(pCmd, msg2); } - strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); // name - SCreateAcctSQL* pAcctOpt = &pInfo->pDCLInfo->acctOpt; - pCmd->defaultVal[0] = pAcctOpt->users; - pCmd->defaultVal[1] = pAcctOpt->dbs; - pCmd->defaultVal[2] = pAcctOpt->tseries; - pCmd->defaultVal[3] = pAcctOpt->streams; - pCmd->defaultVal[4] = pAcctOpt->pps; - pCmd->defaultVal[5] = pAcctOpt->storage; - pCmd->defaultVal[6] = pAcctOpt->qtime; - pCmd->defaultVal[7] = pAcctOpt->conns; - - if (pAcctOpt->stat.n == 0) { - pCmd->defaultVal[8] = -1; - } else { - strdequote(pAcctOpt->stat.z); - pAcctOpt->stat.n = strlen(pAcctOpt->stat.z); - + if (pAcctOpt->stat.n > 0) { if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) { - pCmd->defaultVal[8] = TSDB_VN_READ_ACCCESS; } else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) { - pCmd->defaultVal[8] = TSDB_VN_WRITE_ACCCESS; } else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) { - pCmd->defaultVal[8] = TSDB_VN_ALL_ACCCESS; } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { - pCmd->defaultVal[8] = 0; } else { - const char* msg4 = "invalid state option, available options[no, r, w, all]"; - return invalidSqlErrMsg(pCmd, msg4); + return invalidSqlErrMsg(pCmd, msg1); } } + break; } - case DESCRIBE_TABLE: { - pCmd->command = TSDB_SQL_DESCRIBE_TABLE; + case TSDB_SQL_DESCRIBE_TABLE: { SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; - const char* msg = "table name is too long"; + const char* msg2 = "table name is too long"; const char* msg1 = "invalid table name"; if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) { @@ -488,107 +364,99 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (pToken->n > TSDB_METER_NAME_LEN) { - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg2); } if (setMeterID(pSql, pToken, 0) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg); - } - - int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0); - if (ret != TSDB_CODE_SUCCESS) { - return ret; + return invalidSqlErrMsg(pCmd, msg2); } - break; + return tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0); } - case ALTER_DNODE: - case ALTER_USER_PASSWD: - case ALTER_USER_PRIVILEGES: { - pCmd->command = (pInfo->sqlType == ALTER_DNODE) ? TSDB_SQL_CFG_DNODE : TSDB_SQL_ALTER_USER; - - tDCLSQL* pDCL = pInfo->pDCLInfo; - const char* msg = "parameters too long"; + case TSDB_SQL_CFG_DNODE: { const char* msg1 = "invalid ip address"; const char* msg2 = "invalid configure options or values"; - const char* msg3 = "password can not be empty"; - if (pInfo->sqlType != ALTER_DNODE) { - strdequote(pDCL->a[1].z); - strtrim(pDCL->a[1].z); - pDCL->a[1].n = strlen(pDCL->a[1].z); + /* validate the ip address */ + tDCLSQL* pDCL = pInfo->pDCLInfo; + if (!validateIpAddress(pDCL->a[0].z, pDCL->a[0].n)) { + return invalidSqlErrMsg(pCmd, msg1); } - if (pDCL->a[1].n <= 0) { - return invalidSqlErrMsg(pCmd, msg3); + /* validate the parameter names and options */ + if (validateDNodeConfig(pDCL) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg2); } - if (pDCL->a[0].n > TSDB_METER_NAME_LEN || pDCL->a[1].n > TSDB_PASSWORD_LEN) { - return invalidSqlErrMsg(pCmd, msg); - } + char* pMsg = pCmd->payload + tsRpcHeadSize; + pMsg += sizeof(SMgmtHead); - if (pCmd->command == TSDB_SQL_CFG_DNODE) { - char ip[128] = {0}; - strncpy(ip, pDCL->a[0].z, pDCL->a[0].n); + SCfgMsg* pCfg = (SCfgMsg*)pMsg; + strncpy(pCfg->ip, pDCL->a[0].z, pDCL->a[0].n); - /* validate the ip address */ - if (!validateIpAddress(ip)) { - return invalidSqlErrMsg(pCmd, msg1); - } + strncpy(pCfg->config, pDCL->a[1].z, pDCL->a[1].n); - strcpy(pMeterMetaInfo->name, ip); + if (pDCL->nTokens == 3) { + pCfg->config[pDCL->a[1].n] = ' '; // add sep + strncpy(&pCfg->config[pDCL->a[1].n + 1], pDCL->a[2].z, pDCL->a[2].n); + } - /* validate the parameter names and options */ - if (validateDNodeConfig(pDCL) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg2); - } + break; + } - strncpy(pCmd->payload, pDCL->a[1].z, pDCL->a[1].n); + case TSDB_SQL_CREATE_USER: + case TSDB_SQL_ALTER_USER: { + const char* msg5 = "invalid user rights"; + const char* msg7 = "not support options"; + const char* msg2 = "invalid user/account name"; + const char* msg3 = "name too long"; - if (pDCL->nTokens == 3) { - pCmd->payload[pDCL->a[1].n] = ' '; // add sep - strncpy(&pCmd->payload[pDCL->a[1].n + 1], pDCL->a[2].z, pDCL->a[2].n); - } - } else { - const char* msg = "invalid user rights"; - const char* msg1 = "password can not be empty or larger than 24 characters"; + pCmd->command = pInfo->type; + tDCLSQL* pDCL = pInfo->pDCLInfo; - strncpy(pMeterMetaInfo->name, pDCL->a[0].z, pDCL->a[0].n); + SUserInfo* pUser = &pInfo->pDCLInfo->user; + SSQLToken* pName = &pUser->user; + SSQLToken* pPwd = &pUser->passwd; - if (pInfo->sqlType == ALTER_USER_PASSWD) { - /* update the password for user */ - pCmd->order.order |= TSDB_ALTER_USER_PASSWD; + if (pName->n > TSDB_USER_LEN) { + return invalidSqlErrMsg(pCmd, msg3); + } - strdequote(pDCL->a[1].z); - pDCL->a[1].n = strlen(pDCL->a[1].z); + if (tscValidateName(pName) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg2); + } - if (pDCL->a[1].n <= 0 || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { - /* password cannot be empty string */ - return invalidSqlErrMsg(pCmd, msg1); + if (pCmd->command == TSDB_SQL_CREATE_USER) { + if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + } else { + if (pUser->type == TSDB_ALTER_USER_PASSWD) { + if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; } + } else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { + assert(pPwd == NULL); - strncpy(pCmd->payload, pDCL->a[1].z, pDCL->a[1].n); - } else if (pInfo->sqlType == ALTER_USER_PRIVILEGES) { - pCmd->order.order |= TSDB_ALTER_USER_PRIVILEGES; - - if (strncasecmp(pDCL->a[1].z, "super", 5) == 0 && pDCL->a[1].n == 5) { + if (strncasecmp(pUser->privilege.z, "super", 5) == 0 && pDCL->a[1].n == 5) { pCmd->count = 1; } else if (strncasecmp(pDCL->a[1].z, "read", 4) == 0 && pDCL->a[1].n == 4) { pCmd->count = 2; } else if (strncasecmp(pDCL->a[1].z, "write", 5) == 0 && pDCL->a[1].n == 5) { pCmd->count = 3; } else { - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg5); } } else { - return TSDB_CODE_INVALID_SQL; + return invalidSqlErrMsg(pCmd, msg7); } } + break; } - case ALTER_LOCAL: { - pCmd->command = TSDB_SQL_CFG_LOCAL; + + case TSDB_SQL_CFG_LOCAL: { tDCLSQL* pDCL = pInfo->pDCLInfo; const char* msg = "invalid configure options or values"; @@ -605,447 +473,64 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { break; } - case TSQL_CREATE_NORMAL_METER: - case TSQL_CREATE_NORMAL_METRIC: { - const char* msg = "table name too long"; - const char* msg1 = "invalid table name"; - - tFieldList* pFieldList = pInfo->pCreateTableInfo->colInfo.pColumns; - tFieldList* pTagList = pInfo->pCreateTableInfo->colInfo.pTagColumns; - assert(pFieldList != NULL); - - pCmd->command = TSDB_SQL_CREATE_TABLE; - pCmd->existsCheck = pInfo->pCreateTableInfo->existCheck; - - // if sql specifies db, use it, otherwise use default db - SSQLToken* pzTableName = &(pInfo->pCreateTableInfo->name); - - if (tscValidateName(pzTableName) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg1); - } - - if (setMeterID(pSql, pzTableName, 0) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg); - } - - if (!validateTableColumnInfo(pFieldList, pCmd) || - (pTagList != NULL && !validateTagParams(pTagList, pFieldList, pCmd))) { - return TSDB_CODE_INVALID_SQL; - } - int32_t col = 0; - for (; col < pFieldList->nField; ++col) { - tscFieldInfoSetValFromField(&pCmd->fieldsInfo, col, &pFieldList->p[col]); - } - pCmd->numOfCols = (int16_t)pFieldList->nField; + case TSDB_SQL_CREATE_TABLE: { + SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo; - if (pTagList != NULL) { // create metric[optional] - for (int32_t i = 0; i < pTagList->nField; ++i) { - tscFieldInfoSetValFromField(&pCmd->fieldsInfo, col++, &pTagList->p[i]); + if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { + if ((code = doCheckForCreateTable(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + return code; } - pCmd->count = pTagList->nField; - } - break; - } - case TSQL_CREATE_METER_FROM_METRIC: { - pCmd->command = TSDB_SQL_CREATE_TABLE; - pCmd->existsCheck = pInfo->pCreateTableInfo->existCheck; - - const char* msg = "invalid table name"; - const char* msg1 = "illegal value or data overflow"; - const char* msg2 = "illegal number of tags"; - const char* msg3 = "tag value too long"; - - // table name - // metric name, create table by using dst - SSQLToken* pToken = &(pInfo->pCreateTableInfo->usingInfo.metricName); - - if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg); - } - - if (setMeterID(pSql, pToken, 0) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg); - } - - // get meter meta from mnode - STagData* pTag = (STagData*)pCmd->payload; - strncpy(pTag->name, pMeterMetaInfo->name, TSDB_METER_ID_LEN); - - tVariantList* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals; - - int32_t code = tscGetMeterMeta(pSql, pTag->name, 0); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - if (pMeterMetaInfo->pMeterMeta->numOfTags != pList->nExpr) { - return invalidSqlErrMsg(pCmd, msg2); - } - - // too long tag values will return invalid sql, not be truncated automatically - SSchema* pTagSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta); - - char* tagVal = pTag->data; - for (int32_t i = 0; i < pList->nExpr; ++i) { - int32_t ret = tVariantDump(&(pList->a[i].pVar), tagVal, pTagSchema[i].type); - if (ret != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg1); + } else if (pCreateTable->type == TSQL_CREATE_TABLE_FROM_STABLE) { + if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + return code; } - // validate the length of binary - if ((pTagSchema[i].type == TSDB_DATA_TYPE_BINARY || pTagSchema[i].type == TSDB_DATA_TYPE_NCHAR) && - pList->a[i].pVar.nLen > pTagSchema[i].bytes) { - return invalidSqlErrMsg(pCmd, msg3); + } else if (pCreateTable->type == TSQL_CREATE_STREAM) { + if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + return code; } - - tagVal += pTagSchema[i].bytes; - } - - if (tscValidateName(&pInfo->pCreateTableInfo->name) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg); - } - - int32_t ret = setMeterID(pSql, &pInfo->pCreateTableInfo->name, 0); - if (ret != TSDB_CODE_SUCCESS) { - return ret; } - pCmd->numOfCols = 0; - pCmd->count = 0; break; } - case TSQL_CREATE_STREAM: { - pCmd->command = TSDB_SQL_CREATE_TABLE; - const char* msg1 = "invalid table name"; - const char* msg2 = "table name too long"; - const char* msg3 = "fill only available for interval query"; - const char* msg4 = "fill option not supported in stream computing"; - const char* msg5 = "sql too long"; // todo ADD support - - // if sql specifies db, use it, otherwise use default db - SSQLToken* pzTableName = &(pInfo->pCreateTableInfo->name); - SQuerySQL* pQuerySql = pInfo->pCreateTableInfo->pSelect; - if (tscValidateName(pzTableName) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg1); - } - - tVariantList* pSrcMeterName = pInfo->pCreateTableInfo->pSelect->from; - tVariant* pVar = &pSrcMeterName->a[0].pVar; - - SSQLToken srcToken = {.z = pVar->pz, .n = pVar->nLen, .type = TK_STRING}; - if (tscValidateName(&srcToken) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg1); - } - - if (setMeterID(pSql, &srcToken, 0) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg2); - } - - int32_t code = tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - bool isMetric = UTIL_METER_IS_METRIC(pMeterMetaInfo); - if (parseSelectClause(pCmd, pQuerySql->pSelection, isMetric) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - if (pQuerySql->pWhere != NULL) { // query condition in stream computing - if (parseWhereClause(pSql, &pQuerySql->pWhere) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - } - - // set interval value - if (parseIntervalClause(pCmd, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } else { - if ((pCmd->nAggTimeInterval > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pCmd) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_INVALID_SQL; + case TSDB_SQL_SELECT: { + for(int32_t i = 0; i < pInfo->subclauseInfo.numOfClause; ++i) { + SQuerySQL* pQuerySql = pInfo->subclauseInfo.pClause[i]; + + if ((code = doCheckForQuery(pSql, pQuerySql, i)) != TSDB_CODE_SUCCESS) { + return code; } } + + return TSDB_CODE_SUCCESS;// do not build query message here + } - if (setSlidingClause(pCmd, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - // set the created table[stream] name - if (setMeterID(pSql, pzTableName, 0) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg1); - } - - // copy sql length - int ret = tscAllocPayload(pCmd, pQuerySql->selectToken.n + 8); - if (TSDB_CODE_SUCCESS != ret) { - invalidSqlErrMsg(pCmd, "client out of memory"); - return ret; - } - - strncpy(pCmd->payload, pQuerySql->selectToken.z, pQuerySql->selectToken.n); - if (pQuerySql->selectToken.n > TSDB_MAX_SAVED_SQL_LEN) { - return invalidSqlErrMsg(pCmd, msg5); - } - - if (tsRewriteFieldNameIfNecessary(pCmd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - pCmd->numOfCols = pCmd->fieldsInfo.numOfOutputCols; - - if (validateSqlFunctionInStreamSql(pCmd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - /* - * check if fill operation is available, the fill operation is parsed and executed during query execution, not - * here. - */ - if (pQuerySql->fillType != NULL) { - if (pCmd->nAggTimeInterval == 0) { - return invalidSqlErrMsg(pCmd, msg3); - } - - tVariantListItem* pItem = &pQuerySql->fillType->a[0]; - if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) { - if (!((strncmp(pItem->pVar.pz, "none", 4) == 0 && pItem->pVar.nLen == 4) || - (strncmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4))) { - return invalidSqlErrMsg(pCmd, msg4); - } - } + case TSDB_SQL_ALTER_TABLE: { + if ((code = setAlterTableInfo(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + return code; } break; } - case TSQL_QUERY_METER: { - SQuerySQL* pQuerySql = pInfo->pQueryInfo; - assert(pQuerySql != NULL && (pQuerySql->from == NULL || pQuerySql->from->nExpr > 0)); - - const char* msg0 = "invalid table name"; - const char* msg1 = "table name too long"; - const char* msg2 = "point interpolation query needs timestamp"; - const char* msg3 = "sliding value too small"; - const char* msg4 = "sliding value no larger than the interval value"; - const char* msg5 = "fill only available for interval query"; - const char* msg6 = "start(end) time of query range required or time range too large"; - const char* msg7 = "illegal number of tables in from clause"; - const char* msg8 = "too many columns in selection clause"; - const char* msg9 = "TWA query requires both the start and end time"; - - int32_t code = TSDB_CODE_SUCCESS; - - // too many result columns not support order by in query - if (pQuerySql->pSelection->nExpr > TSDB_MAX_COLUMNS) { - return invalidSqlErrMsg(pCmd, msg8); - } - - /* - * handle the sql expression without from subclause - * select current_database(); - * select server_version(); - * select client_version(); - * select server_state(); - */ - if (pQuerySql->from == NULL) { - assert(pQuerySql->fillType == NULL && pQuerySql->pGroupby == NULL && pQuerySql->pWhere == NULL && - pQuerySql->pSortOrder == NULL); - return doLocalQueryProcess(pQuerySql, pCmd); - } - - if (pQuerySql->from->nExpr > TSDB_MAX_JOIN_TABLE_NUM) { - return invalidSqlErrMsg(pCmd, msg7); - } - - // set all query tables, which are maybe more than one. - for (int32_t i = 0; i < pQuerySql->from->nExpr; ++i) { - tVariant* pTableItem = &pQuerySql->from->a[i].pVar; - - if (pTableItem->nType != TSDB_DATA_TYPE_BINARY) { - return invalidSqlErrMsg(pCmd, msg0); - } - - pTableItem->nLen = strdequote(pTableItem->pz); - - SSQLToken tableName = {.z = pTableItem->pz, .n = pTableItem->nLen, .type = TK_STRING}; - if (tscValidateName(&tableName) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg0); - } - - if (pCmd->numOfTables <= i) { - tscAddEmptyMeterMetaInfo(pCmd); - } - - SSQLToken t = {.type = TSDB_DATA_TYPE_BINARY, .n = pTableItem->nLen, .z = pTableItem->pz}; - if (setMeterID(pSql, &t, i) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg1); - } - - SMeterMetaInfo* pMeterInfo1 = tscGetMeterMetaInfo(pCmd, i); - code = tscGetMeterMeta(pSql, pMeterInfo1->name, i); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } - - pSql->cmd.command = TSDB_SQL_SELECT; - - // parse the group by clause in the first place - if (parseGroupbyClause(pCmd, pQuerySql->pGroupby) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - bool isMetric = UTIL_METER_IS_METRIC(pMeterMetaInfo); - if (parseSelectClause(pCmd, pQuerySql->pSelection, isMetric) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - // set interval value - if (parseIntervalClause(pCmd, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } else { - if ((pCmd->nAggTimeInterval > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pCmd) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_INVALID_SQL; - } - } - - // set sliding value - SSQLToken* pSliding = &pQuerySql->sliding; - if (pSliding->n != 0) { - // TODO refactor pCmd->count == 1 means sql in stream function - if (!tscEmbedded && pCmd->count == 0) { - const char* msg = "not support sliding in query"; - return invalidSqlErrMsg(pCmd, msg); - } - - getTimestampInUsFromStr(pSliding->z, pSliding->n, &pCmd->nSlidingTime); - if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) { - pCmd->nSlidingTime /= 1000; - } - - if (pCmd->nSlidingTime < tsMinSlidingTime) { - return invalidSqlErrMsg(pCmd, msg3); - } - - if (pCmd->nSlidingTime > pCmd->nAggTimeInterval) { - return invalidSqlErrMsg(pCmd, msg4); - } - } - - // set order by info - if (parseOrderbyClause(pCmd, pQuerySql, tsGetSchema(pMeterMetaInfo->pMeterMeta), - pMeterMetaInfo->pMeterMeta->numOfColumns) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - // set where info - if (pQuerySql->pWhere != NULL) { - if (parseWhereClause(pSql, &pQuerySql->pWhere) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; - } - - pQuerySql->pWhere = NULL; - - if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) { - pCmd->stime = pCmd->stime / 1000; - pCmd->etime = pCmd->etime / 1000; - } - } else { // set the time rang - pCmd->stime = 0; - pCmd->etime = INT64_MAX; - } - - // user does not specified the query time window, twa is not allowed in such case. - if ((pCmd->stime == 0 || pCmd->etime == INT64_MAX || - (pCmd->etime == INT64_MAX / 1000 && pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI)) && - tscIsTWAQuery(pCmd)) { - return invalidSqlErrMsg(pCmd, msg9); - } - - // no result due to invalid query time range - if (pCmd->stime > pCmd->etime) { - pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; - return TSDB_CODE_SUCCESS; - } - - if (!hasTimestampForPointInterpQuery(pCmd)) { - return invalidSqlErrMsg(pCmd, msg2); - } - - if (pQuerySql->fillType != NULL) { - if (pCmd->nAggTimeInterval == 0 && (!tscIsPointInterpQuery(pCmd))) { - return invalidSqlErrMsg(pCmd, msg5); - } - - if (pCmd->nAggTimeInterval > 0) { - int64_t timeRange = labs(pCmd->stime - pCmd->etime); - // number of result is not greater than 10,000,000 - if ((timeRange == 0) || (timeRange / pCmd->nAggTimeInterval) > MAX_RETRIEVE_ROWS_IN_INTERVAL_QUERY) { - return invalidSqlErrMsg(pCmd, msg6); - } - } - - int32_t ret = parseFillClause(pCmd, pQuerySql); - if (ret != TSDB_CODE_SUCCESS) { - return ret; - } - } - - // in case of join query, time range is required. - if (QUERY_IS_JOIN_QUERY(pCmd->type)) { - int64_t timeRange = labs(pCmd->stime - pCmd->etime); - - if (timeRange == 0 && pCmd->stime == 0) { - return invalidSqlErrMsg(pCmd, msg6); - } - } - - // handle the limit offset value, validate the limit - pCmd->limit = pQuerySql->limit; - - // temporarily save the original limitation value - if ((code = parseLimitClause(pSql, pQuerySql)) != TSDB_CODE_SUCCESS) { + case TSDB_SQL_KILL_QUERY: + case TSDB_SQL_KILL_STREAM: + case TSDB_SQL_KILL_CONNECTION: { + if ((code = setKillInfo(pSql, pInfo)) != TSDB_CODE_SUCCESS) { return code; } - if ((code = doFunctionsCompatibleCheck(pSql)) != TSDB_CODE_SUCCESS) { - return code; - } - - setColumnOffsetValueInResultset(pCmd); - - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { - updateTagColumnIndex(pCmd, i); - } - break; } - case TSQL_INSERT: { - assert(false); - } - case ALTER_TABLE_ADD_COLUMN: - case ALTER_TABLE_DROP_COLUMN: - case ALTER_TABLE_TAGS_ADD: - case ALTER_TABLE_TAGS_DROP: - case ALTER_TABLE_TAGS_CHG: - case ALTER_TABLE_TAGS_SET: { - return setAlterTableInfo(pSql, pInfo); - } - - case KILL_CONNECTION: - case KILL_QUERY: - case KILL_STREAM: { - return setKillInfo(pSql, pInfo); - } default: - return TSDB_CODE_INVALID_SQL; + return invalidSqlErrMsg(pCmd, "not support sql expression"); } - return TSDB_CODE_SUCCESS; + return tscBuildMsg[pCmd->command](pSql, pInfo); } /* @@ -1053,7 +538,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { * are available. */ static bool isTopBottomQuery(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int32_t functionId = tscSqlExprGet(pCmd, i)->functionId; if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) { @@ -1076,20 +561,20 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { // interval is not null SSQLToken* t = &pQuerySql->interval; - if (getTimestampInUsFromStr(t->z, t->n, &pCmd->nAggTimeInterval) != TSDB_CODE_SUCCESS) { + if (getTimestampInUsFromStr(t->z, t->n, &pCmd->pQueryInfo[0].nAggTimeInterval) != TSDB_CODE_SUCCESS) { return TSDB_CODE_INVALID_SQL; } /* revised the time precision according to the flag */ if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) { - pCmd->nAggTimeInterval = pCmd->nAggTimeInterval / 1000; + pCmd->pQueryInfo[0].nAggTimeInterval = pCmd->pQueryInfo[0].nAggTimeInterval / 1000; } /* parser has filter the illegal type, no need to check here */ - pCmd->intervalTimeUnit = pQuerySql->interval.z[pQuerySql->interval.n - 1]; + pCmd->pQueryInfo[0].intervalTimeUnit = pQuerySql->interval.z[pQuerySql->interval.n - 1]; // interval cannot be less than 10 milliseconds - if (pCmd->nAggTimeInterval < tsMinIntervalTime) { + if (pCmd->pQueryInfo[0].nAggTimeInterval < tsMinIntervalTime) { return invalidSqlErrMsg(pCmd, msg2); } @@ -1099,7 +584,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { } // check the invalid sql expresssion: select count(tbname)/count(tag1)/count(tag2) from super_table interval(1d); - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_COUNT && TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { return invalidSqlErrMsg(pCmd, msg1); @@ -1110,7 +595,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { uint64_t uid = tscSqlExprGet(pCmd, 0)->uid; int32_t tableIndex = COLUMN_INDEX_INITIAL_VAL; - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); if (pMeterMetaInfo->pMeterMeta->uid == uid) { tableIndex = i; @@ -1139,16 +624,16 @@ int32_t setSlidingClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { SSQLToken* pSliding = &pQuerySql->sliding; if (pSliding->n != 0) { - getTimestampInUsFromStr(pSliding->z, pSliding->n, &pCmd->nSlidingTime); + getTimestampInUsFromStr(pSliding->z, pSliding->n, &pCmd->pQueryInfo[0].nSlidingTime); if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) { - pCmd->nSlidingTime /= 1000; + pCmd->pQueryInfo[0].nSlidingTime /= 1000; } - if (pCmd->nSlidingTime < tsMinSlidingTime) { + if (pCmd->pQueryInfo[0].nSlidingTime < tsMinSlidingTime) { return invalidSqlErrMsg(pCmd, msg0); } - if (pCmd->nSlidingTime > pCmd->nAggTimeInterval) { + if (pCmd->pQueryInfo[0].nSlidingTime > pCmd->pQueryInfo[0].nAggTimeInterval) { return invalidSqlErrMsg(pCmd, msg1); } } @@ -1540,7 +1025,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric const char* msg3 = "not support query expression"; for (int32_t i = 0; i < pSelection->nExpr; ++i) { - int32_t outputIndex = pCmd->fieldsInfo.numOfOutputCols; + int32_t outputIndex = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; tSQLExprItem* pItem = &pSelection->a[i]; // project on all fields @@ -1607,7 +1092,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric return invalidSqlErrMsg(pCmd, msg3); } - if (pCmd->fieldsInfo.numOfOutputCols > TSDB_MAX_COLUMNS) { + if (pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols > TSDB_MAX_COLUMNS) { return TSDB_CODE_INVALID_SQL; } } @@ -1645,7 +1130,7 @@ int32_t insertResultField(SSqlCmd* pCmd, int32_t outputIndex, SColumnList* pIdLi tscColumnBaseInfoInsert(pCmd, &(pIdList->ids[i])); } - tscFieldInfoSetValue(&pCmd->fieldsInfo, outputIndex, type, fieldName, bytes); + tscFieldInfoSetValue(&pCmd->pQueryInfo[0].fieldsInfo, outputIndex, type, fieldName, bytes); return TSDB_CODE_SUCCESS; } @@ -1769,7 +1254,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) { const char* msg0 = "invalid column name"; const char* msg1 = "tag for table query is not allowed"; - int32_t startPos = pCmd->fieldsInfo.numOfOutputCols; + int32_t startPos = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; if (pItem->pNode->nSQLOptr == TK_ALL) { // project on all fields SColumnIndex index = COLUMN_INDEX_INITIALIZER; @@ -1779,7 +1264,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) { // all meters columns are required if (index.tableIndex == COLUMN_INDEX_INITIAL_VAL) { // all table columns are required. - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { index.tableIndex = i; int32_t inc = doAddProjectionExprAndResultFields(pCmd, &index, startPos); startPos += inc; @@ -1958,7 +1443,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem SColumnIndex index = COLUMN_INDEX_INITIALIZER; if ((getColumnIndexByNameEx(&pParamElem->pNode->colInfo, pCmd, &index) != TSDB_CODE_SUCCESS) || - index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { + index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { return invalidSqlErrMsg(pCmd, msg3); } @@ -2096,7 +1581,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem } else { // select * from xxx int32_t numOfFields = 0; - for (int32_t j = 0; j < pCmd->numOfTables; ++j) { + for (int32_t j = 0; j < pCmd->pQueryInfo->numOfTables; ++j) { pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, j); SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); @@ -2292,7 +1777,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p } else { // not specify the table name, try to locate the table index by column name if (pIndex->tableIndex == COLUMN_INDEX_INITIAL_VAL) { - for (int16_t i = 0; i < pCmd->numOfTables; ++i) { + for (int16_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { int16_t colIndex = doGetColumnIndex(pCmd, i, pToken); if (colIndex != COLUMN_INDEX_INITIAL_VAL) { @@ -2325,7 +1810,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex) { if (pTableToken->n == 0) { // only one table and no table name prefix in column name - if (pCmd->numOfTables == 1) { + if (pCmd->pQueryInfo->numOfTables == 1) { pIndex->tableIndex = 0; } @@ -2335,7 +1820,7 @@ static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL; char tableName[TSDB_METER_ID_LEN + 1] = {0}; - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); extractTableName(pMeterMetaInfo->name, tableName); @@ -2364,7 +1849,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pInd } int32_t getColumnIndexByNameEx(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex) { - if (pCmd->pMeterInfo == NULL || pCmd->numOfTables == 0) { + if (pCmd->pQueryInfo[0].pMeterInfo == NULL || pCmd->pQueryInfo->numOfTables == 0) { return TSDB_CODE_INVALID_SQL; } @@ -2440,125 +1925,75 @@ int32_t changeFunctionID(int32_t optr, int16_t* functionId) { return TSDB_CODE_SUCCESS; } -// TODO support like for showing metrics, there are show meters with like ops int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSqlCmd* pCmd = &pSql->cmd; SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); pCmd->command = TSDB_SQL_SHOW; - int8_t type = pInfo->sqlType; - const char* msg = "database name too long"; - const char* msg1 = "invalid database name"; + const char* msg1 = "invalid name"; const char* msg2 = "pattern filter string too long"; - - switch (type) { - case SHOW_VGROUPS: - pCmd->showType = TSDB_MGMT_TABLE_VGROUP; - break; - case SHOW_TABLES: - pCmd->showType = TSDB_MGMT_TABLE_TABLE; - break; - case SHOW_STABLES: - pCmd->showType = TSDB_MGMT_TABLE_METRIC; - break; - - case SHOW_DATABASES: - pCmd->showType = TSDB_MGMT_TABLE_DB; - break; - case SHOW_MNODES: - pCmd->showType = TSDB_MGMT_TABLE_MNODE; - break; - case SHOW_DNODES: - pCmd->showType = TSDB_MGMT_TABLE_PNODE; - break; - case SHOW_ACCOUNTS: - pCmd->showType = TSDB_MGMT_TABLE_ACCT; - break; - case SHOW_USERS: - pCmd->showType = TSDB_MGMT_TABLE_USER; - break; - case SHOW_MODULES: - pCmd->showType = TSDB_MGMT_TABLE_MODULE; - break; - case SHOW_CONNECTIONS: - pCmd->showType = TSDB_MGMT_TABLE_CONNS; - break; - case SHOW_QUERIES: - pCmd->showType = TSDB_MGMT_TABLE_QUERIES; - break; - case SHOW_SCORES: - pCmd->showType = TSDB_MGMT_TABLE_SCORES; - break; - case SHOW_GRANTS: - pCmd->showType = TSDB_MGMT_TABLE_GRANTS; - break; - case SHOW_STREAMS: - pCmd->showType = TSDB_MGMT_TABLE_STREAMS; - break; - case SHOW_CONFIGS: - pCmd->showType = TSDB_MGMT_TABLE_CONFIGS; - break; - case SHOW_VNODES: - pCmd->showType = TSDB_MGMT_TABLE_VNODES; - break; - default: - return TSDB_CODE_INVALID_SQL; - } + const char* msg3 = "database name too long"; + const char* msg4 = "invalid ip address"; + const char* msg5 = "database name is empty"; + const char* msg6 = "pattern string is empty"; /* * database prefix in pInfo->pDCLInfo->a[0] * wildcard in like clause in pInfo->pDCLInfo->a[1] */ - if (type == SHOW_TABLES || type == SHOW_STABLES || type == SHOW_VGROUPS) { + SShowInfo* pShowInfo = &pInfo->pDCLInfo->showOpt; + int16_t showType = pShowInfo->showType; + if (showType == TSDB_MGMT_TABLE_TABLE || showType == TSDB_MGMT_TABLE_METRIC || showType == TSDB_MGMT_TABLE_VGROUP) { // db prefix in tagCond, show table conds in payload - if (pInfo->pDCLInfo->nTokens > 0) { - SSQLToken* pDbPrefixToken = &pInfo->pDCLInfo->a[0]; + SSQLToken* pDbPrefixToken = &pShowInfo->prefix; + if (pDbPrefixToken->type != 0) { + assert(pDbPrefixToken->n >= 0); if (pDbPrefixToken->n > TSDB_DB_NAME_LEN) { // db name is too long - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg3); } - if (pDbPrefixToken->n > 0 && tscValidateName(pDbPrefixToken) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg1); + if (pDbPrefixToken->n <= 0) { + return invalidSqlErrMsg(pCmd, msg5); } - int32_t ret = 0; - if (pDbPrefixToken->n > 0) { // has db prefix - ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pDbPrefixToken, NULL, NULL); + if (tscValidateName(pDbPrefixToken) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); } + int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pDbPrefixToken, NULL, NULL); if (ret != TSDB_CODE_SUCCESS) { - return ret; + return invalidSqlErrMsg(pCmd, msg1); } + } - if (type != SHOW_VGROUPS && pInfo->pDCLInfo->nTokens == 2) { - // set the like conds for show tables - SSQLToken* likeToken = &pInfo->pDCLInfo->a[1]; + // show table/stable like 'xxxx', set the like pattern for show tables + SSQLToken* pPattern = &pShowInfo->pattern; + if (pPattern->type != 0) { + pPattern->n = strdequote(pPattern->z); - strncpy(pCmd->payload, likeToken->z, likeToken->n); - pCmd->payloadLen = strdequote(pCmd->payload); + if (pPattern->n <= 0) { + return invalidSqlErrMsg(pCmd, msg6); + } - if (pCmd->payloadLen > TSDB_METER_NAME_LEN) { - return invalidSqlErrMsg(pCmd, msg2); - } + if (pCmd->payloadLen > TSDB_METER_NAME_LEN) { + return invalidSqlErrMsg(pCmd, msg2); } } - } else if (type == SHOW_VNODES) { - if (NULL == pInfo->pDCLInfo) { + } else if (showType == TSDB_MGMT_TABLE_VNODES) { + if (pShowInfo->prefix.type == 0) { return invalidSqlErrMsg(pCmd, "No specified ip of dnode"); } // show vnodes may be ip addr of dnode in payload - if (pInfo->pDCLInfo->nTokens > 0) { - SSQLToken* pDnodeIp = &pInfo->pDCLInfo->a[0]; - - if (pDnodeIp->n > TSDB_IPv4ADDR_LEN) { // ip addr is too long - return invalidSqlErrMsg(pCmd, msg); - } + SSQLToken* pDnodeIp = &pShowInfo->prefix; + if (pDnodeIp->n > TSDB_IPv4ADDR_LEN) { // ip addr is too long + return invalidSqlErrMsg(pCmd, msg3); + } - strncpy(pCmd->payload, pDnodeIp->z, pDnodeIp->n); - pCmd->payloadLen = strdequote(pCmd->payload); + if (!validateIpAddress(pDnodeIp->z, pDnodeIp->n)) { + return invalidSqlErrMsg(pCmd, msg4); } } @@ -2566,54 +2001,48 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { - SSqlCmd* pCmd = &pSql->cmd; + const char* msg1 = "invalid ip address"; + const char* msg2 = "invalid port"; - switch (pInfo->sqlType) { - case KILL_QUERY: - pCmd->command = TSDB_SQL_KILL_QUERY; - break; - case KILL_STREAM: - pCmd->command = TSDB_SQL_KILL_STREAM; - break; - case KILL_CONNECTION: - pCmd->command = TSDB_SQL_KILL_CONNECTION; - break; - default: - return TSDB_CODE_INVALID_SQL; - } + SSqlCmd* pCmd = &pSql->cmd; + pCmd->command = pInfo->type; - SSQLToken* pToken = &(pInfo->pDCLInfo->a[0]); - if (pToken->n > TSDB_KILL_MSG_LEN) { + SSQLToken* ip = &(pInfo->pDCLInfo->ip); + if (ip->n > TSDB_KILL_MSG_LEN) { return TSDB_CODE_INVALID_SQL; } - strncpy(pCmd->payload, pToken->z, pToken->n); + strncpy(pCmd->payload, ip->z, ip->n); const char delim = ':'; - char* ipStr = strtok(pToken->z, &delim); - char* portStr = strtok(NULL, &delim); - if (!validateIpAddress(ipStr)) { + char* ipStr = strtok(ip->z, &delim); + char* portStr = strtok(NULL, &delim); + + if (!validateIpAddress(ipStr, strlen(ipStr))) { memset(pCmd->payload, 0, tListLen(pCmd->payload)); - const char* msg = "invalid ip address"; - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg1); } uint16_t port = (uint16_t)strtol(portStr, NULL, 10); if (port <= 0 || port > 65535) { memset(pCmd->payload, 0, tListLen(pCmd->payload)); - - const char* msg = "invalid port"; - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg2); } return TSDB_CODE_SUCCESS; } -bool validateIpAddress(char* ip) { - in_addr_t ipAddr = inet_addr(ip); - return (ipAddr != 0) && (ipAddr != 0xffffffff); +bool validateIpAddress(const char* ip, size_t size) { + char tmp[128] = {0}; // buffer to build null-terminated string + assert(size < 128); + + strncpy(tmp, ip, size); + + in_addr_t ipAddr = inet_addr(tmp); + + return ipAddr != INADDR_NONE; } int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd* pCmd) { @@ -2629,7 +2058,7 @@ int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd* pCmd) { int16_t type = 0; int16_t intermediateBytes = 0; - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, k); TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, k); @@ -2659,7 +2088,7 @@ void tscRestoreSQLFunctionForMetricQuery(SSqlCmd* pCmd) { return; } - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, i); @@ -2676,7 +2105,7 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) { const char* msg2 = "TWA only support group by tbname for super table query"; // filter sql function not supported by metric query yet. - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int32_t functionId = tscSqlExprGet(pCmd, i)->functionId; if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_METRIC) == 0) { return true; @@ -2684,12 +2113,12 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) { } if (tscIsTWAQuery(pCmd)) { - if (pCmd->groupbyExpr.numOfGroupCols == 0) { + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols == 0) { invalidSqlErrMsg(pCmd, msg1); return true; } - if (pCmd->groupbyExpr.numOfGroupCols != 1 || pCmd->groupbyExpr.columnInfo[0].colIdx != TSDB_TBNAME_COLUMN_INDEX) { + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols != 1 || pCmd->pQueryInfo[0].groupbyExpr.columnInfo[0].colIdx != TSDB_TBNAME_COLUMN_INDEX) { invalidSqlErrMsg(pCmd, msg2); return true; } @@ -2711,7 +2140,7 @@ static bool functionCompatibleCheck(SSqlCmd* pCmd) { // diff function cannot be executed with other function // arithmetic function can be executed with other arithmetic functions - for (int32_t i = startIdx + 1; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = startIdx + 1; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); int16_t functionId = pExpr->functionId; @@ -2738,14 +2167,14 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) { * update tags column index for group by tags * group by columns belong to this table */ - if (pCmd->groupbyExpr.numOfGroupCols > 0 && pCmd->groupbyExpr.tableIndex == tableIndex) { - for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { - int32_t index = pCmd->groupbyExpr.columnInfo[i].colIdx; + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0 && pCmd->pQueryInfo[0].groupbyExpr.tableIndex == tableIndex) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) { + int32_t index = pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i].colIdx; for (int32_t j = 0; j < pMeterMetaInfo->numOfTags; ++j) { int32_t tagColIndex = pMeterMetaInfo->tagColumnIndex[j]; if (tagColIndex == index) { - pCmd->groupbyExpr.columnInfo[i].colIdx = j; + pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i].colIdx = j; break; } } @@ -2753,7 +2182,7 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) { } // update tags column index for expression - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (!TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { // not tags, continue @@ -2774,7 +2203,7 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) { } // update join condition tag column index - SJoinInfo* pJoinInfo = &pCmd->tagCond.joinInfo; + SJoinInfo* pJoinInfo = &pCmd->pQueryInfo[0].tagCond.joinInfo; if (!pJoinInfo->hasJoin) { // not join query return; } @@ -2814,7 +2243,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) { return TSDB_CODE_SUCCESS; } - pCmd->groupbyExpr.numOfGroupCols = pList->nExpr; + pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols = pList->nExpr; if (pList->nExpr > TSDB_MAX_TAGS) { return invalidSqlErrMsg(pCmd, msg1); } @@ -2865,19 +2294,19 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) { relIndex -= pMeterMeta->numOfColumns; } - pCmd->groupbyExpr.columnInfo[i] = + pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i] = (SColIndexEx){.colIdx = relIndex, .flag = TSDB_COL_TAG, .colId = pSchema->colId}; // relIndex; - addRequiredTagColumn(pCmd, pCmd->groupbyExpr.columnInfo[i].colIdx, index.tableIndex); + addRequiredTagColumn(pCmd, pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i].colIdx, index.tableIndex); } else { // check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by - if (pSchema->type > TSDB_DATA_TYPE_BIGINT) { + if (pSchema->type > TSDB_DATA_TYPE_BINARY) { return invalidSqlErrMsg(pCmd, msg8); } tscColumnBaseInfoInsert(pCmd, &index); - pCmd->groupbyExpr.columnInfo[i] = + pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i] = (SColIndexEx){.colIdx = index.columnIndex, .flag = TSDB_COL_NORMAL, .colId = pSchema->colId}; // relIndex; - pCmd->groupbyExpr.orderType = TSQL_SO_ASC; + pCmd->pQueryInfo[0].groupbyExpr.orderType = TSQL_SO_ASC; if (i == 0 && pList->nExpr > 1) { return invalidSqlErrMsg(pCmd, msg7); @@ -2885,7 +2314,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) { } } - pCmd->groupbyExpr.tableIndex = tableIndex; + pCmd->pQueryInfo[0].groupbyExpr.tableIndex = tableIndex; return TSDB_CODE_SUCCESS; } @@ -3213,7 +2642,7 @@ static void relToString(SSqlCmd* pCmd, tSQLExpr* pExpr, char** str) { const char* or = "OR"; const char*and = "AND"; - // if (pCmd->tagCond.relType == TSQL_STABLE_QTYPE_COND) { + // if (pCmd->pQueryInfo[0].tagCond.relType == TSQL_STABLE_QTYPE_COND) { if (pExpr->nSQLOptr == TK_AND) { strcpy(*str, and); *str += strlen(and); @@ -3315,7 +2744,7 @@ static int32_t getJoinCondInfo(SSqlObj* pSql, tSQLExpr* pExpr) { return invalidSqlErrMsg(pCmd, msg); } - STagCond* pTagCond = &pCmd->tagCond; + STagCond* pTagCond = &pCmd->pQueryInfo[0].tagCond; SJoinNode* pLeft = &pTagCond->joinInfo.left; SJoinNode* pRight = &pTagCond->joinInfo.right; @@ -3847,14 +3276,14 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_ SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, tableCondIndex); - STagCond* pTagCond = &pSql->cmd.tagCond; + STagCond* pTagCond = &pSql->cmd.pQueryInfo[0].tagCond; pTagCond->tbnameCond.uid = pMeterMetaInfo->pMeterMeta->uid; assert(pExpr->nSQLOptr == TK_LIKE || pExpr->nSQLOptr == TK_IN); if (pExpr->nSQLOptr == TK_LIKE) { char* str = taosStringBuilderGetResult(sb, NULL); - pCmd->tagCond.tbnameCond.cond = strdup(str); + pCmd->pQueryInfo[0].tagCond.tbnameCond.cond = strdup(str); return TSDB_CODE_SUCCESS; } @@ -3903,7 +3332,7 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_ } char* str = taosStringBuilderGetResult(&sb1, NULL); - pCmd->tagCond.tbnameCond.cond = strdup(str); + pCmd->pQueryInfo[0].tagCond.tbnameCond.cond = strdup(str); taosStringBuilderDestroy(&sb1); tfree(segments); @@ -3911,8 +3340,8 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_ } static bool validateFilterExpr(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { - SColumnBase* pColBase = &pCmd->colList.pColList[i]; + for (int32_t i = 0; i < pCmd->pQueryInfo[0].colList.numOfCols; ++i) { + SColumnBase* pColBase = &pCmd->pQueryInfo[0].colList.pColList[i]; for (int32_t j = 0; j < pColBase->numOfFilters; ++j) { SColumnFilterInfo* pColFilter = &pColBase->filterInfo[j]; @@ -3969,12 +3398,12 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, tSQLExpr* pExpr) { } // update the timestamp query range - if (pCmd->stime < stime) { - pCmd->stime = stime; + if (pCmd->pQueryInfo[0].stime < stime) { + pCmd->pQueryInfo[0].stime = stime; } - if (pCmd->etime > etime) { - pCmd->etime = etime; + if (pCmd->pQueryInfo[0].etime > etime) { + pCmd->pQueryInfo[0].etime = etime; } } @@ -3987,7 +3416,7 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr) { const char* msg3 = "condition missing for join query"; if (!QUERY_IS_JOIN_QUERY(pCmd->type)) { - if (pCmd->numOfTables == 1) { + if (pCmd->pQueryInfo->numOfTables == 1) { return TSDB_CODE_SUCCESS; } else { return invalidSqlErrMsg(pCmd, msg3); @@ -4054,7 +3483,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr int32_t ret = TSDB_CODE_SUCCESS; if (pCondExpr->pTagCond != NULL) { - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { tSQLExpr* p1 = extractExprForSTable(pExpr, pCmd, i); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); @@ -4066,7 +3495,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr return ret; } - tsSetMetricQueryCond(&pCmd->tagCond, pMeterMetaInfo->pMeterMeta->uid, c); + tsSetMetricQueryCond(&pCmd->pQueryInfo[0].tagCond, pMeterMetaInfo->pMeterMeta->uid, c); doCompactQueryExpr(pExpr); tSQLExprDestroy(p1); @@ -4088,8 +3517,8 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) { int32_t ret = TSDB_CODE_SUCCESS; SSqlCmd* pCmd = &pSql->cmd; - pCmd->stime = 0; - pCmd->etime = INT64_MAX; + pCmd->pQueryInfo[0].stime = 0; + pCmd->pQueryInfo[0].etime = INT64_MAX; // tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space SStringBuilder sb = {0}; @@ -4140,7 +3569,7 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) { } // 7. query condition for table name - pCmd->tagCond.relType = (condExpr.relType == TK_AND) ? TSDB_RELATION_AND : TSDB_RELATION_OR; + pCmd->pQueryInfo[0].tagCond.relType = (condExpr.relType == TK_AND) ? TSDB_RELATION_AND : TSDB_RELATION_OR; ret = setTableCondForMetricQuery(pSql, condExpr.pTableCond, condExpr.tableCondIndex, &sb); taosStringBuilderDestroy(&sb); @@ -4247,7 +3676,7 @@ int32_t getTimeRange(int64_t* stime, int64_t* etime, tSQLExpr* pRight, int32_t o int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd) { const char rep[] = {'(', ')', '*', ',', '.', '/', '\\', '+', '-', '%', ' '}; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { char* fieldName = tscFieldInfoGetField(pCmd, i)->name; for (int32_t j = 0; j < TSDB_COL_NAME_LEN && fieldName[j] != 0; ++j) { for (int32_t k = 0; k < tListLen(rep); ++k) { @@ -4262,9 +3691,9 @@ int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd) { } // the column name may be identical, here check again - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { char* fieldName = tscFieldInfoGetField(pCmd, i)->name; - for (int32_t j = i + 1; j < pCmd->fieldsInfo.numOfOutputCols; ++j) { + for (int32_t j = i + 1; j < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++j) { if (strncasecmp(fieldName, tscFieldInfoGetField(pCmd, j)->name, TSDB_COL_NAME_LEN) == 0) { const char* msg = "duplicated column name in new table"; return invalidSqlErrMsg(pCmd, msg); @@ -4289,20 +3718,20 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) { } if (strncasecmp(pItem->pVar.pz, "none", 4) == 0 && pItem->pVar.nLen == 4) { - pCmd->interpoType = TSDB_INTERPO_NONE; + pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_NONE; } else if (strncasecmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4) { - pCmd->interpoType = TSDB_INTERPO_NULL; - for (int32_t i = START_INTERPO_COL_IDX; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_NULL; + for (int32_t i = START_INTERPO_COL_IDX; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { TAOS_FIELD* pFields = tscFieldInfoGetField(pCmd, i); - setNull((char*)&pCmd->defaultVal[i], pFields->type, pFields->bytes); + setNull((char*)&pCmd->pQueryInfo[0].defaultVal[i], pFields->type, pFields->bytes); } } else if (strncasecmp(pItem->pVar.pz, "prev", 4) == 0 && pItem->pVar.nLen == 4) { - pCmd->interpoType = TSDB_INTERPO_PREV; + pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_PREV; } else if (strncasecmp(pItem->pVar.pz, "linear", 6) == 0 && pItem->pVar.nLen == 6) { // not support yet - pCmd->interpoType = TSDB_INTERPO_LINEAR; + pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_LINEAR; } else if (strncasecmp(pItem->pVar.pz, "value", 5) == 0 && pItem->pVar.nLen == 5) { - pCmd->interpoType = TSDB_INTERPO_SET_VALUE; + pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_SET_VALUE; if (pFillToken->nExpr == 1) { return invalidSqlErrMsg(pCmd, msg1); @@ -4315,12 +3744,12 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) { if (tscIsPointInterpQuery(pCmd)) { startPos = 0; - if (numOfFillVal > pCmd->fieldsInfo.numOfOutputCols) { - numOfFillVal = pCmd->fieldsInfo.numOfOutputCols; + if (numOfFillVal > pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) { + numOfFillVal = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; } } else { numOfFillVal = - (pFillToken->nExpr > pCmd->fieldsInfo.numOfOutputCols) ? pCmd->fieldsInfo.numOfOutputCols : pFillToken->nExpr; + (pFillToken->nExpr > pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) ? pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols : pFillToken->nExpr; } int32_t j = 1; @@ -4328,26 +3757,26 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) { for (int32_t i = startPos; i < numOfFillVal; ++i, ++j) { TAOS_FIELD* pFields = tscFieldInfoGetField(pCmd, i); - int32_t ret = tVariantDump(&pFillToken->a[j].pVar, (char*)&pCmd->defaultVal[i], pFields->type); + int32_t ret = tVariantDump(&pFillToken->a[j].pVar, (char*)&pCmd->pQueryInfo[0].defaultVal[i], pFields->type); if (ret != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(pCmd, msg); } if (pFields->type == TSDB_DATA_TYPE_BINARY || pFields->type == TSDB_DATA_TYPE_NCHAR) { - setNull((char*)(&pCmd->defaultVal[i]), pFields->type, pFields->bytes); + setNull((char*)(&pCmd->pQueryInfo[0].defaultVal[i]), pFields->type, pFields->bytes); } } - if ((pFillToken->nExpr < pCmd->fieldsInfo.numOfOutputCols) || - ((pFillToken->nExpr - 1 < pCmd->fieldsInfo.numOfOutputCols) && (tscIsPointInterpQuery(pCmd)))) { + if ((pFillToken->nExpr < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) || + ((pFillToken->nExpr - 1 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) && (tscIsPointInterpQuery(pCmd)))) { tVariantListItem* lastItem = &pFillToken->a[pFillToken->nExpr - 1]; - for (int32_t i = numOfFillVal; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = numOfFillVal; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { TAOS_FIELD* pFields = tscFieldInfoGetField(pCmd, i); - tVariantDump(&lastItem->pVar, (char*)&pCmd->defaultVal[i], pFields->type); + tVariantDump(&lastItem->pVar, (char*)&pCmd->pQueryInfo[0].defaultVal[i], pFields->type); if (pFields->type == TSDB_DATA_TYPE_BINARY || pFields->type == TSDB_DATA_TYPE_NCHAR) { - setNull((char*)(&pCmd->defaultVal[i]), pFields->type, pFields->bytes); + setNull((char*)(&pCmd->pQueryInfo[0].defaultVal[i]), pFields->type, pFields->bytes); } } } @@ -4372,7 +3801,7 @@ static void setDefaultOrderInfo(SSqlCmd* pCmd) { /* for metric query, set default ascending order for group output */ if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) { - pCmd->groupbyExpr.orderType = TSQL_SO_ASC; + pCmd->pQueryInfo[0].groupbyExpr.orderType = TSQL_SO_ASC; } } @@ -4428,7 +3857,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema if (index.columnIndex >= pMeterMetaInfo->pMeterMeta->numOfColumns) { int32_t relTagIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; - if (relTagIndex == pCmd->groupbyExpr.columnInfo[0].colIdx) { + if (relTagIndex == pCmd->pQueryInfo[0].groupbyExpr.columnInfo[0].colIdx) { orderByTags = true; } } else if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { @@ -4447,8 +3876,8 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema if (pSortorder->nExpr == 1) { if (orderByTags) { - pCmd->groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; - pCmd->groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder; + pCmd->pQueryInfo[0].groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; + pCmd->pQueryInfo[0].groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder; } else if (isTopBottomQuery(pCmd)) { /* order of top/bottom query in interval is not valid */ SSqlExpr* pExpr = tscSqlExprGet(pCmd, 0); @@ -4470,8 +3899,8 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema if (pSortorder->nExpr == 2) { if (orderByTags) { - pCmd->groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; - pCmd->groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder; + pCmd->pQueryInfo[0].groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; + pCmd->pQueryInfo[0].groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder; } else { pCmd->order.order = pSortorder->a[0].sortOrder; pCmd->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; @@ -4523,21 +3952,25 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { const int32_t DEFAULT_TABLE_INDEX = 0; + + const char* msg1 = "invalid table name"; + const char* msg2 = "table name too long"; + const char* msg3 = "manipulation of tag available for super table"; + const char* msg4 = "set tag value only available for table"; + const char* msg5 = "only support add one tag"; + const char* msg6 = "column can only be modified by super table"; SSqlCmd* pCmd = &pSql->cmd; - SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, DEFAULT_TABLE_INDEX); - SAlterTableSQL* pAlterSQL = pInfo->pAlterInfo; - pCmd->command = TSDB_SQL_ALTER_TABLE; + + SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, DEFAULT_TABLE_INDEX); if (tscValidateName(&(pAlterSQL->name)) != TSDB_CODE_SUCCESS) { - const char* msg = "invalid table name"; - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg1); } if (setMeterID(pSql, &(pAlterSQL->name), 0) != TSDB_CODE_SUCCESS) { - const char* msg = "table name too long"; - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg2); } int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo->name, DEFAULT_TABLE_INDEX); @@ -4546,41 +3979,31 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } SMeterMeta* pMeterMeta = pMeterMetaInfo->pMeterMeta; - SSchema* pSchema = tsGetSchema(pMeterMeta); - if (pInfo->sqlType == ALTER_TABLE_TAGS_ADD || pInfo->sqlType == ALTER_TABLE_TAGS_DROP || - pInfo->sqlType == ALTER_TABLE_TAGS_CHG) { + if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN || pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN || + pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) { - const char* msg = "manipulation of tag available for metric"; - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg3); } - } else if ((pInfo->sqlType == ALTER_TABLE_TAGS_SET) && (UTIL_METER_IS_METRIC(pMeterMetaInfo))) { - const char* msg = "set tag value only available for table"; - return invalidSqlErrMsg(pCmd, msg); - } else if ((pInfo->sqlType == ALTER_TABLE_ADD_COLUMN || pInfo->sqlType == ALTER_TABLE_DROP_COLUMN) && + } else if ((pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) && (UTIL_METER_IS_METRIC(pMeterMetaInfo))) { + return invalidSqlErrMsg(pCmd, msg4); + } else if ((pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN || pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) && UTIL_METER_IS_CREATE_FROM_METRIC(pMeterMetaInfo)) { - const char* msg = "column can only be modified by metric"; - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg6); } - if (pInfo->sqlType == ALTER_TABLE_TAGS_ADD) { - pCmd->count = TSDB_ALTER_TABLE_ADD_TAG_COLUMN; - + if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) { tFieldList* pFieldList = pAlterSQL->pAddColumns; if (pFieldList->nField > 1) { - const char* msg = "only support add one tag"; - return invalidSqlErrMsg(pCmd, msg); + return invalidSqlErrMsg(pCmd, msg5); } if (!validateOneTags(pCmd, &pFieldList->p[0])) { return TSDB_CODE_INVALID_SQL; } - tscFieldInfoSetValFromField(&pCmd->fieldsInfo, 0, &pFieldList->p[0]); - pCmd->numOfCols = 1; // only one column - - } else if (pInfo->sqlType == ALTER_TABLE_TAGS_DROP) { - pCmd->count = TSDB_ALTER_TABLE_DROP_TAG_COLUMN; + tscFieldInfoSetValFromField(&pCmd->pQueryInfo[0].fieldsInfo, 0, &pFieldList->p[0]); + } else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) { const char* msg1 = "no tags can be dropped"; const char* msg2 = "only support one tag"; @@ -4601,36 +4024,28 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pItem->pVar.nLen > TSDB_COL_NAME_LEN) { return invalidSqlErrMsg(pCmd, msg3); } - - int32_t idx = -1; - for (int32_t i = 0; i < pMeterMeta->numOfTags; ++i) { - int32_t tagIdx = i + pMeterMeta->numOfColumns; - char* tagName = pSchema[tagIdx].name; - size_t nLen = strlen(tagName); - - if ((strncasecmp(tagName, pItem->pVar.pz, nLen) == 0) && (pItem->pVar.nLen == nLen)) { - idx = i; - break; - } + + SColumnIndex index = COLUMN_INDEX_INITIALIZER; + SSQLToken name = {.z = pItem->pVar.pz, .n = pItem->pVar.nLen, .type = TK_STRING}; + + if (getColumnIndexByNameEx(&name, pCmd, &index) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; } - if (idx == -1) { + if (index.columnIndex < pMeterMeta->numOfColumns) { return invalidSqlErrMsg(pCmd, msg4); - } else if (idx == 0) { + } else if (index.columnIndex == 0) { return invalidSqlErrMsg(pCmd, msg5); } - char name[128] = {0}; - strncpy(name, pItem->pVar.pz, pItem->pVar.nLen); - tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); - - pCmd->numOfCols = 1; // only one column - - } else if (pInfo->sqlType == ALTER_TABLE_TAGS_CHG) { + char name1[128] = {0}; + strncpy(name1, pItem->pVar.pz, pItem->pVar.nLen); + tscFieldInfoSetValue(&pCmd->pQueryInfo[0].fieldsInfo, 0, TSDB_DATA_TYPE_INT, name1, + tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); + } else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { const char* msg1 = "tag name too long"; const char* msg2 = "invalid tag name"; - pCmd->count = TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN; tVariantList* pVarList = pAlterSQL->varList; if (pVarList->nExpr > 2) { return TSDB_CODE_INVALID_SQL; @@ -4662,63 +4077,47 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { char name[128] = {0}; strncpy(name, pVarList->a[0].pVar.pz, pVarList->a[0].pVar.nLen); - tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); + tscFieldInfoSetValue(&pCmd->pQueryInfo[0].fieldsInfo, 0, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); memset(name, 0, tListLen(name)); strncpy(name, pVarList->a[1].pVar.pz, pVarList->a[1].pVar.nLen); - tscFieldInfoSetValue(&pCmd->fieldsInfo, 1, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); - - pCmd->numOfCols = 2; - } else if (pInfo->sqlType == ALTER_TABLE_TAGS_SET) { - const char* msg0 = "tag name too long"; + tscFieldInfoSetValue(&pCmd->pQueryInfo[0].fieldsInfo, 1, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); + } else if (pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) { const char* msg1 = "invalid tag value"; - const char* msg2 = "invalid tag name"; + const char* msg2 = "update normal column not supported"; const char* msg3 = "tag value too long"; - pCmd->count = TSDB_ALTER_TABLE_UPDATE_TAG_VAL; - - // Note: update can only be applied to meter not metric. - // the following is handle display tags value for meters created according to metric - + // Note: update can only be applied to table not super table. + // the following is handle display tags value for meters created according to super table tVariantList* pVarList = pAlterSQL->varList; tVariant* pTagName = &pVarList->a[0].pVar; - if (pTagName->nLen > TSDB_COL_NAME_LEN) { - return invalidSqlErrMsg(pCmd, msg0); - } - - int32_t tagsIndex = -1; - SSchema* pTagsSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta); - - for (int32_t i = 0; i < pMeterMetaInfo->pMeterMeta->numOfTags; ++i) { - if (strcmp(pTagName->pz, pTagsSchema[i].name) == 0 && strlen(pTagsSchema[i].name) == pTagName->nLen) { - tagsIndex = i; - break; - } + SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; + SSQLToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen}; + if (getColumnIndexByNameEx(&name, pCmd, &columnIndex) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; } - if (tagsIndex == -1) { + if (columnIndex.columnIndex < pMeterMeta->numOfColumns) { return invalidSqlErrMsg(pCmd, msg2); } - if (tVariantDump(&pVarList->a[1].pVar, pCmd->payload, pTagsSchema[tagsIndex].type) != TSDB_CODE_SUCCESS) { + SSchema* pTagsSchema = tsGetColumnSchema(pMeterMetaInfo->pMeterMeta, columnIndex.columnIndex); + if (tVariantDump(&pVarList->a[1].pVar, pAlterSQL->tagData.data/*pCmd->payload*/, pTagsSchema->type) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(pCmd, msg1); } // validate the length of binary - if ((pTagsSchema[tagsIndex].type == TSDB_DATA_TYPE_BINARY || pTagsSchema[tagsIndex].type == TSDB_DATA_TYPE_NCHAR) && - pVarList->a[1].pVar.nLen > pTagsSchema[tagsIndex].bytes) { + if ((pTagsSchema->type == TSDB_DATA_TYPE_BINARY || pTagsSchema->type == TSDB_DATA_TYPE_NCHAR) && + pVarList->a[1].pVar.nLen > pTagsSchema->bytes) { return invalidSqlErrMsg(pCmd, msg3); } - char name[128] = {0}; - strncpy(name, pTagName->pz, pTagName->nLen); - tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); - - pCmd->numOfCols = 1; - } else if (pInfo->sqlType == ALTER_TABLE_ADD_COLUMN) { - pCmd->count = TSDB_ALTER_TABLE_ADD_COLUMN; + char name1[128] = {0}; + strncpy(name1, pTagName->pz, pTagName->nLen); + tscFieldInfoSetValue(&pCmd->pQueryInfo[0].fieldsInfo, 0, TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); + } else if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN) { tFieldList* pFieldList = pAlterSQL->pAddColumns; if (pFieldList->nField > 1) { const char* msg = "only support add one column"; @@ -4729,16 +4128,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return TSDB_CODE_INVALID_SQL; } - tscFieldInfoSetValFromField(&pCmd->fieldsInfo, 0, &pFieldList->p[0]); - pCmd->numOfCols = 1; // only one column - } else if (pInfo->sqlType == ALTER_TABLE_DROP_COLUMN) { - pCmd->count = TSDB_ALTER_TABLE_DROP_COLUMN; - + tscFieldInfoSetValFromField(&pCmd->pQueryInfo[0].fieldsInfo, 0, &pFieldList->p[0]); + } else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) { const char* msg1 = "no columns can be dropped"; const char* msg2 = "only support one column"; - const char* msg3 = "column name too long"; const char* msg4 = "illegal column name"; - const char* msg5 = "primary timestamp column cannot be dropped"; + const char* msg3 = "primary timestamp column cannot be dropped"; if (pMeterMeta->numOfColumns == TSDB_MIN_COLUMNS) { // return invalidSqlErrMsg(pCmd, msg1); @@ -4749,32 +4144,20 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } tVariantListItem* pItem = &pAlterSQL->varList->a[0]; - if (pItem->pVar.nLen > TSDB_COL_NAME_LEN) { - return invalidSqlErrMsg(pCmd, msg3); - } - - int32_t idx = -1; - for (int32_t i = 0; i < pMeterMeta->numOfColumns; ++i) { - char* colName = pSchema[i].name; - size_t len = strlen(colName); - - if ((strncasecmp(colName, pItem->pVar.pz, len) == 0) && (len == pItem->pVar.nLen)) { - idx = i; - break; - } - } - if (idx == -1) { + SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; + SSQLToken name = {.type = TK_STRING, .z = pItem->pVar.pz, .n = pItem->pVar.nLen}; + if (getColumnIndexByNameEx(&name, pCmd, &columnIndex) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(pCmd, msg4); - } else if (idx == 0) { - return invalidSqlErrMsg(pCmd, msg5); } - char name[128] = {0}; - strncpy(name, pItem->pVar.pz, pItem->pVar.nLen); - tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); + if (columnIndex.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) { + return invalidSqlErrMsg(pCmd, msg3); + } - pCmd->numOfCols = 1; // only one column + char name1[128] = {0}; + strncpy(name1, pItem->pVar.pz, pItem->pVar.nLen); + tscFieldInfoSetValue(&pCmd->pQueryInfo[0].fieldsInfo, 0, TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); } return TSDB_CODE_SUCCESS; @@ -4784,11 +4167,11 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd) { const char* msg0 = "sample interval can not be less than 10ms."; const char* msg1 = "functions not allowed in select clause"; - if (pCmd->nAggTimeInterval != 0 && pCmd->nAggTimeInterval < 10) { + if (pCmd->pQueryInfo[0].nAggTimeInterval != 0 && pCmd->pQueryInfo[0].nAggTimeInterval < 10) { return invalidSqlErrMsg(pCmd, msg0); } - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int32_t functId = tscSqlExprGet(pCmd, i)->functionId; if (!IS_STREAM_QUERY_VALID(aAggs[functId].nStatus)) { return invalidSqlErrMsg(pCmd, msg1); @@ -4803,13 +4186,13 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) { const char* msg1 = "column projection is not compatible with interval"; // multi-output set/ todo refactor - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, k); // projection query on primary timestamp, the selectivity function needs to be present. if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { bool hasSelectivity = false; - for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) { + for (int32_t j = 0; j < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++j) { SSqlExpr* pEx = tscSqlExprGet(pCmd, j); if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) { hasSelectivity = true; @@ -4967,7 +4350,7 @@ bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd) { return true; } - return (pCmd->stime == pCmd->etime) && (pCmd->stime != 0); + return (pCmd->pQueryInfo[0].stime == pCmd->pQueryInfo[0].etime) && (pCmd->pQueryInfo[0].stime != 0); } int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { @@ -4980,16 +4363,16 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { const char* msg3 = "slimit/soffset can not apply to projection query"; // handle the limit offset value, validate the limit - pCmd->limit = pQuerySql->limit; - pCmd->globalLimit = pCmd->limit.limit; + pCmd->pQueryInfo->limit = pQuerySql->limit; + pCmd->globalLimit = pCmd->pQueryInfo->limit.limit; - pCmd->slimit = pQuerySql->slimit; + pCmd->pQueryInfo[0].slimit = pQuerySql->slimit; - if (pCmd->slimit.offset < 0 || pCmd->limit.offset < 0) { + if (pCmd->pQueryInfo[0].slimit.offset < 0 || pCmd->pQueryInfo->limit.offset < 0) { return invalidSqlErrMsg(pCmd, msg0); } - if (pCmd->limit.limit == 0) { + if (pCmd->pQueryInfo->limit.limit == 0) { tscTrace("%p limit 0, no output result", pSql); pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; } @@ -5003,12 +4386,12 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { if (queryOnTags == true) { // local handle the metric tag query pCmd->command = TSDB_SQL_RETRIEVE_TAGS; } else { - if (tscProjectionQueryOnMetric(pCmd) && (pCmd->slimit.limit > 0 || pCmd->slimit.offset > 0)) { + if (tscProjectionQueryOnMetric(pCmd) && (pCmd->pQueryInfo[0].slimit.limit > 0 || pCmd->pQueryInfo[0].slimit.offset > 0)) { return invalidSqlErrMsg(pCmd, msg3); } } - if (pCmd->slimit.limit == 0) { + if (pCmd->pQueryInfo[0].slimit.limit == 0) { tscTrace("%p limit 0, no output result", pSql); pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; return TSDB_CODE_SUCCESS; @@ -5032,14 +4415,14 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { } // keep original limitation value in globalLimit - pCmd->globalLimit = pCmd->limit.limit; + pCmd->globalLimit = pCmd->pQueryInfo->limit.limit; } else { - if (pCmd->slimit.limit != -1 || pCmd->slimit.offset != 0) { + if (pCmd->pQueryInfo[0].slimit.limit != -1 || pCmd->pQueryInfo[0].slimit.offset != 0) { return invalidSqlErrMsg(pCmd, msg1); } // filter the query functions operating on "tbname" column that are not supported by normal columns. - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->colInfo.colIdx == TSDB_TBNAME_COLUMN_INDEX) { return invalidSqlErrMsg(pCmd, msg2); @@ -5141,7 +4524,7 @@ int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex) { // the first column not timestamp column, add it SSqlExpr* pExpr = NULL; - if (pCmd->exprsInfo.numOfExprs > 0) { + if (pCmd->pQueryInfo[0].exprsInfo.numOfExprs > 0) { pExpr = tscSqlExprGet(pCmd, 0); } @@ -5159,14 +4542,14 @@ void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex } void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIndex) { - if (pParentObj->cmd.groupbyExpr.numOfGroupCols > 0) { - int32_t num = pSql->cmd.exprsInfo.numOfExprs; + if (pParentObj->cmd.pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) { + int32_t num = pSql->cmd.pQueryInfo[0].exprsInfo.numOfExprs; SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, num - 1); SSqlCmd* pCmd = &pSql->cmd; if (pExpr->functionId != TSDB_FUNC_TAG) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); - int16_t columnInfo = tscGetJoinTagColIndexByUid(&pCmd->tagCond, pMeterMetaInfo->pMeterMeta->uid); + int16_t columnInfo = tscGetJoinTagColIndexByUid(&pCmd->pQueryInfo[0].tagCond, pMeterMetaInfo->pMeterMeta->uid); SColumnIndex index = {.tableIndex = 0, .columnIndex = columnInfo}; SSchema* pSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta); @@ -5174,32 +4557,32 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIn int16_t bytes = pSchema[index.columnIndex].bytes; char* name = pSchema[index.columnIndex].name; - pExpr = tscSqlExprInsert(pCmd, pCmd->fieldsInfo.numOfOutputCols, TSDB_FUNC_TAG, &index, type, bytes, bytes); + pExpr = tscSqlExprInsert(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, TSDB_FUNC_TAG, &index, type, bytes, bytes); pExpr->colInfo.flag = TSDB_COL_TAG; // NOTE: tag column does not add to source column list SColumnList ids = {0}; - insertResultField(pCmd, pCmd->fieldsInfo.numOfOutputCols, &ids, bytes, type, name); + insertResultField(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, &ids, bytes, type, name); int32_t relIndex = index.columnIndex; pExpr->colInfo.colIdx = relIndex; - pCmd->groupbyExpr.columnInfo[0].colIdx = relIndex; + pCmd->pQueryInfo[0].groupbyExpr.columnInfo[0].colIdx = relIndex; - addRequiredTagColumn(pCmd, pCmd->groupbyExpr.columnInfo[0].colIdx, 0); + addRequiredTagColumn(pCmd, pCmd->pQueryInfo[0].groupbyExpr.columnInfo[0].colIdx, 0); } } } void doAddGroupColumnForSubquery(SSqlCmd* pCmd, int32_t tagIndex) { - int32_t index = pCmd->groupbyExpr.columnInfo[tagIndex].colIdx; + int32_t index = pCmd->pQueryInfo[0].groupbyExpr.columnInfo[tagIndex].colIdx; SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SSchema* pSchema = tsGetColumnSchema(pMeterMetaInfo->pMeterMeta, index); SColumnIndex colIndex = {.tableIndex = 0, .columnIndex = index}; - SSqlExpr* pExpr = tscSqlExprInsert(pCmd, pCmd->fieldsInfo.numOfOutputCols, TSDB_FUNC_PRJ, &colIndex, pSchema->type, + SSqlExpr* pExpr = tscSqlExprInsert(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, TSDB_FUNC_PRJ, &colIndex, pSchema->type, pSchema->bytes, pSchema->bytes); pExpr->colInfo.flag = TSDB_COL_NORMAL; @@ -5211,13 +4594,13 @@ void doAddGroupColumnForSubquery(SSqlCmd* pCmd, int32_t tagIndex) { list.num = 1; list.ids[0] = colIndex; - insertResultField(pCmd, pCmd->fieldsInfo.numOfOutputCols, &list, pSchema->bytes, pSchema->type, pSchema->name); - tscFieldInfoUpdateVisible(&pCmd->fieldsInfo, pCmd->fieldsInfo.numOfOutputCols - 1, false); + insertResultField(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, &list, pSchema->bytes, pSchema->type, pSchema->name); + tscFieldInfoUpdateVisible(&pCmd->pQueryInfo[0].fieldsInfo, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - 1, false); } static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) { int32_t tagLength = 0; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_TAGPRJ || pExpr->functionId == TSDB_FUNC_TAG) { pExpr->functionId = TSDB_FUNC_TAG_DUMMY; @@ -5231,7 +4614,7 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId != TSDB_FUNC_TAG_DUMMY && pExpr->functionId != TSDB_FUNC_TS_DUMMY) { SSchema* pColSchema = &pSchema[pExpr->colInfo.colIdx]; @@ -5242,12 +4625,12 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) { } static void doUpdateSqlFunctionForColPrj(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_PRJ) { bool qualifiedCol = false; - for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { - if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) { + for (int32_t j = 0; j < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++j) { + if (pExpr->colInfo.colId == pCmd->pQueryInfo[0].groupbyExpr.columnInfo[j].colId) { qualifiedCol = true; pExpr->param[0].i64Key = 1; // limit the output to be 1 for each state value @@ -5275,7 +4658,7 @@ static bool onlyTagPrjFunction(SSqlCmd* pCmd) { bool hasTagPrj = false; bool hasColumnPrj = false; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_PRJ) { hasColumnPrj = true; @@ -5291,13 +4674,13 @@ static bool onlyTagPrjFunction(SSqlCmd* pCmd) { static bool allTagPrjInGroupby(SSqlCmd* pCmd) { bool allInGroupby = true; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId != TSDB_FUNC_TAGPRJ) { continue; } - if (!tagColumnInGroupby(&pCmd->groupbyExpr, pExpr->colInfo.colId)) { + if (!tagColumnInGroupby(&pCmd->pQueryInfo[0].groupbyExpr, pExpr->colInfo.colId)) { allInGroupby = false; break; } @@ -5308,7 +4691,7 @@ static bool allTagPrjInGroupby(SSqlCmd* pCmd) { } static void updateTagPrjFunction(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_TAGPRJ) { pExpr->functionId = TSDB_FUNC_TAG; @@ -5330,7 +4713,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { int16_t numOfSelectivity = 0; int16_t numOfAggregation = 0; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_TAGPRJ || (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) { @@ -5339,9 +4722,9 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { } } - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int16_t functionId = tscSqlExprGet(pCmd, i)->functionId; - if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS || + if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_ARITHM) { continue; } @@ -5371,7 +4754,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { * If more than one selectivity functions exist, all the selectivity functions must be last_row. * Otherwise, return with error code. */ - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int16_t functionId = tscSqlExprGet(pCmd, i)->functionId; if (functionId == TSDB_FUNC_TAGPRJ) { continue; @@ -5387,7 +4770,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { } } else { if ((pCmd->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) == TSDB_QUERY_TYPE_PROJECTION_QUERY) { - if (numOfAggregation > 0 && pCmd->groupbyExpr.numOfGroupCols == 0) { + if (numOfAggregation > 0 && pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols == 0) { return invalidSqlErrMsg(pCmd, msg3); } @@ -5412,8 +4795,8 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) { int16_t type = 0; char* name = NULL; - for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { - SColIndexEx* pColIndex = &pCmd->groupbyExpr.columnInfo[i]; + for (int32_t i = 0; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) { + SColIndexEx* pColIndex = &pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i]; int16_t colIndex = pColIndex->colIdx; if (pColIndex->colIdx == TSDB_TBNAME_COLUMN_INDEX) { @@ -5430,24 +4813,24 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) { } if (TSDB_COL_IS_TAG(pColIndex->flag)) { - SColumnIndex index = {.tableIndex = pCmd->groupbyExpr.tableIndex, .columnIndex = colIndex}; + SColumnIndex index = {.tableIndex = pCmd->pQueryInfo[0].groupbyExpr.tableIndex, .columnIndex = colIndex}; SSqlExpr* pExpr = - tscSqlExprInsert(pCmd, pCmd->fieldsInfo.numOfOutputCols, TSDB_FUNC_TAG, &index, type, bytes, bytes); + tscSqlExprInsert(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, TSDB_FUNC_TAG, &index, type, bytes, bytes); pExpr->colInfo.flag = TSDB_COL_TAG; // NOTE: tag column does not add to source column list SColumnList ids = {0}; - insertResultField(pCmd, pCmd->fieldsInfo.numOfOutputCols, &ids, bytes, type, name); + insertResultField(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, &ids, bytes, type, name); } else { // if this query is "group by" normal column, interval is not allowed - if (pCmd->nAggTimeInterval > 0) { + if (pCmd->pQueryInfo[0].nAggTimeInterval > 0) { return invalidSqlErrMsg(pCmd, msg2); } bool hasGroupColumn = false; - for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) { + for (int32_t j = 0; j < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++j) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, j); if (pExpr->colInfo.colId == pColIndex->colId) { break; @@ -5477,14 +4860,14 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { // only retrieve tags, group by is not supportted if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) { - if (pCmd->groupbyExpr.numOfGroupCols > 0 || pCmd->nAggTimeInterval > 0) { + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0 || pCmd->pQueryInfo[0].nAggTimeInterval > 0) { return invalidSqlErrMsg(pCmd, msg4); } else { return TSDB_CODE_SUCCESS; } } - if (pCmd->groupbyExpr.numOfGroupCols > 0) { + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) { // check if all the tags prj columns belongs to the group by columns if (onlyTagPrjFunction(pCmd) && allTagPrjInGroupby(pCmd)) { updateTagPrjFunction(pCmd); @@ -5492,7 +4875,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { } // check all query functions in selection clause, multi-output functions are not allowed - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); int32_t functId = pExpr->functionId; @@ -5502,8 +4885,8 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { */ if (functId == TSDB_FUNC_PRJ && pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) { bool qualified = false; - for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { - SColIndexEx* pColIndex = &pCmd->groupbyExpr.columnInfo[j]; + for (int32_t j = 0; j < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++j) { + SColIndexEx* pColIndex = &pCmd->pQueryInfo[0].groupbyExpr.columnInfo[j]; if (pColIndex->colId == pExpr->colInfo.colId) { qualified = true; break; @@ -5682,21 +5065,21 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) { // for debug purpose void tscPrintSelectClause(SSqlCmd* pCmd) { - if (pCmd == NULL || pCmd->exprsInfo.numOfExprs == 0) { + if (pCmd == NULL || pCmd->pQueryInfo[0].exprsInfo.numOfExprs == 0) { return; } char* str = calloc(1, 10240); int32_t offset = 0; - offset += sprintf(str, "%d [", pCmd->exprsInfo.numOfExprs); - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + offset += sprintf(str, "%d [", pCmd->pQueryInfo[0].exprsInfo.numOfExprs); + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); int32_t size = sprintf(str + offset, "%s(%d)", aAggs[pExpr->functionId].aName, pExpr->colInfo.colId); offset += size; - if (i < pCmd->exprsInfo.numOfExprs - 1) { + if (i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs - 1) { str[offset++] = ','; } } @@ -5706,3 +5089,424 @@ void tscPrintSelectClause(SSqlCmd* pCmd) { free(str); } + +int32_t doCheckForCreateTable(SSqlObj* pSql, SSqlInfo* pInfo) { + const char* msg1 = "invalid table name"; + const char* msg2 = "table name too long"; + + SSqlCmd* pCmd = &pSql->cmd; + + SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo; + + tFieldList* pFieldList = pCreateTable->colInfo.pColumns; + tFieldList* pTagList = pCreateTable->colInfo.pTagColumns; + + assert(pFieldList != NULL); + + // if sql specifies db, use it, otherwise use default db + SSQLToken* pzTableName = &(pCreateTable->name); + + if (tscValidateName(pzTableName) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + if (setMeterID(pSql, pzTableName, 0) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg2); + } + + if (!validateTableColumnInfo(pFieldList, pCmd) || + (pTagList != NULL && !validateTagParams(pTagList, pFieldList, pCmd))) { + return TSDB_CODE_INVALID_SQL; + } + + int32_t col = 0; + for (; col < pFieldList->nField; ++col) { + tscFieldInfoSetValFromField(&pCmd->pQueryInfo[0].fieldsInfo, col, &pFieldList->p[col]); + } + + pCmd->numOfCols = (int16_t)pFieldList->nField; + + if (pTagList != NULL) { // create metric[optional] + for (int32_t i = 0; i < pTagList->nField; ++i) { + tscFieldInfoSetValFromField(&pCmd->pQueryInfo[0].fieldsInfo, col++, &pTagList->p[i]); + } + + pCmd->count = pTagList->nField; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { + const char* msg1 = "invalid table name"; + const char* msg3 = "tag value too long"; + const char* msg4 = "illegal value or data overflow"; + const char* msg5 = "tags number not matched"; + + SSqlCmd* pCmd = &pSql->cmd; + + SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo; + SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + + // super table name, create table by using dst + SSQLToken* pToken = &(pCreateTable->usingInfo.stableName); + + if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + if (setMeterID(pSql, pToken, 0) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + // get meter meta from mnode + strncpy(pCreateTable->usingInfo.tagdata.name, pMeterMetaInfo->name, TSDB_METER_ID_LEN); + tVariantList* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals; + + int32_t code = tscGetMeterMeta(pSql, pCreateTable->usingInfo.tagdata.name, 0); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + if (pMeterMetaInfo->pMeterMeta->numOfTags != pList->nExpr) { + return invalidSqlErrMsg(pCmd, msg5); + } + + // too long tag values will return invalid sql, not be truncated automatically + SSchema* pTagSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta); + + char* tagVal = pCreateTable->usingInfo.tagdata.data; + for (int32_t i = 0; i < pList->nExpr; ++i) { + int32_t ret = tVariantDump(&(pList->a[i].pVar), tagVal, pTagSchema[i].type); + if (ret != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg4); + } + + // validate the length of binary + if ((pTagSchema[i].type == TSDB_DATA_TYPE_BINARY || pTagSchema[i].type == TSDB_DATA_TYPE_NCHAR) && + pList->a[i].pVar.nLen > pTagSchema[i].bytes) { + return invalidSqlErrMsg(pCmd, msg3); + } + + tagVal += pTagSchema[i].bytes; + } + + // table name + if (tscValidateName(&pInfo->pCreateTableInfo->name) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + int32_t ret = setMeterID(pSql, &pInfo->pCreateTableInfo->name, 0); + if (ret != TSDB_CODE_SUCCESS) { + return ret; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { + const char* msg1 = "invalid table name"; + const char* msg2 = "table name too long"; + const char* msg3 = "fill only available for interval query"; + const char* msg4 = "fill option not supported in stream computing"; + const char* msg5 = "sql too long"; // todo ADD support + + SSqlCmd* pCmd = &pSql->cmd; + + SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo; + SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + + // if sql specifies db, use it, otherwise use default db + SSQLToken* pzTableName = &(pCreateTable->name); + SQuerySQL* pQuerySql = pCreateTable->pSelect; + + if (tscValidateName(pzTableName) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + tVariantList* pSrcMeterName = pInfo->pCreateTableInfo->pSelect->from; + tVariant* pVar = &pSrcMeterName->a[0].pVar; + + SSQLToken srcToken = {.z = pVar->pz, .n = pVar->nLen, .type = TK_STRING}; + if (tscValidateName(&srcToken) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + if (setMeterID(pSql, &srcToken, 0) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg2); + } + + int32_t code = tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + bool isMetric = UTIL_METER_IS_METRIC(pMeterMetaInfo); + if (parseSelectClause(pCmd, pQuerySql->pSelection, isMetric) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + if (pQuerySql->pWhere != NULL) { // query condition in stream computing + if (parseWhereClause(pSql, &pQuerySql->pWhere) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + } + + // set interval value + if (parseIntervalClause(pCmd, pQuerySql) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } else { + if ((pCmd->pQueryInfo[0].nAggTimeInterval > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pCmd) != TSDB_CODE_SUCCESS)) { + return TSDB_CODE_INVALID_SQL; + } + } + + if (setSlidingClause(pCmd, pQuerySql) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + // set the created table[stream] name + if (setMeterID(pSql, pzTableName, 0) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + if (pQuerySql->selectToken.n > TSDB_MAX_SAVED_SQL_LEN) { + return invalidSqlErrMsg(pCmd, msg5); + } + + if (tsRewriteFieldNameIfNecessary(pCmd) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + pCmd->numOfCols = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; + + if (validateSqlFunctionInStreamSql(pCmd) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + /* + * check if fill operation is available, the fill operation is parsed and executed during query execution, + * not here. + */ + if (pQuerySql->fillType != NULL) { + if (pCmd->pQueryInfo[0].nAggTimeInterval == 0) { + return invalidSqlErrMsg(pCmd, msg3); + } + + tVariantListItem* pItem = &pQuerySql->fillType->a[0]; + if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) { + if (!((strncmp(pItem->pVar.pz, "none", 4) == 0 && pItem->pVar.nLen == 4) || + (strncmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4))) { + return invalidSqlErrMsg(pCmd, msg4); + } + } + } + + // set the number of stream table columns + pCmd->numOfCols = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; + return TSDB_CODE_SUCCESS; +} + +int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { + assert(pQuerySql != NULL && (pQuerySql->from == NULL || pQuerySql->from->nExpr > 0)); + + const char* msg0 = "invalid table name"; + const char* msg1 = "table name too long"; + const char* msg2 = "point interpolation query needs timestamp"; + const char* msg3 = "sliding value too small"; + const char* msg4 = "sliding value no larger than the interval value"; + const char* msg5 = "fill only available for interval query"; + const char* msg6 = "start(end) time of query range required or time range too large"; + const char* msg7 = "illegal number of tables in from clause"; + const char* msg8 = "too many columns in selection clause"; + const char* msg9 = "TWA query requires both the start and end time"; + + int32_t code = TSDB_CODE_SUCCESS; + + SSqlCmd* pCmd = &pSql->cmd; + + SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + + // too many result columns not support order by in query + if (pQuerySql->pSelection->nExpr > TSDB_MAX_COLUMNS) { + return invalidSqlErrMsg(pCmd, msg8); + } + + /* + * handle the sql expression without from subclause + * select current_database(); + * select server_version(); + * select client_version(); + * select server_state(); + */ + if (pQuerySql->from == NULL) { + assert(pQuerySql->fillType == NULL && pQuerySql->pGroupby == NULL && pQuerySql->pWhere == NULL && + pQuerySql->pSortOrder == NULL); + return doLocalQueryProcess(pQuerySql, pCmd); + } + + if (pQuerySql->from->nExpr > TSDB_MAX_JOIN_TABLE_NUM) { + return invalidSqlErrMsg(pCmd, msg7); + } + + // set all query tables, which are maybe more than one. + for (int32_t i = 0; i < pQuerySql->from->nExpr; ++i) { + tVariant* pTableItem = &pQuerySql->from->a[i].pVar; + + if (pTableItem->nType != TSDB_DATA_TYPE_BINARY) { + return invalidSqlErrMsg(pCmd, msg0); + } + + pTableItem->nLen = strdequote(pTableItem->pz); + + SSQLToken tableName = {.z = pTableItem->pz, .n = pTableItem->nLen, .type = TK_STRING}; + if (tscValidateName(&tableName) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg0); + } + + if (pCmd->pQueryInfo->numOfTables <= i) { + tscAddEmptyMeterMetaInfo(pCmd); + } + + SSQLToken t = {.type = TSDB_DATA_TYPE_BINARY, .n = pTableItem->nLen, .z = pTableItem->pz}; + if (setMeterID(pSql, &t, i) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(pCmd, msg1); + } + + SMeterMetaInfo* pMeterInfo1 = tscGetMeterMetaInfo(pCmd, i); + code = tscGetMeterMeta(pSql, pMeterInfo1->name, i); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + } + + // parse the group by clause in the first place + if (parseGroupbyClause(pCmd, pQuerySql->pGroupby) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + bool isMetric = UTIL_METER_IS_METRIC(pMeterMetaInfo); + if (parseSelectClause(pCmd, pQuerySql->pSelection, isMetric) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + // set interval value + if (parseIntervalClause(pCmd, pQuerySql) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } else { + if ((pCmd->pQueryInfo[0].nAggTimeInterval > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pCmd) != TSDB_CODE_SUCCESS)) { + return TSDB_CODE_INVALID_SQL; + } + } + + // set sliding value + SSQLToken* pSliding = &pQuerySql->sliding; + if (pSliding->n != 0) { + // TODO refactor pCmd->count == 1 means sql in stream function + if (!tscEmbedded && pCmd->count == 0) { + const char* msg = "not support sliding in query"; + return invalidSqlErrMsg(pCmd, msg); + } + + getTimestampInUsFromStr(pSliding->z, pSliding->n, &pCmd->pQueryInfo[0].nSlidingTime); + if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) { + pCmd->pQueryInfo[0].nSlidingTime /= 1000; + } + + if (pCmd->pQueryInfo[0].nSlidingTime < tsMinSlidingTime) { + return invalidSqlErrMsg(pCmd, msg3); + } + + if (pCmd->pQueryInfo[0].nSlidingTime > pCmd->pQueryInfo[0].nAggTimeInterval) { + return invalidSqlErrMsg(pCmd, msg4); + } + } + + // set order by info + if (parseOrderbyClause(pCmd, pQuerySql, tsGetSchema(pMeterMetaInfo->pMeterMeta), + pMeterMetaInfo->pMeterMeta->numOfColumns) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + // set where info + if (pQuerySql->pWhere != NULL) { + if (parseWhereClause(pSql, &pQuerySql->pWhere) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + pQuerySql->pWhere = NULL; + + if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) { + pCmd->pQueryInfo[0].stime = pCmd->pQueryInfo[0].stime / 1000; + pCmd->pQueryInfo[0].etime = pCmd->pQueryInfo[0].etime / 1000; + } + } else { // set the time rang + pCmd->pQueryInfo[0].stime = 0; + pCmd->pQueryInfo[0].etime = INT64_MAX; + } + + // user does not specified the query time window, twa is not allowed in such case. + if ((pCmd->pQueryInfo[0].stime == 0 || pCmd->pQueryInfo[0].etime == INT64_MAX || + (pCmd->pQueryInfo[0].etime == INT64_MAX / 1000 && pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI)) && + tscIsTWAQuery(pCmd)) { + return invalidSqlErrMsg(pCmd, msg9); + } + + // no result due to invalid query time range + if (pCmd->pQueryInfo[0].stime > pCmd->pQueryInfo[0].etime) { + pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; + return TSDB_CODE_SUCCESS; + } + + if (!hasTimestampForPointInterpQuery(pCmd)) { + return invalidSqlErrMsg(pCmd, msg2); + } + + if (pQuerySql->fillType != NULL) { + if (pCmd->pQueryInfo[0].nAggTimeInterval == 0 && (!tscIsPointInterpQuery(pCmd))) { + return invalidSqlErrMsg(pCmd, msg5); + } + + if (pCmd->pQueryInfo[0].nAggTimeInterval > 0) { + int64_t timeRange = labs(pCmd->pQueryInfo[0].stime - pCmd->pQueryInfo[0].etime); + // number of result is not greater than 10,000,000 + if ((timeRange == 0) || (timeRange / pCmd->pQueryInfo[0].nAggTimeInterval) > MAX_RETRIEVE_ROWS_IN_INTERVAL_QUERY) { + return invalidSqlErrMsg(pCmd, msg6); + } + } + + int32_t ret = parseFillClause(pCmd, pQuerySql); + if (ret != TSDB_CODE_SUCCESS) { + return ret; + } + } + + // in case of join query, time range is required. + if (QUERY_IS_JOIN_QUERY(pCmd->type)) { + int64_t timeRange = labs(pCmd->pQueryInfo[0].stime - pCmd->pQueryInfo[0].etime); + + if (timeRange == 0 && pCmd->pQueryInfo[0].stime == 0) { + return invalidSqlErrMsg(pCmd, msg6); + } + } + + // handle the limit offset value, validate the limit + pCmd->pQueryInfo->limit = pQuerySql->limit; + + // temporarily save the original limitation value + if ((code = parseLimitClause(pSql, pQuerySql)) != TSDB_CODE_SUCCESS) { + return code; + } + + if ((code = doFunctionsCompatibleCheck(pSql)) != TSDB_CODE_SUCCESS) { + return code; + } + + setColumnOffsetValueInResultset(pCmd); + + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { + updateTagColumnIndex(pCmd, i); + } + + return TSDB_CODE_SUCCESS; // Does not build query message here +} diff --git a/src/client/src/tscSQLParserImpl.c b/src/client/src/tscSQLParserImpl.c index cc4375fb03896b240bc57fdabcf2728ade996329..49353c6febadafc221d311d472e36d451d191492 100644 --- a/src/client/src/tscSQLParserImpl.c +++ b/src/client/src/tscSQLParserImpl.c @@ -24,7 +24,7 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { void *pParser = ParseAlloc(malloc); - pSQLInfo->validSql = true; + pSQLInfo->valid = true; int32_t i = 0; while (1) { @@ -50,12 +50,12 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { } case TK_ILLEGAL: { snprintf(pSQLInfo->pzErrMsg, tListLen(pSQLInfo->pzErrMsg), "unrecognized token: \"%s\"", t0.z); - pSQLInfo->validSql = false; + pSQLInfo->valid = false; goto abort_parse; } default: Parse(pParser, t0.type, t0, pSQLInfo); - if (pSQLInfo->validSql == false) { + if (pSQLInfo->valid == false) { goto abort_parse; } } @@ -554,58 +554,62 @@ tSQLExprListList *tSQLListListAppend(tSQLExprListList *pList, tSQLExprList *pExp return pList; } -void tSetInsertSQLElems(SSqlInfo *pInfo, SSQLToken *pName, tSQLExprListList *pList) { - SInsertSQL *pInsert = calloc(1, sizeof(SInsertSQL)); - - pInsert->name = *pName; - pInsert->pValue = pList; - - pInfo->pInsertInfo = pInsert; - pInfo->sqlType = TSQL_INSERT; -} - -void destroyQuerySql(SQuerySQL *pSql) { - if (pSql == NULL) return; - - tSQLExprListDestroy(pSql->pSelection); - pSql->pSelection = NULL; - - tSQLExprDestroy(pSql->pWhere); - pSql->pWhere = NULL; - - tVariantListDestroy(pSql->pSortOrder); - pSql->pSortOrder = NULL; - - tVariantListDestroy(pSql->pGroupby); - pSql->pGroupby = NULL; - - tVariantListDestroy(pSql->from); - pSql->from = NULL; - - tVariantListDestroy(pSql->fillType); +void doDestroyQuerySql(SQuerySQL *pQuerySql) { + if (pQuerySql == NULL) { + return; + } + + tSQLExprListDestroy(pQuerySql->pSelection); + + pQuerySql->pSelection = NULL; + + tSQLExprDestroy(pQuerySql->pWhere); + pQuerySql->pWhere = NULL; + + tVariantListDestroy(pQuerySql->pSortOrder); + pQuerySql->pSortOrder = NULL; + + tVariantListDestroy(pQuerySql->pGroupby); + pQuerySql->pGroupby = NULL; + + tVariantListDestroy(pQuerySql->from); + pQuerySql->from = NULL; + + tVariantListDestroy(pQuerySql->fillType); + + free(pQuerySql); +} + +void destroyAllSelectClause(SSubclauseInfo *pClause) { + if (pClause == NULL || pClause->numOfClause == 0) { + return; + } - free(pSql); + for(int32_t i = 0; i < pClause->numOfClause; ++i) { + SQuerySQL *pQuerySql = pClause->pClause[i]; + doDestroyQuerySql(pQuerySql); + } } -SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pMetricName, +SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pStableName, tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type) { SCreateTableSQL *pCreate = calloc(1, sizeof(SCreateTableSQL)); switch (type) { - case TSQL_CREATE_NORMAL_METER: { + case TSQL_CREATE_TABLE: { pCreate->colInfo.pColumns = pCols; assert(pTagVals == NULL && pTags == NULL); break; } - case TSQL_CREATE_NORMAL_METRIC: { + case TSQL_CREATE_STABLE: { pCreate->colInfo.pColumns = pCols; pCreate->colInfo.pTagColumns = pTags; assert(pTagVals == NULL && pTags != NULL && pCols != NULL); break; } - case TSQL_CREATE_METER_FROM_METRIC: { + case TSQL_CREATE_TABLE_FROM_STABLE: { pCreate->usingInfo.pTagVals = pTagVals; - pCreate->usingInfo.metricName = *pMetricName; + pCreate->usingInfo.stableName = *pStableName; break; } case TSQL_CREATE_STREAM: { @@ -616,19 +620,24 @@ SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLTo assert(false); } + pCreate->type = type; return pCreate; } SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type) { SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL)); + pAlterTable->name = *pMeterName; + pAlterTable->type = type; - if (type == ALTER_TABLE_ADD_COLUMN || type == ALTER_TABLE_TAGS_ADD) { + if (type == TSDB_ALTER_TABLE_ADD_COLUMN || type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) { pAlterTable->pAddColumns = pCols; assert(pVals == NULL); } else { - /* ALTER_TABLE_TAGS_CHG, ALTER_TABLE_TAGS_SET, ALTER_TABLE_TAGS_DROP, - * ALTER_TABLE_DROP_COLUMN */ + /* + * ALTER_TABLE_TAGS_CHG, ALTER_TABLE_TAGS_SET, ALTER_TABLE_TAGS_DROP, + * ALTER_TABLE_DROP_COLUMN + */ pAlterTable->varList = pVals; assert(pCols == NULL); } @@ -639,27 +648,28 @@ SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tV void SQLInfoDestroy(SSqlInfo *pInfo) { if (pInfo == NULL) return; - if (pInfo->sqlType == TSQL_QUERY_METER) { - destroyQuerySql(pInfo->pQueryInfo); - } else if (pInfo->sqlType >= TSQL_CREATE_NORMAL_METER && pInfo->sqlType <= TSQL_CREATE_STREAM) { + if (pInfo->type == TSDB_SQL_SELECT) { + destroyAllSelectClause(&pInfo->subclauseInfo); + } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) { SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo; - destroyQuerySql(pCreateTableInfo->pSelect); + doDestroyQuerySql(pCreateTableInfo->pSelect); tFieldListDestroy(pCreateTableInfo->colInfo.pColumns); tFieldListDestroy(pCreateTableInfo->colInfo.pTagColumns); tVariantListDestroy(pCreateTableInfo->usingInfo.pTagVals); tfree(pInfo->pCreateTableInfo); - } else if (pInfo->sqlType >= ALTER_TABLE_TAGS_ADD && pInfo->sqlType <= ALTER_TABLE_DROP_COLUMN) { + } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { tVariantListDestroy(pInfo->pAlterInfo->varList); tFieldListDestroy(pInfo->pAlterInfo->pAddColumns); + tfree(pInfo->pAlterInfo); } else { if (pInfo->pDCLInfo != NULL && pInfo->pDCLInfo->nAlloc > 0) { free(pInfo->pDCLInfo->a); } - if (pInfo->sqlType == CREATE_DATABASE) { + if (pInfo->type == TSDB_SQL_CREATE_DB) { tVariantListDestroy(pInfo->pDCLInfo->dbOpt.keep); } @@ -667,13 +677,52 @@ void SQLInfoDestroy(SSqlInfo *pInfo) { } } -void setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SSQLToken *pMeterName, int32_t type) { - pInfo->sqlType = type; - pInfo->pCreateTableInfo = pSqlExprInfo; +SSubclauseInfo* setSubclause(SSubclauseInfo* pSubclause, void *pSqlExprInfo) { + if (pSubclause == NULL) { + pSubclause = calloc(1, sizeof(SSubclauseInfo)); + } + + int32_t newSize = pSubclause->numOfClause + 1; + char* tmp = realloc(pSubclause->pClause, newSize * POINTER_BYTES); + if (tmp == NULL) { + return pSubclause; + } + + pSubclause->pClause = (SQuerySQL**) tmp; + + pSubclause->pClause[newSize - 1] = pSqlExprInfo; + pSubclause->numOfClause++; + + return pSubclause; +} +SSqlInfo* setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SSQLToken *pMeterName, int32_t type) { + pInfo->type = type; + + if (type == TSDB_SQL_SELECT) { + pInfo->subclauseInfo = *(SSubclauseInfo*) pSqlExprInfo; + free(pSqlExprInfo); + } else { + pInfo->pCreateTableInfo = pSqlExprInfo; + } + if (pMeterName != NULL) { pInfo->pCreateTableInfo->name = *pMeterName; } + + return pInfo; +} + +SSubclauseInfo* appendSelectClause(SSubclauseInfo *pQueryInfo, void *pSubclause) { + char* tmp = realloc(pQueryInfo->pClause, (pQueryInfo->numOfClause + 1) * POINTER_BYTES); + if (tmp == NULL) { // out of memory + return pQueryInfo; + } + + pQueryInfo->pClause = (SQuerySQL**) tmp; + pQueryInfo->pClause[pQueryInfo->numOfClause++] = pSubclause; + + return pQueryInfo; } void setCreatedMeterName(SSqlInfo *pInfo, SSQLToken *pMeterName, SSQLToken *pIfNotExists) { @@ -703,7 +752,7 @@ tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken) { } void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) { - pInfo->sqlType = type; + pInfo->type = type; if (nParam == 0) return; if (pInfo->pDCLInfo == NULL) pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); @@ -718,8 +767,42 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) { va_end(va); } +void setDropDBTableInfo(SSqlInfo *pInfo, int32_t type, SSQLToken* pToken, SSQLToken* existsCheck) { + pInfo->type = type; + + if (pInfo->pDCLInfo == NULL) { + pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); + } + + tTokenListAppend(pInfo->pDCLInfo, pToken); + pInfo->pDCLInfo->existsCheck = (existsCheck->n == 1); +} + +void setShowOptions(SSqlInfo *pInfo, int32_t type, SSQLToken* prefix, SSQLToken* pPatterns) { + if (pInfo->pDCLInfo == NULL) { + pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); + } + + pInfo->type = TSDB_SQL_SHOW; + + SShowInfo* pShowInfo = &pInfo->pDCLInfo->showOpt; + pShowInfo->showType = type; + + if (prefix != NULL && prefix->type != 0) { + pShowInfo->prefix = *prefix; + } else { + pShowInfo->prefix.type = 0; + } + + if (pPatterns != NULL && pPatterns->type != 0) { + pShowInfo->pattern = *pPatterns; + } else { + pShowInfo->pattern.type = 0; + } +} + void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists) { - pInfo->sqlType = type; + pInfo->type = type; if (pInfo->pDCLInfo == NULL) { pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); } @@ -731,18 +814,68 @@ void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBI } void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo) { - pInfo->sqlType = type; + pInfo->type = type; if (pInfo->pDCLInfo == NULL) { pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); } pInfo->pDCLInfo->acctOpt = *pAcctInfo; + + assert(pName != NULL); + pInfo->pDCLInfo->user.user = *pName; + + if (pPwd != NULL) { + pInfo->pDCLInfo->user.passwd = *pPwd; +// pInfo->pDCLInfo->user.hasPasswd = true; + } else { +// pInfo->pDCLInfo->user.hasPasswd = false; + } +} - tTokenListAppend(pInfo->pDCLInfo, pName); +void setCreateUserSQL(SSqlInfo *pInfo, SSQLToken *pName, SSQLToken *pPasswd) { + pInfo->type = TSDB_SQL_CREATE_USER; + if (pInfo->pDCLInfo == NULL) { + pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); + } + + assert(pName != NULL && pPasswd != NULL); + + pInfo->pDCLInfo->user.user = *pName; + pInfo->pDCLInfo->user.passwd = *pPasswd; +} - if (pPwd->n > 0) { - tTokenListAppend(pInfo->pDCLInfo, pPwd); +void setAlterUserSQL(SSqlInfo *pInfo, int16_t type, SSQLToken *pName, SSQLToken* pPwd, SSQLToken *pPrivilege) { + pInfo->type = TSDB_SQL_ALTER_USER; + if (pInfo->pDCLInfo == NULL) { + pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); + } + + assert(pName != NULL); + + SUserInfo* pUser = &pInfo->pDCLInfo->user; + pUser->type = type; + pUser->user = *pName; + + if (pPwd != NULL) { + pUser->passwd = *pPwd; +// pUser->hasPasswd = true; + } + + if (pPrivilege != NULL) { + pUser->privilege = *pPrivilege; +// pUser->hasPrivilege = true; + } +} + +void setKillSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *ip) { + pInfo->type = type; + if (pInfo->pDCLInfo == NULL) { + pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); } + + assert(ip != NULL); + + pInfo->pDCLInfo->ip = *ip; } void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) { diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 737c1342d8b8d852a9fa66fd8c5635be15b4d911..e499486e624507e4cffb534a5a86d872736f5c37 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -58,12 +58,12 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu * the fields and offset attributes in pCmd and pModel may be different due to * merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object. */ - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SQLFunctionCtx *pCtx = &pReducer->pCtx[i]; pCtx->aOutputBuf = pReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pReducer->resColModel->maxCapacity; pCtx->order = pCmd->order.order; - pCtx->functionId = pCmd->exprsInfo.pExprs[i].functionId; + pCtx->functionId = pCmd->pQueryInfo[0].exprsInfo.pExprs[i].functionId; // input buffer hold only one point data pCtx->aInputElemBuf = pReducer->pTempBuffer->data + pDesc->pSchema->colOffset[i]; @@ -105,10 +105,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu int16_t n = 0; int16_t tagLen = 0; - SQLFunctionCtx** pTagCtx = calloc(pCmd->fieldsInfo.numOfOutputCols, POINTER_BYTES); + SQLFunctionCtx** pTagCtx = calloc(pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, POINTER_BYTES); SQLFunctionCtx* pCtx = NULL; - for(int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for(int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TS_DUMMY) { tagLen += pExpr->resBytes; @@ -238,7 +238,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd param->pLocalData = pReducer->pLocalDataSrc; param->pDesc = pReducer->pDesc; param->numOfElems = pReducer->pLocalDataSrc[0]->pMemBuffer->numOfElemsPerPage; - param->groupOrderType = pCmd->groupbyExpr.orderType; + param->groupOrderType = pCmd->pQueryInfo[0].groupbyExpr.orderType; pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator); if (pReducer->pLoserTree == NULL || pRes->code != 0) { @@ -247,7 +247,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd // the input data format follows the old format, but output in a new format. // so, all the input must be parsed as old format - pReducer->pCtx = (SQLFunctionCtx *)calloc(pCmd->fieldsInfo.numOfOutputCols, sizeof(SQLFunctionCtx)); + pReducer->pCtx = (SQLFunctionCtx *)calloc(pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, sizeof(SQLFunctionCtx)); pReducer->rowSize = pMemBuffer[0]->nElemSize; @@ -294,14 +294,14 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd } pReducer->pTempBuffer->numOfElems = 0; - pReducer->pResInfo = calloc((size_t)pCmd->fieldsInfo.numOfOutputCols, sizeof(SResultInfo)); + pReducer->pResInfo = calloc((size_t)pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, sizeof(SResultInfo)); tscCreateResPointerInfo(pCmd, pRes); tscInitSqlContext(pCmd, pRes, pReducer, pDesc); // we change the maxCapacity of schema to denote that there is only one row in temp buffer pReducer->pDesc->pSchema->maxCapacity = 1; - pReducer->offset = pCmd->limit.offset; + pReducer->offset = pCmd->pQueryInfo->limit.offset; pRes->pLocalReducer = pReducer; pRes->numOfGroups = 0; @@ -309,18 +309,18 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); int16_t prec = pMeterMetaInfo->pMeterMeta->precision; - int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime; - int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, prec); + int64_t stime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].stime : pCmd->pQueryInfo[0].etime; + int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, prec); SInterpolationInfo *pInterpoInfo = &pReducer->interpolationInfo; - taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->groupbyExpr.numOfGroupCols, + taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols, pReducer->rowSize); - int32_t startIndex = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupCols; + int32_t startIndex = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; - if (pCmd->groupbyExpr.numOfGroupCols > 0) { - pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pCmd->groupbyExpr.numOfGroupCols; - for (int32_t i = 1; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) { + pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; + for (int32_t i = 1; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) { pInterpoInfo->pTags[i] = pReducer->resColModel->pFields[startIndex + i - 1].bytes + pInterpoInfo->pTags[i - 1]; } } else { @@ -444,7 +444,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { tfree(pLocalReducer->interpolationInfo.pTags); if (pLocalReducer->pCtx != NULL) { - for(int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for(int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i]; tVariantDestroy(&pCtx->tag); } @@ -459,7 +459,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { tfree(pLocalReducer->pResultBuf); if (pLocalReducer->pResInfo != NULL) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { tfree(pLocalReducer->pResInfo[i].interResultBuf); } @@ -494,12 +494,12 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCmd, tColModel *pModel) { int32_t numOfGroupByCols = 0; - if (pCmd->groupbyExpr.numOfGroupCols > 0) { - numOfGroupByCols = pCmd->groupbyExpr.numOfGroupCols; + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) { + numOfGroupByCols = pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; } // primary timestamp column is involved in final result - if (pCmd->nAggTimeInterval != 0) { + if (pCmd->pQueryInfo[0].nAggTimeInterval != 0) { numOfGroupByCols++; } @@ -509,14 +509,14 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm } if (numOfGroupByCols > 0) { - int32_t startCols = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupCols; + int32_t startCols = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; // tags value locate at the last columns - for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) { orderIdx[i] = startCols++; } - if (pCmd->nAggTimeInterval != 0) { + if (pCmd->pQueryInfo[0].nAggTimeInterval != 0) { // the first column is the timestamp, handles queries like "interval(10m) group by tags" orderIdx[numOfGroupByCols - 1] = PRIMARYKEY_TIMESTAMP_COL_INDEX; } @@ -550,10 +550,10 @@ bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage if (pOrderDesc->orderIdx.pData[numOfCols - 1] == PRIMARYKEY_TIMESTAMP_COL_INDEX) { //<= 0 // super table interval query - assert(pCmd->nAggTimeInterval > 0); + assert(pCmd->pQueryInfo[0].nAggTimeInterval > 0); pOrderDesc->orderIdx.numOfOrderedCols -= 1; } else { // simple group by query - assert(pCmd->nAggTimeInterval == 0); + assert(pCmd->pQueryInfo[0].nAggTimeInterval == 0); } // only one row exists @@ -581,7 +581,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr return pRes->code; } - pSchema = (SSchema *)calloc(1, sizeof(SSchema) * pCmd->fieldsInfo.numOfOutputCols); + pSchema = (SSchema *)calloc(1, sizeof(SSchema) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols); if (pSchema == NULL) { tscError("%p failed to allocate memory", pSql); pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; @@ -589,7 +589,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr } int32_t rlen = 0; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, i); pSchema[i].bytes = pExpr->resBytes; @@ -599,7 +599,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr } int32_t capacity = nBufferSizes / rlen; - pModel = tColModelCreate(pSchema, pCmd->fieldsInfo.numOfOutputCols, capacity); + pModel = tColModelCreate(pSchema, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, capacity); for (int32_t i = 0; i < pMeterMetaInfo->pMetricMeta->numOfVnodes; ++i) { char tmpPath[512] = {0}; @@ -615,8 +615,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr return pRes->code; } - memset(pSchema, 0, sizeof(SSchema) * pCmd->fieldsInfo.numOfOutputCols); - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + memset(pSchema, 0, sizeof(SSchema) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols); + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); pSchema[i].type = pField->type; @@ -624,7 +624,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr strcpy(pSchema[i].name, pField->name); } - *pFinalModel = tColModelCreate(pSchema, pCmd->fieldsInfo.numOfOutputCols, capacity); + *pFinalModel = tColModelCreate(pSchema, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, capacity); tfree(pSchema); return TSDB_CODE_SUCCESS; @@ -719,10 +719,10 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); int16_t prec = pMeterMetaInfo->pMeterMeta->precision; - int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime; - int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, prec); + int64_t stime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].stime : pCmd->pQueryInfo[0].etime; + int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, prec); - taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->groupbyExpr.numOfGroupCols, + taosInitInterpoInfo(pInterpoInfo, pCmd->order.order, revisedSTime, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols, pLocalReducer->rowSize); pLocalReducer->discard = true; @@ -734,7 +734,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC // todo merge with following function static void reversedCopyResultToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage *pFinalDataPage) { - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); int32_t offset = tscFieldInfoGetOffset(pCmd, i); @@ -751,7 +751,7 @@ static void reversedCopyResultToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage * static void reversedCopyFromInterpolationToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage **pResPages, SLocalReducer *pLocalReducer) { - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); int32_t offset = tscFieldInfoGetOffset(pCmd, i); @@ -786,38 +786,38 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo assert(pRes->pLocalReducer == NULL); } - if (pCmd->nAggTimeInterval == 0 || pCmd->interpoType == TSDB_INTERPO_NONE) { + if (pCmd->pQueryInfo[0].nAggTimeInterval == 0 || pCmd->pQueryInfo[0].interpoType == TSDB_INTERPO_NONE) { // no interval query, no interpolation pRes->data = pLocalReducer->pFinalRes; pRes->numOfRows = pFinalDataPage->numOfElems; pRes->numOfTotal += pRes->numOfRows; - if (pCmd->limit.offset > 0) { - if (pCmd->limit.offset < pRes->numOfRows) { + if (pCmd->pQueryInfo->limit.offset > 0) { + if (pCmd->pQueryInfo->limit.offset < pRes->numOfRows) { int32_t prevSize = pFinalDataPage->numOfElems; - tColModelErase(pLocalReducer->resColModel, pFinalDataPage, prevSize, 0, pCmd->limit.offset - 1); + tColModelErase(pLocalReducer->resColModel, pFinalDataPage, prevSize, 0, pCmd->pQueryInfo->limit.offset - 1); /* remove the hole in column model */ tColModelCompact(pLocalReducer->resColModel, pFinalDataPage, prevSize); - pRes->numOfRows -= pCmd->limit.offset; - pRes->numOfTotal -= pCmd->limit.offset; - pCmd->limit.offset = 0; + pRes->numOfRows -= pCmd->pQueryInfo->limit.offset; + pRes->numOfTotal -= pCmd->pQueryInfo->limit.offset; + pCmd->pQueryInfo->limit.offset = 0; } else { - pCmd->limit.offset -= pRes->numOfRows; + pCmd->pQueryInfo->limit.offset -= pRes->numOfRows; pRes->numOfRows = 0; pRes->numOfTotal = 0; } } - if (pCmd->limit.limit >= 0 && pRes->numOfTotal > pCmd->limit.limit) { + if (pCmd->pQueryInfo->limit.limit >= 0 && pRes->numOfTotal > pCmd->pQueryInfo->limit.limit) { /* impose the limitation of output rows on the final result */ int32_t prevSize = pFinalDataPage->numOfElems; - int32_t overFlow = pRes->numOfTotal - pCmd->limit.limit; + int32_t overFlow = pRes->numOfTotal - pCmd->pQueryInfo->limit.limit; assert(overFlow < pRes->numOfRows); - pRes->numOfTotal = pCmd->limit.limit; + pRes->numOfTotal = pCmd->pQueryInfo->limit.limit; pRes->numOfRows -= overFlow; pFinalDataPage->numOfElems -= overFlow; @@ -842,18 +842,18 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo int64_t * pPrimaryKeys = (int64_t *)pLocalReducer->pBufForInterpo; SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo; - int64_t actualETime = (pCmd->stime < pCmd->etime) ? pCmd->etime : pCmd->stime; + int64_t actualETime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].etime : pCmd->pQueryInfo[0].stime; - tFilePage **pResPages = malloc(POINTER_BYTES * pCmd->fieldsInfo.numOfOutputCols); - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + tFilePage **pResPages = malloc(POINTER_BYTES * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols); + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalReducer->resColModel->maxCapacity); } - char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pCmd->fieldsInfo.numOfOutputCols); - int32_t *functions = (int32_t *)((char *)srcData + pCmd->fieldsInfo.numOfOutputCols * sizeof(void *)); + char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols); + int32_t *functions = (int32_t *)((char *)srcData + pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols * sizeof(void *)); - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { srcData[i] = pLocalReducer->pBufForInterpo + tscFieldInfoGetOffset(pCmd, i) * pInterpoInfo->numOfRawDataInRows; functions[i] = tscSqlExprGet(pCmd, i)->functionId; } @@ -863,23 +863,23 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo while (1) { int32_t remains = taosNumOfRemainPoints(pInterpoInfo); - TSKEY etime = taosGetRevisedEndKey(actualETime, pCmd->order.order, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, + TSKEY etime = taosGetRevisedEndKey(actualETime, pCmd->order.order, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, precision); - int32_t nrows = taosGetNumOfResultWithInterpo(pInterpoInfo, pPrimaryKeys, remains, pCmd->nAggTimeInterval, etime, + int32_t nrows = taosGetNumOfResultWithInterpo(pInterpoInfo, pPrimaryKeys, remains, pCmd->pQueryInfo[0].nAggTimeInterval, etime, pLocalReducer->resColModel->maxCapacity); - int32_t newRows = taosDoInterpoResult(pInterpoInfo, pCmd->interpoType, pResPages, remains, nrows, - pCmd->nAggTimeInterval, pPrimaryKeys, pLocalReducer->resColModel, srcData, - pCmd->defaultVal, functions, pLocalReducer->resColModel->maxCapacity); + int32_t newRows = taosDoInterpoResult(pInterpoInfo, pCmd->pQueryInfo[0].interpoType, pResPages, remains, nrows, + pCmd->pQueryInfo[0].nAggTimeInterval, pPrimaryKeys, pLocalReducer->resColModel, srcData, + pCmd->pQueryInfo[0].defaultVal, functions, pLocalReducer->resColModel->maxCapacity); assert(newRows <= nrows); - if (pCmd->limit.offset < newRows) { - newRows -= pCmd->limit.offset; + if (pCmd->pQueryInfo->limit.offset < newRows) { + newRows -= pCmd->pQueryInfo->limit.offset; - if (pCmd->limit.offset > 0) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + if (pCmd->pQueryInfo->limit.offset > 0) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); - memmove(pResPages[i]->data, pResPages[i]->data + pField->bytes * pCmd->limit.offset, newRows * pField->bytes); + memmove(pResPages[i]->data, pResPages[i]->data + pField->bytes * pCmd->pQueryInfo->limit.offset, newRows * pField->bytes); } } @@ -887,10 +887,10 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo pRes->numOfRows = newRows; pRes->numOfTotal += newRows; - pCmd->limit.offset = 0; + pCmd->pQueryInfo->limit.offset = 0; break; } else { - pCmd->limit.offset -= newRows; + pCmd->pQueryInfo->limit.offset -= newRows; pRes->numOfRows = 0; int32_t rpoints = taosNumOfRemainPoints(pInterpoInfo); @@ -902,7 +902,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo /* all output for current group are completed */ int32_t totalRemainRows = - taosGetNumOfResWithoutLimit(pInterpoInfo, pPrimaryKeys, rpoints, pCmd->nAggTimeInterval, actualETime); + taosGetNumOfResWithoutLimit(pInterpoInfo, pPrimaryKeys, rpoints, pCmd->pQueryInfo[0].nAggTimeInterval, actualETime); if (totalRemainRows <= 0) { break; } @@ -911,13 +911,13 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo } if (pRes->numOfRows > 0) { - if (pCmd->limit.limit >= 0 && pRes->numOfTotal > pCmd->limit.limit) { - int32_t overFlow = pRes->numOfTotal - pCmd->limit.limit; + if (pCmd->pQueryInfo->limit.limit >= 0 && pRes->numOfTotal > pCmd->pQueryInfo->limit.limit) { + int32_t overFlow = pRes->numOfTotal - pCmd->pQueryInfo->limit.limit; pRes->numOfRows -= overFlow; assert(pRes->numOfRows >= 0); - pRes->numOfTotal = pCmd->limit.limit; + pRes->numOfTotal = pCmd->pQueryInfo->limit.limit; pFinalDataPage->numOfElems -= overFlow; /* set remain data to be discarded, and reset the interpolation information */ @@ -925,7 +925,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo } if (pCmd->order.order == TSQL_SO_ASC) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); memcpy(pRes->data + pLocalReducer->resColModel->colOffset[i] * pRes->numOfRows, pResPages[i]->data, @@ -937,7 +937,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo } pFinalDataPage->numOfElems = 0; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { tfree(pResPages[i]); } tfree(pResPages); @@ -961,7 +961,7 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, bool needInit) { // the tag columns need to be set before all functions execution - for(int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) { + for(int32_t j = 0; j < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++j) { SSqlExpr * pExpr = tscSqlExprGet(pCmd, j); SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[j]; @@ -981,7 +981,7 @@ static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, } } - for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) { + for (int32_t j = 0; j < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++j) { int32_t functionId = tscSqlExprGet(pCmd, j)->functionId; if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { continue; @@ -1002,7 +1002,7 @@ static void handleUnprocessedRow(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, tF static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) { int64_t maxOutput = 0; - for (int32_t j = 0; j < pCmd->exprsInfo.numOfExprs; ++j) { + for (int32_t j = 0; j < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++j) { int32_t functionId = tscSqlExprGet(pCmd, j)->functionId; /* @@ -1028,7 +1028,7 @@ static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) { */ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReducer *pLocalReducer) { int32_t maxBufSize = 0; // find the max tags column length to prepare the buffer - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, k); if (maxBufSize < pExpr->resBytes && pExpr->functionId == TSDB_FUNC_TAG) { maxBufSize = pExpr->resBytes; @@ -1038,7 +1038,7 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce assert(maxBufSize >= 0); char *buf = malloc((size_t) maxBufSize); - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, k); if (pExpr->functionId != TSDB_FUNC_TAG) { continue; @@ -1060,7 +1060,7 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce } int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) { - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, k); aAggs[pExpr->functionId].xFinalize(&pLocalReducer->pCtx[k]); @@ -1107,7 +1107,7 @@ bool needToMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuff } static bool reachGroupResultLimit(SSqlCmd *pCmd, SSqlRes *pRes) { - return (pRes->numOfGroups >= pCmd->slimit.limit && pCmd->slimit.limit >= 0); + return (pRes->numOfGroups >= pCmd->pQueryInfo[0].slimit.limit && pCmd->pQueryInfo[0].slimit.limit >= 0); } static bool saveGroupResultInfo(SSqlObj *pSql) { @@ -1147,9 +1147,9 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no * ignore the output of the current group since this group is skipped by user * We set the numOfRows to be 0 and discard the possible remain results. */ - if (pCmd->slimit.offset > 0) { + if (pCmd->pQueryInfo[0].slimit.offset > 0) { pRes->numOfRows = 0; - pCmd->slimit.offset -= 1; + pCmd->pQueryInfo[0].slimit.offset -= 1; pLocalReducer->discard = !noMoreCurrentGroupRes; return false; } @@ -1163,22 +1163,22 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no #endif SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo; - int32_t startIndex = pCmd->fieldsInfo.numOfOutputCols - pCmd->groupbyExpr.numOfGroupCols; + int32_t startIndex = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; - for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) { memcpy(pInterpoInfo->pTags[i], pLocalReducer->pBufForInterpo + pModel->colOffset[startIndex + i] * pResBuf->numOfElems, pModel->pFields[startIndex + i].bytes); } - taosInterpoSetStartInfo(&pLocalReducer->interpolationInfo, pResBuf->numOfElems, pCmd->interpoType); + taosInterpoSetStartInfo(&pLocalReducer->interpolationInfo, pResBuf->numOfElems, pCmd->pQueryInfo[0].interpoType); doInterpolateResult(pSql, pLocalReducer, noMoreCurrentGroupRes); return true; } void resetOutputBuf(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) { // reset output buffer to the beginning - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { pLocalReducer->pCtx[i].aOutputBuf = pLocalReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pLocalReducer->resColModel->maxCapacity; } @@ -1190,17 +1190,17 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer // In handling data in other groups, we need to reset the interpolation information for a new group data pRes->numOfRows = 0; pRes->numOfTotal = 0; - pCmd->limit.offset = pLocalReducer->offset; + pCmd->pQueryInfo->limit.offset = pLocalReducer->offset; SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); int16_t precision = pMeterMetaInfo->pMeterMeta->precision; // for group result interpolation, do not return if not data is generated - if (pCmd->interpoType != TSDB_INTERPO_NONE) { - int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime; - int64_t newTime = taosGetIntervalStartTimestamp(stime, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, precision); + if (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) { + int64_t stime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].stime : pCmd->pQueryInfo[0].etime; + int64_t newTime = taosGetIntervalStartTimestamp(stime, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, precision); - taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pCmd->order.order, newTime, pCmd->groupbyExpr.numOfGroupCols, + taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pCmd->order.order, newTime, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols, pLocalReducer->rowSize); } } @@ -1220,15 +1220,15 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) { int8_t p = pMeterMetaInfo->pMeterMeta->precision; if (taosHasRemainsDataForInterpolation(pInterpoInfo)) { - assert(pCmd->interpoType != TSDB_INTERPO_NONE); + assert(pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE); tFilePage *pFinalDataBuf = pLocalReducer->pResultBuf; int64_t etime = *(int64_t *)(pFinalDataBuf->data + TSDB_KEYSIZE * (pInterpoInfo->numOfRawDataInRows - 1)); int32_t remain = taosNumOfRemainPoints(pInterpoInfo); - TSKEY ekey = taosGetRevisedEndKey(etime, pCmd->order.order, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, p); + TSKEY ekey = taosGetRevisedEndKey(etime, pCmd->order.order, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, p); int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, (TSKEY *)pLocalReducer->pBufForInterpo, remain, - pCmd->nAggTimeInterval, ekey, pLocalReducer->resColModel->maxCapacity); + pCmd->pQueryInfo[0].nAggTimeInterval, ekey, pLocalReducer->resColModel->maxCapacity); if (rows > 0) { // do interpo doInterpolateResult(pSql, pLocalReducer, false); } @@ -1254,11 +1254,11 @@ static bool doHandleLastRemainData(SSqlObj *pSql) { if ((isAllSourcesCompleted(pLocalReducer) && !pLocalReducer->hasPrevRow) || pLocalReducer->pLocalDataSrc[0] == NULL || prevGroupCompleted) { // if interpoType == TSDB_INTERPO_NONE, return directly - if (pCmd->interpoType != TSDB_INTERPO_NONE) { - int64_t etime = (pCmd->stime < pCmd->etime) ? pCmd->etime : pCmd->stime; + if (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) { + int64_t etime = (pCmd->pQueryInfo[0].stime < pCmd->pQueryInfo[0].etime) ? pCmd->pQueryInfo[0].etime : pCmd->pQueryInfo[0].stime; - etime = taosGetRevisedEndKey(etime, pCmd->order.order, pCmd->nAggTimeInterval, pCmd->intervalTimeUnit, precision); - int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pCmd->nAggTimeInterval, etime, + etime = taosGetRevisedEndKey(etime, pCmd->order.order, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, precision); + int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pCmd->pQueryInfo[0].nAggTimeInterval, etime, pLocalReducer->resColModel->maxCapacity); if (rows > 0) { // do interpo doInterpolateResult(pSql, pLocalReducer, true); @@ -1291,7 +1291,7 @@ static void doMergeWithPrevRows(SSqlObj *pSql, int32_t numOfRes) { SSqlRes * pRes = &pSql->res; SLocalReducer *pLocalReducer = pRes->pLocalReducer; - for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { + for (int32_t k = 0; k < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++k) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, k); SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k]; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 37bbd93ec610692fc538d0a6b4d5524ddfb22cd7..2a5a14a3f517e059bfee600297a0914d73b06b13 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -18,13 +18,13 @@ #include "trpc.h" #include "tscJoinProcess.h" #include "tscProfile.h" +#include "tscSQLParser.h" #include "tscSecondaryMerge.h" #include "tscUtil.h" #include "tschemautil.h" #include "tsclient.h" #include "tscompression.h" #include "tsocket.h" -#include "tscSQLParser.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" @@ -32,23 +32,26 @@ #define TSC_MGMT_VNODE 999 #ifdef CLUSTER - SIpStrList tscMgmtIpList; - int tsMasterIndex = 0; - int tsSlaveIndex = 1; +SIpStrList tscMgmtIpList; +int tsMasterIndex = 0; +int tsSlaveIndex = 1; #else - int tsMasterIndex = 0; - int tsSlaveIndex = 0; // slave == master for single node edition - uint32_t tsServerIp; +int tsMasterIndex = 0; +int tsSlaveIndex = 0; // slave == master for single node edition +uint32_t tsServerIp; #endif -int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql); +int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0}; + int (*tscProcessMsgRsp[TSDB_SQL_MAX])(SSqlObj *pSql); void (*tscUpdateVnodeMsg[TSDB_SQL_MAX])(SSqlObj *pSql, char *buf); void tscProcessActivityTimer(void *handle, void *tmrId); -int tscKeepConn[TSDB_SQL_MAX] = {0}; +int tscKeepConn[TSDB_SQL_MAX] = {0}; static int32_t minMsgSize() { return tsRpcHeadSize + sizeof(STaosDigest); } +static char *doBuildMsgHeader(SSqlObj *pSql, char **pStart); + #ifdef CLUSTER void tscPrintMgmtIp() { if (tscMgmtIpList.numOfIps <= 0) { @@ -71,7 +74,7 @@ static int32_t tscGetMgmtConnMaxRetryTimes() { #ifdef CLUSTER return tscMgmtIpList.numOfIps * factor; #else - return 1*factor; + return 1 * factor; #endif } @@ -89,7 +92,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { if (code == 0) { SHeartBeatRsp *pRsp = (SHeartBeatRsp *)pRes->pRsp; #ifdef CLUSTER - SIpList * pIpList = &pRsp->ipList; + SIpList *pIpList = &pRsp->ipList; tscMgmtIpList.numOfIps = pIpList->numOfIps; if (memcmp(tscMgmtIpList.ip, pIpList->ip, pIpList->numOfIps * 4) != 0) { for (int i = 0; i < pIpList->numOfIps; ++i) { @@ -179,11 +182,11 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { connInit.spi = 1; connInit.encrypt = 0; connInit.secret = pSql->pTscObj->pass; - + #ifdef CLUSTER connInit.peerIp = tscMgmtIpList.ipstr[pSql->index]; #else - connInit.peerIp = tsServerIpStr; + connInit.peerIp = tsServerIpStr; #endif thandle = taosOpenRpcConn(&connInit, pCode); } @@ -199,13 +202,13 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { pSql->vnode = TSC_MGMT_VNODE; #endif } - + // the pSql->res.code is the previous error(status) code. if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) { if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) { *pCode = pSql->res.code; } - + tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode); } } @@ -304,13 +307,13 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) { break; } - + // the pSql->res.code is the previous error(status) code. if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) { if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) { *pCode = pSql->res.code; } - + tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode); } } @@ -352,14 +355,14 @@ int tscSendMsgToServer(SSqlObj *pSql) { * this SQL object may be released by other thread due to the completion of this query even before the log * is dumped to log file. So the signature needs to be kept in a local variable. */ - uint64_t signature = (uint64_t) pSql->signature; + uint64_t signature = (uint64_t)pSql->signature; if (tscUpdateVnodeMsg[pSql->cmd.command]) (*tscUpdateVnodeMsg[pSql->cmd.command])(pSql, buf); - + int ret = taosSendMsgToPeerH(pSql->thandle, pStart, pSql->cmd.payloadLen, pSql); if (ret >= 0) { code = 0; } - + tscTrace("%p send msg ret:%d code:%d sig:%p", pSql, ret, code, signature); } } @@ -421,7 +424,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); if (msg == NULL) { tscTrace("%p no response from ip:0x%x", pSql, pSql->ip); - + #ifdef CLUSTER pSql->index++; #else @@ -459,9 +462,9 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { } } else { uint16_t rspCode = pMsg->content[0]; - + #ifdef CLUSTER - + if (rspCode == TSDB_CODE_REDIRECT) { tscTrace("%p it shall be redirected!", pSql); taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); @@ -469,7 +472,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { if (pCmd->command > TSDB_SQL_MGMT) { tscProcessMgmtRedirect(pSql, pMsg->content + 1); - } else if (pCmd->command == TSDB_SQL_INSERT){ + } else if (pCmd->command == TSDB_SQL_INSERT) { pSql->index++; pSql->maxRetry = TSDB_VNODES_SUPPORT * 2; } else { @@ -480,26 +483,26 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { if (code == 0) return pSql; msg = NULL; } else if (rspCode == TSDB_CODE_NOT_ACTIVE_TABLE || rspCode == TSDB_CODE_INVALID_TABLE_ID || - rspCode == TSDB_CODE_NOT_ACTIVE_VNODE || rspCode == TSDB_CODE_INVALID_VNODE_ID || - rspCode == TSDB_CODE_TABLE_ID_MISMATCH || rspCode == TSDB_CODE_NETWORK_UNAVAIL) { + rspCode == TSDB_CODE_NOT_ACTIVE_VNODE || rspCode == TSDB_CODE_INVALID_VNODE_ID || + rspCode == TSDB_CODE_TABLE_ID_MISMATCH || rspCode == TSDB_CODE_NETWORK_UNAVAIL) { #else - if (rspCode == TSDB_CODE_NOT_ACTIVE_TABLE || rspCode == TSDB_CODE_INVALID_TABLE_ID || + if (rspCode == TSDB_CODE_NOT_ACTIVE_TABLE || rspCode == TSDB_CODE_INVALID_TABLE_ID || rspCode == TSDB_CODE_NOT_ACTIVE_VNODE || rspCode == TSDB_CODE_INVALID_VNODE_ID || rspCode == TSDB_CODE_TABLE_ID_MISMATCH || rspCode == TSDB_CODE_NETWORK_UNAVAIL) { #endif pSql->thandle = NULL; taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); - + if (pCmd->command == TSDB_SQL_CONNECT) { code = TSDB_CODE_NETWORK_UNAVAIL; } else if (pCmd->command == TSDB_SQL_HB) { code = TSDB_CODE_NOT_READY; } else { tscTrace("%p it shall renew meter meta, code:%d", pSql, rspCode); - + pSql->maxRetry = TSDB_VNODES_SUPPORT * 2; - pSql->res.code = (uint8_t) rspCode; // keep the previous error code - + pSql->res.code = (uint8_t)rspCode; // keep the previous error code + code = tscRenewMeterMeta(pSql, pMeterMetaInfo->name); if (code == TSDB_CODE_ACTION_IN_PROGRESS) return pSql; @@ -631,7 +634,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { } static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj); -static int tscLaunchMetricSubQueries(SSqlObj *pSql); +static int tscLaunchMetricSubQueries(SSqlObj *pSql); // todo merge with callback int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySupporter *pSupporter) { @@ -651,7 +654,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu if (pNew == NULL) { return TSDB_CODE_CLI_OUT_OF_MEMORY; } - + pSql->pSubs[pSql->numOfSubs++] = pNew; assert(pSql->numOfSubs <= pSupporter->pState->numOfTotal); @@ -659,19 +662,19 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu addGroupInfoForSubquery(pSql, pNew, tableIndex); // refactor as one method - tscColumnBaseInfoUpdateTableIndex(&pNew->cmd.colList, 0); - tscColumnBaseInfoCopy(&pSupporter->colList, &pNew->cmd.colList, 0); + tscColumnBaseInfoUpdateTableIndex(&pNew->cmd.pQueryInfo[0].colList, 0); + tscColumnBaseInfoCopy(&pSupporter->colList, &pNew->cmd.pQueryInfo[0].colList, 0); - tscSqlExprCopy(&pSupporter->exprsInfo, &pNew->cmd.exprsInfo, pSupporter->uid); + tscSqlExprCopy(&pSupporter->exprsInfo, &pNew->cmd.pQueryInfo[0].exprsInfo, pSupporter->uid); - tscFieldInfoCopyAll(&pNew->cmd.fieldsInfo, &pSupporter->fieldsInfo); - tscTagCondCopy(&pSupporter->tagCond, &pNew->cmd.tagCond); - pSupporter->groupbyExpr = pNew->cmd.groupbyExpr; + tscFieldInfoCopyAll(&pNew->cmd.pQueryInfo[0].fieldsInfo, &pSupporter->fieldsInfo); + tscTagCondCopy(&pSupporter->tagCond, &pNew->cmd.pQueryInfo[0].tagCond); + pSupporter->groupbyExpr = pNew->cmd.pQueryInfo[0].groupbyExpr; pNew->cmd.numOfCols = 0; - pNew->cmd.nAggTimeInterval = 0; - memset(&pNew->cmd.limit, 0, sizeof(SLimitVal)); - memset(&pNew->cmd.groupbyExpr, 0, sizeof(SSqlGroupbyExpr)); + pNew->cmd.pQueryInfo[0].nAggTimeInterval = 0; + memset(&pNew->cmd.pQueryInfo[0].limit, 0, sizeof(SLimitVal)); + memset(&pNew->cmd.pQueryInfo[0].groupbyExpr, 0, sizeof(SSqlGroupbyExpr)); // set the ts,tags that involved in join, as the output column of intermediate result tscFreeSqlCmdData(&pNew->cmd); @@ -694,18 +697,18 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu for (int32_t i = 0; i < pSupporter->colList.numOfCols; ++i) { SColumnBase *pColBase = &pSupporter->colList.pColList[i]; if (pColBase->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered. - tscColumnBaseCopy(&pNew->cmd.colList.pColList[pNew->cmd.colList.numOfCols], pColBase); - pNew->cmd.colList.numOfCols++; + tscColumnBaseCopy(&pNew->cmd.pQueryInfo[0].colList.pColList[pNew->cmd.pQueryInfo[0].colList.numOfCols], pColBase); + pNew->cmd.pQueryInfo[0].colList.numOfCols++; } } } else { pNew->cmd.type |= TSDB_QUERY_TYPE_SUBQUERY; } - + #ifdef _DEBUG_VIEW tscPrintSelectClause(&pNew->cmd); #endif - + return tscProcessSql(pNew); } @@ -713,30 +716,31 @@ int doProcessSql(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - int32_t code = TSDB_CODE_SUCCESS; - void *asyncFp = pSql->fp; - if (tscBuildMsg[pCmd->command](pSql) < 0) { // build msg failed - code = TSDB_CODE_APP_ERROR; - } else { - code = tscSendMsgToServer(pSql); + if (pCmd->command == TSDB_SQL_SELECT || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_RETRIEVE || + pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_CONNECT || pCmd->command == TSDB_SQL_HB || + pCmd->command == TSDB_SQL_META || pCmd->command == TSDB_SQL_METRIC) { + tscBuildMsg[pCmd->command](pSql, NULL); } + + int32_t code = tscSendMsgToServer(pSql); + if (asyncFp) { - if (code != 0) { + if (code != TSDB_CODE_SUCCESS) { pRes->code = code; tscQueueAsyncRes(pSql); } return 0; } - if (code != 0) { + if (code != TSDB_CODE_SUCCESS) { pRes->code = code; return code; } tsem_wait(&pSql->rspSem); - if (pRes->code == 0 && tscProcessMsgRsp[pCmd->command]) (*tscProcessMsgRsp[pCmd->command])(pSql); + if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) (*tscProcessMsgRsp[pCmd->command])(pSql); tsem_post(&pSql->emptyRspSem); @@ -747,12 +751,13 @@ int tscProcessSql(SSqlObj *pSql) { char * name = NULL; SSqlRes * pRes = &pSql->res; SSqlCmd * pCmd = &pSql->cmd; + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); if (pMeterMetaInfo != NULL) { name = pMeterMetaInfo->name; } - + tscTrace("%p SQL cmd:%d will be processed, name:%s, type:%d", pSql, pSql->cmd.command, name, pSql->cmd.type); pSql->retry = 0; if (pSql->cmd.command < TSDB_SQL_MGMT) { @@ -761,18 +766,19 @@ int tscProcessSql(SSqlObj *pSql) { #else pSql->maxRetry = 2; #endif - + // the pMeterMetaInfo cannot be NULL if (pMeterMetaInfo == NULL) { pSql->res.code = TSDB_CODE_OTHERS; return pSql->res.code; } - + if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) { pSql->index = pMeterMetaInfo->pMeterMeta->index; } else { // it must be the parent SSqlObj for super table query if ((pSql->cmd.type & TSDB_QUERY_TYPE_SUBQUERY) != 0) { - int32_t idx = pMeterMetaInfo->vnodeIndex; + int32_t idx = pMeterMetaInfo->vnodeIndex; + SVnodeSidList *pSidList = tscGetVnodeSidList(pMeterMetaInfo->pMetricMeta, idx); pSql->index = pSidList->index; } @@ -787,14 +793,14 @@ int tscProcessSql(SSqlObj *pSql) { if (QUERY_IS_JOIN_QUERY(pSql->cmd.type)) { if ((pSql->cmd.type & TSDB_QUERY_TYPE_SUBQUERY) == 0) { SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); - pState->numOfTotal = pSql->cmd.numOfTables; + pState->numOfTotal = pSql->cmd.pQueryInfo[0].numOfTables; - for (int32_t i = 0; i < pSql->cmd.numOfTables; ++i) { + for (int32_t i = 0; i < pSql->cmd.pQueryInfo[0].numOfTables; ++i) { SJoinSubquerySupporter *pSupporter = tscCreateJoinSupporter(pSql, pState, i); if (pSupporter == NULL) { // failed to create support struct, abort current query tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i); - pState->numOfCompleted = pSql->cmd.numOfTables - i - 1; + pState->numOfCompleted = pSql->cmd.pQueryInfo[0].numOfTables - i - 1; pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; return pSql->res.code; @@ -965,8 +971,8 @@ int tscLaunchMetricSubQueries(SSqlObj *pSql) { } // todo handle multi-vnode situation - if (pSql->cmd.tsBuf) { - pNew->cmd.tsBuf = tsBufClone(pSql->cmd.tsBuf); + if (pSql->cmd.pQueryInfo[0].tsBuf) { + pNew->cmd.pQueryInfo[0].tsBuf = tsBufClone(pSql->cmd.pQueryInfo[0].tsBuf); } tscTrace("%p sub:%p launch subquery.orderOfSub:%d", pSql, pNew, trs->subqueryIndex); @@ -1039,7 +1045,7 @@ static void tscHandleSubRetrievalError(SRetrieveSupport *trsupport, SSqlObj *pSq if (numOfRows >= 0) { // current query is successful, but other sub query failed, still abort current query. tscTrace("%p sub:%p retrieve numOfRows:%d,orderOfSub:%d", pPObj, pSql, numOfRows, subqueryIndex); tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d", pPObj, pSql, - subqueryIndex, trsupport->pState->code); + subqueryIndex, trsupport->pState->code); } else { if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && trsupport->pState->code == TSDB_CODE_SUCCESS) { /* @@ -1118,7 +1124,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { tOrderDescriptor *pDesc = trsupport->pOrderDescriptor; SSqlObj *pSql = (SSqlObj *)tres; - if (pSql == NULL) { // sql object has been released in error process, return immediately + if (pSql == NULL) { // sql object has been released in error process, return immediately tscTrace("%p subquery has been released, idx:%d, abort", pPObj, idx); return; } @@ -1157,7 +1163,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { return; } int32_t ret = saveToBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pRes->data, - pRes->numOfRows, pCmd->groupbyExpr.orderType); + pRes->numOfRows, pCmd->pQueryInfo[0].groupbyExpr.orderType); if (ret < 0) { // set no disk space error info, and abort retry tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); @@ -1168,8 +1174,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { } else { // all data has been retrieved to client /* data in from current vnode is stored in cache and disk */ - uint32_t numOfRowsFromVnode = - trsupport->pExtMemBuffer[idx]->numOfAllElems + trsupport->localBuffer->numOfElems; + uint32_t numOfRowsFromVnode = trsupport->pExtMemBuffer[idx]->numOfAllElems + trsupport->localBuffer->numOfElems; tscTrace("%p sub:%p all data retrieved from ip:%u,vid:%d, numOfRows:%d, orderOfSub:%d", pPObj, pSql, pSvd->ip, pSvd->vnode, numOfRowsFromVnode, idx); @@ -1192,7 +1197,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { // each result for a vnode is ordered as an independant list, // then used as an input of loser tree for disk-based merge routine int32_t ret = - tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pCmd->groupbyExpr.orderType); + tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pCmd->pQueryInfo[0].groupbyExpr.orderType); if (ret != 0) { /* set no disk space error info, and abort retry */ return tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); @@ -1285,12 +1290,12 @@ static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsu SSqlObj *pNew = createSubqueryObj(pSql, 0, tscRetrieveDataRes, trsupport, prevSqlObj); if (pNew != NULL) { // the sub query of two-stage super table query pNew->cmd.type |= TSDB_QUERY_TYPE_STABLE_SUBQUERY; - assert(pNew->cmd.numOfTables == 1); - - //launch subquery for each vnode, so the subquery index equals to the vnodeIndex. - SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pNew->cmd, 0); + assert(pNew->cmd.pQueryInfo[0].numOfTables == 1); + + // launch subquery for each vnode, so the subquery index equals to the vnodeIndex. + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pNew->cmd, 0); pMeterMetaInfo->vnodeIndex = trsupport->subqueryIndex; - + pSql->pSubs[trsupport->subqueryIndex] = pNew; } @@ -1345,7 +1350,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { trsupport->pState->code = -TSDB_CODE_CLI_OUT_OF_MEMORY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; } else { - assert(pNew->cmd.pMeterInfo[0]->pMeterMeta != NULL && pNew->cmd.pMeterInfo[0]->pMetricMeta != NULL); + assert(pNew->cmd.pQueryInfo[0].pMeterInfo[0]->pMeterMeta != NULL && pNew->cmd.pQueryInfo[0].pMeterInfo[0]->pMetricMeta != NULL); tscProcessSql(pNew); return; } @@ -1372,7 +1377,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { } } -int tscBuildRetrieveMsg(SSqlObj *pSql) { +int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) { char *pMsg, *pStart; int msgLen = 0; @@ -1382,7 +1387,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql) { *((uint64_t *)pMsg) = pSql->res.qhandle; pMsg += sizeof(pSql->res.qhandle); - *((uint16_t*)pMsg) = htons(pSql->cmd.type); + *((uint16_t *)pMsg) = htons(pSql->cmd.type); pMsg += sizeof(pSql->cmd.type); msgLen = pMsg - pStart; @@ -1403,10 +1408,11 @@ void tscUpdateVnodeInSubmitMsg(SSqlObj *pSql, char *buf) { pShellMsg = (SShellSubmitMsg *)pMsg; pShellMsg->vnode = htons(pMeterMeta->vpeerDesc[pSql->index].vnode); - tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pSql->index].ip), htons(pShellMsg->vnode)); + tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pSql->index].ip), + htons(pShellMsg->vnode)); } -int tscBuildSubmitMsg(SSqlObj *pSql) { +int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SShellSubmitMsg *pShellMsg; char * pMsg, *pStart; int msgLen = 0; @@ -1424,7 +1430,8 @@ int tscBuildSubmitMsg(SSqlObj *pSql) { // pSql->cmd.payloadLen is set during parse sql routine, so we do not use it here pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; - tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pMeterMeta->index].ip), htons(pShellMsg->vnode)); + tscTrace("%p update submit msg vnode:%s:%d", pSql, taosIpStr(pMeterMeta->vpeerDesc[pMeterMeta->index].ip), + htons(pShellMsg->vnode)); return msgLen; } @@ -1452,9 +1459,10 @@ void tscUpdateVnodeInQueryMsg(SSqlObj *pSql, char *buf) { */ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) { const static int32_t MIN_QUERY_MSG_PKT_SIZE = TSDB_MAX_BYTES_PER_ROW * 5; - int32_t srcColListSize = pCmd->numOfCols * sizeof(SColumnInfo); - int32_t exprSize = sizeof(SSqlFuncExprMsg) * pCmd->fieldsInfo.numOfOutputCols; + int32_t srcColListSize = pCmd->pQueryInfo[0].colList.numOfCols * sizeof(SColumnInfo); + + int32_t exprSize = sizeof(SSqlFuncExprMsg) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); // meter query without tags values @@ -1467,19 +1475,19 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) { SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex); int32_t meterInfoSize = (pMetricMeta->tagLen + sizeof(SMeterSidExtInfo)) * pVnodeSidList->numOfSids; - int32_t outputColumnSize = pCmd->fieldsInfo.numOfOutputCols * sizeof(SSqlFuncExprMsg); + int32_t outputColumnSize = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols * sizeof(SSqlFuncExprMsg); int32_t size = meterInfoSize + outputColumnSize + srcColListSize + exprSize + MIN_QUERY_MSG_PKT_SIZE; - if (pCmd->tsBuf != NULL) { - size += pCmd->tsBuf->fileSize; + if (pCmd->pQueryInfo[0].tsBuf != NULL) { + size += pCmd->pQueryInfo[0].tsBuf->fileSize; } return size; } -static char* doSerializeTableInfo(SSqlObj* pSql, int32_t numOfMeters, int32_t vnodeId, char* pMsg) { +static char *doSerializeTableInfo(SSqlObj *pSql, int32_t numOfMeters, int32_t vnodeId, char *pMsg) { SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); - + SMeterMeta * pMeterMeta = pMeterMetaInfo->pMeterMeta; SMetricMeta *pMetricMeta = pMeterMetaInfo->pMetricMeta; @@ -1491,20 +1499,20 @@ static char* doSerializeTableInfo(SSqlObj* pSql, int32_t numOfMeters, int32_t vn SMeterSidExtInfo *pMeterInfo = (SMeterSidExtInfo *)pMsg; pMeterInfo->sid = htonl(pMeterMeta->sid); pMeterInfo->uid = htobe64(pMeterMeta->uid); - + pMsg += sizeof(SMeterSidExtInfo); } else { SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex); - + for (int32_t i = 0; i < numOfMeters; ++i) { SMeterSidExtInfo *pMeterInfo = (SMeterSidExtInfo *)pMsg; SMeterSidExtInfo *pQueryMeterInfo = tscGetMeterSidInfo(pVnodeSidList, i); - + pMeterInfo->sid = htonl(pQueryMeterInfo->sid); pMeterInfo->uid = htobe64(pQueryMeterInfo->uid); - + pMsg += sizeof(SMeterSidExtInfo); - + memcpy(pMsg, pQueryMeterInfo->tags, pMetricMeta->tagLen); pMsg += pMetricMeta->tagLen; @@ -1513,11 +1521,11 @@ static char* doSerializeTableInfo(SSqlObj* pSql, int32_t numOfMeters, int32_t vn #endif } } - + return pMsg; } -int tscBuildQueryMsg(SSqlObj *pSql) { +int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; int32_t size = tscEstimateQueryMsgSize(pCmd); @@ -1570,25 +1578,25 @@ int tscBuildQueryMsg(SSqlObj *pSql) { pQueryMsg->numOfTagsCols = htons(pMeterMetaInfo->numOfTags); if (pCmd->order.order == TSQL_SO_ASC) { - pQueryMsg->skey = htobe64(pCmd->stime); - pQueryMsg->ekey = htobe64(pCmd->etime); + pQueryMsg->skey = htobe64(pCmd->pQueryInfo[0].stime); + pQueryMsg->ekey = htobe64(pCmd->pQueryInfo[0].etime); } else { - pQueryMsg->skey = htobe64(pCmd->etime); - pQueryMsg->ekey = htobe64(pCmd->stime); + pQueryMsg->skey = htobe64(pCmd->pQueryInfo[0].etime); + pQueryMsg->ekey = htobe64(pCmd->pQueryInfo[0].stime); } pQueryMsg->num = htonl(0); pQueryMsg->order = htons(pCmd->order.order); pQueryMsg->orderColId = htons(pCmd->order.orderColId); - pQueryMsg->interpoType = htons(pCmd->interpoType); + pQueryMsg->interpoType = htons(pCmd->pQueryInfo[0].interpoType); - pQueryMsg->limit = htobe64(pCmd->limit.limit); - pQueryMsg->offset = htobe64(pCmd->limit.offset); + pQueryMsg->limit = htobe64(pCmd->pQueryInfo->limit.limit); + pQueryMsg->offset = htobe64(pCmd->pQueryInfo->limit.offset); - pQueryMsg->numOfCols = htons(pCmd->colList.numOfCols); + pQueryMsg->numOfCols = htons(pCmd->pQueryInfo[0].colList.numOfCols); - if (pCmd->colList.numOfCols <= 0) { + if (pCmd->pQueryInfo[0].colList.numOfCols <= 0) { tscError("%p illegal value of numOfCols in query msg: %d", pSql, pMeterMeta->numOfColumns); return -1; } @@ -1598,19 +1606,19 @@ int tscBuildQueryMsg(SSqlObj *pSql) { return -1; } - pQueryMsg->nAggTimeInterval = htobe64(pCmd->nAggTimeInterval); - pQueryMsg->intervalTimeUnit = pCmd->intervalTimeUnit; - if (pCmd->nAggTimeInterval < 0) { - tscError("%p illegal value of aggregation time interval in query msg: %ld", pSql, pCmd->nAggTimeInterval); + pQueryMsg->nAggTimeInterval = htobe64(pCmd->pQueryInfo[0].nAggTimeInterval); + pQueryMsg->intervalTimeUnit = pCmd->pQueryInfo[0].intervalTimeUnit; + if (pCmd->pQueryInfo[0].nAggTimeInterval < 0) { + tscError("%p illegal value of aggregation time interval in query msg: %ld", pSql, pCmd->pQueryInfo[0].nAggTimeInterval); return -1; } - if (pCmd->groupbyExpr.numOfGroupCols < 0) { - tscError("%p illegal value of numOfGroupCols in query msg: %d", pSql, pCmd->groupbyExpr.numOfGroupCols); + if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols < 0) { + tscError("%p illegal value of numOfGroupCols in query msg: %d", pSql, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols); return -1; } - pQueryMsg->numOfGroupCols = htons(pCmd->groupbyExpr.numOfGroupCols); + pQueryMsg->numOfGroupCols = htons(pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols); if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) { // query on meter pQueryMsg->tagLength = 0; @@ -1619,19 +1627,19 @@ int tscBuildQueryMsg(SSqlObj *pSql) { } pQueryMsg->queryType = htons(pCmd->type); - pQueryMsg->numOfOutputCols = htons(pCmd->exprsInfo.numOfExprs); + pQueryMsg->numOfOutputCols = htons(pCmd->pQueryInfo[0].exprsInfo.numOfExprs); - if (pCmd->fieldsInfo.numOfOutputCols < 0) { - tscError("%p illegal value of number of output columns in query msg: %d", pSql, pCmd->fieldsInfo.numOfOutputCols); + if (pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols < 0) { + tscError("%p illegal value of number of output columns in query msg: %d", pSql, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols); return -1; } // set column list ids - char * pMsg = (char *)(pQueryMsg->colList) + pCmd->colList.numOfCols * sizeof(SColumnInfo); + char * pMsg = (char *)(pQueryMsg->colList) + pCmd->pQueryInfo[0].colList.numOfCols * sizeof(SColumnInfo); SSchema *pSchema = tsGetSchema(pMeterMeta); - for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { - SColumnBase *pCol = tscColumnBaseInfoGet(&pCmd->colList, i); + for (int32_t i = 0; i < pCmd->pQueryInfo[0].colList.numOfCols; ++i) { + SColumnBase *pCol = tscColumnBaseInfoGet(&pCmd->pQueryInfo[0].colList, i); SSchema * pColSchema = &pSchema[pCol->colIndex.columnIndex]; if (pCol->colIndex.columnIndex >= pMeterMeta->numOfColumns || pColSchema->type < TSDB_DATA_TYPE_BOOL || @@ -1680,7 +1688,7 @@ int tscBuildQueryMsg(SSqlObj *pSql) { SSqlFuncExprMsg *pSqlFuncExpr = (SSqlFuncExprMsg *)pMsg; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_ARITHM) { @@ -1720,8 +1728,8 @@ int tscBuildQueryMsg(SSqlObj *pSql) { int32_t len = 0; if (hasArithmeticFunction) { - SColumnBase *pColBase = pCmd->colList.pColList; - for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { + SColumnBase *pColBase = pCmd->pQueryInfo[0].colList.pColList; + for (int32_t i = 0; i < pCmd->pQueryInfo[0].colList.numOfCols; ++i) { char * name = pSchema[pColBase[i].colIndex.columnIndex].name; int32_t lenx = strlen(name); memcpy(pMsg, name, lenx); @@ -1755,7 +1763,7 @@ int tscBuildQueryMsg(SSqlObj *pSql) { } } - SSqlGroupbyExpr *pGroupbyExpr = &pCmd->groupbyExpr; + SSqlGroupbyExpr *pGroupbyExpr = &pCmd->pQueryInfo[0].groupbyExpr; if (pGroupbyExpr->numOfGroupCols != 0) { pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex); pQueryMsg->orderType = htons(pGroupbyExpr->orderType); @@ -1777,10 +1785,10 @@ int tscBuildQueryMsg(SSqlObj *pSql) { } } - if (pCmd->interpoType != TSDB_INTERPO_NONE) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { - *((int64_t *)pMsg) = htobe64(pCmd->defaultVal[i]); - pMsg += sizeof(pCmd->defaultVal[0]); + if (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { + *((int64_t *)pMsg) = htobe64(pCmd->pQueryInfo[0].defaultVal[i]); + pMsg += sizeof(pCmd->pQueryInfo[0].defaultVal[0]); } } @@ -1789,13 +1797,13 @@ int tscBuildQueryMsg(SSqlObj *pSql) { int32_t tsLen = 0; int32_t numOfBlocks = 0; - if (pCmd->tsBuf != NULL) { - STSVnodeBlockInfo *pBlockInfo = tsBufGetVnodeBlockInfo(pCmd->tsBuf, pMeterMetaInfo->vnodeIndex); + if (pCmd->pQueryInfo[0].tsBuf != NULL) { + STSVnodeBlockInfo *pBlockInfo = tsBufGetVnodeBlockInfo(pCmd->pQueryInfo[0].tsBuf, pMeterMetaInfo->vnodeIndex); assert(QUERY_IS_JOIN_QUERY(pCmd->type) && pBlockInfo != NULL); // this query should not be sent // todo refactor - fseek(pCmd->tsBuf->f, pBlockInfo->offset, SEEK_SET); - fread(pMsg, pBlockInfo->compLen, 1, pCmd->tsBuf->f); + fseek(pCmd->pQueryInfo[0].tsBuf->f, pBlockInfo->offset, SEEK_SET); + fread(pMsg, pBlockInfo->compLen, 1, pCmd->pQueryInfo[0].tsBuf->f); pMsg += pBlockInfo->compLen; tsLen = pBlockInfo->compLen; @@ -1804,8 +1812,8 @@ int tscBuildQueryMsg(SSqlObj *pSql) { pQueryMsg->tsLen = htonl(tsLen); pQueryMsg->tsNumOfBlocks = htonl(numOfBlocks); - if (pCmd->tsBuf != NULL) { - pQueryMsg->tsOrder = htonl(pCmd->tsBuf->tsOrder); + if (pCmd->pQueryInfo[0].tsBuf != NULL) { + pQueryMsg->tsOrder = htonl(pCmd->pQueryInfo[0].tsBuf->tsOrder); } msgLen = pMsg - pStart; @@ -1815,346 +1823,266 @@ int tscBuildQueryMsg(SSqlObj *pSql) { pSql->cmd.msgType = TSDB_MSG_TYPE_QUERY; assert(msgLen + minMsgSize() <= size); - return msgLen; + + return TSDB_CODE_SUCCESS; } -int tscBuildCreateDbMsg(SSqlObj *pSql) { +int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCreateDbMsg *pCreateDbMsg; char * pMsg, *pStart; - int msgLen = 0; - - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - pStart = pCmd->payload + tsRpcHeadSize; - pMsg = pStart; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + SSqlCmd *pCmd = &pSql->cmd; + pMsg = doBuildMsgHeader(pSql, &pStart); pCreateDbMsg = (SCreateDbMsg *)pMsg; + + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db)); pMsg += sizeof(SCreateDbMsg); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; + pCmd->payloadLen = pMsg - pStart; pCmd->msgType = TSDB_MSG_TYPE_CREATE_DB; - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildCreateDnodeMsg(SSqlObj *pSql) { +int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCreateDnodeMsg *pCreate; - char * pMsg, *pStart; - int msgLen = 0; - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + char *pMsg, *pStart; - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; + SSqlCmd *pCmd = &pSql->cmd; - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + pMsg = doBuildMsgHeader(pSql, &pStart); pCreate = (SCreateDnodeMsg *)pMsg; - strcpy(pCreate->ip, pMeterMetaInfo->name); + strncpy(pCreate->ip, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); pMsg += sizeof(SCreateDnodeMsg); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CREATE_PNODE; + pCmd->payloadLen = pMsg - pStart; + pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE; - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildDropDnodeMsg(SSqlObj *pSql) { - SDropDnodeMsg *pDrop; - char * pMsg, *pStart; - int msgLen = 0; - - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); - - pDrop = (SDropDnodeMsg *)pMsg; - strcpy(pDrop->ip, pMeterMetaInfo->name); +int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SCreateAcctMsg *pAlterMsg; + char * pMsg, *pStart; + int msgLen = 0; - pMsg += sizeof(SDropDnodeMsg); + SSqlCmd *pCmd = &pSql->cmd; - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_DROP_PNODE; + pMsg = doBuildMsgHeader(pSql, &pStart); - return msgLen; -} + pAlterMsg = (SCreateAcctMsg *)pMsg; -int tscBuildCreateUserMsg(SSqlObj *pSql) { - SCreateUserMsg *pCreateMsg; - char * pMsg, *pStart; - int msgLen = 0; + SSQLToken *pName = &pInfo->pDCLInfo->user.user; + SSQLToken *pPwd = &pInfo->pDCLInfo->user.passwd; - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + strncpy(pAlterMsg->user, pName->z, pName->n); + strncpy(pAlterMsg->pass, pPwd->z, pPwd->n); - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; + pMsg += sizeof(SCreateAcctMsg); - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + SCreateAcctSQL *pAcctOpt = &pInfo->pDCLInfo->acctOpt; - pCreateMsg = (SCreateUserMsg *)pMsg; - strcpy(pCreateMsg->user, pMeterMetaInfo->name); - strcpy(pCreateMsg->pass, pCmd->payload); + pAlterMsg->cfg.maxUsers = htonl(pAcctOpt->maxUsers); + pAlterMsg->cfg.maxDbs = htonl(pAcctOpt->maxDbs); + pAlterMsg->cfg.maxTimeSeries = htonl(pAcctOpt->maxTimeSeries); + pAlterMsg->cfg.maxStreams = htonl(pAcctOpt->maxStreams); + pAlterMsg->cfg.maxPointsPerSecond = htonl(pAcctOpt->maxPointsPerSecond); + pAlterMsg->cfg.maxStorage = htobe64(pAcctOpt->maxStorage); + pAlterMsg->cfg.maxQueryTime = htobe64(pAcctOpt->maxQueryTime); + pAlterMsg->cfg.maxConnections = htonl(pAcctOpt->maxConnections); - pMsg += sizeof(SCreateUserMsg); + if (pAcctOpt->stat.n == 0) { + pAlterMsg->cfg.accessState = -1; + } else { + if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) { + pAlterMsg->cfg.accessState = TSDB_VN_READ_ACCCESS; + } else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) { + pAlterMsg->cfg.accessState = TSDB_VN_WRITE_ACCCESS; + } else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) { + pAlterMsg->cfg.accessState = TSDB_VN_ALL_ACCCESS; + } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { + pAlterMsg->cfg.accessState = 0; + } + } msgLen = pMsg - pStart; pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CREATE_USER; - return msgLen; + pCmd->msgType = TSDB_MSG_TYPE_CREATE_ACCT; + return TSDB_CODE_SUCCESS; } -static int tscBuildAcctMsgImpl(SSqlObj *pSql) { - SCreateAcctMsg *pAlterMsg; - char * pMsg, *pStart; - int msgLen = 0; +int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SAlterUserMsg *pAlterMsg; + char * pMsg, *pStart; - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + SSqlCmd *pCmd = &pSql->cmd; - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; + pMsg = doBuildMsgHeader(pSql, &pStart); + pAlterMsg = (SCreateUserMsg *)pMsg; - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + SUserInfo *pUser = &pInfo->pDCLInfo->user; + strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n); + pAlterMsg->flag = pUser->type; - pAlterMsg = (SCreateAcctMsg *)pMsg; - strcpy(pAlterMsg->user, pMeterMetaInfo->name); - strcpy(pAlterMsg->pass, pCmd->payload); + if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { + pAlterMsg->privilege = (char)pCmd->count; + } else if (pUser->type == TSDB_ALTER_USER_PASSWD) { + strncpy(pAlterMsg->pass, pUser->passwd.z, pUser->passwd.n); + } - pMsg += sizeof(SCreateAcctMsg); + pMsg += sizeof(SAlterUserMsg); - pAlterMsg->cfg.maxUsers = htonl((int32_t)pCmd->defaultVal[0]); - pAlterMsg->cfg.maxDbs = htonl((int32_t)pCmd->defaultVal[1]); - pAlterMsg->cfg.maxTimeSeries = htonl((int32_t)pCmd->defaultVal[2]); - pAlterMsg->cfg.maxStreams = htonl((int32_t)pCmd->defaultVal[3]); - pAlterMsg->cfg.maxPointsPerSecond = htonl((int32_t)pCmd->defaultVal[4]); - pAlterMsg->cfg.maxStorage = htobe64(pCmd->defaultVal[5]); - pAlterMsg->cfg.maxQueryTime = htobe64(pCmd->defaultVal[6]); - pAlterMsg->cfg.maxConnections = htonl((int32_t)pCmd->defaultVal[7]); - pAlterMsg->cfg.accessState = (int8_t)pCmd->defaultVal[8]; + pCmd->payloadLen = pMsg - pStart; - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; + if (pUser->type == TSDB_ALTER_USER_PASSWD || pUser->type == TSDB_ALTER_USER_PRIVILEGES) { + pCmd->msgType = TSDB_MSG_TYPE_ALTER_USER; + } else { + pCmd->msgType = TSDB_MSG_TYPE_CREATE_USER; + } - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildCreateAcctMsg(SSqlObj *pSql) { - int msgLen = tscBuildAcctMsgImpl(pSql); - pSql->cmd.msgType = TSDB_MSG_TYPE_CREATE_ACCT; - return msgLen; -} +int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + char * pStart = NULL; + SSqlCmd *pCmd = &pSql->cmd; -int tscBuildAlterAcctMsg(SSqlObj *pSql) { - int msgLen = tscBuildAcctMsgImpl(pSql); - pSql->cmd.msgType = TSDB_MSG_TYPE_ALTER_ACCT; - return msgLen; -} + char *pMsg = doBuildMsgHeader(pSql, &pStart); + pMsg += sizeof(SCfgMsg); -int tscBuildAlterUserMsg(SSqlObj *pSql) { - SAlterUserMsg *pAlterMsg; - char * pMsg, *pStart; - int msgLen = 0; + pCmd->payloadLen = pMsg - pStart; + pCmd->msgType = TSDB_MSG_TYPE_CFG_PNODE; - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + return TSDB_CODE_SUCCESS; +} - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; +char *doBuildMsgHeader(SSqlObj *pSql, char **pStart) { + SSqlCmd *pCmd = &pSql->cmd; + STscObj *pObj = pSql->pTscObj; + + char *pMsg = pCmd->payload + tsRpcHeadSize; + *pStart = pMsg; SMgmtHead *pMgmt = (SMgmtHead *)pMsg; strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); - - pAlterMsg = (SCreateUserMsg *)pMsg; - strcpy(pAlterMsg->user, pMeterMetaInfo->name); - strcpy(pAlterMsg->pass, pCmd->payload); - pAlterMsg->flag = pCmd->order.order; - pAlterMsg->privilege = (char)pCmd->count; - - pMsg += sizeof(SAlterUserMsg); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_ALTER_USER; + pMsg += sizeof(SMgmtHead); - return msgLen; + return pMsg; } -int tscBuildCfgDnodeMsg(SSqlObj *pSql) { - SCfgMsg *pCfg; - char * pMsg, *pStart; - int msgLen = 0; - - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); +int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SDropDbMsg *pDropDbMsg; + char * pMsg, *pStart; - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; + SSqlCmd *pCmd = &pSql->cmd; - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + pMsg = doBuildMsgHeader(pSql, &pStart); + pDropDbMsg = (SDropDbMsg *)pMsg; - pCfg = (SCfgMsg *)pMsg; - strcpy(pCfg->ip, pMeterMetaInfo->name); - strcpy(pCfg->config, pCmd->payload); + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db)); + pDropDbMsg->ignoreNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0; - pMsg += sizeof(SCfgMsg); + pMsg += sizeof(SDropDbMsg); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CFG_PNODE; + pCmd->payloadLen = pMsg - pStart; + pCmd->msgType = TSDB_MSG_TYPE_DROP_DB; - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildDropDbMsg(SSqlObj *pSql) { - SDropDbMsg *pDropDbMsg; - char * pMsg, *pStart; - int msgLen = 0; - - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; +int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SDropTableMsg *pDropTableMsg; + char * pMsg, *pStart; + int msgLen = 0; - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + SSqlCmd *pCmd = &pSql->cmd; - pDropDbMsg = (SDropDbMsg *)pMsg; - strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db)); + pMsg = doBuildMsgHeader(pSql, &pStart); + pDropTableMsg = (SDropTableMsg *)pMsg; - pDropDbMsg->ignoreNotExists = htons(pCmd->existsCheck ? 1 : 0); + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); + strcpy(pDropTableMsg->meterId, pMeterMetaInfo->name); - pMsg += sizeof(SDropDbMsg); + pDropTableMsg->igNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0; + pMsg += sizeof(SDropTableMsg); msgLen = pMsg - pStart; pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_DROP_DB; + pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE; - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildDropUserMsg(SSqlObj *pSql) { - SDropUserMsg *pDropMsg; - char * pMsg, *pStart; - int msgLen = 0; +int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SDropDnodeMsg *pDrop; + char * pMsg, *pStart; SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + pMsg = doBuildMsgHeader(pSql, &pStart); + pDrop = (SDropDnodeMsg *)pMsg; - pDropMsg = (SDropUserMsg *)pMsg; - strcpy(pDropMsg->user, pMeterMetaInfo->name); + strcpy(pDrop->ip, pMeterMetaInfo->name); - pMsg += sizeof(SDropUserMsg); + pMsg += sizeof(SDropDnodeMsg); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_DROP_USER; + pCmd->payloadLen = pMsg - pStart; + pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE; - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildDropAcctMsg(SSqlObj *pSql) { - SDropAcctMsg *pDropMsg; +int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SDropUserMsg *pDropMsg; char * pMsg, *pStart; int msgLen = 0; - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; + SSqlCmd *pCmd = &pSql->cmd; - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + pMsg = doBuildMsgHeader(pSql, &pStart); + pDropMsg = (SDropUserMsg *)pMsg; - pDropMsg = (SDropAcctMsg *)pMsg; + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); strcpy(pDropMsg->user, pMeterMetaInfo->name); - pMsg += sizeof(SDropAcctMsg); + pMsg += sizeof(SDropUserMsg); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_DROP_ACCT; + pCmd->payloadLen = pMsg - pStart; + pCmd->msgType = TSDB_MSG_TYPE_DROP_USER; return msgLen; } -int tscBuildUseDbMsg(SSqlObj *pSql) { +int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SUseDbMsg *pUseDbMsg; char * pMsg, *pStart; - int msgLen = 0; - SSqlCmd * pCmd = &pSql->cmd; - STscObj * pObj = pSql->pTscObj; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + SSqlCmd *pCmd = &pSql->cmd; + pMsg = doBuildMsgHeader(pSql, &pStart); pUseDbMsg = (SUseDbMsg *)pMsg; + + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); strcpy(pUseDbMsg->db, pMeterMetaInfo->name); pMsg += sizeof(SUseDbMsg); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; + pCmd->payloadLen = pMsg - pStart; pCmd->msgType = TSDB_MSG_TYPE_USE_DB; - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildShowMsg(SSqlObj *pSql) { +int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SShowMsg *pShowMsg; char * pMsg, *pStart; int msgLen = 0; @@ -2162,10 +2090,6 @@ int tscBuildShowMsg(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; STscObj *pObj = pSql->pTscObj; - assert(pCmd->payloadLen < TSDB_SQLCMD_SIZE); - char payload[TSDB_SQLCMD_SIZE] = {0}; - memcpy(payload, pCmd->payload, pCmd->payloadLen); - int32_t size = minMsgSize() + sizeof(SMgmtHead) + sizeof(SShowTableMsg) + pCmd->payloadLen + TSDB_EXTRA_PAYLOAD_SIZE; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for show msg", pSql); @@ -2181,7 +2105,7 @@ int tscBuildShowMsg(SSqlObj *pSql) { size_t nameLen = strlen(pMeterMetaInfo->name); if (nameLen > 0) { - strcpy(pMgmt->db, pMeterMetaInfo->name); + strcpy(pMgmt->db, pMeterMetaInfo->name); // prefix is set here } else { strcpy(pMgmt->db, pObj->db); } @@ -2189,152 +2113,107 @@ int tscBuildShowMsg(SSqlObj *pSql) { pMsg += sizeof(SMgmtHead); pShowMsg = (SShowMsg *)pMsg; - pShowMsg->type = pCmd->showType; + SShowInfo *pShowInfo = &pInfo->pDCLInfo->showOpt; - if ((pShowMsg->type == TSDB_MGMT_TABLE_TABLE || pShowMsg->type == TSDB_MGMT_TABLE_METRIC || pShowMsg->type == TSDB_MGMT_TABLE_VNODES ) && pCmd->payloadLen != 0) { - // only show tables support wildcard query - pShowMsg->payloadLen = htons(pCmd->payloadLen); - memcpy(pShowMsg->payload, payload, pCmd->payloadLen); - } + pShowMsg->type = pShowInfo->showType; + + if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { + SSQLToken *pPattern = &pShowInfo->pattern; + if (pPattern->type > 0) { // only show tables support wildcard query + strncpy(pShowMsg->payload, pPattern->z, pPattern->n); + pShowMsg->payloadLen = htons(pPattern->n); + } + pMsg += (sizeof(SShowTableMsg) + pPattern->n); + } else { + SSQLToken *pIpAddr = &pShowInfo->prefix; + assert(pIpAddr->n > 0 && pIpAddr->type > 0); - pMsg += (sizeof(SShowTableMsg) + pCmd->payloadLen); + strncpy(pShowMsg->payload, pIpAddr->z, pIpAddr->n); + pShowMsg->payloadLen = htons(pIpAddr->n); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; + pMsg += (sizeof(SShowTableMsg) + pIpAddr->n); + } + + pCmd->payloadLen = pMsg - pStart; pCmd->msgType = TSDB_MSG_TYPE_SHOW; assert(msgLen + minMsgSize() <= size); - return msgLen; + + return TSDB_CODE_SUCCESS; } -int tscBuildKillQueryMsg(SSqlObj *pSql) { +int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SKillQuery *pKill; char * pMsg, *pStart; - int msgLen = 0; SSqlCmd *pCmd = &pSql->cmd; - STscObj *pObj = pSql->pTscObj; - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); + pMsg = doBuildMsgHeader(pSql, &pStart); pKill = (SKillQuery *)pMsg; - pKill->handle = 0; - strcpy(pKill->queryId, pCmd->payload); - - pMsg += sizeof(SKillQuery); - - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY; - - return msgLen; -} - -int tscBuildKillStreamMsg(SSqlObj *pSql) { - SKillStream *pKill; - char * pMsg, *pStart; - int msgLen = 0; - - SSqlCmd *pCmd = &pSql->cmd; - STscObj *pObj = pSql->pTscObj; - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); - - pKill = (SKillStream *)pMsg; - pKill->handle = 0; - strcpy(pKill->queryId, pCmd->payload); - - pMsg += sizeof(SKillStream); - - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_KILL_STREAM; - - return msgLen; -} - -int tscBuildKillConnectionMsg(SSqlObj *pSql) { - SKillConnection *pKill; - char * pMsg, *pStart; - int msgLen = 0; - SSqlCmd *pCmd = &pSql->cmd; - STscObj *pObj = pSql->pTscObj; - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - strcpy(pMgmt->db, pObj->db); - pMsg += sizeof(SMgmtHead); - - pKill = (SKillStream *)pMsg; pKill->handle = 0; - strcpy(pKill->queryId, pCmd->payload); + strncpy(pKill->queryId, pInfo->pDCLInfo->ip.z, pInfo->pDCLInfo->ip.n); - pMsg += sizeof(SKillStream); + pMsg += sizeof(SKillQuery); - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_KILL_CONNECTION; + pCmd->payloadLen = pMsg - pStart; - return msgLen; + switch (pCmd->command) { + case TSDB_SQL_KILL_QUERY: + pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY; + break; + case TSDB_SQL_KILL_CONNECTION: + pCmd->msgType = TSDB_MSG_TYPE_KILL_CONNECTION; + break; + case TSDB_SQL_KILL_STREAM: + pCmd->msgType = TSDB_MSG_TYPE_KILL_STREAM; + break; + } + return TSDB_CODE_SUCCESS; } -int tscEstimateCreateTableMsgLength(SSqlObj *pSql) { +int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &(pSql->cmd); int32_t size = minMsgSize() + sizeof(SMgmtHead) + sizeof(SCreateTableMsg); - if (pCmd->numOfCols == 0 && pCmd->count == 0) { + SCreateTableSQL* pCreateTableInfo = pInfo->pCreateTableInfo; + if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) { size += sizeof(STagData); } else { size += sizeof(SSchema) * (pCmd->numOfCols + pCmd->count); } - - if (strlen(pCmd->payload) > 0) size += strlen(pCmd->payload) + 1; + + if (pCreateTableInfo->pSelect != NULL) { + size += (pCreateTableInfo->pSelect->selectToken.n + 1); + } return size + TSDB_EXTRA_PAYLOAD_SIZE; } -int tscBuildCreateTableMsg(SSqlObj *pSql) { +int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCreateTableMsg *pCreateTableMsg; char * pMsg, *pStart; int msgLen = 0; SSchema * pSchema; int size = 0; - // tmp variable to - // 1. save tags data in order to avoid too long tag values overlapped by header - // 2. save the selection clause, in create table as .. sql string - char *tmpData = calloc(1, pSql->cmd.allocSize); - - // STagData is in binary format, strncpy is not available - memcpy(tmpData, pSql->cmd.payload, pSql->cmd.allocSize); - SSqlCmd * pCmd = &pSql->cmd; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); // Reallocate the payload size - size = tscEstimateCreateTableMsgLength(pSql); + size = tscEstimateCreateTableMsgLength(pSql, pInfo); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for create table msg", pSql); - free(tmpData); - return -1; + return TSDB_CODE_CLI_OUT_OF_MEMORY; } pMsg = pCmd->payload + tsRpcHeadSize; pStart = pMsg; SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - // use dbinfo from meterid without modifying current db info + + // use dbinfo from table id without modifying current db info tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db); pMsg += sizeof(SMgmtHead); @@ -2342,59 +2221,59 @@ int tscBuildCreateTableMsg(SSqlObj *pSql) { pCreateTableMsg = (SCreateTableMsg *)pMsg; strcpy(pCreateTableMsg->meterId, pMeterMetaInfo->name); - pCreateTableMsg->igExists = pCmd->existsCheck ? 1 : 0; + SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo; + + pCreateTableMsg->igExists = pCreateTable->existCheck ? 1 : 0; + pCreateTableMsg->numOfColumns = htons(pCmd->numOfCols); pCreateTableMsg->numOfTags = htons(pCmd->count); - pMsg = (char *)pCreateTableMsg->schema; pCreateTableMsg->sqlLen = 0; - short sqlLen = (short)(strlen(tmpData) + 1); + pMsg = (char *)pCreateTableMsg->schema; - if (pCmd->numOfCols == 0 && pCmd->count == 0) { - // create by using metric, tags value - memcpy(pMsg, tmpData, sizeof(STagData)); + int8_t type = pInfo->pCreateTableInfo->type; + if (type == TSQL_CREATE_TABLE_FROM_STABLE) { // create by using super table, tags value + memcpy(pMsg, &pInfo->pCreateTableInfo->usingInfo.tagdata, sizeof(STagData)); pMsg += sizeof(STagData); - } else { - // create metric/create normal meter + } else { // create (super) table pSchema = pCreateTableMsg->schema; + for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); pSchema->type = pField->type; strcpy(pSchema->name, pField->name); pSchema->bytes = htons(pField->bytes); + pSchema++; } pMsg = (char *)pSchema; + if (type == TSQL_CREATE_STREAM) { // check if it is a stream sql + SQuerySQL *pQuerySql = pInfo->pCreateTableInfo->pSelect; - // check if it is a stream sql - if (sqlLen > 1) { - memcpy(pMsg, tmpData, sqlLen); - pMsg[sqlLen - 1] = 0; - - pCreateTableMsg->sqlLen = htons(sqlLen); - pMsg += sqlLen; + strncpy(pMsg, pQuerySql->selectToken.z, pQuerySql->selectToken.n + 1); + pCreateTableMsg->sqlLen = htons(pQuerySql->selectToken.n + 1); + pMsg += pQuerySql->selectToken.n + 1; } } - tfree(tmpData); - tscClearFieldInfo(&pCmd->fieldsInfo); + tscClearFieldInfo(&pCmd->pQueryInfo[0].fieldsInfo); msgLen = pMsg - pStart; pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE; assert(msgLen + minMsgSize() <= size); - return msgLen; + return TSDB_CODE_SUCCESS; } int tscEstimateAlterTableMsgLength(SSqlCmd *pCmd) { - return minMsgSize() + sizeof(SMgmtHead) + sizeof(SAlterTableMsg) + sizeof(SSchema) * pCmd->numOfCols + + return minMsgSize() + sizeof(SMgmtHead) + sizeof(SAlterTableMsg) + sizeof(SSchema) * tscNumOfFields(pCmd) + TSDB_EXTRA_PAYLOAD_SIZE; } -int tscBuildAlterTableMsg(SSqlObj *pSql) { +int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SAlterTableMsg *pAlterTableMsg; char * pMsg, *pStart; int msgLen = 0; @@ -2403,10 +2282,6 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) { SSqlCmd * pCmd = &pSql->cmd; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - char buf[TSDB_MAX_TAGS_LEN] = {0}; - int32_t len = (TSDB_MAX_TAGS_LEN < pCmd->allocSize) ? TSDB_MAX_TAGS_LEN : pCmd->allocSize; - memcpy(buf, pCmd->payload, len); - size = tscEstimateAlterTableMsgLength(pCmd); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for alter table msg", pSql); @@ -2420,14 +2295,17 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) { tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db); pMsg += sizeof(SMgmtHead); + SAlterTableSQL* pAlterInfo = pInfo->pAlterInfo; + pAlterTableMsg = (SAlterTableMsg *)pMsg; strcpy(pAlterTableMsg->meterId, pMeterMetaInfo->name); - pAlterTableMsg->type = htons(pCmd->count); - pAlterTableMsg->numOfCols = htons(pCmd->numOfCols); - memcpy(pAlterTableMsg->tagVal, buf, TSDB_MAX_TAGS_LEN); + pAlterTableMsg->type = htons(pAlterInfo->type); + + pAlterTableMsg->numOfCols = htons(tscNumOfFields(pCmd)); + memcpy(pAlterTableMsg->tagVal, pAlterInfo->tagData.data, TSDB_MAX_TAGS_LEN); SSchema *pSchema = pAlterTableMsg->schema; - for (int i = 0; i < pCmd->numOfCols; ++i) { + for (int i = 0; i < tscNumOfFields(pCmd); ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); pSchema->type = pField->type; @@ -2443,10 +2321,11 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) { pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE; assert(msgLen + minMsgSize() <= size); - return msgLen; + + return TSDB_CODE_SUCCESS; } -int tscAlterDbMsg(SSqlObj *pSql) { +int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SAlterDbMsg *pAlterDbMsg; char * pMsg, *pStart; int msgLen = 0; @@ -2471,38 +2350,10 @@ int tscAlterDbMsg(SSqlObj *pSql) { pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_ALTER_DB; - return msgLen; -} - -int tscBuildDropTableMsg(SSqlObj *pSql) { - SDropTableMsg *pDropTableMsg; - char * pMsg, *pStart; - int msgLen = 0; - - SSqlCmd * pCmd = &pSql->cmd; - SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - - pMsg = pCmd->payload + tsRpcHeadSize; - pStart = pMsg; - - SMgmtHead *pMgmt = (SMgmtHead *)pMsg; - tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db); - pMsg += sizeof(SMgmtHead); - - pDropTableMsg = (SDropTableMsg *)pMsg; - strcpy(pDropTableMsg->meterId, pMeterMetaInfo->name); - - pDropTableMsg->igNotExists = pCmd->existsCheck ? 1 : 0; - pMsg += sizeof(SDropTableMsg); - - msgLen = pMsg - pStart; - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE; - - return msgLen; + return TSDB_CODE_SUCCESS; } -int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql) { +int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { char *pMsg, *pStart; int msgLen = 0; @@ -2524,17 +2375,17 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql) { pMsg += sizeof(SMgmtHead); - *((uint64_t *) pMsg) = pSql->res.qhandle; + *((uint64_t *)pMsg) = pSql->res.qhandle; pMsg += sizeof(pSql->res.qhandle); - *((uint16_t*) pMsg) = htons(pCmd->type); + *((uint16_t *)pMsg) = htons(pCmd->type); pMsg += sizeof(pCmd->type); msgLen = pMsg - pStart; pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_RETRIEVE; - return msgLen; + return TSDB_CODE_SUCCESS; } static int tscSetResultPointer(SSqlCmd *pCmd, SSqlRes *pRes) { @@ -2542,7 +2393,7 @@ static int tscSetResultPointer(SSqlCmd *pCmd, SSqlRes *pRes) { return pRes->code; } - for (int i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); int16_t offset = tscFieldInfoGetOffset(pCmd, i); @@ -2642,7 +2493,7 @@ int tscProcessRetrieveMetricRsp(SSqlObj *pSql) { int tscProcessEmptyResultRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder(pSql, 0); } -int tscBuildConnectMsg(SSqlObj *pSql) { +int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SConnectMsg *pConnect; char * pMsg, *pStart; int msgLen = 0; @@ -2670,7 +2521,7 @@ int tscBuildConnectMsg(SSqlObj *pSql) { return msgLen; } -int tscBuildMeterMetaMsg(SSqlObj *pSql) { +int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SMeterInfoMsg *pInfoMsg; char * pMsg, *pStart; int msgLen = 0; @@ -2696,10 +2547,10 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql) { pInfoMsg = (SMeterInfoMsg *)pMsg; strcpy(pInfoMsg->meterId, pMeterMetaInfo->name); - pInfoMsg->createFlag = htons((uint16_t)pCmd->defaultVal[0]); + pInfoMsg->createFlag = htons((uint16_t)pCmd->pQueryInfo[0].defaultVal[0]); pMsg += sizeof(SMeterInfoMsg); - if (pCmd->defaultVal[0] != 0) { + if (pCmd->pQueryInfo[0].defaultVal[0] != 0) { memcpy(pInfoMsg->tags, tmpData, sizeof(STagData)); pMsg += sizeof(STagData); } @@ -2719,7 +2570,7 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql) { * | SMgmtHead | SMultiMeterInfoMsg | meterId0 | meterId1 | meterId2 | ...... * no used 4B **/ -int tscBuildMultiMeterMetaMsg(SSqlObj *pSql) { +int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; // copy payload content to temp buff @@ -2759,31 +2610,31 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) { minMsgSize() + sizeof(SMetricMetaMsg) + sizeof(SMgmtHead) + sizeof(int16_t) * TSDB_MAX_TAGS; int32_t n = 0; - for (int32_t i = 0; i < pCmd->tagCond.numOfTagCond; ++i) { - n += strlen(pCmd->tagCond.cond[i].cond); + for (int32_t i = 0; i < pCmd->pQueryInfo[0].tagCond.numOfTagCond; ++i) { + n += strlen(pCmd->pQueryInfo[0].tagCond.cond[i].cond); } int32_t tagLen = n * TSDB_NCHAR_SIZE; - if (pCmd->tagCond.tbnameCond.cond != NULL) { - tagLen += strlen(pCmd->tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE; + if (pCmd->pQueryInfo[0].tagCond.tbnameCond.cond != NULL) { + tagLen += strlen(pCmd->pQueryInfo[0].tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE; } - + int32_t joinCondLen = (TSDB_METER_ID_LEN + sizeof(int16_t)) * 2; - int32_t elemSize = sizeof(SMetricMetaElemMsg) * pCmd->numOfTables; + int32_t elemSize = sizeof(SMetricMetaElemMsg) * pCmd->pQueryInfo->numOfTables; int32_t len = tagLen + joinCondLen + elemSize + defaultSize; return MAX(len, TSDB_DEFAULT_PAYLOAD_SIZE); } -int tscBuildMetricMetaMsg(SSqlObj *pSql) { +int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SMetricMetaMsg *pMetaMsg; char * pMsg, *pStart; int msgLen = 0; int tableIndex = 0; SSqlCmd * pCmd = &pSql->cmd; - STagCond *pTagCond = &pCmd->tagCond; + STagCond *pTagCond = &pCmd->pQueryInfo[0].tagCond; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, tableIndex); @@ -2802,7 +2653,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { pMsg += sizeof(SMgmtHead); pMetaMsg = (SMetricMetaMsg *)pMsg; - pMetaMsg->numOfMeters = htonl(pCmd->numOfTables); + pMetaMsg->numOfMeters = htonl(pCmd->pQueryInfo->numOfTables); pMsg += sizeof(SMetricMetaMsg); @@ -2824,7 +2675,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { *(int16_t *)pMsg = pTagCond->joinInfo.right.tagCol; pMsg += sizeof(int16_t); - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); uint64_t uid = pMeterMetaInfo->pMeterMeta->uid; @@ -2840,7 +2691,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { SCond *pCond = tsGetMetricQueryCondPos(pTagCond, uid); if (pCond != NULL) { condLen = strlen(pCond->cond) + 1; - + bool ret = taosMbsToUcs4(pCond->cond, condLen, pMsg, condLen * TSDB_NCHAR_SIZE); if (!ret) { tscError("%p mbs to ucs4 failed:%s", pSql, tsGetMetricQueryCondPos(pTagCond, uid)); @@ -2860,7 +2711,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { offset = pMsg - (char *)pMetaMsg; pElem->tableCond = htonl(offset); - + uint32_t len = strlen(pTagCond->tbnameCond.cond); pElem->tableCondLen = htonl(len); @@ -2868,7 +2719,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { pMsg += len; } - SSqlGroupbyExpr *pGroupby = &pCmd->groupbyExpr; + SSqlGroupbyExpr *pGroupby = &pCmd->pQueryInfo[0].groupbyExpr; if (pGroupby->tableIndex != i && pGroupby->numOfGroupCols > 0) { pElem->orderType = 0; @@ -2886,15 +2737,15 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { offset = pMsg - (char *)pMetaMsg; pElem->groupbyTagColumnList = htonl(offset); - for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { - SColIndexEx *pCol = &pCmd->groupbyExpr.columnInfo[j]; - SColIndexEx* pDestCol = (SColIndexEx*) pMsg; - + for (int32_t j = 0; j < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++j) { + SColIndexEx *pCol = &pCmd->pQueryInfo[0].groupbyExpr.columnInfo[j]; + SColIndexEx *pDestCol = (SColIndexEx *)pMsg; + pDestCol->colIdxInBuf = 0; pDestCol->colIdx = htons(pCol->colIdx); pDestCol->colId = htons(pDestCol->colId); pDestCol->flag = htons(pDestCol->flag); - + pMsg += sizeof(SColIndexEx); } } @@ -2937,7 +2788,7 @@ int tscEstimateHeartBeatMsgLength(SSqlObj *pSql) { return size + TSDB_EXTRA_PAYLOAD_SIZE; } -int tscBuildHeartBeatMsg(SSqlObj *pSql) { +int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { char *pMsg, *pStart; int msgLen = 0; int size = 0; @@ -3268,10 +3119,10 @@ int tscProcessMetricMetaRsp(SSqlObj *pSql) { for (int32_t j = 0; j < pSidLists->numOfSids; ++j) { pLists->pSidExtInfoList[j] = pBuf - (char *)pLists; memcpy(pBuf, rsp, elemSize); - - ((SMeterSidExtInfo*) pBuf)->uid = htobe64(((SMeterSidExtInfo*) pBuf)->uid); - ((SMeterSidExtInfo*) pBuf)->sid = htonl(((SMeterSidExtInfo*) pBuf)->sid); - + + ((SMeterSidExtInfo *)pBuf)->uid = htobe64(((SMeterSidExtInfo *)pBuf)->uid); + ((SMeterSidExtInfo *)pBuf)->sid = htonl(((SMeterSidExtInfo *)pBuf)->sid); + rsp += elemSize; pBuf += elemSize; } @@ -3344,7 +3195,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { pSchema++; } - key[0] = pCmd->showType + 'a'; + key[0] = pCmd->msgType + 'a'; strcpy(key + 1, "showlist"); taosRemoveDataFromCache(tscCacheHandle, (void *)&(pMeterMetaInfo->pMeterMeta), false); @@ -3352,16 +3203,16 @@ int tscProcessShowRsp(SSqlObj *pSql) { int32_t size = pMeta->numOfColumns * sizeof(SSchema) + sizeof(SMeterMeta); pMeterMetaInfo->pMeterMeta = (SMeterMeta *)taosAddDataIntoCache(tscCacheHandle, key, (char *)pMeta, size, tsMeterMetaKeepTimer); - pCmd->numOfCols = pCmd->fieldsInfo.numOfOutputCols; + pCmd->numOfCols = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; SSchema *pMeterSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); - tscColumnBaseInfoReserve(&pCmd->colList, pMeta->numOfColumns); + tscColumnBaseInfoReserve(&pCmd->pQueryInfo[0].colList, pMeta->numOfColumns); SColumnIndex index = {0}; for (int16_t i = 0; i < pMeta->numOfColumns; ++i) { index.columnIndex = i; tscColumnBaseInfoInsert(pCmd, &index); - tscFieldInfoSetValFromSchema(&pCmd->fieldsInfo, i, &pMeterSchema[i]); + tscFieldInfoSetValFromSchema(&pCmd->pQueryInfo[0].fieldsInfo, i, &pMeterSchema[i]); } tscFieldInfoCalOffset(pCmd); @@ -3369,7 +3220,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { } int tscProcessConnectRsp(SSqlObj *pSql) { - char temp[TSDB_METER_ID_LEN*2]; + char temp[TSDB_METER_ID_LEN * 2]; SConnectRsp *pConnect; STscObj *pObj = pSql->pTscObj; @@ -3377,14 +3228,14 @@ int tscProcessConnectRsp(SSqlObj *pSql) { pConnect = (SConnectRsp *)pRes->pRsp; strcpy(pObj->acctId, pConnect->acctId); // copy acctId from response - int32_t len =sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db); - + int32_t len = sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db); + assert(len <= tListLen(pObj->db)); strncpy(pObj->db, temp, tListLen(pObj->db)); - + #ifdef CLUSTER - SIpList * pIpList; - char *rsp = pRes->pRsp + sizeof(SConnectRsp); + SIpList *pIpList; + char * rsp = pRes->pRsp + sizeof(SConnectRsp); pIpList = (SIpList *)rsp; tscMgmtIpList.numOfIps = pIpList->numOfIps; for (int i = 0; i < pIpList->numOfIps; ++i) { @@ -3456,12 +3307,12 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) { taosRemoveDataFromCache(tscCacheHandle, (void **)&pMeterMeta, true); if (pMeterMetaInfo->pMeterMeta) { - bool isMetric = UTIL_METER_IS_METRIC(pMeterMetaInfo); + bool isSuperTable = UTIL_METER_IS_METRIC(pMeterMetaInfo); taosRemoveDataFromCache(tscCacheHandle, (void **)&(pMeterMetaInfo->pMeterMeta), true); taosRemoveDataFromCache(tscCacheHandle, (void **)&(pMeterMetaInfo->pMetricMeta), true); - if (isMetric) { // if it is a metric, reset whole query cache + if (isSuperTable) { // if it is a super table, reset whole query cache tscTrace("%p reset query cache since table:%s is stable", pSql, pMeterMetaInfo->name); taosClearDataCache(tscCacheHandle); } @@ -3546,10 +3397,14 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { pNew->cmd.payload = NULL; pNew->cmd.allocSize = 0; - pNew->cmd.defaultVal[0] = pSql->cmd.defaultVal[0]; // flag of create table if not exists + pNew->cmd.pQueryInfo = calloc(1, sizeof(SQueryInfo)); + pNew->cmd.numOfQueries = 1; + + pNew->cmd.pQueryInfo[0].defaultVal[0] = pSql->cmd.pQueryInfo[0].defaultVal[0]; // flag of create table if not exists if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { tscError("%p malloc failed for payload to get meter meta", pSql); free(pNew); + return TSDB_CODE_CLI_OUT_OF_MEMORY; } @@ -3589,7 +3444,8 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { } int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { - SSqlCmd * pCmd = &pSql->cmd; + SSqlCmd *pCmd = &pSql->cmd; + SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index); // if the SSqlCmd owns a metermeta, release it first @@ -3609,7 +3465,7 @@ int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { * for async insert operation, release data block buffer before issue new object to get metermeta * because in metermeta callback function, the tscParse function will generate the submit data blocks */ - //if (pSql->fp != NULL && pSql->pStream == NULL) { + // if (pSql->fp != NULL && pSql->pStream == NULL) { // tscFreeSqlCmdData(pCmd); //} @@ -3617,7 +3473,7 @@ int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { } int tscGetMeterMetaEx(SSqlObj *pSql, char *meterId, bool createIfNotExists) { - pSql->cmd.defaultVal[0] = createIfNotExists ? 1 : 0; + pSql->cmd.pQueryInfo[0].defaultVal[0] = createIfNotExists ? 1 : 0; return tscGetMeterMeta(pSql, meterId, 0); } @@ -3686,7 +3542,7 @@ int tscGetMetricMeta(SSqlObj *pSql) { * the vnode query condition is serialized into pCmd->payload, we need to rebuild key for metricmeta info in cache. */ bool reqMetricMeta = false; - for (int32_t i = 0; i < pSql->cmd.numOfTables; ++i) { + for (int32_t i = 0; i < pSql->cmd.pQueryInfo[0].numOfTables; ++i) { char tagstr[TSDB_MAX_TAGS_LEN + 1] = {0}; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); @@ -3714,7 +3570,7 @@ int tscGetMetricMeta(SSqlObj *pSql) { pNew->cmd.command = TSDB_SQL_METRIC; - for (int32_t i = 0; i < pSql->cmd.numOfTables; ++i) { + for (int32_t i = 0; i < pSql->cmd.pQueryInfo[0].numOfTables; ++i) { SMeterMetaInfo *pMMInfo = tscGetMeterMetaInfo(&pSql->cmd, i); SMeterMeta *pMeterMeta = taosGetDataFromCache(tscCacheHandle, pMMInfo->name); @@ -3727,12 +3583,12 @@ int tscGetMetricMeta(SSqlObj *pSql) { } // the query condition on meter is serialized into payload - tscTagCondCopy(&pNew->cmd.tagCond, &pSql->cmd.tagCond); + tscTagCondCopy(&pNew->cmd.pQueryInfo[0].tagCond, &pSql->cmd.pQueryInfo[0].tagCond); - pNew->cmd.groupbyExpr = pSql->cmd.groupbyExpr; - pNew->cmd.numOfTables = pSql->cmd.numOfTables; + pNew->cmd.pQueryInfo[0].groupbyExpr = pSql->cmd.pQueryInfo[0].groupbyExpr; + pNew->cmd.pQueryInfo[0].numOfTables = pSql->cmd.pQueryInfo[0].numOfTables; - pNew->cmd.slimit = pSql->cmd.slimit; + pNew->cmd.pQueryInfo[0].slimit = pSql->cmd.pQueryInfo[0].slimit; pNew->cmd.order = pSql->cmd.order; if (pSql->fp != NULL && pSql->pStream == NULL) { @@ -3746,7 +3602,7 @@ int tscGetMetricMeta(SSqlObj *pSql) { code = tscProcessSql(pNew); - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { char tagstr[TSDB_MAX_TAGS_LEN] = {0}; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); @@ -3779,17 +3635,17 @@ void tscInitMsgs() { tscBuildMsg[TSDB_SQL_FETCH] = tscBuildRetrieveMsg; tscBuildMsg[TSDB_SQL_CREATE_DB] = tscBuildCreateDbMsg; - tscBuildMsg[TSDB_SQL_CREATE_USER] = tscBuildCreateUserMsg; + tscBuildMsg[TSDB_SQL_CREATE_USER] = tscBuildUserMsg; - tscBuildMsg[TSDB_SQL_CREATE_ACCT] = tscBuildCreateAcctMsg; - tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAlterAcctMsg; + tscBuildMsg[TSDB_SQL_CREATE_ACCT] = tscBuildAcctMsg; + tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAcctMsg; tscBuildMsg[TSDB_SQL_CREATE_TABLE] = tscBuildCreateTableMsg; - tscBuildMsg[TSDB_SQL_DROP_USER] = tscBuildDropUserMsg; + tscBuildMsg[TSDB_SQL_DROP_USER] = tscBuildDropAcctMsg; tscBuildMsg[TSDB_SQL_DROP_ACCT] = tscBuildDropAcctMsg; tscBuildMsg[TSDB_SQL_DROP_DB] = tscBuildDropDbMsg; tscBuildMsg[TSDB_SQL_DROP_TABLE] = tscBuildDropTableMsg; - tscBuildMsg[TSDB_SQL_ALTER_USER] = tscBuildAlterUserMsg; + tscBuildMsg[TSDB_SQL_ALTER_USER] = tscBuildUserMsg; tscBuildMsg[TSDB_SQL_CREATE_DNODE] = tscBuildCreateDnodeMsg; tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg; tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg; @@ -3805,9 +3661,9 @@ void tscInitMsgs() { tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg; tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg; tscBuildMsg[TSDB_SQL_RETRIEVE] = tscBuildRetrieveFromMgmtMsg; - tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillQueryMsg; - tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillStreamMsg; - tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillConnectionMsg; + tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg; + tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg; + tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg; tscProcessMsgRsp[TSDB_SQL_SELECT] = tscProcessQueryRsp; tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromVnode; @@ -3821,16 +3677,16 @@ void tscInitMsgs() { tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiMeterMetaRsp; tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; - tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromVnode; // rsp handled by same function. + tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromVnode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; - + tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessTagRetrieveRsp; - + tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_METRIC] = tscProcessRetrieveMetricRsp; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index e4344b4b10b172449e45ba369787899a375f82d1..4cd442996372529d299ed5489fa1d9172bd20e25 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -28,7 +28,7 @@ #include "tsocket.h" #include "ttimer.h" #include "tutil.h" -#include "ihash.h" +#include "hash.h" TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) { @@ -207,7 +207,7 @@ int taos_query_imp(STscObj *pObj, SSqlObj *pSql) { pRes->numOfTotal = 0; pSql->asyncTblPos = NULL; if (NULL != pSql->pTableHashList) { - taosCleanUpIntHash(pSql->pTableHashList); + taosCleanUpHashTable(pSql->pTableHashList); pSql->pTableHashList = NULL; } @@ -298,7 +298,7 @@ int taos_num_fields(TAOS_RES *res) { SSqlObj *pSql = (SSqlObj *)res; if (pSql == NULL || pSql->signature != pSql) return 0; - SFieldInfo *pFieldsInfo = &pSql->cmd.fieldsInfo; + SFieldInfo *pFieldsInfo = &pSql->cmd.pQueryInfo[0].fieldsInfo; return (pFieldsInfo->numOfOutputCols - pFieldsInfo->numOfHiddenCols); } @@ -321,7 +321,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { SSqlObj *pSql = (SSqlObj *)res; if (pSql == NULL || pSql->signature != pSql) return 0; - return pSql->cmd.fieldsInfo.pFields; + return pSql->cmd.pQueryInfo[0].fieldsInfo.pFields; } int taos_retrieve(TAOS_RES *res) { @@ -370,7 +370,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) { pRes->numOfTotal += pRes->numOfRows; } - for (int i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pCmd, i, pCmd->order) + pRes->bytes[i] * (1 - pCmd->order.order) * (pRes->numOfRows - 1); } @@ -386,11 +386,11 @@ static void **doSetResultRowData(SSqlObj *pSql) { int32_t num = 0; - for (int i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pCmd, i, pCmd->order) + pRes->bytes[i] * pRes->row; // primary key column cannot be null in interval query, no need to check - if (i == 0 && pCmd->nAggTimeInterval > 0) { + if (i == 0 && pCmd->pQueryInfo[0].nAggTimeInterval > 0) { continue; } @@ -419,7 +419,7 @@ static void **doSetResultRowData(SSqlObj *pSql) { } } - assert(num <= pCmd->fieldsInfo.numOfOutputCols); + assert(num <= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols); return pRes->tsrow; } @@ -445,7 +445,7 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) { SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd; SMeterMetaInfo *pMetaInfo = tscGetMeterMetaInfo(pCmd1, 0); - assert(pCmd1->numOfTables == 1); + assert(pCmd1->pQueryInfo[0].numOfTables == 1); /* * if the global limitation is not reached, and current result has not exhausted, or next more vnodes are @@ -500,7 +500,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) { } if (pRes->tsrow == NULL) { - pRes->tsrow = malloc(POINTER_BYTES * pCmd->exprsInfo.numOfExprs); + pRes->tsrow = malloc(POINTER_BYTES * pCmd->pQueryInfo[0].exprsInfo.numOfExprs); } bool success = false; @@ -526,7 +526,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) { } if (success) { // current row of final output has been built, return to app - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { int32_t tableIndex = pRes->pColumnIndex[i].tableIndex; int32_t columnIndex = pRes->pColumnIndex[i].columnIndex; @@ -611,8 +611,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { * update the limit and offset value according to current retrieval results * Note: if pRes->offset > 0, pRes->numOfRows = 0, pRes->numOfTotal = 0; */ - pCmd->limit.limit = pCmd->globalLimit - pRes->numOfTotal; - pCmd->limit.offset = pRes->offset; + pCmd->pQueryInfo->limit.limit = pCmd->globalLimit - pRes->numOfTotal; + pCmd->pQueryInfo->limit.offset = pRes->offset; assert((pRes->offset >= 0 && pRes->numOfRows == 0) || (pRes->offset == 0 && pRes->numOfRows >= 0)); @@ -665,8 +665,8 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); /* update the limit value according to current retrieval results */ - pCmd->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal; - pCmd->limit.offset = pRes->offset; + pCmd->pQueryInfo->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal; + pCmd->pQueryInfo->limit.offset = pRes->offset; if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { pSql->cmd.command = TSDB_SQL_SELECT; @@ -956,7 +956,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { pSql->asyncTblPos = NULL; if (NULL != pSql->pTableHashList) { - taosCleanUpIntHash(pSql->pTableHashList); + taosCleanUpHashTable(pSql->pTableHashList); pSql->pTableHashList = NULL; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 31af78f6188477b8a1866cd20dfe35c4c12018cd..95c5e2fbc6a44d13dfdb6f2a25f1684d79c81395 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -32,7 +32,7 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql); static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer); static bool isProjectStream(SSqlCmd *pCmd) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { SSqlExpr *pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId != TSDB_FUNC_PRJ) { return false; @@ -109,18 +109,18 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) { if (isProjectStream(&pSql->cmd)) { /* - * pSql->cmd.etime, which is the start time, does not change in case of + * pSql->cmd.pQueryInfo[0].etime, which is the start time, does not change in case of * repeat first execution, once the first execution failed. */ - pSql->cmd.stime = pStream->stime; // start time + pSql->cmd.pQueryInfo[0].stime = pStream->stime; // start time - pSql->cmd.etime = taosGetTimestamp(pStream->precision); // end time - if (pSql->cmd.etime > pStream->etime) { - pSql->cmd.etime = pStream->etime; + pSql->cmd.pQueryInfo[0].etime = taosGetTimestamp(pStream->precision); // end time + if (pSql->cmd.pQueryInfo[0].etime > pStream->etime) { + pSql->cmd.pQueryInfo[0].etime = pStream->etime; } } else { - pSql->cmd.stime = pStream->stime - pStream->interval; - pSql->cmd.etime = pStream->stime - 1; + pSql->cmd.pQueryInfo[0].stime = pStream->stime - pStream->interval; + pSql->cmd.pQueryInfo[0].etime = pStream->stime - 1; } // launch stream computing in a new thread @@ -198,7 +198,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf pStream->useconds += pSql->res.useconds; if (pStream->numOfRes == 0) { - if (pSql->cmd.interpoType == TSDB_INTERPO_SET_VALUE || pSql->cmd.interpoType == TSDB_INTERPO_NULL) { + if (pSql->cmd.pQueryInfo[0].interpoType == TSDB_INTERPO_SET_VALUE || pSql->cmd.pQueryInfo[0].interpoType == TSDB_INTERPO_NULL) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; @@ -210,11 +210,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf void *oldPtr = pSql->res.data; pSql->res.data = tmpRes; - for (int32_t i = 1; i < pSql->cmd.fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 1; i < pSql->cmd.pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int16_t offset = tscFieldInfoGetOffset(pCmd, i); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); - assignVal(pSql->res.data + offset, (char *)(&pCmd->defaultVal[i]), pField->bytes, pField->type); + assignVal(pSql->res.data + offset, (char *)(&pCmd->pQueryInfo[0].defaultVal[i]), pField->bytes, pField->type); row[i] = pSql->res.data + offset; } @@ -222,7 +222,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf row[0] = pRes->data; // char result[512] = {0}; - // taos_print_row(result, row, pSql->cmd.fieldsInfo.pFields, pSql->cmd.fieldsInfo.numOfOutputCols); + // taos_print_row(result, row, pSql->cmd.pQueryInfo[0].fieldsInfo.pFields, pSql->cmd.pQueryInfo[0].fieldsInfo.numOfOutputCols); // tscPrint("%p stream:%p query result: %s", pSql, pStream, result); tscTrace("%p stream:%p fetch result", pSql, pStream); @@ -352,36 +352,36 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) { int64_t minIntervalTime = (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinIntervalTime * 1000L : tsMinIntervalTime; - if (pCmd->nAggTimeInterval < minIntervalTime) { + if (pCmd->pQueryInfo[0].nAggTimeInterval < minIntervalTime) { tscWarn("%p stream:%p, original sample interval:%ld too small, reset to:%" PRId64 "", pSql, pStream, - pCmd->nAggTimeInterval, minIntervalTime); - pCmd->nAggTimeInterval = minIntervalTime; + pCmd->pQueryInfo[0].nAggTimeInterval, minIntervalTime); + pCmd->pQueryInfo[0].nAggTimeInterval = minIntervalTime; } - pStream->interval = pCmd->nAggTimeInterval; // it shall be derived from sql string + pStream->interval = pCmd->pQueryInfo[0].nAggTimeInterval; // it shall be derived from sql string - if (pCmd->nSlidingTime == 0) { - pCmd->nSlidingTime = pCmd->nAggTimeInterval; + if (pCmd->pQueryInfo[0].nSlidingTime == 0) { + pCmd->pQueryInfo[0].nSlidingTime = pCmd->pQueryInfo[0].nAggTimeInterval; } int64_t minSlidingTime = (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinSlidingTime * 1000L : tsMinSlidingTime; - if (pCmd->nSlidingTime < minSlidingTime) { - tscWarn("%p stream:%p, original sliding value:%" PRId64 " too small, reset to:%" PRId64 "", pSql, pStream, pCmd->nSlidingTime, - minSlidingTime); + if (pCmd->pQueryInfo[0].nSlidingTime < minSlidingTime) { + tscWarn("%p stream:%p, original sliding value:%" PRId64 " too small, reset to:%" PRId64 "", pSql, pStream, + pCmd->pQueryInfo[0].nSlidingTime, minSlidingTime); - pCmd->nSlidingTime = minSlidingTime; + pCmd->pQueryInfo[0].nSlidingTime = minSlidingTime; } - if (pCmd->nSlidingTime > pCmd->nAggTimeInterval) { + if (pCmd->pQueryInfo[0].nSlidingTime > pCmd->pQueryInfo[0].nAggTimeInterval) { tscWarn("%p stream:%p, sliding value:%" PRId64 " can not be larger than interval range, reset to:%" PRId64 "", pSql, pStream, - pCmd->nSlidingTime, pCmd->nAggTimeInterval); + pCmd->pQueryInfo[0].nSlidingTime, pCmd->pQueryInfo[0].nAggTimeInterval); - pCmd->nSlidingTime = pCmd->nAggTimeInterval; + pCmd->pQueryInfo[0].nSlidingTime = pCmd->pQueryInfo[0].nAggTimeInterval; } - pStream->slidingTime = pCmd->nSlidingTime; + pStream->slidingTime = pCmd->pQueryInfo[0].nSlidingTime; } static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, int64_t stime) { @@ -393,10 +393,10 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in pStream->slidingTime = tsProjectExecInterval; if (stime != 0) { // first projection start from the latest event timestamp - assert(stime >= pCmd->stime); + assert(stime >= pCmd->pQueryInfo[0].stime); stime += 1; // exclude the last records from table } else { - stime = pCmd->stime; + stime = pCmd->pQueryInfo[0].stime; } } else { // timewindow based aggregation stream if (stime == 0) { // no data in meter till now @@ -529,7 +529,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p pStream->precision = pMeterMetaInfo->pMeterMeta->precision; pStream->ctime = taosGetTimestamp(pStream->precision); - pStream->etime = pCmd->etime; + pStream->etime = pCmd->pQueryInfo[0].etime; pSql->pStream = pStream; tscAddIntoStreamList(pStream); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 3362af2343e4eedf1493e59a383dcede46f2040d..400171eaa237e84ed15732c7248555dfbf44c878 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -13,8 +13,9 @@ * along with this program. If not, see . */ +#include "tscUtil.h" +#include "hash.h" #include "os.h" -#include "ihash.h" #include "taosmsg.h" #include "tcache.h" #include "tkey.h" @@ -23,7 +24,6 @@ #include "tscProfile.h" #include "tscSecondaryMerge.h" #include "tschemautil.h" -#include "tscUtil.h" #include "tsclient.h" #include "tsqldef.h" #include "ttimer.h" @@ -47,7 +47,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) { len += sprintf(&tagIdBuf[len], "%d,", pMeterMetaInfo->tagColumnIndex[i]); } - STagCond* pTagCond = &pCmd->tagCond; + STagCond* pTagCond = &pCmd->pQueryInfo[0].tagCond; assert(len < tListLen(tagIdBuf)); const int32_t maxKeySize = TSDB_MAX_TAGS_LEN; // allowed max key size @@ -73,7 +73,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) { int32_t keyLen = snprintf(tmp, bufSize, "%s,%s,%s,%d,%s,[%s],%d", pMeterMetaInfo->name, (cond != NULL ? cond->cond : NULL), (tbnameCondLen > 0 ? pTagCond->tbnameCond.cond : NULL), - pTagCond->relType, join, tagIdBuf, pCmd->groupbyExpr.orderType); + pTagCond->relType, join, tagIdBuf, pCmd->pQueryInfo[0].groupbyExpr.orderType); assert(keyLen <= bufSize); @@ -120,7 +120,7 @@ bool tscQueryOnMetric(SSqlCmd* pCmd) { } bool tscQueryMetricTags(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { if (tscSqlExprGet(pCmd, i)->functionId != TSDB_FUNC_TAGPRJ) { return false; } @@ -133,7 +133,7 @@ bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd) { bool hasTags = false; int32_t numOfSelectivity = 0; - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int32_t functId = tscSqlExprGet(pCmd, i)->functionId; if (functId == TSDB_FUNC_TAG_DUMMY) { hasTags = true; @@ -232,7 +232,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) { * 1. failed to get metermeta from server; 2. not a metric; 3. limit 0; 4. show query, instead of a select query */ if (pMeterMetaInfo == NULL || !UTIL_METER_IS_METRIC(pMeterMetaInfo) || - pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pCmd->exprsInfo.numOfExprs == 0) { + pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pCmd->pQueryInfo[0].exprsInfo.numOfExprs == 0) { return false; } @@ -242,7 +242,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) { } // for project query, only the following two function is allowed - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int32_t functionId = tscSqlExprGet(pCmd, i)->functionId; if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM) { @@ -254,7 +254,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) { } bool tscProjectionQueryOnTable(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) { int32_t functionId = tscSqlExprGet(pCmd, i)->functionId; if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TS) { return false; @@ -265,7 +265,7 @@ bool tscProjectionQueryOnTable(SSqlCmd* pCmd) { } bool tscIsPointInterpQuery(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr == NULL) { return false; @@ -284,7 +284,7 @@ bool tscIsPointInterpQuery(SSqlCmd* pCmd) { } bool tscIsTWAQuery(SSqlCmd* pCmd) { - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr == NULL) { continue; @@ -304,8 +304,8 @@ void tscClearInterpInfo(SSqlCmd* pCmd) { return; } - pCmd->interpoType = TSDB_INTERPO_NONE; - memset(pCmd->defaultVal, 0, sizeof(pCmd->defaultVal)); + pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_NONE; + memset(pCmd->pQueryInfo[0].defaultVal, 0, sizeof(pCmd->pQueryInfo[0].defaultVal)); } void tscClearSqlMetaInfoForce(SSqlCmd* pCmd) { @@ -319,7 +319,7 @@ void tscClearSqlMetaInfoForce(SSqlCmd* pCmd) { int32_t tscCreateResPointerInfo(SSqlCmd* pCmd, SSqlRes* pRes) { if (pRes->tsrow == NULL) { pRes->numOfnchar = 0; - int32_t numOfOutputCols = pCmd->fieldsInfo.numOfOutputCols; + int32_t numOfOutputCols = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; for (int32_t i = 0; i < numOfOutputCols; ++i) { TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, i); @@ -361,18 +361,22 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) { void tscFreeSqlCmdData(SSqlCmd* pCmd) { pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); - tscTagCondRelease(&pCmd->tagCond); - tscClearFieldInfo(&pCmd->fieldsInfo); + if (pCmd->pQueryInfo == NULL) { + return; + } + + tscTagCondRelease(&pCmd->pQueryInfo[0].tagCond); + tscClearFieldInfo(&pCmd->pQueryInfo[0].fieldsInfo); - tfree(pCmd->exprsInfo.pExprs); - memset(&pCmd->exprsInfo, 0, sizeof(pCmd->exprsInfo)); + tfree(pCmd->pQueryInfo[0].exprsInfo.pExprs); + memset(&pCmd->pQueryInfo[0].exprsInfo, 0, sizeof(pCmd->pQueryInfo[0].exprsInfo)); - tscColumnBaseInfoDestroy(&pCmd->colList); - memset(&pCmd->colList, 0, sizeof(pCmd->colList)); + tscColumnBaseInfoDestroy(&pCmd->pQueryInfo[0].colList); + memset(&pCmd->pQueryInfo[0].colList, 0, sizeof(pCmd->pQueryInfo[0].colList)); - if (pCmd->tsBuf != NULL) { - tsBufDestory(pCmd->tsBuf); - pCmd->tsBuf = NULL; + if (pCmd->pQueryInfo[0].tsBuf != NULL) { + tsBufDestory(pCmd->pQueryInfo[0].tsBuf); + pCmd->pQueryInfo[0].tsBuf = NULL; } } @@ -392,7 +396,7 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) { tscRemoveFromSqlList(pSql); } - pCmd->command = -1; + pCmd->command = 0; // pSql->sqlstr will be used by tscBuildQueryStreamDesc pthread_mutex_lock(&pObj->mutex); @@ -434,7 +438,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { pCmd->allocSize = 0; if (pSql->res.buffer != NULL) { - for (int i = 0; i < pCmd->fieldsInfo.numOfOutputCols; i++) { + for (int i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; i++) { if (pSql->res.buffer[i] != NULL) { tfree(pSql->res.buffer[i]); } @@ -614,7 +618,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff */ dataBuf->pMeterMeta = taosGetDataFromCache(tscCacheHandle, dataBuf->meterId); assert(initialSize > 0); - + if (dataBuf->pMeterMeta == NULL) { tfree(dataBuf); return TSDB_CODE_QUERY_CACHE_ERASED; @@ -629,18 +633,18 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, STableDataBlocks** dataBlocks) { *dataBlocks = NULL; - STableDataBlocks** t1 = (STableDataBlocks**) taosGetIntHashData(pHashList, id); + STableDataBlocks** t1 = (STableDataBlocks**)taosGetDataFromHash(pHashList, (const char*)&id, sizeof(id)); if (t1 != NULL) { *dataBlocks = *t1; } if (*dataBlocks == NULL) { - int32_t ret = tscCreateDataBlock((size_t) size, rowSize, startOffset, tableId, dataBlocks); + int32_t ret = tscCreateDataBlock((size_t)size, rowSize, startOffset, tableId, dataBlocks); if (ret != TSDB_CODE_SUCCESS) { return ret; } - *dataBlocks = *(STableDataBlocks**)taosAddIntHash(pHashList, id, (char*)dataBlocks); + taosAddToHashTable(pHashList, (const char*)&id, sizeof(int64_t), (char*)dataBlocks, POINTER_BYTES); tscAppendDataBlock(pDataBlockList, *dataBlocks); } @@ -650,19 +654,19 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockList) { SSqlCmd* pCmd = &pSql->cmd; - void* pVnodeDataBlockHashList = taosInitIntHash(8, POINTER_BYTES, taosHashInt); + void* pVnodeDataBlockHashList = taosInitHashTable(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false); SDataBlockList* pVnodeDataBlockList = tscCreateBlockArrayList(); for (int32_t i = 0; i < pTableDataBlockList->nSize; ++i) { STableDataBlocks* pOneTableBlock = pTableDataBlockList->pData[i]; STableDataBlocks* dataBuf = NULL; - int32_t ret = tscGetDataBlockFromList(pVnodeDataBlockHashList, pVnodeDataBlockList, pOneTableBlock->vgid, - TSDB_PAYLOAD_SIZE, tsInsertHeadSize, 0, pOneTableBlock->meterId, &dataBuf); + int32_t ret = tscGetDataBlockFromList(pVnodeDataBlockHashList, pVnodeDataBlockList, pOneTableBlock->vgid, + TSDB_PAYLOAD_SIZE, tsInsertHeadSize, 0, pOneTableBlock->meterId, &dataBuf); if (ret != TSDB_CODE_SUCCESS) { tscError("%p failed to allocate the data buffer block for merging table data", pSql); tscDestroyBlockArrayList(pTableDataBlockList); - + return ret; } @@ -679,7 +683,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi } else { // failed to allocate memory, free already allocated memory and return error code tscError("%p failed to allocate memory for merging submit block, size:%d", pSql, dataBuf->nAllocSize); - taosCleanUpIntHash(pVnodeDataBlockHashList); + taosCleanUpHashTable(pVnodeDataBlockHashList); tfree(dataBuf->pData); tscDestroyBlockArrayList(pVnodeDataBlockList); @@ -710,7 +714,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi pCmd->pDataBlocks = pVnodeDataBlockList; tscFreeUnusedDataBlocks(pCmd->pDataBlocks); - taosCleanUpIntHash(pVnodeDataBlockHashList); + taosCleanUpHashTable(pVnodeDataBlockHashList); return TSDB_CODE_SUCCESS; } @@ -729,9 +733,14 @@ void tscCloseTscObj(STscObj* pObj) { } bool tscIsInsertOrImportData(char* sqlstr) { - int32_t index = 0; - SSQLToken t0 = tStrGetToken(sqlstr, &index, false, 0, NULL); - return t0.type == TK_INSERT || t0.type == TK_IMPORT; + int32_t index = 0; + + do { + SSQLToken t0 = tStrGetToken(sqlstr, &index, false, 0, NULL); + if (t0.type != TK_LP) { + return t0.type == TK_INSERT || t0.type == TK_IMPORT; + } + } while (1); } int tscAllocPayload(SSqlCmd* pCmd, int size) { @@ -848,7 +857,7 @@ void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, co } void tscFieldInfoCalOffset(SSqlCmd* pCmd) { - SFieldInfo* pFieldInfo = &pCmd->fieldsInfo; + SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo; pFieldInfo->pOffset[0] = 0; for (int32_t i = 1; i < pFieldInfo->numOfOutputCols; ++i) { @@ -857,7 +866,7 @@ void tscFieldInfoCalOffset(SSqlCmd* pCmd) { } void tscFieldInfoUpdateOffset(SSqlCmd* pCmd) { - SFieldInfo* pFieldInfo = &pCmd->fieldsInfo; + SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo; if (pFieldInfo->numOfOutputCols == 0) { return; } @@ -902,23 +911,27 @@ void tscFieldInfoCopyAll(SFieldInfo* src, SFieldInfo* dst) { } TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index) { - if (index >= pCmd->fieldsInfo.numOfOutputCols) { + if (index >= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) { return NULL; } - return &pCmd->fieldsInfo.pFields[index]; + return &pCmd->pQueryInfo[0].fieldsInfo.pFields[index]; +} + +int32_t tscNumOfFields(SSqlCmd* pCmd) { + return pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; } int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index) { - if (index >= pCmd->fieldsInfo.numOfOutputCols) { + if (index >= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) { return 0; } - return pCmd->fieldsInfo.pOffset[index]; + return pCmd->pQueryInfo[0].fieldsInfo.pOffset[index]; } int32_t tscGetResRowLength(SSqlCmd* pCmd) { - SFieldInfo* pFieldInfo = &pCmd->fieldsInfo; + SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo; if (pFieldInfo->numOfOutputCols <= 0) { return 0; } @@ -969,7 +982,7 @@ static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) { } SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId) { - SSqlExprInfo* pExprInfo = &pCmd->exprsInfo; + SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo; _exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1); _exprEvic(pExprInfo, index); @@ -985,7 +998,7 @@ SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SCo int16_t size, int16_t interSize) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pColIndex->tableIndex); - SSqlExprInfo* pExprInfo = &pCmd->exprsInfo; + SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo; _exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1); _exprEvic(pExprInfo, index); @@ -1028,7 +1041,7 @@ SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SCo SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type, int16_t size) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - SSqlExprInfo* pExprInfo = &pCmd->exprsInfo; + SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo; if (index > pExprInfo->numOfExprs) { return NULL; } @@ -1060,11 +1073,11 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, } SSqlExpr* tscSqlExprGet(SSqlCmd* pCmd, int32_t index) { - if (pCmd->exprsInfo.numOfExprs <= index) { + if (pCmd->pQueryInfo[0].exprsInfo.numOfExprs <= index) { return NULL; } - return &pCmd->exprsInfo.pExprs[index]; + return &pCmd->pQueryInfo[0].exprsInfo.pExprs[index]; } void tscSqlExprCopy(SSqlExprInfo* dst, const SSqlExprInfo* src, uint64_t tableuid) { @@ -1144,7 +1157,7 @@ void tscColumnBaseInfoUpdateTableIndex(SColumnBaseInfo* pColList, int16_t tableI // todo refactor SColumnBase* tscColumnBaseInfoInsert(SSqlCmd* pCmd, SColumnIndex* pColIndex) { - SColumnBaseInfo* pcolList = &pCmd->colList; + SColumnBaseInfo* pcolList = &pCmd->pQueryInfo[0].colList; // ignore the tbname column to be inserted into source list if (pColIndex->columnIndex < 0) { @@ -1448,7 +1461,7 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SSqlCmd* pCmd) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); - for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); pColInfo[i].functionId = pExpr->functionId; @@ -1483,7 +1496,9 @@ bool tscShouldFreeHeatBeat(SSqlObj* pHb) { void tscCleanSqlCmd(SSqlCmd* pCmd) { tscFreeSqlCmdData(pCmd); - assert(pCmd->pMeterInfo == NULL); + if (pCmd->pQueryInfo != NULL) { + assert(pCmd->pQueryInfo[0].pMeterInfo == NULL); + } uint32_t allocSize = pCmd->allocSize; char* allocPtr = pCmd->payload; @@ -1539,7 +1554,7 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) { SDataBlockList* pDataBlocks = pCmd->pDataBlocks; SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); - assert(pSql->cmd.numOfTables == 1); + assert(pSql->cmd.pQueryInfo[0].numOfTables == 1); if (pDataBlocks == NULL || pMeterMetaInfo->vnodeIndex >= pDataBlocks->nSize) { tscTrace("%p object should be release since all data blocks have been submit", pSql); @@ -1554,18 +1569,18 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) { } SMeterMetaInfo* tscGetMeterMetaInfo(SSqlCmd* pCmd, int32_t index) { - if (pCmd == NULL || pCmd->numOfTables == 0) { + if (pCmd == NULL || pCmd->numOfQueries == 0 || pCmd->pQueryInfo[0].numOfTables == 0) { return NULL; } - assert(index >= 0 && index <= pCmd->numOfTables && pCmd->pMeterInfo != NULL); - return pCmd->pMeterInfo[index]; + assert(index >= 0 && index <= pCmd->pQueryInfo[0].numOfTables && pCmd->pQueryInfo[0].pMeterInfo != NULL); + return pCmd->pQueryInfo[0].pMeterInfo[index]; } SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* index) { int32_t k = -1; - for (int32_t i = 0; i < pCmd->numOfTables; ++i) { - if (pCmd->pMeterInfo[i]->pMeterMeta->uid == uid) { + for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) { + if (pCmd->pQueryInfo[0].pMeterInfo[i]->pMeterMeta->uid == uid) { k = i; break; } @@ -1578,17 +1593,37 @@ SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* i return tscGetMeterMetaInfo(pCmd, k); } +int32_t tscAddQueryInfo(SSqlCmd* pCmd) { + assert(pCmd != NULL); + + size_t s = pCmd->numOfQueries + 1; + char* tmp = realloc(pCmd->pQueryInfo, s * sizeof(SQueryInfo)); + if (tmp == NULL) { + return TSDB_CODE_CLI_OUT_OF_MEMORY; + } + + pCmd->pQueryInfo = (SQueryInfo*) tmp; + memset(&pCmd->pQueryInfo[pCmd->numOfQueries], 0, sizeof(SQueryInfo)); + + pCmd->numOfQueries++; + return TSDB_CODE_SUCCESS; +} + SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* pMeterMeta, SMetricMeta* pMetricMeta, int16_t numOfTags, int16_t* tags) { - void* pAlloc = realloc(pCmd->pMeterInfo, (pCmd->numOfTables + 1) * POINTER_BYTES); + if (pCmd->pQueryInfo == NULL) { + tscAddQueryInfo(pCmd); + } + + void* pAlloc = realloc(pCmd->pQueryInfo[0].pMeterInfo, (pCmd->pQueryInfo->numOfTables + 1) * POINTER_BYTES); if (pAlloc == NULL) { return NULL; } - pCmd->pMeterInfo = pAlloc; - pCmd->pMeterInfo[pCmd->numOfTables] = calloc(1, sizeof(SMeterMetaInfo)); + pCmd->pQueryInfo[0].pMeterInfo = pAlloc; + pCmd->pQueryInfo[0].pMeterInfo[pCmd->pQueryInfo->numOfTables] = calloc(1, sizeof(SMeterMetaInfo)); - SMeterMetaInfo* pMeterMetaInfo = pCmd->pMeterInfo[pCmd->numOfTables]; + SMeterMetaInfo* pMeterMetaInfo = pCmd->pQueryInfo[0].pMeterInfo[pCmd->pQueryInfo->numOfTables]; assert(pMeterMetaInfo != NULL); if (name != NULL) { @@ -1604,7 +1639,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* memcpy(pMeterMetaInfo->tagColumnIndex, tags, sizeof(pMeterMetaInfo->tagColumnIndex[0]) * numOfTags); } - pCmd->numOfTables += 1; + pCmd->pQueryInfo->numOfTables += 1; return pMeterMetaInfo; } @@ -1612,7 +1647,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SSqlCmd* pCmd) { return tscAddMeterMetaInfo(pCmd, NULL, NULL, NULL, 0, NULL); } void tscRemoveMeterMetaInfo(SSqlCmd* pCmd, int32_t index, bool removeFromCache) { - if (index < 0 || index >= pCmd->numOfTables) { + if (index < 0 || index >= pCmd->pQueryInfo->numOfTables) { return; } @@ -1621,24 +1656,29 @@ void tscRemoveMeterMetaInfo(SSqlCmd* pCmd, int32_t index, bool removeFromCache) tscClearMeterMetaInfo(pMeterMetaInfo, removeFromCache); free(pMeterMetaInfo); - int32_t after = pCmd->numOfTables - index - 1; + int32_t after = pCmd->pQueryInfo->numOfTables - index - 1; if (after > 0) { - memmove(&pCmd->pMeterInfo[index], &pCmd->pMeterInfo[index + 1], after * sizeof(void*)); + memmove(&pCmd->pQueryInfo[0].pMeterInfo[index], &pCmd->pQueryInfo[0].pMeterInfo[index + 1], after * sizeof(void*)); } - pCmd->numOfTables -= 1; + pCmd->pQueryInfo->numOfTables -= 1; } void tscRemoveAllMeterMetaInfo(SSqlCmd* pCmd, bool removeFromCache) { int64_t addr = offsetof(SSqlObj, cmd); - tscTrace("%p deref the metric/meter meta in cache, numOfTables:%d", ((char*)pCmd - addr), pCmd->numOfTables); + if (pCmd->numOfQueries == 0) { + return; + } + + tscTrace("%p deref the metric/meter meta in cache, numOfTables:%d", ((char*)pCmd - addr), + pCmd->pQueryInfo[0].numOfTables); - while (pCmd->numOfTables > 0) { - tscRemoveMeterMetaInfo(pCmd, pCmd->numOfTables - 1, removeFromCache); + while (pCmd->pQueryInfo[0].numOfTables > 0) { + tscRemoveMeterMetaInfo(pCmd, pCmd->pQueryInfo->numOfTables - 1, removeFromCache); } - tfree(pCmd->pMeterInfo); + tfree(pCmd->pQueryInfo[0].pMeterInfo); } void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache) { @@ -1682,17 +1722,27 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void pNew->cmd.payload = NULL; pNew->cmd.allocSize = 0; - pNew->cmd.pMeterInfo = NULL; - - pNew->cmd.colList.pColList = NULL; - pNew->cmd.colList.numOfAlloc = 0; - pNew->cmd.colList.numOfCols = 0; - - pNew->cmd.numOfTables = 0; - pNew->cmd.tsBuf = NULL; - - memset(&pNew->cmd.fieldsInfo, 0, sizeof(SFieldInfo)); - tscTagCondCopy(&pNew->cmd.tagCond, &pCmd->tagCond); + pNew->cmd.pQueryInfo = NULL; + pNew->cmd.numOfQueries = 0; + + if (tscAddQueryInfo(&pNew->cmd) != TSDB_CODE_SUCCESS) { + tscFreeSqlObj(pNew); + return NULL; + } + + memcpy(&pNew->cmd.pQueryInfo[0], &pCmd->pQueryInfo[0], sizeof(SQueryInfo)); + pNew->cmd.pQueryInfo[0].pMeterInfo = NULL; + + pNew->cmd.pQueryInfo[0].colList.pColList = NULL; + pNew->cmd.pQueryInfo[0].colList.numOfAlloc = 0; + pNew->cmd.pQueryInfo[0].colList.numOfCols = 0; + + pNew->cmd.pQueryInfo[0].numOfTables = 0; + pNew->cmd.pQueryInfo[0].tsBuf = NULL; + + memset(&pNew->cmd.pQueryInfo[0].fieldsInfo, 0, sizeof(SFieldInfo)); + + tscTagCondCopy(&pNew->cmd.pQueryInfo[0].tagCond, &pCmd->pQueryInfo[0].tagCond); if (tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE) != TSDB_CODE_SUCCESS) { tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pMeterMetaInfo->vnodeIndex); @@ -1700,8 +1750,8 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void return NULL; } - tscColumnBaseInfoCopy(&pNew->cmd.colList, &pCmd->colList, (int16_t)tableIndex); - + tscColumnBaseInfoCopy(&pNew->cmd.pQueryInfo[0].colList, &pCmd->pQueryInfo[0].colList, (int16_t)tableIndex); + // set the correct query type if (pPrevSql != NULL) { pNew->cmd.type = pPrevSql->cmd.type; @@ -1710,20 +1760,20 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void } uint64_t uid = pMeterMetaInfo->pMeterMeta->uid; - tscSqlExprCopy(&pNew->cmd.exprsInfo, &pCmd->exprsInfo, uid); + tscSqlExprCopy(&pNew->cmd.pQueryInfo[0].exprsInfo, &pCmd->pQueryInfo[0].exprsInfo, uid); - int32_t numOfOutputCols = pNew->cmd.exprsInfo.numOfExprs; + int32_t numOfOutputCols = pNew->cmd.pQueryInfo[0].exprsInfo.numOfExprs; if (numOfOutputCols > 0) { int32_t* indexList = calloc(1, numOfOutputCols * sizeof(int32_t)); - for (int32_t i = 0, j = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { + for (int32_t i = 0, j = 0; i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs; ++i) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->uid == uid) { indexList[j++] = i; } } - tscFieldInfoCopy(&pCmd->fieldsInfo, &pNew->cmd.fieldsInfo, indexList, numOfOutputCols); + tscFieldInfoCopy(&pCmd->pQueryInfo[0].fieldsInfo, &pNew->cmd.pQueryInfo[0].fieldsInfo, indexList, numOfOutputCols); free(indexList); tscFieldInfoUpdateOffset(&pNew->cmd); @@ -1739,7 +1789,8 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void printf("the metricmeta key is:%s\n", key); #endif - char* name = pMeterMetaInfo->name; + char* name = pMeterMetaInfo->name; + SMeterMetaInfo* pFinalInfo = NULL; if (pPrevSql == NULL) { diff --git a/src/inc/hashutil.h b/src/inc/hashutil.h index 063881b0b4338862d8552205b462b824b710e514..e4c044abb088b320c52a38ee22cf4d25f001d7f4 100644 --- a/src/inc/hashutil.h +++ b/src/inc/hashutil.h @@ -16,6 +16,7 @@ #ifndef TDENGINE_HASHUTIL_H #define TDENGINE_HASHUTIL_H +#include "os.h" typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); diff --git a/src/inc/sql.y b/src/inc/sql.y index 3d0ded56ebd245dd7591378f1f5b643f532f2a33..cb660333a9ccac60f97822cbc81af1703866365e 100644 --- a/src/inc/sql.y +++ b/src/inc/sql.y @@ -31,7 +31,7 @@ } %syntax_error { - pInfo->validSql = false; + pInfo->valid = false; int32_t outputBufLen = tListLen(pInfo->pzErrMsg); int32_t len = 0; @@ -59,25 +59,25 @@ program ::= cmd. {} //////////////////////////////////THE SHOW STATEMENT/////////////////////////////////////////// -cmd ::= SHOW DATABASES. { setDCLSQLElems(pInfo, SHOW_DATABASES, 0);} -cmd ::= SHOW MNODES. { setDCLSQLElems(pInfo, SHOW_MNODES, 0);} -cmd ::= SHOW DNODES. { setDCLSQLElems(pInfo, SHOW_DNODES, 0);} -cmd ::= SHOW ACCOUNTS. { setDCLSQLElems(pInfo, SHOW_ACCOUNTS, 0);} -cmd ::= SHOW USERS. { setDCLSQLElems(pInfo, SHOW_USERS, 0);} - -cmd ::= SHOW MODULES. { setDCLSQLElems(pInfo, SHOW_MODULES, 0); } -cmd ::= SHOW QUERIES. { setDCLSQLElems(pInfo, SHOW_QUERIES, 0); } -cmd ::= SHOW CONNECTIONS.{ setDCLSQLElems(pInfo, SHOW_CONNECTIONS, 0);} -cmd ::= SHOW STREAMS. { setDCLSQLElems(pInfo, SHOW_STREAMS, 0); } -cmd ::= SHOW CONFIGS. { setDCLSQLElems(pInfo, SHOW_CONFIGS, 0); } -cmd ::= SHOW SCORES. { setDCLSQLElems(pInfo, SHOW_SCORES, 0); } -cmd ::= SHOW GRANTS. { setDCLSQLElems(pInfo, SHOW_GRANTS, 0); } - -cmd ::= SHOW VNODES. { setDCLSQLElems(pInfo, SHOW_VNODES, 0); } -cmd ::= SHOW VNODES IPTOKEN(X). { setDCLSQLElems(pInfo, SHOW_VNODES, 1, &X); } +cmd ::= SHOW DATABASES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);} +cmd ::= SHOW MNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);} +cmd ::= SHOW DNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);} +cmd ::= SHOW ACCOUNTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);} +cmd ::= SHOW USERS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);} + +cmd ::= SHOW MODULES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0); } +cmd ::= SHOW QUERIES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0); } +cmd ::= SHOW CONNECTIONS.{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);} +cmd ::= SHOW STREAMS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); } +cmd ::= SHOW CONFIGS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_CONFIGS, 0, 0); } +cmd ::= SHOW SCORES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); } +cmd ::= SHOW GRANTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); } + +cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); } +cmd ::= SHOW VNODES IPTOKEN(X). { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); } %type dbPrefix {SSQLToken} -dbPrefix(A) ::=. {A.n = 0;} +dbPrefix(A) ::=. {A.n = 0; A.type = 0;} dbPrefix(A) ::= ids(X) DOT. {A = X; } %type cpxName {SSQLToken} @@ -85,60 +85,60 @@ cpxName(A) ::= . {A.n = 0; } cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; } cmd ::= SHOW dbPrefix(X) TABLES. { - setDCLSQLElems(pInfo, SHOW_TABLES, 1, &X); + setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, 0); } cmd ::= SHOW dbPrefix(X) TABLES LIKE ids(Y). { - setDCLSQLElems(pInfo, SHOW_TABLES, 2, &X, &Y); + setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, &Y); } cmd ::= SHOW dbPrefix(X) STABLES. { - setDCLSQLElems(pInfo, SHOW_STABLES, 1, &X); + setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &X, 0); } cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). { SSQLToken token; setDBName(&token, &X); - setDCLSQLElems(pInfo, SHOW_STABLES, 2, &token, &Y); + setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &Y); } cmd ::= SHOW dbPrefix(X) VGROUPS. { SSQLToken token; setDBName(&token, &X); - setDCLSQLElems(pInfo, SHOW_VGROUPS, 1, &token); + setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0); } //drop configure for tables cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). { X.n += Z.n; - setDCLSQLElems(pInfo, DROP_TABLE, 2, &X, &Y); + setDropDBTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y); } -cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDCLSQLElems(pInfo, DROP_DATABASE, 2, &X, &Y); } -cmd ::= DROP DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, DROP_DNODE, 1, &X); } -cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, DROP_USER, 1, &X); } -cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, DROP_ACCOUNT, 1, &X); } +cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDBTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y); } +cmd ::= DROP DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); } +cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); } +cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); } /////////////////////////////////THE USE STATEMENT////////////////////////////////////////// -cmd ::= USE ids(X). { setDCLSQLElems(pInfo, USE_DATABASE, 1, &X);} +cmd ::= USE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_USE_DB, 1, &X);} /////////////////////////////////THE DESCRIBE STATEMENT///////////////////////////////////// cmd ::= DESCRIBE ids(X) cpxName(Y). { X.n += Y.n; - setDCLSQLElems(pInfo, DESCRIBE_TABLE, 1, &X); + setDCLSQLElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X); } /////////////////////////////////THE ALTER STATEMENT//////////////////////////////////////// -cmd ::= ALTER USER ids(X) PASS ids(Y). { setDCLSQLElems(pInfo, ALTER_USER_PASSWD, 2, &X, &Y); } -cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setDCLSQLElems(pInfo, ALTER_USER_PRIVILEGES, 2, &X, &Y);} -cmd ::= ALTER DNODE IPTOKEN(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_DNODE, 2, &X, &Y); } -cmd ::= ALTER DNODE IPTOKEN(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, ALTER_DNODE, 3, &X, &Y, &Z); } -cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, ALTER_LOCAL, 1, &X); } -cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_LOCAL, 2, &X, &Y); } -cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SSQLToken t = {0}; setCreateDBSQL(pInfo, ALTER_DATABASE, &X, &Y, &t);} +cmd ::= ALTER USER ids(X) PASS ids(Y). { setAlterUserSQL(pInfo, TSDB_ALTER_USER_PASSWD, &X, &Y, NULL); } +cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setAlterUserSQL(pInfo, TSDB_ALTER_USER_PRIVILEGES, &X, NULL, &Y);} +cmd ::= ALTER DNODE IPTOKEN(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &X, &Y); } +cmd ::= ALTER DNODE IPTOKEN(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &X, &Y, &Z); } +cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); } +cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); } +cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SSQLToken t = {0}; setCreateDBSQL(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);} -cmd ::= ALTER ACCOUNT ids(X) acct_optr(Z). { SSQLToken t = {0}; setCreateAcctSQL(pInfo, ALTER_ACCT, &X, &t, &Z);} -cmd ::= ALTER ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSQL(pInfo, ALTER_ACCT, &X, &Y, &Z);} +cmd ::= ALTER ACCOUNT ids(X) acct_optr(Z). { setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &X, NULL, &Z);} +cmd ::= ALTER ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &X, &Y, &Z);} // An IDENTIFIER can be a generic identifier, or one of several keywords. // Any non-standard keyword can also be an identifier. @@ -157,11 +157,11 @@ ifnotexists(X) ::= . {X.n = 0;} /////////////////////////////////THE CREATE STATEMENT/////////////////////////////////////// //create option for dnode/db/user/account -cmd ::= CREATE DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, CREATE_DNODE, 1, &X);} +cmd ::= CREATE DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);} cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). - { setCreateAcctSQL(pInfo, CREATE_ACCOUNT, &X, &Y, &Z);} -cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, CREATE_DATABASE, &X, &Y, &Z);} -cmd ::= CREATE USER ids(X) PASS ids(Y). { setDCLSQLElems(pInfo, CREATE_USER, 2, &X, &Y);} + { setCreateAcctSQL(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);} +cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} +cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSQL(pInfo, &X, &Y);} pps(Y) ::= . {Y.n = 0; } pps(Y) ::= PPS INTEGER(X). {Y = X; } @@ -192,14 +192,14 @@ state(Y) ::= STATE ids(X). {Y = X; } %type acct_optr {SCreateAcctSQL} acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K) conns(L) state(M). { - Y.users = (K.n>0)?atoi(K.z):-1; - Y.dbs = (E.n>0)?atoi(E.z):-1; - Y.tseries = (D.n>0)?atoi(D.z):-1; - Y.streams = (F.n>0)?atoi(F.z):-1; - Y.pps = (C.n>0)?atoi(C.z):-1; - Y.storage = (P.n>0)?strtoll(P.z, NULL, 10):-1; - Y.qtime = (Q.n>0)?strtoll(Q.z, NULL, 10):-1; - Y.conns = (L.n>0)?atoi(L.z):-1; + Y.maxUsers = (K.n>0)?atoi(K.z):-1; + Y.maxDbs = (E.n>0)?atoi(E.z):-1; + Y.maxTimeSeries = (D.n>0)?atoi(D.z):-1; + Y.maxStreams = (F.n>0)?atoi(F.z):-1; + Y.maxPointsPerSecond = (C.n>0)?atoi(C.z):-1; + Y.maxStorage = (P.n>0)?strtoll(P.z, NULL, 10):-1; + Y.maxQueryTime = (Q.n>0)?strtoll(Q.z, NULL, 10):-1; + Y.maxConnections = (L.n>0)?atoi(L.z):-1; Y.stat = M; } @@ -264,29 +264,29 @@ cmd ::= CREATE TABLE ifnotexists(Y) ids(X) cpxName(Z) create_table_args. { %type create_table_args{SCreateTableSQL*} create_table_args(A) ::= LP columnlist(X) RP. { - A = tSetCreateSQLElems(X, NULL, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METER); - setSQLInfo(pInfo, A, NULL, TSQL_CREATE_NORMAL_METER); + A = tSetCreateSQLElems(X, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE); + setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); } -// create metric +// create super table create_table_args(A) ::= LP columnlist(X) RP TAGS LP columnlist(Y) RP. { - A = tSetCreateSQLElems(X, Y, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METRIC); - setSQLInfo(pInfo, A, NULL, TSQL_CREATE_NORMAL_METRIC); + A = tSetCreateSQLElems(X, Y, NULL, NULL, NULL, TSQL_CREATE_STABLE); + setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); } -// create meter by using metric -// create meter meter_name using metric_name tags(tag_values1, tag_values2) +// create table by using super table +// create table table_name using super_table_name tags(tag_values1, tag_values2) create_table_args(A) ::= USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP. { X.n += F.n; - A = tSetCreateSQLElems(NULL, NULL, &X, Y, NULL, TSQL_CREATE_METER_FROM_METRIC); - setSQLInfo(pInfo, A, NULL, TSQL_CREATE_METER_FROM_METRIC); + A = tSetCreateSQLElems(NULL, NULL, &X, Y, NULL, TSQL_CREATE_TABLE_FROM_STABLE); + setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); } // create stream -// create table table_name as select count(*) from metric_name interval(time) +// create table table_name as select count(*) from super_table_name interval(time) create_table_args(A) ::= AS select(S). { A = tSetCreateSQLElems(NULL, NULL, NULL, NULL, S, TSQL_CREATE_STREAM); - setSQLInfo(pInfo, A, NULL, TSQL_CREATE_STREAM); + setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); } %type column{TAOS_FIELD} @@ -343,16 +343,21 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). { } //////////////////////// The SELECT statement ///////////////////////////////// -cmd ::= select(X). { - setSQLInfo(pInfo, X, NULL, TSQL_QUERY_METER); -} - %type select {SQuerySQL*} -%destructor select {destroyQuerySql($$);} +%destructor select {doDestroyQuerySql($$);} select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) fill_opt(F) sliding_opt(S) groupby_opt(P) orderby_opt(Z) having_opt(N) slimit_opt(G) limit_opt(L). { A = tSetQuerySQLElems(&T, W, X, Y, P, Z, &K, &S, F, &L, &G); } +%type union {SSubclauseInfo*} +%destructor union {destroyAllSelectClause($$);} + +union(Y) ::= select(X). { Y = setSubclause(NULL, X); } +union(Y) ::= LP union(X) RP. { Y = X; } +union(Y) ::= union(Z) UNION select(X). { Y = appendSelectClause(Z, X); } + +cmd ::= union(X). { setSQLInfo(pInfo, X, NULL, TSDB_SQL_SELECT); } + // Support for the SQL exprssion without from & where subclauses, e.g., // select current_database(), // select server_version(), select client_version(), @@ -572,34 +577,14 @@ exprlist(A) ::= expritem(X). {A = tSQLExprListAppend(0,X,0);} expritem(A) ::= expr(X). {A = X;} expritem(A) ::= . {A = 0;} -////////////////////////// The INSERT command ///////////////////////////////// -// add support "values() values() values() tags()" operation.... -cmd ::= INSERT INTO cpxName(X) insert_value_list(K). { - tSetInsertSQLElems(pInfo, &X, K); -} - -%type insert_value_list {tSQLExprListList*} -insert_value_list(X) ::= VALUES LP itemlist(Y) RP. {X = tSQLListListAppend(NULL, Y);} -insert_value_list(X) ::= insert_value_list(K) VALUES LP itemlist(Y) RP. -{X = tSQLListListAppend(K, Y);} - -//cmd ::= INSERT INTO cpxName(X) select(S). -// {sqliteInsert(pParse, sqliteSrcListAppend(0,&X,&D), 0, S, F, R);} - -%type itemlist {tSQLExprList*} -%destructor itemlist {tSQLExprListDestroy($$);} - -itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = tSQLExprListAppend(X,Y,0);} -itemlist(A) ::= expr(X). {A = tSQLExprListAppend(0,X,0);} - ///////////////////////////////////reset query cache////////////////////////////////////// -cmd ::= RESET QUERY CACHE. { setDCLSQLElems(pInfo, RESET_QUERY_CACHE, 0);} +cmd ::= RESET QUERY CACHE. { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} ///////////////////////////////////ALTER TABLE statement////////////////////////////////// cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). { X.n += F.n; - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, ALTER_TABLE_ADD_COLUMN); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_ADD_COLUMN); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). { @@ -608,15 +593,15 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). { toTSDBType(A.type); tVariantList* K = tVariantListAppendToken(NULL, &A, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, ALTER_TABLE_DROP_COLUMN); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_DROP_COLUMN); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } //////////////////////////////////ALTER TAGS statement///////////////////////////////////// cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). { X.n += Y.n; - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, ALTER_TABLE_TAGS_ADD); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_ADD); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). { X.n += Z.n; @@ -624,8 +609,8 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). { toTSDBType(Y.type); tVariantList* A = tVariantListAppendToken(NULL, &Y, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, ALTER_TABLE_TAGS_DROP); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_DROP); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). { @@ -637,8 +622,8 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). { toTSDBType(Z.type); A = tVariantListAppendToken(A, &Z, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, ALTER_TABLE_TAGS_CHG); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_CHG); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). { @@ -648,17 +633,18 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). { tVariantList* A = tVariantListAppendToken(NULL, &Y, -1); A = tVariantListAppend(A, &Z, -1); - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, ALTER_TABLE_TAGS_SET); - setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_SET); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL); + setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } ////////////////////////////////////////kill statement/////////////////////////////////////// -cmd ::= KILL CONNECTION IPTOKEN(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setDCLSQLElems(pInfo, KILL_CONNECTION, 1, &X);} -cmd ::= KILL STREAM IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setDCLSQLElems(pInfo, KILL_STREAM, 1, &X);} -cmd ::= KILL QUERY IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setDCLSQLElems(pInfo, KILL_QUERY, 1, &X);} +cmd ::= KILL CONNECTION IPTOKEN(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setKillSQL(pInfo, TSDB_SQL_KILL_CONNECTION, &X);} +cmd ::= KILL STREAM IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setKillSQL(pInfo, TSDB_SQL_KILL_STREAM, &X);} +cmd ::= KILL QUERY IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &X);} %fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL COUNT SUM AVG MIN MAX FIRST LAST TOP BOTTOM STDDEV PERCENTILE APERCENTILE LEASTSQUARES HISTOGRAM DIFF - SPREAD TWA INTERP LAST_ROW NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT METRIC TBNAME JOIN METRICS STABLE NULL. + SPREAD TWA INTERP LAST_ROW NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT METRIC TBNAME JOIN METRICS STABLE NULL INSERT INTO + VALUES. diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 22b10eaa60b1fe871539c9bdbe87db5d3fce2709..95ca7a012906fb40c149d2712279bdfebd2da4b7 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -74,10 +74,10 @@ extern "C" { #define TSDB_MSG_TYPE_CREATE_MNODE_RSP 44 #define TSDB_MSG_TYPE_DROP_MNODE 45 #define TSDB_MSG_TYPE_DROP_MNODE_RSP 46 -#define TSDB_MSG_TYPE_CREATE_PNODE 47 -#define TSDB_MSG_TYPE_CREATE_PNODE_RSP 48 -#define TSDB_MSG_TYPE_DROP_PNODE 49 -#define TSDB_MSG_TYPE_DROP_PNODE_RSP 50 +#define TSDB_MSG_TYPE_CREATE_DNODE 47 +#define TSDB_MSG_TYPE_CREATE_DNODE_RSP 48 +#define TSDB_MSG_TYPE_DROP_DNODE 49 +#define TSDB_MSG_TYPE_DROP_DNODE_RSP 50 #define TSDB_MSG_TYPE_CREATE_DB 51 #define TSDB_MSG_TYPE_CREATE_DB_RSP 52 #define TSDB_MSG_TYPE_DROP_DB 53 @@ -147,7 +147,7 @@ enum _mgmt_table { TSDB_MGMT_TABLE_USER, TSDB_MGMT_TABLE_DB, TSDB_MGMT_TABLE_TABLE, - TSDB_MGMT_TABLE_PNODE, + TSDB_MGMT_TABLE_DNODE, TSDB_MGMT_TABLE_MNODE, TSDB_MGMT_TABLE_VGROUP, TSDB_MGMT_TABLE_METRIC, @@ -312,7 +312,7 @@ typedef struct { typedef struct { char db[TSDB_METER_ID_LEN]; - short ignoreNotExists; + uint8_t ignoreNotExists; } SDropDbMsg, SUseDbMsg; typedef struct { diff --git a/src/inc/tsqldef.h b/src/inc/tsqldef.h index ea0500eb866f65dfe3ef77d0f7b318b2bcbdec0f..c4d863c2916b51e5823d08c0f3f87771f6a0be52 100644 --- a/src/inc/tsqldef.h +++ b/src/inc/tsqldef.h @@ -119,97 +119,100 @@ #define TK_COMMA 101 #define TK_NULL 102 #define TK_SELECT 103 -#define TK_FROM 104 -#define TK_VARIABLE 105 -#define TK_INTERVAL 106 -#define TK_FILL 107 -#define TK_SLIDING 108 -#define TK_ORDER 109 -#define TK_BY 110 -#define TK_ASC 111 -#define TK_DESC 112 -#define TK_GROUP 113 -#define TK_HAVING 114 -#define TK_LIMIT 115 -#define TK_OFFSET 116 -#define TK_SLIMIT 117 -#define TK_SOFFSET 118 -#define TK_WHERE 119 -#define TK_NOW 120 -#define TK_INSERT 121 -#define TK_INTO 122 -#define TK_VALUES 123 -#define TK_RESET 124 -#define TK_QUERY 125 -#define TK_ADD 126 -#define TK_COLUMN 127 -#define TK_TAG 128 -#define TK_CHANGE 129 -#define TK_SET 130 -#define TK_KILL 131 -#define TK_CONNECTION 132 -#define TK_COLON 133 -#define TK_STREAM 134 -#define TK_ABORT 135 -#define TK_AFTER 136 -#define TK_ATTACH 137 -#define TK_BEFORE 138 -#define TK_BEGIN 139 -#define TK_CASCADE 140 -#define TK_CLUSTER 141 -#define TK_CONFLICT 142 -#define TK_COPY 143 -#define TK_DEFERRED 144 -#define TK_DELIMITERS 145 -#define TK_DETACH 146 -#define TK_EACH 147 -#define TK_END 148 -#define TK_EXPLAIN 149 -#define TK_FAIL 150 -#define TK_FOR 151 -#define TK_IGNORE 152 -#define TK_IMMEDIATE 153 -#define TK_INITIALLY 154 -#define TK_INSTEAD 155 -#define TK_MATCH 156 -#define TK_KEY 157 -#define TK_OF 158 -#define TK_RAISE 159 -#define TK_REPLACE 160 -#define TK_RESTRICT 161 -#define TK_ROW 162 -#define TK_STATEMENT 163 -#define TK_TRIGGER 164 -#define TK_VIEW 165 -#define TK_ALL 166 -#define TK_COUNT 167 -#define TK_SUM 168 -#define TK_AVG 169 -#define TK_MIN 170 -#define TK_MAX 171 -#define TK_FIRST 172 -#define TK_LAST 173 -#define TK_TOP 174 -#define TK_BOTTOM 175 -#define TK_STDDEV 176 -#define TK_PERCENTILE 177 -#define TK_APERCENTILE 178 -#define TK_LEASTSQUARES 179 -#define TK_HISTOGRAM 180 -#define TK_DIFF 181 -#define TK_SPREAD 182 -#define TK_TWA 183 -#define TK_INTERP 184 -#define TK_LAST_ROW 185 -#define TK_SEMI 186 -#define TK_NONE 187 -#define TK_PREV 188 -#define TK_LINEAR 189 -#define TK_IMPORT 190 -#define TK_METRIC 191 -#define TK_TBNAME 192 -#define TK_JOIN 193 -#define TK_METRICS 194 -#define TK_STABLE 195 +#define TK_UNION 104 +#define TK_FROM 105 +#define TK_VARIABLE 106 +#define TK_INTERVAL 107 +#define TK_FILL 108 +#define TK_SLIDING 109 +#define TK_ORDER 110 +#define TK_BY 111 +#define TK_ASC 112 +#define TK_DESC 113 +#define TK_GROUP 114 +#define TK_HAVING 115 +#define TK_LIMIT 116 +#define TK_OFFSET 117 +#define TK_SLIMIT 118 +#define TK_SOFFSET 119 +#define TK_WHERE 120 +#define TK_NOW 121 +#define TK_RESET 122 +#define TK_QUERY 123 +#define TK_ADD 124 +#define TK_COLUMN 125 +#define TK_TAG 126 +#define TK_CHANGE 127 +#define TK_SET 128 +#define TK_KILL 129 +#define TK_CONNECTION 130 +#define TK_COLON 131 +#define TK_STREAM 132 +#define TK_ABORT 133 +#define TK_AFTER 134 +#define TK_ATTACH 135 +#define TK_BEFORE 136 +#define TK_BEGIN 137 +#define TK_CASCADE 138 +#define TK_CLUSTER 139 +#define TK_CONFLICT 140 +#define TK_COPY 141 +#define TK_DEFERRED 142 +#define TK_DELIMITERS 143 +#define TK_DETACH 144 +#define TK_EACH 145 +#define TK_END 146 +#define TK_EXPLAIN 147 +#define TK_FAIL 148 +#define TK_FOR 149 +#define TK_IGNORE 150 +#define TK_IMMEDIATE 151 +#define TK_INITIALLY 152 +#define TK_INSTEAD 153 +#define TK_MATCH 154 +#define TK_KEY 155 +#define TK_OF 156 +#define TK_RAISE 157 +#define TK_REPLACE 158 +#define TK_RESTRICT 159 +#define TK_ROW 160 +#define TK_STATEMENT 161 +#define TK_TRIGGER 162 +#define TK_VIEW 163 +#define TK_ALL 164 +#define TK_COUNT 165 +#define TK_SUM 166 +#define TK_AVG 167 +#define TK_MIN 168 +#define TK_MAX 169 +#define TK_FIRST 170 +#define TK_LAST 171 +#define TK_TOP 172 +#define TK_BOTTOM 173 +#define TK_STDDEV 174 +#define TK_PERCENTILE 175 +#define TK_APERCENTILE 176 +#define TK_LEASTSQUARES 177 +#define TK_HISTOGRAM 178 +#define TK_DIFF 179 +#define TK_SPREAD 180 +#define TK_TWA 181 +#define TK_INTERP 182 +#define TK_LAST_ROW 183 +#define TK_SEMI 184 +#define TK_NONE 185 +#define TK_PREV 186 +#define TK_LINEAR 187 +#define TK_IMPORT 188 +#define TK_METRIC 189 +#define TK_TBNAME 190 +#define TK_JOIN 191 +#define TK_METRICS 192 +#define TK_STABLE 193 +#define TK_INSERT 194 +#define TK_INTO 195 +#define TK_VALUES 196 #endif + + diff --git a/src/inc/tutil.h b/src/inc/tutil.h index f3576790a93ad7c056aa7073b8ab55cbcc5da217..fcc3fde13f0c29832683292facbfe8e6dcdc6288 100644 --- a/src/inc/tutil.h +++ b/src/inc/tutil.h @@ -162,15 +162,6 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP int32_t taosInitTimer(void (*callback)(int), int32_t ms); -/** - * murmur hash algorithm - * @key usually string - * @len key length - * @seed hash seed - * @out an int32 value - */ -uint32_t MurmurHash3_32(const void *key, int32_t len); - bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len); bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); diff --git a/src/system/detail/inc/vnodeQueryImpl.h b/src/system/detail/inc/vnodeQueryImpl.h index a26e9b6285af39156edf20d331e0afaaab4bf578..7de221e8d4c6b3ac50f6acc7d985d4526961bf81 100644 --- a/src/system/detail/inc/vnodeQueryImpl.h +++ b/src/system/detail/inc/vnodeQueryImpl.h @@ -22,7 +22,8 @@ extern "C" { #include "os.h" -#include "ihash.h" +#include "hash.h" +#include "hashutil.h" #define GET_QINFO_ADDR(x) ((char*)(x)-offsetof(SQInfo, query)) #define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0) @@ -117,11 +118,9 @@ typedef enum { #define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN) typedef int (*__block_search_fn_t)(char* data, int num, int64_t key, int order); -typedef int32_t (*__read_data_fn_t)(int fd, SQInfo* pQInfo, SQueryFilesInfo* pQueryFile, char* buf, uint64_t offset, - int32_t size); static FORCE_INLINE SMeterObj* getMeterObj(void* hashHandle, int32_t sid) { - return *(SMeterObj**)taosGetIntHashData(hashHandle, sid); + return *(SMeterObj**)taosGetDataFromHash(hashHandle, (const char*) &sid, sizeof(sid)); } bool isQueryKilled(SQuery* pQuery); diff --git a/src/system/detail/inc/vnodeRead.h b/src/system/detail/inc/vnodeRead.h index 0d749f60cc7ab3bd102ec812c1cc84ac42b65c11..15f089c194ab5b8db912ac57feba7b85e9c050bd 100644 --- a/src/system/detail/inc/vnodeRead.h +++ b/src/system/detail/inc/vnodeRead.h @@ -172,7 +172,7 @@ typedef struct SMeterDataInfo { } SMeterDataInfo; typedef struct SMeterQuerySupportObj { - void* pMeterObj; + void* pMetersHashTable; // meter table hash list SMeterSidExtInfo** pMeterSidExtInfo; int32_t numOfMeters; diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index 2872f5e7cac3f74a66d4853bc7c97def70563664..c05eece6067accdfc6d4ee775463c93d32debb10 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -894,7 +894,7 @@ int mgmtProcessShowMsg(char *pMsg, int msgLen, SConnObj *pConn) { SShowRspMsg *pShowRsp; SShowObj * pShow = NULL; - if (pShowMsg->type == TSDB_MGMT_TABLE_PNODE || TSDB_MGMT_TABLE_GRANTS || TSDB_MGMT_TABLE_SCORES) { + if (pShowMsg->type == TSDB_MGMT_TABLE_DNODE || TSDB_MGMT_TABLE_GRANTS || TSDB_MGMT_TABLE_SCORES) { if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_SHOW_RSP) != 0) { return 0; } @@ -1467,8 +1467,8 @@ void mgmtInitProcessShellMsg() { mgmtProcessShellMsg[TSDB_MSG_TYPE_SHOW] = mgmtProcessShowMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CONNECT] = mgmtProcessConnectMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_HEARTBEAT] = mgmtProcessHeartBeatMsg; - mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_PNODE] = mgmtProcessCreateDnodeMsg; - mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_PNODE] = mgmtProcessDropDnodeMsg; + mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_DNODE] = mgmtProcessCreateDnodeMsg; + mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_DNODE] = mgmtProcessDropDnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_MNODE] = mgmtProcessCreateMnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_MNODE] = mgmtProcessDropMnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CFG_MNODE] = mgmtProcessCfgMnodeMsg; diff --git a/src/system/detail/src/vnodeQueryImpl.c b/src/system/detail/src/vnodeQueryImpl.c index fb7498145454e672c3258575bedbcdc73d028210..cb369dea0e00968cab4ddde01aa4768b881ca51f 100644 --- a/src/system/detail/src/vnodeQueryImpl.c +++ b/src/system/detail/src/vnodeQueryImpl.c @@ -3383,6 +3383,10 @@ void forwardQueryStartPosition(SQueryRuntimeEnv *pRuntimeEnv) { updateOffsetVal(pRuntimeEnv, &blockInfo, pBlock); } else { pQuery->limit.offset -= maxReads; + + // update the lastkey, since the following skip operation may traverse to another media. update the lastkey first. + pQuery->lastKey = (QUERY_IS_ASC_QUERY(pQuery))? blockInfo.keyLast+1:blockInfo.keyFirst-1; + doSkipDataBlock(pRuntimeEnv); } } diff --git a/src/system/lite/src/mgmtShell.spec.c b/src/system/lite/src/mgmtShell.spec.c index 5195010b4129fb2677526aa62f3d40f53d9bdded..a1d8e6a34a4e2cc2d7df7c1acc6cdf75a796fc1a 100644 --- a/src/system/lite/src/mgmtShell.spec.c +++ b/src/system/lite/src/mgmtShell.spec.c @@ -24,7 +24,7 @@ int mgmtProcessAlterAcctMsg(char *pMsg, int msgLen, SConnObj *pConn) { } int mgmtProcessCreateDnodeMsg(char *pMsg, int msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_PNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); } int mgmtProcessCfgMnodeMsg(char *pMsg, int msgLen, SConnObj *pConn) { @@ -36,7 +36,7 @@ int mgmtProcessDropMnodeMsg(char *pMsg, int msgLen, SConnObj *pConn) { } int mgmtProcessDropDnodeMsg(char *pMsg, int msgLen, SConnObj *pConn) { - return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_PNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); + return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT); } int mgmtProcessDropAcctMsg(char *pMsg, int msgLen, SConnObj *pConn) {