diff --git a/include/common/tcmdtype.h b/include/common/tmsgtype.h
similarity index 97%
rename from include/common/tcmdtype.h
rename to include/common/tmsgtype.h
index e37996b9c7..d357ca1f47 100644
--- a/include/common/tcmdtype.h
+++ b/include/common/tmsgtype.h
@@ -24,7 +24,7 @@ extern "C" {
#ifdef TSDB_SQL_C
#define TSDB_DEFINE_SQL_TYPE( name, msg ) msg,
-char *sqlCmd[] = {
+char *sqlMsgType[] = {
"null",
#else
#define TSDB_DEFINE_SQL_TYPE( name, msg ) name,
@@ -103,15 +103,13 @@ enum {
};
// create table operation type
-enum TSQL_TYPE {
- TSQL_CREATE_TABLE = 0x1,
+enum TSQL_CREATE_TABLE_TYPE {
+ TSQL_CREATE_TABLE = 0x1,
TSQL_CREATE_STABLE = 0x2,
- TSQL_CREATE_TABLE_FROM_STABLE = 0x3,
+ TSQL_CREATE_CTABLE = 0x3,
TSQL_CREATE_STREAM = 0x4,
};
-extern char *sqlCmd[];
-
#ifdef __cplusplus
}
#endif
diff --git a/include/common/tvariant.h b/include/common/tvariant.h
index c33797684e..13c8aff8e7 100644
--- a/include/common/tvariant.h
+++ b/include/common/tvariant.h
@@ -38,7 +38,7 @@ typedef struct SVariant {
bool taosVariantIsValid(SVariant *pVar);
-//void taosVariantCreate(SVariant *pVar, SToken *token);
+void taosVariantCreate(SVariant *pVar, char* z, int32_t n, int32_t type);
void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type);
diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h
index 8bbd698ad8..eeb5f4cd8e 100644
--- a/include/libs/parser/parser.h
+++ b/include/libs/parser/parser.h
@@ -183,7 +183,7 @@ bool qIsInsertSql(const char* pStr, size_t length);
* @param msg extended error message if exists.
* @return error code
*/
-int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo** pQueryInfo, int64_t id, char* msg);
+int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo** pQueryInfo, int64_t id, char* msg, int32_t msgLen);
/**
* Parse the insert sql statement.
@@ -194,7 +194,7 @@ int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo**
* @param msg extended error message if exists to help avoid the problem in sql statement.
* @return
*/
-int32_t qParseInsertSql(const char* pStr, size_t length, struct SInsertStmtInfo** pInsertInfo, int64_t id, char* msg);
+int32_t qParseInsertSql(const char* pStr, size_t length, struct SInsertStmtInfo** pInsertInfo, int64_t id, char* msg, int32_t msgLen);
/**
* Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
diff --git a/source/common/src/sqlcmdstr.c b/source/common/src/sqlcmdstr.c
index 672106523e..6e845e7e9e 100644
--- a/source/common/src/sqlcmdstr.c
+++ b/source/common/src/sqlcmdstr.c
@@ -15,4 +15,4 @@
#define TSDB_SQL_C
-#include "tcmdtype.h"
+#include "tmsgtype.h"
diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c
index 93772847ad..9216183b88 100644
--- a/source/common/src/tvariant.c
+++ b/source/common/src/tvariant.c
@@ -29,18 +29,16 @@
if ((res) > (maxv)) { *exti = 1; break; } \
assert(0); \
} while (0)
-#if 0
-void tVariantCreate(SVariant *pVar, SToken *token) {
- int32_t ret = 0;
- int32_t type = token->type;
+void taosVariantCreate(SVariant *pVar, char* z, int32_t n, int32_t type) {
+ int32_t ret = 0;
memset(pVar, 0, sizeof(SVariant));
- switch (token->type) {
+ switch (type) {
case TSDB_DATA_TYPE_BOOL: {
- if (strncasecmp(token->z, "true", 4) == 0) {
+ if (strncasecmp(z, "true", 4) == 0) {
pVar->i64 = TSDB_TRUE;
- } else if (strncasecmp(token->z, "false", 5) == 0) {
+ } else if (strncasecmp(z, "false", 5) == 0) {
pVar->i64 = TSDB_FALSE;
} else {
return;
@@ -53,35 +51,35 @@ void tVariantCreate(SVariant *pVar, SToken *token) {
case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_INT:{
- ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, true);
- if (ret != 0) {
- SToken t = {0};
- tGetToken(token->z, &t.type);
- if (t.type == TK_MINUS) { // it is a signed number which is greater than INT64_MAX or less than INT64_MIN
- pVar->nType = -1; // -1 means error type
- return;
- }
-
- // data overflow, try unsigned parse the input number
- ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, false);
- if (ret != 0) {
- pVar->nType = -1; // -1 means error type
- return;
- }
- }
+// ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, true);
+// if (ret != 0) {
+// SToken t = {0};
+// tGetToken(token->z, &t.type);
+// if (t.type == TK_MINUS) { // it is a signed number which is greater than INT64_MAX or less than INT64_MIN
+// pVar->nType = -1; // -1 means error type
+// return;
+// }
+//
+// // data overflow, try unsigned parse the input number
+// ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, false);
+// if (ret != 0) {
+// pVar->nType = -1; // -1 means error type
+// return;
+// }
+// }
break;
}
case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_FLOAT: {
- pVar->d = strtod(token->z, NULL);
+ pVar->d = strtod(z, NULL);
break;
}
case TSDB_DATA_TYPE_BINARY: {
- pVar->pz = strndup(token->z, token->n);
- pVar->nLen = strRmquote(pVar->pz, token->n);
+ pVar->pz = strndup(z, n);
+ pVar->nLen = strRmquote(pVar->pz, n);
break;
}
case TSDB_DATA_TYPE_TIMESTAMP: {
@@ -96,7 +94,7 @@ void tVariantCreate(SVariant *pVar, SToken *token) {
pVar->nType = type;
}
-#endif
+
/**
* create SVariant from binary string, not ascii data
@@ -105,7 +103,7 @@ void tVariantCreate(SVariant *pVar, SToken *token) {
* @param len
* @param type
*/
-void tVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type) {
+void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type) {
switch (type) {
case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: {
@@ -183,7 +181,7 @@ void tVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32
pVar->nType = type;
}
-void tVariantDestroy(SVariant *pVar) {
+void taosVariantDestroy(SVariant *pVar) {
if (pVar == NULL) return;
if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) {
@@ -206,12 +204,12 @@ void tVariantDestroy(SVariant *pVar) {
}
}
-bool tVariantIsValid(SVariant *pVar) {
+bool taosVariantIsValid(SVariant *pVar) {
assert(pVar != NULL);
return isValidDataType(pVar->nType);
}
-void tVariantAssign(SVariant *pDst, const SVariant *pSrc) {
+void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) {
if (pSrc == NULL || pDst == NULL) return;
pDst->nType = pSrc->nType;
@@ -255,7 +253,7 @@ void tVariantAssign(SVariant *pDst, const SVariant *pSrc) {
}
}
-int32_t tVariantCompare(const SVariant* p1, const SVariant* p2) {
+int32_t taosVariantCompare(const SVariant* p1, const SVariant* p2) {
if (p1->nType == TSDB_DATA_TYPE_NULL && p2->nType == TSDB_DATA_TYPE_NULL) {
return 0;
}
@@ -295,7 +293,7 @@ int32_t tVariantCompare(const SVariant* p1, const SVariant* p2) {
}
}
-int32_t tVariantToString(SVariant *pVar, char *dst) {
+int32_t taosVariantToString(SVariant *pVar, char *dst) {
if (pVar == NULL || dst == NULL) return 0;
switch (pVar->nType) {
@@ -893,7 +891,7 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
* to column type defined in schema
*/
-int32_t tVariantDump(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix) {
+int32_t taosVariantDump(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix) {
return tVariantDumpEx(pVariant, payload, type, includeLengthPrefix, NULL, NULL);
}
@@ -974,4 +972,4 @@ int32_t tVariantTypeSetType(SVariant *pVariant, char type) {
}
return 0;
-}
+}
\ No newline at end of file
diff --git a/source/libs/executor/src/texpr.c b/source/libs/executor/src/texpr.c
index 41856132b7..7e2797743d 100644
--- a/source/libs/executor/src/texpr.c
+++ b/source/libs/executor/src/texpr.c
@@ -117,7 +117,7 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
if (pNode->nodeType == TSQL_NODE_EXPR) {
doExprTreeDestroy(&pNode, fp);
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
- tVariantDestroy(pNode->pVal);
+ taosVariantDestroy(pNode->pVal);
} else if (pNode->nodeType == TSQL_NODE_COL) {
tfree(pNode->pSchema);
}
@@ -138,7 +138,7 @@ static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
fp((*pExpr)->_node.info);
}
} else if ((*pExpr)->nodeType == TSQL_NODE_VALUE) {
- tVariantDestroy((*pExpr)->pVal);
+ taosVariantDestroy((*pExpr)->pVal);
free((*pExpr)->pVal);
} else if ((*pExpr)->nodeType == TSQL_NODE_COL) {
free((*pExpr)->pSchema);
@@ -492,8 +492,8 @@ void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) {
uint32_t type = tbufReadUint32(&br);
SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false);
- taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type));
-
+// taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type));
+
int dummy = -1;
int32_t sz = tbufReadInt32(&br);
for (int32_t i = 0; i < sz; i++) {
@@ -528,7 +528,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t
uint32_t sType = tbufReadUint32(&br);
SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(tType), true, false);
- taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(tType));
+// taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(tType));
int dummy = -1;
SVariant tmpVar = {0};
@@ -603,7 +603,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t
return;
}
- tVariantCreateFromBinary(&tmpVar, (char *)pvar, t, sType);
+ taosVariantCreateFromBinary(&tmpVar, (char *)pvar, t, sType);
if (bufLen < t) {
tmp = realloc(tmp, t * TSDB_NCHAR_SIZE);
@@ -686,7 +686,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t
}
taosHashPut(pObj, (char *)pvar, t, &dummy, sizeof(dummy));
- tVariantDestroy(&tmpVar);
+ taosVariantDestroy(&tmpVar);
memset(&tmpVar, 0, sizeof(tmpVar));
}
@@ -694,7 +694,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t
pObj = NULL;
err_ret:
- tVariantDestroy(&tmpVar);
+ taosVariantDestroy(&tmpVar);
taosHashCleanup(pObj);
tfree(tmp);
}
@@ -716,7 +716,7 @@ tExprNode* exprdup(tExprNode* pNode) {
pCloned->_node.hasPK = pNode->_node.hasPK;
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
pCloned->pVal = calloc(1, sizeof(SVariant));
- tVariantAssign(pCloned->pVal, pNode->pVal);
+ taosVariantAssign(pCloned->pVal, pNode->pVal);
} else if (pNode->nodeType == TSQL_NODE_COL) {
pCloned->pSchema = calloc(1, sizeof(SSchema));
*pCloned->pSchema = *pNode->pSchema;
diff --git a/source/libs/parser/inc/astGenerator.h b/source/libs/parser/inc/astGenerator.h
index b6d7545f3b..af489a4e37 100644
--- a/source/libs/parser/inc/astGenerator.h
+++ b/source/libs/parser/inc/astGenerator.h
@@ -285,8 +285,7 @@ int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right);
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type);
-SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type,
- int16_t tableTable);
+SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType);
SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
SToken *igExists);
@@ -299,6 +298,7 @@ SArray *setSubclause(SArray *pList, void *pSqlNode);
SArray *appendSelectClause(SArray *pList, void *pSubclause);
void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists);
+void* destroyCreateTableSql(SCreateTableSql* pCreate);
void SqlInfoDestroy(SSqlInfo *pInfo);
@@ -351,7 +351,7 @@ void *ParseAlloc(void *(*mallocProc)(size_t));
* @param str sql string
* @return sql ast
*/
-SSqlInfo genAST(const char *str);
+SSqlInfo doGenerateAST(const char *str);
#ifdef __cplusplus
}
diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c
index 94f29907e9..bc4d13e02a 100644
--- a/source/libs/parser/src/astGenerator.c
+++ b/source/libs/parser/src/astGenerator.c
@@ -13,9 +13,10 @@
* along with this program. If not, see .
*/
-#include "astGenerator.h"
-#include "../../../../include/client/taos.h"
+#include "taos.h"
#include "os.h"
+#include "astGenerator.h"
+#include "tmsgtype.h"
int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned) {
errno = 0;
@@ -104,7 +105,8 @@ SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrd
if (pAliasToken) {
SListItem item;
- taosVariantCreate(&item.pVar, pAliasToken);
+ assert(0);
+// taosVariantCreate(&item.pVar, pAliasToken);
item.sortOrder = sortOrder;
taosArrayPush(pList, &item);
@@ -371,87 +373,755 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
return pExpr;
}
-tSqlExpr *tSqlExprClone(tSqlExpr *pSrc);
-void tSqlExprCompact(tSqlExpr **pExpr);
-bool tSqlExprIsLeaf(tSqlExpr *pExpr);
-bool tSqlExprIsParentOfLeaf(tSqlExpr *pExpr);
-void tSqlExprDestroy(tSqlExpr *pExpr);
-SArray * tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SToken *pDistinct, SToken *pToken);
-void tSqlExprListDestroy(SArray *pList);
+tSqlExpr *tSqlExprClone(tSqlExpr *pSrc) {
+ tSqlExpr *pExpr = malloc(sizeof(tSqlExpr));
+ memcpy(pExpr, pSrc, sizeof(*pSrc));
+
+ if (pSrc->pLeft) {
+ pExpr->pLeft = tSqlExprClone(pSrc->pLeft);
+ }
+
+ if (pSrc->pRight) {
+ pExpr->pRight = tSqlExprClone(pSrc->pRight);
+ }
+
+ memset(&pExpr->value, 0, sizeof(pExpr->value));
+ taosVariantAssign(&pExpr->value, &pSrc->value);
+
+ //we don't clone paramList now because clone is only used for between/and
+ assert(pSrc->Expr.paramList == NULL);
+ return pExpr;
+}
+
+void tSqlExprCompact(tSqlExpr **pExpr) {
+
+ if (*pExpr == NULL || tSqlExprIsParentOfLeaf(*pExpr)) {
+ return;
+ }
+
+ if ((*pExpr)->pLeft) {
+ tSqlExprCompact(&(*pExpr)->pLeft);
+ }
+
+ if ((*pExpr)->pRight) {
+ tSqlExprCompact(&(*pExpr)->pRight);
+ }
+
+ if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight == NULL && ((*pExpr)->tokenId == TK_OR || (*pExpr)->tokenId == TK_AND)) {
+ tSqlExprDestroy(*pExpr);
+ *pExpr = NULL;
+ } else if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight != NULL) {
+ tSqlExpr* tmpPtr = (*pExpr)->pRight;
+ (*pExpr)->pRight = NULL;
+
+ tSqlExprDestroy(*pExpr);
+ (*pExpr) = tmpPtr;
+ } else if ((*pExpr)->pRight == NULL && (*pExpr)->pLeft != NULL) {
+ tSqlExpr* tmpPtr = (*pExpr)->pLeft;
+ (*pExpr)->pLeft = NULL;
+
+ tSqlExprDestroy(*pExpr);
+ (*pExpr) = tmpPtr;
+ }
+}
+
+bool tSqlExprIsLeaf(tSqlExpr *pExpr) {
+ return (pExpr->pRight == NULL && pExpr->pLeft == NULL) &&
+ (pExpr->tokenId == 0 ||
+ (pExpr->tokenId == TK_ID) ||
+ (pExpr->tokenId >= TK_BOOL && pExpr->tokenId <= TK_NCHAR) ||
+ (pExpr->tokenId == TK_NULL) ||
+ (pExpr->tokenId == TK_SET));
+}
+
+bool tSqlExprIsParentOfLeaf(tSqlExpr *pExpr) {
+ return (pExpr->pLeft != NULL && pExpr->pRight != NULL) &&
+ (tSqlExprIsLeaf(pExpr->pLeft) && tSqlExprIsLeaf(pExpr->pRight));
+}
+
+static void doDestroySqlExprNode(tSqlExpr *pExpr) {
+ if (pExpr == NULL) {
+ return;
+ }
+
+ taosVariantDestroy(&pExpr->value);
+ tSqlExprListDestroy(pExpr->Expr.paramList);
+ free(pExpr);
+}
+
+void tSqlExprDestroy(tSqlExpr *pExpr) {
+ if (pExpr == NULL) {
+ return;
+ }
+
+ tSqlExprDestroy(pExpr->pLeft);
+ pExpr->pLeft = NULL;
+ tSqlExprDestroy(pExpr->pRight);
+ pExpr->pRight = NULL;
+
+ doDestroySqlExprNode(pExpr);
+}
+
+SArray * tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SToken *pDistinct, SToken *pToken) {
+
+ if (pList == NULL) {
+ pList = taosArrayInit(4, sizeof(tSqlExprItem));
+ }
+
+ if (pNode || pToken) {
+ struct tSqlExprItem item = {0};
+
+ item.pNode = pNode;
+ item.distinct = (pDistinct != NULL);
+
+ if (pToken) { // set the as clause
+ item.aliasName = malloc(pToken->n + 1);
+ strncpy(item.aliasName, pToken->z, pToken->n);
+ item.aliasName[pToken->n] = 0;
+
+ strdequote(item.aliasName);
+ }
+
+ taosArrayPush(pList, &item);
+ }
+
+ return pList;
+}
+
+static void freeExprElem(void* item) {
+ tSqlExprItem* exprItem = item;
+
+ tfree(exprItem->aliasName);
+ tSqlExprDestroy(exprItem->pNode);
+}
+
+void tSqlExprListDestroy(SArray *pList) {
+ if (pList == NULL) {
+ return;
+ }
+ taosArrayDestroyEx(pList, freeExprElem);
+}
SSqlNode *tSetQuerySqlNode(SToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere,
- SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps,
- SWindowStateVal *pw, SToken *pSliding, SArray *pFill, SLimit *pLimit, SLimit *pgLimit, tSqlExpr *pHaving);
-int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right);
+ SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
+ SSessionWindowVal *pSession, SWindowStateVal *pWindowStateVal, SToken *pSliding, SArray *pFill, SLimit *pLimit,
+ SLimit *psLimit, tSqlExpr *pHaving) {
+ assert(pSelNodeList != NULL);
-SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type);
+ SSqlNode *pSqlNode = calloc(1, sizeof(SSqlNode));
-SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type,
- int16_t tableTable);
-SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
- SToken *igExists);
+ // all later sql string are belonged to the stream sql
+ pSqlNode->sqlstr = *pSelectToken;
+ pSqlNode->sqlstr.n = (uint32_t)strlen(pSqlNode->sqlstr.z);
-void destroyAllSqlNode(SArray *pSqlNode);
-void destroySqlNode(SSqlNode *pSql);
-void freeCreateTableInfo(void* p);
+ pSqlNode->pSelNodeList = pSelNodeList;
+ pSqlNode->from = pFrom;
+ pSqlNode->pGroupby = pGroupby;
+ pSqlNode->pSortOrder = pSortOrder;
+ pSqlNode->pWhere = pWhere;
+ pSqlNode->fillType = pFill;
+ pSqlNode->pHaving = pHaving;
-SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, int32_t type);
-SArray *setSubclause(SArray *pList, void *pSqlNode);
-SArray *appendSelectClause(SArray *pList, void *pSubclause);
+ if (pLimit != NULL) {
+ pSqlNode->limit = *pLimit;
+ } else {
+ pSqlNode->limit.limit = -1;
+ pSqlNode->limit.offset = 0;
+ }
-void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists);
+ if (psLimit != NULL) {
+ pSqlNode->slimit = *psLimit;
+ } else {
+ pSqlNode->slimit.limit = -1;
+ pSqlNode->slimit.offset = 0;
+ }
-void SqlInfoDestroy(SSqlInfo *pInfo);
+ if (pInterval != NULL) {
+ pSqlNode->interval = *pInterval;
+ } else {
+ TPARSER_SET_NONE_TOKEN(pSqlNode->interval.interval);
+ TPARSER_SET_NONE_TOKEN(pSqlNode->interval.offset);
+ }
-void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
-void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SToken* pToken, SToken* existsCheck,int16_t dbType,int16_t tableType);
-void setShowOptions(SSqlInfo *pInfo, int32_t type, SToken* prefix, SToken* pPatterns);
+ if (pSliding != NULL) {
+ pSqlNode->sliding = *pSliding;
+ } else {
+ TPARSER_SET_NONE_TOKEN(pSqlNode->sliding);
+ }
-void setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SToken *pToken, SCreateDbInfo *pDB, SToken *pIgExists);
+ if (pSession != NULL) {
+ pSqlNode->sessionVal = *pSession;
+ } else {
+ TPARSER_SET_NONE_TOKEN(pSqlNode->sessionVal.gap);
+ TPARSER_SET_NONE_TOKEN(pSqlNode->sessionVal.col);
+ }
-void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SToken *pName, SToken *pPwd, SCreateAcctInfo *pAcctInfo);
-void setCreateUserSql(SSqlInfo *pInfo, SToken *pName, SToken *pPasswd);
-void setKillSql(SSqlInfo *pInfo, int32_t type, SToken *ip);
-void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SToken *pName, SToken* pPwd, SToken *pPrivilege);
+ if (pWindowStateVal != NULL) {
+ pSqlNode->windowstateVal = *pWindowStateVal;
+ } else {
+ TPARSER_SET_NONE_TOKEN(pSqlNode->windowstateVal.col);
+ }
-void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam);
+ return pSqlNode;
+}
-void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo);
+static FORCE_INLINE int32_t tStrTokenCompare(SToken* left, SToken* right) {
+ return (left->type == right->type && left->n == right->n && strncasecmp(left->z, right->z, left->n) == 0) ? 0 : 1;
+}
+
+int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right) {
+ if ((left == NULL && right) || (left && right == NULL) || (left == NULL && right == NULL)) {
+ return 1;
+ }
+
+ if (left->type != right->type) {
+ return 1;
+ }
+
+ if (left->tokenId != right->tokenId) {
+ return 1;
+ }
+
+ if ((left->pLeft && right->pLeft == NULL)
+ || (left->pLeft == NULL && right->pLeft)
+ || (left->pRight && right->pRight == NULL)
+ || (left->pRight == NULL && right->pRight)
+ || (left->Expr.paramList && right->Expr.paramList == NULL)
+ || (left->Expr.paramList == NULL && right->Expr.paramList)) {
+ return 1;
+ }
+
+ if (taosVariantCompare(&left->value, &right->value)) {
+ return 1;
+ }
+
+ if (tStrTokenCompare(&left->columnName, &right->columnName)) {
+ return 1;
+ }
+
+ if (right->Expr.paramList && left->Expr.paramList) {
+ size_t size = taosArrayGetSize(right->Expr.paramList);
+ if (left->Expr.paramList && taosArrayGetSize(left->Expr.paramList) != size) {
+ return 1;
+ }
+
+ for (int32_t i = 0; i < size; i++) {
+ tSqlExprItem* pLeftElem = taosArrayGet(left->Expr.paramList, i);
+ tSqlExpr* pSubLeft = pLeftElem->pNode;
+ tSqlExprItem* pRightElem = taosArrayGet(right->Expr.paramList, i);
+ tSqlExpr* pSubRight = pRightElem->pNode;
+
+ if (tSqlExprCompare(pSubLeft, pSubRight)) {
+ return 1;
+ }
+ }
+ }
+
+ if (left->pLeft && tSqlExprCompare(left->pLeft, right->pLeft)) {
+ return 1;
+ }
+
+ if (left->pRight && tSqlExprCompare(left->pRight, right->pRight)) {
+ return 1;
+ }
+
+ return 0;
+}
+
+SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type) {
+ SCreateTableSql *pCreate = calloc(1, sizeof(SCreateTableSql));
+
+ switch (type) {
+ case TSQL_CREATE_TABLE: {
+ pCreate->colInfo.pColumns = pCols;
+ assert(pTags == NULL);
+ break;
+ }
+ case TSQL_CREATE_STABLE: {
+ pCreate->colInfo.pColumns = pCols;
+ pCreate->colInfo.pTagColumns = pTags;
+ assert(pTags != NULL && pCols != NULL);
+ break;
+ }
+ case TSQL_CREATE_STREAM: {
+ pCreate->pSelect = pSelect;
+ break;
+ }
+
+ case TSQL_CREATE_CTABLE: {
+ assert(0);
+ }
+
+ default:
+ assert(false);
+ }
+
+ pCreate->type = type;
+ return pCreate;
+}
+
+SAlterTableInfo *tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType) {
+ SAlterTableInfo *pAlterTable = calloc(1, sizeof(SAlterTableInfo));
+
+ pAlterTable->name = *pTableName;
+ pAlterTable->type = type;
+ pAlterTable->tableType = tableType;
+
+ if (type == TSDB_ALTER_TABLE_ADD_COLUMN || type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN || type == TSDB_ALTER_TABLE_CHANGE_COLUMN || type == TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN) {
+ pAlterTable->pAddColumns = pCols;
+ assert(pVals == NULL);
+ } else {
+ /*
+ * ALTER_TABLE_TAGS_CHG, ALTER_TABLE_TAGS_SET, ALTER_TABLE_TAGS_DROP,
+ * ALTER_TABLE_DROP_COLUMN
+ */
+ pAlterTable->varList = pVals;
+ assert(pCols == NULL);
+ }
+
+ return pAlterTable;
+}
+SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken, SToken* igExists) {
+ SCreatedTableInfo info;
+ memset(&info, 0, sizeof(SCreatedTableInfo));
+
+ info.name = *pToken;
+ info.pTagNames = pTagNames;
+ info.pTagVals = pTagVals;
+ info.stableName = *pTableName;
+ info.igExist = (igExists->n > 0)? 1:0;
+
+ return info;
+}
+
+void destroyAllSqlNode(SArray *pList) {
+ if (pList == NULL) {
+ return;
+ }
+
+ size_t size = taosArrayGetSize(pList);
+ for(int32_t i = 0; i < size; ++i) {
+ SSqlNode *pNode = taosArrayGetP(pList, i);
+ destroySqlNode(pNode);
+ }
+
+ taosArrayDestroy(pList);
+}
+
+static void freeItem(void *pItem) {
+ SListItem* p = (SListItem*) pItem;
+ taosVariantDestroy(&p->pVar);
+}
+
+void destroySqlNode(SSqlNode *pSqlNode) {
+ if (pSqlNode == NULL) {
+ return;
+ }
+
+ tSqlExprListDestroy(pSqlNode->pSelNodeList);
+ pSqlNode->pSelNodeList = NULL;
+
+ tSqlExprDestroy(pSqlNode->pWhere);
+ pSqlNode->pWhere = NULL;
+
+ taosArrayDestroyEx(pSqlNode->pSortOrder, freeItem);
+ pSqlNode->pSortOrder = NULL;
+
+ taosArrayDestroyEx(pSqlNode->pGroupby, freeItem);
+ pSqlNode->pGroupby = NULL;
+
+ pSqlNode->from = destroyRelationInfo(pSqlNode->from);
+
+ taosArrayDestroyEx(pSqlNode->fillType, freeItem);
+ pSqlNode->fillType = NULL;
+
+ tSqlExprDestroy(pSqlNode->pHaving);
+ free(pSqlNode);
+}
+
+void freeCreateTableInfo(void* p) {
+ SCreatedTableInfo* pInfo = (SCreatedTableInfo*) p;
+ taosArrayDestroy(pInfo->pTagNames);
+ taosArrayDestroyEx(pInfo->pTagVals, freeItem);
+ tfree(pInfo->fullname);
+ tfree(pInfo->tagdata.data);
+}
+
+SSqlInfo* setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, int32_t type) {
+ pInfo->type = type;
+
+ if (type == TSDB_SQL_SELECT) {
+ pInfo->list = (SArray*) pSqlExprInfo;
+ } else {
+ pInfo->pCreateTableInfo = pSqlExprInfo;
+ }
+
+ if (pTableName != NULL) {
+ pInfo->pCreateTableInfo->name = *pTableName;
+ }
+
+ return pInfo;
+}
+SArray* setSubclause(SArray* pList, void *pSqlNode) {
+ if (pList == NULL) {
+ pList = taosArrayInit(1, POINTER_BYTES);
+ }
+
+ taosArrayPush(pList, &pSqlNode);
+ return pList;
+}
+SArray* appendSelectClause(SArray *pList, void *pSubclause) {
+ taosArrayPush(pList, &pSubclause);
+ return pList;
+}
+
+void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists) {
+ pInfo->pCreateTableInfo->name = *pTableNameToken;
+ pInfo->pCreateTableInfo->existCheck = (pIfNotExists->n != 0);
+}
+
+void* destroyCreateTableSql(SCreateTableSql* pCreate) {
+ destroySqlNode(pCreate->pSelect);
+
+ taosArrayDestroy(pCreate->colInfo.pColumns);
+ taosArrayDestroy(pCreate->colInfo.pTagColumns);
+
+ taosArrayDestroyEx(pCreate->childTableInfo, freeCreateTableInfo);
+ tfree(pCreate);
+
+ return NULL;
+}
+
+void SqlInfoDestroy(SSqlInfo *pInfo) {
+ if (pInfo == NULL) return;;
+ taosArrayDestroy(pInfo->funcs);
+ if (pInfo->type == TSDB_SQL_SELECT) {
+ destroyAllSqlNode(pInfo->list);
+ } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) {
+ pInfo->pCreateTableInfo = destroyCreateTableSql(pInfo->pCreateTableInfo);
+ } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) {
+ taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeItem);
+ taosArrayDestroy(pInfo->pAlterInfo->pAddColumns);
+ tfree(pInfo->pAlterInfo->tagData.data);
+ tfree(pInfo->pAlterInfo);
+ } else if (pInfo->type == TSDB_SQL_COMPACT_VNODE) {
+ tSqlExprListDestroy(pInfo->list);
+ } else {
+ if (pInfo->pMiscInfo != NULL) {
+ taosArrayDestroy(pInfo->pMiscInfo->a);
+ }
+
+ if (pInfo->pMiscInfo != NULL && (pInfo->type == TSDB_SQL_CREATE_DB || pInfo->type == TSDB_SQL_ALTER_DB)) {
+ taosArrayDestroyEx(pInfo->pMiscInfo->dbOpt.keep, freeItem);
+ }
+
+ tfree(pInfo->pMiscInfo);
+ }
+}
+
+void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
+ pInfo->type = type;
+ if (nParam == 0) {
+ return;
+ }
+
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = (SMiscInfo *)calloc(1, sizeof(SMiscInfo));
+ pInfo->pMiscInfo->a = taosArrayInit(4, sizeof(SToken));
+ }
+
+ va_list va;
+ va_start(va, nParam);
+
+ while ((nParam--) > 0) {
+ SToken *pToken = va_arg(va, SToken *);
+ taosArrayPush(pInfo->pMiscInfo->a, pToken);
+ }
+
+ va_end(va);
+}
+void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SToken* pToken, SToken* existsCheck, int16_t dbType, int16_t tableType) {
+ pInfo->type = type;
+
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = (SMiscInfo *)calloc(1, sizeof(SMiscInfo));
+ pInfo->pMiscInfo->a = taosArrayInit(4, sizeof(SToken));
+ }
+
+ taosArrayPush(pInfo->pMiscInfo->a, pToken);
+
+ pInfo->pMiscInfo->existsCheck = (existsCheck->n == 1);
+ pInfo->pMiscInfo->dbType = dbType;
+ pInfo->pMiscInfo->tableType = tableType;
+}
+void setShowOptions(SSqlInfo *pInfo, int32_t type, SToken* prefix, SToken* pPatterns) {
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
+ }
+
+ pInfo->type = TSDB_SQL_SHOW;
+
+ SShowInfo* pShowInfo = &pInfo->pMiscInfo->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 setCreateDbInfo(SSqlInfo *pInfo, int32_t type, SToken *pToken, SCreateDbInfo *pDB, SToken *pIgExists) {
+ pInfo->type = type;
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
+ }
+
+ pInfo->pMiscInfo->dbOpt = *pDB;
+ pInfo->pMiscInfo->dbOpt.dbname = *pToken;
+ pInfo->pMiscInfo->dbOpt.ignoreExists = pIgExists->n; // sql.y has: ifnotexists(X) ::= IF NOT EXISTS. {X.n = 1;}
+}
+
+void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SToken *pName, SToken *pPwd, SCreateAcctInfo *pAcctInfo) {
+ pInfo->type = type;
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
+ }
+
+ pInfo->pMiscInfo->acctOpt = *pAcctInfo;
+
+ assert(pName != NULL);
+ pInfo->pMiscInfo->user.user = *pName;
+
+ if (pPwd != NULL) {
+ pInfo->pMiscInfo->user.passwd = *pPwd;
+ }
+}
+void setCreateUserSql(SSqlInfo *pInfo, SToken *pName, SToken *pPasswd) {
+ pInfo->type = TSDB_SQL_CREATE_USER;
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
+ }
+
+ assert(pName != NULL && pPasswd != NULL);
+
+ pInfo->pMiscInfo->user.user = *pName;
+ pInfo->pMiscInfo->user.passwd = *pPasswd;
+}
+void setKillSql(SSqlInfo *pInfo, int32_t type, SToken *id) {
+ pInfo->type = type;
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
+ }
+
+ assert(id != NULL);
+ pInfo->pMiscInfo->id = *id;
+}
+
+void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SToken *pName, SToken* pPwd, SToken *pPrivilege) {
+ pInfo->type = TSDB_SQL_ALTER_USER;
+ if (pInfo->pMiscInfo == NULL) {
+ pInfo->pMiscInfo = calloc(1, sizeof(SMiscInfo));
+ }
+
+ assert(pName != NULL);
+
+ SUserInfo* pUser = &pInfo->pMiscInfo->user;
+ pUser->type = type;
+ pUser->user = *pName;
+
+ if (pPwd != NULL) {
+ pUser->passwd = *pPwd;
+ } else {
+ pUser->passwd.type = TSDB_DATA_TYPE_NULL;
+ }
+
+ if (pPrivilege != NULL) {
+ pUser->privilege = *pPrivilege;
+ } else {
+ pUser->privilege.type = TSDB_DATA_TYPE_NULL;
+ }
+}
+
+void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam) {
+ pInfo->type = type;
+ pInfo->list = pParam;
+}
+
+void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) {
+ pDBInfo->compressionLevel = -1;
+
+ pDBInfo->walLevel = -1;
+ pDBInfo->fsyncPeriod = -1;
+ pDBInfo->commitTime = -1;
+ pDBInfo->maxTablesPerVnode = -1;
+
+ pDBInfo->cacheBlockSize = -1;
+ pDBInfo->numOfBlocks = -1;
+ pDBInfo->maxRowsPerBlock = -1;
+ pDBInfo->minRowsPerBlock = -1;
+ pDBInfo->daysPerFile = -1;
+
+ pDBInfo->replica = -1;
+ pDBInfo->quorum = -1;
+ pDBInfo->keep = NULL;
+
+ pDBInfo->update = -1;
+ pDBInfo->cachelast = -1;
+
+ pDBInfo->dbType = -1;
+ pDBInfo->partitions = -1;
+
+ memset(&pDBInfo->precision, 0, sizeof(SToken));
+}
void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo);
// prefix show db.tables;
-void tSetDbName(SToken *pCpxName, SToken *pDb);
+void tSetDbName(SToken *pCpxName, SToken *pDb) {
+ pCpxName->type = pDb->type;
+ pCpxName->z = pDb->z;
+ pCpxName->n = pDb->n;
+}
-void tSetColumnInfo(struct SField *pField, SToken *pName, struct SField *pType);
-void tSetColumnType(struct SField *pField, SToken *type);
+void tSetColumnInfo(SField *pField, SToken *pName, SField *pType) {
+ int32_t maxLen = sizeof(pField->name) / sizeof(pField->name[0]);
-/**
- *
- * @param yyp The parser
- * @param yymajor The major token code number
- * @param yyminor The value for the token
- */
-void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
+ // column name is too long, set the it to be invalid.
+ if ((int32_t) pName->n >= maxLen) {
+ pName->n = -1;
+ } else {
+ strncpy(pField->name, pName->z, pName->n);
+ pField->name[pName->n] = 0;
+ }
-/**
- *
- * @param p The parser to be deleted
- * @param freeProc Function used to reclaim memory
- */
-void ParseFree(void *p, void (*freeProc)(void *));
+ pField->type = pType->type;
+ if(!isValidDataType(pField->type)){
+ pField->bytes = 0;
+ } else {
+ pField->bytes = pType->bytes;
+ }
+}
-/**
- *
- * @param mallocProc The parser allocator
- * @return
- */
-void *ParseAlloc(void *(*mallocProc)(size_t));
+static int32_t tryParseNameTwoParts(SToken *type) {
+ int32_t t = -1;
-SSqlInfo genAST(const char *pStr) {
+ char* str = strndup(type->z, type->n);
+ if (str == NULL) {
+ return t;
+ }
+
+ char* p = strtok(str, " ");
+ if (p == NULL) {
+ tfree(str);
+ return t;
+ } else {
+ char* unsign = strtok(NULL, " ");
+ if (unsign == NULL) {
+ tfree(str);
+ return t;
+ }
+
+ if (strncasecmp(unsign, "UNSIGNED", 8) == 0) {
+ for(int32_t j = TSDB_DATA_TYPE_TINYINT; j <= TSDB_DATA_TYPE_BIGINT; ++j) {
+ if (strcasecmp(p, tDataTypes[j].name) == 0) {
+ t = j;
+ break;
+ }
+ }
+
+ tfree(str);
+
+ if (t == -1) {
+ return -1;
+ }
+
+ switch(t) {
+ case TSDB_DATA_TYPE_TINYINT: return TSDB_DATA_TYPE_UTINYINT;
+ case TSDB_DATA_TYPE_SMALLINT: return TSDB_DATA_TYPE_USMALLINT;
+ case TSDB_DATA_TYPE_INT: return TSDB_DATA_TYPE_UINT;
+ case TSDB_DATA_TYPE_BIGINT: return TSDB_DATA_TYPE_UBIGINT;
+ default:
+ return -1;
+ }
+
+ } else {
+ tfree(str);
+ return -1;
+ }
+ }
+}
+
+void tSetColumnType(SField *pField, SToken *type) {
+ // set the field type invalid
+ pField->type = -1;
+ pField->name[0] = 0;
+
+ int32_t i = 0;
+ while (i < tListLen(tDataTypes)) {
+ if ((type->n == tDataTypes[i].nameLen) &&
+ (strncasecmp(type->z, tDataTypes[i].name, tDataTypes[i].nameLen) == 0)) {
+ break;
+ }
+
+ i += 1;
+ }
+
+ // no qualified data type found, try unsigned data type
+ if (i == tListLen(tDataTypes)) {
+ i = tryParseNameTwoParts(type);
+ if (i == -1) {
+ return;
+ }
+ }
+
+ pField->type = i;
+ pField->bytes = tDataTypes[i].bytes;
+
+ if (i == TSDB_DATA_TYPE_NCHAR) {
+ /*
+ * for nchar, the TOKENTYPE is the number of character, so the length is the
+ * number of bytes in UCS-4 format, which is 4 times larger than the number of characters
+ */
+ if (type->type == 0) {
+ pField->bytes = 0;
+ } else {
+ int32_t bytes = -(int32_t)(type->type);
+ if (bytes > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
+ // overflowed. set bytes to -1 so that error can be reported
+ bytes = -1;
+ } else {
+ bytes = bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
+ }
+ pField->bytes = (int16_t)bytes;
+ }
+ } else if (i == TSDB_DATA_TYPE_BINARY) {
+ /* for binary, the TOKENTYPE is the length of binary */
+ if (type->type == 0) {
+ pField->bytes = 0;
+ } else {
+ int32_t bytes = -(int32_t)(type->type);
+ if (bytes > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
+ // overflowed. set bytes to -1 so that error can be reported
+ bytes = -1;
+ } else {
+ bytes += VARSTR_HEADER_SIZE;
+ }
+
+ pField->bytes = (int16_t)bytes;
+ }
+ }
+}
+
+SSqlInfo doGenerateAST(const char *pStr) {
void *pParser = ParseAlloc(malloc);
SSqlInfo sqlInfo = {0};
-
sqlInfo.valid = true;
sqlInfo.funcs = taosArrayInit(4, sizeof(SToken));
diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c
index be1d93ecf8..45215d7866 100644
--- a/source/libs/parser/src/parser.c
+++ b/source/libs/parser/src/parser.c
@@ -21,13 +21,13 @@ bool qIsInsertSql(const char* pStr, size_t length) {
return false;
}
-int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo** pQueryInfo, int64_t id, char* msg) {
+int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo** pQueryInfo, int64_t id, char* msg, int32_t msgLen) {
*pQueryInfo = calloc(1, sizeof(SQueryStmtInfo));
if (*pQueryInfo == NULL) {
return -1; // set correct error code.
}
- SSqlInfo info = genAST(pStr);
+ SSqlInfo info = doGenerateAST(pStr);
if (!info.valid) {
strcpy(msg, info.msg);
return -1; // set correct error code.
@@ -42,7 +42,7 @@ int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo**
return 0;
}
-int32_t qParseInsertSql(const char* pStr, size_t length, struct SInsertStmtInfo** pInsertInfo, int64_t id, char* msg) {
+int32_t qParseInsertSql(const char* pStr, size_t length, struct SInsertStmtInfo** pInsertInfo, int64_t id, char* msg, int32_t msgLen) {
return 0;
}
diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h
index cc49728e35..653c7770ef 100644
--- a/src/client/inc/tsclient.h
+++ b/src/client/inc/tsclient.h
@@ -36,7 +36,7 @@ extern "C" {
#include "qSqlparser.h"
#include "qTsbuf.h"
#include "qUtil.h"
-#include "tcmdtype.h"
+#include "tmsgtype.h"
typedef enum {
TAOS_REQ_FROM_SHELL,
diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c
index 7f57c7d5c9..308898950a 100644
--- a/src/client/src/tscServer.c
+++ b/src/client/src/tscServer.c
@@ -17,8 +17,8 @@
#include "os.h"
#include "qPlan.h"
#include "qTableMeta.h"
-#include "tcmdtype.h"
#include "tlockfree.h"
+#include "tmsgtype.h"
#include "trpc.h"
#include "tscGlobalmerge.h"
#include "tscLog.h"
diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y
index 336e8620f2..800ee03441 100644
--- a/src/query/inc/sql.y
+++ b/src/query/inc/sql.y
@@ -259,7 +259,7 @@ acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K
intitemlist(A) ::= intitemlist(X) COMMA intitem(Y). { A = tVariantListAppend(X, &Y, -1); }
intitemlist(A) ::= intitem(X). { A = tVariantListAppend(NULL, &X, -1); }
-intitem(A) ::= INTEGER(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
+intitem(A) ::= INTEGER(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
%type keep {SArray*}
%destructor keep {taosArrayDestroy($$);}
@@ -444,39 +444,39 @@ column(A) ::= ids(X) typename(Y). {
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); }
tagitemlist(A) ::= tagitem(X). { A = tVariantListAppend(NULL, &X, -1); }
-tagitem(A) ::= INTEGER(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
-tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
-tagitem(A) ::= STRING(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
-tagitem(A) ::= BOOL(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
-tagitem(A) ::= NULL(X). { X.type = 0; tVariantCreate(&A, &X); }
-tagitem(A) ::= NOW(X). { X.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&A, &X);}
+tagitem(A) ::= INTEGER(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
+tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
+tagitem(A) ::= STRING(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
+tagitem(A) ::= BOOL(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
+tagitem(A) ::= NULL(X). { X.type = 0; taosVariantCreate(&A, &X); }
+tagitem(A) ::= NOW(X). { X.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&A, &X);}
tagitem(A) ::= MINUS(X) INTEGER(Y).{
X.n += Y.n;
X.type = Y.type;
toTSDBType(X.type);
- tVariantCreate(&A, &X);
+ taosVariantCreate(&A, &X);
}
tagitem(A) ::= MINUS(X) FLOAT(Y). {
X.n += Y.n;
X.type = Y.type;
toTSDBType(X.type);
- tVariantCreate(&A, &X);
+ taosVariantCreate(&A, &X);
}
tagitem(A) ::= PLUS(X) INTEGER(Y). {
X.n += Y.n;
X.type = Y.type;
toTSDBType(X.type);
- tVariantCreate(&A, &X);
+ taosVariantCreate(&A, &X);
}
tagitem(A) ::= PLUS(X) FLOAT(Y). {
X.n += Y.n;
X.type = Y.type;
toTSDBType(X.type);
- tVariantCreate(&A, &X);
+ taosVariantCreate(&A, &X);
}
//////////////////////// The SELECT statement /////////////////////////////////
@@ -599,7 +599,7 @@ fill_opt(N) ::= . { N = 0; }
fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP. {
tVariant A = {0};
toTSDBType(Y.type);
- tVariantCreate(&A, &Y);
+ taosVariantCreate(&A, &Y);
tVariantListInsert(X, &A, -1, 0);
N = X;
@@ -639,7 +639,7 @@ item(A) ::= ids(X) cpxName(Y). {
toTSDBType(X.type);
X.n += Y.n;
- tVariantCreate(&A, &X);
+ taosVariantCreate(&A, &X);
}
%type sortorder {int}
@@ -719,7 +719,7 @@ expr(A) ::= BOOL(X). { A = tSqlExprCreateIdValue(&X, TK_BOOL);}
expr(A) ::= NULL(X). { A = tSqlExprCreateIdValue(&X, TK_NULL);}
// ordinary functions: min(x), max(x), top(k, 20)
-expr(A) ::= ID(X) LP exprlist(Y) RP(E). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(Y, &X, &E, X.type); }
+expr(A) ::= ID(X) LP exprlist(Y) RP(E). { (pInfo->funcs, &X); A = tSqlExprCreateFunction(Y, &X, &E, X.type); }
// for parsing sql functions with wildcard for parameters. e.g., count(*)/first(*)/last(*) operation
expr(A) ::= ID(X) LP STAR RP(Y). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(NULL, &X, &Y, X.type); }
diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c
index d156230efb..c6c5690b2c 100644
--- a/src/query/src/qSqlParser.c
+++ b/src/query/src/qSqlParser.c
@@ -17,7 +17,7 @@
#include "os.h"
#include "taosdef.h"
#include "taosmsg.h"
-#include "tcmdtype.h"
+#include "tmsgtype.h"
#include "tstrbuild.h"
#include "ttoken.h"
#include "ttokendef.h"
diff --git a/src/query/src/sql.c b/src/query/src/sql.c
index e89b6232f7..4fe3e860a6 100644
--- a/src/query/src/sql.c
+++ b/src/query/src/sql.c
@@ -27,13 +27,13 @@
/************ Begin %include sections from the grammar ************************/
#line 23 "sql.y"
+#include
+#include
#include
#include
#include
-#include
-#include
#include "qSqlparser.h"
-#include "tcmdtype.h"
+#include "tmsgtype.h"
#include "ttoken.h"
#include "ttokendef.h"
#include "tutil.h"