提交 8880e515 编写于 作者: H Haojun Liao

[td-3949]

上级 f28e7b4e
...@@ -6689,8 +6689,8 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -6689,8 +6689,8 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
} }
STableNamePair* p1 = taosArrayGet(pFromInfo->list, 0); SRelElementPair* p1 = taosArrayGet(pFromInfo->list, 0);
SStrToken srcToken = {.z = p1->name.z, .n = p1->name.n, .type = TK_STRING}; SStrToken srcToken = {.z = p1->tableName.z, .n = p1->tableName.n, .type = TK_STRING};
if (tscValidateName(&srcToken) != TSDB_CODE_SUCCESS) { if (tscValidateName(&srcToken) != TSDB_CODE_SUCCESS) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
...@@ -7085,8 +7085,8 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod ...@@ -7085,8 +7085,8 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
tscAddEmptyMetaInfo(pQueryInfo); tscAddEmptyMetaInfo(pQueryInfo);
} }
STableNamePair *item = taosArrayGet(pSqlNode->from->list, i); SRelElementPair *item = taosArrayGet(pSqlNode->from->list, i);
SStrToken *oriName = &item->name; SStrToken *oriName = &item->tableName;
if (oriName->type == TK_INTEGER || oriName->type == TK_FLOAT) { if (oriName->type == TK_INTEGER || oriName->type == TK_FLOAT) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
...@@ -7284,10 +7284,9 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf ...@@ -7284,10 +7284,9 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
pQueryInfo->window.skey = pQueryInfo->window.skey / 1000; pQueryInfo->window.skey = pQueryInfo->window.skey / 1000;
pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000; pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000;
} }
} else { // set the time rang } else {
if (taosArrayGetSize(pSqlNode->from->list) > 1) { if (taosArrayGetSize(pSqlNode->from->list) > 1) { // Cross join not allowed yet
// If it is a join query, no where clause is not allowed. return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "cross join not supported yet");
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "condition missing for join query ");
} }
} }
......
...@@ -107,14 +107,19 @@ typedef struct SSqlNode { ...@@ -107,14 +107,19 @@ typedef struct SSqlNode {
struct tSqlExpr *pHaving; // having clause [optional] struct tSqlExpr *pHaving; // having clause [optional]
} SSqlNode; } SSqlNode;
typedef struct STableNamePair { typedef struct SRelElementPair {
SStrToken name; union {
SStrToken tableName;
SArray *pSubquery;
//SSqlNode *pSubquery;
};
SStrToken aliasName; SStrToken aliasName;
} STableNamePair; } SRelElementPair;
typedef struct SRelationInfo { typedef struct SRelationInfo {
int32_t type; // nested query|table name list int32_t type; // nested query|table name list
SArray *list; // SArray<STableNamePair>|SArray<SSqlNode*> SArray *list; // SArray<SRelElementPair>|SArray<SSqlNode*>
} SRelationInfo; } SRelationInfo;
typedef struct SCreatedTableInfo { typedef struct SCreatedTableInfo {
...@@ -254,8 +259,9 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int ...@@ -254,8 +259,9 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder); SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
SRelationInfo *setTableNameList(SRelationInfo* pFromInfo, SStrToken *pName, SStrToken* pAlias); SRelationInfo *setTableNameList(SRelationInfo* pFromInfo, SStrToken *pName, SStrToken* pAlias);
SRelationInfo *setSubquery(SRelationInfo* pFromInfo, SArray* pSqlNode); //SRelationInfo *setSubquery(SRelationInfo* pFromInfo, SRelElementPair* p);
void *destroyRelationInfo(SRelationInfo* pFromInfo); void *destroyRelationInfo(SRelationInfo* pFromInfo);
SRelationInfo *addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrToken* pAlias);
// sql expr leaf node // sql expr leaf node
tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType); tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType);
......
...@@ -508,7 +508,13 @@ distinct(X) ::= . { X.n = 0;} ...@@ -508,7 +508,13 @@ distinct(X) ::= . { X.n = 0;}
%type from {SRelationInfo*} %type from {SRelationInfo*}
%destructor from {destroyRelationInfo($$);} %destructor from {destroyRelationInfo($$);}
from(A) ::= FROM tablelist(X). {A = X;} from(A) ::= FROM tablelist(X). {A = X;}
from(A) ::= FROM LP union(Y) RP. {A = setSubquery(NULL, Y);} from(A) ::= FROM sub(X). {A = X;}
%type sub {SRelationInfo*}
%destructor sub {destroyRelationInfo($$);}
sub(A) ::= LP union(Y) RP. {A = addSubqueryElem(NULL, Y, NULL);}
sub(A) ::= LP union(Y) RP ids(Z). {A = addSubqueryElem(NULL, Y, &Z);}
sub(A) ::= sub(X) COMMA LP union(Y) RP ids(Z).{A = addSubqueryElem(X, Y, &Z);}
%type tablelist {SRelationInfo*} %type tablelist {SRelationInfo*}
%destructor tablelist {destroyRelationInfo($$);} %destructor tablelist {destroyRelationInfo($$);}
......
...@@ -535,11 +535,11 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int ...@@ -535,11 +535,11 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int
SRelationInfo *setTableNameList(SRelationInfo* pRelationInfo, SStrToken *pName, SStrToken* pAlias) { SRelationInfo *setTableNameList(SRelationInfo* pRelationInfo, SStrToken *pName, SStrToken* pAlias) {
if (pRelationInfo == NULL) { if (pRelationInfo == NULL) {
pRelationInfo = calloc(1, sizeof(SRelationInfo)); pRelationInfo = calloc(1, sizeof(SRelationInfo));
pRelationInfo->list = taosArrayInit(4, sizeof(STableNamePair)); pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair));
} }
pRelationInfo->type = SQL_NODE_FROM_TABLELIST; pRelationInfo->type = SQL_NODE_FROM_TABLELIST;
STableNamePair p = {.name = *pName}; SRelElementPair p = {.tableName = *pName};
if (pAlias != NULL) { if (pAlias != NULL) {
p.aliasName = *pAlias; p.aliasName = *pAlias;
} else { } else {
...@@ -550,17 +550,41 @@ SRelationInfo *setTableNameList(SRelationInfo* pRelationInfo, SStrToken *pName, ...@@ -550,17 +550,41 @@ SRelationInfo *setTableNameList(SRelationInfo* pRelationInfo, SStrToken *pName,
return pRelationInfo; return pRelationInfo;
} }
SRelationInfo* setSubquery(SRelationInfo* pRelationInfo, SArray* pList) { //SRelationInfo* setSubquery(SRelationInfo* pRelationInfo, SArray* pList, SStrToken* pAlias) {
if (pRelationInfo == NULL) { // if (pRelationInfo == NULL) {
pRelationInfo = calloc(1, sizeof(SRelationInfo)); // pRelationInfo = calloc(1, sizeof(SRelationInfo));
pRelationInfo->list = taosArrayInit(4, POINTER_BYTES); // pRelationInfo->list = taosArrayInit(4, POINTER_BYTES);
} // }
//
pRelationInfo->type = SQL_NODE_FROM_SUBQUERY; // pRelationInfo->type = SQL_NODE_FROM_SUBQUERY;
taosArrayPush(pRelationInfo->list, &pList); // SRelElementPair p = {.pSubquery = pList};
// if (pAlias != NULL) {
return pRelationInfo; // p.aliasName = *pAlias;
} // } else {
// TPARSER_SET_NONE_TOKEN(p.aliasName);
// }
//
// taosArrayPush(pRelationInfo->list, &p);
// return pRelationInfo;
//}
//SRelationInfo* setSubquery(SRelationInfo* pRelationInfo, SRelElementPair* p) {
// if (pRelationInfo == NULL) {
// pRelationInfo = calloc(1, sizeof(SRelationInfo));
// pRelationInfo->list = taosArrayInit(4, POINTER_BYTES);
// }
//
// pRelationInfo->type = SQL_NODE_FROM_SUBQUERY;
// SRelElementPair elem = *p;
//// if (pAlias != NULL) {
//// p.aliasName = *pAlias;
//// } else {
//// TPARSER_SET_NONE_TOKEN(p.aliasName);
//// }
//
// taosArrayPush(pRelationInfo->list, &p);
// return pRelationInfo;
//}
void* destroyRelationInfo(SRelationInfo* pRelationInfo) { void* destroyRelationInfo(SRelationInfo* pRelationInfo) {
if (pRelationInfo == NULL) { if (pRelationInfo == NULL) {
...@@ -582,6 +606,25 @@ void* destroyRelationInfo(SRelationInfo* pRelationInfo) { ...@@ -582,6 +606,25 @@ void* destroyRelationInfo(SRelationInfo* pRelationInfo) {
return NULL; return NULL;
} }
SRelationInfo* addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrToken* pAlias) {
if (pRelationInfo == NULL) {
pRelationInfo = calloc(1, sizeof(SRelationInfo));
pRelationInfo->list = taosArrayInit(4, sizeof(SRelElementPair));
}
pRelationInfo->type = SQL_NODE_FROM_SUBQUERY;
SRelElementPair p = {.pSubquery = pSub};
if (pAlias != NULL) {
p.aliasName = *pAlias;
} else {
TPARSER_SET_NONE_TOKEN(p.aliasName);
}
taosArrayPush(pRelationInfo->list, &p);
return pRelationInfo;
}
void tSetDbName(SStrToken *pCpxName, SStrToken *pDb) { void tSetDbName(SStrToken *pCpxName, SStrToken *pDb) {
pCpxName->type = pDb->type; pCpxName->type = pDb->type;
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册