未验证 提交 7d8ca438 编写于 作者: H haojun Liao 提交者: GitHub

Merge pull request #5401 from taosdata/feature/qrefactor

Feature/qrefactor
...@@ -133,6 +133,7 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo); ...@@ -133,6 +133,7 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo);
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex); bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscQueryTags(SQueryInfo* pQueryInfo); bool tscQueryTags(SQueryInfo* pQueryInfo);
bool tscMultiRoundQuery(SQueryInfo* pQueryInfo, int32_t tableIndex); bool tscMultiRoundQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscQueryBlockInfo(SQueryInfo* pQueryInfo);
SSqlExpr* tscAddFuncInSelectClause(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId, SSqlExpr* tscAddFuncInSelectClause(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId,
SColumnIndex* pIndex, SSchema* pColSchema, int16_t colType); SColumnIndex* pIndex, SSchema* pColSchema, int16_t colType);
......
...@@ -100,6 +100,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalMerger *pReducer, tOrderDescr ...@@ -100,6 +100,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalMerger *pReducer, tOrderDescr
} else if (functionId == TSDB_FUNC_APERCT) { } else if (functionId == TSDB_FUNC_APERCT) {
pCtx->param[0].i64 = pExpr->param[0].i64; pCtx->param[0].i64 = pExpr->param[0].i64;
pCtx->param[0].nType = pExpr->param[0].nType; pCtx->param[0].nType = pExpr->param[0].nType;
} else if (functionId == TSDB_FUNC_BLKINFO) {
pCtx->param[0].i64 = pExpr->param[0].i64;
pCtx->param[0].nType = pExpr->param[0].nType;
pCtx->numOfParams = 1;
} }
pCtx->interBufBytes = pExpr->interBytes; pCtx->interBufBytes = pExpr->interBytes;
...@@ -951,10 +955,10 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp ...@@ -951,10 +955,10 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp
// todo extract function // todo extract function
int64_t actualETime = (pQueryInfo->order.order == TSDB_ORDER_ASC)? pQueryInfo->window.ekey: pQueryInfo->window.skey; int64_t actualETime = (pQueryInfo->order.order == TSDB_ORDER_ASC)? pQueryInfo->window.ekey: pQueryInfo->window.skey;
tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput); void** pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput);
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalMerge->resColModel->capacity); pResPages[i] = calloc(1, pField->bytes * pLocalMerge->resColModel->capacity);
} }
while (1) { while (1) {
...@@ -966,7 +970,7 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp ...@@ -966,7 +970,7 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp
if (pQueryInfo->limit.offset > 0) { if (pQueryInfo->limit.offset > 0) {
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
memmove(pResPages[i]->data, pResPages[i]->data + pField->bytes * pQueryInfo->limit.offset, memmove(pResPages[i], ((char*)pResPages[i]) + pField->bytes * pQueryInfo->limit.offset,
(size_t)(newRows * pField->bytes)); (size_t)(newRows * pField->bytes));
} }
} }
...@@ -1010,7 +1014,7 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp ...@@ -1010,7 +1014,7 @@ static void doFillResult(SSqlObj *pSql, SLocalMerger *pLocalMerge, bool doneOutp
int32_t offset = 0; int32_t offset = 0;
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
memcpy(pRes->data + offset * pRes->numOfRows, pResPages[i]->data, (size_t)(pField->bytes * pRes->numOfRows)); memcpy(pRes->data + offset * pRes->numOfRows, pResPages[i], (size_t)(pField->bytes * pRes->numOfRows));
offset += pField->bytes; offset += pField->bytes;
} }
......
...@@ -75,7 +75,6 @@ static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int3 ...@@ -75,7 +75,6 @@ static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int3
static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnList* pIdList, int16_t bytes, static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnList* pIdList, int16_t bytes,
int8_t type, char* fieldName, SSqlExpr* pSqlExpr); int8_t type, char* fieldName, SSqlExpr* pSqlExpr);
static int32_t convertFunctionId(int32_t optr, int16_t* functionId);
static uint8_t convertOptr(SStrToken *pToken); static uint8_t convertOptr(SStrToken *pToken);
static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool intervalQuery); static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool intervalQuery);
...@@ -176,11 +175,11 @@ static uint8_t convertOptr(SStrToken *pToken) { ...@@ -176,11 +175,11 @@ static uint8_t convertOptr(SStrToken *pToken) {
static bool validateDebugFlag(int32_t v) { static bool validateDebugFlag(int32_t v) {
const static int validFlag[] = {131, 135, 143}; const static int validFlag[] = {131, 135, 143};
for (int i = 0; i < tListLen(validFlag); i++) { for (int i = 0; i < tListLen(validFlag); i++) {
if (v == validFlag[i]) { if (v == validFlag[i]) {
return true; return true;
} }
} }
return false; return false;
} }
...@@ -584,8 +583,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -584,8 +583,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1); SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1);
pCmd->payload[t->n] = ' '; // add sep pCmd->payload[t->n] = ' '; // add sep
strncpy(&pCmd->payload[t->n + 1], t1->z, t1->n); strncpy(&pCmd->payload[t->n + 1], t1->z, t1->n);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
case TSDB_SQL_CREATE_TABLE: { case TSDB_SQL_CREATE_TABLE: {
...@@ -1537,6 +1536,7 @@ bool isValidDistinctSql(SQueryInfo* pQueryInfo) { ...@@ -1537,6 +1536,7 @@ bool isValidDistinctSql(SQueryInfo* pQueryInfo) {
} }
return false; return false;
} }
int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool intervalQuery) { int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool intervalQuery) {
assert(pSelection != NULL && pCmd != NULL); assert(pSelection != NULL && pCmd != NULL);
...@@ -1550,6 +1550,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1550,6 +1550,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
if (pQueryInfo->colList == NULL) { if (pQueryInfo->colList == NULL) {
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
} }
bool hasDistinct = false; bool hasDistinct = false;
for (int32_t i = 0; i < pSelection->nExpr; ++i) { for (int32_t i = 0; i < pSelection->nExpr; ++i) {
int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo); int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
...@@ -1558,26 +1559,25 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1558,26 +1559,25 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
if (hasDistinct == false) { if (hasDistinct == false) {
hasDistinct = (pItem->distinct == true); hasDistinct = (pItem->distinct == true);
} }
// project on all fields
int32_t optr = pItem->pNode->nSQLOptr;
if (optr == TK_ALL || optr == TK_ID || optr == TK_STRING || optr == TK_INTEGER || optr == TK_FLOAT) { int32_t type = pItem->pNode->type;
// it is actually a function, but the function name is invalid if (type == SQL_NODE_SQLFUNCTION) {
if (pItem->pNode->nSQLOptr == TK_ID && (pItem->pNode->colInfo.z == NULL && pItem->pNode->colInfo.n == 0)) { pItem->pNode->functionId = isValidFunction(pItem->pNode->operand.z, pItem->pNode->operand.n);
if (pItem->pNode->functionId < 0) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
} }
// select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2
if (addProjectionExprAndResultField(pCmd, pQueryInfo, pItem) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
} else if (pItem->pNode->nSQLOptr >= TK_COUNT && pItem->pNode->nSQLOptr <= TK_TBID) {
// sql function in selection clause, append sql function info in pSqlCmd structure sequentially // sql function in selection clause, append sql function info in pSqlCmd structure sequentially
if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, pItem, true) != TSDB_CODE_SUCCESS) { if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, pItem, true) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else if (type == SQL_NODE_TABLE_COLUMN || type == SQL_NODE_VALUE) {
} else if (pItem->pNode->nSQLOptr >= TK_PLUS && pItem->pNode->nSQLOptr <= TK_REM) { // use the dynamic array list to decide if the function is valid or not
// select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2
if (addProjectionExprAndResultField(pCmd, pQueryInfo, pItem) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
} else if (type == SQL_NODE_EXPR) {
int32_t code = handleArithmeticExpr(pCmd, clauseIndex, i, pItem); int32_t code = handleArithmeticExpr(pCmd, clauseIndex, i, pItem);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
...@@ -1600,7 +1600,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel ...@@ -1600,7 +1600,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
// there is only one user-defined column in the final result field, add the timestamp column. // there is only one user-defined column in the final result field, add the timestamp column.
size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList); size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList);
if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo)) { if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo) && !tscQueryBlockInfo(pQueryInfo)) {
addPrimaryTsColIntoResult(pQueryInfo); addPrimaryTsColIntoResult(pQueryInfo);
} }
...@@ -1727,7 +1727,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t ...@@ -1727,7 +1727,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
const char* msg1 = "tag for normal table query is not allowed"; const char* msg1 = "tag for normal table query is not allowed";
int32_t startPos = (int32_t)tscSqlExprNumOfExprs(pQueryInfo); int32_t startPos = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
int32_t optr = pItem->pNode->nSQLOptr; int32_t optr = pItem->pNode->tokenId;
if (optr == TK_ALL) { // project on all fields if (optr == TK_ALL) { // project on all fields
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_PROJECTION_QUERY); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_PROJECTION_QUERY);
...@@ -1757,13 +1757,13 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t ...@@ -1757,13 +1757,13 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
index.columnIndex = (pQueryInfo->udColumnId--); index.columnIndex = (pQueryInfo->udColumnId--);
index.tableIndex = 0; index.tableIndex = 0;
SSchema colSchema = tGetUserSpecifiedColumnSchema(&pItem->pNode->val, &pItem->pNode->token, pItem->aliasName); SSchema colSchema = tGetUserSpecifiedColumnSchema(&pItem->pNode->value, &pItem->pNode->token, pItem->aliasName);
SSqlExpr* pExpr = SSqlExpr* pExpr =
tscAddFuncInSelectClause(pQueryInfo, startPos, TSDB_FUNC_PRJ, &index, &colSchema, TSDB_COL_UDC); tscAddFuncInSelectClause(pQueryInfo, startPos, TSDB_FUNC_PRJ, &index, &colSchema, TSDB_COL_UDC);
// NOTE: the first parameter is reserved for the tag column id during join query process. // NOTE: the first parameter is reserved for the tag column id during join query process.
pExpr->numOfParams = 2; pExpr->numOfParams = 2;
tVariantAssign(&pExpr->param[1], &pItem->pNode->val); tVariantAssign(&pExpr->param[1], &pItem->pNode->value);
} else if (optr == TK_ID) { } else if (optr == TK_ID) {
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
...@@ -1872,19 +1872,21 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT ...@@ -1872,19 +1872,21 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT
} }
} }
static void updateLastQueryInfoForGroupby(SQueryInfo* pQueryInfo, STableMeta* pTableMeta, int32_t functionId, int32_t index) {
if (functionId != TSDB_FUNC_LAST) { // todo refactor
return;
}
void setLastOrderForGoupBy(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo) { // todo refactor
SSqlGroupbyExpr* pGroupBy = &pQueryInfo->groupbyExpr; SSqlGroupbyExpr* pGroupBy = &pQueryInfo->groupbyExpr;
if (pGroupBy->numOfGroupCols > 0) { if (pGroupBy->numOfGroupCols > 0) {
size_t idx = taosArrayGetSize(pQueryInfo->exprList);
for(int32_t k = 0; k < pGroupBy->numOfGroupCols; ++k) { for(int32_t k = 0; k < pGroupBy->numOfGroupCols; ++k) {
SColIndex* pIndex = taosArrayGet(pGroupBy->columnInfo, k); SColIndex* pIndex = taosArrayGet(pGroupBy->columnInfo, k);
if (!TSDB_COL_IS_TAG(pIndex->flag) && pIndex->colIndex < tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { // group by normal columns if (!TSDB_COL_IS_TAG(pIndex->flag) && pIndex->colIndex < tscGetNumOfColumns(pTableMeta)) { // group by normal columns
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, idx - 1); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, index);
pExpr->numOfParams = 1; pExpr->numOfParams = 1;
pExpr->param->i64 = TSDB_ORDER_ASC; pExpr->param->i64 = TSDB_ORDER_ASC;
break; return;
} }
} }
} }
...@@ -1892,7 +1894,7 @@ void setLastOrderForGoupBy(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInf ...@@ -1892,7 +1894,7 @@ void setLastOrderForGoupBy(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInf
int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, bool finalResult) { int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, bool finalResult) {
STableMetaInfo* pTableMetaInfo = NULL; STableMetaInfo* pTableMetaInfo = NULL;
int32_t optr = pItem->pNode->nSQLOptr; int32_t functionId = pItem->pNode->functionId;
const char* msg1 = "not support column types"; const char* msg1 = "not support column types";
const char* msg2 = "invalid parameters"; const char* msg2 = "invalid parameters";
...@@ -1902,28 +1904,22 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -1902,28 +1904,22 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const char* msg6 = "function applied to tags not allowed"; const char* msg6 = "function applied to tags not allowed";
const char* msg7 = "normal table can not apply this function"; const char* msg7 = "normal table can not apply this function";
const char* msg8 = "multi-columns selection does not support alias column name"; const char* msg8 = "multi-columns selection does not support alias column name";
const char* msg9 = "invalid function";
const char* msg10 = "diff can no be applied to unsigned numeric type"; const char* msg10 = "diff can no be applied to unsigned numeric type";
switch (optr) { switch (functionId) {
case TK_COUNT: { case TSDB_FUNC_COUNT: {
/* more than one parameter for count() function */ /* more than one parameter for count() function */
if (pItem->pNode->pParam != NULL && pItem->pNode->pParam->nExpr != 1) { if (pItem->pNode->pParam != NULL && pItem->pNode->pParam->nExpr != 1) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
int16_t functionID = 0;
if (convertFunctionId(optr, &functionID) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
SSqlExpr* pExpr = NULL; SSqlExpr* pExpr = NULL;
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (pItem->pNode->pParam != NULL) { if (pItem->pNode->pParam != NULL) {
tSqlExprItem* pParamElem = &pItem->pNode->pParam->a[0]; tSqlExprItem* pParamElem = &pItem->pNode->pParam->a[0];
SStrToken* pToken = &pParamElem->pNode->colInfo; SStrToken* pToken = &pParamElem->pNode->colInfo;
int16_t sqlOptr = pParamElem->pNode->nSQLOptr; int16_t sqlOptr = pParamElem->pNode->tokenId;
if ((pToken->z == NULL || pToken->n == 0) if ((pToken->z == NULL || pToken->n == 0)
&& (TK_INTEGER != sqlOptr)) /*select count(1) from table*/ { && (TK_INTEGER != sqlOptr)) /*select count(1) from table*/ {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
...@@ -1939,11 +1935,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -1939,11 +1935,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, false); pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, false);
} else if (sqlOptr == TK_INTEGER) { // select count(1) from table1 } else if (sqlOptr == TK_INTEGER) { // select count(1) from table1
char buf[8] = {0}; char buf[8] = {0};
int64_t val = -1; int64_t val = -1;
tVariant* pVariant = &pParamElem->pNode->val; tVariant* pVariant = &pParamElem->pNode->value;
if (pVariant->nType == TSDB_DATA_TYPE_BIGINT) { if (pVariant->nType == TSDB_DATA_TYPE_BIGINT) {
tVariantDump(pVariant, buf, TSDB_DATA_TYPE_BIGINT, true); tVariantDump(pVariant, buf, TSDB_DATA_TYPE_BIGINT, true);
val = GET_INT64_VAL(buf); val = GET_INT64_VAL(buf);
...@@ -1951,7 +1947,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -1951,7 +1947,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if (val == 1) { if (val == 1) {
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, false); pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, false);
} else { } else {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
...@@ -1971,12 +1967,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -1971,12 +1967,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
} }
int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, isTag); pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, isTag);
} }
} else { // count(*) is equalled to count(primary_timestamp_key) } else { // count(*) is equalled to count(primary_timestamp_key)
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; int32_t size = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, false); pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, TSDB_DATA_TYPE_BIGINT, size, getNewResColId(pQueryInfo), size, false);
} }
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
...@@ -2001,29 +1997,29 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2001,29 +1997,29 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
case TK_SUM: case TSDB_FUNC_SUM:
case TK_AVG: case TSDB_FUNC_AVG:
case TK_RATE: case TSDB_FUNC_RATE:
case TK_IRATE: case TSDB_FUNC_IRATE:
case TK_SUM_RATE: case TSDB_FUNC_SUM_RATE:
case TK_SUM_IRATE: case TSDB_FUNC_SUM_IRATE:
case TK_AVG_RATE: case TSDB_FUNC_AVG_RATE:
case TK_AVG_IRATE: case TSDB_FUNC_AVG_IRATE:
case TK_TWA: case TSDB_FUNC_TWA:
case TK_MIN: case TSDB_FUNC_MIN:
case TK_MAX: case TSDB_FUNC_MAX:
case TK_DIFF: case TSDB_FUNC_DIFF:
case TK_STDDEV: case TSDB_FUNC_STDDEV:
case TK_LEASTSQUARES: { case TSDB_FUNC_LEASTSQR: {
// 1. valid the number of parameters // 1. valid the number of parameters
if (pItem->pNode->pParam == NULL || (optr != TK_LEASTSQUARES && pItem->pNode->pParam->nExpr != 1) || if (pItem->pNode->pParam == NULL || (functionId != TSDB_FUNC_LEASTSQR && pItem->pNode->pParam->nExpr != 1) ||
(optr == TK_LEASTSQUARES && pItem->pNode->pParam->nExpr != 3)) { (functionId == TSDB_FUNC_LEASTSQR && pItem->pNode->pParam->nExpr != 3)) {
/* no parameters or more than one parameter for function */ /* no parameters or more than one parameter for function */
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]); tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
if (pParamElem->pNode->nSQLOptr != TK_ALL && pParamElem->pNode->nSQLOptr != TK_ID) { if (pParamElem->pNode->tokenId != TK_ALL && pParamElem->pNode->tokenId != TK_ID) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
...@@ -2043,7 +2039,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2043,7 +2039,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if (!IS_NUMERIC_TYPE(colType)) { if (!IS_NUMERIC_TYPE(colType)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
} else if (IS_UNSIGNED_NUMERIC_TYPE(colType) && optr == TK_DIFF) { } else if (IS_UNSIGNED_NUMERIC_TYPE(colType) && functionId == TSDB_FUNC_DIFF) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg10); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg10);
} }
...@@ -2051,18 +2047,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2051,18 +2047,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
int16_t resultSize = 0; int16_t resultSize = 0;
int32_t intermediateResSize = 0; int32_t intermediateResSize = 0;
int16_t functionID = 0; if (getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &resultType, &resultSize,
if (convertFunctionId(optr, &functionID) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
if (getResultDataInfo(pSchema->type, pSchema->bytes, functionID, 0, &resultType, &resultSize,
&intermediateResSize, 0, false) != TSDB_CODE_SUCCESS) { &intermediateResSize, 0, false) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// set the first column ts for diff query // set the first column ts for diff query
if (optr == TK_DIFF) { if (functionId == TSDB_FUNC_DIFF) {
colIndex += 1; colIndex += 1;
SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0}; SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0};
SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE,
...@@ -2077,19 +2068,19 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2077,19 +2068,19 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
} }
SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, resultType, resultSize, getNewResColId(pQueryInfo), resultSize, false); SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pQueryInfo), resultSize, false);
if (optr == TK_LEASTSQUARES) { if (functionId == TSDB_FUNC_LEASTSQR) {
/* set the leastsquares parameters */ /* set the leastsquares parameters */
char val[8] = {0}; char val[8] = {0};
if (tVariantDump(&pParamElem[1].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { if (tVariantDump(&pParamElem[1].pNode->value, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES); addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES);
memset(val, 0, tListLen(val)); memset(val, 0, tListLen(val));
if (tVariantDump(&pParamElem[2].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { if (tVariantDump(&pParamElem[2].pNode->value, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -2115,21 +2106,16 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2115,21 +2106,16 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tscInsertPrimaryTsSourceColumn(pQueryInfo, &index); tscInsertPrimaryTsSourceColumn(pQueryInfo, &index);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
case TK_FIRST: case TSDB_FUNC_FIRST:
case TK_LAST: case TSDB_FUNC_LAST:
case TK_SPREAD: case TSDB_FUNC_SPREAD:
case TK_LAST_ROW: case TSDB_FUNC_LAST_ROW:
case TK_INTERP: { case TSDB_FUNC_INTERP: {
bool requireAllFields = (pItem->pNode->pParam == NULL); bool requireAllFields = (pItem->pNode->pParam == NULL);
int16_t functionID = 0;
if (convertFunctionId(optr, &functionID) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg9);
}
// NOTE: has time range condition or normal column filter condition, the last_row query will be transferred to last query // NOTE: has time range condition or normal column filter condition, the last_row query will be transferred to last query
SConvertFunc cvtFunc = {.originFuncId = functionID, .execFuncId = functionID}; SConvertFunc cvtFunc = {.originFuncId = functionId, .execFuncId = functionId};
if (functionID == TSDB_FUNC_LAST_ROW && ((!TSWINDOW_IS_EQUAL(pQueryInfo->window, TSWINDOW_INITIALIZER)) || (hasNormalColumnFilter(pQueryInfo)))) { if (functionId == TSDB_FUNC_LAST_ROW && ((!TSWINDOW_IS_EQUAL(pQueryInfo->window, TSWINDOW_INITIALIZER)) || (hasNormalColumnFilter(pQueryInfo)))) {
cvtFunc.execFuncId = TSDB_FUNC_LAST; cvtFunc.execFuncId = TSDB_FUNC_LAST;
} }
...@@ -2145,13 +2131,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2145,13 +2131,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
/* in first/last function, multiple columns can be add to resultset */ /* in first/last function, multiple columns can be add to resultset */
for (int32_t i = 0; i < pItem->pNode->pParam->nExpr; ++i) { for (int32_t i = 0; i < pItem->pNode->pParam->nExpr; ++i) {
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[i]); tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[i]);
if (pParamElem->pNode->nSQLOptr != TK_ALL && pParamElem->pNode->nSQLOptr != TK_ID) { if (pParamElem->pNode->tokenId != TK_ALL && pParamElem->pNode->tokenId != TK_ID) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (pParamElem->pNode->nSQLOptr == TK_ALL) { // select table.* if (pParamElem->pNode->tokenId == TK_ALL) { // select table.*
SStrToken tmpToken = pParamElem->pNode->colInfo; SStrToken tmpToken = pParamElem->pNode->colInfo;
if (getTableIndexByName(&tmpToken, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getTableIndexByName(&tmpToken, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
...@@ -2171,9 +2157,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2171,9 +2157,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (optr == TK_LAST) { updateLastQueryInfoForGroupby(pQueryInfo, pTableMetaInfo->pTableMeta, functionId, colIndex - 1);
setLastOrderForGoupBy(pQueryInfo, pTableMetaInfo);
}
} }
} else { } else {
...@@ -2189,19 +2173,16 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2189,19 +2173,16 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
} }
char name[TSDB_COL_NAME_LEN] = {0}; char name[TSDB_COL_NAME_LEN] = {0};
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex); SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex);
bool multiColOutput = pItem->pNode->pParam->nExpr > 1; bool multiColOutput = pItem->pNode->pParam->nExpr > 1;
setResultColName(name, pItem, cvtFunc.originFuncId, &pParamElem->pNode->colInfo, multiColOutput); setResultColName(name, pItem, cvtFunc.originFuncId, &pParamElem->pNode->colInfo, multiColOutput);
if (setExprInfoForFunctions(pCmd, pQueryInfo, pSchema, cvtFunc, name, colIndex++, &index, finalResult) != 0) { if (setExprInfoForFunctions(pCmd, pQueryInfo, pSchema, cvtFunc, name, colIndex + i, &index, finalResult) != 0) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (optr == TK_LAST) { updateLastQueryInfoForGroupby(pQueryInfo, pTableMetaInfo->pTableMeta, functionId, colIndex + i);
setLastOrderForGoupBy(pQueryInfo, pTableMetaInfo);
}
} }
} }
...@@ -2229,24 +2210,21 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2229,24 +2210,21 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
updateLastQueryInfoForGroupby(pQueryInfo, pTableMetaInfo->pTableMeta, functionId, colIndex);
colIndex++; colIndex++;
if (optr == TK_LAST) {
setLastOrderForGoupBy(pQueryInfo, pTableMetaInfo);
}
} }
numOfFields += tscGetNumOfColumns(pTableMetaInfo->pTableMeta); numOfFields += tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
case TK_TOP:
case TK_BOTTOM: case TSDB_FUNC_TOP:
case TK_PERCENTILE: case TSDB_FUNC_BOTTOM:
case TK_APERCENTILE: { case TSDB_FUNC_PERCT:
case TSDB_FUNC_APERCT: {
// 1. valid the number of parameters // 1. valid the number of parameters
if (pItem->pNode->pParam == NULL || pItem->pNode->pParam->nExpr != 2) { if (pItem->pNode->pParam == NULL || pItem->pNode->pParam->nExpr != 2) {
/* no parameters or more than one parameter for function */ /* no parameters or more than one parameter for function */
...@@ -2254,7 +2232,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2254,7 +2232,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
} }
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]); tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
if (pParamElem->pNode->nSQLOptr != TK_ID) { if (pParamElem->pNode->tokenId != TK_ID) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
...@@ -2282,11 +2260,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2282,11 +2260,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
} }
// 3. valid the parameters // 3. valid the parameters
if (pParamElem[1].pNode->nSQLOptr == TK_ID) { if (pParamElem[1].pNode->tokenId == TK_ID) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
tVariant* pVariant = &pParamElem[1].pNode->val; tVariant* pVariant = &pParamElem[1].pNode->value;
int8_t resultType = pSchema[index.columnIndex].type; int8_t resultType = pSchema[index.columnIndex].type;
int16_t resultSize = pSchema[index.columnIndex].bytes; int16_t resultSize = pSchema[index.columnIndex].bytes;
...@@ -2294,7 +2272,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2294,7 +2272,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
char val[8] = {0}; char val[8] = {0};
SSqlExpr* pExpr = NULL; SSqlExpr* pExpr = NULL;
if (optr == TK_PERCENTILE || optr == TK_APERCENTILE) { if (functionId == TSDB_FUNC_PERCT || functionId == TSDB_FUNC_APERCT) {
tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE, true); tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE, true);
double dp = GET_DOUBLE_VAL(val); double dp = GET_DOUBLE_VAL(val);
...@@ -2310,10 +2288,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2310,10 +2288,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
* for dp = 0, it is actually min, * for dp = 0, it is actually min,
* for dp = 100, it is max, * for dp = 100, it is max,
*/ */
int16_t functionId = 0;
if (convertFunctionId(optr, &functionId) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
tscInsertPrimaryTsSourceColumn(pQueryInfo, &index); tscInsertPrimaryTsSourceColumn(pQueryInfo, &index);
colIndex += 1; // the first column is ts colIndex += 1; // the first column is ts
...@@ -2327,11 +2301,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2327,11 +2301,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
} }
int16_t functionId = 0;
if (convertFunctionId(optr, &functionId) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
// todo REFACTOR // todo REFACTOR
// set the first column ts for top/bottom query // set the first column ts for top/bottom query
SColumnIndex index1 = {0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; SColumnIndex index1 = {0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
...@@ -2365,7 +2334,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2365,7 +2334,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
}; };
case TK_TBID: { case TSDB_FUNC_TID_TAG: {
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) { if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
...@@ -2433,7 +2402,31 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2433,7 +2402,31 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
case TSDB_FUNC_BLKINFO: {
// no parameters or more than one parameter for function
if (pItem->pNode->pParam != NULL && pItem->pNode->pParam->nExpr != 0) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
SColumnIndex index = {.tableIndex = 0, .columnIndex = TSDB_BLOCK_DIST_COLUMN_INDEX,};
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
SSchema s = {.name = "block_dist", .type = TSDB_DATA_TYPE_BINARY};
int32_t inter = 0;
int16_t resType = 0;
int16_t bytes = 0;
getResultDataInfo(TSDB_DATA_TYPE_INT, 4, TSDB_FUNC_BLKINFO, 0, &resType, &bytes, &inter, 0, 0);
s.bytes = bytes;
s.type = (uint8_t)resType;
SSqlExpr* pExpr = tscAddFuncInSelectClause(pQueryInfo, 0, TSDB_FUNC_BLKINFO, &index, &s, TSDB_COL_TAG);
pExpr->numOfParams = 1;
pExpr->param[0].i64 = pTableMetaInfo->pTableMeta->tableInfo.rowSize;
pExpr->param[0].nType = TSDB_DATA_TYPE_BIGINT;
return TSDB_CODE_SUCCESS;
}
default: default:
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -2458,8 +2451,8 @@ void getColumnName(tSqlExprItem* pItem, char* resultFieldName, int32_t nameLengt ...@@ -2458,8 +2451,8 @@ void getColumnName(tSqlExprItem* pItem, char* resultFieldName, int32_t nameLengt
if (pItem->aliasName != NULL) { if (pItem->aliasName != NULL) {
strncpy(resultFieldName, pItem->aliasName, nameLength); strncpy(resultFieldName, pItem->aliasName, nameLength);
} else { } else {
int32_t len = ((int32_t)pItem->pNode->operand.n < nameLength) ? (int32_t)pItem->pNode->operand.n : nameLength; int32_t len = ((int32_t)pItem->pNode->token.n < nameLength) ? (int32_t)pItem->pNode->token.n : nameLength;
strncpy(resultFieldName, pItem->pNode->operand.z, len); strncpy(resultFieldName, pItem->pNode->token.z, len);
} }
} }
...@@ -2599,87 +2592,6 @@ int32_t getColumnIndexByName(SSqlCmd* pCmd, const SStrToken* pToken, SQueryInfo* ...@@ -2599,87 +2592,6 @@ int32_t getColumnIndexByName(SSqlCmd* pCmd, const SStrToken* pToken, SQueryInfo*
return doGetColumnIndexByName(pCmd, &tmpToken, pQueryInfo, pIndex); return doGetColumnIndexByName(pCmd, &tmpToken, pQueryInfo, pIndex);
} }
int32_t convertFunctionId(int32_t optr, int16_t* functionId) {
switch (optr) {
case TK_COUNT:
*functionId = TSDB_FUNC_COUNT;
break;
case TK_SUM:
*functionId = TSDB_FUNC_SUM;
break;
case TK_AVG:
*functionId = TSDB_FUNC_AVG;
break;
case TK_RATE:
*functionId = TSDB_FUNC_RATE;
break;
case TK_IRATE:
*functionId = TSDB_FUNC_IRATE;
break;
case TK_SUM_RATE:
*functionId = TSDB_FUNC_SUM_RATE;
break;
case TK_SUM_IRATE:
*functionId = TSDB_FUNC_SUM_IRATE;
break;
case TK_AVG_RATE:
*functionId = TSDB_FUNC_AVG_RATE;
break;
case TK_AVG_IRATE:
*functionId = TSDB_FUNC_AVG_IRATE;
break;
case TK_MIN:
*functionId = TSDB_FUNC_MIN;
break;
case TK_MAX:
*functionId = TSDB_FUNC_MAX;
break;
case TK_STDDEV:
*functionId = TSDB_FUNC_STDDEV;
break;
case TK_PERCENTILE:
*functionId = TSDB_FUNC_PERCT;
break;
case TK_APERCENTILE:
*functionId = TSDB_FUNC_APERCT;
break;
case TK_FIRST:
*functionId = TSDB_FUNC_FIRST;
break;
case TK_LAST:
*functionId = TSDB_FUNC_LAST;
break;
case TK_LEASTSQUARES:
*functionId = TSDB_FUNC_LEASTSQR;
break;
case TK_TOP:
*functionId = TSDB_FUNC_TOP;
break;
case TK_BOTTOM:
*functionId = TSDB_FUNC_BOTTOM;
break;
case TK_DIFF:
*functionId = TSDB_FUNC_DIFF;
break;
case TK_SPREAD:
*functionId = TSDB_FUNC_SPREAD;
break;
case TK_TWA:
*functionId = TSDB_FUNC_TWA;
break;
case TK_INTERP:
*functionId = TSDB_FUNC_INTERP;
break;
case TK_LAST_ROW:
*functionId = TSDB_FUNC_LAST_ROW;
break;
default:
return -1;
}
return TSDB_CODE_SUCCESS;
}
int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
...@@ -3113,39 +3025,39 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, ...@@ -3113,39 +3025,39 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
colType = TSDB_DATA_TYPE_BIGINT; colType = TSDB_DATA_TYPE_BIGINT;
} else if (colType == TSDB_DATA_TYPE_FLOAT || colType == TSDB_DATA_TYPE_DOUBLE) { } else if (colType == TSDB_DATA_TYPE_FLOAT || colType == TSDB_DATA_TYPE_DOUBLE) {
colType = TSDB_DATA_TYPE_DOUBLE; colType = TSDB_DATA_TYPE_DOUBLE;
} else if ((colType == TSDB_DATA_TYPE_TIMESTAMP) && (TSDB_DATA_TYPE_BINARY == pRight->val.nType)) { } else if ((colType == TSDB_DATA_TYPE_TIMESTAMP) && (TSDB_DATA_TYPE_BINARY == pRight->value.nType)) {
int retVal = setColumnFilterInfoForTimestamp(pCmd, pQueryInfo, &pRight->val); int retVal = setColumnFilterInfoForTimestamp(pCmd, pQueryInfo, &pRight->value);
if (TSDB_CODE_SUCCESS != retVal) { if (TSDB_CODE_SUCCESS != retVal) {
return retVal; return retVal;
} }
} }
int32_t retVal = TSDB_CODE_SUCCESS; int32_t retVal = TSDB_CODE_SUCCESS;
if (pExpr->nSQLOptr == TK_LE || pExpr->nSQLOptr == TK_LT) { if (pExpr->tokenId == TK_LE || pExpr->tokenId == TK_LT) {
retVal = tVariantDump(&pRight->val, (char*)&pColumnFilter->upperBndd, colType, false); retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->upperBndd, colType, false);
// TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd
} else if (colType == TSDB_DATA_TYPE_BINARY) { } else if (colType == TSDB_DATA_TYPE_BINARY) {
pColumnFilter->pz = (int64_t)calloc(1, pRight->val.nLen + TSDB_NCHAR_SIZE); pColumnFilter->pz = (int64_t)calloc(1, pRight->value.nLen + TSDB_NCHAR_SIZE);
pColumnFilter->len = pRight->val.nLen; pColumnFilter->len = pRight->value.nLen;
retVal = tVariantDump(&pRight->val, (char*)pColumnFilter->pz, colType, false); retVal = tVariantDump(&pRight->value, (char*)pColumnFilter->pz, colType, false);
} else if (colType == TSDB_DATA_TYPE_NCHAR) { } else if (colType == TSDB_DATA_TYPE_NCHAR) {
// pRight->val.nLen + 1 is larger than the actual nchar string length // pRight->value.nLen + 1 is larger than the actual nchar string length
pColumnFilter->pz = (int64_t)calloc(1, (pRight->val.nLen + 1) * TSDB_NCHAR_SIZE); pColumnFilter->pz = (int64_t)calloc(1, (pRight->value.nLen + 1) * TSDB_NCHAR_SIZE);
retVal = tVariantDump(&pRight->val, (char*)pColumnFilter->pz, colType, false); retVal = tVariantDump(&pRight->value, (char*)pColumnFilter->pz, colType, false);
size_t len = twcslen((wchar_t*)pColumnFilter->pz); size_t len = twcslen((wchar_t*)pColumnFilter->pz);
pColumnFilter->len = len * TSDB_NCHAR_SIZE; pColumnFilter->len = len * TSDB_NCHAR_SIZE;
} else { } else {
retVal = tVariantDump(&pRight->val, (char*)&pColumnFilter->lowerBndd, colType, false); retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->lowerBndd, colType, false);
} }
if (retVal != TSDB_CODE_SUCCESS) { if (retVal != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
} }
switch (pExpr->nSQLOptr) { switch (pExpr->tokenId) {
case TK_LE: case TK_LE:
pColumnFilter->upperRelOptr = TSDB_RELATION_LESS_EQUAL; pColumnFilter->upperRelOptr = TSDB_RELATION_LESS_EQUAL;
break; break;
...@@ -3198,14 +3110,14 @@ typedef struct SCondExpr { ...@@ -3198,14 +3110,14 @@ typedef struct SCondExpr {
static int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t timePrecision); static int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t timePrecision);
static int32_t tSQLExprNodeToString(tSQLExpr* pExpr, char** str) { static int32_t tSQLExprNodeToString(tSQLExpr* pExpr, char** str) {
if (pExpr->nSQLOptr == TK_ID) { // column name if (pExpr->tokenId == TK_ID) { // column name
strncpy(*str, pExpr->colInfo.z, pExpr->colInfo.n); strncpy(*str, pExpr->colInfo.z, pExpr->colInfo.n);
*str += pExpr->colInfo.n; *str += pExpr->colInfo.n;
} else if (pExpr->nSQLOptr >= TK_BOOL && pExpr->nSQLOptr <= TK_STRING) { // value } else if (pExpr->tokenId >= TK_BOOL && pExpr->tokenId <= TK_STRING) { // value
*str += tVariantToString(&pExpr->val, *str); *str += tVariantToString(&pExpr->value, *str);
} else if (pExpr->nSQLOptr >= TK_COUNT && pExpr->nSQLOptr <= TK_AVG_IRATE) { } else if (pExpr->tokenId >= TSDB_FUNC_COUNT && pExpr->tokenId <= TSDB_FUNC_BLKINFO) {
/* /*
* arithmetic expression of aggregation, such as count(ts) + count(ts) *2 * arithmetic expression of aggregation, such as count(ts) + count(ts) *2
*/ */
...@@ -3218,10 +3130,10 @@ static int32_t tSQLExprNodeToString(tSQLExpr* pExpr, char** str) { ...@@ -3218,10 +3130,10 @@ static int32_t tSQLExprNodeToString(tSQLExpr* pExpr, char** str) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
// pExpr->nSQLOptr == 0 while handling "is null" query // pExpr->tokenId == 0 while handling "is null" query
static bool isExprLeafNode(tSQLExpr* pExpr) { static bool isExprLeafNode(tSQLExpr* pExpr) {
return (pExpr->pRight == NULL && pExpr->pLeft == NULL) && return (pExpr->pRight == NULL && pExpr->pLeft == NULL) &&
(pExpr->nSQLOptr == 0 || pExpr->nSQLOptr == TK_ID || (pExpr->nSQLOptr >= TK_BOOL && pExpr->nSQLOptr <= TK_NCHAR) || pExpr->nSQLOptr == TK_SET); (pExpr->tokenId == 0 || pExpr->tokenId == TK_ID || (pExpr->tokenId >= TK_BOOL && pExpr->tokenId <= TK_NCHAR) || pExpr->tokenId == TK_SET);
} }
static bool isExprDirectParentOfLeafNode(tSQLExpr* pExpr) { static bool isExprDirectParentOfLeafNode(tSQLExpr* pExpr) {
...@@ -3263,7 +3175,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) { ...@@ -3263,7 +3175,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
const char* ne = "<>"; const char* ne = "<>";
const char* likeOptr = "LIKE"; const char* likeOptr = "LIKE";
switch (pExpr->nSQLOptr) { switch (pExpr->tokenId) {
case TK_LE: { case TK_LE: {
*(int16_t*)(*exprString) = *(int16_t*)le; *(int16_t*)(*exprString) = *(int16_t*)le;
*exprString += 1; *exprString += 1;
...@@ -3330,13 +3242,13 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { ...@@ -3330,13 +3242,13 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
for (int32_t i = 0; i < pList->nExpr; ++i) { for (int32_t i = 0; i < pList->nExpr; ++i) {
tSQLExpr* pSub = pList->a[i].pNode; tSQLExpr* pSub = pList->a[i].pNode;
taosStringBuilderAppendStringLen(sb, pSub->val.pz, pSub->val.nLen); taosStringBuilderAppendStringLen(sb, pSub->value.pz, pSub->value.nLen);
if (i < pList->nExpr - 1) { if (i < pList->nExpr - 1) {
taosStringBuilderAppendString(sb, TBNAME_LIST_SEP); taosStringBuilderAppendString(sb, TBNAME_LIST_SEP);
} }
if (pSub->val.nLen <= 0 || !tscValidateTableNameLength(pSub->val.nLen)) { if (pSub->value.nLen <= 0 || !tscValidateTableNameLength(pSub->value.nLen)) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
...@@ -3346,7 +3258,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { ...@@ -3346,7 +3258,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
static int32_t tablenameCondToString(tSQLExpr* pExpr, SStringBuilder* sb) { static int32_t tablenameCondToString(tSQLExpr* pExpr, SStringBuilder* sb) {
taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN); taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN);
taosStringBuilderAppendString(sb, pExpr->val.pz); taosStringBuilderAppendString(sb, pExpr->value.pz);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -3400,21 +3312,21 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC ...@@ -3400,21 +3312,21 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
((pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) ? 1 : 0); ((pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) ? 1 : 0);
if (pColFilter->filterstr) { if (pColFilter->filterstr) {
if (pExpr->nSQLOptr != TK_EQ if (pExpr->tokenId != TK_EQ
&& pExpr->nSQLOptr != TK_NE && pExpr->tokenId != TK_NE
&& pExpr->nSQLOptr != TK_ISNULL && pExpr->tokenId != TK_ISNULL
&& pExpr->nSQLOptr != TK_NOTNULL && pExpr->tokenId != TK_NOTNULL
&& pExpr->nSQLOptr != TK_LIKE && pExpr->tokenId != TK_LIKE
) { ) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
} else { } else {
if (pExpr->nSQLOptr == TK_LIKE) { if (pExpr->tokenId == TK_LIKE) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
if (pSchema->type == TSDB_DATA_TYPE_BOOL) { if (pSchema->type == TSDB_DATA_TYPE_BOOL) {
if (pExpr->nSQLOptr != TK_EQ && pExpr->nSQLOptr != TK_NE) { if (pExpr->tokenId != TK_EQ && pExpr->tokenId != TK_NE) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
} }
...@@ -3425,13 +3337,13 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC ...@@ -3425,13 +3337,13 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
} }
static void relToString(tSQLExpr* pExpr, char** str) { static void relToString(tSQLExpr* pExpr, char** str) {
assert(pExpr->nSQLOptr == TK_AND || pExpr->nSQLOptr == TK_OR); assert(pExpr->tokenId == TK_AND || pExpr->tokenId == TK_OR);
const char* or = "OR"; const char* or = "OR";
const char*and = "AND"; const char*and = "AND";
// if (pQueryInfo->tagCond.relType == TSQL_STABLE_QTYPE_COND) { // if (pQueryInfo->tagCond.relType == TSQL_STABLE_QTYPE_COND) {
if (pExpr->nSQLOptr == TK_AND) { if (pExpr->tokenId == TK_AND) {
strcpy(*str, and); strcpy(*str, and);
*str += strlen(and); *str += strlen(and);
} else { } else {
...@@ -3485,10 +3397,10 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* ...@@ -3485,10 +3397,10 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
if (pTableCond->nSQLOptr == TK_IN) { if (pTableCond->tokenId == TK_IN) {
ret = tablenameListToString(pRight, sb); ret = tablenameListToString(pRight, sb);
} else if (pTableCond->nSQLOptr == TK_LIKE) { } else if (pTableCond->tokenId == TK_LIKE) {
if (pRight->nSQLOptr != TK_STRING) { if (pRight->tokenId != TK_STRING) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
...@@ -3508,12 +3420,12 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQ ...@@ -3508,12 +3420,12 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQ
} }
if (!isExprDirectParentOfLeafNode(pExpr)) { // internal node if (!isExprDirectParentOfLeafNode(pExpr)) { // internal node
int32_t ret = getColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pLeft, pExpr->nSQLOptr); int32_t ret = getColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pLeft, pExpr->tokenId);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
return getColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pRight, pExpr->nSQLOptr); return getColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pRight, pExpr->tokenId);
} else { // handle leaf node } else { // handle leaf node
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(pCmd, &pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(pCmd, &pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
...@@ -3583,8 +3495,8 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* ...@@ -3583,8 +3495,8 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
} }
static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList,
int32_t* type, uint64_t* uid) { int32_t* type, uint64_t* uid) {
if (pExpr->nSQLOptr == TK_ID) { if (pExpr->type == SQL_NODE_TABLE_COLUMN) {
if (*type == NON_ARITHMEIC_EXPR) { if (*type == NON_ARITHMEIC_EXPR) {
*type = NORMAL_ARITHMETIC; *type = NORMAL_ARITHMETIC;
} else if (*type == AGG_ARIGHTMEIC) { } else if (*type == AGG_ARIGHTMEIC) {
...@@ -3606,9 +3518,9 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQuer ...@@ -3606,9 +3518,9 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQuer
} }
pList->ids[pList->num++] = index; pList->ids[pList->num++] = index;
} else if (pExpr->nSQLOptr == TK_FLOAT && (isnan(pExpr->val.dKey) || isinf(pExpr->val.dKey))) { } else if (pExpr->tokenId == TK_FLOAT && (isnan(pExpr->value.dKey) || isinf(pExpr->value.dKey))) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} else if (pExpr->nSQLOptr >= TK_COUNT && pExpr->nSQLOptr <= TK_AVG_IRATE) { } else if (pExpr->type == SQL_NODE_SQLFUNCTION) {
if (*type == NON_ARITHMEIC_EXPR) { if (*type == NON_ARITHMEIC_EXPR) {
*type = AGG_ARIGHTMEIC; *type = AGG_ARIGHTMEIC;
} else if (*type == NORMAL_ARITHMETIC) { } else if (*type == NORMAL_ARITHMETIC) {
...@@ -3621,6 +3533,11 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQuer ...@@ -3621,6 +3533,11 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQuer
// sql function list in selection clause. // sql function list in selection clause.
// Append the sqlExpr into exprList of pQueryInfo structure sequentially // Append the sqlExpr into exprList of pQueryInfo structure sequentially
pExpr->functionId = isValidFunction(pExpr->operand.z, pExpr->operand.n);
if (pExpr->functionId < 0) {
return TSDB_CODE_TSC_INVALID_SQL;
}
if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, &item, false) != TSDB_CODE_SUCCESS) { if (addExprAndResultField(pCmd, pQueryInfo, outputIndex, &item, false) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -3662,7 +3579,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI ...@@ -3662,7 +3579,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI
uint64_t uidLeft = 0; uint64_t uidLeft = 0;
uint64_t uidRight = 0; uint64_t uidRight = 0;
if (pLeft->nSQLOptr >= TK_PLUS && pLeft->nSQLOptr <= TK_REM) { if (pLeft->type == SQL_NODE_EXPR) {
int32_t ret = validateArithmeticSQLExpr(pCmd, pLeft, pQueryInfo, pList, type); int32_t ret = validateArithmeticSQLExpr(pCmd, pLeft, pQueryInfo, pList, type);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
...@@ -3675,7 +3592,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI ...@@ -3675,7 +3592,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI
} }
tSQLExpr* pRight = pExpr->pRight; tSQLExpr* pRight = pExpr->pRight;
if (pRight->nSQLOptr >= TK_PLUS && pRight->nSQLOptr <= TK_REM) { if (pRight->type == SQL_NODE_EXPR) {
int32_t ret = validateArithmeticSQLExpr(pCmd, pRight, pQueryInfo, pList, type); int32_t ret = validateArithmeticSQLExpr(pCmd, pRight, pQueryInfo, pList, type);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
...@@ -3708,22 +3625,15 @@ static bool isValidExpr(tSQLExpr* pLeft, tSQLExpr* pRight, int32_t optr) { ...@@ -3708,22 +3625,15 @@ static bool isValidExpr(tSQLExpr* pLeft, tSQLExpr* pRight, int32_t optr) {
* *
* However, columnA < 4+12 is valid * However, columnA < 4+12 is valid
*/ */
if (pLeft->nSQLOptr >= TK_COUNT && pLeft->nSQLOptr <= TK_AVG_IRATE) { if (pLeft->type == SQL_NODE_SQLFUNCTION) {
return false; return false;
} }
if (pRight == NULL) { if (pRight == NULL) {
return true; return true;
} }
if (pRight->nSQLOptr >= TK_COUNT && pRight->nSQLOptr <= TK_AVG_IRATE) {
return false;
}
if (pLeft->nSQLOptr >= TK_BOOL if (pLeft->tokenId >= TK_BOOL && pLeft->tokenId <= TK_BINARY && pRight->tokenId >= TK_BOOL && pRight->tokenId <= TK_BINARY) {
&& pLeft->nSQLOptr <= TK_BINARY
&& pRight->nSQLOptr >= TK_BOOL
&& pRight->nSQLOptr <= TK_BINARY) {
return false; return false;
} }
...@@ -3734,8 +3644,8 @@ static void exchangeExpr(tSQLExpr* pExpr) { ...@@ -3734,8 +3644,8 @@ static void exchangeExpr(tSQLExpr* pExpr) {
tSQLExpr* pLeft = pExpr->pLeft; tSQLExpr* pLeft = pExpr->pLeft;
tSQLExpr* pRight = pExpr->pRight; tSQLExpr* pRight = pExpr->pRight;
if (pRight->nSQLOptr == TK_ID && (pLeft->nSQLOptr == TK_INTEGER || pLeft->nSQLOptr == TK_FLOAT || if (pRight->tokenId == TK_ID && (pLeft->tokenId == TK_INTEGER || pLeft->tokenId == TK_FLOAT ||
pLeft->nSQLOptr == TK_STRING || pLeft->nSQLOptr == TK_BOOL)) { pLeft->tokenId == TK_STRING || pLeft->tokenId == TK_BOOL)) {
/* /*
* exchange value of the left handside and the value of the right-handside * exchange value of the left handside and the value of the right-handside
* to make sure that the value of filter expression always locates in * to make sure that the value of filter expression always locates in
...@@ -3743,7 +3653,7 @@ static void exchangeExpr(tSQLExpr* pExpr) { ...@@ -3743,7 +3653,7 @@ static void exchangeExpr(tSQLExpr* pExpr) {
* the column-id is at the left handside. * the column-id is at the left handside.
*/ */
uint32_t optr = 0; uint32_t optr = 0;
switch (pExpr->nSQLOptr) { switch (pExpr->tokenId) {
case TK_LE: case TK_LE:
optr = TK_GE; optr = TK_GE;
break; break;
...@@ -3757,10 +3667,10 @@ static void exchangeExpr(tSQLExpr* pExpr) { ...@@ -3757,10 +3667,10 @@ static void exchangeExpr(tSQLExpr* pExpr) {
optr = TK_LE; optr = TK_LE;
break; break;
default: default:
optr = pExpr->nSQLOptr; optr = pExpr->tokenId;
} }
pExpr->nSQLOptr = optr; pExpr->tokenId = optr;
SWAP(pExpr->pLeft, pExpr->pRight, void*); SWAP(pExpr->pLeft, pExpr->pRight, void*);
} }
} }
...@@ -3774,11 +3684,11 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr ...@@ -3774,11 +3684,11 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr
tSQLExpr* pRight = pExpr->pRight; tSQLExpr* pRight = pExpr->pRight;
if (pRight->nSQLOptr != TK_ID) { if (pRight->tokenId != TK_ID) {
return true; return true;
} }
if (pExpr->nSQLOptr != TK_EQ) { if (pExpr->tokenId != TK_EQ) {
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
return false; return false;
} }
...@@ -3820,7 +3730,7 @@ static bool validTableNameOptr(tSQLExpr* pExpr) { ...@@ -3820,7 +3730,7 @@ static bool validTableNameOptr(tSQLExpr* pExpr) {
const char nameFilterOptr[] = {TK_IN, TK_LIKE}; const char nameFilterOptr[] = {TK_IN, TK_LIKE};
for (int32_t i = 0; i < tListLen(nameFilterOptr); ++i) { for (int32_t i = 0; i < tListLen(nameFilterOptr); ++i) {
if (pExpr->nSQLOptr == nameFilterOptr[i]) { if (pExpr->tokenId == nameFilterOptr[i]) {
return true; return true;
} }
} }
...@@ -3874,7 +3784,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL ...@@ -3874,7 +3784,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
} }
// set join query condition // set join query condition
if (pRight->nSQLOptr == TK_ID) { // no need to keep the timestamp join condition if (pRight->tokenId == TK_ID) { // no need to keep the timestamp join condition
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY);
pCondExpr->tsJoin = true; pCondExpr->tsJoin = true;
...@@ -3896,8 +3806,8 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL ...@@ -3896,8 +3806,8 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
} }
// check for like expression // check for like expression
if ((*pExpr)->nSQLOptr == TK_LIKE) { if ((*pExpr)->tokenId == TK_LIKE) {
if (pRight->val.nLen > TSDB_PATTERN_STRING_MAX_LEN) { if (pRight->value.nLen > TSDB_PATTERN_STRING_MAX_LEN) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg8); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg8);
} }
...@@ -3930,7 +3840,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL ...@@ -3930,7 +3840,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
*type = TSQL_EXPR_TBNAME; *type = TSQL_EXPR_TBNAME;
*pExpr = NULL; *pExpr = NULL;
} else { } else {
if (pRight != NULL && pRight->nSQLOptr == TK_ID) { // join on tag columns for stable query if (pRight != NULL && pRight->tokenId == TK_ID) { // join on tag columns for stable query
if (!validateJoinExprNode(pCmd, pQueryInfo, *pExpr, &index)) { if (!validateJoinExprNode(pCmd, pQueryInfo, *pExpr, &index)) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -3954,7 +3864,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL ...@@ -3954,7 +3864,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
} else { // query on other columns } else { // query on other columns
*type = TSQL_EXPR_COLUMN; *type = TSQL_EXPR_COLUMN;
if (pRight->nSQLOptr == TK_ID) { // other column cannot be served as the join column if (pRight->tokenId == TK_ID) { // other column cannot be served as the join column
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
} }
...@@ -3976,7 +3886,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr ...@@ -3976,7 +3886,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
tSQLExpr* pLeft = (*pExpr)->pLeft; tSQLExpr* pLeft = (*pExpr)->pLeft;
tSQLExpr* pRight = (*pExpr)->pRight; tSQLExpr* pRight = (*pExpr)->pRight;
if (!isValidExpr(pLeft, pRight, (*pExpr)->nSQLOptr)) { if (!isValidExpr(pLeft, pRight, (*pExpr)->tokenId)) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -3984,12 +3894,12 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr ...@@ -3984,12 +3894,12 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
int32_t rightType = -1; int32_t rightType = -1;
if (!isExprDirectParentOfLeafNode(*pExpr)) { if (!isExprDirectParentOfLeafNode(*pExpr)) {
int32_t ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, &leftType, (*pExpr)->nSQLOptr); int32_t ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, &leftType, (*pExpr)->tokenId);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, &rightType, (*pExpr)->nSQLOptr); ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, &rightType, (*pExpr)->tokenId);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
...@@ -3999,7 +3909,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr ...@@ -3999,7 +3909,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
* expression is not valid for parent node, it must be TK_AND operator. * expression is not valid for parent node, it must be TK_AND operator.
*/ */
if (leftType != rightType) { if (leftType != rightType) {
if ((*pExpr)->nSQLOptr == TK_OR && (leftType + rightType != TSQL_EXPR_TBNAME + TSQL_EXPR_TAG)) { if ((*pExpr)->tokenId == TK_OR && (leftType + rightType != TSQL_EXPR_TBNAME + TSQL_EXPR_TAG)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
} }
...@@ -4027,7 +3937,7 @@ static void doCompactQueryExpr(tSQLExpr** pExpr) { ...@@ -4027,7 +3937,7 @@ static void doCompactQueryExpr(tSQLExpr** pExpr) {
} }
if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight == NULL && if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight == NULL &&
((*pExpr)->nSQLOptr == TK_OR || (*pExpr)->nSQLOptr == TK_AND)) { ((*pExpr)->tokenId == TK_OR || (*pExpr)->tokenId == TK_AND)) {
tSqlExprNodeDestroy(*pExpr); tSqlExprNodeDestroy(*pExpr);
*pExpr = NULL; *pExpr = NULL;
...@@ -4061,7 +3971,7 @@ static void doExtractExprForSTable(SSqlCmd* pCmd, tSQLExpr** pExpr, SQueryInfo* ...@@ -4061,7 +3971,7 @@ static void doExtractExprForSTable(SSqlCmd* pCmd, tSQLExpr** pExpr, SQueryInfo*
(*pExpr) = NULL; (*pExpr) = NULL;
} else { } else {
*pOut = tSqlExprCreate(NULL, NULL, (*pExpr)->nSQLOptr); *pOut = tSqlExprCreate(NULL, NULL, (*pExpr)->tokenId);
doExtractExprForSTable(pCmd, &(*pExpr)->pLeft, pQueryInfo, &((*pOut)->pLeft), tableIndex); doExtractExprForSTable(pCmd, &(*pExpr)->pLeft, pQueryInfo, &((*pOut)->pLeft), tableIndex);
doExtractExprForSTable(pCmd, &(*pExpr)->pRight, pQueryInfo, &((*pOut)->pRight), tableIndex); doExtractExprForSTable(pCmd, &(*pExpr)->pRight, pQueryInfo, &((*pOut)->pRight), tableIndex);
...@@ -4105,9 +4015,9 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, ...@@ -4105,9 +4015,9 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
STagCond* pTagCond = &pQueryInfo->tagCond; STagCond* pTagCond = &pQueryInfo->tagCond;
pTagCond->tbnameCond.uid = pTableMetaInfo->pTableMeta->id.uid; pTagCond->tbnameCond.uid = pTableMetaInfo->pTableMeta->id.uid;
assert(pExpr->nSQLOptr == TK_LIKE || pExpr->nSQLOptr == TK_IN); assert(pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_IN);
if (pExpr->nSQLOptr == TK_LIKE) { if (pExpr->tokenId == TK_LIKE) {
char* str = taosStringBuilderGetResult(sb, NULL); char* str = taosStringBuilderGetResult(sb, NULL);
pQueryInfo->tagCond.tbnameCond.cond = strdup(str); pQueryInfo->tagCond.tbnameCond.cond = strdup(str);
pQueryInfo->tagCond.tbnameCond.len = (int32_t) strlen(str); pQueryInfo->tagCond.tbnameCond.len = (int32_t) strlen(str);
...@@ -4203,7 +4113,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLE ...@@ -4203,7 +4113,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLE
} }
if (!isExprDirectParentOfLeafNode(pExpr)) { if (!isExprDirectParentOfLeafNode(pExpr)) {
if (pExpr->nSQLOptr == TK_OR) { if (pExpr->tokenId == TK_OR) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
...@@ -4222,7 +4132,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLE ...@@ -4222,7 +4132,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLE
tSQLExpr* pRight = pExpr->pRight; tSQLExpr* pRight = pExpr->pRight;
STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX}; STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX};
if (getTimeRange(&win, pRight, pExpr->nSQLOptr, tinfo.precision) != TSDB_CODE_SUCCESS) { if (getTimeRange(&win, pRight, pExpr->tokenId, tinfo.precision) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg0); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg0);
} }
...@@ -4366,7 +4276,7 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) { ...@@ -4366,7 +4276,7 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) {
retVal = tVariantDump(vVariant, tmp, schemaType, false); retVal = tVariantDump(vVariant, tmp, schemaType, false);
free(tmp); free(tmp);
} else if (schemaType == TSDB_DATA_TYPE_NCHAR) { } else if (schemaType == TSDB_DATA_TYPE_NCHAR) {
// pRight->val.nLen + 1 is larger than the actual nchar string length // pRight->value.nLen + 1 is larger than the actual nchar string length
char *tmp = calloc(1, (vVariant->nLen + 1) * TSDB_NCHAR_SIZE); char *tmp = calloc(1, (vVariant->nLen + 1) * TSDB_NCHAR_SIZE);
retVal = tVariantDump(vVariant, tmp, schemaType, false); retVal = tVariantDump(vVariant, tmp, schemaType, false);
free(tmp); free(tmp);
...@@ -4465,7 +4375,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql ...@@ -4465,7 +4375,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
} }
int32_t type = 0; int32_t type = 0;
if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->nSQLOptr)) != TSDB_CODE_SUCCESS) { if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
...@@ -4522,7 +4432,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql ...@@ -4522,7 +4432,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t timePrecision) { int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t timePrecision) {
// this is join condition, do nothing // this is join condition, do nothing
if (pRight->nSQLOptr == TK_ID) { if (pRight->tokenId == TK_ID) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -4530,42 +4440,42 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t ...@@ -4530,42 +4440,42 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t
* filter primary ts filter expression like: * filter primary ts filter expression like:
* where ts in ('2015-12-12 4:8:12') * where ts in ('2015-12-12 4:8:12')
*/ */
if (pRight->nSQLOptr == TK_SET || optr == TK_IN) { if (pRight->tokenId == TK_SET || optr == TK_IN) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int64_t val = 0; int64_t val = 0;
bool parsed = false; bool parsed = false;
if (pRight->val.nType == TSDB_DATA_TYPE_BINARY) { if (pRight->value.nType == TSDB_DATA_TYPE_BINARY) {
pRight->val.nLen = strdequote(pRight->val.pz); pRight->value.nLen = strdequote(pRight->value.pz);
char* seg = strnchr(pRight->val.pz, '-', pRight->val.nLen, false); char* seg = strnchr(pRight->value.pz, '-', pRight->value.nLen, false);
if (seg != NULL) { if (seg != NULL) {
if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO, tsDaylight) == TSDB_CODE_SUCCESS) { if (taosParseTime(pRight->value.pz, &val, pRight->value.nLen, TSDB_TIME_PRECISION_MICRO, tsDaylight) == TSDB_CODE_SUCCESS) {
parsed = true; parsed = true;
} else { } else {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else { } else {
SStrToken token = {.z = pRight->val.pz, .n = pRight->val.nLen, .type = TK_ID}; SStrToken token = {.z = pRight->value.pz, .n = pRight->value.nLen, .type = TK_ID};
int32_t len = tSQLGetToken(pRight->val.pz, &token.type); int32_t len = tSQLGetToken(pRight->value.pz, &token.type);
if ((token.type != TK_INTEGER && token.type != TK_FLOAT) || len != pRight->val.nLen) { if ((token.type != TK_INTEGER && token.type != TK_FLOAT) || len != pRight->value.nLen) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
} else if (pRight->nSQLOptr == TK_INTEGER && timePrecision == TSDB_TIME_PRECISION_MILLI) { } else if (pRight->tokenId == TK_INTEGER && timePrecision == TSDB_TIME_PRECISION_MILLI) {
/* /*
* if the pRight->nSQLOptr == TK_INTEGER/TK_FLOAT, the value is adaptive, we * if the pRight->tokenId == TK_INTEGER/TK_FLOAT, the value is adaptive, we
* need the time precision in metermeta to transfer the value in MICROSECOND * need the time precision in metermeta to transfer the value in MICROSECOND
* *
* Additional check to avoid data overflow * Additional check to avoid data overflow
*/ */
if (pRight->val.i64 <= INT64_MAX / 1000) { if (pRight->value.i64 <= INT64_MAX / 1000) {
pRight->val.i64 *= 1000; pRight->value.i64 *= 1000;
} }
} else if (pRight->nSQLOptr == TK_FLOAT && timePrecision == TSDB_TIME_PRECISION_MILLI) { } else if (pRight->tokenId == TK_FLOAT && timePrecision == TSDB_TIME_PRECISION_MILLI) {
pRight->val.dKey *= 1000; pRight->value.dKey *= 1000;
} }
if (!parsed) { if (!parsed) {
...@@ -4573,7 +4483,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t ...@@ -4573,7 +4483,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t
* failed to parse timestamp in regular formation, try next * failed to parse timestamp in regular formation, try next
* it may be a epoch time in string format * it may be a epoch time in string format
*/ */
tVariantDump(&pRight->val, (char*)&val, TSDB_DATA_TYPE_BIGINT, true); tVariantDump(&pRight->value, (char*)&val, TSDB_DATA_TYPE_BIGINT, true);
/* /*
* transfer it into MICROSECOND format if it is a string, since for * transfer it into MICROSECOND format if it is a string, since for
...@@ -4581,7 +4491,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t ...@@ -4581,7 +4491,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t
* *
* additional check to avoid data overflow * additional check to avoid data overflow
*/ */
if (pRight->nSQLOptr == TK_STRING && timePrecision == TSDB_TIME_PRECISION_MILLI) { if (pRight->tokenId == TK_STRING && timePrecision == TSDB_TIME_PRECISION_MILLI) {
if (val <= INT64_MAX / 1000) { if (val <= INT64_MAX / 1000) {
val *= 1000; val *= 1000;
} }
...@@ -5392,7 +5302,7 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { ...@@ -5392,7 +5302,7 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) {
// reset log does not need value // reset log does not need value
for (int32_t i = 0; i < 1; ++i) { for (int32_t i = 0; i < 1; ++i) {
SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i]; SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i];
if ((pOption->len == pOptionToken->n) && if ((pOption->len == pOptionToken->n) &&
(strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) { (strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -5407,7 +5317,7 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { ...@@ -5407,7 +5317,7 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) {
for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) { for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) {
SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i]; SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i];
if ((pOption->len == pOptionToken->n) if ((pOption->len == pOptionToken->n)
&& (strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) { && (strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -6157,8 +6067,8 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ ...@@ -6157,8 +6067,8 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
index = 2; index = 2;
} else { } else {
for (int32_t i = 0; i < tListLen(functionsInfo); ++i) { for (int32_t i = 0; i < tListLen(functionsInfo); ++i) {
if (strncasecmp(functionsInfo[i].name, pExpr->operand.z, functionsInfo[i].len) == 0 && if (strncasecmp(functionsInfo[i].name, pExpr->token.z, functionsInfo[i].len) == 0 &&
functionsInfo[i].len == pExpr->operand.n) { functionsInfo[i].len == pExpr->token.n) {
index = i; index = i;
break; break;
} }
...@@ -6453,12 +6363,12 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6453,12 +6363,12 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
tVariantListItem* pItem = taosArrayGet(pValList, i); tVariantListItem* pItem = taosArrayGet(pValList, i);
findColumnIndex = false; findColumnIndex = false;
// todo speedup by using hash list // todo speedup by using hash list
for (int32_t t = 0; t < schemaSize; ++t) { for (int32_t t = 0; t < schemaSize; ++t) {
if (strncmp(sToken->z, pTagSchema[t].name, sToken->n) == 0 && strlen(pTagSchema[t].name) == sToken->n) { if (strncmp(sToken->z, pTagSchema[t].name, sToken->n) == 0 && strlen(pTagSchema[t].name) == sToken->n) {
SSchema* pSchema = &pTagSchema[t]; SSchema* pSchema = &pTagSchema[t];
char tagVal[TSDB_MAX_TAGS_LEN]; char tagVal[TSDB_MAX_TAGS_LEN];
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
if (pItem->pVar.nLen > pSchema->bytes) { if (pItem->pVar.nLen > pSchema->bytes) {
...@@ -6466,9 +6376,9 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6466,9 +6376,9 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
} }
ret = tVariantDump(&(pItem->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. // 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) { if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
int16_t len = varDataTLen(tagVal); int16_t len = varDataTLen(tagVal);
...@@ -6477,12 +6387,12 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6477,12 +6387,12 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
} }
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
} }
tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal); tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal);
findColumnIndex = true; findColumnIndex = true;
...@@ -6493,7 +6403,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6493,7 +6403,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
if (!findColumnIndex) { if (!findColumnIndex) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
return tscInvalidSQLErrMsg(pCmd->payload, "invalid tag name", sToken->z); return tscInvalidSQLErrMsg(pCmd->payload, "invalid tag name", sToken->z);
} }
} }
} else { } else {
if (schemaSize != valSize) { if (schemaSize != valSize) {
...@@ -6504,7 +6414,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6504,7 +6414,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
for (int32_t i = 0; i < valSize; ++i) { for (int32_t i = 0; i < valSize; ++i) {
SSchema* pSchema = &pTagSchema[i]; SSchema* pSchema = &pTagSchema[i];
tVariantListItem* pItem = taosArrayGet(pValList, i); tVariantListItem* pItem = taosArrayGet(pValList, i);
char tagVal[TSDB_MAX_TAGS_LEN]; char tagVal[TSDB_MAX_TAGS_LEN];
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
if (pItem->pVar.nLen > pSchema->bytes) { if (pItem->pVar.nLen > pSchema->bytes) {
...@@ -6512,9 +6422,9 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6512,9 +6422,9 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
} }
ret = tVariantDump(&(pItem->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. // 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) { if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
int16_t len = varDataTLen(tagVal); int16_t len = varDataTLen(tagVal);
...@@ -6523,12 +6433,12 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6523,12 +6433,12 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
} }
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
} }
tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal); tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal);
} }
} }
...@@ -6953,25 +6863,25 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS ...@@ -6953,25 +6863,25 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
} }
} }
if (pSqlExpr->pLeft == NULL && pSqlExpr->pRight == NULL && pSqlExpr->nSQLOptr == 0) { if (pSqlExpr->pLeft == NULL && pSqlExpr->pRight == NULL && pSqlExpr->tokenId == 0) {
*pExpr = calloc(1, sizeof(tExprNode)); *pExpr = calloc(1, sizeof(tExprNode));
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (pSqlExpr->pLeft == NULL) { if (pSqlExpr->pLeft == NULL) {
if (pSqlExpr->nSQLOptr >= TK_BOOL && pSqlExpr->nSQLOptr <= TK_STRING) { if (pSqlExpr->type == SQL_NODE_VALUE) {
*pExpr = calloc(1, sizeof(tExprNode)); *pExpr = calloc(1, sizeof(tExprNode));
(*pExpr)->nodeType = TSQL_NODE_VALUE; (*pExpr)->nodeType = TSQL_NODE_VALUE;
(*pExpr)->pVal = calloc(1, sizeof(tVariant)); (*pExpr)->pVal = calloc(1, sizeof(tVariant));
tVariantAssign((*pExpr)->pVal, &pSqlExpr->val); tVariantAssign((*pExpr)->pVal, &pSqlExpr->value);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (pSqlExpr->nSQLOptr >= TK_COUNT && pSqlExpr->nSQLOptr <= TK_AVG_IRATE) { } else if (pSqlExpr->type == SQL_NODE_SQLFUNCTION) {
// arithmetic expression on the results of aggregation functions // arithmetic expression on the results of aggregation functions
*pExpr = calloc(1, sizeof(tExprNode)); *pExpr = calloc(1, sizeof(tExprNode));
(*pExpr)->nodeType = TSQL_NODE_COL; (*pExpr)->nodeType = TSQL_NODE_COL;
(*pExpr)->pSchema = calloc(1, sizeof(SSchema)); (*pExpr)->pSchema = calloc(1, sizeof(SSchema));
strncpy((*pExpr)->pSchema->name, pSqlExpr->operand.z, pSqlExpr->operand.n); strncpy((*pExpr)->pSchema->name, pSqlExpr->token.z, pSqlExpr->token.n);
// set the input column data byte and type. // set the input column data byte and type.
size_t size = taosArrayGetSize(pQueryInfo->exprList); size_t size = taosArrayGetSize(pQueryInfo->exprList);
...@@ -6991,7 +6901,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS ...@@ -6991,7 +6901,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
break; break;
} }
} }
} else if (pSqlExpr->nSQLOptr == TK_ID) { // column name, normal column arithmetic expression } else if (pSqlExpr->type == SQL_NODE_TABLE_COLUMN) { // column name, normal column arithmetic expression
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
int32_t ret = getColumnIndexByName(pCmd, &pSqlExpr->colInfo, pQueryInfo, &index); int32_t ret = getColumnIndexByName(pCmd, &pSqlExpr->colInfo, pQueryInfo, &index);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -7031,7 +6941,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS ...@@ -7031,7 +6941,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
(*pExpr)->_node.pLeft = pLeft; (*pExpr)->_node.pLeft = pLeft;
(*pExpr)->_node.pRight = pRight; (*pExpr)->_node.pRight = pRight;
SStrToken t = {.type = pSqlExpr->nSQLOptr}; SStrToken t = {.type = pSqlExpr->tokenId};
(*pExpr)->_node.optr = convertOptr(&t); (*pExpr)->_node.optr = convertOptr(&t);
assert((*pExpr)->_node.optr != 0); assert((*pExpr)->_node.optr != 0);
......
...@@ -497,8 +497,6 @@ int tscProcessSql(SSqlObj *pSql) { ...@@ -497,8 +497,6 @@ int tscProcessSql(SSqlObj *pSql) {
return pSql->res.code; return pSql->res.code;
} }
} else if (pCmd->command >= TSDB_SQL_LOCAL) { } else if (pCmd->command >= TSDB_SQL_LOCAL) {
//pSql->epSet = tscMgmtEpSet;
// } else { // local handler
return (*tscProcessMsgRsp[pCmd->command])(pSql); return (*tscProcessMsgRsp[pCmd->command])(pSql);
} }
...@@ -705,7 +703,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -705,7 +703,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList); size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList);
if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo)) { if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo) && !tscQueryBlockInfo(pQueryInfo)) {
tscError("%p illegal value of numOfCols in query msg: %" PRIu64 ", table cols:%d", pSql, (uint64_t)numOfSrcCols, tscError("%p illegal value of numOfCols in query msg: %" PRIu64 ", table cols:%d", pSql, (uint64_t)numOfSrcCols,
tscGetNumOfColumns(pTableMeta)); tscGetNumOfColumns(pTableMeta));
...@@ -835,13 +833,31 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -835,13 +833,31 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSqlFuncExpr->colInfo.colIndex = htons(pExpr->colInfo.colIndex); pSqlFuncExpr->colInfo.colIndex = htons(pExpr->colInfo.colIndex);
pSqlFuncExpr->colInfo.flag = htons(pExpr->colInfo.flag); pSqlFuncExpr->colInfo.flag = htons(pExpr->colInfo.flag);
if (TSDB_COL_IS_UD_COL(pExpr->colInfo.flag)) {
pSqlFuncExpr->colType = htons(pExpr->resType);
pSqlFuncExpr->colBytes = htons(pExpr->resBytes);
} else if (pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
SSchema *s = tGetTbnameColumnSchema();
pSqlFuncExpr->colType = htons(s->type);
pSqlFuncExpr->colBytes = htons(s->bytes);
} else if (pExpr->colInfo.colId == TSDB_BLOCK_DIST_COLUMN_INDEX) {
SSchema s = tGetBlockDistColumnSchema();
pSqlFuncExpr->colType = htons(s.type);
pSqlFuncExpr->colBytes = htons(s.bytes);
} else {
SSchema* s = tscGetColumnSchemaById(pTableMeta, pExpr->colInfo.colId);
pSqlFuncExpr->colType = htons(s->type);
pSqlFuncExpr->colBytes = htons(s->bytes);
}
pSqlFuncExpr->functionId = htons(pExpr->functionId); pSqlFuncExpr->functionId = htons(pExpr->functionId);
pSqlFuncExpr->numOfParams = htons(pExpr->numOfParams); pSqlFuncExpr->numOfParams = htons(pExpr->numOfParams);
pSqlFuncExpr->resColId = htons(pExpr->resColId); pSqlFuncExpr->resColId = htons(pExpr->resColId);
pMsg += sizeof(SSqlFuncMsg); pMsg += sizeof(SSqlFuncMsg);
for (int32_t j = 0; j < pExpr->numOfParams; ++j) { for (int32_t j = 0; j < pExpr->numOfParams; ++j) { // todo add log
// todo add log
pSqlFuncExpr->arg[j].argType = htons((uint16_t)pExpr->param[j].nType); pSqlFuncExpr->arg[j].argType = htons((uint16_t)pExpr->param[j].nType);
pSqlFuncExpr->arg[j].argBytes = htons(pExpr->param[j].nLen); pSqlFuncExpr->arg[j].argBytes = htons(pExpr->param[j].nLen);
...@@ -866,6 +882,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -866,6 +882,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
for (int32_t i = 0; i < output; ++i) { for (int32_t i = 0; i < output; ++i) {
SInternalField* pField = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i); SInternalField* pField = tscFieldInfoGetInternalField(&pQueryInfo->fieldsInfo, i);
SSqlExpr *pExpr = pField->pSqlExpr; SSqlExpr *pExpr = pField->pSqlExpr;
// this should be switched to projection query
if (pExpr != NULL) { if (pExpr != NULL) {
// the queried table has been removed and a new table with the same name has already been created already // the queried table has been removed and a new table with the same name has already been created already
// return error msg // return error msg
...@@ -879,33 +897,31 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -879,33 +897,31 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pSqlFuncExpr1->colInfo.colId = htons(pExpr->colInfo.colId); pSqlFuncExpr1->numOfParams = 0; // no params for projection query
pSqlFuncExpr1->colInfo.colIndex = htons(pExpr->colInfo.colIndex); pSqlFuncExpr1->functionId = htons(TSDB_FUNC_PRJ);
pSqlFuncExpr1->colInfo.flag = htons(pExpr->colInfo.flag); pSqlFuncExpr1->colInfo.colId = htons(pExpr->resColId);
pSqlFuncExpr1->colInfo.flag = htons(TSDB_COL_NORMAL);
pSqlFuncExpr1->functionId = htons(pExpr->functionId);
pSqlFuncExpr1->numOfParams = htons(pExpr->numOfParams); bool assign = false;
pMsg += sizeof(SSqlFuncMsg); for (int32_t f = 0; f < tscSqlExprNumOfExprs(pQueryInfo); ++f) {
SSqlExpr *pe = tscSqlExprGet(pQueryInfo, f);
for (int32_t j = 0; j < pExpr->numOfParams; ++j) { if (pe == pExpr) {
// todo add log pSqlFuncExpr1->colInfo.colIndex = htons(f);
pSqlFuncExpr1->arg[j].argType = htons((uint16_t)pExpr->param[j].nType); pSqlFuncExpr1->colType = htons(pe->resType);
pSqlFuncExpr1->arg[j].argBytes = htons(pExpr->param[j].nLen); pSqlFuncExpr1->colBytes = htons(pe->resBytes);
assign = true;
if (pExpr->param[j].nType == TSDB_DATA_TYPE_BINARY) { break;
memcpy(pMsg, pExpr->param[j].pz, pExpr->param[j].nLen);
pMsg += pExpr->param[j].nLen;
} else {
pSqlFuncExpr1->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64);
} }
} }
assert(assign);
pMsg += sizeof(SSqlFuncMsg);
pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg; pSqlFuncExpr1 = (SSqlFuncMsg *)pMsg;
} else { } else {
assert(pField->pArithExprInfo != NULL); assert(pField->pArithExprInfo != NULL);
SExprInfo* pExprInfo = pField->pArithExprInfo; SExprInfo* pExprInfo = pField->pArithExprInfo;
pSqlFuncExpr1->colInfo.colId = htons(pExprInfo->base.colInfo.colId); pSqlFuncExpr1->colInfo.colId = htons(pExprInfo->base.colInfo.colId);
pSqlFuncExpr1->functionId = htons(pExprInfo->base.functionId); pSqlFuncExpr1->functionId = htons(pExprInfo->base.functionId);
pSqlFuncExpr1->numOfParams = htons(pExprInfo->base.numOfParams); pSqlFuncExpr1->numOfParams = htons(pExprInfo->base.numOfParams);
pMsg += sizeof(SSqlFuncMsg); pMsg += sizeof(SSqlFuncMsg);
......
...@@ -503,9 +503,19 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) { ...@@ -503,9 +503,19 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
if (taosArrayGetSize(pSub->progress) > 0) { // fix crash in single tabel subscription if (taosArrayGetSize(pSub->progress) > 0) { // fix crash in single table subscription
pQueryInfo->window.skey = ((SSubscriptionProgress*)taosArrayGet(pSub->progress, 0))->key;
tscDebug("subscribe:%s set subscribe skey:%"PRId64, pSub->topic, pQueryInfo->window.skey); size_t size = taosArrayGetSize(pSub->progress);
TSKEY s = INT64_MAX;
for(int32_t i = 0; i < size; ++i) {
TSKEY k = ((SSubscriptionProgress*)taosArrayGet(pSub->progress, i))->key;
if (s > k) {
s = k;
}
}
pQueryInfo->window.skey = s;
tscDebug("subscribe:%s set next round subscribe skey:%"PRId64, pSub->topic, pQueryInfo->window.skey);
} }
if (pSub->pTimer == NULL) { if (pSub->pTimer == NULL) {
......
...@@ -74,14 +74,14 @@ static bool allSubqueryDone(SSqlObj *pParentSql) { ...@@ -74,14 +74,14 @@ static bool allSubqueryDone(SSqlObj *pParentSql) {
SSubqueryState *subState = &pParentSql->subState; SSubqueryState *subState = &pParentSql->subState;
//lock in caller //lock in caller
tscDebug("%p total subqueries: %d", pParentSql, subState->numOfSub);
for (int i = 0; i < subState->numOfSub; i++) { for (int i = 0; i < subState->numOfSub; i++) {
if (0 == subState->states[i]) { if (0 == subState->states[i]) {
tscDebug("%p subquery:%p,%d is NOT finished, total:%d", pParentSql, pParentSql->pSubs[i], i, subState->numOfSub); tscDebug("%p subquery:%p, index: %d NOT finished, abort query completion check", pParentSql, pParentSql->pSubs[i], i);
done = false; done = false;
break; break;
} else { } else {
tscDebug("%p subquery:%p,%d is finished, total:%d", pParentSql, pParentSql->pSubs[i], i, subState->numOfSub); tscDebug("%p subquery:%p, index: %d finished", pParentSql, pParentSql->pSubs[i], i);
} }
} }
...@@ -453,7 +453,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) { ...@@ -453,7 +453,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
pSubQueryInfo->tsBuf = NULL; pSubQueryInfo->tsBuf = NULL;
// free result for async object will also free sqlObj // free result for async object will also free sqlObj
assert(tscSqlExprNumOfExprs(pSubQueryInfo) == 1); // ts_comp query only requires one resutl columns assert(tscSqlExprNumOfExprs(pSubQueryInfo) == 1); // ts_comp query only requires one result columns
taos_free_result(pPrevSub); taos_free_result(pPrevSub);
SSqlObj *pNew = createSubqueryObj(pSql, (int16_t) i, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL); SSqlObj *pNew = createSubqueryObj(pSql, (int16_t) i, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL);
...@@ -507,6 +507,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) { ...@@ -507,6 +507,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0); SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
int16_t funcId = pExpr->functionId; int16_t funcId = pExpr->functionId;
// add the invisible timestamp column
if ((pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) || if ((pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) ||
(funcId != TSDB_FUNC_TS && funcId != TSDB_FUNC_TS_DUMMY && funcId != TSDB_FUNC_PRJ)) { (funcId != TSDB_FUNC_TS && funcId != TSDB_FUNC_TS_DUMMY && funcId != TSDB_FUNC_PRJ)) {
...@@ -847,6 +848,8 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow ...@@ -847,6 +848,8 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
SSqlRes* pRes = &pSql->res; SSqlRes* pRes = &pSql->res;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
// todo, the type may not include TSDB_QUERY_TYPE_TAG_FILTER_QUERY
assert(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)); assert(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY));
if (pParentSql->res.code != TSDB_CODE_SUCCESS) { if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
...@@ -2643,12 +2646,17 @@ static SSqlObj *tscCreateSTableSubquery(SSqlObj *pSql, SRetrieveSupport *trsuppo ...@@ -2643,12 +2646,17 @@ static SSqlObj *tscCreateSTableSubquery(SSqlObj *pSql, SRetrieveSupport *trsuppo
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
pQueryInfo->type |= TSDB_QUERY_TYPE_STABLE_SUBQUERY; pQueryInfo->type |= TSDB_QUERY_TYPE_STABLE_SUBQUERY;
// clear the limit/offset info, since it should not be sent to vnode to be executed.
pQueryInfo->limit.limit = -1;
pQueryInfo->limit.offset = 0;
assert(pQueryInfo->numOfTables == 1 && pNew->cmd.numOfClause == 1 && trsupport->subqueryIndex < pSql->subState.numOfSub); assert(pQueryInfo->numOfTables == 1 && pNew->cmd.numOfClause == 1 && trsupport->subqueryIndex < pSql->subState.numOfSub);
// launch subquery for each vnode, so the subquery index equals to the vgroupIndex. // launch subquery for each vnode, so the subquery index equals to the vgroupIndex.
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, table_index); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, table_index);
pTableMetaInfo->vgroupIndex = trsupport->subqueryIndex; pTableMetaInfo->vgroupIndex = trsupport->subqueryIndex;
pSql->pSubs[trsupport->subqueryIndex] = pNew; pSql->pSubs[trsupport->subqueryIndex] = pNew;
} }
...@@ -3102,30 +3110,6 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) { ...@@ -3102,30 +3110,6 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
} }
} }
static UNUSED_FUNC void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pField) {
SSqlRes *pRes = &pSql->res;
if (pRes->tsrow[columnIndex] != NULL && pField->type == TSDB_DATA_TYPE_NCHAR) {
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
if (pRes->buffer[columnIndex] == NULL) {
pRes->buffer[columnIndex] = malloc(pField->bytes + TSDB_NCHAR_SIZE);
}
/* string terminated char for binary data*/
memset(pRes->buffer[columnIndex], 0, pField->bytes + TSDB_NCHAR_SIZE);
int32_t length = taosUcs4ToMbs(pRes->tsrow[columnIndex], pRes->length[columnIndex], pRes->buffer[columnIndex]);
if ( length >= 0 ) {
pRes->tsrow[columnIndex] = (unsigned char*)pRes->buffer[columnIndex];
pRes->length[columnIndex] = length;
} else {
tscError("%p charset:%s to %s. val:%s convert failed.", pSql, DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)pRes->tsrow[columnIndex]);
pRes->tsrow[columnIndex] = NULL;
pRes->length[columnIndex] = 0;
}
}
}
char *getArithmeticInputSrc(void *param, const char *name, int32_t colId) { char *getArithmeticInputSrc(void *param, const char *name, int32_t colId) {
SArithmeticSupport *pSupport = (SArithmeticSupport *) param; SArithmeticSupport *pSupport = (SArithmeticSupport *) param;
......
...@@ -97,6 +97,22 @@ bool tscQueryTags(SQueryInfo* pQueryInfo) { ...@@ -97,6 +97,22 @@ bool tscQueryTags(SQueryInfo* pQueryInfo) {
return true; return true;
} }
bool tscQueryBlockInfo(SQueryInfo* pQueryInfo) {
int32_t numOfCols = (int32_t) tscSqlExprNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < numOfCols; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
int32_t functId = pExpr->functionId;
// "select count(tbname)" query
if (functId == TSDB_FUNC_BLKINFO) {
return true;
}
}
return false;
}
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) { bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
if (pQueryInfo == NULL) { if (pQueryInfo == NULL) {
return false; return false;
...@@ -1722,10 +1738,15 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo) { ...@@ -1722,10 +1738,15 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo) {
pQueryInfo->fieldsInfo.internalField = taosArrayInit(4, sizeof(SInternalField)); pQueryInfo->fieldsInfo.internalField = taosArrayInit(4, sizeof(SInternalField));
assert(pQueryInfo->exprList == NULL); assert(pQueryInfo->exprList == NULL);
pQueryInfo->exprList = taosArrayInit(4, POINTER_BYTES); pQueryInfo->exprList = taosArrayInit(4, POINTER_BYTES);
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
pQueryInfo->udColumnId = TSDB_UD_COLUMN_INDEX; pQueryInfo->udColumnId = TSDB_UD_COLUMN_INDEX;
pQueryInfo->resColumnId= -1000; pQueryInfo->resColumnId = -1000;
pQueryInfo->limit.limit = -1;
pQueryInfo->limit.offset = 0;
pQueryInfo->slimit.limit = -1;
pQueryInfo->slimit.offset = 0;
} }
int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) { int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
......
...@@ -33,7 +33,7 @@ typedef struct SDataStatis { ...@@ -33,7 +33,7 @@ typedef struct SDataStatis {
typedef struct SColumnInfoData { typedef struct SColumnInfoData {
SColumnInfo info; SColumnInfo info;
void* pData; // the corresponding block data in memory char* pData; // the corresponding block data in memory
} SColumnInfoData; } SColumnInfoData;
typedef struct SResPair { typedef struct SResPair {
......
...@@ -252,7 +252,7 @@ int32_t* taosGetErrno(); ...@@ -252,7 +252,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_QRY_IN_EXEC TAOS_DEF_ERROR_CODE(0, 0x0709) //"Multiple retrieval of this query") #define TSDB_CODE_QRY_IN_EXEC TAOS_DEF_ERROR_CODE(0, 0x0709) //"Multiple retrieval of this query")
#define TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW TAOS_DEF_ERROR_CODE(0, 0x070A) //"Too many time window in query") #define TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW TAOS_DEF_ERROR_CODE(0, 0x070A) //"Too many time window in query")
#define TSDB_CODE_QRY_NOT_ENOUGH_BUFFER TAOS_DEF_ERROR_CODE(0, 0x070B) //"Query buffer limit has reached") #define TSDB_CODE_QRY_NOT_ENOUGH_BUFFER TAOS_DEF_ERROR_CODE(0, 0x070B) //"Query buffer limit has reached")
#define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistance in replica") #define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica")
// grant // grant
......
...@@ -394,7 +394,7 @@ typedef struct SColIndex { ...@@ -394,7 +394,7 @@ typedef struct SColIndex {
int16_t colId; // column id int16_t colId; // column id
int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag
uint16_t flag; // denote if it is a tag or a normal column uint16_t flag; // denote if it is a tag or a normal column
char name[TSDB_COL_NAME_LEN]; char name[TSDB_COL_NAME_LEN]; // TODO remove it
} SColIndex; } SColIndex;
/* sql function msg, to describe the message to vnode about sql function /* sql function msg, to describe the message to vnode about sql function
...@@ -402,7 +402,10 @@ typedef struct SColIndex { ...@@ -402,7 +402,10 @@ typedef struct SColIndex {
typedef struct SSqlFuncMsg { typedef struct SSqlFuncMsg {
int16_t functionId; int16_t functionId;
int16_t numOfParams; int16_t numOfParams;
int16_t resColId; // result column id, id of the current output column int16_t resColId; // result column id, id of the current output column
int16_t colType;
int16_t colBytes;
SColIndex colInfo; SColIndex colInfo;
struct ArgElem { struct ArgElem {
......
...@@ -158,13 +158,18 @@ int32_t tsdbInsertData(STsdbRepo *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pR ...@@ -158,13 +158,18 @@ int32_t tsdbInsertData(STsdbRepo *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pR
typedef void *TsdbQueryHandleT; // Use void to hide implementation details typedef void *TsdbQueryHandleT; // Use void to hide implementation details
// query condition to build vnode iterator #define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
#define BLOCK_LOAD_TABLE_RR_ORDER 3
// query condition to build multi-table data block iterator
typedef struct STsdbQueryCond { typedef struct STsdbQueryCond {
STimeWindow twindow; STimeWindow twindow;
int32_t order; // desc|asc order to iterate the data block int32_t order; // desc|asc order to iterate the data block
int32_t numOfCols; int32_t numOfCols;
SColumnInfo *colList; SColumnInfo *colList;
bool loadExternalRows; // load external rows or not bool loadExternalRows; // load external rows or not
int32_t type; // data block load type:
} STsdbQueryCond; } STsdbQueryCond;
typedef struct SMemRef { typedef struct SMemRef {
...@@ -181,17 +186,31 @@ typedef struct SDataBlockInfo { ...@@ -181,17 +186,31 @@ typedef struct SDataBlockInfo {
int32_t tid; int32_t tid;
} SDataBlockInfo; } SDataBlockInfo;
typedef struct SFileBlockInfo {
int32_t numOfRows;
} SFileBlockInfo;
typedef struct { typedef struct {
void *pTable; void *pTable;
TSKEY lastKey; TSKEY lastKey;
} STableKeyInfo; } STableKeyInfo;
typedef struct { typedef struct {
size_t numOfTables; uint32_t numOfTables;
SArray * pGroupList; SArray * pGroupList;
SHashObj *map; // speedup acquire the tableQueryInfo by table uid SHashObj *map; // speedup acquire the tableQueryInfo by table uid
} STableGroupInfo; } STableGroupInfo;
typedef struct {
uint16_t rowSize;
uint16_t numOfFiles;
uint32_t numOfTables;
uint64_t totalSize;
int32_t firstSeekTimeUs;
uint32_t numOfRowsInMemTable;
SArray *dataBlockInfos;
} STableBlockDist;
/** /**
* Get the data block iterator, starting from position according to the query condition * Get the data block iterator, starting from position according to the query condition
* *
...@@ -252,16 +271,7 @@ int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle); ...@@ -252,16 +271,7 @@ int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle);
* @param pQueryHandle * @param pQueryHandle
* @return * @return
*/ */
bool tsdbNextDataBlock(TsdbQueryHandleT *pQueryHandle); bool tsdbNextDataBlock(TsdbQueryHandleT pQueryHandle);
/**
* move to next block if exists but not merge data in memtable
*
* @param pQueryHandle
* @return
*/
bool tsdbNextDataBlockWithoutMerge(TsdbQueryHandleT *pQueryHandle);
SArray* tsdbGetExternalRow(TsdbQueryHandleT *pHandle, SMemRef* pMemRef, int16_t type);
/** /**
* Get current data block information * Get current data block information
...@@ -306,7 +316,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo *tsdb, uint64_t uid, TSKEY key, const ...@@ -306,7 +316,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo *tsdb, uint64_t uid, TSKEY key, const
SColIndex *pColIndex, int32_t numOfCols); SColIndex *pColIndex, int32_t numOfCols);
/** /**
* destory the created table group list, which is generated by tag query * destroy the created table group list, which is generated by tag query
* @param pGroupList * @param pGroupList
*/ */
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList); void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
...@@ -336,6 +346,12 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo *tsdb, SArray *pTableIdList, STabl ...@@ -336,6 +346,12 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo *tsdb, SArray *pTableIdList, STabl
*/ */
void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle); void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle);
void tsdbResetQueryHandle(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond);
void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond, STableGroupInfo* groupList);
int32_t tsdbGetFileBlocksDistInfo(TsdbQueryHandleT* queryHandle, STableBlockDist* pTableBlockInfo);
/** /**
* get the statistics of repo usage * get the statistics of repo usage
* @param repo. point to the tsdbrepo * @param repo. point to the tsdbrepo
......
...@@ -191,52 +191,18 @@ ...@@ -191,52 +191,18 @@
#define TK_STATEMENT 172 #define TK_STATEMENT 172
#define TK_TRIGGER 173 #define TK_TRIGGER 173
#define TK_VIEW 174 #define TK_VIEW 174
#define TK_COUNT 175 #define TK_SEMI 175
#define TK_SUM 176 #define TK_NONE 176
#define TK_AVG 177 #define TK_PREV 177
#define TK_MIN 178 #define TK_LINEAR 178
#define TK_MAX 179 #define TK_IMPORT 179
#define TK_FIRST 180 #define TK_METRIC 180
#define TK_LAST 181 #define TK_TBNAME 181
#define TK_TOP 182 #define TK_JOIN 182
#define TK_BOTTOM 183 #define TK_METRICS 183
#define TK_STDDEV 184 #define TK_INSERT 184
#define TK_PERCENTILE 185 #define TK_INTO 185
#define TK_APERCENTILE 186 #define TK_VALUES 186
#define TK_LEASTSQUARES 187
#define TK_HISTOGRAM 188
#define TK_DIFF 189
#define TK_SPREAD 190
#define TK_TWA 191
#define TK_INTERP 192
#define TK_LAST_ROW 193
#define TK_RATE 194
#define TK_IRATE 195
#define TK_SUM_RATE 196
#define TK_SUM_IRATE 197
#define TK_AVG_RATE 198
#define TK_AVG_IRATE 199
#define TK_TBID 200
#define TK_SEMI 201
#define TK_NONE 202
#define TK_PREV 203
#define TK_LINEAR 204
#define TK_IMPORT 205
#define TK_METRIC 206
#define TK_TBNAME 207
#define TK_JOIN 208
#define TK_METRICS 209
#define TK_INSERT 210
#define TK_INTO 211
#define TK_VALUES 212
#define TK_SPACE 300 #define TK_SPACE 300
......
...@@ -171,10 +171,10 @@ extern tDataTypeDescriptor tDataTypes[15]; ...@@ -171,10 +171,10 @@ extern tDataTypeDescriptor tDataTypes[15];
bool isValidDataType(int32_t type); bool isValidDataType(int32_t type);
void setVardataNull(char* val, int32_t type); void setVardataNull(char* val, int32_t type);
void setNull(char *val, int32_t type, int32_t bytes); void setNull(char *val, int32_t type, int32_t bytes);
void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems); void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems);
void* getNullValue(int32_t type); void *getNullValue(int32_t type);
void assignVal(char *val, const char *src, int32_t len, int32_t type); void assignVal(char *val, const char *src, int32_t len, int32_t type);
void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf); void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf);
......
...@@ -26,6 +26,7 @@ extern "C" { ...@@ -26,6 +26,7 @@ extern "C" {
#include "taosdef.h" #include "taosdef.h"
#include "trpc.h" #include "trpc.h"
#include "tvariant.h" #include "tvariant.h"
#include "tsdb.h"
#define TSDB_FUNC_INVALID_ID -1 #define TSDB_FUNC_INVALID_ID -1
#define TSDB_FUNC_COUNT 0 #define TSDB_FUNC_COUNT 0
...@@ -70,15 +71,17 @@ extern "C" { ...@@ -70,15 +71,17 @@ extern "C" {
#define TSDB_FUNC_AVG_IRATE 34 #define TSDB_FUNC_AVG_IRATE 34
#define TSDB_FUNC_TID_TAG 35 #define TSDB_FUNC_TID_TAG 35
#define TSDB_FUNC_HISTOGRAM 36 #define TSDB_FUNC_BLKINFO 36
#define TSDB_FUNC_HLL 37
#define TSDB_FUNC_MODE 38 #define TSDB_FUNC_HISTOGRAM 37
#define TSDB_FUNC_SAMPLE 39 #define TSDB_FUNC_HLL 38
#define TSDB_FUNC_CEIL 40 #define TSDB_FUNC_MODE 39
#define TSDB_FUNC_FLOOR 41 #define TSDB_FUNC_SAMPLE 40
#define TSDB_FUNC_ROUND 42 #define TSDB_FUNC_CEIL 41
#define TSDB_FUNC_MAVG 43 #define TSDB_FUNC_FLOOR 42
#define TSDB_FUNC_CSUM 44 #define TSDB_FUNC_ROUND 43
#define TSDB_FUNC_MAVG 44
#define TSDB_FUNC_CSUM 45
#define TSDB_FUNCSTATE_SO 0x1u // single output #define TSDB_FUNCSTATE_SO 0x1u // single output
...@@ -214,13 +217,14 @@ typedef struct SAggFunctionInfo { ...@@ -214,13 +217,14 @@ typedef struct SAggFunctionInfo {
void (*xFinalize)(SQLFunctionCtx *pCtx); void (*xFinalize)(SQLFunctionCtx *pCtx);
void (*mergeFunc)(SQLFunctionCtx *pCtx); void (*mergeFunc)(SQLFunctionCtx *pCtx);
int32_t (*dataReqFunc)(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId); int32_t (*dataReqFunc)(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId);
} SAggFunctionInfo; } SAggFunctionInfo;
#define GET_RES_INFO(ctx) ((ctx)->resultInfo) #define GET_RES_INFO(ctx) ((ctx)->resultInfo)
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
int16_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable); int16_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable);
int32_t isValidFunction(const char* name, int32_t len);
#define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0) #define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0)
#define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0) #define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0)
...@@ -242,12 +246,16 @@ typedef struct STwaInfo { ...@@ -242,12 +246,16 @@ typedef struct STwaInfo {
STimeWindow win; STimeWindow win;
} STwaInfo; } STwaInfo;
struct SBufferWriter;
void blockDistInfoToBinary(STableBlockDist* pDist, struct SBufferWriter* bw);
void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDist* pDist);
/* global sql function array */ /* global sql function array */
extern struct SAggFunctionInfo aAggs[]; extern struct SAggFunctionInfo aAggs[];
extern int32_t functionCompatList[]; // compatible check array list extern int32_t functionCompatList[]; // compatible check array list
bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const char *minval, const char *maxval); bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const char *maxval);
/** /**
* the numOfRes should be kept, since it may be used later * the numOfRes should be kept, since it may be used later
...@@ -258,14 +266,14 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha ...@@ -258,14 +266,14 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha
(_r)->initialized = false; \ (_r)->initialized = false; \
} while (0) } while (0)
static FORCE_INLINE void initResultInfo(SResultRowCellInfo *pResInfo, uint32_t bufLen) { static FORCE_INLINE void initResultInfo(SResultRowCellInfo *pResInfo, int32_t bufLen) {
pResInfo->initialized = true; // the this struct has been initialized flag pResInfo->initialized = true; // the this struct has been initialized flag
pResInfo->complete = false; pResInfo->complete = false;
pResInfo->hasResult = false; pResInfo->hasResult = false;
pResInfo->numOfRes = 0; pResInfo->numOfRes = 0;
memset(GET_ROWCELL_INTERBUF(pResInfo), 0, (size_t)bufLen); memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen);
} }
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_QUERYEXECUTOR_H #ifndef TDENGINE_QEXECUTOR_H
#define TDENGINE_QUERYEXECUTOR_H #define TDENGINE_QEXECUTOR_H
#include "os.h" #include "os.h"
...@@ -37,30 +37,24 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int ...@@ -37,30 +37,24 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u) #define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP) #define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
#define SET_STABLE_QUERY_OVER(_q) ((_q)->tableIndex = (int32_t)((_q)->tableqinfoGroupInfo.numOfTables))
#define IS_STASBLE_QUERY_OVER(_q) ((_q)->tableIndex >= (int32_t)((_q)->tableqinfoGroupInfo.numOfTables))
#define GET_TABLEGROUP(q, _index) ((SArray*) taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index))) #define GET_TABLEGROUP(q, _index) ((SArray*) taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index)))
#define GET_NUM_OF_RESULTS(_r) (((_r)->outputBuf) == NULL? 0:((_r)->outputBuf)->info.rows)
enum { enum {
// when query starts to execute, this status will set // when query starts to execute, this status will set
QUERY_NOT_COMPLETED = 0x1u, QUERY_NOT_COMPLETED = 0x1u,
/* result output buffer is full, current query is paused.
* this status is only exist in group-by clause and diff/add/division/multiply/ query.
*/
QUERY_RESBUF_FULL = 0x2u,
/* query is over /* query is over
* 1. this status is used in one row result query process, e.g., count/sum/first/last/ avg...etc. * 1. this status is used in one row result query process, e.g., count/sum/first/last/ avg...etc.
* 2. when all data within queried time window, it is also denoted as query_completed * 2. when all data within queried time window, it is also denoted as query_completed
*/ */
QUERY_COMPLETED = 0x4u, QUERY_COMPLETED = 0x2u,
/* when the result is not completed return to client, this status will be /* when the result is not completed return to client, this status will be
* usually used in case of interval query with interpolation option * usually used in case of interval query with interpolation option
*/ */
QUERY_OVER = 0x8u, QUERY_OVER = 0x4u,
}; };
typedef struct SResultRowPool { typedef struct SResultRowPool {
...@@ -86,13 +80,13 @@ typedef struct SSqlGroupbyExpr { ...@@ -86,13 +80,13 @@ typedef struct SSqlGroupbyExpr {
typedef struct SResultRow { typedef struct SResultRow {
int32_t pageId; // pageId & rowId is the position of current result in disk-based output buffer int32_t pageId; // pageId & rowId is the position of current result in disk-based output buffer
int32_t rowId:29; // row index in buffer page int32_t offset:29; // row index in buffer page
bool startInterp; // the time window start timestamp has done the interpolation already. bool startInterp; // the time window start timestamp has done the interpolation already.
bool endInterp; // the time window end timestamp has done the interpolation already. bool endInterp; // the time window end timestamp has done the interpolation already.
bool closed; // this result status: closed or opened bool closed; // this result status: closed or opened
uint32_t numOfRows; // number of rows of current time window uint32_t numOfRows; // number of rows of current time window
SResultRowCellInfo* pCellInfo; // For each result column, there is a resultInfo SResultRowCellInfo* pCellInfo; // For each result column, there is a resultInfo
union {STimeWindow win; char* key;}; // start key of current time window union {STimeWindow win; char* key;}; // start key of current result row
} SResultRow; } SResultRow;
typedef struct SGroupResInfo { typedef struct SGroupResInfo {
...@@ -106,12 +100,11 @@ typedef struct SGroupResInfo { ...@@ -106,12 +100,11 @@ typedef struct SGroupResInfo {
* If the number of generated results is greater than this value, * If the number of generated results is greater than this value,
* query query will be halt and return results to client immediate. * query query will be halt and return results to client immediate.
*/ */
typedef struct SResultRec { typedef struct SRspResultInfo {
int64_t total; // total generated result size in rows int64_t total; // total generated result size in rows
int64_t rows; // current result set size in rows int32_t capacity; // capacity of current result output buffer
int64_t capacity; // capacity of current result output buffer
int32_t threshold; // result size threshold in rows. int32_t threshold; // result size threshold in rows.
} SResultRec; } SRspResultInfo;
typedef struct SResultRowInfo { typedef struct SResultRowInfo {
SResultRow** pResult; // result list SResultRow** pResult; // result list
...@@ -138,7 +131,6 @@ typedef struct SSingleColumnFilterInfo { ...@@ -138,7 +131,6 @@ typedef struct SSingleColumnFilterInfo {
typedef struct STableQueryInfo { typedef struct STableQueryInfo {
TSKEY lastKey; TSKEY lastKey;
int32_t groupIndex; // group id in table list int32_t groupIndex; // group id in table list
int16_t queryRangeSet; // denote if the query range is set, only available for interval query
tVariant tag; tVariant tag;
STimeWindow win; STimeWindow win;
STSCursor cur; STSCursor cur;
...@@ -179,82 +171,135 @@ typedef struct { ...@@ -179,82 +171,135 @@ typedef struct {
SArray* pResult; // SArray<SStddevInterResult> SArray* pResult; // SArray<SStddevInterResult>
} SInterResult; } SInterResult;
typedef struct SSDataBlock {
SDataStatis *pBlockStatis;
SArray *pDataBlock;
SDataBlockInfo info;
} SSDataBlock;
typedef struct SQuery { typedef struct SQuery {
SLimitVal limit;
bool stableQuery; // super table query or not
bool topBotQuery; // TODO used bitwise flag
bool groupbyColumn; // denote if this is a groupby normal column query
bool hasTagResults; // if there are tag values in final result or not
bool timeWindowInterpo;// if the time window start/end required interpolation
bool queryWindowIdentical; // all query time windows are identical for all tables in one group
bool queryBlockDist; // if query data block distribution
bool stabledev; // super table stddev query
int32_t interBufSize; // intermediate buffer sizse
SOrderVal order;
int16_t numOfCols; int16_t numOfCols;
int16_t numOfTags; int16_t numOfTags;
SOrderVal order;
STimeWindow window; STimeWindow window;
SInterval interval; SInterval interval;
int16_t precision; int16_t precision;
int16_t numOfOutput; int16_t numOfOutput;
int16_t fillType; int16_t fillType;
int16_t checkResultBuf; // check if the buffer is full during scan each block int16_t checkResultBuf; // check if the buffer is full during scan each block
SLimitVal limit;
int32_t srcRowSize; // todo extract struct int32_t srcRowSize; // todo extract struct
int32_t resultRowSize; int32_t resultRowSize;
int32_t intermediateResultRowSize; // intermediate result row size, in case of top-k query.
int32_t maxSrcColumnSize; int32_t maxSrcColumnSize;
int32_t tagLen; // tag value length of current query int32_t tagLen; // tag value length of current query
SSqlGroupbyExpr* pGroupbyExpr; SSqlGroupbyExpr* pGroupbyExpr;
SExprInfo* pExpr1; SExprInfo* pExpr1;
SExprInfo* pExpr2; SExprInfo* pExpr2;
int32_t numOfExpr2; int32_t numOfExpr2;
SColumnInfo* colList; SColumnInfo* colList;
SColumnInfo* tagColList; SColumnInfo* tagColList;
int32_t numOfFilterCols; int32_t numOfFilterCols;
int64_t* fillVal; int64_t* fillVal;
uint32_t status; // query status
SResultRec rec;
int32_t pos;
tFilePage** sdata;
STableQueryInfo* current;
int32_t numOfCheckedBlocks; // number of check data blocks
SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query. SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query.
SSingleColumnFilterInfo* pFilterInfo; SSingleColumnFilterInfo* pFilterInfo;
STableQueryInfo* current;
void* tsdb;
SMemRef memRef;
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
int32_t vgId;
} SQuery; } SQuery;
typedef SSDataBlock* (*__operator_fn_t)(void* param);
typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num);
struct SOperatorInfo;
typedef struct SQueryRuntimeEnv { typedef struct SQueryRuntimeEnv {
jmp_buf env; jmp_buf env;
SQuery* pQuery; SQuery* pQuery;
SQLFunctionCtx* pCtx; uint32_t status; // query status
int32_t numOfRowsPerPage; void* qinfo;
uint16_t* offset; uint8_t scanFlag; // denotes reversed scan of data or not
uint16_t scanFlag; // denotes reversed scan of data or not void* pQueryHandle;
SFillInfo* pFillInfo;
SResultRowInfo resultRowInfo; int32_t prevGroupId; // previous executed group id
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
SQueryCostInfo summary; SHashObj* pResultRowHashTable; // quick locate the window object for each result
void* pQueryHandle; char* keyBuf; // window key buffer
void* pSecQueryHandle; // another thread for SResultRowPool* pool; // window result object pool
bool stableQuery; // super table query or not char** prevRow;
bool topBotQuery; // TODO used bitwise flag
bool groupbyColumn; // denote if this is a groupby normal column query SArray* prevResult; // intermediate result, SArray<SInterResult>
bool hasTagResults; // if there are tag values in final result or not STSBuf* pTsBuf; // timestamp filter list
bool timeWindowInterpo;// if the time window start/end required interpolation STSCursor cur;
bool queryWindowIdentical; // all query time windows are identical for all tables in one group
bool queryBlockDist; // if query data block distribution char* tagVal; // tag value of current data block
bool stabledev; // super table stddev query SArithmeticSupport *sasArray;
int32_t interBufSize; // intermediate buffer sizse
int32_t prevGroupId; // previous executed group id SSDataBlock *outputBuf;
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
SHashObj* pResultRowHashTable; // quick locate the window object for each result struct SOperatorInfo *proot;
char* keyBuf; // window key buffer struct SOperatorInfo *pTableScanner; // table scan operator
SResultRowPool* pool; // window result object pool SGroupResInfo groupResInfo;
int64_t currentOffset; // dynamic offset value
int32_t* rowCellInfoOffset;// offset value for each row result cell info
char** prevRow; SRspResultInfo resultInfo;
SHashObj *pTableRetrieveTsMap;
SArray* prevResult; // intermediate result, SArray<SInterResult>
STSBuf* pTsBuf; // timestamp filter list
STSCursor cur;
char* tagVal; // tag value of current data block
SArithmeticSupport *sasArray;
} SQueryRuntimeEnv; } SQueryRuntimeEnv;
enum {
OP_IN_EXECUTING = 1,
OP_RES_TO_RETURN = 2,
OP_EXEC_DONE = 3,
};
enum OPERATOR_TYPE_E {
OP_TableScan = 1,
OP_DataBlocksOptScan = 2,
OP_TableSeqScan = 3,
OP_TagScan = 4,
OP_TableBlockInfoScan= 5,
OP_Aggregate = 6,
OP_Arithmetic = 7,
OP_Groupby = 8,
OP_Limit = 9,
OP_Offset = 10,
OP_TimeInterval = 11,
OP_Fill = 12,
OP_MultiTableAggregate = 13,
OP_MultiTableTimeInterval = 14,
};
typedef struct SOperatorInfo {
uint8_t operatorType;
bool blockingOptr; // block operator or not
uint8_t status; // denote if current operator is completed
int32_t numOfOutput; // number of columns of the current operator results
char *name; // name, used to show the query execution plan
void *info; // extension attribution
SExprInfo *pExpr;
SQueryRuntimeEnv *pRuntimeEnv;
struct SOperatorInfo *upstream;
__operator_fn_t exec;
__optr_cleanup_fn_t cleanup;
} SOperatorInfo;
enum { enum {
QUERY_RESULT_NOT_READY = 1, QUERY_RESULT_NOT_READY = 1,
QUERY_RESULT_READY = 2, QUERY_RESULT_READY = 2,
...@@ -262,23 +307,11 @@ enum { ...@@ -262,23 +307,11 @@ enum {
typedef struct SQInfo { typedef struct SQInfo {
void* signature; void* signature;
int32_t code; // error code to returned to client int32_t code; // error code to returned to client
int64_t owner; // if it is in execution int64_t owner; // if it is in execution
void* tsdb;
SMemRef memRef;
int32_t vgId;
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
SQueryRuntimeEnv runtimeEnv;
SHashObj* arrTableIdInfo;
int32_t groupIndex;
/* SQueryRuntimeEnv runtimeEnv;
* the query is executed position on which meter of the whole list. SQuery query;
* when the index reaches the last one of the list, it means the query is completed.
*/
int32_t tableIndex;
SGroupResInfo groupResInfo;
void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables; void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
pthread_mutex_t lock; // used to synchronize the rsp/query threads pthread_mutex_t lock; // used to synchronize the rsp/query threads
...@@ -287,6 +320,7 @@ typedef struct SQInfo { ...@@ -287,6 +320,7 @@ typedef struct SQInfo {
void* rspContext; // response context void* rspContext; // response context
int64_t startExecTs; // start to exec timestamp int64_t startExecTs; // start to exec timestamp
char* sql; // query sql string char* sql; // query sql string
SQueryCostInfo summary;
} SQInfo; } SQInfo;
typedef struct SQueryParam { typedef struct SQueryParam {
...@@ -305,10 +339,85 @@ typedef struct SQueryParam { ...@@ -305,10 +339,85 @@ typedef struct SQueryParam {
SSqlGroupbyExpr *pGroupbyExpr; SSqlGroupbyExpr *pGroupbyExpr;
} SQueryParam; } SQueryParam;
typedef struct STableScanInfo {
void *pQueryHandle;
int32_t numOfBlocks;
int32_t numOfSkipped;
int32_t numOfBlockStatis;
int64_t numOfRows;
int32_t order; // scan order
int32_t times; // repeat counts
int32_t current;
int32_t reverseTimes; // 0 by default
SQLFunctionCtx *pCtx; // next operator query context
SResultRowInfo *pResultRowInfo;
int32_t *rowCellInfoOffset;
SExprInfo *pExpr;
SSDataBlock block;
bool loadExternalRows; // load external rows (prev & next rows)
int32_t numOfOutput;
int64_t elapsedTime;
int32_t tableIndex;
} STableScanInfo;
typedef struct STagScanInfo {
SColumnInfo* pCols;
SSDataBlock* pRes;
int32_t totalTables;
int32_t currentIndex;
} STagScanInfo;
typedef struct SOptrBasicInfo {
SResultRowInfo resultRowInfo;
int32_t *rowCellInfoOffset; // offset value for each row result cell info
SQLFunctionCtx *pCtx;
SSDataBlock *pRes;
} SOptrBasicInfo;
typedef struct SOptrBasicInfo STableIntervalOperatorInfo;
typedef struct SAggOperatorInfo {
SOptrBasicInfo binfo;
uint32_t seed;
} SAggOperatorInfo;
typedef struct SArithOperatorInfo {
SOptrBasicInfo binfo;
int32_t bufCapacity;
uint32_t seed;
} SArithOperatorInfo;
typedef struct SLimitOperatorInfo {
int64_t limit;
int64_t total;
} SLimitOperatorInfo;
typedef struct SOffsetOperatorInfo {
int64_t offset;
} SOffsetOperatorInfo;
typedef struct SFillOperatorInfo {
SFillInfo *pFillInfo;
SSDataBlock *pRes;
int64_t totalInputRows;
} SFillOperatorInfo;
typedef struct SGroupbyOperatorInfo {
SOptrBasicInfo binfo;
int32_t colIndex;
char *prevData; // previous group by value
} SGroupbyOperatorInfo;
void freeParam(SQueryParam *param); void freeParam(SQueryParam *param);
int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param); int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param);
int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
SColumnInfo* pTagCols); SColumnInfo* pTagCols);
int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo,
SSqlFuncMsg **pExprMsg, SExprInfo *prevExpr);
SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code); SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code);
SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs, SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs,
SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, bool stableQuery, char* sql); SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, bool stableQuery, char* sql);
...@@ -318,13 +427,9 @@ void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters); ...@@ -318,13 +427,9 @@ void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters);
bool isQueryKilled(SQInfo *pQInfo); bool isQueryKilled(SQInfo *pQInfo);
int32_t checkForQueryBuf(size_t numOfTables); int32_t checkForQueryBuf(size_t numOfTables);
bool doBuildResCheck(SQInfo* pQInfo); bool doBuildResCheck(SQInfo* pQInfo);
void setQueryStatus(SQuery *pQuery, int8_t status); void setQueryStatus(SQueryRuntimeEnv *pRuntimeEnv, int8_t status);
bool onlyQueryTags(SQuery* pQuery); bool onlyQueryTags(SQuery* pQuery);
void buildTagQueryResult(SQInfo *pQInfo);
void stableQueryImpl(SQInfo *pQInfo);
void buildTableBlockDistResult(SQInfo *pQInfo);
void tableQueryImpl(SQInfo *pQInfo);
bool isValidQInfo(void *param); bool isValidQInfo(void *param);
int32_t doDumpQueryResult(SQInfo *pQInfo, char *data); int32_t doDumpQueryResult(SQInfo *pQInfo, char *data);
...@@ -336,4 +441,4 @@ void freeQInfo(SQInfo *pQInfo); ...@@ -336,4 +441,4 @@ void freeQInfo(SQInfo *pQInfo);
int32_t getMaximumIdleDurationSec(); int32_t getMaximumIdleDurationSec();
#endif // TDENGINE_QUERYEXECUTOR_H #endif // TDENGINE_QEXECUTOR_H
...@@ -24,6 +24,8 @@ extern "C" { ...@@ -24,6 +24,8 @@ extern "C" {
#include "qExtbuffer.h" #include "qExtbuffer.h"
#include "taosdef.h" #include "taosdef.h"
struct SSDataBlock;
typedef struct { typedef struct {
STColumn col; // column info STColumn col; // column info
int16_t functionId; // sql function id int16_t functionId; // sql function id
...@@ -78,7 +80,7 @@ void* taosDestroyFillInfo(SFillInfo *pFillInfo); ...@@ -78,7 +80,7 @@ void* taosDestroyFillInfo(SFillInfo *pFillInfo);
void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey); void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey);
void taosFillSetDataBlockFromFilePage(SFillInfo* pFillInfo, const tFilePage** pInput); void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const struct SSDataBlock* pInput);
void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, const tFilePage* pInput); void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, const tFilePage* pInput);
...@@ -88,7 +90,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t ...@@ -88,7 +90,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t
int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType); int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType);
int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, tFilePage** output, int32_t capacity); int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t capacity);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -55,7 +55,6 @@ typedef struct SResultBufStatis { ...@@ -55,7 +55,6 @@ typedef struct SResultBufStatis {
} SResultBufStatis; } SResultBufStatis;
typedef struct SDiskbasedResultBuf { typedef struct SDiskbasedResultBuf {
int32_t numOfRowsPerPage;
int32_t numOfPages; int32_t numOfPages;
int64_t totalBufSize; int64_t totalBufSize;
int64_t fileSize; // disk file size int64_t fileSize; // disk file size
...@@ -77,7 +76,7 @@ typedef struct SDiskbasedResultBuf { ...@@ -77,7 +76,7 @@ typedef struct SDiskbasedResultBuf {
SResultBufStatis statis; SResultBufStatis statis;
} SDiskbasedResultBuf; } SDiskbasedResultBuf;
#define DEFAULT_INTERN_BUF_PAGE_SIZE (256L) // in bytes #define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes
#define PAGE_INFO_INITIALIZER (SPageDiskInfo){-1, -1} #define PAGE_INFO_INITIALIZER (SPageDiskInfo){-1, -1}
/** /**
...@@ -89,8 +88,7 @@ typedef struct SDiskbasedResultBuf { ...@@ -89,8 +88,7 @@ typedef struct SDiskbasedResultBuf {
* @param handle * @param handle
* @return * @return
*/ */
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t rowSize, int32_t pagesize, int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t pagesize, int32_t inMemBufSize, const void* handle);
int32_t inMemBufSize, const void* handle);
/** /**
* *
...@@ -101,13 +99,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro ...@@ -101,13 +99,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro
*/ */
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId); tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
/**
*
* @param pResultBuf
* @return
*/
size_t getNumOfRowsPerPage(const SDiskbasedResultBuf* pResultBuf);
/** /**
* *
* @param pResultBuf * @param pResultBuf
......
...@@ -45,7 +45,7 @@ typedef struct SLimitVal { ...@@ -45,7 +45,7 @@ typedef struct SLimitVal {
typedef struct SOrderVal { typedef struct SOrderVal {
uint32_t order; uint32_t order;
int32_t orderColId; int32_t orderColId;
} SOrderVal; } SOrderVal;
typedef struct tVariantListItem { typedef struct tVariantListItem {
...@@ -185,19 +185,32 @@ typedef struct SSqlInfo { ...@@ -185,19 +185,32 @@ typedef struct SSqlInfo {
}; };
} SSqlInfo; } SSqlInfo;
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
enum SQL_NODE_TYPE {
SQL_NODE_TABLE_COLUMN= 1,
SQL_NODE_SQLFUNCTION = 2,
SQL_NODE_VALUE = 3,
SQL_NODE_EXPR = 4,
};
typedef struct tSQLExpr { typedef struct tSQLExpr {
uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr) uint16_t type; // sql node type
uint32_t tokenId; // 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 // the whole string of the function(col, param), while the function name is kept in token
SStrToken operand; SStrToken operand;
SStrToken colInfo; // field id uint32_t functionId; // function id
tVariant val; // value only for string, float, int
SStrToken colInfo; // table column info
tVariant value; // the use input value
SStrToken token; // original sql expr string SStrToken token; // original sql expr string
struct tSQLExpr *pLeft; // left child struct tSQLExpr *pLeft; // left child
struct tSQLExpr *pRight; // right child struct tSQLExpr *pRight; // right child
struct tSQLExprList *pParam; // function parameters struct tSQLExprList *pParam; // function parameters list
} tSQLExpr; } tSQLExpr;
// used in select clause. select <tSQLExprList> from xxx // used in select clause. select <tSQLExprList> from xxx
...@@ -294,16 +307,6 @@ void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type); ...@@ -294,16 +307,6 @@ void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type);
void *ParseAlloc(void *(*mallocProc)(size_t)); void *ParseAlloc(void *(*mallocProc)(size_t));
enum {
TSQL_NODE_TYPE_EXPR = 0x1,
TSQL_NODE_TYPE_ID = 0x2,
TSQL_NODE_TYPE_VALUE = 0x4,
};
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
SSqlInfo qSQLParse(const char *str); SSqlInfo qSQLParse(const char *str);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -112,13 +112,11 @@ STSBuf* tsBufClone(STSBuf* pTSBuf); ...@@ -112,13 +112,11 @@ STSBuf* tsBufClone(STSBuf* pTSBuf);
STSGroupBlockInfo* tsBufGetGroupBlockInfo(STSBuf* pTSBuf, int32_t id); STSGroupBlockInfo* tsBufGetGroupBlockInfo(STSBuf* pTSBuf, int32_t id);
void tsBufFlush(STSBuf* pTSBuf); void tsBufFlush(STSBuf* pTSBuf);
void tsBufResetPos(STSBuf* pTSBuf); void tsBufResetPos(STSBuf* pTSBuf);
STSElem tsBufGetElem(STSBuf* pTSBuf);
bool tsBufNextPos(STSBuf* pTSBuf); bool tsBufNextPos(STSBuf* pTSBuf);
STSElem tsBufGetElem(STSBuf* pTSBuf);
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t id, tVariant* tag); STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t id, tVariant* tag);
STSCursor tsBufGetCursor(STSBuf* pTSBuf); STSCursor tsBufGetCursor(STSBuf* pTSBuf);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#define GET_RES_WINDOW_KEY_LEN(_l) ((_l) + sizeof(uint64_t)) #define GET_RES_WINDOW_KEY_LEN(_l) ((_l) + sizeof(uint64_t))
#define curTimeWindowIndex(_winres) ((_winres)->curIndex) #define curTimeWindowIndex(_winres) ((_winres)->curIndex)
#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!sq))? (_q)->pExpr1[1].base.arg->argValue.i64:1) #define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!(sq)))? (_q)->pExpr1[1].base.arg->argValue.i64:1)
int32_t getOutputInterResultBufSize(SQuery* pQuery); int32_t getOutputInterResultBufSize(SQuery* pQuery);
...@@ -44,22 +44,18 @@ void closeResultRow(SResultRowInfo* pResultRowInfo, int32_t slot); ...@@ -44,22 +44,18 @@ void closeResultRow(SResultRowInfo* pResultRowInfo, int32_t slot);
bool isResultRowClosed(SResultRowInfo *pResultRowInfo, int32_t slot); bool isResultRowClosed(SResultRowInfo *pResultRowInfo, int32_t slot);
void clearResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* pResultRow, int16_t type); void clearResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* pResultRow, int16_t type);
SResultRowCellInfo* getResultCell(SQueryRuntimeEnv* pRuntimeEnv, const SResultRow* pRow, int32_t index); SResultRowCellInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t* offset);
static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) { static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {
assert(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size); assert(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size);
return pResultRowInfo->pResult[slot]; return pResultRowInfo->pResult[slot];
} }
static FORCE_INLINE char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SResultRow *pResult, static FORCE_INLINE char *getPosInResultPage(SQuery *pQuery, tFilePage* page, int32_t rowOffset, int16_t offset) {
tFilePage* page) { assert(rowOffset >= 0 && pQuery != NULL);
assert(pResult != NULL && pRuntimeEnv != NULL);
SQuery *pQuery = pRuntimeEnv->pQuery; int32_t numOfRows = (int32_t)GET_ROW_PARAM_FOR_MULTIOUTPUT(pQuery, pQuery->topBotQuery, pQuery->stableQuery);
return ((char *)page->data) + rowOffset + offset * numOfRows;
int32_t realRowId = (int32_t)(pResult->rowId * GET_ROW_PARAM_FOR_MULTIOUTPUT(pQuery, pRuntimeEnv->topBotQuery, pRuntimeEnv->stableQuery));
return ((char *)page->data) + pRuntimeEnv->offset[columnIndex] * pRuntimeEnv->numOfRowsPerPage +
pQuery->pExpr1[columnIndex].bytes * realRowId;
} }
bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type); bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type);
...@@ -74,8 +70,6 @@ void* destroyResultRowPool(SResultRowPool* p); ...@@ -74,8 +70,6 @@ void* destroyResultRowPool(SResultRowPool* p);
int32_t getNumOfAllocatedResultRows(SResultRowPool* p); int32_t getNumOfAllocatedResultRows(SResultRowPool* p);
int32_t getNumOfUsedResultRows(SResultRowPool* p); int32_t getNumOfUsedResultRows(SResultRowPool* p);
bool isPointInterpoQuery(SQuery *pQuery);
typedef struct { typedef struct {
SArray* pResult; // SArray<SResPair> SArray* pResult; // SArray<SResPair>
int32_t colId; int32_t colId;
...@@ -85,12 +79,14 @@ void interResToBinary(SBufferWriter* bw, SArray* pRes, int32_t tagLen); ...@@ -85,12 +79,14 @@ void interResToBinary(SBufferWriter* bw, SArray* pRes, int32_t tagLen);
SArray* interResFromBinary(const char* data, int32_t len); SArray* interResFromBinary(const char* data, int32_t len);
void freeInterResult(void* param); void freeInterResult(void* param);
void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo, int32_t offset); void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo);
void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo); void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo);
bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo);
bool hasRemainData(SGroupResInfo* pGroupResInfo); bool hasRemainData(SGroupResInfo* pGroupResInfo);
bool incNextGroup(SGroupResInfo* pGroupResInfo); bool incNextGroup(SGroupResInfo* pGroupResInfo);
int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo); int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo);
int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQInfo *pQInfo); int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t* offset);
#endif // TDENGINE_QUERYUTIL_H #endif // TDENGINE_QUERYUTIL_H
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "taosmsg.h" #include "taosmsg.h"
#include "texpr.h" #include "texpr.h"
#include "ttype.h" #include "ttype.h"
#include "tsdb.h"
#include "qAggMain.h" #include "qAggMain.h"
#include "qFill.h" #include "qFill.h"
...@@ -26,11 +27,9 @@ ...@@ -26,11 +27,9 @@
#include "qTsbuf.h" #include "qTsbuf.h"
#include "queryLog.h" #include "queryLog.h"
//#define GET_INPUT_DATA_LIST(x) (((char *)((x)->pInput)) + ((x)->startOffset) * ((x)->inputBytes))
#define GET_INPUT_DATA_LIST(x) ((char *)((x)->pInput)) #define GET_INPUT_DATA_LIST(x) ((char *)((x)->pInput))
#define GET_INPUT_DATA(x, y) (GET_INPUT_DATA_LIST(x) + (y) * (x)->inputBytes) #define GET_INPUT_DATA(x, y) (GET_INPUT_DATA_LIST(x) + (y) * (x)->inputBytes)
//#define GET_TS_LIST(x) ((TSKEY*)&((x)->ptsList[(x)->startOffset]))
#define GET_TS_LIST(x) ((TSKEY*)((x)->ptsList)) #define GET_TS_LIST(x) ((TSKEY*)((x)->ptsList))
#define GET_TS_DATA(x, y) (GET_TS_LIST(x)[(y)]) #define GET_TS_DATA(x, y) (GET_TS_LIST(x)[(y)])
...@@ -191,6 +190,11 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -191,6 +190,11 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
*bytes = (int16_t)(dataBytes + sizeof(int16_t) + sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t) + VARSTR_HEADER_SIZE); *bytes = (int16_t)(dataBytes + sizeof(int16_t) + sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t) + VARSTR_HEADER_SIZE);
*interBytes = 0; *interBytes = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == TSDB_FUNC_BLKINFO) {
*type = TSDB_DATA_TYPE_BINARY;
*bytes = 16384;
*interBytes = 0;
return TSDB_CODE_SUCCESS;
} }
if (functionId == TSDB_FUNC_COUNT) { if (functionId == TSDB_FUNC_COUNT) {
...@@ -209,7 +213,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -209,7 +213,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
if (functionId == TSDB_FUNC_TS_COMP) { if (functionId == TSDB_FUNC_TS_COMP) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
*bytes = sizeof(int32_t); // this results is compressed ts data *bytes = 1; // this results is compressed ts data, only one byte
*interBytes = POINTER_BYTES; *interBytes = POINTER_BYTES;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -355,6 +359,22 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -355,6 +359,22 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
// TODO use hash table
int32_t isValidFunction(const char* name, int32_t len) {
for(int32_t i = 0; i <= TSDB_FUNC_BLKINFO; ++i) {
int32_t nameLen = (int32_t) strlen(aAggs[i].name);
if (len != nameLen) {
continue;
}
if (strncasecmp(aAggs[i].name, name, len) == 0) {
return i;
}
}
return -1;
}
// set the query flag to denote that query is completed // set the query flag to denote that query is completed
static void no_next_step(SQLFunctionCtx *pCtx) { static void no_next_step(SQLFunctionCtx *pCtx) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
...@@ -458,7 +478,7 @@ static void count_func_merge(SQLFunctionCtx *pCtx) { ...@@ -458,7 +478,7 @@ static void count_func_merge(SQLFunctionCtx *pCtx) {
* @param filterCols * @param filterCols
* @return * @return
*/ */
int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { int32_t countRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { if (colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} else { } else {
...@@ -466,7 +486,7 @@ int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32 ...@@ -466,7 +486,7 @@ int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32
} }
} }
int32_t no_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { int32_t noDataRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -674,16 +694,16 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) { ...@@ -674,16 +694,16 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) {
} }
} }
static int32_t statisRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t statisRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
return BLK_DATA_STATIS_NEEDED; return BLK_DATA_STATIS_NEEDED;
} }
static int32_t dataBlockRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t dataBlockRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} }
// todo: if column in current data block are null, opt for this case // todo: if column in current data block are null, opt for this case
static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order == TSDB_ORDER_DESC) { if (pCtx->order == TSDB_ORDER_DESC) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -696,7 +716,7 @@ static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, i ...@@ -696,7 +716,7 @@ static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, i
} }
} }
static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order != pCtx->param[0].i64) { if (pCtx->order != pCtx->param[0].i64) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -708,7 +728,7 @@ static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, in ...@@ -708,7 +728,7 @@ static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, in
} }
} }
static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order == TSDB_ORDER_DESC) { if (pCtx->order == TSDB_ORDER_DESC) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -724,11 +744,11 @@ static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY en ...@@ -724,11 +744,11 @@ static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY en
if (pInfo->hasResult != DATA_SET_FLAG) { if (pInfo->hasResult != DATA_SET_FLAG) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} else { // data in current block is not earlier than current result } else { // data in current block is not earlier than current result
return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; return (pInfo->ts <= w->skey) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
} }
} }
static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order != pCtx->param[0].i64) { if (pCtx->order != pCtx->param[0].i64) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -744,7 +764,7 @@ static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end ...@@ -744,7 +764,7 @@ static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end
if (pInfo->hasResult != DATA_SET_FLAG) { if (pInfo->hasResult != DATA_SET_FLAG) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} else { } else {
return (pInfo->ts > end) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; return (pInfo->ts > w->ekey) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
} }
} }
...@@ -1359,7 +1379,21 @@ static void min_function_f(SQLFunctionCtx *pCtx, int32_t index) { ...@@ -1359,7 +1379,21 @@ static void min_function_f(SQLFunctionCtx *pCtx, int32_t index) {
} }
static void stddev_function(SQLFunctionCtx *pCtx) { static void stddev_function(SQLFunctionCtx *pCtx) {
SStddevInfo *pStd = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
SStddevInfo *pStd = GET_ROWCELL_INTERBUF(pResInfo);
if (pCtx->currentStage == REPEAT_SCAN && pStd->stage == 0) {
pStd->stage++;
avg_finalizer(pCtx);
pResInfo->initialized = true; // set it initialized to avoid re-initialization
// save average value into tmpBuf, for second stage scan
SAvgInfo *pAvg = GET_ROWCELL_INTERBUF(pResInfo);
pStd->avg = GET_DOUBLE_VAL(pCtx->pOutput);
assert((isnan(pAvg->sum) && pAvg->num == 0) || (pStd->num == pAvg->num && pStd->avg == pAvg->sum));
}
if (pStd->stage == 0) { if (pStd->stage == 0) {
// the first stage is to calculate average value // the first stage is to calculate average value
...@@ -1432,7 +1466,20 @@ static void stddev_function_f(SQLFunctionCtx *pCtx, int32_t index) { ...@@ -1432,7 +1466,20 @@ static void stddev_function_f(SQLFunctionCtx *pCtx, int32_t index) {
// the second stage to calculate standard deviation // the second stage to calculate standard deviation
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
SStddevInfo *pStd = GET_ROWCELL_INTERBUF(pResInfo); SStddevInfo *pStd = GET_ROWCELL_INTERBUF(pResInfo);
if (pCtx->currentStage == REPEAT_SCAN && pStd->stage == 0) {
pStd->stage++;
avg_finalizer(pCtx);
pResInfo->initialized = true; // set it initialized to avoid re-initialization
// save average value into tmpBuf, for second stage scan
SAvgInfo *pAvg = GET_ROWCELL_INTERBUF(pResInfo);
pStd->avg = GET_DOUBLE_VAL(pCtx->pOutput);
assert((isnan(pAvg->sum) && pAvg->num == 0) || (pStd->num == pAvg->num && pStd->avg == pAvg->sum));
}
/* the first stage is to calculate average value */ /* the first stage is to calculate average value */
if (pStd->stage == 0) { if (pStd->stage == 0) {
avg_function_f(pCtx, index); avg_function_f(pCtx, index);
...@@ -1574,7 +1621,7 @@ static void stddev_dst_function(SQLFunctionCtx *pCtx) { ...@@ -1574,7 +1621,7 @@ static void stddev_dst_function(SQLFunctionCtx *pCtx) {
if (p == NULL) { if (p == NULL) {
return; return;
} }
avg = p->avg; avg = p->avg;
} }
...@@ -1776,7 +1823,7 @@ static bool first_last_function_setup(SQLFunctionCtx *pCtx) { ...@@ -1776,7 +1823,7 @@ static bool first_last_function_setup(SQLFunctionCtx *pCtx) {
// todo opt for null block // todo opt for null block
static void first_function(SQLFunctionCtx *pCtx) { static void first_function(SQLFunctionCtx *pCtx) {
if (pCtx->order == TSDB_ORDER_DESC || pCtx->preAggVals.dataBlockLoaded == false) { if (pCtx->order == TSDB_ORDER_DESC /*|| pCtx->preAggVals.dataBlockLoaded == false*/) {
return; return;
} }
...@@ -1850,7 +1897,7 @@ static void first_dist_function(SQLFunctionCtx *pCtx) { ...@@ -1850,7 +1897,7 @@ static void first_dist_function(SQLFunctionCtx *pCtx) {
* 1. data block that are not loaded * 1. data block that are not loaded
* 2. scan data files in desc order * 2. scan data files in desc order
*/ */
if (pCtx->order == TSDB_ORDER_DESC || pCtx->preAggVals.dataBlockLoaded == false) { if (pCtx->order == TSDB_ORDER_DESC/* || pCtx->preAggVals.dataBlockLoaded == false*/) {
return; return;
} }
...@@ -1921,7 +1968,7 @@ static void first_dist_func_merge(SQLFunctionCtx *pCtx) { ...@@ -1921,7 +1968,7 @@ static void first_dist_func_merge(SQLFunctionCtx *pCtx) {
* least one data in this block that is not null.(TODO opt for this case) * least one data in this block that is not null.(TODO opt for this case)
*/ */
static void last_function(SQLFunctionCtx *pCtx) { static void last_function(SQLFunctionCtx *pCtx) {
if (pCtx->order != pCtx->param[0].i64 || pCtx->preAggVals.dataBlockLoaded == false) { if (pCtx->order != pCtx->param[0].i64/* || pCtx->preAggVals.dataBlockLoaded == false*/) {
return; return;
} }
...@@ -1934,6 +1981,7 @@ static void last_function(SQLFunctionCtx *pCtx) { ...@@ -1934,6 +1981,7 @@ static void last_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
} }
memcpy(pCtx->pOutput, data, pCtx->inputBytes); memcpy(pCtx->pOutput, data, pCtx->inputBytes);
TSKEY ts = GET_TS_DATA(pCtx, i); TSKEY ts = GET_TS_DATA(pCtx, i);
...@@ -2013,13 +2061,7 @@ static void last_dist_function(SQLFunctionCtx *pCtx) { ...@@ -2013,13 +2061,7 @@ static void last_dist_function(SQLFunctionCtx *pCtx) {
return; return;
} }
// data block is discard, not loaded, do not need to check it
if (!pCtx->preAggVals.dataBlockLoaded) {
return;
}
int32_t notNullElems = 0; int32_t notNullElems = 0;
for (int32_t i = pCtx->size - 1; i >= 0; --i) { for (int32_t i = pCtx->size - 1; i >= 0; --i) {
char *data = GET_INPUT_DATA(pCtx, i); char *data = GET_INPUT_DATA(pCtx, i);
if (pCtx->hasNull && isNull(data, pCtx->inputType)) { if (pCtx->hasNull && isNull(data, pCtx->inputType)) {
...@@ -2125,12 +2167,7 @@ static void last_row_finalizer(SQLFunctionCtx *pCtx) { ...@@ -2125,12 +2167,7 @@ static void last_row_finalizer(SQLFunctionCtx *pCtx) {
// do nothing at the first stage // do nothing at the first stage
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->hasResult != DATA_SET_FLAG) { if (pResInfo->hasResult != DATA_SET_FLAG) {
if (pCtx->outputType == TSDB_DATA_TYPE_BINARY || pCtx->outputType == TSDB_DATA_TYPE_NCHAR) { setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
setVardataNull(pCtx->pOutput, pCtx->outputType);
} else {
setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
}
return; return;
} }
...@@ -2445,7 +2482,7 @@ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) { ...@@ -2445,7 +2482,7 @@ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) {
} }
} }
bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const char *minval, const char *maxval) { bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const char *maxval) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo == NULL) { if (pResInfo == NULL) {
return true; return true;
...@@ -2460,7 +2497,7 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha ...@@ -2460,7 +2497,7 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha
tValuePair **pRes = (tValuePair**) pTopBotInfo->res; tValuePair **pRes = (tValuePair**) pTopBotInfo->res;
if (functionId == TSDB_FUNC_TOP) { if (pCtx->functionId == TSDB_FUNC_TOP) {
switch (pCtx->inputType) { switch (pCtx->inputType) {
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
return GET_INT8_VAL(maxval) > pRes[0]->v.i64; return GET_INT8_VAL(maxval) > pRes[0]->v.i64;
...@@ -2531,9 +2568,13 @@ static bool top_bottom_function_setup(SQLFunctionCtx *pCtx) { ...@@ -2531,9 +2568,13 @@ static bool top_bottom_function_setup(SQLFunctionCtx *pCtx) {
static void top_function(SQLFunctionCtx *pCtx) { static void top_function(SQLFunctionCtx *pCtx) {
int32_t notNullElems = 0; int32_t notNullElems = 0;
STopBotInfo *pRes = getTopBotOutputInfo(pCtx); STopBotInfo *pRes = getTopBotOutputInfo(pCtx);
assert(pRes->num >= 0); assert(pRes->num >= 0);
if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotInfo) + POINTER_BYTES * pCtx->param[0].i64)) {
buildTopBotStruct(pRes, pCtx);
}
for (int32_t i = 0; i < pCtx->size; ++i) { for (int32_t i = 0; i < pCtx->size; ++i) {
char *data = GET_INPUT_DATA(pCtx, i); char *data = GET_INPUT_DATA(pCtx, i);
...@@ -2609,13 +2650,13 @@ static void bottom_function(SQLFunctionCtx *pCtx) { ...@@ -2609,13 +2650,13 @@ static void bottom_function(SQLFunctionCtx *pCtx) {
if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotInfo) + POINTER_BYTES * pCtx->param[0].i64)) { if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotInfo) + POINTER_BYTES * pCtx->param[0].i64)) {
buildTopBotStruct(pRes, pCtx); buildTopBotStruct(pRes, pCtx);
} }
for (int32_t i = 0; i < pCtx->size; ++i) { for (int32_t i = 0; i < pCtx->size; ++i) {
char *data = GET_INPUT_DATA(pCtx, i); char *data = GET_INPUT_DATA(pCtx, i);
TSKEY ts = GET_TS_DATA(pCtx, i); TSKEY ts = GET_TS_DATA(pCtx, i);
if (pCtx->hasNull && isNull(data, pCtx->inputType)) { if (pCtx->hasNull && isNull(data, pCtx->inputType)) {
continue; continue;
} }
notNullElems++; notNullElems++;
...@@ -2648,7 +2689,7 @@ static void bottom_function_f(SQLFunctionCtx *pCtx, int32_t index) { ...@@ -2648,7 +2689,7 @@ static void bottom_function_f(SQLFunctionCtx *pCtx, int32_t index) {
if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotInfo) + POINTER_BYTES * pCtx->param[0].i64)) { if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotInfo) + POINTER_BYTES * pCtx->param[0].i64)) {
buildTopBotStruct(pRes, pCtx); buildTopBotStruct(pRes, pCtx);
} }
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
do_bottom_function_add(pRes, (int32_t)pCtx->param[0].i64, pData, ts, pCtx->inputType, &pCtx->tagInfo, NULL, 0); do_bottom_function_add(pRes, (int32_t)pCtx->param[0].i64, pData, ts, pCtx->inputType, &pCtx->tagInfo, NULL, 0);
...@@ -2729,6 +2770,17 @@ static void percentile_function(SQLFunctionCtx *pCtx) { ...@@ -2729,6 +2770,17 @@ static void percentile_function(SQLFunctionCtx *pCtx) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
if (pCtx->currentStage == REPEAT_SCAN && pInfo->stage == 0) {
// all data are null, set it completed
if (pInfo->numOfElems == 0) {
pResInfo->complete = true;
} else {
pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, pInfo->minval, pInfo->maxval);
}
pInfo->stage += 1;
}
// the first stage, only acquire the min/max value // the first stage, only acquire the min/max value
if (pInfo->stage == 0) { if (pInfo->stage == 0) {
if (pCtx->preAggVals.isSet) { if (pCtx->preAggVals.isSet) {
...@@ -2802,10 +2854,20 @@ static void percentile_function_f(SQLFunctionCtx *pCtx, int32_t index) { ...@@ -2802,10 +2854,20 @@ static void percentile_function_f(SQLFunctionCtx *pCtx, int32_t index) {
} }
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
SPercentileInfo *pInfo = (SPercentileInfo *)GET_ROWCELL_INTERBUF(pResInfo); SPercentileInfo *pInfo = (SPercentileInfo *)GET_ROWCELL_INTERBUF(pResInfo);
if (pInfo->stage == 0) {
if (pCtx->currentStage == REPEAT_SCAN && pInfo->stage == 0) {
// all data are null, set it completed
if (pInfo->numOfElems == 0) {
pResInfo->complete = true;
} else {
pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, pInfo->minval, pInfo->maxval);
}
pInfo->stage += 1;
}
if (pInfo->stage == 0) {
double v = 0; double v = 0;
GET_TYPED_DATA(v, double, pCtx->inputType, pData); GET_TYPED_DATA(v, double, pCtx->inputType, pData);
...@@ -3240,8 +3302,6 @@ static void col_project_function(SQLFunctionCtx *pCtx) { ...@@ -3240,8 +3302,6 @@ static void col_project_function(SQLFunctionCtx *pCtx) {
pCtx->inputBytes); pCtx->inputBytes);
} }
} }
pCtx->pOutput += pCtx->size * pCtx->outputBytes;
} }
static void col_project_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void col_project_function_f(SQLFunctionCtx *pCtx, int32_t index) {
...@@ -3547,9 +3607,6 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3547,9 +3607,6 @@ static void diff_function(SQLFunctionCtx *pCtx) {
int32_t forwardStep = (isFirstBlock) ? notNullElems - 1 : notNullElems; int32_t forwardStep = (isFirstBlock) ? notNullElems - 1 : notNullElems;
GET_RES_INFO(pCtx)->numOfRes += forwardStep; GET_RES_INFO(pCtx)->numOfRes += forwardStep;
pCtx->pOutput += forwardStep * pCtx->outputBytes;
pCtx->ptsOutputBuf = (char*)pCtx->ptsOutputBuf + forwardStep * TSDB_KEYSIZE;
} }
} }
...@@ -3631,7 +3688,7 @@ char *getArithColumnData(void *param, const char* name, int32_t colId) { ...@@ -3631,7 +3688,7 @@ char *getArithColumnData(void *param, const char* name, int32_t colId) {
} }
} }
assert(index >= 0 && colId >= 0); assert(index >= 0 /*&& colId >= 0*/);
return pSupport->data[index] + pSupport->offset * pSupport->colList[index].bytes; return pSupport->data[index] + pSupport->offset * pSupport->colList[index].bytes;
} }
...@@ -3640,7 +3697,6 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) { ...@@ -3640,7 +3697,6 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz; SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
arithmeticTreeTraverse(sas->pArithExpr->pExpr, pCtx->size, pCtx->pOutput, sas, pCtx->order, getArithColumnData); arithmeticTreeTraverse(sas->pArithExpr->pExpr, pCtx->size, pCtx->pOutput, sas, pCtx->order, getArithColumnData);
pCtx->pOutput += pCtx->outputBytes * pCtx->size;
} }
static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
...@@ -4171,50 +4227,88 @@ static void interp_function_impl(SQLFunctionCtx *pCtx) { ...@@ -4171,50 +4227,88 @@ static void interp_function_impl(SQLFunctionCtx *pCtx) {
} }
if (pCtx->inputType == TSDB_DATA_TYPE_TIMESTAMP) { if (pCtx->inputType == TSDB_DATA_TYPE_TIMESTAMP) {
*(TSKEY *) pCtx->pOutput = pCtx->startTs; *(TSKEY *)pCtx->pOutput = pCtx->startTs;
} else if (type == TSDB_FILL_NULL) {
setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
} else if (type == TSDB_FILL_SET_VALUE) {
tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true);
} else { } else {
if (pCtx->start.key == INT64_MIN) { if (pCtx->start.key != INT64_MIN && pCtx->start.key < pCtx->startTs && pCtx->end.key > pCtx->startTs) {
assert(pCtx->end.key == INT64_MIN); if (type == TSDB_FILL_PREV) {
return; if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) {
} SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->start.val);
} else {
if (type == TSDB_FILL_NULL) { assignVal(pCtx->pOutput, pCtx->start.ptr, pCtx->outputBytes, pCtx->inputType);
setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); }
} else if (type == TSDB_FILL_SET_VALUE) { } else if (type == TSDB_FILL_NEXT) {
tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true); if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) {
} else if (type == TSDB_FILL_PREV) { SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->end.val);
if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) { } else {
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->start.val); assignVal(pCtx->pOutput, pCtx->end.ptr, pCtx->outputBytes, pCtx->inputType);
} else { }
assignVal(pCtx->pOutput, pCtx->start.ptr, pCtx->outputBytes, pCtx->inputType); } else if (type == TSDB_FILL_LINEAR) {
SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val};
SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val};
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
int32_t srcType = pCtx->inputType;
if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data?
if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} else {
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE);
}
} else {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
}
} }
} else if (type == TSDB_FILL_NEXT) { } else {
if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) { // no data generated yet
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->end.val); if (pCtx->size == 1) {
} else { return;
assignVal(pCtx->pOutput, pCtx->end.ptr, pCtx->outputBytes, pCtx->inputType);
} }
} else if (type == TSDB_FILL_LINEAR) {
SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val}; // check the timestamp in input buffer
SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val}; TSKEY skey = GET_TS_DATA(pCtx, 0);
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput}; TSKEY ekey = GET_TS_DATA(pCtx, 1);
int32_t srcType = pCtx->inputType; // no data generated yet
if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data? if (!(skey < pCtx->startTs && ekey > pCtx->startTs)) {
if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) { return;
setNull(pCtx->pOutput, srcType, pCtx->inputBytes); }
assert(pCtx->start.key == INT64_MIN && skey < pCtx->startTs && ekey > pCtx->startTs);
if (type == TSDB_FILL_PREV) {
assignVal(pCtx->pOutput, pCtx->pInput, pCtx->outputBytes, pCtx->inputType);
} else if (type == TSDB_FILL_NEXT) {
char* val = ((char*)pCtx->pInput) + pCtx->inputBytes;
assignVal(pCtx->pOutput, val, pCtx->outputBytes, pCtx->inputType);
} else if (type == TSDB_FILL_LINEAR) {
char *start = GET_INPUT_DATA(pCtx, 0);
char *end = GET_INPUT_DATA(pCtx, 1);
SPoint point1 = {.key = skey, .val = start};
SPoint point2 = {.key = ekey, .val = end};
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
int32_t srcType = pCtx->inputType;
if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data?
if (isNull(start, srcType) || isNull(end, srcType)) {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} else {
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, srcType);
}
} else { } else {
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE); setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} }
} else {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} }
} }
} }
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
} }
static void interp_function(SQLFunctionCtx *pCtx) { static void interp_function(SQLFunctionCtx *pCtx) {
// at this point, the value is existed, return directly // at this point, the value is existed, return directly
if (pCtx->size > 0) { if (pCtx->size > 0) {
...@@ -4289,11 +4383,22 @@ static void ts_comp_finalize(SQLFunctionCtx *pCtx) { ...@@ -4289,11 +4383,22 @@ static void ts_comp_finalize(SQLFunctionCtx *pCtx) {
STSBuf * pTSbuf = pInfo->pTSBuf; STSBuf * pTSbuf = pInfo->pTSBuf;
tsBufFlush(pTSbuf); tsBufFlush(pTSbuf);
qDebug("total timestamp :%"PRId64, pTSbuf->numOfTotal);
// TODO refactor transfer ownership of current file
*(FILE **)pCtx->pOutput = pTSbuf->f; *(FILE **)pCtx->pOutput = pTSbuf->f;
pResInfo->complete = true;
// get the file size
struct stat fStat;
if ((fstat(fileno(pTSbuf->f), &fStat) == 0)) {
pResInfo->numOfRes = fStat.st_size;
}
pTSbuf->remainOpen = true; pTSbuf->remainOpen = true;
tsBufDestroy(pTSbuf); tsBufDestroy(pTSbuf);
doFinalizer(pCtx); doFinalizer(pCtx);
} }
...@@ -4637,10 +4742,126 @@ static void sumrate_finalizer(SQLFunctionCtx *pCtx) { ...@@ -4637,10 +4742,126 @@ static void sumrate_finalizer(SQLFunctionCtx *pCtx) {
doFinalizer(pCtx); doFinalizer(pCtx);
} }
void blockInfo_func(SQLFunctionCtx* pCtx) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
STableBlockDist* pDist = (STableBlockDist*) GET_ROWCELL_INTERBUF(pResInfo);
///////////////////////////////////////////////////////////////////////////////////////////// int32_t len = *(int32_t*) pCtx->pInput;
blockDistInfoFromBinary((char*)pCtx->pInput + sizeof(int32_t), len, pDist);
pDist->rowSize = (int16_t) pCtx->param[0].i64;
memcpy(pCtx->pOutput, pCtx->pInput, sizeof(int32_t) + len);
pResInfo->numOfRes = 1;
pResInfo->hasResult = DATA_SET_FLAG;
}
static void mergeTableBlockDist(STableBlockDist* pDist, const STableBlockDist* pSrc) {
assert(pDist != NULL && pSrc != NULL);
pDist->numOfTables += pSrc->numOfTables;
pDist->numOfRowsInMemTable += pSrc->numOfRowsInMemTable;
pDist->numOfFiles += pSrc->numOfFiles;
pDist->totalSize += pSrc->totalSize;
if (pDist->dataBlockInfos == NULL) {
pDist->dataBlockInfos = taosArrayInit(4, sizeof(SFileBlockInfo));
}
taosArrayPushBatch(pDist->dataBlockInfos, pSrc->dataBlockInfos->pData, (int32_t) taosArrayGetSize(pSrc->dataBlockInfos));
}
void block_func_merge(SQLFunctionCtx* pCtx) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
STableBlockDist* pDist = (STableBlockDist*) GET_ROWCELL_INTERBUF(pResInfo);
STableBlockDist info = {0};
int32_t len = *(int32_t*) pCtx->pInput;
blockDistInfoFromBinary(((char*)pCtx->pInput) + sizeof(int32_t), len, &info);
mergeTableBlockDist(pDist, &info);
}
static int32_t doGetPercentile(const SArray* pArray, double rate) {
int32_t len = (int32_t)taosArrayGetSize(pArray);
if (len <= 0) {
return 0;
}
assert(rate >= 0 && rate <= 1.0);
int idx = (int32_t)((len - 1) * rate);
return ((SFileBlockInfo *)(taosArrayGet(pArray, idx)))->numOfRows;
}
static int compareBlockInfo(const void *pLeft, const void *pRight) {
int32_t left = ((SFileBlockInfo *)pLeft)->numOfRows;
int32_t right = ((SFileBlockInfo *)pRight)->numOfRows;
if (left > right) return 1;
if (left < right) return -1;
return 0;
}
void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) {
if (pTableBlockDist == NULL) {
return;
}
int64_t min = INT64_MAX, max = INT64_MIN, avg = 0;
SArray* blockInfos= pTableBlockDist->dataBlockInfos;
int64_t totalRows = 0, totalBlocks = taosArrayGetSize(blockInfos);
for (size_t i = 0; i < taosArrayGetSize(blockInfos); i++) {
SFileBlockInfo *blockInfo = taosArrayGet(blockInfos, i);
int64_t rows = blockInfo->numOfRows;
min = MIN(min, rows);
max = MAX(max, rows);
totalRows += rows;
}
avg = totalBlocks > 0 ? (int64_t)(totalRows/totalBlocks) : 0;
taosArraySort(blockInfos, compareBlockInfo);
uint64_t totalLen = pTableBlockDist->totalSize;
int32_t rowSize = pTableBlockDist->rowSize;
int sz = sprintf(result + VARSTR_HEADER_SIZE,
"summary: \n\t "
"5th=[%d], 10th=[%d], 20th=[%d], 30th=[%d], 40th=[%d], 50th=[%d]\n\t "
"60th=[%d], 70th=[%d], 80th=[%d], 90th=[%d], 95th=[%d], 99th=[%d]\n\t "
"Min=[%"PRId64"(Rows)] Max=[%"PRId64"(Rows)] Avg=[%"PRId64"(Rows)] Stddev=[%.2f] \n\t "
"Rows=[%"PRId64"], Blocks=[%"PRId64"], Size=[%.3f(Kb)] Comp=[%.2f%%]\n\t "
"RowsInMem=[%d] \n\t SeekHeaderTime=[%d(us)]",
doGetPercentile(blockInfos, 0.05), doGetPercentile(blockInfos, 0.10),
doGetPercentile(blockInfos, 0.20), doGetPercentile(blockInfos, 0.30),
doGetPercentile(blockInfos, 0.40), doGetPercentile(blockInfos, 0.50),
doGetPercentile(blockInfos, 0.60), doGetPercentile(blockInfos, 0.70),
doGetPercentile(blockInfos, 0.80), doGetPercentile(blockInfos, 0.90),
doGetPercentile(blockInfos, 0.95), doGetPercentile(blockInfos, 0.99),
min, max, avg, 0.0,
totalRows, totalBlocks, totalLen/1024.0, (double)(totalLen*100.0)/(rowSize*totalRows),
pTableBlockDist->numOfRowsInMemTable, pTableBlockDist->firstSeekTimeUs);
varDataSetLen(result, sz);
UNUSED(sz);
}
void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
STableBlockDist* pDist = (STableBlockDist*) GET_ROWCELL_INTERBUF(pResInfo);
pDist->rowSize = (int16_t)pCtx->param[0].i64;
generateBlockDistResult(pDist, pCtx->pOutput);
// cannot set the numOfIteratedElems again since it is set during previous iteration
pResInfo->numOfRes = 1;
pResInfo->hasResult = DATA_SET_FLAG;
doFinalizer(pCtx);
}
/////////////////////////////////////////////////////////////////////////////////////////////
/* /*
* function compatible list. * function compatible list.
* tag and ts are not involved in the compatibility check * tag and ts are not involved in the compatibility check
...@@ -4659,8 +4880,8 @@ int32_t functionCompatList[] = { ...@@ -4659,8 +4880,8 @@ int32_t functionCompatList[] = {
4, -1, -1, 1, 1, 1, 1, 1, 1, -1, 4, -1, -1, 1, 1, 1, 1, 1, 1, -1,
// tag, colprj, tagprj, arithmetic, diff, first_dist, last_dist, interp rate irate // tag, colprj, tagprj, arithmetic, diff, first_dist, last_dist, interp rate irate
1, 1, 1, 1, -1, 1, 1, 5, 1, 1, 1, 1, 1, 1, -1, 1, 1, 5, 1, 1,
// sum_rate, sum_irate, avg_rate, avg_irate // sum_rate, sum_irate, avg_rate, avg_irate, tid_tag, blk_info
1, 1, 1, 1, 1, 1, 1, 1, 6, 7
}; };
SAggFunctionInfo aAggs[] = {{ SAggFunctionInfo aAggs[] = {{
...@@ -4675,7 +4896,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4675,7 +4896,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
count_func_merge, count_func_merge,
count_load_data_info, countRequired,
}, },
{ {
// 1 // 1
...@@ -4860,7 +5081,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4860,7 +5081,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
spread_function_finalizer, spread_function_finalizer,
spread_func_merge, spread_func_merge,
count_load_data_info, countRequired,
}, },
{ {
// 14 // 14
...@@ -4902,7 +5123,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4902,7 +5123,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 17 // 17
...@@ -4930,7 +5151,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4930,7 +5151,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 19 // 19
...@@ -4958,7 +5179,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4958,7 +5179,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 21, column project sql function // 21, column project sql function
...@@ -4986,7 +5207,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4986,7 +5207,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 23 // 23
...@@ -5159,7 +5380,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -5159,7 +5380,7 @@ SAggFunctionInfo aAggs[] = {{
}, },
{ {
// 35 // 35
"tid_tag", // return table id and the corresponding tags for join match and subscribe "tbid", // return table id and the corresponding tags for join match and subscribe
TSDB_FUNC_TID_TAG, TSDB_FUNC_TID_TAG,
TSDB_FUNC_TID_TAG, TSDB_FUNC_TID_TAG,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE, TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE,
...@@ -5170,4 +5391,18 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -5170,4 +5391,18 @@ SAggFunctionInfo aAggs[] = {{
noop1, noop1,
noop1, noop1,
dataBlockRequired, dataBlockRequired,
} }; },
{
// 35
"_block_dist", // return table id and the corresponding tags for join match and subscribe
TSDB_FUNC_BLKINFO,
TSDB_FUNC_BLKINFO,
TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STABLE,
function_setup,
blockInfo_func,
noop2,
no_next_step,
blockinfo_func_finalizer,
block_func_merge,
dataBlockRequired,
}};
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -23,18 +23,19 @@ ...@@ -23,18 +23,19 @@
#include "qFill.h" #include "qFill.h"
#include "qExtbuffer.h" #include "qExtbuffer.h"
#include "queryLog.h" #include "queryLog.h"
#include "qExecutor.h"
#define FILL_IS_ASC_FILL(_f) ((_f)->order == TSDB_ORDER_ASC) #define FILL_IS_ASC_FILL(_f) ((_f)->order == TSDB_ORDER_ASC)
#define DO_INTERPOLATION(_v1, _v2, _k1, _k2, _k) ((_v1) + ((_v2) - (_v1)) * (((double)(_k)) - ((double)(_k1))) / (((double)(_k2)) - ((double)(_k1)))) #define DO_INTERPOLATION(_v1, _v2, _k1, _k2, _k) ((_v1) + ((_v2) - (_v1)) * (((double)(_k)) - ((double)(_k1))) / (((double)(_k2)) - ((double)(_k1))))
static void setTagsValue(SFillInfo* pFillInfo, tFilePage** data, int32_t genRows) { static void setTagsValue(SFillInfo* pFillInfo, void** data, int32_t genRows) {
for(int32_t j = 0; j < pFillInfo->numOfCols; ++j) { for(int32_t j = 0; j < pFillInfo->numOfCols; ++j) {
SFillColInfo* pCol = &pFillInfo->pFillCol[j]; SFillColInfo* pCol = &pFillInfo->pFillCol[j];
if (TSDB_COL_IS_NORMAL_COL(pCol->flag)) { if (TSDB_COL_IS_NORMAL_COL(pCol->flag)) {
continue; continue;
} }
char* val1 = elePtrAt(data[j]->data, pCol->col.bytes, genRows); char* val1 = elePtrAt(data[j], pCol->col.bytes, genRows);
assert(pCol->tagIndex >= 0 && pCol->tagIndex < pFillInfo->numOfTags); assert(pCol->tagIndex >= 0 && pCol->tagIndex < pFillInfo->numOfTags);
SFillTagColInfo* pTag = &pFillInfo->pTags[pCol->tagIndex]; SFillTagColInfo* pTag = &pFillInfo->pTags[pCol->tagIndex];
...@@ -44,17 +45,17 @@ static void setTagsValue(SFillInfo* pFillInfo, tFilePage** data, int32_t genRows ...@@ -44,17 +45,17 @@ static void setTagsValue(SFillInfo* pFillInfo, tFilePage** data, int32_t genRows
} }
} }
static void setNullValueForRow(SFillInfo* pFillInfo, tFilePage** data, int32_t numOfCol, int32_t rowIndex) { static void setNullValueForRow(SFillInfo* pFillInfo, void** data, int32_t numOfCol, int32_t rowIndex) {
// the first are always the timestamp column, so start from the second column. // the first are always the timestamp column, so start from the second column.
for (int32_t i = 1; i < numOfCol; ++i) { for (int32_t i = 1; i < numOfCol; ++i) {
SFillColInfo* pCol = &pFillInfo->pFillCol[i]; SFillColInfo* pCol = &pFillInfo->pFillCol[i];
char* output = elePtrAt(data[i]->data, pCol->col.bytes, rowIndex); char* output = elePtrAt(data[i], pCol->col.bytes, rowIndex);
setNull(output, pCol->col.type, pCol->col.bytes); setNull(output, pCol->col.type, pCol->col.bytes);
} }
} }
static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** srcData, int64_t ts, bool outOfBound) { static void doFillOneRowResult(SFillInfo* pFillInfo, void** data, char** srcData, int64_t ts, bool outOfBound) {
char* prev = pFillInfo->prevValues; char* prev = pFillInfo->prevValues;
char* next = pFillInfo->nextValues; char* next = pFillInfo->nextValues;
...@@ -63,7 +64,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr ...@@ -63,7 +64,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr
// set the primary timestamp column value // set the primary timestamp column value
int32_t index = pFillInfo->numOfCurrent; int32_t index = pFillInfo->numOfCurrent;
char* val = elePtrAt(data[0]->data, TSDB_KEYSIZE, index); char* val = elePtrAt(data[0], TSDB_KEYSIZE, index);
*(TSKEY*) val = pFillInfo->currentKey; *(TSKEY*) val = pFillInfo->currentKey;
// set the other values // set the other values
...@@ -77,7 +78,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr ...@@ -77,7 +78,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr
continue; continue;
} }
char* output = elePtrAt(data[i]->data, pCol->col.bytes, index); char* output = elePtrAt(data[i], pCol->col.bytes, index);
assignVal(output, p + pCol->col.offset, pCol->col.bytes, pCol->col.type); assignVal(output, p + pCol->col.offset, pCol->col.bytes, pCol->col.type);
} }
} else { // no prev value yet, set the value for NULL } else { // no prev value yet, set the value for NULL
...@@ -93,7 +94,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr ...@@ -93,7 +94,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr
continue; continue;
} }
char* output = elePtrAt(data[i]->data, pCol->col.bytes, index); char* output = elePtrAt(data[i], pCol->col.bytes, index);
assignVal(output, p + pCol->col.offset, pCol->col.bytes, pCol->col.type); assignVal(output, p + pCol->col.offset, pCol->col.bytes, pCol->col.type);
} }
} else { // no prev value yet, set the value for NULL } else { // no prev value yet, set the value for NULL
...@@ -111,7 +112,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr ...@@ -111,7 +112,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr
int16_t type = pCol->col.type; int16_t type = pCol->col.type;
int16_t bytes = pCol->col.bytes; int16_t bytes = pCol->col.bytes;
char *val1 = elePtrAt(data[i]->data, pCol->col.bytes, index); char *val1 = elePtrAt(data[i], pCol->col.bytes, index);
if (type == TSDB_DATA_TYPE_BINARY|| type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BOOL) { if (type == TSDB_DATA_TYPE_BINARY|| type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BOOL) {
setNull(val1, pCol->col.type, bytes); setNull(val1, pCol->col.type, bytes);
continue; continue;
...@@ -132,7 +133,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr ...@@ -132,7 +133,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, tFilePage** data, char** sr
continue; continue;
} }
char* val1 = elePtrAt(data[i]->data, pCol->col.bytes, index); char* val1 = elePtrAt(data[i], pCol->col.bytes, index);
assignVal(val1, (char*)&pCol->fillVal.i, pCol->col.bytes, pCol->col.type); assignVal(val1, (char*)&pCol->fillVal.i, pCol->col.bytes, pCol->col.type);
} }
} }
...@@ -162,7 +163,7 @@ static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, char** srcData, char* bu ...@@ -162,7 +163,7 @@ static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, char** srcData, char* bu
} }
} }
static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t outputRows) { static int32_t fillResultImpl(SFillInfo* pFillInfo, void** data, int32_t outputRows) {
pFillInfo->numOfCurrent = 0; pFillInfo->numOfCurrent = 0;
char** srcData = pFillInfo->pData; char** srcData = pFillInfo->pData;
...@@ -213,7 +214,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou ...@@ -213,7 +214,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou
continue; continue;
} }
char* output = elePtrAt(data[i]->data, pCol->col.bytes, pFillInfo->numOfCurrent); char* output = elePtrAt(data[i], pCol->col.bytes, pFillInfo->numOfCurrent);
char* src = elePtrAt(srcData[i], pCol->col.bytes, pFillInfo->index); char* src = elePtrAt(srcData[i], pCol->col.bytes, pFillInfo->index);
if (i == 0 || (pCol->functionId != TSDB_FUNC_COUNT && !isNull(src, pCol->col.type)) || if (i == 0 || (pCol->functionId != TSDB_FUNC_COUNT && !isNull(src, pCol->col.type)) ||
...@@ -255,7 +256,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou ...@@ -255,7 +256,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t ou
return pFillInfo->numOfCurrent; return pFillInfo->numOfCurrent;
} }
static int64_t appendFilledResult(SFillInfo* pFillInfo, tFilePage** output, int64_t resultCapacity) { static int64_t appendFilledResult(SFillInfo* pFillInfo, void** output, int64_t resultCapacity) {
/* /*
* These data are generated according to fill strategy, since the current timestamp is out of the time window of * These data are generated according to fill strategy, since the current timestamp is out of the time window of
* real result set. Note that we need to keep the direct previous result rows, to generated the filled data. * real result set. Note that we need to keep the direct previous result rows, to generated the filled data.
...@@ -278,7 +279,7 @@ static int32_t setTagColumnInfo(SFillInfo* pFillInfo, int32_t numOfCols, int32_t ...@@ -278,7 +279,7 @@ static int32_t setTagColumnInfo(SFillInfo* pFillInfo, int32_t numOfCols, int32_t
int32_t k = 0; int32_t k = 0;
for (int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
SFillColInfo* pColInfo = &pFillInfo->pFillCol[i]; SFillColInfo* pColInfo = &pFillInfo->pFillCol[i];
pFillInfo->pData[i] = calloc(1, pColInfo->col.bytes * capacity); pFillInfo->pData[i] = NULL;
if (TSDB_COL_IS_TAG(pColInfo->flag)) { if (TSDB_COL_IS_TAG(pColInfo->flag)) {
bool exists = false; bool exists = false;
...@@ -356,6 +357,10 @@ SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int3 ...@@ -356,6 +357,10 @@ SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int3
pFillInfo->rowSize = setTagColumnInfo(pFillInfo, pFillInfo->numOfCols, pFillInfo->alloc); pFillInfo->rowSize = setTagColumnInfo(pFillInfo, pFillInfo->numOfCols, pFillInfo->alloc);
assert(pFillInfo->rowSize > 0); assert(pFillInfo->rowSize > 0);
for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
pFillInfo->pData[i] = malloc(pFillInfo->pFillCol[i].col.bytes * pFillInfo->alloc);
}
return pFillInfo; return pFillInfo;
} }
...@@ -375,11 +380,16 @@ void* taosDestroyFillInfo(SFillInfo* pFillInfo) { ...@@ -375,11 +380,16 @@ void* taosDestroyFillInfo(SFillInfo* pFillInfo) {
tfree(pFillInfo->prevValues); tfree(pFillInfo->prevValues);
tfree(pFillInfo->nextValues); tfree(pFillInfo->nextValues);
tfree(pFillInfo->pTags);
for(int32_t i = 0; i < pFillInfo->numOfTags; ++i) {
tfree(pFillInfo->pTags[i].tagVal);
}
for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) { for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
tfree(pFillInfo->pData[i]); tfree(pFillInfo->pData[i]);
} }
tfree(pFillInfo->pTags);
tfree(pFillInfo->pData); tfree(pFillInfo->pData);
tfree(pFillInfo->pFillCol); tfree(pFillInfo->pFillCol);
...@@ -413,10 +423,19 @@ void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey) ...@@ -413,10 +423,19 @@ void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey)
} }
} }
// copy the data into source data buffer void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const SSDataBlock* pInput) {
void taosFillSetDataBlockFromFilePage(SFillInfo* pFillInfo, const tFilePage** pInput) {
for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) {
memcpy(pFillInfo->pData[i], pInput[i]->data, pFillInfo->numOfRows * pFillInfo->pFillCol[i].col.bytes); SColumnInfoData* pColData = taosArrayGet(pInput->pDataBlock, i);
// pFillInfo->pData[i] = pColData->pData;
if (pInput->info.rows > pFillInfo->alloc) {
char* t = realloc(pFillInfo->pData[i], pColData->info.bytes * pInput->info.rows);
assert(t != NULL);
pFillInfo->pData[i] = t;
pFillInfo->alloc = pInput->info.rows;
}
memcpy(pFillInfo->pData[i], pColData->pData, pColData->info.bytes * pInput->info.rows);
} }
} }
...@@ -427,12 +446,20 @@ void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, const tFilePage* ...@@ -427,12 +446,20 @@ void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, const tFilePage*
SFillColInfo* pCol = &pFillInfo->pFillCol[i]; SFillColInfo* pCol = &pFillInfo->pFillCol[i];
const char* data = pInput->data + pCol->col.offset * pInput->num; const char* data = pInput->data + pCol->col.offset * pInput->num;
memcpy(pFillInfo->pData[i], data, (size_t)(pInput->num * pCol->col.bytes)); if (pInput->num > pFillInfo->alloc) {
char* t = realloc(pFillInfo->pData[i], (size_t)(pCol->col.bytes * pInput->num));
assert(t != NULL);
pFillInfo->pData[i] = t;
pFillInfo->alloc = (int32_t)pInput->num;
}
memcpy(pFillInfo->pData[i], data, (size_t)(pCol->col.bytes * pInput->num));
if (TSDB_COL_IS_TAG(pCol->flag)) { // copy the tag value to tag value buffer if (TSDB_COL_IS_TAG(pCol->flag)) { // copy the tag value to tag value buffer
SFillTagColInfo* pTag = &pFillInfo->pTags[pCol->tagIndex]; SFillTagColInfo* pTag = &pFillInfo->pTags[pCol->tagIndex];
assert (pTag->col.colId == pCol->col.colId); assert (pTag->col.colId == pCol->col.colId);
memcpy(pTag->tagVal, data, pCol->col.bytes); memcpy(pTag->tagVal, data, pCol->col.bytes); // TODO not memcpy??
} }
} }
} }
...@@ -490,7 +517,7 @@ int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* ...@@ -490,7 +517,7 @@ int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint*
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, tFilePage** output, int32_t capacity) { int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t capacity) {
int32_t remain = taosNumOfRemainRows(pFillInfo); int32_t remain = taosNumOfRemainRows(pFillInfo);
int64_t numOfRes = getNumOfResultsAfterFillGap(pFillInfo, pFillInfo->end, capacity); int64_t numOfRes = getNumOfResultsAfterFillGap(pFillInfo, pFillInfo->end, capacity);
......
...@@ -135,28 +135,33 @@ tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) { ...@@ -135,28 +135,33 @@ tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) {
if (optrType == TK_INTEGER || optrType == TK_STRING || optrType == TK_FLOAT || optrType == TK_BOOL) { if (optrType == TK_INTEGER || optrType == TK_STRING || optrType == TK_FLOAT || optrType == TK_BOOL) {
toTSDBType(pToken->type); toTSDBType(pToken->type);
tVariantCreate(&pSqlExpr->val, pToken); tVariantCreate(&pSqlExpr->value, pToken);
pSqlExpr->nSQLOptr = optrType; pSqlExpr->tokenId = optrType;
pSqlExpr->type = SQL_NODE_VALUE;
} else if (optrType == TK_NOW) { } else if (optrType == TK_NOW) {
// use microsecond by default // use microsecond by default
pSqlExpr->val.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_MICRO); pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_MICRO);
pSqlExpr->val.nType = TSDB_DATA_TYPE_BIGINT; pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pSqlExpr->nSQLOptr = TK_TIMESTAMP; // TK_TIMESTAMP used to denote the time value is in microsecond pSqlExpr->tokenId = TK_TIMESTAMP; // TK_TIMESTAMP used to denote the time value is in microsecond
pSqlExpr->type = SQL_NODE_VALUE;
} else if (optrType == TK_VARIABLE) { } else if (optrType == TK_VARIABLE) {
int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->val.i64); int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR; terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
} }
pSqlExpr->val.nType = TSDB_DATA_TYPE_BIGINT; pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pSqlExpr->nSQLOptr = TK_TIMESTAMP; pSqlExpr->tokenId = TK_TIMESTAMP;
} else { // it must be the column name (tk_id) if it is not the number pSqlExpr->type = SQL_NODE_VALUE;
} else {
// Here it must be the column name (tk_id) if it is not a number or string.
assert(optrType == TK_ID || optrType == TK_ALL); assert(optrType == TK_ID || optrType == TK_ALL);
if (pToken != NULL) { if (pToken != NULL) {
pSqlExpr->colInfo = *pToken; pSqlExpr->colInfo = *pToken;
} }
pSqlExpr->nSQLOptr = optrType; pSqlExpr->tokenId = optrType;
pSqlExpr->type = SQL_NODE_TABLE_COLUMN;
} }
return pSqlExpr; return pSqlExpr;
...@@ -167,19 +172,22 @@ tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) { ...@@ -167,19 +172,22 @@ tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) {
* function name is denoted by pFunctionToken * function name is denoted by pFunctionToken
*/ */
tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType) { tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType) {
if (pFuncToken == NULL) return NULL; if (pFuncToken == NULL) {
return NULL;
}
tSQLExpr *pExpr = calloc(1, sizeof(tSQLExpr)); tSQLExpr *pExpr = calloc(1, sizeof(tSQLExpr));
pExpr->nSQLOptr = optType; pExpr->tokenId = optType;
pExpr->pParam = pList; pExpr->type = SQL_NODE_SQLFUNCTION;
pExpr->pParam = pList;
int32_t len = (int32_t)((endToken->z + endToken->n) - pFuncToken->z); int32_t len = (int32_t)((endToken->z + endToken->n) - pFuncToken->z);
pExpr->operand.z = pFuncToken->z; pExpr->operand = (*pFuncToken);
pExpr->operand.n = len; // raw field name pExpr->token.n = len;
pExpr->operand.type = pFuncToken->type; pExpr->token.z = pFuncToken->z;
pExpr->token.type = pFuncToken->type;
pExpr->token = pExpr->operand;
return pExpr; return pExpr;
} }
...@@ -190,6 +198,7 @@ tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SSt ...@@ -190,6 +198,7 @@ tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SSt
tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) { tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
tSQLExpr *pExpr = calloc(1, sizeof(tSQLExpr)); tSQLExpr *pExpr = calloc(1, sizeof(tSQLExpr));
pExpr->type = SQL_NODE_EXPR;
if (pLeft != NULL && pRight != NULL && (optrType != TK_IN)) { if (pLeft != NULL && pRight != NULL && (optrType != TK_IN)) {
char* endPos = pRight->token.z + pRight->token.n; char* endPos = pRight->token.z + pRight->token.n;
pExpr->token.z = pLeft->token.z; pExpr->token.z = pLeft->token.z;
...@@ -203,32 +212,33 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) { ...@@ -203,32 +212,33 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
* if a token is noted as the TK_TIMESTAMP, the time precision is microsecond * if a token is noted as the TK_TIMESTAMP, the time precision is microsecond
* Otherwise, the time precision is adaptive, determined by the time precision from databases. * Otherwise, the time precision is adaptive, determined by the time precision from databases.
*/ */
if ((pLeft->nSQLOptr == TK_INTEGER && pRight->nSQLOptr == TK_INTEGER) || if ((pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_INTEGER) ||
(pLeft->nSQLOptr == TK_TIMESTAMP && pRight->nSQLOptr == TK_TIMESTAMP)) { (pLeft->tokenId == TK_TIMESTAMP && pRight->tokenId == TK_TIMESTAMP)) {
pExpr->val.nType = TSDB_DATA_TYPE_BIGINT; pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pExpr->nSQLOptr = pLeft->nSQLOptr; pExpr->tokenId = pLeft->tokenId;
pExpr->type = SQL_NODE_VALUE;
switch (optrType) { switch (optrType) {
case TK_PLUS: { case TK_PLUS: {
pExpr->val.i64 = pLeft->val.i64 + pRight->val.i64; pExpr->value.i64 = pLeft->value.i64 + pRight->value.i64;
break; break;
} }
case TK_MINUS: { case TK_MINUS: {
pExpr->val.i64 = pLeft->val.i64 - pRight->val.i64; pExpr->value.i64 = pLeft->value.i64 - pRight->value.i64;
break; break;
} }
case TK_STAR: { case TK_STAR: {
pExpr->val.i64 = pLeft->val.i64 * pRight->val.i64; pExpr->value.i64 = pLeft->value.i64 * pRight->value.i64;
break; break;
} }
case TK_DIVIDE: { case TK_DIVIDE: {
pExpr->nSQLOptr = TK_FLOAT; pExpr->tokenId = TK_FLOAT;
pExpr->val.nType = TSDB_DATA_TYPE_DOUBLE; pExpr->value.nType = TSDB_DATA_TYPE_DOUBLE;
pExpr->val.dKey = (double)pLeft->val.i64 / pRight->val.i64; pExpr->value.dKey = (double)pLeft->value.i64 / pRight->value.i64;
break; break;
} }
case TK_REM: { case TK_REM: {
pExpr->val.i64 = pLeft->val.i64 % pRight->val.i64; pExpr->value.i64 = pLeft->value.i64 % pRight->value.i64;
break; break;
} }
} }
...@@ -236,33 +246,35 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) { ...@@ -236,33 +246,35 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
tSqlExprDestroy(pLeft); tSqlExprDestroy(pLeft);
tSqlExprDestroy(pRight); tSqlExprDestroy(pRight);
} else if ((pLeft->nSQLOptr == TK_FLOAT && pRight->nSQLOptr == TK_INTEGER) || (pLeft->nSQLOptr == TK_INTEGER && pRight->nSQLOptr == TK_FLOAT) || } else if ((pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_INTEGER) ||
(pLeft->nSQLOptr == TK_FLOAT && pRight->nSQLOptr == TK_FLOAT)) { (pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_FLOAT) ||
pExpr->val.nType = TSDB_DATA_TYPE_DOUBLE; (pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_FLOAT)) {
pExpr->nSQLOptr = TK_FLOAT; pExpr->value.nType = TSDB_DATA_TYPE_DOUBLE;
pExpr->tokenId = TK_FLOAT;
pExpr->type = SQL_NODE_VALUE;
double left = (pLeft->val.nType == TSDB_DATA_TYPE_DOUBLE) ? pLeft->val.dKey : pLeft->val.i64; double left = (pLeft->value.nType == TSDB_DATA_TYPE_DOUBLE) ? pLeft->value.dKey : pLeft->value.i64;
double right = (pRight->val.nType == TSDB_DATA_TYPE_DOUBLE) ? pRight->val.dKey : pRight->val.i64; double right = (pRight->value.nType == TSDB_DATA_TYPE_DOUBLE) ? pRight->value.dKey : pRight->value.i64;
switch (optrType) { switch (optrType) {
case TK_PLUS: { case TK_PLUS: {
pExpr->val.dKey = left + right; pExpr->value.dKey = left + right;
break; break;
} }
case TK_MINUS: { case TK_MINUS: {
pExpr->val.dKey = left - right; pExpr->value.dKey = left - right;
break; break;
} }
case TK_STAR: { case TK_STAR: {
pExpr->val.dKey = left * right; pExpr->value.dKey = left * right;
break; break;
} }
case TK_DIVIDE: { case TK_DIVIDE: {
pExpr->val.dKey = left / right; pExpr->value.dKey = left / right;
break; break;
} }
case TK_REM: { case TK_REM: {
pExpr->val.dKey = left - ((int64_t)(left / right)) * right; pExpr->value.dKey = left - ((int64_t)(left / right)) * right;
break; break;
} }
} }
...@@ -271,21 +283,21 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) { ...@@ -271,21 +283,21 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
tSqlExprDestroy(pRight); tSqlExprDestroy(pRight);
} else { } else {
pExpr->nSQLOptr = optrType; pExpr->tokenId = optrType;
pExpr->pLeft = pLeft; pExpr->pLeft = pLeft;
pExpr->pRight = pRight; pExpr->pRight = pRight;
} }
} else if (optrType == TK_IN) { } else if (optrType == TK_IN) {
pExpr->nSQLOptr = optrType; pExpr->tokenId = optrType;
pExpr->pLeft = pLeft; pExpr->pLeft = pLeft;
tSQLExpr *pRSub = calloc(1, sizeof(tSQLExpr)); tSQLExpr *pRSub = calloc(1, sizeof(tSQLExpr));
pRSub->nSQLOptr = TK_SET; // TODO refactor ..... pRSub->tokenId = TK_SET; // TODO refactor .....
pRSub->pParam = (tSQLExprList *)pRight; pRSub->pParam = (tSQLExprList *)pRight;
pExpr->pRight = pRSub; pExpr->pRight = pRSub;
} else { } else {
pExpr->nSQLOptr = optrType; pExpr->tokenId = optrType;
pExpr->pLeft = pLeft; pExpr->pLeft = pLeft;
if (pLeft != NULL && pRight == NULL) { if (pLeft != NULL && pRight == NULL) {
...@@ -325,8 +337,8 @@ void tSqlExprNodeDestroy(tSQLExpr *pExpr) { ...@@ -325,8 +337,8 @@ void tSqlExprNodeDestroy(tSQLExpr *pExpr) {
return; return;
} }
if (pExpr->nSQLOptr == TK_STRING) { if (pExpr->tokenId == TK_STRING) {
tVariantDestroy(&pExpr->val); tVariantDestroy(&pExpr->value);
} }
tSqlExprListDestroy(pExpr->pParam); tSqlExprListDestroy(pExpr->pParam);
......
...@@ -254,7 +254,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, ...@@ -254,7 +254,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval,
resetSlotInfo(pBucket); resetSlotInfo(pBucket);
int32_t ret = createDiskbasedResultBuffer(&pBucket->pBuffer, pBucket->bytes, pBucket->bufPageSize, pBucket->bufPageSize * 512, NULL); int32_t ret = createDiskbasedResultBuffer(&pBucket->pBuffer, pBucket->bufPageSize, pBucket->bufPageSize * 512, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tMemBucketDestroy(pBucket); tMemBucketDestroy(pBucket);
return NULL; return NULL;
......
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
#define GET_DATA_PAYLOAD(_p) ((char *)(_p)->pData + POINTER_BYTES) #define GET_DATA_PAYLOAD(_p) ((char *)(_p)->pData + POINTER_BYTES)
#define NO_IN_MEM_AVAILABLE_PAGES(_b) (listNEles((_b)->lruList) >= (_b)->inMemPages) #define NO_IN_MEM_AVAILABLE_PAGES(_b) (listNEles((_b)->lruList) >= (_b)->inMemPages)
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t rowSize, int32_t pagesize, int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t pagesize, int32_t inMemBufSize, const void* handle) {
int32_t inMemBufSize, const void* handle) {
*pResultBuf = calloc(1, sizeof(SDiskbasedResultBuf)); *pResultBuf = calloc(1, sizeof(SDiskbasedResultBuf));
SDiskbasedResultBuf* pResBuf = *pResultBuf; SDiskbasedResultBuf* pResBuf = *pResultBuf;
...@@ -31,7 +30,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro ...@@ -31,7 +30,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro
// at least more than 2 pages must be in memory // at least more than 2 pages must be in memory
assert(inMemBufSize >= pagesize * 2); assert(inMemBufSize >= pagesize * 2);
pResBuf->numOfRowsPerPage = (pagesize - sizeof(tFilePage)) / rowSize;
pResBuf->lruList = tdListNew(POINTER_BYTES); pResBuf->lruList = tdListNew(POINTER_BYTES);
// init id hash table // init id hash table
...@@ -387,8 +385,6 @@ void releaseResBufPageInfo(SDiskbasedResultBuf* pResultBuf, SPageInfo* pi) { ...@@ -387,8 +385,6 @@ void releaseResBufPageInfo(SDiskbasedResultBuf* pResultBuf, SPageInfo* pi) {
pResultBuf->statis.releasePages += 1; pResultBuf->statis.releasePages += 1;
} }
size_t getNumOfRowsPerPage(const SDiskbasedResultBuf* pResultBuf) { return pResultBuf->numOfRowsPerPage; }
size_t getNumOfResultBufGroupId(const SDiskbasedResultBuf* pResultBuf) { return taosHashGetSize(pResultBuf->groupSet); } size_t getNumOfResultBufGroupId(const SDiskbasedResultBuf* pResultBuf) { return taosHashGetSize(pResultBuf->groupSet); }
size_t getResBufSize(const SDiskbasedResultBuf* pResultBuf) { return (size_t)pResultBuf->totalBufSize; } size_t getResBufSize(const SDiskbasedResultBuf* pResultBuf) { return (size_t)pResultBuf->totalBufSize; }
......
...@@ -200,25 +200,6 @@ static SKeyword keywordTable[] = { ...@@ -200,25 +200,6 @@ static SKeyword keywordTable[] = {
{"TRIGGER", TK_TRIGGER}, {"TRIGGER", TK_TRIGGER},
{"VIEW", TK_VIEW}, {"VIEW", TK_VIEW},
{"ALL", TK_ALL}, {"ALL", TK_ALL},
{"COUNT", TK_COUNT},
{"SUM", TK_SUM},
{"AVG", TK_AVG},
{"MIN", TK_MIN},
{"MAX", TK_MAX},
{"FIRST", TK_FIRST},
{"LAST", TK_LAST},
{"TOP", TK_TOP},
{"BOTTOM", TK_BOTTOM},
{"STDDEV", TK_STDDEV},
{"PERCENTILE", TK_PERCENTILE},
{"APERCENTILE", TK_APERCENTILE},
{"LEASTSQUARES", TK_LEASTSQUARES},
{"HISTOGRAM", TK_HISTOGRAM},
{"DIFF", TK_DIFF},
{"SPREAD", TK_SPREAD},
{"TWA", TK_TWA},
{"INTERP", TK_INTERP},
{"LAST_ROW", TK_LAST_ROW},
{"SEMI", TK_SEMI}, {"SEMI", TK_SEMI},
{"NONE", TK_NONE}, {"NONE", TK_NONE},
{"PREV", TK_PREV}, {"PREV", TK_PREV},
...@@ -228,17 +209,10 @@ static SKeyword keywordTable[] = { ...@@ -228,17 +209,10 @@ static SKeyword keywordTable[] = {
{"TBNAME", TK_TBNAME}, {"TBNAME", TK_TBNAME},
{"JOIN", TK_JOIN}, {"JOIN", TK_JOIN},
{"METRICS", TK_METRICS}, {"METRICS", TK_METRICS},
{"TBID", TK_TBID},
{"STABLE", TK_STABLE}, {"STABLE", TK_STABLE},
{"FILE", TK_FILE}, {"FILE", TK_FILE},
{"VNODES", TK_VNODES}, {"VNODES", TK_VNODES},
{"UNION", TK_UNION}, {"UNION", TK_UNION},
{"RATE", TK_RATE},
{"IRATE", TK_IRATE},
{"SUM_RATE", TK_SUM_RATE},
{"SUM_IRATE", TK_SUM_IRATE},
{"AVG_RATE", TK_AVG_RATE},
{"AVG_IRATE", TK_AVG_IRATE},
{"CACHELAST", TK_CACHELAST}, {"CACHELAST", TK_CACHELAST},
{"DISTINCT", TK_DISTINCT}, {"DISTINCT", TK_DISTINCT},
{"PARTITIONS", TK_PARTITIONS}, {"PARTITIONS", TK_PARTITIONS},
...@@ -297,7 +271,7 @@ int tSQLKeywordCode(const char* z, int n) { ...@@ -297,7 +271,7 @@ int tSQLKeywordCode(const char* z, int n) {
* Return the length of the token that begins at z[0]. * Return the length of the token that begins at z[0].
* Store the token type in *type before returning. * Store the token type in *type before returning.
*/ */
uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { uint32_t tSQLGetToken(char* z, uint32_t* tokenId) {
uint32_t i; uint32_t i;
switch (*z) { switch (*z) {
case ' ': case ' ':
...@@ -307,121 +281,121 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -307,121 +281,121 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
case '\r': { case '\r': {
for (i = 1; isspace(z[i]); i++) { for (i = 1; isspace(z[i]); i++) {
} }
*tokenType = TK_SPACE; *tokenId = TK_SPACE;
return i; return i;
} }
case ':': { case ':': {
*tokenType = TK_COLON; *tokenId = TK_COLON;
return 1; return 1;
} }
case '-': { case '-': {
if (z[1] == '-') { if (z[1] == '-') {
for (i = 2; z[i] && z[i] != '\n'; i++) { for (i = 2; z[i] && z[i] != '\n'; i++) {
} }
*tokenType = TK_COMMENT; *tokenId = TK_COMMENT;
return i; return i;
} }
*tokenType = TK_MINUS; *tokenId = TK_MINUS;
return 1; return 1;
} }
case '(': { case '(': {
*tokenType = TK_LP; *tokenId = TK_LP;
return 1; return 1;
} }
case ')': { case ')': {
*tokenType = TK_RP; *tokenId = TK_RP;
return 1; return 1;
} }
case ';': { case ';': {
*tokenType = TK_SEMI; *tokenId = TK_SEMI;
return 1; return 1;
} }
case '+': { case '+': {
*tokenType = TK_PLUS; *tokenId = TK_PLUS;
return 1; return 1;
} }
case '*': { case '*': {
*tokenType = TK_STAR; *tokenId = TK_STAR;
return 1; return 1;
} }
case '/': { case '/': {
if (z[1] != '*' || z[2] == 0) { if (z[1] != '*' || z[2] == 0) {
*tokenType = TK_SLASH; *tokenId = TK_SLASH;
return 1; return 1;
} }
for (i = 3; z[i] && (z[i] != '/' || z[i - 1] != '*'); i++) { for (i = 3; z[i] && (z[i] != '/' || z[i - 1] != '*'); i++) {
} }
if (z[i]) i++; if (z[i]) i++;
*tokenType = TK_COMMENT; *tokenId = TK_COMMENT;
return i; return i;
} }
case '%': { case '%': {
*tokenType = TK_REM; *tokenId = TK_REM;
return 1; return 1;
} }
case '=': { case '=': {
*tokenType = TK_EQ; *tokenId = TK_EQ;
return 1 + (z[1] == '='); return 1 + (z[1] == '=');
} }
case '<': { case '<': {
if (z[1] == '=') { if (z[1] == '=') {
*tokenType = TK_LE; *tokenId = TK_LE;
return 2; return 2;
} else if (z[1] == '>') { } else if (z[1] == '>') {
*tokenType = TK_NE; *tokenId = TK_NE;
return 2; return 2;
} else if (z[1] == '<') { } else if (z[1] == '<') {
*tokenType = TK_LSHIFT; *tokenId = TK_LSHIFT;
return 2; return 2;
} else { } else {
*tokenType = TK_LT; *tokenId = TK_LT;
return 1; return 1;
} }
} }
case '>': { case '>': {
if (z[1] == '=') { if (z[1] == '=') {
*tokenType = TK_GE; *tokenId = TK_GE;
return 2; return 2;
} else if (z[1] == '>') { } else if (z[1] == '>') {
*tokenType = TK_RSHIFT; *tokenId = TK_RSHIFT;
return 2; return 2;
} else { } else {
*tokenType = TK_GT; *tokenId = TK_GT;
return 1; return 1;
} }
} }
case '!': { case '!': {
if (z[1] != '=') { if (z[1] != '=') {
*tokenType = TK_ILLEGAL; *tokenId = TK_ILLEGAL;
return 2; return 2;
} else { } else {
*tokenType = TK_NE; *tokenId = TK_NE;
return 2; return 2;
} }
} }
case '|': { case '|': {
if (z[1] != '|') { if (z[1] != '|') {
*tokenType = TK_BITOR; *tokenId = TK_BITOR;
return 1; return 1;
} else { } else {
*tokenType = TK_CONCAT; *tokenId = TK_CONCAT;
return 2; return 2;
} }
} }
case ',': { case ',': {
*tokenType = TK_COMMA; *tokenId = TK_COMMA;
return 1; return 1;
} }
case '&': { case '&': {
*tokenType = TK_BITAND; *tokenId = TK_BITAND;
return 1; return 1;
} }
case '~': { case '~': {
*tokenType = TK_BITNOT; *tokenId = TK_BITNOT;
return 1; return 1;
} }
case '?': { case '?': {
*tokenType = TK_QUESTION; *tokenId = TK_QUESTION;
return 1; return 1;
} }
case '\'': case '\'':
...@@ -447,7 +421,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -447,7 +421,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
if (z[i]) i++; if (z[i]) i++;
if (strEnd) { if (strEnd) {
*tokenType = TK_STRING; *tokenId = TK_STRING;
return i; return i;
} }
...@@ -471,10 +445,10 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -471,10 +445,10 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
} }
} }
*tokenType = TK_FLOAT; *tokenId = TK_FLOAT;
return i; return i;
} else { } else {
*tokenType = TK_DOT; *tokenId = TK_DOT;
return 1; return 1;
} }
} }
...@@ -483,7 +457,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -483,7 +457,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
char next = z[1]; char next = z[1];
if (next == 'b') { // bin number if (next == 'b') { // bin number
*tokenType = TK_BIN; *tokenId = TK_BIN;
for (i = 2; (z[i] == '0' || z[i] == '1'); ++i) { for (i = 2; (z[i] == '0' || z[i] == '1'); ++i) {
} }
...@@ -493,7 +467,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -493,7 +467,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
return i; return i;
} else if (next == 'x') { //hex number } else if (next == 'x') { //hex number
*tokenType = TK_HEX; *tokenId = TK_HEX;
for (i = 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) { for (i = 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) {
} }
...@@ -513,7 +487,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -513,7 +487,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
case '7': case '7':
case '8': case '8':
case '9': { case '9': {
*tokenType = TK_INTEGER; *tokenId = TK_INTEGER;
for (i = 1; isdigit(z[i]); i++) { for (i = 1; isdigit(z[i]); i++) {
} }
...@@ -523,7 +497,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -523,7 +497,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' ||
z[i] == 'Y' || z[i] == 'W') && z[i] == 'Y' || z[i] == 'W') &&
(isIdChar[(uint8_t)z[i + 1]] == 0)) { (isIdChar[(uint8_t)z[i + 1]] == 0)) {
*tokenType = TK_VARIABLE; *tokenId = TK_VARIABLE;
i += 1; i += 1;
return i; return i;
} }
...@@ -534,12 +508,12 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -534,12 +508,12 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
while (isdigit(z[i])) { while (isdigit(z[i])) {
i++; i++;
} }
*tokenType = TK_FLOAT; *tokenId = TK_FLOAT;
seg++; seg++;
} }
if (seg == 4) { // ip address if (seg == 4) { // ip address
*tokenType = TK_IPTOKEN; *tokenId = TK_IPTOKEN;
return i; return i;
} }
...@@ -549,14 +523,14 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -549,14 +523,14 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
while (isdigit(z[i])) { while (isdigit(z[i])) {
i++; i++;
} }
*tokenType = TK_FLOAT; *tokenId = TK_FLOAT;
} }
return i; return i;
} }
case '[': { case '[': {
for (i = 1; z[i] && z[i - 1] != ']'; i++) { for (i = 1; z[i] && z[i - 1] != ']'; i++) {
} }
*tokenType = TK_ID; *tokenId = TK_ID;
return i; return i;
} }
case 'T': case 'T':
...@@ -567,7 +541,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -567,7 +541,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
} }
if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) { if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) {
*tokenType = TK_BOOL; *tokenId = TK_BOOL;
return i; return i;
} }
} }
...@@ -577,12 +551,12 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { ...@@ -577,12 +551,12 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
} }
for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) { for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) {
} }
*tokenType = tSQLKeywordCode(z, i); *tokenId = tSQLKeywordCode(z, i);
return i; return i;
} }
} }
*tokenType = TK_ILLEGAL; *tokenId = TK_ILLEGAL;
return 0; return 0;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "tbuffer.h" #include "tbuffer.h"
#include "tlosertree.h" #include "tlosertree.h"
#include "queryLog.h" #include "queryLog.h"
#include "tscompression.h"
typedef struct SCompSupporter { typedef struct SCompSupporter {
STableQueryInfo **pTableQueryInfo; STableQueryInfo **pTableQueryInfo;
...@@ -135,20 +136,22 @@ void clearResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16 ...@@ -135,20 +136,22 @@ void clearResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16
if (pResultRow->pageId >= 0) { if (pResultRow->pageId >= 0) {
tFilePage *page = getResBufPage(pRuntimeEnv->pResultBuf, pResultRow->pageId); tFilePage *page = getResBufPage(pRuntimeEnv->pResultBuf, pResultRow->pageId);
int16_t offset = 0;
for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfOutput; ++i) { for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfOutput; ++i) {
SResultRowCellInfo *pResultInfo = &pResultRow->pCellInfo[i]; SResultRowCellInfo *pResultInfo = &pResultRow->pCellInfo[i];
char * s = getPosInResultPage(pRuntimeEnv, i, pResultRow, page); int16_t size = pRuntimeEnv->pQuery->pExpr1[i].bytes;
size_t size = pRuntimeEnv->pQuery->pExpr1[i].bytes; char * s = getPosInResultPage(pRuntimeEnv->pQuery, page, pResultRow->offset, offset);
memset(s, 0, size); memset(s, 0, size);
offset += size;
RESET_RESULT_INFO(pResultInfo); RESET_RESULT_INFO(pResultInfo);
} }
} }
pResultRow->numOfRows = 0; pResultRow->numOfRows = 0;
pResultRow->pageId = -1; pResultRow->pageId = -1;
pResultRow->rowId = -1; pResultRow->offset = -1;
pResultRow->closed = false; pResultRow->closed = false;
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
...@@ -158,13 +161,15 @@ void clearResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16 ...@@ -158,13 +161,15 @@ void clearResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResultRow, int16
} }
} }
SResultRowCellInfo* getResultCell(SQueryRuntimeEnv* pRuntimeEnv, const SResultRow* pRow, int32_t index) { // TODO refactor: use macro
assert(index >= 0 && index < pRuntimeEnv->pQuery->numOfOutput); SResultRowCellInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t* offset) {
return (SResultRowCellInfo*)((char*) pRow->pCellInfo + pRuntimeEnv->rowCellInfoOffset[index]); assert(index >= 0 && offset != NULL);
return (SResultRowCellInfo*)((char*) pRow->pCellInfo + offset[index]);
} }
size_t getResultRowSize(SQueryRuntimeEnv* pRuntimeEnv) { size_t getResultRowSize(SQueryRuntimeEnv* pRuntimeEnv) {
return (pRuntimeEnv->pQuery->numOfOutput * sizeof(SResultRowCellInfo)) + pRuntimeEnv->interBufSize + sizeof(SResultRow); SQuery* pQuery = pRuntimeEnv->pQuery;
return (pQuery->numOfOutput * sizeof(SResultRowCellInfo)) + pQuery->interBufSize + sizeof(SResultRow);
} }
SResultRowPool* initResultRowPool(size_t size) { SResultRowPool* initResultRowPool(size_t size) {
...@@ -340,18 +345,18 @@ void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) { ...@@ -340,18 +345,18 @@ void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) {
pGroupResInfo->index = 0; pGroupResInfo->index = 0;
} }
void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo, int32_t offset) { void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo) {
if (pGroupResInfo->pRows != NULL) { if (pGroupResInfo->pRows != NULL) {
taosArrayDestroy(pGroupResInfo->pRows); taosArrayDestroy(pGroupResInfo->pRows);
} }
pGroupResInfo->pRows = taosArrayFromList(pResultInfo->pResult, pResultInfo->size, POINTER_BYTES); pGroupResInfo->pRows = taosArrayFromList(pResultInfo->pResult, pResultInfo->size, POINTER_BYTES);
pGroupResInfo->index = offset; pGroupResInfo->index = 0;
assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo)); assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
} }
bool hasRemainData(SGroupResInfo* pGroupResInfo) { bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo) {
if (pGroupResInfo->pRows == NULL) { if (pGroupResInfo->pRows == NULL) {
return false; return false;
} }
...@@ -359,6 +364,14 @@ bool hasRemainData(SGroupResInfo* pGroupResInfo) { ...@@ -359,6 +364,14 @@ bool hasRemainData(SGroupResInfo* pGroupResInfo) {
return pGroupResInfo->index < taosArrayGetSize(pGroupResInfo->pRows); return pGroupResInfo->index < taosArrayGetSize(pGroupResInfo->pRows);
} }
bool hasRemainData(SGroupResInfo* pGroupResInfo) {
if (hasRemainDataInCurrentGroup(pGroupResInfo)) {
return true;
}
return pGroupResInfo->currentGroup < pGroupResInfo->totalGroup;
}
bool incNextGroup(SGroupResInfo* pGroupResInfo) { bool incNextGroup(SGroupResInfo* pGroupResInfo) {
return (++pGroupResInfo->currentGroup) < pGroupResInfo->totalGroup; return (++pGroupResInfo->currentGroup) < pGroupResInfo->totalGroup;
} }
...@@ -372,7 +385,7 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) { ...@@ -372,7 +385,7 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) {
return (int32_t) taosArrayGetSize(pGroupResInfo->pRows); return (int32_t) taosArrayGetSize(pGroupResInfo->pRows);
} }
static int64_t getNumOfResultWindowRes(SQueryRuntimeEnv* pRuntimeEnv, SResultRow *pResultRow) { static int64_t getNumOfResultWindowRes(SQueryRuntimeEnv* pRuntimeEnv, SResultRow *pResultRow, int32_t* rowCellInfoOffset) {
SQuery* pQuery = pRuntimeEnv->pQuery; SQuery* pQuery = pRuntimeEnv->pQuery;
for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { for (int32_t j = 0; j < pQuery->numOfOutput; ++j) {
...@@ -386,7 +399,7 @@ static int64_t getNumOfResultWindowRes(SQueryRuntimeEnv* pRuntimeEnv, SResultRow ...@@ -386,7 +399,7 @@ static int64_t getNumOfResultWindowRes(SQueryRuntimeEnv* pRuntimeEnv, SResultRow
continue; continue;
} }
SResultRowCellInfo *pResultInfo = getResultCell(pRuntimeEnv, pResultRow, j); SResultRowCellInfo *pResultInfo = getResultCell(pResultRow, j, rowCellInfoOffset);
assert(pResultInfo != NULL); assert(pResultInfo != NULL);
if (pResultInfo->numOfRes > 0) { if (pResultInfo->numOfRes > 0) {
...@@ -437,7 +450,8 @@ static int32_t tableResultComparFn(const void *pLeft, const void *pRight, void * ...@@ -437,7 +450,8 @@ static int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *
} }
} }
static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupResInfo* pGroupResInfo, SArray *pTableList, void* qinfo) { static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupResInfo* pGroupResInfo, SArray *pTableList,
int32_t* rowCellInfoOffset) {
bool ascQuery = QUERY_IS_ASC_QUERY(pRuntimeEnv->pQuery); bool ascQuery = QUERY_IS_ASC_QUERY(pRuntimeEnv->pQuery);
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
...@@ -455,7 +469,7 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes ...@@ -455,7 +469,7 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes
pTableQueryInfoList = malloc(POINTER_BYTES * size); pTableQueryInfoList = malloc(POINTER_BYTES * size);
if (pTableQueryInfoList == NULL || posList == NULL || pGroupResInfo->pRows == NULL || pGroupResInfo->pRows == NULL) { if (pTableQueryInfoList == NULL || posList == NULL || pGroupResInfo->pRows == NULL || pGroupResInfo->pRows == NULL) {
qError("QInfo:%p failed alloc memory", qinfo); qError("QInfo:%p failed alloc memory", pRuntimeEnv->qinfo);
code = TSDB_CODE_QRY_OUT_OF_MEMORY; code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _end; goto _end;
} }
...@@ -491,7 +505,7 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes ...@@ -491,7 +505,7 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes
SResultRowInfo *pWindowResInfo = &pTableQueryInfoList[tableIndex]->resInfo; SResultRowInfo *pWindowResInfo = &pTableQueryInfoList[tableIndex]->resInfo;
SResultRow *pWindowRes = getResultRow(pWindowResInfo, cs.rowIndex[tableIndex]); SResultRow *pWindowRes = getResultRow(pWindowResInfo, cs.rowIndex[tableIndex]);
int64_t num = getNumOfResultWindowRes(pRuntimeEnv, pWindowRes); int64_t num = getNumOfResultWindowRes(pRuntimeEnv, pWindowRes, rowCellInfoOffset);
if (num <= 0) { if (num <= 0) {
cs.rowIndex[tableIndex] += 1; cs.rowIndex[tableIndex] += 1;
...@@ -527,7 +541,7 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes ...@@ -527,7 +541,7 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes
int64_t endt = taosGetTimestampMs(); int64_t endt = taosGetTimestampMs();
qDebug("QInfo:%p result merge completed for group:%d, elapsed time:%" PRId64 " ms", qinfo, qDebug("QInfo:%p result merge completed for group:%d, elapsed time:%" PRId64 " ms", pRuntimeEnv->qinfo,
pGroupResInfo->currentGroup, endt - startt); pGroupResInfo->currentGroup, endt - startt);
_end: _end:
...@@ -538,13 +552,13 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes ...@@ -538,13 +552,13 @@ static int32_t mergeIntoGroupResultImpl(SQueryRuntimeEnv *pRuntimeEnv, SGroupRes
return code; return code;
} }
int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQInfo *pQInfo) { int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQueryRuntimeEnv* pRuntimeEnv, int32_t* offset) {
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
while (pGroupResInfo->currentGroup < pGroupResInfo->totalGroup) { while (pGroupResInfo->currentGroup < pGroupResInfo->totalGroup) {
SArray *group = GET_TABLEGROUP(pQInfo, pGroupResInfo->currentGroup); SArray *group = GET_TABLEGROUP(pRuntimeEnv, pGroupResInfo->currentGroup);
int32_t ret = mergeIntoGroupResultImpl(&pQInfo->runtimeEnv, pGroupResInfo, group, pQInfo); int32_t ret = mergeIntoGroupResultImpl(pRuntimeEnv, pGroupResInfo, group, offset);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
...@@ -554,19 +568,83 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQInfo *pQInfo) { ...@@ -554,19 +568,83 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, SQInfo *pQInfo) {
break; break;
} }
qDebug("QInfo:%p no result in group %d, continue", pQInfo, pGroupResInfo->currentGroup); qDebug("QInfo:%p no result in group %d, continue", pRuntimeEnv->qinfo, pGroupResInfo->currentGroup);
cleanupGroupResInfo(pGroupResInfo); cleanupGroupResInfo(pGroupResInfo);
incNextGroup(pGroupResInfo); incNextGroup(pGroupResInfo);
} }
if (pGroupResInfo->currentGroup >= pGroupResInfo->totalGroup && !hasRemainData(pGroupResInfo)) {
SET_STABLE_QUERY_OVER(pQInfo);
}
int64_t elapsedTime = taosGetTimestampUs() - st; int64_t elapsedTime = taosGetTimestampUs() - st;
qDebug("QInfo:%p merge res data into group, index:%d, total group:%d, elapsed time:%" PRId64 "us", pQInfo, qDebug("QInfo:%p merge res data into group, index:%d, total group:%d, elapsed time:%" PRId64 "us", pRuntimeEnv->qinfo,
pGroupResInfo->currentGroup, pGroupResInfo->totalGroup, elapsedTime); pGroupResInfo->currentGroup, pGroupResInfo->totalGroup, elapsedTime);
pQInfo->runtimeEnv.summary.firstStageMergeTime += elapsedTime; // pQInfo->summary.firstStageMergeTime += elapsedTime;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void blockDistInfoToBinary(STableBlockDist* pDist, struct SBufferWriter* bw) {
tbufWriteUint32(bw, pDist->numOfTables);
tbufWriteUint16(bw, pDist->numOfFiles);
tbufWriteUint64(bw, pDist->totalSize);
tbufWriteUint32(bw, pDist->numOfRowsInMemTable);
tbufWriteUint64(bw, taosArrayGetSize(pDist->dataBlockInfos));
// compress the binary string
char* p = TARRAY_GET_START(pDist->dataBlockInfos);
// compress extra bytes
size_t x = taosArrayGetSize(pDist->dataBlockInfos) * pDist->dataBlockInfos->elemSize;
char* tmp = malloc(x + 2);
bool comp = false;
int32_t len = tsCompressString(p, (int32_t)x, 1, tmp, (int32_t)x, ONE_STAGE_COMP, NULL, 0);
if (len == -1 || len >= x) { // compress failed, do not compress this binary data
comp = false;
len = (int32_t)x;
} else {
comp = true;
}
tbufWriteUint8(bw, comp);
tbufWriteUint32(bw, len);
if (comp) {
tbufWriteBinary(bw, tmp, len);
} else {
tbufWriteBinary(bw, p, len);
}
tfree(tmp);
}
void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDist* pDist) {
SBufferReader br = tbufInitReader(data, len, false);
pDist->numOfTables = tbufReadUint32(&br);
pDist->numOfFiles = tbufReadUint16(&br);
pDist->totalSize = tbufReadUint64(&br);
pDist->numOfRowsInMemTable = tbufReadUint32(&br);
int64_t numOfBlocks = tbufReadUint64(&br);
bool comp = tbufReadUint8(&br);
uint32_t compLen = tbufReadUint32(&br);
size_t originalLen = (size_t) (numOfBlocks*sizeof(SFileBlockInfo));
char* outputBuf = NULL;
if (comp) {
outputBuf = malloc(originalLen);
size_t actualLen = compLen;
const char* compStr = tbufReadBinary(&br, &actualLen);
int32_t orignalLen = tsDecompressString(compStr, compLen, 1, outputBuf,
(int32_t)originalLen , ONE_STAGE_COMP, NULL, 0);
assert(orignalLen == numOfBlocks*sizeof(SFileBlockInfo));
} else {
outputBuf = (char*) tbufReadBinary(&br, &originalLen);
}
pDist->dataBlockInfos = taosArrayFromList(outputBuf, (uint32_t) numOfBlocks, sizeof(SFileBlockInfo));
if (comp) {
tfree(outputBuf);
}
}
...@@ -96,7 +96,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi ...@@ -96,7 +96,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
} }
if (param.pSecExprMsg != NULL) { if (param.pSecExprMsg != NULL) {
if ((code = createQueryFuncExprFromMsg(pQueryMsg, pQueryMsg->secondStageOutput, &param.pSecExprs, param.pSecExprMsg, param.pTagColumnInfo)) != TSDB_CODE_SUCCESS) { if ((code = createIndirectQueryFuncExprFromMsg(pQueryMsg, pQueryMsg->secondStageOutput, &param.pSecExprs, param.pSecExprMsg, param.pExprs)) != TSDB_CODE_SUCCESS) {
goto _over; goto _over;
} }
} }
...@@ -144,11 +144,11 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi ...@@ -144,11 +144,11 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
goto _over; goto _over;
} }
qDebug("qmsg:%p query on %" PRIzu " tables in one group from client", pQueryMsg, tableGroupInfo.numOfTables); qDebug("qmsg:%p query on %u tables in one group from client", pQueryMsg, tableGroupInfo.numOfTables);
} }
int64_t el = taosGetTimestampUs() - st; int64_t el = taosGetTimestampUs() - st;
qDebug("qmsg:%p tag filter completed, numOfTables:%" PRIzu ", elapsed time:%"PRId64"us", pQueryMsg, tableGroupInfo.numOfTables, el); qDebug("qmsg:%p tag filter completed, numOfTables:%u, elapsed time:%"PRId64"us", pQueryMsg, tableGroupInfo.numOfTables, el);
} else { } else {
assert(0); assert(0);
} }
...@@ -209,6 +209,7 @@ bool qTableQuery(qinfo_t qinfo) { ...@@ -209,6 +209,7 @@ bool qTableQuery(qinfo_t qinfo) {
return false; return false;
} }
pQInfo->startExecTs = taosGetTimestampSec(); pQInfo->startExecTs = taosGetTimestampSec();
if (isQueryKilled(pQInfo)) { if (isQueryKilled(pQInfo)) {
...@@ -216,9 +217,10 @@ bool qTableQuery(qinfo_t qinfo) { ...@@ -216,9 +217,10 @@ bool qTableQuery(qinfo_t qinfo) {
return doBuildResCheck(pQInfo); return doBuildResCheck(pQInfo);
} }
if (pQInfo->tableqinfoGroupInfo.numOfTables == 0) { SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
if (pRuntimeEnv->tableqinfoGroupInfo.numOfTables == 0) {
qDebug("QInfo:%p no table exists for query, abort", pQInfo); qDebug("QInfo:%p no table exists for query, abort", pQInfo);
setQueryStatus(pQInfo->runtimeEnv.pQuery, QUERY_COMPLETED); setQueryStatus(pRuntimeEnv, QUERY_COMPLETED);
return doBuildResCheck(pQInfo); return doBuildResCheck(pQInfo);
} }
...@@ -232,26 +234,16 @@ bool qTableQuery(qinfo_t qinfo) { ...@@ -232,26 +234,16 @@ bool qTableQuery(qinfo_t qinfo) {
qDebug("QInfo:%p query task is launched", pQInfo); qDebug("QInfo:%p query task is launched", pQInfo);
SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; pRuntimeEnv->outputBuf = pRuntimeEnv->proot->exec(pRuntimeEnv->proot);
if (onlyQueryTags(pQInfo->runtimeEnv.pQuery)) {
assert(pQInfo->runtimeEnv.pQueryHandle == NULL);
buildTagQueryResult(pQInfo);
} else if (pQInfo->runtimeEnv.stableQuery) {
stableQueryImpl(pQInfo);
} else if (pQInfo->runtimeEnv.queryBlockDist){
buildTableBlockDistResult(pQInfo);
} else {
tableQueryImpl(pQInfo);
}
SQuery* pQuery = pRuntimeEnv->pQuery;
if (isQueryKilled(pQInfo)) { if (isQueryKilled(pQInfo)) {
qDebug("QInfo:%p query is killed", pQInfo); qDebug("QInfo:%p query is killed", pQInfo);
} else if (pQuery->rec.rows == 0) { } else if (GET_NUM_OF_RESULTS(pRuntimeEnv) == 0) {
qDebug("QInfo:%p over, %" PRIzu " tables queried, %"PRId64" rows are returned", pQInfo, pQInfo->tableqinfoGroupInfo.numOfTables, pQuery->rec.total); qDebug("QInfo:%p over, %u tables queried, %"PRId64" rows are returned", pQInfo, pRuntimeEnv->tableqinfoGroupInfo.numOfTables,
pRuntimeEnv->resultInfo.total);
} else { } else {
qDebug("QInfo:%p query paused, %" PRId64 " rows returned, numOfTotal:%" PRId64 " rows", qDebug("QInfo:%p query paused, %d rows returned, numOfTotal:%" PRId64 " rows",
pQInfo, pQuery->rec.rows, pQuery->rec.total + pQuery->rec.rows); pQInfo, GET_NUM_OF_RESULTS(pRuntimeEnv), pRuntimeEnv->resultInfo.total + GET_NUM_OF_RESULTS(pRuntimeEnv));
} }
return doBuildResCheck(pQInfo); return doBuildResCheck(pQInfo);
...@@ -279,6 +271,7 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex ...@@ -279,6 +271,7 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex
*buildRes = true; *buildRes = true;
code = pQInfo->code; code = pQInfo->code;
} else { } else {
SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
pthread_mutex_lock(&pQInfo->lock); pthread_mutex_lock(&pQInfo->lock);
...@@ -286,8 +279,8 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex ...@@ -286,8 +279,8 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex
assert(pQInfo->rspContext == NULL); assert(pQInfo->rspContext == NULL);
if (pQInfo->dataReady == QUERY_RESULT_READY) { if (pQInfo->dataReady == QUERY_RESULT_READY) {
*buildRes = true; *buildRes = true;
qDebug("QInfo:%p retrieve result info, rowsize:%d, rows:%" PRId64 ", code:%s", pQInfo, pQuery->resultRowSize, qDebug("QInfo:%p retrieve result info, rowsize:%d, rows:%d, code:%s", pQInfo, pQuery->resultRowSize,
pQuery->rec.rows, tstrerror(pQInfo->code)); GET_NUM_OF_RESULTS(pRuntimeEnv), tstrerror(pQInfo->code));
} else { } else {
*buildRes = false; *buildRes = false;
qDebug("QInfo:%p retrieve req set query return result after paused", pQInfo); qDebug("QInfo:%p retrieve req set query return result after paused", pQInfo);
...@@ -309,12 +302,13 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co ...@@ -309,12 +302,13 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
return TSDB_CODE_QRY_INVALID_QHANDLE; return TSDB_CODE_QRY_INVALID_QHANDLE;
} }
SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
size_t size = getResultSize(pQInfo, &pQuery->rec.rows); SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
int32_t s = GET_NUM_OF_RESULTS(pRuntimeEnv);
size_t size = pQuery->resultRowSize * s;
size += sizeof(int32_t); size += sizeof(int32_t);
size += sizeof(STableIdInfo) * taosHashGetSize(pQInfo->arrTableIdInfo); size += sizeof(STableIdInfo) * taosHashGetSize(pRuntimeEnv->pTableRetrieveTsMap);
*contLen = (int32_t)(size + sizeof(SRetrieveTableRsp)); *contLen = (int32_t)(size + sizeof(SRetrieveTableRsp));
...@@ -324,27 +318,27 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co ...@@ -324,27 +318,27 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
return TSDB_CODE_QRY_OUT_OF_MEMORY; return TSDB_CODE_QRY_OUT_OF_MEMORY;
} }
(*pRsp)->numOfRows = htonl((int32_t)pQuery->rec.rows); (*pRsp)->numOfRows = htonl((int32_t)s);
if (pQInfo->code == TSDB_CODE_SUCCESS) { if (pQInfo->code == TSDB_CODE_SUCCESS) {
(*pRsp)->offset = htobe64(pQuery->limit.offset); (*pRsp)->offset = htobe64(pQInfo->runtimeEnv.currentOffset);
(*pRsp)->useconds = htobe64(pRuntimeEnv->summary.elapsedTime); (*pRsp)->useconds = htobe64(pQInfo->summary.elapsedTime);
} else { } else {
(*pRsp)->offset = 0; (*pRsp)->offset = 0;
(*pRsp)->useconds = htobe64(pRuntimeEnv->summary.elapsedTime); (*pRsp)->useconds = htobe64(pQInfo->summary.elapsedTime);
} }
(*pRsp)->precision = htons(pQuery->precision); (*pRsp)->precision = htons(pQuery->precision);
if (pQuery->rec.rows > 0 && pQInfo->code == TSDB_CODE_SUCCESS) { if (GET_NUM_OF_RESULTS(&(pQInfo->runtimeEnv)) > 0 && pQInfo->code == TSDB_CODE_SUCCESS) {
doDumpQueryResult(pQInfo, (*pRsp)->data); doDumpQueryResult(pQInfo, (*pRsp)->data);
} else { } else {
setQueryStatus(pQuery, QUERY_OVER); setQueryStatus(pRuntimeEnv, QUERY_OVER);
} }
pQInfo->rspContext = NULL; pQInfo->rspContext = NULL;
pQInfo->dataReady = QUERY_RESULT_NOT_READY; pQInfo->dataReady = QUERY_RESULT_NOT_READY;
if (IS_QUERY_KILLED(pQInfo) || Q_STATUS_EQUAL(pQuery->status, QUERY_OVER)) { if (IS_QUERY_KILLED(pQInfo) || Q_STATUS_EQUAL(pRuntimeEnv->status, QUERY_OVER)) {
// here current thread hold the refcount, so it is safe to free tsdbQueryHandle. // here current thread hold the refcount, so it is safe to free tsdbQueryHandle.
*continueExec = false; *continueExec = false;
(*pRsp)->completed = 1; // notify no more result to client (*pRsp)->completed = 1; // notify no more result to client
...@@ -394,8 +388,7 @@ int32_t qQueryCompleted(qinfo_t qinfo) { ...@@ -394,8 +388,7 @@ int32_t qQueryCompleted(qinfo_t qinfo) {
return TSDB_CODE_QRY_INVALID_QHANDLE; return TSDB_CODE_QRY_INVALID_QHANDLE;
} }
SQuery* pQuery = pQInfo->runtimeEnv.pQuery; return isQueryKilled(pQInfo) || Q_STATUS_EQUAL(pQInfo->runtimeEnv.status, QUERY_OVER);
return isQueryKilled(pQInfo) || Q_STATUS_EQUAL(pQuery->status, QUERY_OVER);
} }
void qDestroyQueryInfo(qinfo_t qHandle) { void qDestroyQueryInfo(qinfo_t qHandle) {
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
** input grammar file: ** input grammar file:
*/ */
#include <stdio.h> #include <stdio.h>
#include <assert.h>
/************ Begin %include sections from the grammar ************************/ /************ Begin %include sections from the grammar ************************/
#include <stdio.h> #include <stdio.h>
...@@ -77,10 +76,8 @@ ...@@ -77,10 +76,8 @@
** zero the stack is dynamically sized using realloc() ** zero the stack is dynamically sized using realloc()
** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_SDECL A static variable declaration for the %extra_argument
** ParseARG_PDECL A parameter declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument
** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
** ParseARG_STORE Code to store %extra_argument into yypParser ** ParseARG_STORE Code to store %extra_argument into yypParser
** ParseARG_FETCH Code to extract %extra_argument from yypParser ** ParseARG_FETCH Code to extract %extra_argument from yypParser
** ParseCTX_* As ParseARG_ except for %extra_context
** YYERRORSYMBOL is the code number of the error symbol. If not ** YYERRORSYMBOL is the code number of the error symbol. If not
** defined, then do no error processing. ** defined, then do no error processing.
** YYNSTATE the combined number of states. ** YYNSTATE the combined number of states.
...@@ -100,46 +97,39 @@ ...@@ -100,46 +97,39 @@
#endif #endif
/************* Begin control #defines *****************************************/ /************* Begin control #defines *****************************************/
#define YYCODETYPE unsigned short int #define YYCODETYPE unsigned short int
#define YYNOCODE 287 #define YYNOCODE 263
#define YYACTIONTYPE unsigned short int #define YYACTIONTYPE unsigned short int
#define ParseTOKENTYPE SStrToken #define ParseTOKENTYPE SStrToken
typedef union { typedef union {
int yyinit; int yyinit;
ParseTOKENTYPE yy0; ParseTOKENTYPE yy0;
SCreateDbInfo yy100; SLimitVal yy18;
SCreateDbInfo yy94;
int yy116; int yy116;
SIntervalVal yy126; SSubclauseInfo* yy141;
tSQLExprList* yy178; tSQLExprList* yy170;
SArray* yy207; tVariant yy218;
int64_t yy208; SIntervalVal yy220;
tVariant yy232; SCreatedTableInfo yy252;
SLimitVal yy314; tSQLExpr* yy282;
SCreateTableSQL* yy414; SCreateTableSQL* yy310;
SSubclauseInfo* yy441; SQuerySQL* yy372;
tSQLExpr* yy484; SCreateAcctInfo yy419;
SCreateAcctInfo yy505; SArray* yy429;
TAOS_FIELD yy517; TAOS_FIELD yy451;
SQuerySQL* yy526; int64_t yy481;
SCreatedTableInfo yy542;
} YYMINORTYPE; } YYMINORTYPE;
#ifndef YYSTACKDEPTH #ifndef YYSTACKDEPTH
#define YYSTACKDEPTH 100 #define YYSTACKDEPTH 100
#endif #endif
#define ParseARG_SDECL SSqlInfo* pInfo; #define ParseARG_SDECL SSqlInfo* pInfo;
#define ParseARG_PDECL ,SSqlInfo* pInfo #define ParseARG_PDECL ,SSqlInfo* pInfo
#define ParseARG_PARAM ,pInfo #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo
#define ParseARG_FETCH SSqlInfo* pInfo=yypParser->pInfo; #define ParseARG_STORE yypParser->pInfo = pInfo
#define ParseARG_STORE yypParser->pInfo=pInfo;
#define ParseCTX_SDECL
#define ParseCTX_PDECL
#define ParseCTX_PARAM
#define ParseCTX_FETCH
#define ParseCTX_STORE
#define YYFALLBACK 1 #define YYFALLBACK 1
#define YYNSTATE 306 #define YYNSTATE 306
#define YYNRULE 263 #define YYNRULE 263
#define YYNRULE_WITH_ACTION 263 #define YYNTOKEN 187
#define YYNTOKEN 213
#define YY_MAX_SHIFT 305 #define YY_MAX_SHIFT 305
#define YY_MIN_SHIFTREDUCE 494 #define YY_MIN_SHIFTREDUCE 494
#define YY_MAX_SHIFTREDUCE 756 #define YY_MAX_SHIFTREDUCE 756
...@@ -149,7 +139,6 @@ typedef union { ...@@ -149,7 +139,6 @@ typedef union {
#define YY_MIN_REDUCE 760 #define YY_MIN_REDUCE 760
#define YY_MAX_REDUCE 1022 #define YY_MAX_REDUCE 1022
/************* End control #defines *******************************************/ /************* End control #defines *******************************************/
#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
/* Define the yytestcase() macro to be a no-op if is not already defined /* Define the yytestcase() macro to be a no-op if is not already defined
** otherwise. ** otherwise.
...@@ -231,149 +220,146 @@ static const YYACTIONTYPE yy_action[] = { ...@@ -231,149 +220,146 @@ static const YYACTIONTYPE yy_action[] = {
/* 120 */ 209, 41, 24, 50, 253, 55, 53, 57, 54, 957, /* 120 */ 209, 41, 24, 50, 253, 55, 53, 57, 54, 957,
/* 130 */ 36, 248, 704, 46, 45, 135, 664, 44, 43, 42, /* 130 */ 36, 248, 704, 46, 45, 135, 664, 44, 43, 42,
/* 140 */ 47, 49, 894, 51, 52, 241, 892, 209, 41, 229, /* 140 */ 47, 49, 894, 51, 52, 241, 892, 209, 41, 229,
/* 150 */ 50, 253, 55, 53, 57, 54, 233, 232, 101, 213, /* 150 */ 50, 253, 55, 53, 57, 54, 233, 232, 180, 213,
/* 160 */ 46, 45, 903, 289, 44, 43, 42, 23, 267, 298, /* 160 */ 46, 45, 903, 218, 44, 43, 42, 23, 267, 298,
/* 170 */ 297, 266, 265, 264, 296, 263, 295, 294, 293, 262, /* 170 */ 297, 266, 265, 264, 296, 263, 295, 294, 293, 262,
/* 180 */ 292, 291, 866, 30, 854, 855, 856, 857, 858, 859, /* 180 */ 292, 291, 866, 30, 854, 855, 856, 857, 858, 859,
/* 190 */ 860, 861, 862, 863, 864, 865, 867, 868, 51, 52, /* 190 */ 860, 861, 862, 863, 864, 865, 867, 868, 51, 52,
/* 200 */ 917, 76, 209, 41, 900, 50, 253, 55, 53, 57, /* 200 */ 917, 76, 209, 41, 900, 50, 253, 55, 53, 57,
/* 210 */ 54, 299, 18, 180, 198, 46, 45, 30, 269, 44, /* 210 */ 54, 299, 18, 30, 198, 46, 45, 69, 269, 44,
/* 220 */ 43, 42, 208, 717, 272, 269, 708, 903, 711, 185, /* 220 */ 43, 42, 208, 717, 272, 269, 708, 903, 711, 185,
/* 230 */ 714, 1001, 208, 717, 69, 186, 708, 906, 711, 77, /* 230 */ 714, 219, 208, 717, 271, 186, 708, 906, 711, 101,
/* 240 */ 714, 114, 113, 184, 1000, 644, 215, 221, 641, 657, /* 240 */ 714, 114, 113, 184, 289, 644, 215, 221, 641, 891,
/* 250 */ 642, 71, 643, 12, 205, 206, 25, 80, 252, 145, /* 250 */ 642, 128, 643, 1014, 205, 206, 77, 902, 252, 36,
/* 260 */ 23, 902, 298, 297, 205, 206, 891, 296, 999, 295, /* 260 */ 23, 706, 298, 297, 205, 206, 967, 296, 71, 295,
/* 270 */ 294, 293, 24, 292, 291, 874, 223, 224, 872, 873, /* 270 */ 294, 293, 24, 292, 291, 874, 223, 224, 872, 873,
/* 280 */ 36, 193, 904, 875, 805, 877, 878, 876, 161, 879, /* 280 */ 36, 1001, 904, 875, 805, 877, 878, 876, 161, 879,
/* 290 */ 880, 55, 53, 57, 54, 67, 220, 619, 814, 46, /* 290 */ 880, 55, 53, 57, 54, 1000, 220, 707, 814, 46,
/* 300 */ 45, 235, 161, 44, 43, 42, 99, 104, 192, 44, /* 300 */ 45, 235, 161, 44, 43, 42, 99, 104, 192, 44,
/* 310 */ 43, 42, 93, 103, 109, 112, 102, 239, 78, 254, /* 310 */ 43, 42, 93, 103, 109, 112, 102, 254, 78, 302,
/* 320 */ 218, 31, 106, 5, 151, 56, 1, 149, 194, 33, /* 320 */ 301, 122, 106, 5, 151, 56, 1, 149, 999, 33,
/* 330 */ 150, 88, 83, 87, 30, 56, 169, 165, 716, 128, /* 330 */ 150, 88, 83, 87, 657, 56, 169, 165, 716, 30,
/* 340 */ 30, 30, 167, 164, 117, 116, 115, 36, 716, 889, /* 340 */ 30, 25, 167, 164, 117, 116, 115, 30, 716, 889,
/* 350 */ 890, 29, 893, 715, 645, 806, 46, 45, 1014, 161, /* 350 */ 890, 29, 893, 715, 645, 193, 46, 45, 3, 162,
/* 360 */ 44, 43, 42, 715, 222, 685, 686, 276, 275, 302, /* 360 */ 44, 43, 42, 715, 222, 207, 806, 276, 275, 12,
/* 370 */ 301, 122, 3, 162, 706, 273, 672, 710, 903, 713, /* 370 */ 161, 685, 686, 80, 652, 145, 710, 709, 713, 712,
/* 380 */ 132, 277, 281, 676, 903, 903, 652, 60, 219, 677, /* 380 */ 273, 277, 238, 903, 903, 239, 672, 61, 281, 31,
/* 390 */ 207, 271, 737, 20, 238, 718, 19, 61, 709, 19, /* 390 */ 132, 903, 676, 677, 737, 718, 60, 20, 19, 19,
/* 400 */ 712, 64, 630, 905, 256, 632, 31, 258, 31, 60, /* 400 */ 64, 194, 630, 256, 92, 91, 31, 31, 62, 6,
/* 410 */ 707, 79, 631, 178, 28, 720, 60, 259, 62, 179, /* 410 */ 178, 632, 258, 720, 631, 60, 79, 28, 60, 65,
/* 420 */ 65, 92, 91, 111, 110, 14, 13, 98, 97, 16, /* 420 */ 259, 14, 13, 67, 648, 619, 649, 179, 98, 97,
/* 430 */ 15, 648, 181, 649, 6, 646, 175, 647, 127, 125, /* 430 */ 16, 15, 646, 966, 647, 111, 110, 127, 125, 181,
/* 440 */ 182, 183, 189, 190, 967, 188, 173, 187, 966, 177, /* 440 */ 175, 182, 183, 189, 190, 188, 173, 187, 177, 905,
/* 450 */ 210, 963, 962, 211, 280, 129, 919, 927, 39, 949, /* 450 */ 210, 963, 919, 962, 211, 280, 949, 39, 129, 948,
/* 460 */ 948, 934, 936, 131, 146, 899, 144, 147, 148, 36, /* 460 */ 144, 927, 934, 36, 936, 126, 131, 146, 899, 237,
/* 470 */ 817, 261, 37, 171, 34, 270, 813, 237, 1019, 89, /* 470 */ 147, 671, 142, 148, 817, 261, 136, 37, 251, 66,
/* 480 */ 1018, 1016, 126, 152, 274, 1013, 95, 671, 242, 1012, /* 480 */ 916, 58, 63, 137, 171, 138, 34, 270, 242, 249,
/* 490 */ 200, 1010, 153, 835, 246, 35, 32, 916, 38, 172, /* 490 */ 813, 1019, 89, 200, 1018, 1016, 246, 139, 247, 152,
/* 500 */ 63, 66, 802, 136, 58, 251, 137, 138, 249, 247, /* 500 */ 140, 274, 1013, 95, 245, 1012, 1010, 153, 835, 35,
/* 510 */ 105, 800, 107, 245, 108, 243, 40, 798, 139, 797, /* 510 */ 243, 32, 38, 172, 40, 802, 105, 800, 107, 108,
/* 520 */ 290, 100, 225, 282, 163, 795, 283, 794, 793, 792, /* 520 */ 798, 797, 225, 163, 795, 794, 793, 792, 791, 790,
/* 530 */ 791, 790, 166, 168, 787, 785, 783, 781, 779, 284, /* 530 */ 166, 168, 787, 785, 783, 781, 779, 170, 290, 240,
/* 540 */ 170, 286, 240, 72, 73, 950, 285, 287, 288, 300, /* 540 */ 72, 73, 950, 100, 282, 283, 284, 285, 286, 287,
/* 550 */ 756, 195, 227, 217, 260, 228, 755, 230, 196, 191, /* 550 */ 288, 300, 756, 195, 217, 260, 227, 228, 755, 230,
/* 560 */ 231, 84, 85, 754, 742, 234, 796, 238, 74, 654, /* 560 */ 196, 191, 231, 84, 85, 754, 742, 234, 238, 654,
/* 570 */ 673, 118, 789, 156, 119, 155, 836, 154, 157, 158, /* 570 */ 74, 68, 673, 255, 796, 8, 156, 133, 836, 118,
/* 580 */ 160, 159, 120, 788, 2, 121, 780, 4, 870, 255, /* 580 */ 154, 159, 155, 158, 157, 160, 119, 789, 2, 120,
/* 590 */ 8, 901, 68, 133, 202, 244, 140, 141, 142, 143, /* 590 */ 870, 788, 901, 121, 780, 4, 202, 141, 678, 143,
/* 600 */ 882, 678, 134, 26, 27, 9, 10, 719, 7, 11, /* 600 */ 244, 134, 9, 10, 82, 719, 882, 26, 27, 7,
/* 610 */ 721, 21, 22, 257, 82, 583, 579, 80, 577, 576, /* 610 */ 11, 21, 721, 22, 583, 257, 579, 577, 80, 576,
/* 620 */ 575, 572, 545, 268, 86, 90, 31, 94, 59, 96, /* 620 */ 575, 572, 545, 268, 86, 90, 31, 94, 96, 59,
/* 630 */ 622, 621, 618, 567, 565, 557, 563, 559, 561, 555, /* 630 */ 622, 621, 618, 567, 565, 557, 563, 559, 561, 555,
/* 640 */ 553, 586, 585, 584, 582, 581, 580, 578, 574, 573, /* 640 */ 553, 586, 585, 584, 582, 581, 580, 578, 574, 573,
/* 650 */ 60, 543, 511, 509, 760, 759, 759, 759, 759, 759, /* 650 */ 60, 543, 511, 509, 760, 759, 759, 759, 759, 759,
/* 660 */ 759, 759, 759, 759, 759, 759, 123, 124, /* 660 */ 759, 759, 759, 759, 759, 759, 123, 124,
}; };
static const YYCODETYPE yy_lookahead[] = { static const YYCODETYPE yy_lookahead[] = {
/* 0 */ 276, 1, 276, 215, 216, 276, 216, 5, 276, 9, /* 0 */ 251, 1, 251, 190, 191, 251, 191, 5, 251, 9,
/* 10 */ 286, 285, 286, 13, 14, 216, 16, 17, 216, 235, /* 10 */ 261, 260, 261, 13, 14, 191, 16, 17, 191, 210,
/* 20 */ 20, 21, 276, 23, 24, 25, 26, 27, 28, 213, /* 20 */ 20, 21, 251, 23, 24, 25, 26, 27, 28, 188,
/* 30 */ 214, 285, 286, 33, 34, 33, 34, 37, 38, 39, /* 30 */ 189, 260, 261, 33, 34, 33, 34, 37, 38, 39,
/* 40 */ 13, 14, 235, 16, 17, 261, 216, 20, 21, 1, /* 40 */ 13, 14, 210, 16, 17, 236, 191, 20, 21, 1,
/* 50 */ 23, 24, 25, 26, 27, 28, 257, 9, 37, 260, /* 50 */ 23, 24, 25, 26, 27, 28, 232, 9, 37, 235,
/* 60 */ 33, 34, 235, 216, 37, 38, 39, 14, 261, 16, /* 60 */ 33, 34, 210, 191, 37, 38, 39, 14, 236, 16,
/* 70 */ 17, 216, 282, 20, 21, 259, 23, 24, 25, 26, /* 70 */ 17, 191, 257, 20, 21, 234, 23, 24, 25, 26,
/* 80 */ 27, 28, 280, 216, 282, 81, 33, 34, 261, 273, /* 80 */ 27, 28, 255, 191, 257, 81, 33, 34, 236, 248,
/* 90 */ 37, 38, 39, 45, 46, 47, 48, 49, 50, 51, /* 90 */ 37, 38, 39, 45, 46, 47, 48, 49, 50, 51,
/* 100 */ 52, 53, 54, 55, 56, 57, 58, 277, 222, 61, /* 100 */ 52, 53, 54, 55, 56, 57, 58, 252, 197, 61,
/* 110 */ 110, 1, 257, 13, 14, 260, 16, 17, 216, 9, /* 110 */ 110, 1, 232, 13, 14, 235, 16, 17, 191, 9,
/* 120 */ 20, 21, 104, 23, 24, 25, 26, 27, 28, 282, /* 120 */ 20, 21, 104, 23, 24, 25, 26, 27, 28, 257,
/* 130 */ 112, 284, 105, 33, 34, 216, 115, 37, 38, 39, /* 130 */ 112, 259, 105, 33, 34, 191, 115, 37, 38, 39,
/* 140 */ 13, 14, 256, 16, 17, 278, 0, 20, 21, 134, /* 140 */ 13, 14, 231, 16, 17, 253, 0, 20, 21, 134,
/* 150 */ 23, 24, 25, 26, 27, 28, 141, 142, 76, 257, /* 150 */ 23, 24, 25, 26, 27, 28, 141, 142, 251, 232,
/* 160 */ 33, 34, 260, 81, 37, 38, 39, 88, 89, 90, /* 160 */ 33, 34, 235, 67, 37, 38, 39, 88, 89, 90,
/* 170 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, /* 170 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
/* 180 */ 101, 102, 234, 216, 236, 237, 238, 239, 240, 241, /* 180 */ 101, 102, 209, 191, 211, 212, 213, 214, 215, 216,
/* 190 */ 242, 243, 244, 245, 246, 247, 248, 249, 16, 17, /* 190 */ 217, 218, 219, 220, 221, 222, 223, 224, 16, 17,
/* 200 */ 259, 282, 20, 21, 216, 23, 24, 25, 26, 27, /* 200 */ 234, 257, 20, 21, 191, 23, 24, 25, 26, 27,
/* 210 */ 28, 235, 44, 276, 273, 33, 34, 216, 79, 37, /* 210 */ 28, 210, 44, 191, 248, 33, 34, 197, 79, 37,
/* 220 */ 38, 39, 1, 2, 257, 79, 5, 260, 7, 61, /* 220 */ 38, 39, 1, 2, 232, 79, 5, 235, 7, 61,
/* 230 */ 9, 276, 1, 2, 222, 67, 5, 261, 7, 262, /* 230 */ 9, 135, 1, 2, 138, 67, 5, 236, 7, 76,
/* 240 */ 9, 73, 74, 75, 276, 2, 258, 216, 5, 109, /* 240 */ 9, 73, 74, 75, 81, 2, 233, 191, 5, 229,
/* 250 */ 7, 274, 9, 104, 33, 34, 116, 108, 37, 110, /* 250 */ 7, 104, 9, 236, 33, 34, 237, 235, 37, 112,
/* 260 */ 88, 260, 90, 91, 33, 34, 254, 95, 276, 97, /* 260 */ 88, 1, 90, 91, 33, 34, 227, 95, 249, 97,
/* 270 */ 98, 99, 104, 101, 102, 234, 33, 34, 237, 238, /* 270 */ 98, 99, 104, 101, 102, 209, 33, 34, 212, 213,
/* 280 */ 112, 276, 251, 242, 221, 244, 245, 246, 225, 248, /* 280 */ 112, 251, 226, 217, 196, 219, 220, 221, 200, 223,
/* 290 */ 249, 25, 26, 27, 28, 104, 67, 106, 221, 33, /* 290 */ 224, 25, 26, 27, 28, 251, 67, 37, 196, 33,
/* 300 */ 34, 133, 225, 37, 38, 39, 62, 63, 140, 37, /* 300 */ 34, 133, 200, 37, 38, 39, 62, 63, 140, 37,
/* 310 */ 38, 39, 68, 69, 70, 71, 72, 105, 222, 15, /* 310 */ 38, 39, 68, 69, 70, 71, 72, 15, 197, 64,
/* 320 */ 67, 109, 78, 62, 63, 104, 223, 224, 276, 68, /* 320 */ 65, 66, 78, 62, 63, 104, 198, 199, 251, 68,
/* 330 */ 69, 70, 71, 72, 216, 104, 62, 63, 117, 104, /* 330 */ 69, 70, 71, 72, 109, 104, 62, 63, 117, 191,
/* 340 */ 216, 216, 68, 69, 70, 71, 72, 112, 117, 253, /* 340 */ 191, 116, 68, 69, 70, 71, 72, 191, 117, 228,
/* 350 */ 254, 255, 256, 132, 111, 221, 33, 34, 261, 225, /* 350 */ 229, 230, 231, 132, 111, 251, 33, 34, 194, 195,
/* 360 */ 37, 38, 39, 132, 135, 123, 124, 138, 139, 64, /* 360 */ 37, 38, 39, 132, 135, 60, 196, 138, 139, 104,
/* 370 */ 65, 66, 219, 220, 1, 257, 105, 5, 260, 7, /* 370 */ 200, 123, 124, 108, 105, 110, 5, 5, 7, 7,
/* 380 */ 109, 257, 257, 105, 260, 260, 105, 109, 135, 105, /* 380 */ 232, 232, 113, 235, 235, 105, 105, 109, 232, 109,
/* 390 */ 60, 138, 105, 109, 113, 105, 109, 109, 5, 109, /* 390 */ 109, 235, 105, 105, 105, 105, 109, 109, 109, 109,
/* 400 */ 7, 109, 105, 261, 105, 105, 109, 105, 109, 109, /* 400 */ 109, 251, 105, 105, 136, 137, 109, 109, 130, 104,
/* 410 */ 37, 109, 105, 276, 104, 111, 109, 107, 130, 276, /* 410 */ 251, 105, 105, 111, 105, 109, 109, 104, 109, 128,
/* 420 */ 128, 136, 137, 76, 77, 136, 137, 136, 137, 136, /* 420 */ 107, 136, 137, 104, 5, 106, 7, 251, 136, 137,
/* 430 */ 137, 5, 276, 7, 104, 5, 276, 7, 62, 63, /* 430 */ 136, 137, 5, 227, 7, 76, 77, 62, 63, 251,
/* 440 */ 276, 276, 276, 276, 252, 276, 276, 276, 252, 276, /* 440 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 236,
/* 450 */ 252, 252, 252, 252, 252, 216, 259, 216, 275, 283, /* 450 */ 227, 227, 234, 227, 227, 227, 258, 250, 191, 258,
/* 460 */ 283, 216, 216, 216, 216, 216, 263, 216, 216, 112, /* 460 */ 238, 191, 191, 112, 191, 60, 191, 191, 191, 234,
/* 470 */ 216, 216, 216, 216, 216, 216, 216, 259, 216, 216, /* 470 */ 191, 117, 240, 191, 191, 191, 246, 191, 121, 127,
/* 480 */ 216, 216, 60, 216, 216, 216, 216, 117, 279, 216, /* 480 */ 247, 126, 129, 245, 191, 244, 191, 191, 254, 125,
/* 490 */ 279, 216, 216, 216, 279, 216, 216, 272, 216, 216, /* 490 */ 191, 191, 191, 254, 191, 191, 254, 243, 120, 191,
/* 500 */ 129, 127, 216, 271, 126, 121, 270, 269, 125, 120, /* 500 */ 242, 191, 191, 191, 119, 191, 191, 191, 191, 191,
/* 510 */ 216, 216, 216, 119, 216, 118, 131, 216, 268, 216, /* 510 */ 118, 191, 191, 191, 131, 191, 191, 191, 191, 191,
/* 520 */ 103, 87, 216, 86, 216, 216, 50, 216, 216, 216, /* 520 */ 191, 191, 191, 191, 191, 191, 191, 191, 191, 191,
/* 530 */ 216, 216, 216, 216, 216, 216, 216, 216, 216, 83, /* 530 */ 191, 191, 191, 191, 191, 191, 191, 191, 103, 192,
/* 540 */ 216, 54, 217, 217, 217, 217, 85, 84, 82, 79, /* 540 */ 192, 192, 192, 87, 86, 50, 83, 85, 54, 84,
/* 550 */ 5, 217, 143, 217, 217, 5, 5, 143, 217, 217, /* 550 */ 82, 79, 5, 192, 192, 192, 143, 5, 5, 143,
/* 560 */ 5, 222, 222, 5, 89, 134, 217, 113, 109, 105, /* 560 */ 192, 192, 5, 197, 197, 5, 89, 134, 113, 105,
/* 570 */ 105, 218, 217, 227, 218, 231, 233, 232, 230, 228, /* 570 */ 109, 114, 105, 107, 192, 104, 202, 104, 208, 193,
/* 580 */ 226, 229, 218, 217, 223, 218, 217, 219, 250, 107, /* 580 */ 207, 204, 206, 203, 205, 201, 193, 192, 198, 193,
/* 590 */ 104, 259, 114, 104, 1, 104, 267, 266, 265, 264, /* 590 */ 225, 192, 234, 193, 192, 194, 1, 241, 105, 239,
/* 600 */ 250, 105, 104, 109, 109, 122, 122, 105, 104, 104, /* 600 */ 104, 104, 122, 122, 76, 105, 225, 109, 109, 104,
/* 610 */ 111, 104, 104, 107, 76, 9, 5, 108, 5, 5, /* 610 */ 104, 104, 111, 104, 9, 107, 5, 5, 108, 5,
/* 620 */ 5, 5, 80, 15, 76, 137, 109, 137, 16, 137, /* 620 */ 5, 5, 80, 15, 76, 137, 109, 137, 137, 16,
/* 630 */ 5, 5, 105, 5, 5, 5, 5, 5, 5, 5, /* 630 */ 5, 5, 105, 5, 5, 5, 5, 5, 5, 5,
/* 640 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, /* 640 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
/* 650 */ 109, 80, 60, 59, 0, 287, 287, 287, 287, 287, /* 650 */ 109, 80, 60, 59, 0, 262, 262, 262, 262, 262,
/* 660 */ 287, 287, 287, 287, 287, 287, 21, 21, 287, 287, /* 660 */ 262, 262, 262, 262, 262, 262, 21, 21, 262, 262,
/* 670 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 670 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 680 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 680 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 690 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 690 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 700 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 700 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 710 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 710 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 720 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 720 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 730 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 730 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 740 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 740 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 750 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 750 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 760 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 760 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 770 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 770 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 780 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 780 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 790 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 790 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 800 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 800 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 810 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 810 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 820 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 820 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 830 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 830 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 840 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 840 */ 262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
/* 850 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, /* 850 */ 262, 262, 262, 262, 262,
/* 860 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287,
/* 870 */ 287, 287, 287, 287, 287, 287, 287, 287, 287, 287,
/* 880 */ 287,
}; };
#define YY_SHIFT_COUNT (305) #define YY_SHIFT_COUNT (305)
#define YY_SHIFT_MIN (0) #define YY_SHIFT_MIN (0)
...@@ -382,57 +368,57 @@ static const unsigned short int yy_shift_ofst[] = { ...@@ -382,57 +368,57 @@ static const unsigned short int yy_shift_ofst[] = {
/* 0 */ 168, 79, 79, 172, 172, 139, 221, 231, 110, 110, /* 0 */ 168, 79, 79, 172, 172, 139, 221, 231, 110, 110,
/* 10 */ 110, 110, 110, 110, 110, 110, 110, 0, 48, 231, /* 10 */ 110, 110, 110, 110, 110, 110, 110, 0, 48, 231,
/* 20 */ 243, 243, 243, 243, 18, 110, 110, 110, 110, 146, /* 20 */ 243, 243, 243, 243, 18, 110, 110, 110, 110, 146,
/* 30 */ 110, 110, 82, 139, 4, 4, 668, 668, 668, 231, /* 30 */ 110, 110, 163, 139, 4, 4, 668, 668, 668, 231,
/* 40 */ 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, /* 40 */ 231, 231, 231, 231, 231, 231, 231, 231, 231, 231,
/* 50 */ 231, 231, 231, 231, 231, 231, 231, 231, 231, 243, /* 50 */ 231, 231, 231, 231, 231, 231, 231, 231, 231, 243,
/* 60 */ 243, 2, 2, 2, 2, 2, 2, 2, 235, 110, /* 60 */ 243, 2, 2, 2, 2, 2, 2, 2, 147, 110,
/* 70 */ 110, 21, 110, 110, 110, 242, 242, 140, 110, 110, /* 70 */ 110, 21, 110, 110, 110, 248, 248, 225, 110, 110,
/* 80 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, /* 80 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
/* 90 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, /* 90 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
/* 100 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, /* 100 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
/* 110 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, /* 110 */ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
/* 120 */ 110, 110, 110, 110, 110, 110, 110, 110, 357, 422, /* 120 */ 110, 110, 110, 110, 110, 110, 110, 110, 351, 405,
/* 130 */ 422, 422, 370, 370, 370, 422, 374, 371, 378, 384, /* 130 */ 405, 405, 354, 354, 354, 405, 352, 353, 355, 357,
/* 140 */ 383, 389, 394, 397, 385, 357, 422, 422, 422, 417, /* 140 */ 364, 378, 385, 392, 383, 351, 405, 405, 405, 435,
/* 150 */ 139, 139, 422, 422, 434, 437, 476, 456, 461, 487, /* 150 */ 139, 139, 405, 405, 456, 458, 495, 463, 462, 494,
/* 160 */ 463, 466, 417, 422, 470, 470, 422, 470, 422, 470, /* 160 */ 465, 468, 435, 405, 472, 472, 405, 472, 405, 472,
/* 170 */ 422, 668, 668, 27, 100, 127, 100, 100, 53, 182, /* 170 */ 405, 668, 668, 27, 100, 127, 100, 100, 53, 182,
/* 180 */ 266, 266, 266, 266, 244, 261, 274, 323, 323, 323, /* 180 */ 266, 266, 266, 266, 244, 261, 274, 323, 323, 323,
/* 190 */ 323, 229, 15, 272, 272, 149, 253, 305, 281, 212, /* 190 */ 323, 229, 15, 272, 272, 265, 96, 255, 269, 280,
/* 200 */ 271, 278, 284, 287, 290, 372, 393, 373, 330, 304, /* 200 */ 281, 287, 288, 289, 290, 371, 372, 260, 305, 302,
/* 210 */ 288, 292, 297, 299, 300, 302, 307, 310, 285, 289, /* 210 */ 278, 291, 297, 298, 306, 307, 309, 313, 268, 285,
/* 220 */ 291, 191, 293, 426, 430, 347, 376, 545, 409, 550, /* 220 */ 292, 319, 294, 419, 427, 359, 375, 547, 413, 552,
/* 230 */ 551, 414, 555, 558, 475, 431, 454, 464, 478, 482, /* 230 */ 553, 416, 557, 560, 477, 433, 455, 464, 457, 466,
/* 240 */ 486, 459, 465, 489, 593, 491, 496, 498, 494, 483, /* 240 */ 471, 461, 467, 473, 595, 496, 493, 497, 498, 480,
/* 250 */ 495, 484, 502, 504, 499, 505, 482, 507, 506, 508, /* 250 */ 499, 481, 500, 505, 501, 506, 466, 507, 508, 509,
/* 260 */ 509, 538, 606, 611, 613, 614, 615, 616, 542, 608, /* 260 */ 510, 528, 605, 611, 612, 614, 615, 616, 542, 608,
/* 270 */ 548, 488, 517, 517, 612, 490, 492, 517, 625, 626, /* 270 */ 548, 488, 517, 517, 613, 490, 491, 517, 625, 626,
/* 280 */ 527, 517, 628, 629, 630, 631, 632, 633, 634, 635, /* 280 */ 527, 517, 628, 629, 630, 631, 632, 633, 634, 635,
/* 290 */ 636, 637, 638, 639, 640, 641, 642, 643, 644, 541, /* 290 */ 636, 637, 638, 639, 640, 641, 642, 643, 644, 541,
/* 300 */ 571, 645, 646, 592, 594, 654, /* 300 */ 571, 645, 646, 592, 594, 654,
}; };
#define YY_REDUCE_COUNT (172) #define YY_REDUCE_COUNT (172)
#define YY_REDUCE_MIN (-276) #define YY_REDUCE_MIN (-251)
#define YY_REDUCE_MAX (369) #define YY_REDUCE_MAX (402)
static const short yy_reduce_ofst[] = { static const short yy_reduce_ofst[] = {
/* 0 */ -184, -52, -52, 41, 41, 96, -274, -254, -201, -153, /* 0 */ -159, -27, -27, 66, 66, 121, -249, -229, -176, -128,
/* 10 */ -198, -145, -98, -33, 118, 124, 125, -170, -212, -276, /* 10 */ -173, -120, -73, -8, 148, 149, 156, -145, -187, -251,
/* 20 */ -216, -193, -173, -24, -59, -133, -210, -81, -12, -114, /* 20 */ -191, -168, -148, 1, -34, -108, -185, -56, 13, -89,
/* 30 */ 31, 1, 63, 12, 77, 134, -23, 103, 153, -271, /* 30 */ 56, 22, 88, 20, 102, 170, 19, 128, 164, -246,
/* 40 */ -268, -63, -45, -32, -8, 5, 52, 137, 143, 156, /* 40 */ -243, -93, 30, 44, 77, 104, 150, 159, 176, 188,
/* 50 */ 160, 164, 165, 166, 167, 169, 170, 171, 173, 97, /* 50 */ 189, 190, 191, 192, 193, 194, 195, 196, 197, 17,
/* 60 */ 142, 192, 196, 198, 199, 200, 201, 202, 197, 239, /* 60 */ 213, 39, 206, 223, 224, 226, 227, 228, 218, 267,
/* 70 */ 241, 183, 245, 246, 247, 176, 177, 203, 248, 249, /* 70 */ 270, 207, 271, 273, 275, 198, 201, 222, 276, 277,
/* 80 */ 251, 252, 254, 255, 256, 257, 258, 259, 260, 262, /* 80 */ 279, 282, 283, 284, 286, 293, 295, 296, 299, 300,
/* 90 */ 263, 264, 265, 267, 268, 269, 270, 273, 275, 276, /* 90 */ 301, 303, 304, 308, 310, 311, 312, 314, 315, 316,
/* 100 */ 277, 279, 280, 282, 283, 286, 294, 295, 296, 298, /* 100 */ 317, 318, 320, 321, 322, 324, 325, 326, 327, 328,
/* 110 */ 301, 303, 306, 308, 309, 311, 312, 313, 314, 315, /* 110 */ 329, 330, 331, 332, 333, 334, 335, 336, 337, 338,
/* 120 */ 316, 317, 318, 319, 320, 321, 322, 324, 218, 325, /* 120 */ 339, 340, 341, 342, 343, 344, 345, 346, 235, 347,
/* 130 */ 326, 327, 209, 211, 215, 328, 225, 232, 236, 238, /* 130 */ 348, 349, 234, 239, 242, 350, 233, 230, 238, 241,
/* 140 */ 250, 329, 331, 333, 335, 332, 334, 336, 337, 338, /* 140 */ 254, 258, 356, 232, 360, 358, 361, 362, 363, 365,
/* 150 */ 339, 340, 341, 342, 343, 345, 344, 346, 348, 351, /* 150 */ 366, 367, 368, 369, 370, 373, 376, 374, 379, 380,
/* 160 */ 352, 354, 350, 349, 353, 356, 355, 364, 366, 367, /* 160 */ 377, 384, 381, 382, 386, 393, 395, 396, 399, 400,
/* 170 */ 369, 361, 368, /* 170 */ 402, 390, 401,
}; };
static const YYACTIONTYPE yy_default[] = { static const YYACTIONTYPE yy_default[] = {
/* 0 */ 757, 869, 815, 881, 803, 812, 1007, 1007, 757, 757, /* 0 */ 757, 869, 815, 881, 803, 812, 1007, 1007, 757, 757,
...@@ -660,32 +646,6 @@ static const YYCODETYPE yyFallback[] = { ...@@ -660,32 +646,6 @@ static const YYCODETYPE yyFallback[] = {
1, /* STATEMENT => ID */ 1, /* STATEMENT => ID */
1, /* TRIGGER => ID */ 1, /* TRIGGER => ID */
1, /* VIEW => ID */ 1, /* VIEW => ID */
1, /* COUNT => ID */
1, /* SUM => ID */
1, /* AVG => ID */
1, /* MIN => ID */
1, /* MAX => ID */
1, /* FIRST => ID */
1, /* LAST => ID */
1, /* TOP => ID */
1, /* BOTTOM => ID */
1, /* STDDEV => ID */
1, /* PERCENTILE => ID */
1, /* APERCENTILE => ID */
1, /* LEASTSQUARES => ID */
1, /* HISTOGRAM => ID */
1, /* DIFF => ID */
1, /* SPREAD => ID */
1, /* TWA => ID */
1, /* INTERP => ID */
1, /* LAST_ROW => ID */
1, /* RATE => ID */
1, /* IRATE => ID */
1, /* SUM_RATE => ID */
1, /* SUM_IRATE => ID */
1, /* AVG_RATE => ID */
1, /* AVG_IRATE => ID */
1, /* TBID => ID */
1, /* SEMI => ID */ 1, /* SEMI => ID */
1, /* NONE => ID */ 1, /* NONE => ID */
1, /* PREV => ID */ 1, /* PREV => ID */
...@@ -737,7 +697,6 @@ struct yyParser { ...@@ -737,7 +697,6 @@ struct yyParser {
int yyerrcnt; /* Shifts left before out of the error */ int yyerrcnt; /* Shifts left before out of the error */
#endif #endif
ParseARG_SDECL /* A place to hold %extra_argument */ ParseARG_SDECL /* A place to hold %extra_argument */
ParseCTX_SDECL /* A place to hold %extra_context */
#if YYSTACKDEPTH<=0 #if YYSTACKDEPTH<=0
int yystksz; /* Current side of the stack */ int yystksz; /* Current side of the stack */
yyStackEntry *yystack; /* The parser's stack */ yyStackEntry *yystack; /* The parser's stack */
...@@ -960,118 +919,93 @@ static const char *const yyTokenName[] = { ...@@ -960,118 +919,93 @@ static const char *const yyTokenName[] = {
/* 172 */ "STATEMENT", /* 172 */ "STATEMENT",
/* 173 */ "TRIGGER", /* 173 */ "TRIGGER",
/* 174 */ "VIEW", /* 174 */ "VIEW",
/* 175 */ "COUNT", /* 175 */ "SEMI",
/* 176 */ "SUM", /* 176 */ "NONE",
/* 177 */ "AVG", /* 177 */ "PREV",
/* 178 */ "MIN", /* 178 */ "LINEAR",
/* 179 */ "MAX", /* 179 */ "IMPORT",
/* 180 */ "FIRST", /* 180 */ "METRIC",
/* 181 */ "LAST", /* 181 */ "TBNAME",
/* 182 */ "TOP", /* 182 */ "JOIN",
/* 183 */ "BOTTOM", /* 183 */ "METRICS",
/* 184 */ "STDDEV", /* 184 */ "INSERT",
/* 185 */ "PERCENTILE", /* 185 */ "INTO",
/* 186 */ "APERCENTILE", /* 186 */ "VALUES",
/* 187 */ "LEASTSQUARES", /* 187 */ "error",
/* 188 */ "HISTOGRAM", /* 188 */ "program",
/* 189 */ "DIFF", /* 189 */ "cmd",
/* 190 */ "SPREAD", /* 190 */ "dbPrefix",
/* 191 */ "TWA", /* 191 */ "ids",
/* 192 */ "INTERP", /* 192 */ "cpxName",
/* 193 */ "LAST_ROW", /* 193 */ "ifexists",
/* 194 */ "RATE", /* 194 */ "alter_db_optr",
/* 195 */ "IRATE", /* 195 */ "alter_topic_optr",
/* 196 */ "SUM_RATE", /* 196 */ "acct_optr",
/* 197 */ "SUM_IRATE", /* 197 */ "ifnotexists",
/* 198 */ "AVG_RATE", /* 198 */ "db_optr",
/* 199 */ "AVG_IRATE", /* 199 */ "topic_optr",
/* 200 */ "TBID", /* 200 */ "pps",
/* 201 */ "SEMI", /* 201 */ "tseries",
/* 202 */ "NONE", /* 202 */ "dbs",
/* 203 */ "PREV", /* 203 */ "streams",
/* 204 */ "LINEAR", /* 204 */ "storage",
/* 205 */ "IMPORT", /* 205 */ "qtime",
/* 206 */ "METRIC", /* 206 */ "users",
/* 207 */ "TBNAME", /* 207 */ "conns",
/* 208 */ "JOIN", /* 208 */ "state",
/* 209 */ "METRICS", /* 209 */ "keep",
/* 210 */ "INSERT", /* 210 */ "tagitemlist",
/* 211 */ "INTO", /* 211 */ "cache",
/* 212 */ "VALUES", /* 212 */ "replica",
/* 213 */ "program", /* 213 */ "quorum",
/* 214 */ "cmd", /* 214 */ "days",
/* 215 */ "dbPrefix", /* 215 */ "minrows",
/* 216 */ "ids", /* 216 */ "maxrows",
/* 217 */ "cpxName", /* 217 */ "blocks",
/* 218 */ "ifexists", /* 218 */ "ctime",
/* 219 */ "alter_db_optr", /* 219 */ "wal",
/* 220 */ "alter_topic_optr", /* 220 */ "fsync",
/* 221 */ "acct_optr", /* 221 */ "comp",
/* 222 */ "ifnotexists", /* 222 */ "prec",
/* 223 */ "db_optr", /* 223 */ "update",
/* 224 */ "topic_optr", /* 224 */ "cachelast",
/* 225 */ "pps", /* 225 */ "partitions",
/* 226 */ "tseries", /* 226 */ "typename",
/* 227 */ "dbs", /* 227 */ "signed",
/* 228 */ "streams", /* 228 */ "create_table_args",
/* 229 */ "storage", /* 229 */ "create_stable_args",
/* 230 */ "qtime", /* 230 */ "create_table_list",
/* 231 */ "users", /* 231 */ "create_from_stable",
/* 232 */ "conns", /* 232 */ "columnlist",
/* 233 */ "state", /* 233 */ "tagNamelist",
/* 234 */ "keep", /* 234 */ "select",
/* 235 */ "tagitemlist", /* 235 */ "column",
/* 236 */ "cache", /* 236 */ "tagitem",
/* 237 */ "replica", /* 237 */ "selcollist",
/* 238 */ "quorum", /* 238 */ "from",
/* 239 */ "days", /* 239 */ "where_opt",
/* 240 */ "minrows", /* 240 */ "interval_opt",
/* 241 */ "maxrows", /* 241 */ "fill_opt",
/* 242 */ "blocks", /* 242 */ "sliding_opt",
/* 243 */ "ctime", /* 243 */ "groupby_opt",
/* 244 */ "wal", /* 244 */ "orderby_opt",
/* 245 */ "fsync", /* 245 */ "having_opt",
/* 246 */ "comp", /* 246 */ "slimit_opt",
/* 247 */ "prec", /* 247 */ "limit_opt",
/* 248 */ "update", /* 248 */ "union",
/* 249 */ "cachelast", /* 249 */ "sclp",
/* 250 */ "partitions", /* 250 */ "distinct",
/* 251 */ "typename", /* 251 */ "expr",
/* 252 */ "signed", /* 252 */ "as",
/* 253 */ "create_table_args", /* 253 */ "tablelist",
/* 254 */ "create_stable_args", /* 254 */ "tmvar",
/* 255 */ "create_table_list", /* 255 */ "sortlist",
/* 256 */ "create_from_stable", /* 256 */ "sortitem",
/* 257 */ "columnlist", /* 257 */ "item",
/* 258 */ "tagNamelist", /* 258 */ "sortorder",
/* 259 */ "select", /* 259 */ "grouplist",
/* 260 */ "column", /* 260 */ "exprlist",
/* 261 */ "tagitem", /* 261 */ "expritem",
/* 262 */ "selcollist",
/* 263 */ "from",
/* 264 */ "where_opt",
/* 265 */ "interval_opt",
/* 266 */ "fill_opt",
/* 267 */ "sliding_opt",
/* 268 */ "groupby_opt",
/* 269 */ "orderby_opt",
/* 270 */ "having_opt",
/* 271 */ "slimit_opt",
/* 272 */ "limit_opt",
/* 273 */ "union",
/* 274 */ "sclp",
/* 275 */ "distinct",
/* 276 */ "expr",
/* 277 */ "as",
/* 278 */ "tablelist",
/* 279 */ "tmvar",
/* 280 */ "sortlist",
/* 281 */ "sortitem",
/* 282 */ "item",
/* 283 */ "sortorder",
/* 284 */ "grouplist",
/* 285 */ "exprlist",
/* 286 */ "expritem",
}; };
#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
...@@ -1390,29 +1324,28 @@ static int yyGrowStack(yyParser *p){ ...@@ -1390,29 +1324,28 @@ static int yyGrowStack(yyParser *p){
/* Initialize a new parser that has already been allocated. /* Initialize a new parser that has already been allocated.
*/ */
void ParseInit(void *yypRawParser ParseCTX_PDECL){ void ParseInit(void *yypParser){
yyParser *yypParser = (yyParser*)yypRawParser; yyParser *pParser = (yyParser*)yypParser;
ParseCTX_STORE
#ifdef YYTRACKMAXSTACKDEPTH #ifdef YYTRACKMAXSTACKDEPTH
yypParser->yyhwm = 0; pParser->yyhwm = 0;
#endif #endif
#if YYSTACKDEPTH<=0 #if YYSTACKDEPTH<=0
yypParser->yytos = NULL; pParser->yytos = NULL;
yypParser->yystack = NULL; pParser->yystack = NULL;
yypParser->yystksz = 0; pParser->yystksz = 0;
if( yyGrowStack(yypParser) ){ if( yyGrowStack(pParser) ){
yypParser->yystack = &yypParser->yystk0; pParser->yystack = &pParser->yystk0;
yypParser->yystksz = 1; pParser->yystksz = 1;
} }
#endif #endif
#ifndef YYNOERRORRECOVERY #ifndef YYNOERRORRECOVERY
yypParser->yyerrcnt = -1; pParser->yyerrcnt = -1;
#endif #endif
yypParser->yytos = yypParser->yystack; pParser->yytos = pParser->yystack;
yypParser->yystack[0].stateno = 0; pParser->yystack[0].stateno = 0;
yypParser->yystack[0].major = 0; pParser->yystack[0].major = 0;
#if YYSTACKDEPTH>0 #if YYSTACKDEPTH>0
yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1];
#endif #endif
} }
...@@ -1429,14 +1362,11 @@ void ParseInit(void *yypRawParser ParseCTX_PDECL){ ...@@ -1429,14 +1362,11 @@ void ParseInit(void *yypRawParser ParseCTX_PDECL){
** A pointer to a parser. This pointer is used in subsequent calls ** A pointer to a parser. This pointer is used in subsequent calls
** to Parse and ParseFree. ** to Parse and ParseFree.
*/ */
void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){ void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
yyParser *yypParser; yyParser *pParser;
yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
if( yypParser ){ if( pParser ) ParseInit(pParser);
ParseCTX_STORE return pParser;
ParseInit(yypParser ParseCTX_PARAM);
}
return (void*)yypParser;
} }
#endif /* Parse_ENGINEALWAYSONSTACK */ #endif /* Parse_ENGINEALWAYSONSTACK */
...@@ -1453,8 +1383,7 @@ static void yy_destructor( ...@@ -1453,8 +1383,7 @@ static void yy_destructor(
YYCODETYPE yymajor, /* Type code for object to destroy */ YYCODETYPE yymajor, /* Type code for object to destroy */
YYMINORTYPE *yypminor /* The object to be destroyed */ YYMINORTYPE *yypminor /* The object to be destroyed */
){ ){
ParseARG_FETCH ParseARG_FETCH;
ParseCTX_FETCH
switch( yymajor ){ switch( yymajor ){
/* Here is inserted the actions which take place when a /* Here is inserted the actions which take place when a
** terminal or non-terminal is destroyed. This can happen ** terminal or non-terminal is destroyed. This can happen
...@@ -1467,52 +1396,52 @@ static void yy_destructor( ...@@ -1467,52 +1396,52 @@ static void yy_destructor(
** inside the C code. ** inside the C code.
*/ */
/********* Begin destructor definitions ***************************************/ /********* Begin destructor definitions ***************************************/
case 234: /* keep */ case 209: /* keep */
case 235: /* tagitemlist */ case 210: /* tagitemlist */
case 257: /* columnlist */ case 232: /* columnlist */
case 258: /* tagNamelist */ case 233: /* tagNamelist */
case 266: /* fill_opt */ case 241: /* fill_opt */
case 268: /* groupby_opt */ case 243: /* groupby_opt */
case 269: /* orderby_opt */ case 244: /* orderby_opt */
case 280: /* sortlist */ case 255: /* sortlist */
case 284: /* grouplist */ case 259: /* grouplist */
{ {
taosArrayDestroy((yypminor->yy207)); taosArrayDestroy((yypminor->yy429));
} }
break; break;
case 255: /* create_table_list */ case 230: /* create_table_list */
{ {
destroyCreateTableSql((yypminor->yy414)); destroyCreateTableSql((yypminor->yy310));
} }
break; break;
case 259: /* select */ case 234: /* select */
{ {
doDestroyQuerySql((yypminor->yy526)); doDestroyQuerySql((yypminor->yy372));
} }
break; break;
case 262: /* selcollist */ case 237: /* selcollist */
case 274: /* sclp */ case 249: /* sclp */
case 285: /* exprlist */ case 260: /* exprlist */
{ {
tSqlExprListDestroy((yypminor->yy178)); tSqlExprListDestroy((yypminor->yy170));
} }
break; break;
case 264: /* where_opt */ case 239: /* where_opt */
case 270: /* having_opt */ case 245: /* having_opt */
case 276: /* expr */ case 251: /* expr */
case 286: /* expritem */ case 261: /* expritem */
{ {
tSqlExprDestroy((yypminor->yy484)); tSqlExprDestroy((yypminor->yy282));
} }
break; break;
case 273: /* union */ case 248: /* union */
{ {
destroyAllSelectClause((yypminor->yy441)); destroyAllSelectClause((yypminor->yy141));
} }
break; break;
case 281: /* sortitem */ case 256: /* sortitem */
{ {
tVariantDestroy(&(yypminor->yy232)); tVariantDestroy(&(yypminor->yy218));
} }
break; break;
/********* End destructor definitions *****************************************/ /********* End destructor definitions *****************************************/
...@@ -1624,12 +1553,13 @@ int ParseCoverage(FILE *out){ ...@@ -1624,12 +1553,13 @@ int ParseCoverage(FILE *out){
** Find the appropriate action for a parser given the terminal ** Find the appropriate action for a parser given the terminal
** look-ahead token iLookAhead. ** look-ahead token iLookAhead.
*/ */
static YYACTIONTYPE yy_find_shift_action( static unsigned int yy_find_shift_action(
YYCODETYPE iLookAhead, /* The look-ahead token */ yyParser *pParser, /* The parser */
YYACTIONTYPE stateno /* Current state number */ YYCODETYPE iLookAhead /* The look-ahead token */
){ ){
int i; int i;
int stateno = pParser->yytos->stateno;
if( stateno>YY_MAX_SHIFT ) return stateno; if( stateno>YY_MAX_SHIFT ) return stateno;
assert( stateno <= YY_SHIFT_COUNT ); assert( stateno <= YY_SHIFT_COUNT );
#if defined(YYCOVERAGE) #if defined(YYCOVERAGE)
...@@ -1637,19 +1567,15 @@ static YYACTIONTYPE yy_find_shift_action( ...@@ -1637,19 +1567,15 @@ static YYACTIONTYPE yy_find_shift_action(
#endif #endif
do{ do{
i = yy_shift_ofst[stateno]; i = yy_shift_ofst[stateno];
assert( i>=0 ); assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
assert( i<=YY_ACTTAB_COUNT );
assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD );
assert( iLookAhead!=YYNOCODE ); assert( iLookAhead!=YYNOCODE );
assert( iLookAhead < YYNTOKEN ); assert( iLookAhead < YYNTOKEN );
i += iLookAhead; i += iLookAhead;
assert( i<(int)YY_NLOOKAHEAD );
if( yy_lookahead[i]!=iLookAhead ){ if( yy_lookahead[i]!=iLookAhead ){
#ifdef YYFALLBACK #ifdef YYFALLBACK
YYCODETYPE iFallback; /* Fallback token */ YYCODETYPE iFallback; /* Fallback token */
assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) ); if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
iFallback = yyFallback[iLookAhead]; && (iFallback = yyFallback[iLookAhead])!=0 ){
if( iFallback!=0 ){
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
...@@ -1664,8 +1590,15 @@ static YYACTIONTYPE yy_find_shift_action( ...@@ -1664,8 +1590,15 @@ static YYACTIONTYPE yy_find_shift_action(
#ifdef YYWILDCARD #ifdef YYWILDCARD
{ {
int j = i - iLookAhead + YYWILDCARD; int j = i - iLookAhead + YYWILDCARD;
assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); if(
if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ #if YY_SHIFT_MIN+YYWILDCARD<0
j>=0 &&
#endif
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
j<YY_ACTTAB_COUNT &&
#endif
yy_lookahead[j]==YYWILDCARD && iLookAhead>0
){
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
...@@ -1679,7 +1612,6 @@ static YYACTIONTYPE yy_find_shift_action( ...@@ -1679,7 +1612,6 @@ static YYACTIONTYPE yy_find_shift_action(
#endif /* YYWILDCARD */ #endif /* YYWILDCARD */
return yy_default[stateno]; return yy_default[stateno];
}else{ }else{
assert( i>=0 && i<sizeof(yy_action)/sizeof(yy_action[0]) );
return yy_action[i]; return yy_action[i];
} }
}while(1); }while(1);
...@@ -1689,8 +1621,8 @@ static YYACTIONTYPE yy_find_shift_action( ...@@ -1689,8 +1621,8 @@ static YYACTIONTYPE yy_find_shift_action(
** Find the appropriate action for a parser given the non-terminal ** Find the appropriate action for a parser given the non-terminal
** look-ahead token iLookAhead. ** look-ahead token iLookAhead.
*/ */
static YYACTIONTYPE yy_find_reduce_action( static int yy_find_reduce_action(
YYACTIONTYPE stateno, /* Current state number */ int stateno, /* Current state number */
YYCODETYPE iLookAhead /* The look-ahead token */ YYCODETYPE iLookAhead /* The look-ahead token */
){ ){
int i; int i;
...@@ -1719,8 +1651,7 @@ static YYACTIONTYPE yy_find_reduce_action( ...@@ -1719,8 +1651,7 @@ static YYACTIONTYPE yy_find_reduce_action(
** The following routine is called if the stack overflows. ** The following routine is called if the stack overflows.
*/ */
static void yyStackOverflow(yyParser *yypParser){ static void yyStackOverflow(yyParser *yypParser){
ParseARG_FETCH ParseARG_FETCH;
ParseCTX_FETCH
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
...@@ -1731,8 +1662,7 @@ static void yyStackOverflow(yyParser *yypParser){ ...@@ -1731,8 +1662,7 @@ static void yyStackOverflow(yyParser *yypParser){
** stack every overflows */ ** stack every overflows */
/******** Begin %stack_overflow code ******************************************/ /******** Begin %stack_overflow code ******************************************/
/******** End %stack_overflow code ********************************************/ /******** End %stack_overflow code ********************************************/
ParseARG_STORE /* Suppress warning about unused %extra_argument var */ ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
ParseCTX_STORE
} }
/* /*
...@@ -1761,8 +1691,8 @@ static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){ ...@@ -1761,8 +1691,8 @@ static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
*/ */
static void yy_shift( static void yy_shift(
yyParser *yypParser, /* The parser to be shifted */ yyParser *yypParser, /* The parser to be shifted */
YYACTIONTYPE yyNewState, /* The new state to shift in */ int yyNewState, /* The new state to shift in */
YYCODETYPE yyMajor, /* The major token to shift in */ int yyMajor, /* The major token to shift in */
ParseTOKENTYPE yyMinor /* The minor token to shift in */ ParseTOKENTYPE yyMinor /* The minor token to shift in */
){ ){
yyStackEntry *yytos; yyStackEntry *yytos;
...@@ -1792,546 +1722,282 @@ static void yy_shift( ...@@ -1792,546 +1722,282 @@ static void yy_shift(
yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
} }
yytos = yypParser->yytos; yytos = yypParser->yytos;
yytos->stateno = yyNewState; yytos->stateno = (YYACTIONTYPE)yyNewState;
yytos->major = yyMajor; yytos->major = (YYCODETYPE)yyMajor;
yytos->minor.yy0 = yyMinor; yytos->minor.yy0 = yyMinor;
yyTraceShift(yypParser, yyNewState, "Shift"); yyTraceShift(yypParser, yyNewState, "Shift");
} }
/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side /* The following table contains information about every rule that
** of that rule */ ** is used during the reduce.
static const YYCODETYPE yyRuleInfoLhs[] = { */
213, /* (0) program ::= cmd */ static const struct {
214, /* (1) cmd ::= SHOW DATABASES */ YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
214, /* (2) cmd ::= SHOW TOPICS */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */
214, /* (3) cmd ::= SHOW MNODES */ } yyRuleInfo[] = {
214, /* (4) cmd ::= SHOW DNODES */ { 188, -1 }, /* (0) program ::= cmd */
214, /* (5) cmd ::= SHOW ACCOUNTS */ { 189, -2 }, /* (1) cmd ::= SHOW DATABASES */
214, /* (6) cmd ::= SHOW USERS */ { 189, -2 }, /* (2) cmd ::= SHOW TOPICS */
214, /* (7) cmd ::= SHOW MODULES */ { 189, -2 }, /* (3) cmd ::= SHOW MNODES */
214, /* (8) cmd ::= SHOW QUERIES */ { 189, -2 }, /* (4) cmd ::= SHOW DNODES */
214, /* (9) cmd ::= SHOW CONNECTIONS */ { 189, -2 }, /* (5) cmd ::= SHOW ACCOUNTS */
214, /* (10) cmd ::= SHOW STREAMS */ { 189, -2 }, /* (6) cmd ::= SHOW USERS */
214, /* (11) cmd ::= SHOW VARIABLES */ { 189, -2 }, /* (7) cmd ::= SHOW MODULES */
214, /* (12) cmd ::= SHOW SCORES */ { 189, -2 }, /* (8) cmd ::= SHOW QUERIES */
214, /* (13) cmd ::= SHOW GRANTS */ { 189, -2 }, /* (9) cmd ::= SHOW CONNECTIONS */
214, /* (14) cmd ::= SHOW VNODES */ { 189, -2 }, /* (10) cmd ::= SHOW STREAMS */
214, /* (15) cmd ::= SHOW VNODES IPTOKEN */ { 189, -2 }, /* (11) cmd ::= SHOW VARIABLES */
215, /* (16) dbPrefix ::= */ { 189, -2 }, /* (12) cmd ::= SHOW SCORES */
215, /* (17) dbPrefix ::= ids DOT */ { 189, -2 }, /* (13) cmd ::= SHOW GRANTS */
217, /* (18) cpxName ::= */ { 189, -2 }, /* (14) cmd ::= SHOW VNODES */
217, /* (19) cpxName ::= DOT ids */ { 189, -3 }, /* (15) cmd ::= SHOW VNODES IPTOKEN */
214, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ { 190, 0 }, /* (16) dbPrefix ::= */
214, /* (21) cmd ::= SHOW CREATE DATABASE ids */ { 190, -2 }, /* (17) dbPrefix ::= ids DOT */
214, /* (22) cmd ::= SHOW dbPrefix TABLES */ { 192, 0 }, /* (18) cpxName ::= */
214, /* (23) cmd ::= SHOW dbPrefix TABLES LIKE ids */ { 192, -2 }, /* (19) cpxName ::= DOT ids */
214, /* (24) cmd ::= SHOW dbPrefix STABLES */ { 189, -5 }, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */
214, /* (25) cmd ::= SHOW dbPrefix STABLES LIKE ids */ { 189, -4 }, /* (21) cmd ::= SHOW CREATE DATABASE ids */
214, /* (26) cmd ::= SHOW dbPrefix VGROUPS */ { 189, -3 }, /* (22) cmd ::= SHOW dbPrefix TABLES */
214, /* (27) cmd ::= SHOW dbPrefix VGROUPS ids */ { 189, -5 }, /* (23) cmd ::= SHOW dbPrefix TABLES LIKE ids */
214, /* (28) cmd ::= DROP TABLE ifexists ids cpxName */ { 189, -3 }, /* (24) cmd ::= SHOW dbPrefix STABLES */
214, /* (29) cmd ::= DROP STABLE ifexists ids cpxName */ { 189, -5 }, /* (25) cmd ::= SHOW dbPrefix STABLES LIKE ids */
214, /* (30) cmd ::= DROP DATABASE ifexists ids */ { 189, -3 }, /* (26) cmd ::= SHOW dbPrefix VGROUPS */
214, /* (31) cmd ::= DROP TOPIC ifexists ids */ { 189, -4 }, /* (27) cmd ::= SHOW dbPrefix VGROUPS ids */
214, /* (32) cmd ::= DROP DNODE ids */ { 189, -5 }, /* (28) cmd ::= DROP TABLE ifexists ids cpxName */
214, /* (33) cmd ::= DROP USER ids */ { 189, -5 }, /* (29) cmd ::= DROP STABLE ifexists ids cpxName */
214, /* (34) cmd ::= DROP ACCOUNT ids */ { 189, -4 }, /* (30) cmd ::= DROP DATABASE ifexists ids */
214, /* (35) cmd ::= USE ids */ { 189, -4 }, /* (31) cmd ::= DROP TOPIC ifexists ids */
214, /* (36) cmd ::= DESCRIBE ids cpxName */ { 189, -3 }, /* (32) cmd ::= DROP DNODE ids */
214, /* (37) cmd ::= ALTER USER ids PASS ids */ { 189, -3 }, /* (33) cmd ::= DROP USER ids */
214, /* (38) cmd ::= ALTER USER ids PRIVILEGE ids */ { 189, -3 }, /* (34) cmd ::= DROP ACCOUNT ids */
214, /* (39) cmd ::= ALTER DNODE ids ids */ { 189, -2 }, /* (35) cmd ::= USE ids */
214, /* (40) cmd ::= ALTER DNODE ids ids ids */ { 189, -3 }, /* (36) cmd ::= DESCRIBE ids cpxName */
214, /* (41) cmd ::= ALTER LOCAL ids */ { 189, -5 }, /* (37) cmd ::= ALTER USER ids PASS ids */
214, /* (42) cmd ::= ALTER LOCAL ids ids */ { 189, -5 }, /* (38) cmd ::= ALTER USER ids PRIVILEGE ids */
214, /* (43) cmd ::= ALTER DATABASE ids alter_db_optr */ { 189, -4 }, /* (39) cmd ::= ALTER DNODE ids ids */
214, /* (44) cmd ::= ALTER TOPIC ids alter_topic_optr */ { 189, -5 }, /* (40) cmd ::= ALTER DNODE ids ids ids */
214, /* (45) cmd ::= ALTER ACCOUNT ids acct_optr */ { 189, -3 }, /* (41) cmd ::= ALTER LOCAL ids */
214, /* (46) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ { 189, -4 }, /* (42) cmd ::= ALTER LOCAL ids ids */
216, /* (47) ids ::= ID */ { 189, -4 }, /* (43) cmd ::= ALTER DATABASE ids alter_db_optr */
216, /* (48) ids ::= STRING */ { 189, -4 }, /* (44) cmd ::= ALTER TOPIC ids alter_topic_optr */
218, /* (49) ifexists ::= IF EXISTS */ { 189, -4 }, /* (45) cmd ::= ALTER ACCOUNT ids acct_optr */
218, /* (50) ifexists ::= */ { 189, -6 }, /* (46) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */
222, /* (51) ifnotexists ::= IF NOT EXISTS */ { 191, -1 }, /* (47) ids ::= ID */
222, /* (52) ifnotexists ::= */ { 191, -1 }, /* (48) ids ::= STRING */
214, /* (53) cmd ::= CREATE DNODE ids */ { 193, -2 }, /* (49) ifexists ::= IF EXISTS */
214, /* (54) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ { 193, 0 }, /* (50) ifexists ::= */
214, /* (55) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ { 197, -3 }, /* (51) ifnotexists ::= IF NOT EXISTS */
214, /* (56) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ { 197, 0 }, /* (52) ifnotexists ::= */
214, /* (57) cmd ::= CREATE USER ids PASS ids */ { 189, -3 }, /* (53) cmd ::= CREATE DNODE ids */
225, /* (58) pps ::= */ { 189, -6 }, /* (54) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */
225, /* (59) pps ::= PPS INTEGER */ { 189, -5 }, /* (55) cmd ::= CREATE DATABASE ifnotexists ids db_optr */
226, /* (60) tseries ::= */ { 189, -5 }, /* (56) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */
226, /* (61) tseries ::= TSERIES INTEGER */ { 189, -5 }, /* (57) cmd ::= CREATE USER ids PASS ids */
227, /* (62) dbs ::= */ { 200, 0 }, /* (58) pps ::= */
227, /* (63) dbs ::= DBS INTEGER */ { 200, -2 }, /* (59) pps ::= PPS INTEGER */
228, /* (64) streams ::= */ { 201, 0 }, /* (60) tseries ::= */
228, /* (65) streams ::= STREAMS INTEGER */ { 201, -2 }, /* (61) tseries ::= TSERIES INTEGER */
229, /* (66) storage ::= */ { 202, 0 }, /* (62) dbs ::= */
229, /* (67) storage ::= STORAGE INTEGER */ { 202, -2 }, /* (63) dbs ::= DBS INTEGER */
230, /* (68) qtime ::= */ { 203, 0 }, /* (64) streams ::= */
230, /* (69) qtime ::= QTIME INTEGER */ { 203, -2 }, /* (65) streams ::= STREAMS INTEGER */
231, /* (70) users ::= */ { 204, 0 }, /* (66) storage ::= */
231, /* (71) users ::= USERS INTEGER */ { 204, -2 }, /* (67) storage ::= STORAGE INTEGER */
232, /* (72) conns ::= */ { 205, 0 }, /* (68) qtime ::= */
232, /* (73) conns ::= CONNS INTEGER */ { 205, -2 }, /* (69) qtime ::= QTIME INTEGER */
233, /* (74) state ::= */ { 206, 0 }, /* (70) users ::= */
233, /* (75) state ::= STATE ids */ { 206, -2 }, /* (71) users ::= USERS INTEGER */
221, /* (76) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { 207, 0 }, /* (72) conns ::= */
234, /* (77) keep ::= KEEP tagitemlist */ { 207, -2 }, /* (73) conns ::= CONNS INTEGER */
236, /* (78) cache ::= CACHE INTEGER */ { 208, 0 }, /* (74) state ::= */
237, /* (79) replica ::= REPLICA INTEGER */ { 208, -2 }, /* (75) state ::= STATE ids */
238, /* (80) quorum ::= QUORUM INTEGER */ { 196, -9 }, /* (76) acct_optr ::= pps tseries storage streams qtime dbs users conns state */
239, /* (81) days ::= DAYS INTEGER */ { 209, -2 }, /* (77) keep ::= KEEP tagitemlist */
240, /* (82) minrows ::= MINROWS INTEGER */ { 211, -2 }, /* (78) cache ::= CACHE INTEGER */
241, /* (83) maxrows ::= MAXROWS INTEGER */ { 212, -2 }, /* (79) replica ::= REPLICA INTEGER */
242, /* (84) blocks ::= BLOCKS INTEGER */ { 213, -2 }, /* (80) quorum ::= QUORUM INTEGER */
243, /* (85) ctime ::= CTIME INTEGER */ { 214, -2 }, /* (81) days ::= DAYS INTEGER */
244, /* (86) wal ::= WAL INTEGER */ { 215, -2 }, /* (82) minrows ::= MINROWS INTEGER */
245, /* (87) fsync ::= FSYNC INTEGER */ { 216, -2 }, /* (83) maxrows ::= MAXROWS INTEGER */
246, /* (88) comp ::= COMP INTEGER */ { 217, -2 }, /* (84) blocks ::= BLOCKS INTEGER */
247, /* (89) prec ::= PRECISION STRING */ { 218, -2 }, /* (85) ctime ::= CTIME INTEGER */
248, /* (90) update ::= UPDATE INTEGER */ { 219, -2 }, /* (86) wal ::= WAL INTEGER */
249, /* (91) cachelast ::= CACHELAST INTEGER */ { 220, -2 }, /* (87) fsync ::= FSYNC INTEGER */
250, /* (92) partitions ::= PARTITIONS INTEGER */ { 221, -2 }, /* (88) comp ::= COMP INTEGER */
223, /* (93) db_optr ::= */ { 222, -2 }, /* (89) prec ::= PRECISION STRING */
223, /* (94) db_optr ::= db_optr cache */ { 223, -2 }, /* (90) update ::= UPDATE INTEGER */
223, /* (95) db_optr ::= db_optr replica */ { 224, -2 }, /* (91) cachelast ::= CACHELAST INTEGER */
223, /* (96) db_optr ::= db_optr quorum */ { 225, -2 }, /* (92) partitions ::= PARTITIONS INTEGER */
223, /* (97) db_optr ::= db_optr days */ { 198, 0 }, /* (93) db_optr ::= */
223, /* (98) db_optr ::= db_optr minrows */ { 198, -2 }, /* (94) db_optr ::= db_optr cache */
223, /* (99) db_optr ::= db_optr maxrows */ { 198, -2 }, /* (95) db_optr ::= db_optr replica */
223, /* (100) db_optr ::= db_optr blocks */ { 198, -2 }, /* (96) db_optr ::= db_optr quorum */
223, /* (101) db_optr ::= db_optr ctime */ { 198, -2 }, /* (97) db_optr ::= db_optr days */
223, /* (102) db_optr ::= db_optr wal */ { 198, -2 }, /* (98) db_optr ::= db_optr minrows */
223, /* (103) db_optr ::= db_optr fsync */ { 198, -2 }, /* (99) db_optr ::= db_optr maxrows */
223, /* (104) db_optr ::= db_optr comp */ { 198, -2 }, /* (100) db_optr ::= db_optr blocks */
223, /* (105) db_optr ::= db_optr prec */ { 198, -2 }, /* (101) db_optr ::= db_optr ctime */
223, /* (106) db_optr ::= db_optr keep */ { 198, -2 }, /* (102) db_optr ::= db_optr wal */
223, /* (107) db_optr ::= db_optr update */ { 198, -2 }, /* (103) db_optr ::= db_optr fsync */
223, /* (108) db_optr ::= db_optr cachelast */ { 198, -2 }, /* (104) db_optr ::= db_optr comp */
224, /* (109) topic_optr ::= db_optr */ { 198, -2 }, /* (105) db_optr ::= db_optr prec */
224, /* (110) topic_optr ::= topic_optr partitions */ { 198, -2 }, /* (106) db_optr ::= db_optr keep */
219, /* (111) alter_db_optr ::= */ { 198, -2 }, /* (107) db_optr ::= db_optr update */
219, /* (112) alter_db_optr ::= alter_db_optr replica */ { 198, -2 }, /* (108) db_optr ::= db_optr cachelast */
219, /* (113) alter_db_optr ::= alter_db_optr quorum */ { 199, -1 }, /* (109) topic_optr ::= db_optr */
219, /* (114) alter_db_optr ::= alter_db_optr keep */ { 199, -2 }, /* (110) topic_optr ::= topic_optr partitions */
219, /* (115) alter_db_optr ::= alter_db_optr blocks */ { 194, 0 }, /* (111) alter_db_optr ::= */
219, /* (116) alter_db_optr ::= alter_db_optr comp */ { 194, -2 }, /* (112) alter_db_optr ::= alter_db_optr replica */
219, /* (117) alter_db_optr ::= alter_db_optr wal */ { 194, -2 }, /* (113) alter_db_optr ::= alter_db_optr quorum */
219, /* (118) alter_db_optr ::= alter_db_optr fsync */ { 194, -2 }, /* (114) alter_db_optr ::= alter_db_optr keep */
219, /* (119) alter_db_optr ::= alter_db_optr update */ { 194, -2 }, /* (115) alter_db_optr ::= alter_db_optr blocks */
219, /* (120) alter_db_optr ::= alter_db_optr cachelast */ { 194, -2 }, /* (116) alter_db_optr ::= alter_db_optr comp */
220, /* (121) alter_topic_optr ::= alter_db_optr */ { 194, -2 }, /* (117) alter_db_optr ::= alter_db_optr wal */
220, /* (122) alter_topic_optr ::= alter_topic_optr partitions */ { 194, -2 }, /* (118) alter_db_optr ::= alter_db_optr fsync */
251, /* (123) typename ::= ids */ { 194, -2 }, /* (119) alter_db_optr ::= alter_db_optr update */
251, /* (124) typename ::= ids LP signed RP */ { 194, -2 }, /* (120) alter_db_optr ::= alter_db_optr cachelast */
251, /* (125) typename ::= ids UNSIGNED */ { 195, -1 }, /* (121) alter_topic_optr ::= alter_db_optr */
252, /* (126) signed ::= INTEGER */ { 195, -2 }, /* (122) alter_topic_optr ::= alter_topic_optr partitions */
252, /* (127) signed ::= PLUS INTEGER */ { 226, -1 }, /* (123) typename ::= ids */
252, /* (128) signed ::= MINUS INTEGER */ { 226, -4 }, /* (124) typename ::= ids LP signed RP */
214, /* (129) cmd ::= CREATE TABLE create_table_args */ { 226, -2 }, /* (125) typename ::= ids UNSIGNED */
214, /* (130) cmd ::= CREATE TABLE create_stable_args */ { 227, -1 }, /* (126) signed ::= INTEGER */
214, /* (131) cmd ::= CREATE STABLE create_stable_args */ { 227, -2 }, /* (127) signed ::= PLUS INTEGER */
214, /* (132) cmd ::= CREATE TABLE create_table_list */ { 227, -2 }, /* (128) signed ::= MINUS INTEGER */
255, /* (133) create_table_list ::= create_from_stable */ { 189, -3 }, /* (129) cmd ::= CREATE TABLE create_table_args */
255, /* (134) create_table_list ::= create_table_list create_from_stable */ { 189, -3 }, /* (130) cmd ::= CREATE TABLE create_stable_args */
253, /* (135) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { 189, -3 }, /* (131) cmd ::= CREATE STABLE create_stable_args */
254, /* (136) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { 189, -3 }, /* (132) cmd ::= CREATE TABLE create_table_list */
256, /* (137) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ { 230, -1 }, /* (133) create_table_list ::= create_from_stable */
256, /* (138) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ { 230, -2 }, /* (134) create_table_list ::= create_table_list create_from_stable */
258, /* (139) tagNamelist ::= tagNamelist COMMA ids */ { 228, -6 }, /* (135) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */
258, /* (140) tagNamelist ::= ids */ { 229, -10 }, /* (136) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */
253, /* (141) create_table_args ::= ifnotexists ids cpxName AS select */ { 231, -10 }, /* (137) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */
257, /* (142) columnlist ::= columnlist COMMA column */ { 231, -13 }, /* (138) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */
257, /* (143) columnlist ::= column */ { 233, -3 }, /* (139) tagNamelist ::= tagNamelist COMMA ids */
260, /* (144) column ::= ids typename */ { 233, -1 }, /* (140) tagNamelist ::= ids */
235, /* (145) tagitemlist ::= tagitemlist COMMA tagitem */ { 228, -5 }, /* (141) create_table_args ::= ifnotexists ids cpxName AS select */
235, /* (146) tagitemlist ::= tagitem */ { 232, -3 }, /* (142) columnlist ::= columnlist COMMA column */
261, /* (147) tagitem ::= INTEGER */ { 232, -1 }, /* (143) columnlist ::= column */
261, /* (148) tagitem ::= FLOAT */ { 235, -2 }, /* (144) column ::= ids typename */
261, /* (149) tagitem ::= STRING */ { 210, -3 }, /* (145) tagitemlist ::= tagitemlist COMMA tagitem */
261, /* (150) tagitem ::= BOOL */ { 210, -1 }, /* (146) tagitemlist ::= tagitem */
261, /* (151) tagitem ::= NULL */ { 236, -1 }, /* (147) tagitem ::= INTEGER */
261, /* (152) tagitem ::= MINUS INTEGER */ { 236, -1 }, /* (148) tagitem ::= FLOAT */
261, /* (153) tagitem ::= MINUS FLOAT */ { 236, -1 }, /* (149) tagitem ::= STRING */
261, /* (154) tagitem ::= PLUS INTEGER */ { 236, -1 }, /* (150) tagitem ::= BOOL */
261, /* (155) tagitem ::= PLUS FLOAT */ { 236, -1 }, /* (151) tagitem ::= NULL */
259, /* (156) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ { 236, -2 }, /* (152) tagitem ::= MINUS INTEGER */
273, /* (157) union ::= select */ { 236, -2 }, /* (153) tagitem ::= MINUS FLOAT */
273, /* (158) union ::= LP union RP */ { 236, -2 }, /* (154) tagitem ::= PLUS INTEGER */
273, /* (159) union ::= union UNION ALL select */ { 236, -2 }, /* (155) tagitem ::= PLUS FLOAT */
273, /* (160) union ::= union UNION ALL LP select RP */ { 234, -12 }, /* (156) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
214, /* (161) cmd ::= union */ { 248, -1 }, /* (157) union ::= select */
259, /* (162) select ::= SELECT selcollist */ { 248, -3 }, /* (158) union ::= LP union RP */
274, /* (163) sclp ::= selcollist COMMA */ { 248, -4 }, /* (159) union ::= union UNION ALL select */
274, /* (164) sclp ::= */ { 248, -6 }, /* (160) union ::= union UNION ALL LP select RP */
262, /* (165) selcollist ::= sclp distinct expr as */ { 189, -1 }, /* (161) cmd ::= union */
262, /* (166) selcollist ::= sclp STAR */ { 234, -2 }, /* (162) select ::= SELECT selcollist */
277, /* (167) as ::= AS ids */ { 249, -2 }, /* (163) sclp ::= selcollist COMMA */
277, /* (168) as ::= ids */ { 249, 0 }, /* (164) sclp ::= */
277, /* (169) as ::= */ { 237, -4 }, /* (165) selcollist ::= sclp distinct expr as */
275, /* (170) distinct ::= DISTINCT */ { 237, -2 }, /* (166) selcollist ::= sclp STAR */
275, /* (171) distinct ::= */ { 252, -2 }, /* (167) as ::= AS ids */
263, /* (172) from ::= FROM tablelist */ { 252, -1 }, /* (168) as ::= ids */
278, /* (173) tablelist ::= ids cpxName */ { 252, 0 }, /* (169) as ::= */
278, /* (174) tablelist ::= ids cpxName ids */ { 250, -1 }, /* (170) distinct ::= DISTINCT */
278, /* (175) tablelist ::= tablelist COMMA ids cpxName */ { 250, 0 }, /* (171) distinct ::= */
278, /* (176) tablelist ::= tablelist COMMA ids cpxName ids */ { 238, -2 }, /* (172) from ::= FROM tablelist */
279, /* (177) tmvar ::= VARIABLE */ { 253, -2 }, /* (173) tablelist ::= ids cpxName */
265, /* (178) interval_opt ::= INTERVAL LP tmvar RP */ { 253, -3 }, /* (174) tablelist ::= ids cpxName ids */
265, /* (179) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ { 253, -4 }, /* (175) tablelist ::= tablelist COMMA ids cpxName */
265, /* (180) interval_opt ::= */ { 253, -5 }, /* (176) tablelist ::= tablelist COMMA ids cpxName ids */
266, /* (181) fill_opt ::= */ { 254, -1 }, /* (177) tmvar ::= VARIABLE */
266, /* (182) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { 240, -4 }, /* (178) interval_opt ::= INTERVAL LP tmvar RP */
266, /* (183) fill_opt ::= FILL LP ID RP */ { 240, -6 }, /* (179) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */
267, /* (184) sliding_opt ::= SLIDING LP tmvar RP */ { 240, 0 }, /* (180) interval_opt ::= */
267, /* (185) sliding_opt ::= */ { 241, 0 }, /* (181) fill_opt ::= */
269, /* (186) orderby_opt ::= */ { 241, -6 }, /* (182) fill_opt ::= FILL LP ID COMMA tagitemlist RP */
269, /* (187) orderby_opt ::= ORDER BY sortlist */ { 241, -4 }, /* (183) fill_opt ::= FILL LP ID RP */
280, /* (188) sortlist ::= sortlist COMMA item sortorder */ { 242, -4 }, /* (184) sliding_opt ::= SLIDING LP tmvar RP */
280, /* (189) sortlist ::= item sortorder */ { 242, 0 }, /* (185) sliding_opt ::= */
282, /* (190) item ::= ids cpxName */ { 244, 0 }, /* (186) orderby_opt ::= */
283, /* (191) sortorder ::= ASC */ { 244, -3 }, /* (187) orderby_opt ::= ORDER BY sortlist */
283, /* (192) sortorder ::= DESC */ { 255, -4 }, /* (188) sortlist ::= sortlist COMMA item sortorder */
283, /* (193) sortorder ::= */ { 255, -2 }, /* (189) sortlist ::= item sortorder */
268, /* (194) groupby_opt ::= */ { 257, -2 }, /* (190) item ::= ids cpxName */
268, /* (195) groupby_opt ::= GROUP BY grouplist */ { 258, -1 }, /* (191) sortorder ::= ASC */
284, /* (196) grouplist ::= grouplist COMMA item */ { 258, -1 }, /* (192) sortorder ::= DESC */
284, /* (197) grouplist ::= item */ { 258, 0 }, /* (193) sortorder ::= */
270, /* (198) having_opt ::= */ { 243, 0 }, /* (194) groupby_opt ::= */
270, /* (199) having_opt ::= HAVING expr */ { 243, -3 }, /* (195) groupby_opt ::= GROUP BY grouplist */
272, /* (200) limit_opt ::= */ { 259, -3 }, /* (196) grouplist ::= grouplist COMMA item */
272, /* (201) limit_opt ::= LIMIT signed */ { 259, -1 }, /* (197) grouplist ::= item */
272, /* (202) limit_opt ::= LIMIT signed OFFSET signed */ { 245, 0 }, /* (198) having_opt ::= */
272, /* (203) limit_opt ::= LIMIT signed COMMA signed */ { 245, -2 }, /* (199) having_opt ::= HAVING expr */
271, /* (204) slimit_opt ::= */ { 247, 0 }, /* (200) limit_opt ::= */
271, /* (205) slimit_opt ::= SLIMIT signed */ { 247, -2 }, /* (201) limit_opt ::= LIMIT signed */
271, /* (206) slimit_opt ::= SLIMIT signed SOFFSET signed */ { 247, -4 }, /* (202) limit_opt ::= LIMIT signed OFFSET signed */
271, /* (207) slimit_opt ::= SLIMIT signed COMMA signed */ { 247, -4 }, /* (203) limit_opt ::= LIMIT signed COMMA signed */
264, /* (208) where_opt ::= */ { 246, 0 }, /* (204) slimit_opt ::= */
264, /* (209) where_opt ::= WHERE expr */ { 246, -2 }, /* (205) slimit_opt ::= SLIMIT signed */
276, /* (210) expr ::= LP expr RP */ { 246, -4 }, /* (206) slimit_opt ::= SLIMIT signed SOFFSET signed */
276, /* (211) expr ::= ID */ { 246, -4 }, /* (207) slimit_opt ::= SLIMIT signed COMMA signed */
276, /* (212) expr ::= ID DOT ID */ { 239, 0 }, /* (208) where_opt ::= */
276, /* (213) expr ::= ID DOT STAR */ { 239, -2 }, /* (209) where_opt ::= WHERE expr */
276, /* (214) expr ::= INTEGER */ { 251, -3 }, /* (210) expr ::= LP expr RP */
276, /* (215) expr ::= MINUS INTEGER */ { 251, -1 }, /* (211) expr ::= ID */
276, /* (216) expr ::= PLUS INTEGER */ { 251, -3 }, /* (212) expr ::= ID DOT ID */
276, /* (217) expr ::= FLOAT */ { 251, -3 }, /* (213) expr ::= ID DOT STAR */
276, /* (218) expr ::= MINUS FLOAT */ { 251, -1 }, /* (214) expr ::= INTEGER */
276, /* (219) expr ::= PLUS FLOAT */ { 251, -2 }, /* (215) expr ::= MINUS INTEGER */
276, /* (220) expr ::= STRING */ { 251, -2 }, /* (216) expr ::= PLUS INTEGER */
276, /* (221) expr ::= NOW */ { 251, -1 }, /* (217) expr ::= FLOAT */
276, /* (222) expr ::= VARIABLE */ { 251, -2 }, /* (218) expr ::= MINUS FLOAT */
276, /* (223) expr ::= BOOL */ { 251, -2 }, /* (219) expr ::= PLUS FLOAT */
276, /* (224) expr ::= ID LP exprlist RP */ { 251, -1 }, /* (220) expr ::= STRING */
276, /* (225) expr ::= ID LP STAR RP */ { 251, -1 }, /* (221) expr ::= NOW */
276, /* (226) expr ::= expr IS NULL */ { 251, -1 }, /* (222) expr ::= VARIABLE */
276, /* (227) expr ::= expr IS NOT NULL */ { 251, -1 }, /* (223) expr ::= BOOL */
276, /* (228) expr ::= expr LT expr */ { 251, -4 }, /* (224) expr ::= ID LP exprlist RP */
276, /* (229) expr ::= expr GT expr */ { 251, -4 }, /* (225) expr ::= ID LP STAR RP */
276, /* (230) expr ::= expr LE expr */ { 251, -3 }, /* (226) expr ::= expr IS NULL */
276, /* (231) expr ::= expr GE expr */ { 251, -4 }, /* (227) expr ::= expr IS NOT NULL */
276, /* (232) expr ::= expr NE expr */ { 251, -3 }, /* (228) expr ::= expr LT expr */
276, /* (233) expr ::= expr EQ expr */ { 251, -3 }, /* (229) expr ::= expr GT expr */
276, /* (234) expr ::= expr BETWEEN expr AND expr */ { 251, -3 }, /* (230) expr ::= expr LE expr */
276, /* (235) expr ::= expr AND expr */ { 251, -3 }, /* (231) expr ::= expr GE expr */
276, /* (236) expr ::= expr OR expr */ { 251, -3 }, /* (232) expr ::= expr NE expr */
276, /* (237) expr ::= expr PLUS expr */ { 251, -3 }, /* (233) expr ::= expr EQ expr */
276, /* (238) expr ::= expr MINUS expr */ { 251, -5 }, /* (234) expr ::= expr BETWEEN expr AND expr */
276, /* (239) expr ::= expr STAR expr */ { 251, -3 }, /* (235) expr ::= expr AND expr */
276, /* (240) expr ::= expr SLASH expr */ { 251, -3 }, /* (236) expr ::= expr OR expr */
276, /* (241) expr ::= expr REM expr */ { 251, -3 }, /* (237) expr ::= expr PLUS expr */
276, /* (242) expr ::= expr LIKE expr */ { 251, -3 }, /* (238) expr ::= expr MINUS expr */
276, /* (243) expr ::= expr IN LP exprlist RP */ { 251, -3 }, /* (239) expr ::= expr STAR expr */
285, /* (244) exprlist ::= exprlist COMMA expritem */ { 251, -3 }, /* (240) expr ::= expr SLASH expr */
285, /* (245) exprlist ::= expritem */ { 251, -3 }, /* (241) expr ::= expr REM expr */
286, /* (246) expritem ::= expr */ { 251, -3 }, /* (242) expr ::= expr LIKE expr */
286, /* (247) expritem ::= */ { 251, -5 }, /* (243) expr ::= expr IN LP exprlist RP */
214, /* (248) cmd ::= RESET QUERY CACHE */ { 260, -3 }, /* (244) exprlist ::= exprlist COMMA expritem */
214, /* (249) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { 260, -1 }, /* (245) exprlist ::= expritem */
214, /* (250) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { 261, -1 }, /* (246) expritem ::= expr */
214, /* (251) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { 261, 0 }, /* (247) expritem ::= */
214, /* (252) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { 189, -3 }, /* (248) cmd ::= RESET QUERY CACHE */
214, /* (253) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { 189, -7 }, /* (249) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
214, /* (254) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { 189, -7 }, /* (250) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */
214, /* (255) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { 189, -7 }, /* (251) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
214, /* (256) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { 189, -7 }, /* (252) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */
214, /* (257) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { 189, -8 }, /* (253) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */
214, /* (258) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { 189, -9 }, /* (254) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */
214, /* (259) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { 189, -7 }, /* (255) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */
214, /* (260) cmd ::= KILL CONNECTION INTEGER */ { 189, -7 }, /* (256) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */
214, /* (261) cmd ::= KILL STREAM INTEGER COLON INTEGER */ { 189, -7 }, /* (257) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */
214, /* (262) cmd ::= KILL QUERY INTEGER COLON INTEGER */ { 189, -7 }, /* (258) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */
}; { 189, -8 }, /* (259) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */
{ 189, -3 }, /* (260) cmd ::= KILL CONNECTION INTEGER */
/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number { 189, -5 }, /* (261) cmd ::= KILL STREAM INTEGER COLON INTEGER */
** of symbols on the right-hand side of that rule. */ { 189, -5 }, /* (262) cmd ::= KILL QUERY INTEGER COLON INTEGER */
static const signed char yyRuleInfoNRhs[] = {
-1, /* (0) program ::= cmd */
-2, /* (1) cmd ::= SHOW DATABASES */
-2, /* (2) cmd ::= SHOW TOPICS */
-2, /* (3) cmd ::= SHOW MNODES */
-2, /* (4) cmd ::= SHOW DNODES */
-2, /* (5) cmd ::= SHOW ACCOUNTS */
-2, /* (6) cmd ::= SHOW USERS */
-2, /* (7) cmd ::= SHOW MODULES */
-2, /* (8) cmd ::= SHOW QUERIES */
-2, /* (9) cmd ::= SHOW CONNECTIONS */
-2, /* (10) cmd ::= SHOW STREAMS */
-2, /* (11) cmd ::= SHOW VARIABLES */
-2, /* (12) cmd ::= SHOW SCORES */
-2, /* (13) cmd ::= SHOW GRANTS */
-2, /* (14) cmd ::= SHOW VNODES */
-3, /* (15) cmd ::= SHOW VNODES IPTOKEN */
0, /* (16) dbPrefix ::= */
-2, /* (17) dbPrefix ::= ids DOT */
0, /* (18) cpxName ::= */
-2, /* (19) cpxName ::= DOT ids */
-5, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */
-4, /* (21) cmd ::= SHOW CREATE DATABASE ids */
-3, /* (22) cmd ::= SHOW dbPrefix TABLES */
-5, /* (23) cmd ::= SHOW dbPrefix TABLES LIKE ids */
-3, /* (24) cmd ::= SHOW dbPrefix STABLES */
-5, /* (25) cmd ::= SHOW dbPrefix STABLES LIKE ids */
-3, /* (26) cmd ::= SHOW dbPrefix VGROUPS */
-4, /* (27) cmd ::= SHOW dbPrefix VGROUPS ids */
-5, /* (28) cmd ::= DROP TABLE ifexists ids cpxName */
-5, /* (29) cmd ::= DROP STABLE ifexists ids cpxName */
-4, /* (30) cmd ::= DROP DATABASE ifexists ids */
-4, /* (31) cmd ::= DROP TOPIC ifexists ids */
-3, /* (32) cmd ::= DROP DNODE ids */
-3, /* (33) cmd ::= DROP USER ids */
-3, /* (34) cmd ::= DROP ACCOUNT ids */
-2, /* (35) cmd ::= USE ids */
-3, /* (36) cmd ::= DESCRIBE ids cpxName */
-5, /* (37) cmd ::= ALTER USER ids PASS ids */
-5, /* (38) cmd ::= ALTER USER ids PRIVILEGE ids */
-4, /* (39) cmd ::= ALTER DNODE ids ids */
-5, /* (40) cmd ::= ALTER DNODE ids ids ids */
-3, /* (41) cmd ::= ALTER LOCAL ids */
-4, /* (42) cmd ::= ALTER LOCAL ids ids */
-4, /* (43) cmd ::= ALTER DATABASE ids alter_db_optr */
-4, /* (44) cmd ::= ALTER TOPIC ids alter_topic_optr */
-4, /* (45) cmd ::= ALTER ACCOUNT ids acct_optr */
-6, /* (46) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */
-1, /* (47) ids ::= ID */
-1, /* (48) ids ::= STRING */
-2, /* (49) ifexists ::= IF EXISTS */
0, /* (50) ifexists ::= */
-3, /* (51) ifnotexists ::= IF NOT EXISTS */
0, /* (52) ifnotexists ::= */
-3, /* (53) cmd ::= CREATE DNODE ids */
-6, /* (54) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */
-5, /* (55) cmd ::= CREATE DATABASE ifnotexists ids db_optr */
-5, /* (56) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */
-5, /* (57) cmd ::= CREATE USER ids PASS ids */
0, /* (58) pps ::= */
-2, /* (59) pps ::= PPS INTEGER */
0, /* (60) tseries ::= */
-2, /* (61) tseries ::= TSERIES INTEGER */
0, /* (62) dbs ::= */
-2, /* (63) dbs ::= DBS INTEGER */
0, /* (64) streams ::= */
-2, /* (65) streams ::= STREAMS INTEGER */
0, /* (66) storage ::= */
-2, /* (67) storage ::= STORAGE INTEGER */
0, /* (68) qtime ::= */
-2, /* (69) qtime ::= QTIME INTEGER */
0, /* (70) users ::= */
-2, /* (71) users ::= USERS INTEGER */
0, /* (72) conns ::= */
-2, /* (73) conns ::= CONNS INTEGER */
0, /* (74) state ::= */
-2, /* (75) state ::= STATE ids */
-9, /* (76) acct_optr ::= pps tseries storage streams qtime dbs users conns state */
-2, /* (77) keep ::= KEEP tagitemlist */
-2, /* (78) cache ::= CACHE INTEGER */
-2, /* (79) replica ::= REPLICA INTEGER */
-2, /* (80) quorum ::= QUORUM INTEGER */
-2, /* (81) days ::= DAYS INTEGER */
-2, /* (82) minrows ::= MINROWS INTEGER */
-2, /* (83) maxrows ::= MAXROWS INTEGER */
-2, /* (84) blocks ::= BLOCKS INTEGER */
-2, /* (85) ctime ::= CTIME INTEGER */
-2, /* (86) wal ::= WAL INTEGER */
-2, /* (87) fsync ::= FSYNC INTEGER */
-2, /* (88) comp ::= COMP INTEGER */
-2, /* (89) prec ::= PRECISION STRING */
-2, /* (90) update ::= UPDATE INTEGER */
-2, /* (91) cachelast ::= CACHELAST INTEGER */
-2, /* (92) partitions ::= PARTITIONS INTEGER */
0, /* (93) db_optr ::= */
-2, /* (94) db_optr ::= db_optr cache */
-2, /* (95) db_optr ::= db_optr replica */
-2, /* (96) db_optr ::= db_optr quorum */
-2, /* (97) db_optr ::= db_optr days */
-2, /* (98) db_optr ::= db_optr minrows */
-2, /* (99) db_optr ::= db_optr maxrows */
-2, /* (100) db_optr ::= db_optr blocks */
-2, /* (101) db_optr ::= db_optr ctime */
-2, /* (102) db_optr ::= db_optr wal */
-2, /* (103) db_optr ::= db_optr fsync */
-2, /* (104) db_optr ::= db_optr comp */
-2, /* (105) db_optr ::= db_optr prec */
-2, /* (106) db_optr ::= db_optr keep */
-2, /* (107) db_optr ::= db_optr update */
-2, /* (108) db_optr ::= db_optr cachelast */
-1, /* (109) topic_optr ::= db_optr */
-2, /* (110) topic_optr ::= topic_optr partitions */
0, /* (111) alter_db_optr ::= */
-2, /* (112) alter_db_optr ::= alter_db_optr replica */
-2, /* (113) alter_db_optr ::= alter_db_optr quorum */
-2, /* (114) alter_db_optr ::= alter_db_optr keep */
-2, /* (115) alter_db_optr ::= alter_db_optr blocks */
-2, /* (116) alter_db_optr ::= alter_db_optr comp */
-2, /* (117) alter_db_optr ::= alter_db_optr wal */
-2, /* (118) alter_db_optr ::= alter_db_optr fsync */
-2, /* (119) alter_db_optr ::= alter_db_optr update */
-2, /* (120) alter_db_optr ::= alter_db_optr cachelast */
-1, /* (121) alter_topic_optr ::= alter_db_optr */
-2, /* (122) alter_topic_optr ::= alter_topic_optr partitions */
-1, /* (123) typename ::= ids */
-4, /* (124) typename ::= ids LP signed RP */
-2, /* (125) typename ::= ids UNSIGNED */
-1, /* (126) signed ::= INTEGER */
-2, /* (127) signed ::= PLUS INTEGER */
-2, /* (128) signed ::= MINUS INTEGER */
-3, /* (129) cmd ::= CREATE TABLE create_table_args */
-3, /* (130) cmd ::= CREATE TABLE create_stable_args */
-3, /* (131) cmd ::= CREATE STABLE create_stable_args */
-3, /* (132) cmd ::= CREATE TABLE create_table_list */
-1, /* (133) create_table_list ::= create_from_stable */
-2, /* (134) create_table_list ::= create_table_list create_from_stable */
-6, /* (135) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */
-10, /* (136) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */
-10, /* (137) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */
-13, /* (138) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */
-3, /* (139) tagNamelist ::= tagNamelist COMMA ids */
-1, /* (140) tagNamelist ::= ids */
-5, /* (141) create_table_args ::= ifnotexists ids cpxName AS select */
-3, /* (142) columnlist ::= columnlist COMMA column */
-1, /* (143) columnlist ::= column */
-2, /* (144) column ::= ids typename */
-3, /* (145) tagitemlist ::= tagitemlist COMMA tagitem */
-1, /* (146) tagitemlist ::= tagitem */
-1, /* (147) tagitem ::= INTEGER */
-1, /* (148) tagitem ::= FLOAT */
-1, /* (149) tagitem ::= STRING */
-1, /* (150) tagitem ::= BOOL */
-1, /* (151) tagitem ::= NULL */
-2, /* (152) tagitem ::= MINUS INTEGER */
-2, /* (153) tagitem ::= MINUS FLOAT */
-2, /* (154) tagitem ::= PLUS INTEGER */
-2, /* (155) tagitem ::= PLUS FLOAT */
-12, /* (156) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
-1, /* (157) union ::= select */
-3, /* (158) union ::= LP union RP */
-4, /* (159) union ::= union UNION ALL select */
-6, /* (160) union ::= union UNION ALL LP select RP */
-1, /* (161) cmd ::= union */
-2, /* (162) select ::= SELECT selcollist */
-2, /* (163) sclp ::= selcollist COMMA */
0, /* (164) sclp ::= */
-4, /* (165) selcollist ::= sclp distinct expr as */
-2, /* (166) selcollist ::= sclp STAR */
-2, /* (167) as ::= AS ids */
-1, /* (168) as ::= ids */
0, /* (169) as ::= */
-1, /* (170) distinct ::= DISTINCT */
0, /* (171) distinct ::= */
-2, /* (172) from ::= FROM tablelist */
-2, /* (173) tablelist ::= ids cpxName */
-3, /* (174) tablelist ::= ids cpxName ids */
-4, /* (175) tablelist ::= tablelist COMMA ids cpxName */
-5, /* (176) tablelist ::= tablelist COMMA ids cpxName ids */
-1, /* (177) tmvar ::= VARIABLE */
-4, /* (178) interval_opt ::= INTERVAL LP tmvar RP */
-6, /* (179) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */
0, /* (180) interval_opt ::= */
0, /* (181) fill_opt ::= */
-6, /* (182) fill_opt ::= FILL LP ID COMMA tagitemlist RP */
-4, /* (183) fill_opt ::= FILL LP ID RP */
-4, /* (184) sliding_opt ::= SLIDING LP tmvar RP */
0, /* (185) sliding_opt ::= */
0, /* (186) orderby_opt ::= */
-3, /* (187) orderby_opt ::= ORDER BY sortlist */
-4, /* (188) sortlist ::= sortlist COMMA item sortorder */
-2, /* (189) sortlist ::= item sortorder */
-2, /* (190) item ::= ids cpxName */
-1, /* (191) sortorder ::= ASC */
-1, /* (192) sortorder ::= DESC */
0, /* (193) sortorder ::= */
0, /* (194) groupby_opt ::= */
-3, /* (195) groupby_opt ::= GROUP BY grouplist */
-3, /* (196) grouplist ::= grouplist COMMA item */
-1, /* (197) grouplist ::= item */
0, /* (198) having_opt ::= */
-2, /* (199) having_opt ::= HAVING expr */
0, /* (200) limit_opt ::= */
-2, /* (201) limit_opt ::= LIMIT signed */
-4, /* (202) limit_opt ::= LIMIT signed OFFSET signed */
-4, /* (203) limit_opt ::= LIMIT signed COMMA signed */
0, /* (204) slimit_opt ::= */
-2, /* (205) slimit_opt ::= SLIMIT signed */
-4, /* (206) slimit_opt ::= SLIMIT signed SOFFSET signed */
-4, /* (207) slimit_opt ::= SLIMIT signed COMMA signed */
0, /* (208) where_opt ::= */
-2, /* (209) where_opt ::= WHERE expr */
-3, /* (210) expr ::= LP expr RP */
-1, /* (211) expr ::= ID */
-3, /* (212) expr ::= ID DOT ID */
-3, /* (213) expr ::= ID DOT STAR */
-1, /* (214) expr ::= INTEGER */
-2, /* (215) expr ::= MINUS INTEGER */
-2, /* (216) expr ::= PLUS INTEGER */
-1, /* (217) expr ::= FLOAT */
-2, /* (218) expr ::= MINUS FLOAT */
-2, /* (219) expr ::= PLUS FLOAT */
-1, /* (220) expr ::= STRING */
-1, /* (221) expr ::= NOW */
-1, /* (222) expr ::= VARIABLE */
-1, /* (223) expr ::= BOOL */
-4, /* (224) expr ::= ID LP exprlist RP */
-4, /* (225) expr ::= ID LP STAR RP */
-3, /* (226) expr ::= expr IS NULL */
-4, /* (227) expr ::= expr IS NOT NULL */
-3, /* (228) expr ::= expr LT expr */
-3, /* (229) expr ::= expr GT expr */
-3, /* (230) expr ::= expr LE expr */
-3, /* (231) expr ::= expr GE expr */
-3, /* (232) expr ::= expr NE expr */
-3, /* (233) expr ::= expr EQ expr */
-5, /* (234) expr ::= expr BETWEEN expr AND expr */
-3, /* (235) expr ::= expr AND expr */
-3, /* (236) expr ::= expr OR expr */
-3, /* (237) expr ::= expr PLUS expr */
-3, /* (238) expr ::= expr MINUS expr */
-3, /* (239) expr ::= expr STAR expr */
-3, /* (240) expr ::= expr SLASH expr */
-3, /* (241) expr ::= expr REM expr */
-3, /* (242) expr ::= expr LIKE expr */
-5, /* (243) expr ::= expr IN LP exprlist RP */
-3, /* (244) exprlist ::= exprlist COMMA expritem */
-1, /* (245) exprlist ::= expritem */
-1, /* (246) expritem ::= expr */
0, /* (247) expritem ::= */
-3, /* (248) cmd ::= RESET QUERY CACHE */
-7, /* (249) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
-7, /* (250) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */
-7, /* (251) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
-7, /* (252) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */
-8, /* (253) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */
-9, /* (254) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */
-7, /* (255) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */
-7, /* (256) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */
-7, /* (257) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */
-7, /* (258) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */
-8, /* (259) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */
-3, /* (260) cmd ::= KILL CONNECTION INTEGER */
-5, /* (261) cmd ::= KILL STREAM INTEGER COLON INTEGER */
-5, /* (262) cmd ::= KILL QUERY INTEGER COLON INTEGER */
}; };
static void yy_accept(yyParser*); /* Forward Declaration */ static void yy_accept(yyParser*); /* Forward Declaration */
...@@ -2346,34 +2012,30 @@ static void yy_accept(yyParser*); /* Forward Declaration */ ...@@ -2346,34 +2012,30 @@ static void yy_accept(yyParser*); /* Forward Declaration */
** only called from one place, optimizing compilers will in-line it, which ** only called from one place, optimizing compilers will in-line it, which
** means that the extra parameters have no performance impact. ** means that the extra parameters have no performance impact.
*/ */
static YYACTIONTYPE yy_reduce( static void yy_reduce(
yyParser *yypParser, /* The parser */ yyParser *yypParser, /* The parser */
unsigned int yyruleno, /* Number of the rule by which to reduce */ unsigned int yyruleno, /* Number of the rule by which to reduce */
int yyLookahead, /* Lookahead token, or YYNOCODE if none */ int yyLookahead, /* Lookahead token, or YYNOCODE if none */
ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
ParseCTX_PDECL /* %extra_context */
){ ){
int yygoto; /* The next state */ int yygoto; /* The next state */
YYACTIONTYPE yyact; /* The next action */ int yyact; /* The next action */
yyStackEntry *yymsp; /* The top of the parser's stack */ yyStackEntry *yymsp; /* The top of the parser's stack */
int yysize; /* Amount to pop the stack */ int yysize; /* Amount to pop the stack */
ParseARG_FETCH ParseARG_FETCH;
(void)yyLookahead; (void)yyLookahead;
(void)yyLookaheadToken; (void)yyLookaheadToken;
yymsp = yypParser->yytos; yymsp = yypParser->yytos;
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
yysize = yyRuleInfoNRhs[yyruleno]; yysize = yyRuleInfo[yyruleno].nrhs;
if( yysize ){ if( yysize ){
fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
yyTracePrompt, yyTracePrompt,
yyruleno, yyRuleName[yyruleno], yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
yymsp[yysize].stateno);
}else{ }else{
fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n", fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
yyTracePrompt, yyruleno, yyRuleName[yyruleno], yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
} }
} }
#endif /* NDEBUG */ #endif /* NDEBUG */
...@@ -2381,7 +2043,7 @@ static YYACTIONTYPE yy_reduce( ...@@ -2381,7 +2043,7 @@ static YYACTIONTYPE yy_reduce(
/* Check that the stack is large enough to grow by a single entry /* Check that the stack is large enough to grow by a single entry
** if the RHS of the rule is empty. This ensures that there is room ** if the RHS of the rule is empty. This ensures that there is room
** enough on the stack to push the LHS value */ ** enough on the stack to push the LHS value */
if( yyRuleInfoNRhs[yyruleno]==0 ){ if( yyRuleInfo[yyruleno].nrhs==0 ){
#ifdef YYTRACKMAXSTACKDEPTH #ifdef YYTRACKMAXSTACKDEPTH
if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
yypParser->yyhwm++; yypParser->yyhwm++;
...@@ -2391,19 +2053,13 @@ static YYACTIONTYPE yy_reduce( ...@@ -2391,19 +2053,13 @@ static YYACTIONTYPE yy_reduce(
#if YYSTACKDEPTH>0 #if YYSTACKDEPTH>0
if( yypParser->yytos>=yypParser->yystackEnd ){ if( yypParser->yytos>=yypParser->yystackEnd ){
yyStackOverflow(yypParser); yyStackOverflow(yypParser);
/* The call to yyStackOverflow() above pops the stack until it is return;
** empty, causing the main parser loop to exit. So the return value
** is never used and does not matter. */
return 0;
} }
#else #else
if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
if( yyGrowStack(yypParser) ){ if( yyGrowStack(yypParser) ){
yyStackOverflow(yypParser); yyStackOverflow(yypParser);
/* The call to yyStackOverflow() above pops the stack until it is return;
** empty, causing the main parser loop to exit. So the return value
** is never used and does not matter. */
return 0;
} }
yymsp = yypParser->yytos; yymsp = yypParser->yytos;
} }
...@@ -2588,13 +2244,13 @@ static YYACTIONTYPE yy_reduce( ...@@ -2588,13 +2244,13 @@ static YYACTIONTYPE yy_reduce(
break; break;
case 43: /* cmd ::= ALTER DATABASE ids alter_db_optr */ case 43: /* cmd ::= ALTER DATABASE ids alter_db_optr */
case 44: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==44); case 44: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==44);
{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy100, &t);} { SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy94, &t);}
break; break;
case 45: /* cmd ::= ALTER ACCOUNT ids acct_optr */ case 45: /* cmd ::= ALTER ACCOUNT ids acct_optr */
{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy505);} { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy419);}
break; break;
case 46: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ case 46: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */
{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy505);} { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy419);}
break; break;
case 47: /* ids ::= ID */ case 47: /* ids ::= ID */
case 48: /* ids ::= STRING */ yytestcase(yyruleno==48); case 48: /* ids ::= STRING */ yytestcase(yyruleno==48);
...@@ -2616,11 +2272,11 @@ static YYACTIONTYPE yy_reduce( ...@@ -2616,11 +2272,11 @@ static YYACTIONTYPE yy_reduce(
{ setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} { setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);}
break; break;
case 54: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ case 54: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */
{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy505);} { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy419);}
break; break;
case 55: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ case 55: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */
case 56: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==56); case 56: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==56);
{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy100, &yymsp[-2].minor.yy0);} { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy94, &yymsp[-2].minor.yy0);}
break; break;
case 57: /* cmd ::= CREATE USER ids PASS ids */ case 57: /* cmd ::= CREATE USER ids PASS ids */
{ setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);}
...@@ -2649,20 +2305,20 @@ static YYACTIONTYPE yy_reduce( ...@@ -2649,20 +2305,20 @@ static YYACTIONTYPE yy_reduce(
break; break;
case 76: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ case 76: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */
{ {
yylhsminor.yy505.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; yylhsminor.yy419.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1;
yylhsminor.yy505.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; yylhsminor.yy419.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1;
yylhsminor.yy505.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; yylhsminor.yy419.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1;
yylhsminor.yy505.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; yylhsminor.yy419.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1;
yylhsminor.yy505.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; yylhsminor.yy419.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1;
yylhsminor.yy505.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; yylhsminor.yy419.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1;
yylhsminor.yy505.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; yylhsminor.yy419.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1;
yylhsminor.yy505.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; yylhsminor.yy419.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1;
yylhsminor.yy505.stat = yymsp[0].minor.yy0; yylhsminor.yy419.stat = yymsp[0].minor.yy0;
} }
yymsp[-8].minor.yy505 = yylhsminor.yy505; yymsp[-8].minor.yy419 = yylhsminor.yy419;
break; break;
case 77: /* keep ::= KEEP tagitemlist */ case 77: /* keep ::= KEEP tagitemlist */
{ yymsp[-1].minor.yy207 = yymsp[0].minor.yy207; } { yymsp[-1].minor.yy429 = yymsp[0].minor.yy429; }
break; break;
case 78: /* cache ::= CACHE INTEGER */ case 78: /* cache ::= CACHE INTEGER */
case 79: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==79); case 79: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==79);
...@@ -2682,234 +2338,234 @@ static YYACTIONTYPE yy_reduce( ...@@ -2682,234 +2338,234 @@ static YYACTIONTYPE yy_reduce(
{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
break; break;
case 93: /* db_optr ::= */ case 93: /* db_optr ::= */
{setDefaultCreateDbOption(&yymsp[1].minor.yy100); yymsp[1].minor.yy100.dbType = TSDB_DB_TYPE_DEFAULT;} {setDefaultCreateDbOption(&yymsp[1].minor.yy94); yymsp[1].minor.yy94.dbType = TSDB_DB_TYPE_DEFAULT;}
break; break;
case 94: /* db_optr ::= db_optr cache */ case 94: /* db_optr ::= db_optr cache */
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 95: /* db_optr ::= db_optr replica */ case 95: /* db_optr ::= db_optr replica */
case 112: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==112); case 112: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==112);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 96: /* db_optr ::= db_optr quorum */ case 96: /* db_optr ::= db_optr quorum */
case 113: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==113); case 113: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==113);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 97: /* db_optr ::= db_optr days */ case 97: /* db_optr ::= db_optr days */
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 98: /* db_optr ::= db_optr minrows */ case 98: /* db_optr ::= db_optr minrows */
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 99: /* db_optr ::= db_optr maxrows */ case 99: /* db_optr ::= db_optr maxrows */
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 100: /* db_optr ::= db_optr blocks */ case 100: /* db_optr ::= db_optr blocks */
case 115: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==115); case 115: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==115);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 101: /* db_optr ::= db_optr ctime */ case 101: /* db_optr ::= db_optr ctime */
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 102: /* db_optr ::= db_optr wal */ case 102: /* db_optr ::= db_optr wal */
case 117: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==117); case 117: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==117);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 103: /* db_optr ::= db_optr fsync */ case 103: /* db_optr ::= db_optr fsync */
case 118: /* alter_db_optr ::= alter_db_optr fsync */ yytestcase(yyruleno==118); case 118: /* alter_db_optr ::= alter_db_optr fsync */ yytestcase(yyruleno==118);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 104: /* db_optr ::= db_optr comp */ case 104: /* db_optr ::= db_optr comp */
case 116: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==116); case 116: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==116);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 105: /* db_optr ::= db_optr prec */ case 105: /* db_optr ::= db_optr prec */
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.precision = yymsp[0].minor.yy0; } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.precision = yymsp[0].minor.yy0; }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 106: /* db_optr ::= db_optr keep */ case 106: /* db_optr ::= db_optr keep */
case 114: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==114); case 114: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==114);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.keep = yymsp[0].minor.yy207; } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.keep = yymsp[0].minor.yy429; }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 107: /* db_optr ::= db_optr update */ case 107: /* db_optr ::= db_optr update */
case 119: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==119); case 119: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==119);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 108: /* db_optr ::= db_optr cachelast */ case 108: /* db_optr ::= db_optr cachelast */
case 120: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==120); case 120: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==120);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 109: /* topic_optr ::= db_optr */ case 109: /* topic_optr ::= db_optr */
case 121: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==121); case 121: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==121);
{ yylhsminor.yy100 = yymsp[0].minor.yy100; yylhsminor.yy100.dbType = TSDB_DB_TYPE_TOPIC; } { yylhsminor.yy94 = yymsp[0].minor.yy94; yylhsminor.yy94.dbType = TSDB_DB_TYPE_TOPIC; }
yymsp[0].minor.yy100 = yylhsminor.yy100; yymsp[0].minor.yy94 = yylhsminor.yy94;
break; break;
case 110: /* topic_optr ::= topic_optr partitions */ case 110: /* topic_optr ::= topic_optr partitions */
case 122: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==122); case 122: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==122);
{ yylhsminor.yy100 = yymsp[-1].minor.yy100; yylhsminor.yy100.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy94 = yymsp[-1].minor.yy94; yylhsminor.yy94.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[-1].minor.yy100 = yylhsminor.yy100; yymsp[-1].minor.yy94 = yylhsminor.yy94;
break; break;
case 111: /* alter_db_optr ::= */ case 111: /* alter_db_optr ::= */
{ setDefaultCreateDbOption(&yymsp[1].minor.yy100); yymsp[1].minor.yy100.dbType = TSDB_DB_TYPE_DEFAULT;} { setDefaultCreateDbOption(&yymsp[1].minor.yy94); yymsp[1].minor.yy94.dbType = TSDB_DB_TYPE_DEFAULT;}
break; break;
case 123: /* typename ::= ids */ case 123: /* typename ::= ids */
{ {
yymsp[0].minor.yy0.type = 0; yymsp[0].minor.yy0.type = 0;
tSqlSetColumnType (&yylhsminor.yy517, &yymsp[0].minor.yy0); tSqlSetColumnType (&yylhsminor.yy451, &yymsp[0].minor.yy0);
} }
yymsp[0].minor.yy517 = yylhsminor.yy517; yymsp[0].minor.yy451 = yylhsminor.yy451;
break; break;
case 124: /* typename ::= ids LP signed RP */ case 124: /* typename ::= ids LP signed RP */
{ {
if (yymsp[-1].minor.yy208 <= 0) { if (yymsp[-1].minor.yy481 <= 0) {
yymsp[-3].minor.yy0.type = 0; yymsp[-3].minor.yy0.type = 0;
tSqlSetColumnType(&yylhsminor.yy517, &yymsp[-3].minor.yy0); tSqlSetColumnType(&yylhsminor.yy451, &yymsp[-3].minor.yy0);
} else { } else {
yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy208; // negative value of name length yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy481; // negative value of name length
tSqlSetColumnType(&yylhsminor.yy517, &yymsp[-3].minor.yy0); tSqlSetColumnType(&yylhsminor.yy451, &yymsp[-3].minor.yy0);
} }
} }
yymsp[-3].minor.yy517 = yylhsminor.yy517; yymsp[-3].minor.yy451 = yylhsminor.yy451;
break; break;
case 125: /* typename ::= ids UNSIGNED */ case 125: /* typename ::= ids UNSIGNED */
{ {
yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.type = 0;
yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z);
tSqlSetColumnType (&yylhsminor.yy517, &yymsp[-1].minor.yy0); tSqlSetColumnType (&yylhsminor.yy451, &yymsp[-1].minor.yy0);
} }
yymsp[-1].minor.yy517 = yylhsminor.yy517; yymsp[-1].minor.yy451 = yylhsminor.yy451;
break; break;
case 126: /* signed ::= INTEGER */ case 126: /* signed ::= INTEGER */
{ yylhsminor.yy208 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy481 = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
yymsp[0].minor.yy208 = yylhsminor.yy208; yymsp[0].minor.yy481 = yylhsminor.yy481;
break; break;
case 127: /* signed ::= PLUS INTEGER */ case 127: /* signed ::= PLUS INTEGER */
{ yymsp[-1].minor.yy208 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yymsp[-1].minor.yy481 = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
break; break;
case 128: /* signed ::= MINUS INTEGER */ case 128: /* signed ::= MINUS INTEGER */
{ yymsp[-1].minor.yy208 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} { yymsp[-1].minor.yy481 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);}
break; break;
case 132: /* cmd ::= CREATE TABLE create_table_list */ case 132: /* cmd ::= CREATE TABLE create_table_list */
{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy414;} { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy310;}
break; break;
case 133: /* create_table_list ::= create_from_stable */ case 133: /* create_table_list ::= create_from_stable */
{ {
SCreateTableSQL* pCreateTable = calloc(1, sizeof(SCreateTableSQL)); SCreateTableSQL* pCreateTable = calloc(1, sizeof(SCreateTableSQL));
pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo));
taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy542); taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy252);
pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE;
yylhsminor.yy414 = pCreateTable; yylhsminor.yy310 = pCreateTable;
} }
yymsp[0].minor.yy414 = yylhsminor.yy414; yymsp[0].minor.yy310 = yylhsminor.yy310;
break; break;
case 134: /* create_table_list ::= create_table_list create_from_stable */ case 134: /* create_table_list ::= create_table_list create_from_stable */
{ {
taosArrayPush(yymsp[-1].minor.yy414->childTableInfo, &yymsp[0].minor.yy542); taosArrayPush(yymsp[-1].minor.yy310->childTableInfo, &yymsp[0].minor.yy252);
yylhsminor.yy414 = yymsp[-1].minor.yy414; yylhsminor.yy310 = yymsp[-1].minor.yy310;
} }
yymsp[-1].minor.yy414 = yylhsminor.yy414; yymsp[-1].minor.yy310 = yylhsminor.yy310;
break; break;
case 135: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ case 135: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */
{ {
yylhsminor.yy414 = tSetCreateSqlElems(yymsp[-1].minor.yy207, NULL, NULL, TSQL_CREATE_TABLE); yylhsminor.yy310 = tSetCreateSqlElems(yymsp[-1].minor.yy429, NULL, NULL, TSQL_CREATE_TABLE);
setSqlInfo(pInfo, yylhsminor.yy414, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, yylhsminor.yy310, NULL, TSDB_SQL_CREATE_TABLE);
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0);
} }
yymsp[-5].minor.yy414 = yylhsminor.yy414; yymsp[-5].minor.yy310 = yylhsminor.yy310;
break; break;
case 136: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ case 136: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */
{ {
yylhsminor.yy414 = tSetCreateSqlElems(yymsp[-5].minor.yy207, yymsp[-1].minor.yy207, NULL, TSQL_CREATE_STABLE); yylhsminor.yy310 = tSetCreateSqlElems(yymsp[-5].minor.yy429, yymsp[-1].minor.yy429, NULL, TSQL_CREATE_STABLE);
setSqlInfo(pInfo, yylhsminor.yy414, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, yylhsminor.yy310, NULL, TSDB_SQL_CREATE_TABLE);
yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n;
setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0);
} }
yymsp[-9].minor.yy414 = yylhsminor.yy414; yymsp[-9].minor.yy310 = yylhsminor.yy310;
break; break;
case 137: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ case 137: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */
{ {
yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n;
yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n;
yylhsminor.yy542 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy207, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); yylhsminor.yy252 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy429, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0);
} }
yymsp[-9].minor.yy542 = yylhsminor.yy542; yymsp[-9].minor.yy252 = yylhsminor.yy252;
break; break;
case 138: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ case 138: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */
{ {
yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n;
yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n;
yylhsminor.yy542 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy207, yymsp[-1].minor.yy207, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); yylhsminor.yy252 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy429, yymsp[-1].minor.yy429, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0);
} }
yymsp[-12].minor.yy542 = yylhsminor.yy542; yymsp[-12].minor.yy252 = yylhsminor.yy252;
break; break;
case 139: /* tagNamelist ::= tagNamelist COMMA ids */ case 139: /* tagNamelist ::= tagNamelist COMMA ids */
{taosArrayPush(yymsp[-2].minor.yy207, &yymsp[0].minor.yy0); yylhsminor.yy207 = yymsp[-2].minor.yy207; } {taosArrayPush(yymsp[-2].minor.yy429, &yymsp[0].minor.yy0); yylhsminor.yy429 = yymsp[-2].minor.yy429; }
yymsp[-2].minor.yy207 = yylhsminor.yy207; yymsp[-2].minor.yy429 = yylhsminor.yy429;
break; break;
case 140: /* tagNamelist ::= ids */ case 140: /* tagNamelist ::= ids */
{yylhsminor.yy207 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy207, &yymsp[0].minor.yy0);} {yylhsminor.yy429 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy429, &yymsp[0].minor.yy0);}
yymsp[0].minor.yy207 = yylhsminor.yy207; yymsp[0].minor.yy429 = yylhsminor.yy429;
break; break;
case 141: /* create_table_args ::= ifnotexists ids cpxName AS select */ case 141: /* create_table_args ::= ifnotexists ids cpxName AS select */
{ {
yylhsminor.yy414 = tSetCreateSqlElems(NULL, NULL, yymsp[0].minor.yy526, TSQL_CREATE_STREAM); yylhsminor.yy310 = tSetCreateSqlElems(NULL, NULL, yymsp[0].minor.yy372, TSQL_CREATE_STREAM);
setSqlInfo(pInfo, yylhsminor.yy414, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, yylhsminor.yy310, NULL, TSDB_SQL_CREATE_TABLE);
yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n;
setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0);
} }
yymsp[-4].minor.yy414 = yylhsminor.yy414; yymsp[-4].minor.yy310 = yylhsminor.yy310;
break; break;
case 142: /* columnlist ::= columnlist COMMA column */ case 142: /* columnlist ::= columnlist COMMA column */
{taosArrayPush(yymsp[-2].minor.yy207, &yymsp[0].minor.yy517); yylhsminor.yy207 = yymsp[-2].minor.yy207; } {taosArrayPush(yymsp[-2].minor.yy429, &yymsp[0].minor.yy451); yylhsminor.yy429 = yymsp[-2].minor.yy429; }
yymsp[-2].minor.yy207 = yylhsminor.yy207; yymsp[-2].minor.yy429 = yylhsminor.yy429;
break; break;
case 143: /* columnlist ::= column */ case 143: /* columnlist ::= column */
{yylhsminor.yy207 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy207, &yymsp[0].minor.yy517);} {yylhsminor.yy429 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy429, &yymsp[0].minor.yy451);}
yymsp[0].minor.yy207 = yylhsminor.yy207; yymsp[0].minor.yy429 = yylhsminor.yy429;
break; break;
case 144: /* column ::= ids typename */ case 144: /* column ::= ids typename */
{ {
tSqlSetColumnInfo(&yylhsminor.yy517, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy517); tSqlSetColumnInfo(&yylhsminor.yy451, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy451);
} }
yymsp[-1].minor.yy517 = yylhsminor.yy517; yymsp[-1].minor.yy451 = yylhsminor.yy451;
break; break;
case 145: /* tagitemlist ::= tagitemlist COMMA tagitem */ case 145: /* tagitemlist ::= tagitemlist COMMA tagitem */
{ yylhsminor.yy207 = tVariantListAppend(yymsp[-2].minor.yy207, &yymsp[0].minor.yy232, -1); } { yylhsminor.yy429 = tVariantListAppend(yymsp[-2].minor.yy429, &yymsp[0].minor.yy218, -1); }
yymsp[-2].minor.yy207 = yylhsminor.yy207; yymsp[-2].minor.yy429 = yylhsminor.yy429;
break; break;
case 146: /* tagitemlist ::= tagitem */ case 146: /* tagitemlist ::= tagitem */
{ yylhsminor.yy207 = tVariantListAppend(NULL, &yymsp[0].minor.yy232, -1); } { yylhsminor.yy429 = tVariantListAppend(NULL, &yymsp[0].minor.yy218, -1); }
yymsp[0].minor.yy207 = yylhsminor.yy207; yymsp[0].minor.yy429 = yylhsminor.yy429;
break; break;
case 147: /* tagitem ::= INTEGER */ case 147: /* tagitem ::= INTEGER */
case 148: /* tagitem ::= FLOAT */ yytestcase(yyruleno==148); case 148: /* tagitem ::= FLOAT */ yytestcase(yyruleno==148);
case 149: /* tagitem ::= STRING */ yytestcase(yyruleno==149); case 149: /* tagitem ::= STRING */ yytestcase(yyruleno==149);
case 150: /* tagitem ::= BOOL */ yytestcase(yyruleno==150); case 150: /* tagitem ::= BOOL */ yytestcase(yyruleno==150);
{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy232, &yymsp[0].minor.yy0); } { toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy218, &yymsp[0].minor.yy0); }
yymsp[0].minor.yy232 = yylhsminor.yy232; yymsp[0].minor.yy218 = yylhsminor.yy218;
break; break;
case 151: /* tagitem ::= NULL */ case 151: /* tagitem ::= NULL */
{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy232, &yymsp[0].minor.yy0); } { yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy218, &yymsp[0].minor.yy0); }
yymsp[0].minor.yy232 = yylhsminor.yy232; yymsp[0].minor.yy218 = yylhsminor.yy218;
break; break;
case 152: /* tagitem ::= MINUS INTEGER */ case 152: /* tagitem ::= MINUS INTEGER */
case 153: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==153); case 153: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==153);
...@@ -2919,59 +2575,59 @@ static YYACTIONTYPE yy_reduce( ...@@ -2919,59 +2575,59 @@ static YYACTIONTYPE yy_reduce(
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type;
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
tVariantCreate(&yylhsminor.yy232, &yymsp[-1].minor.yy0); tVariantCreate(&yylhsminor.yy218, &yymsp[-1].minor.yy0);
} }
yymsp[-1].minor.yy232 = yylhsminor.yy232; yymsp[-1].minor.yy218 = yylhsminor.yy218;
break; break;
case 156: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ case 156: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
{ {
yylhsminor.yy526 = tSetQuerySqlElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy178, yymsp[-9].minor.yy207, yymsp[-8].minor.yy484, yymsp[-4].minor.yy207, yymsp[-3].minor.yy207, &yymsp[-7].minor.yy126, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy207, &yymsp[0].minor.yy314, &yymsp[-1].minor.yy314); yylhsminor.yy372 = tSetQuerySqlElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy170, yymsp[-9].minor.yy429, yymsp[-8].minor.yy282, yymsp[-4].minor.yy429, yymsp[-3].minor.yy429, &yymsp[-7].minor.yy220, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy429, &yymsp[0].minor.yy18, &yymsp[-1].minor.yy18);
} }
yymsp[-11].minor.yy526 = yylhsminor.yy526; yymsp[-11].minor.yy372 = yylhsminor.yy372;
break; break;
case 157: /* union ::= select */ case 157: /* union ::= select */
{ yylhsminor.yy441 = setSubclause(NULL, yymsp[0].minor.yy526); } { yylhsminor.yy141 = setSubclause(NULL, yymsp[0].minor.yy372); }
yymsp[0].minor.yy441 = yylhsminor.yy441; yymsp[0].minor.yy141 = yylhsminor.yy141;
break; break;
case 158: /* union ::= LP union RP */ case 158: /* union ::= LP union RP */
{ yymsp[-2].minor.yy441 = yymsp[-1].minor.yy441; } { yymsp[-2].minor.yy141 = yymsp[-1].minor.yy141; }
break; break;
case 159: /* union ::= union UNION ALL select */ case 159: /* union ::= union UNION ALL select */
{ yylhsminor.yy441 = appendSelectClause(yymsp[-3].minor.yy441, yymsp[0].minor.yy526); } { yylhsminor.yy141 = appendSelectClause(yymsp[-3].minor.yy141, yymsp[0].minor.yy372); }
yymsp[-3].minor.yy441 = yylhsminor.yy441; yymsp[-3].minor.yy141 = yylhsminor.yy141;
break; break;
case 160: /* union ::= union UNION ALL LP select RP */ case 160: /* union ::= union UNION ALL LP select RP */
{ yylhsminor.yy441 = appendSelectClause(yymsp[-5].minor.yy441, yymsp[-1].minor.yy526); } { yylhsminor.yy141 = appendSelectClause(yymsp[-5].minor.yy141, yymsp[-1].minor.yy372); }
yymsp[-5].minor.yy441 = yylhsminor.yy441; yymsp[-5].minor.yy141 = yylhsminor.yy141;
break; break;
case 161: /* cmd ::= union */ case 161: /* cmd ::= union */
{ setSqlInfo(pInfo, yymsp[0].minor.yy441, NULL, TSDB_SQL_SELECT); } { setSqlInfo(pInfo, yymsp[0].minor.yy141, NULL, TSDB_SQL_SELECT); }
break; break;
case 162: /* select ::= SELECT selcollist */ case 162: /* select ::= SELECT selcollist */
{ {
yylhsminor.yy526 = tSetQuerySqlElems(&yymsp[-1].minor.yy0, yymsp[0].minor.yy178, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); yylhsminor.yy372 = tSetQuerySqlElems(&yymsp[-1].minor.yy0, yymsp[0].minor.yy170, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
} }
yymsp[-1].minor.yy526 = yylhsminor.yy526; yymsp[-1].minor.yy372 = yylhsminor.yy372;
break; break;
case 163: /* sclp ::= selcollist COMMA */ case 163: /* sclp ::= selcollist COMMA */
{yylhsminor.yy178 = yymsp[-1].minor.yy178;} {yylhsminor.yy170 = yymsp[-1].minor.yy170;}
yymsp[-1].minor.yy178 = yylhsminor.yy178; yymsp[-1].minor.yy170 = yylhsminor.yy170;
break; break;
case 164: /* sclp ::= */ case 164: /* sclp ::= */
{yymsp[1].minor.yy178 = 0;} {yymsp[1].minor.yy170 = 0;}
break; break;
case 165: /* selcollist ::= sclp distinct expr as */ case 165: /* selcollist ::= sclp distinct expr as */
{ {
yylhsminor.yy178 = tSqlExprListAppend(yymsp[-3].minor.yy178, yymsp[-1].minor.yy484, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); yylhsminor.yy170 = tSqlExprListAppend(yymsp[-3].minor.yy170, yymsp[-1].minor.yy282, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0);
} }
yymsp[-3].minor.yy178 = yylhsminor.yy178; yymsp[-3].minor.yy170 = yylhsminor.yy170;
break; break;
case 166: /* selcollist ::= sclp STAR */ case 166: /* selcollist ::= sclp STAR */
{ {
tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL); tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL);
yylhsminor.yy178 = tSqlExprListAppend(yymsp[-1].minor.yy178, pNode, 0, 0); yylhsminor.yy170 = tSqlExprListAppend(yymsp[-1].minor.yy170, pNode, 0, 0);
} }
yymsp[-1].minor.yy178 = yylhsminor.yy178; yymsp[-1].minor.yy170 = yylhsminor.yy170;
break; break;
case 167: /* as ::= AS ids */ case 167: /* as ::= AS ids */
{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
...@@ -2988,61 +2644,61 @@ static YYACTIONTYPE yy_reduce( ...@@ -2988,61 +2644,61 @@ static YYACTIONTYPE yy_reduce(
yymsp[0].minor.yy0 = yylhsminor.yy0; yymsp[0].minor.yy0 = yylhsminor.yy0;
break; break;
case 172: /* from ::= FROM tablelist */ case 172: /* from ::= FROM tablelist */
{yymsp[-1].minor.yy207 = yymsp[0].minor.yy207;} {yymsp[-1].minor.yy429 = yymsp[0].minor.yy429;}
break; break;
case 173: /* tablelist ::= ids cpxName */ case 173: /* tablelist ::= ids cpxName */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
yylhsminor.yy207 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); yylhsminor.yy429 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
yylhsminor.yy207 = tVariantListAppendToken(yylhsminor.yy207, &yymsp[-1].minor.yy0, -1); // table alias name yylhsminor.yy429 = tVariantListAppendToken(yylhsminor.yy429, &yymsp[-1].minor.yy0, -1); // table alias name
} }
yymsp[-1].minor.yy207 = yylhsminor.yy207; yymsp[-1].minor.yy429 = yylhsminor.yy429;
break; break;
case 174: /* tablelist ::= ids cpxName ids */ case 174: /* tablelist ::= ids cpxName ids */
{ {
toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[-2].minor.yy0.type);
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n;
yylhsminor.yy207 = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); yylhsminor.yy429 = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
yylhsminor.yy207 = tVariantListAppendToken(yylhsminor.yy207, &yymsp[0].minor.yy0, -1); yylhsminor.yy429 = tVariantListAppendToken(yylhsminor.yy429, &yymsp[0].minor.yy0, -1);
} }
yymsp[-2].minor.yy207 = yylhsminor.yy207; yymsp[-2].minor.yy429 = yylhsminor.yy429;
break; break;
case 175: /* tablelist ::= tablelist COMMA ids cpxName */ case 175: /* tablelist ::= tablelist COMMA ids cpxName */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
yylhsminor.yy207 = tVariantListAppendToken(yymsp[-3].minor.yy207, &yymsp[-1].minor.yy0, -1); yylhsminor.yy429 = tVariantListAppendToken(yymsp[-3].minor.yy429, &yymsp[-1].minor.yy0, -1);
yylhsminor.yy207 = tVariantListAppendToken(yylhsminor.yy207, &yymsp[-1].minor.yy0, -1); yylhsminor.yy429 = tVariantListAppendToken(yylhsminor.yy429, &yymsp[-1].minor.yy0, -1);
} }
yymsp[-3].minor.yy207 = yylhsminor.yy207; yymsp[-3].minor.yy429 = yylhsminor.yy429;
break; break;
case 176: /* tablelist ::= tablelist COMMA ids cpxName ids */ case 176: /* tablelist ::= tablelist COMMA ids cpxName ids */
{ {
toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[-2].minor.yy0.type);
toTSDBType(yymsp[0].minor.yy0.type); toTSDBType(yymsp[0].minor.yy0.type);
yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n;
yylhsminor.yy207 = tVariantListAppendToken(yymsp[-4].minor.yy207, &yymsp[-2].minor.yy0, -1); yylhsminor.yy429 = tVariantListAppendToken(yymsp[-4].minor.yy429, &yymsp[-2].minor.yy0, -1);
yylhsminor.yy207 = tVariantListAppendToken(yylhsminor.yy207, &yymsp[0].minor.yy0, -1); yylhsminor.yy429 = tVariantListAppendToken(yylhsminor.yy429, &yymsp[0].minor.yy0, -1);
} }
yymsp[-4].minor.yy207 = yylhsminor.yy207; yymsp[-4].minor.yy429 = yylhsminor.yy429;
break; break;
case 177: /* tmvar ::= VARIABLE */ case 177: /* tmvar ::= VARIABLE */
{yylhsminor.yy0 = yymsp[0].minor.yy0;} {yylhsminor.yy0 = yymsp[0].minor.yy0;}
yymsp[0].minor.yy0 = yylhsminor.yy0; yymsp[0].minor.yy0 = yylhsminor.yy0;
break; break;
case 178: /* interval_opt ::= INTERVAL LP tmvar RP */ case 178: /* interval_opt ::= INTERVAL LP tmvar RP */
{yymsp[-3].minor.yy126.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy126.offset.n = 0; yymsp[-3].minor.yy126.offset.z = NULL; yymsp[-3].minor.yy126.offset.type = 0;} {yymsp[-3].minor.yy220.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy220.offset.n = 0; yymsp[-3].minor.yy220.offset.z = NULL; yymsp[-3].minor.yy220.offset.type = 0;}
break; break;
case 179: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ case 179: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */
{yymsp[-5].minor.yy126.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy126.offset = yymsp[-1].minor.yy0;} {yymsp[-5].minor.yy220.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy220.offset = yymsp[-1].minor.yy0;}
break; break;
case 180: /* interval_opt ::= */ case 180: /* interval_opt ::= */
{memset(&yymsp[1].minor.yy126, 0, sizeof(yymsp[1].minor.yy126));} {memset(&yymsp[1].minor.yy220, 0, sizeof(yymsp[1].minor.yy220));}
break; break;
case 181: /* fill_opt ::= */ case 181: /* fill_opt ::= */
{yymsp[1].minor.yy207 = 0; } {yymsp[1].minor.yy429 = 0; }
break; break;
case 182: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ case 182: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{ {
...@@ -3050,14 +2706,14 @@ static YYACTIONTYPE yy_reduce( ...@@ -3050,14 +2706,14 @@ static YYACTIONTYPE yy_reduce(
toTSDBType(yymsp[-3].minor.yy0.type); toTSDBType(yymsp[-3].minor.yy0.type);
tVariantCreate(&A, &yymsp[-3].minor.yy0); tVariantCreate(&A, &yymsp[-3].minor.yy0);
tVariantListInsert(yymsp[-1].minor.yy207, &A, -1, 0); tVariantListInsert(yymsp[-1].minor.yy429, &A, -1, 0);
yymsp[-5].minor.yy207 = yymsp[-1].minor.yy207; yymsp[-5].minor.yy429 = yymsp[-1].minor.yy429;
} }
break; break;
case 183: /* fill_opt ::= FILL LP ID RP */ case 183: /* fill_opt ::= FILL LP ID RP */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-3].minor.yy207 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); yymsp[-3].minor.yy429 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);
} }
break; break;
case 184: /* sliding_opt ::= SLIDING LP tmvar RP */ case 184: /* sliding_opt ::= SLIDING LP tmvar RP */
...@@ -3067,31 +2723,31 @@ static YYACTIONTYPE yy_reduce( ...@@ -3067,31 +2723,31 @@ static YYACTIONTYPE yy_reduce(
{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; }
break; break;
case 186: /* orderby_opt ::= */ case 186: /* orderby_opt ::= */
{yymsp[1].minor.yy207 = 0;} {yymsp[1].minor.yy429 = 0;}
break; break;
case 187: /* orderby_opt ::= ORDER BY sortlist */ case 187: /* orderby_opt ::= ORDER BY sortlist */
{yymsp[-2].minor.yy207 = yymsp[0].minor.yy207;} {yymsp[-2].minor.yy429 = yymsp[0].minor.yy429;}
break; break;
case 188: /* sortlist ::= sortlist COMMA item sortorder */ case 188: /* sortlist ::= sortlist COMMA item sortorder */
{ {
yylhsminor.yy207 = tVariantListAppend(yymsp[-3].minor.yy207, &yymsp[-1].minor.yy232, yymsp[0].minor.yy116); yylhsminor.yy429 = tVariantListAppend(yymsp[-3].minor.yy429, &yymsp[-1].minor.yy218, yymsp[0].minor.yy116);
} }
yymsp[-3].minor.yy207 = yylhsminor.yy207; yymsp[-3].minor.yy429 = yylhsminor.yy429;
break; break;
case 189: /* sortlist ::= item sortorder */ case 189: /* sortlist ::= item sortorder */
{ {
yylhsminor.yy207 = tVariantListAppend(NULL, &yymsp[-1].minor.yy232, yymsp[0].minor.yy116); yylhsminor.yy429 = tVariantListAppend(NULL, &yymsp[-1].minor.yy218, yymsp[0].minor.yy116);
} }
yymsp[-1].minor.yy207 = yylhsminor.yy207; yymsp[-1].minor.yy429 = yylhsminor.yy429;
break; break;
case 190: /* item ::= ids cpxName */ case 190: /* item ::= ids cpxName */
{ {
toTSDBType(yymsp[-1].minor.yy0.type); toTSDBType(yymsp[-1].minor.yy0.type);
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
tVariantCreate(&yylhsminor.yy232, &yymsp[-1].minor.yy0); tVariantCreate(&yylhsminor.yy218, &yymsp[-1].minor.yy0);
} }
yymsp[-1].minor.yy232 = yylhsminor.yy232; yymsp[-1].minor.yy218 = yylhsminor.yy218;
break; break;
case 191: /* sortorder ::= ASC */ case 191: /* sortorder ::= ASC */
{ yymsp[0].minor.yy116 = TSDB_ORDER_ASC; } { yymsp[0].minor.yy116 = TSDB_ORDER_ASC; }
...@@ -3103,193 +2759,193 @@ static YYACTIONTYPE yy_reduce( ...@@ -3103,193 +2759,193 @@ static YYACTIONTYPE yy_reduce(
{ yymsp[1].minor.yy116 = TSDB_ORDER_ASC; } { yymsp[1].minor.yy116 = TSDB_ORDER_ASC; }
break; break;
case 194: /* groupby_opt ::= */ case 194: /* groupby_opt ::= */
{ yymsp[1].minor.yy207 = 0;} { yymsp[1].minor.yy429 = 0;}
break; break;
case 195: /* groupby_opt ::= GROUP BY grouplist */ case 195: /* groupby_opt ::= GROUP BY grouplist */
{ yymsp[-2].minor.yy207 = yymsp[0].minor.yy207;} { yymsp[-2].minor.yy429 = yymsp[0].minor.yy429;}
break; break;
case 196: /* grouplist ::= grouplist COMMA item */ case 196: /* grouplist ::= grouplist COMMA item */
{ {
yylhsminor.yy207 = tVariantListAppend(yymsp[-2].minor.yy207, &yymsp[0].minor.yy232, -1); yylhsminor.yy429 = tVariantListAppend(yymsp[-2].minor.yy429, &yymsp[0].minor.yy218, -1);
} }
yymsp[-2].minor.yy207 = yylhsminor.yy207; yymsp[-2].minor.yy429 = yylhsminor.yy429;
break; break;
case 197: /* grouplist ::= item */ case 197: /* grouplist ::= item */
{ {
yylhsminor.yy207 = tVariantListAppend(NULL, &yymsp[0].minor.yy232, -1); yylhsminor.yy429 = tVariantListAppend(NULL, &yymsp[0].minor.yy218, -1);
} }
yymsp[0].minor.yy207 = yylhsminor.yy207; yymsp[0].minor.yy429 = yylhsminor.yy429;
break; break;
case 198: /* having_opt ::= */ case 198: /* having_opt ::= */
case 208: /* where_opt ::= */ yytestcase(yyruleno==208); case 208: /* where_opt ::= */ yytestcase(yyruleno==208);
case 247: /* expritem ::= */ yytestcase(yyruleno==247); case 247: /* expritem ::= */ yytestcase(yyruleno==247);
{yymsp[1].minor.yy484 = 0;} {yymsp[1].minor.yy282 = 0;}
break; break;
case 199: /* having_opt ::= HAVING expr */ case 199: /* having_opt ::= HAVING expr */
case 209: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==209); case 209: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==209);
{yymsp[-1].minor.yy484 = yymsp[0].minor.yy484;} {yymsp[-1].minor.yy282 = yymsp[0].minor.yy282;}
break; break;
case 200: /* limit_opt ::= */ case 200: /* limit_opt ::= */
case 204: /* slimit_opt ::= */ yytestcase(yyruleno==204); case 204: /* slimit_opt ::= */ yytestcase(yyruleno==204);
{yymsp[1].minor.yy314.limit = -1; yymsp[1].minor.yy314.offset = 0;} {yymsp[1].minor.yy18.limit = -1; yymsp[1].minor.yy18.offset = 0;}
break; break;
case 201: /* limit_opt ::= LIMIT signed */ case 201: /* limit_opt ::= LIMIT signed */
case 205: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==205); case 205: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==205);
{yymsp[-1].minor.yy314.limit = yymsp[0].minor.yy208; yymsp[-1].minor.yy314.offset = 0;} {yymsp[-1].minor.yy18.limit = yymsp[0].minor.yy481; yymsp[-1].minor.yy18.offset = 0;}
break; break;
case 202: /* limit_opt ::= LIMIT signed OFFSET signed */ case 202: /* limit_opt ::= LIMIT signed OFFSET signed */
{ yymsp[-3].minor.yy314.limit = yymsp[-2].minor.yy208; yymsp[-3].minor.yy314.offset = yymsp[0].minor.yy208;} { yymsp[-3].minor.yy18.limit = yymsp[-2].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[0].minor.yy481;}
break; break;
case 203: /* limit_opt ::= LIMIT signed COMMA signed */ case 203: /* limit_opt ::= LIMIT signed COMMA signed */
{ yymsp[-3].minor.yy314.limit = yymsp[0].minor.yy208; yymsp[-3].minor.yy314.offset = yymsp[-2].minor.yy208;} { yymsp[-3].minor.yy18.limit = yymsp[0].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[-2].minor.yy481;}
break; break;
case 206: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ case 206: /* slimit_opt ::= SLIMIT signed SOFFSET signed */
{yymsp[-3].minor.yy314.limit = yymsp[-2].minor.yy208; yymsp[-3].minor.yy314.offset = yymsp[0].minor.yy208;} {yymsp[-3].minor.yy18.limit = yymsp[-2].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[0].minor.yy481;}
break; break;
case 207: /* slimit_opt ::= SLIMIT signed COMMA signed */ case 207: /* slimit_opt ::= SLIMIT signed COMMA signed */
{yymsp[-3].minor.yy314.limit = yymsp[0].minor.yy208; yymsp[-3].minor.yy314.offset = yymsp[-2].minor.yy208;} {yymsp[-3].minor.yy18.limit = yymsp[0].minor.yy481; yymsp[-3].minor.yy18.offset = yymsp[-2].minor.yy481;}
break; break;
case 210: /* expr ::= LP expr RP */ case 210: /* expr ::= LP expr RP */
{yylhsminor.yy484 = yymsp[-1].minor.yy484; yylhsminor.yy484->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy484->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} {yylhsminor.yy282 = yymsp[-1].minor.yy282; yylhsminor.yy282->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy282->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 211: /* expr ::= ID */ case 211: /* expr ::= ID */
{ yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} { yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);}
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 212: /* expr ::= ID DOT ID */ case 212: /* expr ::= ID DOT ID */
{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 213: /* expr ::= ID DOT STAR */ case 213: /* expr ::= ID DOT STAR */
{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 214: /* expr ::= INTEGER */ case 214: /* expr ::= INTEGER */
{ yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} { yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);}
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 215: /* expr ::= MINUS INTEGER */ case 215: /* expr ::= MINUS INTEGER */
case 216: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==216); case 216: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==216);
{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);}
yymsp[-1].minor.yy484 = yylhsminor.yy484; yymsp[-1].minor.yy282 = yylhsminor.yy282;
break; break;
case 217: /* expr ::= FLOAT */ case 217: /* expr ::= FLOAT */
{ yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} { yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);}
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 218: /* expr ::= MINUS FLOAT */ case 218: /* expr ::= MINUS FLOAT */
case 219: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==219); case 219: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==219);
{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);}
yymsp[-1].minor.yy484 = yylhsminor.yy484; yymsp[-1].minor.yy282 = yylhsminor.yy282;
break; break;
case 220: /* expr ::= STRING */ case 220: /* expr ::= STRING */
{ yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} { yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);}
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 221: /* expr ::= NOW */ case 221: /* expr ::= NOW */
{ yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } { yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); }
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 222: /* expr ::= VARIABLE */ case 222: /* expr ::= VARIABLE */
{ yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} { yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);}
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 223: /* expr ::= BOOL */ case 223: /* expr ::= BOOL */
{ yylhsminor.yy484 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} { yylhsminor.yy282 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);}
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 224: /* expr ::= ID LP exprlist RP */ case 224: /* expr ::= ID LP exprlist RP */
{ yylhsminor.yy484 = tSqlExprCreateFunction(yymsp[-1].minor.yy178, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } { yylhsminor.yy282 = tSqlExprCreateFunction(yymsp[-1].minor.yy170, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); }
yymsp[-3].minor.yy484 = yylhsminor.yy484; yymsp[-3].minor.yy282 = yylhsminor.yy282;
break; break;
case 225: /* expr ::= ID LP STAR RP */ case 225: /* expr ::= ID LP STAR RP */
{ yylhsminor.yy484 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } { yylhsminor.yy282 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); }
yymsp[-3].minor.yy484 = yylhsminor.yy484; yymsp[-3].minor.yy282 = yylhsminor.yy282;
break; break;
case 226: /* expr ::= expr IS NULL */ case 226: /* expr ::= expr IS NULL */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, NULL, TK_ISNULL);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, NULL, TK_ISNULL);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 227: /* expr ::= expr IS NOT NULL */ case 227: /* expr ::= expr IS NOT NULL */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-3].minor.yy484, NULL, TK_NOTNULL);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-3].minor.yy282, NULL, TK_NOTNULL);}
yymsp[-3].minor.yy484 = yylhsminor.yy484; yymsp[-3].minor.yy282 = yylhsminor.yy282;
break; break;
case 228: /* expr ::= expr LT expr */ case 228: /* expr ::= expr LT expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_LT);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_LT);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 229: /* expr ::= expr GT expr */ case 229: /* expr ::= expr GT expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_GT);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_GT);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 230: /* expr ::= expr LE expr */ case 230: /* expr ::= expr LE expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_LE);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_LE);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 231: /* expr ::= expr GE expr */ case 231: /* expr ::= expr GE expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_GE);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_GE);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 232: /* expr ::= expr NE expr */ case 232: /* expr ::= expr NE expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_NE);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_NE);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 233: /* expr ::= expr EQ expr */ case 233: /* expr ::= expr EQ expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_EQ);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_EQ);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 234: /* expr ::= expr BETWEEN expr AND expr */ case 234: /* expr ::= expr BETWEEN expr AND expr */
{ tSQLExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy484); yylhsminor.yy484 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy484, yymsp[-2].minor.yy484, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy484, TK_LE), TK_AND);} { tSQLExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy282); yylhsminor.yy282 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy282, yymsp[-2].minor.yy282, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy282, TK_LE), TK_AND);}
yymsp[-4].minor.yy484 = yylhsminor.yy484; yymsp[-4].minor.yy282 = yylhsminor.yy282;
break; break;
case 235: /* expr ::= expr AND expr */ case 235: /* expr ::= expr AND expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_AND);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_AND);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 236: /* expr ::= expr OR expr */ case 236: /* expr ::= expr OR expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_OR); } {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_OR); }
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 237: /* expr ::= expr PLUS expr */ case 237: /* expr ::= expr PLUS expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_PLUS); } {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_PLUS); }
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 238: /* expr ::= expr MINUS expr */ case 238: /* expr ::= expr MINUS expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_MINUS); } {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_MINUS); }
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 239: /* expr ::= expr STAR expr */ case 239: /* expr ::= expr STAR expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_STAR); } {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_STAR); }
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 240: /* expr ::= expr SLASH expr */ case 240: /* expr ::= expr SLASH expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_DIVIDE);} {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_DIVIDE);}
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 241: /* expr ::= expr REM expr */ case 241: /* expr ::= expr REM expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_REM); } {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_REM); }
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 242: /* expr ::= expr LIKE expr */ case 242: /* expr ::= expr LIKE expr */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-2].minor.yy484, yymsp[0].minor.yy484, TK_LIKE); } {yylhsminor.yy282 = tSqlExprCreate(yymsp[-2].minor.yy282, yymsp[0].minor.yy282, TK_LIKE); }
yymsp[-2].minor.yy484 = yylhsminor.yy484; yymsp[-2].minor.yy282 = yylhsminor.yy282;
break; break;
case 243: /* expr ::= expr IN LP exprlist RP */ case 243: /* expr ::= expr IN LP exprlist RP */
{yylhsminor.yy484 = tSqlExprCreate(yymsp[-4].minor.yy484, (tSQLExpr*)yymsp[-1].minor.yy178, TK_IN); } {yylhsminor.yy282 = tSqlExprCreate(yymsp[-4].minor.yy282, (tSQLExpr*)yymsp[-1].minor.yy170, TK_IN); }
yymsp[-4].minor.yy484 = yylhsminor.yy484; yymsp[-4].minor.yy282 = yylhsminor.yy282;
break; break;
case 244: /* exprlist ::= exprlist COMMA expritem */ case 244: /* exprlist ::= exprlist COMMA expritem */
{yylhsminor.yy178 = tSqlExprListAppend(yymsp[-2].minor.yy178,yymsp[0].minor.yy484,0, 0);} {yylhsminor.yy170 = tSqlExprListAppend(yymsp[-2].minor.yy170,yymsp[0].minor.yy282,0, 0);}
yymsp[-2].minor.yy178 = yylhsminor.yy178; yymsp[-2].minor.yy170 = yylhsminor.yy170;
break; break;
case 245: /* exprlist ::= expritem */ case 245: /* exprlist ::= expritem */
{yylhsminor.yy178 = tSqlExprListAppend(0,yymsp[0].minor.yy484,0, 0);} {yylhsminor.yy170 = tSqlExprListAppend(0,yymsp[0].minor.yy282,0, 0);}
yymsp[0].minor.yy178 = yylhsminor.yy178; yymsp[0].minor.yy170 = yylhsminor.yy170;
break; break;
case 246: /* expritem ::= expr */ case 246: /* expritem ::= expr */
{yylhsminor.yy484 = yymsp[0].minor.yy484;} {yylhsminor.yy282 = yymsp[0].minor.yy282;}
yymsp[0].minor.yy484 = yylhsminor.yy484; yymsp[0].minor.yy282 = yylhsminor.yy282;
break; break;
case 248: /* cmd ::= RESET QUERY CACHE */ case 248: /* cmd ::= RESET QUERY CACHE */
{ setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
...@@ -3297,7 +2953,7 @@ static YYACTIONTYPE yy_reduce( ...@@ -3297,7 +2953,7 @@ static YYACTIONTYPE yy_reduce(
case 249: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ case 249: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{ {
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy207, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; break;
...@@ -3315,7 +2971,7 @@ static YYACTIONTYPE yy_reduce( ...@@ -3315,7 +2971,7 @@ static YYACTIONTYPE yy_reduce(
case 251: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ case 251: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{ {
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy207, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; break;
...@@ -3350,7 +3006,7 @@ static YYACTIONTYPE yy_reduce( ...@@ -3350,7 +3006,7 @@ static YYACTIONTYPE yy_reduce(
toTSDBType(yymsp[-2].minor.yy0.type); toTSDBType(yymsp[-2].minor.yy0.type);
SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
A = tVariantListAppend(A, &yymsp[0].minor.yy232, -1); A = tVariantListAppend(A, &yymsp[0].minor.yy218, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1); SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
...@@ -3359,7 +3015,7 @@ static YYACTIONTYPE yy_reduce( ...@@ -3359,7 +3015,7 @@ static YYACTIONTYPE yy_reduce(
case 255: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ case 255: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */
{ {
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy207, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; break;
...@@ -3377,7 +3033,7 @@ static YYACTIONTYPE yy_reduce( ...@@ -3377,7 +3033,7 @@ static YYACTIONTYPE yy_reduce(
case 257: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ case 257: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */
{ {
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy207, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy429, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
break; break;
...@@ -3419,9 +3075,9 @@ static YYACTIONTYPE yy_reduce( ...@@ -3419,9 +3075,9 @@ static YYACTIONTYPE yy_reduce(
break; break;
/********** End reduce actions ************************************************/ /********** End reduce actions ************************************************/
}; };
assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) ); assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
yygoto = yyRuleInfoLhs[yyruleno]; yygoto = yyRuleInfo[yyruleno].lhs;
yysize = yyRuleInfoNRhs[yyruleno]; yysize = yyRuleInfo[yyruleno].nrhs;
yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto); yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
/* There are no SHIFTREDUCE actions on nonterminals because the table /* There are no SHIFTREDUCE actions on nonterminals because the table
...@@ -3436,7 +3092,6 @@ static YYACTIONTYPE yy_reduce( ...@@ -3436,7 +3092,6 @@ static YYACTIONTYPE yy_reduce(
yymsp->stateno = (YYACTIONTYPE)yyact; yymsp->stateno = (YYACTIONTYPE)yyact;
yymsp->major = (YYCODETYPE)yygoto; yymsp->major = (YYCODETYPE)yygoto;
yyTraceShift(yypParser, yyact, "... then shift"); yyTraceShift(yypParser, yyact, "... then shift");
return yyact;
} }
/* /*
...@@ -3446,8 +3101,7 @@ static YYACTIONTYPE yy_reduce( ...@@ -3446,8 +3101,7 @@ static YYACTIONTYPE yy_reduce(
static void yy_parse_failed( static void yy_parse_failed(
yyParser *yypParser /* The parser */ yyParser *yypParser /* The parser */
){ ){
ParseARG_FETCH ParseARG_FETCH;
ParseCTX_FETCH
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
...@@ -3458,8 +3112,7 @@ static void yy_parse_failed( ...@@ -3458,8 +3112,7 @@ static void yy_parse_failed(
** parser fails */ ** parser fails */
/************ Begin %parse_failure code ***************************************/ /************ Begin %parse_failure code ***************************************/
/************ End %parse_failure code *****************************************/ /************ End %parse_failure code *****************************************/
ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
ParseCTX_STORE
} }
#endif /* YYNOERRORRECOVERY */ #endif /* YYNOERRORRECOVERY */
...@@ -3471,8 +3124,7 @@ static void yy_syntax_error( ...@@ -3471,8 +3124,7 @@ static void yy_syntax_error(
int yymajor, /* The major type of the error token */ int yymajor, /* The major type of the error token */
ParseTOKENTYPE yyminor /* The minor type of the error token */ ParseTOKENTYPE yyminor /* The minor type of the error token */
){ ){
ParseARG_FETCH ParseARG_FETCH;
ParseCTX_FETCH
#define TOKEN yyminor #define TOKEN yyminor
/************ Begin %syntax_error code ****************************************/ /************ Begin %syntax_error code ****************************************/
...@@ -3498,8 +3150,7 @@ static void yy_syntax_error( ...@@ -3498,8 +3150,7 @@ static void yy_syntax_error(
assert(len <= outputBufLen); assert(len <= outputBufLen);
/************ End %syntax_error code ******************************************/ /************ End %syntax_error code ******************************************/
ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
ParseCTX_STORE
} }
/* /*
...@@ -3508,8 +3159,7 @@ static void yy_syntax_error( ...@@ -3508,8 +3159,7 @@ static void yy_syntax_error(
static void yy_accept( static void yy_accept(
yyParser *yypParser /* The parser */ yyParser *yypParser /* The parser */
){ ){
ParseARG_FETCH ParseARG_FETCH;
ParseCTX_FETCH
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
...@@ -3524,8 +3174,7 @@ static void yy_accept( ...@@ -3524,8 +3174,7 @@ static void yy_accept(
/*********** Begin %parse_accept code *****************************************/ /*********** Begin %parse_accept code *****************************************/
/*********** End %parse_accept code *******************************************/ /*********** End %parse_accept code *******************************************/
ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
ParseCTX_STORE
} }
/* The main parser program. /* The main parser program.
...@@ -3554,47 +3203,45 @@ void Parse( ...@@ -3554,47 +3203,45 @@ void Parse(
ParseARG_PDECL /* Optional %extra_argument parameter */ ParseARG_PDECL /* Optional %extra_argument parameter */
){ ){
YYMINORTYPE yyminorunion; YYMINORTYPE yyminorunion;
YYACTIONTYPE yyact; /* The parser action. */ unsigned int yyact; /* The parser action. */
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
int yyendofinput; /* True if we are at the end of input */ int yyendofinput; /* True if we are at the end of input */
#endif #endif
#ifdef YYERRORSYMBOL #ifdef YYERRORSYMBOL
int yyerrorhit = 0; /* True if yymajor has invoked an error */ int yyerrorhit = 0; /* True if yymajor has invoked an error */
#endif #endif
yyParser *yypParser = (yyParser*)yyp; /* The parser */ yyParser *yypParser; /* The parser */
ParseCTX_FETCH
ParseARG_STORE
yypParser = (yyParser*)yyp;
assert( yypParser->yytos!=0 ); assert( yypParser->yytos!=0 );
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
yyendofinput = (yymajor==0); yyendofinput = (yymajor==0);
#endif #endif
ParseARG_STORE;
yyact = yypParser->yytos->stateno;
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
if( yyact < YY_MIN_REDUCE ){ int stateno = yypParser->yytos->stateno;
if( stateno < YY_MIN_REDUCE ){
fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
yyTracePrompt,yyTokenName[yymajor],yyact); yyTracePrompt,yyTokenName[yymajor],stateno);
}else{ }else{
fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE); yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE);
} }
} }
#endif #endif
do{ do{
assert( yyact==yypParser->yytos->stateno ); yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
if( yyact >= YY_MIN_REDUCE ){ if( yyact >= YY_MIN_REDUCE ){
yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor, yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
yyminor ParseCTX_PARAM);
}else if( yyact <= YY_MAX_SHIFTREDUCE ){ }else if( yyact <= YY_MAX_SHIFTREDUCE ){
yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); yy_shift(yypParser,yyact,yymajor,yyminor);
#ifndef YYNOERRORRECOVERY #ifndef YYNOERRORRECOVERY
yypParser->yyerrcnt--; yypParser->yyerrcnt--;
#endif #endif
break; yymajor = YYNOCODE;
}else if( yyact==YY_ACCEPT_ACTION ){ }else if( yyact==YY_ACCEPT_ACTION ){
yypParser->yytos--; yypParser->yytos--;
yy_accept(yypParser); yy_accept(yypParser);
...@@ -3645,9 +3292,10 @@ void Parse( ...@@ -3645,9 +3292,10 @@ void Parse(
yymajor = YYNOCODE; yymajor = YYNOCODE;
}else{ }else{
while( yypParser->yytos >= yypParser->yystack while( yypParser->yytos >= yypParser->yystack
&& yymx != YYERRORSYMBOL
&& (yyact = yy_find_reduce_action( && (yyact = yy_find_reduce_action(
yypParser->yytos->stateno, yypParser->yytos->stateno,
YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE YYERRORSYMBOL)) >= YY_MIN_REDUCE
){ ){
yy_pop_parser_stack(yypParser); yy_pop_parser_stack(yypParser);
} }
...@@ -3664,8 +3312,6 @@ void Parse( ...@@ -3664,8 +3312,6 @@ void Parse(
} }
yypParser->yyerrcnt = 3; yypParser->yyerrcnt = 3;
yyerrorhit = 1; yyerrorhit = 1;
if( yymajor==YYNOCODE ) break;
yyact = yypParser->yytos->stateno;
#elif defined(YYNOERRORRECOVERY) #elif defined(YYNOERRORRECOVERY)
/* If the YYNOERRORRECOVERY macro is defined, then do not attempt to /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
** do any kind of error recovery. Instead, simply invoke the syntax ** do any kind of error recovery. Instead, simply invoke the syntax
...@@ -3676,7 +3322,8 @@ void Parse( ...@@ -3676,7 +3322,8 @@ void Parse(
*/ */
yy_syntax_error(yypParser,yymajor, yyminor); yy_syntax_error(yypParser,yymajor, yyminor);
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
break; yymajor = YYNOCODE;
#else /* YYERRORSYMBOL is not defined */ #else /* YYERRORSYMBOL is not defined */
/* This is what we do if the grammar does not define ERROR: /* This is what we do if the grammar does not define ERROR:
** **
...@@ -3698,10 +3345,10 @@ void Parse( ...@@ -3698,10 +3345,10 @@ void Parse(
yypParser->yyerrcnt = -1; yypParser->yyerrcnt = -1;
#endif #endif
} }
break; yymajor = YYNOCODE;
#endif #endif
} }
}while( yypParser->yytos>yypParser->yystack ); }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack );
#ifndef NDEBUG #ifndef NDEBUG
if( yyTraceFILE ){ if( yyTraceFILE ){
yyStackEntry *i; yyStackEntry *i;
...@@ -3716,17 +3363,3 @@ void Parse( ...@@ -3716,17 +3363,3 @@ void Parse(
#endif #endif
return; return;
} }
/*
** Return the fallback token corresponding to canonical token iToken, or
** 0 if iToken has no fallback.
*/
int ParseFallback(int iToken){
#ifdef YYFALLBACK
assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
return yyFallback[iToken];
#else
(void)iToken;
return 0;
#endif
}
...@@ -10,7 +10,7 @@ namespace { ...@@ -10,7 +10,7 @@ namespace {
// simple test // simple test
void simpleTest() { void simpleTest() {
SDiskbasedResultBuf* pResultBuf = NULL; SDiskbasedResultBuf* pResultBuf = NULL;
int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 64, 1024, 4096, NULL); int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4096, NULL);
int32_t pageId = 0; int32_t pageId = 0;
int32_t groupId = 0; int32_t groupId = 0;
...@@ -52,7 +52,7 @@ void simpleTest() { ...@@ -52,7 +52,7 @@ void simpleTest() {
void writeDownTest() { void writeDownTest() {
SDiskbasedResultBuf* pResultBuf = NULL; SDiskbasedResultBuf* pResultBuf = NULL;
int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 64, 1024, 4*1024, NULL); int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4*1024, NULL);
int32_t pageId = 0; int32_t pageId = 0;
int32_t writePageId = 0; int32_t writePageId = 0;
...@@ -99,7 +99,7 @@ void writeDownTest() { ...@@ -99,7 +99,7 @@ void writeDownTest() {
void recyclePageTest() { void recyclePageTest() {
SDiskbasedResultBuf* pResultBuf = NULL; SDiskbasedResultBuf* pResultBuf = NULL;
int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 64, 1024, 4*1024, NULL); int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4*1024, NULL);
int32_t pageId = 0; int32_t pageId = 0;
int32_t writePageId = 0; int32_t writePageId = 0;
......
...@@ -34,11 +34,9 @@ ...@@ -34,11 +34,9 @@
.tid = (_checkInfo)->tableId.tid, \ .tid = (_checkInfo)->tableId.tid, \
.uid = (_checkInfo)->tableId.uid}) .uid = (_checkInfo)->tableId.uid})
enum { enum {
TSDB_QUERY_TYPE_ALL = 1, TSDB_QUERY_TYPE_ALL = 1,
TSDB_QUERY_TYPE_LAST = 2, TSDB_QUERY_TYPE_LAST = 2,
TSDB_QUERY_TYPE_EXTERNAL = 3,
}; };
typedef struct SQueryFilePos { typedef struct SQueryFilePos {
...@@ -68,7 +66,7 @@ typedef struct STableCheckInfo { ...@@ -68,7 +66,7 @@ typedef struct STableCheckInfo {
STableId tableId; STableId tableId;
TSKEY lastKey; TSKEY lastKey;
STable* pTableObj; STable* pTableObj;
SBlockInfo* pCompInfo; SBlockInfo* pCompInfo;
int32_t compSize; int32_t compSize;
int32_t numOfBlocks:29; // number of qualified data blocks not the original blocks int32_t numOfBlocks:29; // number of qualified data blocks not the original blocks
int8_t chosen:2; // indicate which iterator should move forward int8_t chosen:2; // indicate which iterator should move forward
...@@ -78,8 +76,8 @@ typedef struct STableCheckInfo { ...@@ -78,8 +76,8 @@ typedef struct STableCheckInfo {
} STableCheckInfo; } STableCheckInfo;
typedef struct STableBlockInfo { typedef struct STableBlockInfo {
SBlock* compBlock; SBlock *compBlock;
STableCheckInfo* pTableCheckInfo; STableCheckInfo *pTableCheckInfo;
} STableBlockInfo; } STableBlockInfo;
typedef struct SBlockOrderSupporter { typedef struct SBlockOrderSupporter {
...@@ -111,6 +109,8 @@ typedef struct STsdbQueryHandle { ...@@ -111,6 +109,8 @@ typedef struct STsdbQueryHandle {
bool checkFiles; // check file stage bool checkFiles; // check file stage
bool cachelastrow; // check if last row cached bool cachelastrow; // check if last row cached
bool loadExternalRow; // load time window external data rows bool loadExternalRow; // load time window external data rows
bool currentLoadExternalRows; // current load external rows
int32_t loadType; // block load type
void* qinfo; // query info handle, for debug purpose void* qinfo; // query info handle, for debug purpose
int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows
SDFileSet* pFileGroup; SDFileSet* pFileGroup;
...@@ -147,6 +147,8 @@ static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, ...@@ -147,6 +147,8 @@ static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey,
static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2); static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2);
static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SMemRef* pMemRef); static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SMemRef* pMemRef);
static void* doFreeColumnInfoData(SArray* pColumnInfoData); static void* doFreeColumnInfoData(SArray* pColumnInfoData);
static void* destroyTableCheckInfo(SArray* pTableCheckInfo);
static bool tsdbGetExternalRow(TsdbQueryHandleT pHandle);
static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) { static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) {
pBlockLoadInfo->slot = -1; pBlockLoadInfo->slot = -1;
...@@ -294,40 +296,48 @@ static SArray* createCheckInfoFromTableGroup(STsdbQueryHandle* pQueryHandle, STa ...@@ -294,40 +296,48 @@ static SArray* createCheckInfoFromTableGroup(STsdbQueryHandle* pQueryHandle, STa
taosArraySort(pTableCheckInfo, tsdbCheckInfoCompar); taosArraySort(pTableCheckInfo, tsdbCheckInfoCompar);
size_t gsize = taosArrayGetSize(pTableCheckInfo); size_t gsize = taosArrayGetSize(pTableCheckInfo);
for (int32_t i = 0; i < gsize; ++i) { for (int32_t i = 0; i < gsize; ++i) {
STableCheckInfo* pInfo = (STableCheckInfo*) taosArrayGet(pTableCheckInfo, i); STableCheckInfo* pInfo = (STableCheckInfo*) taosArrayGet(pTableCheckInfo, i);
taosArrayPush(pTable, &pInfo->pTableObj); taosArrayPush(pTable, &pInfo->pTableObj);
} }
*psTable = pTable; *psTable = pTable;
return pTableCheckInfo; return pTableCheckInfo;
} }
static SArray* createCheckInfoFromCheckInfo(SArray* pTableCheckInfo, TSKEY skey, SArray** psTable) { static void resetCheckInfo(STsdbQueryHandle* pQueryHandle) {
size_t si = taosArrayGetSize(pTableCheckInfo); size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
SArray* pNew = taosArrayInit(si, sizeof(STableCheckInfo)); assert(numOfTables >= 1);
if (pNew == NULL) {
return NULL; // todo apply the lastkey of table check to avoid to load header file
for (int32_t i = 0; i < numOfTables; ++i) {
STableCheckInfo* pCheckInfo = (STableCheckInfo*) taosArrayGet(pQueryHandle->pTableCheckInfo, i);
pCheckInfo->lastKey = pQueryHandle->window.skey;
pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter);
pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter);
pCheckInfo->initBuf = false;
if (ASCENDING_TRAVERSE(pQueryHandle->order)) {
assert(pCheckInfo->lastKey >= pQueryHandle->window.skey);
} else {
assert(pCheckInfo->lastKey <= pQueryHandle->window.skey);
}
} }
}
SArray* pTable = taosArrayInit(si, sizeof(STable*)); // only one table, not need to sort again
static SArray* createCheckInfoFromCheckInfo(STableCheckInfo* pCheckInfo, TSKEY skey, SArray** psTable) {
SArray* pNew = taosArrayInit(1, sizeof(STableCheckInfo));
SArray* pTable = taosArrayInit(1, sizeof(STable*));
for (int32_t j = 0; j < si; ++j) { STableCheckInfo info = { .lastKey = skey, .pTableObj = pCheckInfo->pTableObj};
STableCheckInfo* pCheckInfo = (STableCheckInfo*) taosArrayGet(pTableCheckInfo, j);
STableCheckInfo info = { .lastKey = skey, .pTableObj = pCheckInfo->pTableObj};
info.tableId = pCheckInfo->tableId; info.tableId = pCheckInfo->tableId;
taosArrayPush(pNew, &info); taosArrayPush(pNew, &info);
taosArrayPush(pTable, &pCheckInfo->pTableObj); taosArrayPush(pTable, &pCheckInfo->pTableObj);
}
*psTable = pTable; *psTable = pTable;
// it is ordered already, no need to sort again.
taosArraySort(pNew, tsdbCheckInfoCompar);
return pNew; return pNew;
} }
...@@ -351,14 +361,15 @@ static STsdbQueryHandle* tsdbQueryTablesImpl(STsdbRepo* tsdb, STsdbQueryCond* pC ...@@ -351,14 +361,15 @@ static STsdbQueryHandle* tsdbQueryTablesImpl(STsdbRepo* tsdb, STsdbQueryCond* pC
pQueryHandle->locateStart = false; pQueryHandle->locateStart = false;
pQueryHandle->pMemRef = pMemRef; pQueryHandle->pMemRef = pMemRef;
pQueryHandle->loadExternalRow = pCond->loadExternalRows; pQueryHandle->loadExternalRow = pCond->loadExternalRows;
pQueryHandle->currentLoadExternalRows = pCond->loadExternalRows;
pQueryHandle->loadType = pCond->type;
if (tsdbInitReadH(&pQueryHandle->rhelper, (STsdbRepo*)tsdb) != 0) { if (tsdbInitReadH(&pQueryHandle->rhelper, (STsdbRepo*)tsdb) != 0) {
goto out_of_memory; goto out_of_memory;
} }
//tsdbMayTakeMemSnapshot(pQueryHandle);
assert(pCond != NULL && pCond->numOfCols > 0 && pMemRef != NULL); assert(pCond != NULL && pCond->numOfCols > 0 && pMemRef != NULL);
if (ASCENDING_TRAVERSE(pCond->order)) { if (ASCENDING_TRAVERSE(pCond->order)) {
assert(pQueryHandle->window.skey <= pQueryHandle->window.ekey); assert(pQueryHandle->window.skey <= pQueryHandle->window.ekey);
} else { } else {
...@@ -388,7 +399,9 @@ static STsdbQueryHandle* tsdbQueryTablesImpl(STsdbRepo* tsdb, STsdbQueryCond* pC ...@@ -388,7 +399,9 @@ static STsdbQueryHandle* tsdbQueryTablesImpl(STsdbRepo* tsdb, STsdbQueryCond* pC
pQueryHandle->statis[i].colId = colInfo.info.colId; pQueryHandle->statis[i].colId = colInfo.info.colId;
} }
pQueryHandle->defaultLoadColumn = getDefaultLoadColumns(pQueryHandle, true); if (pCond->numOfCols > 0) {
pQueryHandle->defaultLoadColumn = getDefaultLoadColumns(pQueryHandle, true);
}
STsdbMeta* pMeta = tsdbGetMeta(tsdb); STsdbMeta* pMeta = tsdbGetMeta(tsdb);
assert(pMeta != NULL); assert(pMeta != NULL);
...@@ -433,6 +446,74 @@ TsdbQueryHandleT* tsdbQueryTables(STsdbRepo* tsdb, STsdbQueryCond* pCond, STable ...@@ -433,6 +446,74 @@ TsdbQueryHandleT* tsdbQueryTables(STsdbRepo* tsdb, STsdbQueryCond* pCond, STable
return (TsdbQueryHandleT) pQueryHandle; return (TsdbQueryHandleT) pQueryHandle;
} }
void tsdbResetQueryHandle(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond) {
STsdbQueryHandle* pQueryHandle = queryHandle;
pQueryHandle->order = pCond->order;
pQueryHandle->window = pCond->twindow;
pQueryHandle->type = TSDB_QUERY_TYPE_ALL;
pQueryHandle->cur.fid = -1;
pQueryHandle->cur.win = TSWINDOW_INITIALIZER;
pQueryHandle->checkFiles = true;
pQueryHandle->activeIndex = 0; // current active table index
pQueryHandle->locateStart = false;
pQueryHandle->loadExternalRow = pCond->loadExternalRows;
if (ASCENDING_TRAVERSE(pCond->order)) {
assert(pQueryHandle->window.skey <= pQueryHandle->window.ekey);
} else {
assert(pQueryHandle->window.skey >= pQueryHandle->window.ekey);
}
// allocate buffer in order to load data blocks from file
memset(pQueryHandle->statis, 0, sizeof(SDataStatis));
tsdbInitDataBlockLoadInfo(&pQueryHandle->dataBlockLoadInfo);
tsdbInitCompBlockLoadInfo(&pQueryHandle->compBlockLoadInfo);
resetCheckInfo(pQueryHandle);
}
void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond, STableGroupInfo* groupList) {
STsdbQueryHandle* pQueryHandle = queryHandle;
pQueryHandle->order = pCond->order;
pQueryHandle->window = pCond->twindow;
pQueryHandle->type = TSDB_QUERY_TYPE_ALL;
pQueryHandle->cur.fid = -1;
pQueryHandle->cur.win = TSWINDOW_INITIALIZER;
pQueryHandle->checkFiles = true;
pQueryHandle->activeIndex = 0; // current active table index
pQueryHandle->locateStart = false;
pQueryHandle->loadExternalRow = pCond->loadExternalRows;
if (ASCENDING_TRAVERSE(pCond->order)) {
assert(pQueryHandle->window.skey <= pQueryHandle->window.ekey);
} else {
assert(pQueryHandle->window.skey >= pQueryHandle->window.ekey);
}
// allocate buffer in order to load data blocks from file
memset(pQueryHandle->statis, 0, sizeof(SDataStatis));
tsdbInitDataBlockLoadInfo(&pQueryHandle->dataBlockLoadInfo);
tsdbInitCompBlockLoadInfo(&pQueryHandle->compBlockLoadInfo);
SArray* pTable = NULL;
STsdbMeta* pMeta = tsdbGetMeta(pQueryHandle->pTsdb);
pQueryHandle->pTableCheckInfo = destroyTableCheckInfo(pQueryHandle->pTableCheckInfo);
pQueryHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pQueryHandle, groupList, pMeta, &pTable);
if (pQueryHandle->pTableCheckInfo == NULL) {
tsdbCleanupQueryHandle(pQueryHandle);
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
}
pQueryHandle->prev = doFreeColumnInfoData(pQueryHandle->prev);
pQueryHandle->next = doFreeColumnInfoData(pQueryHandle->next);
}
TsdbQueryHandleT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo, SMemRef* pMemRef) { TsdbQueryHandleT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo, SMemRef* pMemRef) {
pCond->twindow = updateLastrowForEachGroup(groupList); pCond->twindow = updateLastrowForEachGroup(groupList);
...@@ -469,12 +550,45 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) { ...@@ -469,12 +550,45 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) {
return res; return res;
} }
// leave only one table for each group
static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGroupList) {
assert(pGroupList);
size_t numOfGroup = taosArrayGetSize(pGroupList->pGroupList);
STableGroupInfo* pNew = calloc(1, sizeof(STableGroupInfo));
pNew->pGroupList = taosArrayInit(numOfGroup, sizeof(SArray));
for(int32_t i = 0; i < numOfGroup; ++i) {
SArray* oneGroup = taosArrayGetP(pGroupList->pGroupList, i);
size_t numOfTables = taosArrayGetSize(oneGroup);
SArray* px = taosArrayInit(4, sizeof(STableKeyInfo));
for (int32_t j = 0; j < numOfTables; ++j) {
STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(oneGroup, j);
if (window->skey <= pInfo->lastKey && ((STable*)pInfo->pTable)->lastKey != TSKEY_INITIAL_VAL) {
taosArrayPush(px, pInfo);
pNew->numOfTables += 1;
break;
}
}
// there are no data in this group
if (taosArrayGetSize(px) == 0) {
taosArrayDestroy(px);
} else {
taosArrayPush(pNew->pGroupList, &px);
}
}
return pNew;
}
TsdbQueryHandleT tsdbQueryRowsInExternalWindow(STsdbRepo *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, void* qinfo, SMemRef* pRef) { TsdbQueryHandleT tsdbQueryRowsInExternalWindow(STsdbRepo *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, void* qinfo, SMemRef* pRef) {
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo, pRef); STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList);
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, pNew, qinfo, pRef);
pQueryHandle->loadExternalRow = true; pQueryHandle->loadExternalRow = true;
if (pQueryHandle != NULL) { pQueryHandle->currentLoadExternalRows = true;
changeQueryHandleForInterpQuery(pQueryHandle);
}
return pQueryHandle; return pQueryHandle;
} }
...@@ -769,77 +883,94 @@ static int32_t binarySearchForBlock(SBlock* pBlock, int32_t numOfBlocks, TSKEY s ...@@ -769,77 +883,94 @@ static int32_t binarySearchForBlock(SBlock* pBlock, int32_t numOfBlocks, TSKEY s
return midSlot; return midSlot;
} }
static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlocks) { static int32_t loadBlockInfo(STsdbQueryHandle * pQueryHandle, int32_t index, int32_t* numOfBlocks) {
// load all the comp offset value for all tables in this file int32_t code = 0;
int32_t code = TSDB_CODE_SUCCESS;
*numOfBlocks = 0; STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, index);
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); pCheckInfo->numOfBlocks = 0;
for (int32_t i = 0; i < numOfTables; ++i) { if (tsdbSetReadTable(&pQueryHandle->rhelper, pCheckInfo->pTableObj) != TSDB_CODE_SUCCESS) {
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i); code = terrno;
pCheckInfo->numOfBlocks = 0; return code;
}
if (tsdbSetReadTable(&pQueryHandle->rhelper, pCheckInfo->pTableObj) != TSDB_CODE_SUCCESS) { SBlockIdx* compIndex = pQueryHandle->rhelper.pBlkIdx;
code = terrno;
break; // no data block in this file, try next file
} if (compIndex == NULL || compIndex->uid != pCheckInfo->tableId.uid) {
return 0; // no data blocks in the file belongs to pCheckInfo->pTable
}
SBlockIdx* compIndex = pQueryHandle->rhelper.pBlkIdx; if (pCheckInfo->compSize < (int32_t)compIndex->len) {
assert(compIndex->len > 0);
// no data block in this file, try next file char* t = realloc(pCheckInfo->pCompInfo, compIndex->len);
if (compIndex == NULL || compIndex->uid != pCheckInfo->tableId.uid) { if (t == NULL) {
continue; // no data blocks in the file belongs to pCheckInfo->pTable terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
code = TSDB_CODE_TDB_OUT_OF_MEMORY;
return code;
} }
if (pCheckInfo->compSize < (int32_t)compIndex->len) { pCheckInfo->pCompInfo = (SBlockInfo*)t;
assert(compIndex->len > 0); pCheckInfo->compSize = compIndex->len;
}
char* t = realloc(pCheckInfo->pCompInfo, compIndex->len); tsdbLoadBlockInfo(&(pQueryHandle->rhelper), (void*)(pCheckInfo->pCompInfo));
if (t == NULL) { SBlockInfo* pCompInfo = pCheckInfo->pCompInfo;
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
code = TSDB_CODE_TDB_OUT_OF_MEMORY;
break;
}
pCheckInfo->pCompInfo = (SBlockInfo*) t; TSKEY s = TSKEY_INITIAL_VAL, e = TSKEY_INITIAL_VAL;
pCheckInfo->compSize = compIndex->len;
}
tsdbLoadBlockInfo(&(pQueryHandle->rhelper), (void *)(pCheckInfo->pCompInfo)); if (ASCENDING_TRAVERSE(pQueryHandle->order)) {
SBlockInfo* pCompInfo = pCheckInfo->pCompInfo; assert(pCheckInfo->lastKey <= pQueryHandle->window.ekey && pQueryHandle->window.skey <= pQueryHandle->window.ekey);
} else {
assert(pCheckInfo->lastKey >= pQueryHandle->window.ekey && pQueryHandle->window.skey >= pQueryHandle->window.ekey);
}
TSKEY s = TSKEY_INITIAL_VAL, e = TSKEY_INITIAL_VAL; s = MIN(pCheckInfo->lastKey, pQueryHandle->window.ekey);
e = MAX(pCheckInfo->lastKey, pQueryHandle->window.ekey);
if (ASCENDING_TRAVERSE(pQueryHandle->order)) { // discard the unqualified data block based on the query time window
assert(pCheckInfo->lastKey <= pQueryHandle->window.ekey && pQueryHandle->window.skey <= pQueryHandle->window.ekey); int32_t start = binarySearchForBlock(pCompInfo->blocks, compIndex->numOfBlocks, s, TSDB_ORDER_ASC);
} else { int32_t end = start;
assert(pCheckInfo->lastKey >= pQueryHandle->window.ekey && pQueryHandle->window.skey >= pQueryHandle->window.ekey);
}
s = MIN(pCheckInfo->lastKey, pQueryHandle->window.ekey); if (s > pCompInfo->blocks[start].keyLast) {
e = MAX(pCheckInfo->lastKey, pQueryHandle->window.ekey); return 0;
}
// discard the unqualified data block based on the query time window // todo speedup the procedure of located end block
int32_t start = binarySearchForBlock(pCompInfo->blocks, compIndex->numOfBlocks, s, TSDB_ORDER_ASC); while (end < (int32_t)compIndex->numOfBlocks && (pCompInfo->blocks[end].keyFirst <= e)) {
int32_t end = start; end += 1;
}
if (s > pCompInfo->blocks[start].keyLast) { pCheckInfo->numOfBlocks = (end - start);
continue;
}
// todo speedup the procedure of located end block if (start > 0) {
while (end < (int32_t)compIndex->numOfBlocks && (pCompInfo->blocks[end].keyFirst <= e)) { memmove(pCompInfo->blocks, &pCompInfo->blocks[start], pCheckInfo->numOfBlocks * sizeof(SBlock));
end += 1; }
}
pCheckInfo->numOfBlocks = (end - start); (*numOfBlocks) += pCheckInfo->numOfBlocks;
return 0;
}
if (start > 0) { static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlocks) {
memmove(pCompInfo->blocks, &pCompInfo->blocks[start], pCheckInfo->numOfBlocks * sizeof(SBlock)); // load all the comp offset value for all tables in this file
} int32_t code = TSDB_CODE_SUCCESS;
*numOfBlocks = 0;
size_t numOfTables = 0;
if (pQueryHandle->loadType == BLOCK_LOAD_TABLE_SEQ_ORDER) {
code = loadBlockInfo(pQueryHandle, pQueryHandle->activeIndex, numOfBlocks);
} else if (pQueryHandle->loadType == BLOCK_LOAD_OFFSET_SEQ_ORDER) {
numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
(*numOfBlocks) += pCheckInfo->numOfBlocks; for (int32_t i = 0; i < numOfTables; ++i) {
code = loadBlockInfo(pQueryHandle, i, numOfBlocks);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
}
} else {
assert(0);
} }
return code; return code;
...@@ -1268,7 +1399,7 @@ static void copyOneRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity, ...@@ -1268,7 +1399,7 @@ static void copyOneRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity,
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
SET_DOUBLE_PTR(pData, value); SET_DOUBLE_PTR(pData, value);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
*(TSKEY *)pData = tdGetKey(*(TKEY *)value); *(TSKEY *)pData = tdGetKey(*(TKEY *)value);
break; break;
default: default:
...@@ -1730,6 +1861,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO ...@@ -1730,6 +1861,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
memset(pQueryHandle->pDataBlockInfo, 0, size); memset(pQueryHandle->pDataBlockInfo, 0, size);
*numOfAllocBlocks = numOfBlocks; *numOfAllocBlocks = numOfBlocks;
// access data blocks according to the offset of each block in asc/desc order.
int32_t numOfTables = (int32_t)taosArrayGetSize(pQueryHandle->pTableCheckInfo); int32_t numOfTables = (int32_t)taosArrayGetSize(pQueryHandle->pTableCheckInfo);
SBlockOrderSupporter sup = {0}; SBlockOrderSupporter sup = {0};
...@@ -1959,6 +2091,91 @@ static void moveToNextDataBlockInCurrentFile(STsdbQueryHandle* pQueryHandle) { ...@@ -1959,6 +2091,91 @@ static void moveToNextDataBlockInCurrentFile(STsdbQueryHandle* pQueryHandle) {
cur->blockCompleted = false; cur->blockCompleted = false;
} }
int32_t tsdbGetFileBlocksDistInfo(TsdbQueryHandleT* queryHandle, STableBlockDist* pTableBlockInfo) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) queryHandle;
pTableBlockInfo->totalSize = 0;
STsdbFS* pFileHandle = REPO_FS(pQueryHandle->pTsdb);
// find the start data block in file
pQueryHandle->locateStart = true;
STsdbCfg* pCfg = &pQueryHandle->pTsdb->config;
int32_t fid = getFileIdFromKey(pQueryHandle->window.skey, pCfg->daysPerFile, pCfg->precision);
tsdbRLockFS(pFileHandle);
tsdbFSIterInit(&pQueryHandle->fileIter, pFileHandle, pQueryHandle->order);
tsdbFSIterSeek(&pQueryHandle->fileIter, fid);
tsdbUnLockFS(pFileHandle);
pTableBlockInfo->numOfFiles += 1;
int32_t code = TSDB_CODE_SUCCESS;
int32_t numOfBlocks = 0;
int32_t numOfTables = (int32_t)taosArrayGetSize(pQueryHandle->pTableCheckInfo);
STimeWindow win = TSWINDOW_INITIALIZER;
while (true) {
numOfBlocks = 0;
tsdbRLockFS(REPO_FS(pQueryHandle->pTsdb));
if ((pQueryHandle->pFileGroup = tsdbFSIterNext(&pQueryHandle->fileIter)) == NULL) {
tsdbUnLockFS(REPO_FS(pQueryHandle->pTsdb));
break;
}
tsdbGetFidKeyRange(pCfg->daysPerFile, pCfg->precision, pQueryHandle->pFileGroup->fid, &win.skey, &win.ekey);
// current file are not overlapped with query time window, ignore remain files
if ((ASCENDING_TRAVERSE(pQueryHandle->order) && win.skey > pQueryHandle->window.ekey) ||
(!ASCENDING_TRAVERSE(pQueryHandle->order) && win.ekey < pQueryHandle->window.ekey)) {
tsdbUnLockFS(REPO_FS(pQueryHandle->pTsdb));
tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %p", pQueryHandle,
pQueryHandle->window.skey, pQueryHandle->window.ekey, pQueryHandle->qinfo);
pQueryHandle->pFileGroup = NULL;
break;
}
pTableBlockInfo->numOfFiles += 1;
if (tsdbSetAndOpenReadFSet(&pQueryHandle->rhelper, pQueryHandle->pFileGroup) < 0) {
tsdbUnLockFS(REPO_FS(pQueryHandle->pTsdb));
code = terrno;
break;
}
tsdbUnLockFS(REPO_FS(pQueryHandle->pTsdb));
if (tsdbLoadBlockIdx(&pQueryHandle->rhelper) < 0) {
code = terrno;
break;
}
if ((code = getFileCompInfo(pQueryHandle, &numOfBlocks)) != TSDB_CODE_SUCCESS) {
break;
}
tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %p", pQueryHandle, numOfBlocks, numOfTables,
pQueryHandle->pFileGroup->fid, pQueryHandle->qinfo);
if (numOfBlocks == 0) {
continue;
}
for (int32_t i = 0; i < numOfTables; ++i) {
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i);
SBlock* pBlock = pCheckInfo->pCompInfo->blocks;
for (int32_t j = 0; j < pCheckInfo->numOfBlocks; ++j) {
pTableBlockInfo->totalSize += pBlock[j].len;
int32_t numOfRows = pBlock[j].numOfRows;
taosArrayPush(pTableBlockInfo->dataBlockInfos, &numOfRows);
}
}
}
return code;
}
static int32_t getDataBlocksInFiles(STsdbQueryHandle* pQueryHandle, bool* exists) { static int32_t getDataBlocksInFiles(STsdbQueryHandle* pQueryHandle, bool* exists) {
STsdbFS* pFileHandle = REPO_FS(pQueryHandle->pTsdb); STsdbFS* pFileHandle = REPO_FS(pQueryHandle->pTsdb);
SQueryFilePos* cur = &pQueryHandle->cur; SQueryFilePos* cur = &pQueryHandle->cur;
...@@ -2017,19 +2234,14 @@ static bool doHasDataInBuffer(STsdbQueryHandle* pQueryHandle) { ...@@ -2017,19 +2234,14 @@ static bool doHasDataInBuffer(STsdbQueryHandle* pQueryHandle) {
pQueryHandle->activeIndex += 1; pQueryHandle->activeIndex += 1;
} }
if (pQueryHandle->loadExternalRow && pQueryHandle->window.skey == pQueryHandle->window.ekey) {
SMemRef* pMemRef = pQueryHandle->pMemRef;
doGetExternalRow(pQueryHandle, TSDB_PREV_ROW, pMemRef);
doGetExternalRow(pQueryHandle, TSDB_NEXT_ROW, pMemRef);
}
// no data in memtable or imemtable, decrease the memory reference. // no data in memtable or imemtable, decrease the memory reference.
tsdbMayUnTakeMemSnapshot(pQueryHandle); // TODO !!
// tsdbMayUnTakeMemSnapshot(pQueryHandle);
return false; return false;
} }
//todo not unref yet, since it is not support multi-group interpolation query //todo not unref yet, since it is not support multi-group interpolation query
static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle) { static UNUSED_FUNC void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle) {
// filter the queried time stamp in the first place // filter the queried time stamp in the first place
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle; STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle;
...@@ -2152,149 +2364,164 @@ static void destroyHelper(void* param) { ...@@ -2152,149 +2364,164 @@ static void destroyHelper(void* param) {
free(param); free(param);
} }
// handle data in cache situation static bool loadBlockOfActiveTable(STsdbQueryHandle* pQueryHandle) {
bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle;
int64_t stime = taosGetTimestampUs();
int64_t elapsedTime = stime;
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
assert(numOfTables > 0);
if (pQueryHandle->type == TSDB_QUERY_TYPE_LAST && pQueryHandle->cachelastrow) {
// the last row is cached in buffer, return it directly.
// here note that the pQueryHandle->window must be the TS_INITIALIZER
int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pQueryHandle));
SQueryFilePos* cur = &pQueryHandle->cur;
SDataRow pRow = NULL;
TSKEY key = TSKEY_INITIAL_VAL;
int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order)? 1:-1;
if (++pQueryHandle->activeIndex < numOfTables) {
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key);
if (ret != TSDB_CODE_SUCCESS) {
return false;
}
copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, 0, pRow, numOfCols, pCheckInfo->pTableObj, NULL);
tfree(pRow);
// update the last key value
pCheckInfo->lastKey = key + step;
cur->rows = 1; // only one row
cur->lastKey = key + step;
cur->mixBlock = true;
cur->win.skey = key;
cur->win.ekey = key;
return true;
}
return false;
}
if (pQueryHandle->checkFiles) { if (pQueryHandle->checkFiles) {
// check if the query range overlaps with the file data block // check if the query range overlaps with the file data block
bool exists = true; bool exists = true;
int32_t code = getDataBlocksInFiles(pQueryHandle, &exists); int32_t code = getDataBlocksInFiles(pQueryHandle, &exists);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
pQueryHandle->activeIndex = 0;
pQueryHandle->checkFiles = false; pQueryHandle->checkFiles = false;
return false; return false;
} }
if (exists) { if (exists) {
pQueryHandle->cost.checkForNextTime += (taosGetTimestampUs() - stime); if (pQueryHandle->currentLoadExternalRows && pQueryHandle->window.skey == pQueryHandle->window.ekey) {
SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, 0);
assert(*(int64_t*)pColInfo->pData == pQueryHandle->window.skey);
}
pQueryHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found.
return exists; return exists;
} }
pQueryHandle->activeIndex = 0;
pQueryHandle->checkFiles = false; pQueryHandle->checkFiles = false;
} }
// TODO: opt by consider the scan order if (hasMoreDataInCache(pQueryHandle)) {
bool ret = doHasDataInBuffer(pQueryHandle); pQueryHandle->currentLoadExternalRows = false;
terrno = TSDB_CODE_SUCCESS; return true;
}
elapsedTime = taosGetTimestampUs() - stime; // current result is empty
pQueryHandle->cost.checkForNextTime += elapsedTime; if (pQueryHandle->currentLoadExternalRows && pQueryHandle->window.skey == pQueryHandle->window.ekey && pQueryHandle->cur.rows == 0) {
return ret; SMemRef* pMemRef = pQueryHandle->pMemRef;
doGetExternalRow(pQueryHandle, TSDB_PREV_ROW, pMemRef);
doGetExternalRow(pQueryHandle, TSDB_NEXT_ROW, pMemRef);
bool result = tsdbGetExternalRow(pQueryHandle);
pQueryHandle->prev = doFreeColumnInfoData(pQueryHandle->prev);
pQueryHandle->next = doFreeColumnInfoData(pQueryHandle->next);
pQueryHandle->currentLoadExternalRows = false;
return result;
}
return false;
} }
bool tsdbNextDataBlockWithoutMerge(TsdbQueryHandleT* pHandle) { static bool loadCachedLastRow(STsdbQueryHandle* pQueryHandle) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle; // the last row is cached in buffer, return it directly.
// here note that the pQueryHandle->window must be the TS_INITIALIZER
int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pQueryHandle));
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
assert(numOfTables > 0 && numOfCols > 0);
int64_t stime = taosGetTimestampUs(); SQueryFilePos* cur = &pQueryHandle->cur;
int64_t elapsedTime = stime;
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); SDataRow pRow = NULL;
assert(numOfTables > 0); TSKEY key = TSKEY_INITIAL_VAL;
int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order)? 1:-1;
if (pQueryHandle->type == TSDB_QUERY_TYPE_LAST && pQueryHandle->cachelastrow) { if (++pQueryHandle->activeIndex < numOfTables) {
// the last row is cached in buffer, return it directly. STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
// here note that the pQueryHandle->window must be the TS_INITIALIZER int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key);
int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pQueryHandle)); if (ret != TSDB_CODE_SUCCESS) {
SQueryFilePos* cur = &pQueryHandle->cur; return false;
}
SDataRow pRow = NULL;
TSKEY key = TSKEY_INITIAL_VAL;
int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order)? 1:-1;
if (++pQueryHandle->activeIndex < numOfTables) {
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key);
if (ret != TSDB_CODE_SUCCESS) {
return false;
}
copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, 0, pRow, numOfCols, pCheckInfo->pTableObj, NULL); copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, 0, pRow, numOfCols, pCheckInfo->pTableObj, NULL);
tfree(pRow); tfree(pRow);
// update the last key value // update the last key value
pCheckInfo->lastKey = key + step; pCheckInfo->lastKey = key + step;
cur->rows = 1; // only one row cur->rows = 1; // only one row
cur->lastKey = key + step; cur->lastKey = key + step;
cur->mixBlock = true; cur->mixBlock = true;
cur->win.skey = key; cur->win.skey = key;
cur->win.ekey = key; cur->win.ekey = key;
return true;
}
return false;
}
static bool loadDataBlockFromTableSeq(STsdbQueryHandle* pQueryHandle) {
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
assert(numOfTables > 0);
int64_t stime = taosGetTimestampUs();
while(pQueryHandle->activeIndex < numOfTables) {
if (loadBlockOfActiveTable(pQueryHandle)) {
return true; return true;
} }
return false; STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
pCheckInfo->numOfBlocks = 0;
pQueryHandle->activeIndex += 1;
pQueryHandle->locateStart = false;
pQueryHandle->checkFiles = true;
pQueryHandle->cur.rows = 0;
pQueryHandle->currentLoadExternalRows = pQueryHandle->loadExternalRow;
terrno = TSDB_CODE_SUCCESS;
int64_t elapsedTime = taosGetTimestampUs() - stime;
pQueryHandle->cost.checkForNextTime += elapsedTime;
} }
if (pQueryHandle->checkFiles) { return false;
// check if the query range overlaps with the file data block }
bool exists = true;
// handle data in cache situation
bool tsdbNextDataBlock(TsdbQueryHandleT pHandle) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle;
int64_t stime = taosGetTimestampUs();
int64_t elapsedTime = stime;
if (pQueryHandle->type == TSDB_QUERY_TYPE_LAST && pQueryHandle->cachelastrow) {
return loadCachedLastRow(pQueryHandle);
}
if (pQueryHandle->loadType == BLOCK_LOAD_TABLE_SEQ_ORDER) {
return loadDataBlockFromTableSeq(pQueryHandle);
} else { // loadType == RR and Offset Order
if (pQueryHandle->checkFiles) {
// check if the query range overlaps with the file data block
bool exists = true;
int32_t code = getDataBlocksInFiles(pQueryHandle, &exists);
if (code != TSDB_CODE_SUCCESS) {
pQueryHandle->activeIndex = 0;
pQueryHandle->checkFiles = false;
return false;
}
if (exists) {
pQueryHandle->cost.checkForNextTime += (taosGetTimestampUs() - stime);
return exists;
}
int32_t code = getDataBlocksInFiles(pQueryHandle, &exists);
if (code != TSDB_CODE_SUCCESS) {
pQueryHandle->activeIndex = 0; pQueryHandle->activeIndex = 0;
pQueryHandle->checkFiles = false; pQueryHandle->checkFiles = false;
return false;
} }
if (exists) { // TODO: opt by consider the scan order
pQueryHandle->cost.checkForNextTime += (taosGetTimestampUs() - stime); bool ret = doHasDataInBuffer(pQueryHandle);
return exists; terrno = TSDB_CODE_SUCCESS;
}
pQueryHandle->activeIndex = 0; elapsedTime = taosGetTimestampUs() - stime;
pQueryHandle->checkFiles = false; pQueryHandle->cost.checkForNextTime += elapsedTime;
return ret;
} }
elapsedTime = taosGetTimestampUs() - stime;
pQueryHandle->cost.checkForNextTime += elapsedTime;
return false;
} }
static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SMemRef* pMemRef) { static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SMemRef* pMemRef) {
...@@ -2342,7 +2569,7 @@ static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SM ...@@ -2342,7 +2569,7 @@ static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SM
} }
// load the previous row // load the previous row
STsdbQueryCond cond = {.numOfCols = numOfCols, .loadExternalRows = false,}; STsdbQueryCond cond = {.numOfCols = numOfCols, .loadExternalRows = false, .type = BLOCK_LOAD_OFFSET_SEQ_ORDER};
if (type == TSDB_PREV_ROW) { if (type == TSDB_PREV_ROW) {
cond.order = TSDB_ORDER_DESC; cond.order = TSDB_ORDER_DESC;
cond.twindow = (STimeWindow){pQueryHandle->window.skey, INT64_MIN}; cond.twindow = (STimeWindow){pQueryHandle->window.skey, INT64_MIN};
...@@ -2363,20 +2590,20 @@ static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SM ...@@ -2363,20 +2590,20 @@ static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SM
} }
pSecQueryHandle = tsdbQueryTablesImpl(pQueryHandle->pTsdb, &cond, pQueryHandle->qinfo, pMemRef); pSecQueryHandle = tsdbQueryTablesImpl(pQueryHandle->pTsdb, &cond, pQueryHandle->qinfo, pMemRef);
tfree(cond.colList); tfree(cond.colList);
// current table, only one table
STableCheckInfo* pCurrent = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
SArray* psTable = NULL; SArray* psTable = NULL;
pSecQueryHandle->pTableCheckInfo = createCheckInfoFromCheckInfo(pCurrent, pSecQueryHandle->window.skey, &psTable);
pSecQueryHandle->pTableCheckInfo = createCheckInfoFromCheckInfo(pQueryHandle->pTableCheckInfo, pSecQueryHandle->window.skey, &psTable);
if (pSecQueryHandle->pTableCheckInfo == NULL) { if (pSecQueryHandle->pTableCheckInfo == NULL) {
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto out_of_memory; goto out_of_memory;
} }
tsdbMayTakeMemSnapshot(pSecQueryHandle, psTable);
tsdbMayTakeMemSnapshot(pSecQueryHandle, psTable);
if (!tsdbNextDataBlock((void*)pSecQueryHandle)) { if (!tsdbNextDataBlock((void*)pSecQueryHandle)) {
// no result in current query, free the corresponding result rows structure // no result in current query, free the corresponding result rows structure
if (type == TSDB_PREV_ROW) { if (type == TSDB_PREV_ROW) {
...@@ -2406,10 +2633,35 @@ out_of_memory: ...@@ -2406,10 +2633,35 @@ out_of_memory:
return terrno; return terrno;
} }
SArray* tsdbGetExternalRow(TsdbQueryHandleT *pHandle, SMemRef* pMemRef, int16_t type) { bool tsdbGetExternalRow(TsdbQueryHandleT pHandle) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle; STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle;
assert(type == TSDB_PREV_ROW || type == TSDB_NEXT_ROW); SQueryFilePos* cur = &pQueryHandle->cur;
return (type == TSDB_PREV_ROW)? pQueryHandle->prev:pQueryHandle->next;
cur->fid = INT32_MIN;
cur->mixBlock = true;
if (pQueryHandle->prev == NULL || pQueryHandle->next == NULL) {
cur->rows = 0;
return false;
}
int32_t numOfCols = (int32_t) QH_GET_NUM_OF_COLS(pQueryHandle);
for (int32_t i = 0; i < numOfCols; ++i) {
SColumnInfoData* pColInfoData = taosArrayGet(pQueryHandle->pColumns, i);
SColumnInfoData* first = taosArrayGet(pQueryHandle->prev, i);
memcpy(pColInfoData->pData, first->pData, pColInfoData->info.bytes);
SColumnInfoData* sec = taosArrayGet(pQueryHandle->next, i);
memcpy(((char*)pColInfoData->pData) + pColInfoData->info.bytes, sec->pData, pColInfoData->info.bytes);
if (i == 0 && pColInfoData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
cur->win.skey = *(TSKEY*)pColInfoData->pData;
cur->win.ekey = *(TSKEY*)(((char*)pColInfoData->pData) + TSDB_KEYSIZE);
}
}
cur->rows = 2;
return true;
} }
/* /*
...@@ -2949,10 +3201,10 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons ...@@ -2949,10 +3201,10 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
goto _error; goto _error;
} }
pGroupInfo->numOfTables = taosArrayGetSize(res); pGroupInfo->numOfTables = (uint32_t) taosArrayGetSize(res);
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey);
tsdbDebug("%p no table name/tag condition, all tables belong to one group, numOfTables:%" PRIzu "", tsdb, pGroupInfo->numOfTables); tsdbDebug("%p no table name/tag condition, all tables belong to one group, numOfTables:%u", tsdb, pGroupInfo->numOfTables);
taosArrayDestroy(res); taosArrayDestroy(res);
if (tsdbUnlockRepoMeta(tsdb) < 0) goto _error; if (tsdbUnlockRepoMeta(tsdb) < 0) goto _error;
...@@ -2994,10 +3246,10 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons ...@@ -2994,10 +3246,10 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
} END_TRY } END_TRY
doQueryTableList(pTable, res, expr); doQueryTableList(pTable, res, expr);
pGroupInfo->numOfTables = taosArrayGetSize(res); pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res);
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey);
tsdbDebug("%p stable tid:%d, uid:%"PRIu64" query, numOfTables:%" PRIzu ", belong to %" PRIzu " groups", tsdb, pTable->tableId.tid, tsdbDebug("%p stable tid:%d, uid:%"PRIu64" query, numOfTables:%u, belong to %" PRIzu " groups", tsdb, pTable->tableId.tid,
pTable->tableId.uid, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList)); pTable->tableId.uid, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList));
taosArrayDestroy(res); taosArrayDestroy(res);
...@@ -3074,7 +3326,7 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl ...@@ -3074,7 +3326,7 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl
return terrno; return terrno;
} }
pGroupInfo->numOfTables = taosArrayGetSize(group); pGroupInfo->numOfTables = (uint32_t) taosArrayGetSize(group);
if (pGroupInfo->numOfTables > 0) { if (pGroupInfo->numOfTables > 0) {
taosArrayPush(pGroupInfo->pGroupList, &group); taosArrayPush(pGroupInfo->pGroupList, &group);
} else { } else {
...@@ -3099,23 +3351,26 @@ static void* doFreeColumnInfoData(SArray* pColumnInfoData) { ...@@ -3099,23 +3351,26 @@ static void* doFreeColumnInfoData(SArray* pColumnInfoData) {
return NULL; return NULL;
} }
static void* destroyTableCheckInfo(SArray* pTableCheckInfo) {
size_t size = taosArrayGetSize(pTableCheckInfo);
for (int32_t i = 0; i < size; ++i) {
STableCheckInfo* p = taosArrayGet(pTableCheckInfo, i);
destroyTableMemIterator(p);
tfree(p->pCompInfo);
}
taosArrayDestroy(pTableCheckInfo);
return NULL;
}
void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*)queryHandle; STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*)queryHandle;
if (pQueryHandle == NULL) { if (pQueryHandle == NULL) {
return; return;
} }
if (pQueryHandle->pTableCheckInfo != NULL) {
size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
for (int32_t i = 0; i < size; ++i) {
STableCheckInfo* pTableCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i);
destroyTableMemIterator(pTableCheckInfo);
tfree(pTableCheckInfo->pCompInfo);
}
taosArrayDestroy(pQueryHandle->pTableCheckInfo);
}
pQueryHandle->pTableCheckInfo = destroyTableCheckInfo(pQueryHandle->pTableCheckInfo);
pQueryHandle->pColumns = doFreeColumnInfoData(pQueryHandle->pColumns); pQueryHandle->pColumns = doFreeColumnInfoData(pQueryHandle->pColumns);
taosArrayDestroy(pQueryHandle->defaultLoadColumn); taosArrayDestroy(pQueryHandle->defaultLoadColumn);
......
...@@ -25,7 +25,8 @@ extern "C" { ...@@ -25,7 +25,8 @@ extern "C" {
#define TARRAY_MIN_SIZE 8 #define TARRAY_MIN_SIZE 8
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize)) #define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize) #define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
#define TARRAY_GET_START(array) ((array)->pData)
typedef struct SArray { typedef struct SArray {
size_t size; size_t size;
......
...@@ -73,14 +73,14 @@ int main( int argc, char** argv ) { ...@@ -73,14 +73,14 @@ int main( int argc, char** argv ) {
} }
*/ */
typedef struct { typedef struct SBufferReader {
bool endian; bool endian;
const char* data; const char* data;
size_t pos; size_t pos;
size_t size; size_t size;
} SBufferReader; } SBufferReader;
typedef struct { typedef struct SBufferWriter {
bool endian; bool endian;
char* data; char* data;
size_t pos; size_t pos;
......
...@@ -94,8 +94,9 @@ while $i < 10 ...@@ -94,8 +94,9 @@ while $i < 10
$i = $i + 1 $i = $i + 1
endw endw
print ==> sleep 8 seconds to renew cache print ==> sleep 1 seconds to renew cache
sleep 8000 sql reset query cache
sleep 1000
print =============== step5 print =============== step5
......
...@@ -55,7 +55,7 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1 ...@@ -55,7 +55,7 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
print =============== step3 print =============== step3
print ==> sleep 8 seconds to renew cache print ==> sleep 1 seconds to renew cache
sql reset query cache sql reset query cache
sleep 1000 sleep 1000
......
...@@ -39,10 +39,9 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1 ...@@ -39,10 +39,9 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
print =============== step3 print =============== step3
print ==> sleep 8 seconds to renew cache print ==> sleep 1 seconds to renew cache
sleep 2000
sql reset query cache sql reset query cache
sleep 18000 sleep 1000
print =============== step4 print =============== step4
sql create database $db sql create database $db
......
...@@ -93,6 +93,7 @@ $halfTbNum = $tbNum / 2 ...@@ -93,6 +93,7 @@ $halfTbNum = $tbNum / 2
$nchar = 'nchar . $c $nchar = 'nchar . $c
$nchar = $nchar . ' $nchar = $nchar . '
$ts = $ts + 1
sql insert into $tb5 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb6 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb7 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb8 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb9 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) sql insert into $tb5 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb6 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb7 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb8 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) $tb9 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar )
$x = $x + 1 $x = $x + 1
endw endw
......
...@@ -426,7 +426,7 @@ if $data02 != 9.000000020 then ...@@ -426,7 +426,7 @@ if $data02 != 9.000000020 then
endi endi
# all possible function in the arithmetic expression, add more # all possible function in the arithmetic expression, add more
sql select min(c1) * max(c2) /4, sum(c1) * apercentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2), count(1)/sum(c1), avg(c2)*count(c2) from $stb where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-11-25 19:30:00.000'; sql select min(c1) * max(c2) /4, sum(c1) * apercentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2), count(1)/sum(c1), avg(c2)*count(c2) from $stb where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-11-25 19:30:01.000';
if $rows != 1 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -462,7 +462,7 @@ if $rows != 0 then ...@@ -462,7 +462,7 @@ if $rows != 0 then
endi endi
# no result return [d.3] # no result return [d.3]
sql select sum(c2) - avg(c2) from $stb where ts > '2018-11-25 19:30:00.000' sql select sum(c2) - avg(c2) from $stb where ts > '2018-11-25 19:30:01.000'
if $rows != 0 then if $rows != 0 then
return -1 return -1
endi endi
...@@ -520,35 +520,35 @@ if $data91 != 9 then ...@@ -520,35 +520,35 @@ if $data91 != 9 then
endi endi
# in group by column # in group by column
sql select apercentile(c6, 50)-first(c6)+last(c5)*12, last(c5)*12 from ca_stb0 group by c2; #sql select apercentile(c6, 50)-first(c6)+last(c5)*12, last(c5)*12 from ca_stb0 group by c2;
if $rows != 10 then #if $rows != 10 then
return -1 # return -1
endi #endi
#
if $data00 != 0.000000000 then #if $data00 != 0.000000000 then
return -1 # return -1
endi #endi
#
if $data01 != 0.000000000 then #if $data01 != 0.000000000 then
return -1 # return -1
endi #endi
#
if $data10 != 12.000000000 then #if $data10 != 12.000000000 then
return -1 # return -1
endi #endi
#
if $data11 != 12.000000000 then #if $data11 != 12.000000000 then
return -1 # return -1
endi #endi
#
if $data20 != 24.000000000 then #if $data20 != 24.000000000 then
return -1 # return -1
endi #endi
#
if $data21 != 24.000000000 then #if $data21 != 24.000000000 then
return -1 # return -1
endi #endi
#
sql_error select first(c6) - last(c6) *12 / count(*) from $stb group by c3; sql_error select first(c6) - last(c6) *12 / count(*) from $stb group by c3;
sql select first(c6) - last(c6) *12 / count(*) from $stb group by c5; sql select first(c6) - last(c6) *12 / count(*) from $stb group by c5;
......
...@@ -313,6 +313,7 @@ if $rows != 9 then ...@@ -313,6 +313,7 @@ if $rows != 9 then
return -1 return -1
endi endi
if $data01 != 0 then if $data01 != 0 then
print expect 0, actual:$data01
return -1 return -1
endi endi
if $data11 != 6 then if $data11 != 6 then
...@@ -979,10 +980,6 @@ if $data00 != @20-01-01 01:01:00.000@ then ...@@ -979,10 +980,6 @@ if $data00 != @20-01-01 01:01:00.000@ then
return -1 return -1
endi endi
if $data00 != @20-01-01 01:01:00.000@ then
return -1
endi
if $data1
if $data01 != 2.000000000 then if $data01 != 2.000000000 then
return -1 return -1
endi endi
......
...@@ -775,8 +775,24 @@ if $rows != 1 then ...@@ -775,8 +775,24 @@ if $rows != 1 then
return -1 return -1
endi endi
if $data00 != 0.000000000 then if $data00 != 0.000000000 then
return -1 return -1
endi endi
sql select count(tbname) from st1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
sql select count(id) from st1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
...@@ -579,7 +579,7 @@ $tb = $tbPrefix . 0 ...@@ -579,7 +579,7 @@ $tb = $tbPrefix . 0
## interp(*) from stb + group by + fill(none) ## interp(*) from stb + group by + fill(none)
$t = $ts0 + 1000 $t = $ts0 + 1000
sql select interp(*) from $stb where ts = $t fill(NULL) group by tbname sql select interp(*) from $stb where ts = $t fill(NULL) group by tbname
if $rows != $tbNum then if $rows != $tbNum then
return -1 return -1
endi endi
......
...@@ -347,6 +347,7 @@ $val = $rowNum + $rowNum ...@@ -347,6 +347,7 @@ $val = $rowNum + $rowNum
print $val print $val
print $rows print $rows
if $rows != $val then if $rows != $val then
print expect $val , actual:$rows
return -1 return -1
endi endi
......
...@@ -538,6 +538,7 @@ $offset = $offset + 1 ...@@ -538,6 +538,7 @@ $offset = $offset + 1
sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit $offset offset $offset sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit $offset offset $offset
$val = $rowNum - $offset $val = $rowNum - $offset
if $rows != $val then if $rows != $val then
print expect $val, actual:$rows
return -1 return -1
endi endi
if $data00 != @18-10-22 02:30:00.000@ then if $data00 != @18-10-22 02:30:00.000@ then
......
...@@ -107,3 +107,6 @@ sleep 100 ...@@ -107,3 +107,6 @@ sleep 100
run general/parser/function.sim run general/parser/function.sim
sleep 100 sleep 100
run general/parser/stableOp.sim run general/parser/stableOp.sim
sleep 100
run general/parser/slimit_alter_tags.sim
...@@ -73,6 +73,60 @@ if $row != 100 then ...@@ -73,6 +73,60 @@ if $row != 100 then
return -1 return -1
endi endi
sql select bottom(c3, 5) from tb_tb1 interval(1y);
if $rows != 5 then
return -1
endi
if $data01 != 0.00000 then
print expect 0.00000, actual:$data01
return -1
endi
if $data11 != 0.00000 then
return -1
endi
if $data21 != 0.00000 then
return -1
endi
if $data31 != 0.00000 then
return -1
endi
sql select top(c4, 5) from tb_tb1 interval(1y);
if $rows != 5 then
return -1
endi
if $data01 != 9.000000000 then
print expect 9.000000000, acutal:$data01
return -1
endi
if $data11 != 9.000000000 then
return -1
endi
if $data21 != 9.000000000 then
return -1
endi
if $data31 != 9.000000000 then
return -1
endi
sql select top(c3, 5) from tb_tb1 interval(40h)
if $rows != 25 then
return -1
endi
if $data01 != 9.00000 then
print expect 9.00000, actual:$data01
return -1
endi
sql select last(*) from tb_tb9 sql select last(*) from tb_tb9
if $row != 1 then if $row != 1 then
return -1 return -1
......
...@@ -100,8 +100,9 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1 ...@@ -100,8 +100,9 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
print =============== step5 print =============== step5
print ==> sleep 8 seconds to renew cache print ==> renew cache
sleep 8000 sql reset query cache
sleep 1000
print =============== step6 print =============== step6
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
./test.sh -f general/http/grafana_bug.sim ./test.sh -f general/http/grafana_bug.sim
./test.sh -f general/http/grafana.sim ./test.sh -f general/http/grafana.sim
./test.sh -f general/insert/basic.sim ./test.sh -f general/insert/basic.sim
./test.sh -f general/insert/insert_drop.sim ./test.sh -f general/insert/insert_drop.sim
./test.sh -f general/insert/query_block1_memory.sim ./test.sh -f general/insert/query_block1_memory.sim
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册