From db03fcce117d8b877f8f116a29cadf264ba3ee48 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 17 Jun 2020 17:33:01 +0800 Subject: [PATCH] [td-225] refactor code and fix bugs in slimit_alter_tags.sim --- .../{tscSecondaryMerge.h => tscLocalMerge.h} | 0 src/client/inc/tscUtil.h | 2 +- src/client/src/tscAsync.c | 3 +- src/client/src/tscFunctionImpl.c | 6 +- src/client/src/tscLocal.c | 1 - .../{tscSecondaryMerge.c => tscLocalMerge.c} | 2 +- src/client/src/tscServer.c | 115 +----------------- src/client/src/tscSql.c | 5 - src/client/src/tscSubquery.c | 2 +- src/client/src/tscUtil.c | 4 +- src/common/src/tdataformat.c | 2 +- src/common/src/ttypes.c | 12 +- src/inc/taosdef.h | 2 +- src/query/src/qExecutor.c | 4 +- src/query/src/tvariant.c | 5 +- .../general/parser/slimit_alter_tags.sim | 8 +- tests/script/general/parser/testSuite.sim | 20 +-- 17 files changed, 36 insertions(+), 157 deletions(-) rename src/client/inc/{tscSecondaryMerge.h => tscLocalMerge.h} (100%) rename src/client/src/{tscSecondaryMerge.c => tscLocalMerge.c} (99%) diff --git a/src/client/inc/tscSecondaryMerge.h b/src/client/inc/tscLocalMerge.h similarity index 100% rename from src/client/inc/tscSecondaryMerge.h rename to src/client/inc/tscLocalMerge.h diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 32b266cf43..581ce00a62 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -28,7 +28,7 @@ extern "C" { #include "exception.h" #include "qextbuffer.h" #include "taosdef.h" -#include "tscSecondaryMerge.h" +#include "tscLocalMerge.h" #include "tsclient.h" #define UTIL_TABLE_IS_SUPER_TABLE(metaInfo) \ diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 7755224389..ccea187124 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -19,9 +19,8 @@ #include "tnote.h" #include "trpc.h" #include "tscLog.h" -#include "tscProfile.h" #include "tscSubquery.h" -#include "tscSecondaryMerge.h" +#include "tscLocalMerge.h" #include "tscUtil.h" #include "tsched.h" #include "tschemautil.h" diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index cf72aa2460..e34e0f5ce2 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -153,7 +153,7 @@ typedef struct SRateInfo { int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { - if (!isValidDataType(dataType, dataBytes)) { + if (!isValidDataType(dataType)) { tscError("Illegal data type %d or data type length %d", dataType, dataBytes); return TSDB_CODE_TSC_INVALID_SQL; } @@ -2989,12 +2989,12 @@ static void tag_project_function_f(SQLFunctionCtx *pCtx, int32_t index) { */ static void tag_function(SQLFunctionCtx *pCtx) { SET_VAL(pCtx, 1, 1); - tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->tag.nType, true); + tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->outputType, true); } static void tag_function_f(SQLFunctionCtx *pCtx, int32_t index) { SET_VAL(pCtx, 1, 1); - tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->tag.nType, true); + tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->outputType, true); } static void copy_function(SQLFunctionCtx *pCtx) { diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index a880f4487e..9007121af4 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -22,7 +22,6 @@ #include "taosdef.h" #include "tscLog.h" #include "qextbuffer.h" -#include "tscSecondaryMerge.h" #include "tschemautil.h" #include "tname.h" diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscLocalMerge.c similarity index 99% rename from src/client/src/tscSecondaryMerge.c rename to src/client/src/tscLocalMerge.c index fd9ac533fd..05bc60a8ab 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -13,7 +13,6 @@ * along with this program. If not, see . */ -#include "tscSecondaryMerge.h" #include "os.h" #include "tlosertree.h" #include "tscUtil.h" @@ -21,6 +20,7 @@ #include "tsclient.h" #include "tutil.h" #include "tscLog.h" +#include "tscLocalMerge.h" typedef struct SCompareParam { SLocalDataSource **pLocalData; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 8a6d9d02a8..5a2054bbcd 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -14,20 +14,18 @@ */ #include "os.h" +#include "qsqltype.h" #include "tcache.h" #include "trpc.h" +#include "tscLocalMerge.h" +#include "tscLog.h" #include "tscProfile.h" -#include "tscSecondaryMerge.h" -#include "tscSubquery.h" #include "tscUtil.h" #include "tschemautil.h" #include "tsclient.h" -#include "tsocket.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" -#include "tscLog.h" -#include "qsqltype.h" #define TSC_MGMT_VNODE 999 @@ -1933,113 +1931,6 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) { } int tscProcessSTableVgroupRsp(SSqlObj *pSql) { -#if 0 - void ** metricMetaList = NULL; - int32_t * sizes = NULL; - - int32_t num = htons(*(int16_t *)rsp); - rsp += sizeof(int16_t); - - metricMetaList = calloc(1, POINTER_BYTES * num); - sizes = calloc(1, sizeof(int32_t) * num); - - // return with error code - if (metricMetaList == NULL || sizes == NULL) { - tfree(metricMetaList); - tfree(sizes); - pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; - - return pSql->res.code; - } - - for (int32_t k = 0; k < num; ++k) { - pMeta = (SSuperTableMeta *)rsp; - - size_t size = (size_t)pSql->res.rspLen - 1; - rsp = rsp + sizeof(SSuperTableMeta); - - pMeta->numOfTables = htonl(pMeta->numOfTables); - pMeta->numOfVnodes = htonl(pMeta->numOfVnodes); - pMeta->tagLen = htons(pMeta->tagLen); - - size += pMeta->numOfVnodes * sizeof(SVnodeSidList *) + pMeta->numOfTables * sizeof(STableIdInfo *); - - char *pBuf = calloc(1, size); - if (pBuf == NULL) { - pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; - goto _error_clean; - } - - SSuperTableMeta *pNewMetricMeta = (SSuperTableMeta *)pBuf; - metricMetaList[k] = pNewMetricMeta; - - pNewMetricMeta->numOfTables = pMeta->numOfTables; - pNewMetricMeta->numOfVnodes = pMeta->numOfVnodes; - pNewMetricMeta->tagLen = pMeta->tagLen; - - pBuf = pBuf + sizeof(SSuperTableMeta) + pNewMetricMeta->numOfVnodes * sizeof(SVnodeSidList *); - - for (int32_t i = 0; i < pMeta->numOfVnodes; ++i) { - SVnodeSidList *pSidLists = (SVnodeSidList *)rsp; - memcpy(pBuf, pSidLists, sizeof(SVnodeSidList)); - - pNewMetricMeta->list[i] = pBuf - (char *)pNewMetricMeta; // offset value - SVnodeSidList *pLists = (SVnodeSidList *)pBuf; - - tscTrace("%p metricmeta:vid:%d,numOfTables:%d", pSql, i, pLists->numOfSids); - - pBuf += sizeof(SVnodeSidList) + sizeof(STableIdInfo *) * pSidLists->numOfSids; - rsp += sizeof(SVnodeSidList); - - size_t elemSize = sizeof(STableIdInfo) + pNewMetricMeta->tagLen; - for (int32_t j = 0; j < pSidLists->numOfSids; ++j) { - pLists->pSidExtInfoList[j] = pBuf - (char *)pLists; - memcpy(pBuf, rsp, elemSize); - - ((STableIdInfo *)pBuf)->uid = htobe64(((STableIdInfo *)pBuf)->uid); - ((STableIdInfo *)pBuf)->sid = htonl(((STableIdInfo *)pBuf)->sid); - - rsp += elemSize; - pBuf += elemSize; - } - } - - sizes[k] = pBuf - (char *)pNewMetricMeta; - } - - SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); - for (int32_t i = 0; i < num; ++i) { - char name[TSDB_MAX_TAGS_LEN + 1] = {0}; - - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); - tscGetMetricMetaCacheKey(pQueryInfo, name, pTableMetaInfo->pTableMeta->uid); - -#ifdef _DEBUG_VIEW - printf("generate the metric key:%s, index:%d\n", name, i); -#endif - - // release the used metricmeta - taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pMetricMeta), false); - pTableMetaInfo->pMetricMeta = (SSuperTableMeta *)taosCachePut(tscCacheHandle, name, (char *)metricMetaList[i], - sizes[i], tsMetricMetaKeepTimer); - tfree(metricMetaList[i]); - - // failed to put into cache - if (pTableMetaInfo->pMetricMeta == NULL) { - pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; - goto _error_clean; - } - } - -_error_clean: - // free allocated resource - for (int32_t i = 0; i < num; ++i) { - tfree(metricMetaList[i]); - } - - free(sizes); - free(metricMetaList); -#endif SSqlRes* pRes = &pSql->res; // NOTE: the order of several table must be preserved. diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 6f043f186a..126e34704c 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -20,14 +20,9 @@ #include "tnote.h" #include "trpc.h" #include "tscLog.h" -#include "tscProfile.h" -#include "tscSecondaryMerge.h" #include "tscSubquery.h" #include "tscUtil.h" #include "tsclient.h" -#include "tscompression.h" -#include "tsocket.h" -#include "ttimer.h" #include "ttokendef.h" #include "tutil.h" diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 2ec02bb425..239df6c682 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1193,7 +1193,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter SSchema s1 = {.colId = s->colId, .type = type, .bytes = bytes}; pSupporter->tagSize = s1.bytes; - assert(isValidDataType(s1.type, 0) && s1.bytes > 0); + assert(isValidDataType(s1.type) && s1.bytes > 0); // set get tags query type TSDB_QUERY_SET_TYPE(pNewQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 04b8ab8376..01f2bb7dd5 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -22,7 +22,7 @@ #include "tkey.h" #include "tmd5.h" #include "tscProfile.h" -#include "tscSecondaryMerge.h" +#include "tscLocalMerge.h" #include "tscSubquery.h" #include "tschemautil.h" #include "tsclient.h" @@ -32,7 +32,7 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo); static void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache); - + SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) { if (pTagCond->pCond == NULL) { return NULL; diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index 40cdac9833..8dcbbf2c0b 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -105,7 +105,7 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { } int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int32_t bytes) { - if (!isValidDataType(type, 0)) return -1; + if (!isValidDataType(type)) return -1; if (pBuilder->nCols >= pBuilder->tCols) { pBuilder->tCols *= 2; diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 4aee027c0b..3c63e2deac 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -363,16 +363,8 @@ char tTokenTypeSwitcher[13] = { TSDB_DATA_TYPE_NCHAR, // TK_NCHAR }; -bool isValidDataType(int32_t type, int32_t length) { - if (type < TSDB_DATA_TYPE_NULL || type > TSDB_DATA_TYPE_NCHAR) { - return false; - } - - if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { -// return length >= 0 && length <= TSDB_MAX_BINARY_LEN; - } - - return true; +bool isValidDataType(int32_t type) { + return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_NCHAR; } bool isNull(const char *val, int32_t type) { diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 7490de90d0..8b82e1f149 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -156,7 +156,7 @@ typedef struct tDataTypeDescriptor { extern tDataTypeDescriptor tDataTypeDesc[11]; #define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*) -bool isValidDataType(int32_t type, int32_t length); +bool isValidDataType(int32_t type); bool isNull(const char *val, int32_t type); void setVardataNull(char* val, int32_t type); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 2dff94bee0..b131c7a8e0 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1400,7 +1400,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order pCtx->inputType = pQuery->colList[index].type; } - assert(isValidDataType(pCtx->inputType, pCtx->inputBytes)); + assert(isValidDataType(pCtx->inputType)); pCtx->ptsOutputBuf = NULL; pCtx->outputBytes = pQuery->pSelectExpr[i].bytes; @@ -5315,7 +5315,7 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * if (pExprs[i].base.functionId == TSDB_FUNC_TAG_DUMMY || pExprs[i].base.functionId == TSDB_FUNC_TS_DUMMY) { tagLen += pExprs[i].bytes; } - assert(isValidDataType(pExprs[i].type, pExprs[i].bytes)); + assert(isValidDataType(pExprs[i].type)); } // TODO refactor diff --git a/src/query/src/tvariant.c b/src/query/src/tvariant.c index 7ba4e7899e..1650db6cfd 100644 --- a/src/query/src/tvariant.c +++ b/src/query/src/tvariant.c @@ -474,6 +474,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result free(pVariant->pz); pVariant->nLen = 0; } + setNull((char *)result, type, tDataTypeDesc[type].nSize); return 0; } @@ -597,10 +598,10 @@ static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) { * todo handle the return value */ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix) { - if (pVariant == NULL || (pVariant->nType != 0 && !isValidDataType(pVariant->nType, pVariant->nLen))) { + if (pVariant == NULL || (pVariant->nType != 0 && !isValidDataType(pVariant->nType))) { return -1; } - + errno = 0; // reset global error code switch (type) { diff --git a/tests/script/general/parser/slimit_alter_tags.sim b/tests/script/general/parser/slimit_alter_tags.sim index 54bc868f6a..e8e81e8809 100644 --- a/tests/script/general/parser/slimit_alter_tags.sim +++ b/tests/script/general/parser/slimit_alter_tags.sim @@ -84,11 +84,13 @@ while $i < 10 sql alter table $tb set tag tg_added = $tg_added $i = $i + 1 endw -sql describe tb0 -if $rows != 7 then + +sql select t1,t2,tg_added from tb0 +if $rows != 1 then return -1 endi -if $data63 != tb0 then + +if $data02 != tb0 then return -1 endi diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index 5b629112da..f288288fb7 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -1,12 +1,12 @@ -#run general/parser/alter.sim -#sleep 2000 -#run general/parser/alter1.sim -#sleep 2000 -#run general/parser/alter_stable.sim -#sleep 2000 -#run general/parser/auto_create_tb.sim -#sleep 2000 -#run general/parser/auto_create_tb_drop_tb.sim +run general/parser/alter.sim +sleep 2000 +run general/parser/alter1.sim +sleep 2000 +run general/parser/alter_stable.sim +sleep 2000 +run general/parser/auto_create_tb.sim +sleep 2000 +run general/parser/auto_create_tb_drop_tb.sim sleep 2000 run general/parser/col_arithmetic_operation.sim @@ -84,7 +84,7 @@ sleep 2000 run general/parser/set_tag_vals.sim sleep 2000 -run general/parser/slimit_alter_tags.sim +run general/parser/slimit_alter_tags.sim # persistent failed sleep 2000 run general/parser/join.sim -- GitLab