提交 a6d0bf4f 编写于 作者: H Haojun Liao

[td-225]refactor

上级 45acc9d3
......@@ -1359,7 +1359,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
}
}
} else {
SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr);
SSqlInfo SQLInfo = qSqlParse(pSql->sqlstr);
ret = tscToSQLCmd(pSql, &SQLInfo);
if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0 && SQLInfo.type == TSDB_SQL_NULL) {
tscResetSqlCmd(pCmd, true);
......
......@@ -77,29 +77,29 @@ static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SC
static uint8_t convertOptr(SStrToken *pToken);
static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool timeWindowQuery);
static int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, SArray* pSelectList, bool isSTable, bool joinQuery, bool timeWindowQuery);
static bool validateIpAddress(const char* ip, size_t size);
static bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool intervalQuery);
static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool twQuery);
static int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd);
static int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
static int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySqlNode);
static int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* offsetToken);
static int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSliding);
static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem);
static int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql);
static int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL);
static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema* pSchema);
static int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql);
static int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySQL);
static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySqlNode, SSchema* pSchema);
static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type);
static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type);
static int32_t validateEp(char* ep);
static int32_t validateDNodeConfig(SMiscInfo* pOptions);
static int32_t validateLocalConfig(SMiscInfo* pOptions);
......@@ -110,15 +110,15 @@ static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo);
static bool hasNormalColumnFilter(SQueryInfo* pQueryInfo);
static int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t index, SQuerySQL* pQuerySql, SSqlObj* pSql);
static int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t index, SQuerySqlNode* pQuerySqlNode, SSqlObj* pSql);
static int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDbInfo* pCreateDbSql);
static int32_t getColumnIndexByName(SSqlCmd* pCmd, const SStrToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
static int32_t getTableIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
static int32_t optrToString(tSqlExpr* pExpr, char** exprString);
static int32_t getTableIndexImpl(SStrToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
static int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySqlNode);
static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate);
static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex);
......@@ -126,8 +126,8 @@ static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t column
static int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* pInfo);
static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo);
static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo);
static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index);
static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid);
static int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t index);
static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid);
static bool validateDebugFlag(int32_t v);
static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) {
......@@ -592,7 +592,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
case TSDB_SQL_CREATE_TABLE: {
SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo;
SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo;
if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) {
if ((code = doCheckForCreateTable(pSql, 0, pInfo)) != TSDB_CODE_SUCCESS) {
......@@ -627,9 +627,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
assert(pCmd->numOfClause == pInfo->subclauseInfo.numOfClause);
for (int32_t i = pCmd->clauseIndex; i < pInfo->subclauseInfo.numOfClause; ++i) {
SQuerySQL* pQuerySql = pInfo->subclauseInfo.pClause[i];
SQuerySqlNode* pQuerySqlNode = pInfo->subclauseInfo.pClause[i];
tscTrace("%p start to parse %dth subclause, total:%d", pSql, i, pInfo->subclauseInfo.numOfClause);
if ((code = doCheckForQuery(pSql, pQuerySql, i)) != TSDB_CODE_SUCCESS) {
if ((code = doValidateSqlNode(pSql, pQuerySqlNode, i)) != TSDB_CODE_SUCCESS) {
return code;
}
......@@ -771,7 +771,7 @@ static int32_t checkInvalidExprForTimeWindow(SSqlCmd* pCmd, SQueryInfo* pQueryIn
return addPrimaryTsColumnForTimeWindowQuery(pQueryInfo);
}
int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySqlNode) {
const char* msg2 = "interval cannot be less than 10 ms";
const char* msg3 = "sliding cannot be used without interval";
......@@ -780,8 +780,8 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
if (pQuerySql->interval.interval.type == 0 || pQuerySql->interval.interval.n == 0) {
if (pQuerySql->sliding.n > 0) {
if (pQuerySqlNode->interval == NULL) {
if (pQuerySqlNode->sliding != NULL) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
......@@ -794,7 +794,7 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
}
// interval is not null
SStrToken* t = &pQuerySql->interval.interval;
SStrToken *t = &pQuerySqlNode->interval->interval;
if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.interval, &pQueryInfo->interval.intervalUnit) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
......@@ -811,11 +811,11 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
}
}
if (parseIntervalOffset(pCmd, pQueryInfo, &pQuerySql->interval.offset) != TSDB_CODE_SUCCESS) {
if (parseIntervalOffset(pCmd, pQueryInfo, &pQuerySqlNode->interval->offset) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
if (parseSlidingClause(pCmd, pQueryInfo, &pQuerySql->sliding) != TSDB_CODE_SUCCESS) {
if (parseSlidingClause(pCmd, pQueryInfo, pQuerySqlNode->sliding) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
......@@ -823,19 +823,19 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQ
return checkInvalidExprForTimeWindow(pCmd, pQueryInfo);
}
int32_t parseSessionClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL * pQuerySql) {
int32_t parseSessionClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode * pQuerySqlNode) {
const char* msg1 = "gap should be fixed time window";
const char* msg2 = "only one type time window allowed";
const char* msg3 = "invalid column name";
const char* msg4 = "invalid time window";
// no session window
if (pQuerySql->sessionVal.gap.n == 0 || pQuerySql->sessionVal.col.n == 0) {
if (pQuerySqlNode->sessionVal == NULL) {
return TSDB_CODE_SUCCESS;
}
SStrToken* col = &pQuerySql->sessionVal.col;
SStrToken* gap = &pQuerySql->sessionVal.gap;
SStrToken* col = &pQuerySqlNode->sessionVal->col;
SStrToken* gap = &pQuerySqlNode->sessionVal->gap;
char timeUnit = 0;
if (parseNatualDuration(gap->z, gap->n, &pQueryInfo->sessionWindow.gap, &timeUnit) != TSDB_CODE_SUCCESS) {
......@@ -1588,8 +1588,8 @@ bool isValidDistinctSql(SQueryInfo* pQueryInfo) {
return false;
}
int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool timeWindowQuery) {
assert(pSelection != NULL && pCmd != NULL);
int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, SArray* pSelectList, bool isSTable, bool joinQuery, bool timeWindowQuery) {
assert(pSelectList != NULL && pCmd != NULL);
const char* msg2 = "functions or others can not be mixed up";
const char* msg3 = "not support query expression";
......@@ -1603,9 +1603,10 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
}
bool hasDistinct = false;
for (int32_t i = 0; i < pSelection->nExpr; ++i) {
int32_t numOfExpr = taosArrayGetSize(pSelectList);
for (int32_t i = 0; i < numOfExpr; ++i) {
int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
tSqlExprItem* pItem = &pSelection->a[i];
tSqlExprItem* pItem = taosArrayGet(pSelectList, i);
if (hasDistinct == false) {
hasDistinct = (pItem->distinct == true);
......@@ -1951,12 +1952,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const char* msg6 = "function applied to tags not allowed";
const char* msg7 = "normal table can not apply this function";
const char* msg8 = "multi-columns selection does not support alias column name";
const char* msg10 = "diff can no be applied to unsigned numeric type";
const char* msg9 = "diff can no be applied to unsigned numeric type";
switch (functionId) {
case TSDB_FUNC_COUNT: {
/* more than one parameter for count() function */
if (pItem->pNode->pParam != NULL && pItem->pNode->pParam->nExpr != 1) {
if (pItem->pNode->pParam != NULL && taosArrayGetSize(pItem->pNode->pParam) != 1) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......@@ -1964,7 +1965,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (pItem->pNode->pParam != NULL) {
tSqlExprItem* pParamElem = &pItem->pNode->pParam->a[0];
tSqlExprItem* pParamElem = taosArrayGet(pItem->pNode->pParam, 0);
SStrToken* pToken = &pParamElem->pNode->colInfo;
int16_t sqlOptr = pParamElem->pNode->tokenId;
if ((pToken->z == NULL || pToken->n == 0)
......@@ -2059,13 +2060,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_STDDEV:
case TSDB_FUNC_LEASTSQR: {
// 1. valid the number of parameters
if (pItem->pNode->pParam == NULL || (functionId != TSDB_FUNC_LEASTSQR && pItem->pNode->pParam->nExpr != 1) ||
(functionId == TSDB_FUNC_LEASTSQR && pItem->pNode->pParam->nExpr != 3)) {
if (pItem->pNode->pParam == NULL || (functionId != TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 1) ||
(functionId == TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 3)) {
/* no parameters or more than one parameter for function */
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
tSqlExprItem* pParamElem = taosArrayGet(pItem->pNode->pParam, 0);
if (pParamElem->pNode->tokenId != TK_ALL && pParamElem->pNode->tokenId != TK_ID) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......@@ -2087,7 +2088,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if (!IS_NUMERIC_TYPE(colType)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
} else if (IS_UNSIGNED_NUMERIC_TYPE(colType) && functionId == TSDB_FUNC_DIFF) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg10);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg9);
}
int16_t resultType = 0;
......@@ -2167,17 +2168,17 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
if (!requireAllFields) {
if (pItem->pNode->pParam->nExpr < 1) {
if (taosArrayGetSize(pItem->pNode->pParam) < 1) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
if (pItem->pNode->pParam->nExpr > 1 && (pItem->aliasName != NULL && strlen(pItem->aliasName) > 0)) {
if (taosArrayGetSize(pItem->pNode->pParam) > 1 && (pItem->aliasName != NULL && strlen(pItem->aliasName) > 0)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg8);
}
/* in first/last function, multiple columns can be add to resultset */
for (int32_t i = 0; i < pItem->pNode->pParam->nExpr; ++i) {
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[i]);
for (int32_t i = 0; i < taosArrayGetSize(pItem->pNode->pParam); ++i) {
tSqlExprItem* pParamElem = taosArrayGet(pItem->pNode->pParam, i);
if (pParamElem->pNode->tokenId != TK_ALL && pParamElem->pNode->tokenId != TK_ID) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
......@@ -2220,7 +2221,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
char name[TSDB_COL_NAME_LEN] = {0};
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex);
bool multiColOutput = pItem->pNode->pParam->nExpr > 1;
bool multiColOutput = taosArrayGetSize(pItem->pNode->pParam) > 1;
setResultColName(name, pItem, cvtFunc.originFuncId, &pParamElem->pNode->colInfo, multiColOutput);
if (setExprInfoForFunctions(pCmd, pQueryInfo, pSchema, cvtFunc, name, colIndex + i, &index, finalResult) != 0) {
......@@ -2267,12 +2268,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_PERCT:
case TSDB_FUNC_APERCT: {
// 1. valid the number of parameters
if (pItem->pNode->pParam == NULL || pItem->pNode->pParam->nExpr != 2) {
if (pItem->pNode->pParam == NULL || taosArrayGetSize(pItem->pNode->pParam) != 2) {
/* no parameters or more than one parameter for function */
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
tSqlExprItem* pParamElem = taosArrayGet(pItem->pNode->pParam, 0);
if (pParamElem->pNode->tokenId != TK_ID) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......@@ -2382,12 +2383,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// no parameters or more than one parameter for function
if (pItem->pNode->pParam == NULL || pItem->pNode->pParam->nExpr != 1) {
if (pItem->pNode->pParam == NULL || taosArrayGetSize(pItem->pNode->pParam) != 1) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
tSQLExpr* pParam = pItem->pNode->pParam->a[0].pNode;
tSqlExprItem* pParamItem = taosArrayGet(pItem->pNode->pParam, 0);
tSqlExpr* pParam = pParamItem->pNode;
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(pCmd, &pParam->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
......@@ -2445,7 +2447,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
case TSDB_FUNC_BLKINFO: {
// no parameters or more than one parameter for function
if (pItem->pNode->pParam != NULL && pItem->pNode->pParam->nExpr != 0) {
if (pItem->pNode->pParam != NULL && taosArrayGetSize(pItem->pNode->pParam) != 0) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......@@ -3070,10 +3072,10 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumn* pColumn) {
}
static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnFilterInfo* pColumnFilter,
SColumnIndex* columnIndex, tSQLExpr* pExpr) {
SColumnIndex* columnIndex, tSqlExpr* pExpr) {
const char* msg = "not supported filter condition";
tSQLExpr* pRight = pExpr->pRight;
tSqlExpr* pRight = pExpr->pRight;
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, columnIndex->tableIndex);
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, columnIndex->columnIndex);
......@@ -3151,23 +3153,23 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
}
typedef struct SCondExpr {
tSQLExpr* pTagCond;
tSQLExpr* pTimewindow;
tSqlExpr* pTagCond;
tSqlExpr* pTimewindow;
tSQLExpr* pColumnCond;
tSqlExpr* pColumnCond;
tSQLExpr* pTableCond;
tSqlExpr* pTableCond;
int16_t relType; // relation between table name in expression and other tag
// filter condition expression, TK_AND or TK_OR
int16_t tableCondIndex;
tSQLExpr* pJoinExpr; // join condition
tSqlExpr* pJoinExpr; // join condition
bool tsJoin;
} 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->tokenId == TK_ID) { // column name
strncpy(*str, pExpr->colInfo.z, pExpr->colInfo.n);
*str += pExpr->colInfo.n;
......@@ -3189,23 +3191,23 @@ static int32_t tSQLExprNodeToString(tSQLExpr* pExpr, char** str) {
}
// 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) &&
(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) {
return (pExpr->pLeft != NULL && pExpr->pRight != NULL) &&
(isExprLeafNode(pExpr->pLeft) && isExprLeafNode(pExpr->pRight));
}
static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char** output) {
static int32_t tSQLExprLeafToString(tSqlExpr* pExpr, bool addParentheses, char** output) {
if (!isExprDirectParentOfLeafNode(pExpr)) {
return TSDB_CODE_TSC_INVALID_SQL;
}
tSQLExpr* pLeft = pExpr->pLeft;
tSQLExpr* pRight = pExpr->pRight;
tSqlExpr* pLeft = pExpr->pLeft;
tSqlExpr* pRight = pExpr->pRight;
if (addParentheses) {
*(*output) = '(';
......@@ -3227,7 +3229,7 @@ static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char**
return TSDB_CODE_SUCCESS;
}
static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
static int32_t optrToString(tSqlExpr* pExpr, char** exprString) {
const char* le = "<=";
const char* ge = ">=";
const char* ne = "<>";
......@@ -3288,25 +3290,29 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
return TSDB_CODE_SUCCESS;
}
static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
tSQLExprList* pList = pExpr->pParam;
if (pList->nExpr <= 0) {
static int32_t tablenameListToString(tSqlExpr* pExpr, SStringBuilder* sb) {
SArray* pList = pExpr->pParam;
int32_t size = (int32_t) taosArrayGetSize(pList);
if (size <= 0) {
return TSDB_CODE_TSC_INVALID_SQL;
}
if (pList->nExpr > 0) {
if (size > 0) {
taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN);
}
for (int32_t i = 0; i < pList->nExpr; ++i) {
tSQLExpr* pSub = pList->a[i].pNode;
taosStringBuilderAppendStringLen(sb, pSub->value.pz, pSub->value.nLen);
for (int32_t i = 0; i < size; ++i) {
tSqlExprItem* pSub = taosArrayGet(pList, i);
tVariant* pVar = &pSub->pNode->value;
taosStringBuilderAppendStringLen(sb, pVar->pz, pVar->nLen);
if (i < pList->nExpr - 1) {
if (i < size - 1) {
taosStringBuilderAppendString(sb, TBNAME_LIST_SEP);
}
if (pSub->value.nLen <= 0 || !tscValidateTableNameLength(pSub->value.nLen)) {
if (pVar->nLen <= 0 || !tscValidateTableNameLength(pVar->nLen)) {
return TSDB_CODE_TSC_INVALID_SQL;
}
}
......@@ -3314,7 +3320,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
return TSDB_CODE_SUCCESS;
}
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);
taosStringBuilderAppendString(sb, pExpr->value.pz);
......@@ -3328,7 +3334,7 @@ enum {
TSQL_EXPR_TBNAME = 3,
};
static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnIndex* pIndex, tSQLExpr* pExpr, int32_t sqlOptr) {
static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnIndex* pIndex, tSqlExpr* pExpr, int32_t sqlOptr) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex);
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
......@@ -3394,7 +3400,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
return doExtractColumnFilterInfo(pCmd, pQueryInfo, pColFilter, pIndex, pExpr);
}
static void relToString(tSQLExpr* pExpr, char** str) {
static void relToString(tSqlExpr* pExpr, char** str) {
assert(pExpr->tokenId == TK_AND || pExpr->tokenId == TK_OR);
const char* or = "OR";
......@@ -3411,7 +3417,7 @@ static void relToString(tSQLExpr* pExpr, char** str) {
}
UNUSED_FUNC
static int32_t getTagCondString(tSQLExpr* pExpr, char** str) {
static int32_t getTagCondString(tSqlExpr* pExpr, char** str) {
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
}
......@@ -3438,7 +3444,7 @@ static int32_t getTagCondString(tSQLExpr* pExpr, char** str) {
return tSQLExprLeafToString(pExpr, true, str);
}
static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pTableCond, SStringBuilder* sb) {
static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pTableCond, SStringBuilder* sb) {
const char* msg0 = "invalid table name list";
const char* msg1 = "not string following like";
......@@ -3446,8 +3452,8 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
return TSDB_CODE_SUCCESS;
}
tSQLExpr* pLeft = pTableCond->pLeft;
tSQLExpr* pRight = pTableCond->pRight;
tSqlExpr* pLeft = pTableCond->pLeft;
tSqlExpr* pRight = pTableCond->pRight;
if (!isTablenameToken(&pLeft->colInfo)) {
return TSDB_CODE_TSC_INVALID_SQL;
......@@ -3472,7 +3478,7 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
return ret;
}
static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, int32_t relOptr) {
static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr, int32_t relOptr) {
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
}
......@@ -3494,7 +3500,7 @@ static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQ
}
}
static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr) {
static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) {
const char* msg1 = "invalid join query condition";
const char* msg2 = "invalid table name in join query";
const char* msg3 = "type of join columns must be identical";
......@@ -3552,7 +3558,7 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr*
return TSDB_CODE_SUCCESS;
}
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) {
if (pExpr->type == SQL_NODE_TABLE_COLUMN) {
if (*type == NON_ARITHMEIC_EXPR) {
......@@ -3628,12 +3634,12 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQuer
return TSDB_CODE_SUCCESS;
}
static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type) {
static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSqlExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type) {
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
}
tSQLExpr* pLeft = pExpr->pLeft;
tSqlExpr* pLeft = pExpr->pLeft;
uint64_t uidLeft = 0;
uint64_t uidRight = 0;
......@@ -3649,7 +3655,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI
}
}
tSQLExpr* pRight = pExpr->pRight;
tSqlExpr* pRight = pExpr->pRight;
if (pRight->type == SQL_NODE_EXPR) {
int32_t ret = validateArithmeticSQLExpr(pCmd, pRight, pQueryInfo, pList, type);
if (ret != TSDB_CODE_SUCCESS) {
......@@ -3670,7 +3676,7 @@ static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryI
return TSDB_CODE_SUCCESS;
}
static bool isValidExpr(tSQLExpr* pLeft, tSQLExpr* pRight, int32_t optr) {
static bool isValidExpr(tSqlExpr* pLeft, tSqlExpr* pRight, int32_t optr) {
if (pLeft == NULL || (pRight == NULL && optr != TK_IN)) {
return false;
}
......@@ -3698,9 +3704,9 @@ static bool isValidExpr(tSQLExpr* pLeft, tSQLExpr* pRight, int32_t optr) {
return true;
}
static void exchangeExpr(tSQLExpr* pExpr) {
tSQLExpr* pLeft = pExpr->pLeft;
tSQLExpr* pRight = pExpr->pRight;
static void exchangeExpr(tSqlExpr* pExpr) {
tSqlExpr* pLeft = pExpr->pLeft;
tSqlExpr* pRight = pExpr->pRight;
if (pRight->tokenId == TK_ID && (pLeft->tokenId == TK_INTEGER || pLeft->tokenId == TK_FLOAT ||
pLeft->tokenId == TK_STRING || pLeft->tokenId == TK_BOOL)) {
......@@ -3733,14 +3739,14 @@ static void exchangeExpr(tSQLExpr* pExpr) {
}
}
static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr, SColumnIndex* pLeftIndex) {
static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr, SColumnIndex* pLeftIndex) {
const char* msg1 = "illegal column name";
const char* msg2 = "= is expected in join expression";
const char* msg3 = "join column must have same type";
const char* msg4 = "self join is not allowed";
const char* msg5 = "join table must be the same type(table to table, super table to super table)";
tSQLExpr* pRight = pExpr->pRight;
tSqlExpr* pRight = pExpr->pRight;
if (pRight->tokenId != TK_ID) {
return true;
......@@ -3784,7 +3790,7 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr
return true;
}
static bool validTableNameOptr(tSQLExpr* pExpr) {
static bool validTableNameOptr(tSqlExpr* pExpr) {
const char nameFilterOptr[] = {TK_IN, TK_LIKE};
for (int32_t i = 0; i < tListLen(nameFilterOptr); ++i) {
......@@ -3796,7 +3802,7 @@ static bool validTableNameOptr(tSQLExpr* pExpr) {
return false;
}
static int32_t setExprToCond(tSQLExpr** parent, tSQLExpr* pExpr, const char* msg, int32_t parentOptr, char* msgBuf) {
static int32_t setExprToCond(tSqlExpr** parent, tSqlExpr* pExpr, const char* msg, int32_t parentOptr, char* msgBuf) {
if (*parent != NULL) {
if (parentOptr == TK_OR && msg != NULL) {
return invalidSqlErrMsg(msgBuf, msg);
......@@ -3810,7 +3816,7 @@ static int32_t setExprToCond(tSQLExpr** parent, tSQLExpr* pExpr, const char* msg
return TSDB_CODE_SUCCESS;
}
static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SCondExpr* pCondExpr,
static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SCondExpr* pCondExpr,
int32_t* type, int32_t parentOptr) {
const char* msg1 = "table query cannot use tags filter";
const char* msg2 = "illegal column name";
......@@ -3821,8 +3827,8 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
const char* msg7 = "only in/like allowed in filter table name";
const char* msg8 = "wildcard string should be less than 20 characters";
tSQLExpr* pLeft = (*pExpr)->pLeft;
tSQLExpr* pRight = (*pExpr)->pRight;
tSqlExpr* pLeft = (*pExpr)->pLeft;
tSqlExpr* pRight = (*pExpr)->pRight;
int32_t ret = TSDB_CODE_SUCCESS;
......@@ -3933,7 +3939,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
return ret;
}
int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SCondExpr* pCondExpr,
int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SCondExpr* pCondExpr,
int32_t* type, int32_t parentOptr) {
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
......@@ -3941,8 +3947,8 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
const char* msg1 = "query condition between different columns must use 'AND'";
tSQLExpr* pLeft = (*pExpr)->pLeft;
tSQLExpr* pRight = (*pExpr)->pRight;
tSqlExpr* pLeft = (*pExpr)->pLeft;
tSqlExpr* pRight = (*pExpr)->pRight;
if (!isValidExpr(pLeft, pRight, (*pExpr)->tokenId)) {
return TSDB_CODE_TSC_INVALID_SQL;
......@@ -3981,7 +3987,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr** pExpr
return handleExprInQueryCond(pCmd, pQueryInfo, pExpr, pCondExpr, type, parentOptr);
}
static void doCompactQueryExpr(tSQLExpr** pExpr) {
static void doCompactQueryExpr(tSqlExpr** pExpr) {
if (*pExpr == NULL || isExprDirectParentOfLeafNode(*pExpr)) {
return;
}
......@@ -3996,25 +4002,25 @@ static void doCompactQueryExpr(tSQLExpr** pExpr) {
if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight == NULL &&
((*pExpr)->tokenId == TK_OR || (*pExpr)->tokenId == TK_AND)) {
tSqlExprNodeDestroy(*pExpr);
tSqlExprDestroy(*pExpr);
*pExpr = NULL;
} else if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight != NULL) {
tSQLExpr* tmpPtr = (*pExpr)->pRight;
tSqlExprNodeDestroy(*pExpr);
tSqlExpr* tmpPtr = (*pExpr)->pRight;
tSqlExprDestroy(*pExpr);
(*pExpr) = tmpPtr;
} else if ((*pExpr)->pRight == NULL && (*pExpr)->pLeft != NULL) {
tSQLExpr* tmpPtr = (*pExpr)->pLeft;
tSqlExprNodeDestroy(*pExpr);
tSqlExpr* tmpPtr = (*pExpr)->pLeft;
tSqlExprDestroy(*pExpr);
(*pExpr) = tmpPtr;
}
}
static void doExtractExprForSTable(SSqlCmd* pCmd, tSQLExpr** pExpr, SQueryInfo* pQueryInfo, tSQLExpr** pOut, int32_t tableIndex) {
static void doExtractExprForSTable(SSqlCmd* pCmd, tSqlExpr** pExpr, SQueryInfo* pQueryInfo, tSqlExpr** pOut, int32_t tableIndex) {
if (isExprDirectParentOfLeafNode(*pExpr)) {
tSQLExpr* pLeft = (*pExpr)->pLeft;
tSqlExpr* pLeft = (*pExpr)->pLeft;
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(pCmd, &pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
......@@ -4036,8 +4042,8 @@ static void doExtractExprForSTable(SSqlCmd* pCmd, tSQLExpr** pExpr, SQueryInfo*
}
}
static tSQLExpr* extractExprForSTable(SSqlCmd* pCmd, tSQLExpr** pExpr, SQueryInfo* pQueryInfo, int32_t tableIndex) {
tSQLExpr* pResExpr = NULL;
static tSqlExpr* extractExprForSTable(SSqlCmd* pCmd, tSqlExpr** pExpr, SQueryInfo* pQueryInfo, int32_t tableIndex) {
tSqlExpr* pResExpr = NULL;
if (*pExpr != NULL) {
doExtractExprForSTable(pCmd, pExpr, pQueryInfo, &pResExpr, tableIndex);
......@@ -4061,7 +4067,7 @@ int tableNameCompar(const void* lhs, const void* rhs) {
}
static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, const char* account,
tSQLExpr* pExpr, int16_t tableCondIndex, SStringBuilder* sb) {
tSqlExpr* pExpr, int16_t tableCondIndex, SStringBuilder* sb) {
const char* msg = "table name too long";
if (pExpr == NULL) {
......@@ -4162,7 +4168,7 @@ static bool validateFilterExpr(SQueryInfo* pQueryInfo) {
return true;
}
static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExpr* pExpr) {
static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) {
const char* msg0 = "invalid timestamp";
const char* msg1 = "only one time stamp window allowed";
......@@ -4187,7 +4193,7 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLE
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
tSQLExpr* pRight = pExpr->pRight;
tSqlExpr* pRight = pExpr->pRight;
STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX};
if (getTimeRange(&win, pRight, pExpr->tokenId, tinfo.precision) != TSDB_CODE_SUCCESS) {
......@@ -4351,7 +4357,7 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) {
return TSDB_CODE_SUCCESS;
}
static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr* pCondExpr, tSQLExpr** pExpr) {
static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr* pCondExpr, tSqlExpr** pExpr) {
int32_t ret = TSDB_CODE_SUCCESS;
if (pCondExpr->pTagCond == NULL) {
......@@ -4359,7 +4365,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
}
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
tSQLExpr* p1 = extractExprForSTable(pCmd, pExpr, pQueryInfo, i);
tSqlExpr* p1 = extractExprForSTable(pCmd, pExpr, pQueryInfo, i);
if (p1 == NULL) { // no query condition on this table
continue;
}
......@@ -4414,7 +4420,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
return ret;
}
int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql) {
int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql) {
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
}
......@@ -4488,7 +4494,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
return ret;
}
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
if (pRight->tokenId == TK_ID) {
return TSDB_CODE_SUCCESS;
......@@ -4608,7 +4614,7 @@ int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return TSDB_CODE_SUCCESS;
}
int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySQL) {
SArray* pFillToken = pQuerySQL->fillType;
tVariantListItem* pItem = taosArrayGet(pFillToken, 0);
......@@ -4730,7 +4736,7 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) {
}
}
int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema* pSchema) {
int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySqlNode, SSchema* pSchema) {
const char* msg0 = "only support order by primary timestamp";
const char* msg1 = "invalid column name";
const char* msg2 = "order by primary timestamp or first tag in groupby clause allowed";
......@@ -4745,11 +4751,11 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
pQueryInfo->order.orderColId = 0;
return TSDB_CODE_SUCCESS;
}
if (pQuerySql->pSortOrder == NULL) {
if (pQuerySqlNode->pSortOrder == NULL) {
return TSDB_CODE_SUCCESS;
}
SArray* pSortorder = pQuerySql->pSortOrder;
SArray* pSortorder = pQuerySqlNode->pSortOrder;
/*
* for table query, there is only one or none order option is allowed, which is the
......@@ -4817,7 +4823,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
if (orderByTags) {
pQueryInfo->groupbyExpr.orderIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
tVariantListItem* p1 = taosArrayGet(pQuerySql->pSortOrder, 0);
tVariantListItem* p1 = taosArrayGet(pQuerySqlNode->pSortOrder, 0);
pQueryInfo->groupbyExpr.orderType = p1->sortOrder;
} else if (isTopBottomQuery(pQueryInfo)) {
/* order of top/bottom query in interval is not valid */
......@@ -4829,12 +4835,12 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
tVariantListItem* p1 = taosArrayGet(pQuerySql->pSortOrder, 0);
tVariantListItem* p1 = taosArrayGet(pQuerySqlNode->pSortOrder, 0);
pQueryInfo->order.order = p1->sortOrder;
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
return TSDB_CODE_SUCCESS;
} else {
tVariantListItem* p1 = taosArrayGet(pQuerySql->pSortOrder, 0);
tVariantListItem* p1 = taosArrayGet(pQuerySqlNode->pSortOrder, 0);
pQueryInfo->order.order = p1->sortOrder;
pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
......@@ -4847,7 +4853,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
}
if (s == 2) {
tVariantListItem *pItem = taosArrayGet(pQuerySql->pSortOrder, 0);
tVariantListItem *pItem = taosArrayGet(pQuerySqlNode->pSortOrder, 0);
if (orderByTags) {
pQueryInfo->groupbyExpr.orderIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
pQueryInfo->groupbyExpr.orderType = pItem->sortOrder;
......@@ -4856,7 +4862,7 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
}
pItem = taosArrayGet(pQuerySql->pSortOrder, 1);
pItem = taosArrayGet(pQuerySqlNode->pSortOrder, 1);
tVariant* pVar2 = &pItem->pVar;
SStrToken cname = {pVar2->nLen, pVar2->nType, pVar2->pz};
if (getColumnIndexByName(pCmd, &cname, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
......@@ -4891,13 +4897,13 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
tVariantListItem* pItem = taosArrayGet(pQuerySql->pSortOrder, 0);
tVariantListItem* pItem = taosArrayGet(pQuerySqlNode->pSortOrder, 0);
pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
return TSDB_CODE_SUCCESS;
}
tVariantListItem* pItem = taosArrayGet(pQuerySql->pSortOrder, 0);
tVariantListItem* pItem = taosArrayGet(pQuerySqlNode->pSortOrder, 0);
pQueryInfo->order.order = pItem->sortOrder;
}
......@@ -5425,7 +5431,7 @@ bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo) {
return (pQueryInfo->window.skey == pQueryInfo->window.ekey) && (pQueryInfo->window.skey != 0);
}
int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySQL* pQuerySql, SSqlObj* pSql) {
int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIndex, SQuerySqlNode* pQuerySqlNode, SSqlObj* pSql) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
const char* msg0 = "soffset/offset can not be less than 0";
......@@ -5433,9 +5439,9 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
const char* msg2 = "slimit/soffset can not apply to projection query";
// handle the limit offset value, validate the limit
pQueryInfo->limit = pQuerySql->limit;
pQueryInfo->limit = *pQuerySqlNode->limit;
pQueryInfo->clauseLimit = pQueryInfo->limit.limit;
pQueryInfo->slimit = pQuerySql->slimit;
pQueryInfo->slimit = *pQuerySqlNode->slimit;
tscDebug("%p limit:%" PRId64 ", offset:%" PRId64 " slimit:%" PRId64 ", soffset:%" PRId64, pSql, pQueryInfo->limit.limit,
pQueryInfo->limit.offset, pQueryInfo->slimit.limit, pQueryInfo->slimit.offset);
......@@ -6094,17 +6100,20 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return checkUpdateTagPrjFunctions(pQueryInfo, pCmd);
}
}
int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode* pQuerySqlNode) {
const char* msg1 = "only one expression allowed";
const char* msg2 = "invalid expression in select clause";
const char* msg3 = "invalid function";
tSQLExprList* pExprList = pQuerySql->pSelection;
if (pExprList->nExpr != 1) {
SArray* pExprList = pQuerySqlNode->pSelectList;
size_t size = taosArrayGetSize(pExprList);
if (size != 1) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
bool server_status = false;
tSQLExpr* pExpr = pExprList->a[0].pNode;
tSqlExprItem* pExprItem = taosArrayGet(pExprList, 0);
tSqlExpr* pExpr = pExprItem->pNode;
if (pExpr->operand.z == NULL) {
//handle 'select 1'
if (pExpr->token.n == 1 && 0 == strncasecmp(pExpr->token.z, "1", 1)) {
......@@ -6150,8 +6159,9 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
SColumnIndex ind = {0};
SSqlExpr* pExpr1 = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TAG_DUMMY, &ind, TSDB_DATA_TYPE_INT,
tDataTypes[TSDB_DATA_TYPE_INT].bytes, getNewResColId(pQueryInfo), tDataTypes[TSDB_DATA_TYPE_INT].bytes, false);
const char* name = (pExprList->a[0].aliasName != NULL)? pExprList->a[0].aliasName:functionsInfo[index].name;
tSqlExprItem* item = taosArrayGet(pExprList, 0);
const char* name = (item->aliasName != NULL)? item->aliasName:functionsInfo[index].name;
tstrncpy(pExpr1->aliasName, name, tListLen(pExpr1->aliasName));
return TSDB_CODE_SUCCESS;
......@@ -6286,7 +6296,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, subClauseIndex);
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo;
SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo;
SArray* pFieldList = pCreateTable->colInfo.pColumns;
SArray* pTagList = pCreateTable->colInfo.pTagColumns;
......@@ -6341,7 +6351,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
SSqlCmd* pCmd = &pSql->cmd;
SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo;
SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
// two table: the first one is for current table, and the secondary is for the super table.
......@@ -6550,12 +6560,12 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
assert(pQueryInfo->numOfTables == 1);
SCreateTableSQL* pCreateTable = pInfo->pCreateTableInfo;
SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo;
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
// if sql specifies db, use it, otherwise use default db
SStrToken* pName = &(pCreateTable->name);
SQuerySQL* pQuerySql = pCreateTable->pSelect;
SQuerySqlNode* pQuerySqlNode = pCreateTable->pSelect;
if (tscValidateName(pName) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
......@@ -6583,18 +6593,18 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
}
bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo);
if (parseSelectClause(&pSql->cmd, 0, pQuerySql->pSelection, isSTable, false, false) != TSDB_CODE_SUCCESS) {
if (parseSelectClause(&pSql->cmd, 0, pQuerySqlNode->pSelectList, isSTable, false, false) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
if (pQuerySql->pWhere != NULL) { // query condition in stream computing
if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) {
if (pQuerySqlNode->pWhere != NULL) { // query condition in stream computing
if (parseWhereClause(pQueryInfo, &pQuerySqlNode->pWhere, pSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
}
// set interval value
if (parseIntervalClause(pSql, pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) {
if (parseIntervalClause(pSql, pQueryInfo, pQuerySqlNode) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
......@@ -6612,7 +6622,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return code;
}
if (pQuerySql->selectToken.n > TSDB_MAX_SAVED_SQL_LEN) {
if (pQuerySqlNode->sqlstr.n > TSDB_MAX_SAVED_SQL_LEN) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
......@@ -6630,12 +6640,12 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
* check if fill operation is available, the fill operation is parsed and executed during query execution,
* not here.
*/
if (pQuerySql->fillType != NULL) {
if (pQuerySqlNode->fillType != NULL) {
if (pQueryInfo->interval.interval == 0) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
tVariantListItem* pItem = taosArrayGet(pQuerySql->fillType, 0);
tVariantListItem* pItem = taosArrayGet(pQuerySqlNode->fillType, 0);
if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) {
if (!((strncmp(pItem->pVar.pz, "none", 4) == 0 && pItem->pVar.nLen == 4) ||
(strncmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4))) {
......@@ -6684,10 +6694,10 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return TSDB_CODE_SUCCESS;
}
int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
assert(pQuerySql != NULL && (pQuerySql->from == NULL || taosArrayGetSize(pQuerySql->from) > 0));
int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t index) {
assert(pQuerySqlNode != NULL && (pQuerySqlNode->from == NULL || taosArrayGetSize(pQuerySqlNode->from) > 0));
const char* msg0 = "invalid table name";
const char* msg0 = "invalid table name";
const char* msg1 = "point interpolation query needs timestamp";
const char* msg2 = "fill only available for interval query";
const char* msg3 = "start(end) time of query range required or time range too large";
......@@ -6709,7 +6719,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
assert(pCmd->clauseIndex == index);
// too many result columns not support order by in query
if (pQuerySql->pSelection->nExpr > TSDB_MAX_COLUMNS) {
if (taosArrayGetSize(pQuerySqlNode->pSelectList) > TSDB_MAX_COLUMNS) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
......@@ -6720,13 +6730,13 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
* select client_version();
* select server_state();
*/
if (pQuerySql->from == NULL) {
assert(pQuerySql->fillType == NULL && pQuerySql->pGroupby == NULL && pQuerySql->pWhere == NULL &&
pQuerySql->pSortOrder == NULL);
return doLocalQueryProcess(pCmd, pQueryInfo, pQuerySql);
if (pQuerySqlNode->from == NULL) {
assert(pQuerySqlNode->fillType == NULL && pQuerySqlNode->pGroupby == NULL && pQuerySqlNode->pWhere == NULL &&
pQuerySqlNode->pSortOrder == NULL);
return doLocalQueryProcess(pCmd, pQueryInfo, pQuerySqlNode);
}
size_t fromSize = taosArrayGetSize(pQuerySql->from);
size_t fromSize = taosArrayGetSize(pQuerySqlNode->from);
if (fromSize > TSDB_MAX_JOIN_TABLE_NUM * 2) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
}
......@@ -6739,7 +6749,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
// set all query tables, which are maybe more than one.
for (int32_t i = 0; i < fromSize; ) {
tVariantListItem* item = taosArrayGet(pQuerySql->from, i);
tVariantListItem* item = taosArrayGet(pQuerySqlNode->from, i);
tVariant* pTableItem = &item->pVar;
if (pTableItem->nType != TSDB_DATA_TYPE_BINARY) {
......@@ -6765,7 +6775,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return code;
}
tVariantListItem* p1 = taosArrayGet(pQuerySql->from, i + 1);
tVariantListItem* p1 = taosArrayGet(pQuerySqlNode->from, i + 1);
if (p1->pVar.nType != TSDB_DATA_TYPE_BINARY) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
}
......@@ -6790,7 +6800,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
i += 2;
}
assert(pQueryInfo->numOfTables == taosArrayGetSize(pQuerySql->from) / 2);
assert(pQueryInfo->numOfTables == taosArrayGetSize(pQuerySqlNode->from) / 2);
bool isSTable = false;
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
......@@ -6806,44 +6816,43 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
}
// parse the group by clause in the first place
if (parseGroupbyClause(pQueryInfo, pQuerySql->pGroupby, pCmd) != TSDB_CODE_SUCCESS) {
if (parseGroupbyClause(pQueryInfo, pQuerySqlNode->pGroupby, pCmd) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
// set where info
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
if (pQuerySql->pWhere != NULL) {
if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) {
if (pQuerySqlNode->pWhere != NULL) {
if (parseWhereClause(pQueryInfo, &pQuerySqlNode->pWhere, pSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
pQuerySql->pWhere = NULL;
pQuerySqlNode->pWhere = NULL;
if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) {
pQueryInfo->window.skey = pQueryInfo->window.skey / 1000;
pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000;
}
} else { // set the time rang
if (taosArrayGetSize(pQuerySql->from) > 2) { // it is a join query, no wher clause is not allowed.
if (taosArrayGetSize(pQuerySqlNode->from) > 2) { // it is a join query, no wher clause is not allowed.
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "condition missing for join query ");
}
}
int32_t joinQuery = (pQuerySql->from != NULL && taosArrayGetSize(pQuerySql->from) > 2);
int32_t timeWindowQuery = !(pQuerySql->interval.interval.type == 0 || pQuerySql->interval.interval.n == 0 ||
pQuerySql->sessionVal.gap.n == 0);
int32_t joinQuery = (pQuerySqlNode->from != NULL && taosArrayGetSize(pQuerySqlNode->from) > 2);
int32_t timeWindowQuery = !(pQuerySqlNode->interval == NULL || pQuerySqlNode->sessionVal == NULL);
if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable, joinQuery, timeWindowQuery) != TSDB_CODE_SUCCESS) {
if (parseSelectClause(pCmd, index, pQuerySqlNode->pSelectList, isSTable, joinQuery, timeWindowQuery) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
// set order by info
if (parseOrderbyClause(pCmd, pQueryInfo, pQuerySql, tscGetTableSchema(pTableMetaInfo->pTableMeta)) != TSDB_CODE_SUCCESS) {
if (parseOrderbyClause(pCmd, pQueryInfo, pQuerySqlNode, tscGetTableSchema(pTableMetaInfo->pTableMeta)) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
// set interval value
if (parseIntervalClause(pSql, pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) {
if (parseIntervalClause(pSql, pQueryInfo, pQuerySqlNode) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
} else {
if (isTimeWindowQuery(pQueryInfo) &&
......@@ -6852,7 +6861,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
}
}
if (parseSessionClause(pCmd, pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) {
if (parseSessionClause(pCmd, pQueryInfo, pQuerySqlNode) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
......@@ -6874,7 +6883,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
}
}
if ((code = parseLimitClause(pCmd, pQueryInfo, index, pQuerySql, pSql)) != TSDB_CODE_SUCCESS) {
if ((code = parseLimitClause(pCmd, pQueryInfo, index, pQuerySqlNode, pSql)) != TSDB_CODE_SUCCESS) {
return code;
}
......@@ -6885,7 +6894,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
updateLastScanOrderIfNeeded(pQueryInfo);
tscFieldInfoUpdateOffset(pQueryInfo);
if (pQuerySql->fillType != NULL) {
if (pQuerySqlNode->fillType != NULL) {
if (pQueryInfo->interval.interval == 0 && (!tscIsPointInterpQuery(pQueryInfo))) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......@@ -6898,7 +6907,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return code;
}
if ((code = parseFillClause(pCmd, pQueryInfo, pQuerySql)) != TSDB_CODE_SUCCESS) {
if ((code = parseFillClause(pCmd, pQueryInfo, pQuerySqlNode)) != TSDB_CODE_SUCCESS) {
return code;
}
}
......@@ -6906,7 +6915,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
return TSDB_CODE_SUCCESS; // Does not build query message here
}
int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid) {
int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid) {
tExprNode* pLeft = NULL;
tExprNode* pRight= NULL;
......
......@@ -1350,7 +1350,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd *pCmd = &(pSql->cmd);
int32_t size = minMsgSize() + sizeof(SCMCreateTableMsg) + sizeof(SCreateTableMsg);
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
SCreateTableSql *pCreateTableInfo = pInfo->pCreateTableInfo;
if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) {
int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo);
size += numOfTables * (sizeof(SCreateTableMsg) + TSDB_MAX_TAGS_LEN);
......@@ -1359,7 +1359,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
}
if (pCreateTableInfo->pSelect != NULL) {
size += (pCreateTableInfo->pSelect->selectToken.n + 1);
size += (pCreateTableInfo->pSelect->sqlstr.n + 1);
}
return size + TSDB_EXTRA_PAYLOAD_SIZE;
......@@ -1417,7 +1417,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pCreateMsg->tableName);
assert(code == 0);
SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo;
SCreateTableSql *pCreateTable = pInfo->pCreateTableInfo;
pCreateMsg->igExists = pCreateTable->existCheck ? 1 : 0;
pCreateMsg->numOfColumns = htons(pCmd->numOfCols);
......@@ -1440,11 +1440,11 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg = (char *)pSchema;
if (type == TSQL_CREATE_STREAM) { // check if it is a stream sql
SQuerySQL *pQuerySql = pInfo->pCreateTableInfo->pSelect;
SQuerySqlNode *pQuerySql = pInfo->pCreateTableInfo->pSelect;
strncpy(pMsg, pQuerySql->selectToken.z, pQuerySql->selectToken.n + 1);
pCreateMsg->sqlLen = htons(pQuerySql->selectToken.n + 1);
pMsg += pQuerySql->selectToken.n + 1;
strncpy(pMsg, pQuerySql->sqlstr.z, pQuerySql->sqlstr.n + 1);
pCreateMsg->sqlLen = htons(pQuerySql->sqlstr.n + 1);
pMsg += pQuerySql->sqlstr.n + 1;
}
}
......
......@@ -27,6 +27,18 @@ extern "C" {
#include "tvariant.h"
#define ParseTOKENTYPE SStrToken
#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,
};
extern char tTokenTypeSwitcher[13];
#define toTSDBType(x) \
......@@ -63,20 +75,20 @@ typedef struct SSessionWindowVal {
SStrToken gap;
} SSessionWindowVal;
typedef struct SQuerySQL {
struct tSQLExprList *pSelection; // select clause
SArray * from; // from clause SArray<tVariantListItem>
struct tSQLExpr * pWhere; // where clause [optional]
SArray * pGroupby; // groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray * pSortOrder; // orderby [optional], SArray<tVariantListItem>
SIntervalVal interval; // (interval, interval_offset) [optional]
SSessionWindowVal sessionVal; // session window [optional]
SStrToken sliding; // sliding window [optional]
SLimitVal limit; // limit offset [optional]
SLimitVal slimit; // group limit offset [optional]
SArray * fillType; // fill type[optional], SArray<tVariantListItem>
SStrToken selectToken; // sql string
} SQuerySQL;
typedef struct SQuerySqlNode {
struct SArray *pSelectList; // select clause
SArray *from; // from clause SArray<SQuerySqlNode>
struct tSqlExpr *pWhere; // where clause [optional]
SArray *pGroupby; // groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray *pSortOrder; // orderby [optional], SArray<tVariantListItem>
SIntervalVal *interval; // (interval, interval_offset) [optional]
SSessionWindowVal *sessionVal; // session window [optional]
SStrToken *sliding; // sliding window [optional]
SLimitVal *limit; // limit offset [optional]
SLimitVal *slimit; // group limit offset [optional]
SArray *fillType; // fill type[optional], SArray<tVariantListItem>
SStrToken sqlstr; // sql string in select clause
} SQuerySqlNode;
typedef struct SCreatedTableInfo {
SStrToken name; // table name token
......@@ -88,7 +100,7 @@ typedef struct SCreatedTableInfo {
int8_t igExist; // ignore if exists
} SCreatedTableInfo;
typedef struct SCreateTableSQL {
typedef struct SCreateTableSql {
SStrToken name; // table name, create table [name] xxx
int8_t type; // create normal table/from super table/ stream
bool existCheck;
......@@ -99,16 +111,16 @@ typedef struct SCreateTableSQL {
} colInfo;
SArray *childTableInfo; // SArray<SCreatedTableInfo>
SQuerySQL *pSelect;
} SCreateTableSQL;
SQuerySqlNode *pSelect;
} SCreateTableSql;
typedef struct SAlterTableInfo {
SStrToken name;
int16_t tableType;
int16_t type;
STagData tagData;
SArray *pAddColumns; // SArray<TAOS_FIELD>
SArray *varList; // set t=val or: change src dst, SArray<tVariantListItem>
SStrToken name;
int16_t tableType;
int16_t type;
STagData tagData;
SArray *pAddColumns; // SArray<TAOS_FIELD>
SArray *varList; // set t=val or: change src dst, SArray<tVariantListItem>
} SAlterTableInfo;
typedef struct SCreateDbInfo {
......@@ -147,9 +159,9 @@ typedef struct SCreateAcctInfo {
} SCreateAcctInfo;
typedef struct SShowInfo {
uint8_t showType;
SStrToken prefix;
SStrToken pattern;
uint8_t showType;
SStrToken prefix;
SStrToken pattern;
} SShowInfo;
typedef struct SUserInfo {
......@@ -174,7 +186,7 @@ typedef struct SMiscInfo {
} SMiscInfo;
typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
SQuerySQL **pClause;
SQuerySqlNode **pClause;
int32_t numOfClause;
} SSubclauseInfo;
......@@ -184,26 +196,15 @@ typedef struct SSqlInfo {
SSubclauseInfo subclauseInfo;
char msg[256];
union {
SCreateTableSQL *pCreateTableInfo;
SCreateTableSql *pCreateTableInfo;
SAlterTableInfo *pAlterInfo;
SMiscInfo *pMiscInfo;
};
} 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 {
uint16_t type; // sql node type
uint32_t tokenId; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
uint32_t tokenId; // TK_LE: less than(binary expr)
// the whole string of the function(col, param), while the function name is kept in token
SStrToken operand;
......@@ -213,70 +214,47 @@ typedef struct tSQLExpr {
tVariant value; // the use input value
SStrToken token; // original sql expr string
struct tSQLExpr *pLeft; // left child
struct tSQLExpr *pRight; // right child
struct tSQLExprList *pParam; // function parameters list
} tSQLExpr;
struct tSqlExpr *pLeft; // left child
struct tSqlExpr *pRight; // right child
struct SArray *pParam; // function parameters list
} tSqlExpr;
// used in select clause. select <tSQLExprList> from xxx
// used in select clause. select <SArray> from xxx
typedef struct tSqlExprItem {
tSQLExpr *pNode; // The list of expressions
tSqlExpr *pNode; // The list of expressions
char * aliasName; // alias name, null-terminated string
bool distinct;
} tSqlExprItem;
// todo refactor by using SArray
typedef struct tSQLExprList {
int32_t nExpr; /* Number of expressions on the list */
int32_t nAlloc; /* Number of entries allocated below */
tSqlExprItem *a; /* One entry for each expression */
} tSQLExprList;
/**
*
* @param yyp The parser
* @param yymajor The major token code number
* @param yyminor The value for the token
*/
void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
/**
*
* @param p The parser to be deleted
* @param freeProc Function used to reclaim memory
*/
void ParseFree(void *p, void (*freeProc)(void *));
SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType);
// sql expr leaf node
tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType);
tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
tSQLExpr *tSqlExprClone(tSQLExpr *pSrc);
tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType);
tSqlExpr *tSqlExprClone(tSqlExpr *pSrc);
void tSqlExprDestroy(tSqlExpr *pExpr);
SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinct, SStrToken *pToken);
void tSqlExprListDestroy(SArray *pList);
void tSqlExprDestroy(tSQLExpr *pExpr);
SQuerySqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelectList, SArray *pFrom, tSqlExpr *pWhere,
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
SSessionWindowVal *pSession, SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit,
SLimitVal *pGLimit);
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pDistinct, SStrToken *pToken);
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SQuerySqlNode *pSelect, int32_t type);
void tSqlExprListDestroy(tSQLExprList *pList);
SQuerySQL *tSetQuerySqlNode(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *pSession,
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSelect, int32_t type);
void tSqlExprNodeDestroy(tSQLExpr *pExpr);
SAlterTableInfo * tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableTable);
SAlterTableInfo *tSetAlterTableInfo(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableTable);
SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNames, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists);
void destroyAllSelectClause(SSubclauseInfo *pSql);
void doDestroyQuerySql(SQuerySQL *pSql);
void doDestroyQuerySql(SQuerySqlNode *pSql);
void freeCreateTableInfo(void* p);
SSqlInfo * setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, int32_t type);
SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, int32_t type);
SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo);
SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause);
......@@ -285,7 +263,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
void SqlInfoDestroy(SSqlInfo *pInfo);
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck,int16_t dbType,int16_t tableType);
void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns);
......@@ -300,19 +278,39 @@ void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo);
void setDefaultCreateTopicOption(SCreateDbInfo *pDBInfo);
// prefix show db.tables;
void setDbName(SStrToken *pCpxName, SStrToken *pDb);
void tSetDbName(SStrToken *pCpxName, SStrToken *pDb);
tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType);
void tSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType);
void tSetColumnType(TAOS_FIELD *pField, SStrToken *type);
tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
void tSqlSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType);
/**
*
* @param yyp The parser
* @param yymajor The major token code number
* @param yyminor The value for the token
*/
void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type);
/**
*
* @param p The parser to be deleted
* @param freeProc Function used to reclaim memory
*/
void ParseFree(void *p, void (*freeProc)(void *));
/**
*
* @param mallocProc The parser allocator
* @return
*/
void *ParseAlloc(void *(*mallocProc)(size_t));
SSqlInfo qSQLParse(const char *str);
/**
*
* @param str sql string
* @return sql ast
*/
SSqlInfo qSqlParse(const char *str);
#ifdef __cplusplus
}
......
......@@ -23,7 +23,7 @@
#include "ttokendef.h"
#include "tutil.h"
SSqlInfo qSQLParse(const char *pStr) {
SSqlInfo qSqlParse(const char *pStr) {
void *pParser = ParseAlloc(malloc);
SSqlInfo sqlInfo = {0};
......@@ -80,53 +80,48 @@ abort_parse:
return sqlInfo;
}
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pDistinct, SStrToken *pToken) {
SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinct, SStrToken *pToken) {
if (pList == NULL) {
pList = calloc(1, sizeof(tSQLExprList));
pList = taosArrayInit(4, sizeof(tSqlExprItem));
}
if (pList->nAlloc <= pList->nExpr) {
pList->nAlloc = (pList->nAlloc << 1u) + 4;
pList->a = realloc(pList->a, pList->nAlloc * sizeof(pList->a[0]));
if (pList->a == 0) {
pList->nExpr = pList->nAlloc = 0;
return pList;
}
}
assert(pList->a != 0);
if (pNode || pToken) {
struct tSqlExprItem *pItem = &pList->a[pList->nExpr++];
memset(pItem, 0, sizeof(*pItem));
pItem->pNode = pNode;
struct tSqlExprItem item = {0};
item.pNode = pNode;
item.distinct = (pDistinct != NULL);
if (pToken) { // set the as clause
pItem->aliasName = malloc(pToken->n + 1);
strncpy(pItem->aliasName, pToken->z, pToken->n);
pItem->aliasName[pToken->n] = 0;
item.aliasName = malloc(pToken->n + 1);
strncpy(item.aliasName, pToken->z, pToken->n);
item.aliasName[pToken->n] = 0;
strdequote(pItem->aliasName);
strdequote(item.aliasName);
}
pItem->distinct = (pDistinct != NULL);
taosArrayPush(pList, &item);
}
return pList;
}
void tSqlExprListDestroy(tSQLExprList *pList) {
if (pList == NULL) return;
static void freeExprElem(void* item) {
tSqlExprItem* exprItem = item;
for (int32_t i = 0; i < pList->nExpr; ++i) {
if (pList->a[i].aliasName != NULL) {
free(pList->a[i].aliasName);
}
tSqlExprDestroy(pList->a[i].pNode);
tfree(exprItem->aliasName);
tSqlExprDestroy(exprItem->pNode);
}
void tSqlExprListDestroy(SArray *pList) {
if (pList == NULL) {
return;
}
free(pList->a);
free(pList);
taosArrayDestroyEx(pList, freeExprElem);
}
tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) {
tSQLExpr *pSqlExpr = calloc(1, sizeof(tSQLExpr));
tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
tSqlExpr *pSqlExpr = calloc(1, sizeof(tSqlExpr));
if (pToken != NULL) {
pSqlExpr->token = *pToken;
......@@ -171,15 +166,15 @@ tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) {
* pList is the parameters for function with id(optType)
* function name is denoted by pFunctionToken
*/
tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType) {
tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType) {
if (pFuncToken == NULL) {
return NULL;
}
tSQLExpr *pExpr = calloc(1, sizeof(tSQLExpr));
tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr));
pExpr->tokenId = optType;
pExpr->type = SQL_NODE_SQLFUNCTION;
pExpr->pParam = pList;
pExpr->pParam = pParam;
int32_t len = (int32_t)((endToken->z + endToken->n) - pFuncToken->z);
pExpr->operand = (*pFuncToken);
......@@ -193,10 +188,10 @@ tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SSt
/*
* create binary expression in this procedure
* if the expr is arithmetic, calculate the result and set it to tSQLExpr Object
* if the expr is arithmetic, calculate the result and set it to tSqlExpr Object
*/
tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
tSQLExpr *pExpr = calloc(1, sizeof(tSQLExpr));
tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr));
pExpr->type = SQL_NODE_EXPR;
if (pLeft != NULL && pRight != NULL && (optrType != TK_IN)) {
......@@ -291,9 +286,9 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
pExpr->tokenId = optrType;
pExpr->pLeft = pLeft;
tSQLExpr *pRSub = calloc(1, sizeof(tSQLExpr));
tSqlExpr *pRSub = calloc(1, sizeof(tSqlExpr));
pRSub->tokenId = TK_SET; // TODO refactor .....
pRSub->pParam = (tSQLExprList *)pRight;
pRSub->pParam = (SArray *)pRight;
pExpr->pRight = pRSub;
} else {
......@@ -301,7 +296,7 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
pExpr->pLeft = pLeft;
if (pLeft != NULL && pRight == NULL) {
pRight = calloc(1, sizeof(tSQLExpr));
pRight = calloc(1, sizeof(tSqlExpr));
}
pExpr->pRight = pRight;
......@@ -312,8 +307,8 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
tSQLExpr *tSqlExprClone(tSQLExpr *pSrc) {
tSQLExpr *pExpr = calloc(1, sizeof(tSQLExpr));
tSqlExpr *tSqlExprClone(tSqlExpr *pSrc) {
tSqlExpr *pExpr = calloc(1, sizeof(tSqlExpr));
memcpy(pExpr, pSrc, sizeof(*pSrc));
......@@ -332,7 +327,7 @@ tSQLExpr *tSqlExprClone(tSQLExpr *pSrc) {
}
void tSqlExprNodeDestroy(tSQLExpr *pExpr) {
void doDestroySqlExprNode(tSqlExpr *pExpr) {
if (pExpr == NULL) {
return;
}
......@@ -342,11 +337,10 @@ void tSqlExprNodeDestroy(tSQLExpr *pExpr) {
}
tSqlExprListDestroy(pExpr->pParam);
free(pExpr);
}
void tSqlExprDestroy(tSQLExpr *pExpr) {
void tSqlExprDestroy(tSqlExpr *pExpr) {
if (pExpr == NULL) {
return;
}
......@@ -355,7 +349,8 @@ void tSqlExprDestroy(tSQLExpr *pExpr) {
pExpr->pLeft = NULL;
tSqlExprDestroy(pExpr->pRight);
pExpr->pRight = NULL;
tSqlExprNodeDestroy(pExpr);
doDestroySqlExprNode(pExpr);
}
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pToken, uint8_t order) {
......@@ -411,13 +406,13 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int
return pList;
}
void setDbName(SStrToken *pCpxName, SStrToken *pDb) {
void tSetDbName(SStrToken *pCpxName, SStrToken *pDb) {
pCpxName->type = pDb->type;
pCpxName->z = pDb->z;
pCpxName->n = pDb->n;
}
void tSqlSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType) {
void tSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType) {
int32_t maxLen = sizeof(pField->name) / sizeof(pField->name[0]);
// truncate the column name
......@@ -485,7 +480,7 @@ static int32_t tryParseNameTwoParts(SStrToken *type) {
}
}
void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
// set the field type invalid
pField->type = -1;
pField->name[0] = 0;
......@@ -550,39 +545,39 @@ void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
/*
* extract the select info out of sql string
*/
SQuerySQL *tSetQuerySqlNode(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
SQuerySqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelectList, SArray *pFrom, tSqlExpr *pWhere,
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *pSession,
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) {
assert(pSelection != NULL);
assert(pSelectList != NULL);
SQuerySQL *pQuery = calloc(1, sizeof(SQuerySQL));
pQuery->selectToken = *pSelectToken;
pQuery->selectToken.n = (uint32_t)strlen(pQuery->selectToken.z); // all later sql string are belonged to the stream sql
SQuerySqlNode *pQuery = calloc(1, sizeof(SQuerySqlNode));
pQuery->sqlstr = *pSelectToken;
pQuery->sqlstr.n = (uint32_t)strlen(pQuery->sqlstr.z); // all later sql string are belonged to the stream sql
pQuery->pSelection = pSelection;
pQuery->pSelectList = pSelectList;
pQuery->from = pFrom;
pQuery->pGroupby = pGroupby;
pQuery->pSortOrder = pSortOrder;
pQuery->pWhere = pWhere;
if (pLimit != NULL) {
pQuery->limit = *pLimit;
pQuery->limit = pLimit;
}
if (pGLimit != NULL) {
pQuery->slimit = *pGLimit;
pQuery->slimit = pGLimit;
}
if (pInterval != NULL) {
pQuery->interval = *pInterval;
pQuery->interval = pInterval;
}
if (pSliding != NULL) {
pQuery->sliding = *pSliding;
pQuery->sliding = pSliding;
}
if (pSession != NULL) {
pQuery->sessionVal = *pSession;
pQuery->sessionVal = pSession;
}
pQuery->fillType = pFill;
......@@ -602,14 +597,14 @@ void freeCreateTableInfo(void* p) {
tfree(pInfo->tagdata.data);
}
void doDestroyQuerySql(SQuerySQL *pQuerySql) {
void doDestroyQuerySql(SQuerySqlNode *pQuerySql) {
if (pQuerySql == NULL) {
return;
}
tSqlExprListDestroy(pQuerySql->pSelection);
tSqlExprListDestroy(pQuerySql->pSelectList);
pQuerySql->pSelection = NULL;
pQuerySql->pSelectList = NULL;
tSqlExprDestroy(pQuerySql->pWhere);
pQuerySql->pWhere = NULL;
......@@ -635,15 +630,15 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) {
}
for(int32_t i = 0; i < pClause->numOfClause; ++i) {
SQuerySQL *pQuerySql = pClause->pClause[i];
SQuerySqlNode *pQuerySql = pClause->pClause[i];
doDestroyQuerySql(pQuerySql);
}
tfree(pClause->pClause);
}
SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSelect, int32_t type) {
SCreateTableSQL *pCreate = calloc(1, sizeof(SCreateTableSQL));
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SQuerySqlNode *pSelect, int32_t type) {
SCreateTableSql *pCreate = calloc(1, sizeof(SCreateTableSql));
switch (type) {
case TSQL_CREATE_TABLE: {
......@@ -687,7 +682,7 @@ SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNam
return info;
}
SAlterTableInfo *tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType) {
SAlterTableInfo *tSetAlterTableInfo(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType) {
SAlterTableInfo *pAlterTable = calloc(1, sizeof(SAlterTableInfo));
pAlterTable->name = *pTableName;
......@@ -709,7 +704,7 @@ SAlterTableInfo *tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArra
return pAlterTable;
}
void* destroyCreateTableSql(SCreateTableSQL* pCreate) {
void* destroyCreateTableSql(SCreateTableSql* pCreate) {
doDestroyQuerySql(pCreate->pSelect);
taosArrayDestroy(pCreate->colInfo.pColumns);
......@@ -757,7 +752,7 @@ SSubclauseInfo* setSubclause(SSubclauseInfo* pSubclause, void *pSqlExprInfo) {
return pSubclause;
}
pSubclause->pClause = (SQuerySQL**) tmp;
pSubclause->pClause = (SQuerySqlNode**) tmp;
pSubclause->pClause[newSize - 1] = pSqlExprInfo;
pSubclause->numOfClause++;
......@@ -788,7 +783,7 @@ SSubclauseInfo* appendSelectClause(SSubclauseInfo *pQueryInfo, void *pSubclause)
return pQueryInfo;
}
pQueryInfo->pClause = (SQuerySQL**) tmp;
pQueryInfo->pClause = (SQuerySqlNode**) tmp;
pQueryInfo->pClause[pQueryInfo->numOfClause++] = pSubclause;
return pQueryInfo;
......@@ -799,7 +794,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
pInfo->pCreateTableInfo->existCheck = (pIfNotExists->n != 0);
}
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
void setDCLSqlElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
pInfo->type = type;
if (nParam == 0) {
return;
......
......@@ -104,15 +104,14 @@ typedef union {
int yyinit;
ParseTOKENTYPE yy0;
SCreatedTableInfo yy96;
tSQLExpr* yy178;
tSqlExpr* yy178;
SCreateAcctInfo yy187;
SQuerySQL* yy216;
SCreateTableSQL* yy230;
SCreateTableSql* yy230;
SArray* yy285;
TAOS_FIELD yy295;
SQuerySqlNode* yy342;
tVariant yy362;
SIntervalVal yy376;
tSQLExprList* yy434;
SLimitVal yy438;
int yy460;
SSubclauseInfo* yy513;
......@@ -1426,14 +1425,14 @@ destroyCreateTableSql((yypminor->yy230));
break;
case 235: /* select */
{
doDestroyQuerySql((yypminor->yy216));
doDestroyQuerySql((yypminor->yy342));
}
break;
case 238: /* selcollist */
case 251: /* sclp */
case 262: /* exprlist */
{
tSqlExprListDestroy((yypminor->yy434));
tSqlExprListDestroy((yypminor->yy285));
}
break;
case 240: /* where_opt */
......@@ -2156,12 +2155,12 @@ static void yy_reduce(
case 20: /* cmd ::= SHOW CREATE TABLE ids cpxName */
{
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
setDCLSQLElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &yymsp[-1].minor.yy0);
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &yymsp[-1].minor.yy0);
}
break;
case 21: /* cmd ::= SHOW CREATE DATABASE ids */
{
setDCLSQLElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &yymsp[0].minor.yy0);
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &yymsp[0].minor.yy0);
}
break;
case 22: /* cmd ::= SHOW dbPrefix TABLES */
......@@ -2182,21 +2181,21 @@ static void yy_reduce(
case 25: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */
{
SStrToken token;
setDbName(&token, &yymsp[-3].minor.yy0);
tSetDbName(&token, &yymsp[-3].minor.yy0);
setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &yymsp[0].minor.yy0);
}
break;
case 26: /* cmd ::= SHOW dbPrefix VGROUPS */
{
SStrToken token;
setDbName(&token, &yymsp[-1].minor.yy0);
tSetDbName(&token, &yymsp[-1].minor.yy0);
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
}
break;
case 27: /* cmd ::= SHOW dbPrefix VGROUPS ids */
{
SStrToken token;
setDbName(&token, &yymsp[-2].minor.yy0);
tSetDbName(&token, &yymsp[-2].minor.yy0);
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, &yymsp[0].minor.yy0);
}
break;
......@@ -2219,21 +2218,21 @@ static void yy_reduce(
{ setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0, TSDB_DB_TYPE_TOPIC, -1); }
break;
case 32: /* cmd ::= DROP DNODE ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &yymsp[0].minor.yy0); }
{ setDCLSqlElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &yymsp[0].minor.yy0); }
break;
case 33: /* cmd ::= DROP USER ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &yymsp[0].minor.yy0); }
{ setDCLSqlElems(pInfo, TSDB_SQL_DROP_USER, 1, &yymsp[0].minor.yy0); }
break;
case 34: /* cmd ::= DROP ACCOUNT ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &yymsp[0].minor.yy0); }
{ setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &yymsp[0].minor.yy0); }
break;
case 35: /* cmd ::= USE ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_USE_DB, 1, &yymsp[0].minor.yy0);}
{ setDCLSqlElems(pInfo, TSDB_SQL_USE_DB, 1, &yymsp[0].minor.yy0);}
break;
case 36: /* cmd ::= DESCRIBE ids cpxName */
{
yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n;
setDCLSQLElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &yymsp[-1].minor.yy0);
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &yymsp[-1].minor.yy0);
}
break;
case 37: /* cmd ::= ALTER USER ids PASS ids */
......@@ -2243,16 +2242,16 @@ static void yy_reduce(
{ setAlterUserSql(pInfo, TSDB_ALTER_USER_PRIVILEGES, &yymsp[-2].minor.yy0, NULL, &yymsp[0].minor.yy0);}
break;
case 39: /* cmd ::= ALTER DNODE ids ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
{ setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
break;
case 40: /* cmd ::= ALTER DNODE ids ids ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
{ setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
break;
case 41: /* cmd ::= ALTER LOCAL ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &yymsp[0].minor.yy0); }
{ setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &yymsp[0].minor.yy0); }
break;
case 42: /* cmd ::= ALTER LOCAL ids ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
{ setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
break;
case 43: /* cmd ::= ALTER DATABASE ids alter_db_optr */
case 44: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==44);
......@@ -2281,7 +2280,7 @@ static void yy_reduce(
{ yymsp[-2].minor.yy0.n = 1;}
break;
case 53: /* cmd ::= CREATE DNODE ids */
{ setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);}
{ setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);}
break;
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.yy187);}
......@@ -2437,7 +2436,7 @@ static void yy_reduce(
case 123: /* typename ::= ids */
{
yymsp[0].minor.yy0.type = 0;
tSqlSetColumnType (&yylhsminor.yy295, &yymsp[0].minor.yy0);
tSetColumnType (&yylhsminor.yy295, &yymsp[0].minor.yy0);
}
yymsp[0].minor.yy295 = yylhsminor.yy295;
break;
......@@ -2445,10 +2444,10 @@ static void yy_reduce(
{
if (yymsp[-1].minor.yy525 <= 0) {
yymsp[-3].minor.yy0.type = 0;
tSqlSetColumnType(&yylhsminor.yy295, &yymsp[-3].minor.yy0);
tSetColumnType(&yylhsminor.yy295, &yymsp[-3].minor.yy0);
} else {
yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy525; // negative value of name length
tSqlSetColumnType(&yylhsminor.yy295, &yymsp[-3].minor.yy0);
tSetColumnType(&yylhsminor.yy295, &yymsp[-3].minor.yy0);
}
}
yymsp[-3].minor.yy295 = yylhsminor.yy295;
......@@ -2457,7 +2456,7 @@ static void yy_reduce(
{
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);
tSqlSetColumnType (&yylhsminor.yy295, &yymsp[-1].minor.yy0);
tSetColumnType (&yylhsminor.yy295, &yymsp[-1].minor.yy0);
}
yymsp[-1].minor.yy295 = yylhsminor.yy295;
break;
......@@ -2476,7 +2475,7 @@ static void yy_reduce(
break;
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));
taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy96);
......@@ -2494,7 +2493,7 @@ static void yy_reduce(
break;
case 135: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */
{
yylhsminor.yy230 = tSetCreateSqlElems(yymsp[-1].minor.yy285, NULL, NULL, TSQL_CREATE_TABLE);
yylhsminor.yy230 = tSetCreateTableInfo(yymsp[-1].minor.yy285, NULL, NULL, TSQL_CREATE_TABLE);
setSqlInfo(pInfo, yylhsminor.yy230, NULL, TSDB_SQL_CREATE_TABLE);
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
......@@ -2504,7 +2503,7 @@ static void yy_reduce(
break;
case 136: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */
{
yylhsminor.yy230 = tSetCreateSqlElems(yymsp[-5].minor.yy285, yymsp[-1].minor.yy285, NULL, TSQL_CREATE_STABLE);
yylhsminor.yy230 = tSetCreateTableInfo(yymsp[-5].minor.yy285, yymsp[-1].minor.yy285, NULL, TSQL_CREATE_STABLE);
setSqlInfo(pInfo, yylhsminor.yy230, NULL, TSDB_SQL_CREATE_TABLE);
yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n;
......@@ -2538,7 +2537,7 @@ static void yy_reduce(
break;
case 141: /* create_table_args ::= ifnotexists ids cpxName AS select */
{
yylhsminor.yy230 = tSetCreateSqlElems(NULL, NULL, yymsp[0].minor.yy216, TSQL_CREATE_STREAM);
yylhsminor.yy230 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy342, TSQL_CREATE_STREAM);
setSqlInfo(pInfo, yylhsminor.yy230, NULL, TSDB_SQL_CREATE_TABLE);
yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n;
......@@ -2556,7 +2555,7 @@ static void yy_reduce(
break;
case 144: /* column ::= ids typename */
{
tSqlSetColumnInfo(&yylhsminor.yy295, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy295);
tSetColumnInfo(&yylhsminor.yy295, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy295);
}
yymsp[-1].minor.yy295 = yylhsminor.yy295;
break;
......@@ -2593,23 +2592,23 @@ static void yy_reduce(
break;
case 156: /* select ::= SELECT selcollist from where_opt interval_opt session_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
{
yylhsminor.yy216 = tSetQuerySqlNode(&yymsp[-12].minor.yy0, yymsp[-11].minor.yy434, yymsp[-10].minor.yy285, yymsp[-9].minor.yy178, yymsp[-4].minor.yy285, yymsp[-3].minor.yy285, &yymsp[-8].minor.yy376, &yymsp[-7].minor.yy523, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy285, &yymsp[0].minor.yy438, &yymsp[-1].minor.yy438);
yylhsminor.yy342 = tSetQuerySqlNode(&yymsp[-12].minor.yy0, yymsp[-11].minor.yy285, yymsp[-10].minor.yy285, yymsp[-9].minor.yy178, yymsp[-4].minor.yy285, yymsp[-3].minor.yy285, &yymsp[-8].minor.yy376, &yymsp[-7].minor.yy523, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy285, &yymsp[0].minor.yy438, &yymsp[-1].minor.yy438);
}
yymsp[-12].minor.yy216 = yylhsminor.yy216;
yymsp[-12].minor.yy342 = yylhsminor.yy342;
break;
case 157: /* union ::= select */
{ yylhsminor.yy513 = setSubclause(NULL, yymsp[0].minor.yy216); }
{ yylhsminor.yy513 = setSubclause(NULL, yymsp[0].minor.yy342); }
yymsp[0].minor.yy513 = yylhsminor.yy513;
break;
case 158: /* union ::= LP union RP */
{ yymsp[-2].minor.yy513 = yymsp[-1].minor.yy513; }
break;
case 159: /* union ::= union UNION ALL select */
{ yylhsminor.yy513 = appendSelectClause(yymsp[-3].minor.yy513, yymsp[0].minor.yy216); }
{ yylhsminor.yy513 = appendSelectClause(yymsp[-3].minor.yy513, yymsp[0].minor.yy342); }
yymsp[-3].minor.yy513 = yylhsminor.yy513;
break;
case 160: /* union ::= union UNION ALL LP select RP */
{ yylhsminor.yy513 = appendSelectClause(yymsp[-5].minor.yy513, yymsp[-1].minor.yy216); }
{ yylhsminor.yy513 = appendSelectClause(yymsp[-5].minor.yy513, yymsp[-1].minor.yy342); }
yymsp[-5].minor.yy513 = yylhsminor.yy513;
break;
case 161: /* cmd ::= union */
......@@ -2617,29 +2616,30 @@ static void yy_reduce(
break;
case 162: /* select ::= SELECT selcollist */
{
yylhsminor.yy216 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy434, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
yylhsminor.yy342 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy285, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
yymsp[-1].minor.yy216 = yylhsminor.yy216;
yymsp[-1].minor.yy342 = yylhsminor.yy342;
break;
case 163: /* sclp ::= selcollist COMMA */
{yylhsminor.yy434 = yymsp[-1].minor.yy434;}
yymsp[-1].minor.yy434 = yylhsminor.yy434;
{yylhsminor.yy285 = yymsp[-1].minor.yy285;}
yymsp[-1].minor.yy285 = yylhsminor.yy285;
break;
case 164: /* sclp ::= */
{yymsp[1].minor.yy434 = 0;}
case 188: /* orderby_opt ::= */ yytestcase(yyruleno==188);
{yymsp[1].minor.yy285 = 0;}
break;
case 165: /* selcollist ::= sclp distinct expr as */
{
yylhsminor.yy434 = tSqlExprListAppend(yymsp[-3].minor.yy434, yymsp[-1].minor.yy178, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0);
yylhsminor.yy285 = tSqlExprListAppend(yymsp[-3].minor.yy285, yymsp[-1].minor.yy178, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0);
}
yymsp[-3].minor.yy434 = yylhsminor.yy434;
yymsp[-3].minor.yy285 = yylhsminor.yy285;
break;
case 166: /* selcollist ::= sclp STAR */
{
tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL);
yylhsminor.yy434 = tSqlExprListAppend(yymsp[-1].minor.yy434, pNode, 0, 0);
tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL);
yylhsminor.yy285 = tSqlExprListAppend(yymsp[-1].minor.yy285, pNode, 0, 0);
}
yymsp[-1].minor.yy434 = yylhsminor.yy434;
yymsp[-1].minor.yy285 = yylhsminor.yy285;
break;
case 167: /* as ::= AS ids */
{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
......@@ -2744,9 +2744,6 @@ static void yy_reduce(
case 187: /* sliding_opt ::= */
{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; }
break;
case 188: /* orderby_opt ::= */
{yymsp[1].minor.yy285 = 0;}
break;
case 189: /* orderby_opt ::= ORDER BY sortlist */
{yymsp[-2].minor.yy285 = yymsp[0].minor.yy285;}
break;
......@@ -2832,53 +2829,53 @@ static void yy_reduce(
yymsp[-2].minor.yy178 = yylhsminor.yy178;
break;
case 213: /* expr ::= ID */
{ yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);}
{ yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);}
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 214: /* expr ::= ID DOT ID */
{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);}
{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);}
yymsp[-2].minor.yy178 = yylhsminor.yy178;
break;
case 215: /* expr ::= ID DOT STAR */
{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);}
{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);}
yymsp[-2].minor.yy178 = yylhsminor.yy178;
break;
case 216: /* expr ::= INTEGER */
{ yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);}
{ yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);}
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 217: /* expr ::= MINUS INTEGER */
case 218: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==218);
{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy178 = 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.yy178 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);}
yymsp[-1].minor.yy178 = yylhsminor.yy178;
break;
case 219: /* expr ::= FLOAT */
{ yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);}
{ yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);}
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 220: /* expr ::= MINUS FLOAT */
case 221: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==221);
{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy178 = 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.yy178 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);}
yymsp[-1].minor.yy178 = yylhsminor.yy178;
break;
case 222: /* expr ::= STRING */
{ yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);}
{ yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);}
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 223: /* expr ::= NOW */
{ yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); }
{ yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); }
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 224: /* expr ::= VARIABLE */
{ yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);}
{ yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);}
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 225: /* expr ::= BOOL */
{ yylhsminor.yy178 = tSqlExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);}
{ yylhsminor.yy178 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);}
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 226: /* expr ::= ID LP exprlist RP */
{ yylhsminor.yy178 = tSqlExprCreateFunction(yymsp[-1].minor.yy434, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); }
{ yylhsminor.yy178 = tSqlExprCreateFunction(yymsp[-1].minor.yy285, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); }
yymsp[-3].minor.yy178 = yylhsminor.yy178;
break;
case 227: /* expr ::= ID LP STAR RP */
......@@ -2918,7 +2915,7 @@ static void yy_reduce(
yymsp[-2].minor.yy178 = yylhsminor.yy178;
break;
case 236: /* expr ::= expr BETWEEN expr AND expr */
{ tSQLExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy178); yylhsminor.yy178 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy178, yymsp[-2].minor.yy178, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy178, TK_LE), TK_AND);}
{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy178); yylhsminor.yy178 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy178, yymsp[-2].minor.yy178, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy178, TK_LE), TK_AND);}
yymsp[-4].minor.yy178 = yylhsminor.yy178;
break;
case 237: /* expr ::= expr AND expr */
......@@ -2954,28 +2951,28 @@ static void yy_reduce(
yymsp[-2].minor.yy178 = yylhsminor.yy178;
break;
case 245: /* expr ::= expr IN LP exprlist RP */
{yylhsminor.yy178 = tSqlExprCreate(yymsp[-4].minor.yy178, (tSQLExpr*)yymsp[-1].minor.yy434, TK_IN); }
{yylhsminor.yy178 = tSqlExprCreate(yymsp[-4].minor.yy178, (tSqlExpr*)yymsp[-1].minor.yy285, TK_IN); }
yymsp[-4].minor.yy178 = yylhsminor.yy178;
break;
case 246: /* exprlist ::= exprlist COMMA expritem */
{yylhsminor.yy434 = tSqlExprListAppend(yymsp[-2].minor.yy434,yymsp[0].minor.yy178,0, 0);}
yymsp[-2].minor.yy434 = yylhsminor.yy434;
{yylhsminor.yy285 = tSqlExprListAppend(yymsp[-2].minor.yy285,yymsp[0].minor.yy178,0, 0);}
yymsp[-2].minor.yy285 = yylhsminor.yy285;
break;
case 247: /* exprlist ::= expritem */
{yylhsminor.yy434 = tSqlExprListAppend(0,yymsp[0].minor.yy178,0, 0);}
yymsp[0].minor.yy434 = yylhsminor.yy434;
{yylhsminor.yy285 = tSqlExprListAppend(0,yymsp[0].minor.yy178,0, 0);}
yymsp[0].minor.yy285 = yylhsminor.yy285;
break;
case 248: /* expritem ::= expr */
{yylhsminor.yy178 = yymsp[0].minor.yy178;}
yymsp[0].minor.yy178 = yylhsminor.yy178;
break;
case 250: /* cmd ::= RESET QUERY CACHE */
{ setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
{ setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
break;
case 251: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......@@ -2986,14 +2983,14 @@ static void yy_reduce(
toTSDBType(yymsp[0].minor.yy0.type);
SArray* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
case 253: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......@@ -3004,7 +3001,7 @@ static void yy_reduce(
toTSDBType(yymsp[0].minor.yy0.type);
SArray* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......@@ -3018,7 +3015,7 @@ static void yy_reduce(
toTSDBType(yymsp[0].minor.yy0.type);
A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......@@ -3030,14 +3027,14 @@ static void yy_reduce(
SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1);
A = tVariantListAppend(A, &yymsp[0].minor.yy362, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
case 257: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */
{
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......@@ -3048,14 +3045,14 @@ static void yy_reduce(
toTSDBType(yymsp[0].minor.yy0.type);
SArray* K = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
case 259: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */
{
yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n;
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy285, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......@@ -3066,7 +3063,7 @@ static void yy_reduce(
toTSDBType(yymsp[0].minor.yy0.type);
SArray* A = tVariantListAppendToken(NULL, &yymsp[0].minor.yy0, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......@@ -3080,7 +3077,7 @@ static void yy_reduce(
toTSDBType(yymsp[0].minor.yy0.type);
A = tVariantListAppendToken(A, &yymsp[0].minor.yy0, -1);
SAlterTableInfo* pAlterTable = tAlterTableSqlElems(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册