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

[td-225]refactor.

上级 a6d0bf4f
......@@ -780,8 +780,8 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySqlNode
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
if (pQuerySqlNode->interval == NULL) {
if (pQuerySqlNode->sliding != NULL) {
if (!TPARSER_HAS_TOKEN(pQuerySqlNode->interval.interval)) {
if (TPARSER_HAS_TOKEN(pQuerySqlNode->sliding)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
......@@ -794,7 +794,7 @@ int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySqlNode
}
// interval is not null
SStrToken *t = &pQuerySqlNode->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, SQuerySqlNode
}
}
if (parseIntervalOffset(pCmd, pQueryInfo, &pQuerySqlNode->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, pQuerySqlNode->sliding) != TSDB_CODE_SUCCESS) {
if (parseSlidingClause(pCmd, pQueryInfo, &pQuerySqlNode->sliding) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
}
......@@ -830,12 +830,12 @@ int32_t parseSessionClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySqlNode
const char* msg4 = "invalid time window";
// no session window
if (pQuerySqlNode->sessionVal == NULL) {
if (!TPARSER_HAS_TOKEN(pQuerySqlNode->sessionVal.gap)) {
return TSDB_CODE_SUCCESS;
}
SStrToken* col = &pQuerySqlNode->sessionVal->col;
SStrToken* gap = &pQuerySqlNode->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) {
......@@ -5439,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 = *pQuerySqlNode->limit;
pQueryInfo->limit = pQuerySqlNode->limit;
pQueryInfo->clauseLimit = pQueryInfo->limit.limit;
pQueryInfo->slimit = *pQuerySqlNode->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);
......@@ -6840,7 +6840,8 @@ int32_t doValidateSqlNode(SSqlObj* pSql, SQuerySqlNode* pQuerySqlNode, int32_t i
}
int32_t joinQuery = (pQuerySqlNode->from != NULL && taosArrayGetSize(pQuerySqlNode->from) > 2);
int32_t timeWindowQuery = !(pQuerySqlNode->interval == NULL || pQuerySqlNode->sessionVal == NULL);
int32_t timeWindowQuery =
(TPARSER_HAS_TOKEN(pQuerySqlNode->interval.interval) || TPARSER_HAS_TOKEN(pQuerySqlNode->sessionVal.gap));
if (parseSelectClause(pCmd, index, pQuerySqlNode->pSelectList, isSTable, joinQuery, timeWindowQuery) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_SQL;
......
......@@ -50,6 +50,8 @@ extern char tTokenTypeSwitcher[13];
} \
} while (0)
#define TPARSER_HAS_TOKEN(_t) ((_t).n > 0)
typedef struct SLimitVal {
int64_t limit;
int64_t offset;
......@@ -81,12 +83,12 @@ typedef struct 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>
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]
SStrToken sqlstr; // sql string in select clause
} SQuerySqlNode;
......@@ -222,7 +224,7 @@ typedef struct tSqlExpr {
// used in select clause. select <SArray> from xxx
typedef struct tSqlExprItem {
tSqlExpr *pNode; // The list of expressions
char * aliasName; // alias name, null-terminated string
char *aliasName; // alias name, null-terminated string
bool distinct;
} tSqlExprItem;
......@@ -241,9 +243,8 @@ SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinc
void tSqlExprListDestroy(SArray *pList);
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);
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps,
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pgLimit);
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SQuerySqlNode *pSelect, int32_t type);
......@@ -251,7 +252,7 @@ SAlterTableInfo *tSetAlterTableInfo(SStrToken *pTableName, SArray *pCols, SArray
SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNames, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists);
void destroyAllSelectClause(SSubclauseInfo *pSql);
void doDestroyQuerySql(SQuerySqlNode *pSql);
void destroyQuerySqlNode(SQuerySqlNode *pSql);
void freeCreateTableInfo(void* p);
SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, int32_t type);
......
......@@ -547,38 +547,26 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
*/
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(pSelectList != NULL);
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *psLimit) {
assert(pSelectList != NULL && pLimit != NULL && psLimit != NULL && pInterval != NULL && pSliding != NULL &&
pSession != NULL);
SQuerySqlNode *pQuery = calloc(1, sizeof(SQuerySqlNode));
// all later sql string are belonged to the stream sql
pQuery->sqlstr = *pSelectToken;
pQuery->sqlstr.n = (uint32_t)strlen(pQuery->sqlstr.z); // all later sql string are belonged to the stream sql
pQuery->sqlstr.n = (uint32_t)strlen(pQuery->sqlstr.z);
pQuery->pSelectList = pSelectList;
pQuery->from = pFrom;
pQuery->pGroupby = pGroupby;
pQuery->pSortOrder = pSortOrder;
pQuery->pWhere = pWhere;
if (pLimit != NULL) {
pQuery->limit = pLimit;
}
if (pGLimit != NULL) {
pQuery->slimit = pGLimit;
}
if (pInterval != NULL) {
pQuery->interval = pInterval;
}
if (pSliding != NULL) {
pQuery->sliding = pSliding;
}
if (pSession != NULL) {
pQuery->sessionVal = pSession;
}
pQuery->limit = *pLimit;
pQuery->slimit = *psLimit;
pQuery->interval = *pInterval;
pQuery->sliding = *pSliding;
pQuery->sessionVal = *pSession;
pQuery->fillType = pFill;
return pQuery;
......@@ -597,7 +585,7 @@ void freeCreateTableInfo(void* p) {
tfree(pInfo->tagdata.data);
}
void doDestroyQuerySql(SQuerySqlNode *pQuerySql) {
void destroyQuerySqlNode(SQuerySqlNode *pQuerySql) {
if (pQuerySql == NULL) {
return;
}
......@@ -631,7 +619,7 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) {
for(int32_t i = 0; i < pClause->numOfClause; ++i) {
SQuerySqlNode *pQuerySql = pClause->pClause[i];
doDestroyQuerySql(pQuerySql);
destroyQuerySqlNode(pQuerySql);
}
tfree(pClause->pClause);
......@@ -705,7 +693,7 @@ SAlterTableInfo *tSetAlterTableInfo(SStrToken *pTableName, SArray *pCols, SArray
}
void* destroyCreateTableSql(SCreateTableSql* pCreate) {
doDestroyQuerySql(pCreate->pSelect);
destroyQuerySqlNode(pCreate->pSelect);
taosArrayDestroy(pCreate->colInfo.pColumns);
taosArrayDestroy(pCreate->colInfo.pTagColumns);
......
......@@ -1425,7 +1425,7 @@ destroyCreateTableSql((yypminor->yy230));
break;
case 235: /* select */
{
doDestroyQuerySql((yypminor->yy342));
destroyQuerySqlNode((yypminor->yy342));
}
break;
case 238: /* selcollist */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册