enhance: move bi to enterprise
This commit is contained in:
parent
6134c90398
commit
72307ab877
|
@ -1,4 +1,7 @@
|
||||||
aux_source_directory(src PARSER_SRC)
|
aux_source_directory(src PARSER_SRC)
|
||||||
|
IF (TD_BI_SUPPORT)
|
||||||
|
LIST(APPEND PARSER_SRC ${TD_ENTERPRISE_DIR}/src/plugins/bi/src/biRewriteQuery.c)
|
||||||
|
ENDIF ()
|
||||||
add_library(parser STATIC ${PARSER_SRC})
|
add_library(parser STATIC ${PARSER_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
parser
|
parser
|
||||||
|
|
|
@ -36,7 +36,6 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS
|
||||||
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery);
|
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery);
|
||||||
int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, void** pResRow);
|
int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, void** pResRow);
|
||||||
int32_t translatePostCreateSmaIndex(SParseContext* pParseCxt, SQuery* pQuery, void** pResRow);
|
int32_t translatePostCreateSmaIndex(SParseContext* pParseCxt, SQuery* pQuery, void** pResRow);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TD_PARSER_TRANS_H_
|
||||||
|
#define _TD_PARSER_TRANS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "parToken.h"
|
||||||
|
#include "parUtil.h"
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
typedef struct STranslateContext {
|
||||||
|
SParseContext* pParseCxt;
|
||||||
|
int32_t errCode;
|
||||||
|
SMsgBuf msgBuf;
|
||||||
|
SArray* pNsLevel; // element is SArray*, the element of this subarray is STableNode*
|
||||||
|
int32_t currLevel;
|
||||||
|
int32_t levelNo;
|
||||||
|
ESqlClause currClause;
|
||||||
|
SNode* pCurrStmt;
|
||||||
|
SCmdMsgInfo* pCmdMsg;
|
||||||
|
SHashObj* pDbs;
|
||||||
|
SHashObj* pTables;
|
||||||
|
SHashObj* pTargetTables;
|
||||||
|
SExplainOptions* pExplainOpt;
|
||||||
|
SParseMetaCache* pMetaCache;
|
||||||
|
bool createStream;
|
||||||
|
bool stableQuery;
|
||||||
|
bool showRewrite;
|
||||||
|
SNode* pPrevRoot;
|
||||||
|
SNode* pPostRoot;
|
||||||
|
} STranslateContext;
|
||||||
|
|
||||||
|
int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_PARSER_TRANS_H_*/
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "parInt.h"
|
#include "parInt.h"
|
||||||
|
#include "parTranslater.h"
|
||||||
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
#include "cmdnodes.h"
|
#include "cmdnodes.h"
|
||||||
|
@ -35,28 +36,6 @@ typedef struct SRewriteTbNameContext {
|
||||||
char* pTbName;
|
char* pTbName;
|
||||||
} SRewriteTbNameContext;
|
} SRewriteTbNameContext;
|
||||||
|
|
||||||
typedef struct STranslateContext {
|
|
||||||
SParseContext* pParseCxt;
|
|
||||||
int32_t errCode;
|
|
||||||
SMsgBuf msgBuf;
|
|
||||||
SArray* pNsLevel; // element is SArray*, the element of this subarray is STableNode*
|
|
||||||
int32_t currLevel;
|
|
||||||
int32_t levelNo;
|
|
||||||
ESqlClause currClause;
|
|
||||||
SNode* pCurrStmt;
|
|
||||||
SCmdMsgInfo* pCmdMsg;
|
|
||||||
SHashObj* pDbs;
|
|
||||||
SHashObj* pTables;
|
|
||||||
SHashObj* pTargetTables;
|
|
||||||
SExplainOptions* pExplainOpt;
|
|
||||||
SParseMetaCache* pMetaCache;
|
|
||||||
bool createStream;
|
|
||||||
bool stableQuery;
|
|
||||||
bool showRewrite;
|
|
||||||
SNode* pPrevRoot;
|
|
||||||
SNode* pPostRoot;
|
|
||||||
} STranslateContext;
|
|
||||||
|
|
||||||
typedef struct SBuildTopicContext {
|
typedef struct SBuildTopicContext {
|
||||||
bool colExists;
|
bool colExists;
|
||||||
bool colNotFound;
|
bool colNotFound;
|
||||||
|
@ -3022,107 +3001,13 @@ static int32_t createTags(STranslateContext* pCxt, SNodeList** pOutput) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void biMakeAliasNameInMD5(char* pExprStr, int32_t len, char* pAlias) {
|
|
||||||
T_MD5_CTX ctx;
|
|
||||||
tMD5Init(&ctx);
|
|
||||||
tMD5Update(&ctx, pExprStr, len);
|
|
||||||
tMD5Final(&ctx);
|
|
||||||
char* p = pAlias;
|
|
||||||
for (uint8_t i = 0; i < tListLen(ctx.digest); ++i) {
|
|
||||||
sprintf(p, "%02x", ctx.digest[i]);
|
|
||||||
p += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static SNode* biMakeTbnameProjectAstNode(char* funcName, char* tableAlias) {
|
|
||||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
|
||||||
val->literal = strdup(tableAlias);
|
|
||||||
val->node.resType.type = TSDB_DATA_TYPE_BINARY;
|
|
||||||
val->node.resType.bytes = strlen(val->literal);
|
|
||||||
val->isDuration = false;
|
|
||||||
val->translate = false;
|
|
||||||
|
|
||||||
SNodeList* paramList = nodesMakeList();
|
|
||||||
nodesListAppend(paramList, (SNode*)val);
|
|
||||||
|
|
||||||
SFunctionNode* tbNameFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
|
||||||
strncpy(tbNameFunc->functionName, "tbname", strlen("tbname"));
|
|
||||||
nodesListMakeAppend(&tbNameFunc->pParameterList, (SNode*)val);
|
|
||||||
|
|
||||||
snprintf(tbNameFunc->node.userAlias, sizeof(tbNameFunc->node.userAlias), "%s.tbname", tableAlias);
|
|
||||||
biMakeAliasNameInMD5(tbNameFunc->node.userAlias, strlen(tbNameFunc->node.userAlias), tbNameFunc->node.aliasName);
|
|
||||||
if (funcName == NULL) {
|
|
||||||
return (SNode*)tbNameFunc;
|
|
||||||
} else {
|
|
||||||
SFunctionNode* multiResFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
|
||||||
strncpy(multiResFunc->functionName, funcName, strlen(funcName));
|
|
||||||
nodesListMakeAppend(&multiResFunc->pParameterList, (SNode*)tbNameFunc);
|
|
||||||
|
|
||||||
snprintf(multiResFunc->node.userAlias, sizeof(multiResFunc->node.userAlias), "%s(%s.tbname)", funcName, tableAlias);
|
|
||||||
biMakeAliasNameInMD5(multiResFunc->node.userAlias, strlen(multiResFunc->node.userAlias), multiResFunc->node.aliasName);
|
|
||||||
return (SNode*)multiResFunc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t biRewriteSelectFuncParamStar(STranslateContext* pCxt, SSelectStmt* pSelect, SNode* pNode, SListCell* pSelectListCell) {
|
|
||||||
SNodeList* pTbnameNodeList = nodesMakeList();
|
|
||||||
|
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
|
||||||
if (strcasecmp(pFunc->functionName, "last") == 0 ||
|
|
||||||
strcasecmp(pFunc->functionName, "last_row") == 0 ||
|
|
||||||
strcasecmp(pFunc->functionName, "first") == 0) {
|
|
||||||
SNodeList* pParams = pFunc->pParameterList;
|
|
||||||
SNode* pPara = NULL;
|
|
||||||
FOREACH(pPara, pParams) {
|
|
||||||
if (isStar(pPara)) {
|
|
||||||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
|
||||||
size_t n = taosArrayGetSize(pTables);
|
|
||||||
for (int32_t i = 0; i < n; ++i) {
|
|
||||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectAstNode(pFunc->functionName, pTable->tableAlias);
|
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
|
||||||
}
|
|
||||||
nodesListInsertListAfterPos(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList);
|
|
||||||
} else if (isTableStar(pPara)) {
|
|
||||||
char* pTableAlias = ((SColumnNode*)pPara)->tableAlias;
|
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectAstNode(pFunc->functionName, pTableAlias);
|
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
|
||||||
nodesListInsertListAfterPos(pSelect->pProjectionList, pSelectListCell, pTbnameNodeList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// after translate from
|
|
||||||
// before translate select list
|
|
||||||
static int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|
||||||
SNode* pNode = NULL;
|
|
||||||
SNodeList* pTbnameNodeList = nodesMakeList();
|
|
||||||
WHERE_EACH(pNode, pSelect->pProjectionList) {
|
|
||||||
if (isStar(pNode)) {
|
|
||||||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
|
||||||
size_t n = taosArrayGetSize(pTables);
|
|
||||||
for (int32_t i = 0; i < n; ++i) {
|
|
||||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectAstNode(NULL, pTable->tableAlias);
|
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
|
||||||
}
|
|
||||||
nodesListInsertListAfterPos(pSelect->pProjectionList, cell, pTbnameNodeList);
|
|
||||||
} else if (isTableStar(pNode)) {
|
|
||||||
char* pTableAlias = ((SColumnNode*)pNode)->tableAlias;
|
|
||||||
SNode* pTbnameNode = biMakeTbnameProjectAstNode(NULL, pTableAlias);
|
|
||||||
nodesListAppend(pTbnameNodeList, pTbnameNode);
|
|
||||||
nodesListInsertListAfterPos(pSelect->pProjectionList, cell, pTbnameNodeList);
|
|
||||||
} else if (nodeType(pNode) == QUERY_NODE_FUNCTION) {
|
|
||||||
biRewriteSelectFuncParamStar(pCxt, pSelect, pNode, cell);
|
|
||||||
}
|
|
||||||
WHERE_NEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#ifndef TD_BI_SUPPORT
|
||||||
|
int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
SNode* pNode = NULL;
|
SNode* pNode = NULL;
|
||||||
WHERE_EACH(pNode, pSelect->pProjectionList) {
|
WHERE_EACH(pNode, pSelect->pProjectionList) {
|
||||||
|
|
|
@ -1011,7 +1011,7 @@
|
||||||
,,y,script,./test.sh -f tsim/query/partitionby.sim
|
,,y,script,./test.sh -f tsim/query/partitionby.sim
|
||||||
,,y,script,./test.sh -f tsim/query/tableCount.sim
|
,,y,script,./test.sh -f tsim/query/tableCount.sim
|
||||||
,,y,script,./test.sh -f tsim/query/show_db_table_kind.sim
|
,,y,script,./test.sh -f tsim/query/show_db_table_kind.sim
|
||||||
,,y,script,./test.sh -f tsim/query/bi_star_tbname.sim
|
#,,y,script,./test.sh -f tsim/query/bi_star_tbname.sim
|
||||||
,,y,script,./test.sh -f tsim/query/tag_scan.sim
|
,,y,script,./test.sh -f tsim/query/tag_scan.sim
|
||||||
,,y,script,./test.sh -f tsim/query/nullColSma.sim
|
,,y,script,./test.sh -f tsim/query/nullColSma.sim
|
||||||
,,y,script,./test.sh -f tsim/query/bug3398.sim
|
,,y,script,./test.sh -f tsim/query/bug3398.sim
|
||||||
|
|
Loading…
Reference in New Issue