diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index a8ab715edf667eeb926ee5892545fa02dc9e16af..c62b830a6973f792976fde578b6794872cd9915c 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -134,8 +134,8 @@ typedef struct SJoinNode { } SJoinNode; typedef struct SJoinInfo { - bool hasJoin; - SJoinNode* joinTables[TSDB_MAX_JOIN_TABLE_NUM]; + bool hasJoin; + SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM]; } SJoinInfo; typedef struct STagCond { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index eb27c01ede2eee89129ba6303465428f12204ab0..e6c2ca12bcd45b2018cf0388a2b6fedd23fe48bd 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3678,10 +3678,14 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr SSchema* pLeftSchema = tscGetTableSchema(pLeftMeterMeta->pTableMeta); int16_t leftType = pLeftSchema[pLeftIndex->columnIndex].type; + tscColumnListInsert(pQueryInfo->colList, pLeftIndex->columnIndex, pLeftMeterMeta->pTableMeta->id.uid, &pLeftSchema[pLeftIndex->columnIndex]); + STableMetaInfo* pRightMeterMeta = tscGetMetaInfo(pQueryInfo, rightIndex.tableIndex); SSchema* pRightSchema = tscGetTableSchema(pRightMeterMeta->pTableMeta); int16_t rightType = pRightSchema[rightIndex.columnIndex].type; + tscColumnListInsert(pQueryInfo->colList, rightIndex.columnIndex, pRightMeterMeta->pTableMeta->id.uid, &pRightSchema[rightIndex.columnIndex]); + if (leftType != rightType) { invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return false; @@ -3846,7 +3850,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql taosArrayPush((*rightNode)->tsJoin, &leftIdx); /* - * to release expression, e.g., m1.ts = m2.ts, + * To release expression, e.g., m1.ts = m2.ts, * since this expression is used to set the join query type */ tSqlExprDestroy(*pExpr); diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 5e43469f7be760ae6fe93c480a1e2a213cf923b8..2686473d87a6cf09fd8c68143b1a4dfaaf600abf 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -23,9 +23,15 @@ typedef struct SFillEssInfo { int32_t fillType; // fill type - int64_t *val; // fill value + int64_t *val; // fill value } SFillEssInfo; +typedef struct SJoinCond { + bool tagExists; // denote if tag condition exists or not + SColumn *tagCond[2]; + SColumn *colCond[2]; +} SJoinCond; + static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** prev, int32_t numOfPrev, SExprInfo** pExpr, int32_t numOfOutput, SQueryTableInfo* pTableInfo, void* pExtInfo) { @@ -92,8 +98,8 @@ static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** return pNode; } -static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, - SQueryTableInfo* info, SArray* pExprs, SArray* tableCols) { +static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SQueryTableInfo* info, + SArray* pExprs, SArray* tableCols) { if (pQueryInfo->onlyTagQuery) { int32_t num = taosArrayGetSize(pExprs); SQueryNode* pNode = createQueryNode(QNODE_TAGSCAN, "TableTagScan", NULL, 0, pExprs->pData, num, info, NULL); @@ -232,28 +238,12 @@ SArray* createQueryPlanImpl(SQueryInfo* pQueryInfo) { tNameExtractFullName(&pTableMetaInfo->name, name); SQueryTableInfo info = {.tableName = strdup(name), .id = pTableMetaInfo->pTableMeta->id,}; - // 3. add the join columns (the tags and the primary timestamp column) - tscInsertPrimaryTsSourceColumn(pQueryInfo, info.id.uid); - + // 3. get the required table column list SArray* tableColumnList = taosArrayInit(4, sizeof(SColumn)); tscColumnListCopy(tableColumnList, pQueryInfo->colList, uid); - // TODO add the tag column into the required column list - if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - int16_t tagColId = tscGetJoinTagColIdByUid(&pQueryInfo->tagCond, info.id.uid); - SSchema* s = tscGetColumnSchemaById(pTableMetaInfo->pTableMeta, tagColId); - - SColumn* col = calloc(1, sizeof(SColumn)); - col->tableUid = info.id.uid; - col->info.colId = tagColId; - col->info.type = s->type; - col->info.bytes = s->bytes; - taosArrayPush(pQueryInfo->colList, &col); - } - // 4. add the projection query node SQueryNode* pNode = doAddTableColumnNode(pQueryInfo, pTableMetaInfo, &info, exprList, tableColumnList); - taosArrayPush(upstream, &pNode); } @@ -497,7 +487,7 @@ static int32_t doPrintPlan(char* buf, SQueryNode* pQueryNode, int32_t level, int case QNODE_JOIN: { // print join condition - len1 = sprintf(buf + len, "\n"); + len1 = sprintf(buf + len, ")\n"); len += len1; break; } diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index fb8f164ed3f2920767c61dd08969a7435002f9d4..ed4ac111417cfc4a0369230b7840a0e532950306 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -229,7 +229,6 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) { pExpr->flags &= ~(1 << EXPR_FLAG_TS_ERROR); } - switch (optrType) { case TK_PLUS: { pExpr->value.i64 = pLeft->value.i64 + pRight->value.i64;