[td-10529]fix compiler error.
This commit is contained in:
parent
36ccd8279c
commit
77094cc5ab
|
@ -24,7 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
#ifdef TSDB_SQL_C
|
#ifdef TSDB_SQL_C
|
||||||
#define TSDB_DEFINE_SQL_TYPE( name, msg ) msg,
|
#define TSDB_DEFINE_SQL_TYPE( name, msg ) msg,
|
||||||
char *sqlCmd[] = {
|
char *sqlMsgType[] = {
|
||||||
"null",
|
"null",
|
||||||
#else
|
#else
|
||||||
#define TSDB_DEFINE_SQL_TYPE( name, msg ) name,
|
#define TSDB_DEFINE_SQL_TYPE( name, msg ) name,
|
||||||
|
@ -103,15 +103,13 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
// create table operation type
|
// create table operation type
|
||||||
enum TSQL_TYPE {
|
enum TSQL_CREATE_TABLE_TYPE {
|
||||||
TSQL_CREATE_TABLE = 0x1,
|
TSQL_CREATE_TABLE = 0x1,
|
||||||
TSQL_CREATE_STABLE = 0x2,
|
TSQL_CREATE_STABLE = 0x2,
|
||||||
TSQL_CREATE_TABLE_FROM_STABLE = 0x3,
|
TSQL_CREATE_CTABLE = 0x3,
|
||||||
TSQL_CREATE_STREAM = 0x4,
|
TSQL_CREATE_STREAM = 0x4,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char *sqlCmd[];
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -38,7 +38,7 @@ typedef struct SVariant {
|
||||||
|
|
||||||
bool taosVariantIsValid(SVariant *pVar);
|
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);
|
void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type);
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ bool qIsInsertSql(const char* pStr, size_t length);
|
||||||
* @param msg extended error message if exists.
|
* @param msg extended error message if exists.
|
||||||
* @return error code
|
* @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.
|
* 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.
|
* @param msg extended error message if exists to help avoid the problem in sql statement.
|
||||||
* @return
|
* @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
|
* 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
|
||||||
|
|
|
@ -15,4 +15,4 @@
|
||||||
|
|
||||||
#define TSDB_SQL_C
|
#define TSDB_SQL_C
|
||||||
|
|
||||||
#include "tcmdtype.h"
|
#include "tmsgtype.h"
|
||||||
|
|
|
@ -29,18 +29,16 @@
|
||||||
if ((res) > (maxv)) { *exti = 1; break; } \
|
if ((res) > (maxv)) { *exti = 1; break; } \
|
||||||
assert(0); \
|
assert(0); \
|
||||||
} while (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));
|
memset(pVar, 0, sizeof(SVariant));
|
||||||
|
|
||||||
switch (token->type) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_BOOL: {
|
case TSDB_DATA_TYPE_BOOL: {
|
||||||
if (strncasecmp(token->z, "true", 4) == 0) {
|
if (strncasecmp(z, "true", 4) == 0) {
|
||||||
pVar->i64 = TSDB_TRUE;
|
pVar->i64 = TSDB_TRUE;
|
||||||
} else if (strncasecmp(token->z, "false", 5) == 0) {
|
} else if (strncasecmp(z, "false", 5) == 0) {
|
||||||
pVar->i64 = TSDB_FALSE;
|
pVar->i64 = TSDB_FALSE;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -53,35 +51,35 @@ void tVariantCreate(SVariant *pVar, SToken *token) {
|
||||||
case TSDB_DATA_TYPE_SMALLINT:
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDB_DATA_TYPE_BIGINT:
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
case TSDB_DATA_TYPE_INT:{
|
case TSDB_DATA_TYPE_INT:{
|
||||||
ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, true);
|
// ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, true);
|
||||||
if (ret != 0) {
|
// if (ret != 0) {
|
||||||
SToken t = {0};
|
// SToken t = {0};
|
||||||
tGetToken(token->z, &t.type);
|
// 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
|
// 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
|
// pVar->nType = -1; // -1 means error type
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// data overflow, try unsigned parse the input number
|
// // data overflow, try unsigned parse the input number
|
||||||
ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, false);
|
// ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, false);
|
||||||
if (ret != 0) {
|
// if (ret != 0) {
|
||||||
pVar->nType = -1; // -1 means error type
|
// pVar->nType = -1; // -1 means error type
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_DOUBLE:
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDB_DATA_TYPE_FLOAT: {
|
case TSDB_DATA_TYPE_FLOAT: {
|
||||||
pVar->d = strtod(token->z, NULL);
|
pVar->d = strtod(z, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BINARY: {
|
case TSDB_DATA_TYPE_BINARY: {
|
||||||
pVar->pz = strndup(token->z, token->n);
|
pVar->pz = strndup(z, n);
|
||||||
pVar->nLen = strRmquote(pVar->pz, token->n);
|
pVar->nLen = strRmquote(pVar->pz, n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
|
@ -96,7 +94,7 @@ void tVariantCreate(SVariant *pVar, SToken *token) {
|
||||||
|
|
||||||
pVar->nType = type;
|
pVar->nType = type;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create SVariant from binary string, not ascii data
|
* create SVariant from binary string, not ascii data
|
||||||
|
@ -105,7 +103,7 @@ void tVariantCreate(SVariant *pVar, SToken *token) {
|
||||||
* @param len
|
* @param len
|
||||||
* @param type
|
* @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) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_BOOL:
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDB_DATA_TYPE_TINYINT: {
|
case TSDB_DATA_TYPE_TINYINT: {
|
||||||
|
@ -183,7 +181,7 @@ void tVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32
|
||||||
pVar->nType = type;
|
pVar->nType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tVariantDestroy(SVariant *pVar) {
|
void taosVariantDestroy(SVariant *pVar) {
|
||||||
if (pVar == NULL) return;
|
if (pVar == NULL) return;
|
||||||
|
|
||||||
if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) {
|
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);
|
assert(pVar != NULL);
|
||||||
return isValidDataType(pVar->nType);
|
return isValidDataType(pVar->nType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tVariantAssign(SVariant *pDst, const SVariant *pSrc) {
|
void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) {
|
||||||
if (pSrc == NULL || pDst == NULL) return;
|
if (pSrc == NULL || pDst == NULL) return;
|
||||||
|
|
||||||
pDst->nType = pSrc->nType;
|
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) {
|
if (p1->nType == TSDB_DATA_TYPE_NULL && p2->nType == TSDB_DATA_TYPE_NULL) {
|
||||||
return 0;
|
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;
|
if (pVar == NULL || dst == NULL) return 0;
|
||||||
|
|
||||||
switch (pVar->nType) {
|
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
|
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
|
||||||
* to column type defined in schema
|
* 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);
|
return tVariantDumpEx(pVariant, payload, type, includeLengthPrefix, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -974,4 +972,4 @@ int32_t tVariantTypeSetType(SVariant *pVariant, char type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -117,7 +117,7 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
|
||||||
if (pNode->nodeType == TSQL_NODE_EXPR) {
|
if (pNode->nodeType == TSQL_NODE_EXPR) {
|
||||||
doExprTreeDestroy(&pNode, fp);
|
doExprTreeDestroy(&pNode, fp);
|
||||||
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
|
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
|
||||||
tVariantDestroy(pNode->pVal);
|
taosVariantDestroy(pNode->pVal);
|
||||||
} else if (pNode->nodeType == TSQL_NODE_COL) {
|
} else if (pNode->nodeType == TSQL_NODE_COL) {
|
||||||
tfree(pNode->pSchema);
|
tfree(pNode->pSchema);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
|
||||||
fp((*pExpr)->_node.info);
|
fp((*pExpr)->_node.info);
|
||||||
}
|
}
|
||||||
} else if ((*pExpr)->nodeType == TSQL_NODE_VALUE) {
|
} else if ((*pExpr)->nodeType == TSQL_NODE_VALUE) {
|
||||||
tVariantDestroy((*pExpr)->pVal);
|
taosVariantDestroy((*pExpr)->pVal);
|
||||||
free((*pExpr)->pVal);
|
free((*pExpr)->pVal);
|
||||||
} else if ((*pExpr)->nodeType == TSQL_NODE_COL) {
|
} else if ((*pExpr)->nodeType == TSQL_NODE_COL) {
|
||||||
free((*pExpr)->pSchema);
|
free((*pExpr)->pSchema);
|
||||||
|
@ -492,8 +492,8 @@ void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) {
|
||||||
uint32_t type = tbufReadUint32(&br);
|
uint32_t type = tbufReadUint32(&br);
|
||||||
SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false);
|
SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false);
|
||||||
|
|
||||||
taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type));
|
// taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type));
|
||||||
|
|
||||||
int dummy = -1;
|
int dummy = -1;
|
||||||
int32_t sz = tbufReadInt32(&br);
|
int32_t sz = tbufReadInt32(&br);
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
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);
|
uint32_t sType = tbufReadUint32(&br);
|
||||||
SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(tType), true, false);
|
SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(tType), true, false);
|
||||||
|
|
||||||
taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(tType));
|
// taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(tType));
|
||||||
|
|
||||||
int dummy = -1;
|
int dummy = -1;
|
||||||
SVariant tmpVar = {0};
|
SVariant tmpVar = {0};
|
||||||
|
@ -603,7 +603,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tVariantCreateFromBinary(&tmpVar, (char *)pvar, t, sType);
|
taosVariantCreateFromBinary(&tmpVar, (char *)pvar, t, sType);
|
||||||
|
|
||||||
if (bufLen < t) {
|
if (bufLen < t) {
|
||||||
tmp = realloc(tmp, t * TSDB_NCHAR_SIZE);
|
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));
|
taosHashPut(pObj, (char *)pvar, t, &dummy, sizeof(dummy));
|
||||||
tVariantDestroy(&tmpVar);
|
taosVariantDestroy(&tmpVar);
|
||||||
memset(&tmpVar, 0, sizeof(tmpVar));
|
memset(&tmpVar, 0, sizeof(tmpVar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,7 +694,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t
|
||||||
pObj = NULL;
|
pObj = NULL;
|
||||||
|
|
||||||
err_ret:
|
err_ret:
|
||||||
tVariantDestroy(&tmpVar);
|
taosVariantDestroy(&tmpVar);
|
||||||
taosHashCleanup(pObj);
|
taosHashCleanup(pObj);
|
||||||
tfree(tmp);
|
tfree(tmp);
|
||||||
}
|
}
|
||||||
|
@ -716,7 +716,7 @@ tExprNode* exprdup(tExprNode* pNode) {
|
||||||
pCloned->_node.hasPK = pNode->_node.hasPK;
|
pCloned->_node.hasPK = pNode->_node.hasPK;
|
||||||
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
|
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
|
||||||
pCloned->pVal = calloc(1, sizeof(SVariant));
|
pCloned->pVal = calloc(1, sizeof(SVariant));
|
||||||
tVariantAssign(pCloned->pVal, pNode->pVal);
|
taosVariantAssign(pCloned->pVal, pNode->pVal);
|
||||||
} else if (pNode->nodeType == TSQL_NODE_COL) {
|
} else if (pNode->nodeType == TSQL_NODE_COL) {
|
||||||
pCloned->pSchema = calloc(1, sizeof(SSchema));
|
pCloned->pSchema = calloc(1, sizeof(SSchema));
|
||||||
*pCloned->pSchema = *pNode->pSchema;
|
*pCloned->pSchema = *pNode->pSchema;
|
||||||
|
|
|
@ -285,8 +285,7 @@ int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right);
|
||||||
|
|
||||||
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type);
|
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type);
|
||||||
|
|
||||||
SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type,
|
SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType);
|
||||||
int16_t tableTable);
|
|
||||||
SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
|
SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
|
||||||
SToken *igExists);
|
SToken *igExists);
|
||||||
|
|
||||||
|
@ -299,6 +298,7 @@ SArray *setSubclause(SArray *pList, void *pSqlNode);
|
||||||
SArray *appendSelectClause(SArray *pList, void *pSubclause);
|
SArray *appendSelectClause(SArray *pList, void *pSubclause);
|
||||||
|
|
||||||
void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists);
|
void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists);
|
||||||
|
void* destroyCreateTableSql(SCreateTableSql* pCreate);
|
||||||
|
|
||||||
void SqlInfoDestroy(SSqlInfo *pInfo);
|
void SqlInfoDestroy(SSqlInfo *pInfo);
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ void *ParseAlloc(void *(*mallocProc)(size_t));
|
||||||
* @param str sql string
|
* @param str sql string
|
||||||
* @return sql ast
|
* @return sql ast
|
||||||
*/
|
*/
|
||||||
SSqlInfo genAST(const char *str);
|
SSqlInfo doGenerateAST(const char *str);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,10 @@
|
||||||
* 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 "astGenerator.h"
|
#include "taos.h"
|
||||||
#include "../../../../include/client/taos.h"
|
|
||||||
#include "os.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) {
|
int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -104,7 +105,8 @@ SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrd
|
||||||
|
|
||||||
if (pAliasToken) {
|
if (pAliasToken) {
|
||||||
SListItem item;
|
SListItem item;
|
||||||
taosVariantCreate(&item.pVar, pAliasToken);
|
assert(0);
|
||||||
|
// taosVariantCreate(&item.pVar, pAliasToken);
|
||||||
item.sortOrder = sortOrder;
|
item.sortOrder = sortOrder;
|
||||||
|
|
||||||
taosArrayPush(pList, &item);
|
taosArrayPush(pList, &item);
|
||||||
|
@ -371,87 +373,755 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
|
||||||
return pExpr;
|
return pExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
tSqlExpr *tSqlExprClone(tSqlExpr *pSrc);
|
tSqlExpr *tSqlExprClone(tSqlExpr *pSrc) {
|
||||||
void tSqlExprCompact(tSqlExpr **pExpr);
|
tSqlExpr *pExpr = malloc(sizeof(tSqlExpr));
|
||||||
bool tSqlExprIsLeaf(tSqlExpr *pExpr);
|
memcpy(pExpr, pSrc, sizeof(*pSrc));
|
||||||
bool tSqlExprIsParentOfLeaf(tSqlExpr *pExpr);
|
|
||||||
void tSqlExprDestroy(tSqlExpr *pExpr);
|
if (pSrc->pLeft) {
|
||||||
SArray * tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SToken *pDistinct, SToken *pToken);
|
pExpr->pLeft = tSqlExprClone(pSrc->pLeft);
|
||||||
void tSqlExprListDestroy(SArray *pList);
|
}
|
||||||
|
|
||||||
|
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,
|
SSqlNode *tSetQuerySqlNode(SToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere,
|
||||||
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps,
|
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
|
||||||
SWindowStateVal *pw, SToken *pSliding, SArray *pFill, SLimit *pLimit, SLimit *pgLimit, tSqlExpr *pHaving);
|
SSessionWindowVal *pSession, SWindowStateVal *pWindowStateVal, SToken *pSliding, SArray *pFill, SLimit *pLimit,
|
||||||
int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right);
|
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,
|
// all later sql string are belonged to the stream sql
|
||||||
int16_t tableTable);
|
pSqlNode->sqlstr = *pSelectToken;
|
||||||
SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
|
pSqlNode->sqlstr.n = (uint32_t)strlen(pSqlNode->sqlstr.z);
|
||||||
SToken *igExists);
|
|
||||||
|
|
||||||
void destroyAllSqlNode(SArray *pSqlNode);
|
pSqlNode->pSelNodeList = pSelNodeList;
|
||||||
void destroySqlNode(SSqlNode *pSql);
|
pSqlNode->from = pFrom;
|
||||||
void freeCreateTableInfo(void* p);
|
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);
|
if (pLimit != NULL) {
|
||||||
SArray *setSubclause(SArray *pList, void *pSqlNode);
|
pSqlNode->limit = *pLimit;
|
||||||
SArray *appendSelectClause(SArray *pList, void *pSubclause);
|
} 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, ...);
|
if (pSliding != NULL) {
|
||||||
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SToken* pToken, SToken* existsCheck,int16_t dbType,int16_t tableType);
|
pSqlNode->sliding = *pSliding;
|
||||||
void setShowOptions(SSqlInfo *pInfo, int32_t type, SToken* prefix, SToken* pPatterns);
|
} 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);
|
if (pWindowStateVal != NULL) {
|
||||||
void setCreateUserSql(SSqlInfo *pInfo, SToken *pName, SToken *pPasswd);
|
pSqlNode->windowstateVal = *pWindowStateVal;
|
||||||
void setKillSql(SSqlInfo *pInfo, int32_t type, SToken *ip);
|
} else {
|
||||||
void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SToken *pName, SToken* pPwd, SToken *pPrivilege);
|
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);
|
void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo);
|
||||||
|
|
||||||
// prefix show db.tables;
|
// 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 tSetColumnInfo(SField *pField, SToken *pName, SField *pType) {
|
||||||
void tSetColumnType(struct SField *pField, SToken *type);
|
int32_t maxLen = sizeof(pField->name) / sizeof(pField->name[0]);
|
||||||
|
|
||||||
/**
|
// column name is too long, set the it to be invalid.
|
||||||
*
|
if ((int32_t) pName->n >= maxLen) {
|
||||||
* @param yyp The parser
|
pName->n = -1;
|
||||||
* @param yymajor The major token code number
|
} else {
|
||||||
* @param yyminor The value for the token
|
strncpy(pField->name, pName->z, pName->n);
|
||||||
*/
|
pField->name[pName->n] = 0;
|
||||||
void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
|
}
|
||||||
|
|
||||||
/**
|
pField->type = pType->type;
|
||||||
*
|
if(!isValidDataType(pField->type)){
|
||||||
* @param p The parser to be deleted
|
pField->bytes = 0;
|
||||||
* @param freeProc Function used to reclaim memory
|
} else {
|
||||||
*/
|
pField->bytes = pType->bytes;
|
||||||
void ParseFree(void *p, void (*freeProc)(void *));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
static int32_t tryParseNameTwoParts(SToken *type) {
|
||||||
*
|
int32_t t = -1;
|
||||||
* @param mallocProc The parser allocator
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
void *ParseAlloc(void *(*mallocProc)(size_t));
|
|
||||||
|
|
||||||
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);
|
void *pParser = ParseAlloc(malloc);
|
||||||
|
|
||||||
SSqlInfo sqlInfo = {0};
|
SSqlInfo sqlInfo = {0};
|
||||||
|
|
||||||
sqlInfo.valid = true;
|
sqlInfo.valid = true;
|
||||||
sqlInfo.funcs = taosArrayInit(4, sizeof(SToken));
|
sqlInfo.funcs = taosArrayInit(4, sizeof(SToken));
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@ bool qIsInsertSql(const char* pStr, size_t length) {
|
||||||
return false;
|
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));
|
*pQueryInfo = calloc(1, sizeof(SQueryStmtInfo));
|
||||||
if (*pQueryInfo == NULL) {
|
if (*pQueryInfo == NULL) {
|
||||||
return -1; // set correct error code.
|
return -1; // set correct error code.
|
||||||
}
|
}
|
||||||
|
|
||||||
SSqlInfo info = genAST(pStr);
|
SSqlInfo info = doGenerateAST(pStr);
|
||||||
if (!info.valid) {
|
if (!info.valid) {
|
||||||
strcpy(msg, info.msg);
|
strcpy(msg, info.msg);
|
||||||
return -1; // set correct error code.
|
return -1; // set correct error code.
|
||||||
|
@ -42,7 +42,7 @@ int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo**
|
||||||
return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ extern "C" {
|
||||||
#include "qSqlparser.h"
|
#include "qSqlparser.h"
|
||||||
#include "qTsbuf.h"
|
#include "qTsbuf.h"
|
||||||
#include "qUtil.h"
|
#include "qUtil.h"
|
||||||
#include "tcmdtype.h"
|
#include "tmsgtype.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TAOS_REQ_FROM_SHELL,
|
TAOS_REQ_FROM_SHELL,
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "qPlan.h"
|
#include "qPlan.h"
|
||||||
#include "qTableMeta.h"
|
#include "qTableMeta.h"
|
||||||
#include "tcmdtype.h"
|
|
||||||
#include "tlockfree.h"
|
#include "tlockfree.h"
|
||||||
|
#include "tmsgtype.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tscGlobalmerge.h"
|
#include "tscGlobalmerge.h"
|
||||||
#include "tscLog.h"
|
#include "tscLog.h"
|
||||||
|
|
|
@ -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) ::= intitemlist(X) COMMA intitem(Y). { A = tVariantListAppend(X, &Y, -1); }
|
||||||
intitemlist(A) ::= intitem(X). { A = tVariantListAppend(NULL, &X, -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*}
|
%type keep {SArray*}
|
||||||
%destructor keep {taosArrayDestroy($$);}
|
%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) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); }
|
||||||
tagitemlist(A) ::= tagitem(X). { A = tVariantListAppend(NULL, &X, -1); }
|
tagitemlist(A) ::= tagitem(X). { A = tVariantListAppend(NULL, &X, -1); }
|
||||||
|
|
||||||
tagitem(A) ::= INTEGER(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= INTEGER(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= STRING(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= STRING(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= BOOL(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= BOOL(X). { toTSDBType(X.type); taosVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= NULL(X). { X.type = 0; tVariantCreate(&A, &X); }
|
tagitem(A) ::= NULL(X). { X.type = 0; taosVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= NOW(X). { X.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&A, &X);}
|
tagitem(A) ::= NOW(X). { X.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&A, &X);}
|
||||||
|
|
||||||
tagitem(A) ::= MINUS(X) INTEGER(Y).{
|
tagitem(A) ::= MINUS(X) INTEGER(Y).{
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
X.type = Y.type;
|
X.type = Y.type;
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
tVariantCreate(&A, &X);
|
taosVariantCreate(&A, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
tagitem(A) ::= MINUS(X) FLOAT(Y). {
|
tagitem(A) ::= MINUS(X) FLOAT(Y). {
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
X.type = Y.type;
|
X.type = Y.type;
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
tVariantCreate(&A, &X);
|
taosVariantCreate(&A, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
tagitem(A) ::= PLUS(X) INTEGER(Y). {
|
tagitem(A) ::= PLUS(X) INTEGER(Y). {
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
X.type = Y.type;
|
X.type = Y.type;
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
tVariantCreate(&A, &X);
|
taosVariantCreate(&A, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
tagitem(A) ::= PLUS(X) FLOAT(Y). {
|
tagitem(A) ::= PLUS(X) FLOAT(Y). {
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
X.type = Y.type;
|
X.type = Y.type;
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
tVariantCreate(&A, &X);
|
taosVariantCreate(&A, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////// The SELECT statement /////////////////////////////////
|
//////////////////////// The SELECT statement /////////////////////////////////
|
||||||
|
@ -599,7 +599,7 @@ fill_opt(N) ::= . { N = 0; }
|
||||||
fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP. {
|
fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP. {
|
||||||
tVariant A = {0};
|
tVariant A = {0};
|
||||||
toTSDBType(Y.type);
|
toTSDBType(Y.type);
|
||||||
tVariantCreate(&A, &Y);
|
taosVariantCreate(&A, &Y);
|
||||||
|
|
||||||
tVariantListInsert(X, &A, -1, 0);
|
tVariantListInsert(X, &A, -1, 0);
|
||||||
N = X;
|
N = X;
|
||||||
|
@ -639,7 +639,7 @@ item(A) ::= ids(X) cpxName(Y). {
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
|
|
||||||
tVariantCreate(&A, &X);
|
taosVariantCreate(&A, &X);
|
||||||
}
|
}
|
||||||
|
|
||||||
%type sortorder {int}
|
%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);}
|
expr(A) ::= NULL(X). { A = tSqlExprCreateIdValue(&X, TK_NULL);}
|
||||||
|
|
||||||
// ordinary functions: min(x), max(x), top(k, 20)
|
// 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
|
// 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); }
|
expr(A) ::= ID(X) LP STAR RP(Y). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(NULL, &X, &Y, X.type); }
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tcmdtype.h"
|
#include "tmsgtype.h"
|
||||||
#include "tstrbuild.h"
|
#include "tstrbuild.h"
|
||||||
#include "ttoken.h"
|
#include "ttoken.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
/************ Begin %include sections from the grammar ************************/
|
/************ Begin %include sections from the grammar ************************/
|
||||||
#line 23 "sql.y"
|
#line 23 "sql.y"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "qSqlparser.h"
|
#include "qSqlparser.h"
|
||||||
#include "tcmdtype.h"
|
#include "tmsgtype.h"
|
||||||
#include "ttoken.h"
|
#include "ttoken.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
Loading…
Reference in New Issue