diff --git a/include/common/ttime.h b/include/common/ttime.h index 3de0b98d85217f142a903c6e42c257bba5f299b9..cd704bb1f7971526cbfacc9f6167852d21b8ec5d 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -59,10 +59,11 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) { * precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond. */ static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) { - int64_t factor = (precision == TSDB_TIME_PRECISION_MILLI) ? 1000 : - (precision == TSDB_TIME_PRECISION_MICRO) ? 1000000 : 1000000000; - time_t t = taosTime(NULL); - struct tm * tm= taosLocalTime(&t, NULL); + int64_t factor = (precision == TSDB_TIME_PRECISION_MILLI) ? 1000 + : (precision == TSDB_TIME_PRECISION_MICRO) ? 1000000 + : 1000000000; + time_t t = taosTime(NULL); + struct tm* tm = taosLocalTime(&t, NULL); tm->tm_hour = 0; tm->tm_min = 0; tm->tm_sec = 0; @@ -79,13 +80,13 @@ int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* durati int32_t taosParseTime(const char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth); void deltaToUtcInitOnce(); -char getPrecisionUnit(int32_t precision); +char getPrecisionUnit(int32_t precision); int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision); int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit); -int32_t convertStringToTimestamp(int16_t type, char *inputData, int64_t timePrec, int64_t *timeVal); +int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec, int64_t* timeVal); -void taosFormatUtcTime(char *buf, int32_t bufLen, int64_t time, int32_t precision); +void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t time, int32_t precision); #ifdef __cplusplus } diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index c390f67153fd6be27ad7a8b05cd97762ceeba016..711db65e97db07414a55a709eacfbdc2b57e774f 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -51,14 +51,12 @@ typedef struct STableComInfo { } STableComInfo; typedef struct SIndexMeta { - #ifdef WINDOWS size_t avoidCompilationErrors; #endif } SIndexMeta; - /* * ASSERT(sizeof(SCTableMeta) == 24) * ASSERT(tableType == TSDB_CHILD_TABLE) @@ -95,7 +93,7 @@ typedef struct SDBVgInfo { int32_t vgVersion; int8_t hashMethod; int32_t numOfTable; // DB's table num, unit is TSDB_TABLE_NUM_UNIT - SHashObj *vgHash; //key:vgId, value:SVgroupInfo + SHashObj* vgHash; // key:vgId, value:SVgroupInfo } SDBVgInfo; typedef struct SUseDbOutput { @@ -135,7 +133,7 @@ typedef struct SMsgSendInfo { } SMsgSendInfo; typedef struct SQueryNodeStat { - int32_t tableNum; // vg table number, unit is TSDB_TABLE_NUM_UNIT + int32_t tableNum; // vg table number, unit is TSDB_TABLE_NUM_UNIT } SQueryNodeStat; int32_t initTaskQueue(); @@ -172,7 +170,7 @@ const SSchema* tGetTbnameColumnSchema(); bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta); -char *jobTaskStatusStr(int32_t status); +char* jobTaskStatusStr(int32_t status); SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name); @@ -184,62 +182,87 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE #define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE -#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST) -#define NEED_CLIENT_REFRESH_VG_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) +#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \ + ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST) +#define NEED_CLIENT_REFRESH_VG_ERROR(_code) \ + ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) #define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED) -#define NEED_CLIENT_HANDLE_ERROR(_code) (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code)) +#define NEED_CLIENT_HANDLE_ERROR(_code) \ + (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \ + NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code)) -#define NEED_SCHEDULER_RETRY_ERROR(_code) ((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL) +#define NEED_SCHEDULER_RETRY_ERROR(_code) \ + ((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL) #define REQUEST_MAX_TRY_TIMES 5 -#define qFatal(...) \ - do { \ - if (qDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); \ - } \ +#define qFatal(...) \ + do { \ + if (qDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("QRY FATAL ", DEBUG_FATAL, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define qError(...) \ - do { \ - if (qDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); \ - } \ +#define qError(...) \ + do { \ + if (qDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("QRY ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define qWarn(...) \ - do { \ - if (qDebugFlag & DEBUG_WARN) { \ - taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); \ - } \ +#define qWarn(...) \ + do { \ + if (qDebugFlag & DEBUG_WARN) { \ + taosPrintLog("QRY WARN ", DEBUG_WARN, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define qInfo(...) \ - do { \ - if (qDebugFlag & DEBUG_INFO) { \ - taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); \ - } \ +#define qInfo(...) \ + do { \ + if (qDebugFlag & DEBUG_INFO) { \ + taosPrintLog("QRY ", DEBUG_INFO, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define qDebug(...) \ - do { \ - if (qDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \ - } \ +#define qDebug(...) \ + do { \ + if (qDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("QRY ", DEBUG_DEBUG, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define qTrace(...) \ - do { \ - if (qDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); \ - } \ +#define qTrace(...) \ + do { \ + if (qDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("QRY ", DEBUG_TRACE, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define qDebugL(...) \ - do { \ - if (qDebugFlag & DEBUG_DEBUG) { \ - taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \ - } \ +#define qDebugL(...) \ + do { \ + if (qDebugFlag & DEBUG_DEBUG) { \ + taosPrintLongString("QRY ", DEBUG_DEBUG, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define QRY_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define QRY_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define QRY_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) - +#define QRY_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define QRY_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) +#define QRY_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ + } while (0) #ifdef __cplusplus } diff --git a/include/util/taoserror.h b/include/util/taoserror.h index a0d7b59cf9289851b192acd68c229869a89e7b8c..03f445b498c133b796d8609884aa57ccea48ea8d 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -636,6 +636,8 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_PERMISSION_DENIED TAOS_DEF_ERROR_CODE(0, 0x2644) #define TSDB_CODE_PAR_INVALID_STREAM_QUERY TAOS_DEF_ERROR_CODE(0, 0x2645) #define TSDB_CODE_PAR_INVALID_INTERNAL_PK TAOS_DEF_ERROR_CODE(0, 0x2646) +#define TSDB_CODE_PAR_INVALID_TIMELINE_FUNC TAOS_DEF_ERROR_CODE(0, 0x2647) +#define TSDB_CODE_PAR_INVALID_PASSWD TAOS_DEF_ERROR_CODE(0, 0x2648) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 94238073c6a53905edb5ec5e879b75c4ff3c7df4..666e9e0ffac0bb3f92c592d5d237051b80e16268 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -172,7 +172,8 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, .pTransporter = pTscObj->pAppInfo->pTransporter, .pStmtCb = pStmtCb, - .pUser = pTscObj->user}; + .pUser = pTscObj->user, + .isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER))}; cxt.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); int32_t code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &cxt.pCatalog); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 6e0775ff17de6f8f89eeb19a6aa0ddc6f835480a..57dfcaedddcff22135d575dfa728d85cfe6a9852 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -318,15 +318,19 @@ static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) { STableComInfo* pNode = (STableComInfo*)pObj; int32_t code; - tjsonGetNumberValue(pJson, jkTableComInfoNumOfTags, pNode->numOfTags, code);; + tjsonGetNumberValue(pJson, jkTableComInfoNumOfTags, pNode->numOfTags, code); + ; if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableComInfoPrecision, pNode->precision, code);; + tjsonGetNumberValue(pJson, jkTableComInfoPrecision, pNode->precision, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableComInfoNumOfColumns, pNode->numOfColumns, code);; + tjsonGetNumberValue(pJson, jkTableComInfoNumOfColumns, pNode->numOfColumns, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableComInfoRowSize, pNode->rowSize, code);; + tjsonGetNumberValue(pJson, jkTableComInfoRowSize, pNode->rowSize, code); + ; } return code; @@ -358,12 +362,15 @@ static int32_t jsonToSchema(const SJson* pJson, void* pObj) { SSchema* pNode = (SSchema*)pObj; int32_t code; - tjsonGetNumberValue(pJson, jkSchemaType, pNode->type, code);; + tjsonGetNumberValue(pJson, jkSchemaType, pNode->type, code); + ; if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkSchemaColId, pNode->colId, code);; + tjsonGetNumberValue(pJson, jkSchemaColId, pNode->colId, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkSchemaBytes, pNode->bytes, code);; + tjsonGetNumberValue(pJson, jkSchemaBytes, pNode->bytes, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetStringValue(pJson, jkSchemaName, pNode->name); @@ -415,21 +422,27 @@ static int32_t jsonToTableMeta(const SJson* pJson, void* pObj) { STableMeta* pNode = (STableMeta*)pObj; int32_t code; - tjsonGetNumberValue(pJson, jkTableMetaVgId, pNode->vgId, code);; + tjsonGetNumberValue(pJson, jkTableMetaVgId, pNode->vgId, code); + ; if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableMetaTableType, pNode->tableType, code);; + tjsonGetNumberValue(pJson, jkTableMetaTableType, pNode->tableType, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableMetaUid, pNode->uid, code);; + tjsonGetNumberValue(pJson, jkTableMetaUid, pNode->uid, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableMetaSuid, pNode->suid, code);; + tjsonGetNumberValue(pJson, jkTableMetaSuid, pNode->suid, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableMetaSversion, pNode->sversion, code);; + tjsonGetNumberValue(pJson, jkTableMetaSversion, pNode->sversion, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableMetaTversion, pNode->tversion, code);; + tjsonGetNumberValue(pJson, jkTableMetaTversion, pNode->tversion, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = tjsonToObject(pJson, jkTableMetaComInfo, jsonToTableComInfo, &pNode->tableInfo); @@ -605,7 +618,8 @@ static int32_t jsonToLogicFillNode(const SJson* pJson, void* pObj) { int32_t code = jsonToLogicPlanNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkFillLogicPlanMode, pNode->mode, code);; + tjsonGetNumberValue(pJson, jkFillLogicPlanMode, pNode->mode, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkFillLogicPlanWStartTs, &pNode->pWStartTs); @@ -881,7 +895,8 @@ static int32_t jsonToLogicSubplan(const SJson* pJson, void* pObj) { code = jsonToNodeObject(pJson, jkLogicSubplanRootNode, (SNode**)&pNode->pNode); } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkLogicSubplanType, pNode->subplanType, code);; + tjsonGetNumberValue(pJson, jkLogicSubplanType, pNode->subplanType, code); + ; } int32_t objSize = 0; if (TSDB_CODE_SUCCESS == code) { @@ -1121,33 +1136,43 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) { code = tjsonGetDoubleValue(pJson, jkTableScanPhysiPlanRatio, &pNode->ratio); } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired, code);; + tjsonGetNumberValue(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkTableScanPhysiPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs); } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableScanPhysiPlanInterval, pNode->interval, code);; + tjsonGetNumberValue(pJson, jkTableScanPhysiPlanInterval, pNode->interval, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableScanPhysiPlanOffset, pNode->offset, code);; + tjsonGetNumberValue(pJson, jkTableScanPhysiPlanOffset, pNode->offset, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableScanPhysiPlanSliding, pNode->sliding, code);; + tjsonGetNumberValue(pJson, jkTableScanPhysiPlanSliding, pNode->sliding, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableScanPhysiPlanIntervalUnit, pNode->intervalUnit, code);; + tjsonGetNumberValue(pJson, jkTableScanPhysiPlanIntervalUnit, pNode->intervalUnit, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkTableScanPhysiPlanSlidingUnit, pNode->slidingUnit, code);; + tjsonGetNumberValue(pJson, jkTableScanPhysiPlanSlidingUnit, pNode->slidingUnit, code); + ; } return code; } -static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { return physiTableScanNodeToJson(pObj, pJson); } +static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { + return physiTableScanNodeToJson(pObj, pJson); +} -static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiTableScanNode(pJson, pObj); } +static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { + return jsonToPhysiTableScanNode(pJson, pObj); +} static const char* jkSysTableScanPhysiPlanMnodeEpSet = "MnodeEpSet"; static const char* jkSysTableScanPhysiPlanShowRewrite = "ShowRewrite"; @@ -1181,7 +1206,8 @@ static int32_t jsonToPhysiSysTableScanNode(const SJson* pJson, void* pObj) { code = tjsonGetBoolValue(pJson, jkSysTableScanPhysiPlanShowRewrite, &pNode->showRewrite); } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId, code);; + tjsonGetNumberValue(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId, code); + ; } return code; @@ -1265,7 +1291,8 @@ static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) { int32_t code = jsonToPhysicPlanNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkJoinPhysiPlanJoinType, pNode->joinType, code);; + tjsonGetNumberValue(pJson, jkJoinPhysiPlanJoinType, pNode->joinType, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions); @@ -1427,10 +1454,12 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) { code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk); } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType, code);; + tjsonGetNumberValue(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkWindowPhysiPlanWatermark, pNode->watermark, code);; + tjsonGetNumberValue(pJson, jkWindowPhysiPlanWatermark, pNode->watermark, code); + ; } return code; @@ -1526,7 +1555,8 @@ static int32_t jsonToPhysiFillNode(const SJson* pJson, void* pObj) { int32_t code = jsonToPhysicPlanNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkFillPhysiPlanMode, pNode->mode, code);; + tjsonGetNumberValue(pJson, jkFillPhysiPlanMode, pNode->mode, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkFillPhysiPlanWStartTs, &pNode->pWStartTs); @@ -1565,7 +1595,8 @@ static int32_t jsonToPhysiSessionWindowNode(const SJson* pJson, void* pObj) { int32_t code = jsonToPhysiWindowNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkSessionWindowPhysiPlanGap, pNode->gap, code);; + tjsonGetNumberValue(pJson, jkSessionWindowPhysiPlanGap, pNode->gap, code); + ; } return code; @@ -1727,7 +1758,8 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) { int32_t code = tjsonToObject(pJson, jkSubplanId, jsonToSubplanId, &pNode->id); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkSubplanType, pNode->subplanType, code);; + tjsonGetNumberValue(pJson, jkSubplanType, pNode->subplanType, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetIntValue(pJson, jkSubplanMsgType, &pNode->msgType); @@ -1917,7 +1949,8 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) { code = tjsonGetSmallIntValue(pJson, jkColumnColId, &pNode->colId); } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkColumnColType, pNode->colType, code);; + tjsonGetNumberValue(pJson, jkColumnColType, pNode->colType, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetStringValue(pJson, jkColumnDbName, pNode->dbName); @@ -2171,7 +2204,8 @@ static int32_t jsonToOperatorNode(const SJson* pJson, void* pObj) { int32_t code = jsonToExprNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkOperatorType, pNode->opType, code);; + tjsonGetNumberValue(pJson, jkOperatorType, pNode->opType, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkOperatorLeft, &pNode->pLeft); @@ -2205,7 +2239,8 @@ static int32_t jsonToLogicConditionNode(const SJson* pJson, void* pObj) { int32_t code = jsonToExprNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkLogicCondType, pNode->condType, code);; + tjsonGetNumberValue(pJson, jkLogicCondType, pNode->condType, code); + ; } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkLogicCondParameters, &pNode->pParameterList); @@ -2350,6 +2385,30 @@ static int32_t jsonToRealTableNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkTempTableSubquery = "Subquery"; + +static int32_t tempTableNodeToJson(const void* pObj, SJson* pJson) { + const STempTableNode* pNode = (const STempTableNode*)pObj; + + int32_t code = tableNodeToJson(pObj, pJson); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkTempTableSubquery, nodeToJson, pNode->pSubquery); + } + + return code; +} + +static int32_t jsonToTempTableNode(const SJson* pJson, void* pObj) { + STempTableNode* pNode = (STempTableNode*)pObj; + + int32_t code = jsonToTableNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkTempTableSubquery, &pNode->pSubquery); + } + + return code; +} + static const char* jkGroupingSetType = "GroupingSetType"; static const char* jkGroupingSetParameter = "Parameters"; @@ -2387,10 +2446,12 @@ static int32_t jsonToOrderByExprNode(const SJson* pJson, void* pObj) { int32_t code = jsonToNodeObject(pJson, jkOrderByExprExpr, &pNode->pExpr); if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkOrderByExprOrder, pNode->order, code);; + tjsonGetNumberValue(pJson, jkOrderByExprOrder, pNode->order, code); + ; } if (TSDB_CODE_SUCCESS == code) { - tjsonGetNumberValue(pJson, jkOrderByExprNullOrder, pNode->nullOrder, code);; + tjsonGetNumberValue(pJson, jkOrderByExprNullOrder, pNode->nullOrder, code); + ; } return code; @@ -2497,7 +2558,8 @@ static int32_t jsonToFillNode(const SJson* pJson, void* pObj) { SFillNode* pNode = (SFillNode*)pObj; int32_t code; - tjsonGetNumberValue(pJson, jkFillMode, pNode->mode, code);; + tjsonGetNumberValue(pJson, jkFillMode, pNode->mode, code); + ; if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkFillValues, &pNode->pValues); } @@ -2663,6 +2725,60 @@ static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkSetOperatorOpType = "OpType"; +static const char* jkSetOperatorProjections = "Projections"; +static const char* jkSetOperatorLeft = "Left"; +static const char* jkSetOperatorRight = "Right"; +static const char* jkSetOperatorOrderByList = "OrderByList"; +static const char* jkSetOperatorLimit = "Limit"; + +static int32_t setOperatorToJson(const void* pObj, SJson* pJson) { + const SSetOperator* pNode = (const SSetOperator*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkSetOperatorOpType, pNode->opType); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkSetOperatorProjections, pNode->pProjectionList); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkSetOperatorLeft, nodeToJson, pNode->pLeft); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkSetOperatorRight, nodeToJson, pNode->pRight); + } + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkSetOperatorOrderByList, pNode->pOrderByList); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkSetOperatorLimit, nodeToJson, pNode->pLimit); + } + + return code; +} + +static int32_t jsonToSetOperator(const SJson* pJson, void* pObj) { + SSetOperator* pNode = (SSetOperator*)pObj; + + int32_t code = TSDB_CODE_SUCCESS; + tjsonGetNumberValue(pJson, jkSetOperatorOpType, pNode->opType, code); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkSetOperatorProjections, &pNode->pProjectionList); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkSetOperatorLeft, &pNode->pLeft); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkSetOperatorRight, &pNode->pRight); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkSetOperatorOrderByList, &pNode->pOrderByList); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkSetOperatorLimit, &pNode->pLimit); + } + + return code; +} + static const char* jkSelectStmtDistinct = "Distinct"; static const char* jkSelectStmtProjections = "Projections"; static const char* jkSelectStmtFrom = "From"; @@ -2677,7 +2793,7 @@ static const char* jkSelectStmtSlimit = "Slimit"; static const char* jkSelectStmtStmtName = "StmtName"; static const char* jkSelectStmtHasAggFuncs = "HasAggFuncs"; -static int32_t selectStmtTojson(const void* pObj, SJson* pJson) { +static int32_t selectStmtToJson(const void* pObj, SJson* pJson) { const SSelectStmt* pNode = (const SSelectStmt*)pObj; int32_t code = tjsonAddBoolToObject(pJson, jkSelectStmtDistinct, pNode->isDistinct); @@ -2819,6 +2935,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { case QUERY_NODE_REAL_TABLE: return realTableNodeToJson(pObj, pJson); case QUERY_NODE_TEMP_TABLE: + return tempTableNodeToJson(pObj, pJson); case QUERY_NODE_JOIN_TABLE: break; case QUERY_NODE_GROUPING_SET: @@ -2848,9 +2965,9 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { case QUERY_NODE_DOWNSTREAM_SOURCE: return downstreamSourceNodeToJson(pObj, pJson); case QUERY_NODE_SET_OPERATOR: - break; + return setOperatorToJson(pObj, pJson); case QUERY_NODE_SELECT_STMT: - return selectStmtTojson(pObj, pJson); + return selectStmtToJson(pObj, pJson); case QUERY_NODE_VNODE_MODIF_STMT: case QUERY_NODE_CREATE_DATABASE_STMT: case QUERY_NODE_CREATE_TABLE_STMT: @@ -2918,7 +3035,6 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { case QUERY_NODE_PHYSICAL_PLAN: return planToJson(pObj, pJson); default: - // assert(0); break; } nodesWarn("specificNodeToJson unknown node = %s", nodesNodeName(nodeType(pObj))); @@ -2939,6 +3055,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToFunctionNode(pJson, pObj); case QUERY_NODE_REAL_TABLE: return jsonToRealTableNode(pJson, pObj); + case QUERY_NODE_TEMP_TABLE: + return jsonToTempTableNode(pJson, pObj); case QUERY_NODE_ORDER_BY_EXPR: return jsonToOrderByExprNode(pJson, pObj); case QUERY_NODE_INTERVAL_WINDOW: @@ -2955,6 +3073,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToSlotDescNode(pJson, pObj); case QUERY_NODE_DOWNSTREAM_SOURCE: return jsonToDownstreamSourceNode(pJson, pObj); + case QUERY_NODE_SET_OPERATOR: + return jsonToSetOperator(pJson, pObj); case QUERY_NODE_SELECT_STMT: return jsonToSelectStmt(pJson, pObj); case QUERY_NODE_CREATE_TOPIC_STMT: @@ -3007,7 +3127,6 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { case QUERY_NODE_PHYSICAL_PLAN: return jsonToPlan(pJson, pObj); default: - assert(0); break; } nodesWarn("jsonToSpecificNode unknown node = %s", nodesNodeName(nodeType(pObj))); @@ -3038,7 +3157,8 @@ static int32_t jsonToNode(const SJson* pJson, void* pObj) { SNode* pNode = (SNode*)pObj; int32_t code; - tjsonGetNumberValue(pJson, jkNodeType, pNode->type, code);; + tjsonGetNumberValue(pJson, jkNodeType, pNode->type, code); + ; if (TSDB_CODE_SUCCESS == code) { code = tjsonToObject(pJson, nodesNodeName(pNode->type), jsonToSpecificNode, pNode); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 639da98f48d44150760686a771846abfc18c6f1e..7dc2978ec7928b329af0ae40d812f3440b237df8 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -14,6 +14,8 @@ * along with this program. If not, see . */ +#include + #include "parAst.h" #include "parUtil.h" #include "ttime.h" @@ -76,6 +78,19 @@ static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) { return TSDB_CODE_SUCCESS == pCxt->errCode; } +static bool invalidPassword(const char* pPassword) { + regex_t regex; + + if (regcomp(®ex, "[ '\"`\\]", REG_EXTENDED | REG_ICASE) != 0) { + return false; + } + + /* Execute regular expression */ + int32_t res = regexec(®ex, pPassword, 0, NULL, 0); + regfree(®ex); + return 0 == res; +} + static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, char* pPassword) { if (NULL == pPasswordToken) { pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; @@ -86,6 +101,8 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, strdequote(pPassword); if (strtrim(pPassword) <= 0) { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY); + } else if (invalidPassword(pPassword)) { + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PASSWD); } } return TSDB_CODE_SUCCESS == pCxt->errCode; diff --git a/source/libs/parser/src/parAuthenticator.c b/source/libs/parser/src/parAuthenticator.c index 8f686cefce7d8fde2640b27ece95072a1af7ce72..ad1dca68579111b9494a41255537f604dd76f5d8 100644 --- a/source/libs/parser/src/parAuthenticator.c +++ b/source/libs/parser/src/parAuthenticator.c @@ -65,13 +65,19 @@ static int32_t authSetOperator(SAuthCxt* pCxt, SSetOperator* pSetOper) { return code; } +static int32_t authDropUser(SAuthCxt* pCxt, SDropUserReq* pStmt) { + if (!pCxt->pParseCxt->isSuperUser || 0 == strcmp(pStmt->user, TSDB_DEFAULT_USER)) { + return TSDB_CODE_PAR_PERMISSION_DENIED; + } + return TSDB_CODE_SUCCESS; +} + static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) { switch (nodeType(pStmt)) { case QUERY_NODE_SET_OPERATOR: return authSetOperator(pCxt, (SSetOperator*)pStmt); case QUERY_NODE_SELECT_STMT: return authSelect(pCxt, (SSelectStmt*)pStmt); - case QUERY_NODE_VNODE_MODIF_STMT: case QUERY_NODE_CREATE_DATABASE_STMT: case QUERY_NODE_DROP_DATABASE_STMT: case QUERY_NODE_ALTER_DATABASE_STMT: @@ -84,7 +90,10 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) { case QUERY_NODE_ALTER_TABLE_STMT: case QUERY_NODE_CREATE_USER_STMT: case QUERY_NODE_ALTER_USER_STMT: - case QUERY_NODE_DROP_USER_STMT: + break; + case QUERY_NODE_DROP_USER_STMT: { + return authDropUser(pCxt, (SDropUserReq*)pStmt); + } case QUERY_NODE_USE_DATABASE_STMT: case QUERY_NODE_CREATE_DNODE_STMT: case QUERY_NODE_DROP_DNODE_STMT: diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 9c2bd106863af1d2ac21a2d26aac60fd150f69e2..646ef4cf6293eb754eb04427954104d1c2de651a 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -262,9 +262,9 @@ static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subque break; case QUERY_NODE_SET_OPERATOR: { SSetOperator* pSetOp = (SSetOperator*)pStmt; - code = calcConstQuery(pCxt, pSetOp->pLeft, subquery); + code = calcConstQuery(pCxt, pSetOp->pLeft, false); if (TSDB_CODE_SUCCESS == code) { - code = calcConstQuery(pCxt, pSetOp->pRight, subquery); + code = calcConstQuery(pCxt, pSetOp->pRight, false); } break; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 95ab1500ccd382cdf8ac9f07450761aa66bcf325..6427e13ae98112f898cf92650999939d053c6d1f 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -480,6 +480,31 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) { return res; } +static int32_t parseTimeFromValueNode(SValueNode* pVal) { + if (IS_SIGNED_NUMERIC_TYPE(pVal->node.resType.type)) { + return TSDB_CODE_SUCCESS; + } else if (IS_UNSIGNED_NUMERIC_TYPE(pVal->node.resType.type)) { + pVal->datum.i = pVal->datum.u; + return TSDB_CODE_SUCCESS; + } else if (IS_FLOAT_TYPE(pVal->node.resType.type)) { + pVal->datum.i = pVal->datum.d; + return TSDB_CODE_SUCCESS; + } else if (TSDB_DATA_TYPE_BOOL == pVal->node.resType.type) { + pVal->datum.i = pVal->datum.b; + return TSDB_CODE_SUCCESS; + } else if (IS_VAR_DATA_TYPE(pVal->node.resType.type) || TSDB_DATA_TYPE_TIMESTAMP == pVal->node.resType.type) { + if (TSDB_CODE_SUCCESS == taosParseTime(pVal->literal, &pVal->datum.i, pVal->node.resType.bytes, + pVal->node.resType.precision, tsDaylight)) { + return TSDB_CODE_SUCCESS; + } + char* pEnd = NULL; + pVal->datum.i = strtoll(pVal->literal, &pEnd, 10); + return (NULL != pEnd && '\0' == *pEnd) ? TSDB_CODE_SUCCESS : TSDB_CODE_FAILED; + } else { + return TSDB_CODE_FAILED; + } +} + static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SDataType targetDt) { uint8_t precision = (NULL != pCxt->pCurrStmt ? pCxt->pCurrStmt->precision : targetDt.precision); pVal->node.resType.precision = precision; @@ -571,7 +596,7 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD break; } case TSDB_DATA_TYPE_TIMESTAMP: { - if (taosParseTime(pVal->literal, &pVal->datum.i, targetDt.bytes, precision, tsDaylight) != TSDB_CODE_SUCCESS) { + if (TSDB_CODE_SUCCESS != parseTimeFromValueNode(pVal)) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); } *(int64_t*)&pVal->typeData = pVal->datum.i; @@ -1660,10 +1685,10 @@ static int32_t createPrimaryKeyColByTable(STranslateContext* pCxt, STableNode* p if (NULL == pCol) { return TSDB_CODE_OUT_OF_MEMORY; } - if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { - setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, false, pCol); - } else { - // todo + pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID; + strcpy(pCol->colName, PK_TS_COL_INTERNAL_NAME); + if (!findAndSetColumn(pCol, pTable)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TIMELINE_FUNC); } *pPrimaryKey = (SNode*)pCol; return TSDB_CODE_SUCCESS; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 7183d956a9f02eda15539f3a2c55a65076807cf3..0c703c9dfc40abd39a59673883c44806463a5e2b 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -148,6 +148,10 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "Invalid number of tag columns"; case TSDB_CODE_PAR_INVALID_INTERNAL_PK: return "Invalid _c0 or _rowts expression"; + case TSDB_CODE_PAR_INVALID_TIMELINE_FUNC: + return "Invalid timeline function"; + case TSDB_CODE_PAR_INVALID_PASSWD: + return "Invalid password"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp index 0ba062ebe4f8da6f497e8ea0787d12771cbd41b6..821f480b2003e7752599812f22fb664eb7f33493 100644 --- a/source/libs/parser/test/parSelectTest.cpp +++ b/source/libs/parser/test/parSelectTest.cpp @@ -187,7 +187,7 @@ TEST_F(ParserSelectTest, semanticError) { run("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE); // TSDB_CODE_PAR_WRONG_VALUE_TYPE - run("SELECT timestamp '2010' 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); // TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION run("SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, @@ -235,9 +235,11 @@ TEST_F(ParserSelectTest, semanticError) { TEST_F(ParserSelectTest, setOperator) { useDb("root", "test"); - run("SELECT * FROM t1 UNION ALL SELECT * FROM t1"); + // run("SELECT * FROM t1 UNION ALL SELECT * FROM t1"); - run("(SELECT * FROM t1) UNION ALL (SELECT * FROM t1)"); + // run("(SELECT * FROM t1) UNION ALL (SELECT * FROM t1)"); + + run("SELECT c1 FROM (SELECT c1 FROM t1 UNION ALL SELECT c1 FROM t1)"); } } // namespace ParserTest diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 9968f63c5d5a737d604b4c0f421b2cce59ce3e68..edac2a879fa9c8d6ec10cf532872ef70c82dfba8 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -582,7 +582,7 @@ static bool cpdIsPrimaryKeyEqualCond(SJoinLogicNode* pJoin, SNode* pCond) { return false; } - SOperatorNode* pOper = (SOperatorNode*)pJoin->pOnConditions; + SOperatorNode* pOper = (SOperatorNode*)pCond; if (OP_TYPE_EQUAL != pOper->opType) { return false; } @@ -608,12 +608,16 @@ static int32_t cpdCheckLogicCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, if (LOGIC_COND_TYPE_AND != pOnCond->condType) { return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PLAN_EXPECTED_TS_EQUAL); } + bool hasPrimaryKeyEqualCond = false; SNode* pCond = NULL; FOREACH(pCond, pOnCond->pParameterList) { - if (!cpdIsPrimaryKeyEqualCond(pJoin, pCond)) { - return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PLAN_EXPECTED_TS_EQUAL); + if (cpdIsPrimaryKeyEqualCond(pJoin, pCond)) { + hasPrimaryKeyEqualCond = true; } } + if (!hasPrimaryKeyEqualCond) { + return generateUsageErrMsg(pCxt->pPlanCxt->pMsg, pCxt->pPlanCxt->msgLen, TSDB_CODE_PLAN_EXPECTED_TS_EQUAL); + } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index edf44424e30cadea076da5c4943c2c3234d3f30b..affe9ef2f61f0afce95ba7f1feec5f65f23a7f1f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -261,6 +261,22 @@ typedef struct SSetSlotIdCxt { SHashObj* pRightHash; } SSetSlotIdCxt; +static void dumpSlots(const char* pName, SHashObj* pHash) { + if (NULL == pHash) { + return; + } + planDebug("%s", pName); + void* pIt = taosHashIterate(pHash, NULL); + while (NULL != pIt) { + size_t len = 0; + char* pKey = taosHashGetKey(pIt, &len); + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0}; + strncpy(name, pKey, len); + planDebug("\tslot name = %s", name); + pIt = taosHashIterate(pHash, pIt); + } +} + static EDealRes doSetSlotId(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode) && 0 != strcmp(((SColumnNode*)pNode)->colName, "*")) { SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext; @@ -273,6 +289,8 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { // pIndex is definitely not NULL, otherwise it is a bug if (NULL == pIndex) { planError("doSetSlotId failed, invalid slot name %s", name); + dumpSlots("left datablock desc", pCxt->pLeftHash); + dumpSlots("right datablock desc", pCxt->pRightHash); pCxt->errCode = TSDB_CODE_PLAN_INTERNAL_ERROR; return DEAL_RES_ERROR; } diff --git a/source/libs/planner/test/planJoinTest.cpp b/source/libs/planner/test/planJoinTest.cpp index 4098d383f8edc2461613cfb8ab9102035185b4b9..714900c4e57fb01f4f95ed405a0450937ec8c480 100644 --- a/source/libs/planner/test/planJoinTest.cpp +++ b/source/libs/planner/test/planJoinTest.cpp @@ -23,10 +23,16 @@ class PlanJoinTest : public PlannerTestBase {}; TEST_F(PlanJoinTest, basic) { useDb("root", "test"); - run("select t1.c1, t2.c2 from st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + run("SELECT t1.c1, t2.c2 FROM st1s1 t1, st1s2 t2 WHERE t1.ts = t2.ts"); - run("select t1.*, t2.* from st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + run("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 WHERE t1.ts = t2.ts"); - // run("select t1.c1, t2.c1 from st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and " - // "t2.c2 = 'qwe'"); + run("SELECT t1.c1, t2.c1 FROM st1s1 t1 JOIN st1s2 t2 ON t1.ts = t2.ts"); +} + +TEST_F(PlanJoinTest, withWhere) { + useDb("root", "test"); + + run("SELECT t1.c1, t2.c1 FROM st1s1 t1 JOIN st1s2 t2 ON t1.ts = t2.ts " + "WHERE t1.c1 > t2.c1 AND t1.c2 = 'abc' AND t2.c2 = 'qwe'"); } diff --git a/source/libs/planner/test/planSubqueryTest.cpp b/source/libs/planner/test/planSubqueryTest.cpp index f45cbc6f8f86d06fea0de5f5ce3c4e0226c4986d..11e5e980526c2129d2bd5a2676a47edcb619e32e 100644 --- a/source/libs/planner/test/planSubqueryTest.cpp +++ b/source/libs/planner/test/planSubqueryTest.cpp @@ -23,9 +23,13 @@ class PlanSubqeuryTest : public PlannerTestBase {}; TEST_F(PlanSubqeuryTest, basic) { useDb("root", "test"); - run("SELECT * FROM (SELECT * FROM t1)"); + if (0 == g_skipSql) { + run("SELECT * FROM (SELECT * FROM t1)"); - // run("SELECT LAST(c1) FROM ( SELECT * FROM t1)"); + run("SELECT LAST(c1) FROM (SELECT * FROM t1)"); + } + + run("SELECT c1 FROM (SELECT c1 FROM t1 UNION ALL SELECT c1 FROM t1)"); } TEST_F(PlanSubqeuryTest, doubleGroupBy) { diff --git a/source/libs/planner/test/planTestMain.cpp b/source/libs/planner/test/planTestMain.cpp index 464c636b66cfebf8fd84461fb2a41d804e1856c1..36f66ddff689ed7f29acc571a34d2a3a7c1e6163 100644 --- a/source/libs/planner/test/planTestMain.cpp +++ b/source/libs/planner/test/planTestMain.cpp @@ -25,23 +25,53 @@ class PlannerEnv : public testing::Environment { virtual void SetUp() { initMetaDataEnv(); generateMetaData(); + initLog("/tmp/td"); } virtual void TearDown() { destroyMetaDataEnv(); } PlannerEnv() {} virtual ~PlannerEnv() {} + + private: + void initLog(const char* path) { + dDebugFlag = 143; + vDebugFlag = 0; + mDebugFlag = 143; + cDebugFlag = 0; + jniDebugFlag = 0; + tmrDebugFlag = 135; + uDebugFlag = 135; + rpcDebugFlag = 143; + qDebugFlag = 143; + wDebugFlag = 0; + sDebugFlag = 0; + tsdbDebugFlag = 0; + tsLogEmbedded = 1; + tsAsyncLog = 0; + + taosRemoveDir(path); + taosMkDir(path); + tstrncpy(tsLogDir, path, PATH_MAX); + if (taosInitLog("taoslog", 1) != 0) { + std::cout << "failed to init log file" << std::endl; + } + } }; static void parseArg(int argc, char* argv[]) { int opt = 0; const char* optstring = ""; - static struct option long_options[] = {{"dump", optional_argument, NULL, 'd'}, {0, 0, 0, 0}}; + static struct option long_options[] = { + {"dump", optional_argument, NULL, 'd'}, {"skipSql", optional_argument, NULL, 's'}, {0, 0, 0, 0}}; while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (opt) { case 'd': setDumpModule(optarg); break; + case 's': + g_skipSql = 1; + break; default: break; } diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index b2c590667e84588bf7654738e34bc3205814b6b6..6b038ae8ea9b4f405928e93b313adb685d5b6aac 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -47,6 +47,7 @@ enum DumpModule { }; DumpModule g_dumpModule = DUMP_MODULE_NOTHING; +int32_t g_skipSql = 0; void setDumpModule(const char* pModule) { if (NULL == pModule) { diff --git a/source/libs/planner/test/planTestUtil.h b/source/libs/planner/test/planTestUtil.h index 7913ef531f1fc4cf0093db5ef0f1db8c3bdc2d35..a63bba1a97738d4386f495f75dec78e0d1c1dd7c 100644 --- a/source/libs/planner/test/planTestUtil.h +++ b/source/libs/planner/test/planTestUtil.h @@ -32,6 +32,8 @@ class PlannerTestBase : public testing::Test { std::unique_ptr impl_; }; +extern int32_t g_skipSql; + extern void setDumpModule(const char* pModule); #endif // PLAN_TEST_UTIL_H