提交 7ad5e742 编写于 作者: C Cary Xu

ajust STSma definition

上级 ab90c9f5
...@@ -1856,19 +1856,27 @@ typedef enum { ...@@ -1856,19 +1856,27 @@ typedef enum {
TD_TIME_UNIT_MICROSEC = 9, TD_TIME_UNIT_MICROSEC = 9,
TD_TIME_UNIT_NANOSEC = 10 TD_TIME_UNIT_NANOSEC = 10
} ETDTimeUnit; } ETDTimeUnit;
typedef struct {
uint16_t funcId;
uint16_t nColIds;
col_id_t* colIds; // sorted colIds
} SFuncColIds;
typedef struct { typedef struct {
uint8_t version; // for compatibility uint8_t version; // for compatibility
uint8_t intervalUnit; uint8_t intervalUnit;
uint8_t slidingUnit; uint8_t slidingUnit;
char indexName[TSDB_INDEX_NAME_LEN + 1]; char indexName[TSDB_INDEX_NAME_LEN];
col_id_t numOfColIds; char timezone[TD_TIMEZONE_LEN];
uint16_t numOfFuncIds; uint16_t nFuncColIds;
uint64_t tableUid; // super/common table uid uint16_t tagsFilterLen;
int64_t interval; tb_uid_t tableUid; // super/common table uid
int64_t sliding; int64_t interval;
col_id_t* colIds; // sorted column ids int64_t sliding;
uint16_t* funcIds; // sorted sma function ids SFuncColIds* funcColIds; // sorted funcIds
} STSma; // Time-range-wise SMA char* tagsFilter;
} STSma; // Time-range-wise SMA
typedef struct { typedef struct {
int64_t ver; // use a general definition int64_t ver; // use a general definition
...@@ -1877,13 +1885,13 @@ typedef struct { ...@@ -1877,13 +1885,13 @@ typedef struct {
typedef struct { typedef struct {
int8_t type; // 0 status report, 1 update data int8_t type; // 0 status report, 1 update data
char indexName[TSDB_INDEX_NAME_LEN + 1]; // char indexName[TSDB_INDEX_NAME_LEN]; //
STimeWindow windows; STimeWindow windows;
} STSmaMsg; } STSmaMsg;
typedef struct { typedef struct {
int64_t ver; // use a general definition int64_t ver; // use a general definition
char indexName[TSDB_INDEX_NAME_LEN + 1]; char indexName[TSDB_INDEX_NAME_LEN];
} SVDropTSmaReq; } SVDropTSmaReq;
typedef struct { typedef struct {
} SVCreateTSmaRsp, SVDropTSmaRsp; } SVCreateTSmaRsp, SVDropTSmaRsp;
...@@ -1934,8 +1942,14 @@ typedef struct { ...@@ -1934,8 +1942,14 @@ typedef struct {
static FORCE_INLINE void tdDestroyTSma(STSma* pSma) { static FORCE_INLINE void tdDestroyTSma(STSma* pSma) {
if (pSma) { if (pSma) {
tfree(pSma->colIds); if (pSma->funcColIds != NULL) {
tfree(pSma->funcIds); for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
tfree((pSma->funcColIds + i)->colIds);
}
tfree(pSma->funcColIds);
}
tfree(pSma->tagsFilter);
} }
} }
...@@ -1957,18 +1971,24 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) { ...@@ -1957,18 +1971,24 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
tlen += taosEncodeFixedU8(buf, pSma->intervalUnit); tlen += taosEncodeFixedU8(buf, pSma->intervalUnit);
tlen += taosEncodeFixedU8(buf, pSma->slidingUnit); tlen += taosEncodeFixedU8(buf, pSma->slidingUnit);
tlen += taosEncodeString(buf, pSma->indexName); tlen += taosEncodeString(buf, pSma->indexName);
tlen += taosEncodeFixedU16(buf, pSma->numOfColIds); tlen += taosEncodeString(buf, pSma->timezone);
tlen += taosEncodeFixedU16(buf, pSma->numOfFuncIds); tlen += taosEncodeFixedU16(buf, pSma->nFuncColIds);
tlen += taosEncodeFixedU64(buf, pSma->tableUid); tlen += taosEncodeFixedU16(buf, pSma->tagsFilterLen);
tlen += taosEncodeFixedI64(buf, pSma->tableUid);
tlen += taosEncodeFixedI64(buf, pSma->interval); tlen += taosEncodeFixedI64(buf, pSma->interval);
tlen += taosEncodeFixedI64(buf, pSma->sliding); tlen += taosEncodeFixedI64(buf, pSma->sliding);
for (col_id_t i = 0; i < pSma->numOfColIds; ++i) { for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
tlen += taosEncodeFixedU16(buf, *(pSma->colIds + i)); SFuncColIds* funcColIds = pSma->funcColIds + i;
tlen += taosEncodeFixedU16(buf, funcColIds->funcId);
tlen += taosEncodeFixedU16(buf, funcColIds->nColIds);
for (uint16_t j = 0; j < funcColIds->nColIds; ++j) {
tlen += taosEncodeFixedU16(buf, *(funcColIds->colIds + j));
}
} }
for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) { if (pSma->tagsFilterLen > 0) {
tlen += taosEncodeFixedU16(buf, *(pSma->funcIds + i)); tlen += taosEncodeString(buf, pSma->tagsFilter);
} }
return tlen; return tlen;
...@@ -1989,34 +2009,52 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) { ...@@ -1989,34 +2009,52 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
buf = taosDecodeFixedU8(buf, &pSma->intervalUnit); buf = taosDecodeFixedU8(buf, &pSma->intervalUnit);
buf = taosDecodeFixedU8(buf, &pSma->slidingUnit); buf = taosDecodeFixedU8(buf, &pSma->slidingUnit);
buf = taosDecodeStringTo(buf, pSma->indexName); buf = taosDecodeStringTo(buf, pSma->indexName);
buf = taosDecodeFixedU16(buf, &pSma->numOfColIds); buf = taosDecodeStringTo(buf, pSma->timezone);
buf = taosDecodeFixedU16(buf, &pSma->numOfFuncIds); buf = taosDecodeFixedU16(buf, &pSma->nFuncColIds);
buf = taosDecodeFixedU64(buf, &pSma->tableUid); buf = taosDecodeFixedU16(buf, &pSma->tagsFilterLen);
buf = taosDecodeFixedI64(buf, &pSma->tableUid);
buf = taosDecodeFixedI64(buf, &pSma->interval); buf = taosDecodeFixedI64(buf, &pSma->interval);
buf = taosDecodeFixedI64(buf, &pSma->sliding); buf = taosDecodeFixedI64(buf, &pSma->sliding);
if (pSma->numOfColIds > 0) { if (pSma->nFuncColIds > 0) {
pSma->colIds = (col_id_t*)calloc(pSma->numOfColIds, sizeof(STSma)); pSma->funcColIds = (SFuncColIds*)calloc(pSma->nFuncColIds, sizeof(SFuncColIds));
if (pSma->colIds == NULL) { if (pSma->funcColIds == NULL) {
tdDestroyTSma(pSma);
return NULL; return NULL;
} }
for (uint16_t i = 0; i < pSma->numOfColIds; ++i) { for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
buf = taosDecodeFixedU16(buf, pSma->colIds + i); SFuncColIds* funcColIds = pSma->funcColIds + i;
buf = taosDecodeFixedU16(buf, &funcColIds->funcId);
buf = taosDecodeFixedU16(buf, &funcColIds->nColIds);
if (funcColIds->nColIds > 0) {
funcColIds->colIds = (col_id_t*)calloc(funcColIds->nColIds, sizeof(col_id_t));
if (funcColIds->colIds != NULL) {
for (uint16_t j = 0; j < funcColIds->nColIds; ++j) {
buf = taosDecodeFixedU16(buf, funcColIds->colIds + j);
}
} else {
tdDestroyTSma(pSma);
return NULL;
}
} else {
funcColIds->colIds = NULL;
}
} }
} else { } else {
pSma->colIds = NULL; pSma->funcColIds = NULL;
} }
if (pSma->numOfFuncIds > 0) { if (pSma->tagsFilterLen > 0) {
pSma->funcIds = (uint16_t*)calloc(pSma->numOfFuncIds, sizeof(STSma)); pSma->tagsFilter = (char*)calloc(pSma->tagsFilterLen, 1);
if (pSma->funcIds == NULL) { if (pSma->tagsFilter != NULL) {
buf = taosDecodeStringTo(buf, pSma->tagsFilter);
} else {
tdDestroyTSma(pSma);
return NULL; return NULL;
} }
for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) {
buf = taosDecodeFixedU16(buf, pSma->funcIds + i);
}
} else { } else {
pSma->funcIds = NULL; pSma->tagsFilter = NULL;
} }
return buf; return buf;
......
...@@ -207,7 +207,7 @@ typedef enum ELogicConditionType { ...@@ -207,7 +207,7 @@ typedef enum ELogicConditionType {
#define TSDB_FUNC_TYPE_AGGREGATE 2 #define TSDB_FUNC_TYPE_AGGREGATE 2
#define TSDB_FUNC_MAX_RETRIEVE 1024 #define TSDB_FUNC_MAX_RETRIEVE 1024
#define TSDB_INDEX_NAME_LEN 32 #define TSDB_INDEX_NAME_LEN 33 // 32 + 1 '\0'
#define TSDB_TYPE_STR_MAX_LEN 32 #define TSDB_TYPE_STR_MAX_LEN 32
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN) #define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN #define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN
......
...@@ -43,12 +43,30 @@ typedef struct { ...@@ -43,12 +43,30 @@ typedef struct {
STsdbFSMeta meta; // FS meta STsdbFSMeta meta; // FS meta
SArray * df; // data file array SArray * df; // data file array
// SArray * v2f100.tsma.index_name // SArray * v2t100.index_name
SArray * smaf; // sma data file array v2f1900.tsma.index_name SArray * smaf; // sma data file array v2t1900.index_name
} SFSStatus; } SFSStatus;
typedef struct { /**
* @brief Directory structure of .tsma data files.
*
* root@cary /vnode2/tsdb $ tree .tsma/
* .tsma/
* ├── v2t100.index_name_1
* ├── v2t101.index_name_1
* ├── v2t102.index_name_1
* ├── v2t1900.index_name_3
* ├── v2t1901.index_name_3
* ├── v2t1902.index_name_3
* ├── v2t200.index_name_2
* ├── v2t201.index_name_2
* └── v2t202.index_name_2
*
* 0 directories, 9 files
*/
typedef struct {
pthread_rwlock_t lock; pthread_rwlock_t lock;
SFSStatus *cstatus; // current status SFSStatus *cstatus; // current status
......
...@@ -56,8 +56,8 @@ typedef enum { ...@@ -56,8 +56,8 @@ typedef enum {
TSDB_FILE_SMAL, // .smal(Block-wise SMA) TSDB_FILE_SMAL, // .smal(Block-wise SMA)
TSDB_FILE_MAX, // TSDB_FILE_MAX, //
TSDB_FILE_META, // meta TSDB_FILE_META, // meta
TSDB_FILE_TSMA, // .tsma.${sma_index_name}, Time-range-wise SMA TSDB_FILE_TSMA, // v2t100.${sma_index_name}, Time-range-wise SMA
TSDB_FILE_RSMA, // .rsma.${sma_index_name}, Time-range-wise Rollup SMA TSDB_FILE_RSMA, // v2r100.${sma_index_name}, Time-range-wise Rollup SMA
} E_TSDB_FILE_T; } E_TSDB_FILE_T;
typedef int32_t TSDB_FILE_T; typedef int32_t TSDB_FILE_T;
......
...@@ -31,7 +31,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW ...@@ -31,7 +31,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW
int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg); int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg);
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result); int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
int32_t tsdbFreeSmaState(SSmaStat *pSmaStat); int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
// internal func // internal func
......
...@@ -23,8 +23,8 @@ static const char *TSDB_FNAME_SUFFIX[] = { ...@@ -23,8 +23,8 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"smal", // TSDB_FILE_SMAL "smal", // TSDB_FILE_SMAL
"", // TSDB_FILE_MAX "", // TSDB_FILE_MAX
"meta", // TSDB_FILE_META "meta", // TSDB_FILE_META
"tsma", // TSDB_FILE_TSMA "sma", // TSDB_FILE_TSMA(directory name)
"rsma", // TSDB_FILE_RSMA "sma", // TSDB_FILE_RSMA(directory name)
}; };
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname); static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);
......
...@@ -89,7 +89,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, ...@@ -89,7 +89,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg,
static void tsdbFree(STsdb *pTsdb) { static void tsdbFree(STsdb *pTsdb) {
if (pTsdb) { if (pTsdb) {
tsdbFreeFS(pTsdb->fs); tsdbFreeFS(pTsdb->fs);
tsdbFreeSmaState(pTsdb->pSmaStat); tsdbDestroySmaState(pTsdb->pSmaStat);
tfree(pTsdb->path); tfree(pTsdb->path);
free(pTsdb); free(pTsdb);
} }
......
...@@ -128,7 +128,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) { ...@@ -128,7 +128,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
return pItem; return pItem;
} }
int32_t tsdbFreeSmaState(SSmaStat *pSmaStat) { int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
if (pSmaStat) { if (pSmaStat) {
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready. // TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL); SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
...@@ -404,7 +404,7 @@ static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaData *pData, i ...@@ -404,7 +404,7 @@ static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaData *pData, i
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) { static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) {
pSmaH->pTsdb = pTsdb; pSmaH->pTsdb = pTsdb;
pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision); pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision);
pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); // pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
} }
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t storageLevel, static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t storageLevel,
...@@ -582,7 +582,7 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) { ...@@ -582,7 +582,7 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) { static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) {
pSmaH->pTsdb = pTsdb; pSmaH->pTsdb = pTsdb;
pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision); pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision);
pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); // pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
} }
/** /**
......
...@@ -42,17 +42,20 @@ TEST(testCase, tSmaEncodeDecodeTest) { ...@@ -42,17 +42,20 @@ TEST(testCase, tSmaEncodeDecodeTest) {
tSma.slidingUnit = TD_TIME_UNIT_HOUR; tSma.slidingUnit = TD_TIME_UNIT_HOUR;
tSma.sliding = 0; tSma.sliding = 0;
tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN); tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN);
tstrncpy(tSma.timezone, "Asia/Shanghai", TD_TIMEZONE_LEN);
tSma.tableUid = 1234567890; tSma.tableUid = 1234567890;
tSma.numOfColIds = 2; tSma.nFuncColIds = 5;
tSma.numOfFuncIds = 5; // sum/min/max/avg/last tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds));
tSma.colIds = (col_id_t *)calloc(tSma.numOfColIds, sizeof(col_id_t)); ASSERT(tSma.funcColIds != NULL);
tSma.funcIds = (uint16_t *)calloc(tSma.numOfFuncIds, sizeof(uint16_t)); for (int32_t n = 0; n < tSma.nFuncColIds; ++n) {
SFuncColIds *funcColIds = tSma.funcColIds + n;
for (int32_t i = 0; i < tSma.numOfColIds; ++i) { funcColIds->funcId = n;
*(tSma.colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); funcColIds->nColIds = 10;
} funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t));
for (int32_t i = 0; i < tSma.numOfFuncIds; ++i) { ASSERT(funcColIds->colIds != NULL);
*(tSma.funcIds + i) = (i + 2); for (int32_t i = 0; i < funcColIds->nColIds; ++i) {
*(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
}
} }
STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma}; STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma};
...@@ -81,16 +84,21 @@ TEST(testCase, tSmaEncodeDecodeTest) { ...@@ -81,16 +84,21 @@ TEST(testCase, tSmaEncodeDecodeTest) {
EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit); EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit);
EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit); EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName); EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
EXPECT_EQ(pSma->numOfColIds, qSma->numOfColIds); EXPECT_STRCASEEQ(pSma->timezone, qSma->timezone);
EXPECT_EQ(pSma->numOfFuncIds, qSma->numOfFuncIds); EXPECT_EQ(pSma->nFuncColIds, qSma->nFuncColIds);
EXPECT_EQ(pSma->tableUid, qSma->tableUid); EXPECT_EQ(pSma->tableUid, qSma->tableUid);
EXPECT_EQ(pSma->interval, qSma->interval); EXPECT_EQ(pSma->interval, qSma->interval);
EXPECT_EQ(pSma->sliding, qSma->sliding); EXPECT_EQ(pSma->sliding, qSma->sliding);
for (uint32_t j = 0; j < pSma->numOfColIds; ++j) { EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
EXPECT_EQ(*(col_id_t *)(pSma->colIds + j), *(col_id_t *)(qSma->colIds + j)); EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
} for (uint32_t j = 0; j < pSma->nFuncColIds; ++j) {
for (uint32_t j = 0; j < pSma->numOfFuncIds; ++j) { SFuncColIds *pFuncColIds = pSma->funcColIds + j;
EXPECT_EQ(*(uint16_t *)(pSma->funcIds + j), *(uint16_t *)(qSma->funcIds + j)); SFuncColIds *qFuncColIds = qSma->funcColIds + j;
EXPECT_EQ(pFuncColIds->funcId, qFuncColIds->funcId);
EXPECT_EQ(pFuncColIds->nColIds, qFuncColIds->nColIds);
for (uint32_t k = 0; k < pFuncColIds->nColIds; ++k) {
EXPECT_EQ(*(pFuncColIds->colIds + k), *(qFuncColIds->colIds + k));
}
} }
} }
...@@ -100,9 +108,11 @@ TEST(testCase, tSmaEncodeDecodeTest) { ...@@ -100,9 +108,11 @@ TEST(testCase, tSmaEncodeDecodeTest) {
} }
TEST(testCase, tSma_DB_Put_Get_Del_Test) { TEST(testCase, tSma_DB_Put_Get_Del_Test) {
const char *smaIndexName1 = "sma_index_test_1"; const char * smaIndexName1 = "sma_index_test_1";
const char *smaIndexName2 = "sma_index_test_2"; const char * smaIndexName2 = "sma_index_test_2";
const char *smaTestDir = "./smaTest"; const char * timeZone = "Asia/Shanghai";
const char * tagsFilter = "I'm tags filter";
const char * smaTestDir = "./smaTest";
const uint64_t tbUid = 1234567890; const uint64_t tbUid = 1234567890;
const uint32_t nCntTSma = 2; const uint32_t nCntTSma = 2;
// encode // encode
...@@ -113,21 +123,27 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { ...@@ -113,21 +123,27 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
tSma.slidingUnit = TD_TIME_UNIT_HOUR; tSma.slidingUnit = TD_TIME_UNIT_HOUR;
tSma.sliding = 0; tSma.sliding = 0;
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
tstrncpy(tSma.timezone, timeZone, TD_TIMEZONE_LEN);
tSma.tableUid = tbUid; tSma.tableUid = tbUid;
tSma.numOfColIds = 2; tSma.nFuncColIds = 5;
tSma.numOfFuncIds = 5; // sum/min/max/avg/last tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds));
tSma.colIds = (col_id_t *)calloc(tSma.numOfColIds, sizeof(col_id_t)); ASSERT(tSma.funcColIds != NULL);
tSma.funcIds = (uint16_t *)calloc(tSma.numOfFuncIds, sizeof(uint16_t)); for (int32_t n = 0; n < tSma.nFuncColIds; ++n) {
SFuncColIds *funcColIds = tSma.funcColIds + n;
for (int32_t i = 0; i < tSma.numOfColIds; ++i) { funcColIds->funcId = n;
*(tSma.colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); funcColIds->nColIds = 10;
} funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t));
for (int32_t i = 0; i < tSma.numOfFuncIds; ++i) { ASSERT(funcColIds->colIds != NULL);
*(tSma.funcIds + i) = (i + 2); for (int32_t i = 0; i < funcColIds->nColIds; ++i) {
*(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
}
} }
tSma.tagsFilterLen = strlen(tagsFilter);
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
SMeta * pMeta = NULL; SMeta * pMeta = NULL;
STSma * pSmaCfg = &tSma; STSma * pSmaCfg = &tSma;
const SMetaCfg *pMetaCfg = &defaultMetaOptions; const SMetaCfg *pMetaCfg = &defaultMetaOptions;
taosRemoveDir(smaTestDir); taosRemoveDir(smaTestDir);
...@@ -152,6 +168,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { ...@@ -152,6 +168,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName1); qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName1);
assert(qSmaCfg != NULL); assert(qSmaCfg != NULL);
printf("name1 = %s\n", qSmaCfg->indexName); printf("name1 = %s\n", qSmaCfg->indexName);
printf("timezone1 = %s\n", qSmaCfg->timezone);
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid); EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
tdDestroyTSma(qSmaCfg); tdDestroyTSma(qSmaCfg);
...@@ -160,6 +178,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { ...@@ -160,6 +178,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName2); qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName2);
assert(qSmaCfg != NULL); assert(qSmaCfg != NULL);
printf("name2 = %s\n", qSmaCfg->indexName); printf("name2 = %s\n", qSmaCfg->indexName);
printf("timezone2 = %s\n", qSmaCfg->timezone);
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
EXPECT_EQ(qSmaCfg->interval, tSma.interval); EXPECT_EQ(qSmaCfg->interval, tSma.interval);
tdDestroyTSma(qSmaCfg); tdDestroyTSma(qSmaCfg);
...@@ -170,7 +190,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { ...@@ -170,7 +190,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
assert(pSmaCur != NULL); assert(pSmaCur != NULL);
uint32_t indexCnt = 0; uint32_t indexCnt = 0;
while (1) { while (1) {
const char* indexName = metaSmaCursorNext(pSmaCur); const char *indexName = metaSmaCursorNext(pSmaCur);
if (indexName == NULL) { if (indexName == NULL) {
break; break;
} }
...@@ -185,10 +205,14 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { ...@@ -185,10 +205,14 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
assert(pSW != NULL); assert(pSW != NULL);
EXPECT_EQ(pSW->number, nCntTSma); EXPECT_EQ(pSW->number, nCntTSma);
EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
EXPECT_STRCASEEQ(pSW->tSma->timezone, timeZone);
EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
EXPECT_EQ(pSW->tSma->tableUid, tSma.tableUid); EXPECT_EQ(pSW->tSma->tableUid, tSma.tableUid);
EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
EXPECT_STRCASEEQ((pSW->tSma + 1)->timezone, timeZone);
EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
EXPECT_EQ((pSW->tSma + 1)->tableUid, tSma.tableUid); EXPECT_EQ((pSW->tSma + 1)->tableUid, tSma.tableUid);
tdDestroyTSmaWrapper(pSW); tdDestroyTSmaWrapper(pSW);
tfree(pSW); tfree(pSW);
...@@ -210,11 +234,11 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { ...@@ -210,11 +234,11 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
metaClose(pMeta); metaClose(pMeta);
} }
#if 1 #if 0
TEST(testCase, tSmaInsertTest) { TEST(testCase, tSmaInsertTest) {
STSma tSma = {0}; STSma tSma = {0};
STSmaData* pSmaData = NULL; STSmaData *pSmaData = NULL;
STsdb tsdb = {0}; STsdb tsdb = {0};
// init // init
tSma.intervalUnit = TD_TIME_UNIT_DAY; tSma.intervalUnit = TD_TIME_UNIT_DAY;
...@@ -227,7 +251,7 @@ TEST(testCase, tSmaInsertTest) { ...@@ -227,7 +251,7 @@ TEST(testCase, tSmaInsertTest) {
int32_t dataLen = numOfColIds * numOfBlocks * blockSize; int32_t dataLen = numOfColIds * numOfBlocks * blockSize;
pSmaData = (STSmaData*)malloc(sizeof(STSmaData) + dataLen); pSmaData = (STSmaData *)malloc(sizeof(STSmaData) + dataLen);
ASSERT_EQ(pSmaData != NULL, true); ASSERT_EQ(pSmaData != NULL, true);
pSmaData->tableUid = 3232329230; pSmaData->tableUid = 3232329230;
pSmaData->numOfColIds = numOfColIds; pSmaData->numOfColIds = numOfColIds;
...@@ -235,7 +259,7 @@ TEST(testCase, tSmaInsertTest) { ...@@ -235,7 +259,7 @@ TEST(testCase, tSmaInsertTest) {
pSmaData->dataLen = dataLen; pSmaData->dataLen = dataLen;
pSmaData->tsWindow.skey = 1640000000; pSmaData->tsWindow.skey = 1640000000;
pSmaData->tsWindow.ekey = 1645788649; pSmaData->tsWindow.ekey = 1645788649;
pSmaData->colIds = (col_id_t*)malloc(sizeof(col_id_t) * numOfColIds); pSmaData->colIds = (col_id_t *)malloc(sizeof(col_id_t) * numOfColIds);
ASSERT_EQ(pSmaData->colIds != NULL, true); ASSERT_EQ(pSmaData->colIds != NULL, true);
for (int32_t i = 0; i < numOfColIds; ++i) { for (int32_t i = 0; i < numOfColIds; ++i) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册