fix other platform error
This commit is contained in:
parent
cd9fcb37b8
commit
51fa1d40a4
|
@ -7800,7 +7800,7 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS
|
||||||
int32_t colSize = taosArrayGetSize(pReq->pCols);
|
int32_t colSize = taosArrayGetSize(pReq->pCols);
|
||||||
if (tEncodeI32(&encoder, colSize) < 0) return -1;
|
if (tEncodeI32(&encoder, colSize) < 0) return -1;
|
||||||
for (int32_t i = 0; i < colSize; ++i) {
|
for (int32_t i = 0; i < colSize; ++i) {
|
||||||
SField *pField = taosArrayGet(pReq->pCols, i);
|
SFieldWithOptions *pField = taosArrayGet(pReq->pCols, i);
|
||||||
if (tEncodeI8(&encoder, pField->type) < 0) return -1;
|
if (tEncodeI8(&encoder, pField->type) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
|
if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||||
|
|
|
@ -58,18 +58,17 @@ typedef struct SSysTableShowAdapter {
|
||||||
} SSysTableShowAdapter;
|
} SSysTableShowAdapter;
|
||||||
|
|
||||||
typedef struct SCollectJoinCondsContext {
|
typedef struct SCollectJoinCondsContext {
|
||||||
bool inOp;
|
bool inOp;
|
||||||
|
|
||||||
int32_t primCondNum;
|
int32_t primCondNum;
|
||||||
int32_t logicAndNum;
|
int32_t logicAndNum;
|
||||||
int32_t logicOrNum;
|
int32_t logicOrNum;
|
||||||
int32_t eqCondNum;
|
int32_t eqCondNum;
|
||||||
int32_t neqCondNum;
|
int32_t neqCondNum;
|
||||||
bool primDisorder;
|
bool primDisorder;
|
||||||
int32_t code;
|
int32_t code;
|
||||||
} SCollectJoinCondsContext;
|
} SCollectJoinCondsContext;
|
||||||
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
||||||
{
|
{
|
||||||
|
@ -323,7 +322,8 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery);
|
||||||
static int32_t setRefreshMeta(STranslateContext* pCxt, SQuery* pQuery);
|
static int32_t setRefreshMeta(STranslateContext* pCxt, SQuery* pQuery);
|
||||||
|
|
||||||
static bool isWindowJoinStmt(SSelectStmt* pSelect) {
|
static bool isWindowJoinStmt(SSelectStmt* pSelect) {
|
||||||
return (QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable)) && IS_WINDOW_JOIN(((SJoinTableNode*)pSelect->pFromTable)->subType);
|
return (QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable)) &&
|
||||||
|
IS_WINDOW_JOIN(((SJoinTableNode*)pSelect->pFromTable)->subType);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t replacePsedudoColumnFuncWithColumn(STranslateContext* pCxt, SNode** ppNode);
|
static int32_t replacePsedudoColumnFuncWithColumn(STranslateContext* pCxt, SNode** ppNode);
|
||||||
|
@ -725,12 +725,12 @@ static int32_t initTranslateContext(SParseContext* pParseCxt, SParseMetaCache* p
|
||||||
|
|
||||||
static int32_t resetHighLevelTranslateNamespace(STranslateContext* pCxt) {
|
static int32_t resetHighLevelTranslateNamespace(STranslateContext* pCxt) {
|
||||||
if (NULL != pCxt->pNsLevel) {
|
if (NULL != pCxt->pNsLevel) {
|
||||||
size_t size = taosArrayGetSize(pCxt->pNsLevel);
|
size_t size = taosArrayGetSize(pCxt->pNsLevel);
|
||||||
int32_t levelNum = size - pCxt->currLevel;
|
int32_t levelNum = size - pCxt->currLevel;
|
||||||
if (levelNum <= 0) {
|
if (levelNum <= 0) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = size - 1; i >= pCxt->currLevel; --i) {
|
for (int32_t i = size - 1; i >= pCxt->currLevel; --i) {
|
||||||
taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i));
|
taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i));
|
||||||
}
|
}
|
||||||
|
@ -937,7 +937,6 @@ static bool isCurGlobalTimeLineQuery(SNode* pStmt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool isBlockTimeLineAlignedQuery(SNode* pStmt) {
|
static bool isBlockTimeLineAlignedQuery(SNode* pStmt) {
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
||||||
if (!isBlockTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
if (!isBlockTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
||||||
|
@ -953,7 +952,6 @@ static bool isBlockTimeLineAlignedQuery(SNode* pStmt) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool isTimeLineAlignedQuery(SNode* pStmt) {
|
static bool isTimeLineAlignedQuery(SNode* pStmt) {
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
||||||
if (!isTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
if (!isTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
||||||
|
@ -1058,8 +1056,8 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum
|
||||||
pCol->colId = pCol->isPrimTs ? PRIMARYKEY_TIMESTAMP_COL_ID : 0;
|
pCol->colId = pCol->isPrimTs ? PRIMARYKEY_TIMESTAMP_COL_ID : 0;
|
||||||
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||||
pCol->colType = ((SColumnNode*)pExpr)->colType;
|
pCol->colType = ((SColumnNode*)pExpr)->colType;
|
||||||
//strcpy(pCol->dbName, ((SColumnNode*)pExpr)->dbName);
|
// strcpy(pCol->dbName, ((SColumnNode*)pExpr)->dbName);
|
||||||
//strcpy(pCol->tableName, ((SColumnNode*)pExpr)->tableName);
|
// strcpy(pCol->tableName, ((SColumnNode*)pExpr)->tableName);
|
||||||
}
|
}
|
||||||
strcpy(pCol->colName, pExpr->aliasName);
|
strcpy(pCol->colName, pExpr->aliasName);
|
||||||
if ('\0' == pCol->node.aliasName[0]) {
|
if ('\0' == pCol->node.aliasName[0]) {
|
||||||
|
@ -1075,12 +1073,11 @@ static void setColumnPrimTs(STranslateContext* pCxt, SColumnNode* pCol, const ST
|
||||||
if (PRIMARYKEY_TIMESTAMP_COL_ID != pCol->colId) {
|
if (PRIMARYKEY_TIMESTAMP_COL_ID != pCol->colId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool joinQuery = false;
|
bool joinQuery = false;
|
||||||
SJoinTableNode* pJoinTable = NULL;
|
SJoinTableNode* pJoinTable = NULL;
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pCxt->pCurrStmt) &&
|
if (QUERY_NODE_SELECT_STMT == nodeType(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable &&
|
||||||
NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable &&
|
QUERY_NODE_JOIN_TABLE == nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
||||||
QUERY_NODE_JOIN_TABLE == nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
|
||||||
joinQuery = true;
|
joinQuery = true;
|
||||||
pJoinTable = (SJoinTableNode*)((SSelectStmt*)pCxt->pCurrStmt)->pFromTable;
|
pJoinTable = (SJoinTableNode*)((SSelectStmt*)pCxt->pCurrStmt)->pFromTable;
|
||||||
}
|
}
|
||||||
|
@ -1090,18 +1087,20 @@ static void setColumnPrimTs(STranslateContext* pCxt, SColumnNode* pCol, const ST
|
||||||
if (!joinQuery) {
|
if (!joinQuery) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (pJoinTable->joinType) {
|
switch (pJoinTable->joinType) {
|
||||||
case JOIN_TYPE_INNER:
|
case JOIN_TYPE_INNER:
|
||||||
pCol->isPrimTs = true;
|
pCol->isPrimTs = true;
|
||||||
break;
|
break;
|
||||||
case JOIN_TYPE_LEFT:
|
case JOIN_TYPE_LEFT:
|
||||||
if (!IS_SEMI_JOIN(pJoinTable->subType) && 0 != strcmp(pTable->tableAlias, ((STableNode*)pJoinTable->pLeft)->tableAlias)) {
|
if (!IS_SEMI_JOIN(pJoinTable->subType) &&
|
||||||
|
0 != strcmp(pTable->tableAlias, ((STableNode*)pJoinTable->pLeft)->tableAlias)) {
|
||||||
pCol->isPrimTs = false;
|
pCol->isPrimTs = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case JOIN_TYPE_RIGHT:
|
case JOIN_TYPE_RIGHT:
|
||||||
if (!IS_SEMI_JOIN(pJoinTable->subType) && 0 != strcmp(pTable->tableAlias, ((STableNode*)pJoinTable->pRight)->tableAlias)) {
|
if (!IS_SEMI_JOIN(pJoinTable->subType) &&
|
||||||
|
0 != strcmp(pTable->tableAlias, ((STableNode*)pJoinTable->pRight)->tableAlias)) {
|
||||||
pCol->isPrimTs = false;
|
pCol->isPrimTs = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1111,7 +1110,6 @@ static void setColumnPrimTs(STranslateContext* pCxt, SColumnNode* pCol, const ST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* pTable, bool igTags, SNodeList* pList) {
|
static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* pTable, bool igTags, SNodeList* pList) {
|
||||||
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;
|
||||||
|
@ -1152,18 +1150,15 @@ static bool isInternalPrimaryKey(const SColumnNode* pCol) {
|
||||||
(0 == strcmp(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME) || 0 == strcmp(pCol->colName, C0_PSEUDO_COLUMN_NAME));
|
(0 == strcmp(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME) || 0 == strcmp(pCol->colName, C0_PSEUDO_COLUMN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef, STableNode* pTable, bool* pFound,
|
||||||
|
bool keepOriginTable) {
|
||||||
static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef, STableNode* pTable,
|
|
||||||
bool* pFound, bool keepOriginTable) {
|
|
||||||
SColumnNode* pCol = *pColRef;
|
SColumnNode* pCol = *pColRef;
|
||||||
*pFound = false;
|
*pFound = false;
|
||||||
bool joinQuery = false;
|
bool joinQuery = false;
|
||||||
SJoinTableNode* pJoinTable = NULL;
|
SJoinTableNode* pJoinTable = NULL;
|
||||||
|
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pCxt->pCurrStmt) &&
|
if (QUERY_NODE_SELECT_STMT == nodeType(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable &&
|
||||||
NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable &&
|
QUERY_NODE_JOIN_TABLE == nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
||||||
QUERY_NODE_JOIN_TABLE == nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
|
||||||
joinQuery = true;
|
joinQuery = true;
|
||||||
pJoinTable = (SJoinTableNode*)((SSelectStmt*)pCxt->pCurrStmt)->pFromTable;
|
pJoinTable = (SJoinTableNode*)((SSelectStmt*)pCxt->pCurrStmt)->pFromTable;
|
||||||
if (isInternalPrimaryKey(pCol) && (!IS_WINDOW_JOIN(pJoinTable->subType) || !keepOriginTable)) {
|
if (isInternalPrimaryKey(pCol) && (!IS_WINDOW_JOIN(pJoinTable->subType) || !keepOriginTable)) {
|
||||||
|
@ -1179,7 +1174,7 @@ static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
|
@ -1602,7 +1597,6 @@ static EDealRes translateTimeOffsetValue(STranslateContext* pCxt, SValueNode* pV
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal, SDataType targetDt, bool strict) {
|
static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal, SDataType targetDt, bool strict) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
switch (targetDt.type) {
|
switch (targetDt.type) {
|
||||||
|
@ -1948,23 +1942,22 @@ STableNode* getJoinProbeTable(STranslateContext* pCxt) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// count(*) is rewritten as count(ts) for scannning optimization
|
// count(*) is rewritten as count(ts) for scannning optimization
|
||||||
static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) {
|
static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) {
|
||||||
SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pCount->pParameterList, 0);
|
SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pCount->pParameterList, 0);
|
||||||
STableNode* pTable = NULL;
|
STableNode* pTable = NULL;
|
||||||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
||||||
size_t nums = taosArrayGetSize(pTables);
|
size_t nums = taosArrayGetSize(pTables);
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
if ('\0' == pCol->tableAlias[0] && nums > 1) {
|
if ('\0' == pCol->tableAlias[0] && nums > 1) {
|
||||||
pTable = getJoinProbeTable(pCxt);
|
pTable = getJoinProbeTable(pCxt);
|
||||||
} else {
|
} else {
|
||||||
code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable);
|
code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
if (NULL != pTable && QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
if (NULL != pTable && QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||||
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol);
|
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol);
|
||||||
|
@ -1972,7 +1965,7 @@ static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount)
|
||||||
code = rewriteCountStarAsCount1(pCxt, pCount);
|
code = rewriteCountStarAsCount1(pCxt, pCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2180,8 +2173,6 @@ static int32_t translateInterpPseudoColumnFunc(STranslateContext* pCxt, SNode**
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
if (!fmIsTimelineFunc(pFunc->funcId)) {
|
if (!fmIsTimelineFunc(pFunc->funcId)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -2192,10 +2183,10 @@ static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFu
|
||||||
}
|
}
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
||||||
if ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
if ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
||||||
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
||||||
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
(TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode))) {
|
(TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode))) {
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
||||||
"%s function requires valid time series input", pFunc->functionName);
|
"%s function requires valid time series input", pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
@ -2926,12 +2917,12 @@ static EDealRes rewriteExprToGroupKeyFunc(STranslateContext* pCxt, SNode** pNode
|
||||||
return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isWindowJoinProbeTablePrimCol(SSelectStmt* pSelect, SNode* pNode) {
|
static bool isWindowJoinProbeTablePrimCol(SSelectStmt* pSelect, SNode* pNode) {
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pNode)) {
|
if (QUERY_NODE_COLUMN != nodeType(pNode)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||||
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
||||||
SRealTableNode* pProbeTable = NULL;
|
SRealTableNode* pProbeTable = NULL;
|
||||||
switch (pJoinTable->joinType) {
|
switch (pJoinTable->joinType) {
|
||||||
|
@ -2945,19 +2936,20 @@ static bool isWindowJoinProbeTablePrimCol(SSelectStmt* pSelect, SNode* p
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID && 0 == strcmp(pCol->dbName, pProbeTable->table.dbName) && 0 == strcmp(pCol->tableAlias, pProbeTable->table.tableAlias)) {
|
if (pCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID && 0 == strcmp(pCol->dbName, pProbeTable->table.dbName) &&
|
||||||
|
0 == strcmp(pCol->tableAlias, pProbeTable->table.tableAlias)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isWindowJoinProbeTableCol(SSelectStmt* pSelect, SNode* pNode) {
|
static bool isWindowJoinProbeTableCol(SSelectStmt* pSelect, SNode* pNode) {
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pNode)) {
|
if (QUERY_NODE_COLUMN != nodeType(pNode)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||||
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
||||||
SRealTableNode* pProbeTable = NULL;
|
SRealTableNode* pProbeTable = NULL;
|
||||||
switch (pJoinTable->joinType) {
|
switch (pJoinTable->joinType) {
|
||||||
|
@ -2971,14 +2963,14 @@ static bool isWindowJoinProbeTableCol(SSelectStmt* pSelect, SNode* pNode
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == strcmp(pCol->dbName, pProbeTable->table.dbName) && 0 == strcmp(pCol->tableAlias, pProbeTable->table.tableAlias)) {
|
if (0 == strcmp(pCol->dbName, pProbeTable->table.dbName) &&
|
||||||
|
0 == strcmp(pCol->tableAlias, pProbeTable->table.tableAlias)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct SCheckColContaisCtx {
|
typedef struct SCheckColContaisCtx {
|
||||||
SNode* pTarget;
|
SNode* pTarget;
|
||||||
bool contains;
|
bool contains;
|
||||||
|
@ -3004,7 +2996,7 @@ static bool isWindowJoinGroupCol(SSelectStmt* pSelect, SNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SCheckColContaisCtx ctx = {.pTarget = pNode, .contains = false};
|
SCheckColContaisCtx ctx = {.pTarget = pNode, .contains = false};
|
||||||
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
||||||
|
|
||||||
nodesWalkExpr(pJoinTable->pOnCond, checkColContains, &ctx);
|
nodesWalkExpr(pJoinTable->pOnCond, checkColContains, &ctx);
|
||||||
|
|
||||||
|
@ -3019,7 +3011,7 @@ static bool isWindowJoinSubTbTag(SSelectStmt* pSelect, SNode* pNode) {
|
||||||
if (COLUMN_TYPE_TAG != pCol->colType) {
|
if (COLUMN_TYPE_TAG != pCol->colType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
SJoinTableNode* pJoinTable = (SJoinTableNode*)pSelect->pFromTable;
|
||||||
SRealTableNode* pProbeTable = NULL;
|
SRealTableNode* pProbeTable = NULL;
|
||||||
SRealTableNode* pBuildTable = NULL;
|
SRealTableNode* pBuildTable = NULL;
|
||||||
|
@ -3048,7 +3040,6 @@ static bool isWindowJoinSubTbTag(SSelectStmt* pSelect, SNode* pNode) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool isWindowJoinSubTbname(SSelectStmt* pSelect, SNode* pNode) {
|
static bool isWindowJoinSubTbname(SSelectStmt* pSelect, SNode* pNode) {
|
||||||
if (QUERY_NODE_FUNCTION != nodeType(pNode)) {
|
if (QUERY_NODE_FUNCTION != nodeType(pNode)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -3076,14 +3067,15 @@ static bool isWindowJoinSubTbname(SSelectStmt* pSelect, SNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRealTableNode* pTargetTable = pProbeTable;
|
SRealTableNode* pTargetTable = pProbeTable;
|
||||||
bool isProbeTable = true;
|
bool isProbeTable = true;
|
||||||
SValueNode* pVal = (SValueNode*)nodesListGetNode(pFuncNode->pParameterList, 0);
|
SValueNode* pVal = (SValueNode*)nodesListGetNode(pFuncNode->pParameterList, 0);
|
||||||
if (NULL != pVal && 0 != strcasecmp(pVal->literal, pProbeTable->table.tableAlias)) {
|
if (NULL != pVal && 0 != strcasecmp(pVal->literal, pProbeTable->table.tableAlias)) {
|
||||||
pTargetTable = pBuildTable;
|
pTargetTable = pBuildTable;
|
||||||
isProbeTable = false;
|
isProbeTable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isProbeTable && TSDB_CHILD_TABLE != pTargetTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTargetTable->pMeta->tableType) {
|
if (!isProbeTable && TSDB_CHILD_TABLE != pTargetTable->pMeta->tableType &&
|
||||||
|
TSDB_NORMAL_TABLE != pTargetTable->pMeta->tableType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3157,11 +3149,13 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
if (pSelect->selectFuncNum > 1 || (isDistinctOrderBy(pCxt) && pCxt->currClause == SQL_CLAUSE_ORDER_BY)) {
|
if (pSelect->selectFuncNum > 1 || (isDistinctOrderBy(pCxt) && pCxt->currClause == SQL_CLAUSE_ORDER_BY)) {
|
||||||
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias);
|
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias);
|
||||||
}
|
}
|
||||||
if (isWindowJoinStmt(pSelect) && (isWindowJoinProbeTableCol(pSelect, *pNode) || isWindowJoinGroupCol(pSelect, *pNode) || (isWindowJoinSubTbname(pSelect, *pNode)) || isWindowJoinSubTbTag(pSelect, *pNode))) {
|
if (isWindowJoinStmt(pSelect) &&
|
||||||
|
(isWindowJoinProbeTableCol(pSelect, *pNode) || isWindowJoinGroupCol(pSelect, *pNode) ||
|
||||||
|
(isWindowJoinSubTbname(pSelect, *pNode)) || isWindowJoinSubTbTag(pSelect, *pNode))) {
|
||||||
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSelect->hasOtherVectorFunc || !pSelect->hasSelectFunc){
|
if (pSelect->hasOtherVectorFunc || !pSelect->hasSelectFunc) {
|
||||||
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias);
|
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3179,7 +3173,8 @@ static int32_t checkExprForGroupBy(STranslateContext* pCxt, SNode** pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect, SNodeList* pList) {
|
static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect, SNodeList* pList) {
|
||||||
if (NULL == getGroupByList(pCxt) && NULL == pSelect->pWindow && (!isWindowJoinStmt(pSelect) || (!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc))) {
|
if (NULL == getGroupByList(pCxt) && NULL == pSelect->pWindow &&
|
||||||
|
(!isWindowJoinStmt(pSelect) || (!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc))) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
nodesRewriteExprs(pList, doCheckExprForGroupBy, pCxt);
|
nodesRewriteExprs(pList, doCheckExprForGroupBy, pCxt);
|
||||||
|
@ -3249,7 +3244,6 @@ static EDealRes doCheckGetAggColCoexist(SNode** pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t checkIsEmptyResult(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t checkIsEmptyResult(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (pSelect->timeRange.skey > pSelect->timeRange.ekey && !pSelect->hasCountFunc) {
|
if (pSelect->timeRange.skey > pSelect->timeRange.ekey && !pSelect->hasCountFunc) {
|
||||||
pSelect->isEmptyResult = true;
|
pSelect->isEmptyResult = true;
|
||||||
|
@ -3298,7 +3292,8 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t checkWinJoinAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t checkWinJoinAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (!isWindowJoinStmt(pSelect) || (!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc && !pSelect->hasInterpFunc)) {
|
if (!isWindowJoinStmt(pSelect) ||
|
||||||
|
(!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc && !pSelect->hasInterpFunc)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
if (!pSelect->onlyHasKeepOrderFunc) {
|
if (!pSelect->onlyHasKeepOrderFunc) {
|
||||||
|
@ -3309,19 +3304,20 @@ static int32_t checkWinJoinAggColCoexist(STranslateContext* pCxt, SSelectStmt* p
|
||||||
if (!pSelect->isDistinct) {
|
if (!pSelect->isDistinct) {
|
||||||
nodesRewriteExprs(pSelect->pOrderByList, doCheckGetAggColCoexist, &cxt);
|
nodesRewriteExprs(pSelect->pOrderByList, doCheckGetAggColCoexist, &cxt);
|
||||||
}
|
}
|
||||||
if (((!cxt.existCol && 0 < pSelect->selectFuncNum) || (cxt.existCol && 1 == pSelect->selectFuncNum) )
|
if (((!cxt.existCol && 0 < pSelect->selectFuncNum) || (cxt.existCol && 1 == pSelect->selectFuncNum)) &&
|
||||||
&& !pSelect->hasOtherVectorFunc) {
|
!pSelect->hasOtherVectorFunc) {
|
||||||
return rewriteColsToSelectValFunc(pCxt, pSelect);
|
return rewriteColsToSelectValFunc(pCxt, pSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cxt.existCol) {
|
if (cxt.existCol) {
|
||||||
bool allProbeTableCols = true;
|
bool allProbeTableCols = true;
|
||||||
SNode* pNode = NULL;
|
SNode* pNode = NULL;
|
||||||
FOREACH(pNode, cxt.pColList) {
|
FOREACH(pNode, cxt.pColList) {
|
||||||
if (isWindowJoinProbeTableCol(pSelect, pNode) || isWindowJoinGroupCol(pSelect, pNode) || (isWindowJoinSubTbname(pSelect, pNode)) || isWindowJoinSubTbTag(pSelect, pNode)) {
|
if (isWindowJoinProbeTableCol(pSelect, pNode) || isWindowJoinGroupCol(pSelect, pNode) ||
|
||||||
|
(isWindowJoinSubTbname(pSelect, pNode)) || isWindowJoinSubTbTag(pSelect, pNode)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
allProbeTableCols = false;
|
allProbeTableCols = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3335,7 +3331,8 @@ static int32_t checkWinJoinAggColCoexist(STranslateContext* pCxt, SSelectStmt* p
|
||||||
|
|
||||||
static int32_t checkHavingGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t checkHavingGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (NULL == getGroupByList(pCxt) && NULL == pSelect->pPartitionByList && NULL == pSelect->pWindow && !isWindowJoinStmt(pSelect)) {
|
if (NULL == getGroupByList(pCxt) && NULL == pSelect->pPartitionByList && NULL == pSelect->pWindow &&
|
||||||
|
!isWindowJoinStmt(pSelect)) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
if (NULL != pSelect->pHaving) {
|
if (NULL != pSelect->pHaving) {
|
||||||
|
@ -3363,7 +3360,6 @@ static EDealRes searchAggFuncNode(SNode* pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t checkWindowGrpFuncCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t checkWindowGrpFuncCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (NULL != pSelect->pWindow && !pSelect->hasAggFuncs && !pSelect->hasStateKey) {
|
if (NULL != pSelect->pWindow && !pSelect->hasAggFuncs && !pSelect->hasStateKey) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN);
|
||||||
|
@ -3372,15 +3368,15 @@ static int32_t checkWindowGrpFuncCoexist(STranslateContext* pCxt, SSelectStmt* p
|
||||||
if (!pSelect->hasAggFuncs && NULL != pSelect->pHaving) {
|
if (!pSelect->hasAggFuncs && NULL != pSelect->pHaving) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WJOIN_HAVING_EXPR);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WJOIN_HAVING_EXPR);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (NULL != pSelect->pHaving) {
|
if (NULL != pSelect->pHaving) {
|
||||||
bool hasFunc = false;
|
bool hasFunc = false;
|
||||||
nodesWalkExpr(pSelect->pHaving, searchAggFuncNode, &hasFunc);
|
nodesWalkExpr(pSelect->pHaving, searchAggFuncNode, &hasFunc);
|
||||||
if (!hasFunc) {
|
if (!hasFunc) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WJOIN_HAVING_EXPR);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WJOIN_HAVING_EXPR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (pSelect->hasAggFuncs) {
|
if (pSelect->hasAggFuncs) {
|
||||||
return checkExprListForGroupBy(pCxt, pSelect, pSelect->pProjectionList);
|
return checkExprListForGroupBy(pCxt, pSelect, pSelect->pProjectionList);
|
||||||
}
|
}
|
||||||
|
@ -3688,7 +3684,8 @@ static int32_t replaceTbName(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
return pRewriteCxt.errCode;
|
return pRewriteCxt.errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t addPrimJoinEqCond(SNode** pCond, SRealTableNode* leftTable, SRealTableNode* rightTable, EJoinType joinType, EJoinSubType subType) {
|
static int32_t addPrimJoinEqCond(SNode** pCond, SRealTableNode* leftTable, SRealTableNode* rightTable,
|
||||||
|
EJoinType joinType, EJoinSubType subType) {
|
||||||
struct STableMeta* pLMeta = leftTable->pMeta;
|
struct STableMeta* pLMeta = leftTable->pMeta;
|
||||||
struct STableMeta* pRMeta = rightTable->pMeta;
|
struct STableMeta* pRMeta = rightTable->pMeta;
|
||||||
|
|
||||||
|
@ -3743,7 +3740,6 @@ static int32_t addPrimJoinEqCond(SNode** pCond, SRealTableNode* leftTable, SReal
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool getJoinContais(SNode* pNode) {
|
static bool getJoinContais(SNode* pNode) {
|
||||||
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -3785,13 +3781,13 @@ static bool getJoinContais(SNode* pNode) {
|
||||||
|
|
||||||
static bool getBothJoinContais(SNode* pLeft, SNode* pRight) {
|
static bool getBothJoinContais(SNode* pLeft, SNode* pRight) {
|
||||||
bool joinContains = false;
|
bool joinContains = false;
|
||||||
|
|
||||||
if (NULL != pLeft) {
|
if (NULL != pLeft) {
|
||||||
joinContains= getJoinContais(pLeft);
|
joinContains = getJoinContais(pLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != pRight && !joinContains) {
|
if (NULL != pRight && !joinContains) {
|
||||||
joinContains= getJoinContais(pRight);
|
joinContains = getJoinContais(pRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
return joinContains;
|
return joinContains;
|
||||||
|
@ -3804,20 +3800,23 @@ static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTabl
|
||||||
|
|
||||||
if (IS_ASOF_JOIN(pJoinTable->subType) || IS_WINDOW_JOIN(pJoinTable->subType)) {
|
if (IS_ASOF_JOIN(pJoinTable->subType) || IS_WINDOW_JOIN(pJoinTable->subType)) {
|
||||||
if (QUERY_NODE_REAL_TABLE != nodeType(pJoinTable->pLeft) || QUERY_NODE_REAL_TABLE != nodeType(pJoinTable->pRight)) {
|
if (QUERY_NODE_REAL_TABLE != nodeType(pJoinTable->pLeft) || QUERY_NODE_REAL_TABLE != nodeType(pJoinTable->pRight)) {
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN, "Only support ASOF/WINDOW join between tables");
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN,
|
||||||
|
"Only support ASOF/WINDOW join between tables");
|
||||||
}
|
}
|
||||||
|
|
||||||
SRealTableNode* pLeft = (SRealTableNode*)pJoinTable->pLeft;
|
SRealTableNode* pLeft = (SRealTableNode*)pJoinTable->pLeft;
|
||||||
if (TSDB_SUPER_TABLE != pLeft->pMeta->tableType && TSDB_CHILD_TABLE != pLeft->pMeta->tableType && TSDB_NORMAL_TABLE != pLeft->pMeta->tableType) {
|
if (TSDB_SUPER_TABLE != pLeft->pMeta->tableType && TSDB_CHILD_TABLE != pLeft->pMeta->tableType &&
|
||||||
|
TSDB_NORMAL_TABLE != pLeft->pMeta->tableType) {
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN,
|
||||||
"Unsupported ASOF/WINDOW join table type");
|
"Unsupported ASOF/WINDOW join table type");
|
||||||
}
|
}
|
||||||
|
|
||||||
SRealTableNode* pRight = (SRealTableNode*)pJoinTable->pRight;
|
SRealTableNode* pRight = (SRealTableNode*)pJoinTable->pRight;
|
||||||
if (TSDB_SUPER_TABLE != pRight->pMeta->tableType && TSDB_CHILD_TABLE != pRight->pMeta->tableType && TSDB_NORMAL_TABLE != pRight->pMeta->tableType) {
|
if (TSDB_SUPER_TABLE != pRight->pMeta->tableType && TSDB_CHILD_TABLE != pRight->pMeta->tableType &&
|
||||||
|
TSDB_NORMAL_TABLE != pRight->pMeta->tableType) {
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN,
|
||||||
"Unsupported ASOF/WINDOW join table type");
|
"Unsupported ASOF/WINDOW join table type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_WINDOW_JOIN(pJoinTable->subType)) {
|
if (IS_WINDOW_JOIN(pJoinTable->subType)) {
|
||||||
if (pLeft->table.precision != pRight->table.precision) {
|
if (pLeft->table.precision != pRight->table.precision) {
|
||||||
|
@ -3825,8 +3824,8 @@ static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTabl
|
||||||
"Same database precision required in WINDOW join");
|
"Same database precision required in WINDOW join");
|
||||||
}
|
}
|
||||||
SWindowOffsetNode* pWinOffset = (SWindowOffsetNode*)pJoinTable->pWindowOffset;
|
SWindowOffsetNode* pWinOffset = (SWindowOffsetNode*)pJoinTable->pWindowOffset;
|
||||||
SValueNode* pStart = (SValueNode*)pWinOffset->pStartOffset;
|
SValueNode* pStart = (SValueNode*)pWinOffset->pStartOffset;
|
||||||
SValueNode* pEnd = (SValueNode*)pWinOffset->pEndOffset;
|
SValueNode* pEnd = (SValueNode*)pWinOffset->pEndOffset;
|
||||||
switch (pLeft->table.precision) {
|
switch (pLeft->table.precision) {
|
||||||
case TSDB_TIME_PRECISION_MILLI:
|
case TSDB_TIME_PRECISION_MILLI:
|
||||||
if (TIME_UNIT_NANOSECOND == pStart->unit || TIME_UNIT_MICROSECOND == pStart->unit) {
|
if (TIME_UNIT_NANOSECOND == pStart->unit || TIME_UNIT_MICROSECOND == pStart->unit) {
|
||||||
|
@ -3849,7 +3848,8 @@ static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = addPrimJoinEqCond(&pJoinTable->addPrimCond, pLeft, pRight, pJoinTable->joinType, pJoinTable->subType);
|
int32_t code =
|
||||||
|
addPrimJoinEqCond(&pJoinTable->addPrimCond, pLeft, pRight, pJoinTable->joinType, pJoinTable->subType);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3870,27 +3870,29 @@ static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTabl
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SUPPORT_JOIN,
|
||||||
"Join requires valid time series input");
|
"Join requires valid time series input");
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTable) {
|
static int32_t translateJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTable) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
EJoinType type = pJoinTable->joinType;
|
EJoinType type = pJoinTable->joinType;
|
||||||
EJoinSubType* pSType = &pJoinTable->subType;
|
EJoinSubType* pSType = &pJoinTable->subType;
|
||||||
SSelectStmt* pCurrSmt = (SSelectStmt*)(pCxt->pCurrStmt);
|
SSelectStmt* pCurrSmt = (SSelectStmt*)(pCxt->pCurrStmt);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case JOIN_TYPE_INNER:
|
case JOIN_TYPE_INNER:
|
||||||
if (*pSType == JOIN_STYPE_OUTER || *pSType == JOIN_STYPE_SEMI || *pSType == JOIN_STYPE_ANTI || *pSType == JOIN_STYPE_ASOF || *pSType == JOIN_STYPE_WIN) {
|
if (*pSType == JOIN_STYPE_OUTER || *pSType == JOIN_STYPE_SEMI || *pSType == JOIN_STYPE_ANTI ||
|
||||||
|
*pSType == JOIN_STYPE_ASOF || *pSType == JOIN_STYPE_WIN) {
|
||||||
return buildInvalidOperationMsg(&pCxt->msgBuf, "not supported join type");
|
return buildInvalidOperationMsg(&pCxt->msgBuf, "not supported join type");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case JOIN_TYPE_FULL:
|
case JOIN_TYPE_FULL:
|
||||||
if (*pSType == JOIN_STYPE_SEMI || *pSType == JOIN_STYPE_ANTI || *pSType == JOIN_STYPE_ASOF || *pSType == JOIN_STYPE_WIN) {
|
if (*pSType == JOIN_STYPE_SEMI || *pSType == JOIN_STYPE_ANTI || *pSType == JOIN_STYPE_ASOF ||
|
||||||
|
*pSType == JOIN_STYPE_WIN) {
|
||||||
return buildInvalidOperationMsg(&pCxt->msgBuf, "not supported join type");
|
return buildInvalidOperationMsg(&pCxt->msgBuf, "not supported join type");
|
||||||
}
|
}
|
||||||
//fall down
|
// fall down
|
||||||
default:
|
default:
|
||||||
if (*pSType == JOIN_STYPE_NONE) {
|
if (*pSType == JOIN_STYPE_NONE) {
|
||||||
*pSType = JOIN_STYPE_OUTER;
|
*pSType = JOIN_STYPE_OUTER;
|
||||||
|
@ -3913,16 +3915,18 @@ static int32_t translateJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoin
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WIN_OFFSET_UNIT, pEnd->unit);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WIN_OFFSET_UNIT, pEnd->unit);
|
||||||
}
|
}
|
||||||
if (pStart->datum.i > pEnd->datum.i) {
|
if (pStart->datum.i > pEnd->datum.i) {
|
||||||
TSWAP(((SWindowOffsetNode*)pJoinTable->pWindowOffset)->pStartOffset, ((SWindowOffsetNode*)pJoinTable->pWindowOffset)->pEndOffset);
|
TSWAP(((SWindowOffsetNode*)pJoinTable->pWindowOffset)->pStartOffset,
|
||||||
|
((SWindowOffsetNode*)pJoinTable->pWindowOffset)->pEndOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (*pSType == JOIN_STYPE_WIN) {
|
} else if (*pSType == JOIN_STYPE_WIN) {
|
||||||
return buildInvalidOperationMsg(&pCxt->msgBuf, "WINDOW_OFFSET required for WINDOW join");
|
return buildInvalidOperationMsg(&pCxt->msgBuf, "WINDOW_OFFSET required for WINDOW join");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinTable->pJLimit) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pJoinTable->pJLimit) {
|
||||||
if (*pSType != JOIN_STYPE_ASOF && *pSType != JOIN_STYPE_WIN) {
|
if (*pSType != JOIN_STYPE_ASOF && *pSType != JOIN_STYPE_WIN) {
|
||||||
return buildInvalidOperationMsgExt(&pCxt->msgBuf, "JLIMIT not supported for %s join", getFullJoinTypeString(type, *pSType));
|
return buildInvalidOperationMsgExt(&pCxt->msgBuf, "JLIMIT not supported for %s join",
|
||||||
|
getFullJoinTypeString(type, *pSType));
|
||||||
}
|
}
|
||||||
SLimitNode* pJLimit = (SLimitNode*)pJoinTable->pJLimit;
|
SLimitNode* pJLimit = (SLimitNode*)pJoinTable->pJLimit;
|
||||||
if (pJLimit->limit > JOIN_JLIMIT_MAX_VALUE || pJLimit->limit < 0) {
|
if (pJLimit->limit > JOIN_JLIMIT_MAX_VALUE || pJLimit->limit < 0) {
|
||||||
|
@ -3950,8 +3954,12 @@ EDealRes joinCondsValidater(SNode* pNode, void* pContext) {
|
||||||
if (OP_TYPE_EQUAL < pOp->opType || OP_TYPE_GREATER_THAN > pOp->opType) {
|
if (OP_TYPE_EQUAL < pOp->opType || OP_TYPE_GREATER_THAN > pOp->opType) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((QUERY_NODE_COLUMN != nodeType(pOp->pLeft) && QUERY_NODE_FUNCTION != nodeType(pOp->pLeft) && !(QUERY_NODE_OPERATOR == nodeType(pOp->pLeft) && OP_TYPE_JSON_GET_VALUE ==((SOperatorNode*)pOp->pLeft)->opType)) ||
|
if ((QUERY_NODE_COLUMN != nodeType(pOp->pLeft) && QUERY_NODE_FUNCTION != nodeType(pOp->pLeft) &&
|
||||||
(QUERY_NODE_COLUMN != nodeType(pOp->pRight) && QUERY_NODE_FUNCTION != nodeType(pOp->pRight) && !(QUERY_NODE_OPERATOR == nodeType(pOp->pRight) && OP_TYPE_JSON_GET_VALUE ==((SOperatorNode*)pOp->pRight)->opType))){
|
!(QUERY_NODE_OPERATOR == nodeType(pOp->pLeft) &&
|
||||||
|
OP_TYPE_JSON_GET_VALUE == ((SOperatorNode*)pOp->pLeft)->opType)) ||
|
||||||
|
(QUERY_NODE_COLUMN != nodeType(pOp->pRight) && QUERY_NODE_FUNCTION != nodeType(pOp->pRight) &&
|
||||||
|
!(QUERY_NODE_OPERATOR == nodeType(pOp->pRight) &&
|
||||||
|
OP_TYPE_JSON_GET_VALUE == ((SOperatorNode*)pOp->pRight)->opType))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_COLUMN == nodeType(pOp->pLeft)) {
|
if (QUERY_NODE_COLUMN == nodeType(pOp->pLeft)) {
|
||||||
|
@ -3966,9 +3974,10 @@ EDealRes joinCondsValidater(SNode* pNode, void* pContext) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_FUNCTION == nodeType(pOp->pLeft) && FUNCTION_TYPE_TIMETRUNCATE == ((SFunctionNode*)pOp->pLeft)->funcType) {
|
if (QUERY_NODE_FUNCTION == nodeType(pOp->pLeft) &&
|
||||||
|
FUNCTION_TYPE_TIMETRUNCATE == ((SFunctionNode*)pOp->pLeft)->funcType) {
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)pOp->pLeft;
|
SFunctionNode* pFunc = (SFunctionNode*)pOp->pLeft;
|
||||||
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pParam)) {
|
if (QUERY_NODE_COLUMN != nodeType(pParam)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3977,9 +3986,10 @@ EDealRes joinCondsValidater(SNode* pNode, void* pContext) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_FUNCTION == nodeType(pOp->pRight) && FUNCTION_TYPE_TIMETRUNCATE == ((SFunctionNode*)pOp->pRight)->funcType) {
|
if (QUERY_NODE_FUNCTION == nodeType(pOp->pRight) &&
|
||||||
|
FUNCTION_TYPE_TIMETRUNCATE == ((SFunctionNode*)pOp->pRight)->funcType) {
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)pOp->pRight;
|
SFunctionNode* pFunc = (SFunctionNode*)pOp->pRight;
|
||||||
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pParam)) {
|
if (QUERY_NODE_COLUMN != nodeType(pParam)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3989,7 +3999,7 @@ EDealRes joinCondsValidater(SNode* pNode, void* pContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4005,11 +4015,10 @@ int32_t validateJoinConds(STranslateContext* pCxt, SJoinTableNode* pJoinTable) {
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
nodesWalkExpr(pJoinTable->pOnCond, joinCondsValidater, &code);
|
nodesWalkExpr(pJoinTable->pOnCond, joinCondsValidater, &code);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t translateAudit(STranslateContext* pCxt, SRealTableNode* pRealTable, SName* pName) {
|
static int32_t translateAudit(STranslateContext* pCxt, SRealTableNode* pRealTable, SName* pName) {
|
||||||
if (pRealTable->pMeta->tableType == TSDB_SUPER_TABLE) {
|
if (pRealTable->pMeta->tableType == TSDB_SUPER_TABLE) {
|
||||||
if (IS_AUDIT_DBNAME(pName->dbname) && IS_AUDIT_STB_NAME(pName->tname)) {
|
if (IS_AUDIT_DBNAME(pName->dbname) && IS_AUDIT_STB_NAME(pName->tname)) {
|
||||||
|
@ -4028,7 +4037,8 @@ static bool isJoinTagEqualOnCond(SNode* pCond, char* leftTableAlias, char* right
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SOperatorNode* pOper = (SOperatorNode*)pCond;
|
SOperatorNode* pOper = (SOperatorNode*)pCond;
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pOper->pLeft) || NULL == pOper->pRight || QUERY_NODE_COLUMN != nodeType(pOper->pRight)) {
|
if (QUERY_NODE_COLUMN != nodeType(pOper->pLeft) || NULL == pOper->pRight ||
|
||||||
|
QUERY_NODE_COLUMN != nodeType(pOper->pRight)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SColumnNode* pLeft = (SColumnNode*)(pOper->pLeft);
|
SColumnNode* pLeft = (SColumnNode*)(pOper->pLeft);
|
||||||
|
@ -4080,12 +4090,13 @@ static bool joinTagEqCondContains(SNode* pCond, char* leftTableAlias, char* righ
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool innerJoinTagEqCondContains(SJoinTableNode* pJoinTable, SNode* pWhere) {
|
static bool innerJoinTagEqCondContains(SJoinTableNode* pJoinTable, SNode* pWhere) {
|
||||||
bool condContains = false;
|
bool condContains = false;
|
||||||
SRealTableNode *pLeftTable = (SRealTableNode*)pJoinTable->pLeft;
|
SRealTableNode* pLeftTable = (SRealTableNode*)pJoinTable->pLeft;
|
||||||
SRealTableNode *pRightTable = (SRealTableNode*)pJoinTable->pRight;
|
SRealTableNode* pRightTable = (SRealTableNode*)pJoinTable->pRight;
|
||||||
|
|
||||||
if (NULL != pJoinTable->pOnCond) {
|
if (NULL != pJoinTable->pOnCond) {
|
||||||
condContains = joinTagEqCondContains(pJoinTable->pOnCond, pLeftTable->table.tableAlias, pRightTable->table.tableAlias);
|
condContains =
|
||||||
|
joinTagEqCondContains(pJoinTable->pOnCond, pLeftTable->table.tableAlias, pRightTable->table.tableAlias);
|
||||||
}
|
}
|
||||||
if (NULL != pWhere && !condContains) {
|
if (NULL != pWhere && !condContains) {
|
||||||
condContains = joinTagEqCondContains(pWhere, pLeftTable->table.tableAlias, pRightTable->table.tableAlias);
|
condContains = joinTagEqCondContains(pWhere, pLeftTable->table.tableAlias, pRightTable->table.tableAlias);
|
||||||
|
@ -4114,7 +4125,8 @@ static bool joinNonPrimColCondContains(SJoinTableNode* pJoinTable) {
|
||||||
if (OP_TYPE_EQUAL != pOp->opType) {
|
if (OP_TYPE_EQUAL != pOp->opType) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pOp->pLeft) || NULL == pOp->pRight || QUERY_NODE_COLUMN != nodeType(pOp->pRight)) {
|
if (QUERY_NODE_COLUMN != nodeType(pOp->pLeft) || NULL == pOp->pRight ||
|
||||||
|
QUERY_NODE_COLUMN != nodeType(pOp->pRight)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isPrimaryKeyImpl(pOp->pLeft) || isPrimaryKeyImpl(pOp->pRight)) {
|
if (isPrimaryKeyImpl(pOp->pLeft) || isPrimaryKeyImpl(pOp->pRight)) {
|
||||||
|
@ -4131,17 +4143,18 @@ static bool joinNonPrimColCondContains(SJoinTableNode* pJoinTable) {
|
||||||
if (OP_TYPE_EQUAL != pOp->opType) {
|
if (OP_TYPE_EQUAL != pOp->opType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pOp->pLeft) || NULL == pOp->pRight || QUERY_NODE_COLUMN != nodeType(pOp->pRight)) {
|
if (QUERY_NODE_COLUMN != nodeType(pOp->pLeft) || NULL == pOp->pRight ||
|
||||||
|
QUERY_NODE_COLUMN != nodeType(pOp->pRight)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isPrimaryKeyImpl(pOp->pLeft) || isPrimaryKeyImpl(pOp->pRight)) {
|
if (isPrimaryKeyImpl(pOp->pLeft) || isPrimaryKeyImpl(pOp->pRight)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setJoinTimeLineResMode(STranslateContext* pCxt) {
|
static int32_t setJoinTimeLineResMode(STranslateContext* pCxt) {
|
||||||
|
@ -4149,7 +4162,7 @@ static int32_t setJoinTimeLineResMode(STranslateContext* pCxt) {
|
||||||
if (QUERY_NODE_JOIN_TABLE != nodeType(pCurrSmt->pFromTable)) {
|
if (QUERY_NODE_JOIN_TABLE != nodeType(pCurrSmt->pFromTable)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SJoinTableNode* pJoinTable = (SJoinTableNode*)pCurrSmt->pFromTable;
|
SJoinTableNode* pJoinTable = (SJoinTableNode*)pCurrSmt->pFromTable;
|
||||||
if (JOIN_TYPE_FULL == pJoinTable->joinType) {
|
if (JOIN_TYPE_FULL == pJoinTable->joinType) {
|
||||||
pCurrSmt->timeLineResMode = TIME_LINE_NONE;
|
pCurrSmt->timeLineResMode = TIME_LINE_NONE;
|
||||||
|
@ -4183,7 +4196,7 @@ static int32_t setJoinTimeLineResMode(STranslateContext* pCxt) {
|
||||||
|
|
||||||
int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinParent) {
|
int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinParent) {
|
||||||
SSelectStmt* pCurrSmt = (SSelectStmt*)(pCxt->pCurrStmt);
|
SSelectStmt* pCurrSmt = (SSelectStmt*)(pCxt->pCurrStmt);
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
switch (nodeType(*pTable)) {
|
switch (nodeType(*pTable)) {
|
||||||
case QUERY_NODE_REAL_TABLE: {
|
case QUERY_NODE_REAL_TABLE: {
|
||||||
SRealTableNode* pRealTable = (SRealTableNode*)*pTable;
|
SRealTableNode* pRealTable = (SRealTableNode*)*pTable;
|
||||||
|
@ -4241,7 +4254,7 @@ int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinPare
|
||||||
pCurrSmt->timeLineResMode = pSubStmt->timeLineResMode;
|
pCurrSmt->timeLineResMode = pSubStmt->timeLineResMode;
|
||||||
pCurrSmt->timeLineCurMode = pSubStmt->timeLineResMode;
|
pCurrSmt->timeLineCurMode = pSubStmt->timeLineResMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCurrSmt->joinContains = (getJoinContais(pTempTable->pSubquery) ? true : false);
|
pCurrSmt->joinContains = (getJoinContais(pTempTable->pSubquery) ? true : false);
|
||||||
pTempTable->table.precision = getStmtPrecision(pTempTable->pSubquery);
|
pTempTable->table.precision = getStmtPrecision(pTempTable->pSubquery);
|
||||||
pTempTable->table.singleTable = stmtIsSingleTable(pTempTable->pSubquery);
|
pTempTable->table.singleTable = stmtIsSingleTable(pTempTable->pSubquery);
|
||||||
|
@ -4277,7 +4290,7 @@ int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinPare
|
||||||
((SJoinTableNode*)pJoinTable->pRight)->isLowLevelJoin = true;
|
((SJoinTableNode*)pJoinTable->pRight)->isLowLevelJoin = true;
|
||||||
}
|
}
|
||||||
code = validateJoinConds(pCxt, pJoinTable);
|
code = validateJoinConds(pCxt, pJoinTable);
|
||||||
}
|
}
|
||||||
pCurrSmt->joinContains = true;
|
pCurrSmt->joinContains = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4707,8 +4720,8 @@ static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateHaving(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t translateHaving(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (NULL == pSelect->pGroupByList && NULL == pSelect->pPartitionByList && NULL == pSelect->pWindow && !isWindowJoinStmt(pSelect) &&
|
if (NULL == pSelect->pGroupByList && NULL == pSelect->pPartitionByList && NULL == pSelect->pWindow &&
|
||||||
NULL != pSelect->pHaving) {
|
!isWindowJoinStmt(pSelect) && NULL != pSelect->pHaving) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION);
|
||||||
}
|
}
|
||||||
if (isWindowJoinStmt(pSelect)) {
|
if (isWindowJoinStmt(pSelect)) {
|
||||||
|
@ -5113,24 +5126,24 @@ static int32_t translateWindow(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType == TSDB_SYSTEM_TABLE) {
|
((SRealTableNode*)pSelect->pFromTable)->pMeta->tableType == TSDB_SYSTEM_TABLE) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED, "WINDOW");
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED, "WINDOW");
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_INTERVAL_WINDOW != nodeType(pSelect->pWindow) && ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
if (QUERY_NODE_INTERVAL_WINDOW != nodeType(pSelect->pWindow) &&
|
||||||
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
|
||||||
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
|
||||||
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
|
||||||
(TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode)))) {
|
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow) &&
|
|
||||||
((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
!isBlockTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
||||||
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
||||||
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
(TIME_LINE_NONE == pSelect->timeLineCurMode)))) {
|
(TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode)))) {
|
||||||
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow) &&
|
||||||
|
((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
|
!isBlockTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
||||||
|
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
||||||
|
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
|
(TIME_LINE_NONE == pSelect->timeLineCurMode)))) {
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pCxt->currClause = SQL_CLAUSE_WINDOW;
|
pCxt->currClause = SQL_CLAUSE_WINDOW;
|
||||||
int32_t code = translateExpr(pCxt, &pSelect->pWindow);
|
int32_t code = translateExpr(pCxt, &pSelect->pWindow);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -5652,8 +5665,9 @@ static EDealRes collectTableAlias(SNode* pNode, void* pContext) {
|
||||||
*(SSHashObj**)pContext = pHash;
|
*(SSHashObj**)pContext = pHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
tSimpleHashPut(*(SSHashObj**)pContext, pCol->tableAlias, strlen(pCol->tableAlias), pCol->tableAlias, sizeof(pCol->tableAlias));
|
tSimpleHashPut(*(SSHashObj**)pContext, pCol->tableAlias, strlen(pCol->tableAlias), pCol->tableAlias,
|
||||||
|
sizeof(pCol->tableAlias));
|
||||||
|
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5663,25 +5677,25 @@ static EDealRes appendTsForImplicitTsFuncImpl(SNode* pNode, void* pContext) {
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
||||||
if (!isSelectStmt(pCxt->pCurrStmt)) {
|
if (!isSelectStmt(pCxt->pCurrStmt)) {
|
||||||
pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
||||||
"%s function must be used in select statements", pFunc->functionName);
|
"%s function must be used in select statements", pFunc->functionName);
|
||||||
return DEAL_RES_ERROR;
|
return DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
||||||
if ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
if ((NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
||||||
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) ||
|
||||||
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
(NULL != pSelect->pFromTable && QUERY_NODE_JOIN_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
(TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode))) {
|
(TIME_LINE_GLOBAL != pSelect->timeLineCurMode && TIME_LINE_MULTI != pSelect->timeLineCurMode))) {
|
||||||
pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
||||||
"%s function requires valid time series input", pFunc->functionName);
|
"%s function requires valid time series input", pFunc->functionName);
|
||||||
return DEAL_RES_ERROR;
|
return DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SNode* pPrimaryKey = NULL;
|
SNode* pPrimaryKey = NULL;
|
||||||
SSHashObj* pTableAlias = NULL;
|
SSHashObj* pTableAlias = NULL;
|
||||||
nodesWalkExprs(pFunc->pParameterList, collectTableAlias, &pTableAlias);
|
nodesWalkExprs(pFunc->pParameterList, collectTableAlias, &pTableAlias);
|
||||||
if (NULL == pTableAlias) {
|
if (NULL == pTableAlias) {
|
||||||
pCxt->errCode = tranCreatePrimaryKeyCol(pCxt, NULL, &pPrimaryKey);
|
pCxt->errCode = tranCreatePrimaryKeyCol(pCxt, NULL, &pPrimaryKey);
|
||||||
|
@ -5689,8 +5703,8 @@ static EDealRes appendTsForImplicitTsFuncImpl(SNode* pNode, void* pContext) {
|
||||||
if (tSimpleHashGetSize(pTableAlias) > 1) {
|
if (tSimpleHashGetSize(pTableAlias) > 1) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TIMELINE_FUNC);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TIMELINE_FUNC);
|
||||||
}
|
}
|
||||||
char* tableAlias = NULL;
|
char* tableAlias = NULL;
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
tableAlias = tSimpleHashIterate(pTableAlias, tableAlias, &iter);
|
tableAlias = tSimpleHashIterate(pTableAlias, tableAlias, &iter);
|
||||||
pCxt->errCode = tranCreatePrimaryKeyCol(pCxt, tableAlias, &pPrimaryKey);
|
pCxt->errCode = tranCreatePrimaryKeyCol(pCxt, tableAlias, &pPrimaryKey);
|
||||||
tSimpleHashCleanup(pTableAlias);
|
tSimpleHashCleanup(pTableAlias);
|
||||||
|
@ -5779,7 +5793,8 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
|
||||||
FOREACH(pProject, pProjectionList) {
|
FOREACH(pProject, pProjectionList) {
|
||||||
SExprNode* pExpr = (SExprNode*)pProject;
|
SExprNode* pExpr = (SExprNode*)pProject;
|
||||||
if (0 == strcmp(((SColumnNode*)*pNode)->colName, pExpr->userAlias)) {
|
if (0 == strcmp(((SColumnNode*)*pNode)->colName, pExpr->userAlias)) {
|
||||||
if (!pCxt->nameMatch && (nodeType(*pNode) != nodeType(pProject) || (QUERY_NODE_COLUMN == nodeType(pProject) && !nodesEqualNode(*pNode, pProject)))) {
|
if (!pCxt->nameMatch && (nodeType(*pNode) != nodeType(pProject) ||
|
||||||
|
(QUERY_NODE_COLUMN == nodeType(pProject) && !nodesEqualNode(*pNode, pProject)))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SNode* pNew = nodesCloneNode(pProject);
|
SNode* pNew = nodesCloneNode(pProject);
|
||||||
|
@ -5821,16 +5836,18 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t replaceOrderByAlias(STranslateContext* pCxt, SNodeList* pProjectionList, SNodeList* pOrderByList, bool checkExists, bool nameMatch) {
|
static int32_t replaceOrderByAlias(STranslateContext* pCxt, SNodeList* pProjectionList, SNodeList* pOrderByList,
|
||||||
|
bool checkExists, bool nameMatch) {
|
||||||
if (NULL == pOrderByList) {
|
if (NULL == pOrderByList) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
SReplaceOrderByAliasCxt cxt = {.pTranslateCxt = pCxt, .pProjectionList = pProjectionList, .nameMatch = nameMatch, .notFound = false};
|
SReplaceOrderByAliasCxt cxt = {
|
||||||
|
.pTranslateCxt = pCxt, .pProjectionList = pProjectionList, .nameMatch = nameMatch, .notFound = false};
|
||||||
nodesRewriteExprsPostOrder(pOrderByList, replaceOrderByAliasImpl, &cxt);
|
nodesRewriteExprsPostOrder(pOrderByList, replaceOrderByAliasImpl, &cxt);
|
||||||
if (checkExists && cxt.notFound) {
|
if (checkExists && cxt.notFound) {
|
||||||
return TSDB_CODE_PAR_ORDERBY_UNKNOWN_EXPR;
|
return TSDB_CODE_PAR_ORDERBY_UNKNOWN_EXPR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pCxt->errCode;
|
return pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5839,8 +5856,7 @@ static void resetResultTimeline(SSelectStmt* pSelect) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SNode* pOrder = ((SOrderByExprNode*)nodesListGetNode(pSelect->pOrderByList, 0))->pExpr;
|
SNode* pOrder = ((SOrderByExprNode*)nodesListGetNode(pSelect->pOrderByList, 0))->pExpr;
|
||||||
if ((QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
if ((QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && isPrimaryKeyImpl(pOrder)) ||
|
||||||
isPrimaryKeyImpl(pOrder)) ||
|
|
||||||
(QUERY_NODE_TEMP_TABLE != nodeType(pSelect->pFromTable) && isPrimaryKeyImpl(pOrder))) {
|
(QUERY_NODE_TEMP_TABLE != nodeType(pSelect->pFromTable) && isPrimaryKeyImpl(pOrder))) {
|
||||||
pSelect->timeLineResMode = TIME_LINE_GLOBAL;
|
pSelect->timeLineResMode = TIME_LINE_GLOBAL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -5903,11 +5919,11 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect
|
||||||
resetSelectFuncNumWithoutDup(pSelect);
|
resetSelectFuncNumWithoutDup(pSelect);
|
||||||
code = checkAggColCoexist(pCxt, pSelect);
|
code = checkAggColCoexist(pCxt, pSelect);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = checkWinJoinAggColCoexist(pCxt, pSelect);
|
code = checkWinJoinAggColCoexist(pCxt, pSelect);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = checkWindowGrpFuncCoexist(pCxt, pSelect);
|
code = checkWindowGrpFuncCoexist(pCxt, pSelect);
|
||||||
}
|
}
|
||||||
|
@ -6027,15 +6043,15 @@ static int32_t translateSetOperOrderBy(STranslateContext* pCxt, SSetOperator* pS
|
||||||
|
|
||||||
bool other;
|
bool other;
|
||||||
int32_t code = translateOrderByPosition(pCxt, pSetOperator->pProjectionList, pSetOperator->pOrderByList, &other);
|
int32_t code = translateOrderByPosition(pCxt, pSetOperator->pProjectionList, pSetOperator->pOrderByList, &other);
|
||||||
/*
|
/*
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
if (other) {
|
if (other) {
|
||||||
pCxt->currClause = SQL_CLAUSE_ORDER_BY;
|
pCxt->currClause = SQL_CLAUSE_ORDER_BY;
|
||||||
pCxt->pCurrStmt = (SNode*)pSetOperator;
|
pCxt->pCurrStmt = (SNode*)pSetOperator;
|
||||||
code = translateExprList(pCxt, pSetOperator->pOrderByList);
|
code = translateExprList(pCxt, pSetOperator->pOrderByList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
*/
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = replaceOrderByAlias(pCxt, pSetOperator->pProjectionList, pSetOperator->pOrderByList, true, true);
|
code = replaceOrderByAlias(pCxt, pSetOperator->pProjectionList, pSetOperator->pOrderByList, true, true);
|
||||||
}
|
}
|
||||||
|
@ -7029,6 +7045,12 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray, bool calB
|
||||||
FOREACH(pNode, pList) {
|
FOREACH(pNode, pList) {
|
||||||
SColumnDefNode* pCol = (SColumnDefNode*)pNode;
|
SColumnDefNode* pCol = (SColumnDefNode*)pNode;
|
||||||
SFieldWithOptions field = {.type = pCol->dataType.type, .bytes = calcTypeBytes(pCol->dataType)};
|
SFieldWithOptions field = {.type = pCol->dataType.type, .bytes = calcTypeBytes(pCol->dataType)};
|
||||||
|
if (calBytes) {
|
||||||
|
field.bytes = calcTypeBytes(pCol->dataType);
|
||||||
|
} else {
|
||||||
|
field.bytes = pCol->dataType.bytes;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(field.name, pCol->colName);
|
strcpy(field.name, pCol->colName);
|
||||||
if (pCol->pOptions) {
|
if (pCol->pOptions) {
|
||||||
setColEncode(&field.compress, columnEncodeVal(((SColumnOptions*)pCol->pOptions)->encode));
|
setColEncode(&field.compress, columnEncodeVal(((SColumnOptions*)pCol->pOptions)->encode));
|
||||||
|
|
Loading…
Reference in New Issue