提交 c18b6b1b 编写于 作者: H hjxilinx

add the union support in sql parser. #1032. [TBASE-1140]

上级 25fae2a1
...@@ -21,17 +21,77 @@ extern "C" { ...@@ -21,17 +21,77 @@ extern "C" {
#endif #endif
#include "taos.h" #include "taos.h"
#include "taosmsg.h"
#include "tsqldef.h" #include "tsqldef.h"
#include "ttypes.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 #define MAX_TOKEN_LEN 30
// token type // token type
enum { enum {
TSQL_NODE_TYPE_EXPR = 0x1, TSQL_NODE_TYPE_EXPR = 0x1,
TSQL_NODE_TYPE_ID = 0x2, TSQL_NODE_TYPE_ID = 0x2,
TSQL_NODE_TYPE_VALUE = 0x4, TSQL_NODE_TYPE_VALUE = 0x4,
}; };
extern char tTokenTypeSwitcher[13]; extern char tTokenTypeSwitcher[13];
...@@ -72,72 +132,12 @@ typedef struct tFieldList { ...@@ -72,72 +132,12 @@ typedef struct tFieldList {
TAOS_FIELD *p; TAOS_FIELD *p;
} tFieldList; } tFieldList;
// sql operation type // create table operation type
enum TSQL_TYPE { enum TSQL_TYPE {
TSQL_CREATE_NORMAL_METER = 0x01, TSQL_CREATE_TABLE = 0x1,
TSQL_CREATE_NORMAL_METRIC = 0x02, TSQL_CREATE_STABLE = 0x2,
TSQL_CREATE_METER_FROM_METRIC = 0x04, TSQL_CREATE_TABLE_FROM_STABLE = 0x3,
TSQL_CREATE_STREAM = 0x08, TSQL_CREATE_STREAM = 0x4,
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,
}; };
typedef struct SQuerySQL { typedef struct SQuerySQL {
...@@ -157,33 +157,31 @@ typedef struct SQuerySQL { ...@@ -157,33 +157,31 @@ typedef struct SQuerySQL {
typedef struct SCreateTableSQL { typedef struct SCreateTableSQL {
struct SSQLToken name; // meter name, create table [meterName] xxx struct SSQLToken name; // meter name, create table [meterName] xxx
bool existCheck; bool existCheck;
int8_t type; // create normal table/from super table/ stream
struct { struct {
tFieldList *pTagColumns; // for normal table, pTagColumns = NULL; tFieldList *pTagColumns; // for normal table, pTagColumns = NULL;
tFieldList *pColumns; tFieldList *pColumns;
} colInfo; } colInfo;
struct { struct {
SSQLToken metricName; // metric name, for using clause SSQLToken stableName; // super table name, for using clause
tVariantList *pTagVals; // create by using metric, tag value tVariantList *pTagVals; // create by using metric, tag value
STagData tagdata;
} usingInfo; } usingInfo;
SQuerySQL *pSelect; SQuerySQL *pSelect;
} SCreateTableSQL; } SCreateTableSQL;
typedef struct SAlterTableSQL { typedef struct SAlterTableSQL {
SSQLToken name; SSQLToken name;
int16_t type;
STagData tagData;
tFieldList * pAddColumns; tFieldList * pAddColumns;
SSQLToken dropTagToken;
tVariantList *varList; // set t=val or: change src dst tVariantList *varList; // set t=val or: change src dst
} SAlterTableSQL; } SAlterTableSQL;
typedef struct SInsertSQL {
SSQLToken name;
struct tSQLExprListList *pValue;
} SInsertSQL;
typedef struct SCreateDBInfo { typedef struct SCreateDBInfo {
SSQLToken dbname; SSQLToken dbname;
int32_t replica; int32_t replica;
...@@ -204,41 +202,68 @@ typedef struct SCreateDBInfo { ...@@ -204,41 +202,68 @@ typedef struct SCreateDBInfo {
} SCreateDBInfo; } SCreateDBInfo;
typedef struct SCreateAcctSQL { typedef struct SCreateAcctSQL {
int32_t users; int32_t maxUsers;
int32_t dbs; int32_t maxDbs;
int32_t tseries; int32_t maxTimeSeries;
int32_t streams; int32_t maxStreams;
int32_t pps; int32_t maxPointsPerSecond;
int64_t storage; int64_t maxStorage;
int64_t qtime; int64_t maxQueryTime;
int32_t conns; int32_t maxConnections;
SSQLToken stat; SSQLToken stat;
} SCreateAcctSQL; } 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 { typedef struct tDCLSQL {
int32_t nTokens; /* Number of expressions on the list */ int32_t nTokens; /* Number of expressions on the list */
int32_t nAlloc; /* Number of entries allocated below */ int32_t nAlloc; /* Number of entries allocated below */
SSQLToken *a; /* one entry for element */ SSQLToken *a; /* one entry for element */
bool existsCheck;
union { union {
SCreateDBInfo dbOpt; SCreateDBInfo dbOpt;
SCreateAcctSQL acctOpt; SCreateAcctSQL acctOpt;
SShowInfo showOpt;
SSQLToken ip;
}; };
SUserInfo user;
} tDCLSQL; } tDCLSQL;
typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
SQuerySQL **pClause;
int32_t numOfClause;
} SSubclauseInfo;
typedef struct SSqlInfo { typedef struct SSqlInfo {
int32_t sqlType; int32_t type;
bool validSql; bool valid;
union { union {
SCreateTableSQL *pCreateTableInfo; SCreateTableSQL *pCreateTableInfo;
SInsertSQL * pInsertInfo;
SAlterTableSQL * pAlterInfo; SAlterTableSQL * pAlterInfo;
SQuerySQL * pQueryInfo;
tDCLSQL * pDCLInfo; tDCLSQL * pDCLInfo;
}; };
char pzErrMsg[256]; SSubclauseInfo subclauseInfo;
char pzErrMsg[256];
} SSqlInfo; } SSqlInfo;
typedef struct tSQLExpr { typedef struct tSQLExpr {
...@@ -338,31 +363,40 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, ...@@ -338,31 +363,40 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection,
SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pMetricName, SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pMetricName,
tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type); 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); tSQLExpr *tSQLExprNodeClone(tSQLExpr *pExpr);
SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type); SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type);
tSQLExprListList *tSQLListListAppend(tSQLExprListList *pList, tSQLExprList *pExprList); 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 setCreatedMeterName(SSqlInfo *pInfo, SSQLToken *pMeterName, SSQLToken *pIfNotExists);
void SQLInfoDestroy(SSqlInfo *pInfo); void SQLInfoDestroy(SSqlInfo *pInfo);
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...); 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); tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken);
void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists); 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 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); void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo);
// prefix show db.tables; // prefix show db.tables;
......
...@@ -134,6 +134,7 @@ TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index); ...@@ -134,6 +134,7 @@ TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index);
int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index); int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index);
int32_t tscGetResRowLength(SSqlCmd* pCmd); int32_t tscGetResRowLength(SSqlCmd* pCmd);
void tscClearFieldInfo(SFieldInfo* pFieldInfo); void tscClearFieldInfo(SFieldInfo* pFieldInfo);
int32_t tscNumOfFields(SSqlCmd* pCmd);
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex); 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 ...@@ -186,6 +187,7 @@ void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool remov
SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* pMeterMeta, SMetricMeta* pMetricMeta, SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* pMeterMeta, SMetricMeta* pMetricMeta,
int16_t numOfTags, int16_t* tags); int16_t numOfTags, int16_t* tags);
SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SSqlCmd* pCmd); SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SSqlCmd* pCmd);
int32_t tscAddQueryInfo(SSqlCmd *pCmd);
void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* keyStr, uint64_t uid); void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* keyStr, uint64_t uid);
int tscGetMetricMeta(SSqlObj* pSql); int tscGetMetricMeta(SSqlObj* pSql);
......
...@@ -43,66 +43,6 @@ extern "C" { ...@@ -43,66 +43,6 @@ extern "C" {
((res->data + tscFieldInfoGetOffset(cmd, col) * res->numOfRows) + \ ((res->data + tscFieldInfoGetOffset(cmd, col) * res->numOfRows) + \
(1 - ord.order) * (res->numOfRows - 1) * tscFieldInfoGetField(cmd, col)->bytes) (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 // forward declaration
struct SSqlInfo; struct SSqlInfo;
...@@ -267,6 +207,28 @@ typedef struct SDataBlockList { ...@@ -267,6 +207,28 @@ typedef struct SDataBlockList {
STableDataBlocks **pData; STableDataBlocks **pData;
} SDataBlockList; } 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 { typedef struct {
SOrderVal order; SOrderVal order;
int command; int command;
...@@ -274,18 +236,12 @@ typedef struct { ...@@ -274,18 +236,12 @@ typedef struct {
union { union {
bool existsCheck; // check if the table exists 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 int8_t isInsertFromFile; // load data from file or not
bool import; // import/insert type
uint8_t msgType; uint8_t msgType;
uint16_t type; // query type 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; * use to keep short request msg and error msg, in such case, SSqlCmd->payload == SSqlCmd->ext;
...@@ -297,22 +253,32 @@ typedef struct { ...@@ -297,22 +253,32 @@ typedef struct {
char * payload; char * payload;
int payloadLen; int payloadLen;
short numOfCols; short numOfCols;
SColumnBaseInfo colList;
SFieldInfo fieldsInfo;
SSqlExprInfo exprsInfo;
SLimitVal limit;
SLimitVal slimit;
int64_t globalLimit; int64_t globalLimit;
STagCond tagCond;
int16_t interpoType; // interpolate type SQueryInfo *pQueryInfo;
int16_t numOfTables; 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 // submit data blocks branched according to vnode
SDataBlockList * pDataBlocks; 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 // for parameter ('?') binding and batch processing
int32_t batchSize; int32_t batchSize;
...@@ -435,6 +401,8 @@ typedef struct { ...@@ -435,6 +401,8 @@ typedef struct {
int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion); int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion);
void tscInitMsgs(); void tscInitMsgs();
extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo);
void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle); void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle);
int tscProcessSql(SSqlObj *pSql); int tscProcessSql(SSqlObj *pSql);
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
** The following is the concatenation of all %include directives from the ** The following is the concatenation of all %include directives from the
** input grammar file: ** input grammar file:
*/ */
#pragma GCC diagnostic ignored "-Wunused-variable"
#include <stdio.h> #include <stdio.h>
/************ Begin %include sections from the grammar ************************/ /************ Begin %include sections from the grammar ************************/
...@@ -80,13 +78,15 @@ ...@@ -80,13 +78,15 @@
** defined, then do no error processing. ** defined, then do no error processing.
** YYNSTATE the combined number of states. ** YYNSTATE the combined number of states.
** YYNRULE the number of rules in the grammar ** YYNRULE the number of rules in the grammar
** YYNTOKEN Number of terminal symbols
** YY_MAX_SHIFT Maximum value for shift actions ** YY_MAX_SHIFT Maximum value for shift actions
** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
** YY_MAX_SHIFTREDUCE Maximum 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_ERROR_ACTION The yy_action[] code for syntax error
** YY_ACCEPT_ACTION The yy_action[] code for accept ** YY_ACCEPT_ACTION The yy_action[] code for accept
** YY_NO_ACTION The yy_action[] code for no-op ** 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 #ifndef INTERFACE
# define INTERFACE 1 # define INTERFACE 1
...@@ -99,12 +99,12 @@ ...@@ -99,12 +99,12 @@
typedef union { typedef union {
int yyinit; int yyinit;
ParseTOKENTYPE yy0; ParseTOKENTYPE yy0;
SSubclauseInfo* yy117;
SQuerySQL* yy138; SQuerySQL* yy138;
SCreateAcctSQL yy155; SCreateAcctSQL yy155;
SLimitVal yy162; SLimitVal yy162;
int yy220; int yy220;
tVariant yy236; tVariant yy236;
tSQLExprListList* yy237;
tSQLExpr* yy244; tSQLExpr* yy244;
SCreateDBInfo yy262; SCreateDBInfo yy262;
tSQLExprList* yy284; tSQLExprList* yy284;
...@@ -122,22 +122,19 @@ typedef union { ...@@ -122,22 +122,19 @@ typedef union {
#define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo
#define ParseARG_STORE yypParser->pInfo = pInfo #define ParseARG_STORE yypParser->pInfo = pInfo
#define YYFALLBACK 1 #define YYFALLBACK 1
#define YYNSTATE 252 #define YYNSTATE 241
#define YYNRULE 216 #define YYNRULE 213
#define YY_MAX_SHIFT 251 #define YYNTOKEN 197
#define YY_MIN_SHIFTREDUCE 403 #define YY_MAX_SHIFT 240
#define YY_MAX_SHIFTREDUCE 618 #define YY_MIN_SHIFTREDUCE 391
#define YY_MIN_REDUCE 619 #define YY_MAX_SHIFTREDUCE 603
#define YY_MAX_REDUCE 834 #define YY_ERROR_ACTION 604
#define YY_ERROR_ACTION 835 #define YY_ACCEPT_ACTION 605
#define YY_ACCEPT_ACTION 836 #define YY_NO_ACTION 606
#define YY_NO_ACTION 837 #define YY_MIN_REDUCE 607
#define YY_MAX_REDUCE 819
/************* End control #defines *******************************************/ /************* 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 /* Define the yytestcase() macro to be a no-op if is not already defined
** otherwise. ** otherwise.
** **
...@@ -165,9 +162,6 @@ static const YYMINORTYPE yyzerominor = { 0 }; ...@@ -165,9 +162,6 @@ static const YYMINORTYPE yyzerominor = { 0 };
** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. ** 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_ERROR_ACTION A syntax error has occurred.
** **
** N == YY_ACCEPT_ACTION The parser accepts its input. ** N == YY_ACCEPT_ACTION The parser accepts its input.
...@@ -175,21 +169,22 @@ static const YYMINORTYPE yyzerominor = { 0 }; ...@@ -175,21 +169,22 @@ static const YYMINORTYPE yyzerominor = { 0 };
** N == YY_NO_ACTION No such action. Denotes unused ** N == YY_NO_ACTION No such action. Denotes unused
** slots in the yy_action[] table. ** 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[]. ** 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 ** The (A) formula is preferred. The B formula is used instead if
** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
** 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 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 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 ** 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 ** the yy_shift_ofst[] array.
** YY_SHIFT_USE_DFLT.
** **
** The following are the tables generated in this section: ** The following are the tables generated in this section:
** **
...@@ -203,198 +198,209 @@ static const YYMINORTYPE yyzerominor = { 0 }; ...@@ -203,198 +198,209 @@ static const YYMINORTYPE yyzerominor = { 0 };
** yy_default[] Default action for each state. ** yy_default[] Default action for each state.
** **
*********** Begin parsing tables **********************************************/ *********** Begin parsing tables **********************************************/
#define YY_ACTTAB_COUNT (531) #define YY_ACTTAB_COUNT (516)
static const YYACTIONTYPE yy_action[] = { static const YYACTIONTYPE yy_action[] = {
/* 0 */ 443, 74, 78, 244, 85, 77, 153, 249, 444, 836, /* 0 */ 738, 431, 129, 147, 238, 10, 605, 240, 129, 432,
/* 10 */ 251, 80, 43, 45, 7, 37, 38, 62, 111, 171, /* 10 */ 129, 151, 807, 40, 42, 19, 34, 35, 806, 150,
/* 20 */ 31, 443, 443, 205, 41, 39, 42, 40, 241, 444, /* 20 */ 807, 28, 128, 431, 194, 38, 36, 39, 37, 133,
/* 30 */ 444, 135, 36, 35, 10, 101, 34, 33, 32, 43, /* 30 */ 490, 432, 93, 33, 32, 97, 803, 31, 30, 29,
/* 40 */ 45, 600, 37, 38, 156, 524, 135, 31, 135, 133, /* 40 */ 40, 42, 729, 34, 35, 148, 802, 159, 28, 715,
/* 50 */ 205, 41, 39, 42, 40, 159, 601, 158, 601, 36, /* 50 */ 735, 194, 38, 36, 39, 37, 181, 97, 219, 218,
/* 60 */ 35, 154, 514, 34, 33, 32, 404, 405, 406, 407, /* 60 */ 33, 32, 158, 718, 31, 30, 29, 392, 393, 394,
/* 70 */ 408, 409, 410, 411, 412, 413, 414, 415, 250, 21, /* 70 */ 395, 396, 397, 398, 399, 400, 401, 402, 403, 239,
/* 80 */ 43, 45, 172, 37, 38, 227, 226, 202, 31, 59, /* 80 */ 718, 40, 42, 182, 34, 35, 209, 230, 191, 28,
/* 90 */ 21, 205, 41, 39, 42, 40, 34, 33, 32, 57, /* 90 */ 56, 19, 194, 38, 36, 39, 37, 31, 30, 29,
/* 100 */ 36, 35, 550, 551, 34, 33, 32, 45, 232, 37, /* 100 */ 54, 33, 32, 801, 718, 31, 30, 29, 42, 517,
/* 110 */ 38, 167, 132, 511, 31, 21, 21, 205, 41, 39, /* 110 */ 34, 35, 762, 16, 189, 28, 19, 19, 194, 38,
/* 120 */ 42, 40, 168, 569, 511, 502, 36, 35, 134, 178, /* 120 */ 36, 39, 37, 160, 559, 715, 221, 33, 32, 145,
/* 130 */ 34, 33, 32, 243, 37, 38, 186, 512, 183, 31, /* 130 */ 170, 31, 30, 29, 232, 34, 35, 178, 7, 175,
/* 140 */ 532, 101, 205, 41, 39, 42, 40, 228, 233, 511, /* 140 */ 28, 59, 107, 194, 38, 36, 39, 37, 217, 222,
/* 150 */ 511, 36, 35, 230, 229, 34, 33, 32, 17, 219, /* 150 */ 715, 715, 33, 32, 146, 716, 31, 30, 29, 15,
/* 160 */ 242, 218, 217, 216, 215, 214, 213, 212, 211, 496, /* 160 */ 208, 231, 207, 206, 205, 204, 203, 202, 201, 200,
/* 170 */ 139, 485, 486, 487, 488, 489, 490, 491, 492, 493, /* 170 */ 700, 19, 689, 690, 691, 692, 693, 694, 695, 696,
/* 180 */ 494, 495, 163, 582, 11, 97, 573, 133, 576, 529, /* 180 */ 697, 698, 699, 155, 572, 431, 703, 563, 702, 566,
/* 190 */ 579, 597, 163, 582, 166, 556, 573, 200, 576, 155, /* 190 */ 565, 569, 568, 432, 38, 36, 39, 37, 237, 236,
/* 200 */ 579, 36, 35, 148, 220, 34, 33, 32, 21, 87, /* 200 */ 414, 11, 33, 32, 232, 714, 31, 30, 29, 110,
/* 210 */ 86, 142, 514, 243, 160, 161, 101, 147, 204, 248, /* 210 */ 111, 213, 62, 65, 134, 152, 153, 155, 572, 193,
/* 220 */ 247, 426, 514, 76, 160, 161, 163, 582, 530, 241, /* 220 */ 142, 563, 97, 566, 58, 569, 84, 83, 136, 163,
/* 230 */ 573, 101, 576, 513, 579, 193, 41, 39, 42, 40, /* 230 */ 506, 231, 97, 503, 141, 504, 26, 505, 71, 75,
/* 240 */ 242, 596, 510, 27, 36, 35, 49, 571, 34, 33, /* 240 */ 233, 82, 74, 124, 122, 234, 86, 85, 77, 152,
/* 250 */ 32, 114, 115, 224, 65, 68, 505, 441, 160, 161, /* 250 */ 153, 155, 572, 520, 564, 563, 567, 566, 709, 569,
/* 260 */ 124, 192, 518, 50, 188, 515, 499, 516, 498, 517, /* 260 */ 25, 161, 162, 46, 33, 32, 73, 154, 31, 30,
/* 270 */ 555, 150, 128, 126, 245, 89, 88, 44, 450, 442, /* 270 */ 29, 645, 230, 561, 120, 540, 541, 761, 41, 180,
/* 280 */ 61, 124, 124, 572, 595, 60, 581, 44, 575, 527, /* 280 */ 135, 47, 654, 152, 153, 120, 144, 57, 571, 646,
/* 290 */ 578, 28, 18, 169, 170, 605, 581, 162, 606, 29, /* 290 */ 164, 49, 120, 216, 215, 531, 532, 589, 573, 44,
/* 300 */ 541, 580, 29, 542, 47, 52, 599, 15, 151, 583, /* 300 */ 13, 12, 12, 570, 2, 137, 496, 50, 138, 562,
/* 310 */ 14, 580, 574, 14, 577, 508, 73, 72, 507, 47, /* 310 */ 44, 495, 41, 139, 198, 20, 717, 510, 20, 511,
/* 320 */ 53, 44, 22, 209, 522, 152, 523, 22, 140, 520, /* 320 */ 140, 508, 571, 509, 81, 80, 131, 70, 69, 127,
/* 330 */ 581, 521, 9, 8, 2, 84, 83, 141, 143, 144, /* 330 */ 507, 9, 8, 132, 816, 130, 772, 570, 771, 156,
/* 340 */ 145, 615, 146, 137, 131, 580, 138, 136, 531, 566, /* 340 */ 768, 767, 157, 220, 737, 754, 41, 94, 753, 108,
/* 350 */ 98, 565, 164, 562, 561, 165, 231, 548, 547, 189, /* 350 */ 109, 106, 656, 199, 125, 23, 571, 212, 25, 214,
/* 360 */ 112, 113, 519, 452, 110, 210, 129, 25, 191, 223, /* 360 */ 815, 67, 814, 730, 88, 812, 112, 527, 674, 24,
/* 370 */ 225, 614, 70, 613, 611, 116, 470, 26, 23, 130, /* 370 */ 183, 570, 21, 126, 643, 187, 76, 641, 78, 639,
/* 380 */ 439, 91, 79, 437, 81, 435, 434, 537, 194, 198, /* 380 */ 51, 638, 165, 728, 121, 48, 98, 636, 635, 634,
/* 390 */ 173, 54, 125, 432, 431, 430, 428, 421, 525, 127, /* 390 */ 632, 43, 625, 123, 629, 99, 627, 192, 741, 742,
/* 400 */ 425, 51, 423, 102, 46, 203, 103, 104, 95, 199, /* 400 */ 190, 188, 186, 184, 27, 755, 211, 72, 223, 224,
/* 410 */ 201, 535, 197, 30, 536, 549, 195, 27, 222, 75, /* 410 */ 225, 226, 227, 228, 100, 196, 229, 52, 235, 603,
/* 420 */ 234, 235, 236, 237, 207, 55, 238, 239, 240, 246, /* 420 */ 166, 167, 143, 169, 60, 63, 168, 637, 602, 171,
/* 430 */ 149, 618, 63, 66, 175, 433, 174, 176, 177, 617, /* 430 */ 87, 172, 173, 174, 115, 631, 114, 675, 113, 116,
/* 440 */ 180, 427, 119, 90, 118, 471, 117, 120, 122, 121, /* 440 */ 117, 119, 118, 89, 1, 713, 103, 101, 22, 102,
/* 450 */ 123, 92, 509, 1, 24, 182, 107, 105, 106, 108, /* 450 */ 104, 105, 601, 176, 177, 594, 179, 92, 55, 528,
/* 460 */ 109, 179, 181, 616, 184, 185, 12, 609, 190, 187, /* 460 */ 95, 149, 185, 4, 533, 5, 96, 61, 3, 17,
/* 470 */ 13, 157, 96, 538, 99, 196, 58, 4, 19, 543, /* 470 */ 574, 471, 18, 14, 195, 6, 197, 470, 469, 468,
/* 480 */ 100, 5, 584, 3, 20, 16, 206, 6, 208, 64, /* 480 */ 467, 466, 465, 464, 462, 44, 435, 64, 437, 66,
/* 490 */ 483, 482, 481, 480, 479, 478, 477, 476, 474, 47, /* 490 */ 20, 210, 492, 491, 489, 53, 456, 45, 454, 446,
/* 500 */ 447, 449, 67, 22, 504, 221, 503, 501, 56, 468, /* 500 */ 68, 452, 448, 450, 444, 442, 463, 461, 79, 417,
/* 510 */ 466, 48, 458, 464, 69, 460, 462, 456, 454, 475, /* 510 */ 433, 90, 407, 91, 405, 607,
/* 520 */ 71, 473, 82, 429, 445, 419, 417, 93, 619, 621,
/* 530 */ 94,
}; };
static const YYCODETYPE yy_lookahead[] = { static const YYCODETYPE yy_lookahead[] = {
/* 0 */ 1, 64, 65, 66, 67, 68, 199, 200, 9, 197, /* 0 */ 201, 1, 250, 200, 201, 250, 198, 199, 250, 9,
/* 10 */ 198, 74, 13, 14, 96, 16, 17, 99, 100, 63, /* 10 */ 250, 259, 260, 13, 14, 201, 16, 17, 260, 259,
/* 20 */ 21, 1, 1, 24, 25, 26, 27, 28, 78, 9, /* 20 */ 260, 21, 250, 1, 24, 25, 26, 27, 28, 250,
/* 30 */ 9, 248, 33, 34, 248, 200, 37, 38, 39, 13, /* 30 */ 5, 9, 201, 33, 34, 201, 250, 37, 38, 39,
/* 40 */ 14, 258, 16, 17, 217, 233, 248, 21, 248, 248, /* 40 */ 13, 14, 234, 16, 17, 218, 250, 233, 21, 235,
/* 50 */ 24, 25, 26, 27, 28, 257, 258, 257, 258, 33, /* 50 */ 251, 24, 25, 26, 27, 28, 248, 201, 33, 34,
/* 60 */ 34, 260, 235, 37, 38, 39, 45, 46, 47, 48, /* 60 */ 33, 34, 218, 236, 37, 38, 39, 45, 46, 47,
/* 70 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 200, /* 70 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
/* 80 */ 13, 14, 126, 16, 17, 129, 130, 252, 21, 254, /* 80 */ 236, 13, 14, 252, 16, 17, 218, 78, 254, 21,
/* 90 */ 200, 24, 25, 26, 27, 28, 37, 38, 39, 100, /* 90 */ 256, 201, 24, 25, 26, 27, 28, 37, 38, 39,
/* 100 */ 33, 34, 111, 112, 37, 38, 39, 14, 200, 16, /* 100 */ 100, 33, 34, 250, 236, 37, 38, 39, 14, 101,
/* 110 */ 17, 232, 248, 234, 21, 200, 200, 24, 25, 26, /* 110 */ 16, 17, 256, 105, 258, 21, 201, 201, 24, 25,
/* 120 */ 27, 28, 232, 97, 234, 5, 33, 34, 248, 125, /* 120 */ 26, 27, 28, 233, 97, 235, 201, 33, 34, 250,
/* 130 */ 37, 38, 39, 60, 16, 17, 132, 229, 134, 21, /* 130 */ 123, 37, 38, 39, 60, 16, 17, 130, 96, 132,
/* 140 */ 200, 200, 24, 25, 26, 27, 28, 232, 232, 234, /* 140 */ 21, 99, 100, 24, 25, 26, 27, 28, 233, 233,
/* 150 */ 234, 33, 34, 33, 34, 37, 38, 39, 85, 86, /* 150 */ 235, 235, 33, 34, 250, 230, 37, 38, 39, 85,
/* 160 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 216, /* 160 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
/* 170 */ 248, 218, 219, 220, 221, 222, 223, 224, 225, 226, /* 170 */ 217, 201, 219, 220, 221, 222, 223, 224, 225, 226,
/* 180 */ 227, 228, 1, 2, 44, 200, 5, 248, 7, 249, /* 180 */ 227, 228, 229, 1, 2, 1, 219, 5, 221, 7,
/* 190 */ 9, 248, 1, 2, 217, 254, 5, 256, 7, 260, /* 190 */ 5, 9, 7, 9, 25, 26, 27, 28, 60, 61,
/* 200 */ 9, 33, 34, 63, 217, 37, 38, 39, 200, 69, /* 200 */ 62, 44, 33, 34, 60, 235, 37, 38, 39, 64,
/* 210 */ 70, 71, 235, 60, 33, 34, 200, 77, 37, 60, /* 210 */ 65, 66, 67, 68, 250, 33, 34, 1, 2, 37,
/* 220 */ 61, 62, 235, 72, 33, 34, 1, 2, 37, 78, /* 220 */ 63, 5, 201, 7, 237, 9, 69, 70, 71, 63,
/* 230 */ 5, 200, 7, 235, 9, 250, 25, 26, 27, 28, /* 230 */ 2, 87, 201, 5, 77, 7, 249, 9, 64, 65,
/* 240 */ 87, 248, 234, 103, 33, 34, 101, 1, 37, 38, /* 240 */ 66, 67, 68, 64, 65, 66, 67, 68, 74, 33,
/* 250 */ 39, 64, 65, 66, 67, 68, 231, 204, 33, 34, /* 250 */ 34, 1, 2, 37, 5, 5, 7, 7, 232, 9,
/* 260 */ 207, 121, 2, 118, 124, 5, 218, 7, 220, 9, /* 260 */ 103, 33, 34, 101, 33, 34, 72, 59, 37, 38,
/* 270 */ 254, 131, 64, 65, 66, 67, 68, 96, 204, 204, /* 270 */ 39, 205, 78, 1, 208, 112, 113, 256, 96, 122,
/* 280 */ 236, 207, 207, 37, 248, 254, 105, 96, 5, 101, /* 280 */ 250, 119, 205, 33, 34, 208, 129, 256, 106, 205,
/* 290 */ 7, 247, 104, 33, 34, 97, 105, 59, 97, 101, /* 290 */ 124, 101, 208, 127, 128, 97, 97, 97, 97, 101,
/* 300 */ 97, 120, 101, 97, 101, 101, 97, 101, 248, 97, /* 300 */ 101, 101, 101, 121, 96, 250, 97, 117, 250, 37,
/* 310 */ 101, 120, 5, 101, 7, 97, 127, 128, 97, 101, /* 310 */ 101, 97, 96, 250, 97, 101, 236, 5, 101, 7,
/* 320 */ 116, 96, 101, 97, 5, 248, 7, 101, 248, 5, /* 320 */ 250, 5, 106, 7, 72, 73, 250, 125, 126, 250,
/* 330 */ 105, 7, 127, 128, 96, 72, 73, 248, 248, 248, /* 330 */ 102, 125, 126, 250, 236, 250, 231, 121, 231, 231,
/* 340 */ 248, 235, 248, 248, 248, 120, 248, 248, 200, 230, /* 340 */ 231, 231, 231, 231, 201, 257, 96, 201, 257, 201,
/* 350 */ 200, 230, 230, 230, 230, 230, 230, 255, 255, 123, /* 350 */ 201, 238, 201, 201, 201, 201, 106, 201, 103, 201,
/* 360 */ 200, 200, 102, 200, 237, 200, 200, 200, 259, 200, /* 360 */ 201, 201, 201, 234, 59, 201, 201, 106, 201, 201,
/* 370 */ 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, /* 370 */ 253, 121, 201, 201, 201, 253, 201, 201, 201, 201,
/* 380 */ 200, 59, 200, 200, 200, 200, 200, 105, 251, 251, /* 380 */ 116, 201, 201, 247, 201, 118, 246, 201, 201, 201,
/* 390 */ 200, 115, 200, 200, 200, 200, 200, 200, 246, 200, /* 390 */ 201, 115, 201, 201, 201, 245, 201, 110, 202, 202,
/* 400 */ 200, 117, 200, 245, 114, 109, 244, 243, 201, 108, /* 400 */ 114, 109, 108, 107, 120, 202, 75, 84, 83, 49,
/* 410 */ 113, 201, 107, 119, 201, 201, 106, 103, 75, 84, /* 410 */ 80, 82, 53, 81, 244, 202, 79, 202, 75, 5,
/* 420 */ 83, 49, 80, 82, 201, 201, 53, 81, 79, 75, /* 420 */ 131, 5, 202, 58, 206, 206, 131, 202, 5, 131,
/* 430 */ 201, 5, 205, 205, 5, 201, 133, 133, 58, 5, /* 430 */ 203, 5, 131, 58, 210, 202, 214, 216, 215, 213,
/* 440 */ 5, 201, 209, 202, 213, 215, 214, 212, 211, 210, /* 440 */ 211, 209, 212, 203, 207, 234, 241, 243, 204, 242,
/* 450 */ 208, 202, 233, 206, 203, 58, 240, 242, 241, 239, /* 450 */ 240, 239, 5, 131, 58, 86, 123, 104, 101, 97,
/* 460 */ 238, 133, 133, 5, 133, 58, 96, 86, 123, 125, /* 460 */ 96, 1, 96, 111, 97, 111, 96, 72, 96, 101,
/* 470 */ 96, 1, 122, 97, 96, 96, 101, 110, 101, 97, /* 470 */ 97, 9, 101, 96, 98, 96, 98, 5, 5, 5,
/* 480 */ 96, 110, 97, 96, 101, 96, 98, 96, 98, 72, /* 480 */ 5, 1, 5, 5, 5, 101, 76, 72, 58, 126,
/* 490 */ 9, 5, 5, 5, 5, 1, 5, 5, 5, 101, /* 490 */ 101, 15, 5, 5, 97, 96, 5, 16, 5, 5,
/* 500 */ 76, 58, 72, 101, 5, 15, 5, 97, 96, 5, /* 500 */ 126, 5, 5, 5, 5, 5, 5, 5, 58, 58,
/* 510 */ 5, 16, 5, 5, 128, 5, 5, 5, 5, 5, /* 510 */ 76, 21, 59, 21, 58, 0, 261, 261, 261, 261,
/* 520 */ 128, 5, 58, 58, 76, 59, 58, 21, 0, 261, /* 520 */ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261,
/* 530 */ 21, /* 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 (240)
#define YY_SHIFT_COUNT (251) #define YY_SHIFT_MIN (0)
#define YY_SHIFT_MIN (-82) #define YY_SHIFT_MAX (515)
#define YY_SHIFT_MAX (528) static const unsigned short int yy_shift_ofst[] = {
static const short yy_shift_ofst[] = { /* 0 */ 157, 74, 182, 250, 184, 184, 184, 184, 184, 184,
/* 0 */ 140, 73, 181, 225, 20, 20, 20, 20, 20, 20, /* 10 */ 0, 22, 250, 228, 228, 228, 184, 184, 184, 184,
/* 10 */ -1, 21, 225, 225, 225, 260, 260, 260, 20, 20, /* 20 */ 184, 194, 144, 9, 9, 516, 216, 250, 250, 250,
/* 20 */ 20, 20, 20, 151, 153, -50, -50, -83, 191, 225, /* 30 */ 250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
/* 30 */ 225, 225, 225, 225, 225, 225, 225, 225, 225, 225, /* 40 */ 250, 250, 250, 250, 228, 228, 25, 25, 25, 25,
/* 40 */ 225, 225, 225, 225, 225, 225, 225, 260, 260, 120, /* 50 */ 25, 25, 42, 25, 184, 184, 163, 163, 8, 184,
/* 50 */ 120, 120, 120, 120, 120, -82, 120, 20, 20, -9, /* 60 */ 184, 184, 184, 184, 184, 184, 184, 184, 184, 184,
/* 60 */ -9, 188, 20, 20, 20, 20, 20, 20, 20, 20, /* 70 */ 184, 184, 184, 184, 184, 184, 184, 184, 184, 184,
/* 70 */ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, /* 80 */ 184, 184, 184, 184, 184, 184, 184, 184, 184, 184,
/* 80 */ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, /* 90 */ 184, 184, 255, 305, 305, 261, 261, 305, 264, 267,
/* 90 */ 20, 20, 20, 20, 20, 236, 322, 322, 322, 282, /* 100 */ 276, 287, 286, 292, 294, 296, 284, 255, 305, 305,
/* 100 */ 282, 322, 276, 284, 290, 296, 297, 301, 305, 310, /* 110 */ 331, 331, 305, 323, 325, 360, 330, 329, 359, 332,
/* 110 */ 294, 314, 322, 322, 343, 343, 322, 335, 337, 372, /* 120 */ 337, 305, 343, 305, 343, 516, 516, 27, 68, 68,
/* 120 */ 342, 341, 373, 346, 349, 322, 354, 322, 354, -83, /* 130 */ 68, 94, 119, 169, 169, 169, 174, 231, 231, 231,
/* 130 */ -83, 26, 67, 67, 67, 67, 67, 93, 118, 211, /* 140 */ 231, 145, 179, 166, 7, 60, 60, 138, 198, 199,
/* 140 */ 211, 211, -63, 168, 168, 168, 168, 187, 208, -44, /* 150 */ 200, 201, 185, 249, 272, 208, 162, 190, 209, 214,
/* 150 */ 4, 59, 59, 159, 198, 201, 203, 206, 209, 212, /* 160 */ 217, 312, 316, 202, 206, 252, 414, 289, 416, 295,
/* 160 */ 283, 307, 246, 238, 145, 204, 218, 221, 226, 319, /* 170 */ 365, 423, 298, 426, 301, 375, 447, 322, 396, 369,
/* 170 */ 324, 189, 205, 263, 426, 303, 429, 304, 380, 434, /* 180 */ 333, 353, 357, 362, 364, 460, 366, 367, 370, 368,
/* 180 */ 328, 435, 329, 397, 458, 331, 407, 381, 344, 370, /* 190 */ 352, 371, 354, 373, 372, 377, 376, 379, 378, 395,
/* 190 */ 374, 345, 350, 375, 376, 378, 470, 379, 382, 384, /* 200 */ 462, 472, 473, 474, 475, 480, 477, 478, 479, 384,
/* 200 */ 377, 367, 383, 371, 385, 387, 389, 388, 391, 390, /* 210 */ 410, 476, 415, 430, 481, 363, 374, 389, 487, 488,
/* 210 */ 417, 481, 486, 487, 488, 489, 494, 491, 492, 493, /* 220 */ 397, 399, 389, 491, 493, 494, 496, 497, 498, 499,
/* 220 */ 398, 424, 490, 430, 443, 495, 386, 392, 402, 499, /* 230 */ 500, 501, 502, 450, 451, 434, 490, 492, 453, 456,
/* 230 */ 501, 410, 412, 402, 504, 505, 507, 508, 510, 511, /* 240 */ 515,
/* 240 */ 512, 513, 514, 516, 464, 465, 448, 506, 509, 466,
/* 250 */ 468, 528,
}; };
#define YY_REDUCE_USE_DFLT (-218) #define YY_REDUCE_COUNT (126)
#define YY_REDUCE_COUNT (130) #define YY_REDUCE_MIN (-248)
#define YY_REDUCE_MIN (-217) #define YY_REDUCE_MAX (244)
#define YY_REDUCE_MAX (251)
static const short yy_reduce_ofst[] = { static const short yy_reduce_ofst[] = {
/* 0 */ -188, -47, -202, -200, -59, -165, -121, -110, -85, -84, /* 0 */ -192, -47, -248, -240, -144, -166, -186, -110, -85, -84,
/* 10 */ -60, -193, -199, -61, -217, -173, -23, -13, -15, 16, /* 10 */ -201, -197, -242, -173, -156, -132, -169, 21, 31, -75,
/* 20 */ 31, -92, 8, 53, 48, 74, 75, 44, -214, -136, /* 20 */ -30, 66, -33, 77, 84, -13, -245, -228, -221, -214,
/* 30 */ -120, -78, -57, -7, 36, 60, 77, 80, 89, 90, /* 30 */ -204, -147, -121, -96, -36, 30, 55, 58, 63, 70,
/* 40 */ 91, 92, 94, 95, 96, 98, 99, -2, 106, 119, /* 40 */ 76, 79, 83, 85, 80, 98, 105, 107, 108, 109,
/* 50 */ 121, 122, 123, 124, 125, 25, 126, 148, 150, 102, /* 50 */ 110, 111, 26, 112, 143, 146, 88, 91, 113, 148,
/* 60 */ 103, 127, 160, 161, 163, 165, 166, 167, 169, 170, /* 60 */ 149, 151, 152, 153, 154, 156, 158, 159, 160, 161,
/* 70 */ 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, /* 70 */ 164, 165, 167, 168, 171, 172, 173, 175, 176, 177,
/* 80 */ 182, 183, 184, 185, 186, 190, 192, 193, 194, 195, /* 80 */ 178, 180, 181, 183, 186, 187, 188, 189, 191, 192,
/* 90 */ 196, 197, 199, 200, 202, 109, 207, 210, 213, 137, /* 90 */ 193, 195, 129, 196, 197, 117, 122, 203, 136, 140,
/* 100 */ 138, 214, 152, 158, 162, 164, 215, 217, 216, 220, /* 100 */ 150, 170, 204, 207, 205, 210, 212, 211, 213, 215,
/* 110 */ 222, 219, 223, 224, 227, 228, 229, 230, 232, 231, /* 110 */ 218, 219, 220, 221, 223, 222, 224, 226, 229, 230,
/* 120 */ 233, 235, 239, 237, 242, 234, 241, 240, 249, 247, /* 120 */ 232, 225, 227, 233, 240, 237, 244,
/* 130 */ 251,
}; };
static const YYACTIONTYPE yy_default[] = { static const YYACTIONTYPE yy_default[] = {
/* 0 */ 835, 667, 819, 819, 835, 835, 835, 835, 835, 835, /* 0 */ 604, 655, 809, 809, 604, 604, 604, 604, 604, 604,
/* 10 */ 749, 634, 835, 835, 819, 835, 835, 835, 835, 835, /* 10 */ 739, 622, 809, 604, 604, 604, 604, 604, 604, 604,
/* 20 */ 835, 835, 835, 669, 656, 669, 669, 744, 835, 835, /* 20 */ 604, 657, 644, 657, 657, 734, 604, 604, 604, 604,
/* 30 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, /* 30 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604,
/* 40 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, /* 40 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604,
/* 50 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 768, /* 50 */ 604, 604, 604, 604, 604, 604, 758, 758, 732, 604,
/* 60 */ 768, 742, 835, 835, 835, 835, 835, 835, 835, 835, /* 60 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604,
/* 70 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 654, /* 70 */ 604, 604, 604, 604, 604, 604, 642, 604, 640, 604,
/* 80 */ 835, 652, 835, 835, 835, 835, 835, 835, 835, 835, /* 80 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604,
/* 90 */ 835, 835, 835, 835, 835, 835, 636, 636, 636, 835, /* 90 */ 604, 604, 604, 624, 624, 604, 604, 624, 765, 769,
/* 100 */ 835, 636, 775, 779, 773, 761, 769, 760, 756, 755, /* 100 */ 763, 751, 759, 750, 746, 745, 773, 604, 624, 624,
/* 110 */ 783, 835, 636, 636, 664, 664, 636, 685, 683, 681, /* 110 */ 652, 652, 624, 673, 671, 669, 661, 667, 663, 665,
/* 120 */ 673, 679, 675, 677, 671, 636, 662, 636, 662, 700, /* 120 */ 659, 624, 650, 624, 650, 688, 701, 604, 774, 808,
/* 130 */ 713, 835, 823, 824, 784, 818, 774, 802, 801, 814, /* 130 */ 764, 792, 791, 804, 798, 797, 604, 796, 795, 794,
/* 140 */ 808, 807, 835, 806, 805, 804, 803, 835, 835, 835, /* 140 */ 793, 604, 604, 604, 604, 800, 799, 604, 604, 604,
/* 150 */ 835, 810, 809, 835, 835, 835, 835, 835, 835, 835, /* 150 */ 604, 604, 604, 604, 604, 776, 770, 766, 604, 604,
/* 160 */ 835, 835, 835, 786, 780, 776, 835, 835, 835, 835, /* 160 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604,
/* 170 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, /* 170 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 604,
/* 180 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, /* 180 */ 604, 731, 740, 604, 604, 604, 604, 604, 604, 760,
/* 190 */ 835, 820, 835, 750, 835, 835, 835, 835, 835, 835, /* 190 */ 604, 752, 604, 604, 604, 604, 604, 604, 710, 604,
/* 200 */ 770, 835, 762, 835, 835, 835, 835, 835, 835, 722, /* 200 */ 604, 604, 604, 604, 604, 604, 604, 604, 604, 676,
/* 210 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, /* 210 */ 604, 604, 604, 604, 604, 604, 604, 813, 604, 604,
/* 220 */ 688, 835, 835, 835, 835, 835, 835, 835, 828, 835, /* 220 */ 604, 704, 811, 604, 604, 604, 604, 604, 604, 604,
/* 230 */ 835, 835, 716, 826, 835, 835, 835, 835, 835, 835, /* 230 */ 604, 604, 604, 604, 604, 604, 628, 626, 604, 620,
/* 240 */ 835, 835, 835, 835, 835, 835, 835, 640, 638, 835, /* 240 */ 604,
/* 250 */ 632, 835,
}; };
/********** End of lemon-generated parsing tables *****************************/ /********** End of lemon-generated parsing tables *****************************/
...@@ -518,6 +524,7 @@ static const YYCODETYPE yyFallback[] = { ...@@ -518,6 +524,7 @@ static const YYCODETYPE yyFallback[] = {
0, /* COMMA => nothing */ 0, /* COMMA => nothing */
1, /* NULL => ID */ 1, /* NULL => ID */
0, /* SELECT => nothing */ 0, /* SELECT => nothing */
0, /* UNION => nothing */
0, /* FROM => nothing */ 0, /* FROM => nothing */
0, /* VARIABLE => nothing */ 0, /* VARIABLE => nothing */
0, /* INTERVAL => nothing */ 0, /* INTERVAL => nothing */
...@@ -535,9 +542,6 @@ static const YYCODETYPE yyFallback[] = { ...@@ -535,9 +542,6 @@ static const YYCODETYPE yyFallback[] = {
0, /* SOFFSET => nothing */ 0, /* SOFFSET => nothing */
0, /* WHERE => nothing */ 0, /* WHERE => nothing */
1, /* NOW => ID */ 1, /* NOW => ID */
0, /* INSERT => nothing */
0, /* INTO => nothing */
0, /* VALUES => nothing */
0, /* RESET => nothing */ 0, /* RESET => nothing */
0, /* QUERY => nothing */ 0, /* QUERY => nothing */
0, /* ADD => nothing */ 0, /* ADD => nothing */
...@@ -610,6 +614,9 @@ static const YYCODETYPE yyFallback[] = { ...@@ -610,6 +614,9 @@ static const YYCODETYPE yyFallback[] = {
1, /* JOIN => ID */ 1, /* JOIN => ID */
1, /* METRICS => ID */ 1, /* METRICS => ID */
1, /* STABLE => ID */ 1, /* STABLE => ID */
1, /* INSERT => ID */
1, /* INTO => ID */
1, /* VALUES => ID */
}; };
#endif /* YYFALLBACK */ #endif /* YYFALLBACK */
...@@ -641,17 +648,21 @@ typedef struct yyStackEntry yyStackEntry; ...@@ -641,17 +648,21 @@ typedef struct yyStackEntry yyStackEntry;
/* The state of the parser is completely contained in an instance of /* The state of the parser is completely contained in an instance of
** the following structure */ ** the following structure */
struct yyParser { struct yyParser {
int yyidx; /* Index of top element in stack */ yyStackEntry *yytos; /* Pointer to top element of the stack */
#ifdef YYTRACKMAXSTACKDEPTH #ifdef YYTRACKMAXSTACKDEPTH
int yyidxMax; /* Maximum value of yyidx */ int yyhwm; /* High-water mark of the stack */
#endif #endif
#ifndef YYNOERRORRECOVERY
int yyerrcnt; /* Shifts left before out of the error */ int yyerrcnt; /* Shifts left before out of the error */
#endif
ParseARG_SDECL /* A place to hold %extra_argument */ ParseARG_SDECL /* A place to hold %extra_argument */
#if YYSTACKDEPTH<=0 #if YYSTACKDEPTH<=0
int yystksz; /* Current side of the stack */ int yystksz; /* Current side of the stack */
yyStackEntry *yystack; /* The parser's stack */ yyStackEntry *yystack; /* The parser's stack */
yyStackEntry yystk0; /* First stack entry */
#else #else
yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
yyStackEntry *yystackEnd; /* Last entry in the stack */
#endif #endif
}; };
typedef struct yyParser yyParser; typedef struct yyParser yyParser;
...@@ -688,78 +699,273 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ ...@@ -688,78 +699,273 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
} }
#endif /* NDEBUG */ #endif /* NDEBUG */
#ifndef NDEBUG #if defined(YYCOVERAGE) || !defined(NDEBUG)
/* For tracing shifts, the names of all terminals and nonterminals /* For tracing shifts, the names of all terminals and nonterminals
** are required. The following table supplies these names */ ** are required. The following table supplies these names */
static const char *const yyTokenName[] = { static const char *const yyTokenName[] = {
"$", "ID", "BOOL", "TINYINT", /* 0 */ "$",
"SMALLINT", "INTEGER", "BIGINT", "FLOAT", /* 1 */ "ID",
"DOUBLE", "STRING", "TIMESTAMP", "BINARY", /* 2 */ "BOOL",
"NCHAR", "OR", "AND", "NOT", /* 3 */ "TINYINT",
"EQ", "NE", "ISNULL", "NOTNULL", /* 4 */ "SMALLINT",
"IS", "LIKE", "GLOB", "BETWEEN", /* 5 */ "INTEGER",
"IN", "GT", "GE", "LT", /* 6 */ "BIGINT",
"LE", "BITAND", "BITOR", "LSHIFT", /* 7 */ "FLOAT",
"RSHIFT", "PLUS", "MINUS", "DIVIDE", /* 8 */ "DOUBLE",
"TIMES", "STAR", "SLASH", "REM", /* 9 */ "STRING",
"CONCAT", "UMINUS", "UPLUS", "BITNOT", /* 10 */ "TIMESTAMP",
"SHOW", "DATABASES", "MNODES", "DNODES", /* 11 */ "BINARY",
"ACCOUNTS", "USERS", "MODULES", "QUERIES", /* 12 */ "NCHAR",
"CONNECTIONS", "STREAMS", "CONFIGS", "SCORES", /* 13 */ "OR",
"GRANTS", "VNODES", "IPTOKEN", "DOT", /* 14 */ "AND",
"TABLES", "STABLES", "VGROUPS", "DROP", /* 15 */ "NOT",
"TABLE", "DATABASE", "DNODE", "USER", /* 16 */ "EQ",
"ACCOUNT", "USE", "DESCRIBE", "ALTER", /* 17 */ "NE",
"PASS", "PRIVILEGE", "LOCAL", "IF", /* 18 */ "ISNULL",
"EXISTS", "CREATE", "PPS", "TSERIES", /* 19 */ "NOTNULL",
"DBS", "STORAGE", "QTIME", "CONNS", /* 20 */ "IS",
"STATE", "KEEP", "CACHE", "REPLICA", /* 21 */ "LIKE",
"DAYS", "ROWS", "ABLOCKS", "TBLOCKS", /* 22 */ "GLOB",
"CTIME", "CLOG", "COMP", "PRECISION", /* 23 */ "BETWEEN",
"LP", "RP", "TAGS", "USING", /* 24 */ "IN",
"AS", "COMMA", "NULL", "SELECT", /* 25 */ "GT",
"FROM", "VARIABLE", "INTERVAL", "FILL", /* 26 */ "GE",
"SLIDING", "ORDER", "BY", "ASC", /* 27 */ "LT",
"DESC", "GROUP", "HAVING", "LIMIT", /* 28 */ "LE",
"OFFSET", "SLIMIT", "SOFFSET", "WHERE", /* 29 */ "BITAND",
"NOW", "INSERT", "INTO", "VALUES", /* 30 */ "BITOR",
"RESET", "QUERY", "ADD", "COLUMN", /* 31 */ "LSHIFT",
"TAG", "CHANGE", "SET", "KILL", /* 32 */ "RSHIFT",
"CONNECTION", "COLON", "STREAM", "ABORT", /* 33 */ "PLUS",
"AFTER", "ATTACH", "BEFORE", "BEGIN", /* 34 */ "MINUS",
"CASCADE", "CLUSTER", "CONFLICT", "COPY", /* 35 */ "DIVIDE",
"DEFERRED", "DELIMITERS", "DETACH", "EACH", /* 36 */ "TIMES",
"END", "EXPLAIN", "FAIL", "FOR", /* 37 */ "STAR",
"IGNORE", "IMMEDIATE", "INITIALLY", "INSTEAD", /* 38 */ "SLASH",
"MATCH", "KEY", "OF", "RAISE", /* 39 */ "REM",
"REPLACE", "RESTRICT", "ROW", "STATEMENT", /* 40 */ "CONCAT",
"TRIGGER", "VIEW", "ALL", "COUNT", /* 41 */ "UMINUS",
"SUM", "AVG", "MIN", "MAX", /* 42 */ "UPLUS",
"FIRST", "LAST", "TOP", "BOTTOM", /* 43 */ "BITNOT",
"STDDEV", "PERCENTILE", "APERCENTILE", "LEASTSQUARES", /* 44 */ "SHOW",
"HISTOGRAM", "DIFF", "SPREAD", "TWA", /* 45 */ "DATABASES",
"INTERP", "LAST_ROW", "SEMI", "NONE", /* 46 */ "MNODES",
"PREV", "LINEAR", "IMPORT", "METRIC", /* 47 */ "DNODES",
"TBNAME", "JOIN", "METRICS", "STABLE", /* 48 */ "ACCOUNTS",
"error", "program", "cmd", "dbPrefix", /* 49 */ "USERS",
"ids", "cpxName", "ifexists", "alter_db_optr", /* 50 */ "MODULES",
"acct_optr", "ifnotexists", "db_optr", "pps", /* 51 */ "QUERIES",
"tseries", "dbs", "streams", "storage", /* 52 */ "CONNECTIONS",
"qtime", "users", "conns", "state", /* 53 */ "STREAMS",
"keep", "tagitemlist", "tables", "cache", /* 54 */ "CONFIGS",
"replica", "days", "rows", "ablocks", /* 55 */ "SCORES",
"tblocks", "ctime", "clog", "comp", /* 56 */ "GRANTS",
"prec", "typename", "signed", "create_table_args", /* 57 */ "VNODES",
"columnlist", "select", "column", "tagitem", /* 58 */ "IPTOKEN",
"selcollist", "from", "where_opt", "interval_opt", /* 59 */ "DOT",
"fill_opt", "sliding_opt", "groupby_opt", "orderby_opt", /* 60 */ "TABLES",
"having_opt", "slimit_opt", "limit_opt", "sclp", /* 61 */ "STABLES",
"expr", "as", "tablelist", "tmvar", /* 62 */ "VGROUPS",
"sortlist", "sortitem", "item", "sortorder", /* 63 */ "DROP",
"grouplist", "exprlist", "expritem", "insert_value_list", /* 64 */ "TABLE",
"itemlist", /* 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 #ifndef NDEBUG
/* For tracing reduce actions, the names of all rules are required. /* For tracing reduce actions, the names of all rules are required.
...@@ -886,125 +1092,132 @@ static const char *const yyRuleName[] = { ...@@ -886,125 +1092,132 @@ static const char *const yyRuleName[] = {
/* 118 */ "tagitem ::= MINUS FLOAT", /* 118 */ "tagitem ::= MINUS FLOAT",
/* 119 */ "tagitem ::= PLUS INTEGER", /* 119 */ "tagitem ::= PLUS INTEGER",
/* 120 */ "tagitem ::= PLUS FLOAT", /* 120 */ "tagitem ::= PLUS FLOAT",
/* 121 */ "cmd ::= select", /* 121 */ "select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt",
/* 122 */ "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 */ "select ::= SELECT selcollist", /* 123 */ "union ::= union UNION select",
/* 124 */ "sclp ::= selcollist COMMA", /* 124 */ "cmd ::= union",
/* 125 */ "sclp ::=", /* 125 */ "select ::= SELECT selcollist",
/* 126 */ "selcollist ::= sclp expr as", /* 126 */ "sclp ::= selcollist COMMA",
/* 127 */ "selcollist ::= sclp STAR", /* 127 */ "sclp ::=",
/* 128 */ "as ::= AS ids", /* 128 */ "selcollist ::= sclp expr as",
/* 129 */ "as ::= ids", /* 129 */ "selcollist ::= sclp STAR",
/* 130 */ "as ::=", /* 130 */ "as ::= AS ids",
/* 131 */ "from ::= FROM tablelist", /* 131 */ "as ::= ids",
/* 132 */ "tablelist ::= ids cpxName", /* 132 */ "as ::=",
/* 133 */ "tablelist ::= tablelist COMMA ids cpxName", /* 133 */ "from ::= FROM tablelist",
/* 134 */ "tmvar ::= VARIABLE", /* 134 */ "tablelist ::= ids cpxName",
/* 135 */ "interval_opt ::= INTERVAL LP tmvar RP", /* 135 */ "tablelist ::= tablelist COMMA ids cpxName",
/* 136 */ "interval_opt ::=", /* 136 */ "tmvar ::= VARIABLE",
/* 137 */ "fill_opt ::=", /* 137 */ "interval_opt ::= INTERVAL LP tmvar RP",
/* 138 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", /* 138 */ "interval_opt ::=",
/* 139 */ "fill_opt ::= FILL LP ID RP", /* 139 */ "fill_opt ::=",
/* 140 */ "sliding_opt ::= SLIDING LP tmvar RP", /* 140 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP",
/* 141 */ "sliding_opt ::=", /* 141 */ "fill_opt ::= FILL LP ID RP",
/* 142 */ "orderby_opt ::=", /* 142 */ "sliding_opt ::= SLIDING LP tmvar RP",
/* 143 */ "orderby_opt ::= ORDER BY sortlist", /* 143 */ "sliding_opt ::=",
/* 144 */ "sortlist ::= sortlist COMMA item sortorder", /* 144 */ "orderby_opt ::=",
/* 145 */ "sortlist ::= item sortorder", /* 145 */ "orderby_opt ::= ORDER BY sortlist",
/* 146 */ "item ::= ids cpxName", /* 146 */ "sortlist ::= sortlist COMMA item sortorder",
/* 147 */ "sortorder ::= ASC", /* 147 */ "sortlist ::= item sortorder",
/* 148 */ "sortorder ::= DESC", /* 148 */ "item ::= ids cpxName",
/* 149 */ "sortorder ::=", /* 149 */ "sortorder ::= ASC",
/* 150 */ "groupby_opt ::=", /* 150 */ "sortorder ::= DESC",
/* 151 */ "groupby_opt ::= GROUP BY grouplist", /* 151 */ "sortorder ::=",
/* 152 */ "grouplist ::= grouplist COMMA item", /* 152 */ "groupby_opt ::=",
/* 153 */ "grouplist ::= item", /* 153 */ "groupby_opt ::= GROUP BY grouplist",
/* 154 */ "having_opt ::=", /* 154 */ "grouplist ::= grouplist COMMA item",
/* 155 */ "having_opt ::= HAVING expr", /* 155 */ "grouplist ::= item",
/* 156 */ "limit_opt ::=", /* 156 */ "having_opt ::=",
/* 157 */ "limit_opt ::= LIMIT signed", /* 157 */ "having_opt ::= HAVING expr",
/* 158 */ "limit_opt ::= LIMIT signed OFFSET signed", /* 158 */ "limit_opt ::=",
/* 159 */ "limit_opt ::= LIMIT signed COMMA signed", /* 159 */ "limit_opt ::= LIMIT signed",
/* 160 */ "slimit_opt ::=", /* 160 */ "limit_opt ::= LIMIT signed OFFSET signed",
/* 161 */ "slimit_opt ::= SLIMIT signed", /* 161 */ "limit_opt ::= LIMIT signed COMMA signed",
/* 162 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", /* 162 */ "slimit_opt ::=",
/* 163 */ "slimit_opt ::= SLIMIT signed COMMA signed", /* 163 */ "slimit_opt ::= SLIMIT signed",
/* 164 */ "where_opt ::=", /* 164 */ "slimit_opt ::= SLIMIT signed SOFFSET signed",
/* 165 */ "where_opt ::= WHERE expr", /* 165 */ "slimit_opt ::= SLIMIT signed COMMA signed",
/* 166 */ "expr ::= LP expr RP", /* 166 */ "where_opt ::=",
/* 167 */ "expr ::= ID", /* 167 */ "where_opt ::= WHERE expr",
/* 168 */ "expr ::= ID DOT ID", /* 168 */ "expr ::= LP expr RP",
/* 169 */ "expr ::= ID DOT STAR", /* 169 */ "expr ::= ID",
/* 170 */ "expr ::= INTEGER", /* 170 */ "expr ::= ID DOT ID",
/* 171 */ "expr ::= MINUS INTEGER", /* 171 */ "expr ::= ID DOT STAR",
/* 172 */ "expr ::= PLUS INTEGER", /* 172 */ "expr ::= INTEGER",
/* 173 */ "expr ::= FLOAT", /* 173 */ "expr ::= MINUS INTEGER",
/* 174 */ "expr ::= MINUS FLOAT", /* 174 */ "expr ::= PLUS INTEGER",
/* 175 */ "expr ::= PLUS FLOAT", /* 175 */ "expr ::= FLOAT",
/* 176 */ "expr ::= STRING", /* 176 */ "expr ::= MINUS FLOAT",
/* 177 */ "expr ::= NOW", /* 177 */ "expr ::= PLUS FLOAT",
/* 178 */ "expr ::= VARIABLE", /* 178 */ "expr ::= STRING",
/* 179 */ "expr ::= BOOL", /* 179 */ "expr ::= NOW",
/* 180 */ "expr ::= ID LP exprlist RP", /* 180 */ "expr ::= VARIABLE",
/* 181 */ "expr ::= ID LP STAR RP", /* 181 */ "expr ::= BOOL",
/* 182 */ "expr ::= expr AND expr", /* 182 */ "expr ::= ID LP exprlist RP",
/* 183 */ "expr ::= expr OR expr", /* 183 */ "expr ::= ID LP STAR RP",
/* 184 */ "expr ::= expr LT expr", /* 184 */ "expr ::= expr AND expr",
/* 185 */ "expr ::= expr GT expr", /* 185 */ "expr ::= expr OR expr",
/* 186 */ "expr ::= expr LE expr", /* 186 */ "expr ::= expr LT expr",
/* 187 */ "expr ::= expr GE expr", /* 187 */ "expr ::= expr GT expr",
/* 188 */ "expr ::= expr NE expr", /* 188 */ "expr ::= expr LE expr",
/* 189 */ "expr ::= expr EQ expr", /* 189 */ "expr ::= expr GE expr",
/* 190 */ "expr ::= expr PLUS expr", /* 190 */ "expr ::= expr NE expr",
/* 191 */ "expr ::= expr MINUS expr", /* 191 */ "expr ::= expr EQ expr",
/* 192 */ "expr ::= expr STAR expr", /* 192 */ "expr ::= expr PLUS expr",
/* 193 */ "expr ::= expr SLASH expr", /* 193 */ "expr ::= expr MINUS expr",
/* 194 */ "expr ::= expr REM expr", /* 194 */ "expr ::= expr STAR expr",
/* 195 */ "expr ::= expr LIKE expr", /* 195 */ "expr ::= expr SLASH expr",
/* 196 */ "expr ::= expr IN LP exprlist RP", /* 196 */ "expr ::= expr REM expr",
/* 197 */ "exprlist ::= exprlist COMMA expritem", /* 197 */ "expr ::= expr LIKE expr",
/* 198 */ "exprlist ::= expritem", /* 198 */ "expr ::= expr IN LP exprlist RP",
/* 199 */ "expritem ::= expr", /* 199 */ "exprlist ::= exprlist COMMA expritem",
/* 200 */ "expritem ::=", /* 200 */ "exprlist ::= expritem",
/* 201 */ "cmd ::= INSERT INTO cpxName insert_value_list", /* 201 */ "expritem ::= expr",
/* 202 */ "insert_value_list ::= VALUES LP itemlist RP", /* 202 */ "expritem ::=",
/* 203 */ "insert_value_list ::= insert_value_list VALUES LP itemlist RP", /* 203 */ "cmd ::= RESET QUERY CACHE",
/* 204 */ "itemlist ::= itemlist COMMA expr", /* 204 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist",
/* 205 */ "itemlist ::= expr", /* 205 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids",
/* 206 */ "cmd ::= RESET QUERY CACHE", /* 206 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist",
/* 207 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", /* 207 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids",
/* 208 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", /* 208 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids",
/* 209 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", /* 209 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem",
/* 210 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", /* 210 */ "cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER",
/* 211 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", /* 211 */ "cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER",
/* 212 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", /* 212 */ "cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER",
/* 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",
}; };
#endif /* NDEBUG */ #endif /* NDEBUG */
#if YYSTACKDEPTH<=0 #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 newSize;
int idx;
yyStackEntry *pNew; yyStackEntry *pNew;
newSize = p->yystksz*2 + 100; 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 ){ if( pNew ){
p->yystack = pNew; p->yystack = pNew;
p->yystksz = newSize; p->yytos = &p->yystack[idx];
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
yyTracePrompt, p->yystksz); yyTracePrompt, p->yystksz, newSize);
} }
#endif #endif
p->yystksz = newSize;
} }
return pNew==0;
} }
#endif #endif
...@@ -1017,6 +1230,34 @@ static void yyGrowStack(yyParser *p){ ...@@ -1017,6 +1230,34 @@ static void yyGrowStack(yyParser *p){
# define YYMALLOCARGTYPE size_t # define YYMALLOCARGTYPE size_t
#endif #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. ** This function allocates a new parser.
** The only argument is a pointer to a function which works like ** The only argument is a pointer to a function which works like
...@@ -1032,19 +1273,11 @@ static void yyGrowStack(yyParser *p){ ...@@ -1032,19 +1273,11 @@ static void yyGrowStack(yyParser *p){
void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
yyParser *pParser; yyParser *pParser;
pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
if( pParser ){ if( pParser ) ParseInit(pParser);
pParser->yyidx = -1;
#ifdef YYTRACKMAXSTACKDEPTH
pParser->yyidxMax = 0;
#endif
#if YYSTACKDEPTH<=0
pParser->yystack = NULL;
pParser->yystksz = 0;
yyGrowStack(pParser);
#endif
}
return pParser; return pParser;
} }
#endif /* Parse_ENGINEALWAYSONSTACK */
/* The following function deletes the "minor type" or semantic value /* The following function deletes the "minor type" or semantic value
** associated with a symbol. The symbol can be either a terminal ** associated with a symbol. The symbol can be either a terminal
...@@ -1071,44 +1304,48 @@ static void yy_destructor( ...@@ -1071,44 +1304,48 @@ static void yy_destructor(
** inside the C code. ** inside the C code.
*/ */
/********* Begin destructor definitions ***************************************/ /********* Begin destructor definitions ***************************************/
case 216: /* keep */ case 217: /* keep */
case 217: /* tagitemlist */ case 218: /* tagitemlist */
case 240: /* fill_opt */ case 241: /* fill_opt */
case 242: /* groupby_opt */ case 243: /* groupby_opt */
case 243: /* orderby_opt */ case 244: /* orderby_opt */
case 252: /* sortlist */ case 254: /* sortlist */
case 256: /* grouplist */ case 258: /* grouplist */
{ {
tVariantListDestroy((yypminor->yy480)); tVariantListDestroy((yypminor->yy480));
} }
break; break;
case 232: /* columnlist */ case 233: /* columnlist */
{ {
tFieldListDestroy((yypminor->yy421)); tFieldListDestroy((yypminor->yy421));
} }
break; break;
case 233: /* select */ case 234: /* select */
{ {
destroyQuerySql((yypminor->yy138)); doDestroyQuerySql((yypminor->yy138));
} }
break; break;
case 236: /* selcollist */ case 237: /* selcollist */
case 247: /* sclp */ case 249: /* sclp */
case 257: /* exprlist */ case 259: /* exprlist */
case 260: /* itemlist */
{ {
tSQLExprListDestroy((yypminor->yy284)); tSQLExprListDestroy((yypminor->yy284));
} }
break; break;
case 238: /* where_opt */ case 239: /* where_opt */
case 244: /* having_opt */ case 245: /* having_opt */
case 248: /* expr */ case 250: /* expr */
case 258: /* expritem */ case 260: /* expritem */
{ {
tSQLExprDestroy((yypminor->yy244)); tSQLExprDestroy((yypminor->yy244));
} }
break; break;
case 253: /* sortitem */ case 248: /* union */
{
destroyAllSelectClause((yypminor->yy117));
}
break;
case 255: /* sortitem */
{ {
tVariantDestroy(&(yypminor->yy236)); tVariantDestroy(&(yypminor->yy236));
} }
...@@ -1126,8 +1363,9 @@ tVariantDestroy(&(yypminor->yy236)); ...@@ -1126,8 +1363,9 @@ tVariantDestroy(&(yypminor->yy236));
*/ */
static void yy_pop_parser_stack(yyParser *pParser){ static void yy_pop_parser_stack(yyParser *pParser){
yyStackEntry *yytos; yyStackEntry *yytos;
assert( pParser->yyidx>=0 ); assert( pParser->yytos!=0 );
yytos = &pParser->yystack[pParser->yyidx--]; assert( pParser->yytos > pParser->yystack );
yytos = pParser->yytos--;
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sPopping %s\n", fprintf(yyTraceFILE,"%sPopping %s\n",
...@@ -1138,6 +1376,18 @@ static void yy_pop_parser_stack(yyParser *pParser){ ...@@ -1138,6 +1376,18 @@ static void yy_pop_parser_stack(yyParser *pParser){
yy_destructor(pParser, yytos->major, &yytos->minor); 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 ** Deallocate and destroy a parser. Destructors are called for
** all stack elements before shutting the parser down. ** all stack elements before shutting the parser down.
...@@ -1150,16 +1400,13 @@ void ParseFree( ...@@ -1150,16 +1400,13 @@ void ParseFree(
void *p, /* The parser to be deleted */ void *p, /* The parser to be deleted */
void (*freeProc)(void*) /* Function used to reclaim memory */ void (*freeProc)(void*) /* Function used to reclaim memory */
){ ){
yyParser *pParser = (yyParser*)p;
#ifndef YYPARSEFREENEVERNULL #ifndef YYPARSEFREENEVERNULL
if( pParser==0 ) return; if( p==0 ) return;
#endif
while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
#if YYSTACKDEPTH<=0
free(pParser->yystack);
#endif #endif
(*freeProc)((void*)pParser); ParseFinalize(p);
(*freeProc)(p);
} }
#endif /* Parse_ENGINEALWAYSONSTACK */
/* /*
** Return the peak depth of the stack for a parser. ** Return the peak depth of the stack for a parser.
...@@ -1167,7 +1414,44 @@ void ParseFree( ...@@ -1167,7 +1414,44 @@ void ParseFree(
#ifdef YYTRACKMAXSTACKDEPTH #ifdef YYTRACKMAXSTACKDEPTH
int ParseStackPeak(void *p){ int ParseStackPeak(void *p){
yyParser *pParser = (yyParser*)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; stateno<YYNSTATE; stateno++){
i = yy_shift_ofst[stateno];
for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
if( out ){
fprintf(out,"State %d lookahead %s %s\n", stateno,
yyTokenName[iLookAhead],
yycoverage[stateno][iLookAhead] ? "ok" : "missed");
}
}
}
return nMissed;
} }
#endif #endif
...@@ -1175,61 +1459,63 @@ int ParseStackPeak(void *p){ ...@@ -1175,61 +1459,63 @@ int ParseStackPeak(void *p){
** Find the appropriate action for a parser given the terminal ** Find the appropriate action for a parser given the terminal
** look-ahead token iLookAhead. ** look-ahead token iLookAhead.
*/ */
static int yy_find_shift_action( static unsigned int yy_find_shift_action(
yyParser *pParser, /* The parser */ yyParser *pParser, /* The parser */
YYCODETYPE iLookAhead /* The look-ahead token */ YYCODETYPE iLookAhead /* The look-ahead token */
){ ){
int i; int i;
int stateno = pParser->yystack[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 ); assert( stateno <= YY_SHIFT_COUNT );
#if defined(YYCOVERAGE)
yycoverage[stateno][iLookAhead] = 1;
#endif
do{ do{
i = yy_shift_ofst[stateno]; 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!=YYNOCODE );
assert( iLookAhead < YYNTOKEN );
i += iLookAhead; i += iLookAhead;
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ if( yy_lookahead[i]!=iLookAhead ){
if( iLookAhead>0 ){
#ifdef YYFALLBACK #ifdef YYFALLBACK
YYCODETYPE iFallback; /* Fallback token */ YYCODETYPE iFallback; /* Fallback token */
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
&& (iFallback = yyFallback[iLookAhead])!=0 ){ && (iFallback = yyFallback[iLookAhead])!=0 ){
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
}
#endif
assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
iLookAhead = iFallback;
continue;
} }
#endif
assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
iLookAhead = iFallback;
continue;
}
#endif #endif
#ifdef YYWILDCARD #ifdef YYWILDCARD
{ {
int j = i - iLookAhead + YYWILDCARD; int j = i - iLookAhead + YYWILDCARD;
if( if(
#if YY_SHIFT_MIN+YYWILDCARD<0 #if YY_SHIFT_MIN+YYWILDCARD<0
j>=0 && j>=0 &&
#endif #endif
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
j<YY_ACTTAB_COUNT && j<YY_ACTTAB_COUNT &&
#endif #endif
yy_lookahead[j]==YYWILDCARD yy_lookahead[j]==YYWILDCARD && iLookAhead>0
){ ){
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
yyTracePrompt, yyTokenName[iLookAhead], yyTracePrompt, yyTokenName[iLookAhead],
yyTokenName[YYWILDCARD]); yyTokenName[YYWILDCARD]);
}
#endif /* NDEBUG */
return yy_action[j];
} }
#endif /* NDEBUG */
return yy_action[j];
} }
#endif /* YYWILDCARD */
} }
#endif /* YYWILDCARD */
return yy_default[stateno]; return yy_default[stateno];
}else{ }else{
return yy_action[i]; return yy_action[i];
...@@ -1254,7 +1540,6 @@ static int yy_find_reduce_action( ...@@ -1254,7 +1540,6 @@ static int yy_find_reduce_action(
assert( stateno<=YY_REDUCE_COUNT ); assert( stateno<=YY_REDUCE_COUNT );
#endif #endif
i = yy_reduce_ofst[stateno]; i = yy_reduce_ofst[stateno];
assert( i!=YY_REDUCE_USE_DFLT );
assert( iLookAhead!=YYNOCODE ); assert( iLookAhead!=YYNOCODE );
i += iLookAhead; i += iLookAhead;
#ifdef YYERRORSYMBOL #ifdef YYERRORSYMBOL
...@@ -1271,15 +1556,14 @@ static int yy_find_reduce_action( ...@@ -1271,15 +1556,14 @@ static int yy_find_reduce_action(
/* /*
** The following routine is called if the stack overflows. ** The following routine is called if the stack overflows.
*/ */
static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ static void yyStackOverflow(yyParser *yypParser){
ParseARG_FETCH; ParseARG_FETCH;
yypParser->yyidx--;
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
} }
#endif #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 /* Here code is inserted which will execute if the parser
** stack every overflows */ ** stack every overflows */
/******** Begin %stack_overflow code ******************************************/ /******** Begin %stack_overflow code ******************************************/
...@@ -1291,20 +1575,21 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ ...@@ -1291,20 +1575,21 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
** Print tracing information for a SHIFT action ** Print tracing information for a SHIFT action
*/ */
#ifndef NDEBUG #ifndef NDEBUG
static void yyTraceShift(yyParser *yypParser, int yyNewState){ static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
if( yyTraceFILE ){ if( yyTraceFILE ){
if( yyNewState<YYNSTATE ){ if( yyNewState<YYNSTATE ){
fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n", fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major], yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
yyNewState); yyNewState);
}else{ }else{
fprintf(yyTraceFILE,"%sShift '%s'\n", fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]); yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
yyNewState - YY_MIN_REDUCE);
} }
} }
} }
#else #else
# define yyTraceShift(X,Y) # define yyTraceShift(X,Y,Z)
#endif #endif
/* /*
...@@ -1314,259 +1599,261 @@ static void yy_shift( ...@@ -1314,259 +1599,261 @@ static void yy_shift(
yyParser *yypParser, /* The parser to be shifted */ yyParser *yypParser, /* The parser to be shifted */
int yyNewState, /* The new state to shift in */ int yyNewState, /* The new state to shift in */
int yyMajor, /* The major token 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; yyStackEntry *yytos;
yypParser->yyidx++; yypParser->yytos++;
#ifdef YYTRACKMAXSTACKDEPTH #ifdef YYTRACKMAXSTACKDEPTH
if( yypParser->yyidx>yypParser->yyidxMax ){ if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
yypParser->yyidxMax = yypParser->yyidx; yypParser->yyhwm++;
assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
} }
#endif #endif
#if YYSTACKDEPTH>0 #if YYSTACKDEPTH>0
if( yypParser->yyidx>=YYSTACKDEPTH ){ if( yypParser->yytos>yypParser->yystackEnd ){
yyStackOverflow(yypParser, yypMinor); yypParser->yytos--;
yyStackOverflow(yypParser);
return; return;
} }
#else #else
if( yypParser->yyidx>=yypParser->yystksz ){ if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
yyGrowStack(yypParser); if( yyGrowStack(yypParser) ){
if( yypParser->yyidx>=yypParser->yystksz ){ yypParser->yytos--;
yyStackOverflow(yypParser, yypMinor); yyStackOverflow(yypParser);
return; return;
} }
} }
#endif #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->stateno = (YYACTIONTYPE)yyNewState;
yytos->major = (YYCODETYPE)yyMajor; yytos->major = (YYCODETYPE)yyMajor;
yytos->minor = *yypMinor; yytos->minor.yy0 = yyMinor;
yyTraceShift(yypParser, yyNewState); yyTraceShift(yypParser, yyNewState, "Shift");
} }
/* The following table contains information about every rule that /* The following table contains information about every rule that
** is used during the reduce. ** is used during the reduce.
*/ */
static const struct { static const struct {
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
unsigned char nrhs; /* Number of right-hand side symbols in the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */
} yyRuleInfo[] = { } yyRuleInfo[] = {
{ 197, 1 }, { 198, -1 }, /* (0) program ::= cmd */
{ 198, 2 }, { 199, -2 }, /* (1) cmd ::= SHOW DATABASES */
{ 198, 2 }, { 199, -2 }, /* (2) cmd ::= SHOW MNODES */
{ 198, 2 }, { 199, -2 }, /* (3) cmd ::= SHOW DNODES */
{ 198, 2 }, { 199, -2 }, /* (4) cmd ::= SHOW ACCOUNTS */
{ 198, 2 }, { 199, -2 }, /* (5) cmd ::= SHOW USERS */
{ 198, 2 }, { 199, -2 }, /* (6) cmd ::= SHOW MODULES */
{ 198, 2 }, { 199, -2 }, /* (7) cmd ::= SHOW QUERIES */
{ 198, 2 }, { 199, -2 }, /* (8) cmd ::= SHOW CONNECTIONS */
{ 198, 2 }, { 199, -2 }, /* (9) cmd ::= SHOW STREAMS */
{ 198, 2 }, { 199, -2 }, /* (10) cmd ::= SHOW CONFIGS */
{ 198, 2 }, { 199, -2 }, /* (11) cmd ::= SHOW SCORES */
{ 198, 2 }, { 199, -2 }, /* (12) cmd ::= SHOW GRANTS */
{ 198, 2 }, { 199, -2 }, /* (13) cmd ::= SHOW VNODES */
{ 198, 3 }, { 199, -3 }, /* (14) cmd ::= SHOW VNODES IPTOKEN */
{ 199, 0 }, { 200, 0 }, /* (15) dbPrefix ::= */
{ 199, 2 }, { 200, -2 }, /* (16) dbPrefix ::= ids DOT */
{ 201, 0 }, { 202, 0 }, /* (17) cpxName ::= */
{ 201, 2 }, { 202, -2 }, /* (18) cpxName ::= DOT ids */
{ 198, 3 }, { 199, -3 }, /* (19) cmd ::= SHOW dbPrefix TABLES */
{ 198, 5 }, { 199, -5 }, /* (20) cmd ::= SHOW dbPrefix TABLES LIKE ids */
{ 198, 3 }, { 199, -3 }, /* (21) cmd ::= SHOW dbPrefix STABLES */
{ 198, 5 }, { 199, -5 }, /* (22) cmd ::= SHOW dbPrefix STABLES LIKE ids */
{ 198, 3 }, { 199, -3 }, /* (23) cmd ::= SHOW dbPrefix VGROUPS */
{ 198, 5 }, { 199, -5 }, /* (24) cmd ::= DROP TABLE ifexists ids cpxName */
{ 198, 4 }, { 199, -4 }, /* (25) cmd ::= DROP DATABASE ifexists ids */
{ 198, 3 }, { 199, -3 }, /* (26) cmd ::= DROP DNODE IPTOKEN */
{ 198, 3 }, { 199, -3 }, /* (27) cmd ::= DROP USER ids */
{ 198, 3 }, { 199, -3 }, /* (28) cmd ::= DROP ACCOUNT ids */
{ 198, 2 }, { 199, -2 }, /* (29) cmd ::= USE ids */
{ 198, 3 }, { 199, -3 }, /* (30) cmd ::= DESCRIBE ids cpxName */
{ 198, 5 }, { 199, -5 }, /* (31) cmd ::= ALTER USER ids PASS ids */
{ 198, 5 }, { 199, -5 }, /* (32) cmd ::= ALTER USER ids PRIVILEGE ids */
{ 198, 4 }, { 199, -4 }, /* (33) cmd ::= ALTER DNODE IPTOKEN ids */
{ 198, 5 }, { 199, -5 }, /* (34) cmd ::= ALTER DNODE IPTOKEN ids ids */
{ 198, 3 }, { 199, -3 }, /* (35) cmd ::= ALTER LOCAL ids */
{ 198, 4 }, { 199, -4 }, /* (36) cmd ::= ALTER LOCAL ids ids */
{ 198, 4 }, { 199, -4 }, /* (37) cmd ::= ALTER DATABASE ids alter_db_optr */
{ 198, 4 }, { 199, -4 }, /* (38) cmd ::= ALTER ACCOUNT ids acct_optr */
{ 198, 6 }, { 199, -6 }, /* (39) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */
{ 200, 1 }, { 201, -1 }, /* (40) ids ::= ID */
{ 200, 1 }, { 201, -1 }, /* (41) ids ::= STRING */
{ 202, 2 }, { 203, -2 }, /* (42) ifexists ::= IF EXISTS */
{ 202, 0 }, { 203, 0 }, /* (43) ifexists ::= */
{ 205, 3 }, { 206, -3 }, /* (44) ifnotexists ::= IF NOT EXISTS */
{ 205, 0 }, { 206, 0 }, /* (45) ifnotexists ::= */
{ 198, 3 }, { 199, -3 }, /* (46) cmd ::= CREATE DNODE IPTOKEN */
{ 198, 6 }, { 199, -6 }, /* (47) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */
{ 198, 5 }, { 199, -5 }, /* (48) cmd ::= CREATE DATABASE ifnotexists ids db_optr */
{ 198, 5 }, { 199, -5 }, /* (49) cmd ::= CREATE USER ids PASS ids */
{ 207, 0 }, { 208, 0 }, /* (50) pps ::= */
{ 207, 2 }, { 208, -2 }, /* (51) pps ::= PPS INTEGER */
{ 208, 0 }, { 209, 0 }, /* (52) tseries ::= */
{ 208, 2 }, { 209, -2 }, /* (53) tseries ::= TSERIES INTEGER */
{ 209, 0 }, { 210, 0 }, /* (54) dbs ::= */
{ 209, 2 }, { 210, -2 }, /* (55) dbs ::= DBS INTEGER */
{ 210, 0 }, { 211, 0 }, /* (56) streams ::= */
{ 210, 2 }, { 211, -2 }, /* (57) streams ::= STREAMS INTEGER */
{ 211, 0 }, { 212, 0 }, /* (58) storage ::= */
{ 211, 2 }, { 212, -2 }, /* (59) storage ::= STORAGE INTEGER */
{ 212, 0 }, { 213, 0 }, /* (60) qtime ::= */
{ 212, 2 }, { 213, -2 }, /* (61) qtime ::= QTIME INTEGER */
{ 213, 0 }, { 214, 0 }, /* (62) users ::= */
{ 213, 2 }, { 214, -2 }, /* (63) users ::= USERS INTEGER */
{ 214, 0 }, { 215, 0 }, /* (64) conns ::= */
{ 214, 2 }, { 215, -2 }, /* (65) conns ::= CONNS INTEGER */
{ 215, 0 }, { 216, 0 }, /* (66) state ::= */
{ 215, 2 }, { 216, -2 }, /* (67) state ::= STATE ids */
{ 204, 9 }, { 205, -9 }, /* (68) acct_optr ::= pps tseries storage streams qtime dbs users conns state */
{ 216, 2 }, { 217, -2 }, /* (69) keep ::= KEEP tagitemlist */
{ 218, 2 }, { 219, -2 }, /* (70) tables ::= TABLES INTEGER */
{ 219, 2 }, { 220, -2 }, /* (71) cache ::= CACHE INTEGER */
{ 220, 2 }, { 221, -2 }, /* (72) replica ::= REPLICA INTEGER */
{ 221, 2 }, { 222, -2 }, /* (73) days ::= DAYS INTEGER */
{ 222, 2 }, { 223, -2 }, /* (74) rows ::= ROWS INTEGER */
{ 223, 2 }, { 224, -2 }, /* (75) ablocks ::= ABLOCKS ID */
{ 224, 2 }, { 225, -2 }, /* (76) tblocks ::= TBLOCKS INTEGER */
{ 225, 2 }, { 226, -2 }, /* (77) ctime ::= CTIME INTEGER */
{ 226, 2 }, { 227, -2 }, /* (78) clog ::= CLOG INTEGER */
{ 227, 2 }, { 228, -2 }, /* (79) comp ::= COMP INTEGER */
{ 228, 2 }, { 229, -2 }, /* (80) prec ::= PRECISION STRING */
{ 206, 0 }, { 207, 0 }, /* (81) db_optr ::= */
{ 206, 2 }, { 207, -2 }, /* (82) db_optr ::= db_optr tables */
{ 206, 2 }, { 207, -2 }, /* (83) db_optr ::= db_optr cache */
{ 206, 2 }, { 207, -2 }, /* (84) db_optr ::= db_optr replica */
{ 206, 2 }, { 207, -2 }, /* (85) db_optr ::= db_optr days */
{ 206, 2 }, { 207, -2 }, /* (86) db_optr ::= db_optr rows */
{ 206, 2 }, { 207, -2 }, /* (87) db_optr ::= db_optr ablocks */
{ 206, 2 }, { 207, -2 }, /* (88) db_optr ::= db_optr tblocks */
{ 206, 2 }, { 207, -2 }, /* (89) db_optr ::= db_optr ctime */
{ 206, 2 }, { 207, -2 }, /* (90) db_optr ::= db_optr clog */
{ 206, 2 }, { 207, -2 }, /* (91) db_optr ::= db_optr comp */
{ 206, 2 }, { 207, -2 }, /* (92) db_optr ::= db_optr prec */
{ 206, 2 }, { 207, -2 }, /* (93) db_optr ::= db_optr keep */
{ 203, 0 }, { 204, 0 }, /* (94) alter_db_optr ::= */
{ 203, 2 }, { 204, -2 }, /* (95) alter_db_optr ::= alter_db_optr replica */
{ 203, 2 }, { 204, -2 }, /* (96) alter_db_optr ::= alter_db_optr tables */
{ 229, 1 }, { 230, -1 }, /* (97) typename ::= ids */
{ 229, 4 }, { 230, -4 }, /* (98) typename ::= ids LP signed RP */
{ 230, 1 }, { 231, -1 }, /* (99) signed ::= INTEGER */
{ 230, 2 }, { 231, -2 }, /* (100) signed ::= PLUS INTEGER */
{ 230, 2 }, { 231, -2 }, /* (101) signed ::= MINUS INTEGER */
{ 198, 6 }, { 199, -6 }, /* (102) cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */
{ 231, 3 }, { 232, -3 }, /* (103) create_table_args ::= LP columnlist RP */
{ 231, 7 }, { 232, -7 }, /* (104) create_table_args ::= LP columnlist RP TAGS LP columnlist RP */
{ 231, 7 }, { 232, -7 }, /* (105) create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */
{ 231, 2 }, { 232, -2 }, /* (106) create_table_args ::= AS select */
{ 232, 3 }, { 233, -3 }, /* (107) columnlist ::= columnlist COMMA column */
{ 232, 1 }, { 233, -1 }, /* (108) columnlist ::= column */
{ 234, 2 }, { 235, -2 }, /* (109) column ::= ids typename */
{ 217, 3 }, { 218, -3 }, /* (110) tagitemlist ::= tagitemlist COMMA tagitem */
{ 217, 1 }, { 218, -1 }, /* (111) tagitemlist ::= tagitem */
{ 235, 1 }, { 236, -1 }, /* (112) tagitem ::= INTEGER */
{ 235, 1 }, { 236, -1 }, /* (113) tagitem ::= FLOAT */
{ 235, 1 }, { 236, -1 }, /* (114) tagitem ::= STRING */
{ 235, 1 }, { 236, -1 }, /* (115) tagitem ::= BOOL */
{ 235, 1 }, { 236, -1 }, /* (116) tagitem ::= NULL */
{ 235, 2 }, { 236, -2 }, /* (117) tagitem ::= MINUS INTEGER */
{ 235, 2 }, { 236, -2 }, /* (118) tagitem ::= MINUS FLOAT */
{ 235, 2 }, { 236, -2 }, /* (119) tagitem ::= PLUS INTEGER */
{ 235, 2 }, { 236, -2 }, /* (120) tagitem ::= PLUS FLOAT */
{ 198, 1 }, { 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 */
{ 233, 12 }, { 248, -1 }, /* (122) union ::= select */
{ 233, 2 }, { 248, -3 }, /* (123) union ::= union UNION select */
{ 247, 2 }, { 199, -1 }, /* (124) cmd ::= union */
{ 247, 0 }, { 234, -2 }, /* (125) select ::= SELECT selcollist */
{ 236, 3 }, { 249, -2 }, /* (126) sclp ::= selcollist COMMA */
{ 236, 2 }, { 249, 0 }, /* (127) sclp ::= */
{ 249, 2 }, { 237, -3 }, /* (128) selcollist ::= sclp expr as */
{ 249, 1 }, { 237, -2 }, /* (129) selcollist ::= sclp STAR */
{ 249, 0 }, { 251, -2 }, /* (130) as ::= AS ids */
{ 237, 2 }, { 251, -1 }, /* (131) as ::= ids */
{ 250, 2 }, { 251, 0 }, /* (132) as ::= */
{ 250, 4 }, { 238, -2 }, /* (133) from ::= FROM tablelist */
{ 251, 1 }, { 252, -2 }, /* (134) tablelist ::= ids cpxName */
{ 239, 4 }, { 252, -4 }, /* (135) tablelist ::= tablelist COMMA ids cpxName */
{ 239, 0 }, { 253, -1 }, /* (136) tmvar ::= VARIABLE */
{ 240, 0 }, { 240, -4 }, /* (137) interval_opt ::= INTERVAL LP tmvar RP */
{ 240, 6 }, { 240, 0 }, /* (138) interval_opt ::= */
{ 240, 4 }, { 241, 0 }, /* (139) fill_opt ::= */
{ 241, 4 }, { 241, -6 }, /* (140) fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{ 241, 0 }, { 241, -4 }, /* (141) fill_opt ::= FILL LP ID RP */
{ 243, 0 }, { 242, -4 }, /* (142) sliding_opt ::= SLIDING LP tmvar RP */
{ 243, 3 }, { 242, 0 }, /* (143) sliding_opt ::= */
{ 252, 4 }, { 244, 0 }, /* (144) orderby_opt ::= */
{ 252, 2 }, { 244, -3 }, /* (145) orderby_opt ::= ORDER BY sortlist */
{ 254, 2 }, { 254, -4 }, /* (146) sortlist ::= sortlist COMMA item sortorder */
{ 255, 1 }, { 254, -2 }, /* (147) sortlist ::= item sortorder */
{ 255, 1 }, { 256, -2 }, /* (148) item ::= ids cpxName */
{ 255, 0 }, { 257, -1 }, /* (149) sortorder ::= ASC */
{ 242, 0 }, { 257, -1 }, /* (150) sortorder ::= DESC */
{ 242, 3 }, { 257, 0 }, /* (151) sortorder ::= */
{ 256, 3 }, { 243, 0 }, /* (152) groupby_opt ::= */
{ 256, 1 }, { 243, -3 }, /* (153) groupby_opt ::= GROUP BY grouplist */
{ 244, 0 }, { 258, -3 }, /* (154) grouplist ::= grouplist COMMA item */
{ 244, 2 }, { 258, -1 }, /* (155) grouplist ::= item */
{ 246, 0 }, { 245, 0 }, /* (156) having_opt ::= */
{ 246, 2 }, { 245, -2 }, /* (157) having_opt ::= HAVING expr */
{ 246, 4 }, { 247, 0 }, /* (158) limit_opt ::= */
{ 246, 4 }, { 247, -2 }, /* (159) limit_opt ::= LIMIT signed */
{ 245, 0 }, { 247, -4 }, /* (160) limit_opt ::= LIMIT signed OFFSET signed */
{ 245, 2 }, { 247, -4 }, /* (161) limit_opt ::= LIMIT signed COMMA signed */
{ 245, 4 }, { 246, 0 }, /* (162) slimit_opt ::= */
{ 245, 4 }, { 246, -2 }, /* (163) slimit_opt ::= SLIMIT signed */
{ 238, 0 }, { 246, -4 }, /* (164) slimit_opt ::= SLIMIT signed SOFFSET signed */
{ 238, 2 }, { 246, -4 }, /* (165) slimit_opt ::= SLIMIT signed COMMA signed */
{ 248, 3 }, { 239, 0 }, /* (166) where_opt ::= */
{ 248, 1 }, { 239, -2 }, /* (167) where_opt ::= WHERE expr */
{ 248, 3 }, { 250, -3 }, /* (168) expr ::= LP expr RP */
{ 248, 3 }, { 250, -1 }, /* (169) expr ::= ID */
{ 248, 1 }, { 250, -3 }, /* (170) expr ::= ID DOT ID */
{ 248, 2 }, { 250, -3 }, /* (171) expr ::= ID DOT STAR */
{ 248, 2 }, { 250, -1 }, /* (172) expr ::= INTEGER */
{ 248, 1 }, { 250, -2 }, /* (173) expr ::= MINUS INTEGER */
{ 248, 2 }, { 250, -2 }, /* (174) expr ::= PLUS INTEGER */
{ 248, 2 }, { 250, -1 }, /* (175) expr ::= FLOAT */
{ 248, 1 }, { 250, -2 }, /* (176) expr ::= MINUS FLOAT */
{ 248, 1 }, { 250, -2 }, /* (177) expr ::= PLUS FLOAT */
{ 248, 1 }, { 250, -1 }, /* (178) expr ::= STRING */
{ 248, 1 }, { 250, -1 }, /* (179) expr ::= NOW */
{ 248, 4 }, { 250, -1 }, /* (180) expr ::= VARIABLE */
{ 248, 4 }, { 250, -1 }, /* (181) expr ::= BOOL */
{ 248, 3 }, { 250, -4 }, /* (182) expr ::= ID LP exprlist RP */
{ 248, 3 }, { 250, -4 }, /* (183) expr ::= ID LP STAR RP */
{ 248, 3 }, { 250, -3 }, /* (184) expr ::= expr AND expr */
{ 248, 3 }, { 250, -3 }, /* (185) expr ::= expr OR expr */
{ 248, 3 }, { 250, -3 }, /* (186) expr ::= expr LT expr */
{ 248, 3 }, { 250, -3 }, /* (187) expr ::= expr GT expr */
{ 248, 3 }, { 250, -3 }, /* (188) expr ::= expr LE expr */
{ 248, 3 }, { 250, -3 }, /* (189) expr ::= expr GE expr */
{ 248, 3 }, { 250, -3 }, /* (190) expr ::= expr NE expr */
{ 248, 3 }, { 250, -3 }, /* (191) expr ::= expr EQ expr */
{ 248, 3 }, { 250, -3 }, /* (192) expr ::= expr PLUS expr */
{ 248, 3 }, { 250, -3 }, /* (193) expr ::= expr MINUS expr */
{ 248, 3 }, { 250, -3 }, /* (194) expr ::= expr STAR expr */
{ 248, 3 }, { 250, -3 }, /* (195) expr ::= expr SLASH expr */
{ 248, 5 }, { 250, -3 }, /* (196) expr ::= expr REM expr */
{ 257, 3 }, { 250, -3 }, /* (197) expr ::= expr LIKE expr */
{ 257, 1 }, { 250, -5 }, /* (198) expr ::= expr IN LP exprlist RP */
{ 258, 1 }, { 259, -3 }, /* (199) exprlist ::= exprlist COMMA expritem */
{ 258, 0 }, { 259, -1 }, /* (200) exprlist ::= expritem */
{ 198, 4 }, { 260, -1 }, /* (201) expritem ::= expr */
{ 259, 4 }, { 260, 0 }, /* (202) expritem ::= */
{ 259, 5 }, { 199, -3 }, /* (203) cmd ::= RESET QUERY CACHE */
{ 260, 3 }, { 199, -7 }, /* (204) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{ 260, 1 }, { 199, -7 }, /* (205) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */
{ 198, 3 }, { 199, -7 }, /* (206) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{ 198, 7 }, { 199, -7 }, /* (207) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */
{ 198, 7 }, { 199, -8 }, /* (208) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */
{ 198, 7 }, { 199, -9 }, /* (209) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */
{ 198, 7 }, { 199, -5 }, /* (210) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */
{ 198, 8 }, { 199, -7 }, /* (211) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */
{ 198, 9 }, { 199, -7 }, /* (212) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */
{ 198, 5 },
{ 198, 7 },
{ 198, 7 },
}; };
static void yy_accept(yyParser*); /* Forward Declaration */ static void yy_accept(yyParser*); /* Forward Declaration */
...@@ -1574,27 +1861,66 @@ 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 ** Perform a reduce action and the shift that must immediately
** follow the reduce. ** 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( static void yy_reduce(
yyParser *yypParser, /* The parser */ 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 yygoto; /* The next state */
int yyact; /* The next action */ int yyact; /* The next action */
YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
yyStackEntry *yymsp; /* The top of the parser's stack */ yyStackEntry *yymsp; /* The top of the parser's stack */
int yysize; /* Amount to pop the stack */ int yysize; /* Amount to pop the stack */
ParseARG_FETCH; ParseARG_FETCH;
yymsp = &yypParser->yystack[yypParser->yyidx]; (void)yyLookahead;
(void)yyLookaheadToken;
yymsp = yypParser->yytos;
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE && yyruleno>=0 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
&& yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
yysize = yyRuleInfo[yyruleno].nrhs; yysize = yyRuleInfo[yyruleno].nrhs;
fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, if( yysize ){
yyRuleName[yyruleno], yymsp[-yysize].stateno); 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 */ #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 ){ switch( yyruleno ){
/* Beginning here are the reduction cases. A typical example /* Beginning here are the reduction cases. A typical example
...@@ -1606,167 +1932,174 @@ static void yy_reduce( ...@@ -1606,167 +1932,174 @@ static void yy_reduce(
** break; ** break;
*/ */
/********** Begin reduce actions **********************************************/ /********** Begin reduce actions **********************************************/
YYMINORTYPE yylhsminor;
case 0: /* program ::= cmd */ case 0: /* program ::= cmd */
{} {}
break; break;
case 1: /* cmd ::= SHOW DATABASES */ case 1: /* cmd ::= SHOW DATABASES */
{ setDCLSQLElems(pInfo, SHOW_DATABASES, 0);} { setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);}
break; break;
case 2: /* cmd ::= SHOW MNODES */ case 2: /* cmd ::= SHOW MNODES */
{ setDCLSQLElems(pInfo, SHOW_MNODES, 0);} { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);}
break; break;
case 3: /* cmd ::= SHOW DNODES */ case 3: /* cmd ::= SHOW DNODES */
{ setDCLSQLElems(pInfo, SHOW_DNODES, 0);} { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);}
break; break;
case 4: /* cmd ::= SHOW ACCOUNTS */ case 4: /* cmd ::= SHOW ACCOUNTS */
{ setDCLSQLElems(pInfo, SHOW_ACCOUNTS, 0);} { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);}
break; break;
case 5: /* cmd ::= SHOW USERS */ case 5: /* cmd ::= SHOW USERS */
{ setDCLSQLElems(pInfo, SHOW_USERS, 0);} { setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);}
break; break;
case 6: /* cmd ::= SHOW MODULES */ case 6: /* cmd ::= SHOW MODULES */
{ setDCLSQLElems(pInfo, SHOW_MODULES, 0); } { setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0); }
break; break;
case 7: /* cmd ::= SHOW QUERIES */ case 7: /* cmd ::= SHOW QUERIES */
{ setDCLSQLElems(pInfo, SHOW_QUERIES, 0); } { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0); }
break; break;
case 8: /* cmd ::= SHOW CONNECTIONS */ case 8: /* cmd ::= SHOW CONNECTIONS */
{ setDCLSQLElems(pInfo, SHOW_CONNECTIONS, 0);} { setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);}
break; break;
case 9: /* cmd ::= SHOW STREAMS */ case 9: /* cmd ::= SHOW STREAMS */
{ setDCLSQLElems(pInfo, SHOW_STREAMS, 0); } { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); }
break; break;
case 10: /* cmd ::= SHOW CONFIGS */ case 10: /* cmd ::= SHOW CONFIGS */
{ setDCLSQLElems(pInfo, SHOW_CONFIGS, 0); } { setShowOptions(pInfo, TSDB_MGMT_TABLE_CONFIGS, 0, 0); }
break; break;
case 11: /* cmd ::= SHOW SCORES */ case 11: /* cmd ::= SHOW SCORES */
{ setDCLSQLElems(pInfo, SHOW_SCORES, 0); } { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); }
break; break;
case 12: /* cmd ::= SHOW GRANTS */ case 12: /* cmd ::= SHOW GRANTS */
{ setDCLSQLElems(pInfo, SHOW_GRANTS, 0); } { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); }
break; break;
case 13: /* cmd ::= SHOW VNODES */ case 13: /* cmd ::= SHOW VNODES */
{ setDCLSQLElems(pInfo, SHOW_VNODES, 0); } { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
break; break;
case 14: /* cmd ::= SHOW VNODES IPTOKEN */ 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; break;
case 15: /* dbPrefix ::= */ case 15: /* dbPrefix ::= */
case 43: /* ifexists ::= */ yytestcase(yyruleno==43); {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.type = 0;}
case 45: /* ifnotexists ::= */ yytestcase(yyruleno==45);
{yygotominor.yy0.n = 0;}
break; break;
case 16: /* dbPrefix ::= ids DOT */ case 16: /* dbPrefix ::= ids DOT */
{yygotominor.yy0 = yymsp[-1].minor.yy0; } {yylhsminor.yy0 = yymsp[-1].minor.yy0; }
yymsp[-1].minor.yy0 = yylhsminor.yy0;
break; break;
case 17: /* cpxName ::= */ case 17: /* cpxName ::= */
{yygotominor.yy0.n = 0; } {yymsp[1].minor.yy0.n = 0; }
break; break;
case 18: /* cpxName ::= DOT ids */ 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; break;
case 19: /* cmd ::= SHOW dbPrefix TABLES */ 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; break;
case 20: /* cmd ::= SHOW dbPrefix TABLES LIKE ids */ 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; break;
case 21: /* cmd ::= SHOW dbPrefix STABLES */ 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; break;
case 22: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */ case 22: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */
{ {
SSQLToken token; SSQLToken token;
setDBName(&token, &yymsp[-3].minor.yy0); 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; break;
case 23: /* cmd ::= SHOW dbPrefix VGROUPS */ case 23: /* cmd ::= SHOW dbPrefix VGROUPS */
{ {
SSQLToken token; SSQLToken token;
setDBName(&token, &yymsp[-1].minor.yy0); setDBName(&token, &yymsp[-1].minor.yy0);
setDCLSQLElems(pInfo, SHOW_VGROUPS, 1, &token); setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
} }
break; break;
case 24: /* cmd ::= DROP TABLE ifexists ids cpxName */ case 24: /* cmd ::= DROP TABLE ifexists ids cpxName */
{ {
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; 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; break;
case 25: /* cmd ::= DROP DATABASE ifexists ids */ 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; break;
case 26: /* cmd ::= DROP DNODE IPTOKEN */ 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; break;
case 27: /* cmd ::= DROP USER ids */ 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; break;
case 28: /* cmd ::= DROP ACCOUNT ids */ 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; break;
case 29: /* cmd ::= USE ids */ 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; break;
case 30: /* cmd ::= DESCRIBE ids cpxName */ case 30: /* cmd ::= DESCRIBE ids cpxName */
{ {
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; 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; break;
case 31: /* cmd ::= ALTER USER ids PASS ids */ 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; break;
case 32: /* cmd ::= ALTER USER ids PRIVILEGE ids */ 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; break;
case 33: /* cmd ::= ALTER DNODE IPTOKEN ids */ 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; break;
case 34: /* cmd ::= ALTER DNODE IPTOKEN ids ids */ 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; break;
case 35: /* cmd ::= ALTER LOCAL ids */ 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; break;
case 36: /* cmd ::= ALTER LOCAL ids ids */ 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; break;
case 37: /* cmd ::= ALTER DATABASE ids alter_db_optr */ 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; break;
case 38: /* cmd ::= ALTER ACCOUNT ids acct_optr */ 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; break;
case 39: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ 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; break;
case 40: /* ids ::= ID */ case 40: /* ids ::= ID */
case 41: /* ids ::= STRING */ yytestcase(yyruleno==41); 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; break;
case 42: /* ifexists ::= IF EXISTS */ case 42: /* ifexists ::= IF EXISTS */
case 44: /* ifnotexists ::= IF NOT EXISTS */ yytestcase(yyruleno==44); {yymsp[-1].minor.yy0.n = 1;}
{yygotominor.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; break;
case 46: /* cmd ::= CREATE DNODE IPTOKEN */ 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; break;
case 47: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ 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; break;
case 48: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ 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; break;
case 49: /* cmd ::= CREATE USER ids PASS ids */ 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; break;
case 50: /* pps ::= */ case 50: /* pps ::= */
case 52: /* tseries ::= */ yytestcase(yyruleno==52); case 52: /* tseries ::= */ yytestcase(yyruleno==52);
...@@ -1777,7 +2110,7 @@ static void yy_reduce( ...@@ -1777,7 +2110,7 @@ static void yy_reduce(
case 62: /* users ::= */ yytestcase(yyruleno==62); case 62: /* users ::= */ yytestcase(yyruleno==62);
case 64: /* conns ::= */ yytestcase(yyruleno==64); case 64: /* conns ::= */ yytestcase(yyruleno==64);
case 66: /* state ::= */ yytestcase(yyruleno==66); case 66: /* state ::= */ yytestcase(yyruleno==66);
{yygotominor.yy0.n = 0; } {yymsp[1].minor.yy0.n = 0; }
break; break;
case 51: /* pps ::= PPS INTEGER */ case 51: /* pps ::= PPS INTEGER */
case 53: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==53); case 53: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==53);
...@@ -1788,23 +2121,24 @@ static void yy_reduce( ...@@ -1788,23 +2121,24 @@ static void yy_reduce(
case 63: /* users ::= USERS INTEGER */ yytestcase(yyruleno==63); case 63: /* users ::= USERS INTEGER */ yytestcase(yyruleno==63);
case 65: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==65); case 65: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==65);
case 67: /* state ::= STATE ids */ yytestcase(yyruleno==67); case 67: /* state ::= STATE ids */ yytestcase(yyruleno==67);
{yygotominor.yy0 = yymsp[0].minor.yy0; } {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
break; break;
case 68: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ 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; yylhsminor.yy155.maxUsers = (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; yylhsminor.yy155.maxDbs = (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; yylhsminor.yy155.maxTimeSeries = (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; yylhsminor.yy155.maxStreams = (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; yylhsminor.yy155.maxPointsPerSecond = (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; yylhsminor.yy155.maxStorage = (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; yylhsminor.yy155.maxQueryTime = (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; yylhsminor.yy155.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1;
yygotominor.yy155.stat = yymsp[0].minor.yy0; yylhsminor.yy155.stat = yymsp[0].minor.yy0;
} }
yymsp[-8].minor.yy155 = yylhsminor.yy155;
break; break;
case 69: /* keep ::= KEEP tagitemlist */ case 69: /* keep ::= KEEP tagitemlist */
{ yygotominor.yy480 = yymsp[0].minor.yy480; } { yymsp[-1].minor.yy480 = yymsp[0].minor.yy480; }
break; break;
case 70: /* tables ::= TABLES INTEGER */ case 70: /* tables ::= TABLES INTEGER */
case 71: /* cache ::= CACHE INTEGER */ yytestcase(yyruleno==71); case 71: /* cache ::= CACHE INTEGER */ yytestcase(yyruleno==71);
...@@ -1817,67 +2151,84 @@ static void yy_reduce( ...@@ -1817,67 +2151,84 @@ static void yy_reduce(
case 78: /* clog ::= CLOG INTEGER */ yytestcase(yyruleno==78); case 78: /* clog ::= CLOG INTEGER */ yytestcase(yyruleno==78);
case 79: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==79); case 79: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==79);
case 80: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==80); case 80: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==80);
{ yygotominor.yy0 = yymsp[0].minor.yy0; } { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
break; break;
case 81: /* db_optr ::= */ case 81: /* db_optr ::= */
{setDefaultCreateDbOption(&yygotominor.yy262);} {setDefaultCreateDbOption(&yymsp[1].minor.yy262);}
break; break;
case 82: /* db_optr ::= db_optr tables */ case 82: /* db_optr ::= db_optr tables */
case 96: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==96); 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; break;
case 83: /* db_optr ::= db_optr cache */ 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; break;
case 84: /* db_optr ::= db_optr replica */ case 84: /* db_optr ::= db_optr replica */
case 95: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==95); 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; break;
case 85: /* db_optr ::= db_optr days */ 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; break;
case 86: /* db_optr ::= db_optr rows */ 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; break;
case 87: /* db_optr ::= db_optr ablocks */ 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; break;
case 88: /* db_optr ::= db_optr tblocks */ 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; break;
case 89: /* db_optr ::= db_optr ctime */ 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; break;
case 90: /* db_optr ::= db_optr clog */ 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; break;
case 91: /* db_optr ::= db_optr comp */ 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; break;
case 92: /* db_optr ::= db_optr prec */ 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; break;
case 93: /* db_optr ::= db_optr keep */ 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; break;
case 94: /* alter_db_optr ::= */ case 94: /* alter_db_optr ::= */
{ setDefaultCreateDbOption(&yygotominor.yy262);} { setDefaultCreateDbOption(&yymsp[1].minor.yy262);}
break; break;
case 97: /* typename ::= ids */ 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; break;
case 98: /* typename ::= ids LP signed RP */ case 98: /* typename ::= ids LP signed RP */
{ {
yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy369; // negative value of name length 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; break;
case 99: /* signed ::= INTEGER */ case 99: /* signed ::= INTEGER */
case 100: /* signed ::= PLUS INTEGER */ yytestcase(yyruleno==100); { yylhsminor.yy369 = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
{ yygotominor.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; break;
case 101: /* signed ::= MINUS INTEGER */ 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; break;
case 102: /* cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ case 102: /* cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */
{ {
...@@ -1887,54 +2238,61 @@ static void yy_reduce( ...@@ -1887,54 +2238,61 @@ static void yy_reduce(
break; break;
case 103: /* create_table_args ::= LP columnlist RP */ case 103: /* create_table_args ::= LP columnlist RP */
{ {
yygotominor.yy344 = tSetCreateSQLElems(yymsp[-1].minor.yy421, NULL, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METER); yymsp[-2].minor.yy344 = tSetCreateSQLElems(yymsp[-1].minor.yy421, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE);
setSQLInfo(pInfo, yygotominor.yy344, NULL, TSQL_CREATE_NORMAL_METER); setSQLInfo(pInfo, yymsp[-2].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE);
} }
break; break;
case 104: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ 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); yymsp[-6].minor.yy344 = tSetCreateSQLElems(yymsp[-5].minor.yy421, yymsp[-1].minor.yy421, NULL, NULL, NULL, TSQL_CREATE_STABLE);
setSQLInfo(pInfo, yygotominor.yy344, NULL, TSQL_CREATE_NORMAL_METRIC); setSQLInfo(pInfo, yymsp[-6].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE);
} }
break; break;
case 105: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ case 105: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */
{ {
yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n;
yygotominor.yy344 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy480, 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, yygotominor.yy344, NULL, TSQL_CREATE_METER_FROM_METRIC); setSQLInfo(pInfo, yymsp[-6].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE);
} }
break; break;
case 106: /* create_table_args ::= AS select */ case 106: /* create_table_args ::= AS select */
{ {
yygotominor.yy344 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy138, TSQL_CREATE_STREAM); yymsp[-1].minor.yy344 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy138, TSQL_CREATE_STREAM);
setSQLInfo(pInfo, yygotominor.yy344, NULL, TSQL_CREATE_STREAM); setSQLInfo(pInfo, yymsp[-1].minor.yy344, NULL, TSDB_SQL_CREATE_TABLE);
} }
break; break;
case 107: /* columnlist ::= columnlist COMMA column */ 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; break;
case 108: /* columnlist ::= column */ 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; break;
case 109: /* column ::= ids typename */ 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; break;
case 110: /* tagitemlist ::= tagitemlist COMMA tagitem */ 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; break;
case 111: /* tagitemlist ::= tagitem */ 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; break;
case 112: /* tagitem ::= INTEGER */ case 112: /* tagitem ::= INTEGER */
case 113: /* tagitem ::= FLOAT */ yytestcase(yyruleno==113); case 113: /* tagitem ::= FLOAT */ yytestcase(yyruleno==113);
case 114: /* tagitem ::= STRING */ yytestcase(yyruleno==114); case 114: /* tagitem ::= STRING */ yytestcase(yyruleno==114);
case 115: /* tagitem ::= BOOL */ yytestcase(yyruleno==115); 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; break;
case 116: /* tagitem ::= NULL */ 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; break;
case 117: /* tagitem ::= MINUS INTEGER */ case 117: /* tagitem ::= MINUS INTEGER */
case 118: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==118); case 118: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==118);
...@@ -1944,308 +2302,359 @@ static void yy_reduce( ...@@ -1944,308 +2302,359 @@ static void yy_reduce(
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type;
toTSDBType(yymsp[-1].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; 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; 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; 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; break;
case 124: /* sclp ::= selcollist COMMA */ case 125: /* select ::= SELECT selcollist */
{yygotominor.yy284 = yymsp[-1].minor.yy284;} {
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; break;
case 125: /* sclp ::= */ case 126: /* sclp ::= selcollist COMMA */
{yygotominor.yy284 = 0;} {yylhsminor.yy284 = yymsp[-1].minor.yy284;}
yymsp[-1].minor.yy284 = yylhsminor.yy284;
break; 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; break;
case 127: /* selcollist ::= sclp STAR */ case 129: /* selcollist ::= sclp STAR */
{ {
tSQLExpr *pNode = tSQLExprIdValueCreate(NULL, TK_ALL); 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; break;
case 128: /* as ::= AS ids */ case 131: /* as ::= ids */
case 129: /* as ::= ids */ yytestcase(yyruleno==129); { yylhsminor.yy0 = yymsp[0].minor.yy0; }
{ yygotominor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0;
break; break;
case 130: /* as ::= */ case 132: /* as ::= */
{ yygotominor.yy0.n = 0; } { yymsp[1].minor.yy0.n = 0; }
break; break;
case 131: /* from ::= FROM tablelist */ case 133: /* from ::= FROM tablelist */
case 143: /* orderby_opt ::= ORDER BY sortlist */ yytestcase(yyruleno==143); {yymsp[-1].minor.yy480 = yymsp[0].minor.yy480;}
case 151: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==151);
{yygotominor.yy480 = yymsp[0].minor.yy480;}
break; break;
case 132: /* tablelist ::= ids cpxName */ case 134: /* 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);} { 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; break;
case 133: /* tablelist ::= tablelist COMMA ids cpxName */ case 135: /* 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); } { 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; break;
case 134: /* tmvar ::= VARIABLE */ case 136: /* tmvar ::= VARIABLE */
{yygotominor.yy0 = yymsp[0].minor.yy0;} {yylhsminor.yy0 = yymsp[0].minor.yy0;}
yymsp[0].minor.yy0 = yylhsminor.yy0;
break; break;
case 135: /* interval_opt ::= INTERVAL LP tmvar RP */ case 137: /* interval_opt ::= INTERVAL LP tmvar RP */
case 140: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==140); case 142: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==142);
{yygotominor.yy0 = yymsp[-1].minor.yy0; } {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; }
break; break;
case 136: /* interval_opt ::= */ case 138: /* interval_opt ::= */
case 141: /* sliding_opt ::= */ yytestcase(yyruleno==141); case 143: /* sliding_opt ::= */ yytestcase(yyruleno==143);
{yygotominor.yy0.n = 0; yygotominor.yy0.z = NULL; yygotominor.yy0.type = 0; } {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; }
break; break;
case 137: /* fill_opt ::= */ case 139: /* fill_opt ::= */
{yygotominor.yy480 = 0; } {yymsp[1].minor.yy480 = 0; }
break; break;
case 138: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ case 140: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{ {
tVariant A = {0}; tVariant A = {0};
toTSDBType(yymsp[-3].minor.yy0.type); toTSDBType(yymsp[-3].minor.yy0.type);
tVariantCreate(&A, &yymsp[-3].minor.yy0); tVariantCreate(&A, &yymsp[-3].minor.yy0);
tVariantListInsert(yymsp[-1].minor.yy480, &A, -1, 0); tVariantListInsert(yymsp[-1].minor.yy480, &A, -1, 0);
yygotominor.yy480 = yymsp[-1].minor.yy480; yymsp[-5].minor.yy480 = yymsp[-1].minor.yy480;
} }
break; break;
case 139: /* fill_opt ::= FILL LP ID RP */ case 141: /* fill_opt ::= FILL LP ID RP */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); 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; break;
case 142: /* orderby_opt ::= */ case 144: /* orderby_opt ::= */
case 150: /* groupby_opt ::= */ yytestcase(yyruleno==150); case 152: /* groupby_opt ::= */ yytestcase(yyruleno==152);
{yygotominor.yy480 = 0;} {yymsp[1].minor.yy480 = 0;}
break; 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; 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; break;
case 146: /* item ::= ids cpxName */ case 148: /* item ::= ids cpxName */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
tVariantCreate(&yygotominor.yy236, &yymsp[-1].minor.yy0); tVariantCreate(&yylhsminor.yy236, &yymsp[-1].minor.yy0);
} }
yymsp[-1].minor.yy236 = yylhsminor.yy236;
break; break;
case 147: /* sortorder ::= ASC */ case 149: /* sortorder ::= ASC */
{yygotominor.yy220 = TSQL_SO_ASC; } {yymsp[0].minor.yy220 = TSQL_SO_ASC; }
break; break;
case 148: /* sortorder ::= DESC */ case 150: /* sortorder ::= DESC */
{yygotominor.yy220 = TSQL_SO_DESC;} {yymsp[0].minor.yy220 = TSQL_SO_DESC;}
break; break;
case 149: /* sortorder ::= */ case 151: /* sortorder ::= */
{yygotominor.yy220 = TSQL_SO_ASC;} {yymsp[1].minor.yy220 = TSQL_SO_ASC;}
break; 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; 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; break;
case 154: /* having_opt ::= */ case 156: /* having_opt ::= */
case 164: /* where_opt ::= */ yytestcase(yyruleno==164); case 166: /* where_opt ::= */ yytestcase(yyruleno==166);
case 200: /* expritem ::= */ yytestcase(yyruleno==200); case 202: /* expritem ::= */ yytestcase(yyruleno==202);
{yygotominor.yy244 = 0;} {yymsp[1].minor.yy244 = 0;}
break; break;
case 155: /* having_opt ::= HAVING expr */ case 157: /* having_opt ::= HAVING expr */
case 165: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==165); case 167: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==167);
case 199: /* expritem ::= expr */ yytestcase(yyruleno==199); {yymsp[-1].minor.yy244 = yymsp[0].minor.yy244;}
{yygotominor.yy244 = yymsp[0].minor.yy244;}
break; break;
case 156: /* limit_opt ::= */ case 158: /* limit_opt ::= */
case 160: /* slimit_opt ::= */ yytestcase(yyruleno==160); case 162: /* slimit_opt ::= */ yytestcase(yyruleno==162);
{yygotominor.yy162.limit = -1; yygotominor.yy162.offset = 0;} {yymsp[1].minor.yy162.limit = -1; yymsp[1].minor.yy162.offset = 0;}
break; break;
case 157: /* limit_opt ::= LIMIT signed */ case 159: /* limit_opt ::= LIMIT signed */
case 161: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==161); case 163: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==163);
{yygotominor.yy162.limit = yymsp[0].minor.yy369; yygotominor.yy162.offset = 0;} {yymsp[-1].minor.yy162.limit = yymsp[0].minor.yy369; yymsp[-1].minor.yy162.offset = 0;}
break; break;
case 158: /* limit_opt ::= LIMIT signed OFFSET signed */ case 160: /* limit_opt ::= LIMIT signed OFFSET signed */
case 162: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==162); case 164: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==164);
{yygotominor.yy162.limit = yymsp[-2].minor.yy369; yygotominor.yy162.offset = yymsp[0].minor.yy369;} {yymsp[-3].minor.yy162.limit = yymsp[-2].minor.yy369; yymsp[-3].minor.yy162.offset = yymsp[0].minor.yy369;}
break; break;
case 159: /* limit_opt ::= LIMIT signed COMMA signed */ case 161: /* limit_opt ::= LIMIT signed COMMA signed */
case 163: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==163); case 165: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==165);
{yygotominor.yy162.limit = yymsp[0].minor.yy369; yygotominor.yy162.offset = yymsp[-2].minor.yy369;} {yymsp[-3].minor.yy162.limit = yymsp[0].minor.yy369; yymsp[-3].minor.yy162.offset = yymsp[-2].minor.yy369;}
break; break;
case 166: /* expr ::= LP expr RP */ case 168: /* expr ::= LP expr RP */
{yygotominor.yy244 = yymsp[-1].minor.yy244; } {yymsp[-2].minor.yy244 = yymsp[-1].minor.yy244; }
break; break;
case 167: /* expr ::= ID */ case 169: /* expr ::= ID */
{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} {yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);}
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; break;
case 168: /* expr ::= ID DOT ID */ case 170: /* expr ::= ID DOT ID */
{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_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; break;
case 169: /* expr ::= ID DOT STAR */ case 171: /* expr ::= ID DOT STAR */
{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} {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; break;
case 170: /* expr ::= INTEGER */ case 172: /* expr ::= INTEGER */
{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} {yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);}
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; break;
case 171: /* expr ::= MINUS INTEGER */ case 173: /* expr ::= MINUS INTEGER */
case 172: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==172); 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; yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} {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; break;
case 173: /* expr ::= FLOAT */ case 175: /* expr ::= FLOAT */
{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} {yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);}
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; break;
case 174: /* expr ::= MINUS FLOAT */ case 176: /* expr ::= MINUS FLOAT */
case 175: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==175); 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; yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} {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; break;
case 176: /* expr ::= STRING */ case 178: /* expr ::= STRING */
{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} {yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);}
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; break;
case 177: /* expr ::= NOW */ case 179: /* expr ::= NOW */
{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } {yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); }
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; break;
case 178: /* expr ::= VARIABLE */ case 180: /* expr ::= VARIABLE */
{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} {yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);}
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; break;
case 179: /* expr ::= BOOL */ case 181: /* expr ::= BOOL */
{yygotominor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} {yylhsminor.yy244 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);}
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; 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; 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; break;
case 182: /* expr ::= expr AND expr */ case 184: /* expr ::= expr AND expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_AND);} {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_AND);}
break; yymsp[-2].minor.yy244 = yylhsminor.yy244;
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);}
break; break;
case 185: /* expr ::= expr GT expr */ case 185: /* expr ::= expr OR expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GT);} {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_OR); }
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 186: /* expr ::= expr LE expr */ case 186: /* expr ::= expr LT expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LE);} {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LT);}
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 187: /* expr ::= expr GE expr */ case 187: /* expr ::= expr GT expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GE);} {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GT);}
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 188: /* expr ::= expr NE expr */ case 188: /* expr ::= expr LE expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_NE);} {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LE);}
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 189: /* expr ::= expr EQ expr */ case 189: /* expr ::= expr GE expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_EQ);} {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_GE);}
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 190: /* expr ::= expr PLUS expr */ case 190: /* expr ::= expr NE expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_PLUS); } {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_NE);}
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 191: /* expr ::= expr MINUS expr */ case 191: /* expr ::= expr EQ expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_MINUS); } {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_EQ);}
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 192: /* expr ::= expr STAR expr */ case 192: /* expr ::= expr PLUS expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_STAR); } {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_PLUS); }
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 193: /* expr ::= expr SLASH expr */ case 193: /* expr ::= expr MINUS expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_DIVIDE);} {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_MINUS); }
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 194: /* expr ::= expr REM expr */ case 194: /* expr ::= expr STAR expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_REM); } {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_STAR); }
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 195: /* expr ::= expr LIKE expr */ case 195: /* expr ::= expr SLASH expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LIKE); } {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_DIVIDE);}
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 196: /* expr ::= expr IN LP exprlist RP */ case 196: /* expr ::= expr REM expr */
{yygotominor.yy244 = tSQLExprCreate(yymsp[-4].minor.yy244, (tSQLExpr*)yymsp[-1].minor.yy284, TK_IN); } {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_REM); }
yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 197: /* exprlist ::= exprlist COMMA expritem */ case 197: /* expr ::= expr LIKE expr */
case 204: /* itemlist ::= itemlist COMMA expr */ yytestcase(yyruleno==204); {yylhsminor.yy244 = tSQLExprCreate(yymsp[-2].minor.yy244, yymsp[0].minor.yy244, TK_LIKE); }
{yygotominor.yy284 = tSQLExprListAppend(yymsp[-2].minor.yy284,yymsp[0].minor.yy244,0);} yymsp[-2].minor.yy244 = yylhsminor.yy244;
break; break;
case 198: /* exprlist ::= expritem */ case 198: /* expr ::= expr IN LP exprlist RP */
case 205: /* itemlist ::= expr */ yytestcase(yyruleno==205); {yylhsminor.yy244 = tSQLExprCreate(yymsp[-4].minor.yy244, (tSQLExpr*)yymsp[-1].minor.yy284, TK_IN); }
{yygotominor.yy284 = tSQLExprListAppend(0,yymsp[0].minor.yy244,0);} yymsp[-4].minor.yy244 = yylhsminor.yy244;
break; break;
case 201: /* cmd ::= INSERT INTO cpxName insert_value_list */ case 199: /* exprlist ::= exprlist COMMA expritem */
{ {yylhsminor.yy284 = tSQLExprListAppend(yymsp[-2].minor.yy284,yymsp[0].minor.yy244,0);}
tSetInsertSQLElems(pInfo, &yymsp[-1].minor.yy0, yymsp[0].minor.yy237); yymsp[-2].minor.yy284 = yylhsminor.yy284;
}
break; break;
case 202: /* insert_value_list ::= VALUES LP itemlist RP */ case 200: /* exprlist ::= expritem */
{yygotominor.yy237 = tSQLListListAppend(NULL, yymsp[-1].minor.yy284);} {yylhsminor.yy284 = tSQLExprListAppend(0,yymsp[0].minor.yy244,0);}
yymsp[0].minor.yy284 = yylhsminor.yy284;
break; break;
case 203: /* insert_value_list ::= insert_value_list VALUES LP itemlist RP */ case 201: /* expritem ::= expr */
{yygotominor.yy237 = tSQLListListAppend(yymsp[-4].minor.yy237, yymsp[-1].minor.yy284);} {yylhsminor.yy244 = yymsp[0].minor.yy244;}
yymsp[0].minor.yy244 = yylhsminor.yy244;
break; break;
case 206: /* cmd ::= RESET QUERY CACHE */ case 203: /* cmd ::= RESET QUERY CACHE */
{ setDCLSQLElems(pInfo, RESET_QUERY_CACHE, 0);} { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
break; 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; 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); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy421, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_ADD_COLUMN); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; 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; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
tVariantList* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1); tVariantList* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, K, ALTER_TABLE_DROP_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_DROP_COLUMN); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; 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; 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); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy421, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_ADD); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; 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; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1); tVariantList* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, A, ALTER_TABLE_TAGS_DROP); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_DROP); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; 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; yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n;
...@@ -2255,11 +2664,11 @@ static void yy_reduce( ...@@ -2255,11 +2664,11 @@ static void yy_reduce(
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1); A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-5].minor.yy0, NULL, A, ALTER_TABLE_TAGS_CHG); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_CHG); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; 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; yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n;
...@@ -2267,48 +2676,40 @@ static void yy_reduce( ...@@ -2267,48 +2676,40 @@ static void yy_reduce(
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
A = tVariantListAppend(A, &yymsp[0].minor.yy236, -1); A = tVariantListAppend(A, &yymsp[0].minor.yy236, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, ALTER_TABLE_TAGS_SET); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_SET); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; break;
case 213: /* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ case 210: /* 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);} {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; break;
case 214: /* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ 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); setDCLSQLElems(pInfo, KILL_STREAM, 1, &yymsp[-4].minor.yy0);} {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; break;
case 215: /* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ 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); setDCLSQLElems(pInfo, KILL_QUERY, 1, &yymsp[-4].minor.yy0);} {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; break;
default: default:
break; break;
/********** End reduce actions ************************************************/ /********** End reduce actions ************************************************/
}; };
assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) ); assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
yygoto = yyRuleInfo[yyruleno].lhs; yygoto = yyRuleInfo[yyruleno].lhs;
yysize = yyRuleInfo[yyruleno].nrhs; yysize = yyRuleInfo[yyruleno].nrhs;
yypParser->yyidx -= yysize; yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
if( yyact <= YY_MAX_SHIFTREDUCE ){ /* There are no SHIFTREDUCE actions on nonterminals because the table
if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; ** generator has simplified them to pure REDUCE actions. */
/* If the reduce action popped at least assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
** 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(). /* It is not possible for a REDUCE to be followed by an error */
** That gives a significant speed improvement. */ assert( yyact!=YY_ERROR_ACTION );
if( yysize ){
yypParser->yyidx++; yymsp += yysize+1;
yymsp -= yysize-1; yypParser->yytos = yymsp;
yymsp->stateno = (YYACTIONTYPE)yyact; yymsp->stateno = (YYACTIONTYPE)yyact;
yymsp->major = (YYCODETYPE)yygoto; yymsp->major = (YYCODETYPE)yygoto;
yymsp->minor = yygotominor; yyTraceShift(yypParser, yyact, "... then shift");
yyTraceShift(yypParser, yyact);
}else{
yy_shift(yypParser,yyact,yygoto,&yygotominor);
}
}else{
assert( yyact == YY_ACCEPT_ACTION );
yy_accept(yypParser);
}
} }
/* /*
...@@ -2324,7 +2725,7 @@ static void yy_parse_failed( ...@@ -2324,7 +2725,7 @@ static void yy_parse_failed(
fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
} }
#endif #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 /* Here code is inserted which will be executed whenever the
** parser fails */ ** parser fails */
/************ Begin %parse_failure code ***************************************/ /************ Begin %parse_failure code ***************************************/
...@@ -2339,13 +2740,13 @@ static void yy_parse_failed( ...@@ -2339,13 +2740,13 @@ static void yy_parse_failed(
static void yy_syntax_error( static void yy_syntax_error(
yyParser *yypParser, /* The parser */ yyParser *yypParser, /* The parser */
int yymajor, /* The major type of the error token */ 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; ParseARG_FETCH;
#define TOKEN (yyminor.yy0) #define TOKEN yyminor
/************ Begin %syntax_error code ****************************************/ /************ Begin %syntax_error code ****************************************/
pInfo->validSql = false; pInfo->valid = false;
int32_t outputBufLen = tListLen(pInfo->pzErrMsg); int32_t outputBufLen = tListLen(pInfo->pzErrMsg);
int32_t len = 0; int32_t len = 0;
...@@ -2382,7 +2783,10 @@ static void yy_accept( ...@@ -2382,7 +2783,10 @@ static void yy_accept(
fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
} }
#endif #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 /* Here code is inserted which will be executed whenever the
** parser accepts */ ** parser accepts */
/*********** Begin %parse_accept code *****************************************/ /*********** Begin %parse_accept code *****************************************/
...@@ -2417,7 +2821,7 @@ void Parse( ...@@ -2417,7 +2821,7 @@ void Parse(
ParseARG_PDECL /* Optional %extra_argument parameter */ ParseARG_PDECL /* Optional %extra_argument parameter */
){ ){
YYMINORTYPE yyminorunion; YYMINORTYPE yyminorunion;
int yyact; /* The parser action. */ unsigned int yyact; /* The parser action. */
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
int yyendofinput; /* True if we are at the end of input */ int yyendofinput; /* True if we are at the end of input */
#endif #endif
...@@ -2426,29 +2830,8 @@ void Parse( ...@@ -2426,29 +2830,8 @@ void Parse(
#endif #endif
yyParser *yypParser; /* The parser */ yyParser *yypParser; /* The parser */
/* (re)initialize the parser, if necessary */
yypParser = (yyParser*)yyp; yypParser = (yyParser*)yyp;
if( yypParser->yyidx<0 ){ assert( yypParser->yytos!=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;
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
yyendofinput = (yymajor==0); yyendofinput = (yymajor==0);
#endif #endif
...@@ -2456,21 +2839,34 @@ void Parse( ...@@ -2456,21 +2839,34 @@ void Parse(
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ 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 #endif
do{ do{
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
if( yyact <= YY_MAX_SHIFTREDUCE ){ if( yyact >= YY_MIN_REDUCE ){
if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
yy_shift(yypParser,yyact,yymajor,&yyminorunion); }else if( yyact <= YY_MAX_SHIFTREDUCE ){
yy_shift(yypParser,yyact,yymajor,yyminor);
#ifndef YYNOERRORRECOVERY
yypParser->yyerrcnt--; yypParser->yyerrcnt--;
#endif
yymajor = YYNOCODE; yymajor = YYNOCODE;
}else if( yyact <= YY_MAX_REDUCE ){ }else if( yyact==YY_ACCEPT_ACTION ){
yy_reduce(yypParser,yyact-YY_MIN_REDUCE); yypParser->yytos--;
yy_accept(yypParser);
return;
}else{ }else{
assert( yyact == YY_ERROR_ACTION ); assert( yyact == YY_ERROR_ACTION );
yyminorunion.yy0 = yyminor;
#ifdef YYERRORSYMBOL #ifdef YYERRORSYMBOL
int yymx; int yymx;
#endif #endif
...@@ -2500,9 +2896,9 @@ void Parse( ...@@ -2500,9 +2896,9 @@ void Parse(
** **
*/ */
if( yypParser->yyerrcnt<0 ){ 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 ){ if( yymx==YYERRORSYMBOL || yyerrorhit ){
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
...@@ -2510,26 +2906,26 @@ void Parse( ...@@ -2510,26 +2906,26 @@ void Parse(
yyTracePrompt,yyTokenName[yymajor]); yyTracePrompt,yyTokenName[yymajor]);
} }
#endif #endif
yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
yymajor = YYNOCODE; yymajor = YYNOCODE;
}else{ }else{
while( while( yypParser->yytos >= yypParser->yystack
yypParser->yyidx >= 0 && && yymx != YYERRORSYMBOL
yymx != YYERRORSYMBOL && && (yyact = yy_find_reduce_action(
(yyact = yy_find_reduce_action( yypParser->yytos->stateno,
yypParser->yystack[yypParser->yyidx].stateno,
YYERRORSYMBOL)) >= YY_MIN_REDUCE YYERRORSYMBOL)) >= YY_MIN_REDUCE
){ ){
yy_pop_parser_stack(yypParser); 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_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
yy_parse_failed(yypParser); yy_parse_failed(yypParser);
#ifndef YYNOERRORRECOVERY
yypParser->yyerrcnt = -1;
#endif
yymajor = YYNOCODE; yymajor = YYNOCODE;
}else if( yymx!=YYERRORSYMBOL ){ }else if( yymx!=YYERRORSYMBOL ){
YYMINORTYPE u2; yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
u2.YYERRSYMDT = 0;
yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
} }
} }
yypParser->yyerrcnt = 3; yypParser->yyerrcnt = 3;
...@@ -2542,7 +2938,7 @@ void Parse( ...@@ -2542,7 +2938,7 @@ void Parse(
** Applications can set this macro (for example inside %include) if ** Applications can set this macro (for example inside %include) if
** they intend to abandon the parse upon the first syntax error seen. ** 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); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
yymajor = YYNOCODE; yymajor = YYNOCODE;
...@@ -2557,24 +2953,29 @@ void Parse( ...@@ -2557,24 +2953,29 @@ void Parse(
** three input tokens have been successfully shifted. ** three input tokens have been successfully shifted.
*/ */
if( yypParser->yyerrcnt<=0 ){ if( yypParser->yyerrcnt<=0 ){
yy_syntax_error(yypParser,yymajor,yyminorunion); yy_syntax_error(yypParser,yymajor, yyminor);
} }
yypParser->yyerrcnt = 3; yypParser->yyerrcnt = 3;
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
if( yyendofinput ){ if( yyendofinput ){
yy_parse_failed(yypParser); yy_parse_failed(yypParser);
#ifndef YYNOERRORRECOVERY
yypParser->yyerrcnt = -1;
#endif
} }
yymajor = YYNOCODE; yymajor = YYNOCODE;
#endif #endif
} }
}while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack );
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
int i; yyStackEntry *i;
char cDiv = '[';
fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
for(i=1; i<=yypParser->yyidx; i++) for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ', fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
yyTokenName[yypParser->yystack[i].major]); cDiv = ' ';
}
fprintf(yyTraceFILE,"]\n"); fprintf(yyTraceFILE,"]\n");
} }
#endif #endif
......
...@@ -131,8 +131,8 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf ...@@ -131,8 +131,8 @@ static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOf
} }
/* update the limit value according to current retrieval results */ /* update the limit value according to current retrieval results */
pCmd->limit.limit = pCmd->globalLimit - pRes->numOfTotal; pCmd->pQueryInfo->limit.limit = pCmd->globalLimit - pRes->numOfTotal;
pCmd->limit.offset = pRes->offset; pCmd->pQueryInfo->limit.offset = pRes->offset;
if ((++(pMeterMetaInfo->vnodeIndex)) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { if ((++(pMeterMetaInfo->vnodeIndex)) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
tscTrace("%p retrieve data from next vnode:%d", pSql, pMeterMetaInfo->vnodeIndex); tscTrace("%p retrieve data from next vnode:%d", pSql, pMeterMetaInfo->vnodeIndex);
...@@ -282,7 +282,7 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) { ...@@ -282,7 +282,7 @@ void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows) {
} }
/* update the limit value according to current retrieval results */ /* 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) { if ((++pMeterMetaInfo->vnodeIndex) <= pMeterMetaInfo->pMetricMeta->numOfVnodes) {
pSql->cmd.command = TSDB_SQL_SELECT; // reset flag to launch query first. 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) ...@@ -407,7 +407,7 @@ void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows)
assert(!pCmd->isInsertFromFile && pSql->signature == pSql); assert(!pCmd->isInsertFromFile && pSql->signature == pSql);
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
assert(pCmd->numOfTables == 1); assert(pCmd->pQueryInfo->numOfTables == 1);
SDataBlockList *pDataBlocks = pCmd->pDataBlocks; SDataBlockList *pDataBlocks = pCmd->pDataBlocks;
if (pDataBlocks == NULL || pMeterMetaInfo->vnodeIndex >= pDataBlocks->nSize) { if (pDataBlocks == NULL || pMeterMetaInfo->vnodeIndex >= pDataBlocks->nSize) {
......
...@@ -53,11 +53,11 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor ...@@ -53,11 +53,11 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
*st = INT64_MAX; *st = INT64_MAX;
*et = INT64_MIN; *et = INT64_MIN;
SLimitVal* pLimit = &pSql->cmd.limit; SLimitVal* pLimit = &pSql->cmd.pQueryInfo->limit;
int32_t order = pSql->cmd.order.order; int32_t order = pSql->cmd.order.order;
pSql->pSubs[0]->cmd.tsBuf = output1; pSql->pSubs[0]->cmd.pQueryInfo->tsBuf = output1;
pSql->pSubs[1]->cmd.tsBuf = output2; pSql->pSubs[1]->cmd.pQueryInfo->tsBuf = output2;
tsBufResetPos(pSupporter1->pTSBuf); tsBufResetPos(pSupporter1->pTSBuf);
tsBufResetPos(pSupporter2->pTSBuf); tsBufResetPos(pSupporter2->pTSBuf);
...@@ -113,7 +113,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor ...@@ -113,7 +113,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
} }
// in case of stable query, limit/offset is not applied here // 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(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)); tsBufAppend(output2, elem2.vnode, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts));
} else { } else {
...@@ -168,8 +168,8 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS ...@@ -168,8 +168,8 @@ SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pS
pSupporter->pState = pState; pSupporter->pState = pState;
pSupporter->subqueryIndex = index; pSupporter->subqueryIndex = index;
pSupporter->interval = pSql->cmd.nAggTimeInterval; pSupporter->interval = pSql->cmd.pQueryInfo->nAggTimeInterval;
pSupporter->limit = pSql->cmd.limit; pSupporter->limit = pSql->cmd.pQueryInfo->limit;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, index); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, index);
pSupporter->uid = pMeterMetaInfo->pMeterMeta->uid; pSupporter->uid = pMeterMetaInfo->pMeterMeta->uid;
...@@ -211,8 +211,8 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) { ...@@ -211,8 +211,8 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) {
*/ */
bool needSecondaryQuery(SSqlObj* pSql) { bool needSecondaryQuery(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo->colList.numOfCols; ++i) {
SColumnBase* pBase = tscColumnBaseInfoGet(&pCmd->colList, i); SColumnBase* pBase = tscColumnBaseInfoGet(&pCmd->pQueryInfo->colList, i);
if (pBase->colIndex.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { if (pBase->colIndex.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
return true; return true;
} }
...@@ -272,25 +272,25 @@ int32_t tscLaunchSecondSubquery(SSqlObj* pSql) { ...@@ -272,25 +272,25 @@ int32_t tscLaunchSecondSubquery(SSqlObj* pSql) {
tscFreeSqlCmdData(&pNew->cmd); tscFreeSqlCmdData(&pNew->cmd);
pSql->pSubs[j++] = pNew; pSql->pSubs[j++] = pNew;
pNew->cmd.tsBuf = pSub->cmd.tsBuf; pNew->cmd.pQueryInfo->tsBuf = pSub->cmd.pQueryInfo->tsBuf;
pSub->cmd.tsBuf = NULL; pSub->cmd.pQueryInfo->tsBuf = NULL;
taos_free_result(pSub); taos_free_result(pSub);
// set the second stage sub query for join process // set the second stage sub query for join process
pNew->cmd.type |= TSDB_QUERY_TYPE_JOIN_SEC_STAGE; pNew->cmd.type |= TSDB_QUERY_TYPE_JOIN_SEC_STAGE;
pNew->cmd.nAggTimeInterval = pSupporter->interval; pNew->cmd.pQueryInfo->nAggTimeInterval = pSupporter->interval;
pNew->cmd.groupbyExpr = pSupporter->groupbyExpr; pNew->cmd.pQueryInfo->groupbyExpr = pSupporter->groupbyExpr;
tscColumnBaseInfoCopy(&pNew->cmd.colList, &pSupporter->colList, 0); tscColumnBaseInfoCopy(&pNew->cmd.pQueryInfo->colList, &pSupporter->colList, 0);
tscTagCondCopy(&pNew->cmd.tagCond, &pSupporter->tagCond); tscTagCondCopy(&pNew->cmd.pQueryInfo->tagCond, &pSupporter->tagCond);
tscSqlExprCopy(&pNew->cmd.exprsInfo, &pSupporter->exprsInfo, pSupporter->uid); tscSqlExprCopy(&pNew->cmd.pQueryInfo->exprsInfo, &pSupporter->exprsInfo, pSupporter->uid);
tscFieldInfoCopyAll(&pSupporter->fieldsInfo, &pNew->cmd.fieldsInfo); tscFieldInfoCopyAll(&pSupporter->fieldsInfo, &pNew->cmd.pQueryInfo->fieldsInfo);
// add the ts function for interval query if it is missing // 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); tscAddTimestampColumn(&pNew->cmd, TSDB_FUNC_TS, 0);
} }
...@@ -304,15 +304,15 @@ int32_t tscLaunchSecondSubquery(SSqlObj* pSql) { ...@@ -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 * When handling the projection query, the offset value will be modified for table-table join, which is changed
* during the timestamp intersection. * during the timestamp intersection.
*/ */
pSupporter->limit = pSql->cmd.limit; pSupporter->limit = pSql->cmd.pQueryInfo->limit;
pNew->cmd.limit = pSupporter->limit; pNew->cmd.pQueryInfo->limit = pSupporter->limit;
// fetch the join tag column // fetch the join tag column
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) { if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
SSqlExpr* pExpr = tscSqlExprGet(&pNew->cmd, 0); 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->param[0].i64Key = tagColIndex;
pExpr->numOfParams = 1; pExpr->numOfParams = 1;
} }
...@@ -370,10 +370,10 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter ...@@ -370,10 +370,10 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter
// update the query time range according to the join results on timestamp // update the query time range according to the join results on timestamp
static void updateQueryTimeRange(SSqlObj* pSql, int64_t st, int64_t et) { 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.pQueryInfo->stime = st;
pSql->cmd.etime = et; pSql->cmd.pQueryInfo->etime = et;
} }
static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
...@@ -408,7 +408,7 @@ 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); tscTrace("%p create tmp file for ts block:%s", pSql, pBuf->path);
pSupporter->pTSBuf = pBuf; pSupporter->pTSBuf = pBuf;
} else { } 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); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0);
tsBufMerge(pSupporter->pTSBuf, pBuf, pMeterMetaInfo->vnodeIndex); tsBufMerge(pSupporter->pTSBuf, pBuf, pMeterMetaInfo->vnodeIndex);
...@@ -424,7 +424,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { ...@@ -424,7 +424,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
} else if (numOfRows == 0) { // no data from this vnode anymore } else if (numOfRows == 0) { // no data from this vnode anymore
if (tscProjectionQueryOnMetric(&pParentSql->cmd)) { if (tscProjectionQueryOnMetric(&pParentSql->cmd)) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 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 // for projection query, need to try next vnode
if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
...@@ -480,7 +480,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { ...@@ -480,7 +480,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
if (tscProjectionQueryOnMetric(&pSql->cmd) && numOfRows == 0) { if (tscProjectionQueryOnMetric(&pSql->cmd) && numOfRows == 0) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 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 // for projection query, need to try next vnode if current vnode is exhausted
if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
...@@ -555,7 +555,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) { ...@@ -555,7 +555,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
// wait for all subqueries completed // wait for all subqueries completed
pSupporter->pState->numOfTotal = numOfFetch; pSupporter->pState->numOfTotal = numOfFetch;
assert(pRes1->numOfRows >= 0 && pCmd1->numOfTables == 1); assert(pRes1->numOfRows >= 0 && pCmd1->pQueryInfo->numOfTables == 1);
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd1, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd1, 0);
...@@ -589,13 +589,13 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { ...@@ -589,13 +589,13 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
return; // the column transfer support struct has been built 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
int32_t tableIndexOfSub = -1; 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]; SSqlObj* pSub = pSql->pSubs[j];
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSub->cmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSub->cmd, 0);
...@@ -607,7 +607,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { ...@@ -607,7 +607,7 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd; 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); SSqlExpr* pSubExpr = tscSqlExprGet(pSubCmd, k);
if (pExpr->functionId == pSubExpr->functionId && pExpr->colInfo.colId == pSubExpr->colInfo.colId) { if (pExpr->functionId == pSubExpr->functionId && pExpr->colInfo.colId == pSubExpr->colInfo.colId) {
pRes->pColumnIndex[i] = (SColumnIndex){.tableIndex = tableIndexOfSub, .columnIndex = k}; pRes->pColumnIndex[i] = (SColumnIndex){.tableIndex = tableIndexOfSub, .columnIndex = k};
......
...@@ -254,16 +254,16 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, ...@@ -254,16 +254,16 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
pCmd->order.order = TSQL_SO_ASC; 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; 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; 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); 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; rowLen += noteColLength;
return rowLen; return rowLen;
...@@ -321,7 +321,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) { ...@@ -321,7 +321,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
for (int32_t j = 0; j < pSidList->numOfSids; ++j) { for (int32_t j = 0; j < pSidList->numOfSids; ++j) {
SMeterSidExtInfo *pSidExt = tscGetMeterSidInfo(pSidList, 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; SColIndexEx *pColIndex = &tscSqlExprGet(pCmd, k)->colInfo;
int16_t offsetId = pColIndex->colIdx; int16_t offsetId = pColIndex->colIdx;
...@@ -352,7 +352,7 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) { ...@@ -352,7 +352,7 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
int32_t rowIdx = 0; int32_t rowIdx = 0;
for (int32_t i = 0; i < totalNumOfResults; ++i) { 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->colInfo.colIdx == -1 && pExpr->functionId == TSDB_FUNC_COUNT) { if (pExpr->colInfo.colIdx == -1 && pExpr->functionId == TSDB_FUNC_COUNT) {
...@@ -444,7 +444,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa ...@@ -444,7 +444,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
pCmd->numOfCols = 1; pCmd->numOfCols = 1;
pCmd->order.order = TSQL_SO_ASC; 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); tscInitResObjForLocalQuery(pSql, 1, valueLength);
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, 0); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, 0);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#include <hash.h>
#include "os.h" #include "os.h"
#include "ihash.h" #include "ihash.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
...@@ -953,7 +954,8 @@ int doParserInsertSql(SSqlObj *pSql, char *str) { ...@@ -953,7 +954,8 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
} }
if ((NULL == pSql->asyncTblPos) && (NULL == pSql->pTableHashList)) { 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(); pSql->cmd.pDataBlocks = tscCreateBlockArrayList();
if (NULL == pSql->pTableHashList || NULL == pSql->cmd.pDataBlocks) { if (NULL == pSql->pTableHashList || NULL == pSql->cmd.pDataBlocks) {
code = TSDB_CODE_CLI_OUT_OF_MEMORY; code = TSDB_CODE_CLI_OUT_OF_MEMORY;
...@@ -1239,8 +1241,9 @@ int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion) { ...@@ -1239,8 +1241,9 @@ int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion) {
tscRemoveAllMeterMetaInfo(&pSql->cmd, false); tscRemoveAllMeterMetaInfo(&pSql->cmd, false);
if (NULL == pSql->asyncTblPos) { if (NULL == pSql->asyncTblPos) {
tscTrace("continue parse sql: %s", pSql->asyncTblPos);
tscCleanSqlCmd(&pSql->cmd); tscCleanSqlCmd(&pSql->cmd);
} else {
tscTrace("continue parse sql: %s", pSql->asyncTblPos);
} }
if (tscIsInsertOrImportData(pSql->sqlstr)) { if (tscIsInsertOrImportData(pSql->sqlstr)) {
......
...@@ -70,7 +70,7 @@ static int32_t insertResultField(SSqlCmd* pCmd, int32_t outputIndex, SColumnList ...@@ -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 changeFunctionID(int32_t optr, int16_t* functionId);
static int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric); 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 hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd);
static bool functionCompatibleCheck(SSqlCmd* pCmd); static bool functionCompatibleCheck(SSqlCmd* pCmd);
static void setColumnOffsetValueInResultset(SSqlCmd* pCmd); static void setColumnOffsetValueInResultset(SSqlCmd* pCmd);
...@@ -114,6 +114,11 @@ static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate); ...@@ -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 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 * Used during parsing query sql. Since the query sql usually small in length, error position
* is not needed in the final error message. * is not needed in the final error message.
...@@ -126,7 +131,7 @@ static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) { ...@@ -126,7 +131,7 @@ static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) {
assert(QUERY_IS_STABLE_QUERY(pCmd->type)); assert(QUERY_IS_STABLE_QUERY(pCmd->type));
*queryOnMetricTags = true; *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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId != TSDB_FUNC_TAGPRJ && if (pExpr->functionId != TSDB_FUNC_TAGPRJ &&
...@@ -163,6 +168,30 @@ static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, tVariant* pVar) { ...@@ -163,6 +168,30 @@ static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, tVariant* pVar) {
return TSDB_CODE_SUCCESS; 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 // todo handle memory leak in error handle function
int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) { if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) {
...@@ -171,144 +200,100 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -171,144 +200,100 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSqlCmd* pCmd = &(pSql->cmd); SSqlCmd* pCmd = &(pSql->cmd);
if (!pInfo->validSql) { if (!pInfo->valid) {
return invalidSqlErrMsg(pCmd, pInfo->pzErrMsg); return invalidSqlErrMsg(pCmd, pInfo->pzErrMsg);
} }
SMeterMetaInfo* pMeterMetaInfo = tscAddEmptyMeterMetaInfo(pCmd); SMeterMetaInfo* pMeterMetaInfo = tscAddEmptyMeterMetaInfo(pCmd);
pCmd->command = pInfo->type;
// transfer pInfo into select operation int32_t code = 0;
switch (pInfo->sqlType) {
case DROP_TABLE: switch (pInfo->type) {
case DROP_USER: case TSDB_SQL_DROP_TABLE:
case DROP_ACCOUNT: case TSDB_SQL_DROP_USER:
case DROP_DNODE: case TSDB_SQL_DROP_ACCT:
case DROP_DATABASE: { case TSDB_SQL_DROP_DNODE:
const char* msg = "param name too long"; case TSDB_SQL_DROP_DB: {
const char* msg1 = "invalid ip address"; const char* msg1 = "invalid ip address";
const char* msg2 = "invalid name"; const char* msg2 = "invalid name";
const char* msg3 = "param name too long";
SSQLToken* pzName = &pInfo->pDCLInfo->a[0]; 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); return invalidSqlErrMsg(pCmd, msg2);
} }
if (pInfo->sqlType == DROP_DATABASE) { if (pInfo->type == TSDB_SQL_DROP_DB) {
assert(pInfo->pDCLInfo->nTokens == 2); assert(pInfo->pDCLInfo->nTokens == 1);
pCmd->command = TSDB_SQL_DROP_DB;
pCmd->existsCheck = (pInfo->pDCLInfo->a[1].n == 1);
int32_t code = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pzName, NULL, NULL); int32_t code = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pzName, NULL, NULL);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
return code; } else if (pInfo->type == TSDB_SQL_DROP_TABLE) {
} else if (pInfo->sqlType == DROP_TABLE) { assert(pInfo->pDCLInfo->nTokens == 1);
assert(pInfo->pDCLInfo->nTokens == 2);
pCmd->existsCheck = (pInfo->pDCLInfo->a[1].n == 1);
pCmd->command = TSDB_SQL_DROP_TABLE;
int32_t ret = setMeterID(pSql, pzName, 0); if (setMeterID(pSql, pzName, 0) != TSDB_CODE_SUCCESS) {
if (ret != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(pCmd, msg3);
invalidSqlErrMsg(pCmd, msg);
} }
return ret; } else if (pInfo->type == TSDB_SQL_DROP_DNODE) {
} else { if (!validateIpAddress(pzName->z, pzName->n)) {
if (pzName->n > TSDB_USER_LEN) { return invalidSqlErrMsg(pCmd, msg1);
return invalidSqlErrMsg(pCmd, msg);
} }
if (pInfo->sqlType == DROP_USER) { strncpy(pMeterMetaInfo->name, pzName->z, pzName->n);
pCmd->command = TSDB_SQL_DROP_USER; } else { // drop user
} else if (pInfo->sqlType == DROP_ACCOUNT) { if (pzName->n > TSDB_USER_LEN) {
pCmd->command = TSDB_SQL_DROP_ACCT; return invalidSqlErrMsg(pCmd, msg3);
} 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); strncpy(pMeterMetaInfo->name, pzName->z, pzName->n);
return TSDB_CODE_SUCCESS;
} }
}
case USE_DATABASE: { break;
pCmd->command = TSDB_SQL_USE_DB; }
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) { 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); return invalidSqlErrMsg(pCmd, msg);
} }
int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pToken, NULL, NULL); int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pToken, NULL, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return invalidSqlErrMsg(pCmd, msg);
} }
break; break;
} }
case RESET_QUERY_CACHE: { case TSDB_SQL_RESET_CACHE: {
pCmd->command = TSDB_SQL_RESET_CACHE; return TSDB_CODE_SUCCESS;
break;
} }
case SHOW_DATABASES: case TSDB_SQL_SHOW: {
case SHOW_TABLES: if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) {
case SHOW_STABLES: return TSDB_CODE_INVALID_SQL;
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);
} }
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); SCreateDBInfo* pCreateDB = &(pInfo->pDCLInfo->dbOpt);
if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) { if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) {
const char* msg3 = "invalid db name"; return invalidSqlErrMsg(pCmd, msg1);
return invalidSqlErrMsg(pCmd, msg3);
} }
int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL); int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
const char* msg2 = "name too long";
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
...@@ -319,168 +304,59 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -319,168 +304,59 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
break; break;
} }
case CREATE_DNODE: { case TSDB_SQL_CREATE_DNODE: { // todo parse hostname
// todo parse hostname
pCmd->command = TSDB_SQL_CREATE_DNODE;
const char* msg = "invalid ip address"; const char* msg = "invalid ip address";
char ipAddr[64] = {0}; if (pInfo->pDCLInfo->nTokens > 1) {
const int32_t MAX_IP_ADDRESS_LENGTH = 16;
if (pInfo->pDCLInfo->nTokens > 1 || pInfo->pDCLInfo->a[0].n > MAX_IP_ADDRESS_LENGTH) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
memcpy(ipAddr, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); SSQLToken* pIpAddr = &pInfo->pDCLInfo->a[0];
if (validateIpAddress(ipAddr) == false) { if (!validateIpAddress(pIpAddr->z, pIpAddr->n)) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n);
break; break;
} }
case CREATE_ACCOUNT: case TSDB_SQL_CREATE_ACCT:
case CREATE_USER: { case TSDB_SQL_ALTER_ACCT: {
pCmd->command = (pInfo->sqlType == CREATE_USER) ? TSDB_SQL_CREATE_USER : TSDB_SQL_CREATE_ACCT; const char* msg1 = "invalid state option, available options[no, r, w, all]";
assert(pInfo->pDCLInfo->nTokens >= 2); const char* msg2 = "invalid user/account name";
const char* msg3 = "name too long";
if (pInfo->pDCLInfo->a[1].type != TK_STRING) { SSQLToken* pName = &pInfo->pDCLInfo->user.user;
const char* msg3 = "password needs single quote marks enclosed"; SSQLToken* pPwd = &pInfo->pDCLInfo->user.passwd;
return invalidSqlErrMsg(pCmd, msg3);
}
strdequote(pInfo->pDCLInfo->a[1].z); if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) {
strtrim(pInfo->pDCLInfo->a[1].z); // trim space before and after passwords return TSDB_CODE_INVALID_SQL;
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 (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN) { if (pName->n > TSDB_USER_LEN) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg3);
} }
if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { if (tscValidateName(pName) != TSDB_CODE_SUCCESS) {
const char* msg2 = "invalid user/account name";
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); // name
SCreateAcctSQL* pAcctOpt = &pInfo->pDCLInfo->acctOpt; SCreateAcctSQL* pAcctOpt = &pInfo->pDCLInfo->acctOpt;
pCmd->defaultVal[0] = pAcctOpt->users; if (pAcctOpt->stat.n > 0) {
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) { 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) { } 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) { } 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) { } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) {
pCmd->defaultVal[8] = 0;
} else { } else {
const char* msg4 = "invalid state option, available options[no, r, w, all]"; return invalidSqlErrMsg(pCmd, msg1);
return invalidSqlErrMsg(pCmd, msg4);
} }
} }
break; break;
} }
case DESCRIBE_TABLE: {
pCmd->command = TSDB_SQL_DESCRIBE_TABLE;
case TSDB_SQL_DESCRIBE_TABLE: {
SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; 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"; const char* msg1 = "invalid table name";
if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) { if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
...@@ -488,107 +364,99 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -488,107 +364,99 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (pToken->n > TSDB_METER_NAME_LEN) { if (pToken->n > TSDB_METER_NAME_LEN) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg2);
} }
if (setMeterID(pSql, pToken, 0) != TSDB_CODE_SUCCESS) { if (setMeterID(pSql, pToken, 0) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg2);
}
int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
} }
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* msg1 = "invalid ip address";
const char* msg2 = "invalid configure options or values"; const char* msg2 = "invalid configure options or values";
const char* msg3 = "password can not be empty";
if (pInfo->sqlType != ALTER_DNODE) { /* validate the ip address */
strdequote(pDCL->a[1].z); tDCLSQL* pDCL = pInfo->pDCLInfo;
strtrim(pDCL->a[1].z); if (!validateIpAddress(pDCL->a[0].z, pDCL->a[0].n)) {
pDCL->a[1].n = strlen(pDCL->a[1].z); return invalidSqlErrMsg(pCmd, msg1);
} }
if (pDCL->a[1].n <= 0) { /* validate the parameter names and options */
return invalidSqlErrMsg(pCmd, msg3); 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) { char* pMsg = pCmd->payload + tsRpcHeadSize;
return invalidSqlErrMsg(pCmd, msg); pMsg += sizeof(SMgmtHead);
}
if (pCmd->command == TSDB_SQL_CFG_DNODE) { SCfgMsg* pCfg = (SCfgMsg*)pMsg;
char ip[128] = {0}; strncpy(pCfg->ip, pDCL->a[0].z, pDCL->a[0].n);
strncpy(ip, pDCL->a[0].z, pDCL->a[0].n);
/* validate the ip address */ strncpy(pCfg->config, pDCL->a[1].z, pDCL->a[1].n);
if (!validateIpAddress(ip)) {
return invalidSqlErrMsg(pCmd, msg1);
}
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 */ break;
if (validateDNodeConfig(pDCL) != TSDB_CODE_SUCCESS) { }
return invalidSqlErrMsg(pCmd, msg2);
}
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->command = pInfo->type;
pCmd->payload[pDCL->a[1].n] = ' '; // add sep tDCLSQL* pDCL = pInfo->pDCLInfo;
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";
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) { if (pName->n > TSDB_USER_LEN) {
/* update the password for user */ return invalidSqlErrMsg(pCmd, msg3);
pCmd->order.order |= TSDB_ALTER_USER_PASSWD; }
strdequote(pDCL->a[1].z); if (tscValidateName(pName) != TSDB_CODE_SUCCESS) {
pDCL->a[1].n = strlen(pDCL->a[1].z); return invalidSqlErrMsg(pCmd, msg2);
}
if (pDCL->a[1].n <= 0 || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { if (pCmd->command == TSDB_SQL_CREATE_USER) {
/* password cannot be empty string */ if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(pCmd, msg1); 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); if (strncasecmp(pUser->privilege.z, "super", 5) == 0 && pDCL->a[1].n == 5) {
} 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) {
pCmd->count = 1; pCmd->count = 1;
} else if (strncasecmp(pDCL->a[1].z, "read", 4) == 0 && pDCL->a[1].n == 4) { } else if (strncasecmp(pDCL->a[1].z, "read", 4) == 0 && pDCL->a[1].n == 4) {
pCmd->count = 2; pCmd->count = 2;
} else if (strncasecmp(pDCL->a[1].z, "write", 5) == 0 && pDCL->a[1].n == 5) { } else if (strncasecmp(pDCL->a[1].z, "write", 5) == 0 && pDCL->a[1].n == 5) {
pCmd->count = 3; pCmd->count = 3;
} else { } else {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg5);
} }
} else { } else {
return TSDB_CODE_INVALID_SQL; return invalidSqlErrMsg(pCmd, msg7);
} }
} }
break; break;
} }
case ALTER_LOCAL: {
pCmd->command = TSDB_SQL_CFG_LOCAL; case TSDB_SQL_CFG_LOCAL: {
tDCLSQL* pDCL = pInfo->pDCLInfo; tDCLSQL* pDCL = pInfo->pDCLInfo;
const char* msg = "invalid configure options or values"; const char* msg = "invalid configure options or values";
...@@ -605,447 +473,64 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -605,447 +473,64 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
break; 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; case TSDB_SQL_CREATE_TABLE: {
for (; col < pFieldList->nField; ++col) { SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo;
tscFieldInfoSetValFromField(&pCmd->fieldsInfo, col, &pFieldList->p[col]);
}
pCmd->numOfCols = (int16_t)pFieldList->nField;
if (pTagList != NULL) { // create metric[optional] if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) {
for (int32_t i = 0; i < pTagList->nField; ++i) { if ((code = doCheckForCreateTable(pSql, pInfo)) != TSDB_CODE_SUCCESS) {
tscFieldInfoSetValFromField(&pCmd->fieldsInfo, col++, &pTagList->p[i]); return code;
} }
pCmd->count = pTagList->nField;
}
break; } else if (pCreateTable->type == TSQL_CREATE_TABLE_FROM_STABLE) {
} if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) {
case TSQL_CREATE_METER_FROM_METRIC: { return code;
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);
} }
// validate the length of binary } else if (pCreateTable->type == TSQL_CREATE_STREAM) {
if ((pTagSchema[i].type == TSDB_DATA_TYPE_BINARY || pTagSchema[i].type == TSDB_DATA_TYPE_NCHAR) && if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) {
pList->a[i].pVar.nLen > pTagSchema[i].bytes) { return code;
return invalidSqlErrMsg(pCmd, msg3);
} }
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; 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) { case TSDB_SQL_SELECT: {
return invalidSqlErrMsg(pCmd, msg1); for(int32_t i = 0; i < pInfo->subclauseInfo.numOfClause; ++i) {
} SQuerySQL* pQuerySql = pInfo->subclauseInfo.pClause[i];
tVariantList* pSrcMeterName = pInfo->pCreateTableInfo->pSelect->from; if ((code = doCheckForQuery(pSql, pQuerySql, i)) != TSDB_CODE_SUCCESS) {
tVariant* pVar = &pSrcMeterName->a[0].pVar; return code;
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;
} }
} }
return TSDB_CODE_SUCCESS;// do not build query message here
}
if (setSlidingClause(pCmd, pQuerySql) != TSDB_CODE_SUCCESS) { case TSDB_SQL_ALTER_TABLE: {
return TSDB_CODE_INVALID_SQL; if ((code = setAlterTableInfo(pSql, pInfo)) != TSDB_CODE_SUCCESS) {
} return code;
// 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);
}
}
} }
break; break;
} }
case TSQL_QUERY_METER: { case TSDB_SQL_KILL_QUERY:
SQuerySQL* pQuerySql = pInfo->pQueryInfo; case TSDB_SQL_KILL_STREAM:
assert(pQuerySql != NULL && (pQuerySql->from == NULL || pQuerySql->from->nExpr > 0)); case TSDB_SQL_KILL_CONNECTION: {
if ((code = setKillInfo(pSql, pInfo)) != TSDB_CODE_SUCCESS) {
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) {
return code; 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; 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: 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) { ...@@ -1053,7 +538,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
* are available. * are available.
*/ */
static bool isTopBottomQuery(SSqlCmd* pCmd) { 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; int32_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) { if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
...@@ -1076,20 +561,20 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { ...@@ -1076,20 +561,20 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
// interval is not null // interval is not null
SSQLToken* t = &pQuerySql->interval; 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; return TSDB_CODE_INVALID_SQL;
} }
/* revised the time precision according to the flag */ /* revised the time precision according to the flag */
if (pMeterMetaInfo->pMeterMeta->precision == TSDB_TIME_PRECISION_MILLI) { 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 */ /* 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 // interval cannot be less than 10 milliseconds
if (pCmd->nAggTimeInterval < tsMinIntervalTime) { if (pCmd->pQueryInfo[0].nAggTimeInterval < tsMinIntervalTime) {
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
...@@ -1099,7 +584,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { ...@@ -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); // 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_COUNT && TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { if (pExpr->functionId == TSDB_FUNC_COUNT && TSDB_COL_IS_TAG(pExpr->colInfo.flag)) {
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
...@@ -1110,7 +595,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { ...@@ -1110,7 +595,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
uint64_t uid = tscSqlExprGet(pCmd, 0)->uid; uint64_t uid = tscSqlExprGet(pCmd, 0)->uid;
int32_t tableIndex = COLUMN_INDEX_INITIAL_VAL; 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); pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i);
if (pMeterMetaInfo->pMeterMeta->uid == uid) { if (pMeterMetaInfo->pMeterMeta->uid == uid) {
tableIndex = i; tableIndex = i;
...@@ -1139,16 +624,16 @@ int32_t setSlidingClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { ...@@ -1139,16 +624,16 @@ int32_t setSlidingClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
SSQLToken* pSliding = &pQuerySql->sliding; SSQLToken* pSliding = &pQuerySql->sliding;
if (pSliding->n != 0) { 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) { 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); return invalidSqlErrMsg(pCmd, msg0);
} }
if (pCmd->nSlidingTime > pCmd->nAggTimeInterval) { if (pCmd->pQueryInfo[0].nSlidingTime > pCmd->pQueryInfo[0].nAggTimeInterval) {
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
} }
} }
...@@ -1540,7 +1025,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric ...@@ -1540,7 +1025,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric
const char* msg3 = "not support query expression"; const char* msg3 = "not support query expression";
for (int32_t i = 0; i < pSelection->nExpr; ++i) { 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]; tSQLExprItem* pItem = &pSelection->a[i];
// project on all fields // project on all fields
...@@ -1607,7 +1092,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric ...@@ -1607,7 +1092,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric
return invalidSqlErrMsg(pCmd, msg3); 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; return TSDB_CODE_INVALID_SQL;
} }
} }
...@@ -1645,7 +1130,7 @@ int32_t insertResultField(SSqlCmd* pCmd, int32_t outputIndex, SColumnList* pIdLi ...@@ -1645,7 +1130,7 @@ int32_t insertResultField(SSqlCmd* pCmd, int32_t outputIndex, SColumnList* pIdLi
tscColumnBaseInfoInsert(pCmd, &(pIdList->ids[i])); 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; return TSDB_CODE_SUCCESS;
} }
...@@ -1769,7 +1254,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) { ...@@ -1769,7 +1254,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) {
const char* msg0 = "invalid column name"; const char* msg0 = "invalid column name";
const char* msg1 = "tag for table query is not allowed"; 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 if (pItem->pNode->nSQLOptr == TK_ALL) { // project on all fields
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
...@@ -1779,7 +1264,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) { ...@@ -1779,7 +1264,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) {
// all meters columns are required // all meters columns are required
if (index.tableIndex == COLUMN_INDEX_INITIAL_VAL) { // all table 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; index.tableIndex = i;
int32_t inc = doAddProjectionExprAndResultFields(pCmd, &index, startPos); int32_t inc = doAddProjectionExprAndResultFields(pCmd, &index, startPos);
startPos += inc; startPos += inc;
...@@ -1958,7 +1443,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem ...@@ -1958,7 +1443,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if ((getColumnIndexByNameEx(&pParamElem->pNode->colInfo, pCmd, &index) != TSDB_CODE_SUCCESS) || 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); return invalidSqlErrMsg(pCmd, msg3);
} }
...@@ -2096,7 +1581,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem ...@@ -2096,7 +1581,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
} else { // select * from xxx } else { // select * from xxx
int32_t numOfFields = 0; 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); pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, j);
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
...@@ -2292,7 +1777,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p ...@@ -2292,7 +1777,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p
} else { } else {
// not specify the table name, try to locate the table index by column name // not specify the table name, try to locate the table index by column name
if (pIndex->tableIndex == COLUMN_INDEX_INITIAL_VAL) { 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); int16_t colIndex = doGetColumnIndex(pCmd, i, pToken);
if (colIndex != COLUMN_INDEX_INITIAL_VAL) { if (colIndex != COLUMN_INDEX_INITIAL_VAL) {
...@@ -2325,7 +1810,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p ...@@ -2325,7 +1810,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* p
static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex) { 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 (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; pIndex->tableIndex = 0;
} }
...@@ -2335,7 +1820,7 @@ static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex ...@@ -2335,7 +1820,7 @@ static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex
pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL; pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL;
char tableName[TSDB_METER_ID_LEN + 1] = {0}; 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); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i);
extractTableName(pMeterMetaInfo->name, tableName); extractTableName(pMeterMetaInfo->name, tableName);
...@@ -2364,7 +1849,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pInd ...@@ -2364,7 +1849,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pInd
} }
int32_t getColumnIndexByNameEx(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex) { 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; return TSDB_CODE_INVALID_SQL;
} }
...@@ -2440,125 +1925,75 @@ int32_t changeFunctionID(int32_t optr, int16_t* functionId) { ...@@ -2440,125 +1925,75 @@ int32_t changeFunctionID(int32_t optr, int16_t* functionId) {
return TSDB_CODE_SUCCESS; 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) { int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pCmd->command = TSDB_SQL_SHOW; pCmd->command = TSDB_SQL_SHOW;
int8_t type = pInfo->sqlType;
const char* msg = "database name too long"; const char* msg1 = "invalid name";
const char* msg1 = "invalid database name";
const char* msg2 = "pattern filter string too long"; const char* msg2 = "pattern filter string too long";
const char* msg3 = "database name too long";
switch (type) { const char* msg4 = "invalid ip address";
case SHOW_VGROUPS: const char* msg5 = "database name is empty";
pCmd->showType = TSDB_MGMT_TABLE_VGROUP; const char* msg6 = "pattern string is empty";
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;
}
/* /*
* database prefix in pInfo->pDCLInfo->a[0] * database prefix in pInfo->pDCLInfo->a[0]
* wildcard in like clause in pInfo->pDCLInfo->a[1] * 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 // db prefix in tagCond, show table conds in payload
if (pInfo->pDCLInfo->nTokens > 0) { SSQLToken* pDbPrefixToken = &pShowInfo->prefix;
SSQLToken* pDbPrefixToken = &pInfo->pDCLInfo->a[0]; if (pDbPrefixToken->type != 0) {
assert(pDbPrefixToken->n >= 0);
if (pDbPrefixToken->n > TSDB_DB_NAME_LEN) { // db name is too long 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) { if (pDbPrefixToken->n <= 0) {
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg5);
} }
int32_t ret = 0; if (tscValidateName(pDbPrefixToken) != TSDB_CODE_SUCCESS) {
if (pDbPrefixToken->n > 0) { // has db prefix return invalidSqlErrMsg(pCmd, msg1);
ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pDbPrefixToken, NULL, NULL);
} }
int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), pDbPrefixToken, NULL, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return invalidSqlErrMsg(pCmd, msg1);
} }
}
if (type != SHOW_VGROUPS && pInfo->pDCLInfo->nTokens == 2) { // show table/stable like 'xxxx', set the like pattern for show tables
// set the like conds for show tables SSQLToken* pPattern = &pShowInfo->pattern;
SSQLToken* likeToken = &pInfo->pDCLInfo->a[1]; if (pPattern->type != 0) {
pPattern->n = strdequote(pPattern->z);
strncpy(pCmd->payload, likeToken->z, likeToken->n); if (pPattern->n <= 0) {
pCmd->payloadLen = strdequote(pCmd->payload); return invalidSqlErrMsg(pCmd, msg6);
}
if (pCmd->payloadLen > TSDB_METER_NAME_LEN) { if (pCmd->payloadLen > TSDB_METER_NAME_LEN) {
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
}
} }
} }
} else if (type == SHOW_VNODES) { } else if (showType == TSDB_MGMT_TABLE_VNODES) {
if (NULL == pInfo->pDCLInfo) { if (pShowInfo->prefix.type == 0) {
return invalidSqlErrMsg(pCmd, "No specified ip of dnode"); return invalidSqlErrMsg(pCmd, "No specified ip of dnode");
} }
// show vnodes may be ip addr of dnode in payload // show vnodes may be ip addr of dnode in payload
if (pInfo->pDCLInfo->nTokens > 0) { SSQLToken* pDnodeIp = &pShowInfo->prefix;
SSQLToken* pDnodeIp = &pInfo->pDCLInfo->a[0]; if (pDnodeIp->n > TSDB_IPv4ADDR_LEN) { // ip addr is too long
return invalidSqlErrMsg(pCmd, msg3);
if (pDnodeIp->n > TSDB_IPv4ADDR_LEN) { // ip addr is too long }
return invalidSqlErrMsg(pCmd, msg);
}
strncpy(pCmd->payload, pDnodeIp->z, pDnodeIp->n); if (!validateIpAddress(pDnodeIp->z, pDnodeIp->n)) {
pCmd->payloadLen = strdequote(pCmd->payload); return invalidSqlErrMsg(pCmd, msg4);
} }
} }
...@@ -2566,54 +2001,48 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -2566,54 +2001,48 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
int32_t setKillInfo(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) { SSqlCmd* pCmd = &pSql->cmd;
case KILL_QUERY: pCmd->command = pInfo->type;
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;
}
SSQLToken* pToken = &(pInfo->pDCLInfo->a[0]); SSQLToken* ip = &(pInfo->pDCLInfo->ip);
if (pToken->n > TSDB_KILL_MSG_LEN) { if (ip->n > TSDB_KILL_MSG_LEN) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
strncpy(pCmd->payload, pToken->z, pToken->n); strncpy(pCmd->payload, ip->z, ip->n);
const char delim = ':'; 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)); memset(pCmd->payload, 0, tListLen(pCmd->payload));
const char* msg = "invalid ip address"; return invalidSqlErrMsg(pCmd, msg1);
return invalidSqlErrMsg(pCmd, msg);
} }
uint16_t port = (uint16_t)strtol(portStr, NULL, 10); uint16_t port = (uint16_t)strtol(portStr, NULL, 10);
if (port <= 0 || port > 65535) { if (port <= 0 || port > 65535) {
memset(pCmd->payload, 0, tListLen(pCmd->payload)); memset(pCmd->payload, 0, tListLen(pCmd->payload));
return invalidSqlErrMsg(pCmd, msg2);
const char* msg = "invalid port";
return invalidSqlErrMsg(pCmd, msg);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool validateIpAddress(char* ip) { bool validateIpAddress(const char* ip, size_t size) {
in_addr_t ipAddr = inet_addr(ip); char tmp[128] = {0}; // buffer to build null-terminated string
return (ipAddr != 0) && (ipAddr != 0xffffffff); assert(size < 128);
strncpy(tmp, ip, size);
in_addr_t ipAddr = inet_addr(tmp);
return ipAddr != INADDR_NONE;
} }
int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd* pCmd) { int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd* pCmd) {
...@@ -2629,7 +2058,7 @@ int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd* pCmd) { ...@@ -2629,7 +2058,7 @@ int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd* pCmd) {
int16_t type = 0; int16_t type = 0;
int16_t intermediateBytes = 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, k);
TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, k); TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, k);
...@@ -2659,7 +2088,7 @@ void tscRestoreSQLFunctionForMetricQuery(SSqlCmd* pCmd) { ...@@ -2659,7 +2088,7 @@ void tscRestoreSQLFunctionForMetricQuery(SSqlCmd* pCmd) {
return; 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, i); TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, i);
...@@ -2676,7 +2105,7 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) { ...@@ -2676,7 +2105,7 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) {
const char* msg2 = "TWA only support group by tbname for super table query"; const char* msg2 = "TWA only support group by tbname for super table query";
// filter sql function not supported by metric query yet. // 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; int32_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_METRIC) == 0) { if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_METRIC) == 0) {
return true; return true;
...@@ -2684,12 +2113,12 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) { ...@@ -2684,12 +2113,12 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) {
} }
if (tscIsTWAQuery(pCmd)) { if (tscIsTWAQuery(pCmd)) {
if (pCmd->groupbyExpr.numOfGroupCols == 0) { if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols == 0) {
invalidSqlErrMsg(pCmd, msg1); invalidSqlErrMsg(pCmd, msg1);
return true; 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); invalidSqlErrMsg(pCmd, msg2);
return true; return true;
} }
...@@ -2711,7 +2140,7 @@ static bool functionCompatibleCheck(SSqlCmd* pCmd) { ...@@ -2711,7 +2140,7 @@ static bool functionCompatibleCheck(SSqlCmd* pCmd) {
// diff function cannot be executed with other function // diff function cannot be executed with other function
// arithmetic function can be executed with other arithmetic functions // 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
int16_t functionId = pExpr->functionId; int16_t functionId = pExpr->functionId;
...@@ -2738,14 +2167,14 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) { ...@@ -2738,14 +2167,14 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) {
* update tags column index for group by tags * update tags column index for group by tags
* group by columns belong to this table * group by columns belong to this table
*/ */
if (pCmd->groupbyExpr.numOfGroupCols > 0 && pCmd->groupbyExpr.tableIndex == tableIndex) { if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0 && pCmd->pQueryInfo[0].groupbyExpr.tableIndex == tableIndex) {
for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) {
int32_t index = pCmd->groupbyExpr.columnInfo[i].colIdx; int32_t index = pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i].colIdx;
for (int32_t j = 0; j < pMeterMetaInfo->numOfTags; ++j) { for (int32_t j = 0; j < pMeterMetaInfo->numOfTags; ++j) {
int32_t tagColIndex = pMeterMetaInfo->tagColumnIndex[j]; int32_t tagColIndex = pMeterMetaInfo->tagColumnIndex[j];
if (tagColIndex == index) { if (tagColIndex == index) {
pCmd->groupbyExpr.columnInfo[i].colIdx = j; pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i].colIdx = j;
break; break;
} }
} }
...@@ -2753,7 +2182,7 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) { ...@@ -2753,7 +2182,7 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) {
} }
// update tags column index for expression // 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (!TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { // not tags, continue if (!TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { // not tags, continue
...@@ -2774,7 +2203,7 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) { ...@@ -2774,7 +2203,7 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) {
} }
// update join condition tag column index // update join condition tag column index
SJoinInfo* pJoinInfo = &pCmd->tagCond.joinInfo; SJoinInfo* pJoinInfo = &pCmd->pQueryInfo[0].tagCond.joinInfo;
if (!pJoinInfo->hasJoin) { // not join query if (!pJoinInfo->hasJoin) { // not join query
return; return;
} }
...@@ -2814,7 +2243,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) { ...@@ -2814,7 +2243,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
pCmd->groupbyExpr.numOfGroupCols = pList->nExpr; pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols = pList->nExpr;
if (pList->nExpr > TSDB_MAX_TAGS) { if (pList->nExpr > TSDB_MAX_TAGS) {
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
} }
...@@ -2865,19 +2294,19 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) { ...@@ -2865,19 +2294,19 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
relIndex -= pMeterMeta->numOfColumns; relIndex -= pMeterMeta->numOfColumns;
} }
pCmd->groupbyExpr.columnInfo[i] = pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i] =
(SColIndexEx){.colIdx = relIndex, .flag = TSDB_COL_TAG, .colId = pSchema->colId}; // relIndex; (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 { } else {
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by // 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); return invalidSqlErrMsg(pCmd, msg8);
} }
tscColumnBaseInfoInsert(pCmd, &index); 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; (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) { if (i == 0 && pList->nExpr > 1) {
return invalidSqlErrMsg(pCmd, msg7); return invalidSqlErrMsg(pCmd, msg7);
...@@ -2885,7 +2314,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) { ...@@ -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; return TSDB_CODE_SUCCESS;
} }
...@@ -3213,7 +2642,7 @@ static void relToString(SSqlCmd* pCmd, tSQLExpr* pExpr, char** str) { ...@@ -3213,7 +2642,7 @@ static void relToString(SSqlCmd* pCmd, tSQLExpr* pExpr, char** str) {
const char* or = "OR"; const char* or = "OR";
const char*and = "AND"; 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) { if (pExpr->nSQLOptr == TK_AND) {
strcpy(*str, and); strcpy(*str, and);
*str += strlen(and); *str += strlen(and);
...@@ -3315,7 +2744,7 @@ static int32_t getJoinCondInfo(SSqlObj* pSql, tSQLExpr* pExpr) { ...@@ -3315,7 +2744,7 @@ static int32_t getJoinCondInfo(SSqlObj* pSql, tSQLExpr* pExpr) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
STagCond* pTagCond = &pCmd->tagCond; STagCond* pTagCond = &pCmd->pQueryInfo[0].tagCond;
SJoinNode* pLeft = &pTagCond->joinInfo.left; SJoinNode* pLeft = &pTagCond->joinInfo.left;
SJoinNode* pRight = &pTagCond->joinInfo.right; SJoinNode* pRight = &pTagCond->joinInfo.right;
...@@ -3847,14 +3276,14 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_ ...@@ -3847,14 +3276,14 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, tableCondIndex); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, tableCondIndex);
STagCond* pTagCond = &pSql->cmd.tagCond; STagCond* pTagCond = &pSql->cmd.pQueryInfo[0].tagCond;
pTagCond->tbnameCond.uid = pMeterMetaInfo->pMeterMeta->uid; pTagCond->tbnameCond.uid = pMeterMetaInfo->pMeterMeta->uid;
assert(pExpr->nSQLOptr == TK_LIKE || pExpr->nSQLOptr == TK_IN); assert(pExpr->nSQLOptr == TK_LIKE || pExpr->nSQLOptr == TK_IN);
if (pExpr->nSQLOptr == TK_LIKE) { if (pExpr->nSQLOptr == TK_LIKE) {
char* str = taosStringBuilderGetResult(sb, NULL); char* str = taosStringBuilderGetResult(sb, NULL);
pCmd->tagCond.tbnameCond.cond = strdup(str); pCmd->pQueryInfo[0].tagCond.tbnameCond.cond = strdup(str);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -3903,7 +3332,7 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_ ...@@ -3903,7 +3332,7 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_
} }
char* str = taosStringBuilderGetResult(&sb1, NULL); char* str = taosStringBuilderGetResult(&sb1, NULL);
pCmd->tagCond.tbnameCond.cond = strdup(str); pCmd->pQueryInfo[0].tagCond.tbnameCond.cond = strdup(str);
taosStringBuilderDestroy(&sb1); taosStringBuilderDestroy(&sb1);
tfree(segments); tfree(segments);
...@@ -3911,8 +3340,8 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_ ...@@ -3911,8 +3340,8 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_
} }
static bool validateFilterExpr(SSqlCmd* pCmd) { static bool validateFilterExpr(SSqlCmd* pCmd) {
for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo[0].colList.numOfCols; ++i) {
SColumnBase* pColBase = &pCmd->colList.pColList[i]; SColumnBase* pColBase = &pCmd->pQueryInfo[0].colList.pColList[i];
for (int32_t j = 0; j < pColBase->numOfFilters; ++j) { for (int32_t j = 0; j < pColBase->numOfFilters; ++j) {
SColumnFilterInfo* pColFilter = &pColBase->filterInfo[j]; SColumnFilterInfo* pColFilter = &pColBase->filterInfo[j];
...@@ -3969,12 +3398,12 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, tSQLExpr* pExpr) { ...@@ -3969,12 +3398,12 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, tSQLExpr* pExpr) {
} }
// update the timestamp query range // update the timestamp query range
if (pCmd->stime < stime) { if (pCmd->pQueryInfo[0].stime < stime) {
pCmd->stime = stime; pCmd->pQueryInfo[0].stime = stime;
} }
if (pCmd->etime > etime) { if (pCmd->pQueryInfo[0].etime > etime) {
pCmd->etime = etime; pCmd->pQueryInfo[0].etime = etime;
} }
} }
...@@ -3987,7 +3416,7 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr) { ...@@ -3987,7 +3416,7 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr) {
const char* msg3 = "condition missing for join query"; const char* msg3 = "condition missing for join query";
if (!QUERY_IS_JOIN_QUERY(pCmd->type)) { if (!QUERY_IS_JOIN_QUERY(pCmd->type)) {
if (pCmd->numOfTables == 1) { if (pCmd->pQueryInfo->numOfTables == 1) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
return invalidSqlErrMsg(pCmd, msg3); return invalidSqlErrMsg(pCmd, msg3);
...@@ -4054,7 +3483,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr ...@@ -4054,7 +3483,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
if (pCondExpr->pTagCond != NULL) { 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); tSQLExpr* p1 = extractExprForSTable(pExpr, pCmd, i);
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i);
...@@ -4066,7 +3495,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr ...@@ -4066,7 +3495,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr
return ret; return ret;
} }
tsSetMetricQueryCond(&pCmd->tagCond, pMeterMetaInfo->pMeterMeta->uid, c); tsSetMetricQueryCond(&pCmd->pQueryInfo[0].tagCond, pMeterMetaInfo->pMeterMeta->uid, c);
doCompactQueryExpr(pExpr); doCompactQueryExpr(pExpr);
tSQLExprDestroy(p1); tSQLExprDestroy(p1);
...@@ -4088,8 +3517,8 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) { ...@@ -4088,8 +3517,8 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) {
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
pCmd->stime = 0; pCmd->pQueryInfo[0].stime = 0;
pCmd->etime = INT64_MAX; pCmd->pQueryInfo[0].etime = INT64_MAX;
// tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space // tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space
SStringBuilder sb = {0}; SStringBuilder sb = {0};
...@@ -4140,7 +3569,7 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) { ...@@ -4140,7 +3569,7 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) {
} }
// 7. query condition for table name // 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); ret = setTableCondForMetricQuery(pSql, condExpr.pTableCond, condExpr.tableCondIndex, &sb);
taosStringBuilderDestroy(&sb); taosStringBuilderDestroy(&sb);
...@@ -4247,7 +3676,7 @@ int32_t getTimeRange(int64_t* stime, int64_t* etime, tSQLExpr* pRight, int32_t o ...@@ -4247,7 +3676,7 @@ int32_t getTimeRange(int64_t* stime, int64_t* etime, tSQLExpr* pRight, int32_t o
int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd) { int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd) {
const char rep[] = {'(', ')', '*', ',', '.', '/', '\\', '+', '-', '%', ' '}; 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; char* fieldName = tscFieldInfoGetField(pCmd, i)->name;
for (int32_t j = 0; j < TSDB_COL_NAME_LEN && fieldName[j] != 0; ++j) { for (int32_t j = 0; j < TSDB_COL_NAME_LEN && fieldName[j] != 0; ++j) {
for (int32_t k = 0; k < tListLen(rep); ++k) { for (int32_t k = 0; k < tListLen(rep); ++k) {
...@@ -4262,9 +3691,9 @@ int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd) { ...@@ -4262,9 +3691,9 @@ int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd) {
} }
// the column name may be identical, here check again // 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; 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) { if (strncasecmp(fieldName, tscFieldInfoGetField(pCmd, j)->name, TSDB_COL_NAME_LEN) == 0) {
const char* msg = "duplicated column name in new table"; const char* msg = "duplicated column name in new table";
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
...@@ -4289,20 +3718,20 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) { ...@@ -4289,20 +3718,20 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) {
} }
if (strncasecmp(pItem->pVar.pz, "none", 4) == 0 && pItem->pVar.nLen == 4) { 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) { } else if (strncasecmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4) {
pCmd->interpoType = TSDB_INTERPO_NULL; pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_NULL;
for (int32_t i = START_INTERPO_COL_IDX; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = START_INTERPO_COL_IDX; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
TAOS_FIELD* pFields = tscFieldInfoGetField(pCmd, 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) { } 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) { } else if (strncasecmp(pItem->pVar.pz, "linear", 6) == 0 && pItem->pVar.nLen == 6) {
// not support yet // 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) { } 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) { if (pFillToken->nExpr == 1) {
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
...@@ -4315,12 +3744,12 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) { ...@@ -4315,12 +3744,12 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) {
if (tscIsPointInterpQuery(pCmd)) { if (tscIsPointInterpQuery(pCmd)) {
startPos = 0; startPos = 0;
if (numOfFillVal > pCmd->fieldsInfo.numOfOutputCols) { if (numOfFillVal > pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) {
numOfFillVal = pCmd->fieldsInfo.numOfOutputCols; numOfFillVal = pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols;
} }
} else { } else {
numOfFillVal = 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; int32_t j = 1;
...@@ -4328,26 +3757,26 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) { ...@@ -4328,26 +3757,26 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL) {
for (int32_t i = startPos; i < numOfFillVal; ++i, ++j) { for (int32_t i = startPos; i < numOfFillVal; ++i, ++j) {
TAOS_FIELD* pFields = tscFieldInfoGetField(pCmd, i); 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) { if (ret != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
if (pFields->type == TSDB_DATA_TYPE_BINARY || pFields->type == TSDB_DATA_TYPE_NCHAR) { 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) || if ((pFillToken->nExpr < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) ||
((pFillToken->nExpr - 1 < pCmd->fieldsInfo.numOfOutputCols) && (tscIsPointInterpQuery(pCmd)))) { ((pFillToken->nExpr - 1 < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) && (tscIsPointInterpQuery(pCmd)))) {
tVariantListItem* lastItem = &pFillToken->a[pFillToken->nExpr - 1]; 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); 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) { 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) { ...@@ -4372,7 +3801,7 @@ static void setDefaultOrderInfo(SSqlCmd* pCmd) {
/* for metric query, set default ascending order for group output */ /* for metric query, set default ascending order for group output */
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) { 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 ...@@ -4428,7 +3857,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
if (index.columnIndex >= pMeterMetaInfo->pMeterMeta->numOfColumns) { if (index.columnIndex >= pMeterMetaInfo->pMeterMeta->numOfColumns) {
int32_t relTagIndex = 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; orderByTags = true;
} }
} else if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { } else if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
...@@ -4447,8 +3876,8 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema ...@@ -4447,8 +3876,8 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
if (pSortorder->nExpr == 1) { if (pSortorder->nExpr == 1) {
if (orderByTags) { if (orderByTags) {
pCmd->groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; pCmd->pQueryInfo[0].groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns;
pCmd->groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder; pCmd->pQueryInfo[0].groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder;
} else if (isTopBottomQuery(pCmd)) { } else if (isTopBottomQuery(pCmd)) {
/* order of top/bottom query in interval is not valid */ /* order of top/bottom query in interval is not valid */
SSqlExpr* pExpr = tscSqlExprGet(pCmd, 0); SSqlExpr* pExpr = tscSqlExprGet(pCmd, 0);
...@@ -4470,8 +3899,8 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema ...@@ -4470,8 +3899,8 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
if (pSortorder->nExpr == 2) { if (pSortorder->nExpr == 2) {
if (orderByTags) { if (orderByTags) {
pCmd->groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; pCmd->pQueryInfo[0].groupbyExpr.orderIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns;
pCmd->groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder; pCmd->pQueryInfo[0].groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder;
} else { } else {
pCmd->order.order = pSortorder->a[0].sortOrder; pCmd->order.order = pSortorder->a[0].sortOrder;
pCmd->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; pCmd->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
...@@ -4523,21 +3952,25 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema ...@@ -4523,21 +3952,25 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const int32_t DEFAULT_TABLE_INDEX = 0; 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; SSqlCmd* pCmd = &pSql->cmd;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, DEFAULT_TABLE_INDEX);
SAlterTableSQL* pAlterSQL = pInfo->pAlterInfo; SAlterTableSQL* pAlterSQL = pInfo->pAlterInfo;
pCmd->command = TSDB_SQL_ALTER_TABLE;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, DEFAULT_TABLE_INDEX);
if (tscValidateName(&(pAlterSQL->name)) != TSDB_CODE_SUCCESS) { if (tscValidateName(&(pAlterSQL->name)) != TSDB_CODE_SUCCESS) {
const char* msg = "invalid table name"; return invalidSqlErrMsg(pCmd, msg1);
return invalidSqlErrMsg(pCmd, msg);
} }
if (setMeterID(pSql, &(pAlterSQL->name), 0) != TSDB_CODE_SUCCESS) { if (setMeterID(pSql, &(pAlterSQL->name), 0) != TSDB_CODE_SUCCESS) {
const char* msg = "table name too long"; return invalidSqlErrMsg(pCmd, msg2);
return invalidSqlErrMsg(pCmd, msg);
} }
int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo->name, DEFAULT_TABLE_INDEX); int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo->name, DEFAULT_TABLE_INDEX);
...@@ -4546,41 +3979,31 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4546,41 +3979,31 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
SMeterMeta* pMeterMeta = pMeterMetaInfo->pMeterMeta; SMeterMeta* pMeterMeta = pMeterMetaInfo->pMeterMeta;
SSchema* pSchema = tsGetSchema(pMeterMeta);
if (pInfo->sqlType == ALTER_TABLE_TAGS_ADD || pInfo->sqlType == ALTER_TABLE_TAGS_DROP || if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN || pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN ||
pInfo->sqlType == ALTER_TABLE_TAGS_CHG) { pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) { if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) {
const char* msg = "manipulation of tag available for metric"; return invalidSqlErrMsg(pCmd, msg3);
return invalidSqlErrMsg(pCmd, msg);
} }
} else if ((pInfo->sqlType == ALTER_TABLE_TAGS_SET) && (UTIL_METER_IS_METRIC(pMeterMetaInfo))) { } else if ((pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) && (UTIL_METER_IS_METRIC(pMeterMetaInfo))) {
const char* msg = "set tag value only available for table"; return invalidSqlErrMsg(pCmd, msg4);
return invalidSqlErrMsg(pCmd, msg); } else if ((pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN || pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) &&
} else if ((pInfo->sqlType == ALTER_TABLE_ADD_COLUMN || pInfo->sqlType == ALTER_TABLE_DROP_COLUMN) &&
UTIL_METER_IS_CREATE_FROM_METRIC(pMeterMetaInfo)) { UTIL_METER_IS_CREATE_FROM_METRIC(pMeterMetaInfo)) {
const char* msg = "column can only be modified by metric"; return invalidSqlErrMsg(pCmd, msg6);
return invalidSqlErrMsg(pCmd, msg);
} }
if (pInfo->sqlType == ALTER_TABLE_TAGS_ADD) { if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) {
pCmd->count = TSDB_ALTER_TABLE_ADD_TAG_COLUMN;
tFieldList* pFieldList = pAlterSQL->pAddColumns; tFieldList* pFieldList = pAlterSQL->pAddColumns;
if (pFieldList->nField > 1) { if (pFieldList->nField > 1) {
const char* msg = "only support add one tag"; return invalidSqlErrMsg(pCmd, msg5);
return invalidSqlErrMsg(pCmd, msg);
} }
if (!validateOneTags(pCmd, &pFieldList->p[0])) { if (!validateOneTags(pCmd, &pFieldList->p[0])) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
tscFieldInfoSetValFromField(&pCmd->fieldsInfo, 0, &pFieldList->p[0]); tscFieldInfoSetValFromField(&pCmd->pQueryInfo[0].fieldsInfo, 0, &pFieldList->p[0]);
pCmd->numOfCols = 1; // only one column } else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) {
} else if (pInfo->sqlType == ALTER_TABLE_TAGS_DROP) {
pCmd->count = TSDB_ALTER_TABLE_DROP_TAG_COLUMN;
const char* msg1 = "no tags can be dropped"; const char* msg1 = "no tags can be dropped";
const char* msg2 = "only support one tag"; const char* msg2 = "only support one tag";
...@@ -4601,36 +4024,28 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4601,36 +4024,28 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (pItem->pVar.nLen > TSDB_COL_NAME_LEN) { if (pItem->pVar.nLen > TSDB_COL_NAME_LEN) {
return invalidSqlErrMsg(pCmd, msg3); return invalidSqlErrMsg(pCmd, msg3);
} }
int32_t idx = -1; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
for (int32_t i = 0; i < pMeterMeta->numOfTags; ++i) { SSQLToken name = {.z = pItem->pVar.pz, .n = pItem->pVar.nLen, .type = TK_STRING};
int32_t tagIdx = i + pMeterMeta->numOfColumns;
char* tagName = pSchema[tagIdx].name; if (getColumnIndexByNameEx(&name, pCmd, &index) != TSDB_CODE_SUCCESS) {
size_t nLen = strlen(tagName); return TSDB_CODE_INVALID_SQL;
if ((strncasecmp(tagName, pItem->pVar.pz, nLen) == 0) && (pItem->pVar.nLen == nLen)) {
idx = i;
break;
}
} }
if (idx == -1) { if (index.columnIndex < pMeterMeta->numOfColumns) {
return invalidSqlErrMsg(pCmd, msg4); return invalidSqlErrMsg(pCmd, msg4);
} else if (idx == 0) { } else if (index.columnIndex == 0) {
return invalidSqlErrMsg(pCmd, msg5); return invalidSqlErrMsg(pCmd, msg5);
} }
char name[128] = {0}; char name1[128] = {0};
strncpy(name, pItem->pVar.pz, pItem->pVar.nLen); strncpy(name1, pItem->pVar.pz, pItem->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, name1,
tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
pCmd->numOfCols = 1; // only one column } else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
} else if (pInfo->sqlType == ALTER_TABLE_TAGS_CHG) {
const char* msg1 = "tag name too long"; const char* msg1 = "tag name too long";
const char* msg2 = "invalid tag name"; const char* msg2 = "invalid tag name";
pCmd->count = TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN;
tVariantList* pVarList = pAlterSQL->varList; tVariantList* pVarList = pAlterSQL->varList;
if (pVarList->nExpr > 2) { if (pVarList->nExpr > 2) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
...@@ -4662,63 +4077,47 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4662,63 +4077,47 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char name[128] = {0}; char name[128] = {0};
strncpy(name, pVarList->a[0].pVar.pz, pVarList->a[0].pVar.nLen); 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)); memset(name, 0, tListLen(name));
strncpy(name, pVarList->a[1].pVar.pz, pVarList->a[1].pVar.nLen); 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); 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) {
pCmd->numOfCols = 2;
} else if (pInfo->sqlType == ALTER_TABLE_TAGS_SET) {
const char* msg0 = "tag name too long";
const char* msg1 = "invalid tag value"; 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"; const char* msg3 = "tag value too long";
pCmd->count = TSDB_ALTER_TABLE_UPDATE_TAG_VAL; // 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
// Note: update can only be applied to meter not metric.
// the following is handle display tags value for meters created according to metric
tVariantList* pVarList = pAlterSQL->varList; tVariantList* pVarList = pAlterSQL->varList;
tVariant* pTagName = &pVarList->a[0].pVar; tVariant* pTagName = &pVarList->a[0].pVar;
if (pTagName->nLen > TSDB_COL_NAME_LEN) { SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER;
return invalidSqlErrMsg(pCmd, msg0); SSQLToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen};
} if (getColumnIndexByNameEx(&name, pCmd, &columnIndex) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL;
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;
}
} }
if (tagsIndex == -1) { if (columnIndex.columnIndex < pMeterMeta->numOfColumns) {
return invalidSqlErrMsg(pCmd, msg2); 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); return invalidSqlErrMsg(pCmd, msg1);
} }
// validate the length of binary // validate the length of binary
if ((pTagsSchema[tagsIndex].type == TSDB_DATA_TYPE_BINARY || pTagsSchema[tagsIndex].type == TSDB_DATA_TYPE_NCHAR) && if ((pTagsSchema->type == TSDB_DATA_TYPE_BINARY || pTagsSchema->type == TSDB_DATA_TYPE_NCHAR) &&
pVarList->a[1].pVar.nLen > pTagsSchema[tagsIndex].bytes) { pVarList->a[1].pVar.nLen > pTagsSchema->bytes) {
return invalidSqlErrMsg(pCmd, msg3); return invalidSqlErrMsg(pCmd, msg3);
} }
char name[128] = {0}; char name1[128] = {0};
strncpy(name, pTagName->pz, pTagName->nLen); strncpy(name1, pTagName->pz, pTagName->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, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
pCmd->numOfCols = 1;
} else if (pInfo->sqlType == ALTER_TABLE_ADD_COLUMN) {
pCmd->count = TSDB_ALTER_TABLE_ADD_COLUMN;
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN) {
tFieldList* pFieldList = pAlterSQL->pAddColumns; tFieldList* pFieldList = pAlterSQL->pAddColumns;
if (pFieldList->nField > 1) { if (pFieldList->nField > 1) {
const char* msg = "only support add one column"; const char* msg = "only support add one column";
...@@ -4729,16 +4128,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4729,16 +4128,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
tscFieldInfoSetValFromField(&pCmd->fieldsInfo, 0, &pFieldList->p[0]); tscFieldInfoSetValFromField(&pCmd->pQueryInfo[0].fieldsInfo, 0, &pFieldList->p[0]);
pCmd->numOfCols = 1; // only one column } else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
} else if (pInfo->sqlType == ALTER_TABLE_DROP_COLUMN) {
pCmd->count = TSDB_ALTER_TABLE_DROP_COLUMN;
const char* msg1 = "no columns can be dropped"; const char* msg1 = "no columns can be dropped";
const char* msg2 = "only support one column"; const char* msg2 = "only support one column";
const char* msg3 = "column name too long";
const char* msg4 = "illegal column name"; 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) { // if (pMeterMeta->numOfColumns == TSDB_MIN_COLUMNS) { //
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
...@@ -4749,32 +4144,20 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4749,32 +4144,20 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
tVariantListItem* pItem = &pAlterSQL->varList->a[0]; 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); return invalidSqlErrMsg(pCmd, msg4);
} else if (idx == 0) {
return invalidSqlErrMsg(pCmd, msg5);
} }
char name[128] = {0}; if (columnIndex.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
strncpy(name, pItem->pVar.pz, pItem->pVar.nLen); return invalidSqlErrMsg(pCmd, msg3);
tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize); }
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; return TSDB_CODE_SUCCESS;
...@@ -4784,11 +4167,11 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd) { ...@@ -4784,11 +4167,11 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd) {
const char* msg0 = "sample interval can not be less than 10ms."; const char* msg0 = "sample interval can not be less than 10ms.";
const char* msg1 = "functions not allowed in select clause"; 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); 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; int32_t functId = tscSqlExprGet(pCmd, i)->functionId;
if (!IS_STREAM_QUERY_VALID(aAggs[functId].nStatus)) { if (!IS_STREAM_QUERY_VALID(aAggs[functId].nStatus)) {
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
...@@ -4803,13 +4186,13 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) { ...@@ -4803,13 +4186,13 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
const char* msg1 = "column projection is not compatible with interval"; const char* msg1 = "column projection is not compatible with interval";
// multi-output set/ todo refactor // 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, k);
// projection query on primary timestamp, the selectivity function needs to be present. // 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) { if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
bool hasSelectivity = false; 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); SSqlExpr* pEx = tscSqlExprGet(pCmd, j);
if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) { if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) {
hasSelectivity = true; hasSelectivity = true;
...@@ -4967,7 +4350,7 @@ bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd) { ...@@ -4967,7 +4350,7 @@ bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd) {
return true; 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) { int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
...@@ -4980,16 +4363,16 @@ 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"; const char* msg3 = "slimit/soffset can not apply to projection query";
// handle the limit offset value, validate the limit // handle the limit offset value, validate the limit
pCmd->limit = pQuerySql->limit; pCmd->pQueryInfo->limit = pQuerySql->limit;
pCmd->globalLimit = pCmd->limit.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); return invalidSqlErrMsg(pCmd, msg0);
} }
if (pCmd->limit.limit == 0) { if (pCmd->pQueryInfo->limit.limit == 0) {
tscTrace("%p limit 0, no output result", pSql); tscTrace("%p limit 0, no output result", pSql);
pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
} }
...@@ -5003,12 +4386,12 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { ...@@ -5003,12 +4386,12 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
if (queryOnTags == true) { // local handle the metric tag query if (queryOnTags == true) { // local handle the metric tag query
pCmd->command = TSDB_SQL_RETRIEVE_TAGS; pCmd->command = TSDB_SQL_RETRIEVE_TAGS;
} else { } 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); return invalidSqlErrMsg(pCmd, msg3);
} }
} }
if (pCmd->slimit.limit == 0) { if (pCmd->pQueryInfo[0].slimit.limit == 0) {
tscTrace("%p limit 0, no output result", pSql); tscTrace("%p limit 0, no output result", pSql);
pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -5032,14 +4415,14 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { ...@@ -5032,14 +4415,14 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
} }
// keep original limitation value in globalLimit // keep original limitation value in globalLimit
pCmd->globalLimit = pCmd->limit.limit; pCmd->globalLimit = pCmd->pQueryInfo->limit.limit;
} else { } 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); return invalidSqlErrMsg(pCmd, msg1);
} }
// filter the query functions operating on "tbname" column that are not supported by normal columns. // 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->colInfo.colIdx == TSDB_TBNAME_COLUMN_INDEX) { if (pExpr->colInfo.colIdx == TSDB_TBNAME_COLUMN_INDEX) {
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
...@@ -5141,7 +4524,7 @@ int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { ...@@ -5141,7 +4524,7 @@ int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex) { void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex) {
// the first column not timestamp column, add it // the first column not timestamp column, add it
SSqlExpr* pExpr = NULL; SSqlExpr* pExpr = NULL;
if (pCmd->exprsInfo.numOfExprs > 0) { if (pCmd->pQueryInfo[0].exprsInfo.numOfExprs > 0) {
pExpr = tscSqlExprGet(pCmd, 0); pExpr = tscSqlExprGet(pCmd, 0);
} }
...@@ -5159,14 +4542,14 @@ void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex ...@@ -5159,14 +4542,14 @@ void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex
} }
void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIndex) { void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIndex) {
if (pParentObj->cmd.groupbyExpr.numOfGroupCols > 0) { if (pParentObj->cmd.pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) {
int32_t num = pSql->cmd.exprsInfo.numOfExprs; int32_t num = pSql->cmd.pQueryInfo[0].exprsInfo.numOfExprs;
SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, num - 1); SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, num - 1);
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
if (pExpr->functionId != TSDB_FUNC_TAG) { if (pExpr->functionId != TSDB_FUNC_TAG) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); 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}; SColumnIndex index = {.tableIndex = 0, .columnIndex = columnInfo};
SSchema* pSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta); SSchema* pSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta);
...@@ -5174,32 +4557,32 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIn ...@@ -5174,32 +4557,32 @@ void addGroupInfoForSubquery(SSqlObj* pParentObj, SSqlObj* pSql, int32_t tableIn
int16_t bytes = pSchema[index.columnIndex].bytes; int16_t bytes = pSchema[index.columnIndex].bytes;
char* name = pSchema[index.columnIndex].name; 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; pExpr->colInfo.flag = TSDB_COL_TAG;
// NOTE: tag column does not add to source column list // NOTE: tag column does not add to source column list
SColumnList ids = {0}; 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; int32_t relIndex = index.columnIndex;
pExpr->colInfo.colIdx = relIndex; 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) { 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); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
SSchema* pSchema = tsGetColumnSchema(pMeterMetaInfo->pMeterMeta, index); SSchema* pSchema = tsGetColumnSchema(pMeterMetaInfo->pMeterMeta, index);
SColumnIndex colIndex = {.tableIndex = 0, .columnIndex = 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); pSchema->bytes, pSchema->bytes);
pExpr->colInfo.flag = TSDB_COL_NORMAL; pExpr->colInfo.flag = TSDB_COL_NORMAL;
...@@ -5211,13 +4594,13 @@ void doAddGroupColumnForSubquery(SSqlCmd* pCmd, int32_t tagIndex) { ...@@ -5211,13 +4594,13 @@ void doAddGroupColumnForSubquery(SSqlCmd* pCmd, int32_t tagIndex) {
list.num = 1; list.num = 1;
list.ids[0] = colIndex; list.ids[0] = colIndex;
insertResultField(pCmd, pCmd->fieldsInfo.numOfOutputCols, &list, pSchema->bytes, pSchema->type, pSchema->name); insertResultField(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, &list, pSchema->bytes, pSchema->type, pSchema->name);
tscFieldInfoUpdateVisible(&pCmd->fieldsInfo, pCmd->fieldsInfo.numOfOutputCols - 1, false); tscFieldInfoUpdateVisible(&pCmd->pQueryInfo[0].fieldsInfo, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols - 1, false);
} }
static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) { static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
int32_t tagLength = 0; 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_TAGPRJ || pExpr->functionId == TSDB_FUNC_TAG) { if (pExpr->functionId == TSDB_FUNC_TAGPRJ || pExpr->functionId == TSDB_FUNC_TAG) {
pExpr->functionId = TSDB_FUNC_TAG_DUMMY; pExpr->functionId = TSDB_FUNC_TAG_DUMMY;
...@@ -5231,7 +4614,7 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) { ...@@ -5231,7 +4614,7 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId != TSDB_FUNC_TAG_DUMMY && pExpr->functionId != TSDB_FUNC_TS_DUMMY) { if (pExpr->functionId != TSDB_FUNC_TAG_DUMMY && pExpr->functionId != TSDB_FUNC_TS_DUMMY) {
SSchema* pColSchema = &pSchema[pExpr->colInfo.colIdx]; SSchema* pColSchema = &pSchema[pExpr->colInfo.colIdx];
...@@ -5242,12 +4625,12 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) { ...@@ -5242,12 +4625,12 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
} }
static void doUpdateSqlFunctionForColPrj(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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_PRJ) { if (pExpr->functionId == TSDB_FUNC_PRJ) {
bool qualifiedCol = false; bool qualifiedCol = false;
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { for (int32_t j = 0; j < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++j) {
if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) { if (pExpr->colInfo.colId == pCmd->pQueryInfo[0].groupbyExpr.columnInfo[j].colId) {
qualifiedCol = true; qualifiedCol = true;
pExpr->param[0].i64Key = 1; // limit the output to be 1 for each state value pExpr->param[0].i64Key = 1; // limit the output to be 1 for each state value
...@@ -5275,7 +4658,7 @@ static bool onlyTagPrjFunction(SSqlCmd* pCmd) { ...@@ -5275,7 +4658,7 @@ static bool onlyTagPrjFunction(SSqlCmd* pCmd) {
bool hasTagPrj = false; bool hasTagPrj = false;
bool hasColumnPrj = 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_PRJ) { if (pExpr->functionId == TSDB_FUNC_PRJ) {
hasColumnPrj = true; hasColumnPrj = true;
...@@ -5291,13 +4674,13 @@ static bool onlyTagPrjFunction(SSqlCmd* pCmd) { ...@@ -5291,13 +4674,13 @@ static bool onlyTagPrjFunction(SSqlCmd* pCmd) {
static bool allTagPrjInGroupby(SSqlCmd* pCmd) { static bool allTagPrjInGroupby(SSqlCmd* pCmd) {
bool allInGroupby = true; 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId != TSDB_FUNC_TAGPRJ) { if (pExpr->functionId != TSDB_FUNC_TAGPRJ) {
continue; continue;
} }
if (!tagColumnInGroupby(&pCmd->groupbyExpr, pExpr->colInfo.colId)) { if (!tagColumnInGroupby(&pCmd->pQueryInfo[0].groupbyExpr, pExpr->colInfo.colId)) {
allInGroupby = false; allInGroupby = false;
break; break;
} }
...@@ -5308,7 +4691,7 @@ static bool allTagPrjInGroupby(SSqlCmd* pCmd) { ...@@ -5308,7 +4691,7 @@ static bool allTagPrjInGroupby(SSqlCmd* pCmd) {
} }
static void updateTagPrjFunction(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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_TAGPRJ) { if (pExpr->functionId == TSDB_FUNC_TAGPRJ) {
pExpr->functionId = TSDB_FUNC_TAG; pExpr->functionId = TSDB_FUNC_TAG;
...@@ -5330,7 +4713,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { ...@@ -5330,7 +4713,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
int16_t numOfSelectivity = 0; int16_t numOfSelectivity = 0;
int16_t numOfAggregation = 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_TAGPRJ || if (pExpr->functionId == TSDB_FUNC_TAGPRJ ||
(pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) { (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) {
...@@ -5339,9 +4722,9 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { ...@@ -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; 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) { functionId == TSDB_FUNC_ARITHM) {
continue; continue;
} }
...@@ -5371,7 +4754,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { ...@@ -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. * If more than one selectivity functions exist, all the selectivity functions must be last_row.
* Otherwise, return with error code. * 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; int16_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if (functionId == TSDB_FUNC_TAGPRJ) { if (functionId == TSDB_FUNC_TAGPRJ) {
continue; continue;
...@@ -5387,7 +4770,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { ...@@ -5387,7 +4770,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
} }
} else { } else {
if ((pCmd->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) == TSDB_QUERY_TYPE_PROJECTION_QUERY) { 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); return invalidSqlErrMsg(pCmd, msg3);
} }
...@@ -5412,8 +4795,8 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) { ...@@ -5412,8 +4795,8 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) {
int16_t type = 0; int16_t type = 0;
char* name = NULL; char* name = NULL;
for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++i) {
SColIndexEx* pColIndex = &pCmd->groupbyExpr.columnInfo[i]; SColIndexEx* pColIndex = &pCmd->pQueryInfo[0].groupbyExpr.columnInfo[i];
int16_t colIndex = pColIndex->colIdx; int16_t colIndex = pColIndex->colIdx;
if (pColIndex->colIdx == TSDB_TBNAME_COLUMN_INDEX) { if (pColIndex->colIdx == TSDB_TBNAME_COLUMN_INDEX) {
...@@ -5430,24 +4813,24 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) { ...@@ -5430,24 +4813,24 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) {
} }
if (TSDB_COL_IS_TAG(pColIndex->flag)) { 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 = 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; pExpr->colInfo.flag = TSDB_COL_TAG;
// NOTE: tag column does not add to source column list // NOTE: tag column does not add to source column list
SColumnList ids = {0}; SColumnList ids = {0};
insertResultField(pCmd, pCmd->fieldsInfo.numOfOutputCols, &ids, bytes, type, name); insertResultField(pCmd, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, &ids, bytes, type, name);
} else { } else {
// if this query is "group by" normal column, interval is not allowed // 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); return invalidSqlErrMsg(pCmd, msg2);
} }
bool hasGroupColumn = false; 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, j);
if (pExpr->colInfo.colId == pColIndex->colId) { if (pExpr->colInfo.colId == pColIndex->colId) {
break; break;
...@@ -5477,14 +4860,14 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { ...@@ -5477,14 +4860,14 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
// only retrieve tags, group by is not supportted // only retrieve tags, group by is not supportted
if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) { 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); return invalidSqlErrMsg(pCmd, msg4);
} else { } else {
return TSDB_CODE_SUCCESS; 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 // check if all the tags prj columns belongs to the group by columns
if (onlyTagPrjFunction(pCmd) && allTagPrjInGroupby(pCmd)) { if (onlyTagPrjFunction(pCmd) && allTagPrjInGroupby(pCmd)) {
updateTagPrjFunction(pCmd); updateTagPrjFunction(pCmd);
...@@ -5492,7 +4875,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { ...@@ -5492,7 +4875,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
} }
// check all query functions in selection clause, multi-output functions are not allowed // 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
int32_t functId = pExpr->functionId; int32_t functId = pExpr->functionId;
...@@ -5502,8 +4885,8 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { ...@@ -5502,8 +4885,8 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
*/ */
if (functId == TSDB_FUNC_PRJ && pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) { if (functId == TSDB_FUNC_PRJ && pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
bool qualified = false; bool qualified = false;
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { for (int32_t j = 0; j < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++j) {
SColIndexEx* pColIndex = &pCmd->groupbyExpr.columnInfo[j]; SColIndexEx* pColIndex = &pCmd->pQueryInfo[0].groupbyExpr.columnInfo[j];
if (pColIndex->colId == pExpr->colInfo.colId) { if (pColIndex->colId == pExpr->colInfo.colId) {
qualified = true; qualified = true;
break; break;
...@@ -5682,21 +5065,21 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) { ...@@ -5682,21 +5065,21 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) {
// for debug purpose // for debug purpose
void tscPrintSelectClause(SSqlCmd* pCmd) { void tscPrintSelectClause(SSqlCmd* pCmd) {
if (pCmd == NULL || pCmd->exprsInfo.numOfExprs == 0) { if (pCmd == NULL || pCmd->pQueryInfo[0].exprsInfo.numOfExprs == 0) {
return; return;
} }
char* str = calloc(1, 10240); char* str = calloc(1, 10240);
int32_t offset = 0; int32_t offset = 0;
offset += sprintf(str, "%d [", pCmd->exprsInfo.numOfExprs); offset += sprintf(str, "%d [", pCmd->pQueryInfo[0].exprsInfo.numOfExprs);
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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
int32_t size = sprintf(str + offset, "%s(%d)", aAggs[pExpr->functionId].aName, pExpr->colInfo.colId); int32_t size = sprintf(str + offset, "%s(%d)", aAggs[pExpr->functionId].aName, pExpr->colInfo.colId);
offset += size; offset += size;
if (i < pCmd->exprsInfo.numOfExprs - 1) { if (i < pCmd->pQueryInfo[0].exprsInfo.numOfExprs - 1) {
str[offset++] = ','; str[offset++] = ',';
} }
} }
...@@ -5706,3 +5089,424 @@ void tscPrintSelectClause(SSqlCmd* pCmd) { ...@@ -5706,3 +5089,424 @@ void tscPrintSelectClause(SSqlCmd* pCmd) {
free(str); 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
}
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) {
void *pParser = ParseAlloc(malloc); void *pParser = ParseAlloc(malloc);
pSQLInfo->validSql = true; pSQLInfo->valid = true;
int32_t i = 0; int32_t i = 0;
while (1) { while (1) {
...@@ -50,12 +50,12 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { ...@@ -50,12 +50,12 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) {
} }
case TK_ILLEGAL: { case TK_ILLEGAL: {
snprintf(pSQLInfo->pzErrMsg, tListLen(pSQLInfo->pzErrMsg), "unrecognized token: \"%s\"", t0.z); snprintf(pSQLInfo->pzErrMsg, tListLen(pSQLInfo->pzErrMsg), "unrecognized token: \"%s\"", t0.z);
pSQLInfo->validSql = false; pSQLInfo->valid = false;
goto abort_parse; goto abort_parse;
} }
default: default:
Parse(pParser, t0.type, t0, pSQLInfo); Parse(pParser, t0.type, t0, pSQLInfo);
if (pSQLInfo->validSql == false) { if (pSQLInfo->valid == false) {
goto abort_parse; goto abort_parse;
} }
} }
...@@ -554,58 +554,62 @@ tSQLExprListList *tSQLListListAppend(tSQLExprListList *pList, tSQLExprList *pExp ...@@ -554,58 +554,62 @@ tSQLExprListList *tSQLListListAppend(tSQLExprListList *pList, tSQLExprList *pExp
return pList; return pList;
} }
void tSetInsertSQLElems(SSqlInfo *pInfo, SSQLToken *pName, tSQLExprListList *pList) { void doDestroyQuerySql(SQuerySQL *pQuerySql) {
SInsertSQL *pInsert = calloc(1, sizeof(SInsertSQL)); if (pQuerySql == NULL) {
return;
pInsert->name = *pName; }
pInsert->pValue = pList;
tSQLExprListDestroy(pQuerySql->pSelection);
pInfo->pInsertInfo = pInsert;
pInfo->sqlType = TSQL_INSERT; pQuerySql->pSelection = NULL;
}
tSQLExprDestroy(pQuerySql->pWhere);
void destroyQuerySql(SQuerySQL *pSql) { pQuerySql->pWhere = NULL;
if (pSql == NULL) return;
tVariantListDestroy(pQuerySql->pSortOrder);
tSQLExprListDestroy(pSql->pSelection); pQuerySql->pSortOrder = NULL;
pSql->pSelection = NULL;
tVariantListDestroy(pQuerySql->pGroupby);
tSQLExprDestroy(pSql->pWhere); pQuerySql->pGroupby = NULL;
pSql->pWhere = NULL;
tVariantListDestroy(pQuerySql->from);
tVariantListDestroy(pSql->pSortOrder); pQuerySql->from = NULL;
pSql->pSortOrder = NULL;
tVariantListDestroy(pQuerySql->fillType);
tVariantListDestroy(pSql->pGroupby);
pSql->pGroupby = NULL; free(pQuerySql);
}
tVariantListDestroy(pSql->from);
pSql->from = NULL; void destroyAllSelectClause(SSubclauseInfo *pClause) {
if (pClause == NULL || pClause->numOfClause == 0) {
tVariantListDestroy(pSql->fillType); 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) { tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type) {
SCreateTableSQL *pCreate = calloc(1, sizeof(SCreateTableSQL)); SCreateTableSQL *pCreate = calloc(1, sizeof(SCreateTableSQL));
switch (type) { switch (type) {
case TSQL_CREATE_NORMAL_METER: { case TSQL_CREATE_TABLE: {
pCreate->colInfo.pColumns = pCols; pCreate->colInfo.pColumns = pCols;
assert(pTagVals == NULL && pTags == NULL); assert(pTagVals == NULL && pTags == NULL);
break; break;
} }
case TSQL_CREATE_NORMAL_METRIC: { case TSQL_CREATE_STABLE: {
pCreate->colInfo.pColumns = pCols; pCreate->colInfo.pColumns = pCols;
pCreate->colInfo.pTagColumns = pTags; pCreate->colInfo.pTagColumns = pTags;
assert(pTagVals == NULL && pTags != NULL && pCols != NULL); assert(pTagVals == NULL && pTags != NULL && pCols != NULL);
break; break;
} }
case TSQL_CREATE_METER_FROM_METRIC: { case TSQL_CREATE_TABLE_FROM_STABLE: {
pCreate->usingInfo.pTagVals = pTagVals; pCreate->usingInfo.pTagVals = pTagVals;
pCreate->usingInfo.metricName = *pMetricName; pCreate->usingInfo.stableName = *pStableName;
break; break;
} }
case TSQL_CREATE_STREAM: { case TSQL_CREATE_STREAM: {
...@@ -616,19 +620,24 @@ SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLTo ...@@ -616,19 +620,24 @@ SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLTo
assert(false); assert(false);
} }
pCreate->type = type;
return pCreate; return pCreate;
} }
SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type) { SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type) {
SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL)); SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL));
pAlterTable->name = *pMeterName; 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; pAlterTable->pAddColumns = pCols;
assert(pVals == NULL); assert(pVals == NULL);
} else { } 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; pAlterTable->varList = pVals;
assert(pCols == NULL); assert(pCols == NULL);
} }
...@@ -639,27 +648,28 @@ SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tV ...@@ -639,27 +648,28 @@ SAlterTableSQL *tAlterTableSQLElems(SSQLToken *pMeterName, tFieldList *pCols, tV
void SQLInfoDestroy(SSqlInfo *pInfo) { void SQLInfoDestroy(SSqlInfo *pInfo) {
if (pInfo == NULL) return; if (pInfo == NULL) return;
if (pInfo->sqlType == TSQL_QUERY_METER) { if (pInfo->type == TSDB_SQL_SELECT) {
destroyQuerySql(pInfo->pQueryInfo); destroyAllSelectClause(&pInfo->subclauseInfo);
} else if (pInfo->sqlType >= TSQL_CREATE_NORMAL_METER && pInfo->sqlType <= TSQL_CREATE_STREAM) { } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) {
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo; SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
destroyQuerySql(pCreateTableInfo->pSelect); doDestroyQuerySql(pCreateTableInfo->pSelect);
tFieldListDestroy(pCreateTableInfo->colInfo.pColumns); tFieldListDestroy(pCreateTableInfo->colInfo.pColumns);
tFieldListDestroy(pCreateTableInfo->colInfo.pTagColumns); tFieldListDestroy(pCreateTableInfo->colInfo.pTagColumns);
tVariantListDestroy(pCreateTableInfo->usingInfo.pTagVals); tVariantListDestroy(pCreateTableInfo->usingInfo.pTagVals);
tfree(pInfo->pCreateTableInfo); 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); tVariantListDestroy(pInfo->pAlterInfo->varList);
tFieldListDestroy(pInfo->pAlterInfo->pAddColumns); tFieldListDestroy(pInfo->pAlterInfo->pAddColumns);
tfree(pInfo->pAlterInfo); tfree(pInfo->pAlterInfo);
} else { } else {
if (pInfo->pDCLInfo != NULL && pInfo->pDCLInfo->nAlloc > 0) { if (pInfo->pDCLInfo != NULL && pInfo->pDCLInfo->nAlloc > 0) {
free(pInfo->pDCLInfo->a); free(pInfo->pDCLInfo->a);
} }
if (pInfo->sqlType == CREATE_DATABASE) { if (pInfo->type == TSDB_SQL_CREATE_DB) {
tVariantListDestroy(pInfo->pDCLInfo->dbOpt.keep); tVariantListDestroy(pInfo->pDCLInfo->dbOpt.keep);
} }
...@@ -667,13 +677,52 @@ void SQLInfoDestroy(SSqlInfo *pInfo) { ...@@ -667,13 +677,52 @@ void SQLInfoDestroy(SSqlInfo *pInfo) {
} }
} }
void setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SSQLToken *pMeterName, int32_t type) { SSubclauseInfo* setSubclause(SSubclauseInfo* pSubclause, void *pSqlExprInfo) {
pInfo->sqlType = type; if (pSubclause == NULL) {
pInfo->pCreateTableInfo = pSqlExprInfo; 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) { if (pMeterName != NULL) {
pInfo->pCreateTableInfo->name = *pMeterName; 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) { void setCreatedMeterName(SSqlInfo *pInfo, SSQLToken *pMeterName, SSQLToken *pIfNotExists) {
...@@ -703,7 +752,7 @@ tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken) { ...@@ -703,7 +752,7 @@ tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken) {
} }
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) { void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
pInfo->sqlType = type; pInfo->type = type;
if (nParam == 0) return; if (nParam == 0) return;
if (pInfo->pDCLInfo == NULL) pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); if (pInfo->pDCLInfo == NULL) pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL));
...@@ -718,8 +767,42 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) { ...@@ -718,8 +767,42 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
va_end(va); 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) { void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists) {
pInfo->sqlType = type; pInfo->type = type;
if (pInfo->pDCLInfo == NULL) { if (pInfo->pDCLInfo == NULL) {
pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL));
} }
...@@ -731,18 +814,68 @@ void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBI ...@@ -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) { void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo) {
pInfo->sqlType = type; pInfo->type = type;
if (pInfo->pDCLInfo == NULL) { if (pInfo->pDCLInfo == NULL) {
pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL));
} }
pInfo->pDCLInfo->acctOpt = *pAcctInfo; 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) { void setAlterUserSQL(SSqlInfo *pInfo, int16_t type, SSQLToken *pName, SSQLToken* pPwd, SSQLToken *pPrivilege) {
tTokenListAppend(pInfo->pDCLInfo, pPwd); 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) { void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) {
......
...@@ -58,12 +58,12 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu ...@@ -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 * 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. * 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]; SQLFunctionCtx *pCtx = &pReducer->pCtx[i];
pCtx->aOutputBuf = pReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pReducer->resColModel->maxCapacity; pCtx->aOutputBuf = pReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pReducer->resColModel->maxCapacity;
pCtx->order = pCmd->order.order; 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 // input buffer hold only one point data
pCtx->aInputElemBuf = pReducer->pTempBuffer->data + pDesc->pSchema->colOffset[i]; pCtx->aInputElemBuf = pReducer->pTempBuffer->data + pDesc->pSchema->colOffset[i];
...@@ -105,10 +105,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu ...@@ -105,10 +105,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
int16_t n = 0; int16_t n = 0;
int16_t tagLen = 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; 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TS_DUMMY) { if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TS_DUMMY) {
tagLen += pExpr->resBytes; tagLen += pExpr->resBytes;
...@@ -238,7 +238,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd ...@@ -238,7 +238,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
param->pLocalData = pReducer->pLocalDataSrc; param->pLocalData = pReducer->pLocalDataSrc;
param->pDesc = pReducer->pDesc; param->pDesc = pReducer->pDesc;
param->numOfElems = pReducer->pLocalDataSrc[0]->pMemBuffer->numOfElemsPerPage; 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); pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator);
if (pReducer->pLoserTree == NULL || pRes->code != 0) { if (pReducer->pLoserTree == NULL || pRes->code != 0) {
...@@ -247,7 +247,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd ...@@ -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. // the input data format follows the old format, but output in a new format.
// so, all the input must be parsed as old 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; pReducer->rowSize = pMemBuffer[0]->nElemSize;
...@@ -294,14 +294,14 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd ...@@ -294,14 +294,14 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
} }
pReducer->pTempBuffer->numOfElems = 0; 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); tscCreateResPointerInfo(pCmd, pRes);
tscInitSqlContext(pCmd, pRes, pReducer, pDesc); tscInitSqlContext(pCmd, pRes, pReducer, pDesc);
// we change the maxCapacity of schema to denote that there is only one row in temp buffer // we change the maxCapacity of schema to denote that there is only one row in temp buffer
pReducer->pDesc->pSchema->maxCapacity = 1; pReducer->pDesc->pSchema->maxCapacity = 1;
pReducer->offset = pCmd->limit.offset; pReducer->offset = pCmd->pQueryInfo->limit.offset;
pRes->pLocalReducer = pReducer; pRes->pLocalReducer = pReducer;
pRes->numOfGroups = 0; pRes->numOfGroups = 0;
...@@ -309,18 +309,18 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd ...@@ -309,18 +309,18 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
int16_t prec = pMeterMetaInfo->pMeterMeta->precision; int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime; 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->nAggTimeInterval, pCmd->intervalTimeUnit, prec); int64_t revisedSTime = taosGetIntervalStartTimestamp(stime, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, prec);
SInterpolationInfo *pInterpoInfo = &pReducer->interpolationInfo; 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); 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) { if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) {
pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pCmd->groupbyExpr.numOfGroupCols; pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols;
for (int32_t i = 1; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { 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]; pInterpoInfo->pTags[i] = pReducer->resColModel->pFields[startIndex + i - 1].bytes + pInterpoInfo->pTags[i - 1];
} }
} else { } else {
...@@ -444,7 +444,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { ...@@ -444,7 +444,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
tfree(pLocalReducer->interpolationInfo.pTags); tfree(pLocalReducer->interpolationInfo.pTags);
if (pLocalReducer->pCtx != NULL) { 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]; SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i];
tVariantDestroy(&pCtx->tag); tVariantDestroy(&pCtx->tag);
} }
...@@ -459,7 +459,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { ...@@ -459,7 +459,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
tfree(pLocalReducer->pResultBuf); tfree(pLocalReducer->pResultBuf);
if (pLocalReducer->pResInfo != NULL) { 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); tfree(pLocalReducer->pResInfo[i].interResultBuf);
} }
...@@ -494,12 +494,12 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { ...@@ -494,12 +494,12 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCmd, tColModel *pModel) { static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCmd, tColModel *pModel) {
int32_t numOfGroupByCols = 0; int32_t numOfGroupByCols = 0;
if (pCmd->groupbyExpr.numOfGroupCols > 0) { if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols > 0) {
numOfGroupByCols = pCmd->groupbyExpr.numOfGroupCols; numOfGroupByCols = pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols;
} }
// primary timestamp column is involved in final result // primary timestamp column is involved in final result
if (pCmd->nAggTimeInterval != 0) { if (pCmd->pQueryInfo[0].nAggTimeInterval != 0) {
numOfGroupByCols++; numOfGroupByCols++;
} }
...@@ -509,14 +509,14 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm ...@@ -509,14 +509,14 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
} }
if (numOfGroupByCols > 0) { 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 // 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++; 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" // the first column is the timestamp, handles queries like "interval(10m) group by tags"
orderIdx[numOfGroupByCols - 1] = PRIMARYKEY_TIMESTAMP_COL_INDEX; orderIdx[numOfGroupByCols - 1] = PRIMARYKEY_TIMESTAMP_COL_INDEX;
} }
...@@ -550,10 +550,10 @@ bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage ...@@ -550,10 +550,10 @@ bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage
if (pOrderDesc->orderIdx.pData[numOfCols - 1] == PRIMARYKEY_TIMESTAMP_COL_INDEX) { //<= 0 if (pOrderDesc->orderIdx.pData[numOfCols - 1] == PRIMARYKEY_TIMESTAMP_COL_INDEX) { //<= 0
// super table interval query // super table interval query
assert(pCmd->nAggTimeInterval > 0); assert(pCmd->pQueryInfo[0].nAggTimeInterval > 0);
pOrderDesc->orderIdx.numOfOrderedCols -= 1; pOrderDesc->orderIdx.numOfOrderedCols -= 1;
} else { // simple group by query } else { // simple group by query
assert(pCmd->nAggTimeInterval == 0); assert(pCmd->pQueryInfo[0].nAggTimeInterval == 0);
} }
// only one row exists // only one row exists
...@@ -581,7 +581,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr ...@@ -581,7 +581,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
return pRes->code; 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) { if (pSchema == NULL) {
tscError("%p failed to allocate memory", pSql); tscError("%p failed to allocate memory", pSql);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
...@@ -589,7 +589,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr ...@@ -589,7 +589,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
} }
int32_t rlen = 0; 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
pSchema[i].bytes = pExpr->resBytes; pSchema[i].bytes = pExpr->resBytes;
...@@ -599,7 +599,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr ...@@ -599,7 +599,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
} }
int32_t capacity = nBufferSizes / rlen; 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) { for (int32_t i = 0; i < pMeterMetaInfo->pMetricMeta->numOfVnodes; ++i) {
char tmpPath[512] = {0}; char tmpPath[512] = {0};
...@@ -615,8 +615,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr ...@@ -615,8 +615,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
return pRes->code; return pRes->code;
} }
memset(pSchema, 0, sizeof(SSchema) * pCmd->fieldsInfo.numOfOutputCols); memset(pSchema, 0, sizeof(SSchema) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
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); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
pSchema[i].type = pField->type; pSchema[i].type = pField->type;
...@@ -624,7 +624,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr ...@@ -624,7 +624,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
strcpy(pSchema[i].name, pField->name); strcpy(pSchema[i].name, pField->name);
} }
*pFinalModel = tColModelCreate(pSchema, pCmd->fieldsInfo.numOfOutputCols, capacity); *pFinalModel = tColModelCreate(pSchema, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols, capacity);
tfree(pSchema); tfree(pSchema);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -719,10 +719,10 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC ...@@ -719,10 +719,10 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
int16_t prec = pMeterMetaInfo->pMeterMeta->precision; int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime; 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->nAggTimeInterval, pCmd->intervalTimeUnit, prec); 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->rowSize);
pLocalReducer->discard = true; pLocalReducer->discard = true;
...@@ -734,7 +734,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC ...@@ -734,7 +734,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SSqlCmd *pC
// todo merge with following function // todo merge with following function
static void reversedCopyResultToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage *pFinalDataPage) { 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); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
int32_t offset = tscFieldInfoGetOffset(pCmd, i); int32_t offset = tscFieldInfoGetOffset(pCmd, i);
...@@ -751,7 +751,7 @@ static void reversedCopyResultToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage * ...@@ -751,7 +751,7 @@ static void reversedCopyResultToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage *
static void reversedCopyFromInterpolationToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage **pResPages, static void reversedCopyFromInterpolationToDstBuf(SSqlCmd *pCmd, SSqlRes *pRes, tFilePage **pResPages,
SLocalReducer *pLocalReducer) { 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); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
int32_t offset = tscFieldInfoGetOffset(pCmd, i); int32_t offset = tscFieldInfoGetOffset(pCmd, i);
...@@ -786,38 +786,38 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -786,38 +786,38 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
assert(pRes->pLocalReducer == NULL); 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 // no interval query, no interpolation
pRes->data = pLocalReducer->pFinalRes; pRes->data = pLocalReducer->pFinalRes;
pRes->numOfRows = pFinalDataPage->numOfElems; pRes->numOfRows = pFinalDataPage->numOfElems;
pRes->numOfTotal += pRes->numOfRows; pRes->numOfTotal += pRes->numOfRows;
if (pCmd->limit.offset > 0) { if (pCmd->pQueryInfo->limit.offset > 0) {
if (pCmd->limit.offset < pRes->numOfRows) { if (pCmd->pQueryInfo->limit.offset < pRes->numOfRows) {
int32_t prevSize = pFinalDataPage->numOfElems; 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 */ /* remove the hole in column model */
tColModelCompact(pLocalReducer->resColModel, pFinalDataPage, prevSize); tColModelCompact(pLocalReducer->resColModel, pFinalDataPage, prevSize);
pRes->numOfRows -= pCmd->limit.offset; pRes->numOfRows -= pCmd->pQueryInfo->limit.offset;
pRes->numOfTotal -= pCmd->limit.offset; pRes->numOfTotal -= pCmd->pQueryInfo->limit.offset;
pCmd->limit.offset = 0; pCmd->pQueryInfo->limit.offset = 0;
} else { } else {
pCmd->limit.offset -= pRes->numOfRows; pCmd->pQueryInfo->limit.offset -= pRes->numOfRows;
pRes->numOfRows = 0; pRes->numOfRows = 0;
pRes->numOfTotal = 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 */ /* impose the limitation of output rows on the final result */
int32_t prevSize = pFinalDataPage->numOfElems; 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); assert(overFlow < pRes->numOfRows);
pRes->numOfTotal = pCmd->limit.limit; pRes->numOfTotal = pCmd->pQueryInfo->limit.limit;
pRes->numOfRows -= overFlow; pRes->numOfRows -= overFlow;
pFinalDataPage->numOfElems -= overFlow; pFinalDataPage->numOfElems -= overFlow;
...@@ -842,18 +842,18 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -842,18 +842,18 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
int64_t * pPrimaryKeys = (int64_t *)pLocalReducer->pBufForInterpo; int64_t * pPrimaryKeys = (int64_t *)pLocalReducer->pBufForInterpo;
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo; 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); tFilePage **pResPages = malloc(POINTER_BYTES * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
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); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalReducer->resColModel->maxCapacity); pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalReducer->resColModel->maxCapacity);
} }
char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pCmd->fieldsInfo.numOfOutputCols); char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
int32_t *functions = (int32_t *)((char *)srcData + pCmd->fieldsInfo.numOfOutputCols * sizeof(void *)); 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; srcData[i] = pLocalReducer->pBufForInterpo + tscFieldInfoGetOffset(pCmd, i) * pInterpoInfo->numOfRawDataInRows;
functions[i] = tscSqlExprGet(pCmd, i)->functionId; functions[i] = tscSqlExprGet(pCmd, i)->functionId;
} }
...@@ -863,23 +863,23 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -863,23 +863,23 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
while (1) { while (1) {
int32_t remains = taosNumOfRemainPoints(pInterpoInfo); 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); 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); pLocalReducer->resColModel->maxCapacity);
int32_t newRows = taosDoInterpoResult(pInterpoInfo, pCmd->interpoType, pResPages, remains, nrows, int32_t newRows = taosDoInterpoResult(pInterpoInfo, pCmd->pQueryInfo[0].interpoType, pResPages, remains, nrows,
pCmd->nAggTimeInterval, pPrimaryKeys, pLocalReducer->resColModel, srcData, pCmd->pQueryInfo[0].nAggTimeInterval, pPrimaryKeys, pLocalReducer->resColModel, srcData,
pCmd->defaultVal, functions, pLocalReducer->resColModel->maxCapacity); pCmd->pQueryInfo[0].defaultVal, functions, pLocalReducer->resColModel->maxCapacity);
assert(newRows <= nrows); assert(newRows <= nrows);
if (pCmd->limit.offset < newRows) { if (pCmd->pQueryInfo->limit.offset < newRows) {
newRows -= pCmd->limit.offset; newRows -= pCmd->pQueryInfo->limit.offset;
if (pCmd->limit.offset > 0) { if (pCmd->pQueryInfo->limit.offset > 0) {
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); 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 ...@@ -887,10 +887,10 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
pRes->numOfRows = newRows; pRes->numOfRows = newRows;
pRes->numOfTotal += newRows; pRes->numOfTotal += newRows;
pCmd->limit.offset = 0; pCmd->pQueryInfo->limit.offset = 0;
break; break;
} else { } else {
pCmd->limit.offset -= newRows; pCmd->pQueryInfo->limit.offset -= newRows;
pRes->numOfRows = 0; pRes->numOfRows = 0;
int32_t rpoints = taosNumOfRemainPoints(pInterpoInfo); int32_t rpoints = taosNumOfRemainPoints(pInterpoInfo);
...@@ -902,7 +902,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -902,7 +902,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
/* all output for current group are completed */ /* all output for current group are completed */
int32_t totalRemainRows = int32_t totalRemainRows =
taosGetNumOfResWithoutLimit(pInterpoInfo, pPrimaryKeys, rpoints, pCmd->nAggTimeInterval, actualETime); taosGetNumOfResWithoutLimit(pInterpoInfo, pPrimaryKeys, rpoints, pCmd->pQueryInfo[0].nAggTimeInterval, actualETime);
if (totalRemainRows <= 0) { if (totalRemainRows <= 0) {
break; break;
} }
...@@ -911,13 +911,13 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -911,13 +911,13 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
} }
if (pRes->numOfRows > 0) { if (pRes->numOfRows > 0) {
if (pCmd->limit.limit >= 0 && pRes->numOfTotal > pCmd->limit.limit) { if (pCmd->pQueryInfo->limit.limit >= 0 && pRes->numOfTotal > pCmd->pQueryInfo->limit.limit) {
int32_t overFlow = pRes->numOfTotal - pCmd->limit.limit; int32_t overFlow = pRes->numOfTotal - pCmd->pQueryInfo->limit.limit;
pRes->numOfRows -= overFlow; pRes->numOfRows -= overFlow;
assert(pRes->numOfRows >= 0); assert(pRes->numOfRows >= 0);
pRes->numOfTotal = pCmd->limit.limit; pRes->numOfTotal = pCmd->pQueryInfo->limit.limit;
pFinalDataPage->numOfElems -= overFlow; pFinalDataPage->numOfElems -= overFlow;
/* set remain data to be discarded, and reset the interpolation information */ /* set remain data to be discarded, and reset the interpolation information */
...@@ -925,7 +925,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -925,7 +925,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
} }
if (pCmd->order.order == TSQL_SO_ASC) { 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); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
memcpy(pRes->data + pLocalReducer->resColModel->colOffset[i] * pRes->numOfRows, pResPages[i]->data, memcpy(pRes->data + pLocalReducer->resColModel->colOffset[i] * pRes->numOfRows, pResPages[i]->data,
...@@ -937,7 +937,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo ...@@ -937,7 +937,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
} }
pFinalDataPage->numOfElems = 0; 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[i]);
} }
tfree(pResPages); tfree(pResPages);
...@@ -961,7 +961,7 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) ...@@ -961,7 +961,7 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, bool needInit) { static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, bool needInit) {
// the tag columns need to be set before all functions execution // 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); SSqlExpr * pExpr = tscSqlExprGet(pCmd, j);
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[j]; SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[j];
...@@ -981,7 +981,7 @@ static void doExecuteSecondaryMerge(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, ...@@ -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; int32_t functionId = tscSqlExprGet(pCmd, j)->functionId;
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) {
continue; continue;
...@@ -1002,7 +1002,7 @@ static void handleUnprocessedRow(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, tF ...@@ -1002,7 +1002,7 @@ static void handleUnprocessedRow(SSqlCmd* pCmd, SLocalReducer *pLocalReducer, tF
static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) { static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) {
int64_t maxOutput = 0; 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; int32_t functionId = tscSqlExprGet(pCmd, j)->functionId;
/* /*
...@@ -1028,7 +1028,7 @@ static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) { ...@@ -1028,7 +1028,7 @@ static int64_t getNumOfResultLocal(SSqlCmd *pCmd, SQLFunctionCtx *pCtx) {
*/ */
static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReducer *pLocalReducer) { static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReducer *pLocalReducer) {
int32_t maxBufSize = 0; // find the max tags column length to prepare the buffer 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
if (maxBufSize < pExpr->resBytes && pExpr->functionId == TSDB_FUNC_TAG) { if (maxBufSize < pExpr->resBytes && pExpr->functionId == TSDB_FUNC_TAG) {
maxBufSize = pExpr->resBytes; maxBufSize = pExpr->resBytes;
...@@ -1038,7 +1038,7 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce ...@@ -1038,7 +1038,7 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce
assert(maxBufSize >= 0); assert(maxBufSize >= 0);
char *buf = malloc((size_t) maxBufSize); 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
if (pExpr->functionId != TSDB_FUNC_TAG) { if (pExpr->functionId != TSDB_FUNC_TAG) {
continue; continue;
...@@ -1060,7 +1060,7 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce ...@@ -1060,7 +1060,7 @@ static void fillMultiRowsOfTagsVal(SSqlCmd *pCmd, int32_t numOfRes, SLocalReduce
} }
int32_t finalizeRes(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) { 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
aAggs[pExpr->functionId].xFinalize(&pLocalReducer->pCtx[k]); aAggs[pExpr->functionId].xFinalize(&pLocalReducer->pCtx[k]);
...@@ -1107,7 +1107,7 @@ bool needToMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuff ...@@ -1107,7 +1107,7 @@ bool needToMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tFilePage *tmpBuff
} }
static bool reachGroupResultLimit(SSqlCmd *pCmd, SSqlRes *pRes) { 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) { static bool saveGroupResultInfo(SSqlObj *pSql) {
...@@ -1147,9 +1147,9 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no ...@@ -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 * 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. * 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; pRes->numOfRows = 0;
pCmd->slimit.offset -= 1; pCmd->pQueryInfo[0].slimit.offset -= 1;
pLocalReducer->discard = !noMoreCurrentGroupRes; pLocalReducer->discard = !noMoreCurrentGroupRes;
return false; return false;
} }
...@@ -1163,22 +1163,22 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no ...@@ -1163,22 +1163,22 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
#endif #endif
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo; 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], memcpy(pInterpoInfo->pTags[i],
pLocalReducer->pBufForInterpo + pModel->colOffset[startIndex + i] * pResBuf->numOfElems, pLocalReducer->pBufForInterpo + pModel->colOffset[startIndex + i] * pResBuf->numOfElems,
pModel->pFields[startIndex + i].bytes); 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); doInterpolateResult(pSql, pLocalReducer, noMoreCurrentGroupRes);
return true; return true;
} }
void resetOutputBuf(SSqlCmd *pCmd, SLocalReducer *pLocalReducer) { // reset output buffer to the beginning 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->pCtx[i].aOutputBuf =
pLocalReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pLocalReducer->resColModel->maxCapacity; pLocalReducer->pResultBuf->data + tscFieldInfoGetOffset(pCmd, i) * pLocalReducer->resColModel->maxCapacity;
} }
...@@ -1190,17 +1190,17 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer ...@@ -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 // In handling data in other groups, we need to reset the interpolation information for a new group data
pRes->numOfRows = 0; pRes->numOfRows = 0;
pRes->numOfTotal = 0; pRes->numOfTotal = 0;
pCmd->limit.offset = pLocalReducer->offset; pCmd->pQueryInfo->limit.offset = pLocalReducer->offset;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
int16_t precision = pMeterMetaInfo->pMeterMeta->precision; int16_t precision = pMeterMetaInfo->pMeterMeta->precision;
// for group result interpolation, do not return if not data is generated // for group result interpolation, do not return if not data is generated
if (pCmd->interpoType != TSDB_INTERPO_NONE) { if (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) {
int64_t stime = (pCmd->stime < pCmd->etime) ? pCmd->stime : pCmd->etime; 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->nAggTimeInterval, pCmd->intervalTimeUnit, precision); 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); pLocalReducer->rowSize);
} }
} }
...@@ -1220,15 +1220,15 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) { ...@@ -1220,15 +1220,15 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) {
int8_t p = pMeterMetaInfo->pMeterMeta->precision; int8_t p = pMeterMetaInfo->pMeterMeta->precision;
if (taosHasRemainsDataForInterpolation(pInterpoInfo)) { if (taosHasRemainsDataForInterpolation(pInterpoInfo)) {
assert(pCmd->interpoType != TSDB_INTERPO_NONE); assert(pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE);
tFilePage *pFinalDataBuf = pLocalReducer->pResultBuf; tFilePage *pFinalDataBuf = pLocalReducer->pResultBuf;
int64_t etime = *(int64_t *)(pFinalDataBuf->data + TSDB_KEYSIZE * (pInterpoInfo->numOfRawDataInRows - 1)); int64_t etime = *(int64_t *)(pFinalDataBuf->data + TSDB_KEYSIZE * (pInterpoInfo->numOfRawDataInRows - 1));
int32_t remain = taosNumOfRemainPoints(pInterpoInfo); 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, 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 if (rows > 0) { // do interpo
doInterpolateResult(pSql, pLocalReducer, false); doInterpolateResult(pSql, pLocalReducer, false);
} }
...@@ -1254,11 +1254,11 @@ static bool doHandleLastRemainData(SSqlObj *pSql) { ...@@ -1254,11 +1254,11 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
if ((isAllSourcesCompleted(pLocalReducer) && !pLocalReducer->hasPrevRow) || pLocalReducer->pLocalDataSrc[0] == NULL || if ((isAllSourcesCompleted(pLocalReducer) && !pLocalReducer->hasPrevRow) || pLocalReducer->pLocalDataSrc[0] == NULL ||
prevGroupCompleted) { prevGroupCompleted) {
// if interpoType == TSDB_INTERPO_NONE, return directly // if interpoType == TSDB_INTERPO_NONE, return directly
if (pCmd->interpoType != TSDB_INTERPO_NONE) { if (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) {
int64_t etime = (pCmd->stime < pCmd->etime) ? pCmd->etime : pCmd->stime; 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); etime = taosGetRevisedEndKey(etime, pCmd->order.order, pCmd->pQueryInfo[0].nAggTimeInterval, pCmd->pQueryInfo[0].intervalTimeUnit, precision);
int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pCmd->nAggTimeInterval, etime, int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pCmd->pQueryInfo[0].nAggTimeInterval, etime,
pLocalReducer->resColModel->maxCapacity); pLocalReducer->resColModel->maxCapacity);
if (rows > 0) { // do interpo if (rows > 0) { // do interpo
doInterpolateResult(pSql, pLocalReducer, true); doInterpolateResult(pSql, pLocalReducer, true);
...@@ -1291,7 +1291,7 @@ static void doMergeWithPrevRows(SSqlObj *pSql, int32_t numOfRes) { ...@@ -1291,7 +1291,7 @@ static void doMergeWithPrevRows(SSqlObj *pSql, int32_t numOfRes) {
SSqlRes * pRes = &pSql->res; SSqlRes * pRes = &pSql->res;
SLocalReducer *pLocalReducer = pRes->pLocalReducer; 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, k);
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k]; SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k];
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
#include "trpc.h" #include "trpc.h"
#include "tscJoinProcess.h" #include "tscJoinProcess.h"
#include "tscProfile.h" #include "tscProfile.h"
#include "tscSQLParser.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tsclient.h" #include "tsclient.h"
#include "tscompression.h" #include "tscompression.h"
#include "tsocket.h" #include "tsocket.h"
#include "tscSQLParser.h"
#include "ttime.h" #include "ttime.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
...@@ -32,23 +32,26 @@ ...@@ -32,23 +32,26 @@
#define TSC_MGMT_VNODE 999 #define TSC_MGMT_VNODE 999
#ifdef CLUSTER #ifdef CLUSTER
SIpStrList tscMgmtIpList; SIpStrList tscMgmtIpList;
int tsMasterIndex = 0; int tsMasterIndex = 0;
int tsSlaveIndex = 1; int tsSlaveIndex = 1;
#else #else
int tsMasterIndex = 0; int tsMasterIndex = 0;
int tsSlaveIndex = 0; // slave == master for single node edition int tsSlaveIndex = 0; // slave == master for single node edition
uint32_t tsServerIp; uint32_t tsServerIp;
#endif #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); int (*tscProcessMsgRsp[TSDB_SQL_MAX])(SSqlObj *pSql);
void (*tscUpdateVnodeMsg[TSDB_SQL_MAX])(SSqlObj *pSql, char *buf); void (*tscUpdateVnodeMsg[TSDB_SQL_MAX])(SSqlObj *pSql, char *buf);
void tscProcessActivityTimer(void *handle, void *tmrId); 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 int32_t minMsgSize() { return tsRpcHeadSize + sizeof(STaosDigest); }
static char *doBuildMsgHeader(SSqlObj *pSql, char **pStart);
#ifdef CLUSTER #ifdef CLUSTER
void tscPrintMgmtIp() { void tscPrintMgmtIp() {
if (tscMgmtIpList.numOfIps <= 0) { if (tscMgmtIpList.numOfIps <= 0) {
...@@ -71,7 +74,7 @@ static int32_t tscGetMgmtConnMaxRetryTimes() { ...@@ -71,7 +74,7 @@ static int32_t tscGetMgmtConnMaxRetryTimes() {
#ifdef CLUSTER #ifdef CLUSTER
return tscMgmtIpList.numOfIps * factor; return tscMgmtIpList.numOfIps * factor;
#else #else
return 1*factor; return 1 * factor;
#endif #endif
} }
...@@ -89,7 +92,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { ...@@ -89,7 +92,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) {
if (code == 0) { if (code == 0) {
SHeartBeatRsp *pRsp = (SHeartBeatRsp *)pRes->pRsp; SHeartBeatRsp *pRsp = (SHeartBeatRsp *)pRes->pRsp;
#ifdef CLUSTER #ifdef CLUSTER
SIpList * pIpList = &pRsp->ipList; SIpList *pIpList = &pRsp->ipList;
tscMgmtIpList.numOfIps = pIpList->numOfIps; tscMgmtIpList.numOfIps = pIpList->numOfIps;
if (memcmp(tscMgmtIpList.ip, pIpList->ip, pIpList->numOfIps * 4) != 0) { if (memcmp(tscMgmtIpList.ip, pIpList->ip, pIpList->numOfIps * 4) != 0) {
for (int i = 0; i < pIpList->numOfIps; ++i) { for (int i = 0; i < pIpList->numOfIps; ++i) {
...@@ -179,11 +182,11 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { ...@@ -179,11 +182,11 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) {
connInit.spi = 1; connInit.spi = 1;
connInit.encrypt = 0; connInit.encrypt = 0;
connInit.secret = pSql->pTscObj->pass; connInit.secret = pSql->pTscObj->pass;
#ifdef CLUSTER #ifdef CLUSTER
connInit.peerIp = tscMgmtIpList.ipstr[pSql->index]; connInit.peerIp = tscMgmtIpList.ipstr[pSql->index];
#else #else
connInit.peerIp = tsServerIpStr; connInit.peerIp = tsServerIpStr;
#endif #endif
thandle = taosOpenRpcConn(&connInit, pCode); thandle = taosOpenRpcConn(&connInit, pCode);
} }
...@@ -199,13 +202,13 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { ...@@ -199,13 +202,13 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) {
pSql->vnode = TSC_MGMT_VNODE; pSql->vnode = TSC_MGMT_VNODE;
#endif #endif
} }
// the pSql->res.code is the previous error(status) code. // the pSql->res.code is the previous error(status) code.
if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) { if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) {
if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) { if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) {
*pCode = pSql->res.code; *pCode = pSql->res.code;
} }
tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode); tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode);
} }
} }
...@@ -304,13 +307,13 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) { ...@@ -304,13 +307,13 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
break; break;
} }
// the pSql->res.code is the previous error(status) code. // the pSql->res.code is the previous error(status) code.
if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) { if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) {
if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) { if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) {
*pCode = pSql->res.code; *pCode = pSql->res.code;
} }
tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode); tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode);
} }
} }
...@@ -352,14 +355,14 @@ int tscSendMsgToServer(SSqlObj *pSql) { ...@@ -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 * 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. * 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); if (tscUpdateVnodeMsg[pSql->cmd.command]) (*tscUpdateVnodeMsg[pSql->cmd.command])(pSql, buf);
int ret = taosSendMsgToPeerH(pSql->thandle, pStart, pSql->cmd.payloadLen, pSql); int ret = taosSendMsgToPeerH(pSql->thandle, pStart, pSql->cmd.payloadLen, pSql);
if (ret >= 0) { if (ret >= 0) {
code = 0; code = 0;
} }
tscTrace("%p send msg ret:%d code:%d sig:%p", pSql, ret, code, signature); 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) { ...@@ -421,7 +424,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
if (msg == NULL) { if (msg == NULL) {
tscTrace("%p no response from ip:0x%x", pSql, pSql->ip); tscTrace("%p no response from ip:0x%x", pSql, pSql->ip);
#ifdef CLUSTER #ifdef CLUSTER
pSql->index++; pSql->index++;
#else #else
...@@ -459,9 +462,9 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { ...@@ -459,9 +462,9 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
} }
} else { } else {
uint16_t rspCode = pMsg->content[0]; uint16_t rspCode = pMsg->content[0];
#ifdef CLUSTER #ifdef CLUSTER
if (rspCode == TSDB_CODE_REDIRECT) { if (rspCode == TSDB_CODE_REDIRECT) {
tscTrace("%p it shall be redirected!", pSql); tscTrace("%p it shall be redirected!", pSql);
taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user);
...@@ -469,7 +472,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { ...@@ -469,7 +472,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
if (pCmd->command > TSDB_SQL_MGMT) { if (pCmd->command > TSDB_SQL_MGMT) {
tscProcessMgmtRedirect(pSql, pMsg->content + 1); tscProcessMgmtRedirect(pSql, pMsg->content + 1);
} else if (pCmd->command == TSDB_SQL_INSERT){ } else if (pCmd->command == TSDB_SQL_INSERT) {
pSql->index++; pSql->index++;
pSql->maxRetry = TSDB_VNODES_SUPPORT * 2; pSql->maxRetry = TSDB_VNODES_SUPPORT * 2;
} else { } else {
...@@ -480,26 +483,26 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { ...@@ -480,26 +483,26 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
if (code == 0) return pSql; if (code == 0) return pSql;
msg = NULL; msg = NULL;
} else if (rspCode == TSDB_CODE_NOT_ACTIVE_TABLE || rspCode == TSDB_CODE_INVALID_TABLE_ID || } 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_NOT_ACTIVE_VNODE || rspCode == TSDB_CODE_INVALID_VNODE_ID ||
rspCode == TSDB_CODE_TABLE_ID_MISMATCH || rspCode == TSDB_CODE_NETWORK_UNAVAIL) { rspCode == TSDB_CODE_TABLE_ID_MISMATCH || rspCode == TSDB_CODE_NETWORK_UNAVAIL) {
#else #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_NOT_ACTIVE_VNODE || rspCode == TSDB_CODE_INVALID_VNODE_ID ||
rspCode == TSDB_CODE_TABLE_ID_MISMATCH || rspCode == TSDB_CODE_NETWORK_UNAVAIL) { rspCode == TSDB_CODE_TABLE_ID_MISMATCH || rspCode == TSDB_CODE_NETWORK_UNAVAIL) {
#endif #endif
pSql->thandle = NULL; pSql->thandle = NULL;
taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user);
if (pCmd->command == TSDB_SQL_CONNECT) { if (pCmd->command == TSDB_SQL_CONNECT) {
code = TSDB_CODE_NETWORK_UNAVAIL; code = TSDB_CODE_NETWORK_UNAVAIL;
} else if (pCmd->command == TSDB_SQL_HB) { } else if (pCmd->command == TSDB_SQL_HB) {
code = TSDB_CODE_NOT_READY; code = TSDB_CODE_NOT_READY;
} else { } else {
tscTrace("%p it shall renew meter meta, code:%d", pSql, rspCode); tscTrace("%p it shall renew meter meta, code:%d", pSql, rspCode);
pSql->maxRetry = TSDB_VNODES_SUPPORT * 2; 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); code = tscRenewMeterMeta(pSql, pMeterMetaInfo->name);
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return pSql; if (code == TSDB_CODE_ACTION_IN_PROGRESS) return pSql;
...@@ -631,7 +634,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { ...@@ -631,7 +634,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
} }
static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj); static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj);
static int tscLaunchMetricSubQueries(SSqlObj *pSql); static int tscLaunchMetricSubQueries(SSqlObj *pSql);
// todo merge with callback // todo merge with callback
int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySupporter *pSupporter) { int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySupporter *pSupporter) {
...@@ -651,7 +654,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu ...@@ -651,7 +654,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
if (pNew == NULL) { if (pNew == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_CLI_OUT_OF_MEMORY;
} }
pSql->pSubs[pSql->numOfSubs++] = pNew; pSql->pSubs[pSql->numOfSubs++] = pNew;
assert(pSql->numOfSubs <= pSupporter->pState->numOfTotal); assert(pSql->numOfSubs <= pSupporter->pState->numOfTotal);
...@@ -659,19 +662,19 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu ...@@ -659,19 +662,19 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
addGroupInfoForSubquery(pSql, pNew, tableIndex); addGroupInfoForSubquery(pSql, pNew, tableIndex);
// refactor as one method // refactor as one method
tscColumnBaseInfoUpdateTableIndex(&pNew->cmd.colList, 0); tscColumnBaseInfoUpdateTableIndex(&pNew->cmd.pQueryInfo[0].colList, 0);
tscColumnBaseInfoCopy(&pSupporter->colList, &pNew->cmd.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); tscFieldInfoCopyAll(&pNew->cmd.pQueryInfo[0].fieldsInfo, &pSupporter->fieldsInfo);
tscTagCondCopy(&pSupporter->tagCond, &pNew->cmd.tagCond); tscTagCondCopy(&pSupporter->tagCond, &pNew->cmd.pQueryInfo[0].tagCond);
pSupporter->groupbyExpr = pNew->cmd.groupbyExpr; pSupporter->groupbyExpr = pNew->cmd.pQueryInfo[0].groupbyExpr;
pNew->cmd.numOfCols = 0; pNew->cmd.numOfCols = 0;
pNew->cmd.nAggTimeInterval = 0; pNew->cmd.pQueryInfo[0].nAggTimeInterval = 0;
memset(&pNew->cmd.limit, 0, sizeof(SLimitVal)); memset(&pNew->cmd.pQueryInfo[0].limit, 0, sizeof(SLimitVal));
memset(&pNew->cmd.groupbyExpr, 0, sizeof(SSqlGroupbyExpr)); memset(&pNew->cmd.pQueryInfo[0].groupbyExpr, 0, sizeof(SSqlGroupbyExpr));
// set the ts,tags that involved in join, as the output column of intermediate result // set the ts,tags that involved in join, as the output column of intermediate result
tscFreeSqlCmdData(&pNew->cmd); tscFreeSqlCmdData(&pNew->cmd);
...@@ -694,18 +697,18 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu ...@@ -694,18 +697,18 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
for (int32_t i = 0; i < pSupporter->colList.numOfCols; ++i) { for (int32_t i = 0; i < pSupporter->colList.numOfCols; ++i) {
SColumnBase *pColBase = &pSupporter->colList.pColList[i]; SColumnBase *pColBase = &pSupporter->colList.pColList[i];
if (pColBase->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered. if (pColBase->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered.
tscColumnBaseCopy(&pNew->cmd.colList.pColList[pNew->cmd.colList.numOfCols], pColBase); tscColumnBaseCopy(&pNew->cmd.pQueryInfo[0].colList.pColList[pNew->cmd.pQueryInfo[0].colList.numOfCols], pColBase);
pNew->cmd.colList.numOfCols++; pNew->cmd.pQueryInfo[0].colList.numOfCols++;
} }
} }
} else { } else {
pNew->cmd.type |= TSDB_QUERY_TYPE_SUBQUERY; pNew->cmd.type |= TSDB_QUERY_TYPE_SUBQUERY;
} }
#ifdef _DEBUG_VIEW #ifdef _DEBUG_VIEW
tscPrintSelectClause(&pNew->cmd); tscPrintSelectClause(&pNew->cmd);
#endif #endif
return tscProcessSql(pNew); return tscProcessSql(pNew);
} }
...@@ -713,30 +716,31 @@ int doProcessSql(SSqlObj *pSql) { ...@@ -713,30 +716,31 @@ int doProcessSql(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
int32_t code = TSDB_CODE_SUCCESS;
void *asyncFp = pSql->fp; void *asyncFp = pSql->fp;
if (tscBuildMsg[pCmd->command](pSql) < 0) { // build msg failed if (pCmd->command == TSDB_SQL_SELECT || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_RETRIEVE ||
code = TSDB_CODE_APP_ERROR; pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_CONNECT || pCmd->command == TSDB_SQL_HB ||
} else { pCmd->command == TSDB_SQL_META || pCmd->command == TSDB_SQL_METRIC) {
code = tscSendMsgToServer(pSql); tscBuildMsg[pCmd->command](pSql, NULL);
} }
int32_t code = tscSendMsgToServer(pSql);
if (asyncFp) { if (asyncFp) {
if (code != 0) { if (code != TSDB_CODE_SUCCESS) {
pRes->code = code; pRes->code = code;
tscQueueAsyncRes(pSql); tscQueueAsyncRes(pSql);
} }
return 0; return 0;
} }
if (code != 0) { if (code != TSDB_CODE_SUCCESS) {
pRes->code = code; pRes->code = code;
return code; return code;
} }
tsem_wait(&pSql->rspSem); 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); tsem_post(&pSql->emptyRspSem);
...@@ -747,12 +751,13 @@ int tscProcessSql(SSqlObj *pSql) { ...@@ -747,12 +751,13 @@ int tscProcessSql(SSqlObj *pSql) {
char * name = NULL; char * name = NULL;
SSqlRes * pRes = &pSql->res; SSqlRes * pRes = &pSql->res;
SSqlCmd * pCmd = &pSql->cmd; SSqlCmd * pCmd = &pSql->cmd;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
if (pMeterMetaInfo != NULL) { if (pMeterMetaInfo != NULL) {
name = pMeterMetaInfo->name; name = pMeterMetaInfo->name;
} }
tscTrace("%p SQL cmd:%d will be processed, name:%s, type:%d", pSql, pSql->cmd.command, name, pSql->cmd.type); tscTrace("%p SQL cmd:%d will be processed, name:%s, type:%d", pSql, pSql->cmd.command, name, pSql->cmd.type);
pSql->retry = 0; pSql->retry = 0;
if (pSql->cmd.command < TSDB_SQL_MGMT) { if (pSql->cmd.command < TSDB_SQL_MGMT) {
...@@ -761,18 +766,19 @@ int tscProcessSql(SSqlObj *pSql) { ...@@ -761,18 +766,19 @@ int tscProcessSql(SSqlObj *pSql) {
#else #else
pSql->maxRetry = 2; pSql->maxRetry = 2;
#endif #endif
// the pMeterMetaInfo cannot be NULL // the pMeterMetaInfo cannot be NULL
if (pMeterMetaInfo == NULL) { if (pMeterMetaInfo == NULL) {
pSql->res.code = TSDB_CODE_OTHERS; pSql->res.code = TSDB_CODE_OTHERS;
return pSql->res.code; return pSql->res.code;
} }
if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) { if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) {
pSql->index = pMeterMetaInfo->pMeterMeta->index; pSql->index = pMeterMetaInfo->pMeterMeta->index;
} else { // it must be the parent SSqlObj for super table query } else { // it must be the parent SSqlObj for super table query
if ((pSql->cmd.type & TSDB_QUERY_TYPE_SUBQUERY) != 0) { 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); SVnodeSidList *pSidList = tscGetVnodeSidList(pMeterMetaInfo->pMetricMeta, idx);
pSql->index = pSidList->index; pSql->index = pSidList->index;
} }
...@@ -787,14 +793,14 @@ int tscProcessSql(SSqlObj *pSql) { ...@@ -787,14 +793,14 @@ int tscProcessSql(SSqlObj *pSql) {
if (QUERY_IS_JOIN_QUERY(pSql->cmd.type)) { if (QUERY_IS_JOIN_QUERY(pSql->cmd.type)) {
if ((pSql->cmd.type & TSDB_QUERY_TYPE_SUBQUERY) == 0) { if ((pSql->cmd.type & TSDB_QUERY_TYPE_SUBQUERY) == 0) {
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); 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); SJoinSubquerySupporter *pSupporter = tscCreateJoinSupporter(pSql, pState, i);
if (pSupporter == NULL) { // failed to create support struct, abort current query 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); 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; pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY;
return pSql->res.code; return pSql->res.code;
...@@ -965,8 +971,8 @@ int tscLaunchMetricSubQueries(SSqlObj *pSql) { ...@@ -965,8 +971,8 @@ int tscLaunchMetricSubQueries(SSqlObj *pSql) {
} }
// todo handle multi-vnode situation // todo handle multi-vnode situation
if (pSql->cmd.tsBuf) { if (pSql->cmd.pQueryInfo[0].tsBuf) {
pNew->cmd.tsBuf = tsBufClone(pSql->cmd.tsBuf); pNew->cmd.pQueryInfo[0].tsBuf = tsBufClone(pSql->cmd.pQueryInfo[0].tsBuf);
} }
tscTrace("%p sub:%p launch subquery.orderOfSub:%d", pSql, pNew, trs->subqueryIndex); tscTrace("%p sub:%p launch subquery.orderOfSub:%d", pSql, pNew, trs->subqueryIndex);
...@@ -1039,7 +1045,7 @@ static void tscHandleSubRetrievalError(SRetrieveSupport *trsupport, SSqlObj *pSq ...@@ -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. 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); 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, 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 { } else {
if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && trsupport->pState->code == TSDB_CODE_SUCCESS) { 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) { ...@@ -1118,7 +1124,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
tOrderDescriptor *pDesc = trsupport->pOrderDescriptor; tOrderDescriptor *pDesc = trsupport->pOrderDescriptor;
SSqlObj *pSql = (SSqlObj *)tres; 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); tscTrace("%p subquery has been released, idx:%d, abort", pPObj, idx);
return; return;
} }
...@@ -1157,7 +1163,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { ...@@ -1157,7 +1163,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
return; return;
} }
int32_t ret = saveToBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pRes->data, 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) { if (ret < 0) {
// set no disk space error info, and abort retry // set no disk space error info, and abort retry
tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE);
...@@ -1168,8 +1174,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { ...@@ -1168,8 +1174,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
} else { // all data has been retrieved to client } else { // all data has been retrieved to client
/* data in from current vnode is stored in cache and disk */ /* data in from current vnode is stored in cache and disk */
uint32_t numOfRowsFromVnode = uint32_t numOfRowsFromVnode = trsupport->pExtMemBuffer[idx]->numOfAllElems + trsupport->localBuffer->numOfElems;
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, tscTrace("%p sub:%p all data retrieved from ip:%u,vid:%d, numOfRows:%d, orderOfSub:%d", pPObj, pSql, pSvd->ip,
pSvd->vnode, numOfRowsFromVnode, idx); pSvd->vnode, numOfRowsFromVnode, idx);
...@@ -1192,7 +1197,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { ...@@ -1192,7 +1197,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
// each result for a vnode is ordered as an independant list, // each result for a vnode is ordered as an independant list,
// then used as an input of loser tree for disk-based merge routine // then used as an input of loser tree for disk-based merge routine
int32_t ret = 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) { if (ret != 0) {
/* set no disk space error info, and abort retry */ /* set no disk space error info, and abort retry */
return tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); return tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE);
...@@ -1285,12 +1290,12 @@ static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsu ...@@ -1285,12 +1290,12 @@ static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsu
SSqlObj *pNew = createSubqueryObj(pSql, 0, tscRetrieveDataRes, trsupport, prevSqlObj); SSqlObj *pNew = createSubqueryObj(pSql, 0, tscRetrieveDataRes, trsupport, prevSqlObj);
if (pNew != NULL) { // the sub query of two-stage super table query if (pNew != NULL) { // the sub query of two-stage super table query
pNew->cmd.type |= TSDB_QUERY_TYPE_STABLE_SUBQUERY; pNew->cmd.type |= TSDB_QUERY_TYPE_STABLE_SUBQUERY;
assert(pNew->cmd.numOfTables == 1); assert(pNew->cmd.pQueryInfo[0].numOfTables == 1);
//launch subquery for each vnode, so the subquery index equals to the vnodeIndex. // launch subquery for each vnode, so the subquery index equals to the vnodeIndex.
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pNew->cmd, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pNew->cmd, 0);
pMeterMetaInfo->vnodeIndex = trsupport->subqueryIndex; pMeterMetaInfo->vnodeIndex = trsupport->subqueryIndex;
pSql->pSubs[trsupport->subqueryIndex] = pNew; pSql->pSubs[trsupport->subqueryIndex] = pNew;
} }
...@@ -1345,7 +1350,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { ...@@ -1345,7 +1350,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
trsupport->pState->code = -TSDB_CODE_CLI_OUT_OF_MEMORY; trsupport->pState->code = -TSDB_CODE_CLI_OUT_OF_MEMORY;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
} else { } 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); tscProcessSql(pNew);
return; return;
} }
...@@ -1372,7 +1377,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { ...@@ -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; char *pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -1382,7 +1387,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql) { ...@@ -1382,7 +1387,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql) {
*((uint64_t *)pMsg) = pSql->res.qhandle; *((uint64_t *)pMsg) = pSql->res.qhandle;
pMsg += sizeof(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); pMsg += sizeof(pSql->cmd.type);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
...@@ -1403,10 +1408,11 @@ void tscUpdateVnodeInSubmitMsg(SSqlObj *pSql, char *buf) { ...@@ -1403,10 +1408,11 @@ void tscUpdateVnodeInSubmitMsg(SSqlObj *pSql, char *buf) {
pShellMsg = (SShellSubmitMsg *)pMsg; pShellMsg = (SShellSubmitMsg *)pMsg;
pShellMsg->vnode = htons(pMeterMeta->vpeerDesc[pSql->index].vnode); 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; SShellSubmitMsg *pShellMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -1424,7 +1430,8 @@ int tscBuildSubmitMsg(SSqlObj *pSql) { ...@@ -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.payloadLen is set during parse sql routine, so we do not use it here
pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; 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; return msgLen;
} }
...@@ -1452,9 +1459,10 @@ void tscUpdateVnodeInQueryMsg(SSqlObj *pSql, char *buf) { ...@@ -1452,9 +1459,10 @@ void tscUpdateVnodeInQueryMsg(SSqlObj *pSql, char *buf) {
*/ */
static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) { static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) {
const static int32_t MIN_QUERY_MSG_PKT_SIZE = TSDB_MAX_BYTES_PER_ROW * 5; 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); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
// meter query without tags values // meter query without tags values
...@@ -1467,19 +1475,19 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) { ...@@ -1467,19 +1475,19 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd) {
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex); SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex);
int32_t meterInfoSize = (pMetricMeta->tagLen + sizeof(SMeterSidExtInfo)) * pVnodeSidList->numOfSids; 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; int32_t size = meterInfoSize + outputColumnSize + srcColListSize + exprSize + MIN_QUERY_MSG_PKT_SIZE;
if (pCmd->tsBuf != NULL) { if (pCmd->pQueryInfo[0].tsBuf != NULL) {
size += pCmd->tsBuf->fileSize; size += pCmd->pQueryInfo[0].tsBuf->fileSize;
} }
return size; 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); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0);
SMeterMeta * pMeterMeta = pMeterMetaInfo->pMeterMeta; SMeterMeta * pMeterMeta = pMeterMetaInfo->pMeterMeta;
SMetricMeta *pMetricMeta = pMeterMetaInfo->pMetricMeta; SMetricMeta *pMetricMeta = pMeterMetaInfo->pMetricMeta;
...@@ -1491,20 +1499,20 @@ static char* doSerializeTableInfo(SSqlObj* pSql, int32_t numOfMeters, int32_t vn ...@@ -1491,20 +1499,20 @@ static char* doSerializeTableInfo(SSqlObj* pSql, int32_t numOfMeters, int32_t vn
SMeterSidExtInfo *pMeterInfo = (SMeterSidExtInfo *)pMsg; SMeterSidExtInfo *pMeterInfo = (SMeterSidExtInfo *)pMsg;
pMeterInfo->sid = htonl(pMeterMeta->sid); pMeterInfo->sid = htonl(pMeterMeta->sid);
pMeterInfo->uid = htobe64(pMeterMeta->uid); pMeterInfo->uid = htobe64(pMeterMeta->uid);
pMsg += sizeof(SMeterSidExtInfo); pMsg += sizeof(SMeterSidExtInfo);
} else { } else {
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex); SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex);
for (int32_t i = 0; i < numOfMeters; ++i) { for (int32_t i = 0; i < numOfMeters; ++i) {
SMeterSidExtInfo *pMeterInfo = (SMeterSidExtInfo *)pMsg; SMeterSidExtInfo *pMeterInfo = (SMeterSidExtInfo *)pMsg;
SMeterSidExtInfo *pQueryMeterInfo = tscGetMeterSidInfo(pVnodeSidList, i); SMeterSidExtInfo *pQueryMeterInfo = tscGetMeterSidInfo(pVnodeSidList, i);
pMeterInfo->sid = htonl(pQueryMeterInfo->sid); pMeterInfo->sid = htonl(pQueryMeterInfo->sid);
pMeterInfo->uid = htobe64(pQueryMeterInfo->uid); pMeterInfo->uid = htobe64(pQueryMeterInfo->uid);
pMsg += sizeof(SMeterSidExtInfo); pMsg += sizeof(SMeterSidExtInfo);
memcpy(pMsg, pQueryMeterInfo->tags, pMetricMeta->tagLen); memcpy(pMsg, pQueryMeterInfo->tags, pMetricMeta->tagLen);
pMsg += pMetricMeta->tagLen; pMsg += pMetricMeta->tagLen;
...@@ -1513,11 +1521,11 @@ static char* doSerializeTableInfo(SSqlObj* pSql, int32_t numOfMeters, int32_t vn ...@@ -1513,11 +1521,11 @@ static char* doSerializeTableInfo(SSqlObj* pSql, int32_t numOfMeters, int32_t vn
#endif #endif
} }
} }
return pMsg; return pMsg;
} }
int tscBuildQueryMsg(SSqlObj *pSql) { int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
int32_t size = tscEstimateQueryMsgSize(pCmd); int32_t size = tscEstimateQueryMsgSize(pCmd);
...@@ -1570,25 +1578,25 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1570,25 +1578,25 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
pQueryMsg->numOfTagsCols = htons(pMeterMetaInfo->numOfTags); pQueryMsg->numOfTagsCols = htons(pMeterMetaInfo->numOfTags);
if (pCmd->order.order == TSQL_SO_ASC) { if (pCmd->order.order == TSQL_SO_ASC) {
pQueryMsg->skey = htobe64(pCmd->stime); pQueryMsg->skey = htobe64(pCmd->pQueryInfo[0].stime);
pQueryMsg->ekey = htobe64(pCmd->etime); pQueryMsg->ekey = htobe64(pCmd->pQueryInfo[0].etime);
} else { } else {
pQueryMsg->skey = htobe64(pCmd->etime); pQueryMsg->skey = htobe64(pCmd->pQueryInfo[0].etime);
pQueryMsg->ekey = htobe64(pCmd->stime); pQueryMsg->ekey = htobe64(pCmd->pQueryInfo[0].stime);
} }
pQueryMsg->num = htonl(0); pQueryMsg->num = htonl(0);
pQueryMsg->order = htons(pCmd->order.order); pQueryMsg->order = htons(pCmd->order.order);
pQueryMsg->orderColId = htons(pCmd->order.orderColId); 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->limit = htobe64(pCmd->pQueryInfo->limit.limit);
pQueryMsg->offset = htobe64(pCmd->limit.offset); 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); tscError("%p illegal value of numOfCols in query msg: %d", pSql, pMeterMeta->numOfColumns);
return -1; return -1;
} }
...@@ -1598,19 +1606,19 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1598,19 +1606,19 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
return -1; return -1;
} }
pQueryMsg->nAggTimeInterval = htobe64(pCmd->nAggTimeInterval); pQueryMsg->nAggTimeInterval = htobe64(pCmd->pQueryInfo[0].nAggTimeInterval);
pQueryMsg->intervalTimeUnit = pCmd->intervalTimeUnit; pQueryMsg->intervalTimeUnit = pCmd->pQueryInfo[0].intervalTimeUnit;
if (pCmd->nAggTimeInterval < 0) { if (pCmd->pQueryInfo[0].nAggTimeInterval < 0) {
tscError("%p illegal value of aggregation time interval in query msg: %ld", pSql, pCmd->nAggTimeInterval); tscError("%p illegal value of aggregation time interval in query msg: %ld", pSql, pCmd->pQueryInfo[0].nAggTimeInterval);
return -1; return -1;
} }
if (pCmd->groupbyExpr.numOfGroupCols < 0) { if (pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols < 0) {
tscError("%p illegal value of numOfGroupCols in query msg: %d", pSql, pCmd->groupbyExpr.numOfGroupCols); tscError("%p illegal value of numOfGroupCols in query msg: %d", pSql, pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols);
return -1; 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 if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) { // query on meter
pQueryMsg->tagLength = 0; pQueryMsg->tagLength = 0;
...@@ -1619,19 +1627,19 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1619,19 +1627,19 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
} }
pQueryMsg->queryType = htons(pCmd->type); pQueryMsg->queryType = htons(pCmd->type);
pQueryMsg->numOfOutputCols = htons(pCmd->exprsInfo.numOfExprs); pQueryMsg->numOfOutputCols = htons(pCmd->pQueryInfo[0].exprsInfo.numOfExprs);
if (pCmd->fieldsInfo.numOfOutputCols < 0) { if (pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols < 0) {
tscError("%p illegal value of number of output columns in query msg: %d", pSql, pCmd->fieldsInfo.numOfOutputCols); tscError("%p illegal value of number of output columns in query msg: %d", pSql, pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
return -1; return -1;
} }
// set column list ids // 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); SSchema *pSchema = tsGetSchema(pMeterMeta);
for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo[0].colList.numOfCols; ++i) {
SColumnBase *pCol = tscColumnBaseInfoGet(&pCmd->colList, i); SColumnBase *pCol = tscColumnBaseInfoGet(&pCmd->pQueryInfo[0].colList, i);
SSchema * pColSchema = &pSchema[pCol->colIndex.columnIndex]; SSchema * pColSchema = &pSchema[pCol->colIndex.columnIndex];
if (pCol->colIndex.columnIndex >= pMeterMeta->numOfColumns || pColSchema->type < TSDB_DATA_TYPE_BOOL || if (pCol->colIndex.columnIndex >= pMeterMeta->numOfColumns || pColSchema->type < TSDB_DATA_TYPE_BOOL ||
...@@ -1680,7 +1688,7 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1680,7 +1688,7 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
SSqlFuncExprMsg *pSqlFuncExpr = (SSqlFuncExprMsg *)pMsg; 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_ARITHM) { if (pExpr->functionId == TSDB_FUNC_ARITHM) {
...@@ -1720,8 +1728,8 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1720,8 +1728,8 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
int32_t len = 0; int32_t len = 0;
if (hasArithmeticFunction) { if (hasArithmeticFunction) {
SColumnBase *pColBase = pCmd->colList.pColList; SColumnBase *pColBase = pCmd->pQueryInfo[0].colList.pColList;
for (int32_t i = 0; i < pCmd->colList.numOfCols; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo[0].colList.numOfCols; ++i) {
char * name = pSchema[pColBase[i].colIndex.columnIndex].name; char * name = pSchema[pColBase[i].colIndex.columnIndex].name;
int32_t lenx = strlen(name); int32_t lenx = strlen(name);
memcpy(pMsg, name, lenx); memcpy(pMsg, name, lenx);
...@@ -1755,7 +1763,7 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1755,7 +1763,7 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
} }
} }
SSqlGroupbyExpr *pGroupbyExpr = &pCmd->groupbyExpr; SSqlGroupbyExpr *pGroupbyExpr = &pCmd->pQueryInfo[0].groupbyExpr;
if (pGroupbyExpr->numOfGroupCols != 0) { if (pGroupbyExpr->numOfGroupCols != 0) {
pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex); pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex);
pQueryMsg->orderType = htons(pGroupbyExpr->orderType); pQueryMsg->orderType = htons(pGroupbyExpr->orderType);
...@@ -1777,10 +1785,10 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1777,10 +1785,10 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
} }
} }
if (pCmd->interpoType != TSDB_INTERPO_NONE) { if (pCmd->pQueryInfo[0].interpoType != TSDB_INTERPO_NONE) {
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols; ++i) {
*((int64_t *)pMsg) = htobe64(pCmd->defaultVal[i]); *((int64_t *)pMsg) = htobe64(pCmd->pQueryInfo[0].defaultVal[i]);
pMsg += sizeof(pCmd->defaultVal[0]); pMsg += sizeof(pCmd->pQueryInfo[0].defaultVal[0]);
} }
} }
...@@ -1789,13 +1797,13 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1789,13 +1797,13 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
int32_t tsLen = 0; int32_t tsLen = 0;
int32_t numOfBlocks = 0; int32_t numOfBlocks = 0;
if (pCmd->tsBuf != NULL) { if (pCmd->pQueryInfo[0].tsBuf != NULL) {
STSVnodeBlockInfo *pBlockInfo = tsBufGetVnodeBlockInfo(pCmd->tsBuf, pMeterMetaInfo->vnodeIndex); STSVnodeBlockInfo *pBlockInfo = tsBufGetVnodeBlockInfo(pCmd->pQueryInfo[0].tsBuf, pMeterMetaInfo->vnodeIndex);
assert(QUERY_IS_JOIN_QUERY(pCmd->type) && pBlockInfo != NULL); // this query should not be sent assert(QUERY_IS_JOIN_QUERY(pCmd->type) && pBlockInfo != NULL); // this query should not be sent
// todo refactor // todo refactor
fseek(pCmd->tsBuf->f, pBlockInfo->offset, SEEK_SET); fseek(pCmd->pQueryInfo[0].tsBuf->f, pBlockInfo->offset, SEEK_SET);
fread(pMsg, pBlockInfo->compLen, 1, pCmd->tsBuf->f); fread(pMsg, pBlockInfo->compLen, 1, pCmd->pQueryInfo[0].tsBuf->f);
pMsg += pBlockInfo->compLen; pMsg += pBlockInfo->compLen;
tsLen = pBlockInfo->compLen; tsLen = pBlockInfo->compLen;
...@@ -1804,8 +1812,8 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1804,8 +1812,8 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
pQueryMsg->tsLen = htonl(tsLen); pQueryMsg->tsLen = htonl(tsLen);
pQueryMsg->tsNumOfBlocks = htonl(numOfBlocks); pQueryMsg->tsNumOfBlocks = htonl(numOfBlocks);
if (pCmd->tsBuf != NULL) { if (pCmd->pQueryInfo[0].tsBuf != NULL) {
pQueryMsg->tsOrder = htonl(pCmd->tsBuf->tsOrder); pQueryMsg->tsOrder = htonl(pCmd->pQueryInfo[0].tsBuf->tsOrder);
} }
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
...@@ -1815,346 +1823,266 @@ int tscBuildQueryMsg(SSqlObj *pSql) { ...@@ -1815,346 +1823,266 @@ int tscBuildQueryMsg(SSqlObj *pSql) {
pSql->cmd.msgType = TSDB_MSG_TYPE_QUERY; pSql->cmd.msgType = TSDB_MSG_TYPE_QUERY;
assert(msgLen + minMsgSize() <= size); assert(msgLen + minMsgSize() <= size);
return msgLen;
return TSDB_CODE_SUCCESS;
} }
int tscBuildCreateDbMsg(SSqlObj *pSql) { int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateDbMsg *pCreateDbMsg; SCreateDbMsg *pCreateDbMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd;
STscObj * pObj = pSql->pTscObj;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pStart = pCmd->payload + tsRpcHeadSize; SSqlCmd *pCmd = &pSql->cmd;
pMsg = pStart;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg;
strcpy(pMgmt->db, pObj->db);
pMsg += sizeof(SMgmtHead);
pMsg = doBuildMsgHeader(pSql, &pStart);
pCreateDbMsg = (SCreateDbMsg *)pMsg; pCreateDbMsg = (SCreateDbMsg *)pMsg;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db)); strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db));
pMsg += sizeof(SCreateDbMsg); pMsg += sizeof(SCreateDbMsg);
msgLen = pMsg - pStart; pCmd->payloadLen = pMsg - pStart;
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_CREATE_DB; 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; SCreateDnodeMsg *pCreate;
char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd; char *pMsg, *pStart;
STscObj * pObj = pSql->pTscObj;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pMsg = pCmd->payload + tsRpcHeadSize; SSqlCmd *pCmd = &pSql->cmd;
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; pMsg = doBuildMsgHeader(pSql, &pStart);
strcpy(pMgmt->db, pObj->db);
pMsg += sizeof(SMgmtHead);
pCreate = (SCreateDnodeMsg *)pMsg; pCreate = (SCreateDnodeMsg *)pMsg;
strcpy(pCreate->ip, pMeterMetaInfo->name); strncpy(pCreate->ip, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n);
pMsg += sizeof(SCreateDnodeMsg); pMsg += sizeof(SCreateDnodeMsg);
msgLen = pMsg - pStart; pCmd->payloadLen = pMsg - pStart;
pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE;
pCmd->msgType = TSDB_MSG_TYPE_CREATE_PNODE;
return msgLen; return TSDB_CODE_SUCCESS;
} }
int tscBuildDropDnodeMsg(SSqlObj *pSql) { int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropDnodeMsg *pDrop; SCreateAcctMsg *pAlterMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; 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);
pMsg += sizeof(SDropDnodeMsg); SSqlCmd *pCmd = &pSql->cmd;
msgLen = pMsg - pStart; pMsg = doBuildMsgHeader(pSql, &pStart);
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_DROP_PNODE;
return msgLen; pAlterMsg = (SCreateAcctMsg *)pMsg;
}
int tscBuildCreateUserMsg(SSqlObj *pSql) { SSQLToken *pName = &pInfo->pDCLInfo->user.user;
SCreateUserMsg *pCreateMsg; SSQLToken *pPwd = &pInfo->pDCLInfo->user.passwd;
char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd; strncpy(pAlterMsg->user, pName->z, pName->n);
STscObj * pObj = pSql->pTscObj; strncpy(pAlterMsg->pass, pPwd->z, pPwd->n);
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pMsg = pCmd->payload + tsRpcHeadSize; pMsg += sizeof(SCreateAcctMsg);
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; SCreateAcctSQL *pAcctOpt = &pInfo->pDCLInfo->acctOpt;
strcpy(pMgmt->db, pObj->db);
pMsg += sizeof(SMgmtHead);
pCreateMsg = (SCreateUserMsg *)pMsg; pAlterMsg->cfg.maxUsers = htonl(pAcctOpt->maxUsers);
strcpy(pCreateMsg->user, pMeterMetaInfo->name); pAlterMsg->cfg.maxDbs = htonl(pAcctOpt->maxDbs);
strcpy(pCreateMsg->pass, pCmd->payload); 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; msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen; 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) { int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateAcctMsg *pAlterMsg; SAlterUserMsg *pAlterMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
STscObj * pObj = pSql->pTscObj;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pMsg = pCmd->payload + tsRpcHeadSize; pMsg = doBuildMsgHeader(pSql, &pStart);
pStart = pMsg; pAlterMsg = (SCreateUserMsg *)pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; SUserInfo *pUser = &pInfo->pDCLInfo->user;
strcpy(pMgmt->db, pObj->db); strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n);
pMsg += sizeof(SMgmtHead); pAlterMsg->flag = pUser->type;
pAlterMsg = (SCreateAcctMsg *)pMsg; if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
strcpy(pAlterMsg->user, pMeterMetaInfo->name); pAlterMsg->privilege = (char)pCmd->count;
strcpy(pAlterMsg->pass, pCmd->payload); } 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]); pCmd->payloadLen = pMsg - pStart;
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];
msgLen = pMsg - pStart; if (pUser->type == TSDB_ALTER_USER_PASSWD || pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
pCmd->payloadLen = msgLen; 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) { int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int msgLen = tscBuildAcctMsgImpl(pSql); char * pStart = NULL;
pSql->cmd.msgType = TSDB_MSG_TYPE_CREATE_ACCT; SSqlCmd *pCmd = &pSql->cmd;
return msgLen;
}
int tscBuildAlterAcctMsg(SSqlObj *pSql) { char *pMsg = doBuildMsgHeader(pSql, &pStart);
int msgLen = tscBuildAcctMsgImpl(pSql); pMsg += sizeof(SCfgMsg);
pSql->cmd.msgType = TSDB_MSG_TYPE_ALTER_ACCT;
return msgLen;
}
int tscBuildAlterUserMsg(SSqlObj *pSql) { pCmd->payloadLen = pMsg - pStart;
SAlterUserMsg *pAlterMsg; pCmd->msgType = TSDB_MSG_TYPE_CFG_PNODE;
char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd; return TSDB_CODE_SUCCESS;
STscObj * pObj = pSql->pTscObj; }
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pMsg = pCmd->payload + tsRpcHeadSize; char *doBuildMsgHeader(SSqlObj *pSql, char **pStart) {
pStart = pMsg; SSqlCmd *pCmd = &pSql->cmd;
STscObj *pObj = pSql->pTscObj;
char *pMsg = pCmd->payload + tsRpcHeadSize;
*pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; SMgmtHead *pMgmt = (SMgmtHead *)pMsg;
strcpy(pMgmt->db, pObj->db); 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; pMsg += sizeof(SMgmtHead);
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_ALTER_USER;
return msgLen; return pMsg;
} }
int tscBuildCfgDnodeMsg(SSqlObj *pSql) { int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCfgMsg *pCfg; SDropDbMsg *pDropDbMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd;
STscObj * pObj = pSql->pTscObj;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pMsg = pCmd->payload + tsRpcHeadSize; SSqlCmd *pCmd = &pSql->cmd;
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; pMsg = doBuildMsgHeader(pSql, &pStart);
strcpy(pMgmt->db, pObj->db); pDropDbMsg = (SDropDbMsg *)pMsg;
pMsg += sizeof(SMgmtHead);
pCfg = (SCfgMsg *)pMsg; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
strcpy(pCfg->ip, pMeterMetaInfo->name); strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db));
strcpy(pCfg->config, pCmd->payload); pDropDbMsg->ignoreNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0;
pMsg += sizeof(SCfgMsg); pMsg += sizeof(SDropDbMsg);
msgLen = pMsg - pStart; pCmd->payloadLen = pMsg - pStart;
pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_DROP_DB;
pCmd->msgType = TSDB_MSG_TYPE_CFG_PNODE;
return msgLen; return TSDB_CODE_SUCCESS;
} }
int tscBuildDropDbMsg(SSqlObj *pSql) { int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropDbMsg *pDropDbMsg; SDropTableMsg *pDropTableMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; 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; SSqlCmd *pCmd = &pSql->cmd;
strcpy(pMgmt->db, pObj->db);
pMsg += sizeof(SMgmtHead);
pDropDbMsg = (SDropDbMsg *)pMsg; pMsg = doBuildMsgHeader(pSql, &pStart);
strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db)); 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; msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen; 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) { int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropUserMsg *pDropMsg; SDropDnodeMsg *pDrop;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd; SSqlCmd * pCmd = &pSql->cmd;
STscObj * pObj = pSql->pTscObj;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pMsg = pCmd->payload + tsRpcHeadSize; pMsg = doBuildMsgHeader(pSql, &pStart);
pStart = pMsg; pDrop = (SDropDnodeMsg *)pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg;
strcpy(pMgmt->db, pObj->db);
pMsg += sizeof(SMgmtHead);
pDropMsg = (SDropUserMsg *)pMsg; strcpy(pDrop->ip, pMeterMetaInfo->name);
strcpy(pDropMsg->user, pMeterMetaInfo->name);
pMsg += sizeof(SDropUserMsg); pMsg += sizeof(SDropDnodeMsg);
msgLen = pMsg - pStart; pCmd->payloadLen = pMsg - pStart;
pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE;
pCmd->msgType = TSDB_MSG_TYPE_DROP_USER;
return msgLen; return TSDB_CODE_SUCCESS;
} }
int tscBuildDropAcctMsg(SSqlObj *pSql) { int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropAcctMsg *pDropMsg; SDropUserMsg *pDropMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
STscObj * pObj = pSql->pTscObj;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
pMsg = pCmd->payload + tsRpcHeadSize;
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; pMsg = doBuildMsgHeader(pSql, &pStart);
strcpy(pMgmt->db, pObj->db); pDropMsg = (SDropUserMsg *)pMsg;
pMsg += sizeof(SMgmtHead);
pDropMsg = (SDropAcctMsg *)pMsg; SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
strcpy(pDropMsg->user, pMeterMetaInfo->name); strcpy(pDropMsg->user, pMeterMetaInfo->name);
pMsg += sizeof(SDropAcctMsg); pMsg += sizeof(SDropUserMsg);
msgLen = pMsg - pStart; pCmd->payloadLen = pMsg - pStart;
pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_DROP_USER;
pCmd->msgType = TSDB_MSG_TYPE_DROP_ACCT;
return msgLen; return msgLen;
} }
int tscBuildUseDbMsg(SSqlObj *pSql) { int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SUseDbMsg *pUseDbMsg; SUseDbMsg *pUseDbMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd * pCmd = &pSql->cmd; 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);
pUseDbMsg = (SUseDbMsg *)pMsg; pUseDbMsg = (SUseDbMsg *)pMsg;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
strcpy(pUseDbMsg->db, pMeterMetaInfo->name); strcpy(pUseDbMsg->db, pMeterMetaInfo->name);
pMsg += sizeof(SUseDbMsg); pMsg += sizeof(SUseDbMsg);
msgLen = pMsg - pStart; pCmd->payloadLen = pMsg - pStart;
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_USE_DB; 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; SShowMsg *pShowMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -2162,10 +2090,6 @@ int tscBuildShowMsg(SSqlObj *pSql) { ...@@ -2162,10 +2090,6 @@ int tscBuildShowMsg(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
STscObj *pObj = pSql->pTscObj; 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; int32_t size = minMsgSize() + sizeof(SMgmtHead) + sizeof(SShowTableMsg) + pCmd->payloadLen + TSDB_EXTRA_PAYLOAD_SIZE;
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for show msg", pSql); tscError("%p failed to malloc for show msg", pSql);
...@@ -2181,7 +2105,7 @@ int tscBuildShowMsg(SSqlObj *pSql) { ...@@ -2181,7 +2105,7 @@ int tscBuildShowMsg(SSqlObj *pSql) {
size_t nameLen = strlen(pMeterMetaInfo->name); size_t nameLen = strlen(pMeterMetaInfo->name);
if (nameLen > 0) { if (nameLen > 0) {
strcpy(pMgmt->db, pMeterMetaInfo->name); strcpy(pMgmt->db, pMeterMetaInfo->name); // prefix is set here
} else { } else {
strcpy(pMgmt->db, pObj->db); strcpy(pMgmt->db, pObj->db);
} }
...@@ -2189,152 +2113,107 @@ int tscBuildShowMsg(SSqlObj *pSql) { ...@@ -2189,152 +2113,107 @@ int tscBuildShowMsg(SSqlObj *pSql) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
pShowMsg = (SShowMsg *)pMsg; 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) { pShowMsg->type = pShowInfo->showType;
// only show tables support wildcard query
pShowMsg->payloadLen = htons(pCmd->payloadLen); if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) {
memcpy(pShowMsg->payload, payload, pCmd->payloadLen); 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; pMsg += (sizeof(SShowTableMsg) + pIpAddr->n);
pCmd->payloadLen = msgLen; }
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_SHOW; pCmd->msgType = TSDB_MSG_TYPE_SHOW;
assert(msgLen + minMsgSize() <= size); assert(msgLen + minMsgSize() <= size);
return msgLen;
return TSDB_CODE_SUCCESS;
} }
int tscBuildKillQueryMsg(SSqlObj *pSql) { int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SKillQuery *pKill; SKillQuery *pKill;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd *pCmd = &pSql->cmd; 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 = (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; 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 = pMsg - pStart;
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_KILL_CONNECTION;
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); SSqlCmd *pCmd = &(pSql->cmd);
int32_t size = minMsgSize() + sizeof(SMgmtHead) + sizeof(SCreateTableMsg); 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); size += sizeof(STagData);
} else { } else {
size += sizeof(SSchema) * (pCmd->numOfCols + pCmd->count); 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; return size + TSDB_EXTRA_PAYLOAD_SIZE;
} }
int tscBuildCreateTableMsg(SSqlObj *pSql) { int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateTableMsg *pCreateTableMsg; SCreateTableMsg *pCreateTableMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
SSchema * pSchema; SSchema * pSchema;
int size = 0; 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; SSqlCmd * pCmd = &pSql->cmd;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
// Reallocate the payload size // Reallocate the payload size
size = tscEstimateCreateTableMsgLength(pSql); size = tscEstimateCreateTableMsgLength(pSql, pInfo);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for create table msg", pSql); tscError("%p failed to malloc for create table msg", pSql);
free(tmpData); return TSDB_CODE_CLI_OUT_OF_MEMORY;
return -1;
} }
pMsg = pCmd->payload + tsRpcHeadSize; pMsg = pCmd->payload + tsRpcHeadSize;
pStart = pMsg; pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)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); tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db);
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
...@@ -2342,59 +2221,59 @@ int tscBuildCreateTableMsg(SSqlObj *pSql) { ...@@ -2342,59 +2221,59 @@ int tscBuildCreateTableMsg(SSqlObj *pSql) {
pCreateTableMsg = (SCreateTableMsg *)pMsg; pCreateTableMsg = (SCreateTableMsg *)pMsg;
strcpy(pCreateTableMsg->meterId, pMeterMetaInfo->name); 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->numOfColumns = htons(pCmd->numOfCols);
pCreateTableMsg->numOfTags = htons(pCmd->count); pCreateTableMsg->numOfTags = htons(pCmd->count);
pMsg = (char *)pCreateTableMsg->schema;
pCreateTableMsg->sqlLen = 0; pCreateTableMsg->sqlLen = 0;
short sqlLen = (short)(strlen(tmpData) + 1); pMsg = (char *)pCreateTableMsg->schema;
if (pCmd->numOfCols == 0 && pCmd->count == 0) { int8_t type = pInfo->pCreateTableInfo->type;
// create by using metric, tags value if (type == TSQL_CREATE_TABLE_FROM_STABLE) { // create by using super table, tags value
memcpy(pMsg, tmpData, sizeof(STagData)); memcpy(pMsg, &pInfo->pCreateTableInfo->usingInfo.tagdata, sizeof(STagData));
pMsg += sizeof(STagData); pMsg += sizeof(STagData);
} else { } else { // create (super) table
// create metric/create normal meter
pSchema = pCreateTableMsg->schema; pSchema = pCreateTableMsg->schema;
for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) { for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) {
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
pSchema->type = pField->type; pSchema->type = pField->type;
strcpy(pSchema->name, pField->name); strcpy(pSchema->name, pField->name);
pSchema->bytes = htons(pField->bytes); pSchema->bytes = htons(pField->bytes);
pSchema++; pSchema++;
} }
pMsg = (char *)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 strncpy(pMsg, pQuerySql->selectToken.z, pQuerySql->selectToken.n + 1);
if (sqlLen > 1) { pCreateTableMsg->sqlLen = htons(pQuerySql->selectToken.n + 1);
memcpy(pMsg, tmpData, sqlLen); pMsg += pQuerySql->selectToken.n + 1;
pMsg[sqlLen - 1] = 0;
pCreateTableMsg->sqlLen = htons(sqlLen);
pMsg += sqlLen;
} }
} }
tfree(tmpData); tscClearFieldInfo(&pCmd->pQueryInfo[0].fieldsInfo);
tscClearFieldInfo(&pCmd->fieldsInfo);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen; pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE; pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
assert(msgLen + minMsgSize() <= size); assert(msgLen + minMsgSize() <= size);
return msgLen; return TSDB_CODE_SUCCESS;
} }
int tscEstimateAlterTableMsgLength(SSqlCmd *pCmd) { 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; TSDB_EXTRA_PAYLOAD_SIZE;
} }
int tscBuildAlterTableMsg(SSqlObj *pSql) { int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SAlterTableMsg *pAlterTableMsg; SAlterTableMsg *pAlterTableMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -2403,10 +2282,6 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) { ...@@ -2403,10 +2282,6 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) {
SSqlCmd * pCmd = &pSql->cmd; SSqlCmd * pCmd = &pSql->cmd;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); 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); size = tscEstimateAlterTableMsgLength(pCmd);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for alter table msg", pSql); tscError("%p failed to malloc for alter table msg", pSql);
...@@ -2420,14 +2295,17 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) { ...@@ -2420,14 +2295,17 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) {
tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db); tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db);
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
SAlterTableSQL* pAlterInfo = pInfo->pAlterInfo;
pAlterTableMsg = (SAlterTableMsg *)pMsg; pAlterTableMsg = (SAlterTableMsg *)pMsg;
strcpy(pAlterTableMsg->meterId, pMeterMetaInfo->name); strcpy(pAlterTableMsg->meterId, pMeterMetaInfo->name);
pAlterTableMsg->type = htons(pCmd->count); pAlterTableMsg->type = htons(pAlterInfo->type);
pAlterTableMsg->numOfCols = htons(pCmd->numOfCols);
memcpy(pAlterTableMsg->tagVal, buf, TSDB_MAX_TAGS_LEN); pAlterTableMsg->numOfCols = htons(tscNumOfFields(pCmd));
memcpy(pAlterTableMsg->tagVal, pAlterInfo->tagData.data, TSDB_MAX_TAGS_LEN);
SSchema *pSchema = pAlterTableMsg->schema; 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); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
pSchema->type = pField->type; pSchema->type = pField->type;
...@@ -2443,10 +2321,11 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) { ...@@ -2443,10 +2321,11 @@ int tscBuildAlterTableMsg(SSqlObj *pSql) {
pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE; pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE;
assert(msgLen + minMsgSize() <= size); assert(msgLen + minMsgSize() <= size);
return msgLen;
return TSDB_CODE_SUCCESS;
} }
int tscAlterDbMsg(SSqlObj *pSql) { int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SAlterDbMsg *pAlterDbMsg; SAlterDbMsg *pAlterDbMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -2471,38 +2350,10 @@ int tscAlterDbMsg(SSqlObj *pSql) { ...@@ -2471,38 +2350,10 @@ int tscAlterDbMsg(SSqlObj *pSql) {
pCmd->payloadLen = msgLen; pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_ALTER_DB; pCmd->msgType = TSDB_MSG_TYPE_ALTER_DB;
return msgLen; return TSDB_CODE_SUCCESS;
}
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;
} }
int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql) { int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
char *pMsg, *pStart; char *pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -2524,17 +2375,17 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql) { ...@@ -2524,17 +2375,17 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
*((uint64_t *) pMsg) = pSql->res.qhandle; *((uint64_t *)pMsg) = pSql->res.qhandle;
pMsg += sizeof(pSql->res.qhandle); pMsg += sizeof(pSql->res.qhandle);
*((uint16_t*) pMsg) = htons(pCmd->type); *((uint16_t *)pMsg) = htons(pCmd->type);
pMsg += sizeof(pCmd->type); pMsg += sizeof(pCmd->type);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen; pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_RETRIEVE; pCmd->msgType = TSDB_MSG_TYPE_RETRIEVE;
return msgLen; return TSDB_CODE_SUCCESS;
} }
static int tscSetResultPointer(SSqlCmd *pCmd, SSqlRes *pRes) { static int tscSetResultPointer(SSqlCmd *pCmd, SSqlRes *pRes) {
...@@ -2542,7 +2393,7 @@ static int tscSetResultPointer(SSqlCmd *pCmd, SSqlRes *pRes) { ...@@ -2542,7 +2393,7 @@ static int tscSetResultPointer(SSqlCmd *pCmd, SSqlRes *pRes) {
return pRes->code; 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); TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, i);
int16_t offset = tscFieldInfoGetOffset(pCmd, i); int16_t offset = tscFieldInfoGetOffset(pCmd, i);
...@@ -2642,7 +2493,7 @@ int tscProcessRetrieveMetricRsp(SSqlObj *pSql) { ...@@ -2642,7 +2493,7 @@ int tscProcessRetrieveMetricRsp(SSqlObj *pSql) {
int tscProcessEmptyResultRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder(pSql, 0); } int tscProcessEmptyResultRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder(pSql, 0); }
int tscBuildConnectMsg(SSqlObj *pSql) { int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SConnectMsg *pConnect; SConnectMsg *pConnect;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -2670,7 +2521,7 @@ int tscBuildConnectMsg(SSqlObj *pSql) { ...@@ -2670,7 +2521,7 @@ int tscBuildConnectMsg(SSqlObj *pSql) {
return msgLen; return msgLen;
} }
int tscBuildMeterMetaMsg(SSqlObj *pSql) { int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SMeterInfoMsg *pInfoMsg; SMeterInfoMsg *pInfoMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
...@@ -2696,10 +2547,10 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql) { ...@@ -2696,10 +2547,10 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql) {
pInfoMsg = (SMeterInfoMsg *)pMsg; pInfoMsg = (SMeterInfoMsg *)pMsg;
strcpy(pInfoMsg->meterId, pMeterMetaInfo->name); 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); pMsg += sizeof(SMeterInfoMsg);
if (pCmd->defaultVal[0] != 0) { if (pCmd->pQueryInfo[0].defaultVal[0] != 0) {
memcpy(pInfoMsg->tags, tmpData, sizeof(STagData)); memcpy(pInfoMsg->tags, tmpData, sizeof(STagData));
pMsg += sizeof(STagData); pMsg += sizeof(STagData);
} }
...@@ -2719,7 +2570,7 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql) { ...@@ -2719,7 +2570,7 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql) {
* | SMgmtHead | SMultiMeterInfoMsg | meterId0 | meterId1 | meterId2 | ...... * | SMgmtHead | SMultiMeterInfoMsg | meterId0 | meterId1 | meterId2 | ......
* no used 4B * no used 4B
**/ **/
int tscBuildMultiMeterMetaMsg(SSqlObj *pSql) { int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
// copy payload content to temp buff // copy payload content to temp buff
...@@ -2759,31 +2610,31 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) { ...@@ -2759,31 +2610,31 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
minMsgSize() + sizeof(SMetricMetaMsg) + sizeof(SMgmtHead) + sizeof(int16_t) * TSDB_MAX_TAGS; minMsgSize() + sizeof(SMetricMetaMsg) + sizeof(SMgmtHead) + sizeof(int16_t) * TSDB_MAX_TAGS;
int32_t n = 0; int32_t n = 0;
for (int32_t i = 0; i < pCmd->tagCond.numOfTagCond; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo[0].tagCond.numOfTagCond; ++i) {
n += strlen(pCmd->tagCond.cond[i].cond); n += strlen(pCmd->pQueryInfo[0].tagCond.cond[i].cond);
} }
int32_t tagLen = n * TSDB_NCHAR_SIZE; int32_t tagLen = n * TSDB_NCHAR_SIZE;
if (pCmd->tagCond.tbnameCond.cond != NULL) { if (pCmd->pQueryInfo[0].tagCond.tbnameCond.cond != NULL) {
tagLen += strlen(pCmd->tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE; tagLen += strlen(pCmd->pQueryInfo[0].tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE;
} }
int32_t joinCondLen = (TSDB_METER_ID_LEN + sizeof(int16_t)) * 2; 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; int32_t len = tagLen + joinCondLen + elemSize + defaultSize;
return MAX(len, TSDB_DEFAULT_PAYLOAD_SIZE); return MAX(len, TSDB_DEFAULT_PAYLOAD_SIZE);
} }
int tscBuildMetricMetaMsg(SSqlObj *pSql) { int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SMetricMetaMsg *pMetaMsg; SMetricMetaMsg *pMetaMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
int tableIndex = 0; int tableIndex = 0;
SSqlCmd * pCmd = &pSql->cmd; SSqlCmd * pCmd = &pSql->cmd;
STagCond *pTagCond = &pCmd->tagCond; STagCond *pTagCond = &pCmd->pQueryInfo[0].tagCond;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, tableIndex); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, tableIndex);
...@@ -2802,7 +2653,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { ...@@ -2802,7 +2653,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
pMetaMsg = (SMetricMetaMsg *)pMsg; pMetaMsg = (SMetricMetaMsg *)pMsg;
pMetaMsg->numOfMeters = htonl(pCmd->numOfTables); pMetaMsg->numOfMeters = htonl(pCmd->pQueryInfo->numOfTables);
pMsg += sizeof(SMetricMetaMsg); pMsg += sizeof(SMetricMetaMsg);
...@@ -2824,7 +2675,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { ...@@ -2824,7 +2675,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
*(int16_t *)pMsg = pTagCond->joinInfo.right.tagCol; *(int16_t *)pMsg = pTagCond->joinInfo.right.tagCol;
pMsg += sizeof(int16_t); 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); pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i);
uint64_t uid = pMeterMetaInfo->pMeterMeta->uid; uint64_t uid = pMeterMetaInfo->pMeterMeta->uid;
...@@ -2840,7 +2691,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { ...@@ -2840,7 +2691,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
SCond *pCond = tsGetMetricQueryCondPos(pTagCond, uid); SCond *pCond = tsGetMetricQueryCondPos(pTagCond, uid);
if (pCond != NULL) { if (pCond != NULL) {
condLen = strlen(pCond->cond) + 1; condLen = strlen(pCond->cond) + 1;
bool ret = taosMbsToUcs4(pCond->cond, condLen, pMsg, condLen * TSDB_NCHAR_SIZE); bool ret = taosMbsToUcs4(pCond->cond, condLen, pMsg, condLen * TSDB_NCHAR_SIZE);
if (!ret) { if (!ret) {
tscError("%p mbs to ucs4 failed:%s", pSql, tsGetMetricQueryCondPos(pTagCond, uid)); tscError("%p mbs to ucs4 failed:%s", pSql, tsGetMetricQueryCondPos(pTagCond, uid));
...@@ -2860,7 +2711,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { ...@@ -2860,7 +2711,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
offset = pMsg - (char *)pMetaMsg; offset = pMsg - (char *)pMetaMsg;
pElem->tableCond = htonl(offset); pElem->tableCond = htonl(offset);
uint32_t len = strlen(pTagCond->tbnameCond.cond); uint32_t len = strlen(pTagCond->tbnameCond.cond);
pElem->tableCondLen = htonl(len); pElem->tableCondLen = htonl(len);
...@@ -2868,7 +2719,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { ...@@ -2868,7 +2719,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
pMsg += len; pMsg += len;
} }
SSqlGroupbyExpr *pGroupby = &pCmd->groupbyExpr; SSqlGroupbyExpr *pGroupby = &pCmd->pQueryInfo[0].groupbyExpr;
if (pGroupby->tableIndex != i && pGroupby->numOfGroupCols > 0) { if (pGroupby->tableIndex != i && pGroupby->numOfGroupCols > 0) {
pElem->orderType = 0; pElem->orderType = 0;
...@@ -2886,15 +2737,15 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) { ...@@ -2886,15 +2737,15 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
offset = pMsg - (char *)pMetaMsg; offset = pMsg - (char *)pMetaMsg;
pElem->groupbyTagColumnList = htonl(offset); pElem->groupbyTagColumnList = htonl(offset);
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { for (int32_t j = 0; j < pCmd->pQueryInfo[0].groupbyExpr.numOfGroupCols; ++j) {
SColIndexEx *pCol = &pCmd->groupbyExpr.columnInfo[j]; SColIndexEx *pCol = &pCmd->pQueryInfo[0].groupbyExpr.columnInfo[j];
SColIndexEx* pDestCol = (SColIndexEx*) pMsg; SColIndexEx *pDestCol = (SColIndexEx *)pMsg;
pDestCol->colIdxInBuf = 0; pDestCol->colIdxInBuf = 0;
pDestCol->colIdx = htons(pCol->colIdx); pDestCol->colIdx = htons(pCol->colIdx);
pDestCol->colId = htons(pDestCol->colId); pDestCol->colId = htons(pDestCol->colId);
pDestCol->flag = htons(pDestCol->flag); pDestCol->flag = htons(pDestCol->flag);
pMsg += sizeof(SColIndexEx); pMsg += sizeof(SColIndexEx);
} }
} }
...@@ -2937,7 +2788,7 @@ int tscEstimateHeartBeatMsgLength(SSqlObj *pSql) { ...@@ -2937,7 +2788,7 @@ int tscEstimateHeartBeatMsgLength(SSqlObj *pSql) {
return size + TSDB_EXTRA_PAYLOAD_SIZE; return size + TSDB_EXTRA_PAYLOAD_SIZE;
} }
int tscBuildHeartBeatMsg(SSqlObj *pSql) { int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
char *pMsg, *pStart; char *pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
int size = 0; int size = 0;
...@@ -3268,10 +3119,10 @@ int tscProcessMetricMetaRsp(SSqlObj *pSql) { ...@@ -3268,10 +3119,10 @@ int tscProcessMetricMetaRsp(SSqlObj *pSql) {
for (int32_t j = 0; j < pSidLists->numOfSids; ++j) { for (int32_t j = 0; j < pSidLists->numOfSids; ++j) {
pLists->pSidExtInfoList[j] = pBuf - (char *)pLists; pLists->pSidExtInfoList[j] = pBuf - (char *)pLists;
memcpy(pBuf, rsp, elemSize); memcpy(pBuf, rsp, elemSize);
((SMeterSidExtInfo*) pBuf)->uid = htobe64(((SMeterSidExtInfo*) pBuf)->uid); ((SMeterSidExtInfo *)pBuf)->uid = htobe64(((SMeterSidExtInfo *)pBuf)->uid);
((SMeterSidExtInfo*) pBuf)->sid = htonl(((SMeterSidExtInfo*) pBuf)->sid); ((SMeterSidExtInfo *)pBuf)->sid = htonl(((SMeterSidExtInfo *)pBuf)->sid);
rsp += elemSize; rsp += elemSize;
pBuf += elemSize; pBuf += elemSize;
} }
...@@ -3344,7 +3195,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { ...@@ -3344,7 +3195,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
pSchema++; pSchema++;
} }
key[0] = pCmd->showType + 'a'; key[0] = pCmd->msgType + 'a';
strcpy(key + 1, "showlist"); strcpy(key + 1, "showlist");
taosRemoveDataFromCache(tscCacheHandle, (void *)&(pMeterMetaInfo->pMeterMeta), false); taosRemoveDataFromCache(tscCacheHandle, (void *)&(pMeterMetaInfo->pMeterMeta), false);
...@@ -3352,16 +3203,16 @@ int tscProcessShowRsp(SSqlObj *pSql) { ...@@ -3352,16 +3203,16 @@ int tscProcessShowRsp(SSqlObj *pSql) {
int32_t size = pMeta->numOfColumns * sizeof(SSchema) + sizeof(SMeterMeta); int32_t size = pMeta->numOfColumns * sizeof(SSchema) + sizeof(SMeterMeta);
pMeterMetaInfo->pMeterMeta = pMeterMetaInfo->pMeterMeta =
(SMeterMeta *)taosAddDataIntoCache(tscCacheHandle, key, (char *)pMeta, size, tsMeterMetaKeepTimer); (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); SSchema *pMeterSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
tscColumnBaseInfoReserve(&pCmd->colList, pMeta->numOfColumns); tscColumnBaseInfoReserve(&pCmd->pQueryInfo[0].colList, pMeta->numOfColumns);
SColumnIndex index = {0}; SColumnIndex index = {0};
for (int16_t i = 0; i < pMeta->numOfColumns; ++i) { for (int16_t i = 0; i < pMeta->numOfColumns; ++i) {
index.columnIndex = i; index.columnIndex = i;
tscColumnBaseInfoInsert(pCmd, &index); tscColumnBaseInfoInsert(pCmd, &index);
tscFieldInfoSetValFromSchema(&pCmd->fieldsInfo, i, &pMeterSchema[i]); tscFieldInfoSetValFromSchema(&pCmd->pQueryInfo[0].fieldsInfo, i, &pMeterSchema[i]);
} }
tscFieldInfoCalOffset(pCmd); tscFieldInfoCalOffset(pCmd);
...@@ -3369,7 +3220,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { ...@@ -3369,7 +3220,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
} }
int tscProcessConnectRsp(SSqlObj *pSql) { int tscProcessConnectRsp(SSqlObj *pSql) {
char temp[TSDB_METER_ID_LEN*2]; char temp[TSDB_METER_ID_LEN * 2];
SConnectRsp *pConnect; SConnectRsp *pConnect;
STscObj *pObj = pSql->pTscObj; STscObj *pObj = pSql->pTscObj;
...@@ -3377,14 +3228,14 @@ int tscProcessConnectRsp(SSqlObj *pSql) { ...@@ -3377,14 +3228,14 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
pConnect = (SConnectRsp *)pRes->pRsp; pConnect = (SConnectRsp *)pRes->pRsp;
strcpy(pObj->acctId, pConnect->acctId); // copy acctId from response 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)); assert(len <= tListLen(pObj->db));
strncpy(pObj->db, temp, tListLen(pObj->db)); strncpy(pObj->db, temp, tListLen(pObj->db));
#ifdef CLUSTER #ifdef CLUSTER
SIpList * pIpList; SIpList *pIpList;
char *rsp = pRes->pRsp + sizeof(SConnectRsp); char * rsp = pRes->pRsp + sizeof(SConnectRsp);
pIpList = (SIpList *)rsp; pIpList = (SIpList *)rsp;
tscMgmtIpList.numOfIps = pIpList->numOfIps; tscMgmtIpList.numOfIps = pIpList->numOfIps;
for (int i = 0; i < pIpList->numOfIps; ++i) { for (int i = 0; i < pIpList->numOfIps; ++i) {
...@@ -3456,12 +3307,12 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) { ...@@ -3456,12 +3307,12 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) {
taosRemoveDataFromCache(tscCacheHandle, (void **)&pMeterMeta, true); taosRemoveDataFromCache(tscCacheHandle, (void **)&pMeterMeta, true);
if (pMeterMetaInfo->pMeterMeta) { 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->pMeterMeta), true);
taosRemoveDataFromCache(tscCacheHandle, (void **)&(pMeterMetaInfo->pMetricMeta), 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); tscTrace("%p reset query cache since table:%s is stable", pSql, pMeterMetaInfo->name);
taosClearDataCache(tscCacheHandle); taosClearDataCache(tscCacheHandle);
} }
...@@ -3546,10 +3397,14 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { ...@@ -3546,10 +3397,14 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
pNew->cmd.payload = NULL; pNew->cmd.payload = NULL;
pNew->cmd.allocSize = 0; 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)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
tscError("%p malloc failed for payload to get meter meta", pSql); tscError("%p malloc failed for payload to get meter meta", pSql);
free(pNew); free(pNew);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_CLI_OUT_OF_MEMORY;
} }
...@@ -3589,7 +3444,8 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { ...@@ -3589,7 +3444,8 @@ static int32_t tscDoGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
} }
int tscGetMeterMeta(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); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index);
// if the SSqlCmd owns a metermeta, release it first // if the SSqlCmd owns a metermeta, release it first
...@@ -3609,7 +3465,7 @@ int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { ...@@ -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 * 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 * 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); // tscFreeSqlCmdData(pCmd);
//} //}
...@@ -3617,7 +3473,7 @@ int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) { ...@@ -3617,7 +3473,7 @@ int tscGetMeterMeta(SSqlObj *pSql, char *meterId, int32_t index) {
} }
int tscGetMeterMetaEx(SSqlObj *pSql, char *meterId, bool createIfNotExists) { 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); return tscGetMeterMeta(pSql, meterId, 0);
} }
...@@ -3686,7 +3542,7 @@ int tscGetMetricMeta(SSqlObj *pSql) { ...@@ -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. * the vnode query condition is serialized into pCmd->payload, we need to rebuild key for metricmeta info in cache.
*/ */
bool reqMetricMeta = false; 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}; char tagstr[TSDB_MAX_TAGS_LEN + 1] = {0};
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i);
...@@ -3714,7 +3570,7 @@ int tscGetMetricMeta(SSqlObj *pSql) { ...@@ -3714,7 +3570,7 @@ int tscGetMetricMeta(SSqlObj *pSql) {
pNew->cmd.command = TSDB_SQL_METRIC; 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); SMeterMetaInfo *pMMInfo = tscGetMeterMetaInfo(&pSql->cmd, i);
SMeterMeta *pMeterMeta = taosGetDataFromCache(tscCacheHandle, pMMInfo->name); SMeterMeta *pMeterMeta = taosGetDataFromCache(tscCacheHandle, pMMInfo->name);
...@@ -3727,12 +3583,12 @@ int tscGetMetricMeta(SSqlObj *pSql) { ...@@ -3727,12 +3583,12 @@ int tscGetMetricMeta(SSqlObj *pSql) {
} }
// the query condition on meter is serialized into payload // 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.pQueryInfo[0].groupbyExpr = pSql->cmd.pQueryInfo[0].groupbyExpr;
pNew->cmd.numOfTables = pSql->cmd.numOfTables; 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; pNew->cmd.order = pSql->cmd.order;
if (pSql->fp != NULL && pSql->pStream == NULL) { if (pSql->fp != NULL && pSql->pStream == NULL) {
...@@ -3746,7 +3602,7 @@ int tscGetMetricMeta(SSqlObj *pSql) { ...@@ -3746,7 +3602,7 @@ int tscGetMetricMeta(SSqlObj *pSql) {
code = tscProcessSql(pNew); 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}; char tagstr[TSDB_MAX_TAGS_LEN] = {0};
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i);
...@@ -3779,17 +3635,17 @@ void tscInitMsgs() { ...@@ -3779,17 +3635,17 @@ void tscInitMsgs() {
tscBuildMsg[TSDB_SQL_FETCH] = tscBuildRetrieveMsg; tscBuildMsg[TSDB_SQL_FETCH] = tscBuildRetrieveMsg;
tscBuildMsg[TSDB_SQL_CREATE_DB] = tscBuildCreateDbMsg; 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_CREATE_ACCT] = tscBuildAcctMsg;
tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAlterAcctMsg; tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAcctMsg;
tscBuildMsg[TSDB_SQL_CREATE_TABLE] = tscBuildCreateTableMsg; 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_ACCT] = tscBuildDropAcctMsg;
tscBuildMsg[TSDB_SQL_DROP_DB] = tscBuildDropDbMsg; tscBuildMsg[TSDB_SQL_DROP_DB] = tscBuildDropDbMsg;
tscBuildMsg[TSDB_SQL_DROP_TABLE] = tscBuildDropTableMsg; 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_CREATE_DNODE] = tscBuildCreateDnodeMsg;
tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg; tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg;
tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg; tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg;
...@@ -3805,9 +3661,9 @@ void tscInitMsgs() { ...@@ -3805,9 +3661,9 @@ void tscInitMsgs() {
tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg; tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg;
tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg; tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg;
tscBuildMsg[TSDB_SQL_RETRIEVE] = tscBuildRetrieveFromMgmtMsg; tscBuildMsg[TSDB_SQL_RETRIEVE] = tscBuildRetrieveFromMgmtMsg;
tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillQueryMsg; tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillStreamMsg; tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillConnectionMsg; tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
tscProcessMsgRsp[TSDB_SQL_SELECT] = tscProcessQueryRsp; tscProcessMsgRsp[TSDB_SQL_SELECT] = tscProcessQueryRsp;
tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromVnode; tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromVnode;
...@@ -3821,16 +3677,16 @@ void tscInitMsgs() { ...@@ -3821,16 +3677,16 @@ void tscInitMsgs() {
tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiMeterMetaRsp; tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiMeterMetaRsp;
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; 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_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_METRIC] = tscProcessRetrieveMetricRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_METRIC] = tscProcessRetrieveMetricRsp;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "tsocket.h" #include "tsocket.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.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, 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) { void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) {
...@@ -207,7 +207,7 @@ int taos_query_imp(STscObj *pObj, SSqlObj *pSql) { ...@@ -207,7 +207,7 @@ int taos_query_imp(STscObj *pObj, SSqlObj *pSql) {
pRes->numOfTotal = 0; pRes->numOfTotal = 0;
pSql->asyncTblPos = NULL; pSql->asyncTblPos = NULL;
if (NULL != pSql->pTableHashList) { if (NULL != pSql->pTableHashList) {
taosCleanUpIntHash(pSql->pTableHashList); taosCleanUpHashTable(pSql->pTableHashList);
pSql->pTableHashList = NULL; pSql->pTableHashList = NULL;
} }
...@@ -298,7 +298,7 @@ int taos_num_fields(TAOS_RES *res) { ...@@ -298,7 +298,7 @@ int taos_num_fields(TAOS_RES *res) {
SSqlObj *pSql = (SSqlObj *)res; SSqlObj *pSql = (SSqlObj *)res;
if (pSql == NULL || pSql->signature != pSql) return 0; 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); return (pFieldsInfo->numOfOutputCols - pFieldsInfo->numOfHiddenCols);
} }
...@@ -321,7 +321,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { ...@@ -321,7 +321,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
SSqlObj *pSql = (SSqlObj *)res; SSqlObj *pSql = (SSqlObj *)res;
if (pSql == NULL || pSql->signature != pSql) return 0; 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) { int taos_retrieve(TAOS_RES *res) {
...@@ -370,7 +370,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -370,7 +370,7 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
pRes->numOfTotal += pRes->numOfRows; 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->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pCmd, i, pCmd->order) +
pRes->bytes[i] * (1 - pCmd->order.order) * (pRes->numOfRows - 1); pRes->bytes[i] * (1 - pCmd->order.order) * (pRes->numOfRows - 1);
} }
...@@ -386,11 +386,11 @@ static void **doSetResultRowData(SSqlObj *pSql) { ...@@ -386,11 +386,11 @@ static void **doSetResultRowData(SSqlObj *pSql) {
int32_t num = 0; 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; 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 // 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; continue;
} }
...@@ -419,7 +419,7 @@ static void **doSetResultRowData(SSqlObj *pSql) { ...@@ -419,7 +419,7 @@ static void **doSetResultRowData(SSqlObj *pSql) {
} }
} }
assert(num <= pCmd->fieldsInfo.numOfOutputCols); assert(num <= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols);
return pRes->tsrow; return pRes->tsrow;
} }
...@@ -445,7 +445,7 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) { ...@@ -445,7 +445,7 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd; SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd;
SMeterMetaInfo *pMetaInfo = tscGetMeterMetaInfo(pCmd1, 0); 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 * 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) { ...@@ -500,7 +500,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
} }
if (pRes->tsrow == NULL) { 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; bool success = false;
...@@ -526,7 +526,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) { ...@@ -526,7 +526,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
} }
if (success) { // current row of final output has been built, return to app 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 tableIndex = pRes->pColumnIndex[i].tableIndex;
int32_t columnIndex = pRes->pColumnIndex[i].columnIndex; int32_t columnIndex = pRes->pColumnIndex[i].columnIndex;
...@@ -611,8 +611,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { ...@@ -611,8 +611,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
* update the limit and offset value according to current retrieval results * update the limit and offset value according to current retrieval results
* Note: if pRes->offset > 0, pRes->numOfRows = 0, pRes->numOfTotal = 0; * Note: if pRes->offset > 0, pRes->numOfRows = 0, pRes->numOfTotal = 0;
*/ */
pCmd->limit.limit = pCmd->globalLimit - pRes->numOfTotal; pCmd->pQueryInfo->limit.limit = pCmd->globalLimit - pRes->numOfTotal;
pCmd->limit.offset = pRes->offset; pCmd->pQueryInfo->limit.offset = pRes->offset;
assert((pRes->offset >= 0 && pRes->numOfRows == 0) || (pRes->offset == 0 && pRes->numOfRows >= 0)); 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) { ...@@ -665,8 +665,8 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
/* update the limit value according to current retrieval results */ /* update the limit value according to current retrieval results */
pCmd->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal; pCmd->pQueryInfo->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal;
pCmd->limit.offset = pRes->offset; pCmd->pQueryInfo->limit.offset = pRes->offset;
if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
pSql->cmd.command = TSDB_SQL_SELECT; pSql->cmd.command = TSDB_SQL_SELECT;
...@@ -956,7 +956,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { ...@@ -956,7 +956,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
pSql->asyncTblPos = NULL; pSql->asyncTblPos = NULL;
if (NULL != pSql->pTableHashList) { if (NULL != pSql->pTableHashList) {
taosCleanUpIntHash(pSql->pTableHashList); taosCleanUpHashTable(pSql->pTableHashList);
pSql->pTableHashList = NULL; pSql->pTableHashList = NULL;
} }
......
...@@ -32,7 +32,7 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql); ...@@ -32,7 +32,7 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql);
static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer); static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer);
static bool isProjectStream(SSqlCmd *pCmd) { 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); SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId != TSDB_FUNC_PRJ) { if (pExpr->functionId != TSDB_FUNC_PRJ) {
return false; return false;
...@@ -109,18 +109,18 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) { ...@@ -109,18 +109,18 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
if (isProjectStream(&pSql->cmd)) { 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. * 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 pSql->cmd.pQueryInfo[0].etime = taosGetTimestamp(pStream->precision); // end time
if (pSql->cmd.etime > pStream->etime) { if (pSql->cmd.pQueryInfo[0].etime > pStream->etime) {
pSql->cmd.etime = pStream->etime; pSql->cmd.pQueryInfo[0].etime = pStream->etime;
} }
} else { } else {
pSql->cmd.stime = pStream->stime - pStream->interval; pSql->cmd.pQueryInfo[0].stime = pStream->stime - pStream->interval;
pSql->cmd.etime = pStream->stime - 1; pSql->cmd.pQueryInfo[0].etime = pStream->stime - 1;
} }
// launch stream computing in a new thread // launch stream computing in a new thread
...@@ -198,7 +198,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf ...@@ -198,7 +198,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
pStream->useconds += pSql->res.useconds; pStream->useconds += pSql->res.useconds;
if (pStream->numOfRes == 0) { 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; SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
...@@ -210,11 +210,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf ...@@ -210,11 +210,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
void *oldPtr = pSql->res.data; void *oldPtr = pSql->res.data;
pSql->res.data = tmpRes; 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); int16_t offset = tscFieldInfoGetOffset(pCmd, i);
TAOS_FIELD *pField = tscFieldInfoGetField(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; row[i] = pSql->res.data + offset;
} }
...@@ -222,7 +222,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf ...@@ -222,7 +222,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
row[0] = pRes->data; row[0] = pRes->data;
// char result[512] = {0}; // 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); // tscPrint("%p stream:%p query result: %s", pSql, pStream, result);
tscTrace("%p stream:%p fetch result", pSql, pStream); tscTrace("%p stream:%p fetch result", pSql, pStream);
...@@ -352,36 +352,36 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) { ...@@ -352,36 +352,36 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
int64_t minIntervalTime = int64_t minIntervalTime =
(pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinIntervalTime * 1000L : tsMinIntervalTime; (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, tscWarn("%p stream:%p, original sample interval:%ld too small, reset to:%" PRId64 "", pSql, pStream,
pCmd->nAggTimeInterval, minIntervalTime); pCmd->pQueryInfo[0].nAggTimeInterval, minIntervalTime);
pCmd->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) { if (pCmd->pQueryInfo[0].nSlidingTime == 0) {
pCmd->nSlidingTime = pCmd->nAggTimeInterval; pCmd->pQueryInfo[0].nSlidingTime = pCmd->pQueryInfo[0].nAggTimeInterval;
} }
int64_t minSlidingTime = int64_t minSlidingTime =
(pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinSlidingTime * 1000L : tsMinSlidingTime; (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinSlidingTime * 1000L : tsMinSlidingTime;
if (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->nSlidingTime, tscWarn("%p stream:%p, original sliding value:%" PRId64 " too small, reset to:%" PRId64 "", pSql, pStream,
minSlidingTime); 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, 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) { static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, int64_t stime) {
...@@ -393,10 +393,10 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in ...@@ -393,10 +393,10 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
pStream->slidingTime = tsProjectExecInterval; pStream->slidingTime = tsProjectExecInterval;
if (stime != 0) { // first projection start from the latest event timestamp 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 stime += 1; // exclude the last records from table
} else { } else {
stime = pCmd->stime; stime = pCmd->pQueryInfo[0].stime;
} }
} else { // timewindow based aggregation stream } else { // timewindow based aggregation stream
if (stime == 0) { // no data in meter till now 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 ...@@ -529,7 +529,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
pStream->precision = pMeterMetaInfo->pMeterMeta->precision; pStream->precision = pMeterMetaInfo->pMeterMeta->precision;
pStream->ctime = taosGetTimestamp(pStream->precision); pStream->ctime = taosGetTimestamp(pStream->precision);
pStream->etime = pCmd->etime; pStream->etime = pCmd->pQueryInfo[0].etime;
pSql->pStream = pStream; pSql->pStream = pStream;
tscAddIntoStreamList(pStream); tscAddIntoStreamList(pStream);
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tscUtil.h"
#include "hash.h"
#include "os.h" #include "os.h"
#include "ihash.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tcache.h" #include "tcache.h"
#include "tkey.h" #include "tkey.h"
...@@ -23,7 +24,6 @@ ...@@ -23,7 +24,6 @@
#include "tscProfile.h" #include "tscProfile.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tscUtil.h"
#include "tsclient.h" #include "tsclient.h"
#include "tsqldef.h" #include "tsqldef.h"
#include "ttimer.h" #include "ttimer.h"
...@@ -47,7 +47,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) { ...@@ -47,7 +47,7 @@ void tscGetMetricMetaCacheKey(SSqlCmd* pCmd, char* str, uint64_t uid) {
len += sprintf(&tagIdBuf[len], "%d,", pMeterMetaInfo->tagColumnIndex[i]); len += sprintf(&tagIdBuf[len], "%d,", pMeterMetaInfo->tagColumnIndex[i]);
} }
STagCond* pTagCond = &pCmd->tagCond; STagCond* pTagCond = &pCmd->pQueryInfo[0].tagCond;
assert(len < tListLen(tagIdBuf)); assert(len < tListLen(tagIdBuf));
const int32_t maxKeySize = TSDB_MAX_TAGS_LEN; // allowed max key size 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) { ...@@ -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, 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), (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); assert(keyLen <= bufSize);
...@@ -120,7 +120,7 @@ bool tscQueryOnMetric(SSqlCmd* pCmd) { ...@@ -120,7 +120,7 @@ bool tscQueryOnMetric(SSqlCmd* pCmd) {
} }
bool tscQueryMetricTags(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) { if (tscSqlExprGet(pCmd, i)->functionId != TSDB_FUNC_TAGPRJ) {
return false; return false;
} }
...@@ -133,7 +133,7 @@ bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd) { ...@@ -133,7 +133,7 @@ bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd) {
bool hasTags = false; bool hasTags = false;
int32_t numOfSelectivity = 0; 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; int32_t functId = tscSqlExprGet(pCmd, i)->functionId;
if (functId == TSDB_FUNC_TAG_DUMMY) { if (functId == TSDB_FUNC_TAG_DUMMY) {
hasTags = true; hasTags = true;
...@@ -232,7 +232,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) { ...@@ -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 * 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) || 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; return false;
} }
...@@ -242,7 +242,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) { ...@@ -242,7 +242,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) {
} }
// for project query, only the following two function is allowed // 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; int32_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG &&
functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM) { functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM) {
...@@ -254,7 +254,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) { ...@@ -254,7 +254,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) {
} }
bool tscProjectionQueryOnTable(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; int32_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TS) { if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TS) {
return false; return false;
...@@ -265,7 +265,7 @@ bool tscProjectionQueryOnTable(SSqlCmd* pCmd) { ...@@ -265,7 +265,7 @@ bool tscProjectionQueryOnTable(SSqlCmd* pCmd) {
} }
bool tscIsPointInterpQuery(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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr == NULL) { if (pExpr == NULL) {
return false; return false;
...@@ -284,7 +284,7 @@ bool tscIsPointInterpQuery(SSqlCmd* pCmd) { ...@@ -284,7 +284,7 @@ bool tscIsPointInterpQuery(SSqlCmd* pCmd) {
} }
bool tscIsTWAQuery(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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr == NULL) { if (pExpr == NULL) {
continue; continue;
...@@ -304,8 +304,8 @@ void tscClearInterpInfo(SSqlCmd* pCmd) { ...@@ -304,8 +304,8 @@ void tscClearInterpInfo(SSqlCmd* pCmd) {
return; return;
} }
pCmd->interpoType = TSDB_INTERPO_NONE; pCmd->pQueryInfo[0].interpoType = TSDB_INTERPO_NONE;
memset(pCmd->defaultVal, 0, sizeof(pCmd->defaultVal)); memset(pCmd->pQueryInfo[0].defaultVal, 0, sizeof(pCmd->pQueryInfo[0].defaultVal));
} }
void tscClearSqlMetaInfoForce(SSqlCmd* pCmd) { void tscClearSqlMetaInfoForce(SSqlCmd* pCmd) {
...@@ -319,7 +319,7 @@ void tscClearSqlMetaInfoForce(SSqlCmd* pCmd) { ...@@ -319,7 +319,7 @@ void tscClearSqlMetaInfoForce(SSqlCmd* pCmd) {
int32_t tscCreateResPointerInfo(SSqlCmd* pCmd, SSqlRes* pRes) { int32_t tscCreateResPointerInfo(SSqlCmd* pCmd, SSqlRes* pRes) {
if (pRes->tsrow == NULL) { if (pRes->tsrow == NULL) {
pRes->numOfnchar = 0; 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) { for (int32_t i = 0; i < numOfOutputCols; ++i) {
TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, i); TAOS_FIELD* pField = tscFieldInfoGetField(pCmd, i);
...@@ -361,18 +361,22 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) { ...@@ -361,18 +361,22 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) {
void tscFreeSqlCmdData(SSqlCmd* pCmd) { void tscFreeSqlCmdData(SSqlCmd* pCmd) {
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
tscTagCondRelease(&pCmd->tagCond); if (pCmd->pQueryInfo == NULL) {
tscClearFieldInfo(&pCmd->fieldsInfo); return;
}
tscTagCondRelease(&pCmd->pQueryInfo[0].tagCond);
tscClearFieldInfo(&pCmd->pQueryInfo[0].fieldsInfo);
tfree(pCmd->exprsInfo.pExprs); tfree(pCmd->pQueryInfo[0].exprsInfo.pExprs);
memset(&pCmd->exprsInfo, 0, sizeof(pCmd->exprsInfo)); memset(&pCmd->pQueryInfo[0].exprsInfo, 0, sizeof(pCmd->pQueryInfo[0].exprsInfo));
tscColumnBaseInfoDestroy(&pCmd->colList); tscColumnBaseInfoDestroy(&pCmd->pQueryInfo[0].colList);
memset(&pCmd->colList, 0, sizeof(pCmd->colList)); memset(&pCmd->pQueryInfo[0].colList, 0, sizeof(pCmd->pQueryInfo[0].colList));
if (pCmd->tsBuf != NULL) { if (pCmd->pQueryInfo[0].tsBuf != NULL) {
tsBufDestory(pCmd->tsBuf); tsBufDestory(pCmd->pQueryInfo[0].tsBuf);
pCmd->tsBuf = NULL; pCmd->pQueryInfo[0].tsBuf = NULL;
} }
} }
...@@ -392,7 +396,7 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) { ...@@ -392,7 +396,7 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) {
tscRemoveFromSqlList(pSql); tscRemoveFromSqlList(pSql);
} }
pCmd->command = -1; pCmd->command = 0;
// pSql->sqlstr will be used by tscBuildQueryStreamDesc // pSql->sqlstr will be used by tscBuildQueryStreamDesc
pthread_mutex_lock(&pObj->mutex); pthread_mutex_lock(&pObj->mutex);
...@@ -434,7 +438,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { ...@@ -434,7 +438,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
pCmd->allocSize = 0; pCmd->allocSize = 0;
if (pSql->res.buffer != NULL) { 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) { if (pSql->res.buffer[i] != NULL) {
tfree(pSql->res.buffer[i]); tfree(pSql->res.buffer[i]);
} }
...@@ -614,7 +618,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff ...@@ -614,7 +618,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
*/ */
dataBuf->pMeterMeta = taosGetDataFromCache(tscCacheHandle, dataBuf->meterId); dataBuf->pMeterMeta = taosGetDataFromCache(tscCacheHandle, dataBuf->meterId);
assert(initialSize > 0); assert(initialSize > 0);
if (dataBuf->pMeterMeta == NULL) { if (dataBuf->pMeterMeta == NULL) {
tfree(dataBuf); tfree(dataBuf);
return TSDB_CODE_QUERY_CACHE_ERASED; return TSDB_CODE_QUERY_CACHE_ERASED;
...@@ -629,18 +633,18 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, ...@@ -629,18 +633,18 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
STableDataBlocks** dataBlocks) { STableDataBlocks** dataBlocks) {
*dataBlocks = NULL; *dataBlocks = NULL;
STableDataBlocks** t1 = (STableDataBlocks**) taosGetIntHashData(pHashList, id); STableDataBlocks** t1 = (STableDataBlocks**)taosGetDataFromHash(pHashList, (const char*)&id, sizeof(id));
if (t1 != NULL) { if (t1 != NULL) {
*dataBlocks = *t1; *dataBlocks = *t1;
} }
if (*dataBlocks == NULL) { 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) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
*dataBlocks = *(STableDataBlocks**)taosAddIntHash(pHashList, id, (char*)dataBlocks); taosAddToHashTable(pHashList, (const char*)&id, sizeof(int64_t), (char*)dataBlocks, POINTER_BYTES);
tscAppendDataBlock(pDataBlockList, *dataBlocks); tscAppendDataBlock(pDataBlockList, *dataBlocks);
} }
...@@ -650,19 +654,19 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, ...@@ -650,19 +654,19 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockList) { int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockList) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
void* pVnodeDataBlockHashList = taosInitIntHash(8, POINTER_BYTES, taosHashInt); void* pVnodeDataBlockHashList = taosInitHashTable(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false);
SDataBlockList* pVnodeDataBlockList = tscCreateBlockArrayList(); SDataBlockList* pVnodeDataBlockList = tscCreateBlockArrayList();
for (int32_t i = 0; i < pTableDataBlockList->nSize; ++i) { for (int32_t i = 0; i < pTableDataBlockList->nSize; ++i) {
STableDataBlocks* pOneTableBlock = pTableDataBlockList->pData[i]; STableDataBlocks* pOneTableBlock = pTableDataBlockList->pData[i];
STableDataBlocks* dataBuf = NULL; STableDataBlocks* dataBuf = NULL;
int32_t ret = tscGetDataBlockFromList(pVnodeDataBlockHashList, pVnodeDataBlockList, pOneTableBlock->vgid, int32_t ret = tscGetDataBlockFromList(pVnodeDataBlockHashList, pVnodeDataBlockList, pOneTableBlock->vgid,
TSDB_PAYLOAD_SIZE, tsInsertHeadSize, 0, pOneTableBlock->meterId, &dataBuf); TSDB_PAYLOAD_SIZE, tsInsertHeadSize, 0, pOneTableBlock->meterId, &dataBuf);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tscError("%p failed to allocate the data buffer block for merging table data", pSql); tscError("%p failed to allocate the data buffer block for merging table data", pSql);
tscDestroyBlockArrayList(pTableDataBlockList); tscDestroyBlockArrayList(pTableDataBlockList);
return ret; return ret;
} }
...@@ -679,7 +683,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi ...@@ -679,7 +683,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
} else { // failed to allocate memory, free already allocated memory and return error code } 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); tscError("%p failed to allocate memory for merging submit block, size:%d", pSql, dataBuf->nAllocSize);
taosCleanUpIntHash(pVnodeDataBlockHashList); taosCleanUpHashTable(pVnodeDataBlockHashList);
tfree(dataBuf->pData); tfree(dataBuf->pData);
tscDestroyBlockArrayList(pVnodeDataBlockList); tscDestroyBlockArrayList(pVnodeDataBlockList);
...@@ -710,7 +714,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi ...@@ -710,7 +714,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
pCmd->pDataBlocks = pVnodeDataBlockList; pCmd->pDataBlocks = pVnodeDataBlockList;
tscFreeUnusedDataBlocks(pCmd->pDataBlocks); tscFreeUnusedDataBlocks(pCmd->pDataBlocks);
taosCleanUpIntHash(pVnodeDataBlockHashList); taosCleanUpHashTable(pVnodeDataBlockHashList);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -729,9 +733,14 @@ void tscCloseTscObj(STscObj* pObj) { ...@@ -729,9 +733,14 @@ void tscCloseTscObj(STscObj* pObj) {
} }
bool tscIsInsertOrImportData(char* sqlstr) { bool tscIsInsertOrImportData(char* sqlstr) {
int32_t index = 0; int32_t index = 0;
SSQLToken t0 = tStrGetToken(sqlstr, &index, false, 0, NULL);
return t0.type == TK_INSERT || t0.type == TK_IMPORT; 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) { int tscAllocPayload(SSqlCmd* pCmd, int size) {
...@@ -848,7 +857,7 @@ void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, co ...@@ -848,7 +857,7 @@ void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, co
} }
void tscFieldInfoCalOffset(SSqlCmd* pCmd) { void tscFieldInfoCalOffset(SSqlCmd* pCmd) {
SFieldInfo* pFieldInfo = &pCmd->fieldsInfo; SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo;
pFieldInfo->pOffset[0] = 0; pFieldInfo->pOffset[0] = 0;
for (int32_t i = 1; i < pFieldInfo->numOfOutputCols; ++i) { for (int32_t i = 1; i < pFieldInfo->numOfOutputCols; ++i) {
...@@ -857,7 +866,7 @@ void tscFieldInfoCalOffset(SSqlCmd* pCmd) { ...@@ -857,7 +866,7 @@ void tscFieldInfoCalOffset(SSqlCmd* pCmd) {
} }
void tscFieldInfoUpdateOffset(SSqlCmd* pCmd) { void tscFieldInfoUpdateOffset(SSqlCmd* pCmd) {
SFieldInfo* pFieldInfo = &pCmd->fieldsInfo; SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo;
if (pFieldInfo->numOfOutputCols == 0) { if (pFieldInfo->numOfOutputCols == 0) {
return; return;
} }
...@@ -902,23 +911,27 @@ void tscFieldInfoCopyAll(SFieldInfo* src, SFieldInfo* dst) { ...@@ -902,23 +911,27 @@ void tscFieldInfoCopyAll(SFieldInfo* src, SFieldInfo* dst) {
} }
TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index) { TAOS_FIELD* tscFieldInfoGetField(SSqlCmd* pCmd, int32_t index) {
if (index >= pCmd->fieldsInfo.numOfOutputCols) { if (index >= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) {
return NULL; 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) { int16_t tscFieldInfoGetOffset(SSqlCmd* pCmd, int32_t index) {
if (index >= pCmd->fieldsInfo.numOfOutputCols) { if (index >= pCmd->pQueryInfo[0].fieldsInfo.numOfOutputCols) {
return 0; return 0;
} }
return pCmd->fieldsInfo.pOffset[index]; return pCmd->pQueryInfo[0].fieldsInfo.pOffset[index];
} }
int32_t tscGetResRowLength(SSqlCmd* pCmd) { int32_t tscGetResRowLength(SSqlCmd* pCmd) {
SFieldInfo* pFieldInfo = &pCmd->fieldsInfo; SFieldInfo* pFieldInfo = &pCmd->pQueryInfo[0].fieldsInfo;
if (pFieldInfo->numOfOutputCols <= 0) { if (pFieldInfo->numOfOutputCols <= 0) {
return 0; return 0;
} }
...@@ -969,7 +982,7 @@ static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) { ...@@ -969,7 +982,7 @@ static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) {
} }
SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId) { 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); _exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1);
_exprEvic(pExprInfo, index); _exprEvic(pExprInfo, index);
...@@ -985,7 +998,7 @@ SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SCo ...@@ -985,7 +998,7 @@ SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SCo
int16_t size, int16_t interSize) { int16_t size, int16_t interSize) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pColIndex->tableIndex); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pColIndex->tableIndex);
SSqlExprInfo* pExprInfo = &pCmd->exprsInfo; SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo;
_exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1); _exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1);
_exprEvic(pExprInfo, index); _exprEvic(pExprInfo, index);
...@@ -1028,7 +1041,7 @@ SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SCo ...@@ -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, SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
int16_t size) { int16_t size) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
SSqlExprInfo* pExprInfo = &pCmd->exprsInfo; SSqlExprInfo* pExprInfo = &pCmd->pQueryInfo[0].exprsInfo;
if (index > pExprInfo->numOfExprs) { if (index > pExprInfo->numOfExprs) {
return NULL; return NULL;
} }
...@@ -1060,11 +1073,11 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, ...@@ -1060,11 +1073,11 @@ void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes,
} }
SSqlExpr* tscSqlExprGet(SSqlCmd* pCmd, int32_t index) { SSqlExpr* tscSqlExprGet(SSqlCmd* pCmd, int32_t index) {
if (pCmd->exprsInfo.numOfExprs <= index) { if (pCmd->pQueryInfo[0].exprsInfo.numOfExprs <= index) {
return NULL; return NULL;
} }
return &pCmd->exprsInfo.pExprs[index]; return &pCmd->pQueryInfo[0].exprsInfo.pExprs[index];
} }
void tscSqlExprCopy(SSqlExprInfo* dst, const SSqlExprInfo* src, uint64_t tableuid) { void tscSqlExprCopy(SSqlExprInfo* dst, const SSqlExprInfo* src, uint64_t tableuid) {
...@@ -1144,7 +1157,7 @@ void tscColumnBaseInfoUpdateTableIndex(SColumnBaseInfo* pColList, int16_t tableI ...@@ -1144,7 +1157,7 @@ void tscColumnBaseInfoUpdateTableIndex(SColumnBaseInfo* pColList, int16_t tableI
// todo refactor // todo refactor
SColumnBase* tscColumnBaseInfoInsert(SSqlCmd* pCmd, SColumnIndex* pColIndex) { 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 // ignore the tbname column to be inserted into source list
if (pColIndex->columnIndex < 0) { if (pColIndex->columnIndex < 0) {
...@@ -1448,7 +1461,7 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SSqlCmd* pCmd) { ...@@ -1448,7 +1461,7 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SSqlCmd* pCmd) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
pColInfo[i].functionId = pExpr->functionId; pColInfo[i].functionId = pExpr->functionId;
...@@ -1483,7 +1496,9 @@ bool tscShouldFreeHeatBeat(SSqlObj* pHb) { ...@@ -1483,7 +1496,9 @@ bool tscShouldFreeHeatBeat(SSqlObj* pHb) {
void tscCleanSqlCmd(SSqlCmd* pCmd) { void tscCleanSqlCmd(SSqlCmd* pCmd) {
tscFreeSqlCmdData(pCmd); tscFreeSqlCmdData(pCmd);
assert(pCmd->pMeterInfo == NULL); if (pCmd->pQueryInfo != NULL) {
assert(pCmd->pQueryInfo[0].pMeterInfo == NULL);
}
uint32_t allocSize = pCmd->allocSize; uint32_t allocSize = pCmd->allocSize;
char* allocPtr = pCmd->payload; char* allocPtr = pCmd->payload;
...@@ -1539,7 +1554,7 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) { ...@@ -1539,7 +1554,7 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
SDataBlockList* pDataBlocks = pCmd->pDataBlocks; SDataBlockList* pDataBlocks = pCmd->pDataBlocks;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0); 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) { if (pDataBlocks == NULL || pMeterMetaInfo->vnodeIndex >= pDataBlocks->nSize) {
tscTrace("%p object should be release since all data blocks have been submit", pSql); tscTrace("%p object should be release since all data blocks have been submit", pSql);
...@@ -1554,18 +1569,18 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) { ...@@ -1554,18 +1569,18 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
} }
SMeterMetaInfo* tscGetMeterMetaInfo(SSqlCmd* pCmd, int32_t index) { 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; return NULL;
} }
assert(index >= 0 && index <= pCmd->numOfTables && pCmd->pMeterInfo != NULL); assert(index >= 0 && index <= pCmd->pQueryInfo[0].numOfTables && pCmd->pQueryInfo[0].pMeterInfo != NULL);
return pCmd->pMeterInfo[index]; return pCmd->pQueryInfo[0].pMeterInfo[index];
} }
SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* index) { SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* index) {
int32_t k = -1; int32_t k = -1;
for (int32_t i = 0; i < pCmd->numOfTables; ++i) { for (int32_t i = 0; i < pCmd->pQueryInfo->numOfTables; ++i) {
if (pCmd->pMeterInfo[i]->pMeterMeta->uid == uid) { if (pCmd->pQueryInfo[0].pMeterInfo[i]->pMeterMeta->uid == uid) {
k = i; k = i;
break; break;
} }
...@@ -1578,17 +1593,37 @@ SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* i ...@@ -1578,17 +1593,37 @@ SMeterMetaInfo* tscGetMeterMetaInfoByUid(SSqlCmd* pCmd, uint64_t uid, int32_t* i
return tscGetMeterMetaInfo(pCmd, k); 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, SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* pMeterMeta, SMetricMeta* pMetricMeta,
int16_t numOfTags, int16_t* tags) { 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) { if (pAlloc == NULL) {
return NULL; return NULL;
} }
pCmd->pMeterInfo = pAlloc; pCmd->pQueryInfo[0].pMeterInfo = pAlloc;
pCmd->pMeterInfo[pCmd->numOfTables] = calloc(1, sizeof(SMeterMetaInfo)); 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); assert(pMeterMetaInfo != NULL);
if (name != NULL) { if (name != NULL) {
...@@ -1604,7 +1639,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* ...@@ -1604,7 +1639,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta*
memcpy(pMeterMetaInfo->tagColumnIndex, tags, sizeof(pMeterMetaInfo->tagColumnIndex[0]) * numOfTags); memcpy(pMeterMetaInfo->tagColumnIndex, tags, sizeof(pMeterMetaInfo->tagColumnIndex[0]) * numOfTags);
} }
pCmd->numOfTables += 1; pCmd->pQueryInfo->numOfTables += 1;
return pMeterMetaInfo; return pMeterMetaInfo;
} }
...@@ -1612,7 +1647,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta* ...@@ -1612,7 +1647,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SSqlCmd* pCmd, const char* name, SMeterMeta*
SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SSqlCmd* pCmd) { return tscAddMeterMetaInfo(pCmd, NULL, NULL, NULL, 0, NULL); } SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SSqlCmd* pCmd) { return tscAddMeterMetaInfo(pCmd, NULL, NULL, NULL, 0, NULL); }
void tscRemoveMeterMetaInfo(SSqlCmd* pCmd, int32_t index, bool removeFromCache) { void tscRemoveMeterMetaInfo(SSqlCmd* pCmd, int32_t index, bool removeFromCache) {
if (index < 0 || index >= pCmd->numOfTables) { if (index < 0 || index >= pCmd->pQueryInfo->numOfTables) {
return; return;
} }
...@@ -1621,24 +1656,29 @@ void tscRemoveMeterMetaInfo(SSqlCmd* pCmd, int32_t index, bool removeFromCache) ...@@ -1621,24 +1656,29 @@ void tscRemoveMeterMetaInfo(SSqlCmd* pCmd, int32_t index, bool removeFromCache)
tscClearMeterMetaInfo(pMeterMetaInfo, removeFromCache); tscClearMeterMetaInfo(pMeterMetaInfo, removeFromCache);
free(pMeterMetaInfo); free(pMeterMetaInfo);
int32_t after = pCmd->numOfTables - index - 1; int32_t after = pCmd->pQueryInfo->numOfTables - index - 1;
if (after > 0) { 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) { void tscRemoveAllMeterMetaInfo(SSqlCmd* pCmd, bool removeFromCache) {
int64_t addr = offsetof(SSqlObj, cmd); 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) { while (pCmd->pQueryInfo[0].numOfTables > 0) {
tscRemoveMeterMetaInfo(pCmd, pCmd->numOfTables - 1, removeFromCache); tscRemoveMeterMetaInfo(pCmd, pCmd->pQueryInfo->numOfTables - 1, removeFromCache);
} }
tfree(pCmd->pMeterInfo); tfree(pCmd->pQueryInfo[0].pMeterInfo);
} }
void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache) { void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache) {
...@@ -1682,17 +1722,27 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1682,17 +1722,27 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
pNew->cmd.payload = NULL; pNew->cmd.payload = NULL;
pNew->cmd.allocSize = 0; pNew->cmd.allocSize = 0;
pNew->cmd.pMeterInfo = NULL; pNew->cmd.pQueryInfo = NULL;
pNew->cmd.numOfQueries = 0;
pNew->cmd.colList.pColList = NULL;
pNew->cmd.colList.numOfAlloc = 0; if (tscAddQueryInfo(&pNew->cmd) != TSDB_CODE_SUCCESS) {
pNew->cmd.colList.numOfCols = 0; tscFreeSqlObj(pNew);
return NULL;
pNew->cmd.numOfTables = 0; }
pNew->cmd.tsBuf = NULL;
memcpy(&pNew->cmd.pQueryInfo[0], &pCmd->pQueryInfo[0], sizeof(SQueryInfo));
memset(&pNew->cmd.fieldsInfo, 0, sizeof(SFieldInfo)); pNew->cmd.pQueryInfo[0].pMeterInfo = NULL;
tscTagCondCopy(&pNew->cmd.tagCond, &pCmd->tagCond);
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) { if (tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE) != TSDB_CODE_SUCCESS) {
tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pMeterMetaInfo->vnodeIndex); 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 ...@@ -1700,8 +1750,8 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
return NULL; 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 // set the correct query type
if (pPrevSql != NULL) { if (pPrevSql != NULL) {
pNew->cmd.type = pPrevSql->cmd.type; pNew->cmd.type = pPrevSql->cmd.type;
...@@ -1710,20 +1760,20 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1710,20 +1760,20 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
} }
uint64_t uid = pMeterMetaInfo->pMeterMeta->uid; 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) { if (numOfOutputCols > 0) {
int32_t* indexList = calloc(1, numOfOutputCols * sizeof(int32_t)); 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); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->uid == uid) { if (pExpr->uid == uid) {
indexList[j++] = i; 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); free(indexList);
tscFieldInfoUpdateOffset(&pNew->cmd); tscFieldInfoUpdateOffset(&pNew->cmd);
...@@ -1739,7 +1789,8 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void ...@@ -1739,7 +1789,8 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
printf("the metricmeta key is:%s\n", key); printf("the metricmeta key is:%s\n", key);
#endif #endif
char* name = pMeterMetaInfo->name; char* name = pMeterMetaInfo->name;
SMeterMetaInfo* pFinalInfo = NULL; SMeterMetaInfo* pFinalInfo = NULL;
if (pPrevSql == NULL) { if (pPrevSql == NULL) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#ifndef TDENGINE_HASHUTIL_H #ifndef TDENGINE_HASHUTIL_H
#define TDENGINE_HASHUTIL_H #define TDENGINE_HASHUTIL_H
#include "os.h"
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
} }
%syntax_error { %syntax_error {
pInfo->validSql = false; pInfo->valid = false;
int32_t outputBufLen = tListLen(pInfo->pzErrMsg); int32_t outputBufLen = tListLen(pInfo->pzErrMsg);
int32_t len = 0; int32_t len = 0;
...@@ -59,25 +59,25 @@ ...@@ -59,25 +59,25 @@
program ::= cmd. {} program ::= cmd. {}
//////////////////////////////////THE SHOW STATEMENT/////////////////////////////////////////// //////////////////////////////////THE SHOW STATEMENT///////////////////////////////////////////
cmd ::= SHOW DATABASES. { setDCLSQLElems(pInfo, SHOW_DATABASES, 0);} cmd ::= SHOW DATABASES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);}
cmd ::= SHOW MNODES. { setDCLSQLElems(pInfo, SHOW_MNODES, 0);} cmd ::= SHOW MNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);}
cmd ::= SHOW DNODES. { setDCLSQLElems(pInfo, SHOW_DNODES, 0);} cmd ::= SHOW DNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);}
cmd ::= SHOW ACCOUNTS. { setDCLSQLElems(pInfo, SHOW_ACCOUNTS, 0);} cmd ::= SHOW ACCOUNTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);}
cmd ::= SHOW USERS. { setDCLSQLElems(pInfo, SHOW_USERS, 0);} cmd ::= SHOW USERS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);}
cmd ::= SHOW MODULES. { setDCLSQLElems(pInfo, SHOW_MODULES, 0); } cmd ::= SHOW MODULES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0); }
cmd ::= SHOW QUERIES. { setDCLSQLElems(pInfo, SHOW_QUERIES, 0); } cmd ::= SHOW QUERIES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0); }
cmd ::= SHOW CONNECTIONS.{ setDCLSQLElems(pInfo, SHOW_CONNECTIONS, 0);} cmd ::= SHOW CONNECTIONS.{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);}
cmd ::= SHOW STREAMS. { setDCLSQLElems(pInfo, SHOW_STREAMS, 0); } cmd ::= SHOW STREAMS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); }
cmd ::= SHOW CONFIGS. { setDCLSQLElems(pInfo, SHOW_CONFIGS, 0); } cmd ::= SHOW CONFIGS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_CONFIGS, 0, 0); }
cmd ::= SHOW SCORES. { setDCLSQLElems(pInfo, SHOW_SCORES, 0); } cmd ::= SHOW SCORES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); }
cmd ::= SHOW GRANTS. { setDCLSQLElems(pInfo, SHOW_GRANTS, 0); } cmd ::= SHOW GRANTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); }
cmd ::= SHOW VNODES. { setDCLSQLElems(pInfo, SHOW_VNODES, 0); } cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
cmd ::= SHOW VNODES IPTOKEN(X). { setDCLSQLElems(pInfo, SHOW_VNODES, 1, &X); } cmd ::= SHOW VNODES IPTOKEN(X). { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); }
%type dbPrefix {SSQLToken} %type dbPrefix {SSQLToken}
dbPrefix(A) ::=. {A.n = 0;} dbPrefix(A) ::=. {A.n = 0; A.type = 0;}
dbPrefix(A) ::= ids(X) DOT. {A = X; } dbPrefix(A) ::= ids(X) DOT. {A = X; }
%type cpxName {SSQLToken} %type cpxName {SSQLToken}
...@@ -85,60 +85,60 @@ cpxName(A) ::= . {A.n = 0; } ...@@ -85,60 +85,60 @@ cpxName(A) ::= . {A.n = 0; }
cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; } cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; }
cmd ::= SHOW dbPrefix(X) TABLES. { 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). { 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. { 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). { cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
SSQLToken token; SSQLToken token;
setDBName(&token, &X); setDBName(&token, &X);
setDCLSQLElems(pInfo, SHOW_STABLES, 2, &token, &Y); setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &Y);
} }
cmd ::= SHOW dbPrefix(X) VGROUPS. { cmd ::= SHOW dbPrefix(X) VGROUPS. {
SSQLToken token; SSQLToken token;
setDBName(&token, &X); setDBName(&token, &X);
setDCLSQLElems(pInfo, SHOW_VGROUPS, 1, &token); setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
} }
//drop configure for tables //drop configure for tables
cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). { cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n; 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 DATABASE ifexists(Y) ids(X). { setDropDBTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y); }
cmd ::= DROP DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, DROP_DNODE, 1, &X); } cmd ::= DROP DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); }
cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, DROP_USER, 1, &X); } cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); }
cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, DROP_ACCOUNT, 1, &X); } cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
/////////////////////////////////THE USE STATEMENT////////////////////////////////////////// /////////////////////////////////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///////////////////////////////////// /////////////////////////////////THE DESCRIBE STATEMENT/////////////////////////////////////
cmd ::= DESCRIBE ids(X) cpxName(Y). { cmd ::= DESCRIBE ids(X) cpxName(Y). {
X.n += Y.n; X.n += Y.n;
setDCLSQLElems(pInfo, DESCRIBE_TABLE, 1, &X); setDCLSQLElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
} }
/////////////////////////////////THE ALTER STATEMENT//////////////////////////////////////// /////////////////////////////////THE ALTER STATEMENT////////////////////////////////////////
cmd ::= ALTER USER ids(X) PASS ids(Y). { setDCLSQLElems(pInfo, ALTER_USER_PASSWD, 2, &X, &Y); } 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). { setDCLSQLElems(pInfo, ALTER_USER_PRIVILEGES, 2, &X, &Y);} 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, ALTER_DNODE, 2, &X, &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, ALTER_DNODE, 3, &X, &Y, &Z); } 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, ALTER_LOCAL, 1, &X); } cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); }
cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_LOCAL, 2, &X, &Y); } 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, ALTER_DATABASE, &X, &Y, &t);} 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) 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, ALTER_ACCT, &X, &Y, &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. // An IDENTIFIER can be a generic identifier, or one of several keywords.
// Any non-standard keyword can also be an identifier. // Any non-standard keyword can also be an identifier.
...@@ -157,11 +157,11 @@ ifnotexists(X) ::= . {X.n = 0;} ...@@ -157,11 +157,11 @@ ifnotexists(X) ::= . {X.n = 0;}
/////////////////////////////////THE CREATE STATEMENT/////////////////////////////////////// /////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
//create option for dnode/db/user/account //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). cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
{ setCreateAcctSQL(pInfo, CREATE_ACCOUNT, &X, &Y, &Z);} { setCreateAcctSQL(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, CREATE_DATABASE, &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). { setDCLSQLElems(pInfo, CREATE_USER, 2, &X, &Y);} cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSQL(pInfo, &X, &Y);}
pps(Y) ::= . {Y.n = 0; } pps(Y) ::= . {Y.n = 0; }
pps(Y) ::= PPS INTEGER(X). {Y = X; } pps(Y) ::= PPS INTEGER(X). {Y = X; }
...@@ -192,14 +192,14 @@ state(Y) ::= STATE ids(X). {Y = X; } ...@@ -192,14 +192,14 @@ state(Y) ::= STATE ids(X). {Y = X; }
%type acct_optr {SCreateAcctSQL} %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). { 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.maxUsers = (K.n>0)?atoi(K.z):-1;
Y.dbs = (E.n>0)?atoi(E.z):-1; Y.maxDbs = (E.n>0)?atoi(E.z):-1;
Y.tseries = (D.n>0)?atoi(D.z):-1; Y.maxTimeSeries = (D.n>0)?atoi(D.z):-1;
Y.streams = (F.n>0)?atoi(F.z):-1; Y.maxStreams = (F.n>0)?atoi(F.z):-1;
Y.pps = (C.n>0)?atoi(C.z):-1; Y.maxPointsPerSecond = (C.n>0)?atoi(C.z):-1;
Y.storage = (P.n>0)?strtoll(P.z, NULL, 10):-1; Y.maxStorage = (P.n>0)?strtoll(P.z, NULL, 10):-1;
Y.qtime = (Q.n>0)?strtoll(Q.z, NULL, 10):-1; Y.maxQueryTime = (Q.n>0)?strtoll(Q.z, NULL, 10):-1;
Y.conns = (L.n>0)?atoi(L.z):-1; Y.maxConnections = (L.n>0)?atoi(L.z):-1;
Y.stat = M; Y.stat = M;
} }
...@@ -264,29 +264,29 @@ cmd ::= CREATE TABLE ifnotexists(Y) ids(X) cpxName(Z) create_table_args. { ...@@ -264,29 +264,29 @@ cmd ::= CREATE TABLE ifnotexists(Y) ids(X) cpxName(Z) create_table_args. {
%type create_table_args{SCreateTableSQL*} %type create_table_args{SCreateTableSQL*}
create_table_args(A) ::= LP columnlist(X) RP. { create_table_args(A) ::= LP columnlist(X) RP. {
A = tSetCreateSQLElems(X, NULL, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METER); A = tSetCreateSQLElems(X, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE);
setSQLInfo(pInfo, A, NULL, TSQL_CREATE_NORMAL_METER); 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. { create_table_args(A) ::= LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
A = tSetCreateSQLElems(X, Y, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METRIC); A = tSetCreateSQLElems(X, Y, NULL, NULL, NULL, TSQL_CREATE_STABLE);
setSQLInfo(pInfo, A, NULL, TSQL_CREATE_NORMAL_METRIC); setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
} }
// create meter by using metric // create table by using super table
// create meter meter_name using metric_name tags(tag_values1, tag_values2) // 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. { create_table_args(A) ::= USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP. {
X.n += F.n; X.n += F.n;
A = tSetCreateSQLElems(NULL, NULL, &X, Y, NULL, TSQL_CREATE_METER_FROM_METRIC); A = tSetCreateSQLElems(NULL, NULL, &X, Y, NULL, TSQL_CREATE_TABLE_FROM_STABLE);
setSQLInfo(pInfo, A, NULL, TSQL_CREATE_METER_FROM_METRIC); setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
} }
// create stream // 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). { create_table_args(A) ::= AS select(S). {
A = tSetCreateSQLElems(NULL, NULL, NULL, NULL, S, TSQL_CREATE_STREAM); 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} %type column{TAOS_FIELD}
...@@ -343,16 +343,21 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). { ...@@ -343,16 +343,21 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). {
} }
//////////////////////// The SELECT statement ///////////////////////////////// //////////////////////// The SELECT statement /////////////////////////////////
cmd ::= select(X). {
setSQLInfo(pInfo, X, NULL, TSQL_QUERY_METER);
}
%type select {SQuerySQL*} %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). { 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); 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., // Support for the SQL exprssion without from & where subclauses, e.g.,
// select current_database(), // select current_database(),
// select server_version(), select client_version(), // select server_version(), select client_version(),
...@@ -572,34 +577,14 @@ exprlist(A) ::= expritem(X). {A = tSQLExprListAppend(0,X,0);} ...@@ -572,34 +577,14 @@ exprlist(A) ::= expritem(X). {A = tSQLExprListAppend(0,X,0);}
expritem(A) ::= expr(X). {A = X;} expritem(A) ::= expr(X). {A = X;}
expritem(A) ::= . {A = 0;} 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////////////////////////////////////// ///////////////////////////////////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////////////////////////////////// ///////////////////////////////////ALTER TABLE statement//////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). { cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n; X.n += F.n;
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, ALTER_TABLE_ADD_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_ADD_COLUMN); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). { 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). { ...@@ -608,15 +593,15 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
toTSDBType(A.type); toTSDBType(A.type);
tVariantList* K = tVariantListAppendToken(NULL, &A, -1); tVariantList* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, ALTER_TABLE_DROP_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_DROP_COLUMN); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
//////////////////////////////////ALTER TAGS statement///////////////////////////////////// //////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). { cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
X.n += Y.n; X.n += Y.n;
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, ALTER_TABLE_TAGS_ADD); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_ADD); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). { cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
X.n += Z.n; X.n += Z.n;
...@@ -624,8 +609,8 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). { ...@@ -624,8 +609,8 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
toTSDBType(Y.type); toTSDBType(Y.type);
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1); tVariantList* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, ALTER_TABLE_TAGS_DROP); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_DROP); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). { 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). { ...@@ -637,8 +622,8 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
toTSDBType(Z.type); toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1); A = tVariantListAppendToken(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, ALTER_TABLE_TAGS_CHG); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_CHG); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). { 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). { ...@@ -648,17 +633,18 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1); tVariantList* A = tVariantListAppendToken(NULL, &Y, -1);
A = tVariantListAppend(A, &Z, -1); A = tVariantListAppend(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, ALTER_TABLE_TAGS_SET); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_SET); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
////////////////////////////////////////kill statement/////////////////////////////////////// ////////////////////////////////////////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 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); setDCLSQLElems(pInfo, KILL_STREAM, 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); 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); setDCLSQLElems(pInfo, KILL_QUERY, 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); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &X);}
%fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED %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 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 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 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.
...@@ -74,10 +74,10 @@ extern "C" { ...@@ -74,10 +74,10 @@ extern "C" {
#define TSDB_MSG_TYPE_CREATE_MNODE_RSP 44 #define TSDB_MSG_TYPE_CREATE_MNODE_RSP 44
#define TSDB_MSG_TYPE_DROP_MNODE 45 #define TSDB_MSG_TYPE_DROP_MNODE 45
#define TSDB_MSG_TYPE_DROP_MNODE_RSP 46 #define TSDB_MSG_TYPE_DROP_MNODE_RSP 46
#define TSDB_MSG_TYPE_CREATE_PNODE 47 #define TSDB_MSG_TYPE_CREATE_DNODE 47
#define TSDB_MSG_TYPE_CREATE_PNODE_RSP 48 #define TSDB_MSG_TYPE_CREATE_DNODE_RSP 48
#define TSDB_MSG_TYPE_DROP_PNODE 49 #define TSDB_MSG_TYPE_DROP_DNODE 49
#define TSDB_MSG_TYPE_DROP_PNODE_RSP 50 #define TSDB_MSG_TYPE_DROP_DNODE_RSP 50
#define TSDB_MSG_TYPE_CREATE_DB 51 #define TSDB_MSG_TYPE_CREATE_DB 51
#define TSDB_MSG_TYPE_CREATE_DB_RSP 52 #define TSDB_MSG_TYPE_CREATE_DB_RSP 52
#define TSDB_MSG_TYPE_DROP_DB 53 #define TSDB_MSG_TYPE_DROP_DB 53
...@@ -147,7 +147,7 @@ enum _mgmt_table { ...@@ -147,7 +147,7 @@ enum _mgmt_table {
TSDB_MGMT_TABLE_USER, TSDB_MGMT_TABLE_USER,
TSDB_MGMT_TABLE_DB, TSDB_MGMT_TABLE_DB,
TSDB_MGMT_TABLE_TABLE, TSDB_MGMT_TABLE_TABLE,
TSDB_MGMT_TABLE_PNODE, TSDB_MGMT_TABLE_DNODE,
TSDB_MGMT_TABLE_MNODE, TSDB_MGMT_TABLE_MNODE,
TSDB_MGMT_TABLE_VGROUP, TSDB_MGMT_TABLE_VGROUP,
TSDB_MGMT_TABLE_METRIC, TSDB_MGMT_TABLE_METRIC,
...@@ -312,7 +312,7 @@ typedef struct { ...@@ -312,7 +312,7 @@ typedef struct {
typedef struct { typedef struct {
char db[TSDB_METER_ID_LEN]; char db[TSDB_METER_ID_LEN];
short ignoreNotExists; uint8_t ignoreNotExists;
} SDropDbMsg, SUseDbMsg; } SDropDbMsg, SUseDbMsg;
typedef struct { typedef struct {
......
...@@ -119,97 +119,100 @@ ...@@ -119,97 +119,100 @@
#define TK_COMMA 101 #define TK_COMMA 101
#define TK_NULL 102 #define TK_NULL 102
#define TK_SELECT 103 #define TK_SELECT 103
#define TK_FROM 104 #define TK_UNION 104
#define TK_VARIABLE 105 #define TK_FROM 105
#define TK_INTERVAL 106 #define TK_VARIABLE 106
#define TK_FILL 107 #define TK_INTERVAL 107
#define TK_SLIDING 108 #define TK_FILL 108
#define TK_ORDER 109 #define TK_SLIDING 109
#define TK_BY 110 #define TK_ORDER 110
#define TK_ASC 111 #define TK_BY 111
#define TK_DESC 112 #define TK_ASC 112
#define TK_GROUP 113 #define TK_DESC 113
#define TK_HAVING 114 #define TK_GROUP 114
#define TK_LIMIT 115 #define TK_HAVING 115
#define TK_OFFSET 116 #define TK_LIMIT 116
#define TK_SLIMIT 117 #define TK_OFFSET 117
#define TK_SOFFSET 118 #define TK_SLIMIT 118
#define TK_WHERE 119 #define TK_SOFFSET 119
#define TK_NOW 120 #define TK_WHERE 120
#define TK_INSERT 121 #define TK_NOW 121
#define TK_INTO 122 #define TK_RESET 122
#define TK_VALUES 123 #define TK_QUERY 123
#define TK_RESET 124 #define TK_ADD 124
#define TK_QUERY 125 #define TK_COLUMN 125
#define TK_ADD 126 #define TK_TAG 126
#define TK_COLUMN 127 #define TK_CHANGE 127
#define TK_TAG 128 #define TK_SET 128
#define TK_CHANGE 129 #define TK_KILL 129
#define TK_SET 130 #define TK_CONNECTION 130
#define TK_KILL 131 #define TK_COLON 131
#define TK_CONNECTION 132 #define TK_STREAM 132
#define TK_COLON 133 #define TK_ABORT 133
#define TK_STREAM 134 #define TK_AFTER 134
#define TK_ABORT 135 #define TK_ATTACH 135
#define TK_AFTER 136 #define TK_BEFORE 136
#define TK_ATTACH 137 #define TK_BEGIN 137
#define TK_BEFORE 138 #define TK_CASCADE 138
#define TK_BEGIN 139 #define TK_CLUSTER 139
#define TK_CASCADE 140 #define TK_CONFLICT 140
#define TK_CLUSTER 141 #define TK_COPY 141
#define TK_CONFLICT 142 #define TK_DEFERRED 142
#define TK_COPY 143 #define TK_DELIMITERS 143
#define TK_DEFERRED 144 #define TK_DETACH 144
#define TK_DELIMITERS 145 #define TK_EACH 145
#define TK_DETACH 146 #define TK_END 146
#define TK_EACH 147 #define TK_EXPLAIN 147
#define TK_END 148 #define TK_FAIL 148
#define TK_EXPLAIN 149 #define TK_FOR 149
#define TK_FAIL 150 #define TK_IGNORE 150
#define TK_FOR 151 #define TK_IMMEDIATE 151
#define TK_IGNORE 152 #define TK_INITIALLY 152
#define TK_IMMEDIATE 153 #define TK_INSTEAD 153
#define TK_INITIALLY 154 #define TK_MATCH 154
#define TK_INSTEAD 155 #define TK_KEY 155
#define TK_MATCH 156 #define TK_OF 156
#define TK_KEY 157 #define TK_RAISE 157
#define TK_OF 158 #define TK_REPLACE 158
#define TK_RAISE 159 #define TK_RESTRICT 159
#define TK_REPLACE 160 #define TK_ROW 160
#define TK_RESTRICT 161 #define TK_STATEMENT 161
#define TK_ROW 162 #define TK_TRIGGER 162
#define TK_STATEMENT 163 #define TK_VIEW 163
#define TK_TRIGGER 164 #define TK_ALL 164
#define TK_VIEW 165 #define TK_COUNT 165
#define TK_ALL 166 #define TK_SUM 166
#define TK_COUNT 167 #define TK_AVG 167
#define TK_SUM 168 #define TK_MIN 168
#define TK_AVG 169 #define TK_MAX 169
#define TK_MIN 170 #define TK_FIRST 170
#define TK_MAX 171 #define TK_LAST 171
#define TK_FIRST 172 #define TK_TOP 172
#define TK_LAST 173 #define TK_BOTTOM 173
#define TK_TOP 174 #define TK_STDDEV 174
#define TK_BOTTOM 175 #define TK_PERCENTILE 175
#define TK_STDDEV 176 #define TK_APERCENTILE 176
#define TK_PERCENTILE 177 #define TK_LEASTSQUARES 177
#define TK_APERCENTILE 178 #define TK_HISTOGRAM 178
#define TK_LEASTSQUARES 179 #define TK_DIFF 179
#define TK_HISTOGRAM 180 #define TK_SPREAD 180
#define TK_DIFF 181 #define TK_TWA 181
#define TK_SPREAD 182 #define TK_INTERP 182
#define TK_TWA 183 #define TK_LAST_ROW 183
#define TK_INTERP 184 #define TK_SEMI 184
#define TK_LAST_ROW 185 #define TK_NONE 185
#define TK_SEMI 186 #define TK_PREV 186
#define TK_NONE 187 #define TK_LINEAR 187
#define TK_PREV 188 #define TK_IMPORT 188
#define TK_LINEAR 189 #define TK_METRIC 189
#define TK_IMPORT 190 #define TK_TBNAME 190
#define TK_METRIC 191 #define TK_JOIN 191
#define TK_TBNAME 192 #define TK_METRICS 192
#define TK_JOIN 193 #define TK_STABLE 193
#define TK_METRICS 194 #define TK_INSERT 194
#define TK_STABLE 195 #define TK_INTO 195
#define TK_VALUES 196
#endif #endif
...@@ -162,15 +162,6 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP ...@@ -162,15 +162,6 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP
int32_t taosInitTimer(void (*callback)(int), int32_t ms); 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 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); bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
......
...@@ -22,7 +22,8 @@ extern "C" { ...@@ -22,7 +22,8 @@ extern "C" {
#include "os.h" #include "os.h"
#include "ihash.h" #include "hash.h"
#include "hashutil.h"
#define GET_QINFO_ADDR(x) ((char*)(x)-offsetof(SQInfo, query)) #define GET_QINFO_ADDR(x) ((char*)(x)-offsetof(SQInfo, query))
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0) #define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0)
...@@ -117,11 +118,9 @@ typedef enum { ...@@ -117,11 +118,9 @@ typedef enum {
#define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN) #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 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) { 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); bool isQueryKilled(SQuery* pQuery);
......
...@@ -172,7 +172,7 @@ typedef struct SMeterDataInfo { ...@@ -172,7 +172,7 @@ typedef struct SMeterDataInfo {
} SMeterDataInfo; } SMeterDataInfo;
typedef struct SMeterQuerySupportObj { typedef struct SMeterQuerySupportObj {
void* pMeterObj; void* pMetersHashTable; // meter table hash list
SMeterSidExtInfo** pMeterSidExtInfo; SMeterSidExtInfo** pMeterSidExtInfo;
int32_t numOfMeters; int32_t numOfMeters;
......
...@@ -894,7 +894,7 @@ int mgmtProcessShowMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -894,7 +894,7 @@ int mgmtProcessShowMsg(char *pMsg, int msgLen, SConnObj *pConn) {
SShowRspMsg *pShowRsp; SShowRspMsg *pShowRsp;
SShowObj * pShow = NULL; 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) { if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_SHOW_RSP) != 0) {
return 0; return 0;
} }
...@@ -1467,8 +1467,8 @@ void mgmtInitProcessShellMsg() { ...@@ -1467,8 +1467,8 @@ void mgmtInitProcessShellMsg() {
mgmtProcessShellMsg[TSDB_MSG_TYPE_SHOW] = mgmtProcessShowMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_SHOW] = mgmtProcessShowMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_CONNECT] = mgmtProcessConnectMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CONNECT] = mgmtProcessConnectMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_HEARTBEAT] = mgmtProcessHeartBeatMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_HEARTBEAT] = mgmtProcessHeartBeatMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_PNODE] = mgmtProcessCreateDnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_DNODE] = mgmtProcessCreateDnodeMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_PNODE] = mgmtProcessDropDnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_DNODE] = mgmtProcessDropDnodeMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_MNODE] = mgmtProcessCreateMnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CREATE_MNODE] = mgmtProcessCreateMnodeMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_MNODE] = mgmtProcessDropMnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_DROP_MNODE] = mgmtProcessDropMnodeMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_CFG_MNODE] = mgmtProcessCfgMnodeMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_CFG_MNODE] = mgmtProcessCfgMnodeMsg;
......
...@@ -3383,6 +3383,10 @@ void forwardQueryStartPosition(SQueryRuntimeEnv *pRuntimeEnv) { ...@@ -3383,6 +3383,10 @@ void forwardQueryStartPosition(SQueryRuntimeEnv *pRuntimeEnv) {
updateOffsetVal(pRuntimeEnv, &blockInfo, pBlock); updateOffsetVal(pRuntimeEnv, &blockInfo, pBlock);
} else { } else {
pQuery->limit.offset -= maxReads; 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); doSkipDataBlock(pRuntimeEnv);
} }
} }
......
...@@ -24,7 +24,7 @@ int mgmtProcessAlterAcctMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -24,7 +24,7 @@ int mgmtProcessAlterAcctMsg(char *pMsg, int msgLen, SConnObj *pConn) {
} }
int mgmtProcessCreateDnodeMsg(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) { int mgmtProcessCfgMnodeMsg(char *pMsg, int msgLen, SConnObj *pConn) {
...@@ -36,7 +36,7 @@ int mgmtProcessDropMnodeMsg(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) { 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) { int mgmtProcessDropAcctMsg(char *pMsg, int msgLen, SConnObj *pConn) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册