[TD-1978]
This commit is contained in:
parent
2b9a3b1e1b
commit
9487c1b9c6
|
@ -56,11 +56,11 @@ static SSqlExpr* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t outputIndex, in
|
|||
static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
|
||||
static char* getAccountId(SSqlObj* pSql);
|
||||
|
||||
static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name);
|
||||
static bool has(SArray* pFieldList, int32_t startIdx, const char* name);
|
||||
static void getCurrentDBName(SSqlObj* pSql, SStrToken* pDBToken);
|
||||
static bool hasSpecifyDB(SStrToken* pTableName);
|
||||
static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd);
|
||||
static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSqlCmd* pCmd);
|
||||
static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd);
|
||||
static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pCmd);
|
||||
|
||||
static int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStrToken* tableName, int32_t* len);
|
||||
|
||||
|
@ -80,7 +80,7 @@ static bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQuer
|
|||
static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery);
|
||||
static void setColumnOffsetValueInResultset(SQueryInfo* pQueryInfo);
|
||||
|
||||
static int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd* pCmd);
|
||||
static int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd);
|
||||
|
||||
static int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
||||
static int32_t parseOffsetClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
||||
|
@ -905,7 +905,7 @@ int32_t tscSetTableFullName(STableMetaInfo* pTableMetaInfo, SStrToken* pzTableNa
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) {
|
||||
static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
|
||||
assert(pFieldList != NULL);
|
||||
|
||||
const char* msg = "illegal number of columns";
|
||||
|
@ -917,20 +917,22 @@ static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) {
|
|||
const char* msg6 = "invalid column name";
|
||||
|
||||
// number of fields no less than 2
|
||||
if (pFieldList->nField <= 1 || pFieldList->nField > TSDB_MAX_COLUMNS) {
|
||||
size_t numOfCols = taosArrayGetSize(pFieldList);
|
||||
if (numOfCols <= 1 || numOfCols > TSDB_MAX_COLUMNS) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// first column must be timestamp
|
||||
if (pFieldList->p[0].type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
TAOS_FIELD* pField = taosArrayGet(pFieldList, 0);
|
||||
if (pField->type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t nLen = 0;
|
||||
for (int32_t i = 0; i < pFieldList->nField; ++i) {
|
||||
TAOS_FIELD* pField = &pFieldList->p[i];
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
pField = taosArrayGet(pFieldList, i);
|
||||
|
||||
if (pField->bytes == 0) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
||||
|
@ -954,7 +956,7 @@ static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) {
|
|||
}
|
||||
|
||||
// field name must be unique
|
||||
if (has(pFieldList, i + 1, pFieldList->p[i].name) == true) {
|
||||
if (has(pFieldList, i + 1, pField->name) == true) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
return false;
|
||||
}
|
||||
|
@ -971,7 +973,7 @@ static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSqlCmd* pCmd) {
|
||||
static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pCmd) {
|
||||
assert(pTagsList != NULL);
|
||||
|
||||
const char* msg1 = "invalid number of tag columns";
|
||||
|
@ -983,18 +985,21 @@ static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSq
|
|||
const char* msg7 = "invalid binary/nchar tag length";
|
||||
|
||||
// number of fields at least 1
|
||||
if (pTagsList->nField < 1 || pTagsList->nField > TSDB_MAX_TAGS) {
|
||||
size_t numOfTags = taosArrayGetSize(pTagsList);
|
||||
if (numOfTags < 1 || numOfTags > TSDB_MAX_TAGS) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t nLen = 0;
|
||||
for (int32_t i = 0; i < pTagsList->nField; ++i) {
|
||||
if (pTagsList->p[i].bytes == 0) {
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
TAOS_FIELD* p = taosArrayGet(pTagsList, i);
|
||||
if (p->bytes == 0) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||
return false;
|
||||
}
|
||||
nLen += pTagsList->p[i].bytes;
|
||||
|
||||
nLen += p->bytes;
|
||||
}
|
||||
|
||||
// max tag row length must be less than TSDB_MAX_TAGS_LEN
|
||||
|
@ -1004,37 +1009,41 @@ static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSq
|
|||
}
|
||||
|
||||
// field name must be unique
|
||||
for (int32_t i = 0; i < pTagsList->nField; ++i) {
|
||||
if (has(pFieldList, 0, pTagsList->p[i].name) == true) {
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
TAOS_FIELD* p = taosArrayGet(pTagsList, i);
|
||||
|
||||
if (has(pFieldList, 0, p->name) == true) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* timestamp in tag is not allowed */
|
||||
for (int32_t i = 0; i < pTagsList->nField; ++i) {
|
||||
if (pTagsList->p[i].type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
TAOS_FIELD* p = taosArrayGet(pTagsList, i);
|
||||
|
||||
if (p->type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pTagsList->p[i].type < TSDB_DATA_TYPE_BOOL || pTagsList->p[i].type > TSDB_DATA_TYPE_NCHAR) {
|
||||
if (p->type < TSDB_DATA_TYPE_BOOL || p->type > TSDB_DATA_TYPE_NCHAR) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((pTagsList->p[i].type == TSDB_DATA_TYPE_BINARY && pTagsList->p[i].bytes <= 0) ||
|
||||
(pTagsList->p[i].type == TSDB_DATA_TYPE_NCHAR && pTagsList->p[i].bytes <= 0)) {
|
||||
if ((p->type == TSDB_DATA_TYPE_BINARY && p->bytes <= 0) ||
|
||||
(p->type == TSDB_DATA_TYPE_NCHAR && p->bytes <= 0)) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (validateColumnName(pTagsList->p[i].name) != TSDB_CODE_SUCCESS) {
|
||||
if (validateColumnName(p->name) != TSDB_CODE_SUCCESS) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (has(pTagsList, i + 1, pTagsList->p[i].name) == true) {
|
||||
if (has(pTagsList, i + 1, p->name) == true) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
return false;
|
||||
}
|
||||
|
@ -1181,9 +1190,10 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
|
|||
}
|
||||
|
||||
/* is contained in pFieldList or not */
|
||||
static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name) {
|
||||
for (int32_t j = startIdx; j < pFieldList->nField; ++j) {
|
||||
TAOS_FIELD* field = pFieldList->p + j;
|
||||
static bool has(SArray* pFieldList, int32_t startIdx, const char* name) {
|
||||
size_t numOfCols = taosArrayGetSize(pFieldList);
|
||||
for (int32_t j = startIdx; j < numOfCols; ++j) {
|
||||
TAOS_FIELD* field = taosArrayGet(pFieldList, j);
|
||||
if (strncasecmp(name, field->name, sizeof(field->name) - 1) == 0) return true;
|
||||
}
|
||||
|
||||
|
@ -2796,7 +2806,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd* pCmd) {
|
||||
int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd) {
|
||||
const char* msg1 = "too many columns in group by clause";
|
||||
const char* msg2 = "invalid column name in group by clause";
|
||||
const char* msg3 = "columns from one table allowed as group by columns";
|
||||
|
@ -2816,8 +2826,8 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
|
|||
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
|
||||
}
|
||||
|
||||
pQueryInfo->groupbyExpr.numOfGroupCols = pList->nExpr;
|
||||
if (pList->nExpr > TSDB_MAX_TAGS) {
|
||||
pQueryInfo->groupbyExpr.numOfGroupCols = taosArrayGetSize(pList);
|
||||
if (pQueryInfo->groupbyExpr.numOfGroupCols > TSDB_MAX_TAGS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
|
@ -2830,9 +2840,12 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
|
|||
SSchema s = tscGetTbnameColumnSchema();
|
||||
|
||||
int32_t tableIndex = COLUMN_INDEX_INITIAL_VAL;
|
||||
|
||||
for (int32_t i = 0; i < pList->nExpr; ++i) {
|
||||
tVariant* pVar = &pList->a[i].pVar;
|
||||
|
||||
size_t num = taosArrayGetSize(pList);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
tVariantListItem * pItem = taosArrayGet(pList, i);
|
||||
tVariant* pVar = &pItem->pVar;
|
||||
|
||||
SStrToken token = {pVar->nLen, pVar->nType, pVar->pz};
|
||||
|
||||
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
|
||||
|
@ -2893,7 +2906,7 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
|
|||
taosArrayPush(pGroupExpr->columnInfo, &colIndex);
|
||||
pQueryInfo->groupbyExpr.orderType = TSDB_ORDER_ASC;
|
||||
|
||||
if (i == 0 && pList->nExpr > 1) {
|
||||
if (i == 0 && num > 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||
}
|
||||
}
|
||||
|
@ -4407,8 +4420,8 @@ int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
|
|||
}
|
||||
|
||||
int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
|
||||
tVariantList* pFillToken = pQuerySQL->fillType;
|
||||
tVariantListItem* pItem = &pFillToken->a[0];
|
||||
SArray* pFillToken = pQuerySQL->fillType;
|
||||
tVariantListItem* pItem = taosArrayGet(pFillToken, 0);
|
||||
|
||||
const int32_t START_INTERPO_COL_IDX = 1;
|
||||
|
||||
|
@ -4448,12 +4461,13 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
} else if (strncasecmp(pItem->pVar.pz, "value", 5) == 0 && pItem->pVar.nLen == 5) {
|
||||
pQueryInfo->fillType = TSDB_FILL_SET_VALUE;
|
||||
|
||||
if (pFillToken->nExpr == 1) {
|
||||
size_t num = taosArrayGetSize(pFillToken);
|
||||
if (num == 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
int32_t startPos = 1;
|
||||
int32_t numOfFillVal = pFillToken->nExpr - 1;
|
||||
int32_t numOfFillVal = num - 1;
|
||||
|
||||
/* for point interpolation query, we do not have the timestamp column */
|
||||
if (tscIsPointInterpQuery(pQueryInfo)) {
|
||||
|
@ -4463,7 +4477,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
numOfFillVal = (int32_t)size;
|
||||
}
|
||||
} else {
|
||||
numOfFillVal = (pFillToken->nExpr > (int32_t)size) ? (int32_t)size : pFillToken->nExpr;
|
||||
numOfFillVal = (num > (int32_t)size) ? (int32_t)size : num;
|
||||
}
|
||||
|
||||
int32_t j = 1;
|
||||
|
@ -4476,14 +4490,15 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
continue;
|
||||
}
|
||||
|
||||
int32_t ret = tVariantDump(&pFillToken->a[j].pVar, (char*)&pQueryInfo->fillVal[i], pFields->type, true);
|
||||
tVariant* p = taosArrayGet(pFillToken, j);
|
||||
int32_t ret = tVariantDump(p, (char*)&pQueryInfo->fillVal[i], pFields->type, true);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||
}
|
||||
}
|
||||
|
||||
if ((pFillToken->nExpr < size) || ((pFillToken->nExpr - 1 < size) && (tscIsPointInterpQuery(pQueryInfo)))) {
|
||||
tVariantListItem* lastItem = &pFillToken->a[pFillToken->nExpr - 1];
|
||||
if ((num < size) || ((num - 1 < size) && (tscIsPointInterpQuery(pQueryInfo)))) {
|
||||
tVariantListItem* lastItem = taosArrayGetLast(pFillToken);
|
||||
|
||||
for (int32_t i = numOfFillVal; i < size; ++i) {
|
||||
TAOS_FIELD* pFields = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
@ -4532,7 +4547,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
tVariantList* pSortorder = pQuerySql->pSortOrder;
|
||||
SArray* pSortorder = pQuerySql->pSortOrder;
|
||||
|
||||
/*
|
||||
* for table query, there is only one or none order option is allowed, which is the
|
||||
|
@ -4540,18 +4555,19 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
*
|
||||
* for super table query, the order option must be less than 3.
|
||||
*/
|
||||
size_t size = taosArrayGetSize(pSortorder);
|
||||
if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) {
|
||||
if (pSortorder->nExpr > 1) {
|
||||
if (size > 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg0);
|
||||
}
|
||||
} else {
|
||||
if (pSortorder->nExpr > 2) {
|
||||
if (size > 2) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
}
|
||||
}
|
||||
|
||||
// handle the first part of order by
|
||||
tVariant* pVar = &pSortorder->a[0].pVar;
|
||||
tVariant* pVar = taosArrayGet(pSortorder, 0);
|
||||
|
||||
// e.g., order by 1 asc, return directly with out further check.
|
||||
if (pVar->nType >= TSDB_DATA_TYPE_TINYINT && pVar->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
|
@ -4594,10 +4610,13 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
assert(!(orderByTags && orderByTS));
|
||||
}
|
||||
|
||||
if (pSortorder->nExpr == 1) {
|
||||
size_t s = taosArrayGetSize(pSortorder);
|
||||
if (s == 1) {
|
||||
if (orderByTags) {
|
||||
pQueryInfo->groupbyExpr.orderIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
|
||||
pQueryInfo->groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder;
|
||||
|
||||
tVariantListItem* p1 = taosArrayGet(pQuerySql->pSortOrder, 0);
|
||||
pQueryInfo->groupbyExpr.orderType = p1->sortOrder;
|
||||
} else if (isTopBottomQuery(pQueryInfo)) {
|
||||
/* order of top/bottom query in interval is not valid */
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
|
@ -4608,11 +4627,14 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
pQueryInfo->order.order = pQuerySql->pSortOrder->a[0].sortOrder;
|
||||
tVariantListItem* p1 = taosArrayGet(pQuerySql->pSortOrder, 0);
|
||||
pQueryInfo->order.order = p1->sortOrder;
|
||||
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
pQueryInfo->order.order = pSortorder->a[0].sortOrder;
|
||||
tVariantListItem* p1 = taosArrayGet(pQuerySql->pSortOrder, 0);
|
||||
|
||||
pQueryInfo->order.order = p1->sortOrder;
|
||||
pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
|
||||
|
||||
// orderby ts query on super table
|
||||
|
@ -4622,16 +4644,18 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
}
|
||||
}
|
||||
|
||||
if (pSortorder->nExpr == 2) {
|
||||
if (s == 2) {
|
||||
tVariantListItem *pItem = taosArrayGet(pQuerySql->pSortOrder, 0);
|
||||
if (orderByTags) {
|
||||
pQueryInfo->groupbyExpr.orderIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
|
||||
pQueryInfo->groupbyExpr.orderType = pQuerySql->pSortOrder->a[0].sortOrder;
|
||||
pQueryInfo->groupbyExpr.orderType = pItem->sortOrder;
|
||||
} else {
|
||||
pQueryInfo->order.order = pSortorder->a[0].sortOrder;
|
||||
pQueryInfo->order.order = pItem->sortOrder;
|
||||
pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
|
||||
}
|
||||
|
||||
tVariant* pVar2 = &pSortorder->a[1].pVar;
|
||||
pItem = taosArrayGet(pQuerySql->pSortOrder, 1);
|
||||
tVariant* pVar2 = &pItem->pVar;
|
||||
SStrToken cname = {pVar2->nLen, pVar2->nType, pVar2->pz};
|
||||
if (getColumnIndexByName(pCmd, &cname, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
|
@ -4640,7 +4664,8 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
if (index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
} else {
|
||||
pQueryInfo->order.order = pSortorder->a[1].sortOrder;
|
||||
tVariantListItem* p1 = taosArrayGet(pSortorder, 1);
|
||||
pQueryInfo->order.order = p1->sortOrder;
|
||||
pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
|
||||
}
|
||||
}
|
||||
|
@ -4664,12 +4689,14 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
pQueryInfo->order.order = pQuerySql->pSortOrder->a[0].sortOrder;
|
||||
tVariantListItem* pItem = taosArrayGet(pQuerySql->pSortOrder, 0);
|
||||
pQueryInfo->order.order = pItem->sortOrder;
|
||||
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pQueryInfo->order.order = pQuerySql->pSortOrder->a[0].sortOrder;
|
||||
tVariantListItem* pItem = taosArrayGet(pQuerySql->pSortOrder, 0);
|
||||
pQueryInfo->order.order = pItem->sortOrder;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -4737,27 +4764,28 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) {
|
||||
tFieldList* pFieldList = pAlterSQL->pAddColumns;
|
||||
if (pFieldList->nField > 1) {
|
||||
SArray* pFieldList = pAlterSQL->pAddColumns;
|
||||
if (taosArrayGetSize(pFieldList) > 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
||||
}
|
||||
|
||||
if (!validateOneTags(pCmd, &pFieldList->p[0])) {
|
||||
TAOS_FIELD* p = taosArrayGet(pFieldList, 0);
|
||||
if (!validateOneTags(pCmd, p)) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, p);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) {
|
||||
if (tscGetNumOfTags(pTableMeta) == 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||
}
|
||||
|
||||
// numOfTags == 1
|
||||
if (pAlterSQL->varList->nExpr > 1) {
|
||||
if (taosArrayGetSize(pAlterSQL->varList) > 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg8);
|
||||
}
|
||||
|
||||
tVariantListItem* pItem = &pAlterSQL->varList->a[0];
|
||||
tVariantListItem* pItem = taosArrayGet(pAlterSQL->varList, 0);
|
||||
if (pItem->pVar.nLen >= TSDB_COL_NAME_LEN) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg9);
|
||||
}
|
||||
|
@ -4782,13 +4810,13 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name1, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
|
||||
tVariantList* pVarList = pAlterSQL->varList;
|
||||
if (pVarList->nExpr > 2) {
|
||||
SArray* pVarList = pAlterSQL->varList;
|
||||
if (taosArrayGetSize(pVarList) > 2) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
tVariantListItem* pSrcItem = &pAlterSQL->varList->a[0];
|
||||
tVariantListItem* pDstItem = &pAlterSQL->varList->a[1];
|
||||
tVariantListItem* pSrcItem = taosArrayGet(pAlterSQL->varList, 0);
|
||||
tVariantListItem* pDstItem = taosArrayGet(pAlterSQL->varList, 1);
|
||||
|
||||
if (pSrcItem->pVar.nLen >= TSDB_COL_NAME_LEN || pDstItem->pVar.nLen >= TSDB_COL_NAME_LEN) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg9);
|
||||
|
@ -4811,13 +4839,17 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg19);
|
||||
}
|
||||
|
||||
tVariantListItem* pItem = taosArrayGet(pVarList, 0);
|
||||
|
||||
char name[TSDB_COL_NAME_LEN] = {0};
|
||||
strncpy(name, pVarList->a[0].pVar.pz, pVarList->a[0].pVar.nLen);
|
||||
strncpy(name, pItem->pVar.pz, pItem->pVar.nLen);
|
||||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
|
||||
pItem = taosArrayGet(pVarList, 1);
|
||||
memset(name, 0, tListLen(name));
|
||||
strncpy(name, pVarList->a[1].pVar.pz, pVarList->a[1].pVar.nLen);
|
||||
|
||||
strncpy(name, pItem->pVar.pz, pItem->pVar.nLen);
|
||||
f = tscCreateField(TSDB_DATA_TYPE_INT, name, tDataTypeDesc[TSDB_DATA_TYPE_INT].nSize);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
|
||||
|
@ -4825,12 +4857,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
// the following is used to handle tags value for table created according to super table
|
||||
pCmd->command = TSDB_SQL_UPDATE_TAGS_VAL;
|
||||
|
||||
tVariantList* pVarList = pAlterSQL->varList;
|
||||
tVariant* pTagName = &pVarList->a[0].pVar;
|
||||
SArray* pVarList = pAlterSQL->varList;
|
||||
tVariantListItem* item = taosArrayGet(pVarList, 0);
|
||||
int16_t numOfTags = tscGetNumOfTags(pTableMeta);
|
||||
|
||||
SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER;
|
||||
SStrToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen};
|
||||
SStrToken name = {.type = TK_STRING, .z = item->pVar.pz, .n = item->pVar.nLen};
|
||||
if (getColumnIndexByName(pCmd, &name, pQueryInfo, &columnIndex) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
@ -4839,8 +4871,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg12);
|
||||
}
|
||||
|
||||
tVariantListItem* pItem = taosArrayGet(pVarList, 1);
|
||||
SSchema* pTagsSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, columnIndex.columnIndex);
|
||||
if (tVariantDump(&pVarList->a[1].pVar, pAlterSQL->tagData.data, pTagsSchema->type, true) != TSDB_CODE_SUCCESS) {
|
||||
if (tVariantDump(&pItem->pVar, pAlterSQL->tagData.data, pTagsSchema->type, true) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg13);
|
||||
}
|
||||
|
||||
|
@ -4885,7 +4918,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
// copy the tag value to msg body
|
||||
tVariantDump(&pVarList->a[1].pVar, pUpdateMsg->data + schemaLen, pTagsSchema->type, true);
|
||||
pItem = taosArrayGet(pVarList, 1);
|
||||
tVariantDump(&pItem->pVar, pUpdateMsg->data + schemaLen, pTagsSchema->type, true);
|
||||
|
||||
int32_t len = 0;
|
||||
if (pTagsSchema->type != TSDB_DATA_TYPE_BINARY && pTagsSchema->type != TSDB_DATA_TYPE_NCHAR) {
|
||||
|
@ -4900,27 +4934,29 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
pUpdateMsg->head.contLen = htonl(total);
|
||||
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN) {
|
||||
tFieldList* pFieldList = pAlterSQL->pAddColumns;
|
||||
if (pFieldList->nField > 1) {
|
||||
SArray* pFieldList = pAlterSQL->pAddColumns;
|
||||
if (taosArrayGetSize(pFieldList) > 1) {
|
||||
const char* msg = "only support add one column";
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||
}
|
||||
|
||||
if (!validateOneColumn(pCmd, &pFieldList->p[0])) {
|
||||
TAOS_FIELD* p = taosArrayGet(pFieldList, 0);
|
||||
if (!validateOneColumn(pCmd, p)) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, p);
|
||||
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
|
||||
if (tscGetNumOfColumns(pTableMeta) == TSDB_MIN_COLUMNS) { //
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg15);
|
||||
}
|
||||
|
||||
if (pAlterSQL->varList->nExpr > 1) {
|
||||
size_t size = taosArrayGetSize(pAlterSQL->varList);
|
||||
if (size > 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg16);
|
||||
}
|
||||
|
||||
tVariantListItem* pItem = &pAlterSQL->varList->a[0];
|
||||
tVariantListItem* pItem = taosArrayGet(pAlterSQL->varList, 0);
|
||||
|
||||
SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER;
|
||||
SStrToken name = {.type = TK_STRING, .z = pItem->pVar.pz, .n = pItem->pVar.nLen};
|
||||
|
@ -5291,21 +5327,28 @@ static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* p
|
|||
pMsg->daysToKeep1 = htonl(-1);
|
||||
pMsg->daysToKeep2 = htonl(-1);
|
||||
|
||||
tVariantList* pKeep = pCreateDb->keep;
|
||||
SArray* pKeep = pCreateDb->keep;
|
||||
if (pKeep != NULL) {
|
||||
switch (pKeep->nExpr) {
|
||||
case 1:
|
||||
pMsg->daysToKeep = htonl((int32_t)pKeep->a[0].pVar.i64Key);
|
||||
size_t s = taosArrayGetSize(pKeep);
|
||||
tVariantListItem* p0 = taosArrayGet(pKeep, 0);
|
||||
switch (s) {
|
||||
case 1: {
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64Key);
|
||||
}
|
||||
break;
|
||||
case 2: {
|
||||
pMsg->daysToKeep = htonl((int32_t)pKeep->a[0].pVar.i64Key);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)pKeep->a[1].pVar.i64Key);
|
||||
tVariantListItem* p1 = taosArrayGet(pKeep, 1);
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64Key);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64Key);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
pMsg->daysToKeep = htonl((int32_t)pKeep->a[0].pVar.i64Key);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)pKeep->a[1].pVar.i64Key);
|
||||
pMsg->daysToKeep2 = htonl((int32_t)pKeep->a[2].pVar.i64Key);
|
||||
tVariantListItem* p1 = taosArrayGet(pKeep, 1);
|
||||
tVariantListItem* p2 = taosArrayGet(pKeep, 2);
|
||||
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64Key);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64Key);
|
||||
pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64Key);
|
||||
break;
|
||||
}
|
||||
default: { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); }
|
||||
|
@ -5991,8 +6034,8 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
|
|||
|
||||
SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo;
|
||||
|
||||
tFieldList* pFieldList = pCreateTable->colInfo.pColumns;
|
||||
tFieldList* pTagList = pCreateTable->colInfo.pTagColumns;
|
||||
SArray* pFieldList = pCreateTable->colInfo.pColumns;
|
||||
SArray* pTagList = pCreateTable->colInfo.pTagColumns;
|
||||
|
||||
assert(pFieldList != NULL);
|
||||
|
||||
|
@ -6014,18 +6057,22 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
|
|||
}
|
||||
|
||||
int32_t col = 0;
|
||||
for (; col < pFieldList->nField; ++col) {
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[col]);
|
||||
size_t numOfFields = taosArrayGetSize(pFieldList);
|
||||
|
||||
for (; col < numOfFields; ++col) {
|
||||
TAOS_FIELD* p = taosArrayGet(pTagList, col);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, p);
|
||||
}
|
||||
|
||||
pCmd->numOfCols = (int16_t)pFieldList->nField;
|
||||
pCmd->numOfCols = (int16_t)numOfFields;
|
||||
|
||||
if (pTagList != NULL) { // create super table[optional]
|
||||
for (int32_t i = 0; i < pTagList->nField; ++i) {
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pTagList->p[i]);
|
||||
for (int32_t i = 0; i < numOfFields; ++i) {
|
||||
TAOS_FIELD* p = taosArrayGet(pTagList, i);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, p);
|
||||
}
|
||||
|
||||
pCmd->count = pTagList->nField;
|
||||
pCmd->count = numOfFields;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -6066,14 +6113,15 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
|
||||
// get meter meta from mnode
|
||||
tstrncpy(pCreateTable->usingInfo.tagdata.name, pStableMeterMetaInfo->name, sizeof(pCreateTable->usingInfo.tagdata.name));
|
||||
tVariantList* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals;
|
||||
SArray* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals;
|
||||
|
||||
code = tscGetTableMeta(pSql, pStableMeterMetaInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (tscGetNumOfTags(pStableMeterMetaInfo->pTableMeta) != pList->nExpr) {
|
||||
size_t size = taosArrayGetSize(pList);
|
||||
if (tscGetNumOfTags(pStableMeterMetaInfo->pTableMeta) != size) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
||||
}
|
||||
|
||||
|
@ -6087,18 +6135,19 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
for (int32_t i = 0; i < pList->nExpr; ++i) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSchema* pSchema = &pTagSchema[i];
|
||||
|
||||
tVariantListItem* pItem = taosArrayGet(pList, i);
|
||||
|
||||
char tagVal[TSDB_MAX_TAGS_LEN];
|
||||
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (pList->a[i].pVar.nLen > pSchema->bytes) {
|
||||
if (pItem->pVar.nLen > pSchema->bytes) {
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
}
|
||||
}
|
||||
|
||||
ret = tVariantDump(&(pList->a[i].pVar), tagVal, pSchema->type, true);
|
||||
ret = tVariantDump(&(pItem->pVar), tagVal, pSchema->type, true);
|
||||
|
||||
// check again after the convert since it may be converted from binary to nchar.
|
||||
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
|
@ -6165,13 +6214,13 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
tVariantList* pSrcMeterName = pInfo->pCreateTableInfo->pSelect->from;
|
||||
if (pSrcMeterName == NULL || pSrcMeterName->nExpr == 0) {
|
||||
SArray* pSrcMeterName = pInfo->pCreateTableInfo->pSelect->from;
|
||||
if (pSrcMeterName == NULL || taosArrayGetSize(pSrcMeterName) == 0) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
||||
}
|
||||
|
||||
tVariant* pVar = &pSrcMeterName->a[0].pVar;
|
||||
SStrToken srcToken = {.z = pVar->pz, .n = pVar->nLen, .type = TK_STRING};
|
||||
tVariantListItem* p1 = taosArrayGet(pSrcMeterName, 0);
|
||||
SStrToken srcToken = {.z = p1->pVar.pz, .n = p1->pVar.nLen, .type = TK_STRING};
|
||||
if (tscValidateName(&srcToken) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
@ -6236,7 +6285,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
}
|
||||
|
||||
tVariantListItem* pItem = &pQuerySql->fillType->a[0];
|
||||
tVariantListItem* pItem = taosArrayGet(pQuerySql->fillType, 0);
|
||||
if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) {
|
||||
if (!((strncmp(pItem->pVar.pz, "none", 4) == 0 && pItem->pVar.nLen == 4) ||
|
||||
(strncmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4))) {
|
||||
|
@ -6251,7 +6300,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||
assert(pQuerySql != NULL && (pQuerySql->from == NULL || pQuerySql->from->nExpr > 0));
|
||||
assert(pQuerySql != NULL && (pQuerySql->from == NULL || taosArrayGetSize(pQuerySql->from) > 0));
|
||||
|
||||
const char* msg0 = "invalid table name";
|
||||
const char* msg2 = "point interpolation query needs timestamp";
|
||||
|
@ -6293,19 +6342,21 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
|||
return doLocalQueryProcess(pCmd, pQueryInfo, pQuerySql);
|
||||
}
|
||||
|
||||
if (pQuerySql->from->nExpr > TSDB_MAX_JOIN_TABLE_NUM * 2) {
|
||||
size_t fromSize = taosArrayGetSize(pQuerySql->from);
|
||||
if (fromSize > TSDB_MAX_JOIN_TABLE_NUM * 2) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||
}
|
||||
|
||||
pQueryInfo->command = TSDB_SQL_SELECT;
|
||||
|
||||
if (pQuerySql->from->nExpr > 4) {
|
||||
if (fromSize > 4) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg10);
|
||||
}
|
||||
|
||||
// set all query tables, which are maybe more than one.
|
||||
for (int32_t i = 0; i < pQuerySql->from->nExpr; ) {
|
||||
tVariant* pTableItem = &pQuerySql->from->a[i].pVar;
|
||||
for (int32_t i = 0; i < fromSize; ) {
|
||||
tVariantListItem* item = taosArrayGet(pQuerySql->from, i);
|
||||
tVariant* pTableItem = &item->pVar;
|
||||
|
||||
if (pTableItem->nType != TSDB_DATA_TYPE_BINARY) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg0);
|
||||
|
@ -6330,21 +6381,21 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
|||
return code;
|
||||
}
|
||||
|
||||
tVariant* pTableItem1 = &pQuerySql->from->a[i + 1].pVar;
|
||||
if (pTableItem1->nType != TSDB_DATA_TYPE_BINARY) {
|
||||
tVariantListItem* p1 = taosArrayGet(pQuerySql->from, i);
|
||||
if (p1->pVar.nType != TSDB_DATA_TYPE_BINARY) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg11);
|
||||
}
|
||||
|
||||
SStrToken aliasName = {.z = pTableItem1->pz, .n = pTableItem1->nLen, .type = TK_STRING};
|
||||
SStrToken aliasName = {.z = p1->pVar.pz, .n = p1->pVar.nLen, .type = TK_STRING};
|
||||
if (tscValidateName(&aliasName) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg11);
|
||||
}
|
||||
|
||||
// has no table alias name
|
||||
if (memcmp(pTableItem->pz, pTableItem1->pz, pTableItem1->nLen) == 0) {
|
||||
if (memcmp(pTableItem->pz, p1->pVar.pz, p1->pVar.nLen) == 0) {
|
||||
extractTableName(pTableMetaInfo1->name, pTableMetaInfo1->aliasName);
|
||||
} else {
|
||||
tstrncpy(pTableMetaInfo1->aliasName, pTableItem1->pz, sizeof(pTableMetaInfo1->aliasName));
|
||||
tstrncpy(pTableMetaInfo1->aliasName, p1->pVar.pz, sizeof(pTableMetaInfo1->aliasName));
|
||||
}
|
||||
|
||||
code = tscGetTableMeta(pSql, pTableMetaInfo1);
|
||||
|
@ -6355,7 +6406,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
|||
i += 2;
|
||||
}
|
||||
|
||||
assert(pQueryInfo->numOfTables == pQuerySql->from->nExpr / 2);
|
||||
assert(pQueryInfo->numOfTables == taosArrayGetSize(pQuerySql->from) / 2);
|
||||
bool isSTable = false;
|
||||
|
||||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||
|
@ -6389,12 +6440,12 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
|||
pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000;
|
||||
}
|
||||
} else { // set the time rang
|
||||
if (pQuerySql->from->nExpr > 2) { // it is a join query, no wher clause is not allowed.
|
||||
if (taosArrayGetSize(pQuerySql->from) > 2) { // it is a join query, no wher clause is not allowed.
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "condition missing for join query ");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t joinQuery = (pQuerySql->from != NULL && pQuerySql->from->nExpr > 2);
|
||||
int32_t joinQuery = (pQuerySql->from != NULL && taosArrayGetSize(pQuerySql->from) > 2);
|
||||
|
||||
if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable, joinQuery) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
|
|
|
@ -35,10 +35,6 @@ bool tscValidateTableNameLength(size_t len);
|
|||
|
||||
SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters);
|
||||
|
||||
/**
|
||||
* get the schema for the "tbname" column. it is a built column
|
||||
* @return
|
||||
*/
|
||||
SSchema tscGetTbnameColumnSchema();
|
||||
|
||||
#endif // TDENGINE_NAME_H
|
||||
|
|
|
@ -74,8 +74,6 @@ typedef struct tExprNode {
|
|||
};
|
||||
} tExprNode;
|
||||
|
||||
void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
|
||||
|
||||
void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param);
|
||||
|
||||
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
|
@ -87,6 +85,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond);
|
|||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||
|
||||
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||
void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <tstrbuild.h>
|
||||
#include "taos.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tstoken.h"
|
||||
#include "tstrbuild.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
#define ParseTOKENTYPE SStrToken
|
||||
|
@ -37,12 +37,6 @@ extern char tTokenTypeSwitcher[13];
|
|||
(x) = tTokenTypeSwitcher[(x)]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef struct tFieldList {
|
||||
int32_t nField;
|
||||
int32_t nAlloc;
|
||||
TAOS_FIELD *p;
|
||||
} tFieldList;
|
||||
|
||||
typedef struct SLimitVal {
|
||||
int64_t limit;
|
||||
|
@ -59,12 +53,6 @@ typedef struct tVariantListItem {
|
|||
uint8_t sortOrder;
|
||||
} tVariantListItem;
|
||||
|
||||
typedef struct tVariantList {
|
||||
int32_t nExpr; /* Number of expressions on the list */
|
||||
int32_t nAlloc; /* Number of entries allocated below */
|
||||
tVariantListItem *a; /* One entry for each expression */
|
||||
} tVariantList;
|
||||
|
||||
typedef struct SIntervalVal {
|
||||
SStrToken interval;
|
||||
SStrToken offset;
|
||||
|
@ -72,16 +60,16 @@ typedef struct SIntervalVal {
|
|||
|
||||
typedef struct SQuerySQL {
|
||||
struct tSQLExprList *pSelection; // select clause
|
||||
tVariantList * from; // from clause
|
||||
SArray * from; // from clause SArray<tVariantListItem>
|
||||
struct tSQLExpr * pWhere; // where clause [optional]
|
||||
tVariantList * pGroupby; // groupby clause, only for tags[optional]
|
||||
tVariantList * pSortOrder; // orderby [optional]
|
||||
SArray * pGroupby; // groupby clause, only for tags[optional], SArray<tVariantListItem>
|
||||
SArray * pSortOrder; // orderby [optional], SArray<tVariantListItem>
|
||||
SStrToken interval; // interval [optional]
|
||||
SStrToken offset; // offset window [optional]
|
||||
SStrToken sliding; // sliding window [optional]
|
||||
SLimitVal limit; // limit offset [optional]
|
||||
SLimitVal slimit; // group limit offset [optional]
|
||||
tVariantList * fillType; // fill type[optional]
|
||||
SArray * fillType; // fill type[optional], SArray<tVariantListItem>
|
||||
SStrToken selectToken; // sql string
|
||||
} SQuerySQL;
|
||||
|
||||
|
@ -91,26 +79,25 @@ typedef struct SCreateTableSQL {
|
|||
|
||||
int8_t type; // create normal table/from super table/ stream
|
||||
struct {
|
||||
tFieldList *pTagColumns; // for normal table, pTagColumns = NULL;
|
||||
tFieldList *pColumns;
|
||||
SArray *pTagColumns; // SArray<TAOS_FIELD>
|
||||
SArray *pColumns; // SArray<TAOS_FIELD>
|
||||
} colInfo;
|
||||
|
||||
struct {
|
||||
SStrToken stableName; // super table name, for using clause
|
||||
tVariantList *pTagVals; // create by using metric, tag value
|
||||
STagData tagdata;
|
||||
SStrToken stableName; // super table name, for using clause
|
||||
SArray *pTagVals; // create by using metric, tag value
|
||||
STagData tagdata;
|
||||
} usingInfo;
|
||||
|
||||
SQuerySQL *pSelect;
|
||||
SQuerySQL *pSelect;
|
||||
} SCreateTableSQL;
|
||||
|
||||
typedef struct SAlterTableSQL {
|
||||
SStrToken name;
|
||||
int16_t type;
|
||||
STagData tagData;
|
||||
|
||||
tFieldList * pAddColumns;
|
||||
tVariantList *varList; // set t=val or: change src dst
|
||||
SArray *pAddColumns; // SArray<TAOS_FIELD>
|
||||
SArray *varList; // set t=val or: change src dst, SArray<tVariantListItem>
|
||||
} SAlterTableSQL;
|
||||
|
||||
typedef struct SCreateDBInfo {
|
||||
|
@ -130,7 +117,7 @@ typedef struct SCreateDBInfo {
|
|||
SStrToken precision;
|
||||
bool ignoreExists;
|
||||
|
||||
tVariantList *keep;
|
||||
SArray *keep;
|
||||
} SCreateDBInfo;
|
||||
|
||||
typedef struct SCreateAcctSQL {
|
||||
|
@ -168,7 +155,7 @@ typedef struct tDCLSQL {
|
|||
SCreateDBInfo dbOpt;
|
||||
SCreateAcctSQL acctOpt;
|
||||
SShowInfo showOpt;
|
||||
SStrToken ip;
|
||||
SStrToken ip;
|
||||
};
|
||||
|
||||
SUserInfo user;
|
||||
|
@ -181,33 +168,32 @@ typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
|
|||
} SSubclauseInfo;
|
||||
|
||||
typedef struct SSqlInfo {
|
||||
int32_t type;
|
||||
bool valid;
|
||||
int32_t type;
|
||||
bool valid;
|
||||
|
||||
union {
|
||||
SCreateTableSQL *pCreateTableInfo;
|
||||
SAlterTableSQL * pAlterInfo;
|
||||
tDCLSQL * pDCLInfo;
|
||||
SAlterTableSQL *pAlterInfo;
|
||||
tDCLSQL *pDCLInfo;
|
||||
};
|
||||
|
||||
SSubclauseInfo subclauseInfo;
|
||||
char pzErrMsg[256];
|
||||
SSubclauseInfo subclauseInfo;
|
||||
char pzErrMsg[256];
|
||||
} SSqlInfo;
|
||||
|
||||
typedef struct tSQLExpr {
|
||||
// TK_FUNCTION: sql function, TK_LE: less than(binary expr)
|
||||
uint32_t nSQLOptr;
|
||||
uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
|
||||
|
||||
// the full sql string of function(col, param), which is actually the raw
|
||||
// field name, since the function name is kept in nSQLOptr already
|
||||
SStrToken operand;
|
||||
SStrToken colInfo; // field id
|
||||
tVariant val; // value only for string, float, int
|
||||
|
||||
SStrToken operand;
|
||||
SStrToken colInfo; // field id
|
||||
tVariant val; // value only for string, float, int
|
||||
SStrToken token; // original sql expr string
|
||||
|
||||
struct tSQLExpr *pLeft; // left child
|
||||
struct tSQLExpr *pRight; // right child
|
||||
struct tSQLExprList *pParam; // function parameters
|
||||
SStrToken token; // original sql expr string
|
||||
} tSQLExpr;
|
||||
|
||||
// used in select clause. select <tSQLExprList> from xxx
|
||||
|
@ -238,16 +224,9 @@ void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
|
|||
*/
|
||||
void ParseFree(void *p, void (*freeProc)(void *));
|
||||
|
||||
tVariantList *tVariantListAppend(tVariantList *pList, tVariant *pVar, uint8_t sortOrder);
|
||||
|
||||
tVariantList *tVariantListInsert(tVariantList *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
|
||||
|
||||
tVariantList *tVariantListAppendToken(tVariantList *pList, SStrToken *pAliasToken, uint8_t sortOrder);
|
||||
void tVariantListDestroy(tVariantList *pList);
|
||||
|
||||
tFieldList *tFieldListAppend(tFieldList *pList, TAOS_FIELD *pField);
|
||||
|
||||
void tFieldListDestroy(tFieldList *pList);
|
||||
SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
|
||||
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
|
||||
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
|
||||
|
||||
tSQLExpr *tSQLExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optType);
|
||||
|
||||
|
@ -257,17 +236,16 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken
|
|||
|
||||
void tSQLExprListDestroy(tSQLExprList *pList);
|
||||
|
||||
SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
|
||||
tVariantList *pGroupby, tVariantList *pSortOrder, SIntervalVal *pInterval,
|
||||
SStrToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
||||
SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
|
||||
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
|
||||
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
||||
|
||||
SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrToken *pMetricName,
|
||||
tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type);
|
||||
SCreateTableSQL *tSetCreateSQLElems(SArray *pCols, SArray *pTags, SStrToken *pMetricName,
|
||||
SArray *pTagVals, SQuerySQL *pSelect, int32_t type);
|
||||
|
||||
void tSQLExprNodeDestroy(tSQLExpr *pExpr);
|
||||
tSQLExpr *tSQLExprNodeClone(tSQLExpr *pExpr);
|
||||
void tSQLExprNodeDestroy(tSQLExpr *pExpr);
|
||||
|
||||
SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type);
|
||||
SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, SArray *pCols, SArray *pVals, int32_t type);
|
||||
|
||||
void destroyAllSelectClause(SSubclauseInfo *pSql);
|
||||
void doDestroyQuerySql(SQuerySQL *pSql);
|
||||
|
|
|
@ -223,8 +223,8 @@ acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K
|
|||
Y.stat = M;
|
||||
}
|
||||
|
||||
%type keep {tVariantList*}
|
||||
%destructor keep {tVariantListDestroy($$);}
|
||||
%type keep {SArray*}
|
||||
%destructor keep {taosArrayDestroy($$);}
|
||||
keep(Y) ::= KEEP tagitemlist(X). { Y = X; }
|
||||
|
||||
cache(Y) ::= CACHE INTEGER(X). { Y = X; }
|
||||
|
@ -324,10 +324,10 @@ create_table_args(A) ::= AS select(S). {
|
|||
}
|
||||
|
||||
%type column{TAOS_FIELD}
|
||||
%type columnlist{tFieldList*}
|
||||
%destructor columnlist {tFieldListDestroy($$);}
|
||||
columnlist(A) ::= columnlist(X) COMMA column(Y). {A = tFieldListAppend(X, &Y); }
|
||||
columnlist(A) ::= column(X). {A = tFieldListAppend(NULL, &X);}
|
||||
%type columnlist{SArray*}
|
||||
%destructor columnlist {taosArrayDestroy($$);}
|
||||
columnlist(A) ::= columnlist(X) COMMA column(Y). {A = taosArrayPush(X, &Y); }
|
||||
columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(A, &X);}
|
||||
|
||||
// The information used for a column is the name and type of column:
|
||||
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
|
||||
|
@ -335,8 +335,8 @@ column(A) ::= ids(X) typename(Y). {
|
|||
tSQLSetColumnInfo(&A, &X, &Y);
|
||||
}
|
||||
|
||||
%type tagitemlist {tVariantList*}
|
||||
%destructor tagitemlist {tVariantListDestroy($$);}
|
||||
%type tagitemlist {SArray*}
|
||||
%destructor tagitemlist {taosArrayDestroy($$);}
|
||||
|
||||
%type tagitem {tVariant}
|
||||
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); }
|
||||
|
@ -429,11 +429,11 @@ as(X) ::= ids(Y). { X = Y; }
|
|||
as(X) ::= . { X.n = 0; }
|
||||
|
||||
// A complete FROM clause.
|
||||
%type from {tVariantList*}
|
||||
%type from {SArray*}
|
||||
// current not support query from no-table
|
||||
from(A) ::= FROM tablelist(X). {A = X;}
|
||||
|
||||
%type tablelist {tVariantList*}
|
||||
%type tablelist {SArray*}
|
||||
tablelist(A) ::= ids(X) cpxName(Y). {
|
||||
toTSDBType(X.type);
|
||||
X.n += Y.n;
|
||||
|
@ -473,15 +473,15 @@ interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N.interval = E; N.offset.n = 0;
|
|||
interval_opt(N) ::= INTERVAL LP tmvar(E) COMMA tmvar(O) RP. {N.interval = E; N.offset = O;}
|
||||
interval_opt(N) ::= . {memset(&N, 0, sizeof(N));}
|
||||
|
||||
%type fill_opt {tVariantList*}
|
||||
%destructor fill_opt {tVariantListDestroy($$);}
|
||||
%type fill_opt {SArray*}
|
||||
%destructor fill_opt {taosArrayDestroy($$);}
|
||||
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);
|
||||
|
||||
tVariantListInsert(X, &A, -1, 0);
|
||||
taosArrayPush(X, &A);
|
||||
N = X;
|
||||
}
|
||||
|
||||
|
@ -494,11 +494,11 @@ fill_opt(N) ::= FILL LP ID(Y) RP. {
|
|||
sliding_opt(K) ::= SLIDING LP tmvar(E) RP. {K = E; }
|
||||
sliding_opt(K) ::= . {K.n = 0; K.z = NULL; K.type = 0; }
|
||||
|
||||
%type orderby_opt {tVariantList*}
|
||||
%destructor orderby_opt {tVariantListDestroy($$);}
|
||||
%type orderby_opt {SArray*}
|
||||
%destructor orderby_opt {taosArrayDestroy($$);}
|
||||
|
||||
%type sortlist {tVariantList*}
|
||||
%destructor sortlist {tVariantListDestroy($$);}
|
||||
%type sortlist {SArray*}
|
||||
%destructor sortlist {taosArrayDestroy($$);}
|
||||
|
||||
%type sortitem {tVariant}
|
||||
%destructor sortitem {tVariantDestroy(&$$);}
|
||||
|
@ -528,10 +528,10 @@ sortorder(A) ::= DESC. {A = TSDB_ORDER_DESC;}
|
|||
sortorder(A) ::= . {A = TSDB_ORDER_ASC;} //default is descend order
|
||||
|
||||
//group by clause
|
||||
%type groupby_opt {tVariantList*}
|
||||
%destructor groupby_opt {tVariantListDestroy($$);}
|
||||
%type grouplist {tVariantList*}
|
||||
%destructor grouplist {tVariantListDestroy($$);}
|
||||
%type groupby_opt {SArray*}
|
||||
%destructor groupby_opt {taosArrayDestroy($$);}
|
||||
%type grouplist {SArray*}
|
||||
%destructor grouplist {taosArrayDestroy($$);}
|
||||
|
||||
groupby_opt(A) ::= . {A = 0;}
|
||||
groupby_opt(A) ::= GROUP BY grouplist(X). {A = X;}
|
||||
|
@ -654,7 +654,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
|
|||
X.n += F.n;
|
||||
|
||||
toTSDBType(A.type);
|
||||
tVariantList* K = tVariantListAppendToken(NULL, &A, -1);
|
||||
SArray* K = tVariantListAppendToken(NULL, &A, -1);
|
||||
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
|
||||
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||
|
@ -670,7 +670,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
|
|||
X.n += Z.n;
|
||||
|
||||
toTSDBType(Y.type);
|
||||
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
|
||||
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||
|
@ -680,7 +680,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
|
|||
X.n += F.n;
|
||||
|
||||
toTSDBType(Y.type);
|
||||
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||
|
||||
toTSDBType(Z.type);
|
||||
A = tVariantListAppendToken(A, &Z, -1);
|
||||
|
@ -693,7 +693,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
|
|||
X.n += F.n;
|
||||
|
||||
toTSDBType(Y.type);
|
||||
tVariantList* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
|
||||
A = tVariantListAppend(A, &Z, -1);
|
||||
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
|
||||
|
|
|
@ -15,11 +15,9 @@
|
|||
|
||||
#include "os.h"
|
||||
#include "qSqlparser.h"
|
||||
#include "queryLog.h"
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcmdtype.h"
|
||||
#include "tglobal.h"
|
||||
#include "tstoken.h"
|
||||
#include "tstrbuild.h"
|
||||
#include "ttokendef.h"
|
||||
|
@ -314,130 +312,56 @@ void tSQLExprDestroy(tSQLExpr *pExpr) {
|
|||
tSQLExprNodeDestroy(pExpr);
|
||||
}
|
||||
|
||||
static void *tVariantListExpand(tVariantList *pList) {
|
||||
if (pList->nAlloc <= pList->nExpr) { //
|
||||
int32_t newSize = (pList->nAlloc << 1) + 4;
|
||||
|
||||
void *ptr = realloc(pList->a, newSize * sizeof(pList->a[0]));
|
||||
if (ptr == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pList->nAlloc = newSize;
|
||||
pList->a = ptr;
|
||||
}
|
||||
|
||||
assert(pList->a != 0);
|
||||
return pList;
|
||||
}
|
||||
|
||||
tVariantList *tVariantListAppend(tVariantList *pList, tVariant *pVar, uint8_t sortOrder) {
|
||||
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pToken, uint8_t order) {
|
||||
if (pList == NULL) {
|
||||
pList = calloc(1, sizeof(tVariantList));
|
||||
}
|
||||
|
||||
if (tVariantListExpand(pList) == NULL) {
|
||||
return pList;
|
||||
}
|
||||
|
||||
if (pVar) {
|
||||
tVariantListItem *pItem = &pList->a[pList->nExpr++];
|
||||
/*
|
||||
* Here we do not employ the assign function, since we need the pz attribute of structure
|
||||
* , which is the point to char string, to free it!
|
||||
*
|
||||
* Otherwise, the original pointer may be lost, which causes memory leak.
|
||||
*/
|
||||
memcpy(pItem, pVar, sizeof(tVariant));
|
||||
pItem->sortOrder = sortOrder;
|
||||
}
|
||||
return pList;
|
||||
}
|
||||
|
||||
tVariantList *tVariantListInsert(tVariantList *pList, tVariant *pVar, uint8_t sortOrder, int32_t index) {
|
||||
if (pList == NULL || index >= pList->nExpr) {
|
||||
return tVariantListAppend(NULL, pVar, sortOrder);
|
||||
}
|
||||
|
||||
if (tVariantListExpand(pList) == NULL) {
|
||||
return pList;
|
||||
}
|
||||
|
||||
if (pVar) {
|
||||
memmove(&pList->a[index + 1], &pList->a[index], sizeof(tVariantListItem) * (pList->nExpr - index));
|
||||
|
||||
tVariantListItem *pItem = &pList->a[index];
|
||||
/*
|
||||
* Here we do not employ the assign function, since we need the pz attribute of structure
|
||||
* , which is the point to char string, to free it!
|
||||
*
|
||||
* Otherwise, the original pointer may be lost, which causes memory leak.
|
||||
*/
|
||||
memcpy(pItem, pVar, sizeof(tVariant));
|
||||
pItem->sortOrder = sortOrder;
|
||||
|
||||
pList->nExpr++;
|
||||
}
|
||||
|
||||
return pList;
|
||||
}
|
||||
|
||||
void tVariantListDestroy(tVariantList *pList) {
|
||||
if (pList == NULL) return;
|
||||
|
||||
for (int32_t i = 0; i < pList->nExpr; ++i) {
|
||||
tVariantDestroy(&pList->a[i].pVar);
|
||||
}
|
||||
|
||||
free(pList->a);
|
||||
free(pList);
|
||||
}
|
||||
|
||||
tVariantList *tVariantListAppendToken(tVariantList *pList, SStrToken *pToken, uint8_t sortOrder) {
|
||||
if (pList == NULL) {
|
||||
pList = calloc(1, sizeof(tVariantList));
|
||||
}
|
||||
|
||||
if (tVariantListExpand(pList) == NULL) {
|
||||
return pList;
|
||||
pList = taosArrayInit(4, sizeof(tVariantListItem));
|
||||
}
|
||||
|
||||
if (pToken) {
|
||||
tVariant t = {0};
|
||||
tVariantCreate(&t, pToken);
|
||||
tVariantListItem item = {0};
|
||||
tVariantCreate(&item.pVar, pToken);
|
||||
item.sortOrder = order;
|
||||
|
||||
tVariantListItem *pItem = &pList->a[pList->nExpr++];
|
||||
memcpy(pItem, &t, sizeof(tVariant));
|
||||
pItem->sortOrder = sortOrder;
|
||||
taosArrayPush(pList, &item);
|
||||
}
|
||||
|
||||
return pList;
|
||||
}
|
||||
|
||||
tFieldList *tFieldListAppend(tFieldList *pList, TAOS_FIELD *pField) {
|
||||
if (pList == NULL) pList = calloc(1, sizeof(tFieldList));
|
||||
|
||||
if (pList->nAlloc <= pList->nField) { //
|
||||
pList->nAlloc = (pList->nAlloc << 1) + 4;
|
||||
pList->p = realloc(pList->p, pList->nAlloc * sizeof(pList->p[0]));
|
||||
if (pList->p == 0) {
|
||||
pList->nField = pList->nAlloc = 0;
|
||||
return pList;
|
||||
}
|
||||
SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder) {
|
||||
if (pList == NULL) {
|
||||
pList = taosArrayInit(4, sizeof(tVariantListItem));
|
||||
}
|
||||
assert(pList->p != 0);
|
||||
|
||||
if (pField) {
|
||||
struct TAOS_FIELD *pItem = (struct TAOS_FIELD *)&pList->p[pList->nField++];
|
||||
memcpy(pItem, pField, sizeof(TAOS_FIELD));
|
||||
if (pVar == NULL) {
|
||||
return pList;
|
||||
}
|
||||
|
||||
/*
|
||||
* Here we do not employ the assign function, since we need the pz attribute of structure
|
||||
* , which is the point to char string, to free it!
|
||||
*
|
||||
* Otherwise, the original pointer may be lost, which causes memory leak.
|
||||
*/
|
||||
tVariantListItem item = {0};
|
||||
item.pVar = *pVar;
|
||||
item.sortOrder = sortOrder;
|
||||
|
||||
taosArrayPush(pList, &item);
|
||||
return pList;
|
||||
}
|
||||
|
||||
void tFieldListDestroy(tFieldList *pList) {
|
||||
if (pList == NULL) return;
|
||||
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index) {
|
||||
if (pList == NULL || pVar == NULL || index >= taosArrayGetSize(pList)) {
|
||||
return tVariantListAppend(NULL, pVar, sortOrder);
|
||||
}
|
||||
|
||||
free(pList->p);
|
||||
free(pList);
|
||||
tVariantListItem item = {0};
|
||||
item.pVar = *pVar;
|
||||
item.sortOrder = sortOrder;
|
||||
|
||||
taosArrayInsert(pList, index, &item);
|
||||
return pList;
|
||||
}
|
||||
|
||||
void setDBName(SStrToken *pCpxName, SStrToken *pDB) {
|
||||
|
@ -499,9 +423,9 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
|
|||
/*
|
||||
* extract the select info out of sql string
|
||||
*/
|
||||
SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
|
||||
tVariantList *pGroupby, tVariantList *pSortOrder, SIntervalVal *pInterval,
|
||||
SStrToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) {
|
||||
SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
|
||||
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
|
||||
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) {
|
||||
assert(pSelection != NULL);
|
||||
|
||||
SQuerySQL *pQuery = calloc(1, sizeof(SQuerySQL));
|
||||
|
@ -535,6 +459,11 @@ SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection,
|
|||
return pQuery;
|
||||
}
|
||||
|
||||
void freeVariant(void *pItem) {
|
||||
tVariantListItem* p = (tVariantListItem*) pItem;
|
||||
tVariantDestroy(&p->pVar);
|
||||
}
|
||||
|
||||
void doDestroyQuerySql(SQuerySQL *pQuerySql) {
|
||||
if (pQuerySql == NULL) {
|
||||
return;
|
||||
|
@ -547,17 +476,18 @@ void doDestroyQuerySql(SQuerySQL *pQuerySql) {
|
|||
tSQLExprDestroy(pQuerySql->pWhere);
|
||||
pQuerySql->pWhere = NULL;
|
||||
|
||||
tVariantListDestroy(pQuerySql->pSortOrder);
|
||||
taosArrayDestroyEx(pQuerySql->pSortOrder, freeVariant);
|
||||
pQuerySql->pSortOrder = NULL;
|
||||
|
||||
tVariantListDestroy(pQuerySql->pGroupby);
|
||||
|
||||
taosArrayDestroyEx(pQuerySql->pGroupby, freeVariant);
|
||||
pQuerySql->pGroupby = NULL;
|
||||
|
||||
tVariantListDestroy(pQuerySql->from);
|
||||
|
||||
taosArrayDestroyEx(pQuerySql->from, freeVariant);
|
||||
pQuerySql->from = NULL;
|
||||
|
||||
tVariantListDestroy(pQuerySql->fillType);
|
||||
|
||||
|
||||
taosArrayDestroyEx(pQuerySql->fillType, freeVariant);
|
||||
pQuerySql->fillType = NULL;
|
||||
|
||||
free(pQuerySql);
|
||||
}
|
||||
|
||||
|
@ -574,8 +504,8 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) {
|
|||
taosTFree(pClause->pClause);
|
||||
}
|
||||
|
||||
SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrToken *pStableName,
|
||||
tVariantList *pTagVals, SQuerySQL *pSelect, int32_t type) {
|
||||
SCreateTableSQL *tSetCreateSQLElems(SArray *pCols, SArray *pTags, SStrToken *pStableName,
|
||||
SArray *pTagVals, SQuerySQL *pSelect, int32_t type) {
|
||||
SCreateTableSQL *pCreate = calloc(1, sizeof(SCreateTableSQL));
|
||||
|
||||
switch (type) {
|
||||
|
@ -607,7 +537,7 @@ SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrTo
|
|||
return pCreate;
|
||||
}
|
||||
|
||||
SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, tFieldList *pCols, tVariantList *pVals, int32_t type) {
|
||||
SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, SArray *pCols, SArray *pVals, int32_t type) {
|
||||
SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL));
|
||||
|
||||
pAlterTable->name = *pMeterName;
|
||||
|
@ -637,14 +567,14 @@ void SQLInfoDestroy(SSqlInfo *pInfo) {
|
|||
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
|
||||
doDestroyQuerySql(pCreateTableInfo->pSelect);
|
||||
|
||||
tFieldListDestroy(pCreateTableInfo->colInfo.pColumns);
|
||||
tFieldListDestroy(pCreateTableInfo->colInfo.pTagColumns);
|
||||
taosArrayDestroy(pCreateTableInfo->colInfo.pColumns);
|
||||
taosArrayDestroy(pCreateTableInfo->colInfo.pTagColumns);
|
||||
|
||||
tVariantListDestroy(pCreateTableInfo->usingInfo.pTagVals);
|
||||
taosArrayDestroyEx(pCreateTableInfo->usingInfo.pTagVals, freeVariant);
|
||||
taosTFree(pInfo->pCreateTableInfo);
|
||||
} else if (pInfo->type == TSDB_SQL_ALTER_TABLE) {
|
||||
tVariantListDestroy(pInfo->pAlterInfo->varList);
|
||||
tFieldListDestroy(pInfo->pAlterInfo->pAddColumns);
|
||||
taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeVariant);
|
||||
taosArrayDestroy(pInfo->pAlterInfo->pAddColumns);
|
||||
|
||||
taosTFree(pInfo->pAlterInfo);
|
||||
} else {
|
||||
|
@ -653,7 +583,7 @@ void SQLInfoDestroy(SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
if (pInfo->pDCLInfo != NULL && pInfo->type == TSDB_SQL_CREATE_DB) {
|
||||
tVariantListDestroy(pInfo->pDCLInfo->dbOpt.keep);
|
||||
taosArrayDestroyEx(pInfo->pDCLInfo->dbOpt.keep, freeVariant);
|
||||
}
|
||||
|
||||
taosTFree(pInfo->pDCLInfo);
|
||||
|
|
|
@ -115,9 +115,8 @@ typedef union {
|
|||
int64_t yy271;
|
||||
tVariant yy312;
|
||||
SIntervalVal yy314;
|
||||
SArray* yy347;
|
||||
SCreateTableSQL* yy374;
|
||||
tFieldList* yy449;
|
||||
tVariantList* yy494;
|
||||
} YYMINORTYPE;
|
||||
#ifndef YYSTACKDEPTH
|
||||
#define YYSTACKDEPTH 100
|
||||
|
@ -1361,18 +1360,14 @@ static void yy_destructor(
|
|||
/********* Begin destructor definitions ***************************************/
|
||||
case 226: /* keep */
|
||||
case 227: /* tagitemlist */
|
||||
case 243: /* columnlist */
|
||||
case 251: /* fill_opt */
|
||||
case 253: /* groupby_opt */
|
||||
case 254: /* orderby_opt */
|
||||
case 264: /* sortlist */
|
||||
case 268: /* grouplist */
|
||||
{
|
||||
tVariantListDestroy((yypminor->yy494));
|
||||
}
|
||||
break;
|
||||
case 243: /* columnlist */
|
||||
{
|
||||
tFieldListDestroy((yypminor->yy449));
|
||||
taosArrayDestroy((yypminor->yy347));
|
||||
}
|
||||
break;
|
||||
case 244: /* select */
|
||||
|
@ -2228,7 +2223,7 @@ static void yy_reduce(
|
|||
yymsp[-8].minor.yy73 = yylhsminor.yy73;
|
||||
break;
|
||||
case 72: /* keep ::= KEEP tagitemlist */
|
||||
{ yymsp[-1].minor.yy494 = yymsp[0].minor.yy494; }
|
||||
{ yymsp[-1].minor.yy347 = yymsp[0].minor.yy347; }
|
||||
break;
|
||||
case 73: /* cache ::= CACHE INTEGER */
|
||||
case 74: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==74);
|
||||
|
@ -2303,7 +2298,7 @@ static void yy_reduce(
|
|||
break;
|
||||
case 98: /* db_optr ::= db_optr keep */
|
||||
case 102: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==102);
|
||||
{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.keep = yymsp[0].minor.yy494; }
|
||||
{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.keep = yymsp[0].minor.yy347; }
|
||||
yymsp[-1].minor.yy158 = yylhsminor.yy158;
|
||||
break;
|
||||
case 99: /* alter_db_optr ::= */
|
||||
|
@ -2346,20 +2341,20 @@ static void yy_reduce(
|
|||
break;
|
||||
case 113: /* create_table_args ::= LP columnlist RP */
|
||||
{
|
||||
yymsp[-2].minor.yy374 = tSetCreateSQLElems(yymsp[-1].minor.yy449, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE);
|
||||
yymsp[-2].minor.yy374 = tSetCreateSQLElems(yymsp[-1].minor.yy347, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE);
|
||||
setSQLInfo(pInfo, yymsp[-2].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE);
|
||||
}
|
||||
break;
|
||||
case 114: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */
|
||||
{
|
||||
yymsp[-6].minor.yy374 = tSetCreateSQLElems(yymsp[-5].minor.yy449, yymsp[-1].minor.yy449, NULL, NULL, NULL, TSQL_CREATE_STABLE);
|
||||
yymsp[-6].minor.yy374 = tSetCreateSQLElems(yymsp[-5].minor.yy347, yymsp[-1].minor.yy347, NULL, NULL, NULL, TSQL_CREATE_STABLE);
|
||||
setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE);
|
||||
}
|
||||
break;
|
||||
case 115: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */
|
||||
{
|
||||
yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n;
|
||||
yymsp[-6].minor.yy374 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy494, NULL, TSQL_CREATE_TABLE_FROM_STABLE);
|
||||
yymsp[-6].minor.yy374 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy347, NULL, TSQL_CREATE_TABLE_FROM_STABLE);
|
||||
setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE);
|
||||
}
|
||||
break;
|
||||
|
@ -2370,12 +2365,12 @@ static void yy_reduce(
|
|||
}
|
||||
break;
|
||||
case 117: /* columnlist ::= columnlist COMMA column */
|
||||
{yylhsminor.yy449 = tFieldListAppend(yymsp[-2].minor.yy449, &yymsp[0].minor.yy181); }
|
||||
yymsp[-2].minor.yy449 = yylhsminor.yy449;
|
||||
{yylhsminor.yy347 = taosArrayPush(yymsp[-2].minor.yy347, &yymsp[0].minor.yy181); }
|
||||
yymsp[-2].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 118: /* columnlist ::= column */
|
||||
{yylhsminor.yy449 = tFieldListAppend(NULL, &yymsp[0].minor.yy181);}
|
||||
yymsp[0].minor.yy449 = yylhsminor.yy449;
|
||||
{yylhsminor.yy347 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy347, &yymsp[0].minor.yy181);}
|
||||
yymsp[0].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 119: /* column ::= ids typename */
|
||||
{
|
||||
|
@ -2384,12 +2379,12 @@ static void yy_reduce(
|
|||
yymsp[-1].minor.yy181 = yylhsminor.yy181;
|
||||
break;
|
||||
case 120: /* tagitemlist ::= tagitemlist COMMA tagitem */
|
||||
{ yylhsminor.yy494 = tVariantListAppend(yymsp[-2].minor.yy494, &yymsp[0].minor.yy312, -1); }
|
||||
yymsp[-2].minor.yy494 = yylhsminor.yy494;
|
||||
{ yylhsminor.yy347 = tVariantListAppend(yymsp[-2].minor.yy347, &yymsp[0].minor.yy312, -1); }
|
||||
yymsp[-2].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 121: /* tagitemlist ::= tagitem */
|
||||
{ yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1); }
|
||||
yymsp[0].minor.yy494 = yylhsminor.yy494;
|
||||
{ yylhsminor.yy347 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1); }
|
||||
yymsp[0].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 122: /* tagitem ::= INTEGER */
|
||||
case 123: /* tagitem ::= FLOAT */ yytestcase(yyruleno==123);
|
||||
|
@ -2416,7 +2411,7 @@ static void yy_reduce(
|
|||
break;
|
||||
case 131: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
|
||||
{
|
||||
yylhsminor.yy150 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy224, yymsp[-9].minor.yy494, yymsp[-8].minor.yy66, yymsp[-4].minor.yy494, yymsp[-3].minor.yy494, &yymsp[-7].minor.yy314, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy494, &yymsp[0].minor.yy188, &yymsp[-1].minor.yy188);
|
||||
yylhsminor.yy150 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy224, yymsp[-9].minor.yy347, yymsp[-8].minor.yy66, yymsp[-4].minor.yy347, yymsp[-3].minor.yy347, &yymsp[-7].minor.yy314, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy347, &yymsp[0].minor.yy188, &yymsp[-1].minor.yy188);
|
||||
}
|
||||
yymsp[-11].minor.yy150 = yylhsminor.yy150;
|
||||
break;
|
||||
|
@ -2475,45 +2470,45 @@ static void yy_reduce(
|
|||
{ yymsp[1].minor.yy0.n = 0; }
|
||||
break;
|
||||
case 145: /* from ::= FROM tablelist */
|
||||
{yymsp[-1].minor.yy494 = yymsp[0].minor.yy494;}
|
||||
{yymsp[-1].minor.yy347 = yymsp[0].minor.yy347;}
|
||||
break;
|
||||
case 146: /* tablelist ::= ids cpxName */
|
||||
{
|
||||
toTSDBType(yymsp[-1].minor.yy0.type);
|
||||
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
|
||||
yylhsminor.yy494 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
|
||||
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[-1].minor.yy0, -1); // table alias name
|
||||
yylhsminor.yy347 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
|
||||
yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[-1].minor.yy0, -1); // table alias name
|
||||
}
|
||||
yymsp[-1].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[-1].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 147: /* tablelist ::= ids cpxName ids */
|
||||
{
|
||||
toTSDBType(yymsp[-2].minor.yy0.type);
|
||||
toTSDBType(yymsp[0].minor.yy0.type);
|
||||
yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n;
|
||||
yylhsminor.yy494 = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
|
||||
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[0].minor.yy0, -1);
|
||||
yylhsminor.yy347 = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
|
||||
yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[0].minor.yy0, -1);
|
||||
}
|
||||
yymsp[-2].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[-2].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 148: /* tablelist ::= tablelist COMMA ids cpxName */
|
||||
{
|
||||
toTSDBType(yymsp[-1].minor.yy0.type);
|
||||
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
|
||||
yylhsminor.yy494 = tVariantListAppendToken(yymsp[-3].minor.yy494, &yymsp[-1].minor.yy0, -1);
|
||||
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[-1].minor.yy0, -1);
|
||||
yylhsminor.yy347 = tVariantListAppendToken(yymsp[-3].minor.yy347, &yymsp[-1].minor.yy0, -1);
|
||||
yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[-1].minor.yy0, -1);
|
||||
}
|
||||
yymsp[-3].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[-3].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 149: /* tablelist ::= tablelist COMMA ids cpxName ids */
|
||||
{
|
||||
toTSDBType(yymsp[-2].minor.yy0.type);
|
||||
toTSDBType(yymsp[0].minor.yy0.type);
|
||||
yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n;
|
||||
yylhsminor.yy494 = tVariantListAppendToken(yymsp[-4].minor.yy494, &yymsp[-2].minor.yy0, -1);
|
||||
yylhsminor.yy494 = tVariantListAppendToken(yylhsminor.yy494, &yymsp[0].minor.yy0, -1);
|
||||
yylhsminor.yy347 = tVariantListAppendToken(yymsp[-4].minor.yy347, &yymsp[-2].minor.yy0, -1);
|
||||
yylhsminor.yy347 = tVariantListAppendToken(yylhsminor.yy347, &yymsp[0].minor.yy0, -1);
|
||||
}
|
||||
yymsp[-4].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[-4].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 150: /* tmvar ::= VARIABLE */
|
||||
{yylhsminor.yy0 = yymsp[0].minor.yy0;}
|
||||
|
@ -2529,7 +2524,7 @@ static void yy_reduce(
|
|||
{memset(&yymsp[1].minor.yy314, 0, sizeof(yymsp[1].minor.yy314));}
|
||||
break;
|
||||
case 154: /* fill_opt ::= */
|
||||
{yymsp[1].minor.yy494 = 0; }
|
||||
{yymsp[1].minor.yy347 = 0; }
|
||||
break;
|
||||
case 155: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */
|
||||
{
|
||||
|
@ -2537,14 +2532,14 @@ static void yy_reduce(
|
|||
toTSDBType(yymsp[-3].minor.yy0.type);
|
||||
tVariantCreate(&A, &yymsp[-3].minor.yy0);
|
||||
|
||||
tVariantListInsert(yymsp[-1].minor.yy494, &A, -1, 0);
|
||||
yymsp[-5].minor.yy494 = yymsp[-1].minor.yy494;
|
||||
tVariantListInsert(yymsp[-1].minor.yy347, &A, -1, 0);
|
||||
yymsp[-5].minor.yy347 = yymsp[-1].minor.yy347;
|
||||
}
|
||||
break;
|
||||
case 156: /* fill_opt ::= FILL LP ID RP */
|
||||
{
|
||||
toTSDBType(yymsp[-1].minor.yy0.type);
|
||||
yymsp[-3].minor.yy494 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
|
||||
yymsp[-3].minor.yy347 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
|
||||
}
|
||||
break;
|
||||
case 157: /* sliding_opt ::= SLIDING LP tmvar RP */
|
||||
|
@ -2555,23 +2550,23 @@ static void yy_reduce(
|
|||
break;
|
||||
case 159: /* orderby_opt ::= */
|
||||
case 167: /* groupby_opt ::= */ yytestcase(yyruleno==167);
|
||||
{yymsp[1].minor.yy494 = 0;}
|
||||
{yymsp[1].minor.yy347 = 0;}
|
||||
break;
|
||||
case 160: /* orderby_opt ::= ORDER BY sortlist */
|
||||
case 168: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==168);
|
||||
{yymsp[-2].minor.yy494 = yymsp[0].minor.yy494;}
|
||||
{yymsp[-2].minor.yy347 = yymsp[0].minor.yy347;}
|
||||
break;
|
||||
case 161: /* sortlist ::= sortlist COMMA item sortorder */
|
||||
{
|
||||
yylhsminor.yy494 = tVariantListAppend(yymsp[-3].minor.yy494, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82);
|
||||
yylhsminor.yy347 = tVariantListAppend(yymsp[-3].minor.yy347, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82);
|
||||
}
|
||||
yymsp[-3].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[-3].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 162: /* sortlist ::= item sortorder */
|
||||
{
|
||||
yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82);
|
||||
yylhsminor.yy347 = tVariantListAppend(NULL, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82);
|
||||
}
|
||||
yymsp[-1].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[-1].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 163: /* item ::= ids cpxName */
|
||||
{
|
||||
|
@ -2593,15 +2588,15 @@ static void yy_reduce(
|
|||
break;
|
||||
case 169: /* grouplist ::= grouplist COMMA item */
|
||||
{
|
||||
yylhsminor.yy494 = tVariantListAppend(yymsp[-2].minor.yy494, &yymsp[0].minor.yy312, -1);
|
||||
yylhsminor.yy347 = tVariantListAppend(yymsp[-2].minor.yy347, &yymsp[0].minor.yy312, -1);
|
||||
}
|
||||
yymsp[-2].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[-2].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 170: /* grouplist ::= item */
|
||||
{
|
||||
yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1);
|
||||
yylhsminor.yy347 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1);
|
||||
}
|
||||
yymsp[0].minor.yy494 = yylhsminor.yy494;
|
||||
yymsp[0].minor.yy347 = yylhsminor.yy347;
|
||||
break;
|
||||
case 171: /* having_opt ::= */
|
||||
case 181: /* where_opt ::= */ yytestcase(yyruleno==181);
|
||||
|
@ -2771,7 +2766,7 @@ static void yy_reduce(
|
|||
case 221: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
|
||||
{
|
||||
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy449, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy347, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
|
||||
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||
}
|
||||
break;
|
||||
|
@ -2780,7 +2775,7 @@ static void yy_reduce(
|
|||
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
|
||||
|
||||
toTSDBType(yymsp[0].minor.yy0.type);
|
||||
tVariantList* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
|
||||
SArray* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
|
||||
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
|
||||
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||
|
@ -2789,7 +2784,7 @@ static void yy_reduce(
|
|||
case 223: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
|
||||
{
|
||||
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy449, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy347, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
|
||||
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||
}
|
||||
break;
|
||||
|
@ -2798,7 +2793,7 @@ static void yy_reduce(
|
|||
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
|
||||
|
||||
toTSDBType(yymsp[0].minor.yy0.type);
|
||||
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
|
||||
SArray* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
|
||||
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
|
||||
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
|
||||
|
@ -2809,7 +2804,7 @@ static void yy_reduce(
|
|||
yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n;
|
||||
|
||||
toTSDBType(yymsp[-1].minor.yy0.type);
|
||||
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
|
||||
SArray* A = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
|
||||
|
||||
toTSDBType(yymsp[0].minor.yy0.type);
|
||||
A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1);
|
||||
|
@ -2823,7 +2818,7 @@ static void yy_reduce(
|
|||
yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n;
|
||||
|
||||
toTSDBType(yymsp[-2].minor.yy0.type);
|
||||
tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
|
||||
SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
|
||||
A = tVariantListAppend(A, &yymsp[0].minor.yy312, -1);
|
||||
|
||||
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
|
||||
|
|
|
@ -70,6 +70,13 @@ void* taosArrayGet(const SArray* pArray, size_t index);
|
|||
*/
|
||||
void* taosArrayGetP(const SArray* pArray, size_t index);
|
||||
|
||||
/**
|
||||
* get the last element in the array list
|
||||
* @param pArray
|
||||
* @return
|
||||
*/
|
||||
void* taosArrayGetLast(const SArray* pArray);
|
||||
|
||||
/**
|
||||
* return the size of array
|
||||
* @param pArray
|
||||
|
@ -117,6 +124,13 @@ void taosArrayClear(SArray* pArray);
|
|||
*/
|
||||
void taosArrayDestroy(SArray* pArray);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pArray
|
||||
* @param fp
|
||||
*/
|
||||
void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*));
|
||||
|
||||
/**
|
||||
* sort the array
|
||||
* @param pArray
|
||||
|
|
|
@ -99,6 +99,10 @@ void* taosArrayGetP(const SArray* pArray, size_t index) {
|
|||
return *(void**)d;
|
||||
}
|
||||
|
||||
void* taosArrayGetLast(const SArray* pArray) {
|
||||
return TARRAY_GET_ELEM(pArray, pArray->size - 1);
|
||||
}
|
||||
|
||||
size_t taosArrayGetSize(const SArray* pArray) { return pArray->size; }
|
||||
|
||||
void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
|
||||
|
@ -189,6 +193,18 @@ void taosArrayDestroy(SArray* pArray) {
|
|||
free(pArray);
|
||||
}
|
||||
|
||||
void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*)) {
|
||||
if (fp == NULL) {
|
||||
return taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < pArray->size; ++i) {
|
||||
fp(TARRAY_GET_ELEM(pArray, i));
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*)) {
|
||||
assert(pArray != NULL);
|
||||
assert(compar != NULL);
|
||||
|
|
Loading…
Reference in New Issue