提交 ce166fb1 编写于 作者: X Xiaoyu Wang

fix: error in data precision of super table query

上级 0418e6c0
...@@ -162,84 +162,84 @@ ...@@ -162,84 +162,84 @@
#define TK_INTERVAL 144 #define TK_INTERVAL 144
#define TK_TOPIC 145 #define TK_TOPIC 145
#define TK_AS 146 #define TK_AS 146
#define TK_CGROUP 147 #define TK_CONSUMER 147
#define TK_WITH 148 #define TK_GROUP 148
#define TK_SCHEMA 149 #define TK_WITH 149
#define TK_DESC 150 #define TK_SCHEMA 150
#define TK_DESCRIBE 151 #define TK_DESC 151
#define TK_RESET 152 #define TK_DESCRIBE 152
#define TK_QUERY 153 #define TK_RESET 153
#define TK_CACHE 154 #define TK_QUERY 154
#define TK_EXPLAIN 155 #define TK_CACHE 155
#define TK_ANALYZE 156 #define TK_EXPLAIN 156
#define TK_VERBOSE 157 #define TK_ANALYZE 157
#define TK_NK_BOOL 158 #define TK_VERBOSE 158
#define TK_RATIO 159 #define TK_NK_BOOL 159
#define TK_COMPACT 160 #define TK_RATIO 160
#define TK_VNODES 161 #define TK_COMPACT 161
#define TK_IN 162 #define TK_VNODES 162
#define TK_OUTPUTTYPE 163 #define TK_IN 163
#define TK_AGGREGATE 164 #define TK_OUTPUTTYPE 164
#define TK_BUFSIZE 165 #define TK_AGGREGATE 165
#define TK_STREAM 166 #define TK_BUFSIZE 166
#define TK_INTO 167 #define TK_STREAM 167
#define TK_TRIGGER 168 #define TK_INTO 168
#define TK_AT_ONCE 169 #define TK_TRIGGER 169
#define TK_WINDOW_CLOSE 170 #define TK_AT_ONCE 170
#define TK_WATERMARK 171 #define TK_WINDOW_CLOSE 171
#define TK_KILL 172 #define TK_WATERMARK 172
#define TK_CONNECTION 173 #define TK_KILL 173
#define TK_TRANSACTION 174 #define TK_CONNECTION 174
#define TK_MERGE 175 #define TK_TRANSACTION 175
#define TK_VGROUP 176 #define TK_MERGE 176
#define TK_REDISTRIBUTE 177 #define TK_VGROUP 177
#define TK_SPLIT 178 #define TK_REDISTRIBUTE 178
#define TK_SYNCDB 179 #define TK_SPLIT 179
#define TK_NULL 180 #define TK_SYNCDB 180
#define TK_NK_QUESTION 181 #define TK_NULL 181
#define TK_NK_ARROW 182 #define TK_NK_QUESTION 182
#define TK_ROWTS 183 #define TK_NK_ARROW 183
#define TK_TBNAME 184 #define TK_ROWTS 184
#define TK_QSTARTTS 185 #define TK_TBNAME 185
#define TK_QENDTS 186 #define TK_QSTARTTS 186
#define TK_WSTARTTS 187 #define TK_QENDTS 187
#define TK_WENDTS 188 #define TK_WSTARTTS 188
#define TK_WDURATION 189 #define TK_WENDTS 189
#define TK_CAST 190 #define TK_WDURATION 190
#define TK_NOW 191 #define TK_CAST 191
#define TK_TODAY 192 #define TK_NOW 192
#define TK_TIMEZONE 193 #define TK_TODAY 193
#define TK_COUNT 194 #define TK_TIMEZONE 194
#define TK_FIRST 195 #define TK_COUNT 195
#define TK_LAST 196 #define TK_FIRST 196
#define TK_LAST_ROW 197 #define TK_LAST 197
#define TK_BETWEEN 198 #define TK_LAST_ROW 198
#define TK_IS 199 #define TK_BETWEEN 199
#define TK_NK_LT 200 #define TK_IS 200
#define TK_NK_GT 201 #define TK_NK_LT 201
#define TK_NK_LE 202 #define TK_NK_GT 202
#define TK_NK_GE 203 #define TK_NK_LE 203
#define TK_NK_NE 204 #define TK_NK_GE 204
#define TK_MATCH 205 #define TK_NK_NE 205
#define TK_NMATCH 206 #define TK_MATCH 206
#define TK_CONTAINS 207 #define TK_NMATCH 207
#define TK_JOIN 208 #define TK_CONTAINS 208
#define TK_INNER 209 #define TK_JOIN 209
#define TK_SELECT 210 #define TK_INNER 210
#define TK_DISTINCT 211 #define TK_SELECT 211
#define TK_WHERE 212 #define TK_DISTINCT 212
#define TK_PARTITION 213 #define TK_WHERE 213
#define TK_BY 214 #define TK_PARTITION 214
#define TK_SESSION 215 #define TK_BY 215
#define TK_STATE_WINDOW 216 #define TK_SESSION 216
#define TK_SLIDING 217 #define TK_STATE_WINDOW 217
#define TK_FILL 218 #define TK_SLIDING 218
#define TK_VALUE 219 #define TK_FILL 219
#define TK_NONE 220 #define TK_VALUE 220
#define TK_PREV 221 #define TK_NONE 221
#define TK_LINEAR 222 #define TK_PREV 222
#define TK_NEXT 223 #define TK_LINEAR 223
#define TK_GROUP 224 #define TK_NEXT 224
#define TK_HAVING 225 #define TK_HAVING 225
#define TK_ORDER 226 #define TK_ORDER 226
#define TK_SLIMIT 227 #define TK_SLIMIT 227
......
...@@ -305,6 +305,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) { ...@@ -305,6 +305,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
CLONE_NODE_FIELD(pConditions); CLONE_NODE_FIELD(pConditions);
CLONE_NODE_LIST_FIELD(pChildren); CLONE_NODE_LIST_FIELD(pChildren);
COPY_SCALAR_FIELD(optimizedFlag); COPY_SCALAR_FIELD(optimizedFlag);
COPY_SCALAR_FIELD(precision);
return (SNode*)pDst; return (SNode*)pDst;
} }
......
...@@ -408,7 +408,7 @@ cmd ::= CREATE TOPIC not_exists_opt(A) ...@@ -408,7 +408,7 @@ cmd ::= CREATE TOPIC not_exists_opt(A)
cmd ::= CREATE TOPIC not_exists_opt(A) cmd ::= CREATE TOPIC not_exists_opt(A)
topic_name(B) topic_options(D) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C, D); } topic_name(B) topic_options(D) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C, D); }
cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); } cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); }
cmd ::= DROP CGROUP exists_opt(A) cgroup_name(B) ON topic_name(C). { pCxt->pRootNode = createDropCGroupStmt(pCxt, A, &B, &C); } cmd ::= DROP CONSUMER GROUP exists_opt(A) cgroup_name(B) ON topic_name(C). { pCxt->pRootNode = createDropCGroupStmt(pCxt, A, &B, &C); }
topic_options(A) ::= . { A = createTopicOptions(pCxt); } topic_options(A) ::= . { A = createTopicOptions(pCxt); }
topic_options(A) ::= topic_options(B) WITH TABLE. { ((STopicOptions*)B)->withTable = true; A = B; } topic_options(A) ::= topic_options(B) WITH TABLE. { ((STopicOptions*)B)->withTable = true; A = B; }
......
...@@ -53,7 +53,6 @@ static SKeyword keywordTable[] = { ...@@ -53,7 +53,6 @@ static SKeyword keywordTable[] = {
{"CACHE", TK_CACHE}, {"CACHE", TK_CACHE},
{"CACHELAST", TK_CACHELAST}, {"CACHELAST", TK_CACHELAST},
{"CAST", TK_CAST}, {"CAST", TK_CAST},
{"CGROUP", TK_CGROUP},
{"CLUSTER", TK_CLUSTER}, {"CLUSTER", TK_CLUSTER},
{"COLUMN", TK_COLUMN}, {"COLUMN", TK_COLUMN},
{"COMMENT", TK_COMMENT}, {"COMMENT", TK_COMMENT},
...@@ -62,6 +61,7 @@ static SKeyword keywordTable[] = { ...@@ -62,6 +61,7 @@ static SKeyword keywordTable[] = {
{"CONNS", TK_CONNS}, {"CONNS", TK_CONNS},
{"CONNECTION", TK_CONNECTION}, {"CONNECTION", TK_CONNECTION},
{"CONNECTIONS", TK_CONNECTIONS}, {"CONNECTIONS", TK_CONNECTIONS},
{"CONSUMER", TK_CONSUMER},
{"COUNT", TK_COUNT}, {"COUNT", TK_COUNT},
{"CREATE", TK_CREATE}, {"CREATE", TK_CREATE},
{"DATABASE", TK_DATABASE}, {"DATABASE", TK_DATABASE},
......
...@@ -465,20 +465,22 @@ static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) { ...@@ -465,20 +465,22 @@ static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) {
return isPrimaryKeyImpl(pTable, pExpr); return isPrimaryKeyImpl(pTable, pExpr);
} }
static bool findAndSetColumn(SColumnNode** pColRef, const STableNode* pTable) { static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef, const STableNode* pTable,
bool* pFound) {
SColumnNode* pCol = *pColRef; SColumnNode* pCol = *pColRef;
bool found = false; *pFound = false;
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta; const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta;
if (isInternalPrimaryKey(pCol)) { if (isInternalPrimaryKey(pCol)) {
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema, false, pCol); setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema, false, pCol);
return true; *pFound = true;
return TSDB_CODE_SUCCESS;
} }
int32_t nums = pMeta->tableInfo.numOfTags + pMeta->tableInfo.numOfColumns; int32_t nums = pMeta->tableInfo.numOfTags + pMeta->tableInfo.numOfColumns;
for (int32_t i = 0; i < nums; ++i) { for (int32_t i = 0; i < nums; ++i) {
if (0 == strcmp(pCol->colName, pMeta->schema[i].name)) { if (0 == strcmp(pCol->colName, pMeta->schema[i].name)) {
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema + i, (i >= pMeta->tableInfo.numOfColumns), pCol); setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema + i, (i >= pMeta->tableInfo.numOfColumns), pCol);
found = true; *pFound = true;
break; break;
} }
} }
...@@ -489,13 +491,15 @@ static bool findAndSetColumn(SColumnNode** pColRef, const STableNode* pTable) { ...@@ -489,13 +491,15 @@ static bool findAndSetColumn(SColumnNode** pColRef, const STableNode* pTable) {
SExprNode* pExpr = (SExprNode*)pNode; SExprNode* pExpr = (SExprNode*)pNode;
if (0 == strcmp(pCol->colName, pExpr->aliasName) || if (0 == strcmp(pCol->colName, pExpr->aliasName) ||
(isPrimaryKey((STempTableNode*)pTable, pNode) && isInternalPrimaryKey(pCol))) { (isPrimaryKey((STempTableNode*)pTable, pNode) && isInternalPrimaryKey(pCol))) {
if (*pFound) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pCol->colName);
}
setColumnInfoByExpr(pTable, pExpr, pColRef); setColumnInfoByExpr(pTable, pExpr, pColRef);
found = true; *pFound = true;
break;
} }
} }
} }
return found; return TSDB_CODE_SUCCESS;
} }
static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode** pCol) { static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode** pCol) {
...@@ -506,7 +510,12 @@ static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode** ...@@ -506,7 +510,12 @@ static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode**
STableNode* pTable = taosArrayGetP(pTables, i); STableNode* pTable = taosArrayGetP(pTables, i);
if (belongTable(pCxt->pParseCxt->db, (*pCol), pTable)) { if (belongTable(pCxt->pParseCxt->db, (*pCol), pTable)) {
foundTable = true; foundTable = true;
if (findAndSetColumn(pCol, pTable)) { bool foundCol = false;
pCxt->errCode = findAndSetColumn(pCxt, pCol, pTable, &foundCol);
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
return DEAL_RES_ERROR;
}
if (foundCol) {
break; break;
} }
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName); return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
...@@ -525,14 +534,19 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod ...@@ -525,14 +534,19 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
bool isInternalPk = isInternalPrimaryKey(*pCol); bool isInternalPk = isInternalPrimaryKey(*pCol);
for (size_t i = 0; i < nums; ++i) { for (size_t i = 0; i < nums; ++i) {
STableNode* pTable = taosArrayGetP(pTables, i); STableNode* pTable = taosArrayGetP(pTables, i);
if (findAndSetColumn(pCol, pTable)) { bool foundCol = false;
pCxt->errCode = findAndSetColumn(pCxt, pCol, pTable, &foundCol);
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
return DEAL_RES_ERROR;
}
if (foundCol) {
if (found) { if (found) {
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, (*pCol)->colName); return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, (*pCol)->colName);
} }
found = true; found = true;
if (isInternalPk) { }
break; if (isInternalPk) {
} break;
} }
} }
if (!found) { if (!found) {
...@@ -1939,7 +1953,9 @@ static int32_t createPrimaryKeyColByTable(STranslateContext* pCxt, STableNode* p ...@@ -1939,7 +1953,9 @@ static int32_t createPrimaryKeyColByTable(STranslateContext* pCxt, STableNode* p
} }
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID; pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
strcpy(pCol->colName, PK_TS_COL_INTERNAL_NAME); strcpy(pCol->colName, PK_TS_COL_INTERNAL_NAME);
if (!findAndSetColumn(&pCol, pTable)) { bool found = false;
int32_t code = findAndSetColumn(pCxt, &pCol, pTable, &found);
if (TSDB_CODE_SUCCESS != code || !found) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TIMELINE_FUNC); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TIMELINE_FUNC);
} }
*pPrimaryKey = (SNode*)pCol; *pPrimaryKey = (SNode*)pCol;
......
此差异已折叠。
...@@ -32,7 +32,7 @@ TEST_F(ParserInitialDTest, dropBnode) { ...@@ -32,7 +32,7 @@ TEST_F(ParserInitialDTest, dropBnode) {
run("DROP BNODE ON DNODE 1"); run("DROP BNODE ON DNODE 1");
} }
// DROP CGROUP [ IF EXISTS ] cgroup_name ON topic_name // DROP CONSUMER GROUP [ IF EXISTS ] cgroup_name ON topic_name
TEST_F(ParserInitialDTest, dropCGroup) { TEST_F(ParserInitialDTest, dropCGroup) {
useDb("root", "test"); useDb("root", "test");
...@@ -56,10 +56,10 @@ TEST_F(ParserInitialDTest, dropCGroup) { ...@@ -56,10 +56,10 @@ TEST_F(ParserInitialDTest, dropCGroup) {
}); });
setDropCgroupReqFunc("tp1", "cg1"); setDropCgroupReqFunc("tp1", "cg1");
run("DROP CGROUP cg1 ON tp1"); run("DROP CONSUMER GROUP cg1 ON tp1");
setDropCgroupReqFunc("tp1", "cg1", 1); setDropCgroupReqFunc("tp1", "cg1", 1);
run("DROP CGROUP IF EXISTS cg1 ON tp1"); run("DROP CONSUMER GROUP IF EXISTS cg1 ON tp1");
} }
// todo drop database // todo drop database
......
...@@ -252,6 +252,8 @@ TEST_F(ParserSelectTest, semanticError) { ...@@ -252,6 +252,8 @@ TEST_F(ParserSelectTest, semanticError) {
// TSDB_CODE_PAR_AMBIGUOUS_COLUMN // TSDB_CODE_PAR_AMBIGUOUS_COLUMN
run("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE); run("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE);
run("SELECT c2 FROM (SELECT c1 c2, c2 FROM t1)", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE);
// TSDB_CODE_PAR_WRONG_VALUE_TYPE // TSDB_CODE_PAR_WRONG_VALUE_TYPE
run("SELECT timestamp '2010a' FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); run("SELECT timestamp '2010a' FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE);
......
...@@ -124,6 +124,7 @@ static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelec ...@@ -124,6 +124,7 @@ static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelec
SLogicNode* pNode = NULL; SLogicNode* pNode = NULL;
int32_t code = func(pCxt, pSelect, &pNode); int32_t code = func(pCxt, pSelect, &pNode);
if (TSDB_CODE_SUCCESS == code && NULL != pNode) { if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
pNode->precision = pSelect->precision;
code = pushLogicNode(pCxt, pRoot, pNode); code = pushLogicNode(pCxt, pRoot, pNode);
} }
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
...@@ -400,6 +401,7 @@ static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSel ...@@ -400,6 +401,7 @@ static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSel
nodesDestroyNode(pNode); nodesDestroyNode(pNode);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
pNode->precision = pSelect->precision;
*pLogicNode = pNode; *pLogicNode = pNode;
} }
return code; return code;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册