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

[td-10564] refactor code and fix bug in parse sql.

上级 6fedb60e
......@@ -235,11 +235,12 @@ typedef struct SMultiFunctionsDesc {
bool hasFilter;
bool onlyTagQuery;
bool orderProjectQuery;
bool stateWindow;
bool globalMerge;
bool multigroupResult;
bool blockDistribution;
bool stateWindow;
bool timewindow;
bool sessionWindow;
bool topbotQuery;
bool interpQuery;
bool distinct;
......
......@@ -37,9 +37,14 @@ enum SQL_NODE_TYPE {
SQL_NODE_EXPR = 4,
};
enum SQL_NODE_FROM_TYPE {
SQL_NODE_FROM_SUBQUERY = 1,
SQL_NODE_FROM_TABLELIST = 2,
enum SQL_FROM_NODE_TYPE {
SQL_FROM_NODE_SUBQUERY = 1,
SQL_FROM_NODE_TABLES = 2,
};
enum SQL_UNION_TYPE {
SQL_TYPE_UNIONALL = 1,
SQL_TYPE_UNION = 2,
};
extern char tTokenTypeSwitcher[13];
......@@ -79,8 +84,8 @@ typedef struct SWindowStateVal {
struct SRelationInfo;
typedef struct SSqlNode {
struct SArray *pSelNodeList; // select clause
struct SRelationInfo *from; // from clause SArray<SSqlNode>
struct SArray *pSelNodeList; // select clause
struct tSqlExpr *pWhere; // where clause [optional]
SArray *pGroupby; // groupby clause, only for tags[optional], SArray<SListItem>
SArray *pSortOrder; // orderby [optional], SArray<SListItem>
......@@ -95,18 +100,23 @@ typedef struct SSqlNode {
struct tSqlExpr *pHaving; // having clause [optional]
} SSqlNode;
typedef struct SRelElementPair {
typedef struct SSubclause {
int32_t unionType;
SArray *node;
} SSubclause;
typedef struct SRelElement {
union {
SToken tableName;
SArray *pSubquery;
SToken tableName;
SSubclause *pSubquery;
};
SToken aliasName;
} SRelElementPair;
} SRelElement;
typedef struct SRelationInfo {
int32_t type; // nested query|table name list
SArray *list; // SArray<SRelElementPair>
SArray *list; // SArray<SRelElement>
} SRelationInfo;
typedef struct SCreatedTableInfo {
......@@ -216,7 +226,7 @@ typedef struct SMiscInfo {
typedef struct SSqlInfo {
int32_t type;
bool valid;
SArray *list; // todo refactor
SSubclause sub;
char msg[256];
SArray *funcs;
union {
......@@ -257,7 +267,7 @@ SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrd
SRelationInfo *setTableNameList(SRelationInfo *pRelationInfo, SToken *pName, SToken *pAlias);
void * destroyRelationInfo(SRelationInfo *pFromInfo);
SRelationInfo *addSubquery(SRelationInfo *pRelationInfo, SArray *pSub, SToken *pAlias);
SRelationInfo *addSubquery(SRelationInfo *pRelationInfo, SSubclause *pSub, SToken *pAlias);
// sql expr leaf node
tSqlExpr *tSqlExprCreateIdValue(SToken *pToken, int32_t optrType);
......@@ -285,13 +295,13 @@ SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *
SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
SToken *igExists);
void destroyAllSqlNode(SArray *pSqlNode);
void destroyAllSqlNode(struct SSubclause *pSqlNode);
void destroySqlNode(SSqlNode *pSql);
void freeCreateTableInfo(void* p);
SSqlInfo *setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, int32_t type);
SArray *setSubclause(SArray *pList, void *pSqlNode);
SArray *appendSelectClause(SArray *pList, void *pSubclause);
SSubclause* setSubclause(SSubclause* sub, void *pSqlNode);
SSubclause* appendSelectClause(SSubclause *sub, int32_t unionType, void *pSubclause);
void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists);
void* destroyCreateTableSql(SCreateTableSql* pCreate);
......
......@@ -487,11 +487,11 @@ select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_option(K) sl
select(A) ::= LP select(B) RP. {A = B;}
%type union {SArray*}
%type union {SSubclause*}
%destructor union {destroyAllSqlNode($$);}
union(Y) ::= select(X). { Y = setSubclause(NULL, X); }
union(Y) ::= union(Z) UNION ALL select(X). { Y = appendSelectClause(Z, X); }
union(Y) ::= union(Z) UNION ALL select(X). { Y = appendSelectClause(Z, SQL_TYPE_UNIONALL, X); }
union(Y) ::= union(Z) UNION select(X). { Y = appendSelectClause(Z, SQL_TYPE_UNION, X); }
cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
// Support for the SQL exprssion without from & where subclauses, e.g.,
......
......@@ -72,11 +72,11 @@ SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrd
SRelationInfo *setTableNameList(SRelationInfo *pRelationInfo, SToken *pName, SToken *pAlias) {
if (pRelationInfo == NULL) {
pRelationInfo = calloc(1, sizeof(SRelationInfo));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElement));
}
pRelationInfo->type = SQL_NODE_FROM_TABLELIST;
SRelElementPair p = {.tableName = *pName};
pRelationInfo->type = SQL_FROM_NODE_TABLES;
SRelElement p = {.tableName = *pName};
if (pAlias != NULL) {
p.aliasName = *pAlias;
} else {
......@@ -92,12 +92,12 @@ void *destroyRelationInfo(SRelationInfo *pRelationInfo) {
return NULL;
}
if (pRelationInfo->type == SQL_NODE_FROM_TABLELIST) {
if (pRelationInfo->type == SQL_FROM_NODE_TABLES) {
taosArrayDestroy(pRelationInfo->list);
} else {
size_t size = taosArrayGetSize(pRelationInfo->list);
for(int32_t i = 0; i < size; ++i) {
SArray* pa = taosArrayGetP(pRelationInfo->list, i);
SSubclause* pa = taosArrayGetP(pRelationInfo->list, i);
destroyAllSqlNode(pa);
}
taosArrayDestroy(pRelationInfo->list);
......@@ -107,15 +107,15 @@ void *destroyRelationInfo(SRelationInfo *pRelationInfo) {
return NULL;
}
SRelationInfo *addSubquery(SRelationInfo *pRelationInfo, SArray *pSub, SToken *pAlias) {
SRelationInfo *addSubquery(SRelationInfo *pRelationInfo, SSubclause *pSub, SToken *pAlias) {
if (pRelationInfo == NULL) {
pRelationInfo = calloc(1, sizeof(SRelationInfo));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElement));
}
pRelationInfo->type = SQL_NODE_FROM_SUBQUERY;
pRelationInfo->type = SQL_FROM_NODE_SUBQUERY;
SRelElementPair p = {.pSubquery = pSub};
SRelElement p = {.pSubquery = pSub};
if (pAlias != NULL) {
p.aliasName = *pAlias;
} else {
......@@ -641,18 +641,18 @@ SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames,
return info;
}
void destroyAllSqlNode(SArray *pList) {
if (pList == NULL) {
void destroyAllSqlNode(struct SSubclause *pSub) {
if (pSub->node == NULL) {
return;
}
size_t size = taosArrayGetSize(pList);
size_t size = taosArrayGetSize(pSub->node);
for(int32_t i = 0; i < size; ++i) {
SSqlNode *pNode = taosArrayGetP(pList, i);
SSqlNode *pNode = taosArrayGetP(pSub->node, i);
destroySqlNode(pNode);
}
taosArrayDestroy(pList);
taosArrayDestroy(pSub->node);
}
static void freeItem(void *pItem) {
......@@ -698,7 +698,8 @@ SSqlInfo* setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, in
pInfo->type = type;
if (type == TSDB_SQL_SELECT) {
pInfo->list = (SArray*) pSqlExprInfo;
pInfo->sub = *(SSubclause*) pSqlExprInfo;
tfree(pSqlExprInfo);
} else {
pInfo->pCreateTableInfo = pSqlExprInfo;
}
......@@ -710,18 +711,25 @@ SSqlInfo* setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, in
return pInfo;
}
SArray* setSubclause(SArray* pList, void *pSqlNode) {
if (pList == NULL) {
pList = taosArrayInit(1, POINTER_BYTES);
SSubclause* setSubclause(SSubclause* pSub, void *pSqlNode) {
if (pSub == NULL) {
pSub = malloc(sizeof(SSubclause));
pSub->unionType = SQL_TYPE_UNIONALL;
pSub->node = taosArrayInit(1, POINTER_BYTES);
}
taosArrayPush(pList, &pSqlNode);
return pList;
taosArrayPush(pSub->node, &pSqlNode);
return pSub;
}
SArray* appendSelectClause(SArray *pList, void *pSubclause) {
taosArrayPush(pList, &pSubclause);
return pList;
SSubclause* appendSelectClause(SSubclause *pSub, int32_t type, void *pSubclause) {
taosArrayPush(pSub->node, &pSubclause);
if (type == SQL_TYPE_UNION) {
pSub->unionType = type;
}
return pSub;
}
void setCreatedTableName(SSqlInfo *pInfo, SToken *pTableNameToken, SToken *pIfNotExists) {
......@@ -776,7 +784,7 @@ void destroySqlInfo(SSqlInfo *pInfo) {
taosArrayDestroy(pInfo->funcs);
if (pInfo->type == TSDB_SQL_SELECT) {
destroyAllSqlNode(pInfo->list);
destroyAllSqlNode(&pInfo->sub);
} else if (pInfo->type == TSDB_SQL_CREATE_TABLE) {
pInfo->pCreateTableInfo = destroyCreateTableSql(pInfo->pCreateTableInfo);
} else if (pInfo->type == TSDB_SQL_ALTER_TABLE) {
......@@ -785,7 +793,7 @@ void destroySqlInfo(SSqlInfo *pInfo) {
tfree(pInfo->pAlterInfo->tagData.data);
tfree(pInfo->pAlterInfo);
} else if (pInfo->type == TSDB_SQL_COMPACT_VNODE) {
tSqlExprListDestroy(pInfo->list);
tSqlExprListDestroy(pInfo->sub.node);
} else {
if (pInfo->pMiscInfo != NULL) {
taosArrayDestroy(pInfo->pMiscInfo->a);
......@@ -935,7 +943,7 @@ void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SToken *pName, SToken* pPwd,
void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam) {
pInfo->type = type;
pInfo->list = pParam;
pInfo->sub.node = pParam;
}
void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) {
......
......@@ -268,11 +268,11 @@ void destroyQueryInfo(SQueryStmtInfo* pQueryInfo) {
}
static int32_t doValidateSubquery(SSqlNode* pSqlNode, int32_t index, SQueryStmtInfo* pQueryInfo, SMsgBuf* pMsgBuf) {
SRelElementPair* subInfo = taosArrayGet(pSqlNode->from->list, index);
SRelElement* subInfo = taosArrayGet(pSqlNode->from->list, index);
// union all is not support currently
SSqlNode* p = taosArrayGetP(subInfo->pSubquery, 0);
if (taosArrayGetSize(subInfo->pSubquery) >= 2) {
SSqlNode* p = taosArrayGetP(subInfo->pSubquery->node, 0);
if (taosArrayGetSize(subInfo->pSubquery->node) >= 2) {
return buildInvalidOperationMsg(pMsgBuf, "not support union in subquery");
}
......@@ -804,6 +804,7 @@ int32_t validateSessionNode(SQueryStmtInfo *pQueryInfo, SSessionWindowVal* pSess
SSchema* pSchema = getOneColumnSchema(pTableMeta, index.columnIndex);
pQueryInfo->sessionWindow.col = createColumn(pTableMetaInfo->pTableMeta->uid, pTableMetaInfo->aliasName, index.type, pSchema);
pQueryInfo->info.sessionWindow = true;
return TSDB_CODE_SUCCESS;
}
......@@ -1401,13 +1402,13 @@ int32_t validateSqlNode(SSqlNode* pSqlNode, SQueryStmtInfo* pQueryInfo, SMsgBuf*
// return doLocalQueryProcess(pCmd, pQueryInfo, pSqlNode);
}
if (pSqlNode->from->type == SQL_NODE_FROM_SUBQUERY) {
if (pSqlNode->from->type == SQL_FROM_NODE_SUBQUERY) {
pQueryInfo->numOfTables = 0;
// parse the subquery in the first place
int32_t numOfSub = (int32_t)taosArrayGetSize(pSqlNode->from->list);
for (int32_t i = 0; i < numOfSub; ++i) {
SRelElementPair* subInfo = taosArrayGet(pSqlNode->from->list, i);
SRelElement* subInfo = taosArrayGet(pSqlNode->from->list, i);
code = doValidateSubquery(pSqlNode, i, pQueryInfo, pMsgBuf);
if (code != TSDB_CODE_SUCCESS) {
return code;
......@@ -1574,7 +1575,8 @@ int32_t checkForInvalidExpr(SQueryStmtInfo* pQueryInfo, SMsgBuf* pMsgBuf) {
const char* msg5 = "scalar function can not be used in time window query";
const char* msg6 = "not support distinct mixed with join";
const char* msg7 = "not support distinct mixed with groupby";
const char* msg8 = "_block_dist not support subquery, only support stable/table";
const char* msg8 = "block_dist not support subquery, only support stable/table";
const char* msg9 = "time window aggregate can not be mixed up with group by column";
if (pQueryInfo->info.topbotQuery) {
......@@ -1656,6 +1658,15 @@ int32_t checkForInvalidExpr(SQueryStmtInfo* pQueryInfo, SMsgBuf* pMsgBuf) {
* nested subquery not support block_dist query
* select block_dist() from (select * from table_name)
*/
/*
* 8. invalid sql:
* select count(*) from table_name [interval(10s)|session(ts, 10s)|state_window(col_name)] group by col_name
*/
if ((pQueryInfo->info.timewindow || pQueryInfo->info.stateWindow || pQueryInfo->info.sessionWindow) &&
pQueryInfo->info.groupbyColumn) {
return buildInvalidOperationMsg(pMsgBuf, msg9);
}
}
static int32_t resColId = 5000;
......@@ -3790,7 +3801,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
tscTrace("0x%"PRIx64" start to parse the %dth subclause, total:%"PRIzu, pSql->self, i, size);
if (size > 1 && pSqlNode->from && pSqlNode->from->type == SQL_NODE_FROM_SUBQUERY) {
if (size > 1 && pSqlNode->from && pSqlNode->from->type == SQL_FROM_NODE_SUBQUERY) {
return setInvalidOperatorMsg(pMsgBuf, msg1);
}
......@@ -3895,9 +3906,9 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
SMsgBuf buf = {.buf = msgBuf, .len = msgBufLen};
size_t len = taosArrayGetSize(pInfo->list);
size_t len = taosArrayGetSize(pInfo->sub.node);
for(int32_t i = 0; i < len; ++i) {
SSqlNode* p = taosArrayGetP(pInfo->list, i);
SSqlNode* p = taosArrayGetP(pInfo->sub.node, i);
code = evaluateSqlNode(p, pTableMeta->tableInfo.precision, &buf);
if (code != TSDB_CODE_SUCCESS) {
return code;
......@@ -3905,7 +3916,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
}
for(int32_t i = 0; i < len; ++i) {
SSqlNode* p = taosArrayGetP(pInfo->list, i);
SSqlNode* p = taosArrayGetP(pInfo->sub.node, i);
validateSqlNode(p, pQueryInfo, &buf);
}
......@@ -3916,6 +3927,5 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
return code;
}
// convert the sqlnode into queryinfo
return code;
}
......@@ -82,12 +82,12 @@ static int32_t getTableNameFromSubquery(SSqlNode* pSqlNode, SArray* tableNameLis
int32_t numOfSub = (int32_t)taosArrayGetSize(pSqlNode->from->list);
for (int32_t j = 0; j < numOfSub; ++j) {
SRelElementPair* sub = taosArrayGet(pSqlNode->from->list, j);
SRelElement* sub = taosArrayGet(pSqlNode->from->list, j);
int32_t num = (int32_t)taosArrayGetSize(sub->pSubquery);
int32_t num = (int32_t)taosArrayGetSize(sub->pSubquery->node);
for (int32_t i = 0; i < num; ++i) {
SSqlNode* p = taosArrayGetP(sub->pSubquery, i);
if (p->from->type == SQL_NODE_FROM_TABLELIST) {
SSqlNode* p = taosArrayGetP(sub->pSubquery->node, i);
if (p->from->type == SQL_FROM_NODE_TABLES) {
int32_t code = getTableNameFromSqlNode(p, tableNameList, pMsgBuf);
if (code != TSDB_CODE_SUCCESS) {
return code;
......@@ -105,10 +105,10 @@ int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList, SMsgB
const char* msg1 = "invalid table name";
int32_t numOfTables = (int32_t) taosArrayGetSize(pSqlNode->from->list);
assert(pSqlNode->from->type == SQL_NODE_FROM_TABLELIST);
assert(pSqlNode->from->type == SQL_FROM_NODE_TABLES);
for(int32_t j = 0; j < numOfTables; ++j) {
SRelElementPair* item = taosArrayGet(pSqlNode->from->list, j);
SRelElement* item = taosArrayGet(pSqlNode->from->list, j);
SToken* t = &item->tableName;
if (t->type == TK_INTEGER || t->type == TK_FLOAT || t->type == TK_STRING) {
......@@ -138,15 +138,15 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMet
pMetaInfo->pTableName = taosArrayInit(4, sizeof(SName));
pMetaInfo->pUdf = taosArrayInit(4, POINTER_BYTES);
size_t size = taosArrayGetSize(pSqlInfo->list);
size_t size = taosArrayGetSize(pSqlInfo->sub.node);
for (int32_t i = 0; i < size; ++i) {
SSqlNode* pSqlNode = taosArrayGetP(pSqlInfo->list, i);
SSqlNode* pSqlNode = taosArrayGetP(pSqlInfo->sub.node, i);
if (pSqlNode->from == NULL) {
return buildInvalidOperationMsg(&msgBuf, "invalid from clause");
}
// load the table meta in the FROM clause
if (pSqlNode->from->type == SQL_NODE_FROM_TABLELIST) {
if (pSqlNode->from->type == SQL_FROM_NODE_TABLES) {
code = getTableNameFromSqlNode(pSqlNode, pMetaInfo->pTableName, &msgBuf);
if (code != TSDB_CODE_SUCCESS) {
return code;
......
......@@ -182,7 +182,7 @@ void updateExprInfo(SExprInfo* pExprInfo, int16_t functionId, int32_t colId, int
SExprInfo* getExprInfo(SQueryStmtInfo* pQueryInfo, int32_t index) {
assert(pQueryInfo != NULL && pQueryInfo->exprList && index >= 0);
return taosArrayGetP(getCurrentExprList(pQueryInfo->exprList), index);
return taosArrayGetP(getCurrentExprList(pQueryInfo), index);
}
void destroyExprInfo(SExprInfo* pExprInfo) {
......
此差异已折叠。
......@@ -75,7 +75,7 @@ void sqlCheck(const char* sql, bool valid) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -87,7 +87,7 @@ void sqlCheck(const char* sql, bool valid) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
if (valid) {
......@@ -112,7 +112,7 @@ TEST(testCase, validateAST_test) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -124,7 +124,7 @@ TEST(testCase, validateAST_test) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
SArray* pExprList = pQueryInfo->exprList[0];
......@@ -170,7 +170,7 @@ TEST(testCase, function_Test) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -182,7 +182,7 @@ TEST(testCase, function_Test) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
SArray* pExprList = pQueryInfo->exprList[0];
......@@ -216,7 +216,7 @@ TEST(testCase, function_Test2) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -228,7 +228,7 @@ TEST(testCase, function_Test2) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
SArray* pExprList = pQueryInfo->exprList[0];
......@@ -262,7 +262,7 @@ TEST(testCase, function_Test3) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -274,7 +274,7 @@ TEST(testCase, function_Test3) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
SArray* pExprList = pQueryInfo->exprList[0];
......@@ -307,7 +307,7 @@ TEST(testCase, function_Test4) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -319,7 +319,7 @@ TEST(testCase, function_Test4) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
SArray* pExprList = pQueryInfo->exprList[0];
......@@ -355,7 +355,7 @@ TEST(testCase, function_Test5) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -367,7 +367,7 @@ TEST(testCase, function_Test5) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_EQ(ret, 0);
......@@ -410,6 +410,8 @@ TEST(testCase, function_Test10) {
sqlCheck("select length(length(length(a))) from `t.1abc`", true);
sqlCheck("select count() from `t.1abc`", false);
sqlCheck("select block_dist() from `t.1abc`", true);
sqlCheck("select block_dist(a) from `t.1abc`", false);
sqlCheck("select count(*) from `t.1abc` interval(1s) group by a", false);
}
TEST(testCase, function_Test6) {
......@@ -422,7 +424,7 @@ TEST(testCase, function_Test6) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*)taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -434,7 +436,7 @@ TEST(testCase, function_Test6) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_EQ(ret, 0);
......@@ -492,7 +494,7 @@ TEST(testCase, function_Test6) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -504,7 +506,7 @@ TEST(testCase, function_Test6) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_EQ(ret, 0);
......@@ -551,7 +553,7 @@ TEST(testCase, function_Test6) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -563,7 +565,7 @@ TEST(testCase, function_Test6) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_EQ(ret, 0);
......@@ -601,7 +603,7 @@ TEST(testCase, function_Test6) {
info1 = doGenerateAST("select sum(length(a)+length(b)) from `t.1abc` interval(10s, 1s)");
ASSERT_EQ(info1.valid, true);
pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -612,7 +614,7 @@ TEST(testCase, function_Test6) {
pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_EQ(ret, 0);
......@@ -630,7 +632,7 @@ TEST(testCase, function_Test6) {
SSqlInfo info1 = doGenerateAST("select count(k) from `t.1abc` interval(10s, 1s)");
ASSERT_EQ(info1.valid, true);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -642,7 +644,7 @@ TEST(testCase, function_Test6) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_NE(ret, 0);
......@@ -653,7 +655,7 @@ TEST(testCase, function_Test6) {
info1 = doGenerateAST("select top(a*b, ABC) from `t.1abc` interval(10s, 1s)");
ASSERT_EQ(info1.valid, true);
pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -664,7 +666,7 @@ TEST(testCase, function_Test6) {
pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_NE(ret, 0);
......
......@@ -75,7 +75,7 @@ void generateLogicplan(const char* sql) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -87,7 +87,7 @@ void generateLogicplan(const char* sql) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_EQ(ret, 0);
......@@ -115,7 +115,7 @@ TEST(testCase, planner_test) {
buf.len = 128;
buf.buf = msg;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
ASSERT_EQ(code, 0);
......@@ -127,7 +127,7 @@ TEST(testCase, planner_test) {
SQueryStmtInfo* pQueryInfo = createQueryInfo();
setTableMetaInfo(pQueryInfo, &req);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.sub.node, 0);
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
ASSERT_EQ(ret, 0);
......@@ -165,18 +165,18 @@ TEST(testCase, planner_test) {
}
TEST(testCase, displayPlan) {
// generateLogicplan("select count(*) from `t.1abc`");
// generateLogicplan("select count(*)+ 22 from `t.1abc`");
// generateLogicplan("select count(*)+ 22 from `t.1abc` interval(1h, 20s) sliding(10m) limit 20,30");
// generateLogicplan("select count(*) from `t.1abc` group by a");
// generateLogicplan("select count(A+B) from `t.1abc` group by a");
// generateLogicplan("select count(length(a)+b) from `t.1abc` group by a");
// generateLogicplan("select count(*) from `t.1abc` interval(10s, 5s) sliding(7s)");
// generateLogicplan("select count(*),sum(a),avg(b),min(a+b)+99 from `t.1abc`");
// generateLogicplan("select count(*), min(a) + 99 from `t.1abc`");
// generateLogicplan("select count(length(count(*) + 22)) from `t.1abc`");
// generateLogicplan("select concat(concat(a,b), concat(a,b)) from `t.1abc` limit 20");
// generateLogicplan("select count(*), first(a), last(b) from `t.1abc` state_window(a)");
generateLogicplan("select count(*) from `t.1abc`");
generateLogicplan("select count(*)+ 22 from `t.1abc`");
generateLogicplan("select count(*)+ 22 from `t.1abc` interval(1h, 20s) sliding(10m) limit 20,30");
generateLogicplan("select count(*) from `t.1abc` group by a");
generateLogicplan("select count(A+B) from `t.1abc` group by a");
generateLogicplan("select count(length(a)+b) from `t.1abc` group by a");
generateLogicplan("select count(*) from `t.1abc` interval(10s, 5s) sliding(7s)");
generateLogicplan("select count(*),sum(a),avg(b),min(a+b)+99 from `t.1abc`");
generateLogicplan("select count(*), min(a) + 99 from `t.1abc`");
generateLogicplan("select count(length(count(*) + 22)) from `t.1abc`");
generateLogicplan("select concat(concat(a,b), concat(a,b)) from `t.1abc` limit 20");
generateLogicplan("select count(*), first(a), last(b) from `t.1abc` state_window(a)");
generateLogicplan("select count(*), first(a), last(b) from `t.1abc` session(ts, 20s)");
// order by + group by column + limit offset + fill
......
......@@ -680,12 +680,12 @@ TEST(testCase, generateAST_test) {
msgBuf.buf = msg;
msgBuf.len = 128;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &msgBuf);
ASSERT_EQ(code, 0);
SSqlInfo info2 = doGenerateAST("select * from abc where ts<now+2");
SSqlNode* pNode2 = (SSqlNode*) taosArrayGetP(((SArray*)info2.list), 0);
SSqlNode* pNode2 = (SSqlNode*) taosArrayGetP(((SArray*)info2.sub.node), 0);
code = evaluateSqlNode(pNode2, TSDB_TIME_PRECISION_MILLI, &msgBuf);
ASSERT_NE(code, 0);
......@@ -703,7 +703,7 @@ TEST(testCase, evaluateAST_test) {
msgBuf.buf = msg;
msgBuf.len = 128;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &msgBuf);
ASSERT_EQ(code, 0);
destroySqlInfo(&info1);
......
......@@ -912,7 +912,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tscTrace("0x%"PRIx64" start to parse the %dth subclause, total:%"PRIzu, pSql->self, i, size);
if (size > 1 && pSqlNode->from && pSqlNode->from->type == SQL_NODE_FROM_SUBQUERY) {
if (size > 1 && pSqlNode->from && pSqlNode->from->type == SQL_FROM_NODE_SUBQUERY) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
......@@ -7981,11 +7981,11 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
if (pFromInfo->type == SQL_NODE_FROM_SUBQUERY){
if (pFromInfo->type == SQL_FROM_NODE_SUBQUERY){
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9);
}
SRelElementPair* p1 = taosArrayGet(pFromInfo->list, 0);
SRelElement* p1 = taosArrayGet(pFromInfo->list, 0);
SStrToken srcToken = {.z = p1->tableName.z, .n = p1->tableName.n, .type = TK_STRING};
if (tscValidateName(&srcToken) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
......@@ -8415,10 +8415,10 @@ static int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList
const char* msg1 = "invalid table name";
int32_t numOfTables = (int32_t) taosArrayGetSize(pSqlNode->from->list);
assert(pSqlNode->from->type == SQL_NODE_FROM_TABLELIST);
assert(pSqlNode->from->type == SQL_FROM_NODE_TABLES);
for(int32_t j = 0; j < numOfTables; ++j) {
SRelElementPair* item = taosArrayGet(pSqlNode->from->list, j);
SRelElement* item = taosArrayGet(pSqlNode->from->list, j);
SStrToken* t = &item->tableName;
if (t->type == TK_INTEGER || t->type == TK_FLOAT) {
......@@ -8446,12 +8446,12 @@ static int32_t getTableNameFromSubquery(SSqlNode* pSqlNode, SArray* tableNameLis
int32_t numOfSub = (int32_t) taosArrayGetSize(pSqlNode->from->list);
for(int32_t j = 0; j < numOfSub; ++j) {
SRelElementPair* sub = taosArrayGet(pSqlNode->from->list, j);
SRelElement* sub = taosArrayGet(pSqlNode->from->list, j);
int32_t num = (int32_t)taosArrayGetSize(sub->pSubquery);
for (int32_t i = 0; i < num; ++i) {
SSqlNode* p = taosArrayGetP(sub->pSubquery, i);
if (p->from->type == SQL_NODE_FROM_TABLELIST) {
if (p->from->type == SQL_FROM_NODE_TABLES) {
int32_t code = getTableNameFromSqlNode(p, tableNameList, msgBuf, pSql);
if (code != TSDB_CODE_SUCCESS) {
return code;
......@@ -8520,7 +8520,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
// load the table meta in the from clause
if (pSqlNode->from->type == SQL_NODE_FROM_TABLELIST) {
if (pSqlNode->from->type == SQL_FROM_NODE_TABLES) {
code = getTableNameFromSqlNode(pSqlNode, tableNameList, tscGetErrorMsgPayload(pCmd), pSql);
if (code != TSDB_CODE_SUCCESS) {
goto _end;
......@@ -8678,7 +8678,7 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
tscAddEmptyMetaInfo(pQueryInfo);
}
SRelElementPair *item = taosArrayGet(pSqlNode->from->list, i);
SRelElement *item = taosArrayGet(pSqlNode->from->list, i);
SStrToken *oriName = &item->tableName;
if (oriName->type == TK_INTEGER || oriName->type == TK_FLOAT) {
......@@ -8786,7 +8786,7 @@ static STableMeta* extractTempTableMetaFromSubquery(SQueryInfo* pUpstream) {
}
static int32_t doValidateSubquery(SSqlNode* pSqlNode, int32_t index, SSqlObj* pSql, SQueryInfo* pQueryInfo, char* msgBuf) {
SRelElementPair* subInfo = taosArrayGet(pSqlNode->from->list, index);
SRelElement* subInfo = taosArrayGet(pSqlNode->from->list, index);
// union all is not support currently
SSqlNode* p = taosArrayGetP(subInfo->pSubquery, 0);
......@@ -8890,7 +8890,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return doLocalQueryProcess(pCmd, pQueryInfo, pSqlNode);
}
if (pSqlNode->from->type == SQL_NODE_FROM_SUBQUERY) {
if (pSqlNode->from->type == SQL_FROM_NODE_SUBQUERY) {
clearAllTableMetaInfo(pQueryInfo, false, pSql->self);
pQueryInfo->numOfTables = 0;
......@@ -8898,9 +8898,9 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
int32_t numOfSub = (int32_t)taosArrayGetSize(pSqlNode->from->list);
for (int32_t i = 0; i < numOfSub; ++i) {
// check if there is 3 level select
SRelElementPair* subInfo = taosArrayGet(pSqlNode->from->list, i);
SRelElement* subInfo = taosArrayGet(pSqlNode->from->list, i);
SSqlNode* p = taosArrayGetP(subInfo->pSubquery, 0);
if (p->from->type == SQL_NODE_FROM_SUBQUERY) {
if (p->from->type == SQL_FROM_NODE_SUBQUERY) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9);
}
......@@ -9379,8 +9379,8 @@ bool hasNormalColumnFilter(SQueryInfo* pQueryInfo) {
void normalizeSqlNode(SSqlNode* pSqlNode, const char* dbName) {
assert(pSqlNode != NULL);
if (pSqlNode->from->type == SQL_NODE_FROM_TABLELIST) {
// SRelElementPair *item = taosArrayGet(pSqlNode->from->list, 0);
if (pSqlNode->from->type == SQL_FROM_NODE_TABLES) {
// SRelElement *item = taosArrayGet(pSqlNode->from->list, 0);
// item->TableName.name;
}
......
......@@ -40,8 +40,8 @@ enum SQL_NODE_TYPE {
};
enum SQL_NODE_FROM_TYPE {
SQL_NODE_FROM_SUBQUERY = 1,
SQL_NODE_FROM_TABLELIST = 2,
SQL_FROM_NODE_SUBQUERY = 1,
SQL_FROM_NODE_TABLES = 2,
};
enum SQL_EXPR_FLAG {
......@@ -113,18 +113,18 @@ typedef struct SSqlNode {
struct tSqlExpr *pHaving; // having clause [optional]
} SSqlNode;
typedef struct SRelElementPair {
typedef struct SRelElement {
union {
SStrToken tableName;
SArray *pSubquery;
};
SStrToken aliasName;
} SRelElementPair;
} SRelElement;
typedef struct SRelationInfo {
int32_t type; // nested query|table name list
SArray *list; // SArray<SRelElementPair>
SArray *list; // SArray<SRelElement>
} SRelationInfo;
typedef struct SCreatedTableInfo {
......
......@@ -556,11 +556,11 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int
SRelationInfo *setTableNameList(SRelationInfo* pRelationInfo, SStrToken *pName, SStrToken* pAlias) {
if (pRelationInfo == NULL) {
pRelationInfo = calloc(1, sizeof(SRelationInfo));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElement));
}
pRelationInfo->type = SQL_NODE_FROM_TABLELIST;
SRelElementPair p = {.tableName = *pName};
pRelationInfo->type = SQL_FROM_NODE_TABLES;
SRelElement p = {.tableName = *pName};
if (pAlias != NULL) {
p.aliasName = *pAlias;
} else {
......@@ -576,7 +576,7 @@ void* destroyRelationInfo(SRelationInfo* pRelationInfo) {
return NULL;
}
if (pRelationInfo->type == SQL_NODE_FROM_TABLELIST) {
if (pRelationInfo->type == SQL_FROM_NODE_TABLES) {
taosArrayDestroy(pRelationInfo->list);
} else {
size_t size = taosArrayGetSize(pRelationInfo->list);
......@@ -594,12 +594,12 @@ void* destroyRelationInfo(SRelationInfo* pRelationInfo) {
SRelationInfo* addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrToken* pAlias) {
if (pRelationInfo == NULL) {
pRelationInfo = calloc(1, sizeof(SRelationInfo));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElement));
}
pRelationInfo->type = SQL_NODE_FROM_SUBQUERY;
pRelationInfo->type = SQL_FROM_NODE_SUBQUERY;
SRelElementPair p = {.pSubquery = pSub};
SRelElement p = {.pSubquery = pSub};
if (pAlias != NULL) {
p.aliasName = *pAlias;
} else {
......@@ -972,6 +972,7 @@ void SqlInfoDestroy(SSqlInfo *pInfo) {
SArray* setSubclause(SArray* pList, void *pSqlNode) {
if (pList == NULL) {
pList = taosArrayInit(1, POINTER_BYTES);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册