From a5d6851cbeeab12bda42348b58cd6370ecfc88f1 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 24 Feb 2021 13:15:23 +0800 Subject: [PATCH 01/80] implement compact interfaces --- src/inc/tsdb.h | 3 +++ src/tsdb/inc/tsdbCommitQueue.h | 4 +++- src/tsdb/inc/tsdbCompact.h | 28 ++++++++++++++++++++++++++++ src/tsdb/inc/tsdbint.h | 2 ++ src/tsdb/src/tsdbCommitQueue.c | 23 +++++++++++++++++------ src/tsdb/src/tsdbCompact.c | 6 +++++- src/tsdb/src/tsdbMemTable.c | 2 +- 7 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 src/tsdb/inc/tsdbCompact.h diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 78cd2927c7..d6c9fed971 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -355,6 +355,9 @@ void tsdbDecCommitRef(int vgId); int tsdbSyncSend(void *pRepo, SOCKET socketFd); int tsdbSyncRecv(void *pRepo, SOCKET socketFd); +// For TSDB Compact +int tsdbCompact(STsdbRepo *pRepo); + #ifdef __cplusplus } #endif diff --git a/src/tsdb/inc/tsdbCommitQueue.h b/src/tsdb/inc/tsdbCommitQueue.h index c2353391f9..6342c036b7 100644 --- a/src/tsdb/inc/tsdbCommitQueue.h +++ b/src/tsdb/inc/tsdbCommitQueue.h @@ -16,6 +16,8 @@ #ifndef _TD_TSDB_COMMIT_QUEUE_H_ #define _TD_TSDB_COMMIT_QUEUE_H_ -int tsdbScheduleCommit(STsdbRepo *pRepo); +typedef enum { COMMIT_REQ, COMPACT_REQ } TSDB_REQ_T; + +int tsdbScheduleCommit(STsdbRepo *pRepo, TSDB_REQ_T req); #endif /* _TD_TSDB_COMMIT_QUEUE_H_ */ \ No newline at end of file diff --git a/src/tsdb/inc/tsdbCompact.h b/src/tsdb/inc/tsdbCompact.h new file mode 100644 index 0000000000..5a382de5e0 --- /dev/null +++ b/src/tsdb/inc/tsdbCompact.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef _TD_TSDB_COMPACT_H_ +#define _TD_TSDB_COMPACT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void *tsdbCompactImpl(STsdbRepo *pRepo); + +#ifdef __cplusplus +} +#endif + +#endif /* _TD_TSDB_COMPACT_H_ */ \ No newline at end of file diff --git a/src/tsdb/inc/tsdbint.h b/src/tsdb/inc/tsdbint.h index 074ff20f22..0a448d8194 100644 --- a/src/tsdb/inc/tsdbint.h +++ b/src/tsdb/inc/tsdbint.h @@ -64,6 +64,8 @@ extern "C" { #include "tsdbReadImpl.h" // Commit #include "tsdbCommit.h" +// Compact +#include "tsdbCompact.h" // Commit Queue #include "tsdbCommitQueue.h" // Main definitions diff --git a/src/tsdb/src/tsdbCommitQueue.c b/src/tsdb/src/tsdbCommitQueue.c index 9e8e4acd7e..d515faf861 100644 --- a/src/tsdb/src/tsdbCommitQueue.c +++ b/src/tsdb/src/tsdbCommitQueue.c @@ -26,8 +26,9 @@ typedef struct { } SCommitQueue; typedef struct { + TSDB_REQ_T req; STsdbRepo *pRepo; -} SCommitReq; +} SReq; static void *tsdbLoopCommit(void *arg); @@ -90,16 +91,17 @@ void tsdbDestroyCommitQueue() { pthread_mutex_destroy(&(pQueue->lock)); } -int tsdbScheduleCommit(STsdbRepo *pRepo) { +int tsdbScheduleCommit(STsdbRepo *pRepo, TSDB_REQ_T req) { SCommitQueue *pQueue = &tsCommitQueue; - SListNode *pNode = (SListNode *)calloc(1, sizeof(SListNode) + sizeof(SCommitReq)); + SListNode *pNode = (SListNode *)calloc(1, sizeof(SListNode) + sizeof(SReq)); if (pNode == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } - ((SCommitReq *)pNode->data)->pRepo = pRepo; + ((SReq *)pNode->data)->req = req; + ((SReq *)pNode->data)->pRepo = pRepo; pthread_mutex_lock(&(pQueue->lock)); @@ -116,6 +118,7 @@ static void *tsdbLoopCommit(void *arg) { SCommitQueue *pQueue = &tsCommitQueue; SListNode * pNode = NULL; STsdbRepo * pRepo = NULL; + TSDB_REQ_T req; while (true) { pthread_mutex_lock(&(pQueue->lock)); @@ -136,9 +139,17 @@ static void *tsdbLoopCommit(void *arg) { pthread_mutex_unlock(&(pQueue->lock)); - pRepo = ((SCommitReq *)pNode->data)->pRepo; + req = ((SReq *)pNode->data)->req; + pRepo = ((SReq *)pNode->data)->pRepo; + + if (req == COMMIT_REQ) { + tsdbCommitData(pRepo); + } else if (req == COMPACT_REQ) { + tsdbCompactImpl(pRepo); + } else { + ASSERT(0); + } - tsdbCommitData(pRepo); listNodeFree(pNode); } diff --git a/src/tsdb/src/tsdbCompact.c b/src/tsdb/src/tsdbCompact.c index 6dea4a4e57..d8cd558424 100644 --- a/src/tsdb/src/tsdbCompact.c +++ b/src/tsdb/src/tsdbCompact.c @@ -11,4 +11,8 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ +#include "tsdb.h" + +int tsdbCompact(STsdbRepo *pRepo) { return 0; } +void *tsdbCompactImpl(STsdbRepo *pRepo) { return NULL; } \ No newline at end of file diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 73a1270799..2e4a73e56b 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -232,7 +232,7 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) { if (tsdbLockRepo(pRepo) < 0) return -1; pRepo->imem = pRepo->mem; pRepo->mem = NULL; - tsdbScheduleCommit(pRepo); + tsdbScheduleCommit(pRepo, COMMIT_REQ); if (tsdbUnlockRepo(pRepo) < 0) return -1; return 0; From a46e84dce78a0f22b2dfed290b0e52a5a39f4f32 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 25 Feb 2021 15:26:57 +0800 Subject: [PATCH 02/80] partial work --- src/inc/tfs.h | 2 + src/tsdb/inc/tsdbCommit.h | 7 + src/tsdb/src/tsdbCommit.c | 330 ++++++++++++++++++++------------------ 3 files changed, 182 insertions(+), 157 deletions(-) diff --git a/src/inc/tfs.h b/src/inc/tfs.h index 76e9b17a62..26ae033ac6 100644 --- a/src/inc/tfs.h +++ b/src/inc/tfs.h @@ -31,6 +31,8 @@ typedef struct { #define TFS_UNDECIDED_ID -1 #define TFS_PRIMARY_LEVEL 0 #define TFS_PRIMARY_ID 0 +#define TFS_MIN_LEVEL 0 +#define TFS_MAX_LEVEL (TSDB_MAX_TIERS - 1) // FS APIs ==================================== typedef struct { diff --git a/src/tsdb/inc/tsdbCommit.h b/src/tsdb/inc/tsdbCommit.h index 5e740081d1..9612d15018 100644 --- a/src/tsdb/inc/tsdbCommit.h +++ b/src/tsdb/inc/tsdbCommit.h @@ -29,10 +29,17 @@ typedef struct { int64_t size; } SKVRecord; +#define TSDB_DEFAULT_BLOCK_ROWS(maxRows) ((maxRows)*4 / 5) + void tsdbGetRtnSnap(STsdbRepo *pRepo, SRtn *pRtn); int tsdbEncodeKVRecord(void **buf, SKVRecord *pRecord); void *tsdbDecodeKVRecord(void *buf, SKVRecord *pRecord); void *tsdbCommitData(STsdbRepo *pRepo); +int tsdbApplyRtnOnFSet(STsdbRepo *pRepo, SDFileSet *pSet, SRtn *pRtn); +int tsdbWriteBlockInfoImpl(SDFile *pHeadf, STable *pTable, SArray *pSupA, SArray *pSubA, void **ppBuf, SBlockIdx *pIdx); +int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf); +int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, + bool isLast, bool isSuper, void **ppBuf, void **ppCBuf); static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) { if (fid >= pRtn->maxFid) { diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index a4cc316725..5656db69a4 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -45,7 +45,7 @@ typedef struct { #define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST) #define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh)) #define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh)) -#define TSDB_COMMIT_DEFAULT_ROWS(ch) (TSDB_COMMIT_REPO(ch)->config.maxRowsPerFileBlock * 4 / 5) +#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->config.maxRowsPerFileBlock) #define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) static int tsdbCommitMeta(STsdbRepo *pRepo); @@ -66,7 +66,6 @@ static int tsdbCommitToTable(SCommitH *pCommith, int tid); static int tsdbSetCommitTable(SCommitH *pCommith, STable *pTable); static int tsdbComparKeyBlock(const void *arg1, const void *arg2); static int tsdbWriteBlockInfo(SCommitH *pCommih); -static int tsdbWriteBlockIdx(SCommitH *pCommih); static int tsdbCommitMemData(SCommitH *pCommith, SCommitIter *pIter, TSKEY keyLimit, bool toData); static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx); static int tsdbMoveBlock(SCommitH *pCommith, int bidx); @@ -81,7 +80,6 @@ static bool tsdbCanAddSubBlock(SCommitH *pCommith, SBlock *pBlock, SMergeInfo *p static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget, TSKEY maxKey, int maxRows, int8_t update); static int tsdbApplyRtn(STsdbRepo *pRepo); -static int tsdbApplyRtnOnFSet(STsdbRepo *pRepo, SDFileSet *pSet, SRtn *pRtn); void *tsdbCommitData(STsdbRepo *pRepo) { tsdbStartCommit(pRepo); @@ -109,6 +107,151 @@ _err: return NULL; } +int tsdbApplyRtnOnFSet(STsdbRepo *pRepo, SDFileSet *pSet, SRtn *pRtn) { + SDiskID did; + SDFileSet nSet; + STsdbFS * pfs = REPO_FS(pRepo); + int level; + + ASSERT(pSet->fid >= pRtn->minFid); + + level = tsdbGetFidLevel(pSet->fid, pRtn); + + tfsAllocDisk(level, &(did.level), &(did.id)); + if (did.level == TFS_UNDECIDED_LEVEL) { + terrno = TSDB_CODE_TDB_NO_AVAIL_DISK; + return -1; + } + + if (did.level > TSDB_FSET_LEVEL(pSet)) { + // Need to move the FSET to higher level + tsdbInitDFileSet(&nSet, did, REPO_ID(pRepo), pSet->fid, FS_TXN_VERSION(pfs)); + + if (tsdbCopyDFileSet(pSet, &nSet) < 0) { + tsdbError("vgId:%d failed to copy FSET %d from level %d to level %d since %s", REPO_ID(pRepo), pSet->fid, + TSDB_FSET_LEVEL(pSet), did.level, tstrerror(terrno)); + return -1; + } + + if (tsdbUpdateDFileSet(pfs, &nSet) < 0) { + return -1; + } + + tsdbInfo("vgId:%d FSET %d is copied from level %d disk id %d to level %d disk id %d", REPO_ID(pRepo), pSet->fid, + TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet), did.level, did.id); + } else { + // On a correct level + if (tsdbUpdateDFileSet(pfs, pSet) < 0) { + return -1; + } + } + + return 0; +} + +int tsdbWriteBlockInfoImpl(SDFile *pHeadf, STable *pTable, SArray *pSupA, SArray *pSubA, void **ppBuf, + SBlockIdx *pIdx) { + size_t nSupBlocks; + size_t nSubBlocks; + uint32_t tlen; + SBlockInfo *pBlkInfo; + int64_t offset; + SBlock * pBlock; + + memset(pIdx, 0, sizeof(*pIdx)); + + nSupBlocks = taosArrayGetSize(pSupA); + nSubBlocks = (pSubA == NULL) ? 0 : taosArrayGetSize(pSubA); + + if (nSupBlocks <= 0) { + // No data (data all deleted) + return 0; + } + + tlen = (uint32_t)(sizeof(SBlockInfo) + sizeof(SBlock) * (nSupBlocks + nSubBlocks) + sizeof(TSCKSUM)); + if (tsdbMakeRoom(ppBuf, tlen) < 0) return -1; + pBlkInfo = *ppBuf; + + pBlkInfo->delimiter = TSDB_FILE_DELIMITER; + pBlkInfo->tid = TABLE_TID(pTable); + pBlkInfo->uid = TABLE_UID(pTable); + + memcpy((void *)(pBlkInfo->blocks), taosArrayGet(pSupA, 0), nSupBlocks * sizeof(SBlock)); + if (nSubBlocks > 0) { + memcpy((void *)(pBlkInfo->blocks + nSupBlocks), taosArrayGet(pSubA, 0), nSubBlocks * sizeof(SBlock)); + + for (int i = 0; i < nSupBlocks; i++) { + pBlock = pBlkInfo->blocks + i; + + if (pBlock->numOfSubBlocks > 1) { + pBlock->offset += (sizeof(SBlockInfo) + sizeof(SBlock) * nSupBlocks); + } + } + } + + taosCalcChecksumAppend(0, (uint8_t *)pBlkInfo, tlen); + + if (tsdbAppendDFile(pHeadf, (void *)pBlkInfo, tlen, &offset) < 0) { + return -1; + } + + tsdbUpdateDFileMagic(pHeadf, POINTER_SHIFT(pBlkInfo, tlen - sizeof(TSCKSUM))); + + // Set pIdx + pBlock = taosArrayGetLast(pSupA); + + pIdx->tid = TABLE_TID(pTable); + pIdx->uid = TABLE_UID(pTable); + pIdx->hasLast = pBlock->last ? 1 : 0; + pIdx->maxKey = pBlock->keyLast; + pIdx->numOfBlocks = (uint32_t)nSupBlocks; + pIdx->len = tlen; + pIdx->offset = (uint32_t)offset; + + return 0; +} + +int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) { + SBlockIdx *pBlkIdx; + size_t nidx = taosArrayGetSize(pIdxA); + int tlen = 0, size; + int64_t offset; + + if (nidx <= 0) { + // All data are deleted + pHeadf->info.offset = 0; + pHeadf->info.len = 0; + return 0; + } + + for (size_t i = 0; i < nidx; i++) { + pBlkIdx = (SBlockIdx *)taosArrayGet(pIdxA, i); + + size = tsdbEncodeSBlockIdx(NULL, pBlkIdx); + if (tsdbMakeRoom(ppBuf, tlen + size) < 0) return -1; + + void *ptr = POINTER_SHIFT(*ppBuf, tlen); + tsdbEncodeSBlockIdx(&ptr, pBlkIdx); + + tlen += size; + } + + tlen += sizeof(TSCKSUM); + if (tsdbMakeRoom(ppBuf, tlen) < 0) return -1; + taosCalcChecksumAppend(0, (uint8_t *)(*ppBuf), tlen); + + if (tsdbAppendDFile(pHeadf, *ppBuf, tlen, &offset) < tlen) { + return -1; + } + + tsdbUpdateDFileMagic(pHeadf, POINTER_SHIFT(*ppBuf, tlen - sizeof(TSCKSUM))); + pHeadf->info.offset = (uint32_t)offset; + pHeadf->info.len = tlen; + + return 0; +} + + // =================== Commit Meta Data static int tsdbCommitMeta(STsdbRepo *pRepo) { STsdbFS * pfs = REPO_FS(pRepo); @@ -438,7 +581,8 @@ static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { } } - if (tsdbWriteBlockIdx(pCommith) < 0) { + if (tsdbWriteBlockIdx(TSDB_COMMIT_HEAD_FILE(pCommith), pCommith->aBlkIdx, (void **)(&(TSDB_COMMIT_BUF(pCommith)))) < + 0) { tsdbError("vgId:%d failed to write SBlockIdx part to FSET %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno)); tsdbCloseCommitFile(pCommith, true); // revert the file change @@ -738,23 +882,21 @@ static int tsdbComparKeyBlock(const void *arg1, const void *arg2) { } } -static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, bool isLast, - bool isSuper) { - STsdbRepo * pRepo = TSDB_COMMIT_REPO(pCommith); +int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, + bool isLast, bool isSuper, void **ppBuf, void **ppCBuf) { STsdbCfg * pCfg = REPO_CFG(pRepo); SBlockData *pBlockData; int64_t offset = 0; - STable * pTable = TSDB_COMMIT_TABLE(pCommith); int rowsToWrite = pDataCols->numOfRows; ASSERT(rowsToWrite > 0 && rowsToWrite <= pCfg->maxRowsPerFileBlock); ASSERT((!isLast) || rowsToWrite < pCfg->minRowsPerFileBlock); // Make buffer space - if (tsdbMakeRoom((void **)(&TSDB_COMMIT_BUF(pCommith)), TSDB_BLOCK_STATIS_SIZE(pDataCols->numOfCols)) < 0) { + if (tsdbMakeRoom(ppBuf, TSDB_BLOCK_STATIS_SIZE(pDataCols->numOfCols)) < 0) { return -1; } - pBlockData = (SBlockData *)TSDB_COMMIT_BUF(pCommith); + pBlockData = (SBlockData *)(*ppBuf); // Get # of cols not all NULL(not including key column) int nColsNotAllNull = 0; @@ -800,23 +942,23 @@ static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCo void * tptr; // Make room - if (tsdbMakeRoom((void **)(&TSDB_COMMIT_BUF(pCommith)), lsize + tlen + COMP_OVERFLOW_BYTES + sizeof(TSCKSUM)) < 0) { + if (tsdbMakeRoom(ppBuf, lsize + tlen + COMP_OVERFLOW_BYTES + sizeof(TSCKSUM)) < 0) { return -1; } - pBlockData = (SBlockData *)TSDB_COMMIT_BUF(pCommith); + pBlockData = (SBlockData *)(*ppBuf); pBlockCol = pBlockData->cols + tcol; tptr = POINTER_SHIFT(pBlockData, lsize); if (pCfg->compression == TWO_STAGE_COMP && - tsdbMakeRoom((void **)(&TSDB_COMMIT_COMP_BUF(pCommith)), tlen + COMP_OVERFLOW_BYTES) < 0) { + tsdbMakeRoom(ppCBuf, tlen + COMP_OVERFLOW_BYTES) < 0) { return -1; } // Compress or just copy if (pCfg->compression) { flen = (*(tDataTypes[pDataCol->type].compFunc))((char *)pDataCol->pData, tlen, rowsToWrite, tptr, - tlen + COMP_OVERFLOW_BYTES, pCfg->compression, - TSDB_COMMIT_COMP_BUF(pCommith), tlen + COMP_OVERFLOW_BYTES); + tlen + COMP_OVERFLOW_BYTES, pCfg->compression, *ppCBuf, + tlen + COMP_OVERFLOW_BYTES); } else { flen = tlen; memcpy(tptr, pDataCol->pData, flen); @@ -872,68 +1014,27 @@ static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCo return 0; } +static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, bool isLast, + bool isSuper) { + return tsdbWriteBlockImpl(TSDB_COMMIT_REPO(pCommith), TSDB_COMMIT_TABLE(pCommith), pDFile, pDataCols, pBlock, isLast, + isSuper, (void **)(&(TSDB_COMMIT_BUF(pCommith))), + (void **)(&(TSDB_COMMIT_COMP_BUF(pCommith)))); +} + + static int tsdbWriteBlockInfo(SCommitH *pCommih) { - SDFile * pHeadf = TSDB_COMMIT_HEAD_FILE(pCommih); - SBlockIdx blkIdx; - STable * pTable = TSDB_COMMIT_TABLE(pCommih); - SBlock * pBlock; - size_t nSupBlocks; - size_t nSubBlocks; - uint32_t tlen; - SBlockInfo *pBlkInfo; - int64_t offset; + SDFile * pHeadf = TSDB_COMMIT_HEAD_FILE(pCommih); + SBlockIdx blkIdx; + STable * pTable = TSDB_COMMIT_TABLE(pCommih); - nSupBlocks = taosArrayGetSize(pCommih->aSupBlk); - nSubBlocks = taosArrayGetSize(pCommih->aSubBlk); - - if (nSupBlocks <= 0) { - // No data (data all deleted) - return 0; - } - - tlen = (uint32_t)(sizeof(SBlockInfo) + sizeof(SBlock) * (nSupBlocks + nSubBlocks) + sizeof(TSCKSUM)); - - // Write SBlockInfo part - if (tsdbMakeRoom((void **)(&(TSDB_COMMIT_BUF(pCommih))), tlen) < 0) return -1; - pBlkInfo = TSDB_COMMIT_BUF(pCommih); - - pBlkInfo->delimiter = TSDB_FILE_DELIMITER; - pBlkInfo->tid = TABLE_TID(pTable); - pBlkInfo->uid = TABLE_UID(pTable); - - memcpy((void *)(pBlkInfo->blocks), taosArrayGet(pCommih->aSupBlk, 0), nSupBlocks * sizeof(SBlock)); - if (nSubBlocks > 0) { - memcpy((void *)(pBlkInfo->blocks + nSupBlocks), taosArrayGet(pCommih->aSubBlk, 0), nSubBlocks * sizeof(SBlock)); - - for (int i = 0; i < nSupBlocks; i++) { - pBlock = pBlkInfo->blocks + i; - - if (pBlock->numOfSubBlocks > 1) { - pBlock->offset += (sizeof(SBlockInfo) + sizeof(SBlock) * nSupBlocks); - } - } - } - - taosCalcChecksumAppend(0, (uint8_t *)pBlkInfo, tlen); - - if (tsdbAppendDFile(pHeadf, TSDB_COMMIT_BUF(pCommih), tlen, &offset) < 0) { + if (tsdbWriteBlockInfoImpl(pHeadf, pTable, pCommih->aSupBlk, pCommih->aSubBlk, (void **)(&(TSDB_COMMIT_BUF(pCommih))), + &blkIdx) < 0) { return -1; } - tsdbUpdateDFileMagic(pHeadf, POINTER_SHIFT(pBlkInfo, tlen - sizeof(TSCKSUM))); - - // Set blkIdx - pBlock = taosArrayGet(pCommih->aSupBlk, nSupBlocks - 1); - - blkIdx.tid = TABLE_TID(pTable); - blkIdx.uid = TABLE_UID(pTable); - blkIdx.hasLast = pBlock->last ? 1 : 0; - blkIdx.maxKey = pBlock->keyLast; - blkIdx.numOfBlocks = (uint32_t)nSupBlocks; - blkIdx.len = tlen; - blkIdx.offset = (uint32_t)offset; - - ASSERT(blkIdx.numOfBlocks > 0); + if (blkIdx.numOfBlocks == 0) { + return 0; + } if (taosArrayPush(pCommih->aBlkIdx, (void *)(&blkIdx)) == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -943,49 +1044,6 @@ static int tsdbWriteBlockInfo(SCommitH *pCommih) { return 0; } -static int tsdbWriteBlockIdx(SCommitH *pCommih) { - SBlockIdx *pBlkIdx; - SDFile * pHeadf = TSDB_COMMIT_HEAD_FILE(pCommih); - size_t nidx = taosArrayGetSize(pCommih->aBlkIdx); - int tlen = 0, size; - int64_t offset; - - if (nidx <= 0) { - // All data are deleted - pHeadf->info.offset = 0; - pHeadf->info.len = 0; - return 0; - } - - for (size_t i = 0; i < nidx; i++) { - pBlkIdx = (SBlockIdx *)taosArrayGet(pCommih->aBlkIdx, i); - - size = tsdbEncodeSBlockIdx(NULL, pBlkIdx); - if (tsdbMakeRoom((void **)(&TSDB_COMMIT_BUF(pCommih)), tlen + size) < 0) return -1; - - void *ptr = POINTER_SHIFT(TSDB_COMMIT_BUF(pCommih), tlen); - tsdbEncodeSBlockIdx(&ptr, pBlkIdx); - - tlen += size; - } - - tlen += sizeof(TSCKSUM); - if (tsdbMakeRoom((void **)(&TSDB_COMMIT_BUF(pCommih)), tlen) < 0) return -1; - taosCalcChecksumAppend(0, (uint8_t *)TSDB_COMMIT_BUF(pCommih), tlen); - - if (tsdbAppendDFile(pHeadf, TSDB_COMMIT_BUF(pCommih), tlen, &offset) < tlen) { - tsdbError("vgId:%d failed to write block index part to file %s since %s", TSDB_COMMIT_REPO_ID(pCommih), - TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno)); - return -1; - } - - tsdbUpdateDFileMagic(pHeadf, POINTER_SHIFT(TSDB_COMMIT_BUF(pCommih), tlen - sizeof(TSCKSUM))); - pHeadf->info.offset = (uint32_t)offset; - pHeadf->info.len = tlen; - - return 0; -} - static int tsdbCommitMemData(SCommitH *pCommith, SCommitIter *pIter, TSKEY keyLimit, bool toData) { STsdbRepo *pRepo = TSDB_COMMIT_REPO(pCommith); STsdbCfg * pCfg = REPO_CFG(pRepo); @@ -1438,45 +1496,3 @@ static int tsdbApplyRtn(STsdbRepo *pRepo) { return 0; } - -static int tsdbApplyRtnOnFSet(STsdbRepo *pRepo, SDFileSet *pSet, SRtn *pRtn) { - SDiskID did; - SDFileSet nSet; - STsdbFS * pfs = REPO_FS(pRepo); - int level; - - ASSERT(pSet->fid >= pRtn->minFid); - - level = tsdbGetFidLevel(pSet->fid, pRtn); - - tfsAllocDisk(level, &(did.level), &(did.id)); - if (did.level == TFS_UNDECIDED_LEVEL) { - terrno = TSDB_CODE_TDB_NO_AVAIL_DISK; - return -1; - } - - if (did.level > TSDB_FSET_LEVEL(pSet)) { - // Need to move the FSET to higher level - tsdbInitDFileSet(&nSet, did, REPO_ID(pRepo), pSet->fid, FS_TXN_VERSION(pfs)); - - if (tsdbCopyDFileSet(pSet, &nSet) < 0) { - tsdbError("vgId:%d failed to copy FSET %d from level %d to level %d since %s", REPO_ID(pRepo), pSet->fid, - TSDB_FSET_LEVEL(pSet), did.level, tstrerror(terrno)); - return -1; - } - - if (tsdbUpdateDFileSet(pfs, &nSet) < 0) { - return -1; - } - - tsdbInfo("vgId:%d FSET %d is copied from level %d disk id %d to level %d disk id %d", REPO_ID(pRepo), pSet->fid, - TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet), did.level, did.id); - } else { - // On a correct level - if (tsdbUpdateDFileSet(pfs, pSet) < 0) { - return -1; - } - } - - return 0; -} \ No newline at end of file From afc352547714d73172b6936f4a3a9fea77828744 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 2 Mar 2021 09:21:27 +0800 Subject: [PATCH 03/80] fix return value check problem --- src/tsdb/src/tsdbCommit.c | 4 ++-- src/tsdb/src/tsdbFS.c | 2 +- src/tsdb/src/tsdbReadImpl.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index 5656db69a4..e1f3cbb5f5 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -1188,12 +1188,12 @@ static int tsdbMoveBlock(SCommitH *pCommith, int bidx) { } static int tsdbCommitAddBlock(SCommitH *pCommith, const SBlock *pSupBlock, const SBlock *pSubBlocks, int nSubBlocks) { - if (taosArrayPush(pCommith->aSupBlk, pSupBlock) < 0) { + if (taosArrayPush(pCommith->aSupBlk, pSupBlock) == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } - if (pSubBlocks && taosArrayPushBatch(pCommith->aSubBlk, pSubBlocks, nSubBlocks) < 0) { + if (pSubBlocks && taosArrayPushBatch(pCommith->aSubBlk, pSubBlocks, nSubBlocks) == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index cbff4fbeaa..17d5f8f66f 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -1045,7 +1045,7 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { int code = regexec(®ex, bname, 0, NULL, 0); if (code == 0) { - if (taosArrayPush(fArray, (void *)pf) < 0) { + if (taosArrayPush(fArray, (void *)pf) == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; tfsClosedir(tdir); taosArrayDestroy(fArray); diff --git a/src/tsdb/src/tsdbReadImpl.c b/src/tsdb/src/tsdbReadImpl.c index 572706d45e..7212ae1636 100644 --- a/src/tsdb/src/tsdbReadImpl.c +++ b/src/tsdb/src/tsdbReadImpl.c @@ -139,7 +139,7 @@ int tsdbLoadBlockIdx(SReadH *pReadh) { ptr = tsdbDecodeSBlockIdx(ptr, &blkIdx); ASSERT(ptr != NULL); - if (taosArrayPush(pReadh->aBlkIdx, (void *)(&blkIdx)) < 0) { + if (taosArrayPush(pReadh->aBlkIdx, (void *)(&blkIdx)) == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } From 3449f023ac6ec84e4d65979734027636649484f0 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 2 Mar 2021 13:30:11 +0800 Subject: [PATCH 04/80] change merge datacols interface --- src/common/inc/tdataformat.h | 2 +- src/common/src/tdataformat.c | 15 ++++++++++----- src/tsdb/src/tsdbReadImpl.c | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 959654d158..308f5a1e58 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -296,7 +296,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema); SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData); SDataCols *tdFreeDataCols(SDataCols *pCols); void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols); -int tdMergeDataCols(SDataCols *target, SDataCols *src, int rowsToMerge); +int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset); // ----------------- K-V data row structure /* diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index f5b84e4c9a..db73905119 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -441,30 +441,35 @@ void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) pCols->numOfRows++; } -int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge) { +int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset) { ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows); ASSERT(target->numOfCols == source->numOfCols); + int offset = 0; + + if (pOffset == NULL) { + pOffset = &offset; + } SDataCols *pTarget = NULL; - if (dataColsKeyLast(target) < dataColsKeyFirst(source)) { // No overlap + if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyFirst(source))) { // No overlap ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints); for (int i = 0; i < rowsToMerge; i++) { for (int j = 0; j < source->numOfCols; j++) { if (source->cols[j].len > 0) { - dataColAppendVal(target->cols + j, tdGetColDataOfRow(source->cols + j, i), target->numOfRows, + dataColAppendVal(target->cols + j, tdGetColDataOfRow(source->cols + j, i + (*pOffset)), target->numOfRows, target->maxPoints); } } target->numOfRows++; + (*pOffset)++; } } else { pTarget = tdDupDataCols(target, true); if (pTarget == NULL) goto _err; int iter1 = 0; - int iter2 = 0; - tdMergeTwoDataCols(target, pTarget, &iter1, pTarget->numOfRows, source, &iter2, source->numOfRows, + tdMergeTwoDataCols(target, pTarget, &iter1, pTarget->numOfRows, source, pOffset, source->numOfRows, pTarget->numOfRows + rowsToMerge); } diff --git a/src/tsdb/src/tsdbReadImpl.c b/src/tsdb/src/tsdbReadImpl.c index 7212ae1636..dd14dc700f 100644 --- a/src/tsdb/src/tsdbReadImpl.c +++ b/src/tsdb/src/tsdbReadImpl.c @@ -258,7 +258,7 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) { for (int i = 1; i < pBlock->numOfSubBlocks; i++) { iBlock++; if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1]) < 0) return -1; - if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows) < 0) return -1; + if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL) < 0) return -1; } ASSERT(pReadh->pDCols[0]->numOfRows == pBlock->numOfRows); @@ -284,7 +284,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, for (int i = 1; i < pBlock->numOfSubBlocks; i++) { iBlock++; if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds) < 0) return -1; - if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows) < 0) return -1; + if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL) < 0) return -1; } ASSERT(pReadh->pDCols[0]->numOfRows == pBlock->numOfRows); From bd8cb525559b28582b7a890636562bc0afdbbd39 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 5 Mar 2021 13:25:56 +0800 Subject: [PATCH 05/80] make compact as a plugin interface --- src/tsdb/CMakeLists.txt | 4 ++++ src/tsdb/src/tsdbCompact.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tsdb/CMakeLists.txt b/src/tsdb/CMakeLists.txt index 31d52aae7d..8080a61a6c 100644 --- a/src/tsdb/CMakeLists.txt +++ b/src/tsdb/CMakeLists.txt @@ -6,6 +6,10 @@ AUX_SOURCE_DIRECTORY(src SRC) ADD_LIBRARY(tsdb ${SRC}) TARGET_LINK_LIBRARIES(tsdb tfs common tutil) +IF (TD_TSDB_PLUGINS) + TARGET_LINK_LIBRARIES(tsdb tsdbPlugins) +ENDIF () + IF (TD_LINUX) # Someone has no gtest directory, so comment it # ADD_SUBDIRECTORY(tests) diff --git a/src/tsdb/src/tsdbCompact.c b/src/tsdb/src/tsdbCompact.c index d8cd558424..635bba388a 100644 --- a/src/tsdb/src/tsdbCompact.c +++ b/src/tsdb/src/tsdbCompact.c @@ -14,5 +14,9 @@ */ #include "tsdb.h" +#ifndef _TSDB_PLUGINS + int tsdbCompact(STsdbRepo *pRepo) { return 0; } -void *tsdbCompactImpl(STsdbRepo *pRepo) { return NULL; } \ No newline at end of file +void *tsdbCompactImpl(STsdbRepo *pRepo) { return NULL; } + +#endif \ No newline at end of file From 3c0617bc591227b24b8321c1c8998d62663eac94 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 20 May 2021 09:57:19 +0800 Subject: [PATCH 06/80] TD-2570 --- src/client/inc/tsclient.h | 1 + src/client/src/tscSQLParser.c | 36 +++- src/client/src/tscUtil.c | 1 + src/inc/ttokendef.h | 334 +++++++++++++++++----------------- src/query/inc/qExecutor.h | 13 ++ src/query/inc/qSqlparser.h | 7 +- src/query/inc/sql.y | 11 +- src/query/src/qExecutor.c | 147 +++++++++++++++ src/query/src/qPlan.c | 4 + src/query/src/qSqlParser.c | 8 +- src/query/src/qTokenizer.c | 1 + 11 files changed, 390 insertions(+), 173 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index ec3b0c4421..b2fdafb7f3 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -226,6 +226,7 @@ typedef struct SQueryInfo { int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX int16_t resColumnId; // result column id bool distinctTag; // distinct tag or not + bool windowState; // window state or not int32_t round; // 0/1/.... int32_t bufLen; char* buf; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 63c08fe25b..9b60cca0ed 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -89,6 +89,7 @@ static int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCm static int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); static int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* offsetToken); static int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSliding); +static int32_t validateWindowStateNode(SSqlCmd* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable); static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem); @@ -828,6 +829,35 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS // The following part is used to check for the invalid query expression. return checkInvalidExprForTimeWindow(pCmd, pQueryInfo); } +static int32_t validateWindowStateNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable) { + + const char* msg1 = "invalid column name"; + const char* msg2 = "invalid window state"; + const char* msg3 = "not support window_state on super table"; + + SStrToken *col = &(pSqlNode->windowstateVal.col) ; + if (col->z == NULL || col->n <= 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + //TODO(dengyihao): check tag column + if (isStable) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); + } + + SColumnIndex index = COLUMN_INDEX_INITIALIZER; + if (getColumnIndexByName(pCmd, col, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + + if (tscSqlExprNumOfExprs(pQueryInfo) == 1) { + SSqlExpr* pExpr = &(tscSqlExprGet(pQueryInfo, 0)->base); + if (index.columnIndex == pExpr->colInfo.colIndex && pExpr->colType == TSDB_DATA_TYPE_INT) { + pQueryInfo->windowState = true; + return TSDB_CODE_SUCCESS; + } + } + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); +} int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pSqlNode) { const char* msg1 = "gap should be fixed time window"; @@ -6721,6 +6751,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { return TSDB_CODE_TSC_INVALID_SQL; } + if (isTimeWindowQuery(pQueryInfo) && (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -7288,7 +7319,9 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, int32_t index) { TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_SQL; } - + if (validateWindowStateNode(pCmd, pQueryInfo, pSqlNode, isSTable) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_SQL; + } // set order by info if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMetaInfo->pTableMeta)) != TSDB_CODE_SUCCESS) { @@ -7311,6 +7344,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, int32_t index) { return TSDB_CODE_TSC_INVALID_SQL; } + // parse the window_state /* * transfer sql functions that need secondary merge into another format * in dealing with super table queries such as: count/first/last diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 420b78f64d..a40501d1cf 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -3550,6 +3550,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->pointInterpQuery = tscIsPointInterpQuery(pQueryInfo); pQueryAttr->timeWindowInterpo = timeWindowInterpoRequired(pQueryInfo); pQueryAttr->distinctTag = pQueryInfo->distinctTag; + pQueryAttr->windowState = pQueryInfo->windowState; pQueryAttr->numOfCols = numOfCols; pQueryAttr->numOfOutput = numOfOutput; diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index ef3f8ed1fb..8f5f1d7590 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -17,105 +17,105 @@ #define TDENGINE_TTOKENDEF_H -#define TK_ID 1 -#define TK_BOOL 2 -#define TK_TINYINT 3 -#define TK_SMALLINT 4 -#define TK_INTEGER 5 -#define TK_BIGINT 6 -#define TK_FLOAT 7 -#define TK_DOUBLE 8 -#define TK_STRING 9 -#define TK_TIMESTAMP 10 -#define TK_BINARY 11 -#define TK_NCHAR 12 -#define TK_OR 13 -#define TK_AND 14 -#define TK_NOT 15 -#define TK_EQ 16 -#define TK_NE 17 -#define TK_ISNULL 18 -#define TK_NOTNULL 19 -#define TK_IS 20 -#define TK_LIKE 21 -#define TK_GLOB 22 -#define TK_BETWEEN 23 -#define TK_IN 24 -#define TK_GT 25 -#define TK_GE 26 -#define TK_LT 27 -#define TK_LE 28 -#define TK_BITAND 29 -#define TK_BITOR 30 -#define TK_LSHIFT 31 -#define TK_RSHIFT 32 -#define TK_PLUS 33 -#define TK_MINUS 34 -#define TK_DIVIDE 35 -#define TK_TIMES 36 -#define TK_STAR 37 -#define TK_SLASH 38 -#define TK_REM 39 -#define TK_CONCAT 40 -#define TK_UMINUS 41 -#define TK_UPLUS 42 -#define TK_BITNOT 43 -#define TK_SHOW 44 -#define TK_DATABASES 45 -#define TK_TOPICS 46 -#define TK_MNODES 47 -#define TK_DNODES 48 -#define TK_ACCOUNTS 49 -#define TK_USERS 50 -#define TK_MODULES 51 -#define TK_QUERIES 52 -#define TK_CONNECTIONS 53 -#define TK_STREAMS 54 -#define TK_VARIABLES 55 -#define TK_SCORES 56 -#define TK_GRANTS 57 -#define TK_VNODES 58 -#define TK_IPTOKEN 59 -#define TK_DOT 60 -#define TK_CREATE 61 -#define TK_TABLE 62 -#define TK_STABLE 63 -#define TK_DATABASE 64 -#define TK_TABLES 65 -#define TK_STABLES 66 -#define TK_VGROUPS 67 -#define TK_DROP 68 -#define TK_TOPIC 69 -#define TK_DNODE 70 -#define TK_USER 71 -#define TK_ACCOUNT 72 -#define TK_USE 73 -#define TK_DESCRIBE 74 -#define TK_ALTER 75 -#define TK_PASS 76 -#define TK_PRIVILEGE 77 -#define TK_LOCAL 78 -#define TK_IF 79 -#define TK_EXISTS 80 -#define TK_PPS 81 -#define TK_TSERIES 82 -#define TK_DBS 83 -#define TK_STORAGE 84 -#define TK_QTIME 85 -#define TK_CONNS 86 -#define TK_STATE 87 -#define TK_KEEP 88 -#define TK_CACHE 89 -#define TK_REPLICA 90 -#define TK_QUORUM 91 -#define TK_DAYS 92 -#define TK_MINROWS 93 -#define TK_MAXROWS 94 -#define TK_BLOCKS 95 -#define TK_CTIME 96 -#define TK_WAL 97 -#define TK_FSYNC 98 -#define TK_COMP 99 +#define TK_ID 1 +#define TK_BOOL 2 +#define TK_TINYINT 3 +#define TK_SMALLINT 4 +#define TK_INTEGER 5 +#define TK_BIGINT 6 +#define TK_FLOAT 7 +#define TK_DOUBLE 8 +#define TK_STRING 9 +#define TK_TIMESTAMP 10 +#define TK_BINARY 11 +#define TK_NCHAR 12 +#define TK_OR 13 +#define TK_AND 14 +#define TK_NOT 15 +#define TK_EQ 16 +#define TK_NE 17 +#define TK_ISNULL 18 +#define TK_NOTNULL 19 +#define TK_IS 20 +#define TK_LIKE 21 +#define TK_GLOB 22 +#define TK_BETWEEN 23 +#define TK_IN 24 +#define TK_GT 25 +#define TK_GE 26 +#define TK_LT 27 +#define TK_LE 28 +#define TK_BITAND 29 +#define TK_BITOR 30 +#define TK_LSHIFT 31 +#define TK_RSHIFT 32 +#define TK_PLUS 33 +#define TK_MINUS 34 +#define TK_DIVIDE 35 +#define TK_TIMES 36 +#define TK_STAR 37 +#define TK_SLASH 38 +#define TK_REM 39 +#define TK_CONCAT 40 +#define TK_UMINUS 41 +#define TK_UPLUS 42 +#define TK_BITNOT 43 +#define TK_SHOW 44 +#define TK_DATABASES 45 +#define TK_TOPICS 46 +#define TK_MNODES 47 +#define TK_DNODES 48 +#define TK_ACCOUNTS 49 +#define TK_USERS 50 +#define TK_MODULES 51 +#define TK_QUERIES 52 +#define TK_CONNECTIONS 53 +#define TK_STREAMS 54 +#define TK_VARIABLES 55 +#define TK_SCORES 56 +#define TK_GRANTS 57 +#define TK_VNODES 58 +#define TK_IPTOKEN 59 +#define TK_DOT 60 +#define TK_CREATE 61 +#define TK_TABLE 62 +#define TK_STABLE 63 +#define TK_DATABASE 64 +#define TK_TABLES 65 +#define TK_STABLES 66 +#define TK_VGROUPS 67 +#define TK_DROP 68 +#define TK_TOPIC 69 +#define TK_DNODE 70 +#define TK_USER 71 +#define TK_ACCOUNT 72 +#define TK_USE 73 +#define TK_DESCRIBE 74 +#define TK_ALTER 75 +#define TK_PASS 76 +#define TK_PRIVILEGE 77 +#define TK_LOCAL 78 +#define TK_IF 79 +#define TK_EXISTS 80 +#define TK_PPS 81 +#define TK_TSERIES 82 +#define TK_DBS 83 +#define TK_STORAGE 84 +#define TK_QTIME 85 +#define TK_CONNS 86 +#define TK_STATE 87 +#define TK_KEEP 88 +#define TK_CACHE 89 +#define TK_REPLICA 90 +#define TK_QUORUM 91 +#define TK_DAYS 92 +#define TK_MINROWS 93 +#define TK_MAXROWS 94 +#define TK_BLOCKS 95 +#define TK_CTIME 96 +#define TK_WAL 97 +#define TK_FSYNC 98 +#define TK_COMP 99 #define TK_PRECISION 100 #define TK_UPDATE 101 #define TK_CACHELAST 102 @@ -136,74 +136,74 @@ #define TK_VARIABLE 117 #define TK_INTERVAL 118 #define TK_SESSION 119 -#define TK_FILL 120 -#define TK_SLIDING 121 -#define TK_ORDER 122 -#define TK_BY 123 -#define TK_ASC 124 -#define TK_DESC 125 -#define TK_GROUP 126 -#define TK_HAVING 127 -#define TK_LIMIT 128 -#define TK_OFFSET 129 -#define TK_SLIMIT 130 -#define TK_SOFFSET 131 -#define TK_WHERE 132 -#define TK_NOW 133 -#define TK_RESET 134 -#define TK_QUERY 135 -#define TK_SYNCDB 136 -#define TK_ADD 137 -#define TK_COLUMN 138 -#define TK_TAG 139 -#define TK_CHANGE 140 -#define TK_SET 141 -#define TK_KILL 142 -#define TK_CONNECTION 143 -#define TK_STREAM 144 -#define TK_COLON 145 -#define TK_ABORT 146 -#define TK_AFTER 147 -#define TK_ATTACH 148 -#define TK_BEFORE 149 -#define TK_BEGIN 150 -#define TK_CASCADE 151 -#define TK_CLUSTER 152 -#define TK_CONFLICT 153 -#define TK_COPY 154 -#define TK_DEFERRED 155 -#define TK_DELIMITERS 156 -#define TK_DETACH 157 -#define TK_EACH 158 -#define TK_END 159 -#define TK_EXPLAIN 160 -#define TK_FAIL 161 -#define TK_FOR 162 -#define TK_IGNORE 163 -#define TK_IMMEDIATE 164 -#define TK_INITIALLY 165 -#define TK_INSTEAD 166 -#define TK_MATCH 167 -#define TK_KEY 168 -#define TK_OF 169 -#define TK_RAISE 170 -#define TK_REPLACE 171 -#define TK_RESTRICT 172 -#define TK_ROW 173 -#define TK_STATEMENT 174 -#define TK_TRIGGER 175 -#define TK_VIEW 176 -#define TK_SEMI 177 -#define TK_NONE 178 -#define TK_PREV 179 -#define TK_LINEAR 180 -#define TK_IMPORT 181 -#define TK_TBNAME 182 -#define TK_JOIN 183 -#define TK_INSERT 184 -#define TK_INTO 185 -#define TK_VALUES 186 - +#define TK_WINDOW_STATE 120 +#define TK_FILL 121 +#define TK_SLIDING 122 +#define TK_ORDER 123 +#define TK_BY 124 +#define TK_ASC 125 +#define TK_DESC 126 +#define TK_GROUP 127 +#define TK_HAVING 128 +#define TK_LIMIT 129 +#define TK_OFFSET 130 +#define TK_SLIMIT 131 +#define TK_SOFFSET 132 +#define TK_WHERE 133 +#define TK_NOW 134 +#define TK_RESET 135 +#define TK_QUERY 136 +#define TK_SYNCDB 137 +#define TK_ADD 138 +#define TK_COLUMN 139 +#define TK_TAG 140 +#define TK_CHANGE 141 +#define TK_SET 142 +#define TK_KILL 143 +#define TK_CONNECTION 144 +#define TK_STREAM 145 +#define TK_COLON 146 +#define TK_ABORT 147 +#define TK_AFTER 148 +#define TK_ATTACH 149 +#define TK_BEFORE 150 +#define TK_BEGIN 151 +#define TK_CASCADE 152 +#define TK_CLUSTER 153 +#define TK_CONFLICT 154 +#define TK_COPY 155 +#define TK_DEFERRED 156 +#define TK_DELIMITERS 157 +#define TK_DETACH 158 +#define TK_EACH 159 +#define TK_END 160 +#define TK_EXPLAIN 161 +#define TK_FAIL 162 +#define TK_FOR 163 +#define TK_IGNORE 164 +#define TK_IMMEDIATE 165 +#define TK_INITIALLY 166 +#define TK_INSTEAD 167 +#define TK_MATCH 168 +#define TK_KEY 169 +#define TK_OF 170 +#define TK_RAISE 171 +#define TK_REPLACE 172 +#define TK_RESTRICT 173 +#define TK_ROW 174 +#define TK_STATEMENT 175 +#define TK_TRIGGER 176 +#define TK_VIEW 177 +#define TK_SEMI 178 +#define TK_NONE 179 +#define TK_PREV 180 +#define TK_LINEAR 181 +#define TK_IMPORT 182 +#define TK_TBNAME 183 +#define TK_JOIN 184 +#define TK_INSERT 185 +#define TK_INTO 186 +#define TK_VALUES 187 #define TK_SPACE 300 #define TK_COMMENT 301 diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index b9361650e9..6640061c63 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -196,6 +196,7 @@ typedef struct SQueryAttr { bool pointInterpQuery; // point interpolation query bool needReverseScan; // need reverse scan bool distinctTag; // distinct tag query + bool windowState; // window State on sub/normal table int32_t interBufSize; // intermediate buffer sizse int32_t havingNum; // having expr number @@ -302,6 +303,7 @@ enum OPERATOR_TYPE_E { OP_GlobalAggregate = 18, // global merge for the multi-way data sources. OP_Filter = 19, OP_Distinct = 20, + OP_StateWindow = 21, }; typedef struct SOperatorInfo { @@ -465,6 +467,16 @@ typedef struct SSWindowOperatorInfo { int32_t start; // start row index } SSWindowOperatorInfo; +typedef struct SStateWindowOperatorInfo { + SOptrBasicInfo binfo; + STimeWindow curWindow; // current time window + int32_t numOfRows; // number of rows + int32_t colIndex; // start row index + int32_t start; + char* prevData; // previous data + +} SStateWindowOperatorInfo ; + typedef struct SDistinctOperatorInfo { SHashObj *pSet; SSDataBlock *pRes; @@ -512,6 +524,7 @@ SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperat SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv); SOperatorInfo* createMultiwaySortOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput, int32_t numOfRows, void* merger, bool groupMix); +SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, void* param); SOperatorInfo* createSLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, void* merger); SOperatorInfo* createFilterOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index 85cba06b3e..026ae1d976 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -89,6 +89,10 @@ typedef struct SSessionWindowVal { SStrToken gap; } SSessionWindowVal; +typedef struct SWindowStateVal { + SStrToken col; +} SWindowStateVal; + struct SRelationInfo; typedef struct SSqlNode { @@ -100,6 +104,7 @@ typedef struct SSqlNode { SArray *fillType; // fill type[optional], SArray SIntervalVal interval; // (interval, interval_offset) [optional] SSessionWindowVal sessionVal; // session window [optional] + SWindowStateVal windowstateVal; // window_state(col) [optional] SStrToken sliding; // sliding window [optional] SLimitVal limit; // limit offset [optional] SLimitVal slimit; // group limit offset [optional] @@ -271,7 +276,7 @@ SArray *tSqlExprListAppend(SArray *pList, tSqlExpr *pNode, SStrToken *pDistinc void tSqlExprListDestroy(SArray *pList); SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, - SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps, + SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps, SWindowStateVal *pw, SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pgLimit, tSqlExpr *pHaving); int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right); diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 8ef8ef0e2b..fa1292e2d7 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -456,8 +456,8 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). { //////////////////////// The SELECT statement ///////////////////////////////// %type select {SSqlNode*} %destructor select {destroySqlNode($$);} -select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) session_option(H) fill_opt(F) sliding_opt(S) groupby_opt(P) orderby_opt(Z) having_opt(N) slimit_opt(G) limit_opt(L). { - A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &S, F, &L, &G, N); +select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) session_option(H) windowstate_option(D) fill_opt(F) sliding_opt(S) groupby_opt(P) orderby_opt(Z) having_opt(N) slimit_opt(G) limit_opt(L). { + A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &D, &S, F, &L, &G, N); } select(A) ::= LP select(B) RP. {A = B;} @@ -475,7 +475,7 @@ cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); } // select client_version() // select server_state() select(A) ::= SELECT(T) selcollist(W). { - A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } // selcollist is a list of expressions that are to become the return @@ -552,6 +552,11 @@ session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP. { X.col = V; X.gap = Y; } +%type windowstate_option {SWindowStateVal} +windowstate_option(X) ::= . {X.col.n = 0;} +windowstate_option(X) ::= WINDOW_STATE LP ids(V) RP. { + X.col = V; +} %type fill_opt {SArray*} %destructor fill_opt {taosArrayDestroy($$);} diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index feaa205c3e..9bec84e28e 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1758,6 +1758,11 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf } break; } + case OP_StateWindow: { + pRuntimeEnv->proot = createStatewindowOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); + setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream->info, pRuntimeEnv->proot); + break; + } case OP_Limit: { pRuntimeEnv->proot = createLimitOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot); @@ -4413,6 +4418,12 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf } else if (pDownstream->operatorType == OP_SessionWindow) { SSWindowOperatorInfo* pInfo = pDownstream->info; + pTableScanInfo->pCtx = pInfo->binfo.pCtx; + pTableScanInfo->pResultRowInfo = &pInfo->binfo.resultRowInfo; + pTableScanInfo->rowCellInfoOffset = pInfo->binfo.rowCellInfoOffset; + } else if (pDownstream->operatorType == OP_StateWindow) { + SStateWindowOperatorInfo* pInfo = pDownstream->info; + pTableScanInfo->pCtx = pInfo->binfo.pCtx; pTableScanInfo->pResultRowInfo = &pInfo->binfo.resultRowInfo; pTableScanInfo->rowCellInfoOffset = pInfo->binfo.rowCellInfoOffset; @@ -5050,6 +5061,121 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) { return pIntervalInfo->pRes; } + +static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { + SColumnInfoData* pColInfoData = taosArrayGet(pSDataBlock->pDataBlock, pInfo->colIndex); + SOptrBasicInfo* pBInfo = &pInfo->binfo; + int16_t bytes = pColInfoData->info.bytes; + int16_t type = pColInfoData->info.type; + SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + STableQueryInfo* item = pRuntimeEnv->current; + bool masterScan = IS_MASTER_SCAN(pRuntimeEnv); + + SColumnInfoData* pTsColInfoData = taosArrayGet(pSDataBlock->pDataBlock, 0); + TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; + + if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_TIMESTAMP) { + qError("QInfo:0x%"PRIx64" group by not supported on double/float columns, abort", GET_QID(pRuntimeEnv)); + return; + } + for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { + char* val = ((char*)pColInfoData->pData) + bytes * j; + if (isNull(val, type)) { + continue; + } + if (pInfo->prevData == NULL) { + pInfo->prevData = malloc(bytes); + memcpy(pInfo->prevData, val, bytes); + pInfo->curWindow.skey = tsList[j]; + pInfo->curWindow.ekey = tsList[j]; + pInfo->numOfRows = 1; + pInfo->start = j; + } else if (0 == memcmp(pInfo->prevData, val, bytes)) { + pInfo->curWindow.ekey = tsList[j]; + pInfo->numOfRows += 1; + pInfo->start = j; + } else { + SResultRow* pResult = NULL; + int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, + &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, + pBInfo->rowCellInfoOffset); + if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code + longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); + } + + doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, + pSDataBlock->info.rows, pOperator->numOfOutput); + + pInfo->curWindow.skey = tsList[j]; + pInfo->curWindow.ekey = tsList[j]; + memcpy(pInfo->prevData, val, bytes); + pInfo->numOfRows = 1; + pInfo->start = j; + } + } + SResultRow* pResult = NULL; + + int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, + &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, + pBInfo->rowCellInfoOffset); + if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code + longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); + } + + doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, + pSDataBlock->info.rows, pOperator->numOfOutput); + +} +static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) { + SOperatorInfo* pOperator = (SOperatorInfo*) param; + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + SStateWindowOperatorInfo* pWindowInfo = pOperator->info; + SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; + if (pOperator->status == OP_RES_TO_RETURN) { + toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); + + if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + pOperator->status = OP_EXEC_DONE; + } + return pBInfo->pRes; + } + int32_t order = pQueryAttr->order.order; + STimeWindow win = pQueryAttr->window; + SOperatorInfo* upstream = pOperator->upstream; + while (1) { + SSDataBlock* pBlock = upstream->exec(upstream, newgroup); + if (pBlock == NULL) { + break; + } + setInputDataBlock(pOperator, pBInfo->pCtx, pBlock, pQueryAttr->order.order); + if (pWindowInfo->colIndex == -1) { + pWindowInfo->colIndex = pOperator->pExpr->base.colInfo.colIndex; + } + doStateWindowAggImpl(pOperator, pWindowInfo, pBlock); + } + + // restore the value + pQueryAttr->order.order = order; + pQueryAttr->window = win; + + pOperator->status = OP_RES_TO_RETURN; + closeAllResultRows(&pBInfo->resultRowInfo); + setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); + finalizeQueryResult(pOperator, pBInfo->pCtx, &pBInfo->resultRowInfo, pBInfo->rowCellInfoOffset); + + initGroupResInfo(&pRuntimeEnv->groupResInfo, &pBInfo->resultRowInfo); + toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); + + if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + pOperator->status = OP_EXEC_DONE; + } + + return pBInfo->pRes->info.rows == 0? NULL:pBInfo->pRes; +} static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) { SOperatorInfo* pOperator = (SOperatorInfo*) param; if (pOperator->status == OP_EXEC_DONE) { @@ -5500,7 +5626,28 @@ SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOp return pOperator; } +SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { + SStateWindowOperatorInfo* pInfo = calloc(1, sizeof(SStateWindowOperatorInfo)); + pInfo->colIndex = -1; + pInfo->binfo.pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); + pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); + initResultRowInfo(&pInfo->binfo.resultRowInfo, 8, TSDB_DATA_TYPE_INT); + SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + pOperator->name = "StateWindowOperator"; + pOperator->operatorType = OP_StateWindow; + pOperator->blockingOptr = true; + pOperator->status = OP_IN_EXECUTING; + pOperator->upstream = upstream; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->exec = doStateWindowAgg; + pOperator->cleanup = destroyBasicOperatorInfo; + return pOperator; + +} SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SSWindowOperatorInfo* pInfo = calloc(1, sizeof(SSWindowOperatorInfo)); diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 0554a887ec..52b0329293 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -121,6 +121,10 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { if (pQueryAttr->stableQuery && !pQueryAttr->tsCompQuery) { op = OP_MultiTableAggregate; } else { + if (pQueryAttr->windowState) { + op = OP_StateWindow; + taosArrayPush(plan, &op); + } op = OP_Aggregate; } diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index fb8f164ed3..8432edc6ee 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -725,7 +725,7 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { */ SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, - SSessionWindowVal *pSession, SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, + SSessionWindowVal *pSession, SWindowStateVal *pWindowStateVal, SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *psLimit, tSqlExpr *pHaving) { assert(pSelNodeList != NULL); @@ -777,6 +777,12 @@ SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelat TPARSER_SET_NONE_TOKEN(pSqlNode->sessionVal.col); } + if (pWindowStateVal != NULL) { + pSqlNode->windowstateVal = *pWindowStateVal; + } else { + TPARSER_SET_NONE_TOKEN(pSqlNode->windowstateVal.col); + } + return pSqlNode; } diff --git a/src/query/src/qTokenizer.c b/src/query/src/qTokenizer.c index 7869e27707..7f3c269e99 100644 --- a/src/query/src/qTokenizer.c +++ b/src/query/src/qTokenizer.c @@ -141,6 +141,7 @@ static SKeyword keywordTable[] = { {"VARIABLE", TK_VARIABLE}, {"INTERVAL", TK_INTERVAL}, {"SESSION", TK_SESSION}, + {"WINDOW_STATE", TK_WINDOW_STATE}, {"FILL", TK_FILL}, {"SLIDING", TK_SLIDING}, {"ORDER", TK_ORDER}, From ff3a4c64a371e967eb32cf3d6dd8fd52f40cf8c2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 20 May 2021 10:34:09 +0800 Subject: [PATCH 07/80] [td-2570] update the script and the corresponding tokenizer --- src/inc/ttokendef.h | 200 ++-- src/query/inc/sql.y | 2 +- src/query/src/qTokenizer.c | 2 +- src/query/src/sql.c | 2281 ++++++++++++++++++------------------ 4 files changed, 1252 insertions(+), 1233 deletions(-) diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index 8f5f1d7590..e9585636fd 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -17,105 +17,105 @@ #define TDENGINE_TTOKENDEF_H -#define TK_ID 1 -#define TK_BOOL 2 -#define TK_TINYINT 3 -#define TK_SMALLINT 4 -#define TK_INTEGER 5 -#define TK_BIGINT 6 -#define TK_FLOAT 7 -#define TK_DOUBLE 8 -#define TK_STRING 9 -#define TK_TIMESTAMP 10 -#define TK_BINARY 11 -#define TK_NCHAR 12 -#define TK_OR 13 -#define TK_AND 14 -#define TK_NOT 15 -#define TK_EQ 16 -#define TK_NE 17 -#define TK_ISNULL 18 -#define TK_NOTNULL 19 -#define TK_IS 20 -#define TK_LIKE 21 -#define TK_GLOB 22 -#define TK_BETWEEN 23 -#define TK_IN 24 -#define TK_GT 25 -#define TK_GE 26 -#define TK_LT 27 -#define TK_LE 28 -#define TK_BITAND 29 -#define TK_BITOR 30 -#define TK_LSHIFT 31 -#define TK_RSHIFT 32 -#define TK_PLUS 33 -#define TK_MINUS 34 -#define TK_DIVIDE 35 -#define TK_TIMES 36 -#define TK_STAR 37 -#define TK_SLASH 38 -#define TK_REM 39 -#define TK_CONCAT 40 -#define TK_UMINUS 41 -#define TK_UPLUS 42 -#define TK_BITNOT 43 -#define TK_SHOW 44 -#define TK_DATABASES 45 -#define TK_TOPICS 46 -#define TK_MNODES 47 -#define TK_DNODES 48 -#define TK_ACCOUNTS 49 -#define TK_USERS 50 -#define TK_MODULES 51 -#define TK_QUERIES 52 -#define TK_CONNECTIONS 53 -#define TK_STREAMS 54 -#define TK_VARIABLES 55 -#define TK_SCORES 56 -#define TK_GRANTS 57 -#define TK_VNODES 58 -#define TK_IPTOKEN 59 -#define TK_DOT 60 -#define TK_CREATE 61 -#define TK_TABLE 62 -#define TK_STABLE 63 -#define TK_DATABASE 64 -#define TK_TABLES 65 -#define TK_STABLES 66 -#define TK_VGROUPS 67 -#define TK_DROP 68 -#define TK_TOPIC 69 -#define TK_DNODE 70 -#define TK_USER 71 -#define TK_ACCOUNT 72 -#define TK_USE 73 -#define TK_DESCRIBE 74 -#define TK_ALTER 75 -#define TK_PASS 76 -#define TK_PRIVILEGE 77 -#define TK_LOCAL 78 -#define TK_IF 79 -#define TK_EXISTS 80 -#define TK_PPS 81 -#define TK_TSERIES 82 -#define TK_DBS 83 -#define TK_STORAGE 84 -#define TK_QTIME 85 -#define TK_CONNS 86 -#define TK_STATE 87 -#define TK_KEEP 88 -#define TK_CACHE 89 -#define TK_REPLICA 90 -#define TK_QUORUM 91 -#define TK_DAYS 92 -#define TK_MINROWS 93 -#define TK_MAXROWS 94 -#define TK_BLOCKS 95 -#define TK_CTIME 96 -#define TK_WAL 97 -#define TK_FSYNC 98 -#define TK_COMP 99 +#define TK_ID 1 +#define TK_BOOL 2 +#define TK_TINYINT 3 +#define TK_SMALLINT 4 +#define TK_INTEGER 5 +#define TK_BIGINT 6 +#define TK_FLOAT 7 +#define TK_DOUBLE 8 +#define TK_STRING 9 +#define TK_TIMESTAMP 10 +#define TK_BINARY 11 +#define TK_NCHAR 12 +#define TK_OR 13 +#define TK_AND 14 +#define TK_NOT 15 +#define TK_EQ 16 +#define TK_NE 17 +#define TK_ISNULL 18 +#define TK_NOTNULL 19 +#define TK_IS 20 +#define TK_LIKE 21 +#define TK_GLOB 22 +#define TK_BETWEEN 23 +#define TK_IN 24 +#define TK_GT 25 +#define TK_GE 26 +#define TK_LT 27 +#define TK_LE 28 +#define TK_BITAND 29 +#define TK_BITOR 30 +#define TK_LSHIFT 31 +#define TK_RSHIFT 32 +#define TK_PLUS 33 +#define TK_MINUS 34 +#define TK_DIVIDE 35 +#define TK_TIMES 36 +#define TK_STAR 37 +#define TK_SLASH 38 +#define TK_REM 39 +#define TK_CONCAT 40 +#define TK_UMINUS 41 +#define TK_UPLUS 42 +#define TK_BITNOT 43 +#define TK_SHOW 44 +#define TK_DATABASES 45 +#define TK_TOPICS 46 +#define TK_MNODES 47 +#define TK_DNODES 48 +#define TK_ACCOUNTS 49 +#define TK_USERS 50 +#define TK_MODULES 51 +#define TK_QUERIES 52 +#define TK_CONNECTIONS 53 +#define TK_STREAMS 54 +#define TK_VARIABLES 55 +#define TK_SCORES 56 +#define TK_GRANTS 57 +#define TK_VNODES 58 +#define TK_IPTOKEN 59 +#define TK_DOT 60 +#define TK_CREATE 61 +#define TK_TABLE 62 +#define TK_STABLE 63 +#define TK_DATABASE 64 +#define TK_TABLES 65 +#define TK_STABLES 66 +#define TK_VGROUPS 67 +#define TK_DROP 68 +#define TK_TOPIC 69 +#define TK_DNODE 70 +#define TK_USER 71 +#define TK_ACCOUNT 72 +#define TK_USE 73 +#define TK_DESCRIBE 74 +#define TK_ALTER 75 +#define TK_PASS 76 +#define TK_PRIVILEGE 77 +#define TK_LOCAL 78 +#define TK_IF 79 +#define TK_EXISTS 80 +#define TK_PPS 81 +#define TK_TSERIES 82 +#define TK_DBS 83 +#define TK_STORAGE 84 +#define TK_QTIME 85 +#define TK_CONNS 86 +#define TK_STATE 87 +#define TK_KEEP 88 +#define TK_CACHE 89 +#define TK_REPLICA 90 +#define TK_QUORUM 91 +#define TK_DAYS 92 +#define TK_MINROWS 93 +#define TK_MAXROWS 94 +#define TK_BLOCKS 95 +#define TK_CTIME 96 +#define TK_WAL 97 +#define TK_FSYNC 98 +#define TK_COMP 99 #define TK_PRECISION 100 #define TK_UPDATE 101 #define TK_CACHELAST 102 @@ -136,7 +136,7 @@ #define TK_VARIABLE 117 #define TK_INTERVAL 118 #define TK_SESSION 119 -#define TK_WINDOW_STATE 120 +#define TK_STATE_WINDOW 120 #define TK_FILL 121 #define TK_SLIDING 122 #define TK_ORDER 123 diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index fa1292e2d7..66979d0dea 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -554,7 +554,7 @@ session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP. { } %type windowstate_option {SWindowStateVal} windowstate_option(X) ::= . {X.col.n = 0;} -windowstate_option(X) ::= WINDOW_STATE LP ids(V) RP. { +windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. { X.col = V; } diff --git a/src/query/src/qTokenizer.c b/src/query/src/qTokenizer.c index 7f3c269e99..7029cbfc3c 100644 --- a/src/query/src/qTokenizer.c +++ b/src/query/src/qTokenizer.c @@ -141,7 +141,7 @@ static SKeyword keywordTable[] = { {"VARIABLE", TK_VARIABLE}, {"INTERVAL", TK_INTERVAL}, {"SESSION", TK_SESSION}, - {"WINDOW_STATE", TK_WINDOW_STATE}, + {"STATE_WINDOW", TK_STATE_WINDOW}, {"FILL", TK_FILL}, {"SLIDING", TK_SLIDING}, {"ORDER", TK_ORDER}, diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 9436942f71..363941950f 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -97,27 +97,28 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 264 +#define YYNOCODE 266 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SStrToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SCreateTableSql* yy14; - int yy20; - SSqlNode* yy116; - tSqlExpr* yy118; - SArray* yy159; - SIntervalVal yy184; - SCreatedTableInfo yy206; - SRelationInfo* yy236; - SSessionWindowVal yy249; - int64_t yy317; - SCreateDbInfo yy322; - SCreateAcctInfo yy351; - TAOS_FIELD yy407; - SLimitVal yy440; - tVariant yy488; + SSqlNode* yy6; + SLimitVal yy74; + SCreateDbInfo yy122; + SSessionWindowVal yy139; + TAOS_FIELD yy153; + SWindowStateVal yy158; + int64_t yy179; + SCreateAcctInfo yy211; + tVariant yy216; + SRelationInfo* yy254; + SArray* yy291; + int yy382; + SIntervalVal yy400; + SCreateTableSql* yy412; + tSqlExpr* yy436; + SCreatedTableInfo yy446; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -127,17 +128,17 @@ typedef union { #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 -#define YYNSTATE 317 -#define YYNRULE 270 -#define YYNTOKEN 187 -#define YY_MAX_SHIFT 316 -#define YY_MIN_SHIFTREDUCE 511 -#define YY_MAX_SHIFTREDUCE 780 -#define YY_ERROR_ACTION 781 -#define YY_ACCEPT_ACTION 782 -#define YY_NO_ACTION 783 -#define YY_MIN_REDUCE 784 -#define YY_MAX_REDUCE 1053 +#define YYNSTATE 321 +#define YYNRULE 272 +#define YYNTOKEN 188 +#define YY_MAX_SHIFT 320 +#define YY_MIN_SHIFTREDUCE 516 +#define YY_MAX_SHIFTREDUCE 787 +#define YY_ERROR_ACTION 788 +#define YY_ACCEPT_ACTION 789 +#define YY_NO_ACTION 790 +#define YY_MIN_REDUCE 791 +#define YY_MAX_REDUCE 1062 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -203,261 +204,264 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (685) +#define YY_ACTTAB_COUNT (683) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 925, 559, 206, 314, 211, 141, 952, 3, 168, 560, - /* 10 */ 782, 316, 134, 47, 48, 141, 51, 52, 30, 183, - /* 20 */ 217, 41, 183, 50, 264, 55, 53, 57, 54, 1034, - /* 30 */ 931, 214, 1035, 46, 45, 17, 183, 44, 43, 42, - /* 40 */ 47, 48, 223, 51, 52, 213, 1035, 217, 41, 559, - /* 50 */ 50, 264, 55, 53, 57, 54, 943, 560, 181, 208, - /* 60 */ 46, 45, 928, 222, 44, 43, 42, 48, 949, 51, - /* 70 */ 52, 244, 983, 217, 41, 249, 50, 264, 55, 53, - /* 80 */ 57, 54, 984, 638, 259, 85, 46, 45, 280, 931, - /* 90 */ 44, 43, 42, 512, 513, 514, 515, 516, 517, 518, - /* 100 */ 519, 520, 521, 522, 523, 524, 315, 943, 187, 207, - /* 110 */ 70, 290, 289, 47, 48, 30, 51, 52, 300, 919, - /* 120 */ 217, 41, 209, 50, 264, 55, 53, 57, 54, 44, - /* 130 */ 43, 42, 724, 46, 45, 674, 224, 44, 43, 42, - /* 140 */ 47, 49, 24, 51, 52, 228, 141, 217, 41, 559, - /* 150 */ 50, 264, 55, 53, 57, 54, 220, 560, 105, 928, - /* 160 */ 46, 45, 931, 300, 44, 43, 42, 23, 278, 309, - /* 170 */ 308, 277, 276, 275, 307, 274, 306, 305, 304, 273, - /* 180 */ 303, 302, 891, 30, 879, 880, 881, 882, 883, 884, - /* 190 */ 885, 886, 887, 888, 889, 890, 892, 893, 51, 52, - /* 200 */ 830, 1031, 217, 41, 167, 50, 264, 55, 53, 57, - /* 210 */ 54, 261, 18, 78, 230, 46, 45, 287, 286, 44, - /* 220 */ 43, 42, 216, 739, 221, 30, 728, 928, 731, 192, - /* 230 */ 734, 216, 739, 310, 1030, 728, 193, 731, 236, 734, - /* 240 */ 30, 118, 117, 191, 677, 559, 240, 239, 55, 53, - /* 250 */ 57, 54, 25, 560, 202, 203, 46, 45, 263, 931, - /* 260 */ 44, 43, 42, 202, 203, 74, 283, 61, 23, 928, - /* 270 */ 309, 308, 74, 36, 730, 307, 733, 306, 305, 304, - /* 280 */ 36, 303, 302, 899, 927, 662, 897, 898, 659, 62, - /* 290 */ 660, 900, 661, 902, 903, 901, 82, 904, 905, 103, - /* 300 */ 97, 108, 243, 917, 68, 30, 107, 113, 116, 106, - /* 310 */ 199, 5, 33, 157, 141, 110, 231, 232, 156, 92, - /* 320 */ 87, 91, 681, 226, 30, 56, 30, 914, 915, 29, - /* 330 */ 918, 729, 740, 732, 56, 175, 173, 171, 736, 1, - /* 340 */ 155, 740, 170, 121, 120, 119, 284, 736, 229, 928, - /* 350 */ 265, 46, 45, 69, 735, 44, 43, 42, 839, 666, - /* 360 */ 12, 667, 167, 735, 84, 288, 81, 292, 928, 215, - /* 370 */ 928, 313, 312, 126, 132, 130, 129, 80, 705, 706, - /* 380 */ 831, 79, 280, 929, 167, 916, 737, 245, 726, 684, - /* 390 */ 71, 31, 227, 994, 663, 282, 690, 247, 696, 697, - /* 400 */ 136, 760, 60, 20, 741, 19, 64, 648, 19, 241, - /* 410 */ 267, 31, 650, 6, 31, 269, 60, 1029, 649, 83, - /* 420 */ 28, 200, 60, 270, 727, 201, 65, 96, 95, 185, - /* 430 */ 14, 13, 993, 102, 101, 67, 218, 637, 16, 15, - /* 440 */ 664, 186, 665, 738, 115, 114, 743, 188, 182, 189, - /* 450 */ 190, 196, 197, 195, 180, 194, 184, 133, 1045, 990, - /* 460 */ 930, 989, 219, 291, 39, 951, 959, 944, 961, 135, - /* 470 */ 139, 976, 248, 975, 926, 131, 152, 151, 924, 153, - /* 480 */ 250, 154, 689, 210, 252, 150, 257, 145, 142, 842, - /* 490 */ 941, 143, 272, 144, 262, 37, 146, 66, 58, 178, - /* 500 */ 63, 260, 34, 258, 256, 281, 838, 147, 1050, 254, - /* 510 */ 93, 1049, 1047, 158, 285, 1044, 99, 148, 1043, 1041, - /* 520 */ 159, 860, 251, 35, 32, 38, 149, 179, 827, 109, - /* 530 */ 825, 111, 112, 823, 822, 233, 169, 820, 819, 818, - /* 540 */ 817, 816, 815, 172, 174, 40, 812, 810, 808, 806, - /* 550 */ 176, 803, 177, 301, 246, 72, 75, 104, 253, 977, - /* 560 */ 293, 294, 295, 296, 297, 204, 225, 298, 271, 299, - /* 570 */ 311, 780, 205, 198, 234, 88, 89, 235, 779, 237, - /* 580 */ 238, 778, 766, 765, 242, 247, 821, 814, 162, 266, - /* 590 */ 122, 861, 160, 165, 161, 164, 163, 166, 123, 124, - /* 600 */ 813, 805, 895, 125, 804, 2, 8, 73, 4, 669, - /* 610 */ 76, 691, 137, 212, 694, 86, 138, 77, 907, 255, - /* 620 */ 9, 698, 140, 26, 742, 7, 27, 11, 10, 21, - /* 630 */ 84, 744, 22, 268, 601, 597, 595, 594, 593, 590, - /* 640 */ 563, 279, 94, 90, 31, 59, 640, 639, 636, 585, - /* 650 */ 583, 98, 575, 581, 577, 579, 573, 571, 604, 603, - /* 660 */ 602, 600, 599, 100, 598, 596, 592, 591, 60, 561, - /* 670 */ 528, 784, 526, 783, 783, 783, 783, 783, 783, 127, - /* 680 */ 783, 783, 783, 783, 128, + /* 0 */ 932, 564, 208, 318, 213, 959, 671, 142, 672, 565, + /* 10 */ 789, 320, 17, 47, 48, 142, 51, 52, 30, 185, + /* 20 */ 219, 41, 185, 50, 268, 55, 53, 57, 54, 1043, + /* 30 */ 938, 216, 1044, 46, 45, 183, 185, 44, 43, 42, + /* 40 */ 47, 48, 225, 51, 52, 215, 1044, 219, 41, 564, + /* 50 */ 50, 268, 55, 53, 57, 54, 950, 565, 224, 210, + /* 60 */ 46, 45, 935, 142, 44, 43, 42, 48, 956, 51, + /* 70 */ 52, 30, 246, 219, 41, 992, 50, 268, 55, 53, + /* 80 */ 57, 54, 135, 993, 938, 263, 46, 45, 284, 230, + /* 90 */ 44, 43, 42, 517, 518, 519, 520, 521, 522, 523, + /* 100 */ 524, 525, 526, 527, 528, 529, 319, 643, 86, 209, + /* 110 */ 70, 564, 222, 47, 48, 935, 51, 52, 304, 565, + /* 120 */ 219, 41, 564, 50, 268, 55, 53, 57, 54, 265, + /* 130 */ 565, 79, 731, 46, 45, 294, 293, 44, 43, 42, + /* 140 */ 47, 49, 926, 51, 52, 837, 251, 219, 41, 169, + /* 150 */ 50, 268, 55, 53, 57, 54, 317, 316, 127, 232, + /* 160 */ 46, 45, 291, 290, 44, 43, 42, 23, 282, 313, + /* 170 */ 312, 281, 280, 279, 311, 278, 310, 309, 308, 277, + /* 180 */ 307, 306, 898, 30, 886, 887, 888, 889, 890, 891, + /* 190 */ 892, 893, 894, 895, 896, 897, 899, 900, 51, 52, + /* 200 */ 189, 950, 219, 41, 924, 50, 268, 55, 53, 57, + /* 210 */ 54, 1040, 18, 83, 25, 46, 45, 211, 231, 44, + /* 220 */ 43, 42, 218, 746, 223, 30, 735, 935, 738, 194, + /* 230 */ 741, 218, 746, 226, 12, 735, 195, 738, 85, 741, + /* 240 */ 82, 119, 118, 193, 921, 922, 29, 925, 55, 53, + /* 250 */ 57, 54, 269, 936, 204, 205, 46, 45, 267, 938, + /* 260 */ 44, 43, 42, 204, 205, 238, 287, 228, 23, 935, + /* 270 */ 313, 312, 74, 242, 241, 311, 1054, 310, 309, 308, + /* 280 */ 36, 307, 306, 284, 906, 46, 45, 904, 905, 44, + /* 290 */ 43, 42, 907, 142, 909, 910, 908, 314, 911, 912, + /* 300 */ 104, 98, 109, 245, 737, 68, 740, 108, 114, 117, + /* 310 */ 107, 201, 667, 682, 69, 664, 111, 665, 30, 666, + /* 320 */ 5, 33, 159, 938, 30, 56, 30, 158, 93, 88, + /* 330 */ 92, 30, 747, 736, 56, 739, 28, 229, 743, 274, + /* 340 */ 286, 747, 81, 233, 234, 74, 923, 743, 750, 106, + /* 350 */ 177, 175, 173, 36, 304, 742, 71, 172, 122, 121, + /* 360 */ 120, 80, 934, 1039, 742, 288, 689, 292, 935, 846, + /* 370 */ 935, 217, 296, 169, 249, 935, 44, 43, 42, 133, + /* 380 */ 131, 130, 838, 1, 157, 1038, 169, 3, 170, 712, + /* 390 */ 713, 686, 679, 733, 247, 61, 695, 703, 31, 24, + /* 400 */ 137, 60, 704, 767, 64, 748, 20, 19, 653, 19, + /* 410 */ 271, 202, 31, 655, 31, 6, 744, 60, 62, 273, + /* 420 */ 654, 668, 39, 84, 60, 65, 97, 96, 67, 734, + /* 430 */ 642, 203, 14, 13, 1003, 103, 102, 116, 115, 1002, + /* 440 */ 16, 15, 669, 187, 670, 745, 937, 188, 190, 184, + /* 450 */ 191, 192, 198, 220, 199, 197, 182, 196, 243, 186, + /* 460 */ 134, 999, 998, 221, 295, 153, 958, 966, 985, 968, + /* 470 */ 136, 140, 257, 984, 951, 250, 154, 933, 132, 252, + /* 480 */ 143, 212, 931, 694, 254, 261, 155, 305, 152, 150, + /* 490 */ 148, 146, 144, 948, 156, 266, 849, 66, 276, 37, + /* 500 */ 63, 180, 58, 145, 34, 285, 264, 262, 845, 260, + /* 510 */ 1059, 94, 1058, 1056, 160, 289, 147, 1053, 100, 1052, + /* 520 */ 258, 1050, 161, 867, 35, 32, 38, 181, 834, 110, + /* 530 */ 832, 256, 112, 113, 830, 829, 235, 171, 827, 826, + /* 540 */ 825, 824, 823, 822, 174, 176, 819, 817, 815, 813, + /* 550 */ 178, 810, 179, 253, 40, 248, 72, 75, 255, 105, + /* 560 */ 986, 297, 298, 299, 300, 301, 206, 302, 227, 275, + /* 570 */ 303, 315, 787, 236, 207, 200, 89, 237, 90, 786, + /* 580 */ 239, 240, 785, 773, 772, 244, 249, 674, 828, 821, + /* 590 */ 164, 820, 868, 123, 162, 167, 163, 165, 166, 168, + /* 600 */ 124, 125, 126, 902, 812, 4, 811, 270, 2, 8, + /* 610 */ 73, 76, 151, 149, 696, 699, 139, 138, 77, 914, + /* 620 */ 701, 78, 214, 259, 85, 705, 141, 26, 9, 749, + /* 630 */ 27, 7, 10, 11, 751, 21, 22, 272, 87, 606, + /* 640 */ 602, 600, 599, 598, 595, 568, 283, 91, 31, 59, + /* 650 */ 645, 644, 641, 590, 588, 580, 586, 582, 584, 578, + /* 660 */ 576, 609, 608, 607, 605, 95, 99, 604, 101, 603, + /* 670 */ 601, 597, 596, 60, 566, 533, 531, 791, 790, 790, + /* 680 */ 790, 128, 129, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 191, 1, 190, 191, 210, 191, 191, 194, 195, 9, - /* 10 */ 188, 189, 191, 13, 14, 191, 16, 17, 191, 252, - /* 20 */ 20, 21, 252, 23, 24, 25, 26, 27, 28, 262, - /* 30 */ 236, 261, 262, 33, 34, 252, 252, 37, 38, 39, - /* 40 */ 13, 14, 233, 16, 17, 261, 262, 20, 21, 1, - /* 50 */ 23, 24, 25, 26, 27, 28, 234, 9, 252, 232, - /* 60 */ 33, 34, 235, 210, 37, 38, 39, 14, 253, 16, - /* 70 */ 17, 249, 258, 20, 21, 254, 23, 24, 25, 26, - /* 80 */ 27, 28, 258, 5, 260, 197, 33, 34, 79, 236, + /* 0 */ 192, 1, 191, 192, 211, 192, 5, 192, 7, 9, + /* 10 */ 189, 190, 254, 13, 14, 192, 16, 17, 192, 254, + /* 20 */ 20, 21, 254, 23, 24, 25, 26, 27, 28, 264, + /* 30 */ 237, 263, 264, 33, 34, 254, 254, 37, 38, 39, + /* 40 */ 13, 14, 234, 16, 17, 263, 264, 20, 21, 1, + /* 50 */ 23, 24, 25, 26, 27, 28, 235, 9, 211, 233, + /* 60 */ 33, 34, 236, 192, 37, 38, 39, 14, 255, 16, + /* 70 */ 17, 192, 251, 20, 21, 260, 23, 24, 25, 26, + /* 80 */ 27, 28, 192, 260, 237, 262, 33, 34, 79, 68, /* 90 */ 37, 38, 39, 45, 46, 47, 48, 49, 50, 51, - /* 100 */ 52, 53, 54, 55, 56, 57, 58, 234, 252, 61, - /* 110 */ 110, 33, 34, 13, 14, 191, 16, 17, 81, 231, - /* 120 */ 20, 21, 249, 23, 24, 25, 26, 27, 28, 37, - /* 130 */ 38, 39, 105, 33, 34, 109, 210, 37, 38, 39, - /* 140 */ 13, 14, 116, 16, 17, 68, 191, 20, 21, 1, - /* 150 */ 23, 24, 25, 26, 27, 28, 232, 9, 76, 235, - /* 160 */ 33, 34, 236, 81, 37, 38, 39, 88, 89, 90, + /* 100 */ 52, 53, 54, 55, 56, 57, 58, 5, 198, 61, + /* 110 */ 110, 1, 233, 13, 14, 236, 16, 17, 81, 9, + /* 120 */ 20, 21, 1, 23, 24, 25, 26, 27, 28, 258, + /* 130 */ 9, 260, 105, 33, 34, 33, 34, 37, 38, 39, + /* 140 */ 13, 14, 232, 16, 17, 197, 256, 20, 21, 201, + /* 150 */ 23, 24, 25, 26, 27, 28, 65, 66, 67, 138, + /* 160 */ 33, 34, 141, 142, 37, 38, 39, 88, 89, 90, /* 170 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - /* 180 */ 101, 102, 209, 191, 211, 212, 213, 214, 215, 216, - /* 190 */ 217, 218, 219, 220, 221, 222, 223, 224, 16, 17, - /* 200 */ 196, 252, 20, 21, 200, 23, 24, 25, 26, 27, - /* 210 */ 28, 256, 44, 258, 137, 33, 34, 140, 141, 37, - /* 220 */ 38, 39, 1, 2, 232, 191, 5, 235, 7, 61, - /* 230 */ 9, 1, 2, 210, 252, 5, 68, 7, 135, 9, - /* 240 */ 191, 73, 74, 75, 37, 1, 143, 144, 25, 26, - /* 250 */ 27, 28, 104, 9, 33, 34, 33, 34, 37, 236, - /* 260 */ 37, 38, 39, 33, 34, 104, 232, 109, 88, 235, - /* 270 */ 90, 91, 104, 112, 5, 95, 7, 97, 98, 99, - /* 280 */ 112, 101, 102, 209, 235, 2, 212, 213, 5, 131, - /* 290 */ 7, 217, 9, 219, 220, 221, 197, 223, 224, 62, - /* 300 */ 63, 64, 134, 0, 136, 191, 69, 70, 71, 72, - /* 310 */ 142, 62, 63, 64, 191, 78, 33, 34, 69, 70, - /* 320 */ 71, 72, 115, 68, 191, 104, 191, 228, 229, 230, - /* 330 */ 231, 5, 111, 7, 104, 62, 63, 64, 117, 198, - /* 340 */ 199, 111, 69, 70, 71, 72, 232, 117, 191, 235, - /* 350 */ 15, 33, 34, 197, 133, 37, 38, 39, 196, 5, - /* 360 */ 104, 7, 200, 133, 108, 232, 110, 232, 235, 60, - /* 370 */ 235, 65, 66, 67, 62, 63, 64, 237, 124, 125, - /* 380 */ 196, 258, 79, 226, 200, 229, 117, 105, 1, 105, - /* 390 */ 250, 109, 137, 227, 111, 140, 105, 113, 105, 105, - /* 400 */ 109, 105, 109, 109, 105, 109, 109, 105, 109, 191, - /* 410 */ 105, 109, 105, 104, 109, 105, 109, 252, 105, 109, - /* 420 */ 104, 252, 109, 107, 37, 252, 129, 138, 139, 252, - /* 430 */ 138, 139, 227, 138, 139, 104, 227, 106, 138, 139, - /* 440 */ 5, 252, 7, 117, 76, 77, 111, 252, 252, 252, - /* 450 */ 252, 252, 252, 252, 252, 252, 252, 191, 236, 227, - /* 460 */ 236, 227, 227, 227, 251, 191, 191, 234, 191, 191, - /* 470 */ 191, 259, 234, 259, 234, 60, 191, 238, 191, 191, - /* 480 */ 255, 191, 117, 255, 255, 239, 255, 244, 247, 191, - /* 490 */ 248, 246, 191, 245, 122, 191, 243, 128, 127, 191, - /* 500 */ 130, 126, 191, 121, 120, 191, 191, 242, 191, 119, - /* 510 */ 191, 191, 191, 191, 191, 191, 191, 241, 191, 191, - /* 520 */ 191, 191, 118, 191, 191, 191, 240, 191, 191, 191, - /* 530 */ 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, - /* 540 */ 191, 191, 191, 191, 191, 132, 191, 191, 191, 191, - /* 550 */ 191, 191, 191, 103, 192, 192, 192, 87, 192, 192, - /* 560 */ 86, 50, 83, 85, 54, 192, 192, 84, 192, 82, - /* 570 */ 79, 5, 192, 192, 145, 197, 197, 5, 5, 145, - /* 580 */ 5, 5, 90, 89, 135, 113, 192, 192, 202, 107, - /* 590 */ 193, 208, 207, 204, 206, 203, 205, 201, 193, 193, - /* 600 */ 192, 192, 225, 193, 192, 198, 104, 114, 194, 105, - /* 610 */ 109, 105, 104, 1, 105, 76, 109, 104, 225, 104, - /* 620 */ 123, 105, 104, 109, 105, 104, 109, 104, 123, 104, - /* 630 */ 108, 111, 104, 107, 9, 5, 5, 5, 5, 5, - /* 640 */ 80, 15, 139, 76, 109, 16, 5, 5, 105, 5, - /* 650 */ 5, 139, 5, 5, 5, 5, 5, 5, 5, 5, - /* 660 */ 5, 5, 5, 139, 5, 5, 5, 5, 109, 80, - /* 670 */ 60, 0, 59, 263, 263, 263, 263, 263, 263, 21, - /* 680 */ 263, 263, 263, 263, 21, 263, 263, 263, 263, 263, - /* 690 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 700 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 710 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 720 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 730 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 740 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 750 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 760 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 770 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 780 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 790 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 800 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 810 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 820 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 830 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 840 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 850 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 860 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 870 */ 263, 263, + /* 180 */ 101, 102, 210, 192, 212, 213, 214, 215, 216, 217, + /* 190 */ 218, 219, 220, 221, 222, 223, 224, 225, 16, 17, + /* 200 */ 254, 235, 20, 21, 0, 23, 24, 25, 26, 27, + /* 210 */ 28, 254, 44, 198, 104, 33, 34, 251, 192, 37, + /* 220 */ 38, 39, 1, 2, 233, 192, 5, 236, 7, 61, + /* 230 */ 9, 1, 2, 211, 104, 5, 68, 7, 108, 9, + /* 240 */ 110, 73, 74, 75, 229, 230, 231, 232, 25, 26, + /* 250 */ 27, 28, 15, 227, 33, 34, 33, 34, 37, 237, + /* 260 */ 37, 38, 39, 33, 34, 136, 233, 68, 88, 236, + /* 270 */ 90, 91, 104, 144, 145, 95, 237, 97, 98, 99, + /* 280 */ 112, 101, 102, 79, 210, 33, 34, 213, 214, 37, + /* 290 */ 38, 39, 218, 192, 220, 221, 222, 211, 224, 225, + /* 300 */ 62, 63, 64, 135, 5, 137, 7, 69, 70, 71, + /* 310 */ 72, 143, 2, 37, 198, 5, 78, 7, 192, 9, + /* 320 */ 62, 63, 64, 237, 192, 104, 192, 69, 70, 71, + /* 330 */ 72, 192, 111, 5, 104, 7, 104, 138, 117, 107, + /* 340 */ 141, 111, 238, 33, 34, 104, 230, 117, 111, 76, + /* 350 */ 62, 63, 64, 112, 81, 134, 252, 69, 70, 71, + /* 360 */ 72, 260, 236, 254, 134, 233, 105, 233, 236, 197, + /* 370 */ 236, 60, 233, 201, 113, 236, 37, 38, 39, 62, + /* 380 */ 63, 64, 197, 199, 200, 254, 201, 195, 196, 125, + /* 390 */ 126, 115, 109, 1, 105, 109, 105, 105, 109, 116, + /* 400 */ 109, 109, 105, 105, 109, 105, 109, 109, 105, 109, + /* 410 */ 105, 254, 109, 105, 109, 104, 117, 109, 132, 105, + /* 420 */ 105, 111, 253, 109, 109, 130, 139, 140, 104, 37, + /* 430 */ 106, 254, 139, 140, 228, 139, 140, 76, 77, 228, + /* 440 */ 139, 140, 5, 254, 7, 117, 237, 254, 254, 254, + /* 450 */ 254, 254, 254, 228, 254, 254, 254, 254, 192, 254, + /* 460 */ 192, 228, 228, 228, 228, 239, 192, 192, 261, 192, + /* 470 */ 192, 192, 192, 261, 235, 235, 192, 235, 60, 257, + /* 480 */ 249, 257, 192, 117, 257, 257, 192, 103, 240, 242, + /* 490 */ 244, 246, 248, 250, 192, 123, 192, 129, 192, 192, + /* 500 */ 131, 192, 128, 247, 192, 192, 127, 122, 192, 121, + /* 510 */ 192, 192, 192, 192, 192, 192, 245, 192, 192, 192, + /* 520 */ 120, 192, 192, 192, 192, 192, 192, 192, 192, 192, + /* 530 */ 192, 119, 192, 192, 192, 192, 192, 192, 192, 192, + /* 540 */ 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, + /* 550 */ 192, 192, 192, 118, 133, 193, 193, 193, 193, 87, + /* 560 */ 193, 86, 50, 83, 85, 54, 193, 84, 193, 193, + /* 570 */ 82, 79, 5, 146, 193, 193, 198, 5, 198, 5, + /* 580 */ 146, 5, 5, 90, 89, 136, 113, 105, 193, 193, + /* 590 */ 203, 193, 209, 194, 208, 205, 207, 206, 204, 202, + /* 600 */ 194, 194, 194, 226, 193, 195, 193, 107, 199, 104, + /* 610 */ 114, 109, 241, 243, 105, 105, 109, 104, 104, 226, + /* 620 */ 105, 104, 1, 104, 108, 105, 104, 109, 124, 105, + /* 630 */ 109, 104, 124, 104, 111, 104, 104, 107, 76, 9, + /* 640 */ 5, 5, 5, 5, 5, 80, 15, 76, 109, 16, + /* 650 */ 5, 5, 105, 5, 5, 5, 5, 5, 5, 5, + /* 660 */ 5, 5, 5, 5, 5, 140, 140, 5, 140, 5, + /* 670 */ 5, 5, 5, 109, 80, 60, 59, 0, 265, 265, + /* 680 */ 265, 21, 21, 265, 265, 265, 265, 265, 265, 265, + /* 690 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 700 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 710 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 720 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 730 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 740 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 750 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 760 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 770 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 780 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 790 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 800 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 810 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 820 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 830 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 840 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 850 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 860 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 870 */ 265, }; -#define YY_SHIFT_COUNT (316) +#define YY_SHIFT_COUNT (320) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (671) +#define YY_SHIFT_MAX (677) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 168, 79, 79, 180, 180, 9, 221, 230, 244, 244, - /* 10 */ 244, 244, 244, 244, 244, 244, 244, 0, 48, 230, - /* 20 */ 283, 283, 283, 283, 148, 161, 244, 244, 244, 303, - /* 30 */ 244, 244, 82, 9, 37, 37, 685, 685, 685, 230, + /* 0 */ 168, 79, 79, 180, 180, 9, 221, 230, 121, 121, + /* 10 */ 121, 121, 121, 121, 121, 121, 121, 0, 48, 230, + /* 20 */ 310, 310, 310, 310, 110, 241, 121, 121, 121, 204, + /* 30 */ 121, 121, 273, 9, 37, 37, 683, 683, 683, 230, /* 40 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, - /* 50 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 283, - /* 60 */ 283, 78, 78, 78, 78, 78, 78, 78, 244, 244, - /* 70 */ 244, 207, 244, 161, 161, 244, 244, 244, 254, 254, - /* 80 */ 26, 161, 244, 244, 244, 244, 244, 244, 244, 244, - /* 90 */ 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - /* 100 */ 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - /* 110 */ 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - /* 120 */ 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - /* 130 */ 244, 244, 244, 415, 415, 415, 365, 365, 365, 415, - /* 140 */ 365, 415, 369, 370, 371, 372, 375, 382, 384, 390, - /* 150 */ 404, 413, 415, 415, 415, 450, 9, 9, 415, 415, - /* 160 */ 470, 474, 511, 479, 478, 510, 483, 487, 450, 415, - /* 170 */ 491, 491, 415, 491, 415, 491, 415, 415, 685, 685, - /* 180 */ 27, 100, 127, 100, 100, 53, 182, 223, 223, 223, - /* 190 */ 223, 237, 249, 273, 318, 318, 318, 318, 77, 103, - /* 200 */ 92, 92, 269, 326, 256, 255, 306, 312, 282, 284, - /* 210 */ 291, 293, 294, 296, 299, 387, 309, 335, 158, 297, - /* 220 */ 302, 305, 307, 310, 313, 316, 289, 292, 295, 331, - /* 230 */ 300, 354, 435, 368, 566, 429, 572, 573, 434, 575, - /* 240 */ 576, 492, 494, 449, 472, 482, 502, 493, 504, 501, - /* 250 */ 506, 508, 509, 507, 513, 612, 515, 516, 518, 514, - /* 260 */ 497, 517, 505, 519, 521, 520, 523, 482, 525, 526, - /* 270 */ 528, 522, 539, 625, 630, 631, 632, 633, 634, 560, - /* 280 */ 626, 567, 503, 535, 535, 629, 512, 524, 535, 641, - /* 290 */ 642, 543, 535, 644, 645, 647, 648, 649, 650, 651, - /* 300 */ 652, 653, 654, 655, 656, 657, 659, 660, 661, 662, - /* 310 */ 559, 589, 658, 663, 610, 613, 671, + /* 50 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 310, + /* 60 */ 310, 102, 102, 102, 102, 102, 102, 102, 121, 121, + /* 70 */ 121, 276, 121, 241, 241, 121, 121, 121, 121, 264, + /* 80 */ 264, 283, 241, 121, 121, 121, 121, 121, 121, 121, + /* 90 */ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + /* 100 */ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + /* 110 */ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + /* 120 */ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + /* 130 */ 121, 121, 121, 121, 418, 418, 418, 366, 366, 366, + /* 140 */ 418, 366, 418, 368, 369, 374, 372, 379, 385, 388, + /* 150 */ 400, 412, 435, 421, 418, 418, 418, 384, 9, 9, + /* 160 */ 418, 418, 472, 475, 512, 480, 479, 511, 483, 488, + /* 170 */ 384, 418, 492, 492, 418, 492, 418, 492, 418, 418, + /* 180 */ 683, 683, 27, 100, 127, 100, 100, 53, 182, 223, + /* 190 */ 223, 223, 223, 238, 258, 288, 252, 252, 252, 252, + /* 200 */ 21, 129, 339, 339, 299, 328, 130, 199, 91, 317, + /* 210 */ 289, 261, 291, 292, 297, 298, 300, 392, 311, 237, + /* 220 */ 286, 295, 303, 305, 308, 314, 315, 232, 287, 293, + /* 230 */ 296, 324, 301, 1, 437, 361, 567, 427, 572, 574, + /* 240 */ 434, 576, 577, 493, 495, 449, 473, 500, 505, 496, + /* 250 */ 482, 502, 509, 513, 510, 507, 514, 515, 517, 621, + /* 260 */ 519, 520, 522, 518, 504, 521, 508, 524, 527, 523, + /* 270 */ 529, 500, 531, 530, 532, 516, 562, 630, 635, 636, + /* 280 */ 637, 638, 639, 565, 631, 571, 525, 539, 539, 633, + /* 290 */ 526, 528, 539, 645, 646, 547, 539, 648, 649, 650, + /* 300 */ 651, 652, 653, 654, 655, 656, 657, 658, 659, 662, + /* 310 */ 664, 665, 666, 667, 564, 594, 660, 661, 615, 617, + /* 320 */ 677, }; -#define YY_REDUCE_COUNT (179) -#define YY_REDUCE_MIN (-233) -#define YY_REDUCE_MAX (414) +#define YY_REDUCE_COUNT (181) +#define YY_REDUCE_MIN (-242) +#define YY_REDUCE_MAX (413) static const short yy_reduce_ofst[] = { - /* 0 */ -178, -27, -27, 74, 74, 99, -230, -216, -173, -176, - /* 10 */ -45, -76, -8, 34, 114, 133, 135, -185, -188, -233, - /* 20 */ -206, -147, -74, 23, -179, -127, -186, 123, -191, -112, - /* 30 */ 157, 49, 4, 156, 162, 184, 140, 141, -187, -217, - /* 40 */ -194, -144, -51, -18, 165, 169, 173, 177, 189, 195, - /* 50 */ 196, 197, 198, 199, 200, 201, 202, 203, 204, 222, - /* 60 */ 224, 166, 205, 209, 232, 234, 235, 236, 218, 266, - /* 70 */ 274, 213, 275, 233, 238, 277, 278, 279, 212, 214, - /* 80 */ 239, 240, 285, 287, 288, 290, 298, 301, 304, 308, - /* 90 */ 311, 314, 315, 317, 319, 320, 321, 322, 323, 324, - /* 100 */ 325, 327, 328, 329, 330, 332, 333, 334, 336, 337, - /* 110 */ 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - /* 120 */ 348, 349, 350, 351, 352, 353, 355, 356, 357, 358, - /* 130 */ 359, 360, 361, 362, 363, 364, 225, 228, 229, 366, - /* 140 */ 231, 367, 242, 241, 245, 248, 243, 253, 265, 276, - /* 150 */ 286, 246, 373, 374, 376, 377, 378, 379, 380, 381, - /* 160 */ 383, 385, 388, 386, 391, 392, 389, 396, 393, 394, - /* 170 */ 397, 405, 395, 406, 408, 410, 409, 412, 407, 414, + /* 0 */ -179, -28, -28, 74, 74, 15, -232, -218, -174, -177, + /* 10 */ -129, -121, -9, 33, 132, 134, 139, -187, -189, -235, + /* 20 */ -207, -153, 22, 86, -110, -34, -185, 101, -192, -90, + /* 30 */ 26, 126, -52, 116, 172, 185, 104, 184, 192, -242, + /* 40 */ -219, -54, -43, 109, 131, 157, 177, 189, 193, 194, + /* 50 */ 195, 196, 197, 198, 200, 201, 202, 203, 205, 39, + /* 60 */ 209, 206, 211, 225, 233, 234, 235, 236, 266, 268, + /* 70 */ 274, 169, 275, 239, 240, 277, 278, 279, 280, 207, + /* 80 */ 212, 226, 242, 284, 290, 294, 302, 304, 306, 307, + /* 90 */ 309, 312, 313, 316, 318, 319, 320, 321, 322, 323, + /* 100 */ 325, 326, 327, 329, 330, 331, 332, 333, 334, 335, + /* 110 */ 336, 337, 338, 340, 341, 342, 343, 344, 345, 346, + /* 120 */ 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, + /* 130 */ 357, 358, 359, 360, 362, 363, 364, 222, 224, 227, + /* 140 */ 365, 228, 367, 243, 231, 244, 256, 245, 271, 246, + /* 150 */ 370, 247, 371, 248, 373, 375, 376, 377, 378, 380, + /* 160 */ 381, 382, 383, 386, 389, 387, 391, 394, 390, 397, + /* 170 */ 393, 395, 399, 406, 396, 407, 398, 408, 411, 413, + /* 180 */ 409, 410, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 781, 894, 840, 906, 828, 837, 1037, 1037, 781, 781, - /* 10 */ 781, 781, 781, 781, 781, 781, 781, 953, 800, 1037, - /* 20 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 837, - /* 30 */ 781, 781, 843, 837, 843, 843, 948, 878, 896, 781, - /* 40 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 50 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 60 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 70 */ 781, 955, 958, 781, 781, 960, 781, 781, 980, 980, - /* 80 */ 946, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 90 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 100 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 826, - /* 110 */ 781, 824, 781, 781, 781, 781, 781, 781, 781, 781, - /* 120 */ 781, 781, 781, 781, 781, 781, 811, 781, 781, 781, - /* 130 */ 781, 781, 781, 802, 802, 802, 781, 781, 781, 802, - /* 140 */ 781, 802, 987, 991, 985, 973, 981, 972, 968, 966, - /* 150 */ 965, 995, 802, 802, 802, 841, 837, 837, 802, 802, - /* 160 */ 859, 857, 855, 847, 853, 849, 851, 845, 829, 802, - /* 170 */ 835, 835, 802, 835, 802, 835, 802, 802, 878, 896, - /* 180 */ 781, 996, 781, 1036, 986, 1026, 1025, 1032, 1024, 1023, - /* 190 */ 1022, 781, 781, 781, 1018, 1019, 1021, 1020, 781, 781, - /* 200 */ 1028, 1027, 781, 781, 781, 781, 781, 781, 781, 781, - /* 210 */ 781, 781, 781, 781, 781, 781, 998, 781, 992, 988, - /* 220 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 908, - /* 230 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 240 */ 781, 781, 781, 781, 945, 781, 781, 781, 781, 956, - /* 250 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 982, - /* 260 */ 781, 974, 781, 781, 781, 781, 781, 920, 781, 781, - /* 270 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 280 */ 781, 781, 781, 1048, 1046, 781, 781, 781, 1042, 781, - /* 290 */ 781, 781, 1040, 781, 781, 781, 781, 781, 781, 781, - /* 300 */ 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, - /* 310 */ 862, 781, 809, 807, 781, 798, 781, + /* 0 */ 788, 901, 847, 913, 835, 844, 1046, 1046, 788, 788, + /* 10 */ 788, 788, 788, 788, 788, 788, 788, 960, 807, 1046, + /* 20 */ 788, 788, 788, 788, 788, 788, 788, 788, 788, 844, + /* 30 */ 788, 788, 850, 844, 850, 850, 955, 885, 903, 788, + /* 40 */ 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, + /* 50 */ 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, + /* 60 */ 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, + /* 70 */ 788, 962, 965, 788, 788, 967, 788, 788, 788, 989, + /* 80 */ 989, 953, 788, 788, 788, 788, 788, 788, 788, 788, + /* 90 */ 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, + /* 100 */ 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, + /* 110 */ 833, 788, 831, 788, 788, 788, 788, 788, 788, 788, + /* 120 */ 788, 788, 788, 788, 788, 788, 788, 818, 788, 788, + /* 130 */ 788, 788, 788, 788, 809, 809, 809, 788, 788, 788, + /* 140 */ 809, 788, 809, 996, 1000, 994, 982, 990, 981, 977, + /* 150 */ 975, 973, 972, 1004, 809, 809, 809, 848, 844, 844, + /* 160 */ 809, 809, 866, 864, 862, 854, 860, 856, 858, 852, + /* 170 */ 836, 809, 842, 842, 809, 842, 809, 842, 809, 809, + /* 180 */ 885, 903, 788, 1005, 788, 1045, 995, 1035, 1034, 1041, + /* 190 */ 1033, 1032, 1031, 788, 788, 788, 1027, 1028, 1030, 1029, + /* 200 */ 788, 788, 1037, 1036, 788, 788, 788, 788, 788, 788, + /* 210 */ 788, 788, 788, 788, 788, 788, 788, 788, 1007, 788, + /* 220 */ 1001, 997, 788, 788, 788, 788, 788, 788, 788, 788, + /* 230 */ 788, 915, 788, 788, 788, 788, 788, 788, 788, 788, + /* 240 */ 788, 788, 788, 788, 788, 788, 952, 788, 788, 788, + /* 250 */ 788, 963, 788, 788, 788, 788, 788, 788, 788, 788, + /* 260 */ 788, 788, 788, 991, 788, 983, 788, 788, 788, 788, + /* 270 */ 788, 927, 788, 788, 788, 788, 788, 788, 788, 788, + /* 280 */ 788, 788, 788, 788, 788, 788, 788, 1057, 1055, 788, + /* 290 */ 788, 788, 1051, 788, 788, 788, 1049, 788, 788, 788, + /* 300 */ 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, + /* 310 */ 788, 788, 788, 788, 869, 788, 816, 814, 788, 805, + /* 320 */ 788, }; /********** End of lemon-generated parsing tables *****************************/ @@ -597,6 +601,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* VARIABLE => nothing */ 0, /* INTERVAL => nothing */ 0, /* SESSION => nothing */ + 0, /* STATE_WINDOW => nothing */ 0, /* FILL => nothing */ 0, /* SLIDING => nothing */ 0, /* ORDER => nothing */ @@ -870,149 +875,151 @@ static const char *const yyTokenName[] = { /* 117 */ "VARIABLE", /* 118 */ "INTERVAL", /* 119 */ "SESSION", - /* 120 */ "FILL", - /* 121 */ "SLIDING", - /* 122 */ "ORDER", - /* 123 */ "BY", - /* 124 */ "ASC", - /* 125 */ "DESC", - /* 126 */ "GROUP", - /* 127 */ "HAVING", - /* 128 */ "LIMIT", - /* 129 */ "OFFSET", - /* 130 */ "SLIMIT", - /* 131 */ "SOFFSET", - /* 132 */ "WHERE", - /* 133 */ "NOW", - /* 134 */ "RESET", - /* 135 */ "QUERY", - /* 136 */ "SYNCDB", - /* 137 */ "ADD", - /* 138 */ "COLUMN", - /* 139 */ "TAG", - /* 140 */ "CHANGE", - /* 141 */ "SET", - /* 142 */ "KILL", - /* 143 */ "CONNECTION", - /* 144 */ "STREAM", - /* 145 */ "COLON", - /* 146 */ "ABORT", - /* 147 */ "AFTER", - /* 148 */ "ATTACH", - /* 149 */ "BEFORE", - /* 150 */ "BEGIN", - /* 151 */ "CASCADE", - /* 152 */ "CLUSTER", - /* 153 */ "CONFLICT", - /* 154 */ "COPY", - /* 155 */ "DEFERRED", - /* 156 */ "DELIMITERS", - /* 157 */ "DETACH", - /* 158 */ "EACH", - /* 159 */ "END", - /* 160 */ "EXPLAIN", - /* 161 */ "FAIL", - /* 162 */ "FOR", - /* 163 */ "IGNORE", - /* 164 */ "IMMEDIATE", - /* 165 */ "INITIALLY", - /* 166 */ "INSTEAD", - /* 167 */ "MATCH", - /* 168 */ "KEY", - /* 169 */ "OF", - /* 170 */ "RAISE", - /* 171 */ "REPLACE", - /* 172 */ "RESTRICT", - /* 173 */ "ROW", - /* 174 */ "STATEMENT", - /* 175 */ "TRIGGER", - /* 176 */ "VIEW", - /* 177 */ "SEMI", - /* 178 */ "NONE", - /* 179 */ "PREV", - /* 180 */ "LINEAR", - /* 181 */ "IMPORT", - /* 182 */ "TBNAME", - /* 183 */ "JOIN", - /* 184 */ "INSERT", - /* 185 */ "INTO", - /* 186 */ "VALUES", - /* 187 */ "error", - /* 188 */ "program", - /* 189 */ "cmd", - /* 190 */ "dbPrefix", - /* 191 */ "ids", - /* 192 */ "cpxName", - /* 193 */ "ifexists", - /* 194 */ "alter_db_optr", - /* 195 */ "alter_topic_optr", - /* 196 */ "acct_optr", - /* 197 */ "ifnotexists", - /* 198 */ "db_optr", - /* 199 */ "topic_optr", - /* 200 */ "pps", - /* 201 */ "tseries", - /* 202 */ "dbs", - /* 203 */ "streams", - /* 204 */ "storage", - /* 205 */ "qtime", - /* 206 */ "users", - /* 207 */ "conns", - /* 208 */ "state", - /* 209 */ "keep", - /* 210 */ "tagitemlist", - /* 211 */ "cache", - /* 212 */ "replica", - /* 213 */ "quorum", - /* 214 */ "days", - /* 215 */ "minrows", - /* 216 */ "maxrows", - /* 217 */ "blocks", - /* 218 */ "ctime", - /* 219 */ "wal", - /* 220 */ "fsync", - /* 221 */ "comp", - /* 222 */ "prec", - /* 223 */ "update", - /* 224 */ "cachelast", - /* 225 */ "partitions", - /* 226 */ "typename", - /* 227 */ "signed", - /* 228 */ "create_table_args", - /* 229 */ "create_stable_args", - /* 230 */ "create_table_list", - /* 231 */ "create_from_stable", - /* 232 */ "columnlist", - /* 233 */ "tagNamelist", - /* 234 */ "select", - /* 235 */ "column", - /* 236 */ "tagitem", - /* 237 */ "selcollist", - /* 238 */ "from", - /* 239 */ "where_opt", - /* 240 */ "interval_opt", - /* 241 */ "session_option", - /* 242 */ "fill_opt", - /* 243 */ "sliding_opt", - /* 244 */ "groupby_opt", - /* 245 */ "orderby_opt", - /* 246 */ "having_opt", - /* 247 */ "slimit_opt", - /* 248 */ "limit_opt", - /* 249 */ "union", - /* 250 */ "sclp", - /* 251 */ "distinct", - /* 252 */ "expr", - /* 253 */ "as", - /* 254 */ "tablelist", - /* 255 */ "tmvar", - /* 256 */ "sortlist", - /* 257 */ "sortitem", - /* 258 */ "item", - /* 259 */ "sortorder", - /* 260 */ "grouplist", - /* 261 */ "exprlist", - /* 262 */ "expritem", + /* 120 */ "STATE_WINDOW", + /* 121 */ "FILL", + /* 122 */ "SLIDING", + /* 123 */ "ORDER", + /* 124 */ "BY", + /* 125 */ "ASC", + /* 126 */ "DESC", + /* 127 */ "GROUP", + /* 128 */ "HAVING", + /* 129 */ "LIMIT", + /* 130 */ "OFFSET", + /* 131 */ "SLIMIT", + /* 132 */ "SOFFSET", + /* 133 */ "WHERE", + /* 134 */ "NOW", + /* 135 */ "RESET", + /* 136 */ "QUERY", + /* 137 */ "SYNCDB", + /* 138 */ "ADD", + /* 139 */ "COLUMN", + /* 140 */ "TAG", + /* 141 */ "CHANGE", + /* 142 */ "SET", + /* 143 */ "KILL", + /* 144 */ "CONNECTION", + /* 145 */ "STREAM", + /* 146 */ "COLON", + /* 147 */ "ABORT", + /* 148 */ "AFTER", + /* 149 */ "ATTACH", + /* 150 */ "BEFORE", + /* 151 */ "BEGIN", + /* 152 */ "CASCADE", + /* 153 */ "CLUSTER", + /* 154 */ "CONFLICT", + /* 155 */ "COPY", + /* 156 */ "DEFERRED", + /* 157 */ "DELIMITERS", + /* 158 */ "DETACH", + /* 159 */ "EACH", + /* 160 */ "END", + /* 161 */ "EXPLAIN", + /* 162 */ "FAIL", + /* 163 */ "FOR", + /* 164 */ "IGNORE", + /* 165 */ "IMMEDIATE", + /* 166 */ "INITIALLY", + /* 167 */ "INSTEAD", + /* 168 */ "MATCH", + /* 169 */ "KEY", + /* 170 */ "OF", + /* 171 */ "RAISE", + /* 172 */ "REPLACE", + /* 173 */ "RESTRICT", + /* 174 */ "ROW", + /* 175 */ "STATEMENT", + /* 176 */ "TRIGGER", + /* 177 */ "VIEW", + /* 178 */ "SEMI", + /* 179 */ "NONE", + /* 180 */ "PREV", + /* 181 */ "LINEAR", + /* 182 */ "IMPORT", + /* 183 */ "TBNAME", + /* 184 */ "JOIN", + /* 185 */ "INSERT", + /* 186 */ "INTO", + /* 187 */ "VALUES", + /* 188 */ "error", + /* 189 */ "program", + /* 190 */ "cmd", + /* 191 */ "dbPrefix", + /* 192 */ "ids", + /* 193 */ "cpxName", + /* 194 */ "ifexists", + /* 195 */ "alter_db_optr", + /* 196 */ "alter_topic_optr", + /* 197 */ "acct_optr", + /* 198 */ "ifnotexists", + /* 199 */ "db_optr", + /* 200 */ "topic_optr", + /* 201 */ "pps", + /* 202 */ "tseries", + /* 203 */ "dbs", + /* 204 */ "streams", + /* 205 */ "storage", + /* 206 */ "qtime", + /* 207 */ "users", + /* 208 */ "conns", + /* 209 */ "state", + /* 210 */ "keep", + /* 211 */ "tagitemlist", + /* 212 */ "cache", + /* 213 */ "replica", + /* 214 */ "quorum", + /* 215 */ "days", + /* 216 */ "minrows", + /* 217 */ "maxrows", + /* 218 */ "blocks", + /* 219 */ "ctime", + /* 220 */ "wal", + /* 221 */ "fsync", + /* 222 */ "comp", + /* 223 */ "prec", + /* 224 */ "update", + /* 225 */ "cachelast", + /* 226 */ "partitions", + /* 227 */ "typename", + /* 228 */ "signed", + /* 229 */ "create_table_args", + /* 230 */ "create_stable_args", + /* 231 */ "create_table_list", + /* 232 */ "create_from_stable", + /* 233 */ "columnlist", + /* 234 */ "tagNamelist", + /* 235 */ "select", + /* 236 */ "column", + /* 237 */ "tagitem", + /* 238 */ "selcollist", + /* 239 */ "from", + /* 240 */ "where_opt", + /* 241 */ "interval_opt", + /* 242 */ "session_option", + /* 243 */ "windowstate_option", + /* 244 */ "fill_opt", + /* 245 */ "sliding_opt", + /* 246 */ "groupby_opt", + /* 247 */ "orderby_opt", + /* 248 */ "having_opt", + /* 249 */ "slimit_opt", + /* 250 */ "limit_opt", + /* 251 */ "union", + /* 252 */ "sclp", + /* 253 */ "distinct", + /* 254 */ "expr", + /* 255 */ "as", + /* 256 */ "tablelist", + /* 257 */ "tmvar", + /* 258 */ "sortlist", + /* 259 */ "sortitem", + /* 260 */ "item", + /* 261 */ "sortorder", + /* 262 */ "grouplist", + /* 263 */ "exprlist", + /* 264 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1177,7 +1184,7 @@ static const char *const yyRuleName[] = { /* 154 */ "tagitem ::= MINUS FLOAT", /* 155 */ "tagitem ::= PLUS INTEGER", /* 156 */ "tagitem ::= PLUS FLOAT", - /* 157 */ "select ::= SELECT selcollist from where_opt interval_opt session_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", + /* 157 */ "select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", /* 158 */ "select ::= LP select RP", /* 159 */ "union ::= select", /* 160 */ "union ::= union UNION ALL select", @@ -1204,92 +1211,94 @@ static const char *const yyRuleName[] = { /* 181 */ "interval_opt ::=", /* 182 */ "session_option ::=", /* 183 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 184 */ "fill_opt ::=", - /* 185 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 186 */ "fill_opt ::= FILL LP ID RP", - /* 187 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 188 */ "sliding_opt ::=", - /* 189 */ "orderby_opt ::=", - /* 190 */ "orderby_opt ::= ORDER BY sortlist", - /* 191 */ "sortlist ::= sortlist COMMA item sortorder", - /* 192 */ "sortlist ::= item sortorder", - /* 193 */ "item ::= ids cpxName", - /* 194 */ "sortorder ::= ASC", - /* 195 */ "sortorder ::= DESC", - /* 196 */ "sortorder ::=", - /* 197 */ "groupby_opt ::=", - /* 198 */ "groupby_opt ::= GROUP BY grouplist", - /* 199 */ "grouplist ::= grouplist COMMA item", - /* 200 */ "grouplist ::= item", - /* 201 */ "having_opt ::=", - /* 202 */ "having_opt ::= HAVING expr", - /* 203 */ "limit_opt ::=", - /* 204 */ "limit_opt ::= LIMIT signed", - /* 205 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 206 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 207 */ "slimit_opt ::=", - /* 208 */ "slimit_opt ::= SLIMIT signed", - /* 209 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 210 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 211 */ "where_opt ::=", - /* 212 */ "where_opt ::= WHERE expr", - /* 213 */ "expr ::= LP expr RP", - /* 214 */ "expr ::= ID", - /* 215 */ "expr ::= ID DOT ID", - /* 216 */ "expr ::= ID DOT STAR", - /* 217 */ "expr ::= INTEGER", - /* 218 */ "expr ::= MINUS INTEGER", - /* 219 */ "expr ::= PLUS INTEGER", - /* 220 */ "expr ::= FLOAT", - /* 221 */ "expr ::= MINUS FLOAT", - /* 222 */ "expr ::= PLUS FLOAT", - /* 223 */ "expr ::= STRING", - /* 224 */ "expr ::= NOW", - /* 225 */ "expr ::= VARIABLE", - /* 226 */ "expr ::= PLUS VARIABLE", - /* 227 */ "expr ::= MINUS VARIABLE", - /* 228 */ "expr ::= BOOL", - /* 229 */ "expr ::= NULL", - /* 230 */ "expr ::= ID LP exprlist RP", - /* 231 */ "expr ::= ID LP STAR RP", - /* 232 */ "expr ::= expr IS NULL", - /* 233 */ "expr ::= expr IS NOT NULL", - /* 234 */ "expr ::= expr LT expr", - /* 235 */ "expr ::= expr GT expr", - /* 236 */ "expr ::= expr LE expr", - /* 237 */ "expr ::= expr GE expr", - /* 238 */ "expr ::= expr NE expr", - /* 239 */ "expr ::= expr EQ expr", - /* 240 */ "expr ::= expr BETWEEN expr AND expr", - /* 241 */ "expr ::= expr AND expr", - /* 242 */ "expr ::= expr OR expr", - /* 243 */ "expr ::= expr PLUS expr", - /* 244 */ "expr ::= expr MINUS expr", - /* 245 */ "expr ::= expr STAR expr", - /* 246 */ "expr ::= expr SLASH expr", - /* 247 */ "expr ::= expr REM expr", - /* 248 */ "expr ::= expr LIKE expr", - /* 249 */ "expr ::= expr IN LP exprlist RP", - /* 250 */ "exprlist ::= exprlist COMMA expritem", - /* 251 */ "exprlist ::= expritem", - /* 252 */ "expritem ::= expr", - /* 253 */ "expritem ::=", - /* 254 */ "cmd ::= RESET QUERY CACHE", - /* 255 */ "cmd ::= SYNCDB ids REPLICA", - /* 256 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 257 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 258 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 259 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 260 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 261 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 262 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 263 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 264 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 265 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 266 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 267 */ "cmd ::= KILL CONNECTION INTEGER", - /* 268 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 269 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 184 */ "windowstate_option ::=", + /* 185 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 186 */ "fill_opt ::=", + /* 187 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 188 */ "fill_opt ::= FILL LP ID RP", + /* 189 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 190 */ "sliding_opt ::=", + /* 191 */ "orderby_opt ::=", + /* 192 */ "orderby_opt ::= ORDER BY sortlist", + /* 193 */ "sortlist ::= sortlist COMMA item sortorder", + /* 194 */ "sortlist ::= item sortorder", + /* 195 */ "item ::= ids cpxName", + /* 196 */ "sortorder ::= ASC", + /* 197 */ "sortorder ::= DESC", + /* 198 */ "sortorder ::=", + /* 199 */ "groupby_opt ::=", + /* 200 */ "groupby_opt ::= GROUP BY grouplist", + /* 201 */ "grouplist ::= grouplist COMMA item", + /* 202 */ "grouplist ::= item", + /* 203 */ "having_opt ::=", + /* 204 */ "having_opt ::= HAVING expr", + /* 205 */ "limit_opt ::=", + /* 206 */ "limit_opt ::= LIMIT signed", + /* 207 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 208 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 209 */ "slimit_opt ::=", + /* 210 */ "slimit_opt ::= SLIMIT signed", + /* 211 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 212 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 213 */ "where_opt ::=", + /* 214 */ "where_opt ::= WHERE expr", + /* 215 */ "expr ::= LP expr RP", + /* 216 */ "expr ::= ID", + /* 217 */ "expr ::= ID DOT ID", + /* 218 */ "expr ::= ID DOT STAR", + /* 219 */ "expr ::= INTEGER", + /* 220 */ "expr ::= MINUS INTEGER", + /* 221 */ "expr ::= PLUS INTEGER", + /* 222 */ "expr ::= FLOAT", + /* 223 */ "expr ::= MINUS FLOAT", + /* 224 */ "expr ::= PLUS FLOAT", + /* 225 */ "expr ::= STRING", + /* 226 */ "expr ::= NOW", + /* 227 */ "expr ::= VARIABLE", + /* 228 */ "expr ::= PLUS VARIABLE", + /* 229 */ "expr ::= MINUS VARIABLE", + /* 230 */ "expr ::= BOOL", + /* 231 */ "expr ::= NULL", + /* 232 */ "expr ::= ID LP exprlist RP", + /* 233 */ "expr ::= ID LP STAR RP", + /* 234 */ "expr ::= expr IS NULL", + /* 235 */ "expr ::= expr IS NOT NULL", + /* 236 */ "expr ::= expr LT expr", + /* 237 */ "expr ::= expr GT expr", + /* 238 */ "expr ::= expr LE expr", + /* 239 */ "expr ::= expr GE expr", + /* 240 */ "expr ::= expr NE expr", + /* 241 */ "expr ::= expr EQ expr", + /* 242 */ "expr ::= expr BETWEEN expr AND expr", + /* 243 */ "expr ::= expr AND expr", + /* 244 */ "expr ::= expr OR expr", + /* 245 */ "expr ::= expr PLUS expr", + /* 246 */ "expr ::= expr MINUS expr", + /* 247 */ "expr ::= expr STAR expr", + /* 248 */ "expr ::= expr SLASH expr", + /* 249 */ "expr ::= expr REM expr", + /* 250 */ "expr ::= expr LIKE expr", + /* 251 */ "expr ::= expr IN LP exprlist RP", + /* 252 */ "exprlist ::= exprlist COMMA expritem", + /* 253 */ "exprlist ::= expritem", + /* 254 */ "expritem ::= expr", + /* 255 */ "expritem ::=", + /* 256 */ "cmd ::= RESET QUERY CACHE", + /* 257 */ "cmd ::= SYNCDB ids REPLICA", + /* 258 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 259 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 260 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 261 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 262 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 263 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 264 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 265 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 266 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 267 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 268 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 269 */ "cmd ::= KILL CONNECTION INTEGER", + /* 270 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 271 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1410,58 +1419,58 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 209: /* keep */ - case 210: /* tagitemlist */ - case 232: /* columnlist */ - case 233: /* tagNamelist */ - case 242: /* fill_opt */ - case 244: /* groupby_opt */ - case 245: /* orderby_opt */ - case 256: /* sortlist */ - case 260: /* grouplist */ + case 210: /* keep */ + case 211: /* tagitemlist */ + case 233: /* columnlist */ + case 234: /* tagNamelist */ + case 244: /* fill_opt */ + case 246: /* groupby_opt */ + case 247: /* orderby_opt */ + case 258: /* sortlist */ + case 262: /* grouplist */ { -taosArrayDestroy((yypminor->yy159)); +taosArrayDestroy((yypminor->yy291)); } break; - case 230: /* create_table_list */ + case 231: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy14)); +destroyCreateTableSql((yypminor->yy412)); } break; - case 234: /* select */ + case 235: /* select */ { -destroySqlNode((yypminor->yy116)); +destroySqlNode((yypminor->yy6)); } break; - case 237: /* selcollist */ - case 250: /* sclp */ - case 261: /* exprlist */ + case 238: /* selcollist */ + case 252: /* sclp */ + case 263: /* exprlist */ { -tSqlExprListDestroy((yypminor->yy159)); +tSqlExprListDestroy((yypminor->yy291)); } break; - case 238: /* from */ - case 254: /* tablelist */ + case 239: /* from */ + case 256: /* tablelist */ { -destroyRelationInfo((yypminor->yy236)); +destroyRelationInfo((yypminor->yy254)); } break; - case 239: /* where_opt */ - case 246: /* having_opt */ - case 252: /* expr */ - case 262: /* expritem */ + case 240: /* where_opt */ + case 248: /* having_opt */ + case 254: /* expr */ + case 264: /* expritem */ { -tSqlExprDestroy((yypminor->yy118)); +tSqlExprDestroy((yypminor->yy436)); } break; - case 249: /* union */ + case 251: /* union */ { -destroyAllSqlNode((yypminor->yy159)); +destroyAllSqlNode((yypminor->yy291)); } break; - case 257: /* sortitem */ + case 259: /* sortitem */ { -tVariantDestroy(&(yypminor->yy488)); +tVariantDestroy(&(yypminor->yy216)); } break; /********* End destructor definitions *****************************************/ @@ -1755,276 +1764,278 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 188, -1 }, /* (0) program ::= cmd */ - { 189, -2 }, /* (1) cmd ::= SHOW DATABASES */ - { 189, -2 }, /* (2) cmd ::= SHOW TOPICS */ - { 189, -2 }, /* (3) cmd ::= SHOW MNODES */ - { 189, -2 }, /* (4) cmd ::= SHOW DNODES */ - { 189, -2 }, /* (5) cmd ::= SHOW ACCOUNTS */ - { 189, -2 }, /* (6) cmd ::= SHOW USERS */ - { 189, -2 }, /* (7) cmd ::= SHOW MODULES */ - { 189, -2 }, /* (8) cmd ::= SHOW QUERIES */ - { 189, -2 }, /* (9) cmd ::= SHOW CONNECTIONS */ - { 189, -2 }, /* (10) cmd ::= SHOW STREAMS */ - { 189, -2 }, /* (11) cmd ::= SHOW VARIABLES */ - { 189, -2 }, /* (12) cmd ::= SHOW SCORES */ - { 189, -2 }, /* (13) cmd ::= SHOW GRANTS */ - { 189, -2 }, /* (14) cmd ::= SHOW VNODES */ - { 189, -3 }, /* (15) cmd ::= SHOW VNODES IPTOKEN */ - { 190, 0 }, /* (16) dbPrefix ::= */ - { 190, -2 }, /* (17) dbPrefix ::= ids DOT */ - { 192, 0 }, /* (18) cpxName ::= */ - { 192, -2 }, /* (19) cpxName ::= DOT ids */ - { 189, -5 }, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ - { 189, -5 }, /* (21) cmd ::= SHOW CREATE STABLE ids cpxName */ - { 189, -4 }, /* (22) cmd ::= SHOW CREATE DATABASE ids */ - { 189, -3 }, /* (23) cmd ::= SHOW dbPrefix TABLES */ - { 189, -5 }, /* (24) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - { 189, -3 }, /* (25) cmd ::= SHOW dbPrefix STABLES */ - { 189, -5 }, /* (26) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - { 189, -3 }, /* (27) cmd ::= SHOW dbPrefix VGROUPS */ - { 189, -4 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS ids */ - { 189, -5 }, /* (29) cmd ::= DROP TABLE ifexists ids cpxName */ - { 189, -5 }, /* (30) cmd ::= DROP STABLE ifexists ids cpxName */ - { 189, -4 }, /* (31) cmd ::= DROP DATABASE ifexists ids */ - { 189, -4 }, /* (32) cmd ::= DROP TOPIC ifexists ids */ - { 189, -3 }, /* (33) cmd ::= DROP DNODE ids */ - { 189, -3 }, /* (34) cmd ::= DROP USER ids */ - { 189, -3 }, /* (35) cmd ::= DROP ACCOUNT ids */ - { 189, -2 }, /* (36) cmd ::= USE ids */ - { 189, -3 }, /* (37) cmd ::= DESCRIBE ids cpxName */ - { 189, -5 }, /* (38) cmd ::= ALTER USER ids PASS ids */ - { 189, -5 }, /* (39) cmd ::= ALTER USER ids PRIVILEGE ids */ - { 189, -4 }, /* (40) cmd ::= ALTER DNODE ids ids */ - { 189, -5 }, /* (41) cmd ::= ALTER DNODE ids ids ids */ - { 189, -3 }, /* (42) cmd ::= ALTER LOCAL ids */ - { 189, -4 }, /* (43) cmd ::= ALTER LOCAL ids ids */ - { 189, -4 }, /* (44) cmd ::= ALTER DATABASE ids alter_db_optr */ - { 189, -4 }, /* (45) cmd ::= ALTER TOPIC ids alter_topic_optr */ - { 189, -4 }, /* (46) cmd ::= ALTER ACCOUNT ids acct_optr */ - { 189, -6 }, /* (47) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - { 191, -1 }, /* (48) ids ::= ID */ - { 191, -1 }, /* (49) ids ::= STRING */ - { 193, -2 }, /* (50) ifexists ::= IF EXISTS */ - { 193, 0 }, /* (51) ifexists ::= */ - { 197, -3 }, /* (52) ifnotexists ::= IF NOT EXISTS */ - { 197, 0 }, /* (53) ifnotexists ::= */ - { 189, -3 }, /* (54) cmd ::= CREATE DNODE ids */ - { 189, -6 }, /* (55) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 189, -5 }, /* (56) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 189, -5 }, /* (57) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ - { 189, -5 }, /* (58) cmd ::= CREATE USER ids PASS ids */ - { 200, 0 }, /* (59) pps ::= */ - { 200, -2 }, /* (60) pps ::= PPS INTEGER */ - { 201, 0 }, /* (61) tseries ::= */ - { 201, -2 }, /* (62) tseries ::= TSERIES INTEGER */ - { 202, 0 }, /* (63) dbs ::= */ - { 202, -2 }, /* (64) dbs ::= DBS INTEGER */ - { 203, 0 }, /* (65) streams ::= */ - { 203, -2 }, /* (66) streams ::= STREAMS INTEGER */ - { 204, 0 }, /* (67) storage ::= */ - { 204, -2 }, /* (68) storage ::= STORAGE INTEGER */ - { 205, 0 }, /* (69) qtime ::= */ - { 205, -2 }, /* (70) qtime ::= QTIME INTEGER */ - { 206, 0 }, /* (71) users ::= */ - { 206, -2 }, /* (72) users ::= USERS INTEGER */ - { 207, 0 }, /* (73) conns ::= */ - { 207, -2 }, /* (74) conns ::= CONNS INTEGER */ - { 208, 0 }, /* (75) state ::= */ - { 208, -2 }, /* (76) state ::= STATE ids */ - { 196, -9 }, /* (77) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 209, -2 }, /* (78) keep ::= KEEP tagitemlist */ - { 211, -2 }, /* (79) cache ::= CACHE INTEGER */ - { 212, -2 }, /* (80) replica ::= REPLICA INTEGER */ - { 213, -2 }, /* (81) quorum ::= QUORUM INTEGER */ - { 214, -2 }, /* (82) days ::= DAYS INTEGER */ - { 215, -2 }, /* (83) minrows ::= MINROWS INTEGER */ - { 216, -2 }, /* (84) maxrows ::= MAXROWS INTEGER */ - { 217, -2 }, /* (85) blocks ::= BLOCKS INTEGER */ - { 218, -2 }, /* (86) ctime ::= CTIME INTEGER */ - { 219, -2 }, /* (87) wal ::= WAL INTEGER */ - { 220, -2 }, /* (88) fsync ::= FSYNC INTEGER */ - { 221, -2 }, /* (89) comp ::= COMP INTEGER */ - { 222, -2 }, /* (90) prec ::= PRECISION STRING */ - { 223, -2 }, /* (91) update ::= UPDATE INTEGER */ - { 224, -2 }, /* (92) cachelast ::= CACHELAST INTEGER */ - { 225, -2 }, /* (93) partitions ::= PARTITIONS INTEGER */ - { 198, 0 }, /* (94) db_optr ::= */ - { 198, -2 }, /* (95) db_optr ::= db_optr cache */ - { 198, -2 }, /* (96) db_optr ::= db_optr replica */ - { 198, -2 }, /* (97) db_optr ::= db_optr quorum */ - { 198, -2 }, /* (98) db_optr ::= db_optr days */ - { 198, -2 }, /* (99) db_optr ::= db_optr minrows */ - { 198, -2 }, /* (100) db_optr ::= db_optr maxrows */ - { 198, -2 }, /* (101) db_optr ::= db_optr blocks */ - { 198, -2 }, /* (102) db_optr ::= db_optr ctime */ - { 198, -2 }, /* (103) db_optr ::= db_optr wal */ - { 198, -2 }, /* (104) db_optr ::= db_optr fsync */ - { 198, -2 }, /* (105) db_optr ::= db_optr comp */ - { 198, -2 }, /* (106) db_optr ::= db_optr prec */ - { 198, -2 }, /* (107) db_optr ::= db_optr keep */ - { 198, -2 }, /* (108) db_optr ::= db_optr update */ - { 198, -2 }, /* (109) db_optr ::= db_optr cachelast */ - { 199, -1 }, /* (110) topic_optr ::= db_optr */ - { 199, -2 }, /* (111) topic_optr ::= topic_optr partitions */ - { 194, 0 }, /* (112) alter_db_optr ::= */ - { 194, -2 }, /* (113) alter_db_optr ::= alter_db_optr replica */ - { 194, -2 }, /* (114) alter_db_optr ::= alter_db_optr quorum */ - { 194, -2 }, /* (115) alter_db_optr ::= alter_db_optr keep */ - { 194, -2 }, /* (116) alter_db_optr ::= alter_db_optr blocks */ - { 194, -2 }, /* (117) alter_db_optr ::= alter_db_optr comp */ - { 194, -2 }, /* (118) alter_db_optr ::= alter_db_optr wal */ - { 194, -2 }, /* (119) alter_db_optr ::= alter_db_optr fsync */ - { 194, -2 }, /* (120) alter_db_optr ::= alter_db_optr update */ - { 194, -2 }, /* (121) alter_db_optr ::= alter_db_optr cachelast */ - { 195, -1 }, /* (122) alter_topic_optr ::= alter_db_optr */ - { 195, -2 }, /* (123) alter_topic_optr ::= alter_topic_optr partitions */ - { 226, -1 }, /* (124) typename ::= ids */ - { 226, -4 }, /* (125) typename ::= ids LP signed RP */ - { 226, -2 }, /* (126) typename ::= ids UNSIGNED */ - { 227, -1 }, /* (127) signed ::= INTEGER */ - { 227, -2 }, /* (128) signed ::= PLUS INTEGER */ - { 227, -2 }, /* (129) signed ::= MINUS INTEGER */ - { 189, -3 }, /* (130) cmd ::= CREATE TABLE create_table_args */ - { 189, -3 }, /* (131) cmd ::= CREATE TABLE create_stable_args */ - { 189, -3 }, /* (132) cmd ::= CREATE STABLE create_stable_args */ - { 189, -3 }, /* (133) cmd ::= CREATE TABLE create_table_list */ - { 230, -1 }, /* (134) create_table_list ::= create_from_stable */ - { 230, -2 }, /* (135) create_table_list ::= create_table_list create_from_stable */ - { 228, -6 }, /* (136) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 229, -10 }, /* (137) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 231, -10 }, /* (138) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - { 231, -13 }, /* (139) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - { 233, -3 }, /* (140) tagNamelist ::= tagNamelist COMMA ids */ - { 233, -1 }, /* (141) tagNamelist ::= ids */ - { 228, -5 }, /* (142) create_table_args ::= ifnotexists ids cpxName AS select */ - { 232, -3 }, /* (143) columnlist ::= columnlist COMMA column */ - { 232, -1 }, /* (144) columnlist ::= column */ - { 235, -2 }, /* (145) column ::= ids typename */ - { 210, -3 }, /* (146) tagitemlist ::= tagitemlist COMMA tagitem */ - { 210, -1 }, /* (147) tagitemlist ::= tagitem */ - { 236, -1 }, /* (148) tagitem ::= INTEGER */ - { 236, -1 }, /* (149) tagitem ::= FLOAT */ - { 236, -1 }, /* (150) tagitem ::= STRING */ - { 236, -1 }, /* (151) tagitem ::= BOOL */ - { 236, -1 }, /* (152) tagitem ::= NULL */ - { 236, -2 }, /* (153) tagitem ::= MINUS INTEGER */ - { 236, -2 }, /* (154) tagitem ::= MINUS FLOAT */ - { 236, -2 }, /* (155) tagitem ::= PLUS INTEGER */ - { 236, -2 }, /* (156) tagitem ::= PLUS FLOAT */ - { 234, -13 }, /* (157) select ::= SELECT selcollist from where_opt interval_opt session_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ - { 234, -3 }, /* (158) select ::= LP select RP */ - { 249, -1 }, /* (159) union ::= select */ - { 249, -4 }, /* (160) union ::= union UNION ALL select */ - { 189, -1 }, /* (161) cmd ::= union */ - { 234, -2 }, /* (162) select ::= SELECT selcollist */ - { 250, -2 }, /* (163) sclp ::= selcollist COMMA */ - { 250, 0 }, /* (164) sclp ::= */ - { 237, -4 }, /* (165) selcollist ::= sclp distinct expr as */ - { 237, -2 }, /* (166) selcollist ::= sclp STAR */ - { 253, -2 }, /* (167) as ::= AS ids */ - { 253, -1 }, /* (168) as ::= ids */ - { 253, 0 }, /* (169) as ::= */ - { 251, -1 }, /* (170) distinct ::= DISTINCT */ - { 251, 0 }, /* (171) distinct ::= */ - { 238, -2 }, /* (172) from ::= FROM tablelist */ - { 238, -4 }, /* (173) from ::= FROM LP union RP */ - { 254, -2 }, /* (174) tablelist ::= ids cpxName */ - { 254, -3 }, /* (175) tablelist ::= ids cpxName ids */ - { 254, -4 }, /* (176) tablelist ::= tablelist COMMA ids cpxName */ - { 254, -5 }, /* (177) tablelist ::= tablelist COMMA ids cpxName ids */ - { 255, -1 }, /* (178) tmvar ::= VARIABLE */ - { 240, -4 }, /* (179) interval_opt ::= INTERVAL LP tmvar RP */ - { 240, -6 }, /* (180) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ - { 240, 0 }, /* (181) interval_opt ::= */ - { 241, 0 }, /* (182) session_option ::= */ - { 241, -7 }, /* (183) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 242, 0 }, /* (184) fill_opt ::= */ - { 242, -6 }, /* (185) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 242, -4 }, /* (186) fill_opt ::= FILL LP ID RP */ - { 243, -4 }, /* (187) sliding_opt ::= SLIDING LP tmvar RP */ - { 243, 0 }, /* (188) sliding_opt ::= */ - { 245, 0 }, /* (189) orderby_opt ::= */ - { 245, -3 }, /* (190) orderby_opt ::= ORDER BY sortlist */ - { 256, -4 }, /* (191) sortlist ::= sortlist COMMA item sortorder */ - { 256, -2 }, /* (192) sortlist ::= item sortorder */ - { 258, -2 }, /* (193) item ::= ids cpxName */ - { 259, -1 }, /* (194) sortorder ::= ASC */ - { 259, -1 }, /* (195) sortorder ::= DESC */ - { 259, 0 }, /* (196) sortorder ::= */ - { 244, 0 }, /* (197) groupby_opt ::= */ - { 244, -3 }, /* (198) groupby_opt ::= GROUP BY grouplist */ - { 260, -3 }, /* (199) grouplist ::= grouplist COMMA item */ - { 260, -1 }, /* (200) grouplist ::= item */ - { 246, 0 }, /* (201) having_opt ::= */ - { 246, -2 }, /* (202) having_opt ::= HAVING expr */ - { 248, 0 }, /* (203) limit_opt ::= */ - { 248, -2 }, /* (204) limit_opt ::= LIMIT signed */ - { 248, -4 }, /* (205) limit_opt ::= LIMIT signed OFFSET signed */ - { 248, -4 }, /* (206) limit_opt ::= LIMIT signed COMMA signed */ - { 247, 0 }, /* (207) slimit_opt ::= */ - { 247, -2 }, /* (208) slimit_opt ::= SLIMIT signed */ - { 247, -4 }, /* (209) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 247, -4 }, /* (210) slimit_opt ::= SLIMIT signed COMMA signed */ - { 239, 0 }, /* (211) where_opt ::= */ - { 239, -2 }, /* (212) where_opt ::= WHERE expr */ - { 252, -3 }, /* (213) expr ::= LP expr RP */ - { 252, -1 }, /* (214) expr ::= ID */ - { 252, -3 }, /* (215) expr ::= ID DOT ID */ - { 252, -3 }, /* (216) expr ::= ID DOT STAR */ - { 252, -1 }, /* (217) expr ::= INTEGER */ - { 252, -2 }, /* (218) expr ::= MINUS INTEGER */ - { 252, -2 }, /* (219) expr ::= PLUS INTEGER */ - { 252, -1 }, /* (220) expr ::= FLOAT */ - { 252, -2 }, /* (221) expr ::= MINUS FLOAT */ - { 252, -2 }, /* (222) expr ::= PLUS FLOAT */ - { 252, -1 }, /* (223) expr ::= STRING */ - { 252, -1 }, /* (224) expr ::= NOW */ - { 252, -1 }, /* (225) expr ::= VARIABLE */ - { 252, -2 }, /* (226) expr ::= PLUS VARIABLE */ - { 252, -2 }, /* (227) expr ::= MINUS VARIABLE */ - { 252, -1 }, /* (228) expr ::= BOOL */ - { 252, -1 }, /* (229) expr ::= NULL */ - { 252, -4 }, /* (230) expr ::= ID LP exprlist RP */ - { 252, -4 }, /* (231) expr ::= ID LP STAR RP */ - { 252, -3 }, /* (232) expr ::= expr IS NULL */ - { 252, -4 }, /* (233) expr ::= expr IS NOT NULL */ - { 252, -3 }, /* (234) expr ::= expr LT expr */ - { 252, -3 }, /* (235) expr ::= expr GT expr */ - { 252, -3 }, /* (236) expr ::= expr LE expr */ - { 252, -3 }, /* (237) expr ::= expr GE expr */ - { 252, -3 }, /* (238) expr ::= expr NE expr */ - { 252, -3 }, /* (239) expr ::= expr EQ expr */ - { 252, -5 }, /* (240) expr ::= expr BETWEEN expr AND expr */ - { 252, -3 }, /* (241) expr ::= expr AND expr */ - { 252, -3 }, /* (242) expr ::= expr OR expr */ - { 252, -3 }, /* (243) expr ::= expr PLUS expr */ - { 252, -3 }, /* (244) expr ::= expr MINUS expr */ - { 252, -3 }, /* (245) expr ::= expr STAR expr */ - { 252, -3 }, /* (246) expr ::= expr SLASH expr */ - { 252, -3 }, /* (247) expr ::= expr REM expr */ - { 252, -3 }, /* (248) expr ::= expr LIKE expr */ - { 252, -5 }, /* (249) expr ::= expr IN LP exprlist RP */ - { 261, -3 }, /* (250) exprlist ::= exprlist COMMA expritem */ - { 261, -1 }, /* (251) exprlist ::= expritem */ - { 262, -1 }, /* (252) expritem ::= expr */ - { 262, 0 }, /* (253) expritem ::= */ - { 189, -3 }, /* (254) cmd ::= RESET QUERY CACHE */ - { 189, -3 }, /* (255) cmd ::= SYNCDB ids REPLICA */ - { 189, -7 }, /* (256) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 189, -7 }, /* (257) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 189, -7 }, /* (258) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 189, -7 }, /* (259) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 189, -8 }, /* (260) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 189, -9 }, /* (261) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 189, -7 }, /* (262) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 189, -7 }, /* (263) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 189, -7 }, /* (264) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 189, -7 }, /* (265) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 189, -8 }, /* (266) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 189, -3 }, /* (267) cmd ::= KILL CONNECTION INTEGER */ - { 189, -5 }, /* (268) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 189, -5 }, /* (269) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 189, -1 }, /* (0) program ::= cmd */ + { 190, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 190, -2 }, /* (2) cmd ::= SHOW TOPICS */ + { 190, -2 }, /* (3) cmd ::= SHOW MNODES */ + { 190, -2 }, /* (4) cmd ::= SHOW DNODES */ + { 190, -2 }, /* (5) cmd ::= SHOW ACCOUNTS */ + { 190, -2 }, /* (6) cmd ::= SHOW USERS */ + { 190, -2 }, /* (7) cmd ::= SHOW MODULES */ + { 190, -2 }, /* (8) cmd ::= SHOW QUERIES */ + { 190, -2 }, /* (9) cmd ::= SHOW CONNECTIONS */ + { 190, -2 }, /* (10) cmd ::= SHOW STREAMS */ + { 190, -2 }, /* (11) cmd ::= SHOW VARIABLES */ + { 190, -2 }, /* (12) cmd ::= SHOW SCORES */ + { 190, -2 }, /* (13) cmd ::= SHOW GRANTS */ + { 190, -2 }, /* (14) cmd ::= SHOW VNODES */ + { 190, -3 }, /* (15) cmd ::= SHOW VNODES IPTOKEN */ + { 191, 0 }, /* (16) dbPrefix ::= */ + { 191, -2 }, /* (17) dbPrefix ::= ids DOT */ + { 193, 0 }, /* (18) cpxName ::= */ + { 193, -2 }, /* (19) cpxName ::= DOT ids */ + { 190, -5 }, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ + { 190, -5 }, /* (21) cmd ::= SHOW CREATE STABLE ids cpxName */ + { 190, -4 }, /* (22) cmd ::= SHOW CREATE DATABASE ids */ + { 190, -3 }, /* (23) cmd ::= SHOW dbPrefix TABLES */ + { 190, -5 }, /* (24) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 190, -3 }, /* (25) cmd ::= SHOW dbPrefix STABLES */ + { 190, -5 }, /* (26) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 190, -3 }, /* (27) cmd ::= SHOW dbPrefix VGROUPS */ + { 190, -4 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS ids */ + { 190, -5 }, /* (29) cmd ::= DROP TABLE ifexists ids cpxName */ + { 190, -5 }, /* (30) cmd ::= DROP STABLE ifexists ids cpxName */ + { 190, -4 }, /* (31) cmd ::= DROP DATABASE ifexists ids */ + { 190, -4 }, /* (32) cmd ::= DROP TOPIC ifexists ids */ + { 190, -3 }, /* (33) cmd ::= DROP DNODE ids */ + { 190, -3 }, /* (34) cmd ::= DROP USER ids */ + { 190, -3 }, /* (35) cmd ::= DROP ACCOUNT ids */ + { 190, -2 }, /* (36) cmd ::= USE ids */ + { 190, -3 }, /* (37) cmd ::= DESCRIBE ids cpxName */ + { 190, -5 }, /* (38) cmd ::= ALTER USER ids PASS ids */ + { 190, -5 }, /* (39) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 190, -4 }, /* (40) cmd ::= ALTER DNODE ids ids */ + { 190, -5 }, /* (41) cmd ::= ALTER DNODE ids ids ids */ + { 190, -3 }, /* (42) cmd ::= ALTER LOCAL ids */ + { 190, -4 }, /* (43) cmd ::= ALTER LOCAL ids ids */ + { 190, -4 }, /* (44) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 190, -4 }, /* (45) cmd ::= ALTER TOPIC ids alter_topic_optr */ + { 190, -4 }, /* (46) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 190, -6 }, /* (47) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 192, -1 }, /* (48) ids ::= ID */ + { 192, -1 }, /* (49) ids ::= STRING */ + { 194, -2 }, /* (50) ifexists ::= IF EXISTS */ + { 194, 0 }, /* (51) ifexists ::= */ + { 198, -3 }, /* (52) ifnotexists ::= IF NOT EXISTS */ + { 198, 0 }, /* (53) ifnotexists ::= */ + { 190, -3 }, /* (54) cmd ::= CREATE DNODE ids */ + { 190, -6 }, /* (55) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 190, -5 }, /* (56) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 190, -5 }, /* (57) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + { 190, -5 }, /* (58) cmd ::= CREATE USER ids PASS ids */ + { 201, 0 }, /* (59) pps ::= */ + { 201, -2 }, /* (60) pps ::= PPS INTEGER */ + { 202, 0 }, /* (61) tseries ::= */ + { 202, -2 }, /* (62) tseries ::= TSERIES INTEGER */ + { 203, 0 }, /* (63) dbs ::= */ + { 203, -2 }, /* (64) dbs ::= DBS INTEGER */ + { 204, 0 }, /* (65) streams ::= */ + { 204, -2 }, /* (66) streams ::= STREAMS INTEGER */ + { 205, 0 }, /* (67) storage ::= */ + { 205, -2 }, /* (68) storage ::= STORAGE INTEGER */ + { 206, 0 }, /* (69) qtime ::= */ + { 206, -2 }, /* (70) qtime ::= QTIME INTEGER */ + { 207, 0 }, /* (71) users ::= */ + { 207, -2 }, /* (72) users ::= USERS INTEGER */ + { 208, 0 }, /* (73) conns ::= */ + { 208, -2 }, /* (74) conns ::= CONNS INTEGER */ + { 209, 0 }, /* (75) state ::= */ + { 209, -2 }, /* (76) state ::= STATE ids */ + { 197, -9 }, /* (77) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 210, -2 }, /* (78) keep ::= KEEP tagitemlist */ + { 212, -2 }, /* (79) cache ::= CACHE INTEGER */ + { 213, -2 }, /* (80) replica ::= REPLICA INTEGER */ + { 214, -2 }, /* (81) quorum ::= QUORUM INTEGER */ + { 215, -2 }, /* (82) days ::= DAYS INTEGER */ + { 216, -2 }, /* (83) minrows ::= MINROWS INTEGER */ + { 217, -2 }, /* (84) maxrows ::= MAXROWS INTEGER */ + { 218, -2 }, /* (85) blocks ::= BLOCKS INTEGER */ + { 219, -2 }, /* (86) ctime ::= CTIME INTEGER */ + { 220, -2 }, /* (87) wal ::= WAL INTEGER */ + { 221, -2 }, /* (88) fsync ::= FSYNC INTEGER */ + { 222, -2 }, /* (89) comp ::= COMP INTEGER */ + { 223, -2 }, /* (90) prec ::= PRECISION STRING */ + { 224, -2 }, /* (91) update ::= UPDATE INTEGER */ + { 225, -2 }, /* (92) cachelast ::= CACHELAST INTEGER */ + { 226, -2 }, /* (93) partitions ::= PARTITIONS INTEGER */ + { 199, 0 }, /* (94) db_optr ::= */ + { 199, -2 }, /* (95) db_optr ::= db_optr cache */ + { 199, -2 }, /* (96) db_optr ::= db_optr replica */ + { 199, -2 }, /* (97) db_optr ::= db_optr quorum */ + { 199, -2 }, /* (98) db_optr ::= db_optr days */ + { 199, -2 }, /* (99) db_optr ::= db_optr minrows */ + { 199, -2 }, /* (100) db_optr ::= db_optr maxrows */ + { 199, -2 }, /* (101) db_optr ::= db_optr blocks */ + { 199, -2 }, /* (102) db_optr ::= db_optr ctime */ + { 199, -2 }, /* (103) db_optr ::= db_optr wal */ + { 199, -2 }, /* (104) db_optr ::= db_optr fsync */ + { 199, -2 }, /* (105) db_optr ::= db_optr comp */ + { 199, -2 }, /* (106) db_optr ::= db_optr prec */ + { 199, -2 }, /* (107) db_optr ::= db_optr keep */ + { 199, -2 }, /* (108) db_optr ::= db_optr update */ + { 199, -2 }, /* (109) db_optr ::= db_optr cachelast */ + { 200, -1 }, /* (110) topic_optr ::= db_optr */ + { 200, -2 }, /* (111) topic_optr ::= topic_optr partitions */ + { 195, 0 }, /* (112) alter_db_optr ::= */ + { 195, -2 }, /* (113) alter_db_optr ::= alter_db_optr replica */ + { 195, -2 }, /* (114) alter_db_optr ::= alter_db_optr quorum */ + { 195, -2 }, /* (115) alter_db_optr ::= alter_db_optr keep */ + { 195, -2 }, /* (116) alter_db_optr ::= alter_db_optr blocks */ + { 195, -2 }, /* (117) alter_db_optr ::= alter_db_optr comp */ + { 195, -2 }, /* (118) alter_db_optr ::= alter_db_optr wal */ + { 195, -2 }, /* (119) alter_db_optr ::= alter_db_optr fsync */ + { 195, -2 }, /* (120) alter_db_optr ::= alter_db_optr update */ + { 195, -2 }, /* (121) alter_db_optr ::= alter_db_optr cachelast */ + { 196, -1 }, /* (122) alter_topic_optr ::= alter_db_optr */ + { 196, -2 }, /* (123) alter_topic_optr ::= alter_topic_optr partitions */ + { 227, -1 }, /* (124) typename ::= ids */ + { 227, -4 }, /* (125) typename ::= ids LP signed RP */ + { 227, -2 }, /* (126) typename ::= ids UNSIGNED */ + { 228, -1 }, /* (127) signed ::= INTEGER */ + { 228, -2 }, /* (128) signed ::= PLUS INTEGER */ + { 228, -2 }, /* (129) signed ::= MINUS INTEGER */ + { 190, -3 }, /* (130) cmd ::= CREATE TABLE create_table_args */ + { 190, -3 }, /* (131) cmd ::= CREATE TABLE create_stable_args */ + { 190, -3 }, /* (132) cmd ::= CREATE STABLE create_stable_args */ + { 190, -3 }, /* (133) cmd ::= CREATE TABLE create_table_list */ + { 231, -1 }, /* (134) create_table_list ::= create_from_stable */ + { 231, -2 }, /* (135) create_table_list ::= create_table_list create_from_stable */ + { 229, -6 }, /* (136) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 230, -10 }, /* (137) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 232, -10 }, /* (138) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + { 232, -13 }, /* (139) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + { 234, -3 }, /* (140) tagNamelist ::= tagNamelist COMMA ids */ + { 234, -1 }, /* (141) tagNamelist ::= ids */ + { 229, -5 }, /* (142) create_table_args ::= ifnotexists ids cpxName AS select */ + { 233, -3 }, /* (143) columnlist ::= columnlist COMMA column */ + { 233, -1 }, /* (144) columnlist ::= column */ + { 236, -2 }, /* (145) column ::= ids typename */ + { 211, -3 }, /* (146) tagitemlist ::= tagitemlist COMMA tagitem */ + { 211, -1 }, /* (147) tagitemlist ::= tagitem */ + { 237, -1 }, /* (148) tagitem ::= INTEGER */ + { 237, -1 }, /* (149) tagitem ::= FLOAT */ + { 237, -1 }, /* (150) tagitem ::= STRING */ + { 237, -1 }, /* (151) tagitem ::= BOOL */ + { 237, -1 }, /* (152) tagitem ::= NULL */ + { 237, -2 }, /* (153) tagitem ::= MINUS INTEGER */ + { 237, -2 }, /* (154) tagitem ::= MINUS FLOAT */ + { 237, -2 }, /* (155) tagitem ::= PLUS INTEGER */ + { 237, -2 }, /* (156) tagitem ::= PLUS FLOAT */ + { 235, -14 }, /* (157) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + { 235, -3 }, /* (158) select ::= LP select RP */ + { 251, -1 }, /* (159) union ::= select */ + { 251, -4 }, /* (160) union ::= union UNION ALL select */ + { 190, -1 }, /* (161) cmd ::= union */ + { 235, -2 }, /* (162) select ::= SELECT selcollist */ + { 252, -2 }, /* (163) sclp ::= selcollist COMMA */ + { 252, 0 }, /* (164) sclp ::= */ + { 238, -4 }, /* (165) selcollist ::= sclp distinct expr as */ + { 238, -2 }, /* (166) selcollist ::= sclp STAR */ + { 255, -2 }, /* (167) as ::= AS ids */ + { 255, -1 }, /* (168) as ::= ids */ + { 255, 0 }, /* (169) as ::= */ + { 253, -1 }, /* (170) distinct ::= DISTINCT */ + { 253, 0 }, /* (171) distinct ::= */ + { 239, -2 }, /* (172) from ::= FROM tablelist */ + { 239, -4 }, /* (173) from ::= FROM LP union RP */ + { 256, -2 }, /* (174) tablelist ::= ids cpxName */ + { 256, -3 }, /* (175) tablelist ::= ids cpxName ids */ + { 256, -4 }, /* (176) tablelist ::= tablelist COMMA ids cpxName */ + { 256, -5 }, /* (177) tablelist ::= tablelist COMMA ids cpxName ids */ + { 257, -1 }, /* (178) tmvar ::= VARIABLE */ + { 241, -4 }, /* (179) interval_opt ::= INTERVAL LP tmvar RP */ + { 241, -6 }, /* (180) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + { 241, 0 }, /* (181) interval_opt ::= */ + { 242, 0 }, /* (182) session_option ::= */ + { 242, -7 }, /* (183) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 243, 0 }, /* (184) windowstate_option ::= */ + { 243, -4 }, /* (185) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 244, 0 }, /* (186) fill_opt ::= */ + { 244, -6 }, /* (187) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 244, -4 }, /* (188) fill_opt ::= FILL LP ID RP */ + { 245, -4 }, /* (189) sliding_opt ::= SLIDING LP tmvar RP */ + { 245, 0 }, /* (190) sliding_opt ::= */ + { 247, 0 }, /* (191) orderby_opt ::= */ + { 247, -3 }, /* (192) orderby_opt ::= ORDER BY sortlist */ + { 258, -4 }, /* (193) sortlist ::= sortlist COMMA item sortorder */ + { 258, -2 }, /* (194) sortlist ::= item sortorder */ + { 260, -2 }, /* (195) item ::= ids cpxName */ + { 261, -1 }, /* (196) sortorder ::= ASC */ + { 261, -1 }, /* (197) sortorder ::= DESC */ + { 261, 0 }, /* (198) sortorder ::= */ + { 246, 0 }, /* (199) groupby_opt ::= */ + { 246, -3 }, /* (200) groupby_opt ::= GROUP BY grouplist */ + { 262, -3 }, /* (201) grouplist ::= grouplist COMMA item */ + { 262, -1 }, /* (202) grouplist ::= item */ + { 248, 0 }, /* (203) having_opt ::= */ + { 248, -2 }, /* (204) having_opt ::= HAVING expr */ + { 250, 0 }, /* (205) limit_opt ::= */ + { 250, -2 }, /* (206) limit_opt ::= LIMIT signed */ + { 250, -4 }, /* (207) limit_opt ::= LIMIT signed OFFSET signed */ + { 250, -4 }, /* (208) limit_opt ::= LIMIT signed COMMA signed */ + { 249, 0 }, /* (209) slimit_opt ::= */ + { 249, -2 }, /* (210) slimit_opt ::= SLIMIT signed */ + { 249, -4 }, /* (211) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 249, -4 }, /* (212) slimit_opt ::= SLIMIT signed COMMA signed */ + { 240, 0 }, /* (213) where_opt ::= */ + { 240, -2 }, /* (214) where_opt ::= WHERE expr */ + { 254, -3 }, /* (215) expr ::= LP expr RP */ + { 254, -1 }, /* (216) expr ::= ID */ + { 254, -3 }, /* (217) expr ::= ID DOT ID */ + { 254, -3 }, /* (218) expr ::= ID DOT STAR */ + { 254, -1 }, /* (219) expr ::= INTEGER */ + { 254, -2 }, /* (220) expr ::= MINUS INTEGER */ + { 254, -2 }, /* (221) expr ::= PLUS INTEGER */ + { 254, -1 }, /* (222) expr ::= FLOAT */ + { 254, -2 }, /* (223) expr ::= MINUS FLOAT */ + { 254, -2 }, /* (224) expr ::= PLUS FLOAT */ + { 254, -1 }, /* (225) expr ::= STRING */ + { 254, -1 }, /* (226) expr ::= NOW */ + { 254, -1 }, /* (227) expr ::= VARIABLE */ + { 254, -2 }, /* (228) expr ::= PLUS VARIABLE */ + { 254, -2 }, /* (229) expr ::= MINUS VARIABLE */ + { 254, -1 }, /* (230) expr ::= BOOL */ + { 254, -1 }, /* (231) expr ::= NULL */ + { 254, -4 }, /* (232) expr ::= ID LP exprlist RP */ + { 254, -4 }, /* (233) expr ::= ID LP STAR RP */ + { 254, -3 }, /* (234) expr ::= expr IS NULL */ + { 254, -4 }, /* (235) expr ::= expr IS NOT NULL */ + { 254, -3 }, /* (236) expr ::= expr LT expr */ + { 254, -3 }, /* (237) expr ::= expr GT expr */ + { 254, -3 }, /* (238) expr ::= expr LE expr */ + { 254, -3 }, /* (239) expr ::= expr GE expr */ + { 254, -3 }, /* (240) expr ::= expr NE expr */ + { 254, -3 }, /* (241) expr ::= expr EQ expr */ + { 254, -5 }, /* (242) expr ::= expr BETWEEN expr AND expr */ + { 254, -3 }, /* (243) expr ::= expr AND expr */ + { 254, -3 }, /* (244) expr ::= expr OR expr */ + { 254, -3 }, /* (245) expr ::= expr PLUS expr */ + { 254, -3 }, /* (246) expr ::= expr MINUS expr */ + { 254, -3 }, /* (247) expr ::= expr STAR expr */ + { 254, -3 }, /* (248) expr ::= expr SLASH expr */ + { 254, -3 }, /* (249) expr ::= expr REM expr */ + { 254, -3 }, /* (250) expr ::= expr LIKE expr */ + { 254, -5 }, /* (251) expr ::= expr IN LP exprlist RP */ + { 263, -3 }, /* (252) exprlist ::= exprlist COMMA expritem */ + { 263, -1 }, /* (253) exprlist ::= expritem */ + { 264, -1 }, /* (254) expritem ::= expr */ + { 264, 0 }, /* (255) expritem ::= */ + { 190, -3 }, /* (256) cmd ::= RESET QUERY CACHE */ + { 190, -3 }, /* (257) cmd ::= SYNCDB ids REPLICA */ + { 190, -7 }, /* (258) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 190, -7 }, /* (259) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 190, -7 }, /* (260) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 190, -7 }, /* (261) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 190, -8 }, /* (262) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 190, -9 }, /* (263) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 190, -7 }, /* (264) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 190, -7 }, /* (265) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 190, -7 }, /* (266) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 190, -7 }, /* (267) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 190, -8 }, /* (268) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 190, -3 }, /* (269) cmd ::= KILL CONNECTION INTEGER */ + { 190, -5 }, /* (270) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 190, -5 }, /* (271) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2277,13 +2288,13 @@ static void yy_reduce( break; case 44: /* cmd ::= ALTER DATABASE ids alter_db_optr */ case 45: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==45); -{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy322, &t);} +{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy122, &t);} break; case 46: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy351);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy211);} break; case 47: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy351);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy211);} break; case 48: /* ids ::= ID */ case 49: /* ids ::= STRING */ yytestcase(yyruleno==49); @@ -2305,11 +2316,11 @@ static void yy_reduce( { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; case 55: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy351);} +{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy211);} break; case 56: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ case 57: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==57); -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy322, &yymsp[-2].minor.yy0);} +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy122, &yymsp[-2].minor.yy0);} break; case 58: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} @@ -2338,20 +2349,20 @@ static void yy_reduce( break; case 77: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yylhsminor.yy351.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy351.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy351.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy351.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy351.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy351.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy351.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy351.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy351.stat = yymsp[0].minor.yy0; + yylhsminor.yy211.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy211.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy211.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy211.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy211.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy211.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy211.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy211.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy211.stat = yymsp[0].minor.yy0; } - yymsp[-8].minor.yy351 = yylhsminor.yy351; + yymsp[-8].minor.yy211 = yylhsminor.yy211; break; case 78: /* keep ::= KEEP tagitemlist */ -{ yymsp[-1].minor.yy159 = yymsp[0].minor.yy159; } +{ yymsp[-1].minor.yy291 = yymsp[0].minor.yy291; } break; case 79: /* cache ::= CACHE INTEGER */ case 80: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==80); @@ -2371,234 +2382,234 @@ static void yy_reduce( { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 94: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy322); yymsp[1].minor.yy322.dbType = TSDB_DB_TYPE_DEFAULT;} +{setDefaultCreateDbOption(&yymsp[1].minor.yy122); yymsp[1].minor.yy122.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 95: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 96: /* db_optr ::= db_optr replica */ case 113: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==113); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 97: /* db_optr ::= db_optr quorum */ case 114: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==114); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 98: /* db_optr ::= db_optr days */ -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 99: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 100: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 101: /* db_optr ::= db_optr blocks */ case 116: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==116); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 102: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 103: /* db_optr ::= db_optr wal */ case 118: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==118); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 104: /* db_optr ::= db_optr fsync */ case 119: /* alter_db_optr ::= alter_db_optr fsync */ yytestcase(yyruleno==119); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 105: /* db_optr ::= db_optr comp */ case 117: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==117); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 106: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 107: /* db_optr ::= db_optr keep */ case 115: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==115); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.keep = yymsp[0].minor.yy159; } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.keep = yymsp[0].minor.yy291; } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 108: /* db_optr ::= db_optr update */ case 120: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==120); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 109: /* db_optr ::= db_optr cachelast */ case 121: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==121); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 110: /* topic_optr ::= db_optr */ case 122: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==122); -{ yylhsminor.yy322 = yymsp[0].minor.yy322; yylhsminor.yy322.dbType = TSDB_DB_TYPE_TOPIC; } - yymsp[0].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[0].minor.yy122; yylhsminor.yy122.dbType = TSDB_DB_TYPE_TOPIC; } + yymsp[0].minor.yy122 = yylhsminor.yy122; break; case 111: /* topic_optr ::= topic_optr partitions */ case 123: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==123); -{ yylhsminor.yy322 = yymsp[-1].minor.yy322; yylhsminor.yy322.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; +{ yylhsminor.yy122 = yymsp[-1].minor.yy122; yylhsminor.yy122.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy122 = yylhsminor.yy122; break; case 112: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy322); yymsp[1].minor.yy322.dbType = TSDB_DB_TYPE_DEFAULT;} +{ setDefaultCreateDbOption(&yymsp[1].minor.yy122); yymsp[1].minor.yy122.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 124: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yylhsminor.yy407, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy153, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy407 = yylhsminor.yy407; + yymsp[0].minor.yy153 = yylhsminor.yy153; break; case 125: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy317 <= 0) { + if (yymsp[-1].minor.yy179 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yylhsminor.yy407, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy153, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy317; // negative value of name length - tSetColumnType(&yylhsminor.yy407, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy179; // negative value of name length + tSetColumnType(&yylhsminor.yy153, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy407 = yylhsminor.yy407; + yymsp[-3].minor.yy153 = yylhsminor.yy153; break; case 126: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); - tSetColumnType (&yylhsminor.yy407, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy153, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy407 = yylhsminor.yy407; + yymsp[-1].minor.yy153 = yylhsminor.yy153; break; case 127: /* signed ::= INTEGER */ -{ yylhsminor.yy317 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy317 = yylhsminor.yy317; +{ yylhsminor.yy179 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy179 = yylhsminor.yy179; break; case 128: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy317 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy179 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; case 129: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy317 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +{ yymsp[-1].minor.yy179 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; case 133: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy14;} +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy412;} break; case 134: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy206); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy446); pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; - yylhsminor.yy14 = pCreateTable; + yylhsminor.yy412 = pCreateTable; } - yymsp[0].minor.yy14 = yylhsminor.yy14; + yymsp[0].minor.yy412 = yylhsminor.yy412; break; case 135: /* create_table_list ::= create_table_list create_from_stable */ { - taosArrayPush(yymsp[-1].minor.yy14->childTableInfo, &yymsp[0].minor.yy206); - yylhsminor.yy14 = yymsp[-1].minor.yy14; + taosArrayPush(yymsp[-1].minor.yy412->childTableInfo, &yymsp[0].minor.yy446); + yylhsminor.yy412 = yymsp[-1].minor.yy412; } - yymsp[-1].minor.yy14 = yylhsminor.yy14; + yymsp[-1].minor.yy412 = yylhsminor.yy412; break; case 136: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy14 = tSetCreateTableInfo(yymsp[-1].minor.yy159, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yylhsminor.yy14, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy412 = tSetCreateTableInfo(yymsp[-1].minor.yy291, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy412, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); } - yymsp[-5].minor.yy14 = yylhsminor.yy14; + yymsp[-5].minor.yy412 = yylhsminor.yy412; break; case 137: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy14 = tSetCreateTableInfo(yymsp[-5].minor.yy159, yymsp[-1].minor.yy159, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy14, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy412 = tSetCreateTableInfo(yymsp[-5].minor.yy291, yymsp[-1].minor.yy291, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy412, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy14 = yylhsminor.yy14; + yymsp[-9].minor.yy412 = yylhsminor.yy412; break; case 138: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; - yylhsminor.yy206 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy159, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy446 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy291, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy206 = yylhsminor.yy206; + yymsp[-9].minor.yy446 = yylhsminor.yy446; break; case 139: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; - yylhsminor.yy206 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy159, yymsp[-1].minor.yy159, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy446 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy291, yymsp[-1].minor.yy291, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } - yymsp[-12].minor.yy206 = yylhsminor.yy206; + yymsp[-12].minor.yy446 = yylhsminor.yy446; break; case 140: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy159, &yymsp[0].minor.yy0); yylhsminor.yy159 = yymsp[-2].minor.yy159; } - yymsp[-2].minor.yy159 = yylhsminor.yy159; +{taosArrayPush(yymsp[-2].minor.yy291, &yymsp[0].minor.yy0); yylhsminor.yy291 = yymsp[-2].minor.yy291; } + yymsp[-2].minor.yy291 = yylhsminor.yy291; break; case 141: /* tagNamelist ::= ids */ -{yylhsminor.yy159 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy159, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy159 = yylhsminor.yy159; +{yylhsminor.yy291 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy291, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy291 = yylhsminor.yy291; break; case 142: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy14 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy116, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy14, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy412 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy6, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy412, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } - yymsp[-4].minor.yy14 = yylhsminor.yy14; + yymsp[-4].minor.yy412 = yylhsminor.yy412; break; case 143: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy159, &yymsp[0].minor.yy407); yylhsminor.yy159 = yymsp[-2].minor.yy159; } - yymsp[-2].minor.yy159 = yylhsminor.yy159; +{taosArrayPush(yymsp[-2].minor.yy291, &yymsp[0].minor.yy153); yylhsminor.yy291 = yymsp[-2].minor.yy291; } + yymsp[-2].minor.yy291 = yylhsminor.yy291; break; case 144: /* columnlist ::= column */ -{yylhsminor.yy159 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy159, &yymsp[0].minor.yy407);} - yymsp[0].minor.yy159 = yylhsminor.yy159; +{yylhsminor.yy291 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy291, &yymsp[0].minor.yy153);} + yymsp[0].minor.yy291 = yylhsminor.yy291; break; case 145: /* column ::= ids typename */ { - tSetColumnInfo(&yylhsminor.yy407, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy407); + tSetColumnInfo(&yylhsminor.yy153, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy153); } - yymsp[-1].minor.yy407 = yylhsminor.yy407; + yymsp[-1].minor.yy153 = yylhsminor.yy153; break; case 146: /* tagitemlist ::= tagitemlist COMMA tagitem */ -{ yylhsminor.yy159 = tVariantListAppend(yymsp[-2].minor.yy159, &yymsp[0].minor.yy488, -1); } - yymsp[-2].minor.yy159 = yylhsminor.yy159; +{ yylhsminor.yy291 = tVariantListAppend(yymsp[-2].minor.yy291, &yymsp[0].minor.yy216, -1); } + yymsp[-2].minor.yy291 = yylhsminor.yy291; break; case 147: /* tagitemlist ::= tagitem */ -{ yylhsminor.yy159 = tVariantListAppend(NULL, &yymsp[0].minor.yy488, -1); } - yymsp[0].minor.yy159 = yylhsminor.yy159; +{ yylhsminor.yy291 = tVariantListAppend(NULL, &yymsp[0].minor.yy216, -1); } + yymsp[0].minor.yy291 = yylhsminor.yy291; break; case 148: /* tagitem ::= INTEGER */ case 149: /* tagitem ::= FLOAT */ yytestcase(yyruleno==149); case 150: /* tagitem ::= STRING */ yytestcase(yyruleno==150); case 151: /* tagitem ::= BOOL */ yytestcase(yyruleno==151); -{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy488, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy488 = yylhsminor.yy488; +{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy216, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy216 = yylhsminor.yy216; break; case 152: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy488, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy488 = yylhsminor.yy488; +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy216, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy216 = yylhsminor.yy216; break; case 153: /* tagitem ::= MINUS INTEGER */ case 154: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==154); @@ -2608,56 +2619,56 @@ static void yy_reduce( yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yylhsminor.yy488, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy216, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy488 = yylhsminor.yy488; + yymsp[-1].minor.yy216 = yylhsminor.yy216; break; - case 157: /* select ::= SELECT selcollist from where_opt interval_opt session_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + case 157: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ { - yylhsminor.yy116 = tSetQuerySqlNode(&yymsp[-12].minor.yy0, yymsp[-11].minor.yy159, yymsp[-10].minor.yy236, yymsp[-9].minor.yy118, yymsp[-4].minor.yy159, yymsp[-3].minor.yy159, &yymsp[-8].minor.yy184, &yymsp[-7].minor.yy249, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy159, &yymsp[0].minor.yy440, &yymsp[-1].minor.yy440, yymsp[-2].minor.yy118); + yylhsminor.yy6 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy291, yymsp[-11].minor.yy254, yymsp[-10].minor.yy436, yymsp[-4].minor.yy291, yymsp[-3].minor.yy291, &yymsp[-9].minor.yy400, &yymsp[-8].minor.yy139, &yymsp[-7].minor.yy158, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy291, &yymsp[0].minor.yy74, &yymsp[-1].minor.yy74, yymsp[-2].minor.yy436); } - yymsp[-12].minor.yy116 = yylhsminor.yy116; + yymsp[-13].minor.yy6 = yylhsminor.yy6; break; case 158: /* select ::= LP select RP */ -{yymsp[-2].minor.yy116 = yymsp[-1].minor.yy116;} +{yymsp[-2].minor.yy6 = yymsp[-1].minor.yy6;} break; case 159: /* union ::= select */ -{ yylhsminor.yy159 = setSubclause(NULL, yymsp[0].minor.yy116); } - yymsp[0].minor.yy159 = yylhsminor.yy159; +{ yylhsminor.yy291 = setSubclause(NULL, yymsp[0].minor.yy6); } + yymsp[0].minor.yy291 = yylhsminor.yy291; break; case 160: /* union ::= union UNION ALL select */ -{ yylhsminor.yy159 = appendSelectClause(yymsp[-3].minor.yy159, yymsp[0].minor.yy116); } - yymsp[-3].minor.yy159 = yylhsminor.yy159; +{ yylhsminor.yy291 = appendSelectClause(yymsp[-3].minor.yy291, yymsp[0].minor.yy6); } + yymsp[-3].minor.yy291 = yylhsminor.yy291; break; case 161: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy159, NULL, TSDB_SQL_SELECT); } +{ setSqlInfo(pInfo, yymsp[0].minor.yy291, NULL, TSDB_SQL_SELECT); } break; case 162: /* select ::= SELECT selcollist */ { - yylhsminor.yy116 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy159, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy6 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy291, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy116 = yylhsminor.yy116; + yymsp[-1].minor.yy6 = yylhsminor.yy6; break; case 163: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy159 = yymsp[-1].minor.yy159;} - yymsp[-1].minor.yy159 = yylhsminor.yy159; +{yylhsminor.yy291 = yymsp[-1].minor.yy291;} + yymsp[-1].minor.yy291 = yylhsminor.yy291; break; case 164: /* sclp ::= */ - case 189: /* orderby_opt ::= */ yytestcase(yyruleno==189); -{yymsp[1].minor.yy159 = 0;} + case 191: /* orderby_opt ::= */ yytestcase(yyruleno==191); +{yymsp[1].minor.yy291 = 0;} break; case 165: /* selcollist ::= sclp distinct expr as */ { - yylhsminor.yy159 = tSqlExprListAppend(yymsp[-3].minor.yy159, yymsp[-1].minor.yy118, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy291 = tSqlExprListAppend(yymsp[-3].minor.yy291, yymsp[-1].minor.yy436, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-3].minor.yy159 = yylhsminor.yy159; + yymsp[-3].minor.yy291 = yylhsminor.yy291; break; case 166: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yylhsminor.yy159 = tSqlExprListAppend(yymsp[-1].minor.yy159, pNode, 0, 0); + yylhsminor.yy291 = tSqlExprListAppend(yymsp[-1].minor.yy291, pNode, 0, 0); } - yymsp[-1].minor.yy159 = yylhsminor.yy159; + yymsp[-1].minor.yy291 = yylhsminor.yy291; break; case 167: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } @@ -2674,332 +2685,340 @@ static void yy_reduce( yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 172: /* from ::= FROM tablelist */ -{yymsp[-1].minor.yy236 = yymsp[0].minor.yy236;} +{yymsp[-1].minor.yy254 = yymsp[0].minor.yy254;} break; case 173: /* from ::= FROM LP union RP */ -{yymsp[-3].minor.yy236 = setSubquery(NULL, yymsp[-1].minor.yy159);} +{yymsp[-3].minor.yy254 = setSubquery(NULL, yymsp[-1].minor.yy291);} break; case 174: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy236 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy254 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } - yymsp[-1].minor.yy236 = yylhsminor.yy236; + yymsp[-1].minor.yy254 = yylhsminor.yy254; break; case 175: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy236 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy254 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy236 = yylhsminor.yy236; + yymsp[-2].minor.yy254 = yylhsminor.yy254; break; case 176: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy236 = setTableNameList(yymsp[-3].minor.yy236, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy254 = setTableNameList(yymsp[-3].minor.yy254, &yymsp[-1].minor.yy0, NULL); } - yymsp[-3].minor.yy236 = yylhsminor.yy236; + yymsp[-3].minor.yy254 = yylhsminor.yy254; break; case 177: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy236 = setTableNameList(yymsp[-4].minor.yy236, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy254 = setTableNameList(yymsp[-4].minor.yy254, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-4].minor.yy236 = yylhsminor.yy236; + yymsp[-4].minor.yy254 = yylhsminor.yy254; break; case 178: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 179: /* interval_opt ::= INTERVAL LP tmvar RP */ -{yymsp[-3].minor.yy184.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy184.offset.n = 0;} +{yymsp[-3].minor.yy400.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy400.offset.n = 0;} break; case 180: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ -{yymsp[-5].minor.yy184.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy184.offset = yymsp[-1].minor.yy0;} +{yymsp[-5].minor.yy400.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy400.offset = yymsp[-1].minor.yy0;} break; case 181: /* interval_opt ::= */ -{memset(&yymsp[1].minor.yy184, 0, sizeof(yymsp[1].minor.yy184));} +{memset(&yymsp[1].minor.yy400, 0, sizeof(yymsp[1].minor.yy400));} break; case 182: /* session_option ::= */ -{yymsp[1].minor.yy249.col.n = 0; yymsp[1].minor.yy249.gap.n = 0;} +{yymsp[1].minor.yy139.col.n = 0; yymsp[1].minor.yy139.gap.n = 0;} break; case 183: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yymsp[-6].minor.yy249.col = yymsp[-4].minor.yy0; - yymsp[-6].minor.yy249.gap = yymsp[-1].minor.yy0; + yymsp[-6].minor.yy139.col = yymsp[-4].minor.yy0; + yymsp[-6].minor.yy139.gap = yymsp[-1].minor.yy0; } break; - case 184: /* fill_opt ::= */ -{ yymsp[1].minor.yy159 = 0; } + case 184: /* windowstate_option ::= */ +{yymsp[1].minor.yy158.col.n = 0;} break; - case 185: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 185: /* windowstate_option ::= STATE_WINDOW LP ids RP */ +{ + yymsp[-3].minor.yy158.col = yymsp[-1].minor.yy0; +} + break; + case 186: /* fill_opt ::= */ +{ yymsp[1].minor.yy291 = 0; } + break; + case 187: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); tVariantCreate(&A, &yymsp[-3].minor.yy0); - tVariantListInsert(yymsp[-1].minor.yy159, &A, -1, 0); - yymsp[-5].minor.yy159 = yymsp[-1].minor.yy159; + tVariantListInsert(yymsp[-1].minor.yy291, &A, -1, 0); + yymsp[-5].minor.yy291 = yymsp[-1].minor.yy291; } break; - case 186: /* fill_opt ::= FILL LP ID RP */ + case 188: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy159 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy291 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 187: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 189: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 188: /* sliding_opt ::= */ + case 190: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 190: /* orderby_opt ::= ORDER BY sortlist */ -{yymsp[-2].minor.yy159 = yymsp[0].minor.yy159;} + case 192: /* orderby_opt ::= ORDER BY sortlist */ +{yymsp[-2].minor.yy291 = yymsp[0].minor.yy291;} break; - case 191: /* sortlist ::= sortlist COMMA item sortorder */ + case 193: /* sortlist ::= sortlist COMMA item sortorder */ { - yylhsminor.yy159 = tVariantListAppend(yymsp[-3].minor.yy159, &yymsp[-1].minor.yy488, yymsp[0].minor.yy20); + yylhsminor.yy291 = tVariantListAppend(yymsp[-3].minor.yy291, &yymsp[-1].minor.yy216, yymsp[0].minor.yy382); } - yymsp[-3].minor.yy159 = yylhsminor.yy159; + yymsp[-3].minor.yy291 = yylhsminor.yy291; break; - case 192: /* sortlist ::= item sortorder */ + case 194: /* sortlist ::= item sortorder */ { - yylhsminor.yy159 = tVariantListAppend(NULL, &yymsp[-1].minor.yy488, yymsp[0].minor.yy20); + yylhsminor.yy291 = tVariantListAppend(NULL, &yymsp[-1].minor.yy216, yymsp[0].minor.yy382); } - yymsp[-1].minor.yy159 = yylhsminor.yy159; + yymsp[-1].minor.yy291 = yylhsminor.yy291; break; - case 193: /* item ::= ids cpxName */ + case 195: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yylhsminor.yy488, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy216, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy488 = yylhsminor.yy488; + yymsp[-1].minor.yy216 = yylhsminor.yy216; break; - case 194: /* sortorder ::= ASC */ -{ yymsp[0].minor.yy20 = TSDB_ORDER_ASC; } + case 196: /* sortorder ::= ASC */ +{ yymsp[0].minor.yy382 = TSDB_ORDER_ASC; } break; - case 195: /* sortorder ::= DESC */ -{ yymsp[0].minor.yy20 = TSDB_ORDER_DESC;} + case 197: /* sortorder ::= DESC */ +{ yymsp[0].minor.yy382 = TSDB_ORDER_DESC;} break; - case 196: /* sortorder ::= */ -{ yymsp[1].minor.yy20 = TSDB_ORDER_ASC; } + case 198: /* sortorder ::= */ +{ yymsp[1].minor.yy382 = TSDB_ORDER_ASC; } break; - case 197: /* groupby_opt ::= */ -{ yymsp[1].minor.yy159 = 0;} + case 199: /* groupby_opt ::= */ +{ yymsp[1].minor.yy291 = 0;} break; - case 198: /* groupby_opt ::= GROUP BY grouplist */ -{ yymsp[-2].minor.yy159 = yymsp[0].minor.yy159;} + case 200: /* groupby_opt ::= GROUP BY grouplist */ +{ yymsp[-2].minor.yy291 = yymsp[0].minor.yy291;} break; - case 199: /* grouplist ::= grouplist COMMA item */ + case 201: /* grouplist ::= grouplist COMMA item */ { - yylhsminor.yy159 = tVariantListAppend(yymsp[-2].minor.yy159, &yymsp[0].minor.yy488, -1); + yylhsminor.yy291 = tVariantListAppend(yymsp[-2].minor.yy291, &yymsp[0].minor.yy216, -1); } - yymsp[-2].minor.yy159 = yylhsminor.yy159; + yymsp[-2].minor.yy291 = yylhsminor.yy291; break; - case 200: /* grouplist ::= item */ + case 202: /* grouplist ::= item */ { - yylhsminor.yy159 = tVariantListAppend(NULL, &yymsp[0].minor.yy488, -1); + yylhsminor.yy291 = tVariantListAppend(NULL, &yymsp[0].minor.yy216, -1); } - yymsp[0].minor.yy159 = yylhsminor.yy159; + yymsp[0].minor.yy291 = yylhsminor.yy291; break; - case 201: /* having_opt ::= */ - case 211: /* where_opt ::= */ yytestcase(yyruleno==211); - case 253: /* expritem ::= */ yytestcase(yyruleno==253); -{yymsp[1].minor.yy118 = 0;} + case 203: /* having_opt ::= */ + case 213: /* where_opt ::= */ yytestcase(yyruleno==213); + case 255: /* expritem ::= */ yytestcase(yyruleno==255); +{yymsp[1].minor.yy436 = 0;} break; - case 202: /* having_opt ::= HAVING expr */ - case 212: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==212); -{yymsp[-1].minor.yy118 = yymsp[0].minor.yy118;} + case 204: /* having_opt ::= HAVING expr */ + case 214: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==214); +{yymsp[-1].minor.yy436 = yymsp[0].minor.yy436;} break; - case 203: /* limit_opt ::= */ - case 207: /* slimit_opt ::= */ yytestcase(yyruleno==207); -{yymsp[1].minor.yy440.limit = -1; yymsp[1].minor.yy440.offset = 0;} + case 205: /* limit_opt ::= */ + case 209: /* slimit_opt ::= */ yytestcase(yyruleno==209); +{yymsp[1].minor.yy74.limit = -1; yymsp[1].minor.yy74.offset = 0;} break; - case 204: /* limit_opt ::= LIMIT signed */ - case 208: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==208); -{yymsp[-1].minor.yy440.limit = yymsp[0].minor.yy317; yymsp[-1].minor.yy440.offset = 0;} + case 206: /* limit_opt ::= LIMIT signed */ + case 210: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==210); +{yymsp[-1].minor.yy74.limit = yymsp[0].minor.yy179; yymsp[-1].minor.yy74.offset = 0;} break; - case 205: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yymsp[-3].minor.yy440.limit = yymsp[-2].minor.yy317; yymsp[-3].minor.yy440.offset = yymsp[0].minor.yy317;} + case 207: /* limit_opt ::= LIMIT signed OFFSET signed */ +{ yymsp[-3].minor.yy74.limit = yymsp[-2].minor.yy179; yymsp[-3].minor.yy74.offset = yymsp[0].minor.yy179;} break; - case 206: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yymsp[-3].minor.yy440.limit = yymsp[0].minor.yy317; yymsp[-3].minor.yy440.offset = yymsp[-2].minor.yy317;} + case 208: /* limit_opt ::= LIMIT signed COMMA signed */ +{ yymsp[-3].minor.yy74.limit = yymsp[0].minor.yy179; yymsp[-3].minor.yy74.offset = yymsp[-2].minor.yy179;} break; - case 209: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yymsp[-3].minor.yy440.limit = yymsp[-2].minor.yy317; yymsp[-3].minor.yy440.offset = yymsp[0].minor.yy317;} + case 211: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ +{yymsp[-3].minor.yy74.limit = yymsp[-2].minor.yy179; yymsp[-3].minor.yy74.offset = yymsp[0].minor.yy179;} break; - case 210: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yymsp[-3].minor.yy440.limit = yymsp[0].minor.yy317; yymsp[-3].minor.yy440.offset = yymsp[-2].minor.yy317;} + case 212: /* slimit_opt ::= SLIMIT signed COMMA signed */ +{yymsp[-3].minor.yy74.limit = yymsp[0].minor.yy179; yymsp[-3].minor.yy74.offset = yymsp[-2].minor.yy179;} break; - case 213: /* expr ::= LP expr RP */ -{yylhsminor.yy118 = yymsp[-1].minor.yy118; yylhsminor.yy118->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy118->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 215: /* expr ::= LP expr RP */ +{yylhsminor.yy436 = yymsp[-1].minor.yy436; yylhsminor.yy436->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy436->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 214: /* expr ::= ID */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 216: /* expr ::= ID */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 215: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 217: /* expr ::= ID DOT ID */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 216: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 218: /* expr ::= ID DOT STAR */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 217: /* expr ::= INTEGER */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 219: /* expr ::= INTEGER */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 218: /* expr ::= MINUS INTEGER */ - case 219: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==219); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy118 = yylhsminor.yy118; + case 220: /* expr ::= MINUS INTEGER */ + case 221: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==221); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy436 = yylhsminor.yy436; break; - case 220: /* expr ::= FLOAT */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 222: /* expr ::= FLOAT */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 221: /* expr ::= MINUS FLOAT */ - case 222: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==222); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy118 = yylhsminor.yy118; + case 223: /* expr ::= MINUS FLOAT */ + case 224: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==224); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy436 = yylhsminor.yy436; break; - case 223: /* expr ::= STRING */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 225: /* expr ::= STRING */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 224: /* expr ::= NOW */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 226: /* expr ::= NOW */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 225: /* expr ::= VARIABLE */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 227: /* expr ::= VARIABLE */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 226: /* expr ::= PLUS VARIABLE */ - case 227: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==227); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} - yymsp[-1].minor.yy118 = yylhsminor.yy118; + case 228: /* expr ::= PLUS VARIABLE */ + case 229: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==229); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} + yymsp[-1].minor.yy436 = yylhsminor.yy436; break; - case 228: /* expr ::= BOOL */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 230: /* expr ::= BOOL */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 229: /* expr ::= NULL */ -{ yylhsminor.yy118 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 231: /* expr ::= NULL */ +{ yylhsminor.yy436 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 230: /* expr ::= ID LP exprlist RP */ -{ yylhsminor.yy118 = tSqlExprCreateFunction(yymsp[-1].minor.yy159, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy118 = yylhsminor.yy118; + case 232: /* expr ::= ID LP exprlist RP */ +{ yylhsminor.yy436 = tSqlExprCreateFunction(yymsp[-1].minor.yy291, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy436 = yylhsminor.yy436; break; - case 231: /* expr ::= ID LP STAR RP */ -{ yylhsminor.yy118 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy118 = yylhsminor.yy118; + case 233: /* expr ::= ID LP STAR RP */ +{ yylhsminor.yy436 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy436 = yylhsminor.yy436; break; - case 232: /* expr ::= expr IS NULL */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, NULL, TK_ISNULL);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 234: /* expr ::= expr IS NULL */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, NULL, TK_ISNULL);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 233: /* expr ::= expr IS NOT NULL */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-3].minor.yy118, NULL, TK_NOTNULL);} - yymsp[-3].minor.yy118 = yylhsminor.yy118; + case 235: /* expr ::= expr IS NOT NULL */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-3].minor.yy436, NULL, TK_NOTNULL);} + yymsp[-3].minor.yy436 = yylhsminor.yy436; break; - case 234: /* expr ::= expr LT expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_LT);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 236: /* expr ::= expr LT expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_LT);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 235: /* expr ::= expr GT expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_GT);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 237: /* expr ::= expr GT expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_GT);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 236: /* expr ::= expr LE expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_LE);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 238: /* expr ::= expr LE expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_LE);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 237: /* expr ::= expr GE expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_GE);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 239: /* expr ::= expr GE expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_GE);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 238: /* expr ::= expr NE expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_NE);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 240: /* expr ::= expr NE expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_NE);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 239: /* expr ::= expr EQ expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_EQ);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 241: /* expr ::= expr EQ expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_EQ);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 240: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy118); yylhsminor.yy118 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy118, yymsp[-2].minor.yy118, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy118, TK_LE), TK_AND);} - yymsp[-4].minor.yy118 = yylhsminor.yy118; + case 242: /* expr ::= expr BETWEEN expr AND expr */ +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy436); yylhsminor.yy436 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy436, yymsp[-2].minor.yy436, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy436, TK_LE), TK_AND);} + yymsp[-4].minor.yy436 = yylhsminor.yy436; break; - case 241: /* expr ::= expr AND expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_AND);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 243: /* expr ::= expr AND expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_AND);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 242: /* expr ::= expr OR expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_OR); } - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 244: /* expr ::= expr OR expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_OR); } + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 243: /* expr ::= expr PLUS expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_PLUS); } - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 245: /* expr ::= expr PLUS expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_PLUS); } + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 244: /* expr ::= expr MINUS expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_MINUS); } - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 246: /* expr ::= expr MINUS expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_MINUS); } + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 245: /* expr ::= expr STAR expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_STAR); } - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 247: /* expr ::= expr STAR expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_STAR); } + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 246: /* expr ::= expr SLASH expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_DIVIDE);} - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 248: /* expr ::= expr SLASH expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_DIVIDE);} + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 247: /* expr ::= expr REM expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_REM); } - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 249: /* expr ::= expr REM expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_REM); } + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 248: /* expr ::= expr LIKE expr */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-2].minor.yy118, yymsp[0].minor.yy118, TK_LIKE); } - yymsp[-2].minor.yy118 = yylhsminor.yy118; + case 250: /* expr ::= expr LIKE expr */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-2].minor.yy436, yymsp[0].minor.yy436, TK_LIKE); } + yymsp[-2].minor.yy436 = yylhsminor.yy436; break; - case 249: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy118 = tSqlExprCreate(yymsp[-4].minor.yy118, (tSqlExpr*)yymsp[-1].minor.yy159, TK_IN); } - yymsp[-4].minor.yy118 = yylhsminor.yy118; + case 251: /* expr ::= expr IN LP exprlist RP */ +{yylhsminor.yy436 = tSqlExprCreate(yymsp[-4].minor.yy436, (tSqlExpr*)yymsp[-1].minor.yy291, TK_IN); } + yymsp[-4].minor.yy436 = yylhsminor.yy436; break; - case 250: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy159 = tSqlExprListAppend(yymsp[-2].minor.yy159,yymsp[0].minor.yy118,0, 0);} - yymsp[-2].minor.yy159 = yylhsminor.yy159; + case 252: /* exprlist ::= exprlist COMMA expritem */ +{yylhsminor.yy291 = tSqlExprListAppend(yymsp[-2].minor.yy291,yymsp[0].minor.yy436,0, 0);} + yymsp[-2].minor.yy291 = yylhsminor.yy291; break; - case 251: /* exprlist ::= expritem */ -{yylhsminor.yy159 = tSqlExprListAppend(0,yymsp[0].minor.yy118,0, 0);} - yymsp[0].minor.yy159 = yylhsminor.yy159; + case 253: /* exprlist ::= expritem */ +{yylhsminor.yy291 = tSqlExprListAppend(0,yymsp[0].minor.yy436,0, 0);} + yymsp[0].minor.yy291 = yylhsminor.yy291; break; - case 252: /* expritem ::= expr */ -{yylhsminor.yy118 = yymsp[0].minor.yy118;} - yymsp[0].minor.yy118 = yylhsminor.yy118; + case 254: /* expritem ::= expr */ +{yylhsminor.yy436 = yymsp[0].minor.yy436;} + yymsp[0].minor.yy436 = yylhsminor.yy436; break; - case 254: /* cmd ::= RESET QUERY CACHE */ + case 256: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 255: /* cmd ::= SYNCDB ids REPLICA */ + case 257: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 256: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 258: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy159, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy291, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 257: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 259: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3010,14 +3029,14 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 258: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 260: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy159, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy291, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 259: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 261: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3028,7 +3047,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 260: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 262: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3042,26 +3061,26 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 261: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 263: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy488, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy216, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 262: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 264: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy159, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy291, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 263: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 265: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3072,14 +3091,14 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 264: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 266: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy159, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy291, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 265: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 267: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3090,7 +3109,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 266: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 268: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3104,13 +3123,13 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 267: /* cmd ::= KILL CONNECTION INTEGER */ + case 269: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 268: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 270: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 269: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 271: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: From 182936c4f123a443e2876d0f10682c0d07b478e9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 21 May 2021 05:40:40 +0800 Subject: [PATCH 08/80] [TD-2570] support state window --- src/client/inc/tsclient.h | 2 +- src/client/src/tscSQLParser.c | 56 ++++++++++++++++------- src/client/src/tscServer.c | 1 + src/client/src/tscUtil.c | 7 +-- src/inc/taosmsg.h | 1 + src/query/inc/qExecutor.h | 2 +- src/query/src/qAggMain.c | 6 ++- src/query/src/qExecutor.c | 85 ++++++++++++++++++++++------------- src/query/src/qPlan.c | 12 +++-- 9 files changed, 116 insertions(+), 56 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index b2fdafb7f3..554a062d96 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -226,7 +226,7 @@ typedef struct SQueryInfo { int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX int16_t resColumnId; // result column id bool distinctTag; // distinct tag or not - bool windowState; // window state or not + bool stateWindow; // window state or not int32_t round; // 0/1/.... int32_t bufLen; char* buf; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9b60cca0ed..777ae88860 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -89,7 +89,7 @@ static int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCm static int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); static int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* offsetToken); static int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSliding); -static int32_t validateWindowStateNode(SSqlCmd* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable); +static int32_t validateStateWindowNode(SSqlCmd* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable); static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem); @@ -829,34 +829,58 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS // The following part is used to check for the invalid query expression. return checkInvalidExprForTimeWindow(pCmd, pQueryInfo); } -static int32_t validateWindowStateNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable) { +static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable) { const char* msg1 = "invalid column name"; - const char* msg2 = "invalid window state"; - const char* msg3 = "not support window_state on super table"; + const char* msg3 = "not support state window on super table/tag column"; + const char* msg4 = "not support state_window with group by "; SStrToken *col = &(pSqlNode->windowstateVal.col) ; if (col->z == NULL || col->n <= 0) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); + return TSDB_CODE_SUCCESS; } + + if (pQueryInfo->colList == NULL) { + pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); + } + if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); + } + pQueryInfo->groupbyExpr.numOfGroupCols = 1; + //TODO(dengyihao): check tag column if (isStable) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } SColumnIndex index = COLUMN_INDEX_INITIALIZER; - if (getColumnIndexByName(pCmd, col, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { + if (getColumnIndexByName(pCmd, col, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - if (tscSqlExprNumOfExprs(pQueryInfo) == 1) { - SSqlExpr* pExpr = &(tscSqlExprGet(pQueryInfo, 0)->base); - if (index.columnIndex == pExpr->colInfo.colIndex && pExpr->colType == TSDB_DATA_TYPE_INT) { - pQueryInfo->windowState = true; - return TSDB_CODE_SUCCESS; - } - } - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; + int32_t numOfCols = tscGetNumOfColumns(pTableMeta); + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX || index.columnIndex >= numOfCols) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); + } + + SSqlGroupbyExpr* pGroupExpr = &pQueryInfo->groupbyExpr; + if (pGroupExpr->columnInfo == NULL) { + pGroupExpr->columnInfo = taosArrayInit(4, sizeof(SColIndex)); + } + + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, index.columnIndex); + if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP || pSchema->type == TSDB_DATA_TYPE_FLOAT || pSchema->type == TSDB_DATA_TYPE_DOUBLE) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + + tscColumnListInsert(pQueryInfo->colList, index.columnIndex, pTableMeta->id.uid, pSchema); + SColIndex colIndex = { .colIndex = index.columnIndex, .flag = TSDB_COL_NORMAL, .colId = pSchema->colId }; + taosArrayPush(pGroupExpr->columnInfo, &colIndex); + pQueryInfo->groupbyExpr.orderType = TSDB_ORDER_ASC; + pQueryInfo->stateWindow = true; + return TSDB_CODE_SUCCESS; } int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pSqlNode) { @@ -7319,7 +7343,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, int32_t index) { TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_SQL; } - if (validateWindowStateNode(pCmd, pQueryInfo, pSqlNode, isSTable) != TSDB_CODE_SUCCESS) { + // parse the window_state + if (validateStateWindowNode(pCmd, pQueryInfo, pSqlNode, isSTable) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_SQL; } // set order by info @@ -7344,7 +7369,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, int32_t index) { return TSDB_CODE_TSC_INVALID_SQL; } - // parse the window_state /* * transfer sql functions that need secondary merge into another format * in dealing with super table queries such as: count/first/last diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index d2bf458e58..7b2e83a1ec 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -875,6 +875,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->simpleAgg = query.simpleAgg; pQueryMsg->pointInterpQuery = query.pointInterpQuery; pQueryMsg->needReverseScan = query.needReverseScan; + pQueryMsg->stateWindow = query.stateWindow; pQueryMsg->numOfTags = htonl(numOfTags); pQueryMsg->sqlstrLen = htonl(sqlLen); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index a40501d1cf..d64a3de930 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -3545,12 +3545,13 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->simpleAgg = isSimpleAggregate(pQueryInfo); pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo); pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type); - pQueryAttr->groupbyColumn = tscGroupbyColumn(pQueryInfo); + pQueryAttr->groupbyColumn = (!pQueryInfo->stateWindow) && tscGroupbyColumn(pQueryInfo); pQueryAttr->queryBlockDist = isBlockDistQuery(pQueryInfo); pQueryAttr->pointInterpQuery = tscIsPointInterpQuery(pQueryInfo); pQueryAttr->timeWindowInterpo = timeWindowInterpoRequired(pQueryInfo); pQueryAttr->distinctTag = pQueryInfo->distinctTag; - pQueryAttr->windowState = pQueryInfo->windowState; + pQueryAttr->sw = pQueryInfo->sessionWindow; + pQueryAttr->stateWindow = pQueryInfo->stateWindow; pQueryAttr->numOfCols = numOfCols; pQueryAttr->numOfOutput = numOfOutput; @@ -3558,8 +3559,8 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->slimit = pQueryInfo->slimit; pQueryAttr->order = pQueryInfo->order; pQueryAttr->fillType = pQueryInfo->fillType; - pQueryAttr->groupbyColumn = tscGroupbyColumn(pQueryInfo); pQueryAttr->havingNum = pQueryInfo->havingFieldNum; + if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor pQueryAttr->window = pQueryInfo->window; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 3b7022fb88..d98fc9a6e2 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -471,6 +471,7 @@ typedef struct { bool simpleAgg; bool pointInterpQuery; // point interpolation query bool needReverseScan; // need reverse scan + bool stateWindow; // state window flag STimeWindow window; int32_t numOfTables; diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index 6640061c63..6ad23e219b 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -196,7 +196,7 @@ typedef struct SQueryAttr { bool pointInterpQuery; // point interpolation query bool needReverseScan; // need reverse scan bool distinctTag; // distinct tag query - bool windowState; // window State on sub/normal table + bool stateWindow; // window State on sub/normal table int32_t interBufSize; // intermediate buffer sizse int32_t havingNum; // having expr number diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 3b1ffa46d9..e99f135904 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -3298,8 +3298,12 @@ static void col_project_function(SQLFunctionCtx *pCtx) { if (pCtx->numOfParams == 2) { return; } + if (pCtx->param[0].i64 == 1) { + SET_VAL(pCtx, pCtx->size, 1); + } else { + INC_INIT_VAL(pCtx, pCtx->size); + } - INC_INIT_VAL(pCtx, pCtx->size); char *pData = GET_INPUT_DATA_LIST(pCtx); if (pCtx->order == TSDB_ORDER_ASC) { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 9bec84e28e..6c87b848a4 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -190,7 +190,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator); static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo* pGroupResInfo, int32_t orderType, SSDataBlock* pBlock); static int32_t getGroupbyColumnIndex(SSqlGroupbyExpr *pGroupbyExpr, SSDataBlock* pDataBlock); -static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SGroupbyOperatorInfo *pInfo, int32_t numOfCols, char *pData, int16_t type, int16_t bytes, int32_t groupIndex); +static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *bInfo, int32_t numOfCols, char *pData, int16_t type, int16_t bytes, int32_t groupIndex); static void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size); static void getAlignQueryTimeWindow(SQueryAttr *pQueryAttr, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow *win); @@ -727,7 +727,6 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx if (pCtx[k].preAggVals.isSet && forwardStep < numOfTotal) { pCtx[k].preAggVals.isSet = false; } - if (functionNeedToExecute(pRuntimeEnv, &pCtx[k], functionId)) { aAggs[functionId].xFunction(&pCtx[k]); } @@ -1295,7 +1294,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn } int32_t ret = - setGroupResultOutputBuf(pRuntimeEnv, pInfo, pOperator->numOfOutput, val, type, bytes, item->groupIndex); + setGroupResultOutputBuf(pRuntimeEnv, &(pInfo->binfo), pOperator->numOfOutput, val, type, bytes, item->groupIndex); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); } @@ -1336,7 +1335,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf pInfo->curWindow.ekey = tsList[j]; pInfo->prevTs = tsList[j]; pInfo->numOfRows += 1; - pInfo->start = j; + //pInfo->start = j; } else { // start a new session window SResultRow* pResult = NULL; @@ -1387,12 +1386,12 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { } } -static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SGroupbyOperatorInfo *pInfo, int32_t numOfCols, char *pData, int16_t type, int16_t bytes, int32_t groupIndex) { +static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *binfo, int32_t numOfCols, char *pData, int16_t type, int16_t bytes, int32_t groupIndex) { SDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf; - int32_t *rowCellInfoOffset = pInfo->binfo.rowCellInfoOffset; - SResultRowInfo *pResultRowInfo = &pInfo->binfo.resultRowInfo; - SQLFunctionCtx *pCtx = pInfo->binfo.pCtx; + int32_t *rowCellInfoOffset = binfo->rowCellInfoOffset; + SResultRowInfo *pResultRowInfo = &binfo->resultRowInfo; + SQLFunctionCtx *pCtx = binfo->pCtx; // not assign result buffer yet, add new result buffer, TODO remove it char* d = pData; @@ -3143,7 +3142,7 @@ void finalizeQueryResult(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SResult SQueryAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; int32_t numOfOutput = pOperator->numOfOutput; - if (pQueryAttr->groupbyColumn || QUERY_IS_INTERVAL_QUERY(pQueryAttr) || pQueryAttr->sw.gap > 0) { + if (pQueryAttr->groupbyColumn || QUERY_IS_INTERVAL_QUERY(pQueryAttr) || pQueryAttr->sw.gap > 0 || pQueryAttr->stateWindow) { // for each group result, call the finalize function for each column if (pQueryAttr->groupbyColumn) { closeAllResultRows(pResultRowInfo); @@ -5063,37 +5062,37 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) { static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { - SColumnInfoData* pColInfoData = taosArrayGet(pSDataBlock->pDataBlock, pInfo->colIndex); - SOptrBasicInfo* pBInfo = &pInfo->binfo; - int16_t bytes = pColInfoData->info.bytes; - int16_t type = pColInfoData->info.type; SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; STableQueryInfo* item = pRuntimeEnv->current; - bool masterScan = IS_MASTER_SCAN(pRuntimeEnv); + SColumnInfoData* pColInfoData = taosArrayGet(pSDataBlock->pDataBlock, pInfo->colIndex); + + SOptrBasicInfo* pBInfo = &pInfo->binfo; + + bool masterScan = IS_MASTER_SCAN(pRuntimeEnv); + int16_t bytes = pColInfoData->info.bytes; + int16_t type = pColInfoData->info.type; SColumnInfoData* pTsColInfoData = taosArrayGet(pSDataBlock->pDataBlock, 0); TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; - - if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_TIMESTAMP) { - qError("QInfo:0x%"PRIx64" group by not supported on double/float columns, abort", GET_QID(pRuntimeEnv)); - return; - } + + pInfo->numOfRows = 0; for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { char* val = ((char*)pColInfoData->pData) + bytes * j; if (isNull(val, type)) { continue; } if (pInfo->prevData == NULL) { - pInfo->prevData = malloc(bytes); + pInfo->prevData = malloc(bytes); memcpy(pInfo->prevData, val, bytes); + pInfo->numOfRows = 1; pInfo->curWindow.skey = tsList[j]; pInfo->curWindow.ekey = tsList[j]; - pInfo->numOfRows = 1; - pInfo->start = j; - } else if (0 == memcmp(pInfo->prevData, val, bytes)) { + pInfo->start = j; + + } else if (memcmp(pInfo->prevData, val, bytes) == 0) { pInfo->curWindow.ekey = tsList[j]; pInfo->numOfRows += 1; - pInfo->start = j; + pInfo->start = j; } else { SResultRow* pResult = NULL; int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, @@ -5102,7 +5101,6 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); } - doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, pSDataBlock->info.rows, pOperator->numOfOutput); @@ -5111,7 +5109,30 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI memcpy(pInfo->prevData, val, bytes); pInfo->numOfRows = 1; pInfo->start = j; - } + + } + // Compare with the previous row of this column, and do not set the output buffer again if they are identical. + //if (pInfo->prevData == NULL || (memcmp(pInfo->prevData, val, bytes) != 0)) { + // if (pInfo->prevData == NULL) { + // pInfo->prevData = malloc(bytes); + // } + // pInfo->curWindow.skey = tsList[j]; + // pInfo->curWindow.ekey = tsList[j]; + + // memcpy(pInfo->prevData, val, bytes); + // int32_t ret = + // setGroupResultOutputBuf(pRuntimeEnv, &(pInfo->binfo), pOperator->numOfOutput, (char *)&v, type, bytes, item->groupIndex); + // if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code + // longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); + // } + //} + //for (int32_t k = 0; k < pOperator->numOfOutput; ++k) { + // pInfo->binfo.pCtx[k].size = 1; + // int32_t functionId = pInfo->binfo.pCtx[k].functionId; + // if (functionNeedToExecute(pRuntimeEnv, &pInfo->binfo.pCtx[k], functionId)) { + // aAggs[functionId].xFunctionF(&pInfo->binfo.pCtx[k], j); + // } + //} } SResultRow* pResult = NULL; @@ -5124,25 +5145,28 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI doApplyFunctions(pRuntimeEnv, pBInfo->pCtx, &pInfo->curWindow, pInfo->start, pInfo->numOfRows, tsList, pSDataBlock->info.rows, pOperator->numOfOutput); - } static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) { SOperatorInfo* pOperator = (SOperatorInfo*) param; if (pOperator->status == OP_EXEC_DONE) { return NULL; } + SStateWindowOperatorInfo* pWindowInfo = pOperator->info; - SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; - SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; + + SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } + return pBInfo->pRes; } + + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; int32_t order = pQueryAttr->order.order; STimeWindow win = pQueryAttr->window; SOperatorInfo* upstream = pOperator->upstream; @@ -5153,7 +5177,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) { } setInputDataBlock(pOperator, pBInfo->pCtx, pBlock, pQueryAttr->order.order); if (pWindowInfo->colIndex == -1) { - pWindowInfo->colIndex = pOperator->pExpr->base.colInfo.colIndex; + pWindowInfo->colIndex = getGroupbyColumnIndex(pRuntimeEnv->pQueryAttr->pGroupbyExpr, pBlock); } doStateWindowAggImpl(pOperator, pWindowInfo, pBlock); } @@ -6965,6 +6989,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SSqlGroupbyExpr* pGroupbyExpr pQueryAttr->simpleAgg = pQueryMsg->simpleAgg; pQueryAttr->pointInterpQuery = pQueryMsg->pointInterpQuery; pQueryAttr->needReverseScan = pQueryMsg->needReverseScan; + pQueryAttr->stateWindow = pQueryMsg->stateWindow; pQueryAttr->vgId = vgId; pQueryAttr->tableCols = calloc(numOfCols, sizeof(SSingleColumnFilterInfo)); diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 52b0329293..7ed0e10327 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -113,6 +113,14 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { op = OP_SessionWindow; taosArrayPush(plan, &op); + if (pQueryAttr->pExpr2 != NULL) { + op = OP_Arithmetic; + taosArrayPush(plan, &op); + } + } else if (pQueryAttr->stateWindow) { + op = OP_StateWindow; + taosArrayPush(plan, &op); + if (pQueryAttr->pExpr2 != NULL) { op = OP_Arithmetic; taosArrayPush(plan, &op); @@ -121,10 +129,6 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { if (pQueryAttr->stableQuery && !pQueryAttr->tsCompQuery) { op = OP_MultiTableAggregate; } else { - if (pQueryAttr->windowState) { - op = OP_StateWindow; - taosArrayPush(plan, &op); - } op = OP_Aggregate; } From ad52efd8ccce6fefca5c13eac58a37d3df8499e1 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 21 May 2021 05:55:51 +0800 Subject: [PATCH 09/80] [TD-2570] support state window --- src/query/src/qExecutor.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6c87b848a4..9a4673151c 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1335,7 +1335,10 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf pInfo->curWindow.ekey = tsList[j]; pInfo->prevTs = tsList[j]; pInfo->numOfRows += 1; - //pInfo->start = j; + if (j == 0 && pInfo->start != 0) { + pInfo->numOfRows = 1; + pInfo->start = 0; + } } else { // start a new session window SResultRow* pResult = NULL; @@ -5093,6 +5096,10 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI pInfo->curWindow.ekey = tsList[j]; pInfo->numOfRows += 1; pInfo->start = j; + if (j == 0 && pInfo->start != 0) { + pInfo->numOfRows = 1; + pInfo->start = 0; + } } else { SResultRow* pResult = NULL; int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, From bcf7be5026628d4592c08823a0da1d84e9de8024 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 21 May 2021 07:10:59 +0800 Subject: [PATCH 10/80] [TD-2570] support state window --- src/query/src/qExecutor.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 9a4673151c..f9398c6dd4 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5118,28 +5118,6 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI pInfo->start = j; } - // Compare with the previous row of this column, and do not set the output buffer again if they are identical. - //if (pInfo->prevData == NULL || (memcmp(pInfo->prevData, val, bytes) != 0)) { - // if (pInfo->prevData == NULL) { - // pInfo->prevData = malloc(bytes); - // } - // pInfo->curWindow.skey = tsList[j]; - // pInfo->curWindow.ekey = tsList[j]; - - // memcpy(pInfo->prevData, val, bytes); - // int32_t ret = - // setGroupResultOutputBuf(pRuntimeEnv, &(pInfo->binfo), pOperator->numOfOutput, (char *)&v, type, bytes, item->groupIndex); - // if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code - // longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_APP_ERROR); - // } - //} - //for (int32_t k = 0; k < pOperator->numOfOutput; ++k) { - // pInfo->binfo.pCtx[k].size = 1; - // int32_t functionId = pInfo->binfo.pCtx[k].functionId; - // if (functionNeedToExecute(pRuntimeEnv, &pInfo->binfo.pCtx[k], functionId)) { - // aAggs[functionId].xFunctionF(&pInfo->binfo.pCtx[k], j); - // } - //} } SResultRow* pResult = NULL; From 261e50e23e5bc34723032c4f96e8908d24bb69ce Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Sat, 22 May 2021 15:11:45 +0800 Subject: [PATCH 11/80] cq can continue with output table last row time --- src/client/src/tscStream.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index f0f87f26db..267fa0c0fe 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -539,6 +539,31 @@ static int64_t tscGetLaunchTimestamp(const SSqlStream *pStream) { return (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? timer / 1000L : timer; } +// +// get tableName last row time, if have error return zero. +// +static int64_t tscGetStreamTableLastTime(SSqlObj* pSql, SSqlStream* pStream, const char* tableName) { + + int64_t last_time = 0; + char sql[128] = ""; + sprintf(sql, "select last_row(*) from %s;", tableName); + + // query sql + TAOS_RES* res = taos_query(pSql->pTscObj, sql); + if(res == NULL) + return 0; + + // only fetch one row + TAOS_ROW row = taos_fetch_row(res); + if( row[0] ) { + last_time = *((int64_t*)row[0]); + } + + // free and return + taos_free_result(res); + return last_time; +} + static void tscCreateStream(void *param, TAOS_RES *res, int code) { SSqlStream* pStream = (SSqlStream*)param; SSqlObj* pSql = pStream->pSql; @@ -572,6 +597,13 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) { pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, pStream->stime); + // set output table last record time to stime if have, why do this, because continue with last break + int64_t last_time = tscGetStreamTableLastTime(pSql, pStream, pStream->dstTable); + if(last_time > 0 && last_time > pStream->stime) { + // can replace stime with last row time + pStream->stime = last_time; + } + int64_t starttime = tscGetLaunchTimestamp(pStream); pCmd->command = TSDB_SQL_SELECT; From 1ee65f6c86bdbfc5402fd7ee0048249e07ac9a2a Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Sat, 22 May 2021 15:39:46 +0800 Subject: [PATCH 12/80] modify stream retry defalut delay from 10ms to 10*1000ms --- src/client/src/tscStream.c | 4 ++-- src/common/inc/tglobal.h | 2 +- src/common/src/tglobal.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 267fa0c0fe..0f6a403582 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -48,8 +48,8 @@ static bool isProjectStream(SQueryInfo* pQueryInfo) { static int64_t tscGetRetryDelayTime(SSqlStream* pStream, int64_t slidingTime, int16_t prec) { float retryRangeFactor = 0.3f; - int64_t retryDelta = (int64_t)(tsStreamCompRetryDelay * retryRangeFactor); - retryDelta = ((rand() % retryDelta) + tsStreamCompRetryDelay) * 1000L; + int64_t retryDelta = (int64_t)(tsRetryStreamCompDelay * retryRangeFactor); + retryDelta = ((rand() % retryDelta) + tsRetryStreamCompDelay) * 1000L; if (pStream->interval.intervalUnit != 'n' && pStream->interval.intervalUnit != 'y') { // change to ms diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 26475834d5..1e66ce3f0c 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -74,7 +74,7 @@ extern int32_t tsMinSlidingTime; extern int32_t tsMinIntervalTime; extern int32_t tsMaxStreamComputDelay; extern int32_t tsStreamCompStartDelay; -extern int32_t tsStreamCompRetryDelay; +extern int32_t tsRetryStreamCompDelay; extern float tsStreamComputDelayRatio; // the delayed computing ration of the whole time window extern int32_t tsProjectExecInterval; extern int64_t tsMaxRetentWindow; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index c3c159ee45..2f18c8f73a 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -92,7 +92,7 @@ int32_t tsMaxStreamComputDelay = 20000; int32_t tsStreamCompStartDelay = 10000; // the stream computing delay time after executing failed, change accordingly -int32_t tsStreamCompRetryDelay = 10; +int32_t tsRetryStreamCompDelay = 10*1000; // The delayed computing ration. 10% of the whole computing time window by default. float tsStreamComputDelayRatio = 0.1f; @@ -696,7 +696,7 @@ static void doInitGlobalConfig(void) { taosInitConfigOption(cfg); cfg.option = "retryStreamCompDelay"; - cfg.ptr = &tsStreamCompRetryDelay; + cfg.ptr = &tsRetryStreamCompDelay; cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 10; From 75ca521a8618defa6e68260d4de896bc3132fb62 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 26 May 2021 11:00:29 +0800 Subject: [PATCH 13/80] [td-225] add log for debug purpose --- src/client/src/tscParseInsert.c | 11 ++++------- src/client/src/tscServer.c | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index f09ca351ff..24031c8ce2 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1348,15 +1348,10 @@ int tsParseSql(SSqlObj *pSql, bool initial) { } // make a backup as tsParseInsertSql may modify the string - char* sqlstr = strdup(pSql->sqlstr); ret = tsParseInsertSql(pSql); - if ((sqlstr == NULL) || (pSql->parseRetry >= 1) || - (ret != TSDB_CODE_TSC_SQL_SYNTAX_ERROR && ret != TSDB_CODE_TSC_INVALID_SQL)) { - free(sqlstr); + if ((pSql->parseRetry >= 1) || (ret != TSDB_CODE_TSC_SQL_SYNTAX_ERROR && ret != TSDB_CODE_TSC_INVALID_SQL)) { } else { tscResetSqlCmd(pCmd, true); - free(pSql->sqlstr); - pSql->sqlstr = sqlstr; pSql->parseRetry++; if ((ret = tsInsertInitialCheck(pSql)) == TSDB_CODE_SUCCESS) { ret = tsParseInsertSql(pSql); @@ -1365,9 +1360,11 @@ int tsParseSql(SSqlObj *pSql, bool initial) { } else { SSqlInfo SQLInfo = qSqlParse(pSql->sqlstr); ret = tscToSQLCmd(pSql, &SQLInfo); - if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0 && SQLInfo.type == TSDB_SQL_NULL) { + if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0/* && SQLInfo.type == TSDB_SQL_NULL*/) { + tscDebug("0x%"PRIx64 " parse sql failed, retry again after clear local meta cache", pSql->self); tscResetSqlCmd(pCmd, true); pSql->parseRetry++; + ret = tscToSQLCmd(pSql, &SQLInfo); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 648b95180e..3f47cdba1f 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2517,7 +2517,7 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn pNew->fp = tscTableMetaCallBack; pNew->param = (void *)pSql->self; - tscDebug("0x%"PRIx64" metaRid from %" PRId64 " to %" PRId64 , pSql->self, pSql->metaRid, pNew->self); + tscDebug("0x%"PRIx64" metaRid from %" PRId64 " to 0x%" PRIx64 , pSql->self, pSql->metaRid, pNew->self); pSql->metaRid = pNew->self; From aaf9081309aaf63531663c5fbb54d547ee012367 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Wed, 26 May 2021 07:19:53 +0000 Subject: [PATCH 14/80] modify env --- tests/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Jenkinsfile b/tests/Jenkinsfile index 2f2b9f6933..0c1f651059 100644 --- a/tests/Jenkinsfile +++ b/tests/Jenkinsfile @@ -29,8 +29,8 @@ pipeline { agent none environment{ - WK = '/var/lib/jenkins/workspace/TDinternal' - WKC= '/var/lib/jenkins/workspace/TDinternal/community' + WK = '/data/lib/jenkins/workspace/TDinternal' + WKC= '/data/lib/jenkins/workspace/TDinternal/community' } stages { From 2270703980b5f0ac3ab352dff826986b219f645a Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Wed, 26 May 2021 07:21:07 +0000 Subject: [PATCH 15/80] modify env --- tests/Jenkinsfile | 4 ++-- tests/mas/Jenkinsfile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Jenkinsfile b/tests/Jenkinsfile index e785c8e807..63c12ed8b1 100644 --- a/tests/Jenkinsfile +++ b/tests/Jenkinsfile @@ -29,8 +29,8 @@ pipeline { agent none environment{ - WK = '/var/lib/jenkins/workspace/TDinternal' - WKC= '/var/lib/jenkins/workspace/TDinternal/community' + WK = '/data/lib/jenkins/workspace/TDinternal' + WKC= '/data/lib/jenkins/workspace/TDinternal/community' } stages { diff --git a/tests/mas/Jenkinsfile b/tests/mas/Jenkinsfile index b2a1a5e116..0e6e94a037 100644 --- a/tests/mas/Jenkinsfile +++ b/tests/mas/Jenkinsfile @@ -29,8 +29,8 @@ pipeline { agent none environment{ - WK = '/var/lib/jenkins/workspace/TDinternal' - WKC= '/var/lib/jenkins/workspace/TDinternal/community' + WK = '/data/lib/jenkins/workspace/TDinternal' + WKC= '/data/lib/jenkins/workspace/TDinternal/community' } stages { From 70720a2a18de2b2be13ad296fade2a4918da251c Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 26 May 2021 17:20:58 +0800 Subject: [PATCH 16/80] [td-225] fix bug found by regression test. --- src/client/src/tscParseInsert.c | 10 +++++----- src/client/src/tscSQLParser.c | 8 ++++++-- src/util/inc/ttoken.h | 2 ++ src/util/src/ttokenizer.c | 12 ++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 24031c8ce2..f54237306c 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1358,17 +1358,17 @@ int tsParseSql(SSqlObj *pSql, bool initial) { } } } else { - SSqlInfo SQLInfo = qSqlParse(pSql->sqlstr); - ret = tscToSQLCmd(pSql, &SQLInfo); - if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0/* && SQLInfo.type == TSDB_SQL_NULL*/) { + SSqlInfo sqlInfo = qSqlParse(pSql->sqlstr); + ret = tscToSQLCmd(pSql, &sqlInfo); + if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0/* && sqlInfo.type == TSDB_SQL_NULL*/) { tscDebug("0x%"PRIx64 " parse sql failed, retry again after clear local meta cache", pSql->self); tscResetSqlCmd(pCmd, true); pSql->parseRetry++; - ret = tscToSQLCmd(pSql, &SQLInfo); + ret = tscToSQLCmd(pSql, &sqlInfo); } - SqlInfoDestroy(&SQLInfo); + SqlInfoDestroy(&sqlInfo); } /* diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c472b08dc0..7efa593808 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -361,11 +361,15 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { const char* msg2 = "name too long"; SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt); - if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) { + + char buf[TSDB_DB_NAME_LEN] = {0}; + SStrToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf)); + + if (tscValidateName(&token) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname)); + int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pSql), &token); if (ret != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } diff --git a/src/util/inc/ttoken.h b/src/util/inc/ttoken.h index c1e2170ac3..3e7c5f3129 100644 --- a/src/util/inc/ttoken.h +++ b/src/util/inc/ttoken.h @@ -185,6 +185,8 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SStrToken* pToken) { void taosCleanupKeywordsTable(); +SStrToken taosTokenDup(SStrToken* pToken, char* buf, int32_t len); + #ifdef __cplusplus } #endif diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 54da75cae0..3448e8e2ba 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -664,3 +664,15 @@ void taosCleanupKeywordsTable() { taosHashCleanup(m); } } + +SStrToken taosTokenDup(SStrToken* pToken, char* buf, int32_t len) { + assert(pToken != NULL && buf != NULL); + SStrToken token = *pToken; + token.z = buf; + + assert(len > token.n); + strncpy(token.z, pToken->z, pToken->n); + token.z[token.n] = 0; + + return token; +} From f0a7a53375c9757dff06ec702d4b1e798d16125f Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 26 May 2021 19:49:54 +0800 Subject: [PATCH 17/80] [td-225] --- src/client/src/tscSQLParser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 7efa593808..f8aa444d9e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -361,6 +361,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { const char* msg2 = "name too long"; SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt); + if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + } char buf[TSDB_DB_NAME_LEN] = {0}; SStrToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf)); From 4b4199ce415076bdb4f0a7244e9aef21fb876fe5 Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Wed, 26 May 2021 20:50:00 +0800 Subject: [PATCH 18/80] cq support continue query from last stop time --- src/client/inc/tsclient.h | 1 + src/client/src/tscStream.c | 41 +++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 4bfd3bc88f..0e63fa3551 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -422,6 +422,7 @@ typedef struct SSqlStream { int64_t ctime; // stream created time int64_t stime; // stream next executed time int64_t etime; // stream end query time, when time is larger then etime, the stream will be closed + int64_t ltime; // stream last row time in stream table SInterval interval; void * pTimer; diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 0f6a403582..9094f95dfc 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -538,12 +538,11 @@ static int64_t tscGetLaunchTimestamp(const SSqlStream *pStream) { return (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? timer / 1000L : timer; } - +///* // // get tableName last row time, if have error return zero. // static int64_t tscGetStreamTableLastTime(SSqlObj* pSql, SSqlStream* pStream, const char* tableName) { - int64_t last_time = 0; char sql[128] = ""; sprintf(sql, "select last_row(*) from %s;", tableName); @@ -555,7 +554,7 @@ static int64_t tscGetStreamTableLastTime(SSqlObj* pSql, SSqlStream* pStream, con // only fetch one row TAOS_ROW row = taos_fetch_row(res); - if( row[0] ) { + if( row && row[0] ) { last_time = *((int64_t*)row[0]); } @@ -563,7 +562,7 @@ static int64_t tscGetStreamTableLastTime(SSqlObj* pSql, SSqlStream* pStream, con taos_free_result(res); return last_time; } - +//*/ static void tscCreateStream(void *param, TAOS_RES *res, int code) { SSqlStream* pStream = (SSqlStream*)param; SSqlObj* pSql = pStream->pSql; @@ -597,10 +596,14 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) { pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, pStream->stime); - // set output table last record time to stime if have, why do this, because continue with last break - int64_t last_time = tscGetStreamTableLastTime(pSql, pStream, pStream->dstTable); + // set output table last record time to stime if have, why do this, because continue with last brea + const char* dstTable = pStream->dstTable? pStream->dstTable: ""; + int64_t last_time = tscGetStreamTableLastTime(pSql, pStream, dstTable); + pStream->ltime = last_time; + tscDebug(" CQ get table=%s lasttime=%"PRId64" end.", dstTable, last_time); if(last_time > 0 && last_time > pStream->stime) { // can replace stime with last row time + tscDebug(" CQ set table %s stime=%"PRId64" with lasttime=%"PRId64" ", dstTable, pStream->stime, last_time); pStream->stime = last_time; } @@ -619,6 +622,24 @@ void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable) { pStream->dstTable = dstTable; } +// already run on another thread +void tscCreateStreamThread(SSchedMsg* pMsg) { + tscDebug(" new thread Sched call tscCreateStream begin..."); + tscCreateStream(pMsg->ahandle, NULL, 0); + tscDebug(" new thread Sched call tscCreateStream end."); + return ; +} + +// parsesql async response return and change run thread +void tsParseSqlRet(void* param, TAOS_RES* res, int code) { + SSchedMsg schedMsg = { 0 }; + schedMsg.fp = tscCreateStreamThread; + schedMsg.ahandle = param; + schedMsg.thandle = res; + schedMsg.msg = NULL; + taosScheduleTask(tscQhandle, &schedMsg); +} + TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *)) { STscObj *pObj = (STscObj *)taos; @@ -664,15 +685,17 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p tscDebugL("%p SQL: %s", pSql, pSql->sqlstr); tsem_init(&pSql->rspSem, 0, 0); - pSql->fp = tscCreateStream; - pSql->fetchFp = tscCreateStream; + pSql->fp = tsParseSqlRet; + pSql->fetchFp = tsParseSqlRet; registerSqlObj(pSql); int32_t code = tsParseSql(pSql, true); if (code == TSDB_CODE_SUCCESS) { tscCreateStream(pStream, pSql, code); - } else if (code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + } else if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + tscDebug(" cq parseSql IN Process pass. "); + } else { tscError("0x%"PRIx64" open stream failed, sql:%s, code:%s", pSql->self, sqlstr, tstrerror(code)); taosReleaseRef(tscObjRef, pSql->self); free(pStream); From 0c4075e09fa0c2e40efae77b9ded0a314ad657e2 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 26 May 2021 21:02:14 +0800 Subject: [PATCH 19/80] [TD-4533]: taosdemo resub if resubAfterConsume != -1 (#6243) Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 72 +++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 54dd68de44..29a1f7f1f9 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -364,7 +364,7 @@ typedef struct SDbs_S { typedef struct SpecifiedQueryInfo_S { uint64_t queryInterval; // 0: unlimit > 0 loop/s uint32_t concurrent; - uint64_t sqlCount; + int sqlCount; uint32_t asyncMode; // 0: sync, 1: async uint64_t subscribeInterval; // ms uint64_t queryTimes; @@ -373,6 +373,7 @@ typedef struct SpecifiedQueryInfo_S { char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN+1]; int resubAfterConsume[MAX_QUERY_SQL_COUNT]; + int endAfterConsume[MAX_QUERY_SQL_COUNT]; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; char topic[MAX_QUERY_SQL_COUNT][32]; int consumed[MAX_QUERY_SQL_COUNT]; @@ -391,10 +392,11 @@ typedef struct SuperQueryInfo_S { uint64_t queryTimes; int64_t childTblCount; char childTblPrefix[MAX_TB_NAME_SIZE]; - uint64_t sqlCount; + int sqlCount; char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN+1]; int resubAfterConsume; + int endAfterConsume; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; char* childTblName; @@ -1717,7 +1719,7 @@ static void printfQueryMeta() { if ((SUBSCRIBE_TEST == g_args.test_mode) || (QUERY_TEST == g_args.test_mode)) { printf("specified table query info: \n"); - printf("sqlCount: \033[33m%"PRIu64"\033[0m\n", + printf("sqlCount: \033[33m%d\033[0m\n", g_queryInfo.specifiedQueryInfo.sqlCount); if (g_queryInfo.specifiedQueryInfo.sqlCount > 0) { printf("specified tbl query times:\n"); @@ -1737,15 +1739,15 @@ static void printfQueryMeta() { printf("keepProgress: \033[33m%d\033[0m\n", g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); - for (uint64_t i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { - printf(" sql[%"PRIu64"]: \033[33m%s\033[0m\n", + for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { + printf(" sql[%d]: \033[33m%s\033[0m\n", i, g_queryInfo.specifiedQueryInfo.sql[i]); } printf("\n"); } printf("super table query info:\n"); - printf("sqlCount: \033[33m%"PRIu64"\033[0m\n", + printf("sqlCount: \033[33m%d\033[0m\n", g_queryInfo.superQueryInfo.sqlCount); if (g_queryInfo.superQueryInfo.sqlCount > 0) { @@ -4197,7 +4199,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { if (concurrent && concurrent->type == cJSON_Number) { if (concurrent->valueint <= 0) { errorPrint( - "%s() LN%d, query sqlCount %"PRIu64" or concurrent %d is not correct.\n", + "%s() LN%d, query sqlCount %d or concurrent %d is not correct.\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount, g_queryInfo.specifiedQueryInfo.concurrent); @@ -4296,6 +4298,17 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { tstrncpy(g_queryInfo.specifiedQueryInfo.sql[j], sqlStr->valuestring, MAX_QUERY_SQL_LENGTH); + cJSON* endAfterConsume = + cJSON_GetObjectItem(specifiedQuery, "endAfterConsume"); + if (endAfterConsume + && endAfterConsume->type == cJSON_Number) { + g_queryInfo.specifiedQueryInfo.endAfterConsume[j] + = endAfterConsume->valueint; + } else if (!endAfterConsume) { + // default value is -1, which mean infinite loop + g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = -1; + } + cJSON* resubAfterConsume = cJSON_GetObjectItem(specifiedQuery, "resubAfterConsume"); if (resubAfterConsume @@ -4303,9 +4316,8 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = resubAfterConsume->valueint; } else if (!resubAfterConsume) { - //printf("failed to read json, subscribe interval no found\n"); - //goto PARSE_OVER; - g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = 1; + // default value is -1, which mean do not resub + g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = -1; } cJSON *result = cJSON_GetObjectItem(sql, "result"); @@ -4449,16 +4461,26 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; } + cJSON* superEndAfterConsume = + cJSON_GetObjectItem(superQuery, "endAfterConsume"); + if (superEndAfterConsume + && superEndAfterConsume->type == cJSON_Number) { + g_queryInfo.superQueryInfo.endAfterConsume = + superEndAfterConsume->valueint; + } else if (!superEndAfterConsume) { + // default value is -1, which mean do not resub + g_queryInfo.superQueryInfo.endAfterConsume = -1; + } + cJSON* superResubAfterConsume = - cJSON_GetObjectItem(superQuery, "resubAfterConsume"); + cJSON_GetObjectItem(superQuery, "endAfterConsume"); if (superResubAfterConsume && superResubAfterConsume->type == cJSON_Number) { - g_queryInfo.superQueryInfo.resubAfterConsume = + g_queryInfo.superQueryInfo.endAfterConsume = superResubAfterConsume->valueint; } else if (!superResubAfterConsume) { - //printf("failed to read json, subscribe interval no found\n"); - ////goto PARSE_OVER; - g_queryInfo.superQueryInfo.resubAfterConsume = 1; + // default value is -1, which mean do not resub + g_queryInfo.superQueryInfo.endAfterConsume = -1; } // supert table sqls @@ -6679,7 +6701,10 @@ static void *superSubscribe(void *sarg) { uint64_t st = 0, et = 0; - while(1) { + while ((g_queryInfo.superQueryInfo.endAfterConsume == -1) + || (g_queryInfo.superQueryInfo.endAfterConsume < + consumed[pThreadInfo->end_table_to - pThreadInfo->start_table_from])) { + for (uint64_t i = pThreadInfo->start_table_from; i <= pThreadInfo->end_table_to; i++) { tsubSeq = i - pThreadInfo->start_table_from; @@ -6708,7 +6733,7 @@ static void *superSubscribe(void *sarg) { } consumed[tsubSeq] ++; - if ((g_queryInfo.superQueryInfo.subscribeKeepProgress) + if ((g_queryInfo.superQueryInfo.resubAfterConsume != -1) && (consumed[tsubSeq] >= g_queryInfo.superQueryInfo.resubAfterConsume)) { printf("keepProgress:%d, resub super table query: %"PRIu64"\n", @@ -6790,7 +6815,10 @@ static void *specifiedSubscribe(void *sarg) { // start loop to consume result g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = 0; - while(1) { + while((g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq] == -1) + || (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] < + g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq])) { + if (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode) { continue; } @@ -6806,7 +6834,7 @@ static void *specifiedSubscribe(void *sarg) { } g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] ++; - if ((g_queryInfo.specifiedQueryInfo.subscribeKeepProgress) + if ((g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq] != -1) && (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] >= g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq])) { printf("keepProgress:%d, resub specified query: %"PRIu64"\n", @@ -6873,12 +6901,12 @@ static int subscribeTestProcess() { //==== create threads for query for specified table if (g_queryInfo.specifiedQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, sepcified query sqlCount %"PRIu64".\n", + debugPrint("%s() LN%d, sepcified query sqlCount %d.\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount); } else { if (g_queryInfo.specifiedQueryInfo.concurrent <= 0) { - errorPrint("%s() LN%d, sepcified query sqlCount %"PRIu64".\n", + errorPrint("%s() LN%d, sepcified query sqlCount %d.\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount); exit(-1); @@ -6911,7 +6939,7 @@ static int subscribeTestProcess() { //==== create threads for super table query if (g_queryInfo.superQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, super table query sqlCount %"PRIu64".\n", + debugPrint("%s() LN%d, super table query sqlCount %d.\n", __func__, __LINE__, g_queryInfo.superQueryInfo.sqlCount); } else { From fba02adc526241ccad861186160acc80f47ab44a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 27 May 2021 01:29:01 +0800 Subject: [PATCH 20/80] [TD-4355] --- src/common/src/tglobal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index c3c159ee45..b0f83dc707 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -46,7 +46,7 @@ char tsEmail[TSDB_FQDN_LEN] = {0}; int32_t tsDnodeId = 0; // common -int32_t tsRpcTimer = 1000; +int32_t tsRpcTimer = 300; int32_t tsRpcMaxTime = 600; // seconds; int32_t tsMaxShellConns = 50000; int32_t tsMaxConnections = 5000; From 44b5fc4732f97867c910fae80bcc2616c49a6e73 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 27 May 2021 11:18:04 +0800 Subject: [PATCH 21/80] [td-4372]: fix the taosd server crash caused by dropping a child table, of which the indexed tag value is null. --- src/tsdb/src/tsdbMeta.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 3e6263b9d3..b074b04522 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -928,6 +928,11 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) { STColumn *pCol = schemaColAt(pSchema, DEFAULT_TAG_INDEX_COLUMN); char * key = tdGetKVRowValOfCol(pTable->tagVal, pCol->colId); + if (key == NULL) { + // treat the column as NULL if we cannot find it + key = getNullValue(pCol->type); + } + SArray *res = tSkipListGet(pSTable->pIndex, key); size_t size = taosArrayGetSize(res); From ab6e36e950c00c18158d38404c8f3a75ce9114e4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 27 May 2021 11:22:48 +0800 Subject: [PATCH 22/80] [td-4372] refactor. --- src/tsdb/src/tsdbMeta.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index b074b04522..0a4ea5e153 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -924,15 +924,7 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) { STable *pSTable = pTable->pSuper; ASSERT(pSTable != NULL); - STSchema *pSchema = tsdbGetTableTagSchema(pTable); - STColumn *pCol = schemaColAt(pSchema, DEFAULT_TAG_INDEX_COLUMN); - - char * key = tdGetKVRowValOfCol(pTable->tagVal, pCol->colId); - if (key == NULL) { - // treat the column as NULL if we cannot find it - key = getNullValue(pCol->type); - } - + char* key = getTagIndexKey(pTable); SArray *res = tSkipListGet(pSTable->pIndex, key); size_t size = taosArrayGetSize(res); From 10cfc73555ae896e6f779a7d9ad4fe3374884db6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 27 May 2021 13:49:32 +0800 Subject: [PATCH 23/80] [TD-2570] fix bug --- src/client/inc/tscUtil.h | 1 + src/client/src/tscSQLParser.c | 18 +++++++++++------- src/client/src/tscUtil.c | 3 +++ src/query/src/qExecutor.c | 10 ++++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 9220754330..73be7664c6 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -127,6 +127,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i */ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo); bool tscIsTWAQuery(SQueryInfo* pQueryInfo); +bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo); bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo); bool tscGroupbyColumn(SQueryInfo* pQueryInfo); bool tscIsTopBotQuery(SQueryInfo* pQueryInfo); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 777ae88860..314d9c4541 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -832,8 +832,8 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable) { const char* msg1 = "invalid column name"; - const char* msg3 = "not support state window on super table/tag column"; - const char* msg4 = "not support state_window with group by "; + const char* msg3 = "not support state_window with group by "; + const char* msg4 = "function not support for super table query"; SStrToken *col = &(pSqlNode->windowstateVal.col) ; if (col->z == NULL || col->n <= 0) { @@ -844,13 +844,13 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); } if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } pQueryInfo->groupbyExpr.numOfGroupCols = 1; //TODO(dengyihao): check tag column if (isStable) { - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); } SColumnIndex index = COLUMN_INDEX_INITIALIZER; @@ -2938,6 +2938,9 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) return true; } } + } else if (tscIsSessionWindowQuery(pQueryInfo)) { + invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); + return true; } return false; @@ -7373,6 +7376,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, int32_t index) { * transfer sql functions that need secondary merge into another format * in dealing with super table queries such as: count/first/last */ + if (validateSessionNode(pCmd, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_SQL; + } + if (isSTable) { tscTansformFuncForSTableQuery(pQueryInfo); @@ -7381,9 +7388,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, int32_t index) { } } - if (validateSessionNode(pCmd, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_SQL; - } // no result due to invalid query time range if (pQueryInfo->window.skey > pQueryInfo->window.ekey) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index d64a3de930..902d8bef5f 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -356,6 +356,9 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) { return false; } +bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) { + return pQueryInfo->sessionWindow.gap > 0; +} bool tscNeedReverseScan(SQueryInfo* pQueryInfo) { size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index f9398c6dd4..ee40290078 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1333,7 +1333,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf pInfo->start = j; } else if (tsList[j] - pInfo->prevTs <= gap) { pInfo->curWindow.ekey = tsList[j]; - pInfo->prevTs = tsList[j]; + //pInfo->prevTs = tsList[j]; pInfo->numOfRows += 1; if (j == 0 && pInfo->start != 0) { pInfo->numOfRows = 1; @@ -1342,6 +1342,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf } else { // start a new session window SResultRow* pResult = NULL; + pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -1362,6 +1363,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf SResultRow* pResult = NULL; + pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -2063,6 +2065,8 @@ static bool onlyFirstQuery(SQueryAttr *pQueryAttr) { return onlyOneQueryType(pQu static bool onlyLastQuery(SQueryAttr *pQueryAttr) { return onlyOneQueryType(pQueryAttr, TSDB_FUNC_LAST, TSDB_FUNC_LAST_DST); } +static bool notContainSessionOrStateWindow(SQueryAttr *pQueryAttr) { return !(pQueryAttr->sw.gap > 0 || pQueryAttr->stateWindow); } + static int32_t updateBlockLoadStatus(SQueryAttr *pQuery, int32_t status) { bool hasFirstLastFunc = false; bool hasOtherFunc = false; @@ -2166,7 +2170,7 @@ static void changeExecuteScanOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bo } pQueryAttr->order.order = TSDB_ORDER_ASC; - } else if (onlyLastQuery(pQueryAttr)) { + } else if (onlyLastQuery(pQueryAttr) && notContainSessionOrStateWindow(pQueryAttr)) { if (QUERY_IS_ASC_QUERY(pQueryAttr)) { qDebug(msg, pQInfo, "only-last", pQueryAttr->order.order, TSDB_ORDER_DESC, pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); @@ -5194,6 +5198,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) { SSWindowOperatorInfo* pWindowInfo = pOperator->info; SOptrBasicInfo* pBInfo = &pWindowInfo->binfo; + SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pBInfo->pRes); @@ -5206,6 +5211,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) { } SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + //pQueryAttr->order.order = TSDB_ORDER_ASC; int32_t order = pQueryAttr->order.order; STimeWindow win = pQueryAttr->window; From c40fc27343c5461b2c8de44d1bcf15b422341bba Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 27 May 2021 14:46:15 +0800 Subject: [PATCH 24/80] [TD-3279]: memory link while perform delete action --- src/connector/go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connector/go b/src/connector/go index 8ce6d86558..7a26c432f8 160000 --- a/src/connector/go +++ b/src/connector/go @@ -1 +1 @@ -Subproject commit 8ce6d86558afc8c0b50c10f990fd2b4270cf06fc +Subproject commit 7a26c432f8b4203e42344ff3290b9b9b01b983d5 From 9b385052e4455329343d5358ed231e98e4b0c111 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 27 May 2021 14:46:24 +0800 Subject: [PATCH 25/80] [TD-3279]: memory link while perform delete action --- src/inc/taoserror.h | 2 +- src/mnode/src/mnodeSdb.c | 19 +++++++++---------- src/util/src/terror.c | 1 + 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index b3e5b59627..bfeb53513b 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -215,11 +215,11 @@ int32_t* taosGetErrno(); #define TSDB_CODE_VND_IS_FLOWCTRL TAOS_DEF_ERROR_CODE(0, 0x050C) //"Database memory is full for waiting commit") #define TSDB_CODE_VND_IS_DROPPING TAOS_DEF_ERROR_CODE(0, 0x050D) //"Database is dropping") #define TSDB_CODE_VND_IS_BALANCING TAOS_DEF_ERROR_CODE(0, 0x050E) //"Database is balancing") +#define TSDB_CODE_VND_IS_CLOSING TAOS_DEF_ERROR_CODE(0, 0x0510) //"Database is closing") #define TSDB_CODE_VND_NOT_SYNCED TAOS_DEF_ERROR_CODE(0, 0x0511) //"Database suspended") #define TSDB_CODE_VND_NO_WRITE_AUTH TAOS_DEF_ERROR_CODE(0, 0x0512) //"Database write operation denied") #define TSDB_CODE_VND_IS_SYNCING TAOS_DEF_ERROR_CODE(0, 0x0513) //"Database is syncing") #define TSDB_CODE_VND_INVALID_TSDB_STATE TAOS_DEF_ERROR_CODE(0, 0x0514) //"Invalid tsdb state") -#define TSDB_CODE_VND_IS_CLOSING TAOS_DEF_ERROR_CODE(0, 0x0515) //"Database is closing") // tsdb #define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600) //"Invalid table ID") diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index cc088e3409..a65e29f1ee 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -649,8 +649,6 @@ static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void * dnodeReportStep("mnode-sdb", stepDesc, 0); } - if (qtype == TAOS_QTYPE_QUERY) return sdbPerformDeleteAction(pHead, pTable); - pthread_mutex_lock(&tsSdbMgmt.mutex); if (pHead->version == 0) { @@ -712,13 +710,11 @@ static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void * if (action == SDB_ACTION_INSERT) { return sdbPerformInsertAction(pHead, pTable); } else if (action == SDB_ACTION_DELETE) { - //if (qtype == TAOS_QTYPE_FWD) { - // Drop database/stable may take a long time and cause a timeout, so we confirm first then reput it into queue - // sdbWriteFwdToQueue(1, hparam, TAOS_QTYPE_QUERY, unused); - // return TSDB_CODE_SUCCESS; - //} else { - return sdbPerformDeleteAction(pHead, pTable); - //} + if (qtype == TAOS_QTYPE_FWD) { + // Drop database/stable may take a long time and cause a timeout, so we confirm first + syncConfirmForward(tsSdbMgmt.sync, pHead->version, TSDB_CODE_SUCCESS, false); + } + return sdbPerformDeleteAction(pHead, pTable); } else if (action == SDB_ACTION_UPDATE) { return sdbPerformUpdateAction(pHead, pTable); } else { @@ -1125,7 +1121,10 @@ static void *sdbWorkerFp(void *pWorker) { sdbConfirmForward(1, pRow, pRow->code); } else { if (qtype == TAOS_QTYPE_FWD) { - syncConfirmForward(tsSdbMgmt.sync, pRow->pHead.version, pRow->code, false); + int32_t action = pRow->pHead.msgType % 10; + if (action != SDB_ACTION_DELETE) { + syncConfirmForward(tsSdbMgmt.sync, pRow->pHead.version, pRow->code, false); + } } sdbFreeFromQueue(pRow); } diff --git a/src/util/src/terror.c b/src/util/src/terror.c index fc24b28dc3..9594022d3a 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -227,6 +227,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_FULL, "Database memory is fu TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_FLOWCTRL, "Database memory is full for waiting commit") TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_DROPPING, "Database is dropping") TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_BALANCING, "Database is balancing") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_CLOSING, "Database is closing") TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_SYNCED, "Database suspended") TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, "Database write operation denied") TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_SYNCING, "Database is syncing") From 34d6383a3c2f51102bed107cfd07cfcfa6f43e3c Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Thu, 27 May 2021 15:58:59 +0800 Subject: [PATCH 26/80] [TD-4122]: add test case --- tests/pytest/fulltest.sh | 2 +- tests/pytest/table/tablename-boundary.py | 62 ++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index d8e2a31e70..f120bba536 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -31,7 +31,7 @@ python3 ./test.py -f table/column_name.py python3 ./test.py -f table/column_num.py python3 ./test.py -f table/db_table.py python3 ./test.py -f table/create_sensitive.py -#python3 ./test.py -f table/tablename-boundary.py +python3 ./test.py -f table/tablename-boundary.py python3 ./test.py -f table/max_table_length.py python3 ./test.py -f table/alter_column.py python3 ./test.py -f table/boundary.py diff --git a/tests/pytest/table/tablename-boundary.py b/tests/pytest/table/tablename-boundary.py index 0755e75355..8766a9d4a9 100644 --- a/tests/pytest/table/tablename-boundary.py +++ b/tests/pytest/table/tablename-boundary.py @@ -14,6 +14,13 @@ class TDTestCase: tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) + self.ts = 1622100000000 + + def get_random_string(self, length): + letters = string.ascii_lowercase + result_str = ''.join(random.choice(letters) for i in range(length)) + return result_str + def run(self): tdSql.prepare() @@ -24,19 +31,64 @@ class TDTestCase: shell=True)) - 1 tdLog.info("table name max length is %d" % tableNameMaxLen) chars = string.ascii_uppercase + string.ascii_lowercase - tb_name = ''.join(random.choices(chars, k=tableNameMaxLen)) + tb_name = ''.join(random.choices(chars, k=tableNameMaxLen + 1)) tdLog.info('tb_name length %d' % len(tb_name)) tdLog.info('create table %s (ts timestamp, value int)' % tb_name) - tdSql.error( - 'create table %s (ts timestamp, speed binary(4089))' % - tb_name) + tdSql.error('create table %s (ts timestamp, speed binary(4089))' % tb_name) - tb_name = ''.join(random.choices(chars, k=191)) + tb_name = ''.join(random.choices(chars, k=tableNameMaxLen)) tdLog.info('tb_name length %d' % len(tb_name)) tdLog.info('create table %s (ts timestamp, value int)' % tb_name) tdSql.execute( 'create table %s (ts timestamp, speed binary(4089))' % tb_name) + + db_name = self.get_random_string(33) + tdSql.error("create database %s" % db_name) + + db_name = self.get_random_string(32) + tdSql.execute("create database %s" % db_name) + tdSql.execute("use %s" % db_name) + + tb_name = self.get_random_string(193) + tdSql.error("create table %s(ts timestamp, val int)" % tb_name) + + tb_name = self.get_random_string(192) + tdSql.execute("create table %s.%s(ts timestamp, val int)" % (db_name, tb_name)) + tdSql.query("show %s.tables" % db_name) + tdSql.checkRows(1) + tdSql.checkData(0, 0, tb_name) + + tdSql.execute("insert into %s.%s values(now, 1)" % (db_name, tb_name)) + tdSql.query("select * from %s.%s" %(db_name, tb_name)) + tdSql.checkRows(1) + + db_name = self.get_random_string(32) + tdSql.execute("create database %s update 1" % db_name) + + stb_name = self.get_random_string(192) + tdSql.execute("create table %s.%s(ts timestamp, val int) tags(id int)" % (db_name, stb_name)) + tb_name1 = self.get_random_string(192) + tdSql.execute("insert into %s.%s using %s.%s tags(1) values(%d, 1)(%d, 2)(%d, 3)" % (db_name, tb_name1, db_name, stb_name, self.ts, self.ts + 1, self.ts + 2)) + tb_name2 = self.get_random_string(192) + tdSql.execute("insert into %s.%s using %s.%s tags(2) values(%d, 1)(%d, 2)(%d, 3)" % (db_name, tb_name2, db_name, stb_name, self.ts, self.ts + 1, self.ts + 2)) + + tdSql.query("show %s.tables" % db_name) + tdSql.checkRows(2) + tdSql.checkData(0, 0, tb_name1) + tdSql.checkData(1, 0, tb_name2) + + tdSql.query("select * from %s.%s" % (db_name, stb_name)) + tdSql.checkRows(6) + + tdSql.execute("insert into %s.%s using %s.%s tags(1) values(%d, null)" % (db_name, tb_name1, db_name, stb_name, self.ts)) + + tdSql.query("select * from %s.%s" % (db_name, stb_name)) + tdSql.checkRows(6) + + + + def stop(self): tdSql.close() From 998680015d74f41377bc767c4343bc9565a357e3 Mon Sep 17 00:00:00 2001 From: Huo Linhe Date: Thu, 27 May 2021 17:44:57 +0800 Subject: [PATCH 27/80] [TD-4370]: squashed commit of python connector changes in develop (#6246) commit 0c81e3c0ba89c86f6d17d51d5056146e177cace5 Author: Huo Linhe Date: Fri May 14 10:27:13 2021 +0800 [TD-4160]: remove python connector soft links, fix tests and documents commit f439fce413423e7d7c97eef180c93d63dedab32e Author: Huo Linhe Date: Wed May 12 18:50:53 2021 +0800 [TD-182]: bump python connector version to v2.0.10 (#6091) Also fix url error in setup.py commit 4ae55d494a262e482f6b34e8bf193cc6af62a886 Author: Huo Linhe Date: Wed May 12 09:49:26 2021 +0800 [TD-4370]: merge python connector changes to master Inludes: [TD-182]: use single repo for python connector (#6036) * [TD-182]: use single repo for python connector Remove code for each platform and build up one single python code base for windows/osx/linux platforms and python2/python3 runtime. * [TD-182]: remove redundant code in python connector * [TD-4149] : fix python connection config error --- Jenkinsfile | 2 +- documentation20/cn/08.connector/docs.md | 17 +- packaging/tools/makeclient_power.sh | 15 +- packaging/tools/makepkg_power.sh | 15 +- src/connector/python/.gitignore | 154 +++++ .../python/{linux/python2 => }/LICENSE | 0 src/connector/python/README.md | 17 + src/connector/python/examples/demo.py | 12 + src/connector/python/linux/python2/README.md | 1 - src/connector/python/linux/python2/setup.py | 20 - .../python/linux/python2/taos/cinterface.py | 648 ------------------ .../python/linux/python2/taos/cursor.py | 278 -------- src/connector/python/linux/python3/LICENSE | 12 - src/connector/python/linux/python3/README.md | 1 - src/connector/python/linux/python3/setup.py | 20 - .../python/linux/python3/taos/__init__.py | 25 - .../python/linux/python3/taos/connection.py | 95 --- .../python/linux/python3/taos/constants.py | 42 -- .../python/linux/python3/taos/dbapi.py | 44 -- .../python/linux/python3/taos/error.py | 66 -- .../python/linux/python3/taos/subscription.py | 57 -- src/connector/python/osx/python3/LICENSE | 12 - src/connector/python/osx/python3/README.md | 1 - src/connector/python/osx/python3/setup.py | 20 - .../python/osx/python3/taos/__init__.py | 24 - .../python/osx/python3/taos/cinterface.py | 648 ------------------ .../python/osx/python3/taos/connection.py | 95 --- .../python/osx/python3/taos/constants.py | 42 -- .../python/osx/python3/taos/cursor.py | 280 -------- .../python/osx/python3/taos/dbapi.py | 44 -- .../python/osx/python3/taos/error.py | 66 -- .../python/osx/python3/taos/subscription.py | 57 -- src/connector/python/setup.py | 34 + .../{linux/python2 => }/taos/__init__.py | 0 .../{linux/python3 => }/taos/cinterface.py | 253 +++---- .../{linux/python2 => }/taos/connection.py | 0 .../{linux/python2 => }/taos/constants.py | 0 .../python/{linux/python3 => }/taos/cursor.py | 6 + .../python/{linux/python2 => }/taos/dbapi.py | 0 .../python/{linux/python2 => }/taos/error.py | 0 .../{linux/python2 => }/taos/subscription.py | 0 src/connector/python/windows/python2/LICENSE | 12 - .../python/windows/python2/README.md | 1 - src/connector/python/windows/python2/setup.py | 20 - .../python/windows/python2/taos/__init__.py | 24 - .../python/windows/python2/taos/cinterface.py | 648 ------------------ .../python/windows/python2/taos/connection.py | 96 --- .../python/windows/python2/taos/constants.py | 42 -- .../python/windows/python2/taos/cursor.py | 220 ------ .../python/windows/python2/taos/dbapi.py | 44 -- .../python/windows/python2/taos/error.py | 66 -- .../windows/python2/taos/subscription.py | 57 -- src/connector/python/windows/python3/LICENSE | 12 - .../python/windows/python3/README.md | 1 - src/connector/python/windows/python3/setup.py | 20 - .../python/windows/python3/taos/__init__.py | 24 - .../python/windows/python3/taos/cinterface.py | 648 ------------------ .../python/windows/python3/taos/connection.py | 96 --- .../python/windows/python3/taos/constants.py | 42 -- .../python/windows/python3/taos/cursor.py | 220 ------ .../python/windows/python3/taos/dbapi.py | 44 -- .../python/windows/python3/taos/error.py | 66 -- .../windows/python3/taos/subscription.py | 57 -- ...o-Run-Test-And-How-To-Add-New-Test-Case.md | 4 +- tests/Jenkinsfile | 2 +- tests/pytest/concurrent_inquiry.sh | 2 +- tests/pytest/crash_gen.sh | 2 +- tests/pytest/hivemq-extension-test.py | 2 +- tests/pytest/perf_gen.sh | 2 +- tests/pytest/simpletest_no_sudo.sh | 2 +- tests/pytest/test.py | 2 +- tests/pytest/test.sh | 2 +- tests/pytest/testCompress.py | 2 +- tests/pytest/testMinTablesPerVnode.py | 2 +- tests/pytest/testNoCompress.py | 2 +- 75 files changed, 341 insertions(+), 5268 deletions(-) create mode 100644 src/connector/python/.gitignore rename src/connector/python/{linux/python2 => }/LICENSE (100%) create mode 100644 src/connector/python/README.md create mode 100644 src/connector/python/examples/demo.py delete mode 100644 src/connector/python/linux/python2/README.md delete mode 100644 src/connector/python/linux/python2/setup.py delete mode 100644 src/connector/python/linux/python2/taos/cinterface.py delete mode 100644 src/connector/python/linux/python2/taos/cursor.py delete mode 100644 src/connector/python/linux/python3/LICENSE delete mode 100644 src/connector/python/linux/python3/README.md delete mode 100644 src/connector/python/linux/python3/setup.py delete mode 100644 src/connector/python/linux/python3/taos/__init__.py delete mode 100644 src/connector/python/linux/python3/taos/connection.py delete mode 100644 src/connector/python/linux/python3/taos/constants.py delete mode 100644 src/connector/python/linux/python3/taos/dbapi.py delete mode 100644 src/connector/python/linux/python3/taos/error.py delete mode 100644 src/connector/python/linux/python3/taos/subscription.py delete mode 100644 src/connector/python/osx/python3/LICENSE delete mode 100644 src/connector/python/osx/python3/README.md delete mode 100644 src/connector/python/osx/python3/setup.py delete mode 100644 src/connector/python/osx/python3/taos/__init__.py delete mode 100644 src/connector/python/osx/python3/taos/cinterface.py delete mode 100644 src/connector/python/osx/python3/taos/connection.py delete mode 100644 src/connector/python/osx/python3/taos/constants.py delete mode 100644 src/connector/python/osx/python3/taos/cursor.py delete mode 100644 src/connector/python/osx/python3/taos/dbapi.py delete mode 100644 src/connector/python/osx/python3/taos/error.py delete mode 100644 src/connector/python/osx/python3/taos/subscription.py create mode 100644 src/connector/python/setup.py rename src/connector/python/{linux/python2 => }/taos/__init__.py (100%) rename src/connector/python/{linux/python3 => }/taos/cinterface.py (70%) rename src/connector/python/{linux/python2 => }/taos/connection.py (100%) rename src/connector/python/{linux/python2 => }/taos/constants.py (100%) rename src/connector/python/{linux/python3 => }/taos/cursor.py (98%) rename src/connector/python/{linux/python2 => }/taos/dbapi.py (100%) rename src/connector/python/{linux/python2 => }/taos/error.py (100%) rename src/connector/python/{linux/python2 => }/taos/subscription.py (100%) delete mode 100644 src/connector/python/windows/python2/LICENSE delete mode 100644 src/connector/python/windows/python2/README.md delete mode 100644 src/connector/python/windows/python2/setup.py delete mode 100644 src/connector/python/windows/python2/taos/__init__.py delete mode 100644 src/connector/python/windows/python2/taos/cinterface.py delete mode 100644 src/connector/python/windows/python2/taos/connection.py delete mode 100644 src/connector/python/windows/python2/taos/constants.py delete mode 100644 src/connector/python/windows/python2/taos/cursor.py delete mode 100644 src/connector/python/windows/python2/taos/dbapi.py delete mode 100644 src/connector/python/windows/python2/taos/error.py delete mode 100644 src/connector/python/windows/python2/taos/subscription.py delete mode 100644 src/connector/python/windows/python3/LICENSE delete mode 100644 src/connector/python/windows/python3/README.md delete mode 100644 src/connector/python/windows/python3/setup.py delete mode 100644 src/connector/python/windows/python3/taos/__init__.py delete mode 100644 src/connector/python/windows/python3/taos/cinterface.py delete mode 100644 src/connector/python/windows/python3/taos/connection.py delete mode 100644 src/connector/python/windows/python3/taos/constants.py delete mode 100644 src/connector/python/windows/python3/taos/cursor.py delete mode 100644 src/connector/python/windows/python3/taos/dbapi.py delete mode 100644 src/connector/python/windows/python3/taos/error.py delete mode 100644 src/connector/python/windows/python3/taos/subscription.py diff --git a/Jenkinsfile b/Jenkinsfile index 33ce784bce..b48dca0241 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -94,7 +94,7 @@ def pre_test(){ make > /dev/null make install > /dev/null cd ${WKC}/tests - pip3 install ${WKC}/src/connector/python/linux/python3/ + pip3 install ${WKC}/src/connector/python ''' return 1 } diff --git a/documentation20/cn/08.connector/docs.md b/documentation20/cn/08.connector/docs.md index 6811315e7d..5a6c26587a 100644 --- a/documentation20/cn/08.connector/docs.md +++ b/documentation20/cn/08.connector/docs.md @@ -399,27 +399,22 @@ Python连接器的使用参见[视频教程](https://www.taosdata.com/blog/2020/ #### Linux -用户可以在源代码的src/connector/python(或者tar.gz的/connector/python)文件夹下找到python2和python3的connector安装包。用户可以通过pip命令安装: +用户可以在源代码的src/connector/python(或者tar.gz的/connector/python)文件夹下找到connector安装包。用户可以通过pip命令安装: -​ `pip install src/connector/python/linux/python2/` +​ `pip install src/connector/python/` 或 -​ `pip3 install src/connector/python/linux/python3/` +​ `pip3 install src/connector/python/` #### Windows 在已安装Windows TDengine 客户端的情况下, 将文件"C:\TDengine\driver\taos.dll" 拷贝到 "C:\windows\system32" 目录下, 然后进入Windwos cmd 命令行界面 ```cmd -cd C:\TDengine\connector\python\windows -python -m pip install python2\ -``` -或 -```cmd -cd C:\TDengine\connector\python\windows -python -m pip install python3\ +cd C:\TDengine\connector\python +python -m pip install . ``` -* 如果机器上没有pip命令,用户可将src/connector/python/python3或src/connector/python/python2下的taos文件夹拷贝到应用程序的目录使用。 +* 如果机器上没有pip命令,用户可将src/connector/python下的taos文件夹拷贝到应用程序的目录使用。 对于windows 客户端,安装TDengine windows 客户端后,将C:\TDengine\driver\taos.dll拷贝到C:\windows\system32目录下即可。 ### 使用 diff --git a/packaging/tools/makeclient_power.sh b/packaging/tools/makeclient_power.sh index b5649e019e..8241319e4f 100755 --- a/packaging/tools/makeclient_power.sh +++ b/packaging/tools/makeclient_power.sh @@ -156,20 +156,11 @@ if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then fi cp -r ${connector_dir}/python ${install_dir}/connector - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python2/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python3/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python2/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python3/taos/cinterface.py + sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python2/taos/subscription.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python3/taos/subscription.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python2/taos/subscription.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python3/taos/subscription.py + sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/subscription.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python2/taos/connection.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python3/taos/connection.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python2/taos/connection.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python3/taos/connection.py + sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/connection.py fi # Copy release note # cp ${script_dir}/release_note ${install_dir} diff --git a/packaging/tools/makepkg_power.sh b/packaging/tools/makepkg_power.sh index 1e43f775e2..633a135c14 100755 --- a/packaging/tools/makepkg_power.sh +++ b/packaging/tools/makepkg_power.sh @@ -179,20 +179,11 @@ if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then fi cp -r ${connector_dir}/python ${install_dir}/connector/ - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python2/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python3/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python2/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python3/taos/cinterface.py + sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/cinterface.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python2/taos/subscription.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python3/taos/subscription.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python2/taos/subscription.py - sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python3/taos/subscription.py + sed -i '/password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/subscription.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python2/taos/connection.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/linux/python3/taos/connection.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python2/taos/connection.py - sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/windows/python3/taos/connection.py + sed -i '/self._password/ {s/taosdata/powerdb/g}' ${install_dir}/connector/python/taos/connection.py fi # Copy release note # cp ${script_dir}/release_note ${install_dir} diff --git a/src/connector/python/.gitignore b/src/connector/python/.gitignore new file mode 100644 index 0000000000..228a0b4530 --- /dev/null +++ b/src/connector/python/.gitignore @@ -0,0 +1,154 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +# .env +.env/ +.venv/ +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# operating system-related files +# file properties cache/storage on macOS +*.DS_Store +# thumbnail cache on Windows +Thumbs.db + +# profiling data +.prof + + +# End of https://www.toptal.com/developers/gitignore/api/python diff --git a/src/connector/python/linux/python2/LICENSE b/src/connector/python/LICENSE similarity index 100% rename from src/connector/python/linux/python2/LICENSE rename to src/connector/python/LICENSE diff --git a/src/connector/python/README.md b/src/connector/python/README.md new file mode 100644 index 0000000000..9151e9b8f0 --- /dev/null +++ b/src/connector/python/README.md @@ -0,0 +1,17 @@ +# TDengine Connector for Python + +[TDengine] connector for Python enables python programs to access TDengine, using an API which is compliant with the Python DB API 2.0 (PEP-249). It uses TDengine C client library for client server communications. + +## Install + +```sh +pip install git+https://github.com/taosdata/TDengine-connector-python +``` + +## Source Code + +[TDengine] connector for Python source code is hosted on [GitHub](https://github.com/taosdata/TDengine-connector-python). + +## License - AGPL + +Keep same with [TDengine](https://github.com/taosdata/TDengine). diff --git a/src/connector/python/examples/demo.py b/src/connector/python/examples/demo.py new file mode 100644 index 0000000000..6c7c03f3e2 --- /dev/null +++ b/src/connector/python/examples/demo.py @@ -0,0 +1,12 @@ +import taos + +conn = taos.connect(host='127.0.0.1', + user='root', + passworkd='taodata', + database='log') +cursor = conn.cursor() + +sql = "select * from log.log limit 10" +cursor.execute(sql) +for row in cursor: + print(row) diff --git a/src/connector/python/linux/python2/README.md b/src/connector/python/linux/python2/README.md deleted file mode 100644 index 70db6bba13..0000000000 --- a/src/connector/python/linux/python2/README.md +++ /dev/null @@ -1 +0,0 @@ -# TDengine python client interface \ No newline at end of file diff --git a/src/connector/python/linux/python2/setup.py b/src/connector/python/linux/python2/setup.py deleted file mode 100644 index 3f065e0348..0000000000 --- a/src/connector/python/linux/python2/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="taos", - version="2.0.9", - author="Taosdata Inc.", - author_email="support@taosdata.com", - description="TDengine python client package", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/pypa/sampleproject", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 2", - "Operating System :: Linux", - ], -) diff --git a/src/connector/python/linux/python2/taos/cinterface.py b/src/connector/python/linux/python2/taos/cinterface.py deleted file mode 100644 index 3d0ecd2901..0000000000 --- a/src/connector/python/linux/python2/taos/cinterface.py +++ /dev/null @@ -1,648 +0,0 @@ -import ctypes -from .constants import FieldType -from .error import * -import math -import datetime - - -def _convert_millisecond_to_datetime(milli): - return datetime.datetime.fromtimestamp(milli / 1000.0) - - -def _convert_microsecond_to_datetime(micro): - return datetime.datetime.fromtimestamp(micro / 1000000.0) - - -def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - _timestamp_converter = _convert_millisecond_to_datetime - if micro: - _timestamp_converter = _convert_microsecond_to_datetime - - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - - -def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_byte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_bool))[ - :abs(num_of_rows)]] - - -def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - - -def _crow_tinyint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - - -def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - - -def _crow_smallint_unsigned_to_python( - data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - - -def _crow_int_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - - -def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - - -def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - - -def _crow_bigint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - - -def _crow_float_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C float row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - - -def _crow_double_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C double row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - - -def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - if num_of_rows > 0: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - else: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - - -def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - for i in range(abs(num_of_rows)): - try: - if num_of_rows >= 0: - tmpstr = ctypes.c_char_p(data) - res.append(tmpstr.value.decode()) - else: - res.append((ctypes.cast(data + nbytes * i, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - - return res - - -def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows > 0: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - return res - - -def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows >= 0: - for i in range(abs(num_of_rows)): - try: - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - res.append((ctypes.cast(data + nbytes * i + 2, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - return res - - -_CONVERT_FUNC = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -_CONVERT_FUNC_BLOCK = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python_block, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python_block, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -# Corresponding TAOS_FIELD structure in C - - -class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 65), - ('type', ctypes.c_char), - ('bytes', ctypes.c_short)] - -# C interface class - - -class CTaosInterface(object): - - libtaos = ctypes.CDLL('libtaos.so') - - libtaos.taos_fetch_fields.restype = ctypes.POINTER(TaosField) - libtaos.taos_init.restype = None - libtaos.taos_connect.restype = ctypes.c_void_p - #libtaos.taos_use_result.restype = ctypes.c_void_p - libtaos.taos_fetch_row.restype = ctypes.POINTER(ctypes.c_void_p) - libtaos.taos_errstr.restype = ctypes.c_char_p - libtaos.taos_subscribe.restype = ctypes.c_void_p - libtaos.taos_consume.restype = ctypes.c_void_p - libtaos.taos_fetch_lengths.restype = ctypes.c_void_p - libtaos.taos_free_result.restype = None - libtaos.taos_errno.restype = ctypes.c_int - libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) - - def __init__(self, config=None): - ''' - Function to initialize the class - @host : str, hostname to connect - @user : str, username to connect to server - @password : str, password to connect to server - @db : str, default db to use when log in - @config : str, config directory - - @rtype : None - ''' - if config is None: - self._config = ctypes.c_char_p(None) - else: - try: - self._config = ctypes.c_char_p(config.encode('utf-8')) - except AttributeError: - raise AttributeError("config is expected as a str") - - if config is not None: - CTaosInterface.libtaos.taos_options(3, self._config) - - CTaosInterface.libtaos.taos_init() - - @property - def config(self): - """ Get current config - """ - return self._config - - def connect( - self, - host=None, - user="root", - password="taosdata", - db=None, - port=0): - ''' - Function to connect to server - - @rtype: c_void_p, TDengine handle - ''' - # host - try: - _host = ctypes.c_char_p(host.encode( - "utf-8")) if host is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("host is expected as a str") - - # user - try: - _user = ctypes.c_char_p(user.encode("utf-8")) - except AttributeError: - raise AttributeError("user is expected as a str") - - # password - try: - _password = ctypes.c_char_p(password.encode("utf-8")) - except AttributeError: - raise AttributeError("password is expected as a str") - - # db - try: - _db = ctypes.c_char_p( - db.encode("utf-8")) if db is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("db is expected as a str") - - # port - try: - _port = ctypes.c_int(port) - except TypeError: - raise TypeError("port is expected as an int") - - connection = ctypes.c_void_p(CTaosInterface.libtaos.taos_connect( - _host, _user, _password, _db, _port)) - - if connection.value is None: - print('connect to TDengine failed') - raise ConnectionError("connect to TDengine failed") - # sys.exit(1) - # else: - # print('connect to TDengine success') - - return connection - - @staticmethod - def close(connection): - '''Close the TDengine handle - ''' - CTaosInterface.libtaos.taos_close(connection) - #print('connection is closed') - - @staticmethod - def query(connection, sql): - '''Run SQL - - @sql: str, sql string to run - - @rtype: 0 on success and -1 on failure - ''' - try: - return CTaosInterface.libtaos.taos_query( - connection, ctypes.c_char_p(sql.encode('utf-8'))) - except AttributeError: - raise AttributeError("sql is expected as a string") - # finally: - # CTaosInterface.libtaos.close(connection) - - @staticmethod - def affectedRows(result): - """The affected rows after runing query - """ - return CTaosInterface.libtaos.taos_affected_rows(result) - - @staticmethod - def subscribe(connection, restart, topic, sql, interval): - """Create a subscription - @restart boolean, - @sql string, sql statement for data query, must be a 'select' statement. - @topic string, name of this subscription - """ - return ctypes.c_void_p(CTaosInterface.libtaos.taos_subscribe( - connection, - 1 if restart else 0, - ctypes.c_char_p(topic.encode('utf-8')), - ctypes.c_char_p(sql.encode('utf-8')), - None, - None, - interval)) - - @staticmethod - def consume(sub): - """Consume data of a subscription - """ - result = ctypes.c_void_p(CTaosInterface.libtaos.taos_consume(sub)) - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.libtaos.taos_num_fields(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - return result, fields - - @staticmethod - def unsubscribe(sub, keepProgress): - """Cancel a subscription - """ - CTaosInterface.libtaos.taos_unsubscribe(sub, 1 if keepProgress else 0) - - @staticmethod - def useResult(result): - '''Use result after calling self.query - ''' - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.fieldsCount(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - - return fields - - @staticmethod - def fetchBlock(result, fields): - pblock = ctypes.c_void_p(0) - num_of_rows = CTaosInterface.libtaos.taos_fetch_block( - result, ctypes.byref(pblock)) - if num_of_rows == 0: - return None, 0 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC_BLOCK: - raise DatabaseError("Invalid data type returned from database") - blocks[i] = _CONVERT_FUNC_BLOCK[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - - return blocks, abs(num_of_rows) - - @staticmethod - def fetchRow(result, fields): - pblock = ctypes.c_void_p(0) - pblock = CTaosInterface.libtaos.taos_fetch_row(result) - if pblock: - num_of_rows = 1 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC: - raise DatabaseError( - "Invalid data type returned from database") - if data is None: - blocks[i] = [None] - else: - blocks[i] = _CONVERT_FUNC[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - else: - return None, 0 - return blocks, abs(num_of_rows) - - @staticmethod - def freeResult(result): - CTaosInterface.libtaos.taos_free_result(result) - result.value = None - - @staticmethod - def fieldsCount(result): - return CTaosInterface.libtaos.taos_field_count(result) - - @staticmethod - def fetchFields(result): - return CTaosInterface.libtaos.taos_fetch_fields(result) - - # @staticmethod - # def fetchRow(result, fields): - # l = [] - # row = CTaosInterface.libtaos.taos_fetch_row(result) - # if not row: - # return None - - # for i in range(len(fields)): - # l.append(CTaosInterface.getDataValue( - # row[i], fields[i]['type'], fields[i]['bytes'])) - - # return tuple(l) - - # @staticmethod - # def getDataValue(data, dtype, byte): - # ''' - # ''' - # if not data: - # return None - - # if (dtype == CTaosInterface.TSDB_DATA_TYPE_BOOL): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_bool))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TINYINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_byte))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_SMALLINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_short))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_double))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY): - # return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00') - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR): - # return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00') - - @staticmethod - def errno(result): - """Return the error number. - """ - return CTaosInterface.libtaos.taos_errno(result) - - @staticmethod - def errStr(result): - """Return the error styring - """ - return CTaosInterface.libtaos.taos_errstr(result).decode('utf-8') - - -if __name__ == '__main__': - cinter = CTaosInterface() - conn = cinter.connect() - result = cinter.query(conn, 'show databases') - - print('Query Affected rows: {}'.format(cinter.affectedRows(result))) - - fields = CTaosInterface.useResult(result) - - data, num_of_rows = CTaosInterface.fetchBlock(result, fields) - - print(data) - - cinter.freeResult(result) - cinter.close(conn) diff --git a/src/connector/python/linux/python2/taos/cursor.py b/src/connector/python/linux/python2/taos/cursor.py deleted file mode 100644 index 4c0456b503..0000000000 --- a/src/connector/python/linux/python2/taos/cursor.py +++ /dev/null @@ -1,278 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * -from .constants import FieldType - - -class TDengineCursor(object): - """Database cursor which is used to manage the context of a fetch operation. - - Attributes: - .description: Read-only attribute consists of 7-item sequences: - - > name (mondatory) - > type_code (mondatory) - > display_size - > internal_size - > precision - > scale - > null_ok - - This attribute will be None for operations that do not return rows or - if the cursor has not had an operation invoked via the .execute*() method yet. - - .rowcount:This read-only attribute specifies the number of rows that the last - .execute*() produced (for DQL statements like SELECT) or affected - """ - - def __init__(self, connection=None): - self._description = [] - self._rowcount = -1 - self._connection = None - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - self._logfile = "" - - if connection is not None: - self._connection = connection - - def __iter__(self): - return self - - def next(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetch iterator") - - if self._block_rows <= self._block_iter: - block, self._block_rows = CTaosInterface.fetchRow( - self._result, self._fields) - if self._block_rows == 0: - raise StopIteration - self._block = list(map(tuple, zip(*block))) - self._block_iter = 0 - - data = self._block[self._block_iter] - self._block_iter += 1 - - return data - - @property - def description(self): - """Return the description of the object. - """ - return self._description - - @property - def rowcount(self): - """Return the rowcount of the object - """ - return self._rowcount - - @property - def affected_rows(self): - """Return the affected_rows of the object - """ - return self._affected_rows - - def callproc(self, procname, *args): - """Call a stored database procedure with the given name. - - Void functionality since no stored procedures. - """ - pass - - def log(self, logfile): - self._logfile = logfile - - def close(self): - """Close the cursor. - """ - if self._connection is None: - return False - - self._reset_result() - self._connection = None - - return True - - def execute(self, operation, params=None): - """Prepare and execute a database operation (query or command). - """ - if not operation: - return None - - if not self._connection: - # TODO : change the exception raised here - raise ProgrammingError("Cursor is not connected") - - self._reset_result() - - stmt = operation - if params is not None: - pass - - # global querySeqNum - # querySeqNum += 1 - # localSeqNum = querySeqNum # avoid raice condition - # print(" >> Exec Query ({}): {}".format(localSeqNum, str(stmt))) - self._result = CTaosInterface.query(self._connection._conn, stmt) - # print(" << Query ({}) Exec Done".format(localSeqNum)) - if (self._logfile): - with open(self._logfile, "a") as logfile: - logfile.write("%s;\n" % operation) - - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno == 0: - if CTaosInterface.fieldsCount(self._result) == 0: - self._affected_rows += CTaosInterface.affectedRows( - self._result) - return CTaosInterface.affectedRows(self._result) - else: - self._fields = CTaosInterface.useResult( - self._result) - return self._handle_result() - else: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - - def executemany(self, operation, seq_of_parameters): - """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. - """ - pass - - def fetchone(self): - """Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. - """ - pass - - def fetchmany(self): - pass - - def istype(self, col, dataType): - if (dataType.upper() == "BOOL"): - if (self._description[col][1] == FieldType.C_BOOL): - return True - if (dataType.upper() == "TINYINT"): - if (self._description[col][1] == FieldType.C_TINYINT): - return True - if (dataType.upper() == "TINYINT UNSIGNED"): - if (self._description[col][1] == FieldType.C_TINYINT_UNSIGNED): - return True - if (dataType.upper() == "SMALLINT"): - if (self._description[col][1] == FieldType.C_SMALLINT): - return True - if (dataType.upper() == "SMALLINT UNSIGNED"): - if (self._description[col][1] == FieldType.C_SMALLINT_UNSIGNED): - return True - if (dataType.upper() == "INT"): - if (self._description[col][1] == FieldType.C_INT): - return True - if (dataType.upper() == "INT UNSIGNED"): - if (self._description[col][1] == FieldType.C_INT_UNSIGNED): - return True - if (dataType.upper() == "BIGINT"): - if (self._description[col][1] == FieldType.C_BIGINT): - return True - if (dataType.upper() == "BIGINT UNSIGNED"): - if (self._description[col][1] == FieldType.C_BIGINT_UNSIGNED): - return True - if (dataType.upper() == "FLOAT"): - if (self._description[col][1] == FieldType.C_FLOAT): - return True - if (dataType.upper() == "DOUBLE"): - if (self._description[col][1] == FieldType.C_DOUBLE): - return True - if (dataType.upper() == "BINARY"): - if (self._description[col][1] == FieldType.C_BINARY): - return True - if (dataType.upper() == "TIMESTAMP"): - if (self._description[col][1] == FieldType.C_TIMESTAMP): - return True - if (dataType.upper() == "NCHAR"): - if (self._description[col][1] == FieldType.C_NCHAR): - return True - - return False - - def fetchall_row(self): - """Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation. - """ - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchRow( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - return list(map(tuple, zip(*buffer))) - - def fetchall(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchBlock( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - return list(map(tuple, zip(*buffer))) - - def nextset(self): - """ - """ - pass - - def setinputsize(self, sizes): - pass - - def setutputsize(self, size, column=None): - pass - - def _reset_result(self): - """Reset the result to unused version. - """ - self._description = [] - self._rowcount = -1 - if self._result is not None: - CTaosInterface.freeResult(self._result) - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - - def _handle_result(self): - """Handle the return result from query. - """ - self._description = [] - for ele in self._fields: - self._description.append( - (ele['name'], ele['type'], None, None, None, None, False)) - - return self._result diff --git a/src/connector/python/linux/python3/LICENSE b/src/connector/python/linux/python3/LICENSE deleted file mode 100644 index 79a9d73086..0000000000 --- a/src/connector/python/linux/python3/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ - Copyright (c) 2019 TAOS Data, Inc. - -This program is free software: you can use, redistribute, and/or modify -it under the terms of the GNU Affero General Public License, version 3 -or later ("AGPL"), as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . diff --git a/src/connector/python/linux/python3/README.md b/src/connector/python/linux/python3/README.md deleted file mode 100644 index 70db6bba13..0000000000 --- a/src/connector/python/linux/python3/README.md +++ /dev/null @@ -1 +0,0 @@ -# TDengine python client interface \ No newline at end of file diff --git a/src/connector/python/linux/python3/setup.py b/src/connector/python/linux/python3/setup.py deleted file mode 100644 index 0bd7d51b6a..0000000000 --- a/src/connector/python/linux/python3/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="taos", - version="2.0.9", - author="Taosdata Inc.", - author_email="support@taosdata.com", - description="TDengine python client package", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/pypa/sampleproject", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: Linux", - ], -) diff --git a/src/connector/python/linux/python3/taos/__init__.py b/src/connector/python/linux/python3/taos/__init__.py deleted file mode 100644 index 1b086f36ec..0000000000 --- a/src/connector/python/linux/python3/taos/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ - -from .connection import TDengineConnection -from .cursor import TDengineCursor -from .error import Error - -# Globals -threadsafety = 0 -paramstyle = 'pyformat' - -__all__ = ['connection', 'cursor'] - - -def connect(*args, **kwargs): - """ Function to return a TDengine connector object - - Current supporting keyword parameters: - @dsn: Data source name as string - @user: Username as string(optional) - @password: Password as string(optional) - @host: Hostname(optional) - @database: Database name(optional) - - @rtype: TDengineConnector - """ - return TDengineConnection(*args, **kwargs) diff --git a/src/connector/python/linux/python3/taos/connection.py b/src/connector/python/linux/python3/taos/connection.py deleted file mode 100644 index f6c395342c..0000000000 --- a/src/connector/python/linux/python3/taos/connection.py +++ /dev/null @@ -1,95 +0,0 @@ -from .cursor import TDengineCursor -from .subscription import TDengineSubscription -from .cinterface import CTaosInterface - - -class TDengineConnection(object): - """ TDengine connection object - """ - - def __init__(self, *args, **kwargs): - self._conn = None - self._host = None - self._user = "root" - self._password = "taosdata" - self._database = None - self._port = 0 - self._config = None - self._chandle = None - - self.config(**kwargs) - - def config(self, **kwargs): - # host - if 'host' in kwargs: - self._host = kwargs['host'] - - # user - if 'user' in kwargs: - self._user = kwargs['user'] - - # password - if 'password' in kwargs: - self._password = kwargs['password'] - - # database - if 'database' in kwargs: - self._database = kwargs['database'] - - # port - if 'port' in kwargs: - self._port = kwargs['port'] - - # config - if 'config' in kwargs: - self._config = kwargs['config'] - - self._chandle = CTaosInterface(self._config) - self._conn = self._chandle.connect( - self._host, - self._user, - self._password, - self._database, - self._port) - - def close(self): - """Close current connection. - """ - return CTaosInterface.close(self._conn) - - def subscribe(self, restart, topic, sql, interval): - """Create a subscription. - """ - if self._conn is None: - return None - sub = CTaosInterface.subscribe( - self._conn, restart, topic, sql, interval) - return TDengineSubscription(sub) - - def cursor(self): - """Return a new Cursor object using the connection. - """ - return TDengineCursor(self) - - def commit(self): - """Commit any pending transaction to the database. - - Since TDengine do not support transactions, the implement is void functionality. - """ - pass - - def rollback(self): - """Void functionality - """ - pass - - def clear_result_set(self): - """Clear unused result set on this connection. - """ - pass - - -if __name__ == "__main__": - conn = TDengineConnection(host='192.168.1.107') - conn.close() - print("Hello world") diff --git a/src/connector/python/linux/python3/taos/constants.py b/src/connector/python/linux/python3/taos/constants.py deleted file mode 100644 index 93466f5184..0000000000 --- a/src/connector/python/linux/python3/taos/constants.py +++ /dev/null @@ -1,42 +0,0 @@ -"""Constants in TDengine python -""" - -from .dbapi import * - - -class FieldType(object): - """TDengine Field Types - """ - # type_code - C_NULL = 0 - C_BOOL = 1 - C_TINYINT = 2 - C_SMALLINT = 3 - C_INT = 4 - C_BIGINT = 5 - C_FLOAT = 6 - C_DOUBLE = 7 - C_BINARY = 8 - C_TIMESTAMP = 9 - C_NCHAR = 10 - C_TINYINT_UNSIGNED = 11 - C_SMALLINT_UNSIGNED = 12 - C_INT_UNSIGNED = 13 - C_BIGINT_UNSIGNED = 14 - # NULL value definition - # NOTE: These values should change according to C definition in tsdb.h - C_BOOL_NULL = 0x02 - C_TINYINT_NULL = -128 - C_TINYINT_UNSIGNED_NULL = 255 - C_SMALLINT_NULL = -32768 - C_SMALLINT_UNSIGNED_NULL = 65535 - C_INT_NULL = -2147483648 - C_INT_UNSIGNED_NULL = 4294967295 - C_BIGINT_NULL = -9223372036854775808 - C_BIGINT_UNSIGNED_NULL = 18446744073709551615 - C_FLOAT_NULL = float('nan') - C_DOUBLE_NULL = float('nan') - C_BINARY_NULL = bytearray([int('0xff', 16)]) - # Timestamp precision definition - C_TIMESTAMP_MILLI = 0 - C_TIMESTAMP_MICRO = 1 diff --git a/src/connector/python/linux/python3/taos/dbapi.py b/src/connector/python/linux/python3/taos/dbapi.py deleted file mode 100644 index 594681ada9..0000000000 --- a/src/connector/python/linux/python3/taos/dbapi.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Type Objects and Constructors. -""" - -import time -import datetime - - -class DBAPITypeObject(object): - def __init__(self, *values): - self.values = values - - def __com__(self, other): - if other in self.values: - return 0 - if other < self.values: - return 1 - else: - return -1 - - -Date = datetime.date -Time = datetime.time -Timestamp = datetime.datetime - - -def DataFromTicks(ticks): - return Date(*time.localtime(ticks)[:3]) - - -def TimeFromTicks(ticks): - return Time(*time.localtime(ticks)[3:6]) - - -def TimestampFromTicks(ticks): - return Timestamp(*time.localtime(ticks)[:6]) - - -Binary = bytes - -# STRING = DBAPITypeObject(*constants.FieldType.get_string_types()) -# BINARY = DBAPITypeObject(*constants.FieldType.get_binary_types()) -# NUMBER = BAPITypeObject(*constants.FieldType.get_number_types()) -# DATETIME = DBAPITypeObject(*constants.FieldType.get_timestamp_types()) -# ROWID = DBAPITypeObject() diff --git a/src/connector/python/linux/python3/taos/error.py b/src/connector/python/linux/python3/taos/error.py deleted file mode 100644 index c584badce8..0000000000 --- a/src/connector/python/linux/python3/taos/error.py +++ /dev/null @@ -1,66 +0,0 @@ -"""Python exceptions -""" - - -class Error(Exception): - def __init__(self, msg=None, errno=None): - self.msg = msg - self._full_msg = self.msg - self.errno = errno - - def __str__(self): - return self._full_msg - - -class Warning(Exception): - """Exception raised for important warnings like data truncations while inserting. - """ - pass - - -class InterfaceError(Error): - """Exception raised for errors that are related to the database interface rather than the database itself. - """ - pass - - -class DatabaseError(Error): - """Exception raised for errors that are related to the database. - """ - pass - - -class DataError(DatabaseError): - """Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range. - """ - pass - - -class OperationalError(DatabaseError): - """Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer - """ - pass - - -class IntegrityError(DatabaseError): - """Exception raised when the relational integrity of the database is affected. - """ - pass - - -class InternalError(DatabaseError): - """Exception raised when the database encounters an internal error. - """ - pass - - -class ProgrammingError(DatabaseError): - """Exception raised for programming errors. - """ - pass - - -class NotSupportedError(DatabaseError): - """Exception raised in case a method or database API was used which is not supported by the database,. - """ - pass diff --git a/src/connector/python/linux/python3/taos/subscription.py b/src/connector/python/linux/python3/taos/subscription.py deleted file mode 100644 index 270d9de092..0000000000 --- a/src/connector/python/linux/python3/taos/subscription.py +++ /dev/null @@ -1,57 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * - - -class TDengineSubscription(object): - """TDengine subscription object - """ - - def __init__(self, sub): - self._sub = sub - - def consume(self): - """Consume rows of a subscription - """ - if self._sub is None: - raise OperationalError("Invalid use of consume") - - result, fields = CTaosInterface.consume(self._sub) - buffer = [[] for i in range(len(fields))] - while True: - block, num_of_fields = CTaosInterface.fetchBlock(result, fields) - if num_of_fields == 0: - break - for i in range(len(fields)): - buffer[i].extend(block[i]) - - self.fields = fields - return list(map(tuple, zip(*buffer))) - - def close(self, keepProgress=True): - """Close the Subscription. - """ - if self._sub is None: - return False - - CTaosInterface.unsubscribe(self._sub, keepProgress) - return True - - -if __name__ == '__main__': - from .connection import TDengineConnection - conn = TDengineConnection( - host="127.0.0.1", - user="root", - password="taosdata", - database="test") - - # Generate a cursor object to run SQL commands - sub = conn.subscribe(True, "test", "select * from meters;", 1000) - - for i in range(0, 10): - data = sub.consume() - for d in data: - print(d) - - sub.close() - conn.close() diff --git a/src/connector/python/osx/python3/LICENSE b/src/connector/python/osx/python3/LICENSE deleted file mode 100644 index 79a9d73086..0000000000 --- a/src/connector/python/osx/python3/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ - Copyright (c) 2019 TAOS Data, Inc. - -This program is free software: you can use, redistribute, and/or modify -it under the terms of the GNU Affero General Public License, version 3 -or later ("AGPL"), as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . diff --git a/src/connector/python/osx/python3/README.md b/src/connector/python/osx/python3/README.md deleted file mode 100644 index 70db6bba13..0000000000 --- a/src/connector/python/osx/python3/README.md +++ /dev/null @@ -1 +0,0 @@ -# TDengine python client interface \ No newline at end of file diff --git a/src/connector/python/osx/python3/setup.py b/src/connector/python/osx/python3/setup.py deleted file mode 100644 index 4c865676c9..0000000000 --- a/src/connector/python/osx/python3/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="taos", - version="2.0.9", - author="Taosdata Inc.", - author_email="support@taosdata.com", - description="TDengine python client package", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/pypa/sampleproject", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: MacOS X", - ], -) diff --git a/src/connector/python/osx/python3/taos/__init__.py b/src/connector/python/osx/python3/taos/__init__.py deleted file mode 100644 index 9732635738..0000000000 --- a/src/connector/python/osx/python3/taos/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ - -from .connection import TDengineConnection -from .cursor import TDengineCursor - -# Globals -threadsafety = 0 -paramstyle = 'pyformat' - -__all__ = ['connection', 'cursor'] - - -def connect(*args, **kwargs): - """ Function to return a TDengine connector object - - Current supporting keyword parameters: - @dsn: Data source name as string - @user: Username as string(optional) - @password: Password as string(optional) - @host: Hostname(optional) - @database: Database name(optional) - - @rtype: TDengineConnector - """ - return TDengineConnection(*args, **kwargs) diff --git a/src/connector/python/osx/python3/taos/cinterface.py b/src/connector/python/osx/python3/taos/cinterface.py deleted file mode 100644 index 720fbef6f5..0000000000 --- a/src/connector/python/osx/python3/taos/cinterface.py +++ /dev/null @@ -1,648 +0,0 @@ -import ctypes -from .constants import FieldType -from .error import * -import math -import datetime - - -def _convert_millisecond_to_datetime(milli): - return datetime.datetime.fromtimestamp(milli / 1000.0) - - -def _convert_microsecond_to_datetime(micro): - return datetime.datetime.fromtimestamp(micro / 1000000.0) - - -def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - _timestamp_converter = _convert_millisecond_to_datetime - if micro: - _timestamp_converter = _convert_microsecond_to_datetime - - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - - -def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_byte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_bool))[ - :abs(num_of_rows)]] - - -def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - - -def _crow_tinyint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - - -def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - - -def _crow_smallint_unsigned_to_python( - data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - - -def _crow_int_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - - -def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - - -def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - - -def _crow_bigint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - - -def _crow_float_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C float row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - - -def _crow_double_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C double row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - - -def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - if num_of_rows > 0: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - else: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - - -def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - for i in range(abs(num_of_rows)): - try: - if num_of_rows >= 0: - tmpstr = ctypes.c_char_p(data) - res.append(tmpstr.value.decode()) - else: - res.append((ctypes.cast(data + nbytes * i, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - - return res - - -def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows > 0: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - return res - - -def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows >= 0: - for i in range(abs(num_of_rows)): - try: - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - res.append((ctypes.cast(data + nbytes * i + 2, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - return res - - -_CONVERT_FUNC = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -_CONVERT_FUNC_BLOCK = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python_block, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python_block, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -# Corresponding TAOS_FIELD structure in C - - -class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 65), - ('type', ctypes.c_char), - ('bytes', ctypes.c_short)] - -# C interface class - - -class CTaosInterface(object): - - libtaos = ctypes.CDLL('libtaos.dylib') - - libtaos.taos_fetch_fields.restype = ctypes.POINTER(TaosField) - libtaos.taos_init.restype = None - libtaos.taos_connect.restype = ctypes.c_void_p - #libtaos.taos_use_result.restype = ctypes.c_void_p - libtaos.taos_fetch_row.restype = ctypes.POINTER(ctypes.c_void_p) - libtaos.taos_errstr.restype = ctypes.c_char_p - libtaos.taos_subscribe.restype = ctypes.c_void_p - libtaos.taos_consume.restype = ctypes.c_void_p - libtaos.taos_fetch_lengths.restype = ctypes.c_void_p - libtaos.taos_free_result.restype = None - libtaos.taos_errno.restype = ctypes.c_int - libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) - - def __init__(self, config=None): - ''' - Function to initialize the class - @host : str, hostname to connect - @user : str, username to connect to server - @password : str, password to connect to server - @db : str, default db to use when log in - @config : str, config directory - - @rtype : None - ''' - if config is None: - self._config = ctypes.c_char_p(None) - else: - try: - self._config = ctypes.c_char_p(config.encode('utf-8')) - except AttributeError: - raise AttributeError("config is expected as a str") - - if config is not None: - CTaosInterface.libtaos.taos_options(3, self._config) - - CTaosInterface.libtaos.taos_init() - - @property - def config(self): - """ Get current config - """ - return self._config - - def connect( - self, - host=None, - user="root", - password="taosdata", - db=None, - port=0): - ''' - Function to connect to server - - @rtype: c_void_p, TDengine handle - ''' - # host - try: - _host = ctypes.c_char_p(host.encode( - "utf-8")) if host is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("host is expected as a str") - - # user - try: - _user = ctypes.c_char_p(user.encode("utf-8")) - except AttributeError: - raise AttributeError("user is expected as a str") - - # password - try: - _password = ctypes.c_char_p(password.encode("utf-8")) - except AttributeError: - raise AttributeError("password is expected as a str") - - # db - try: - _db = ctypes.c_char_p( - db.encode("utf-8")) if db is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("db is expected as a str") - - # port - try: - _port = ctypes.c_int(port) - except TypeError: - raise TypeError("port is expected as an int") - - connection = ctypes.c_void_p(CTaosInterface.libtaos.taos_connect( - _host, _user, _password, _db, _port)) - - if connection.value is None: - print('connect to TDengine failed') - raise ConnectionError("connect to TDengine failed") - # sys.exit(1) - # else: - # print('connect to TDengine success') - - return connection - - @staticmethod - def close(connection): - '''Close the TDengine handle - ''' - CTaosInterface.libtaos.taos_close(connection) - #print('connection is closed') - - @staticmethod - def query(connection, sql): - '''Run SQL - - @sql: str, sql string to run - - @rtype: 0 on success and -1 on failure - ''' - try: - return CTaosInterface.libtaos.taos_query( - connection, ctypes.c_char_p(sql.encode('utf-8'))) - except AttributeError: - raise AttributeError("sql is expected as a string") - # finally: - # CTaosInterface.libtaos.close(connection) - - @staticmethod - def affectedRows(result): - """The affected rows after runing query - """ - return CTaosInterface.libtaos.taos_affected_rows(result) - - @staticmethod - def subscribe(connection, restart, topic, sql, interval): - """Create a subscription - @restart boolean, - @sql string, sql statement for data query, must be a 'select' statement. - @topic string, name of this subscription - """ - return ctypes.c_void_p(CTaosInterface.libtaos.taos_subscribe( - connection, - 1 if restart else 0, - ctypes.c_char_p(topic.encode('utf-8')), - ctypes.c_char_p(sql.encode('utf-8')), - None, - None, - interval)) - - @staticmethod - def consume(sub): - """Consume data of a subscription - """ - result = ctypes.c_void_p(CTaosInterface.libtaos.taos_consume(sub)) - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.libtaos.taos_num_fields(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - return result, fields - - @staticmethod - def unsubscribe(sub, keepProgress): - """Cancel a subscription - """ - CTaosInterface.libtaos.taos_unsubscribe(sub, 1 if keepProgress else 0) - - @staticmethod - def useResult(result): - '''Use result after calling self.query - ''' - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.fieldsCount(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - - return fields - - @staticmethod - def fetchBlock(result, fields): - pblock = ctypes.c_void_p(0) - num_of_rows = CTaosInterface.libtaos.taos_fetch_block( - result, ctypes.byref(pblock)) - if num_of_rows == 0: - return None, 0 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC_BLOCK: - raise DatabaseError("Invalid data type returned from database") - blocks[i] = _CONVERT_FUNC_BLOCK[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - - return blocks, abs(num_of_rows) - - @staticmethod - def fetchRow(result, fields): - pblock = ctypes.c_void_p(0) - pblock = CTaosInterface.libtaos.taos_fetch_row(result) - if pblock: - num_of_rows = 1 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC: - raise DatabaseError( - "Invalid data type returned from database") - if data is None: - blocks[i] = [None] - else: - blocks[i] = _CONVERT_FUNC[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - else: - return None, 0 - return blocks, abs(num_of_rows) - - @staticmethod - def freeResult(result): - CTaosInterface.libtaos.taos_free_result(result) - result.value = None - - @staticmethod - def fieldsCount(result): - return CTaosInterface.libtaos.taos_field_count(result) - - @staticmethod - def fetchFields(result): - return CTaosInterface.libtaos.taos_fetch_fields(result) - - # @staticmethod - # def fetchRow(result, fields): - # l = [] - # row = CTaosInterface.libtaos.taos_fetch_row(result) - # if not row: - # return None - - # for i in range(len(fields)): - # l.append(CTaosInterface.getDataValue( - # row[i], fields[i]['type'], fields[i]['bytes'])) - - # return tuple(l) - - # @staticmethod - # def getDataValue(data, dtype, byte): - # ''' - # ''' - # if not data: - # return None - - # if (dtype == CTaosInterface.TSDB_DATA_TYPE_BOOL): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_bool))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TINYINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_byte))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_SMALLINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_short))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_double))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY): - # return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00') - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR): - # return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00') - - @staticmethod - def errno(result): - """Return the error number. - """ - return CTaosInterface.libtaos.taos_errno(result) - - @staticmethod - def errStr(result): - """Return the error styring - """ - return CTaosInterface.libtaos.taos_errstr(result).decode('utf-8') - - -if __name__ == '__main__': - cinter = CTaosInterface() - conn = cinter.connect() - result = cinter.query(conn, 'show databases') - - print('Query Affected rows: {}'.format(cinter.affectedRows(result))) - - fields = CTaosInterface.useResult(result) - - data, num_of_rows = CTaosInterface.fetchBlock(result, fields) - - print(data) - - cinter.freeResult(result) - cinter.close(conn) diff --git a/src/connector/python/osx/python3/taos/connection.py b/src/connector/python/osx/python3/taos/connection.py deleted file mode 100644 index f6c395342c..0000000000 --- a/src/connector/python/osx/python3/taos/connection.py +++ /dev/null @@ -1,95 +0,0 @@ -from .cursor import TDengineCursor -from .subscription import TDengineSubscription -from .cinterface import CTaosInterface - - -class TDengineConnection(object): - """ TDengine connection object - """ - - def __init__(self, *args, **kwargs): - self._conn = None - self._host = None - self._user = "root" - self._password = "taosdata" - self._database = None - self._port = 0 - self._config = None - self._chandle = None - - self.config(**kwargs) - - def config(self, **kwargs): - # host - if 'host' in kwargs: - self._host = kwargs['host'] - - # user - if 'user' in kwargs: - self._user = kwargs['user'] - - # password - if 'password' in kwargs: - self._password = kwargs['password'] - - # database - if 'database' in kwargs: - self._database = kwargs['database'] - - # port - if 'port' in kwargs: - self._port = kwargs['port'] - - # config - if 'config' in kwargs: - self._config = kwargs['config'] - - self._chandle = CTaosInterface(self._config) - self._conn = self._chandle.connect( - self._host, - self._user, - self._password, - self._database, - self._port) - - def close(self): - """Close current connection. - """ - return CTaosInterface.close(self._conn) - - def subscribe(self, restart, topic, sql, interval): - """Create a subscription. - """ - if self._conn is None: - return None - sub = CTaosInterface.subscribe( - self._conn, restart, topic, sql, interval) - return TDengineSubscription(sub) - - def cursor(self): - """Return a new Cursor object using the connection. - """ - return TDengineCursor(self) - - def commit(self): - """Commit any pending transaction to the database. - - Since TDengine do not support transactions, the implement is void functionality. - """ - pass - - def rollback(self): - """Void functionality - """ - pass - - def clear_result_set(self): - """Clear unused result set on this connection. - """ - pass - - -if __name__ == "__main__": - conn = TDengineConnection(host='192.168.1.107') - conn.close() - print("Hello world") diff --git a/src/connector/python/osx/python3/taos/constants.py b/src/connector/python/osx/python3/taos/constants.py deleted file mode 100644 index 93466f5184..0000000000 --- a/src/connector/python/osx/python3/taos/constants.py +++ /dev/null @@ -1,42 +0,0 @@ -"""Constants in TDengine python -""" - -from .dbapi import * - - -class FieldType(object): - """TDengine Field Types - """ - # type_code - C_NULL = 0 - C_BOOL = 1 - C_TINYINT = 2 - C_SMALLINT = 3 - C_INT = 4 - C_BIGINT = 5 - C_FLOAT = 6 - C_DOUBLE = 7 - C_BINARY = 8 - C_TIMESTAMP = 9 - C_NCHAR = 10 - C_TINYINT_UNSIGNED = 11 - C_SMALLINT_UNSIGNED = 12 - C_INT_UNSIGNED = 13 - C_BIGINT_UNSIGNED = 14 - # NULL value definition - # NOTE: These values should change according to C definition in tsdb.h - C_BOOL_NULL = 0x02 - C_TINYINT_NULL = -128 - C_TINYINT_UNSIGNED_NULL = 255 - C_SMALLINT_NULL = -32768 - C_SMALLINT_UNSIGNED_NULL = 65535 - C_INT_NULL = -2147483648 - C_INT_UNSIGNED_NULL = 4294967295 - C_BIGINT_NULL = -9223372036854775808 - C_BIGINT_UNSIGNED_NULL = 18446744073709551615 - C_FLOAT_NULL = float('nan') - C_DOUBLE_NULL = float('nan') - C_BINARY_NULL = bytearray([int('0xff', 16)]) - # Timestamp precision definition - C_TIMESTAMP_MILLI = 0 - C_TIMESTAMP_MICRO = 1 diff --git a/src/connector/python/osx/python3/taos/cursor.py b/src/connector/python/osx/python3/taos/cursor.py deleted file mode 100644 index 32dc0ea3c3..0000000000 --- a/src/connector/python/osx/python3/taos/cursor.py +++ /dev/null @@ -1,280 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * -from .constants import FieldType - -# querySeqNum = 0 - - -class TDengineCursor(object): - """Database cursor which is used to manage the context of a fetch operation. - - Attributes: - .description: Read-only attribute consists of 7-item sequences: - - > name (mondatory) - > type_code (mondatory) - > display_size - > internal_size - > precision - > scale - > null_ok - - This attribute will be None for operations that do not return rows or - if the cursor has not had an operation invoked via the .execute*() method yet. - - .rowcount:This read-only attribute specifies the number of rows that the last - .execute*() produced (for DQL statements like SELECT) or affected - """ - - def __init__(self, connection=None): - self._description = [] - self._rowcount = -1 - self._connection = None - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - self._logfile = "" - - if connection is not None: - self._connection = connection - - def __iter__(self): - return self - - def __next__(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetch iterator") - - if self._block_rows <= self._block_iter: - block, self._block_rows = CTaosInterface.fetchRow( - self._result, self._fields) - if self._block_rows == 0: - raise StopIteration - self._block = list(map(tuple, zip(*block))) - self._block_iter = 0 - - data = self._block[self._block_iter] - self._block_iter += 1 - - return data - - @property - def description(self): - """Return the description of the object. - """ - return self._description - - @property - def rowcount(self): - """Return the rowcount of the object - """ - return self._rowcount - - @property - def affected_rows(self): - """Return the rowcount of insertion - """ - return self._affected_rows - - def callproc(self, procname, *args): - """Call a stored database procedure with the given name. - - Void functionality since no stored procedures. - """ - pass - - def log(self, logfile): - self._logfile = logfile - - def close(self): - """Close the cursor. - """ - if self._connection is None: - return False - - self._reset_result() - self._connection = None - - return True - - def execute(self, operation, params=None): - """Prepare and execute a database operation (query or command). - """ - if not operation: - return None - - if not self._connection: - # TODO : change the exception raised here - raise ProgrammingError("Cursor is not connected") - - self._reset_result() - - stmt = operation - if params is not None: - pass - - # global querySeqNum - # querySeqNum += 1 - # localSeqNum = querySeqNum # avoid raice condition - # print(" >> Exec Query ({}): {}".format(localSeqNum, str(stmt))) - self._result = CTaosInterface.query(self._connection._conn, stmt) - # print(" << Query ({}) Exec Done".format(localSeqNum)) - if (self._logfile): - with open(self._logfile, "a") as logfile: - logfile.write("%s;\n" % operation) - - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno == 0: - if CTaosInterface.fieldsCount(self._result) == 0: - self._affected_rows += CTaosInterface.affectedRows( - self._result) - return CTaosInterface.affectedRows(self._result) - else: - self._fields = CTaosInterface.useResult( - self._result) - return self._handle_result() - else: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - - def executemany(self, operation, seq_of_parameters): - """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. - """ - pass - - def fetchone(self): - """Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. - """ - pass - - def fetchmany(self): - pass - - def istype(self, col, dataType): - if (dataType.upper() == "BOOL"): - if (self._description[col][1] == FieldType.C_BOOL): - return True - if (dataType.upper() == "TINYINT"): - if (self._description[col][1] == FieldType.C_TINYINT): - return True - if (dataType.upper() == "TINYINT UNSIGNED"): - if (self._description[col][1] == FieldType.C_TINYINT_UNSIGNED): - return True - if (dataType.upper() == "SMALLINT"): - if (self._description[col][1] == FieldType.C_SMALLINT): - return True - if (dataType.upper() == "SMALLINT UNSIGNED"): - if (self._description[col][1] == FieldType.C_SMALLINT_UNSIGNED): - return True - if (dataType.upper() == "INT"): - if (self._description[col][1] == FieldType.C_INT): - return True - if (dataType.upper() == "INT UNSIGNED"): - if (self._description[col][1] == FieldType.C_INT_UNSIGNED): - return True - if (dataType.upper() == "BIGINT"): - if (self._description[col][1] == FieldType.C_BIGINT): - return True - if (dataType.upper() == "BIGINT UNSIGNED"): - if (self._description[col][1] == FieldType.C_BIGINT_UNSIGNED): - return True - if (dataType.upper() == "FLOAT"): - if (self._description[col][1] == FieldType.C_FLOAT): - return True - if (dataType.upper() == "DOUBLE"): - if (self._description[col][1] == FieldType.C_DOUBLE): - return True - if (dataType.upper() == "BINARY"): - if (self._description[col][1] == FieldType.C_BINARY): - return True - if (dataType.upper() == "TIMESTAMP"): - if (self._description[col][1] == FieldType.C_TIMESTAMP): - return True - if (dataType.upper() == "NCHAR"): - if (self._description[col][1] == FieldType.C_NCHAR): - return True - - return False - - def fetchall_row(self): - """Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation. - """ - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchRow( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - return list(map(tuple, zip(*buffer))) - - def fetchall(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchBlock( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - return list(map(tuple, zip(*buffer))) - - def nextset(self): - """ - """ - pass - - def setinputsize(self, sizes): - pass - - def setutputsize(self, size, column=None): - pass - - def _reset_result(self): - """Reset the result to unused version. - """ - self._description = [] - self._rowcount = -1 - if self._result is not None: - CTaosInterface.freeResult(self._result) - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - - def _handle_result(self): - """Handle the return result from query. - """ - self._description = [] - for ele in self._fields: - self._description.append( - (ele['name'], ele['type'], None, None, None, None, False)) - - return self._result diff --git a/src/connector/python/osx/python3/taos/dbapi.py b/src/connector/python/osx/python3/taos/dbapi.py deleted file mode 100644 index 594681ada9..0000000000 --- a/src/connector/python/osx/python3/taos/dbapi.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Type Objects and Constructors. -""" - -import time -import datetime - - -class DBAPITypeObject(object): - def __init__(self, *values): - self.values = values - - def __com__(self, other): - if other in self.values: - return 0 - if other < self.values: - return 1 - else: - return -1 - - -Date = datetime.date -Time = datetime.time -Timestamp = datetime.datetime - - -def DataFromTicks(ticks): - return Date(*time.localtime(ticks)[:3]) - - -def TimeFromTicks(ticks): - return Time(*time.localtime(ticks)[3:6]) - - -def TimestampFromTicks(ticks): - return Timestamp(*time.localtime(ticks)[:6]) - - -Binary = bytes - -# STRING = DBAPITypeObject(*constants.FieldType.get_string_types()) -# BINARY = DBAPITypeObject(*constants.FieldType.get_binary_types()) -# NUMBER = BAPITypeObject(*constants.FieldType.get_number_types()) -# DATETIME = DBAPITypeObject(*constants.FieldType.get_timestamp_types()) -# ROWID = DBAPITypeObject() diff --git a/src/connector/python/osx/python3/taos/error.py b/src/connector/python/osx/python3/taos/error.py deleted file mode 100644 index c584badce8..0000000000 --- a/src/connector/python/osx/python3/taos/error.py +++ /dev/null @@ -1,66 +0,0 @@ -"""Python exceptions -""" - - -class Error(Exception): - def __init__(self, msg=None, errno=None): - self.msg = msg - self._full_msg = self.msg - self.errno = errno - - def __str__(self): - return self._full_msg - - -class Warning(Exception): - """Exception raised for important warnings like data truncations while inserting. - """ - pass - - -class InterfaceError(Error): - """Exception raised for errors that are related to the database interface rather than the database itself. - """ - pass - - -class DatabaseError(Error): - """Exception raised for errors that are related to the database. - """ - pass - - -class DataError(DatabaseError): - """Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range. - """ - pass - - -class OperationalError(DatabaseError): - """Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer - """ - pass - - -class IntegrityError(DatabaseError): - """Exception raised when the relational integrity of the database is affected. - """ - pass - - -class InternalError(DatabaseError): - """Exception raised when the database encounters an internal error. - """ - pass - - -class ProgrammingError(DatabaseError): - """Exception raised for programming errors. - """ - pass - - -class NotSupportedError(DatabaseError): - """Exception raised in case a method or database API was used which is not supported by the database,. - """ - pass diff --git a/src/connector/python/osx/python3/taos/subscription.py b/src/connector/python/osx/python3/taos/subscription.py deleted file mode 100644 index 270d9de092..0000000000 --- a/src/connector/python/osx/python3/taos/subscription.py +++ /dev/null @@ -1,57 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * - - -class TDengineSubscription(object): - """TDengine subscription object - """ - - def __init__(self, sub): - self._sub = sub - - def consume(self): - """Consume rows of a subscription - """ - if self._sub is None: - raise OperationalError("Invalid use of consume") - - result, fields = CTaosInterface.consume(self._sub) - buffer = [[] for i in range(len(fields))] - while True: - block, num_of_fields = CTaosInterface.fetchBlock(result, fields) - if num_of_fields == 0: - break - for i in range(len(fields)): - buffer[i].extend(block[i]) - - self.fields = fields - return list(map(tuple, zip(*buffer))) - - def close(self, keepProgress=True): - """Close the Subscription. - """ - if self._sub is None: - return False - - CTaosInterface.unsubscribe(self._sub, keepProgress) - return True - - -if __name__ == '__main__': - from .connection import TDengineConnection - conn = TDengineConnection( - host="127.0.0.1", - user="root", - password="taosdata", - database="test") - - # Generate a cursor object to run SQL commands - sub = conn.subscribe(True, "test", "select * from meters;", 1000) - - for i in range(0, 10): - data = sub.consume() - for d in data: - print(d) - - sub.close() - conn.close() diff --git a/src/connector/python/setup.py b/src/connector/python/setup.py new file mode 100644 index 0000000000..901e8396c0 --- /dev/null +++ b/src/connector/python/setup.py @@ -0,0 +1,34 @@ +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name="taos", + version="2.0.10", + author="Taosdata Inc.", + author_email="support@taosdata.com", + description="TDengine python client package", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/taosdata/TDengine/tree/develop/src/connector/python", + packages=setuptools.find_packages(), + classifiers=[ + "Environment :: Console", + "Environment :: MacOS X", + "Environment :: Win32 (MS Windows)", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", + "Operating System :: MacOS", + "Programming Language :: Python :: 2.7", + "Operating System :: Linux", + "Operating System :: POSIX :: Linux", + "Operating System :: Microsoft :: Windows", + "Operating System :: Microsoft :: Windows :: Windows 10", + ], +) diff --git a/src/connector/python/linux/python2/taos/__init__.py b/src/connector/python/taos/__init__.py similarity index 100% rename from src/connector/python/linux/python2/taos/__init__.py rename to src/connector/python/taos/__init__.py diff --git a/src/connector/python/linux/python3/taos/cinterface.py b/src/connector/python/taos/cinterface.py similarity index 70% rename from src/connector/python/linux/python3/taos/cinterface.py rename to src/connector/python/taos/cinterface.py index 3d0ecd2901..b8824327b0 100644 --- a/src/connector/python/linux/python3/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -3,6 +3,7 @@ from .constants import FieldType from .error import * import math import datetime +import platform def _convert_millisecond_to_datetime(milli): @@ -20,46 +21,28 @@ def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False): if micro: _timestamp_converter = _convert_microsecond_to_datetime - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] + return [ + None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( + data, ctypes.POINTER( + ctypes.c_int64))[ + :abs(num_of_rows)]] def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C bool row to python row """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_byte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_bool))[ - :abs(num_of_rows)]] + return [ + None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( + data, ctypes.POINTER( + ctypes.c_byte))[ + :abs(num_of_rows)]] def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C tinyint row to python row """ - if num_of_rows > 0: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] + return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] def _crow_tinyint_unsigned_to_python( @@ -69,92 +52,56 @@ def _crow_tinyint_unsigned_to_python( micro=False): """Function to convert C tinyint row to python row """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] + return [ + None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER( + ctypes.c_ubyte))[ + :abs(num_of_rows)]] def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C smallint row to python row """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] + return [ + None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER( + ctypes.c_short))[ + :abs(num_of_rows)]] def _crow_smallint_unsigned_to_python( data, num_of_rows, nbytes=None, micro=False): """Function to convert C smallint row to python row """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] + return [ + None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER( + ctypes.c_ushort))[ + :abs(num_of_rows)]] def _crow_int_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C int row to python row """ - if num_of_rows > 0: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] + return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C int row to python row """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] + return [ + None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER( + ctypes.c_uint))[ + :abs(num_of_rows)]] def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C bigint row to python row """ - if num_of_rows > 0: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] + return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] def _crow_bigint_unsigned_to_python( @@ -164,52 +111,33 @@ def _crow_bigint_unsigned_to_python( micro=False): """Function to convert C bigint row to python row """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] + return [ + None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( + data, ctypes.POINTER( + ctypes.c_uint64))[ + :abs(num_of_rows)]] def _crow_float_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C float row to python row """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] + return [None if math.isnan(ele) else ele for ele in ctypes.cast( + data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] def _crow_double_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C double row to python row """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] + return [None if math.isnan(ele) else ele for ele in ctypes.cast( + data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False): """Function to convert C binary row to python row """ assert(nbytes is not None) - if num_of_rows > 0: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - else: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] + return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( + 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): @@ -236,30 +164,17 @@ def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False): """ assert(nbytes is not None) res = [] - if num_of_rows > 0: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) + for i in range(abs(num_of_rows)): + try: + rbyte = ctypes.cast( + data + nbytes * i, + ctypes.POINTER( + ctypes.c_short))[ + :1].pop() + tmpstr = ctypes.c_char_p(data + nbytes * i + 2) + res.append(tmpstr.value.decode()[0:rbyte]) + except ValueError: + res.append(None) return res @@ -268,20 +183,12 @@ def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, micro=False): """ assert(nbytes is not None) res = [] - if num_of_rows >= 0: - for i in range(abs(num_of_rows)): - try: - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - res.append((ctypes.cast(data + nbytes * i + 2, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) + for i in range(abs(num_of_rows)): + try: + tmpstr = ctypes.c_char_p(data + nbytes * i + 2) + res.append(tmpstr.value.decode()) + except ValueError: + res.append(None) return res @@ -330,14 +237,38 @@ class TaosField(ctypes.Structure): # C interface class +def _load_taos_linux(): + return ctypes.CDLL('libtaos.so') + + +def _load_taos_darwin(): + return ctypes.cDLL('libtaos.dylib') + + +def _load_taos_windows(): + return ctypes.windll.LoadLibrary('taos') + + +def _load_taos(): + load_func = { + 'Linux': _load_taos_linux, + 'Darwin': _load_taos_darwin, + 'Windows': _load_taos_windows, + } + try: + return load_func[platform.system()]() + except: + sys.exit('unsupported platform to TDengine connector') + + class CTaosInterface(object): - libtaos = ctypes.CDLL('libtaos.so') + libtaos = _load_taos() libtaos.taos_fetch_fields.restype = ctypes.POINTER(TaosField) libtaos.taos_init.restype = None libtaos.taos_connect.restype = ctypes.c_void_p - #libtaos.taos_use_result.restype = ctypes.c_void_p + # libtaos.taos_use_result.restype = ctypes.c_void_p libtaos.taos_fetch_row.restype = ctypes.POINTER(ctypes.c_void_p) libtaos.taos_errstr.restype = ctypes.c_char_p libtaos.taos_subscribe.restype = ctypes.c_void_p @@ -438,7 +369,7 @@ class CTaosInterface(object): '''Close the TDengine handle ''' CTaosInterface.libtaos.taos_close(connection) - #print('connection is closed') + # print('connection is closed') @staticmethod def query(connection, sql): diff --git a/src/connector/python/linux/python2/taos/connection.py b/src/connector/python/taos/connection.py similarity index 100% rename from src/connector/python/linux/python2/taos/connection.py rename to src/connector/python/taos/connection.py diff --git a/src/connector/python/linux/python2/taos/constants.py b/src/connector/python/taos/constants.py similarity index 100% rename from src/connector/python/linux/python2/taos/constants.py rename to src/connector/python/taos/constants.py diff --git a/src/connector/python/linux/python3/taos/cursor.py b/src/connector/python/taos/cursor.py similarity index 98% rename from src/connector/python/linux/python3/taos/cursor.py rename to src/connector/python/taos/cursor.py index 32dc0ea3c3..d443ec95d0 100644 --- a/src/connector/python/linux/python3/taos/cursor.py +++ b/src/connector/python/taos/cursor.py @@ -45,6 +45,12 @@ class TDengineCursor(object): return self def __next__(self): + return self._taos_next() + + def next(self): + return self._taos_next() + + def _taos_next(self): if self._result is None or self._fields is None: raise OperationalError("Invalid use of fetch iterator") diff --git a/src/connector/python/linux/python2/taos/dbapi.py b/src/connector/python/taos/dbapi.py similarity index 100% rename from src/connector/python/linux/python2/taos/dbapi.py rename to src/connector/python/taos/dbapi.py diff --git a/src/connector/python/linux/python2/taos/error.py b/src/connector/python/taos/error.py similarity index 100% rename from src/connector/python/linux/python2/taos/error.py rename to src/connector/python/taos/error.py diff --git a/src/connector/python/linux/python2/taos/subscription.py b/src/connector/python/taos/subscription.py similarity index 100% rename from src/connector/python/linux/python2/taos/subscription.py rename to src/connector/python/taos/subscription.py diff --git a/src/connector/python/windows/python2/LICENSE b/src/connector/python/windows/python2/LICENSE deleted file mode 100644 index 79a9d73086..0000000000 --- a/src/connector/python/windows/python2/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ - Copyright (c) 2019 TAOS Data, Inc. - -This program is free software: you can use, redistribute, and/or modify -it under the terms of the GNU Affero General Public License, version 3 -or later ("AGPL"), as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . diff --git a/src/connector/python/windows/python2/README.md b/src/connector/python/windows/python2/README.md deleted file mode 100644 index 70db6bba13..0000000000 --- a/src/connector/python/windows/python2/README.md +++ /dev/null @@ -1 +0,0 @@ -# TDengine python client interface \ No newline at end of file diff --git a/src/connector/python/windows/python2/setup.py b/src/connector/python/windows/python2/setup.py deleted file mode 100644 index 24d75f937c..0000000000 --- a/src/connector/python/windows/python2/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="taos", - version="2.0.9", - author="Taosdata Inc.", - author_email="support@taosdata.com", - description="TDengine python client package", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/pypa/sampleproject", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 2", - "Operating System :: Windows", - ], -) diff --git a/src/connector/python/windows/python2/taos/__init__.py b/src/connector/python/windows/python2/taos/__init__.py deleted file mode 100644 index 9732635738..0000000000 --- a/src/connector/python/windows/python2/taos/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ - -from .connection import TDengineConnection -from .cursor import TDengineCursor - -# Globals -threadsafety = 0 -paramstyle = 'pyformat' - -__all__ = ['connection', 'cursor'] - - -def connect(*args, **kwargs): - """ Function to return a TDengine connector object - - Current supporting keyword parameters: - @dsn: Data source name as string - @user: Username as string(optional) - @password: Password as string(optional) - @host: Hostname(optional) - @database: Database name(optional) - - @rtype: TDengineConnector - """ - return TDengineConnection(*args, **kwargs) diff --git a/src/connector/python/windows/python2/taos/cinterface.py b/src/connector/python/windows/python2/taos/cinterface.py deleted file mode 100644 index 65cb183f26..0000000000 --- a/src/connector/python/windows/python2/taos/cinterface.py +++ /dev/null @@ -1,648 +0,0 @@ -import ctypes -from .constants import FieldType -from .error import * -import math -import datetime - - -def _convert_millisecond_to_datetime(milli): - return datetime.datetime.fromtimestamp(milli / 1000.0) - - -def _convert_microsecond_to_datetime(micro): - return datetime.datetime.fromtimestamp(micro / 1000000.0) - - -def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - _timestamp_converter = _convert_millisecond_to_datetime - if micro: - _timestamp_converter = _convert_microsecond_to_datetime - - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - - -def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_byte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_bool))[ - :abs(num_of_rows)]] - - -def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - - -def _crow_tinyint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - - -def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - - -def _crow_smallint_unsigned_to_python( - data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - - -def _crow_int_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - - -def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - - -def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - - -def _crow_bigint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - - -def _crow_float_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C float row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - - -def _crow_double_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C double row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - - -def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - if num_of_rows > 0: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - else: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - - -def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - for i in range(abs(num_of_rows)): - try: - if num_of_rows >= 0: - tmpstr = ctypes.c_char_p(data) - res.append(tmpstr.value.decode()) - else: - res.append((ctypes.cast(data + nbytes * i, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - - return res - - -def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows > 0: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - return res - - -def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows >= 0: - for i in range(abs(num_of_rows)): - try: - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - res.append((ctypes.cast(data + nbytes * i + 2, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - return res - - -_CONVERT_FUNC = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -_CONVERT_FUNC_BLOCK = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python_block, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python_block, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -# Corresponding TAOS_FIELD structure in C - - -class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 65), - ('type', ctypes.c_char), - ('bytes', ctypes.c_short)] - -# C interface class - - -class CTaosInterface(object): - - libtaos = ctypes.windll.LoadLibrary('taos') - - libtaos.taos_fetch_fields.restype = ctypes.POINTER(TaosField) - libtaos.taos_init.restype = None - libtaos.taos_connect.restype = ctypes.c_void_p - #libtaos.taos_use_result.restype = ctypes.c_void_p - libtaos.taos_fetch_row.restype = ctypes.POINTER(ctypes.c_void_p) - libtaos.taos_errstr.restype = ctypes.c_char_p - libtaos.taos_subscribe.restype = ctypes.c_void_p - libtaos.taos_consume.restype = ctypes.c_void_p - libtaos.taos_fetch_lengths.restype = ctypes.c_void_p - libtaos.taos_free_result.restype = None - libtaos.taos_errno.restype = ctypes.c_int - libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) - - def __init__(self, config=None): - ''' - Function to initialize the class - @host : str, hostname to connect - @user : str, username to connect to server - @password : str, password to connect to server - @db : str, default db to use when log in - @config : str, config directory - - @rtype : None - ''' - if config is None: - self._config = ctypes.c_char_p(None) - else: - try: - self._config = ctypes.c_char_p(config.encode('utf-8')) - except AttributeError: - raise AttributeError("config is expected as a str") - - if config is not None: - CTaosInterface.libtaos.taos_options(3, self._config) - - CTaosInterface.libtaos.taos_init() - - @property - def config(self): - """ Get current config - """ - return self._config - - def connect( - self, - host=None, - user="root", - password="taosdata", - db=None, - port=0): - ''' - Function to connect to server - - @rtype: c_void_p, TDengine handle - ''' - # host - try: - _host = ctypes.c_char_p(host.encode( - "utf-8")) if host is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("host is expected as a str") - - # user - try: - _user = ctypes.c_char_p(user.encode("utf-8")) - except AttributeError: - raise AttributeError("user is expected as a str") - - # password - try: - _password = ctypes.c_char_p(password.encode("utf-8")) - except AttributeError: - raise AttributeError("password is expected as a str") - - # db - try: - _db = ctypes.c_char_p( - db.encode("utf-8")) if db is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("db is expected as a str") - - # port - try: - _port = ctypes.c_int(port) - except TypeError: - raise TypeError("port is expected as an int") - - connection = ctypes.c_void_p(CTaosInterface.libtaos.taos_connect( - _host, _user, _password, _db, _port)) - - if connection.value is None: - print('connect to TDengine failed') - raise ConnectionError("connect to TDengine failed") - # sys.exit(1) - # else: - # print('connect to TDengine success') - - return connection - - @staticmethod - def close(connection): - '''Close the TDengine handle - ''' - CTaosInterface.libtaos.taos_close(connection) - #print('connection is closed') - - @staticmethod - def query(connection, sql): - '''Run SQL - - @sql: str, sql string to run - - @rtype: 0 on success and -1 on failure - ''' - try: - return CTaosInterface.libtaos.taos_query( - connection, ctypes.c_char_p(sql.encode('utf-8'))) - except AttributeError: - raise AttributeError("sql is expected as a string") - # finally: - # CTaosInterface.libtaos.close(connection) - - @staticmethod - def affectedRows(result): - """The affected rows after runing query - """ - return CTaosInterface.libtaos.taos_affected_rows(result) - - @staticmethod - def subscribe(connection, restart, topic, sql, interval): - """Create a subscription - @restart boolean, - @sql string, sql statement for data query, must be a 'select' statement. - @topic string, name of this subscription - """ - return ctypes.c_void_p(CTaosInterface.libtaos.taos_subscribe( - connection, - 1 if restart else 0, - ctypes.c_char_p(topic.encode('utf-8')), - ctypes.c_char_p(sql.encode('utf-8')), - None, - None, - interval)) - - @staticmethod - def consume(sub): - """Consume data of a subscription - """ - result = ctypes.c_void_p(CTaosInterface.libtaos.taos_consume(sub)) - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.libtaos.taos_num_fields(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - return result, fields - - @staticmethod - def unsubscribe(sub, keepProgress): - """Cancel a subscription - """ - CTaosInterface.libtaos.taos_unsubscribe(sub, 1 if keepProgress else 0) - - @staticmethod - def useResult(result): - '''Use result after calling self.query - ''' - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.fieldsCount(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - - return fields - - @staticmethod - def fetchBlock(result, fields): - pblock = ctypes.c_void_p(0) - num_of_rows = CTaosInterface.libtaos.taos_fetch_block( - result, ctypes.byref(pblock)) - if num_of_rows == 0: - return None, 0 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC_BLOCK: - raise DatabaseError("Invalid data type returned from database") - blocks[i] = _CONVERT_FUNC_BLOCK[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - - return blocks, abs(num_of_rows) - - @staticmethod - def fetchRow(result, fields): - pblock = ctypes.c_void_p(0) - pblock = CTaosInterface.libtaos.taos_fetch_row(result) - if pblock: - num_of_rows = 1 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC: - raise DatabaseError( - "Invalid data type returned from database") - if data is None: - blocks[i] = [None] - else: - blocks[i] = _CONVERT_FUNC[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - else: - return None, 0 - return blocks, abs(num_of_rows) - - @staticmethod - def freeResult(result): - CTaosInterface.libtaos.taos_free_result(result) - result.value = None - - @staticmethod - def fieldsCount(result): - return CTaosInterface.libtaos.taos_field_count(result) - - @staticmethod - def fetchFields(result): - return CTaosInterface.libtaos.taos_fetch_fields(result) - - # @staticmethod - # def fetchRow(result, fields): - # l = [] - # row = CTaosInterface.libtaos.taos_fetch_row(result) - # if not row: - # return None - - # for i in range(len(fields)): - # l.append(CTaosInterface.getDataValue( - # row[i], fields[i]['type'], fields[i]['bytes'])) - - # return tuple(l) - - # @staticmethod - # def getDataValue(data, dtype, byte): - # ''' - # ''' - # if not data: - # return None - - # if (dtype == CTaosInterface.TSDB_DATA_TYPE_BOOL): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_bool))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TINYINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_byte))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_SMALLINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_short))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_double))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY): - # return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00') - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR): - # return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00') - - @staticmethod - def errno(result): - """Return the error number. - """ - return CTaosInterface.libtaos.taos_errno(result) - - @staticmethod - def errStr(result): - """Return the error styring - """ - return CTaosInterface.libtaos.taos_errstr(result).decode('utf-8') - - -if __name__ == '__main__': - cinter = CTaosInterface() - conn = cinter.connect() - result = cinter.query(conn, 'show databases') - - print('Query Affected rows: {}'.format(cinter.affectedRows(result))) - - fields = CTaosInterface.useResult(result) - - data, num_of_rows = CTaosInterface.fetchBlock(result, fields) - - print(data) - - cinter.freeResult(result) - cinter.close(conn) diff --git a/src/connector/python/windows/python2/taos/connection.py b/src/connector/python/windows/python2/taos/connection.py deleted file mode 100644 index 5729d01c6d..0000000000 --- a/src/connector/python/windows/python2/taos/connection.py +++ /dev/null @@ -1,96 +0,0 @@ -from .cursor import TDengineCursor -from .subscription import TDengineSubscription -from .cinterface import CTaosInterface - - -class TDengineConnection(object): - """ TDengine connection object - """ - - def __init__(self, *args, **kwargs): - self._conn = None - self._host = None - self._user = "root" - self._password = "taosdata" - self._database = None - self._port = 0 - self._config = None - self._chandle = None - - if len(kwargs) > 0: - self.config(**kwargs) - - def config(self, **kwargs): - # host - if 'host' in kwargs: - self._host = kwargs['host'] - - # user - if 'user' in kwargs: - self._user = kwargs['user'] - - # password - if 'password' in kwargs: - self._password = kwargs['password'] - - # database - if 'database' in kwargs: - self._database = kwargs['database'] - - # port - if 'port' in kwargs: - self._port = kwargs['port'] - - # config - if 'config' in kwargs: - self._config = kwargs['config'] - - self._chandle = CTaosInterface(self._config) - self._conn = self._chandle.connect( - self._host, - self._user, - self._password, - self._database, - self._port) - - def close(self): - """Close current connection. - """ - return CTaosInterface.close(self._conn) - - def subscribe(self, restart, topic, sql, interval): - """Create a subscription. - """ - if self._conn is None: - return None - sub = CTaosInterface.subscribe( - self._conn, restart, topic, sql, interval) - return TDengineSubscription(sub) - - def cursor(self): - """Return a new Cursor object using the connection. - """ - return TDengineCursor(self) - - def commit(self): - """Commit any pending transaction to the database. - - Since TDengine do not support transactions, the implement is void functionality. - """ - pass - - def rollback(self): - """Void functionality - """ - pass - - def clear_result_set(self): - """Clear unused result set on this connection. - """ - pass - - -if __name__ == "__main__": - conn = TDengineConnection(host='192.168.1.107') - conn.close() - print("Hello world") diff --git a/src/connector/python/windows/python2/taos/constants.py b/src/connector/python/windows/python2/taos/constants.py deleted file mode 100644 index 8a8011c3e3..0000000000 --- a/src/connector/python/windows/python2/taos/constants.py +++ /dev/null @@ -1,42 +0,0 @@ -"""Constants in TDengine python -""" - -from .dbapi import * - - -class FieldType(object): - """TDengine Field Types - """ - # type_code - C_NULL = 0 - C_BOOL = 1 - C_TINYINT = 2 - C_SMALLINT = 3 - C_INT = 4 - C_BIGINT = 5 - C_FLOAT = 6 - C_DOUBLE = 7 - C_BINARY = 8 - C_TIMESTAMP = 9 - C_NCHAR = 10 - C_TINYINT_UNSIGNED = 11 - C_SMALLINT_UNSIGNED = 12 - C_INT_UNSIGNED = 13 - C_BIGINT_UNSIGNED = 14 - # NULL value definition - # NOTE: These values should change according to C definition in tsdb.h - C_BOOL_NULL = 0x02 - C_TINYINT_NULL = -128 - C_TINYINT_UNSIGNED_NULL = 255 - C_SMALLINT_NULL = -32768 - C_SMALLINT_UNSIGNED_NULL = 65535 - C_INT_NULL = -2147483648 - C_INT_UNSIGNED_NULL = 4294967295 - C_BIGINT_NULL = -9223372036854775808 - C_BIGINT_UNSIGNED_NULL = 18446744073709551615 - C_FLOAT_NULL = float('nan') - C_DOUBLE_NULL = float('nan') - C_BINARY_NULL = bytearray([int('0xff', 16)]) - # Time precision definition - C_TIMESTAMP_MILLI = 0 - C_TIMESTAMP_MICRO = 1 diff --git a/src/connector/python/windows/python2/taos/cursor.py b/src/connector/python/windows/python2/taos/cursor.py deleted file mode 100644 index 5f4666b593..0000000000 --- a/src/connector/python/windows/python2/taos/cursor.py +++ /dev/null @@ -1,220 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * -from .constants import FieldType - -# querySeqNum = 0 - - -class TDengineCursor(object): - """Database cursor which is used to manage the context of a fetch operation. - - Attributes: - .description: Read-only attribute consists of 7-item sequences: - - > name (mondatory) - > type_code (mondatory) - > display_size - > internal_size - > precision - > scale - > null_ok - - This attribute will be None for operations that do not return rows or - if the cursor has not had an operation invoked via the .execute*() method yet. - - .rowcount:This read-only attribute specifies the number of rows that the last - .execute*() produced (for DQL statements like SELECT) or affected - """ - - def __init__(self, connection=None): - self._description = [] - self._rowcount = -1 - self._connection = None - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - self._logfile = "" - - if connection is not None: - self._connection = connection - - def __iter__(self): - return self - - def __next__(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetch iterator") - - if self._block_rows <= self._block_iter: - block, self._block_rows = CTaosInterface.fetchRow( - self._result, self._fields) - if self._block_rows == 0: - raise StopIteration - self._block = list(map(tuple, zip(*block))) - self._block_iter = 0 - - data = self._block[self._block_iter] - self._block_iter += 1 - - return data - - @property - def description(self): - """Return the description of the object. - """ - return self._description - - @property - def rowcount(self): - """Return the rowcount of the object - """ - return self._rowcount - - @property - def affected_rows(self): - """Return the affected_rows of the object - """ - return self._affected_rows - - def callproc(self, procname, *args): - """Call a stored database procedure with the given name. - - Void functionality since no stored procedures. - """ - pass - - def close(self): - """Close the cursor. - """ - if self._connection is None: - return False - - self._reset_result() - self._connection = None - - return True - - def execute(self, operation, params=None): - """Prepare and execute a database operation (query or command). - """ - if not operation: - return None - - if not self._connection: - # TODO : change the exception raised here - raise ProgrammingError("Cursor is not connected") - - self._reset_result() - - stmt = operation - if params is not None: - pass - - self._result = CTaosInterface.query(self._connection._conn, stmt) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno == 0: - if CTaosInterface.fieldsCount(self._result) == 0: - self._affected_rows += CTaosInterface.affectedRows( - self._result) - return CTaosInterface.affectedRows(self._result) - else: - self._fields = CTaosInterface.useResult(self._result) - return self._handle_result() - else: - raise ProgrammingError(CTaosInterface.errStr(self._result), errno) - - def executemany(self, operation, seq_of_parameters): - """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. - """ - pass - - def fetchone(self): - """Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. - """ - pass - - def fetchmany(self): - pass - - def fetchall_row(self): - """Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation. - """ - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchRow( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - return list(map(tuple, zip(*buffer))) - - def fetchall(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchBlock( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - - return list(map(tuple, zip(*buffer))) - - def nextset(self): - """ - """ - pass - - def setinputsize(self, sizes): - pass - - def setutputsize(self, size, column=None): - pass - - def _reset_result(self): - """Reset the result to unused version. - """ - self._description = [] - self._rowcount = -1 - if self._result is not None: - CTaosInterface.freeResult(self._result) - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - - def _handle_result(self): - """Handle the return result from query. - """ - self._description = [] - for ele in self._fields: - self._description.append( - (ele['name'], ele['type'], None, None, None, None, False)) - - return self._result diff --git a/src/connector/python/windows/python2/taos/dbapi.py b/src/connector/python/windows/python2/taos/dbapi.py deleted file mode 100644 index 594681ada9..0000000000 --- a/src/connector/python/windows/python2/taos/dbapi.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Type Objects and Constructors. -""" - -import time -import datetime - - -class DBAPITypeObject(object): - def __init__(self, *values): - self.values = values - - def __com__(self, other): - if other in self.values: - return 0 - if other < self.values: - return 1 - else: - return -1 - - -Date = datetime.date -Time = datetime.time -Timestamp = datetime.datetime - - -def DataFromTicks(ticks): - return Date(*time.localtime(ticks)[:3]) - - -def TimeFromTicks(ticks): - return Time(*time.localtime(ticks)[3:6]) - - -def TimestampFromTicks(ticks): - return Timestamp(*time.localtime(ticks)[:6]) - - -Binary = bytes - -# STRING = DBAPITypeObject(*constants.FieldType.get_string_types()) -# BINARY = DBAPITypeObject(*constants.FieldType.get_binary_types()) -# NUMBER = BAPITypeObject(*constants.FieldType.get_number_types()) -# DATETIME = DBAPITypeObject(*constants.FieldType.get_timestamp_types()) -# ROWID = DBAPITypeObject() diff --git a/src/connector/python/windows/python2/taos/error.py b/src/connector/python/windows/python2/taos/error.py deleted file mode 100644 index c584badce8..0000000000 --- a/src/connector/python/windows/python2/taos/error.py +++ /dev/null @@ -1,66 +0,0 @@ -"""Python exceptions -""" - - -class Error(Exception): - def __init__(self, msg=None, errno=None): - self.msg = msg - self._full_msg = self.msg - self.errno = errno - - def __str__(self): - return self._full_msg - - -class Warning(Exception): - """Exception raised for important warnings like data truncations while inserting. - """ - pass - - -class InterfaceError(Error): - """Exception raised for errors that are related to the database interface rather than the database itself. - """ - pass - - -class DatabaseError(Error): - """Exception raised for errors that are related to the database. - """ - pass - - -class DataError(DatabaseError): - """Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range. - """ - pass - - -class OperationalError(DatabaseError): - """Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer - """ - pass - - -class IntegrityError(DatabaseError): - """Exception raised when the relational integrity of the database is affected. - """ - pass - - -class InternalError(DatabaseError): - """Exception raised when the database encounters an internal error. - """ - pass - - -class ProgrammingError(DatabaseError): - """Exception raised for programming errors. - """ - pass - - -class NotSupportedError(DatabaseError): - """Exception raised in case a method or database API was used which is not supported by the database,. - """ - pass diff --git a/src/connector/python/windows/python2/taos/subscription.py b/src/connector/python/windows/python2/taos/subscription.py deleted file mode 100644 index 270d9de092..0000000000 --- a/src/connector/python/windows/python2/taos/subscription.py +++ /dev/null @@ -1,57 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * - - -class TDengineSubscription(object): - """TDengine subscription object - """ - - def __init__(self, sub): - self._sub = sub - - def consume(self): - """Consume rows of a subscription - """ - if self._sub is None: - raise OperationalError("Invalid use of consume") - - result, fields = CTaosInterface.consume(self._sub) - buffer = [[] for i in range(len(fields))] - while True: - block, num_of_fields = CTaosInterface.fetchBlock(result, fields) - if num_of_fields == 0: - break - for i in range(len(fields)): - buffer[i].extend(block[i]) - - self.fields = fields - return list(map(tuple, zip(*buffer))) - - def close(self, keepProgress=True): - """Close the Subscription. - """ - if self._sub is None: - return False - - CTaosInterface.unsubscribe(self._sub, keepProgress) - return True - - -if __name__ == '__main__': - from .connection import TDengineConnection - conn = TDengineConnection( - host="127.0.0.1", - user="root", - password="taosdata", - database="test") - - # Generate a cursor object to run SQL commands - sub = conn.subscribe(True, "test", "select * from meters;", 1000) - - for i in range(0, 10): - data = sub.consume() - for d in data: - print(d) - - sub.close() - conn.close() diff --git a/src/connector/python/windows/python3/LICENSE b/src/connector/python/windows/python3/LICENSE deleted file mode 100644 index 2d032e65d8..0000000000 --- a/src/connector/python/windows/python3/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ - Copyright (c) 2019 TAOS Data, Inc. - -This program is free software: you can use, redistribute, and/or modify -it under the terms of the GNU Affero General Public License, version 3 -or later ("AGPL"), as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . diff --git a/src/connector/python/windows/python3/README.md b/src/connector/python/windows/python3/README.md deleted file mode 100644 index 70db6bba13..0000000000 --- a/src/connector/python/windows/python3/README.md +++ /dev/null @@ -1 +0,0 @@ -# TDengine python client interface \ No newline at end of file diff --git a/src/connector/python/windows/python3/setup.py b/src/connector/python/windows/python3/setup.py deleted file mode 100644 index 2659c493aa..0000000000 --- a/src/connector/python/windows/python3/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="taos", - version="2.0.9", - author="Taosdata Inc.", - author_email="support@taosdata.com", - description="TDengine python client package", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/pypa/sampleproject", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: Windows", - ], -) diff --git a/src/connector/python/windows/python3/taos/__init__.py b/src/connector/python/windows/python3/taos/__init__.py deleted file mode 100644 index b57e25fd2c..0000000000 --- a/src/connector/python/windows/python3/taos/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ - -from .connection import TDengineConnection -from .cursor import TDengineCursor - -# Globals -threadsafety = 0 -paramstyle = 'pyformat' - -__all__ = ['connection', 'cursor'] - - -def connect(*args, **kwargs): - """ Function to return a TDengine connector object - - Current supporting keyword parameters: - @dsn: Data source name as string - @user: Username as string(optional) - @password: Password as string(optional) - @host: Hostname(optional) - @database: Database name(optional) - - @rtype: TDengineConnector - """ - return TDengineConnection(*args, **kwargs) diff --git a/src/connector/python/windows/python3/taos/cinterface.py b/src/connector/python/windows/python3/taos/cinterface.py deleted file mode 100644 index 65cb183f26..0000000000 --- a/src/connector/python/windows/python3/taos/cinterface.py +++ /dev/null @@ -1,648 +0,0 @@ -import ctypes -from .constants import FieldType -from .error import * -import math -import datetime - - -def _convert_millisecond_to_datetime(milli): - return datetime.datetime.fromtimestamp(milli / 1000.0) - - -def _convert_microsecond_to_datetime(micro): - return datetime.datetime.fromtimestamp(micro / 1000000.0) - - -def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - _timestamp_converter = _convert_millisecond_to_datetime - if micro: - _timestamp_converter = _convert_microsecond_to_datetime - - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_NULL else _timestamp_converter(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_int64))[ - :abs(num_of_rows)]] - - -def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bool row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_byte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_bool))[ - :abs(num_of_rows)]] - - -def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]] - - -def _crow_tinyint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C tinyint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_TINYINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ubyte))[ - :abs(num_of_rows)]] - - -def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_short))[ - :abs(num_of_rows)]] - - -def _crow_smallint_unsigned_to_python( - data, num_of_rows, nbytes=None, micro=False): - """Function to convert C smallint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_SMALLINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_ushort))[ - :abs(num_of_rows)]] - - -def _crow_int_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]] - - -def _crow_int_unsigned_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C int row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_INT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint))[ - :abs(num_of_rows)]] - - -def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - else: - return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_int64))[:abs(num_of_rows)]] - - -def _crow_bigint_unsigned_to_python( - data, - num_of_rows, - nbytes=None, - micro=False): - """Function to convert C bigint row to python row - """ - if num_of_rows > 0: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - else: - return [ - None if ele == FieldType.C_BIGINT_UNSIGNED_NULL else ele for ele in ctypes.cast( - data, ctypes.POINTER( - ctypes.c_uint64))[ - :abs(num_of_rows)]] - - -def _crow_float_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C float row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]] - - -def _crow_double_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C double row to python row - """ - if num_of_rows > 0: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - else: - return [None if math.isnan(ele) else ele for ele in ctypes.cast( - data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]] - - -def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - if num_of_rows > 0: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - else: - return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode( - 'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]] - - -def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - for i in range(abs(num_of_rows)): - try: - if num_of_rows >= 0: - tmpstr = ctypes.c_char_p(data) - res.append(tmpstr.value.decode()) - else: - res.append((ctypes.cast(data + nbytes * i, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - - return res - - -def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C binary row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows > 0: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - rbyte = ctypes.cast( - data + nbytes * i, - ctypes.POINTER( - ctypes.c_short))[ - :1].pop() - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()[0:rbyte]) - except ValueError: - res.append(None) - return res - - -def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, micro=False): - """Function to convert C nchar row to python row - """ - assert(nbytes is not None) - res = [] - if num_of_rows >= 0: - for i in range(abs(num_of_rows)): - try: - tmpstr = ctypes.c_char_p(data + nbytes * i + 2) - res.append(tmpstr.value.decode()) - except ValueError: - res.append(None) - else: - for i in range(abs(num_of_rows)): - try: - res.append((ctypes.cast(data + nbytes * i + 2, - ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value) - except ValueError: - res.append(None) - return res - - -_CONVERT_FUNC = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -_CONVERT_FUNC_BLOCK = { - FieldType.C_BOOL: _crow_bool_to_python, - FieldType.C_TINYINT: _crow_tinyint_to_python, - FieldType.C_SMALLINT: _crow_smallint_to_python, - FieldType.C_INT: _crow_int_to_python, - FieldType.C_BIGINT: _crow_bigint_to_python, - FieldType.C_FLOAT: _crow_float_to_python, - FieldType.C_DOUBLE: _crow_double_to_python, - FieldType.C_BINARY: _crow_binary_to_python_block, - FieldType.C_TIMESTAMP: _crow_timestamp_to_python, - FieldType.C_NCHAR: _crow_nchar_to_python_block, - FieldType.C_TINYINT_UNSIGNED: _crow_tinyint_unsigned_to_python, - FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, - FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, - FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python -} - -# Corresponding TAOS_FIELD structure in C - - -class TaosField(ctypes.Structure): - _fields_ = [('name', ctypes.c_char * 65), - ('type', ctypes.c_char), - ('bytes', ctypes.c_short)] - -# C interface class - - -class CTaosInterface(object): - - libtaos = ctypes.windll.LoadLibrary('taos') - - libtaos.taos_fetch_fields.restype = ctypes.POINTER(TaosField) - libtaos.taos_init.restype = None - libtaos.taos_connect.restype = ctypes.c_void_p - #libtaos.taos_use_result.restype = ctypes.c_void_p - libtaos.taos_fetch_row.restype = ctypes.POINTER(ctypes.c_void_p) - libtaos.taos_errstr.restype = ctypes.c_char_p - libtaos.taos_subscribe.restype = ctypes.c_void_p - libtaos.taos_consume.restype = ctypes.c_void_p - libtaos.taos_fetch_lengths.restype = ctypes.c_void_p - libtaos.taos_free_result.restype = None - libtaos.taos_errno.restype = ctypes.c_int - libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) - - def __init__(self, config=None): - ''' - Function to initialize the class - @host : str, hostname to connect - @user : str, username to connect to server - @password : str, password to connect to server - @db : str, default db to use when log in - @config : str, config directory - - @rtype : None - ''' - if config is None: - self._config = ctypes.c_char_p(None) - else: - try: - self._config = ctypes.c_char_p(config.encode('utf-8')) - except AttributeError: - raise AttributeError("config is expected as a str") - - if config is not None: - CTaosInterface.libtaos.taos_options(3, self._config) - - CTaosInterface.libtaos.taos_init() - - @property - def config(self): - """ Get current config - """ - return self._config - - def connect( - self, - host=None, - user="root", - password="taosdata", - db=None, - port=0): - ''' - Function to connect to server - - @rtype: c_void_p, TDengine handle - ''' - # host - try: - _host = ctypes.c_char_p(host.encode( - "utf-8")) if host is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("host is expected as a str") - - # user - try: - _user = ctypes.c_char_p(user.encode("utf-8")) - except AttributeError: - raise AttributeError("user is expected as a str") - - # password - try: - _password = ctypes.c_char_p(password.encode("utf-8")) - except AttributeError: - raise AttributeError("password is expected as a str") - - # db - try: - _db = ctypes.c_char_p( - db.encode("utf-8")) if db is not None else ctypes.c_char_p(None) - except AttributeError: - raise AttributeError("db is expected as a str") - - # port - try: - _port = ctypes.c_int(port) - except TypeError: - raise TypeError("port is expected as an int") - - connection = ctypes.c_void_p(CTaosInterface.libtaos.taos_connect( - _host, _user, _password, _db, _port)) - - if connection.value is None: - print('connect to TDengine failed') - raise ConnectionError("connect to TDengine failed") - # sys.exit(1) - # else: - # print('connect to TDengine success') - - return connection - - @staticmethod - def close(connection): - '''Close the TDengine handle - ''' - CTaosInterface.libtaos.taos_close(connection) - #print('connection is closed') - - @staticmethod - def query(connection, sql): - '''Run SQL - - @sql: str, sql string to run - - @rtype: 0 on success and -1 on failure - ''' - try: - return CTaosInterface.libtaos.taos_query( - connection, ctypes.c_char_p(sql.encode('utf-8'))) - except AttributeError: - raise AttributeError("sql is expected as a string") - # finally: - # CTaosInterface.libtaos.close(connection) - - @staticmethod - def affectedRows(result): - """The affected rows after runing query - """ - return CTaosInterface.libtaos.taos_affected_rows(result) - - @staticmethod - def subscribe(connection, restart, topic, sql, interval): - """Create a subscription - @restart boolean, - @sql string, sql statement for data query, must be a 'select' statement. - @topic string, name of this subscription - """ - return ctypes.c_void_p(CTaosInterface.libtaos.taos_subscribe( - connection, - 1 if restart else 0, - ctypes.c_char_p(topic.encode('utf-8')), - ctypes.c_char_p(sql.encode('utf-8')), - None, - None, - interval)) - - @staticmethod - def consume(sub): - """Consume data of a subscription - """ - result = ctypes.c_void_p(CTaosInterface.libtaos.taos_consume(sub)) - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.libtaos.taos_num_fields(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - return result, fields - - @staticmethod - def unsubscribe(sub, keepProgress): - """Cancel a subscription - """ - CTaosInterface.libtaos.taos_unsubscribe(sub, 1 if keepProgress else 0) - - @staticmethod - def useResult(result): - '''Use result after calling self.query - ''' - fields = [] - pfields = CTaosInterface.fetchFields(result) - for i in range(CTaosInterface.fieldsCount(result)): - fields.append({'name': pfields[i].name.decode('utf-8'), - 'bytes': pfields[i].bytes, - 'type': ord(pfields[i].type)}) - - return fields - - @staticmethod - def fetchBlock(result, fields): - pblock = ctypes.c_void_p(0) - num_of_rows = CTaosInterface.libtaos.taos_fetch_block( - result, ctypes.byref(pblock)) - if num_of_rows == 0: - return None, 0 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC_BLOCK: - raise DatabaseError("Invalid data type returned from database") - blocks[i] = _CONVERT_FUNC_BLOCK[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - - return blocks, abs(num_of_rows) - - @staticmethod - def fetchRow(result, fields): - pblock = ctypes.c_void_p(0) - pblock = CTaosInterface.libtaos.taos_fetch_row(result) - if pblock: - num_of_rows = 1 - isMicro = (CTaosInterface.libtaos.taos_result_precision( - result) == FieldType.C_TIMESTAMP_MICRO) - blocks = [None] * len(fields) - fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result) - fieldLen = [ - ele for ele in ctypes.cast( - fieldL, ctypes.POINTER( - ctypes.c_int))[ - :len(fields)]] - for i in range(len(fields)): - data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i] - if fields[i]['type'] not in _CONVERT_FUNC: - raise DatabaseError( - "Invalid data type returned from database") - if data is None: - blocks[i] = [None] - else: - blocks[i] = _CONVERT_FUNC[fields[i]['type']]( - data, num_of_rows, fieldLen[i], isMicro) - else: - return None, 0 - return blocks, abs(num_of_rows) - - @staticmethod - def freeResult(result): - CTaosInterface.libtaos.taos_free_result(result) - result.value = None - - @staticmethod - def fieldsCount(result): - return CTaosInterface.libtaos.taos_field_count(result) - - @staticmethod - def fetchFields(result): - return CTaosInterface.libtaos.taos_fetch_fields(result) - - # @staticmethod - # def fetchRow(result, fields): - # l = [] - # row = CTaosInterface.libtaos.taos_fetch_row(result) - # if not row: - # return None - - # for i in range(len(fields)): - # l.append(CTaosInterface.getDataValue( - # row[i], fields[i]['type'], fields[i]['bytes'])) - - # return tuple(l) - - # @staticmethod - # def getDataValue(data, dtype, byte): - # ''' - # ''' - # if not data: - # return None - - # if (dtype == CTaosInterface.TSDB_DATA_TYPE_BOOL): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_bool))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TINYINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_byte))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_SMALLINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_short))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_float))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_double))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY): - # return (ctypes.cast(data, ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00') - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP): - # return ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[0] - # elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR): - # return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00') - - @staticmethod - def errno(result): - """Return the error number. - """ - return CTaosInterface.libtaos.taos_errno(result) - - @staticmethod - def errStr(result): - """Return the error styring - """ - return CTaosInterface.libtaos.taos_errstr(result).decode('utf-8') - - -if __name__ == '__main__': - cinter = CTaosInterface() - conn = cinter.connect() - result = cinter.query(conn, 'show databases') - - print('Query Affected rows: {}'.format(cinter.affectedRows(result))) - - fields = CTaosInterface.useResult(result) - - data, num_of_rows = CTaosInterface.fetchBlock(result, fields) - - print(data) - - cinter.freeResult(result) - cinter.close(conn) diff --git a/src/connector/python/windows/python3/taos/connection.py b/src/connector/python/windows/python3/taos/connection.py deleted file mode 100644 index 5729d01c6d..0000000000 --- a/src/connector/python/windows/python3/taos/connection.py +++ /dev/null @@ -1,96 +0,0 @@ -from .cursor import TDengineCursor -from .subscription import TDengineSubscription -from .cinterface import CTaosInterface - - -class TDengineConnection(object): - """ TDengine connection object - """ - - def __init__(self, *args, **kwargs): - self._conn = None - self._host = None - self._user = "root" - self._password = "taosdata" - self._database = None - self._port = 0 - self._config = None - self._chandle = None - - if len(kwargs) > 0: - self.config(**kwargs) - - def config(self, **kwargs): - # host - if 'host' in kwargs: - self._host = kwargs['host'] - - # user - if 'user' in kwargs: - self._user = kwargs['user'] - - # password - if 'password' in kwargs: - self._password = kwargs['password'] - - # database - if 'database' in kwargs: - self._database = kwargs['database'] - - # port - if 'port' in kwargs: - self._port = kwargs['port'] - - # config - if 'config' in kwargs: - self._config = kwargs['config'] - - self._chandle = CTaosInterface(self._config) - self._conn = self._chandle.connect( - self._host, - self._user, - self._password, - self._database, - self._port) - - def close(self): - """Close current connection. - """ - return CTaosInterface.close(self._conn) - - def subscribe(self, restart, topic, sql, interval): - """Create a subscription. - """ - if self._conn is None: - return None - sub = CTaosInterface.subscribe( - self._conn, restart, topic, sql, interval) - return TDengineSubscription(sub) - - def cursor(self): - """Return a new Cursor object using the connection. - """ - return TDengineCursor(self) - - def commit(self): - """Commit any pending transaction to the database. - - Since TDengine do not support transactions, the implement is void functionality. - """ - pass - - def rollback(self): - """Void functionality - """ - pass - - def clear_result_set(self): - """Clear unused result set on this connection. - """ - pass - - -if __name__ == "__main__": - conn = TDengineConnection(host='192.168.1.107') - conn.close() - print("Hello world") diff --git a/src/connector/python/windows/python3/taos/constants.py b/src/connector/python/windows/python3/taos/constants.py deleted file mode 100644 index 49fc17b2fb..0000000000 --- a/src/connector/python/windows/python3/taos/constants.py +++ /dev/null @@ -1,42 +0,0 @@ -"""Constants in TDengine python -""" - -from .dbapi import * - - -class FieldType(object): - """TDengine Field Types - """ - # type_code - C_NULL = 0 - C_BOOL = 1 - C_TINYINT = 2 - C_SMALLINT = 3 - C_INT = 4 - C_BIGINT = 5 - C_FLOAT = 6 - C_DOUBLE = 7 - C_BINARY = 8 - C_TIMESTAMP = 9 - C_NCHAR = 10 - C_TINYINT_UNSIGNED = 11 - C_SMALLINT_UNSIGNED = 12 - C_INT_UNSIGNED = 13 - C_BIGINT_UNSIGNED = 14 - # NULL value definition - # NOTE: These values should change according to C definition in tsdb.h - C_BOOL_NULL = 0x02 - C_TINYINT_NULL = -128 - C_TINYINT_UNSIGNED_NULL = 255 - C_SMALLINT_NULL = -32768 - C_SMALLINT_UNSIGNED_NULL = 65535 - C_INT_NULL = -2147483648 - C_INT_UNSIGNED_NULL = 4294967295 - C_BIGINT_NULL = -9223372036854775808 - C_BIGINT_UNSIGNED_NULL = 18446744073709551615 - C_FLOAT_NULL = float('nan') - C_DOUBLE_NULL = float('nan') - C_BINARY_NULL = bytearray([int('0xff', 16)]) - # Timestamp precision definition - C_TIMESTAMP_MILLI = 0 - C_TIMESTAMP_MICRO = 1 diff --git a/src/connector/python/windows/python3/taos/cursor.py b/src/connector/python/windows/python3/taos/cursor.py deleted file mode 100644 index 136cd42fe4..0000000000 --- a/src/connector/python/windows/python3/taos/cursor.py +++ /dev/null @@ -1,220 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * -from .constants import FieldType - -# querySeqNum = 0 - - -class TDengineCursor(object): - """Database cursor which is used to manage the context of a fetch operation. - - Attributes: - .description: Read-only attribute consists of 7-item sequences: - - > name (mondatory) - > type_code (mondatory) - > display_size - > internal_size - > precision - > scale - > null_ok - - This attribute will be None for operations that do not return rows or - if the cursor has not had an operation invoked via the .execute*() method yet. - - .rowcount:This read-only attribute specifies the number of rows that the last - .execute*() produced (for DQL statements like SELECT) or affected - """ - - def __init__(self, connection=None): - self._description = [] - self._rowcount = -1 - self._connection = None - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - self._logfile = "" - - if connection is not None: - self._connection = connection - - def __iter__(self): - return self - - def __next__(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetch iterator") - - if self._block_rows <= self._block_iter: - block, self._block_rows = CTaosInterface.fetchRow( - self._result, self._fields) - if self._block_rows == 0: - raise StopIteration - self._block = list(map(tuple, zip(*block))) - self._block_iter = 0 - - data = self._block[self._block_iter] - self._block_iter += 1 - - return data - - @property - def description(self): - """Return the description of the object. - """ - return self._description - - @property - def rowcount(self): - """Return the rowcount of the object - """ - return self._rowcount - - @property - def affected_rows(self): - """Return the affected_rows of the object - """ - return self._affected_rows - - def callproc(self, procname, *args): - """Call a stored database procedure with the given name. - - Void functionality since no stored procedures. - """ - pass - - def close(self): - """Close the cursor. - """ - if self._connection is None: - return False - - self._reset_result() - self._connection = None - - return True - - def execute(self, operation, params=None): - """Prepare and execute a database operation (query or command). - """ - if not operation: - return None - - if not self._connection: - # TODO : change the exception raised here - raise ProgrammingError("Cursor is not connected") - - self._reset_result() - - stmt = operation - if params is not None: - pass - - self._result = CTaosInterface.query(self._connection._conn, stmt) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno == 0: - if CTaosInterface.fieldsCount(self._result) == 0: - self._affected_rows += CTaosInterface.affectedRows( - self._result) - return CTaosInterface.affectedRows(self._result) - else: - self._fields = CTaosInterface.useResult(self._result) - return self._handle_result() - else: - raise ProgrammingError(CTaosInterface.errStr(self._result), errno) - - def executemany(self, operation, seq_of_parameters): - """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. - """ - pass - - def fetchone(self): - """Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. - """ - pass - - def fetchmany(self): - pass - - def fetchall_row(self): - """Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation. - """ - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchRow( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - return list(map(tuple, zip(*buffer))) - - def fetchall(self): - if self._result is None or self._fields is None: - raise OperationalError("Invalid use of fetchall") - - buffer = [[] for i in range(len(self._fields))] - self._rowcount = 0 - while True: - block, num_of_fields = CTaosInterface.fetchBlock( - self._result, self._fields) - errno = CTaosInterface.libtaos.taos_errno(self._result) - if errno != 0: - raise ProgrammingError( - CTaosInterface.errStr( - self._result), errno) - if num_of_fields == 0: - break - self._rowcount += num_of_fields - for i in range(len(self._fields)): - buffer[i].extend(block[i]) - - return list(map(tuple, zip(*buffer))) - - def nextset(self): - """ - """ - pass - - def setinputsize(self, sizes): - pass - - def setutputsize(self, size, column=None): - pass - - def _reset_result(self): - """Reset the result to unused version. - """ - self._description = [] - self._rowcount = -1 - if self._result is not None: - CTaosInterface.freeResult(self._result) - self._result = None - self._fields = None - self._block = None - self._block_rows = -1 - self._block_iter = 0 - self._affected_rows = 0 - - def _handle_result(self): - """Handle the return result from query. - """ - self._description = [] - for ele in self._fields: - self._description.append( - (ele['name'], ele['type'], None, None, None, None, False)) - - return self._result diff --git a/src/connector/python/windows/python3/taos/dbapi.py b/src/connector/python/windows/python3/taos/dbapi.py deleted file mode 100644 index a29621f7a3..0000000000 --- a/src/connector/python/windows/python3/taos/dbapi.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Type Objects and Constructors. -""" - -import time -import datetime - - -class DBAPITypeObject(object): - def __init__(self, *values): - self.values = values - - def __com__(self, other): - if other in self.values: - return 0 - if other < self.values: - return 1 - else: - return -1 - - -Date = datetime.date -Time = datetime.time -Timestamp = datetime.datetime - - -def DataFromTicks(ticks): - return Date(*time.localtime(ticks)[:3]) - - -def TimeFromTicks(ticks): - return Time(*time.localtime(ticks)[3:6]) - - -def TimestampFromTicks(ticks): - return Timestamp(*time.localtime(ticks)[:6]) - - -Binary = bytes - -# STRING = DBAPITypeObject(*constants.FieldType.get_string_types()) -# BINARY = DBAPITypeObject(*constants.FieldType.get_binary_types()) -# NUMBER = BAPITypeObject(*constants.FieldType.get_number_types()) -# DATETIME = DBAPITypeObject(*constants.FieldType.get_timestamp_types()) -# ROWID = DBAPITypeObject() diff --git a/src/connector/python/windows/python3/taos/error.py b/src/connector/python/windows/python3/taos/error.py deleted file mode 100644 index 238b293a0b..0000000000 --- a/src/connector/python/windows/python3/taos/error.py +++ /dev/null @@ -1,66 +0,0 @@ -"""Python exceptions -""" - - -class Error(Exception): - def __init__(self, msg=None, errno=None): - self.msg = msg - self._full_msg = self.msg - self.errno = errno - - def __str__(self): - return self._full_msg - - -class Warning(Exception): - """Exception raised for important warnings like data truncations while inserting. - """ - pass - - -class InterfaceError(Error): - """Exception raised for errors that are related to the database interface rather than the database itself. - """ - pass - - -class DatabaseError(Error): - """Exception raised for errors that are related to the database. - """ - pass - - -class DataError(DatabaseError): - """Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range. - """ - pass - - -class OperationalError(DatabaseError): - """Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer - """ - pass - - -class IntegrityError(DatabaseError): - """Exception raised when the relational integrity of the database is affected. - """ - pass - - -class InternalError(DatabaseError): - """Exception raised when the database encounters an internal error. - """ - pass - - -class ProgrammingError(DatabaseError): - """Exception raised for programming errors. - """ - pass - - -class NotSupportedError(DatabaseError): - """Exception raised in case a method or database API was used which is not supported by the database,. - """ - pass diff --git a/src/connector/python/windows/python3/taos/subscription.py b/src/connector/python/windows/python3/taos/subscription.py deleted file mode 100644 index 270d9de092..0000000000 --- a/src/connector/python/windows/python3/taos/subscription.py +++ /dev/null @@ -1,57 +0,0 @@ -from .cinterface import CTaosInterface -from .error import * - - -class TDengineSubscription(object): - """TDengine subscription object - """ - - def __init__(self, sub): - self._sub = sub - - def consume(self): - """Consume rows of a subscription - """ - if self._sub is None: - raise OperationalError("Invalid use of consume") - - result, fields = CTaosInterface.consume(self._sub) - buffer = [[] for i in range(len(fields))] - while True: - block, num_of_fields = CTaosInterface.fetchBlock(result, fields) - if num_of_fields == 0: - break - for i in range(len(fields)): - buffer[i].extend(block[i]) - - self.fields = fields - return list(map(tuple, zip(*buffer))) - - def close(self, keepProgress=True): - """Close the Subscription. - """ - if self._sub is None: - return False - - CTaosInterface.unsubscribe(self._sub, keepProgress) - return True - - -if __name__ == '__main__': - from .connection import TDengineConnection - conn = TDengineConnection( - host="127.0.0.1", - user="root", - password="taosdata", - database="test") - - # Generate a cursor object to run SQL commands - sub = conn.subscribe(True, "test", "select * from meters;", 1000) - - for i in range(0, 10): - data = sub.consume() - for d in data: - print(d) - - sub.close() - conn.close() diff --git a/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md b/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md index b476c118a7..6845d091b5 100644 --- a/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md +++ b/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md @@ -8,8 +8,8 @@ 3. mkdir debug; cd debug; cmake ..; make ; sudo make install -4. pip install ../src/connector/python/linux/python2 ; pip3 install - ../src/connector/python/linux/python3 +4. pip install ../src/connector/python ; pip3 install + ../src/connector/python 5. pip install numpy; pip3 install numpy (numpy is required only if you need to run querySort.py) diff --git a/tests/Jenkinsfile b/tests/Jenkinsfile index e785c8e807..74cbc35208 100644 --- a/tests/Jenkinsfile +++ b/tests/Jenkinsfile @@ -21,7 +21,7 @@ def pre_test(){ cmake .. > /dev/null make > /dev/null make install > /dev/null - pip3 install ${WKC}/src/connector/python/linux/python3/ + pip3 install ${WKC}/src/connector/python ''' return 1 } diff --git a/tests/pytest/concurrent_inquiry.sh b/tests/pytest/concurrent_inquiry.sh index e5918792f4..6ac15fb46f 100755 --- a/tests/pytest/concurrent_inquiry.sh +++ b/tests/pytest/concurrent_inquiry.sh @@ -48,7 +48,7 @@ fi PYTHON_EXEC=python3.8 # First we need to set up a path for Python to find our own TAOS modules, so that "import" can work. -export PYTHONPATH=$(pwd)/../../src/connector/python/linux/python3:$(pwd) +export PYTHONPATH=$(pwd)/../../src/connector/python:$(pwd) # Then let us set up the library path so that our compiled SO file can be loaded by Python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR diff --git a/tests/pytest/crash_gen.sh b/tests/pytest/crash_gen.sh index 0af09634df..127e13c5be 100755 --- a/tests/pytest/crash_gen.sh +++ b/tests/pytest/crash_gen.sh @@ -48,7 +48,7 @@ fi PYTHON_EXEC=python3.8 # First we need to set up a path for Python to find our own TAOS modules, so that "import" can work. -export PYTHONPATH=$(pwd)/../../src/connector/python/linux/python3:$(pwd) +export PYTHONPATH=$(pwd)/../../src/connector/python:$(pwd) # Then let us set up the library path so that our compiled SO file can be loaded by Python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR diff --git a/tests/pytest/hivemq-extension-test.py b/tests/pytest/hivemq-extension-test.py index 3d0b1ef83f..9d293ea5ed 100644 --- a/tests/pytest/hivemq-extension-test.py +++ b/tests/pytest/hivemq-extension-test.py @@ -10,7 +10,7 @@ # ################################################################### # install pip -# pip install src/connector/python/linux/python2/ +# pip install src/connector/python/ import sys import os import os.path diff --git a/tests/pytest/perf_gen.sh b/tests/pytest/perf_gen.sh index fcedd2d407..d28b5422f8 100755 --- a/tests/pytest/perf_gen.sh +++ b/tests/pytest/perf_gen.sh @@ -48,7 +48,7 @@ fi PYTHON_EXEC=python3.8 # First we need to set up a path for Python to find our own TAOS modules, so that "import" can work. -export PYTHONPATH=$(pwd)/../../src/connector/python/linux/python3:$(pwd) +export PYTHONPATH=$(pwd)/../../src/connector/python:$(pwd) # Then let us set up the library path so that our compiled SO file can be loaded by Python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR diff --git a/tests/pytest/simpletest_no_sudo.sh b/tests/pytest/simpletest_no_sudo.sh index 61faf3df52..36edfc027f 100755 --- a/tests/pytest/simpletest_no_sudo.sh +++ b/tests/pytest/simpletest_no_sudo.sh @@ -4,7 +4,7 @@ # 2. No files are needed outside the development tree, everything is done in the local source code directory # First we need to set up a path for Python to find our own TAOS modules, so that "import" can work. -export PYTHONPATH=$(pwd)/../../src/connector/python/linux/python3 +export PYTHONPATH=$(pwd)/../../src/connector/python # Then let us set up the library path so that our compiled SO file can be loaded by Python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/../../build/build/lib diff --git a/tests/pytest/test.py b/tests/pytest/test.py index c7781f2087..65abd3ef93 100644 --- a/tests/pytest/test.py +++ b/tests/pytest/test.py @@ -10,7 +10,7 @@ # ################################################################### # install pip -# pip install src/connector/python/linux/python2/ +# pip install src/connector/python/ # -*- coding: utf-8 -*- import sys diff --git a/tests/pytest/test.sh b/tests/pytest/test.sh index fbb9ba9879..4e74341f70 100755 --- a/tests/pytest/test.sh +++ b/tests/pytest/test.sh @@ -13,7 +13,7 @@ else fi TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib -export PYTHONPATH=$(pwd)/../../src/connector/python/linux/python3 +export PYTHONPATH=$(pwd)/../../src/connector/python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR if [[ "$1" == *"test.py"* ]]; then diff --git a/tests/pytest/testCompress.py b/tests/pytest/testCompress.py index 0f5d9ef3b1..1ad032f05f 100644 --- a/tests/pytest/testCompress.py +++ b/tests/pytest/testCompress.py @@ -10,7 +10,7 @@ # ################################################################### # install pip -# pip install src/connector/python/linux/python2/ +# pip install src/connector/python/ # -*- coding: utf-8 -*- import sys diff --git a/tests/pytest/testMinTablesPerVnode.py b/tests/pytest/testMinTablesPerVnode.py index 91cea833e7..a111113c07 100644 --- a/tests/pytest/testMinTablesPerVnode.py +++ b/tests/pytest/testMinTablesPerVnode.py @@ -10,7 +10,7 @@ # ################################################################### # install pip -# pip install src/connector/python/linux/python2/ +# pip install src/connector/python/ # -*- coding: utf-8 -*- import sys diff --git a/tests/pytest/testNoCompress.py b/tests/pytest/testNoCompress.py index e3b40b4426..d41055c755 100644 --- a/tests/pytest/testNoCompress.py +++ b/tests/pytest/testNoCompress.py @@ -10,7 +10,7 @@ # ################################################################### # install pip -# pip install src/connector/python/linux/python2/ +# pip install src/connector/python/ # -*- coding: utf-8 -*- import sys From 24751e99fec9d7362c6519b589b2423bc48b051a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 28 May 2021 05:10:47 +0800 Subject: [PATCH 28/80] [TD-2570]: --- src/client/src/tscSQLParser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 314d9c4541..8f726e17b5 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -921,6 +921,9 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS if (getColumnIndexByName(pCmd, col, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); } + if (index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); + } pQueryInfo->sessionWindow.primaryColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; From f8f091b5c7025839541f6228c7a637ab92f43552 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Fri, 28 May 2021 10:12:46 +0800 Subject: [PATCH 29/80] [TD-4376] adding test case --- tests/pytest/fulltest.sh | 2 +- tests/pytest/tag_lite/drop_auto_create.py | 47 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/pytest/tag_lite/drop_auto_create.py diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index d8e2a31e70..a7cbbf42c1 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -332,5 +332,5 @@ python3 ./test.py -f tag_lite/alter_tag.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py - +python3 ./test.py -f tag_lite/drop_auto_create.py #======================p4-end=============== diff --git a/tests/pytest/tag_lite/drop_auto_create.py b/tests/pytest/tag_lite/drop_auto_create.py new file mode 100644 index 0000000000..86ec65914a --- /dev/null +++ b/tests/pytest/tag_lite/drop_auto_create.py @@ -0,0 +1,47 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + tdSql.execute('create table m1(ts timestamp, k int) tags(a binary(12), b int, c double);') + tdSql.execute('insert into tm0 using m1(b,c) tags(1, 99) values(now, 1);') + tdSql.execute('insert into tm1 using m1(b,c) tags(2, 100) values(now, 2);') + tdLog.info("2 rows inserted") + tdSql.query('select * from m1;') + tdSql.checkRows(2) + tdSql.execute('select *,tbname from m1;') + tdSql.execute("drop table tm0; ") + tdSql.query('select * from m1') + tdSql.checkRows(1) + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From 6bd6001fe96ff80f12add4246fc4d31293f1731f Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Fri, 28 May 2021 10:43:15 +0800 Subject: [PATCH 30/80] [TD-4376] modify execute to query for select --- tests/pytest/tag_lite/drop_auto_create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/tag_lite/drop_auto_create.py b/tests/pytest/tag_lite/drop_auto_create.py index 86ec65914a..f89b41008b 100644 --- a/tests/pytest/tag_lite/drop_auto_create.py +++ b/tests/pytest/tag_lite/drop_auto_create.py @@ -31,7 +31,7 @@ class TDTestCase: tdLog.info("2 rows inserted") tdSql.query('select * from m1;') tdSql.checkRows(2) - tdSql.execute('select *,tbname from m1;') + tdSql.query('select *,tbname from m1;') tdSql.execute("drop table tm0; ") tdSql.query('select * from m1') tdSql.checkRows(1) From afb0d66d0368e0dc996d3f521192be1393406d8b Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 28 May 2021 10:47:06 +0800 Subject: [PATCH 31/80] [TD-4382]: taosdemo query result file is null. (#6259) * [TD-4382]: taosdemo query result file is null. * modify CI Co-authored-by: Shuduo Sang Co-authored-by: liuyq-617 --- Jenkinsfile | 2 +- src/kit/taosdemo/taosdemo.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b48dca0241..6b6ef420e6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -94,7 +94,7 @@ def pre_test(){ make > /dev/null make install > /dev/null cd ${WKC}/tests - pip3 install ${WKC}/src/connector/python + pip3 install ${WKC}/src/connector/python/ ''' return 1 } diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 29a1f7f1f9..3c528ab26f 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -6261,7 +6261,7 @@ static void *specifiedTableQuery(void *sarg) { uint64_t lastPrintTime = taosGetTimestampMs(); uint64_t startTs = taosGetTimestampMs(); - if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq] != NULL) { + if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] != '\0') { sprintf(pThreadInfo->filePath, "%s-%d", g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], pThreadInfo->threadID); @@ -6362,7 +6362,7 @@ static void *superTableQuery(void *sarg) { for (int j = 0; j < g_queryInfo.superQueryInfo.sqlCount; j++) { memset(sqlstr,0,sizeof(sqlstr)); replaceChildTblName(g_queryInfo.superQueryInfo.sql[j], sqlstr, i); - if (g_queryInfo.superQueryInfo.result[j] != NULL) { + if (g_queryInfo.superQueryInfo.result[j][0] != '\0') { sprintf(pThreadInfo->filePath, "%s-%d", g_queryInfo.superQueryInfo.result[j], pThreadInfo->threadID); @@ -6796,7 +6796,7 @@ static void *specifiedSubscribe(void *sarg) { "taosdemo-subscribe-%"PRIu64"-%d", pThreadInfo->querySeq, pThreadInfo->threadID); - if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq] != NULL) { + if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] != '\0') { sprintf(pThreadInfo->filePath, "%s-%d", g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], pThreadInfo->threadID); From 398397bcaaa082b004b0b359fcdbfe849e57b7de Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Fri, 28 May 2021 11:10:20 +0800 Subject: [PATCH 32/80] change to asynchrous call mode with support last time query --- src/client/src/tscStream.c | 127 +++++++++++++++++++++---------------- src/cq/src/cqMain.c | 7 +- 2 files changed, 79 insertions(+), 55 deletions(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9094f95dfc..7e6132b7c8 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -25,6 +25,7 @@ #include "tutil.h" #include "tscProfile.h" +#include "tscSubquery.h" static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOfRows); static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOfRows); @@ -538,31 +539,7 @@ static int64_t tscGetLaunchTimestamp(const SSqlStream *pStream) { return (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? timer / 1000L : timer; } -///* -// -// get tableName last row time, if have error return zero. -// -static int64_t tscGetStreamTableLastTime(SSqlObj* pSql, SSqlStream* pStream, const char* tableName) { - int64_t last_time = 0; - char sql[128] = ""; - sprintf(sql, "select last_row(*) from %s;", tableName); - // query sql - TAOS_RES* res = taos_query(pSql->pTscObj, sql); - if(res == NULL) - return 0; - - // only fetch one row - TAOS_ROW row = taos_fetch_row(res); - if( row && row[0] ) { - last_time = *((int64_t*)row[0]); - } - - // free and return - taos_free_result(res); - return last_time; -} -//*/ static void tscCreateStream(void *param, TAOS_RES *res, int code) { SSqlStream* pStream = (SSqlStream*)param; SSqlObj* pSql = pStream->pSql; @@ -596,15 +573,12 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) { pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, pStream->stime); - // set output table last record time to stime if have, why do this, because continue with last brea + // set stime with ltime if ltime > stime const char* dstTable = pStream->dstTable? pStream->dstTable: ""; - int64_t last_time = tscGetStreamTableLastTime(pSql, pStream, dstTable); - pStream->ltime = last_time; - tscDebug(" CQ get table=%s lasttime=%"PRId64" end.", dstTable, last_time); - if(last_time > 0 && last_time > pStream->stime) { - // can replace stime with last row time - tscDebug(" CQ set table %s stime=%"PRId64" with lasttime=%"PRId64" ", dstTable, pStream->stime, last_time); - pStream->stime = last_time; + tscDebug(" CQ table=%s ltime is %"PRId64, dstTable, pStream->ltime); + if(pStream->ltime > 0 && pStream->ltime > pStream->stime) { + tscWarn(" CQ set stream %s stime=%"PRId64" replace with ltime=%"PRId64" ", dstTable, pStream->stime, pStream->ltime); + pStream->stime = pStream->ltime; } int64_t starttime = tscGetLaunchTimestamp(pStream); @@ -622,25 +596,66 @@ void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable) { pStream->dstTable = dstTable; } -// already run on another thread -void tscCreateStreamThread(SSchedMsg* pMsg) { - tscDebug(" new thread Sched call tscCreateStream begin..."); - tscCreateStream(pMsg->ahandle, NULL, 0); - tscDebug(" new thread Sched call tscCreateStream end."); +// fetchFp call back +void fetchFpStreamLastRow(void* param ,TAOS_RES* res, int num) { + SSqlStream* pStream = (SSqlStream*)param; + SSqlObj* pSql = res; + + // get row data set to ltime + tscSetSqlOwner(pSql); + TAOS_ROW row = doSetResultRowData(pSql); + if( row && row[0] ) { + pStream->ltime = *((int64_t*)row[0]); + const char* dstTable = pStream->dstTable? pStream->dstTable: ""; + tscDebug(" CQ stream table=%s last row time=%"PRId64" .", dstTable, pStream->ltime); + } + tscClearSqlOwner(pSql); + + // no condition call + tscCreateStream(param, pStream->pSql, TSDB_CODE_SUCCESS); + taos_free_result(res); +} + +// fp callback +void fpStreamLastRow(void* param ,TAOS_RES* res, int code) { + // check result successful + if (code != TSDB_CODE_SUCCESS) { + tscCreateStream(param, res, TSDB_CODE_SUCCESS); + taos_free_result(res); + return ; + } + + // asynchronous fetch last row data + taos_fetch_rows_a(res, fetchFpStreamLastRow, param); +} + +void cbParseSql(void* param, TAOS_RES* res, int code) { + // check result successful + SSqlStream* pStream = (SSqlStream*)param; + SSqlObj* pSql = pStream->pSql; + SSqlCmd* pCmd = &pSql->cmd; + if (code != TSDB_CODE_SUCCESS) { + pSql->res.code = code; + tscDebug("0x%"PRIx64" open stream parse sql failed, sql:%s, reason:%s, code:%s", pSql->self, pSql->sqlstr, pCmd->payload, tstrerror(code)); + pStream->fp(pStream->param, NULL, NULL); + return; + } + + // check dstTable valid + if(pStream->dstTable == NULL || strlen(pStream->dstTable) == 0) { + tscDebug(" cbParseSql dstTable is empty."); + tscCreateStream(param, res, code); + return ; + } + + // query stream last row time async + char sql[128] = ""; + sprintf(sql, "select last_row(*) from %s;", pStream->dstTable); + taos_query_a(pSql->pTscObj, sql, fpStreamLastRow, param); return ; } -// parsesql async response return and change run thread -void tsParseSqlRet(void* param, TAOS_RES* res, int code) { - SSchedMsg schedMsg = { 0 }; - schedMsg.fp = tscCreateStreamThread; - schedMsg.ahandle = param; - schedMsg.thandle = res; - schedMsg.msg = NULL; - taosScheduleTask(tscQhandle, &schedMsg); -} - -TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), +TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* dstTable, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *)) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) return NULL; @@ -671,6 +686,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p pSql->pStream = pStream; pSql->param = pStream; pSql->maxRetry = TSDB_MAX_REPLICA; + tscSetStreamDestTable(pStream, dstTable); pSql->sqlstr = calloc(1, strlen(sqlstr) + 1); if (pSql->sqlstr == NULL) { @@ -685,16 +701,16 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p tscDebugL("%p SQL: %s", pSql, pSql->sqlstr); tsem_init(&pSql->rspSem, 0, 0); - pSql->fp = tsParseSqlRet; - pSql->fetchFp = tsParseSqlRet; + pSql->fp = cbParseSql; + pSql->fetchFp = cbParseSql; registerSqlObj(pSql); - + int32_t code = tsParseSql(pSql, true); if (code == TSDB_CODE_SUCCESS) { - tscCreateStream(pStream, pSql, code); + cbParseSql(pStream, pSql, code); } else if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { - tscDebug(" cq parseSql IN Process pass. "); + tscDebug(" CQ taso_open_stream IN Process. sql=%s", sqlstr); } else { tscError("0x%"PRIx64" open stream failed, sql:%s, code:%s", pSql->self, sqlstr, tstrerror(code)); taosReleaseRef(tscObjRef, pSql->self); @@ -705,6 +721,11 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p return pStream; } +TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), + int64_t stime, void *param, void (*callback)(void *)) { + return taos_open_stream_withname(taos, "", sqlstr, fp, stime, param, callback); +} + void taos_close_stream(TAOS_STREAM *handle) { SSqlStream *pStream = (SSqlStream *)handle; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 5d5d5f339e..ee4be02b90 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -437,6 +437,10 @@ static void cqProcessCreateTimer(void *param, void *tmrId) { taosReleaseRef(cqObjRef, (int64_t)param); } +// inner implement in tscStream.c +TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* desName, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), + int64_t stime, void *param, void (*callback)(void *)); + static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { pObj->pContext = pContext; @@ -449,11 +453,10 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { pObj->tmrId = 0; if (pObj->pStream == NULL) { - pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, INT64_MIN, (void *)pObj->rid, NULL); + pObj->pStream = taos_open_stream_withname(pContext->dbConn, pObj->dstTable, pObj->sqlStr, cqProcessStreamRes, INT64_MIN, (void *)pObj->rid, NULL); // TODO the pObj->pStream may be released if error happens if (pObj->pStream) { - tscSetStreamDestTable(pObj->pStream, pObj->dstTable); pContext->num++; cDebug("vgId:%d, id:%d CQ:%s is opened", pContext->vgId, pObj->tid, pObj->sqlStr); } else { From c7764d44780c89e7b1f46c80e4e96dfeea3068f2 Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Fri, 28 May 2021 13:00:12 +0800 Subject: [PATCH 33/80] ltime > stime to do replace --- src/client/src/tscStream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 7e6132b7c8..2226c3d95d 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -576,7 +576,7 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) { // set stime with ltime if ltime > stime const char* dstTable = pStream->dstTable? pStream->dstTable: ""; tscDebug(" CQ table=%s ltime is %"PRId64, dstTable, pStream->ltime); - if(pStream->ltime > 0 && pStream->ltime > pStream->stime) { + if(pStream->ltime > pStream->stime) { tscWarn(" CQ set stream %s stime=%"PRId64" replace with ltime=%"PRId64" ", dstTable, pStream->stime, pStream->ltime); pStream->stime = pStream->ltime; } From 5bc050ccdf122e48d9915ace7a357e898a58be03 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 28 May 2021 14:19:16 +0800 Subject: [PATCH 34/80] TD-4393 --- src/vnode/src/vnodeMgmt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vnode/src/vnodeMgmt.c b/src/vnode/src/vnodeMgmt.c index 32f9532138..7e6022fc87 100644 --- a/src/vnode/src/vnodeMgmt.c +++ b/src/vnode/src/vnodeMgmt.c @@ -91,18 +91,18 @@ static void vnodeIncRef(void *ptNode) { } void *vnodeAcquire(int32_t vgId) { - SVnodeObj **ppVnode = NULL; + SVnodeObj *pVnode = NULL; if (tsVnodesHash != NULL) { - ppVnode = taosHashGetClone(tsVnodesHash, &vgId, sizeof(int32_t), vnodeIncRef, NULL, sizeof(void *)); + taosHashGetClone(tsVnodesHash, &vgId, sizeof(int32_t), vnodeIncRef, &pVnode, sizeof(void *)); } - if (ppVnode == NULL || *ppVnode == NULL) { + if (pVnode == NULL) { terrno = TSDB_CODE_VND_INVALID_VGROUP_ID; vDebug("vgId:%d, not exist", vgId); return NULL; } - return *ppVnode; + return pVnode; } void vnodeRelease(void *vparam) { From f382d2b9dd18f296807c35b1e86fef095db92d1c Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 28 May 2021 15:16:20 +0800 Subject: [PATCH 35/80] fix bug --- src/client/src/tscParseInsert.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index f54237306c..f1dd8975dc 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -769,6 +769,10 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC index = 0; sToken = tStrGetToken(sql, &index, false); + if (sToken.type == TK_ILLEGAL) { + return tscSQLSyntaxErrMsg(pCmd->payload, "unrecognized token", sToken.z); + } + if (sToken.type == TK_RP) { break; } From 1465fd9cfc7d35125401e96a75ffcd63f988f12e Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Fri, 28 May 2021 16:50:43 +0800 Subject: [PATCH 36/80] Fix test failure --- tests/pytest/table/tablename-boundary.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/pytest/table/tablename-boundary.py b/tests/pytest/table/tablename-boundary.py index 8766a9d4a9..dc22c3343b 100644 --- a/tests/pytest/table/tablename-boundary.py +++ b/tests/pytest/table/tablename-boundary.py @@ -74,9 +74,7 @@ class TDTestCase: tdSql.execute("insert into %s.%s using %s.%s tags(2) values(%d, 1)(%d, 2)(%d, 3)" % (db_name, tb_name2, db_name, stb_name, self.ts, self.ts + 1, self.ts + 2)) tdSql.query("show %s.tables" % db_name) - tdSql.checkRows(2) - tdSql.checkData(0, 0, tb_name1) - tdSql.checkData(1, 0, tb_name2) + tdSql.checkRows(2) tdSql.query("select * from %s.%s" % (db_name, stb_name)) tdSql.checkRows(6) From 72e2c66d86a6f37904d552422b310f23c456d115 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 28 May 2021 17:59:32 +0800 Subject: [PATCH 37/80] [TD-4068]: taosdemo support stmt. (#6270) * [TD-4068]: taosdemo support stmt. for easy merge purpose. disabled in master. * fix clang compile error. --- src/kit/taosdemo/taosdemo.c | 1469 ++++++++++++++++++++++++----------- 1 file changed, 1020 insertions(+), 449 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 3c528ab26f..70ddbacf44 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -19,6 +19,7 @@ */ #include +#include #define _GNU_SOURCE #define CURL_STATICLIB @@ -52,6 +53,8 @@ #include "taoserror.h" #include "tutil.h" +#define STMT_IFACE_ENABLED 0 + #define REQ_EXTRA_BUF_LEN 1024 #define RESP_BUF_LEN 4096 @@ -61,6 +64,8 @@ extern char configDir[]; #define QUERY_JSON_NAME "query.json" #define SUBSCRIBE_JSON_NAME "subscribe.json" +#define STR_INSERT_INTO "INSERT INTO " + enum TEST_MODE { INSERT_TEST, // 0 QUERY_TEST, // 1 @@ -70,6 +75,8 @@ enum TEST_MODE { #define MAX_RECORDS_PER_REQ 32766 +#define HEAD_BUFF_LEN 1024*24 // 16*1024 + (192+32)*2 + insert into .. + #define MAX_SQL_SIZE 65536 #define BUFFER_SIZE (65536*2) #define COND_BUF_LEN BUFFER_SIZE - 30 @@ -120,17 +127,24 @@ enum enumSYNC_MODE { MODE_BUT }; +enum enum_TAOS_INTERFACE { + TAOSC_IFACE, + REST_IFACE, + STMT_IFACE, + INTERFACE_BUT +}; + typedef enum enumQUERY_CLASS { SPECIFIED_CLASS, STABLE_CLASS, CLASS_BUT } QUERY_CLASS; -typedef enum enum_INSERT_MODE { +typedef enum enum_PROGRESSIVE_OR_INTERLACE { PROGRESSIVE_INSERT_MODE, INTERLACE_INSERT_MODE, INVALID_INSERT_MODE -} INSERT_MODE; +} PROG_OR_INTERLACE_MODE; typedef enum enumQUERY_TYPE { NO_INSERT_TYPE, @@ -196,6 +210,7 @@ typedef struct SArguments_S { uint32_t test_mode; char * host; uint16_t port; + uint16_t iface; char * user; char * password; char * database; @@ -217,13 +232,13 @@ typedef struct SArguments_S { uint32_t num_of_threads; uint64_t insert_interval; int64_t query_times; - uint64_t interlace_rows; - uint64_t num_of_RPR; // num_of_records_per_req + uint32_t interlace_rows; + uint32_t num_of_RPR; // num_of_records_per_req uint64_t max_sql_len; int64_t num_of_tables; int64_t num_of_DPT; int abort; - int disorderRatio; // 0: no disorder, >0: x% + uint32_t disorderRatio; // 0: no disorder, >0: x% int disorderRange; // ms or us by database precision uint32_t method_of_delete; char ** arg_list; @@ -246,12 +261,12 @@ typedef struct SSuperTable_S { uint8_t autoCreateTable; // 0: create sub table, 1: auto create sub table char childTblPrefix[MAX_TB_NAME_SIZE]; char dataSource[MAX_TB_NAME_SIZE+1]; // rand_gen or sample - char insertMode[MAX_TB_NAME_SIZE]; // taosc, rest + uint16_t iface; // 0: taosc, 1: rest, 2: stmt int64_t childTblLimit; uint64_t childTblOffset; // int multiThreadWriteOneTbl; // 0: no, 1: yes - uint64_t interlaceRows; // + uint32_t interlaceRows; // int disorderRatio; // 0: no disorder, >0: x% int disorderRange; // ms or us by database precision uint64_t maxSqlLen; // @@ -364,7 +379,7 @@ typedef struct SDbs_S { typedef struct SpecifiedQueryInfo_S { uint64_t queryInterval; // 0: unlimit > 0 loop/s uint32_t concurrent; - int sqlCount; + uint64_t sqlCount; uint32_t asyncMode; // 0: sync, 1: async uint64_t subscribeInterval; // ms uint64_t queryTimes; @@ -392,7 +407,7 @@ typedef struct SuperQueryInfo_S { uint64_t queryTimes; int64_t childTblCount; char childTblPrefix[MAX_TB_NAME_SIZE]; - int sqlCount; + uint64_t sqlCount; char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN+1]; int resubAfterConsume; @@ -420,6 +435,7 @@ typedef struct SQueryMetaInfo_S { typedef struct SThreadInfo_S { TAOS * taos; + TAOS_STMT *stmt; int threadID; char db_name[MAX_DB_NAME_SIZE+1]; uint32_t time_precision; @@ -434,6 +450,7 @@ typedef struct SThreadInfo_S { char* cols; bool use_metric; SSuperTable* superTblInfo; + char *buffer; // sql cmd buffer // for async insert tsem_t lock_sem; @@ -541,7 +558,7 @@ static int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet); static int postProceSql(char *host, struct sockaddr_in *pServAddr, uint16_t port, char* sqlstr, threadInfo *pThreadInfo); static int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, - int disorderRatio, int disorderRange); + int disorderRatio, int disorderRange); /* ************ Global variables ************ */ @@ -557,6 +574,7 @@ SArguments g_args = { 0, // test_mode "127.0.0.1", // host 6030, // port + TAOSC_IFACE, // iface "root", // user #ifdef _TD_POWER_ "powerdb", // password @@ -673,6 +691,8 @@ static void printHelp() { "The host to connect to TDengine. Default is localhost."); printf("%s%s%s%s\n", indent, "-p", indent, "The TCP/IP port number to use for the connection. Default is 0."); + printf("%s%s%s%s\n", indent, "-I", indent, + "The interface (taosc, rest, and stmt) taosdemo uses. Default is 'taosc'."); printf("%s%s%s%s\n", indent, "-d", indent, "Destination database. Default is 'test'."); printf("%s%s%s%s\n", indent, "-a", indent, @@ -761,6 +781,23 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { exit(EXIT_FAILURE); } arguments->port = atoi(argv[++i]); + } else if (strcmp(argv[i], "-I") == 0) { + if (argc == i+1) { + printHelp(); + errorPrint("%s", "\n\t-I need a valid string following!\n"); + exit(EXIT_FAILURE); + } + ++i; + if (0 == strcasecmp(argv[i], "taosc")) { + arguments->iface = TAOSC_IFACE; + } else if (0 == strcasecmp(argv[i], "rest")) { + arguments->iface = REST_IFACE; + } else if (0 == strcasecmp(argv[i], "stmt")) { + arguments->iface = STMT_IFACE; + } else { + errorPrint("%s", "\n\t-I need a valid string following!\n"); + exit(EXIT_FAILURE); + } } else if (strcmp(argv[i], "-u") == 0) { if (argc == i+1) { printHelp(); @@ -897,6 +934,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { && strcasecmp(argv[i], "BIGINT") && strcasecmp(argv[i], "DOUBLE") && strcasecmp(argv[i], "BINARY") + && strcasecmp(argv[i], "TIMESTAMP") && strcasecmp(argv[i], "NCHAR")) { printHelp(); errorPrint("%s", "-b: Invalid data_type!\n"); @@ -918,6 +956,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { && strcasecmp(token, "BIGINT") && strcasecmp(token, "DOUBLE") && strcasecmp(token, "BINARY") + && strcasecmp(token, "TIMESTAMP") && strcasecmp(token, "NCHAR")) { printHelp(); free(g_dupstr); @@ -1019,6 +1058,19 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { } } + int columnCount; + for (columnCount = 0; columnCount < MAX_NUM_DATATYPE; columnCount ++) { + if (g_args.datatype[columnCount] == NULL) { + break; + } + } + + if (0 == columnCount) { + perror("data type error!"); + exit(-1); + } + g_args.num_of_CPR = columnCount; + if (((arguments->debug_print) && (arguments->metaFile == NULL)) || arguments->verbose_print) { printf("###################################################################\n"); @@ -1028,7 +1080,8 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { arguments->port ); printf("# User: %s\n", arguments->user); printf("# Password: %s\n", arguments->password); - printf("# Use metric: %s\n", arguments->use_metric ? "true" : "false"); + printf("# Use metric: %s\n", + arguments->use_metric ? "true" : "false"); if (*(arguments->datatype)) { printf("# Specified data type: "); for (int i = 0; i < MAX_NUM_DATATYPE; i++) @@ -1040,7 +1093,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { } printf("# Insertion interval: %"PRIu64"\n", arguments->insert_interval); - printf("# Number of records per req: %"PRIu64"\n", + printf("# Number of records per req: %u\n", arguments->num_of_RPR); printf("# Max SQL length: %"PRIu64"\n", arguments->max_sql_len); @@ -1068,8 +1121,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { } static bool getInfoFromJsonFile(char* file); -//static int generateOneRowDataForStb(SSuperTable* stbInfo); -//static int getDataIntoMemForStb(SSuperTable* stbInfo); static void init_rand_data(); static void tmfclose(FILE *fp) { if (NULL != fp) { @@ -1088,7 +1139,7 @@ static int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) { TAOS_RES *res = NULL; int32_t code = -1; - for (i = 0; i < 5; i++) { + for (i = 0; i < 5 /* retry */; i++) { if (NULL != res) { taos_free_result(res); res = NULL; @@ -1104,7 +1155,8 @@ static int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) { verbosePrint("%s() LN%d - command: %s\n", __func__, __LINE__, command); if (code != 0) { if (!quiet) { - errorPrint("Failed to execute %s, reason: %s\n", command, taos_errstr(res)); + errorPrint("Failed to execute %s, reason: %s\n", + command, taos_errstr(res)); } taos_free_result(res); //taos_close(taos); @@ -1320,6 +1372,8 @@ static void init_rand_data() { static int printfInsertMeta() { SHOW_PARSE_RESULT_START(); + printf("interface: \033[33m%s\033[0m\n", + (g_args.iface==TAOSC_IFACE)?"taosc":(g_args.iface==REST_IFACE)?"rest":"stmt"); printf("host: \033[33m%s:%u\033[0m\n", g_Dbs.host, g_Dbs.port); printf("user: \033[33m%s\033[0m\n", g_Dbs.user); @@ -1331,7 +1385,7 @@ static int printfInsertMeta() { g_Dbs.threadCountByCreateTbl); printf("top insert interval: \033[33m%"PRIu64"\033[0m\n", g_args.insert_interval); - printf("number of records per req: \033[33m%"PRIu64"\033[0m\n", + printf("number of records per req: \033[33m%u\033[0m\n", g_args.num_of_RPR); printf("max sql length: \033[33m%"PRIu64"\033[0m\n", g_args.max_sql_len); @@ -1437,8 +1491,9 @@ static int printfInsertMeta() { g_Dbs.db[i].superTbls[j].childTblPrefix); printf(" dataSource: \033[33m%s\033[0m\n", g_Dbs.db[i].superTbls[j].dataSource); - printf(" insertMode: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].insertMode); + printf(" iface: \033[33m%s\033[0m\n", + (g_Dbs.db[i].superTbls[j].iface==TAOSC_IFACE)?"taosc": + (g_Dbs.db[i].superTbls[j].iface==REST_IFACE)?"rest":"stmt"); if (g_Dbs.db[i].superTbls[j].childTblLimit > 0) { printf(" childTblLimit: \033[33m%"PRId64"\033[0m\n", g_Dbs.db[i].superTbls[j].childTblLimit); @@ -1456,7 +1511,7 @@ static int printfInsertMeta() { printf(" multiThreadWriteOneTbl: \033[33myes\033[0m\n"); } */ - printf(" interlaceRows: \033[33m%"PRIu64"\033[0m\n", + printf(" interlaceRows: \033[33m%u\033[0m\n", g_Dbs.db[i].superTbls[j].interlaceRows); if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { @@ -1534,7 +1589,7 @@ static void printfInsertMetaToFile(FILE* fp) { fprintf(fp, "resultFile: %s\n", g_Dbs.resultFile); fprintf(fp, "thread num of insert data: %d\n", g_Dbs.threadCount); fprintf(fp, "thread num of create table: %d\n", g_Dbs.threadCountByCreateTbl); - fprintf(fp, "number of records per req: %"PRIu64"\n", g_args.num_of_RPR); + fprintf(fp, "number of records per req: %u\n", g_args.num_of_RPR); fprintf(fp, "max sql length: %"PRIu64"\n", g_args.max_sql_len); fprintf(fp, "database count: %d\n", g_Dbs.dbCount); @@ -1626,11 +1681,12 @@ static void printfInsertMetaToFile(FILE* fp) { g_Dbs.db[i].superTbls[j].childTblPrefix); fprintf(fp, " dataSource: %s\n", g_Dbs.db[i].superTbls[j].dataSource); - fprintf(fp, " insertMode: %s\n", - g_Dbs.db[i].superTbls[j].insertMode); + fprintf(fp, " iface: %s\n", + (g_Dbs.db[i].superTbls[j].iface==TAOSC_IFACE)?"taosc": + (g_Dbs.db[i].superTbls[j].iface==REST_IFACE)?"rest":"stmt"); fprintf(fp, " insertRows: %"PRId64"\n", g_Dbs.db[i].superTbls[j].insertRows); - fprintf(fp, " interlace rows: %"PRIu64"\n", + fprintf(fp, " interlace rows: %u\n", g_Dbs.db[i].superTbls[j].interlaceRows); if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { fprintf(fp, " stable insert interval: %"PRIu64"\n", @@ -1643,7 +1699,7 @@ static void printfInsertMetaToFile(FILE* fp) { fprintf(fp, " multiThreadWriteOneTbl: yes\n"); } */ - fprintf(fp, " interlaceRows: %"PRIu64"\n", + fprintf(fp, " interlaceRows: %u\n", g_Dbs.db[i].superTbls[j].interlaceRows); fprintf(fp, " disorderRange: %d\n", g_Dbs.db[i].superTbls[j].disorderRange); @@ -1719,7 +1775,7 @@ static void printfQueryMeta() { if ((SUBSCRIBE_TEST == g_args.test_mode) || (QUERY_TEST == g_args.test_mode)) { printf("specified table query info: \n"); - printf("sqlCount: \033[33m%d\033[0m\n", + printf("sqlCount: \033[33m%"PRIu64"\033[0m\n", g_queryInfo.specifiedQueryInfo.sqlCount); if (g_queryInfo.specifiedQueryInfo.sqlCount > 0) { printf("specified tbl query times:\n"); @@ -1739,15 +1795,15 @@ static void printfQueryMeta() { printf("keepProgress: \033[33m%d\033[0m\n", g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); - for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { - printf(" sql[%d]: \033[33m%s\033[0m\n", + for (uint64_t i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { + printf(" sql[%"PRIu64"]: \033[33m%s\033[0m\n", i, g_queryInfo.specifiedQueryInfo.sql[i]); } printf("\n"); } printf("super table query info:\n"); - printf("sqlCount: \033[33m%d\033[0m\n", + printf("sqlCount: \033[33m%"PRIu64"\033[0m\n", g_queryInfo.superQueryInfo.sqlCount); if (g_queryInfo.superQueryInfo.sqlCount > 0) { @@ -2803,7 +2859,7 @@ static int createDatabasesAndStables() { int validStbCount = 0; - for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { sprintf(command, "describe %s.%s;", g_Dbs.db[i].dbName, g_Dbs.db[i].superTbls[j].sTblName); ret = queryDbExec(taos, command, NO_INSERT_TYPE, true); @@ -2813,7 +2869,7 @@ static int createDatabasesAndStables() { &g_Dbs.db[i].superTbls[j]); if (0 != ret) { - errorPrint("create super table %d failed!\n\n", j); + errorPrint("create super table %"PRIu64" failed!\n\n", j); continue; } } @@ -2841,7 +2897,7 @@ static void* createTable(void *sarg) threadInfo *pThreadInfo = (threadInfo *)sarg; SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - int64_t lastPrintTime = taosGetTimestampMs(); + uint64_t lastPrintTime = taosGetTimestampMs(); int buff_len; buff_len = BUFFER_SIZE / 8; @@ -2915,7 +2971,7 @@ static void* createTable(void *sarg) return NULL; } - int64_t currentPrintTime = taosGetTimestampMs(); + uint64_t currentPrintTime = taosGetTimestampMs(); if (currentPrintTime - lastPrintTime > 30*1000) { printf("thread[%d] already create %"PRIu64" - %"PRIu64" tables\n", pThreadInfo->threadID, pThreadInfo->start_table_from, i); @@ -2934,11 +2990,11 @@ static void* createTable(void *sarg) } static int startMultiThreadCreateChildTable( - char* cols, int threads, uint64_t startFrom, int64_t ntables, + char* cols, int threads, uint64_t tableFrom, int64_t ntables, char* db_name, SSuperTable* superTblInfo) { pthread_t *pids = malloc(threads * sizeof(pthread_t)); - threadInfo *infos = malloc(threads * sizeof(threadInfo)); + threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); if ((NULL == pids) || (NULL == infos)) { printf("malloc failed\n"); @@ -2978,10 +3034,10 @@ static int startMultiThreadCreateChildTable( return -1; } - pThreadInfo->start_table_from = startFrom; + pThreadInfo->start_table_from = tableFrom; pThreadInfo->ntables = iend_table_to = i < b ? startFrom + a : startFrom + a - 1; - startFrom = pThreadInfo->end_table_to + 1; + pThreadInfo->end_table_to = i < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; pThreadInfo->use_metric = true; pThreadInfo->cols = cols; pThreadInfo->minDelay = UINT64_MAX; @@ -3011,7 +3067,7 @@ static void createChildTables() { if (g_Dbs.use_metric) { if (g_Dbs.db[i].superTblCount > 0) { // with super table - for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { if ((AUTO_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) || (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists)) { continue; @@ -3019,15 +3075,15 @@ static void createChildTables() { verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); - uint64_t startFrom = 0; + uint64_t tableFrom = 0; g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount; verbosePrint("%s() LN%d: create %"PRId64" child tables from %"PRIu64"\n", - __func__, __LINE__, g_totalChildTables, startFrom); + __func__, __LINE__, g_totalChildTables, tableFrom); startMultiThreadCreateChildTable( g_Dbs.db[i].superTbls[j].colsOfCreateChildTable, g_Dbs.threadCountByCreateTbl, - startFrom, + tableFrom, g_Dbs.db[i].superTbls[j].childTblCount, g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j])); } @@ -3036,11 +3092,14 @@ static void createChildTables() { // normal table len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP"); for (int j = 0; j < g_args.num_of_CPR; j++) { - if ((strncasecmp(g_args.datatype[j], "BINARY", strlen("BINARY")) == 0) + if (g_args.datatype[j] + && ((strncasecmp(g_args.datatype[j], + "BINARY", strlen("BINARY")) == 0) || (strncasecmp(g_args.datatype[j], - "NCHAR", strlen("NCHAR")) == 0)) { + "NCHAR", strlen("NCHAR")) == 0))) { snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, - ", COL%d %s(%d)", j, g_args.datatype[j], g_args.len_of_binary); + ", COL%d %s(%d)", j, g_args.datatype[j], + g_args.len_of_binary); } else { snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ", COL%d %s", j, g_args.datatype[j]); @@ -3132,10 +3191,12 @@ static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) { return 0; } +#if 0 int readSampleFromJsonFileToMem(SSuperTable * superTblInfo) { // TODO return 0; } +#endif /* Read 10000 lines at most. If more than 10000 lines, continue to read after using @@ -3520,9 +3581,9 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { // rows per table need be less than insert batch if (g_args.interlace_rows > g_args.num_of_RPR) { - printf("NOTICE: interlace rows value %"PRIu64" > num_of_records_per_req %"PRIu64"\n\n", + printf("NOTICE: interlace rows value %u > num_of_records_per_req %u\n\n", g_args.interlace_rows, g_args.num_of_RPR); - printf(" interlace rows value will be set to num_of_records_per_req %"PRIu64"\n\n", + printf(" interlace rows value will be set to num_of_records_per_req %u\n\n", g_args.num_of_RPR); prompt(); g_args.interlace_rows = g_args.num_of_RPR; @@ -3837,15 +3898,24 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { goto PARSE_OVER; } - cJSON *insertMode = cJSON_GetObjectItem(stbInfo, "insert_mode"); // taosc , rest - if (insertMode && insertMode->type == cJSON_String - && insertMode->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].insertMode, - insertMode->valuestring, MAX_DB_NAME_SIZE); - } else if (!insertMode) { - tstrncpy(g_Dbs.db[i].superTbls[j].insertMode, "taosc", MAX_DB_NAME_SIZE); + cJSON *stbIface = cJSON_GetObjectItem(stbInfo, "insert_mode"); // taosc , rest, stmt + if (stbIface && stbIface->type == cJSON_String + && stbIface->valuestring != NULL) { + if (0 == strcasecmp(stbIface->valuestring, "taosc")) { + g_Dbs.db[i].superTbls[j].iface= TAOSC_IFACE; + } else if (0 == strcasecmp(stbIface->valuestring, "rest")) { + g_Dbs.db[i].superTbls[j].iface= REST_IFACE; + } else if (0 == strcasecmp(stbIface->valuestring, "stmt")) { + g_Dbs.db[i].superTbls[j].iface= STMT_IFACE; + } else { + errorPrint("%s() LN%d, failed to read json, insert_mode %s not recognized\n", + __func__, __LINE__, stbIface->valuestring); + goto PARSE_OVER; + } + } else if (!stbIface) { + g_Dbs.db[i].superTbls[j].iface = TAOSC_IFACE; } else { - printf("ERROR: failed to read json, insert_mode not found\n"); + errorPrint("%s", "failed to read json, insert_mode not found\n"); goto PARSE_OVER; } @@ -3936,9 +4006,9 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { goto PARSE_OVER; } - cJSON* maxSqlLen = cJSON_GetObjectItem(stbInfo, "max_sql_len"); - if (maxSqlLen && maxSqlLen->type == cJSON_Number) { - int32_t len = maxSqlLen->valueint; + cJSON* stbMaxSqlLen = cJSON_GetObjectItem(stbInfo, "max_sql_len"); + if (stbMaxSqlLen && stbMaxSqlLen->type == cJSON_Number) { + int32_t len = stbMaxSqlLen->valueint; if (len > TSDB_MAX_ALLOWED_SQL_LEN) { len = TSDB_MAX_ALLOWED_SQL_LEN; } else if (len < 5) { @@ -3948,7 +4018,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { } else if (!maxSqlLen) { g_Dbs.db[i].superTbls[j].maxSqlLen = g_args.max_sql_len; } else { - errorPrint("%s() LN%d, failed to read json, maxSqlLen input mistake\n", + errorPrint("%s() LN%d, failed to read json, stbMaxSqlLen input mistake\n", __func__, __LINE__); goto PARSE_OVER; } @@ -3970,24 +4040,25 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { goto PARSE_OVER; } */ - cJSON* interlaceRows = cJSON_GetObjectItem(stbInfo, "interlace_rows"); - if (interlaceRows && interlaceRows->type == cJSON_Number) { - if (interlaceRows->valueint < 0) { + cJSON* stbInterlaceRows = cJSON_GetObjectItem(stbInfo, "interlace_rows"); + if (stbInterlaceRows && stbInterlaceRows->type == cJSON_Number) { + if (stbInterlaceRows->valueint < 0) { errorPrint("%s() LN%d, failed to read json, interlace rows input mistake\n", __func__, __LINE__); goto PARSE_OVER; } - g_Dbs.db[i].superTbls[j].interlaceRows = interlaceRows->valueint; + g_Dbs.db[i].superTbls[j].interlaceRows = stbInterlaceRows->valueint; // rows per table need be less than insert batch if (g_Dbs.db[i].superTbls[j].interlaceRows > g_args.num_of_RPR) { - printf("NOTICE: db[%d].superTbl[%d]'s interlace rows value %"PRIu64" > num_of_records_per_req %"PRIu64"\n\n", - i, j, g_Dbs.db[i].superTbls[j].interlaceRows, g_args.num_of_RPR); - printf(" interlace rows value will be set to num_of_records_per_req %"PRIu64"\n\n", + printf("NOTICE: db[%d].superTbl[%d]'s interlace rows value %u > num_of_records_per_req %u\n\n", + i, j, g_Dbs.db[i].superTbls[j].interlaceRows, + g_args.num_of_RPR); + printf(" interlace rows value will be set to num_of_records_per_req %u\n\n", g_args.num_of_RPR); prompt(); g_Dbs.db[i].superTbls[j].interlaceRows = g_args.num_of_RPR; } - } else if (!interlaceRows) { + } else if (!stbInterlaceRows) { g_Dbs.db[i].superTbls[j].interlaceRows = 0; // 0 means progressive mode, > 0 mean interlace mode. max value is less or equ num_of_records_per_req } else { errorPrint( @@ -4199,7 +4270,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { if (concurrent && concurrent->type == cJSON_Number) { if (concurrent->valueint <= 0) { errorPrint( - "%s() LN%d, query sqlCount %d or concurrent %d is not correct.\n", + "%s() LN%d, query sqlCount %"PRIu64" or concurrent %d is not correct.\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount, g_queryInfo.specifiedQueryInfo.concurrent); @@ -4613,7 +4684,7 @@ static void prepareSampleData() { static void postFreeResource() { tmfclose(g_fpOfInsertResult); for (int i = 0; i < g_Dbs.dbCount; i++) { - for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { if (0 != g_Dbs.db[i].superTbls[j].colsOfCreateChildTable) { free(g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); g_Dbs.db[i].superTbls[j].colsOfCreateChildTable = NULL; @@ -4661,16 +4732,22 @@ static int getRowDataFromSample( return dataLen; } -static int64_t generateRowData(char* recBuf, int64_t timestamp, SSuperTable* stbInfo) { +static int64_t generateStbRowData( + SSuperTable* stbInfo, + char* recBuf, int64_t timestamp) +{ int64_t dataLen = 0; char *pstr = recBuf; int64_t maxLen = MAX_DATA_SIZE; - dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "(%" PRId64 ",", timestamp); + dataLen += snprintf(pstr + dataLen, maxLen - dataLen, + "(%" PRId64 ",", timestamp); for (int i = 0; i < stbInfo->columnCount; i++) { - if ((0 == strncasecmp(stbInfo->columns[i].dataType, "BINARY", strlen("BINARY"))) - || (0 == strncasecmp(stbInfo->columns[i].dataType, "NCHAR", strlen("NCHAR")))) { + if ((0 == strncasecmp(stbInfo->columns[i].dataType, + "BINARY", strlen("BINARY"))) + || (0 == strncasecmp(stbInfo->columns[i].dataType, + "NCHAR", strlen("NCHAR")))) { if (stbInfo->columns[i].dataLen > TSDB_MAX_BINARY_LEN) { errorPrint( "binary or nchar length overflow, max size:%u\n", (uint32_t)TSDB_MAX_BINARY_LEN); @@ -4686,23 +4763,23 @@ static int64_t generateRowData(char* recBuf, int64_t timestamp, SSuperTable* stb dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "\'%s\',", buf); tmfree(buf); } else if (0 == strncasecmp(stbInfo->columns[i].dataType, - "INT", 3)) { + "INT", strlen("INT"))) { dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%d,", rand_int()); } else if (0 == strncasecmp(stbInfo->columns[i].dataType, - "BIGINT", 6)) { + "BIGINT", strlen("BIGINT"))) { dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%"PRId64",", rand_bigint()); } else if (0 == strncasecmp(stbInfo->columns[i].dataType, - "FLOAT", 5)) { + "FLOAT", strlen("FLOAT"))) { dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%f,", rand_float()); } else if (0 == strncasecmp(stbInfo->columns[i].dataType, - "DOUBLE", 6)) { + "DOUBLE", strlen("DOUBLE"))) { dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%f,", rand_double()); } else if (0 == strncasecmp(stbInfo->columns[i].dataType, - "SMALLINT", 8)) { + "SMALLINT", strlen("SMALLINT"))) { dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "%d,", rand_smallint()); } else if (0 == strncasecmp(stbInfo->columns[i].dataType, @@ -4732,46 +4809,38 @@ static int64_t generateRowData(char* recBuf, int64_t timestamp, SSuperTable* stb } static int64_t generateData(char *recBuf, char **data_type, - int num_of_cols, int64_t timestamp, int lenOfBinary) { + int64_t timestamp, int lenOfBinary) { memset(recBuf, 0, MAX_DATA_SIZE); char *pstr = recBuf; pstr += sprintf(pstr, "(%" PRId64, timestamp); - int c = 0; - for (; c < MAX_NUM_DATATYPE; c++) { - if (data_type[c] == NULL) { - break; - } - } + int columnCount = g_args.num_of_CPR; - if (0 == c) { - perror("data type error!"); - exit(-1); - } - - for (int i = 0; i < c; i++) { - if (strcasecmp(data_type[i % c], "TINYINT") == 0) { + for (int i = 0; i < columnCount; i++) { + if (strcasecmp(data_type[i % columnCount], "TINYINT") == 0) { pstr += sprintf(pstr, ",%d", rand_tinyint() ); - } else if (strcasecmp(data_type[i % c], "SMALLINT") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "SMALLINT") == 0) { pstr += sprintf(pstr, ",%d", rand_smallint()); - } else if (strcasecmp(data_type[i % c], "INT") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "INT") == 0) { pstr += sprintf(pstr, ",%d", rand_int()); - } else if (strcasecmp(data_type[i % c], "BIGINT") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "BIGINT") == 0) { pstr += sprintf(pstr, ",%" PRId64, rand_bigint()); - } else if (strcasecmp(data_type[i % c], "FLOAT") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "TIMESTAMP") == 0) { + pstr += sprintf(pstr, ",%" PRId64, rand_bigint()); + } else if (strcasecmp(data_type[i % columnCount], "FLOAT") == 0) { pstr += sprintf(pstr, ",%10.4f", rand_float()); - } else if (strcasecmp(data_type[i % c], "DOUBLE") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "DOUBLE") == 0) { double t = rand_double(); pstr += sprintf(pstr, ",%20.8f", t); - } else if (strcasecmp(data_type[i % c], "BOOL") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "BOOL") == 0) { bool b = rand_bool() & 1; pstr += sprintf(pstr, ",%s", b ? "true" : "false"); - } else if (strcasecmp(data_type[i % c], "BINARY") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "BINARY") == 0) { char *s = malloc(lenOfBinary); rand_string(s, lenOfBinary); pstr += sprintf(pstr, ",\"%s\"", s); free(s); - } else if (strcasecmp(data_type[i % c], "NCHAR") == 0) { + } else if (strcasecmp(data_type[i % columnCount], "NCHAR") == 0) { char *s = malloc(lenOfBinary); rand_string(s, lenOfBinary); pstr += sprintf(pstr, ",\"%s\"", s); @@ -4818,35 +4887,60 @@ static int prepareSampleDataForSTable(SSuperTable *superTblInfo) { return 0; } -static int64_t execInsert(threadInfo *pThreadInfo, char *buffer, uint64_t k) +static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) { - int affectedRows; - SSuperTable* superTblInfo = pThreadInfo->superTblInfo; + int32_t affectedRows; + SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - verbosePrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, - __func__, __LINE__, buffer); - if (superTblInfo) { - if (0 == strncasecmp(superTblInfo->insertMode, "taosc", strlen("taosc"))) { - affectedRows = queryDbExec(pThreadInfo->taos, buffer, INSERT_TYPE, false); - } else if (0 == strncasecmp(superTblInfo->insertMode, "rest", strlen("rest"))) { - if (0 != postProceSql(g_Dbs.host, &g_Dbs.serv_addr, g_Dbs.port, - buffer, NULL /* not set result file */)) { - affectedRows = -1; - printf("========restful return fail, threadID[%d]\n", - pThreadInfo->threadID); - } else { - affectedRows = k; - } - } else { - errorPrint("%s() LN%d: unknown insert mode: %s\n", - __func__, __LINE__, superTblInfo->insertMode); - affectedRows = 0; + verbosePrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, + __func__, __LINE__, pThreadInfo->buffer); + + uint16_t iface; + if (superTblInfo) + iface = superTblInfo->iface; + else + iface = g_args.iface; + + debugPrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, + __func__, __LINE__, + (g_args.iface==TAOSC_IFACE)? + "taosc":(g_args.iface==REST_IFACE)?"rest":"stmt"); + + switch(iface) { + case TAOSC_IFACE: + affectedRows = queryDbExec( + pThreadInfo->taos, + pThreadInfo->buffer, INSERT_TYPE, false); + break; + + case REST_IFACE: + if (0 != postProceSql(g_Dbs.host, &g_Dbs.serv_addr, g_Dbs.port, + pThreadInfo->buffer, NULL /* not set result file */)) { + affectedRows = -1; + printf("========restful return fail, threadID[%d]\n", + pThreadInfo->threadID); + } else { + affectedRows = k; + } + break; + + case STMT_IFACE: + debugPrint("%s() LN%d, stmt=%p", __func__, __LINE__, pThreadInfo->stmt); + if (0 != taos_stmt_execute(pThreadInfo->stmt)) { + errorPrint("%s() LN%d, failied to execute insert statement\n", + __func__, __LINE__); + exit(-1); + } + affectedRows = k; + break; + + default: + errorPrint("%s() LN%d: unknown insert mode: %d\n", + __func__, __LINE__, superTblInfo->iface); + affectedRows = 0; } - } else { - affectedRows = queryDbExec(pThreadInfo->taos, buffer, INSERT_TYPE, false); - } - return affectedRows; + return affectedRows; } static void getTableName(char *pTblName, @@ -4874,90 +4968,48 @@ static void getTableName(char *pTblName, } } -static int64_t generateDataTail( - SSuperTable* superTblInfo, - uint64_t batch, char* buffer, int64_t remainderBufLen, int64_t insertRows, - uint64_t startFrom, int64_t startTime, int64_t *pSamplePos, int64_t *dataLen) { - uint64_t len = 0; - uint32_t ncols_per_record = 1; // count first col ts +static int32_t generateDataTailWithoutStb( + uint32_t batch, char* buffer, + int64_t remainderBufLen, int64_t insertRows, + uint64_t recordFrom, int64_t startTime, + /* int64_t *pSamplePos, */int64_t *dataLen) { + uint64_t len = 0; char *pstr = buffer; - if (superTblInfo == NULL) { - uint32_t datatypeSeq = 0; - while(g_args.datatype[datatypeSeq]) { - datatypeSeq ++; - ncols_per_record ++; - } - } + verbosePrint("%s() LN%d batch=%d\n", __func__, __LINE__, batch); - verbosePrint("%s() LN%d batch=%"PRIu64"\n", __func__, __LINE__, batch); - - bool tsRand; - if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, - "rand", strlen("rand")))) { - tsRand = true; - } else { - tsRand = false; - } - - uint64_t k = 0; + int32_t k = 0; for (k = 0; k < batch;) { char data[MAX_DATA_SIZE]; memset(data, 0, MAX_DATA_SIZE); int64_t retLen = 0; - if (superTblInfo) { - if (tsRand) { - retLen = generateRowData( - data, - startTime + getTSRandTail( - superTblInfo->timeStampStep, k, - superTblInfo->disorderRatio, - superTblInfo->disorderRange), - superTblInfo); - } else { - retLen = getRowDataFromSample( - data, - remainderBufLen, - startTime + superTblInfo->timeStampStep * k, - superTblInfo, - pSamplePos); - } - if (retLen > remainderBufLen) { - break; - } + char **data_type = g_args.datatype; + int lenOfBinary = g_args.len_of_binary; - pstr += snprintf(pstr , retLen + 1, "%s", data); - k++; - len += retLen; - remainderBufLen -= retLen; - } else { - char **data_type = g_args.datatype; - int lenOfBinary = g_args.len_of_binary; - retLen = generateData(data, data_type, - ncols_per_record, - startTime + getTSRandTail( - DEFAULT_TIMESTAMP_STEP, k, - g_args.disorderRatio, - g_args.disorderRange), - lenOfBinary); - if (len > remainderBufLen) - break; + retLen = generateData(data, data_type, + startTime + getTSRandTail( + (int64_t) DEFAULT_TIMESTAMP_STEP, k, + g_args.disorderRatio, + g_args.disorderRange), + lenOfBinary); - pstr += sprintf(pstr, "%s", data); - k++; - len += retLen; - remainderBufLen -= retLen; - } + if (len > remainderBufLen) + break; - verbosePrint("%s() LN%d len=%"PRIu64" k=%"PRIu64" \nbuffer=%s\n", + pstr += sprintf(pstr, "%s", data); + k++; + len += retLen; + remainderBufLen -= retLen; + + verbosePrint("%s() LN%d len=%"PRIu64" k=%d \nbuffer=%s\n", __func__, __LINE__, len, k, buffer); - startFrom ++; + recordFrom ++; - if (startFrom >= insertRows) { + if (recordFrom >= insertRows) { break; } } @@ -4966,17 +5018,121 @@ static int64_t generateDataTail( return k; } -static int generateSQLHead(char *tableName, int32_t tableSeq, - threadInfo* pThreadInfo, SSuperTable* superTblInfo, +static int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, + int disorderRatio, int disorderRange) +{ + int64_t randTail = timeStampStep * seq; + if (disorderRatio > 0) { + int rand_num = taosRandom() % 100; + if(rand_num < disorderRatio) { + randTail = (randTail + + (taosRandom() % disorderRange + 1)) * (-1); + debugPrint("rand data generated, back %"PRId64"\n", randTail); + } + } + + return randTail; +} + +static int32_t generateStbDataTail( + SSuperTable* superTblInfo, + uint32_t batch, char* buffer, + int64_t remainderBufLen, int64_t insertRows, + uint64_t recordFrom, int64_t startTime, + int64_t *pSamplePos, int64_t *dataLen) { + uint64_t len = 0; + + char *pstr = buffer; + + bool tsRand; + if (0 == strncasecmp(superTblInfo->dataSource, "rand", strlen("rand"))) { + tsRand = true; + } else { + tsRand = false; + } + verbosePrint("%s() LN%d batch=%u\n", __func__, __LINE__, batch); + + int32_t k = 0; + for (k = 0; k < batch;) { + char data[MAX_DATA_SIZE]; + memset(data, 0, MAX_DATA_SIZE); + + int64_t retLen = 0; + + if (tsRand) { + retLen = generateStbRowData(superTblInfo, data, + startTime + getTSRandTail( + superTblInfo->timeStampStep, k, + superTblInfo->disorderRatio, + superTblInfo->disorderRange) + ); + } else { + retLen = getRowDataFromSample( + data, + remainderBufLen, + startTime + superTblInfo->timeStampStep * k, + superTblInfo, + pSamplePos); + } + + if (retLen > remainderBufLen) { + break; + } + + pstr += snprintf(pstr , retLen + 1, "%s", data); + k++; + len += retLen; + remainderBufLen -= retLen; + + verbosePrint("%s() LN%d len=%"PRIu64" k=%u \nbuffer=%s\n", + __func__, __LINE__, len, k, buffer); + + recordFrom ++; + + if (recordFrom >= insertRows) { + break; + } + } + + *dataLen = len; + return k; +} + + +static int generateSQLHeadWithoutStb(char *tableName, + char *dbName, char *buffer, int remainderBufLen) { int len; -#define HEAD_BUFF_LEN 1024*24 // 16*1024 + (192+32)*2 + insert into .. char headBuf[HEAD_BUFF_LEN]; - if (superTblInfo) { - if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { + len = snprintf( + headBuf, + HEAD_BUFF_LEN, + "%s.%s values", + dbName, + tableName); + + if (len > remainderBufLen) + return -1; + + tstrncpy(buffer, headBuf, len + 1); + + return len; +} + +static int generateStbSQLHead( + SSuperTable* superTblInfo, + char *tableName, int32_t tableSeq, + char *dbName, + char *buffer, int remainderBufLen) +{ + int len; + + char headBuf[HEAD_BUFF_LEN]; + + if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { char* tagsValBuf = NULL; if (0 == superTblInfo->tagSource) { tagsValBuf = generateTagVaulesForStb(superTblInfo, tableSeq); @@ -4995,9 +5151,9 @@ static int generateSQLHead(char *tableName, int32_t tableSeq, headBuf, HEAD_BUFF_LEN, "%s.%s using %s.%s tags %s values", - pThreadInfo->db_name, + dbName, tableName, - pThreadInfo->db_name, + dbName, superTblInfo->sTblName, tagsValBuf); tmfree(tagsValBuf); @@ -5006,22 +5162,14 @@ static int generateSQLHead(char *tableName, int32_t tableSeq, headBuf, HEAD_BUFF_LEN, "%s.%s values", - pThreadInfo->db_name, + dbName, tableName); } else { len = snprintf( headBuf, HEAD_BUFF_LEN, "%s.%s values", - pThreadInfo->db_name, - tableName); - } - } else { - len = snprintf( - headBuf, - HEAD_BUFF_LEN, - "%s.%s values", - pThreadInfo->db_name, + dbName, tableName); } @@ -5033,8 +5181,11 @@ static int generateSQLHead(char *tableName, int32_t tableSeq, return len; } -static int64_t generateInterlaceDataBuffer( - char *tableName, uint64_t batchPerTbl, uint64_t i, uint64_t batchPerTblTimes, +static int32_t generateStbInterlaceData( + SSuperTable *superTblInfo, + char *tableName, uint32_t batchPerTbl, + uint64_t i, + uint32_t batchPerTblTimes, uint64_t tableSeq, threadInfo *pThreadInfo, char *buffer, int64_t insertRows, @@ -5043,10 +5194,11 @@ static int64_t generateInterlaceDataBuffer( { assert(buffer); char *pstr = buffer; - SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - int headLen = generateSQLHead(tableName, tableSeq, pThreadInfo, - superTblInfo, pstr, *pRemainderBufLen); + int headLen = generateStbSQLHead( + superTblInfo, + tableName, tableSeq, pThreadInfo->db_name, + pstr, *pRemainderBufLen); if (headLen <= 0) { return 0; @@ -5060,29 +5212,25 @@ static int64_t generateInterlaceDataBuffer( int64_t dataLen = 0; - verbosePrint("[%d] %s() LN%d i=%"PRIu64" batchPerTblTimes=%"PRIu64" batchPerTbl = %"PRIu64"\n", + verbosePrint("[%d] %s() LN%d i=%"PRIu64" batchPerTblTimes=%u batchPerTbl = %u\n", pThreadInfo->threadID, __func__, __LINE__, i, batchPerTblTimes, batchPerTbl); - if (superTblInfo) { - if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { + if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { startTime = taosGetTimestamp(pThreadInfo->time_precision); - } - } else { - startTime = 1500000000000; } - int64_t k = generateDataTail( - superTblInfo, - batchPerTbl, pstr, *pRemainderBufLen, insertRows, 0, - startTime, - &(pThreadInfo->samplePos), &dataLen); + int32_t k = generateStbDataTail( + superTblInfo, + batchPerTbl, pstr, *pRemainderBufLen, insertRows, 0, + startTime, + &(pThreadInfo->samplePos), &dataLen); if (k == batchPerTbl) { pstr += dataLen; *pRemainderBufLen -= dataLen; } else { - debugPrint("%s() LN%d, generated data tail: %"PRIu64", not equal batch per table: %"PRIu64"\n", + debugPrint("%s() LN%d, generated data tail: %u, not equal batch per table: %u\n", __func__, __LINE__, k, batchPerTbl); pstr -= headLen; pstr[0] = '\0'; @@ -5092,50 +5240,361 @@ static int64_t generateInterlaceDataBuffer( return k; } -static int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, - int disorderRatio, int disorderRange) +static int64_t generateInterlaceDataWithoutStb( + char *tableName, uint32_t batch, + uint64_t tableSeq, + char *dbName, char *buffer, + int64_t insertRows, + int64_t startTime, + uint64_t *pRemainderBufLen) { - int64_t randTail = timeStampStep * seq; - if (disorderRatio > 0) { - int rand_num = taosRandom() % 100; - if(rand_num < disorderRatio) { - randTail = (randTail + - (taosRandom() % disorderRange + 1)) * (-1); - debugPrint("rand data generated, back %"PRId64"\n", randTail); + assert(buffer); + char *pstr = buffer; + + int headLen = generateSQLHeadWithoutStb( + tableName, dbName, + pstr, *pRemainderBufLen); + + if (headLen <= 0) { + return 0; + } + + pstr += headLen; + *pRemainderBufLen -= headLen; + + int64_t dataLen = 0; + + int32_t k = generateDataTailWithoutStb( + batch, pstr, *pRemainderBufLen, insertRows, 0, + startTime, + &dataLen); + + if (k == batch) { + pstr += dataLen; + *pRemainderBufLen -= dataLen; + } else { + debugPrint("%s() LN%d, generated data tail: %d, not equal batch per table: %u\n", + __func__, __LINE__, k, batch); + pstr -= headLen; + pstr[0] = '\0'; + k = 0; + } + + return k; +} + +#if STMT_IFACE_ENABLED == 1 +static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind, + char *dataType, int32_t dataLen, char **ptr) +{ + if (0 == strncasecmp(dataType, + "BINARY", strlen("BINARY"))) { + if (dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint( "binary length overflow, max size:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *bind_binary = (char *)*ptr; + rand_string(bind_binary, dataLen); + + bind->buffer_type = TSDB_DATA_TYPE_BINARY; + bind->buffer_length = dataLen; + bind->buffer = bind_binary; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "NCHAR", strlen("NCHAR"))) { + if (dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint( "nchar length overflow, max size:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *bind_nchar = (char *)*ptr; + rand_string(bind_nchar, dataLen); + + bind->buffer_type = TSDB_DATA_TYPE_NCHAR; + bind->buffer_length = strlen(bind_nchar); + bind->buffer = bind_nchar; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "INT", strlen("INT"))) { + int32_t *bind_int = (int32_t *)*ptr; + + *bind_int = rand_int(); + bind->buffer_type = TSDB_DATA_TYPE_INT; + bind->buffer_length = sizeof(int32_t); + bind->buffer = bind_int; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "BIGINT", strlen("BIGINT"))) { + int64_t *bind_bigint = (int64_t *)*ptr; + + *bind_bigint = rand_bigint(); + bind->buffer_type = TSDB_DATA_TYPE_BIGINT; + bind->buffer_length = sizeof(int64_t); + bind->buffer = bind_bigint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "FLOAT", strlen("FLOAT"))) { + float *bind_float = (float *) *ptr; + + *bind_float = rand_float(); + bind->buffer_type = TSDB_DATA_TYPE_FLOAT; + bind->buffer_length = sizeof(float); + bind->buffer = bind_float; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "DOUBLE", strlen("DOUBLE"))) { + double *bind_double = (double *)*ptr; + + *bind_double = rand_double(); + bind->buffer_type = TSDB_DATA_TYPE_DOUBLE; + bind->buffer_length = sizeof(double); + bind->buffer = bind_double; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "SMALLINT", strlen("SMALLINT"))) { + int16_t *bind_smallint = (int16_t *)*ptr; + + *bind_smallint = rand_smallint(); + bind->buffer_type = TSDB_DATA_TYPE_SMALLINT; + bind->buffer_length = sizeof(int16_t); + bind->buffer = bind_smallint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "TINYINT", strlen("TINYINT"))) { + int8_t *bind_tinyint = (int8_t *)*ptr; + + *bind_tinyint = rand_tinyint(); + bind->buffer_type = TSDB_DATA_TYPE_TINYINT; + bind->buffer_length = sizeof(int8_t); + bind->buffer = bind_tinyint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "BOOL", strlen("BOOL"))) { + int8_t *bind_bool = (int8_t *)*ptr; + + *bind_bool = rand_bool(); + bind->buffer_type = TSDB_DATA_TYPE_BOOL; + bind->buffer_length = sizeof(int8_t); + bind->buffer = bind_bool; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else if (0 == strncasecmp(dataType, + "TIMESTAMP", strlen("TIMESTAMP"))) { + int64_t *bind_ts2 = (int64_t *) *ptr; + + *bind_ts2 = rand_bigint(); + bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + bind->buffer_length = sizeof(int64_t); + bind->buffer = bind_ts2; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + *ptr += bind->buffer_length; + } else { + errorPrint( "No support data type: %s\n", + dataType); + return -1; + } + + return 0; +} + +static int32_t prepareStmtWithoutStb( + TAOS_STMT *stmt, + char *tableName, + uint32_t batch, + int64_t insertRows, + int64_t recordFrom, + int64_t startTime) +{ + int ret = taos_stmt_set_tbname(stmt, tableName); + if (ret != 0) { + errorPrint("failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s\n", + tableName, ret, taos_errstr(NULL)); + return ret; + } + + char **data_type = g_args.datatype; + + char *bindArray = malloc(sizeof(TAOS_BIND) * (g_args.num_of_CPR + 1)); + if (bindArray == NULL) { + errorPrint("Failed to allocate %d bind params\n", + (g_args.num_of_CPR + 1)); + return -1; + } + + int32_t k = 0; + for (k = 0; k < batch;) { + /* columnCount + 1 (ts) */ + char data[MAX_DATA_SIZE]; + memset(data, 0, MAX_DATA_SIZE); + + char *ptr = data; + TAOS_BIND *bind = (TAOS_BIND *)(bindArray + 0); + + int64_t *bind_ts; + + bind_ts = (int64_t *)ptr; + bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + *bind_ts = startTime + getTSRandTail( + (int64_t)DEFAULT_TIMESTAMP_STEP, k, + g_args.disorderRatio, + g_args.disorderRange); + bind->buffer_length = sizeof(int64_t); + bind->buffer = bind_ts; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + ptr += bind->buffer_length; + + for (int i = 0; i < g_args.num_of_CPR; i ++) { + bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * (i + 1))); + if ( -1 == prepareStmtBindArrayByType( + bind, + data_type[i], + g_args.len_of_binary, + &ptr)) { + return -1; + } + } + taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray); + // if msg > 3MB, break + taos_stmt_add_batch(stmt); + + k++; + recordFrom ++; + if (recordFrom >= insertRows) { + break; } } - return randTail; + return k; } -static int64_t generateProgressiveDataBuffer( +static int32_t prepareStbStmt(SSuperTable *stbInfo, + TAOS_STMT *stmt, + char *tableName, uint32_t batch, + uint64_t insertRows, + uint64_t recordFrom, + int64_t startTime, char *buffer) +{ + int ret = taos_stmt_set_tbname(stmt, tableName); + if (ret != 0) { + errorPrint("failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s\n", + tableName, ret, taos_errstr(NULL)); + return ret; + } + + char *bindArray = malloc(sizeof(TAOS_BIND) * (stbInfo->columnCount + 1)); + if (bindArray == NULL) { + errorPrint("Failed to allocate %d bind params\n", + (stbInfo->columnCount + 1)); + return -1; + } + + bool tsRand; + if (0 == strncasecmp(stbInfo->dataSource, "rand", strlen("rand"))) { + tsRand = true; + } else { + tsRand = false; + } + + uint32_t k; + for (k = 0; k < batch;) { + /* columnCount + 1 (ts) */ + char data[MAX_DATA_SIZE]; + memset(data, 0, MAX_DATA_SIZE); + + char *ptr = data; + TAOS_BIND *bind = (TAOS_BIND *)(bindArray + 0); + + int64_t *bind_ts; + + bind_ts = (int64_t *)ptr; + bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + if (tsRand) { + *bind_ts = startTime + getTSRandTail( + stbInfo->timeStampStep, k, + stbInfo->disorderRatio, + stbInfo->disorderRange); + } else { + *bind_ts = startTime + stbInfo->timeStampStep * k; + } + bind->buffer_length = sizeof(int64_t); + bind->buffer = bind_ts; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + ptr += bind->buffer_length; + + for (int i = 0; i < stbInfo->columnCount; i ++) { + bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * (i + 1))); + if ( -1 == prepareStmtBindArrayByType( + bind, + stbInfo->columns[i].dataType, + stbInfo->columns[i].dataLen, + &ptr)) { + return -1; + } + } + taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray); + // if msg > 3MB, break + taos_stmt_add_batch(stmt); + + k++; + recordFrom ++; + if (recordFrom >= insertRows) { + break; + } + } + + return k; +} +#endif + +static int32_t generateStbProgressiveData( + SSuperTable *superTblInfo, char *tableName, int64_t tableSeq, - threadInfo *pThreadInfo, char *buffer, + char *dbName, char *buffer, int64_t insertRows, - uint64_t startFrom, int64_t startTime, int64_t *pSamplePos, + uint64_t recordFrom, int64_t startTime, int64_t *pSamplePos, int64_t *pRemainderBufLen) { - SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - - int ncols_per_record = 1; // count first col ts - - if (superTblInfo == NULL) { - int datatypeSeq = 0; - while(g_args.datatype[datatypeSeq]) { - datatypeSeq ++; - ncols_per_record ++; - } - } - assert(buffer != NULL); char *pstr = buffer; - int64_t k = 0; - memset(buffer, 0, *pRemainderBufLen); - int64_t headLen = generateSQLHead(tableName, tableSeq, pThreadInfo, superTblInfo, + int64_t headLen = generateStbSQLHead( + superTblInfo, + tableName, tableSeq, dbName, buffer, *pRemainderBufLen); if (headLen <= 0) { @@ -5145,29 +5604,64 @@ static int64_t generateProgressiveDataBuffer( *pRemainderBufLen -= headLen; int64_t dataLen; - k = generateDataTail(superTblInfo, - g_args.num_of_RPR, pstr, *pRemainderBufLen, insertRows, startFrom, + + return generateStbDataTail(superTblInfo, + g_args.num_of_RPR, pstr, *pRemainderBufLen, + insertRows, recordFrom, startTime, pSamplePos, &dataLen); +} - return k; +static int32_t generateProgressiveDataWithoutStb( + char *tableName, + /* int64_t tableSeq, */ + threadInfo *pThreadInfo, char *buffer, + int64_t insertRows, + uint64_t recordFrom, int64_t startTime, /*int64_t *pSamplePos, */ + int64_t *pRemainderBufLen) +{ + assert(buffer != NULL); + char *pstr = buffer; + + memset(buffer, 0, *pRemainderBufLen); + + int64_t headLen = generateSQLHeadWithoutStb( + tableName, pThreadInfo->db_name, + buffer, *pRemainderBufLen); + + if (headLen <= 0) { + return 0; + } + pstr += headLen; + *pRemainderBufLen -= headLen; + + int64_t dataLen; + + return generateDataTailWithoutStb( + g_args.num_of_RPR, pstr, *pRemainderBufLen, insertRows, recordFrom, + startTime, + /*pSamplePos, */&dataLen); } static void printStatPerThread(threadInfo *pThreadInfo) { - fprintf(stderr, "====thread[%d] completed total inserted rows: %"PRIu64 ", total affected rows: %"PRIu64". %.2f records/second====\n", + fprintf(stderr, "====thread[%d] completed total inserted rows: %"PRIu64 ", total affected rows: %"PRIu64". %.2f records/second====\n", pThreadInfo->threadID, pThreadInfo->totalInsertRows, pThreadInfo->totalAffectedRows, (double)(pThreadInfo->totalAffectedRows / (pThreadInfo->totalDelay/1000.0))); } +// sync write interlace data static void* syncWriteInterlace(threadInfo *pThreadInfo) { debugPrint("[%d] %s() LN%d: ### interlace write\n", pThreadInfo->threadID, __func__, __LINE__); int64_t insertRows; - uint64_t interlaceRows; + uint32_t interlaceRows; + uint64_t maxSqlLen; + int64_t nTimeStampStep; + uint64_t insert_interval; SSuperTable* superTblInfo = pThreadInfo->superTblInfo; @@ -5180,62 +5674,30 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { } else { interlaceRows = superTblInfo->interlaceRows; } + maxSqlLen = superTblInfo->maxSqlLen; + nTimeStampStep = superTblInfo->timeStampStep; + insert_interval = superTblInfo->insertInterval; } else { insertRows = g_args.num_of_DPT; interlaceRows = g_args.interlace_rows; + maxSqlLen = g_args.max_sql_len; + nTimeStampStep = DEFAULT_TIMESTAMP_STEP; + insert_interval = g_args.insert_interval; } + debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->start_table_from, + pThreadInfo->ntables, insertRows); + if (interlaceRows > insertRows) interlaceRows = insertRows; if (interlaceRows > g_args.num_of_RPR) interlaceRows = g_args.num_of_RPR; - int insertMode; - - if (interlaceRows > 0) { - insertMode = INTERLACE_INSERT_MODE; - } else { - insertMode = PROGRESSIVE_INSERT_MODE; - } - - // TODO: prompt tbl count multple interlace rows and batch - // - - uint64_t maxSqlLen = superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len; - char* buffer = calloc(maxSqlLen, 1); - if (NULL == buffer) { - errorPrint( "%s() LN%d, Failed to alloc %"PRIu64" Bytes, reason:%s\n", - __func__, __LINE__, maxSqlLen, strerror(errno)); - return NULL; - } - - char tableName[TSDB_TABLE_NAME_LEN]; - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - int64_t nTimeStampStep = superTblInfo?superTblInfo->timeStampStep:DEFAULT_TIMESTAMP_STEP; - - uint64_t insert_interval = - superTblInfo?superTblInfo->insertInterval:g_args.insert_interval; - uint64_t st = 0; - uint64_t et = UINT64_MAX; - - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; - - uint64_t tableSeq = pThreadInfo->start_table_from; - - debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, pThreadInfo->start_table_from, - pThreadInfo->ntables, insertRows); - - int64_t startTime = pThreadInfo->start_time; - - uint64_t batchPerTbl = interlaceRows; - uint64_t batchPerTblTimes; + uint32_t batchPerTbl = interlaceRows; + uint32_t batchPerTblTimes; if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { batchPerTblTimes = @@ -5244,52 +5706,116 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { batchPerTblTimes = 1; } + pThreadInfo->buffer = calloc(maxSqlLen, 1); + if (NULL == pThreadInfo->buffer) { + errorPrint( "%s() LN%d, Failed to alloc %"PRIu64" Bytes, reason:%s\n", + __func__, __LINE__, maxSqlLen, strerror(errno)); + return NULL; + } + + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; + + uint64_t st = 0; + uint64_t et = UINT64_MAX; + + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + uint64_t endTs; + + uint64_t tableSeq = pThreadInfo->start_table_from; + int64_t startTime = pThreadInfo->start_time; + uint64_t generatedRecPerTbl = 0; bool flagSleep = true; uint64_t sleepTimeTotal = 0; - char *strInsertInto = "insert into "; - int nInsertBufLen = strlen(strInsertInto); - while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { if ((flagSleep) && (insert_interval)) { st = taosGetTimestampMs(); flagSleep = false; } // generate data - memset(buffer, 0, maxSqlLen); + memset(pThreadInfo->buffer, 0, maxSqlLen); uint64_t remainderBufLen = maxSqlLen; - char *pstr = buffer; + char *pstr = pThreadInfo->buffer; - int len = snprintf(pstr, nInsertBufLen + 1, "%s", strInsertInto); + int len = snprintf(pstr, + strlen(STR_INSERT_INTO) + 1, "%s", STR_INSERT_INTO); pstr += len; remainderBufLen -= len; - uint64_t recOfBatch = 0; + uint32_t recOfBatch = 0; + + for (uint32_t i = 0; i < batchPerTblTimes; i ++) { + char tableName[TSDB_TABLE_NAME_LEN]; - for (uint64_t i = 0; i < batchPerTblTimes; i ++) { getTableName(tableName, pThreadInfo, tableSeq); if (0 == strlen(tableName)) { errorPrint("[%d] %s() LN%d, getTableName return null\n", pThreadInfo->threadID, __func__, __LINE__); - free(buffer); + free(pThreadInfo->buffer); return NULL; } uint64_t oldRemainderLen = remainderBufLen; - int64_t generated = generateInterlaceDataBuffer( - tableName, batchPerTbl, i, batchPerTblTimes, - tableSeq, - pThreadInfo, pstr, - insertRows, - startTime, - &remainderBufLen); - debugPrint("[%d] %s() LN%d, generated records is %"PRId64"\n", + int32_t generated; + if (superTblInfo) { + if (superTblInfo->iface == STMT_IFACE) { +#if STMT_IFACE_ENABLED == 1 + generated = prepareStbStmt(superTblInfo, + pThreadInfo->stmt, + tableName, + batchPerTbl, + insertRows, i, + startTime, + pThreadInfo->buffer); +#else + generated = -1; +#endif + } else { + generated = generateStbInterlaceData( + superTblInfo, + tableName, batchPerTbl, i, + batchPerTblTimes, + tableSeq, + pThreadInfo, pstr, + insertRows, + startTime, + &remainderBufLen); + } + } else { + if (g_args.iface == STMT_IFACE) { + debugPrint("[%d] %s() LN%d, tableName:%s, batch:%d startTime:%"PRId64"\n", + pThreadInfo->threadID, + __func__, __LINE__, + tableName, batchPerTbl, startTime); +#if STMT_IFACE_ENABLED == 1 + generated = prepareStmtWithoutStb( + pThreadInfo->stmt, tableName, + batchPerTbl, + insertRows, i, + startTime); +#else + generated = -1; +#endif + } else { + generated = generateInterlaceDataWithoutStb( + tableName, batchPerTbl, + tableSeq, + pThreadInfo->db_name, pstr, + insertRows, + startTime, + &remainderBufLen); + } + } + + debugPrint("[%d] %s() LN%d, generated records is %d\n", pThreadInfo->threadID, __func__, __LINE__, generated); if (generated < 0) { - errorPrint("[%d] %s() LN%d, generated records is %"PRId64"\n", + errorPrint("[%d] %s() LN%d, generated records is %d\n", pThreadInfo->threadID, __func__, __LINE__, generated); goto free_of_interlace; } else if (generated == 0) { @@ -5298,15 +5824,15 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { tableSeq ++; recOfBatch += batchPerTbl; + pstr += (oldRemainderLen - remainderBufLen); -// startTime += batchPerTbl * superTblInfo->timeStampStep; pThreadInfo->totalInsertRows += batchPerTbl; - verbosePrint("[%d] %s() LN%d batchPerTbl=%"PRId64" recOfBatch=%"PRId64"\n", + + verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", pThreadInfo->threadID, __func__, __LINE__, batchPerTbl, recOfBatch); - if (insertMode == INTERLACE_INSERT_MODE) { - if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { + if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { // turn to first table tableSeq = pThreadInfo->start_table_from; generatedRecPerTbl += batchPerTbl; @@ -5318,13 +5844,12 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { if (generatedRecPerTbl >= insertRows) break; - int remainRows = insertRows - generatedRecPerTbl; + int64_t remainRows = insertRows - generatedRecPerTbl; if ((remainRows > 0) && (batchPerTbl > remainRows)) batchPerTbl = remainRows; if (pThreadInfo->ntables * batchPerTbl < g_args.num_of_RPR) break; - } } verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%"PRId64" insertRows=%"PRId64"\n", @@ -5335,22 +5860,22 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { break; } - verbosePrint("[%d] %s() LN%d recOfBatch=%"PRIu64" totalInsertRows=%"PRIu64"\n", + verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"PRIu64"\n", pThreadInfo->threadID, __func__, __LINE__, recOfBatch, pThreadInfo->totalInsertRows); verbosePrint("[%d] %s() LN%d, buffer=%s\n", - pThreadInfo->threadID, __func__, __LINE__, buffer); + pThreadInfo->threadID, __func__, __LINE__, pThreadInfo->buffer); startTs = taosGetTimestampMs(); if (recOfBatch == 0) { - errorPrint("[%d] %s() LN%d try inserting records of batch is %"PRIu64"\n", + errorPrint("[%d] %s() LN%d try inserting records of batch is %d\n", pThreadInfo->threadID, __func__, __LINE__, recOfBatch); errorPrint("%s\n", "\tPlease check if the batch or the buffer length is proper value!\n"); goto free_of_interlace; } - int64_t affectedRows = execInsert(pThreadInfo, buffer, recOfBatch); + int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); endTs = taosGetTimestampMs(); uint64_t delay = endTs - startTs; @@ -5366,9 +5891,9 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { pThreadInfo->totalDelay += delay; if (recOfBatch != affectedRows) { - errorPrint("[%d] %s() LN%d execInsert insert %"PRIu64", affected rows: %"PRId64"\n%s\n", + errorPrint("[%d] %s() LN%d execInsert insert %d, affected rows: %"PRId64"\n%s\n", pThreadInfo->threadID, __func__, __LINE__, - recOfBatch, affectedRows, buffer); + recOfBatch, affectedRows, pThreadInfo->buffer); goto free_of_interlace; } @@ -5387,8 +5912,8 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { et = taosGetTimestampMs(); if (insert_interval > (et - st) ) { - int sleepTime = insert_interval - (et -st); - performancePrint("%s() LN%d sleep: %d ms for insert interval\n", + uint64_t sleepTime = insert_interval - (et -st); + performancePrint("%s() LN%d sleep: %"PRId64" ms for insert interval\n", __func__, __LINE__, sleepTime); taosMsleep(sleepTime); // ms sleepTimeTotal += insert_interval; @@ -5397,27 +5922,26 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { } free_of_interlace: - tmfree(buffer); + tmfree(pThreadInfo->buffer); printStatPerThread(pThreadInfo); return NULL; } -// sync insertion -/* - 1 thread: 100 tables * 2000 rows/s - 1 thread: 10 tables * 20000 rows/s - 6 thread: 300 tables * 2000 rows/s - - 2 taosinsertdata , 1 thread: 10 tables * 20000 rows/s -*/ +// sync insertion progressive data static void* syncWriteProgressive(threadInfo *pThreadInfo) { debugPrint("%s() LN%d: ### progressive write\n", __func__, __LINE__); SSuperTable* superTblInfo = pThreadInfo->superTblInfo; uint64_t maxSqlLen = superTblInfo?superTblInfo->maxSqlLen:g_args.max_sql_len; + int64_t timeStampStep = + superTblInfo?superTblInfo->timeStampStep:DEFAULT_TIMESTAMP_STEP; + int64_t insertRows = + (superTblInfo)?superTblInfo->insertRows:g_args.num_of_DPT; + verbosePrint("%s() LN%d insertRows=%"PRId64"\n", + __func__, __LINE__, insertRows); - char* buffer = calloc(maxSqlLen, 1); - if (NULL == buffer) { + pThreadInfo->buffer = calloc(maxSqlLen, 1); + if (NULL == pThreadInfo->buffer) { errorPrint( "Failed to alloc %"PRIu64" Bytes, reason:%s\n", maxSqlLen, strerror(errno)); @@ -5428,35 +5952,17 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { uint64_t startTs = taosGetTimestampMs(); uint64_t endTs; - int64_t timeStampStep = - superTblInfo?superTblInfo->timeStampStep:DEFAULT_TIMESTAMP_STEP; -/* int insert_interval = - superTblInfo?superTblInfo->insertInterval:g_args.insert_interval; - uint64_t st = 0; - uint64_t et = 0xffffffff; - */ - pThreadInfo->totalInsertRows = 0; pThreadInfo->totalAffectedRows = 0; pThreadInfo->samplePos = 0; - for (uint64_t tableSeq = - pThreadInfo->start_table_from; tableSeq <= pThreadInfo->end_table_to; - tableSeq ++) { + for (uint64_t tableSeq = pThreadInfo->start_table_from; + tableSeq <= pThreadInfo->end_table_to; + tableSeq ++) { int64_t start_time = pThreadInfo->start_time; - int64_t insertRows = (superTblInfo)?superTblInfo->insertRows:g_args.num_of_DPT; - - verbosePrint("%s() LN%d insertRows=%"PRId64"\n", __func__, __LINE__, insertRows); - for (uint64_t i = 0; i < insertRows;) { - /* - if (insert_interval) { - st = taosGetTimestampMs(); - } - */ - char tableName[TSDB_TABLE_NAME_LEN]; getTableName(tableName, pThreadInfo, tableSeq); verbosePrint("%s() LN%d: tid=%d seq=%"PRId64" tableName=%s\n", @@ -5464,19 +5970,57 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { pThreadInfo->threadID, tableSeq, tableName); int64_t remainderBufLen = maxSqlLen; - char *pstr = buffer; - int nInsertBufLen = strlen("insert into "); + char *pstr = pThreadInfo->buffer; - int len = snprintf(pstr, nInsertBufLen + 1, "%s", "insert into "); + int len = snprintf(pstr, + strlen(STR_INSERT_INTO) + 1, "%s", STR_INSERT_INTO); pstr += len; remainderBufLen -= len; - int64_t generated = generateProgressiveDataBuffer( - tableName, tableSeq, pThreadInfo, pstr, insertRows, - i, start_time, - &(pThreadInfo->samplePos), - &remainderBufLen); + int32_t generated; + if (superTblInfo) { + if (superTblInfo->iface == STMT_IFACE) { +#if STMT_IFACE_ENABLED == 1 + generated = prepareStbStmt( + superTblInfo, + pThreadInfo->stmt, + tableName, + g_args.num_of_RPR, + insertRows, i, start_time, pstr); +#else + generated = -1; +#endif + } else { + generated = generateStbProgressiveData( + superTblInfo, + tableName, tableSeq, pThreadInfo->db_name, pstr, + insertRows, i, start_time, + &(pThreadInfo->samplePos), + &remainderBufLen); + } + } else { + if (g_args.iface == STMT_IFACE) { +#if STMT_IFACE_ENABLED == 1 + generated = prepareStmtWithoutStb( + pThreadInfo->stmt, + tableName, + g_args.num_of_RPR, + insertRows, i, + start_time); +#else + generated = -1; +#endif + } else { + generated = generateProgressiveDataWithoutStb( + tableName, + /* tableSeq, */ + pThreadInfo, pstr, insertRows, + i, start_time, + /* &(pThreadInfo->samplePos), */ + &remainderBufLen); + } + } if (generated > 0) i += generated; else @@ -5487,13 +6031,13 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { startTs = taosGetTimestampMs(); - int64_t affectedRows = execInsert(pThreadInfo, buffer, generated); + int32_t affectedRows = execInsert(pThreadInfo, generated); endTs = taosGetTimestampMs(); uint64_t delay = endTs - startTs; performancePrint("%s() LN%d, insert execution time is %"PRId64"ms\n", __func__, __LINE__, delay); - verbosePrint("[%d] %s() LN%d affectedRows=%"PRId64"\n", + verbosePrint("[%d] %s() LN%d affectedRows=%d\n", pThreadInfo->threadID, __func__, __LINE__, affectedRows); @@ -5503,7 +6047,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { pThreadInfo->totalDelay += delay; if (affectedRows < 0) { - errorPrint("%s() LN%d, affected rows: %"PRId64"\n", + errorPrint("%s() LN%d, affected rows: %d\n", __func__, __LINE__, affectedRows); goto free_of_progressive; } @@ -5521,32 +6065,19 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { if (i >= insertRows) break; -/* - if (insert_interval) { - et = taosGetTimestampMs(); - - if (insert_interval > ((et - st)) ) { - int sleep_time = insert_interval - (et -st); - performancePrint("%s() LN%d sleep: %d ms for insert interval\n", - __func__, __LINE__, sleep_time); - taosMsleep(sleep_time); // ms - } - } - */ } // num_of_DPT - if (g_args.verbose_print) { - if ((tableSeq == pThreadInfo->ntables - 1) && superTblInfo && + if ((g_args.verbose_print) && + (tableSeq == pThreadInfo->ntables - 1) && (superTblInfo) && (0 == strncasecmp( superTblInfo->dataSource, "sample", strlen("sample")))) { verbosePrint("%s() LN%d samplePos=%"PRId64"\n", __func__, __LINE__, pThreadInfo->samplePos); - } } } // tableSeq free_of_progressive: - tmfree(buffer); + tmfree(pThreadInfo->buffer); printStatPerThread(pThreadInfo); return NULL; } @@ -5556,7 +6087,7 @@ static void* syncWrite(void *sarg) { threadInfo *pThreadInfo = (threadInfo *)sarg; SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - int interlaceRows; + uint32_t interlaceRows; if (superTblInfo) { if ((superTblInfo->interlaceRows == 0) @@ -5576,7 +6107,6 @@ static void* syncWrite(void *sarg) { // progressive mode return syncWriteProgressive(pThreadInfo); } - } static void callBack(void *param, TAOS_RES *res, int code) { @@ -5616,9 +6146,10 @@ static void callBack(void *param, TAOS_RES *res, int code) { && rand_num < pThreadInfo->superTblInfo->disorderRatio) { int64_t d = pThreadInfo->lastTs - (taosRandom() % pThreadInfo->superTblInfo->disorderRange + 1); - generateRowData(data, d, pThreadInfo->superTblInfo); + generateStbRowData(pThreadInfo->superTblInfo, data, d); } else { - generateRowData(data, pThreadInfo->lastTs += 1000, pThreadInfo->superTblInfo); + generateStbRowData(pThreadInfo->superTblInfo, + data, pThreadInfo->lastTs += 1000); } pstr += sprintf(pstr, "%s", data); pThreadInfo->counter++; @@ -5686,24 +6217,6 @@ static int convertHostToServAddr(char *host, uint16_t port, struct sockaddr_in * static void startMultiThreadInsertData(int threads, char* db_name, char* precision,SSuperTable* superTblInfo) { - pthread_t *pids = malloc(threads * sizeof(pthread_t)); - assert(pids != NULL); - - threadInfo *infos = malloc(threads * sizeof(threadInfo)); - assert(infos != NULL); - - memset(pids, 0, threads * sizeof(pthread_t)); - memset(infos, 0, threads * sizeof(threadInfo)); - - //TAOS* taos; - //if (0 == strncasecmp(superTblInfo->insertMode, "taosc", 5)) { - // taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, db_name, g_Dbs.port); - // if (NULL == taos) { - // printf("connect to server fail, reason: %s\n", taos_errstr(NULL)); - // exit(-1); - // } - //} - int32_t timePrec = TSDB_TIME_PRECISION_MILLI; if (0 != precision[0]) { if (0 == strncasecmp(precision, "ms", 2)) { @@ -5755,17 +6268,17 @@ static void startMultiThreadInsertData(int threads, char* db_name, } } - TAOS* taos = taos_connect( + TAOS* taos0 = taos_connect( g_Dbs.host, g_Dbs.user, g_Dbs.password, db_name, g_Dbs.port); - if (NULL == taos) { + if (NULL == taos0) { errorPrint("%s() LN%d, connect to server fail , reason: %s\n", __func__, __LINE__, taos_errstr(NULL)); exit(-1); } int64_t ntables = 0; - uint64_t startFrom; + uint64_t tableFrom; if (superTblInfo) { int64_t limit; @@ -5792,7 +6305,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, } ntables = limit; - startFrom = offset; + tableFrom = offset; if ((superTblInfo->childTblExists != TBL_NO_EXISTS) && ((superTblInfo->childTblOffset + superTblInfo->childTblLimit ) @@ -5811,23 +6324,23 @@ static void startMultiThreadInsertData(int threads, char* db_name, limit * TSDB_TABLE_NAME_LEN); if (superTblInfo->childTblName == NULL) { errorPrint("%s() LN%d, alloc memory failed!\n", __func__, __LINE__); - taos_close(taos); + taos_close(taos0); exit(-1); } int64_t childTblCount; getChildNameOfSuperTableWithLimitAndOffset( - taos, + taos0, db_name, superTblInfo->sTblName, &superTblInfo->childTblName, &childTblCount, limit, offset); } else { ntables = g_args.num_of_tables; - startFrom = 0; + tableFrom = 0; } - taos_close(taos); + taos_close(taos0); int64_t a = ntables / threads; if (a < 1) { @@ -5841,11 +6354,22 @@ static void startMultiThreadInsertData(int threads, char* db_name, } if ((superTblInfo) - && (0 == strncasecmp(superTblInfo->insertMode, "rest", strlen("rest")))) { - if (convertHostToServAddr(g_Dbs.host, g_Dbs.port, &(g_Dbs.serv_addr)) != 0) - exit(-1); + && (superTblInfo->iface == REST_IFACE)) { + if (convertHostToServAddr( + g_Dbs.host, g_Dbs.port, &(g_Dbs.serv_addr)) != 0) { + exit(-1); + } } + pthread_t *pids = malloc(threads * sizeof(pthread_t)); + assert(pids != NULL); + + threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); + assert(infos != NULL); + + memset(pids, 0, threads * sizeof(pthread_t)); + memset(infos, 0, threads * sizeof(threadInfo)); + for (int i = 0; i < threads; i++) { threadInfo *pThreadInfo = infos + i; pThreadInfo->threadID = i; @@ -5857,17 +6381,59 @@ static void startMultiThreadInsertData(int threads, char* db_name, pThreadInfo->minDelay = UINT64_MAX; if ((NULL == superTblInfo) || - (0 == strncasecmp(superTblInfo->insertMode, "taosc", 5))) { - //pThreadInfo->taos = taos; + (superTblInfo->iface != REST_IFACE)) { + //t_info->taos = taos; pThreadInfo->taos = taos_connect( g_Dbs.host, g_Dbs.user, g_Dbs.password, db_name, g_Dbs.port); if (NULL == pThreadInfo->taos) { errorPrint( - "connect to server fail from insert sub thread, reason: %s\n", + "%s() LN%d, connect to server fail from insert sub thread, reason: %s\n", + __func__, __LINE__, taos_errstr(NULL)); + free(infos); exit(-1); } + + if ((g_args.iface == STMT_IFACE) + || ((superTblInfo) && (superTblInfo->iface == STMT_IFACE))) { + + int columnCount; + if (superTblInfo) { + columnCount = superTblInfo->columnCount; + } else { + columnCount = g_args.num_of_CPR; + } + + pThreadInfo->stmt = taos_stmt_init(pThreadInfo->taos); + if (NULL == pThreadInfo->stmt) { + errorPrint( + "%s() LN%d, failed init stmt, reason: %s\n", + __func__, __LINE__, + taos_errstr(NULL)); + free(pids); + free(infos); + exit(-1); + } + + char buffer[3000]; + char *pstr = buffer; + pstr += sprintf(pstr, "INSERT INTO ? values(?"); + + for (int col = 0; col < columnCount; col ++) { + pstr += sprintf(pstr, ",?"); + } + pstr += sprintf(pstr, ")"); + + int ret = taos_stmt_prepare(pThreadInfo->stmt, buffer, 0); + if (ret != 0){ + errorPrint("failed to execute taos_stmt_prepare. return 0x%x. reason: %s\n", + ret, taos_errstr(NULL)); + free(pids); + free(infos); + exit(-1); + } + } } else { pThreadInfo->taos = NULL; } @@ -5875,10 +6441,10 @@ static void startMultiThreadInsertData(int threads, char* db_name, /* if ((NULL == superTblInfo) || (0 == superTblInfo->multiThreadWriteOneTbl)) { */ - pThreadInfo->start_table_from = startFrom; + pThreadInfo->start_table_from = tableFrom; pThreadInfo->ntables = iend_table_to = i < b ? startFrom + a : startFrom + a - 1; - startFrom = pThreadInfo->end_table_to + 1; + pThreadInfo->end_table_to = i < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; /* } else { pThreadInfo->start_table_from = 0; pThreadInfo->ntables = superTblInfo->childTblCount; @@ -5906,6 +6472,11 @@ static void startMultiThreadInsertData(int threads, char* db_name, for (int i = 0; i < threads; i++) { threadInfo *pThreadInfo = infos + i; + tsem_destroy(&(pThreadInfo->lock_sem)); + + if (pThreadInfo->stmt) { + taos_stmt_close(pThreadInfo->stmt); + } tsem_destroy(&(pThreadInfo->lock_sem)); taos_close(pThreadInfo->taos); @@ -6182,13 +6753,13 @@ static int insertTestProcess() { } } - taosMsleep(1000); + // taosMsleep(1000); // create sub threads for inserting data //start = taosGetTimestampMs(); for (int i = 0; i < g_Dbs.dbCount; i++) { if (g_Dbs.use_metric) { if (g_Dbs.db[i].superTblCount > 0) { - for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { SSuperTable* superTblInfo = &g_Dbs.db[i].superTbls[j]; @@ -6512,15 +7083,15 @@ static int queryTestProcess() { b = ntables % threads; } - uint64_t startFrom = 0; + uint64_t tableFrom = 0; for (int i = 0; i < threads; i++) { threadInfo *pThreadInfo = infosOfSub + i; pThreadInfo->threadID = i; - pThreadInfo->start_table_from = startFrom; + pThreadInfo->start_table_from = tableFrom; pThreadInfo->ntables = iend_table_to = i < b ? startFrom + a : startFrom + a - 1; - startFrom = pThreadInfo->end_table_to + 1; + pThreadInfo->end_table_to = i < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; pThreadInfo->taos = NULL; // TODO: workaround to use separate taos connection; pthread_create(pidsOfSub + i, NULL, superTableQuery, pThreadInfo); } @@ -6901,12 +7472,12 @@ static int subscribeTestProcess() { //==== create threads for query for specified table if (g_queryInfo.specifiedQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, sepcified query sqlCount %d.\n", + debugPrint("%s() LN%d, sepcified query sqlCount %"PRIu64".\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount); } else { if (g_queryInfo.specifiedQueryInfo.concurrent <= 0) { - errorPrint("%s() LN%d, sepcified query sqlCount %d.\n", + errorPrint("%s() LN%d, sepcified query sqlCount %"PRIu64".\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount); exit(-1); @@ -6939,7 +7510,7 @@ static int subscribeTestProcess() { //==== create threads for super table query if (g_queryInfo.superQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, super table query sqlCount %d.\n", + debugPrint("%s() LN%d, super table query sqlCount %"PRIu64".\n", __func__, __LINE__, g_queryInfo.superQueryInfo.sqlCount); } else { @@ -6975,17 +7546,17 @@ static int subscribeTestProcess() { } for (uint64_t i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { - uint64_t startFrom = 0; + uint64_t tableFrom = 0; for (int j = 0; j < threads; j++) { uint64_t seq = i * threads + j; threadInfo *pThreadInfo = infosOfStable + seq; pThreadInfo->threadID = seq; pThreadInfo->querySeq = i; - pThreadInfo->start_table_from = startFrom; + pThreadInfo->start_table_from = tableFrom; pThreadInfo->ntables = jend_table_to = jend_table_to + 1; + pThreadInfo->end_table_to = jend_table_to + 1; pThreadInfo->taos = NULL; // TODO: workaround to use separate taos connection; pthread_create(pidsOfStable + seq, NULL, superSubscribe, pThreadInfo); @@ -7104,7 +7675,7 @@ static void setParaFromArg(){ tstrncpy(g_Dbs.db[0].superTbls[0].childTblPrefix, g_args.tb_prefix, MAX_TB_NAME_SIZE); tstrncpy(g_Dbs.db[0].superTbls[0].dataSource, "rand", MAX_TB_NAME_SIZE); - tstrncpy(g_Dbs.db[0].superTbls[0].insertMode, "taosc", MAX_TB_NAME_SIZE); + g_Dbs.db[0].superTbls[0].iface = g_args.iface; tstrncpy(g_Dbs.db[0].superTbls[0].startTimestamp, "2017-07-14 10:40:00.000", MAX_TB_NAME_SIZE); g_Dbs.db[0].superTbls[0].timeStampStep = DEFAULT_TIMESTAMP_STEP; From 24cf44583e7f9802164ee415532c963d4e38b618 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Fri, 28 May 2021 19:41:47 +0800 Subject: [PATCH 38/80] [TD-4417]: return database not ready if vnode status & role not ready --- src/vnode/src/vnodeWrite.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 16089c8e91..555eda6d13 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -303,6 +303,17 @@ static int32_t vnodeWriteToWQueueImp(SVWriteMsg *pWrite) { } int32_t vnodeWriteToWQueue(void *vparam, void *wparam, int32_t qtype, void *rparam) { + SVnodeObj *pVnode = vparam; + if (qtype == TAOS_QTYPE_RPC) { + if (!vnodeInReadyStatus(pVnode)) { + return TSDB_CODE_APP_NOT_READY; // it may be in deleting or closing state + } + + if (pVnode->role != TAOS_SYNC_ROLE_MASTER) { + return TSDB_CODE_APP_NOT_READY; + } + } + SVWriteMsg *pWrite = vnodeBuildVWriteMsg(vparam, wparam, qtype, rparam); if (pWrite == NULL) { assert(terrno != 0); From 921b36c7b1a66c1eee8780a8a7bdd7b640828b85 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 29 May 2021 07:31:35 +0800 Subject: [PATCH 39/80] [TD-4406]: taosdemo auto create table. (#6281) * [TD-4406]: taosdemo auto create table. * fix child table exists or auto create logic. Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 230 +++++++++++++++++++----------------- 1 file changed, 123 insertions(+), 107 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 70ddbacf44..406544b306 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -255,12 +255,13 @@ typedef struct SColumn_S { typedef struct SSuperTable_S { char sTblName[MAX_TB_NAME_SIZE+1]; + char dataSource[MAX_TB_NAME_SIZE+1]; // rand_gen or sample + char childTblPrefix[MAX_TB_NAME_SIZE]; + char insertMode[MAX_TB_NAME_SIZE]; // taosc, rest + uint16_t childTblExists; int64_t childTblCount; - bool childTblExists; // 0: no, 1: yes uint64_t batchCreateTableNum; // 0: no batch, > 0: batch table number in one sql uint8_t autoCreateTable; // 0: create sub table, 1: auto create sub table - char childTblPrefix[MAX_TB_NAME_SIZE]; - char dataSource[MAX_TB_NAME_SIZE+1]; // rand_gen or sample uint16_t iface; // 0: taosc, 1: rest, 2: stmt int64_t childTblLimit; uint64_t childTblOffset; @@ -830,7 +831,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { if ((argc == i+1) || (!isStringNumber(argv[i+1]))) { printHelp(); - errorPrint("%s", "\n\t-q need a number following!\nQuery mode -- 0: SYNC, 1: ASYNC. Default is SYNC.\n"); + errorPrint("%s", "\n\t-q need a number following!\nQuery mode -- 0: SYNC, not-0: ASYNC. Default is SYNC.\n"); exit(EXIT_FAILURE); } arguments->async_mode = atoi(argv[++i]); @@ -1471,7 +1472,8 @@ static int printfInsertMeta() { if (PRE_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) { printf(" autoCreateTable: \033[33m%s\033[0m\n", "no"); - } else if (AUTO_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) { + } else if (AUTO_CREATE_SUBTBL == + g_Dbs.db[i].superTbls[j].autoCreateTable) { printf(" autoCreateTable: \033[33m%s\033[0m\n", "yes"); } else { printf(" autoCreateTable: \033[33m%s\033[0m\n", "error"); @@ -3063,64 +3065,61 @@ static void createChildTables() { char tblColsBuf[MAX_SQL_SIZE]; int len; - for (int i = 0; i < g_Dbs.dbCount; i++) { - if (g_Dbs.use_metric) { - if (g_Dbs.db[i].superTblCount > 0) { - // with super table - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - if ((AUTO_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) - || (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists)) { - continue; - } + for (int i = 0; i < g_Dbs.dbCount; i++) { + if (g_Dbs.use_metric) { + if (g_Dbs.db[i].superTblCount > 0) { + // with super table + for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + if ((AUTO_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) + || (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists)) { + continue; + } + verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, + g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); + uint64_t startFrom = 0; + g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount; - verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, - g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); - uint64_t tableFrom = 0; - g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount; + verbosePrint("%s() LN%d: create %"PRId64" child tables from %"PRIu64"\n", + __func__, __LINE__, g_totalChildTables, startFrom); - verbosePrint("%s() LN%d: create %"PRId64" child tables from %"PRIu64"\n", - __func__, __LINE__, g_totalChildTables, tableFrom); - startMultiThreadCreateChildTable( - g_Dbs.db[i].superTbls[j].colsOfCreateChildTable, - g_Dbs.threadCountByCreateTbl, - tableFrom, - g_Dbs.db[i].superTbls[j].childTblCount, - g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j])); + startMultiThreadCreateChildTable( + g_Dbs.db[i].superTbls[j].colsOfCreateChildTable, + g_Dbs.threadCountByCreateTbl, + startFrom, + g_Dbs.db[i].superTbls[j].childTblCount, + g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j])); + } + } + } else { + // normal table + len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP"); + for (int j = 0; j < g_args.num_of_CPR; j++) { + if ((strncasecmp(g_args.datatype[j], "BINARY", strlen("BINARY")) == 0) + || (strncasecmp(g_args.datatype[j], + "NCHAR", strlen("NCHAR")) == 0)) { + snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, + ", COL%d %s(%d)", j, g_args.datatype[j], g_args.len_of_binary); + } else { + snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, + ", COL%d %s", j, g_args.datatype[j]); + } + len = strlen(tblColsBuf); + } + + snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")"); + + verbosePrint("%s() LN%d: dbName: %s num of tb: %"PRId64" schema: %s\n", + __func__, __LINE__, + g_Dbs.db[i].dbName, g_args.num_of_tables, tblColsBuf); + startMultiThreadCreateChildTable( + tblColsBuf, + g_Dbs.threadCountByCreateTbl, + 0, + g_args.num_of_tables, + g_Dbs.db[i].dbName, + NULL); } - } - } else { - // normal table - len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP"); - for (int j = 0; j < g_args.num_of_CPR; j++) { - if (g_args.datatype[j] - && ((strncasecmp(g_args.datatype[j], - "BINARY", strlen("BINARY")) == 0) - || (strncasecmp(g_args.datatype[j], - "NCHAR", strlen("NCHAR")) == 0))) { - snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, - ", COL%d %s(%d)", j, g_args.datatype[j], - g_args.len_of_binary); - } else { - snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, - ", COL%d %s", j, g_args.datatype[j]); - } - len = strlen(tblColsBuf); - } - - snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")"); - - verbosePrint("%s() LN%d: dbName: %s num of tb: %"PRId64" schema: %s\n", - __func__, __LINE__, - g_Dbs.db[i].dbName, g_args.num_of_tables, tblColsBuf); - startMultiThreadCreateChildTable( - tblColsBuf, - g_Dbs.threadCountByCreateTbl, - 0, - g_args.num_of_tables, - g_Dbs.db[i].dbName, - NULL); } - } } /* @@ -3814,36 +3813,40 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { // dbinfo cJSON *stbName = cJSON_GetObjectItem(stbInfo, "name"); - if (!stbName || stbName->type != cJSON_String || stbName->valuestring == NULL) { + if (!stbName || stbName->type != cJSON_String + || stbName->valuestring == NULL) { errorPrint("%s() LN%d, failed to read json, stb name not found\n", __func__, __LINE__); goto PARSE_OVER; } - tstrncpy(g_Dbs.db[i].superTbls[j].sTblName, stbName->valuestring, MAX_TB_NAME_SIZE); + tstrncpy(g_Dbs.db[i].superTbls[j].sTblName, stbName->valuestring, + MAX_TB_NAME_SIZE); cJSON *prefix = cJSON_GetObjectItem(stbInfo, "childtable_prefix"); if (!prefix || prefix->type != cJSON_String || prefix->valuestring == NULL) { printf("ERROR: failed to read json, childtable_prefix not found\n"); goto PARSE_OVER; } - tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, MAX_DB_NAME_SIZE); + tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, + MAX_DB_NAME_SIZE); - cJSON *autoCreateTbl = cJSON_GetObjectItem(stbInfo, "auto_create_table"); // yes, no, null + cJSON *autoCreateTbl = cJSON_GetObjectItem(stbInfo, "auto_create_table"); if (autoCreateTbl && autoCreateTbl->type == cJSON_String && autoCreateTbl->valuestring != NULL) { - if (0 == strncasecmp(autoCreateTbl->valuestring, "yes", 3)) { - g_Dbs.db[i].superTbls[j].autoCreateTable = AUTO_CREATE_SUBTBL; - } else if (0 == strncasecmp(autoCreateTbl->valuestring, "no", 2)) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } else { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } + if ((0 == strncasecmp(autoCreateTbl->valuestring, "yes", 3)) + && (TBL_ALREADY_EXISTS != g_Dbs.db[i].superTbls[j].childTblExists)) { + g_Dbs.db[i].superTbls[j].autoCreateTable = AUTO_CREATE_SUBTBL; + } else if (0 == strncasecmp(autoCreateTbl->valuestring, "no", 2)) { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } else { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } } else if (!autoCreateTbl) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; } else { - printf("ERROR: failed to read json, auto_create_table not found\n"); - goto PARSE_OVER; + printf("ERROR: failed to read json, auto_create_table not found\n"); + goto PARSE_OVER; } cJSON* batchCreateTbl = cJSON_GetObjectItem(stbInfo, "batch_create_tbl_num"); @@ -3877,6 +3880,10 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { goto PARSE_OVER; } + if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } + cJSON* count = cJSON_GetObjectItem(stbInfo, "childtable_count"); if (!count || count->type != cJSON_Number || 0 >= count->valueint) { errorPrint("%s() LN%d, failed to read json, childtable_count input mistake\n", @@ -3934,7 +3941,8 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { cJSON* childTbl_offset = cJSON_GetObjectItem(stbInfo, "childtable_offset"); if ((childTbl_offset) && (g_Dbs.db[i].drop != true) && (g_Dbs.db[i].superTbls[j].childTblExists == TBL_ALREADY_EXISTS)) { - if (childTbl_offset->type != cJSON_Number || 0 > childTbl_offset->valueint) { + if ((childTbl_offset->type != cJSON_Number) + || (0 > childTbl_offset->valueint)) { printf("ERROR: failed to read json, childtable_offset\n"); goto PARSE_OVER; } @@ -3990,7 +3998,8 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { } cJSON *tagsFile = cJSON_GetObjectItem(stbInfo, "tags_file"); - if (tagsFile && tagsFile->type == cJSON_String && tagsFile->valuestring != NULL) { + if ((tagsFile && tagsFile->type == cJSON_String) + && (tagsFile->valuestring != NULL)) { tstrncpy(g_Dbs.db[i].superTbls[j].tagsFile, tagsFile->valuestring, MAX_FILE_NAME_LEN); if (0 == g_Dbs.db[i].superTbls[j].tagsFile[0]) { @@ -4946,26 +4955,29 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) static void getTableName(char *pTblName, threadInfo* pThreadInfo, uint64_t tableSeq) { - SSuperTable* superTblInfo = pThreadInfo->superTblInfo; - if ((superTblInfo) - && (AUTO_CREATE_SUBTBL != superTblInfo->autoCreateTable)) { - if (superTblInfo->childTblLimit > 0) { - snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s", - superTblInfo->childTblName + - (tableSeq - superTblInfo->childTblOffset) * TSDB_TABLE_NAME_LEN); + SSuperTable* superTblInfo = pThreadInfo->superTblInfo; + if (superTblInfo) { + if (AUTO_CREATE_SUBTBL != superTblInfo->autoCreateTable) { + if (superTblInfo->childTblLimit > 0) { + snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s", + superTblInfo->childTblName + + (tableSeq - superTblInfo->childTblOffset) * TSDB_TABLE_NAME_LEN); + } else { + verbosePrint("[%d] %s() LN%d: from=%"PRIu64" count=%"PRId64" seq=%"PRIu64"\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->start_table_from, + pThreadInfo->ntables, tableSeq); + snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s", + superTblInfo->childTblName + tableSeq * TSDB_TABLE_NAME_LEN); + } + } else { + snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s%"PRIu64"", + superTblInfo->childTblPrefix, tableSeq); + } } else { - - verbosePrint("[%d] %s() LN%d: from=%"PRIu64" count=%"PRId64" seq=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->start_table_from, - pThreadInfo->ntables, tableSeq); - snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s", - superTblInfo->childTblName + tableSeq * TSDB_TABLE_NAME_LEN); + snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s%"PRIu64"", + g_args.tb_prefix, tableSeq); } - } else { - snprintf(pTblName, TSDB_TABLE_NAME_LEN, "%s%"PRIu64"", - g_args.tb_prefix, tableSeq); - } } static int32_t generateDataTailWithoutStb( @@ -5132,7 +5144,8 @@ static int generateStbSQLHead( char headBuf[HEAD_BUFF_LEN]; - if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { + if ((AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) + && (TBL_ALREADY_EXISTS != superTblInfo->childTblExists)) { char* tagsValBuf = NULL; if (0 == superTblInfo->tagSource) { tagsValBuf = generateTagVaulesForStb(superTblInfo, tableSeq); @@ -6753,7 +6766,6 @@ static int insertTestProcess() { } } - // taosMsleep(1000); // create sub threads for inserting data //start = taosGetTimestampMs(); for (int i = 0; i < g_Dbs.dbCount; i++) { @@ -7397,11 +7409,14 @@ static void *specifiedSubscribe(void *sarg) { g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID] = taos_consume( g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID]); if (g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID]) { - if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] != 0) { + if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] + != 0) { sprintf(pThreadInfo->filePath, "%s-%d", g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], pThreadInfo->threadID); - fetchResult(g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID], pThreadInfo); + fetchResult( + g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID], + pThreadInfo); } g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] ++; @@ -7414,16 +7429,17 @@ static void *specifiedSubscribe(void *sarg) { g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = 0; taos_unsubscribe(g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID], g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); - g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID] = subscribeImpl( - SPECIFIED_CLASS, - pThreadInfo, - g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq], - g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], - g_queryInfo.specifiedQueryInfo.subscribeRestart, - g_queryInfo.specifiedQueryInfo.subscribeInterval); + g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID] = + subscribeImpl( + SPECIFIED_CLASS, + pThreadInfo, + g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq], + g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], + g_queryInfo.specifiedQueryInfo.subscribeRestart, + g_queryInfo.specifiedQueryInfo.subscribeInterval); if (NULL == g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID]) { - taos_close(pThreadInfo->taos); - return NULL; + taos_close(pThreadInfo->taos); + return NULL; } } } @@ -7636,7 +7652,7 @@ static void setParaFromArg(){ g_Dbs.threadCountByCreateTbl = g_args.num_of_threads; g_Dbs.dbCount = 1; - g_Dbs.db[0].drop = 1; + g_Dbs.db[0].drop = true; tstrncpy(g_Dbs.db[0].dbName, g_args.database, MAX_DB_NAME_SIZE); g_Dbs.db[0].dbCfg.replica = g_args.replica; From 5694f03f1afd2abc60409b656c33df8444c3355e Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 29 May 2021 08:21:57 +0800 Subject: [PATCH 40/80] Hotfix/sangshuduo/td 3913 mips compile support (#6279) * [TD-3913]: mips compile support. * [TD-3912]: support mips64 compile. add mips64 header file and modify tcrc32c.c for mips64. * [TD-3913]: mips compile support. verified on real loongson machine. * fix cmake. * fix gcc 4.8 compile error. * fix clang compile error. Co-authored-by: Shuduo Sang --- src/os/src/detail/osTime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index d9d070218e..67e0c2642e 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -87,12 +87,12 @@ static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t time int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } -int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t daylight) { +int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) { /* parse datatime string in with tz */ if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec); } else { - return (*parseLocaltimeFp[daylight])(timestr, time, timePrec); + return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); } } From 5456f3a0090005365262080e17c75a0f4cc4935b Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 29 May 2021 09:12:19 +0800 Subject: [PATCH 41/80] Revert "[TD-4533]: taosdemo resub if resubAfterConsume != -1 (#6243)" (#6289) This reverts commit 0c4075e09fa0c2e40efae77b9ded0a314ad657e2. --- src/kit/taosdemo/taosdemo.c | 52 +++++++++---------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 406544b306..a8af72d36a 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -389,7 +389,6 @@ typedef struct SpecifiedQueryInfo_S { char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN+1]; int resubAfterConsume[MAX_QUERY_SQL_COUNT]; - int endAfterConsume[MAX_QUERY_SQL_COUNT]; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; char topic[MAX_QUERY_SQL_COUNT][32]; int consumed[MAX_QUERY_SQL_COUNT]; @@ -412,7 +411,6 @@ typedef struct SuperQueryInfo_S { char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN+1]; int resubAfterConsume; - int endAfterConsume; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; char* childTblName; @@ -4378,17 +4376,6 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { tstrncpy(g_queryInfo.specifiedQueryInfo.sql[j], sqlStr->valuestring, MAX_QUERY_SQL_LENGTH); - cJSON* endAfterConsume = - cJSON_GetObjectItem(specifiedQuery, "endAfterConsume"); - if (endAfterConsume - && endAfterConsume->type == cJSON_Number) { - g_queryInfo.specifiedQueryInfo.endAfterConsume[j] - = endAfterConsume->valueint; - } else if (!endAfterConsume) { - // default value is -1, which mean infinite loop - g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = -1; - } - cJSON* resubAfterConsume = cJSON_GetObjectItem(specifiedQuery, "resubAfterConsume"); if (resubAfterConsume @@ -4396,8 +4383,9 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = resubAfterConsume->valueint; } else if (!resubAfterConsume) { - // default value is -1, which mean do not resub - g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = -1; + //printf("failed to read json, subscribe interval no found\n"); + //goto PARSE_OVER; + g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = 1; } cJSON *result = cJSON_GetObjectItem(sql, "result"); @@ -4541,26 +4529,16 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; } - cJSON* superEndAfterConsume = - cJSON_GetObjectItem(superQuery, "endAfterConsume"); - if (superEndAfterConsume - && superEndAfterConsume->type == cJSON_Number) { - g_queryInfo.superQueryInfo.endAfterConsume = - superEndAfterConsume->valueint; - } else if (!superEndAfterConsume) { - // default value is -1, which mean do not resub - g_queryInfo.superQueryInfo.endAfterConsume = -1; - } - cJSON* superResubAfterConsume = - cJSON_GetObjectItem(superQuery, "endAfterConsume"); + cJSON_GetObjectItem(superQuery, "resubAfterConsume"); if (superResubAfterConsume && superResubAfterConsume->type == cJSON_Number) { - g_queryInfo.superQueryInfo.endAfterConsume = + g_queryInfo.superQueryInfo.resubAfterConsume = superResubAfterConsume->valueint; } else if (!superResubAfterConsume) { - // default value is -1, which mean do not resub - g_queryInfo.superQueryInfo.endAfterConsume = -1; + //printf("failed to read json, subscribe interval no found\n"); + ////goto PARSE_OVER; + g_queryInfo.superQueryInfo.resubAfterConsume = 1; } // supert table sqls @@ -7284,10 +7262,7 @@ static void *superSubscribe(void *sarg) { uint64_t st = 0, et = 0; - while ((g_queryInfo.superQueryInfo.endAfterConsume == -1) - || (g_queryInfo.superQueryInfo.endAfterConsume < - consumed[pThreadInfo->end_table_to - pThreadInfo->start_table_from])) { - + while(1) { for (uint64_t i = pThreadInfo->start_table_from; i <= pThreadInfo->end_table_to; i++) { tsubSeq = i - pThreadInfo->start_table_from; @@ -7316,7 +7291,7 @@ static void *superSubscribe(void *sarg) { } consumed[tsubSeq] ++; - if ((g_queryInfo.superQueryInfo.resubAfterConsume != -1) + if ((g_queryInfo.superQueryInfo.subscribeKeepProgress) && (consumed[tsubSeq] >= g_queryInfo.superQueryInfo.resubAfterConsume)) { printf("keepProgress:%d, resub super table query: %"PRIu64"\n", @@ -7398,10 +7373,7 @@ static void *specifiedSubscribe(void *sarg) { // start loop to consume result g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = 0; - while((g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq] == -1) - || (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] < - g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq])) { - + while(1) { if (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode) { continue; } @@ -7420,7 +7392,7 @@ static void *specifiedSubscribe(void *sarg) { } g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] ++; - if ((g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq] != -1) + if ((g_queryInfo.specifiedQueryInfo.subscribeKeepProgress) && (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] >= g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq])) { printf("keepProgress:%d, resub specified query: %"PRIu64"\n", From af7658b00245e239c2943f8d5370023fad35fed1 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 29 May 2021 09:32:22 +0800 Subject: [PATCH 42/80] [TD-4353]: taosdemo resub if resubAfterConsume != -1 (#6287) Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 72 +++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index a8af72d36a..e7b2d4f16b 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -380,7 +380,7 @@ typedef struct SDbs_S { typedef struct SpecifiedQueryInfo_S { uint64_t queryInterval; // 0: unlimit > 0 loop/s uint32_t concurrent; - uint64_t sqlCount; + int sqlCount; uint32_t asyncMode; // 0: sync, 1: async uint64_t subscribeInterval; // ms uint64_t queryTimes; @@ -389,6 +389,7 @@ typedef struct SpecifiedQueryInfo_S { char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN+1]; int resubAfterConsume[MAX_QUERY_SQL_COUNT]; + int endAfterConsume[MAX_QUERY_SQL_COUNT]; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; char topic[MAX_QUERY_SQL_COUNT][32]; int consumed[MAX_QUERY_SQL_COUNT]; @@ -407,10 +408,11 @@ typedef struct SuperQueryInfo_S { uint64_t queryTimes; int64_t childTblCount; char childTblPrefix[MAX_TB_NAME_SIZE]; - uint64_t sqlCount; + int sqlCount; char sql[MAX_QUERY_SQL_COUNT][MAX_QUERY_SQL_LENGTH+1]; char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN+1]; int resubAfterConsume; + int endAfterConsume; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; char* childTblName; @@ -1775,7 +1777,7 @@ static void printfQueryMeta() { if ((SUBSCRIBE_TEST == g_args.test_mode) || (QUERY_TEST == g_args.test_mode)) { printf("specified table query info: \n"); - printf("sqlCount: \033[33m%"PRIu64"\033[0m\n", + printf("sqlCount: \033[33m%d\033[0m\n", g_queryInfo.specifiedQueryInfo.sqlCount); if (g_queryInfo.specifiedQueryInfo.sqlCount > 0) { printf("specified tbl query times:\n"); @@ -1795,15 +1797,15 @@ static void printfQueryMeta() { printf("keepProgress: \033[33m%d\033[0m\n", g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); - for (uint64_t i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { - printf(" sql[%"PRIu64"]: \033[33m%s\033[0m\n", + for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { + printf(" sql[%d]: \033[33m%s\033[0m\n", i, g_queryInfo.specifiedQueryInfo.sql[i]); } printf("\n"); } printf("super table query info:\n"); - printf("sqlCount: \033[33m%"PRIu64"\033[0m\n", + printf("sqlCount: \033[33m%d\033[0m\n", g_queryInfo.superQueryInfo.sqlCount); if (g_queryInfo.superQueryInfo.sqlCount > 0) { @@ -4277,7 +4279,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { if (concurrent && concurrent->type == cJSON_Number) { if (concurrent->valueint <= 0) { errorPrint( - "%s() LN%d, query sqlCount %"PRIu64" or concurrent %d is not correct.\n", + "%s() LN%d, query sqlCount %d or concurrent %d is not correct.\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount, g_queryInfo.specifiedQueryInfo.concurrent); @@ -4376,6 +4378,17 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { tstrncpy(g_queryInfo.specifiedQueryInfo.sql[j], sqlStr->valuestring, MAX_QUERY_SQL_LENGTH); + cJSON* endAfterConsume = + cJSON_GetObjectItem(specifiedQuery, "endAfterConsume"); + if (endAfterConsume + && endAfterConsume->type == cJSON_Number) { + g_queryInfo.specifiedQueryInfo.endAfterConsume[j] + = endAfterConsume->valueint; + } else if (!endAfterConsume) { + // default value is -1, which mean infinite loop + g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = -1; + } + cJSON* resubAfterConsume = cJSON_GetObjectItem(specifiedQuery, "resubAfterConsume"); if (resubAfterConsume @@ -4383,9 +4396,8 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = resubAfterConsume->valueint; } else if (!resubAfterConsume) { - //printf("failed to read json, subscribe interval no found\n"); - //goto PARSE_OVER; - g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = 1; + // default value is -1, which mean do not resub + g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = -1; } cJSON *result = cJSON_GetObjectItem(sql, "result"); @@ -4529,16 +4541,26 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; } + cJSON* superEndAfterConsume = + cJSON_GetObjectItem(superQuery, "endAfterConsume"); + if (superEndAfterConsume + && superEndAfterConsume->type == cJSON_Number) { + g_queryInfo.superQueryInfo.endAfterConsume = + superEndAfterConsume->valueint; + } else if (!superEndAfterConsume) { + // default value is -1, which mean do not resub + g_queryInfo.superQueryInfo.endAfterConsume = -1; + } + cJSON* superResubAfterConsume = - cJSON_GetObjectItem(superQuery, "resubAfterConsume"); + cJSON_GetObjectItem(superQuery, "endAfterConsume"); if (superResubAfterConsume && superResubAfterConsume->type == cJSON_Number) { - g_queryInfo.superQueryInfo.resubAfterConsume = + g_queryInfo.superQueryInfo.endAfterConsume = superResubAfterConsume->valueint; } else if (!superResubAfterConsume) { - //printf("failed to read json, subscribe interval no found\n"); - ////goto PARSE_OVER; - g_queryInfo.superQueryInfo.resubAfterConsume = 1; + // default value is -1, which mean do not resub + g_queryInfo.superQueryInfo.endAfterConsume = -1; } // supert table sqls @@ -7262,7 +7284,10 @@ static void *superSubscribe(void *sarg) { uint64_t st = 0, et = 0; - while(1) { + while ((g_queryInfo.superQueryInfo.endAfterConsume == -1) + || (g_queryInfo.superQueryInfo.endAfterConsume < + consumed[pThreadInfo->end_table_to - pThreadInfo->start_table_from])) { + for (uint64_t i = pThreadInfo->start_table_from; i <= pThreadInfo->end_table_to; i++) { tsubSeq = i - pThreadInfo->start_table_from; @@ -7291,7 +7316,7 @@ static void *superSubscribe(void *sarg) { } consumed[tsubSeq] ++; - if ((g_queryInfo.superQueryInfo.subscribeKeepProgress) + if ((g_queryInfo.superQueryInfo.resubAfterConsume != -1) && (consumed[tsubSeq] >= g_queryInfo.superQueryInfo.resubAfterConsume)) { printf("keepProgress:%d, resub super table query: %"PRIu64"\n", @@ -7373,7 +7398,10 @@ static void *specifiedSubscribe(void *sarg) { // start loop to consume result g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = 0; - while(1) { + while((g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq] == -1) + || (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] < + g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq])) { + if (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode) { continue; } @@ -7392,7 +7420,7 @@ static void *specifiedSubscribe(void *sarg) { } g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] ++; - if ((g_queryInfo.specifiedQueryInfo.subscribeKeepProgress) + if ((g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq] != -1) && (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] >= g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq])) { printf("keepProgress:%d, resub specified query: %"PRIu64"\n", @@ -7460,12 +7488,12 @@ static int subscribeTestProcess() { //==== create threads for query for specified table if (g_queryInfo.specifiedQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, sepcified query sqlCount %"PRIu64".\n", + debugPrint("%s() LN%d, sepcified query sqlCount %d.\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount); } else { if (g_queryInfo.specifiedQueryInfo.concurrent <= 0) { - errorPrint("%s() LN%d, sepcified query sqlCount %"PRIu64".\n", + errorPrint("%s() LN%d, sepcified query sqlCount %d.\n", __func__, __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount); exit(-1); @@ -7498,7 +7526,7 @@ static int subscribeTestProcess() { //==== create threads for super table query if (g_queryInfo.superQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, super table query sqlCount %"PRIu64".\n", + debugPrint("%s() LN%d, super table query sqlCount %d.\n", __func__, __LINE__, g_queryInfo.superQueryInfo.sqlCount); } else { From 413e09307c8d71246920600a9fd8fc7da687469a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 29 May 2021 14:25:55 +0800 Subject: [PATCH 43/80] [TD-3178] fix some bug --- src/client/src/tscSQLParser.c | 8 +++++++- src/query/src/qExecutor.c | 30 ++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 8f726e17b5..b02d2fb5a4 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -916,6 +916,9 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS if (pQueryInfo->sessionWindow.gap != 0 && pQueryInfo->interval.interval != 0) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } + if (pQueryInfo->sessionWindow.gap == 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); + } SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(pCmd, col, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { @@ -6196,7 +6199,7 @@ static int32_t doTagFunctionCheck(SQueryInfo* pQueryInfo) { int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { const char* msg1 = "functions/columns not allowed in group by query"; const char* msg2 = "projection query on columns not allowed"; - const char* msg3 = "group by not allowed on projection query"; + const char* msg3 = "group by/session/state_window not allowed on projection query"; const char* msg4 = "retrieve tags not compatible with group by or interval query"; const char* msg5 = "functions can not be mixed up"; @@ -6212,6 +6215,9 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { return TSDB_CODE_SUCCESS; } } + if (tscIsProjectionQuery(pQueryInfo) && pQueryInfo->sessionWindow.gap > 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); + } if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { // check if all the tags prj columns belongs to the group by columns diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index ee40290078..1603768152 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -185,8 +185,12 @@ static void destroySFillOperatorInfo(void* param, int32_t numOfOutput); static void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput); static void destroyArithOperatorInfo(void* param, int32_t numOfOutput); static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput); +static void destroySWindowOperatorInfo(void* param, int32_t numOfOutput); +static void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput); +static void destroyAggOperatorInfo(void* param, int32_t numOfOutput); static void destroyOperatorInfo(SOperatorInfo* pOperator); + static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo* pGroupResInfo, int32_t orderType, SSDataBlock* pBlock); static int32_t getGroupbyColumnIndex(SSqlGroupbyExpr *pGroupbyExpr, SSDataBlock* pDataBlock); @@ -4541,7 +4545,6 @@ static void destroyGlobalAggOperatorInfo(void* param, int32_t numOfOutput) { tfree(pInfo->prevRow); tfree(pInfo->currentGroupColData); } - static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) { SSLimitOperatorInfo *pInfo = (SSLimitOperatorInfo*) param; taosArrayDestroy(pInfo->orderColumnList); @@ -5099,13 +5102,14 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } else if (memcmp(pInfo->prevData, val, bytes) == 0) { pInfo->curWindow.ekey = tsList[j]; pInfo->numOfRows += 1; - pInfo->start = j; + //pInfo->start = j; if (j == 0 && pInfo->start != 0) { pInfo->numOfRows = 1; pInfo->start = 0; } } else { SResultRow* pResult = NULL; + pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -5125,6 +5129,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } SResultRow* pResult = NULL; + pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -5442,7 +5447,7 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->exec = doAggregate; - pOperator->cleanup = destroyBasicOperatorInfo; + pOperator->cleanup = destroyAggOperatorInfo; return pOperator; } @@ -5460,6 +5465,19 @@ static void destroyBasicOperatorInfo(void* param, int32_t numOfOutput) { SOptrBasicInfo* pInfo = (SOptrBasicInfo*) param; doDestroyBasicInfo(pInfo, numOfOutput); } +static void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput) { + SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*) param; + doDestroyBasicInfo(&pInfo->binfo, numOfOutput); + tfree(pInfo->prevData); +} +static void destroyAggOperatorInfo(void* param, int32_t numOfOutput) { + SAggOperatorInfo* pInfo = (SAggOperatorInfo*) param; + doDestroyBasicInfo(&pInfo->binfo, numOfOutput); +} +static void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) { + SSWindowOperatorInfo* pInfo = (SSWindowOperatorInfo*) param; + doDestroyBasicInfo(&pInfo->binfo, numOfOutput); +} static void destroySFillOperatorInfo(void* param, int32_t numOfOutput) { SFillOperatorInfo* pInfo = (SFillOperatorInfo*) param; @@ -5515,7 +5533,7 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SO pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->exec = doSTableAggregate; - pOperator->cleanup = destroyBasicOperatorInfo; + pOperator->cleanup = destroyAggOperatorInfo; return pOperator; } @@ -5659,7 +5677,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpe pOperator->info = pInfo; pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->exec = doStateWindowAgg; - pOperator->cleanup = destroyBasicOperatorInfo; + pOperator->cleanup = destroyStateWindowOperatorInfo; return pOperator; } @@ -5683,7 +5701,7 @@ SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato pOperator->info = pInfo; pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->exec = doSessionWindowAgg; - pOperator->cleanup = destroyBasicOperatorInfo; + pOperator->cleanup = destroySWindowOperatorInfo; return pOperator; } From 458405cc6381c0436fb4c6c4f4c0eab2c6431481 Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Sat, 29 May 2021 18:52:56 +0800 Subject: [PATCH 44/80] [TD-4423]: add test case --- tests/pytest/insert/nchar.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pytest/insert/nchar.py b/tests/pytest/insert/nchar.py index 3319aa3c56..5ad52b96a1 100644 --- a/tests/pytest/insert/nchar.py +++ b/tests/pytest/insert/nchar.py @@ -36,6 +36,10 @@ class TDTestCase: tdSql.checkData(1, 1, '涛思数据') tdSql.error("insert into tb values (now, 'taosdata001')") + + tdSql.error("insert into tb(now, 😀)") + tdSql.query("select * from tb") + tdSql.checkRows(2) def stop(self): tdSql.close() From daa52050521df5726cd55edc5513c1b1db9d8dd5 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sun, 30 May 2021 07:02:30 +0800 Subject: [PATCH 45/80] Hotfix/sangshuduo/td 4406 taosdemo auto create tables (#6294) * [TD-4406]: taosdemo auto create table. * fix child table exists or auto create logic. * reduce redundant conditions. Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index e7b2d4f16b..c072045d56 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -5144,8 +5144,7 @@ static int generateStbSQLHead( char headBuf[HEAD_BUFF_LEN]; - if ((AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) - && (TBL_ALREADY_EXISTS != superTblInfo->childTblExists)) { + if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { char* tagsValBuf = NULL; if (0 == superTblInfo->tagSource) { tagsValBuf = generateTagVaulesForStb(superTblInfo, tableSeq); From 7946d97e3310884c173ed1532df9ee1c8a4c6004 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sun, 30 May 2021 07:03:23 +0800 Subject: [PATCH 46/80] Feature/sangshuduo/td 4068 taosdemo stmt for master (#6296) * [TD-4068]: taosdemo support stmt. for easy merge purpose. disabled in master. * fix clang compile error. * fix memory leak, add more macros. change sqlcount to int Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index c072045d56..f0b8cf7ca9 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -693,7 +693,11 @@ static void printHelp() { printf("%s%s%s%s\n", indent, "-p", indent, "The TCP/IP port number to use for the connection. Default is 0."); printf("%s%s%s%s\n", indent, "-I", indent, +#if STMT_IFACE_ENABLED == 1 "The interface (taosc, rest, and stmt) taosdemo uses. Default is 'taosc'."); +#else + "The interface (taosc, rest) taosdemo uses. Default is 'taosc'."); +#endif printf("%s%s%s%s\n", indent, "-d", indent, "Destination database. Default is 'test'."); printf("%s%s%s%s\n", indent, "-a", indent, @@ -793,8 +797,10 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { arguments->iface = TAOSC_IFACE; } else if (0 == strcasecmp(argv[i], "rest")) { arguments->iface = REST_IFACE; +#if STMT_IFACE_ENABLED == 1 } else if (0 == strcasecmp(argv[i], "stmt")) { arguments->iface = STMT_IFACE; +#endif } else { errorPrint("%s", "\n\t-I need a valid string following!\n"); exit(EXIT_FAILURE); @@ -3912,8 +3918,10 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { g_Dbs.db[i].superTbls[j].iface= TAOSC_IFACE; } else if (0 == strcasecmp(stbIface->valuestring, "rest")) { g_Dbs.db[i].superTbls[j].iface= REST_IFACE; +#if STMT_IFACE_ENABLED == 1 } else if (0 == strcasecmp(stbIface->valuestring, "stmt")) { g_Dbs.db[i].superTbls[j].iface= STMT_IFACE; +#endif } else { errorPrint("%s() LN%d, failed to read json, insert_mode %s not recognized\n", __func__, __LINE__, stbIface->valuestring); @@ -4933,6 +4941,7 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) } break; +#if STMT_IFACE_ENABLED == 1 case STMT_IFACE: debugPrint("%s() LN%d, stmt=%p", __func__, __LINE__, pThreadInfo->stmt); if (0 != taos_stmt_execute(pThreadInfo->stmt)) { @@ -4942,6 +4951,7 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) } affectedRows = k; break; +#endif default: errorPrint("%s() LN%d: unknown insert mode: %d\n", @@ -5506,6 +5516,7 @@ static int32_t prepareStmtWithoutStb( } } + free(bindArray); return k; } @@ -5586,6 +5597,7 @@ static int32_t prepareStbStmt(SSuperTable *stbInfo, } } + free(bindArray); return k; } #endif @@ -6407,6 +6419,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, exit(-1); } +#if STMT_IFACE_ENABLED == 1 if ((g_args.iface == STMT_IFACE) || ((superTblInfo) && (superTblInfo->iface == STMT_IFACE))) { @@ -6446,6 +6459,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, exit(-1); } } +#endif } else { pThreadInfo->taos = NULL; } @@ -6486,9 +6500,11 @@ static void startMultiThreadInsertData(int threads, char* db_name, tsem_destroy(&(pThreadInfo->lock_sem)); +#if STMT_IFACE_ENABLED == 1 if (pThreadInfo->stmt) { taos_stmt_close(pThreadInfo->stmt); } +#endif tsem_destroy(&(pThreadInfo->lock_sem)); taos_close(pThreadInfo->taos); From c60cf34575c3569f789b555490b7ddac8a875d77 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Thu, 27 May 2021 16:19:13 +0800 Subject: [PATCH 47/80] [TD-4243]:fix coredump when select _block_dist() from table --- src/query/src/qExecutor.c | 2 + src/tsdb/src/tsdbRead.c | 47 +++++------ tests/script/fullGeneralSuite.sim | 1 + tests/script/general/compute/block_dist.sim | 94 +++++++++++++++++++++ tests/script/general/compute/testSuite.sim | 1 + tests/script/regressionSuite.sim | 1 + 6 files changed, 122 insertions(+), 24 deletions(-) create mode 100644 tests/script/general/compute/block_dist.sim diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index eca2a25a35..f97a0c4a74 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2845,6 +2845,8 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, if (tagColId == TSDB_TBNAME_COLUMN_INDEX) { val = tsdbGetTableName(pTable); assert(val != NULL); + } else if (tagColId == TSDB_BLOCK_DIST_COLUMN_INDEX) { + val = NULL; } else { val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); } diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 1b24405952..1cc0780b9d 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -367,40 +367,39 @@ static STsdbQueryHandle* tsdbQueryTablesImpl(STsdbRepo* tsdb, STsdbQueryCond* pC goto out_of_memory; } - assert(pCond != NULL && pCond->numOfCols > 0 && pMemRef != NULL); + assert(pCond != NULL && pMemRef != NULL); if (ASCENDING_TRAVERSE(pCond->order)) { assert(pQueryHandle->window.skey <= pQueryHandle->window.ekey); } else { assert(pQueryHandle->window.skey >= pQueryHandle->window.ekey); } - - // allocate buffer in order to load data blocks from file - pQueryHandle->statis = calloc(pCond->numOfCols, sizeof(SDataStatis)); - if (pQueryHandle->statis == NULL) { - goto out_of_memory; - } - - pQueryHandle->pColumns = taosArrayInit(pCond->numOfCols, sizeof(SColumnInfoData)); // todo: use list instead of array? - if (pQueryHandle->pColumns == NULL) { - goto out_of_memory; - } - - for (int32_t i = 0; i < pCond->numOfCols; ++i) { - SColumnInfoData colInfo = {{0}, 0}; - - colInfo.info = pCond->colList[i]; - colInfo.pData = calloc(1, EXTRA_BYTES + pQueryHandle->outputCapacity * pCond->colList[i].bytes); - if (colInfo.pData == NULL) { + if (pCond->numOfCols > 0) { + // allocate buffer in order to load data blocks from file + pQueryHandle->statis = calloc(pCond->numOfCols, sizeof(SDataStatis)); + if (pQueryHandle->statis == NULL) { goto out_of_memory; } - taosArrayPush(pQueryHandle->pColumns, &colInfo); - pQueryHandle->statis[i].colId = colInfo.info.colId; - } - if (pCond->numOfCols > 0) { + pQueryHandle->pColumns = + taosArrayInit(pCond->numOfCols, sizeof(SColumnInfoData)); // todo: use list instead of array? + if (pQueryHandle->pColumns == NULL) { + goto out_of_memory; + } + + for (int32_t i = 0; i < pCond->numOfCols; ++i) { + SColumnInfoData colInfo = {{0}, 0}; + + colInfo.info = pCond->colList[i]; + colInfo.pData = calloc(1, EXTRA_BYTES + pQueryHandle->outputCapacity * pCond->colList[i].bytes); + if (colInfo.pData == NULL) { + goto out_of_memory; + } + taosArrayPush(pQueryHandle->pColumns, &colInfo); + pQueryHandle->statis[i].colId = colInfo.info.colId; + } + pQueryHandle->defaultLoadColumn = getDefaultLoadColumns(pQueryHandle, true); } - STsdbMeta* pMeta = tsdbGetMeta(tsdb); assert(pMeta != NULL); diff --git a/tests/script/fullGeneralSuite.sim b/tests/script/fullGeneralSuite.sim index cde51ebdbf..2cd2236200 100644 --- a/tests/script/fullGeneralSuite.sim +++ b/tests/script/fullGeneralSuite.sim @@ -33,6 +33,7 @@ run general/compute/percentile.sim run general/compute/stddev.sim run general/compute/sum.sim run general/compute/top.sim +run general/compute/block_dist.sim run general/db/alter_option.sim run general/db/alter_tables_d2.sim run general/db/alter_tables_v1.sim diff --git a/tests/script/general/compute/block_dist.sim b/tests/script/general/compute/block_dist.sim new file mode 100644 index 0000000000..51cf903654 --- /dev/null +++ b/tests/script/general/compute/block_dist.sim @@ -0,0 +1,94 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start +sleep 2000 +sql connect + +$dbPrefix = m_di_db +$tbPrefix = m_di_tb +$mtPrefix = m_di_mt +$ntPrefix = m_di_nt +$tbNum = 1 +$rowNum = 2000 + +print =============== step1 +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i +$nt = $ntPrefix . $i + +sql drop database $db -x step1 +step1: +sql create database $db +sql use $db +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using $mt tags( $i ) + + $x = 0 + while $x < $rowNum + $cc = $x * 60000 + $ms = 1601481600000 + $cc + sql insert into $tb values ($ms , $x ) + $x = $x + 1 + endw + + $i = $i + 1 +endw + +sql create table $nt (ts timestamp, tbcol int) +$x = 0 +while $x < $rowNum + $cc = $x * 60000 + $ms = 1601481600000 + $cc + sql insert into $nt values ($ms , $x ) + $x = $x + 1 +endw + +sleep 100 + +print =============== step2 +$i = 0 +$tb = $tbPrefix . $i + +sql select _block_dist() from $tb + +if $rows != 1 then + print expect 1, actual:$rows + return -1 +endi + +print =============== step3 +$i = 0 +$mt = $mtPrefix . $i +sql select _block_dist() from $mt + +if $rows != 1 then + print expect 1, actual:$rows + return -1 +endi + +print =============== step4 +$i = 0 +$nt = $ntPrefix . $i + +sql select _block_dist() from $nt + +if $rows != 1 then + print expect 1, actual:$rows + return -1 +endi + +print =============== clear +sql drop database $db +sql show databases +if $rows != 0 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/compute/testSuite.sim b/tests/script/general/compute/testSuite.sim index 6cd6badaee..91bf4bf0cd 100644 --- a/tests/script/general/compute/testSuite.sim +++ b/tests/script/general/compute/testSuite.sim @@ -14,3 +14,4 @@ run general/compute/percentile.sim run general/compute/stddev.sim run general/compute/sum.sim run general/compute/top.sim +run general/compute/block_dist.sim diff --git a/tests/script/regressionSuite.sim b/tests/script/regressionSuite.sim index e5e2194e87..d5742cd98f 100644 --- a/tests/script/regressionSuite.sim +++ b/tests/script/regressionSuite.sim @@ -32,6 +32,7 @@ run general/compute/percentile.sim run general/compute/stddev.sim run general/compute/sum.sim run general/compute/top.sim +run general/compute/block_dist.sim run general/db/alter_option.sim run general/db/alter_tables_d2.sim run general/db/alter_tables_v1.sim From 9291d422c549e4a54f74886aa204c15b94c7edf7 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 30 May 2021 23:34:12 +0800 Subject: [PATCH 48/80] [TD-4360]: Change the log output level from error to info --- src/tsdb/src/tsdbMeta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 0a4ea5e153..88293cfbbb 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -68,7 +68,7 @@ int tsdbCreateTable(STsdbRepo *repo, STableCfg *pCfg) { TABLE_CHAR_NAME(pMeta->tables[tid]), TABLE_TID(pMeta->tables[tid]), TABLE_UID(pMeta->tables[tid])); return 0; } else { - tsdbError("vgId:%d table %s at tid %d uid %" PRIu64 + tsdbInfo("vgId:%d table %s at tid %d uid %" PRIu64 " exists, replace it with new table, this can be not reasonable", REPO_ID(pRepo), TABLE_CHAR_NAME(pMeta->tables[tid]), TABLE_TID(pMeta->tables[tid]), TABLE_UID(pMeta->tables[tid])); From 50d9a1c5a5f3ab85c3b90db96c55f16b360e1e10 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Mon, 31 May 2021 11:11:02 +0800 Subject: [PATCH 49/80] [TD-4439] add test case --- tests/pytest/fulltest.sh | 1 + tests/pytest/insert/insert_before_use_db.py | 35 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/pytest/insert/insert_before_use_db.py diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index be2cfee04b..c93fbc5eb3 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -334,5 +334,6 @@ python3 ./test.py -f tag_lite/alter_tag.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py +python3 test.py -f insert/insert_before_use_db.py #======================p4-end=============== diff --git a/tests/pytest/insert/insert_before_use_db.py b/tests/pytest/insert/insert_before_use_db.py new file mode 100644 index 0000000000..94ee83b691 --- /dev/null +++ b/tests/pytest/insert/insert_before_use_db.py @@ -0,0 +1,35 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.error('insert into tb values (now + 10m, 10)') + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From 39342aec9b2cee57fe5d5d29520b749360418a2d Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Mon, 31 May 2021 11:16:56 +0800 Subject: [PATCH 50/80] [TD-4439] moldifying the test case --- tests/pytest/insert/insert_before_use_db.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pytest/insert/insert_before_use_db.py b/tests/pytest/insert/insert_before_use_db.py index 94ee83b691..8cc02b3d4b 100644 --- a/tests/pytest/insert/insert_before_use_db.py +++ b/tests/pytest/insert/insert_before_use_db.py @@ -24,6 +24,10 @@ class TDTestCase: def run(self): tdSql.error('insert into tb values (now + 10m, 10)') + tdSql.prepare() + tdSql.error('insert into tb values (now + 10m, 10)') + tdSql.execute('drop database db') + tdSql.error('insert into tb values (now + 10m, 10)') def stop(self): From 7f3fab499389316cd6b37d471ec42147ad758e7a Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 31 May 2021 11:39:32 +0800 Subject: [PATCH 51/80] Feature/sangshuduo/td 4068 taosdemo stmt for master (#6300) * [TD-4068]: taosdemo support stmt. for easy merge purpose. disabled in master. * fix clang compile error. * fix memory leak, add more macros. change sqlcount to int * fix rest segfault. Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index f0b8cf7ca9..993bb40ee2 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -2910,8 +2910,8 @@ static void* createTable(void *sarg) int buff_len; buff_len = BUFFER_SIZE / 8; - char *buffer = calloc(buff_len, 1); - if (buffer == NULL) { + pThreadInfo->buffer = calloc(buff_len, 1); + if (pThreadInfo->buffer == NULL) { errorPrint("%s() LN%d, Memory allocated failed!\n", __func__, __LINE__); exit(-1); } @@ -2926,7 +2926,7 @@ static void* createTable(void *sarg) for (uint64_t i = pThreadInfo->start_table_from; i <= pThreadInfo->end_table_to; i++) { if (0 == g_Dbs.use_metric) { - snprintf(buffer, buff_len, + snprintf(pThreadInfo->buffer, buff_len, "create table if not exists %s.%s%"PRIu64" %s;", pThreadInfo->db_name, g_args.tb_prefix, i, @@ -2935,13 +2935,13 @@ static void* createTable(void *sarg) if (superTblInfo == NULL) { errorPrint("%s() LN%d, use metric, but super table info is NULL\n", __func__, __LINE__); - free(buffer); + free(pThreadInfo->buffer); exit(-1); } else { if (0 == len) { batchNum = 0; - memset(buffer, 0, buff_len); - len += snprintf(buffer + len, + memset(pThreadInfo->buffer, 0, buff_len); + len += snprintf(pThreadInfo->buffer + len, buff_len - len, "create table "); } char* tagsValBuf = NULL; @@ -2953,10 +2953,10 @@ static void* createTable(void *sarg) i % superTblInfo->tagSampleCount); } if (NULL == tagsValBuf) { - free(buffer); + free(pThreadInfo->buffer); return NULL; } - len += snprintf(buffer + len, + len += snprintf(pThreadInfo->buffer + len, buff_len - len, "if not exists %s.%s%"PRIu64" using %s.%s tags %s ", pThreadInfo->db_name, superTblInfo->childTblPrefix, @@ -2973,9 +2973,10 @@ static void* createTable(void *sarg) } len = 0; - if (0 != queryDbExec(pThreadInfo->taos, buffer, NO_INSERT_TYPE, false)){ - errorPrint( "queryDbExec() failed. buffer:\n%s\n", buffer); - free(buffer); + if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, + NO_INSERT_TYPE, false)){ + errorPrint( "queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer); + free(pThreadInfo->buffer); return NULL; } @@ -2988,12 +2989,13 @@ static void* createTable(void *sarg) } if (0 != len) { - if (0 != queryDbExec(pThreadInfo->taos, buffer, NO_INSERT_TYPE, false)) { - errorPrint( "queryDbExec() failed. buffer:\n%s\n", buffer); + if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, + NO_INSERT_TYPE, false)) { + errorPrint( "queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer); } } - free(buffer); + free(pThreadInfo->buffer); return NULL; } @@ -4932,7 +4934,7 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) case REST_IFACE: if (0 != postProceSql(g_Dbs.host, &g_Dbs.serv_addr, g_Dbs.port, - pThreadInfo->buffer, NULL /* not set result file */)) { + pThreadInfo->buffer, pThreadInfo)) { affectedRows = -1; printf("========restful return fail, threadID[%d]\n", pThreadInfo->threadID); From 5276ccc334775167313e641313353193ac9b2b31 Mon Sep 17 00:00:00 2001 From: lichuang Date: Mon, 31 May 2021 11:56:19 +0800 Subject: [PATCH 52/80] [TD-1568]fix tdMergeDataCols bug --- src/common/src/tdataformat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index db73905119..7ae34d532c 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -462,8 +462,8 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int * } } target->numOfRows++; - (*pOffset)++; } + (*pOffset) += rowsToMerge; } else { pTarget = tdDupDataCols(target, true); if (pTarget == NULL) goto _err; From cd76a29533d5575990de44a11c8dfe0da48501de Mon Sep 17 00:00:00 2001 From: Steven Li Date: Mon, 31 May 2021 06:22:20 +0000 Subject: [PATCH 53/80] Adjust table locking in crash_gen to expose same-connection consistency issues, supporting TD-4444 --- src/connector/python/taos/__init__.py | 4 + tests/pytest/crash_gen/crash_gen_main.py | 139 ++++++++++++++++------ tests/pytest/crash_gen/service_manager.py | 10 +- tests/pytest/crash_gen/shared/misc.py | 3 +- 4 files changed, 115 insertions(+), 41 deletions(-) diff --git a/src/connector/python/taos/__init__.py b/src/connector/python/taos/__init__.py index 9732635738..52c6db311e 100644 --- a/src/connector/python/taos/__init__.py +++ b/src/connector/python/taos/__init__.py @@ -2,6 +2,10 @@ from .connection import TDengineConnection from .cursor import TDengineCursor +# For some reason, the following is needed for VS Code (through PyLance) to +# recognize that "error" is a valid module of the "taos" package. +from .error import ProgrammingError + # Globals threadsafety = 0 paramstyle = 'pyformat' diff --git a/tests/pytest/crash_gen/crash_gen_main.py b/tests/pytest/crash_gen/crash_gen_main.py index 644aa79916..b743eee2ef 100755 --- a/tests/pytest/crash_gen/crash_gen_main.py +++ b/tests/pytest/crash_gen/crash_gen_main.py @@ -37,6 +37,7 @@ import requests import gc import taos + from .shared.types import TdColumns, TdTags # from crash_gen import ServiceManager, TdeInstance, TdeSubProcess @@ -160,6 +161,7 @@ class WorkerThread: Logging.debug("[TRD] Thread Coordinator not running any more, worker thread now stopping...") break + # Before we fetch the task and run it, let's ensure we properly "use" the database (not needed any more) try: if (Config.getConfig().per_thread_db_connection): # most likely TRUE @@ -1362,9 +1364,12 @@ class Task(): Progress.emit(Progress.ACCEPTABLE_ERROR) self._err = err else: # not an acceptable error - errMsg = "[=] Unexpected Taos library exception ({}): errno=0x{:X}, msg: {}, SQL: {}".format( + shortTid = threading.get_ident() % 10000 + errMsg = "[=] Unexpected Taos library exception ({}): errno=0x{:X}, thread={}, msg: {}, SQL: {}".format( self.__class__.__name__, - errno2, err, wt.getDbConn().getLastSql()) + errno2, + shortTid, + err, wt.getDbConn().getLastSql()) self.logDebug(errMsg) if Config.getConfig().debug: # raise # so that we see full stack @@ -1411,21 +1416,31 @@ class Task(): def lockTable(self, ftName): # full table name # print(" <<" + ftName + '_', end="", flush=True) - with Task._lock: - if not ftName in Task._tableLocks: + with Task._lock: # SHORT lock! so we only protect lock creation + if not ftName in Task._tableLocks: # Create new lock and add to list, if needed Task._tableLocks[ftName] = threading.Lock() - Task._tableLocks[ftName].acquire() + # No lock protection, anybody can do this any time + lock = Task._tableLocks[ftName] + # Logging.info("Acquiring lock: {}, {}".format(ftName, lock)) + lock.acquire() + # Logging.info("Acquiring lock successful: {}".format(lock)) def unlockTable(self, ftName): # print('_' + ftName + ">> ", end="", flush=True) - with Task._lock: + with Task._lock: if not ftName in self._tableLocks: raise RuntimeError("Corrupt state, no such lock") lock = Task._tableLocks[ftName] if not lock.locked(): raise RuntimeError("Corrupte state, already unlocked") - lock.release() + + # Important note, we want to protect unlocking under the task level + # locking, because we don't want the lock to be deleted (maybe in the futur) + # while we unlock it + # Logging.info("Releasing lock: {}".format(lock)) + lock.release() + # Logging.info("Releasing lock successful: {}".format(lock)) class ExecutionStats: @@ -1696,6 +1711,11 @@ class TdSuperTable: return dbc.query("SELECT * FROM {}.{}".format(self._dbName, self._stName)) > 0 def ensureRegTable(self, task: Optional[Task], dbc: DbConn, regTableName: str): + ''' + Make sure a regular table exists for this super table, creating it if necessary. + If there is an associated "Task" that wants to do this, "lock" this table so that + others don't access it while we create it. + ''' dbName = self._dbName sql = "select tbname from {}.{} where tbname in ('{}')".format(dbName, self._stName, regTableName) if dbc.query(sql) >= 1 : # reg table exists already @@ -1703,18 +1723,24 @@ class TdSuperTable: # acquire a lock first, so as to be able to *verify*. More details in TD-1471 fullTableName = dbName + '.' + regTableName - if task is not None: # TODO: what happens if we don't lock the table - task.lockTable(fullTableName) + if task is not None: # Somethime thie operation is requested on behalf of a "task" + # Logging.info("Locking table for creation: {}".format(fullTableName)) + task.lockTable(fullTableName) # in which case we'll lock this table to ensure serialized access + # Logging.info("Table locked for creation".format(fullTableName)) Progress.emit(Progress.CREATE_TABLE_ATTEMPT) # ATTEMPT to create a new table # print("(" + fullTableName[-3:] + ")", end="", flush=True) try: sql = "CREATE TABLE {} USING {}.{} tags ({})".format( fullTableName, dbName, self._stName, self._getTagStrForSql(dbc) ) + # Logging.info("Creating regular with SQL: {}".format(sql)) dbc.execute(sql) + # Logging.info("Regular table created: {}".format(sql)) finally: if task is not None: + # Logging.info("Unlocking table after creation: {}".format(fullTableName)) task.unlockTable(fullTableName) # no matter what + # Logging.info("Table unlocked after creation: {}".format(fullTableName)) def _getTagStrForSql(self, dbc) : tags = self._getTags(dbc) @@ -2011,9 +2037,30 @@ class TaskAddData(StateTransitionTask): def canBeginFrom(cls, state: AnyState): return state.canAddData() + def _lockTableIfNeeded(self, fullTableName, extraMsg = ''): + if Config.getConfig().verify_data: + # Logging.info("Locking table: {}".format(fullTableName)) + self.lockTable(fullTableName) + # Logging.info("Table locked {}: {}".format(extraMsg, fullTableName)) + # print("_w" + str(nextInt % 100), end="", flush=True) # Trace what was written + else: + # Logging.info("Skipping locking table") + pass + + def _unlockTableIfNeeded(self, fullTableName): + if Config.getConfig().verify_data: + # Logging.info("Unlocking table: {}".format(fullTableName)) + self.unlockTable(fullTableName) + # Logging.info("Table unlocked: {}".format(fullTableName)) + else: + pass + # Logging.info("Skipping unlocking table") + def _addDataInBatch(self, db, dbc, regTableName, te: TaskExecutor): numRecords = self.LARGE_NUMBER_OF_RECORDS if Config.getConfig().larger_data else self.SMALL_NUMBER_OF_RECORDS + fullTableName = db.getName() + '.' + regTableName + self._lockTableIfNeeded(fullTableName, 'batch') sql = "INSERT INTO {} VALUES ".format(fullTableName) for j in range(numRecords): # number of records per table @@ -2021,51 +2068,60 @@ class TaskAddData(StateTransitionTask): nextTick = db.getNextTick() nextColor = db.getNextColor() sql += "('{}', {}, '{}');".format(nextTick, nextInt, nextColor) - dbc.execute(sql) + + # Logging.info("Adding data in batch: {}".format(sql)) + try: + dbc.execute(sql) + finally: + # Logging.info("Data added in batch: {}".format(sql)) + self._unlockTableIfNeeded(fullTableName) + + def _addData(self, db: Database, dbc, regTableName, te: TaskExecutor): # implied: NOT in batches numRecords = self.LARGE_NUMBER_OF_RECORDS if Config.getConfig().larger_data else self.SMALL_NUMBER_OF_RECORDS for j in range(numRecords): # number of records per table - nextInt = db.getNextInt() + intToWrite = db.getNextInt() nextTick = db.getNextTick() nextColor = db.getNextColor() if Config.getConfig().record_ops: self.prepToRecordOps() if self.fAddLogReady is None: raise CrashGenError("Unexpected empty fAddLogReady") - self.fAddLogReady.write("Ready to write {} to {}\n".format(nextInt, regTableName)) + self.fAddLogReady.write("Ready to write {} to {}\n".format(intToWrite, regTableName)) self.fAddLogReady.flush() os.fsync(self.fAddLogReady.fileno()) # TODO: too ugly trying to lock the table reliably, refactor... fullTableName = db.getName() + '.' + regTableName - if Config.getConfig().verify_data: - self.lockTable(fullTableName) - # print("_w" + str(nextInt % 100), end="", flush=True) # Trace what was written - + self._lockTableIfNeeded(fullTableName) # so that we are verify read-back. TODO: deal with exceptions before unlock + try: sql = "INSERT INTO {} VALUES ('{}', {}, '{}');".format( # removed: tags ('{}', {}) fullTableName, # ds.getFixedSuperTableName(), # ds.getNextBinary(), ds.getNextFloat(), - nextTick, nextInt, nextColor) + nextTick, intToWrite, nextColor) + # Logging.info("Adding data: {}".format(sql)) dbc.execute(sql) + # Logging.info("Data added: {}".format(sql)) + intWrote = intToWrite # Quick hack, attach an update statement here. TODO: create an "update" task if (not Config.getConfig().use_shadow_db) and Dice.throw(5) == 0: # 1 in N chance, plus not using shaddow DB - nextInt = db.getNextInt() + intToUpdate = db.getNextInt() # Updated, but should not succeed nextColor = db.getNextColor() sql = "INSERt INTO {} VALUES ('{}', {}, '{}');".format( # "INSERt" means "update" here fullTableName, - nextTick, nextInt, nextColor) + nextTick, intToUpdate, nextColor) # sql = "UPDATE {} set speed={}, color='{}' WHERE ts='{}'".format( # fullTableName, db.getNextInt(), db.getNextColor(), nextTick) dbc.execute(sql) + intWrote = intToUpdate # We updated, seems TDengine non-cluster accepts this. except: # Any exception at all - if Config.getConfig().verify_data: - self.unlockTable(fullTableName) + self._unlockTableIfNeeded(fullTableName) raise # Now read it back and verify, we might encounter an error if table is dropped @@ -2073,33 +2129,41 @@ class TaskAddData(StateTransitionTask): try: readBack = dbc.queryScalar("SELECT speed from {}.{} WHERE ts='{}'". format(db.getName(), regTableName, nextTick)) - if readBack != nextInt : + if readBack != intWrote : raise taos.error.ProgrammingError( "Failed to read back same data, wrote: {}, read: {}" - .format(nextInt, readBack), 0x999) + .format(intWrote, readBack), 0x999) except taos.error.ProgrammingError as err: errno = Helper.convertErrno(err.errno) - if errno in [CrashGenError.INVALID_EMPTY_RESULT, CrashGenError.INVALID_MULTIPLE_RESULT] : # not a single result + if errno == CrashGenError.INVALID_EMPTY_RESULT: # empty result raise taos.error.ProgrammingError( - "Failed to read back same data for tick: {}, wrote: {}, read: {}" - .format(nextTick, nextInt, "Empty Result" if errno == CrashGenError.INVALID_EMPTY_RESULT else "Multiple Result"), + "Failed to read back same data for tick: {}, wrote: {}, read: EMPTY" + .format(nextTick, intWrote), + errno) + elif errno == CrashGenError.INVALID_MULTIPLE_RESULT : # multiple results + raise taos.error.ProgrammingError( + "Failed to read back same data for tick: {}, wrote: {}, read: MULTIPLE RESULTS" + .format(nextTick, intWrote), errno) elif errno in [0x218, 0x362]: # table doesn't exist # do nothing - dummy = 0 + pass else: # Re-throw otherwise raise finally: - self.unlockTable(fullTableName) # Unlock the table no matter what + self._unlockTableIfNeeded(fullTableName) # Quite ugly, refactor lock/unlock + # Done with read-back verification, unlock the table now + else: + self._unlockTableIfNeeded(fullTableName) # Successfully wrote the data into the DB, let's record it somehow - te.recordDataMark(nextInt) + te.recordDataMark(intWrote) if Config.getConfig().record_ops: if self.fAddLogDone is None: raise CrashGenError("Unexpected empty fAddLogDone") - self.fAddLogDone.write("Wrote {} to {}\n".format(nextInt, regTableName)) + self.fAddLogDone.write("Wrote {} to {}\n".format(intWrote, regTableName)) self.fAddLogDone.flush() os.fsync(self.fAddLogDone.fileno()) @@ -2137,15 +2201,16 @@ class TaskAddData(StateTransitionTask): class ThreadStacks: # stack info for all threads def __init__(self): self._allStacks = {} - allFrames = sys._current_frames() - for th in threading.enumerate(): + allFrames = sys._current_frames() # All current stack frames + for th in threading.enumerate(): # For each thread if th.ident is None: continue - stack = traceback.extract_stack(allFrames[th.ident]) - self._allStacks[th.native_id] = stack + stack = traceback.extract_stack(allFrames[th.ident]) # Get stack for a thread + shortTid = th.ident % 10000 + self._allStacks[shortTid] = stack # Was using th.native_id def print(self, filteredEndName = None, filterInternal = False): - for thNid, stack in self._allStacks.items(): # for each thread, stack frames top to bottom + for tIdent, stack in self._allStacks.items(): # for each thread, stack frames top to bottom lastFrame = stack[-1] if filteredEndName: # we need to filter out stacks that match this name if lastFrame.name == filteredEndName : # end did not match @@ -2157,7 +2222,7 @@ class ThreadStacks: # stack info for all threads '__init__']: # the thread that extracted the stack continue # ignore # Now print - print("\n<----- Thread Info for LWP/ID: {} (most recent call last) <-----".format(thNid)) + print("\n<----- Thread Info for LWP/ID: {} (most recent call last) <-----".format(tIdent)) stackFrame = 0 for frame in stack: # was using: reversed(stack) # print(frame) @@ -2376,7 +2441,7 @@ class MainExec: action='store', default=0, type=int, - help='Maximum number of DBs to keep, set to disable dropping DB. (default: 0)') + help='Number of DBs to use, set to disable dropping DB. (default: 0)') parser.add_argument( '-c', '--connector-type', diff --git a/tests/pytest/crash_gen/service_manager.py b/tests/pytest/crash_gen/service_manager.py index 1cd65c1dde..c6685ec469 100644 --- a/tests/pytest/crash_gen/service_manager.py +++ b/tests/pytest/crash_gen/service_manager.py @@ -179,7 +179,7 @@ quorum 2 def getServiceCmdLine(self): # to start the instance if Config.getConfig().track_memory_leaks: Logging.info("Invoking VALGRIND on service...") - return ['exec /usr/bin/valgrind', '--leak-check=yes', self.getExecFile(), '-c', self.getCfgDir()] + return ['exec valgrind', '--leak-check=yes', self.getExecFile(), '-c', self.getCfgDir()] else: # TODO: move "exec -c" into Popen(), we can both "use shell" and NOT fork so ask to lose kill control return ["exec " + self.getExecFile(), '-c', self.getCfgDir()] # used in subproce.Popen() @@ -310,7 +310,7 @@ class TdeSubProcess: # print("Starting TDengine with env: ", myEnv.items()) print("Starting TDengine: {}".format(cmdLine)) - return Popen( + ret = Popen( ' '.join(cmdLine), # ' '.join(cmdLine) if useShell else cmdLine, shell=True, # Always use shell, since we need to pass ENV vars stdout=PIPE, @@ -318,6 +318,10 @@ class TdeSubProcess: close_fds=ON_POSIX, env=myEnv ) # had text=True, which interferred with reading EOF + time.sleep(0.01) # very brief wait, then let's check if sub process started successfully. + if ret.poll(): + raise CrashGenError("Sub process failed to start with command line: {}".format(cmdLine)) + return ret STOP_SIGNAL = signal.SIGINT # signal.SIGKILL/SIGINT # What signal to use (in kill) to stop a taosd process? SIG_KILL_RETCODE = 137 # ref: https://stackoverflow.com/questions/43268156/process-finished-with-exit-code-137-in-pycharm @@ -614,7 +618,7 @@ class ServiceManager: # Find if there's already a taosd service, and then kill it for proc in psutil.process_iter(): - if proc.name() == 'taosd': + if proc.name() == 'taosd' or proc.name() == 'memcheck-amd64-': # Regular or under Valgrind Logging.info("Killing an existing TAOSD process in 2 seconds... press CTRL-C to interrupt") time.sleep(2.0) proc.kill() diff --git a/tests/pytest/crash_gen/shared/misc.py b/tests/pytest/crash_gen/shared/misc.py index 90ad802ff1..78923bcc29 100644 --- a/tests/pytest/crash_gen/shared/misc.py +++ b/tests/pytest/crash_gen/shared/misc.py @@ -35,7 +35,8 @@ class LoggingFilter(logging.Filter): class MyLoggingAdapter(logging.LoggerAdapter): def process(self, msg, kwargs): - return "[{:04d}] {}".format(threading.get_ident() % 10000, msg), kwargs + shortTid = threading.get_ident() % 10000 + return "[{:04d}] {}".format(shortTid, msg), kwargs # return '[%s] %s' % (self.extra['connid'], msg), kwargs From e969616f5832e34ceb381bbe2dd2ca9cb75eb28f Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 31 May 2021 14:48:37 +0800 Subject: [PATCH 54/80] [td-255]update the sql.c --- src/inc/ttokendef.h | 198 ++-- src/query/src/sql.c | 2540 +++++++++++++++++++++++++------------------ 2 files changed, 1605 insertions(+), 1133 deletions(-) diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index 21e67413af..e9585636fd 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -17,105 +17,105 @@ #define TDENGINE_TTOKENDEF_H -#define TK_ID 1 -#define TK_BOOL 2 -#define TK_TINYINT 3 -#define TK_SMALLINT 4 -#define TK_INTEGER 5 -#define TK_BIGINT 6 -#define TK_FLOAT 7 -#define TK_DOUBLE 8 -#define TK_STRING 9 -#define TK_TIMESTAMP 10 -#define TK_BINARY 11 -#define TK_NCHAR 12 -#define TK_OR 13 -#define TK_AND 14 -#define TK_NOT 15 -#define TK_EQ 16 -#define TK_NE 17 -#define TK_ISNULL 18 -#define TK_NOTNULL 19 -#define TK_IS 20 -#define TK_LIKE 21 -#define TK_GLOB 22 -#define TK_BETWEEN 23 -#define TK_IN 24 -#define TK_GT 25 -#define TK_GE 26 -#define TK_LT 27 -#define TK_LE 28 -#define TK_BITAND 29 -#define TK_BITOR 30 -#define TK_LSHIFT 31 -#define TK_RSHIFT 32 -#define TK_PLUS 33 -#define TK_MINUS 34 -#define TK_DIVIDE 35 -#define TK_TIMES 36 -#define TK_STAR 37 -#define TK_SLASH 38 -#define TK_REM 39 -#define TK_CONCAT 40 -#define TK_UMINUS 41 -#define TK_UPLUS 42 -#define TK_BITNOT 43 -#define TK_SHOW 44 -#define TK_DATABASES 45 -#define TK_TOPICS 46 -#define TK_MNODES 47 -#define TK_DNODES 48 -#define TK_ACCOUNTS 49 -#define TK_USERS 50 -#define TK_MODULES 51 -#define TK_QUERIES 52 -#define TK_CONNECTIONS 53 -#define TK_STREAMS 54 -#define TK_VARIABLES 55 -#define TK_SCORES 56 -#define TK_GRANTS 57 -#define TK_VNODES 58 -#define TK_IPTOKEN 59 -#define TK_DOT 60 -#define TK_CREATE 61 -#define TK_TABLE 62 -#define TK_STABLE 63 -#define TK_DATABASE 64 -#define TK_TABLES 65 -#define TK_STABLES 66 -#define TK_VGROUPS 67 -#define TK_DROP 68 -#define TK_TOPIC 69 -#define TK_DNODE 70 -#define TK_USER 71 -#define TK_ACCOUNT 72 -#define TK_USE 73 -#define TK_DESCRIBE 74 -#define TK_ALTER 75 -#define TK_PASS 76 -#define TK_PRIVILEGE 77 -#define TK_LOCAL 78 -#define TK_IF 79 -#define TK_EXISTS 80 -#define TK_PPS 81 -#define TK_TSERIES 82 -#define TK_DBS 83 -#define TK_STORAGE 84 -#define TK_QTIME 85 -#define TK_CONNS 86 -#define TK_STATE 87 -#define TK_KEEP 88 -#define TK_CACHE 89 -#define TK_REPLICA 90 -#define TK_QUORUM 91 -#define TK_DAYS 92 -#define TK_MINROWS 93 -#define TK_MAXROWS 94 -#define TK_BLOCKS 95 -#define TK_CTIME 96 -#define TK_WAL 97 -#define TK_FSYNC 98 -#define TK_COMP 99 +#define TK_ID 1 +#define TK_BOOL 2 +#define TK_TINYINT 3 +#define TK_SMALLINT 4 +#define TK_INTEGER 5 +#define TK_BIGINT 6 +#define TK_FLOAT 7 +#define TK_DOUBLE 8 +#define TK_STRING 9 +#define TK_TIMESTAMP 10 +#define TK_BINARY 11 +#define TK_NCHAR 12 +#define TK_OR 13 +#define TK_AND 14 +#define TK_NOT 15 +#define TK_EQ 16 +#define TK_NE 17 +#define TK_ISNULL 18 +#define TK_NOTNULL 19 +#define TK_IS 20 +#define TK_LIKE 21 +#define TK_GLOB 22 +#define TK_BETWEEN 23 +#define TK_IN 24 +#define TK_GT 25 +#define TK_GE 26 +#define TK_LT 27 +#define TK_LE 28 +#define TK_BITAND 29 +#define TK_BITOR 30 +#define TK_LSHIFT 31 +#define TK_RSHIFT 32 +#define TK_PLUS 33 +#define TK_MINUS 34 +#define TK_DIVIDE 35 +#define TK_TIMES 36 +#define TK_STAR 37 +#define TK_SLASH 38 +#define TK_REM 39 +#define TK_CONCAT 40 +#define TK_UMINUS 41 +#define TK_UPLUS 42 +#define TK_BITNOT 43 +#define TK_SHOW 44 +#define TK_DATABASES 45 +#define TK_TOPICS 46 +#define TK_MNODES 47 +#define TK_DNODES 48 +#define TK_ACCOUNTS 49 +#define TK_USERS 50 +#define TK_MODULES 51 +#define TK_QUERIES 52 +#define TK_CONNECTIONS 53 +#define TK_STREAMS 54 +#define TK_VARIABLES 55 +#define TK_SCORES 56 +#define TK_GRANTS 57 +#define TK_VNODES 58 +#define TK_IPTOKEN 59 +#define TK_DOT 60 +#define TK_CREATE 61 +#define TK_TABLE 62 +#define TK_STABLE 63 +#define TK_DATABASE 64 +#define TK_TABLES 65 +#define TK_STABLES 66 +#define TK_VGROUPS 67 +#define TK_DROP 68 +#define TK_TOPIC 69 +#define TK_DNODE 70 +#define TK_USER 71 +#define TK_ACCOUNT 72 +#define TK_USE 73 +#define TK_DESCRIBE 74 +#define TK_ALTER 75 +#define TK_PASS 76 +#define TK_PRIVILEGE 77 +#define TK_LOCAL 78 +#define TK_IF 79 +#define TK_EXISTS 80 +#define TK_PPS 81 +#define TK_TSERIES 82 +#define TK_DBS 83 +#define TK_STORAGE 84 +#define TK_QTIME 85 +#define TK_CONNS 86 +#define TK_STATE 87 +#define TK_KEEP 88 +#define TK_CACHE 89 +#define TK_REPLICA 90 +#define TK_QUORUM 91 +#define TK_DAYS 92 +#define TK_MINROWS 93 +#define TK_MAXROWS 94 +#define TK_BLOCKS 95 +#define TK_CTIME 96 +#define TK_WAL 97 +#define TK_FSYNC 98 +#define TK_COMP 99 #define TK_PRECISION 100 #define TK_UPDATE 101 #define TK_CACHELAST 102 diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 9909ef2e13..55a6833cc1 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -1,9 +1,29 @@ -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. +/* +** 2000-05-29 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** Driver template for the LEMON parser generator. +** +** The "lemon" program processes an LALR(1) input grammar file, then uses +** this template to construct a parser. The "lemon" program inserts text +** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the +** interstitial "-" characters) contained in this template is changed into +** the value of the %name directive from the grammar. Otherwise, the content +** of this template is copied straight through into the generate parser +** source file. +** +** The following is the concatenation of all %include directives from the +** input grammar file: */ -/* First off, code is included that follows the "include" declaration -** in the input grammar file. */ #include +/************ Begin %include sections from the grammar ************************/ #include #include @@ -16,55 +36,66 @@ #include "ttokendef.h" #include "tutil.h" #include "tvariant.h" -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* -** These constants (all generated automatically by the parser generator) -** specify the various kinds of tokens (terminals) that the parser -** understands. -** -** Each symbol here is a terminal symbol in the grammar. -*/ -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control +/**************** End of %include directives **********************************/ +/* These constants specify the various numeric values for terminal symbols +** in a format understandable to "makeheaders". This section is blank unless +** "lemon" is run with the "-m" command-line option. +***************** Begin makeheaders token definitions *************************/ +/**************** End makeheaders token definitions ***************************/ + +/* The next sections is a series of control #defines. ** various aspects of the generated parser. -** YYCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** YYNOCODE is a number of type YYCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. +** YYCODETYPE is the data type used to store the integer codes +** that represent terminal and non-terminal symbols. +** "unsigned char" is used if there are fewer than +** 256 symbols. Larger types otherwise. +** YYNOCODE is a number of type YYCODETYPE that is not used for +** any terminal or nonterminal symbol. ** YYFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** YYACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** ParseTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** YYMINORTYPE is the data type used for all minor tokens. +** (also known as: "terminal symbols") have fall-back +** values which should be used if the original symbol +** would not parse. This permits keywords to sometimes +** be used as identifiers, for example. +** YYACTIONTYPE is the data type used for "action codes" - numbers +** that indicate what to do in response to the next +** token. +** ParseTOKENTYPE is the data type used for minor type for terminal +** symbols. Background: A "minor type" is a semantic +** value associated with a terminal or non-terminal +** symbols. For example, for an "ID" terminal symbol, +** the minor type might be the name of the identifier. +** Each non-terminal can have a different minor type. +** Terminal symbols all have the same minor type, though. +** This macros defines the minor type for terminal +** symbols. +** YYMINORTYPE is the data type used for all minor types. ** This is typically a union of many types, one of ** which is ParseTOKENTYPE. The entry in the union -** for base tokens is called "yy0". +** for terminal symbols is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If ** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument ** ParseARG_STORE Code to store %extra_argument into yypParser ** ParseARG_FETCH Code to extract %extra_argument from yypParser -** YYNSTATE the combined number of states. -** YYNRULE the number of rules in the grammar ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. +** YYNSTATE the combined number of states. +** YYNRULE the number of rules in the grammar +** YYNTOKEN Number of terminal symbols +** YY_MAX_SHIFT Maximum value for shift actions +** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions +** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions +** YY_ERROR_ACTION The yy_action[] code for syntax error +** YY_ACCEPT_ACTION The yy_action[] code for accept +** YY_NO_ACTION The yy_action[] code for no-op +** YY_MIN_REDUCE Minimum value for reduce actions +** YY_MAX_REDUCE Maximum value for reduce actions */ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int #define YYNOCODE 267 #define YYACTIONTYPE unsigned short int @@ -96,16 +127,19 @@ typedef union { #define ParseARG_PDECL ,SSqlInfo* pInfo #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo -#define YYNSTATE 523 -#define YYNRULE 275 #define YYFALLBACK 1 -#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) -#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) -#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) - -/* The yyzerominor constant is used to initialize instances of -** YYMINORTYPE objects to zero. */ -static const YYMINORTYPE yyzerominor = { 0 }; +#define YYNSTATE 327 +#define YYNRULE 275 +#define YYNTOKEN 188 +#define YY_MAX_SHIFT 326 +#define YY_MIN_SHIFTREDUCE 523 +#define YY_MAX_SHIFTREDUCE 797 +#define YY_ERROR_ACTION 798 +#define YY_ACCEPT_ACTION 799 +#define YY_NO_ACTION 800 +#define YY_MIN_REDUCE 801 +#define YY_MAX_REDUCE 1075 +/************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. @@ -128,33 +162,35 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** Suppose the action integer is N. Then the action is determined as ** follows ** -** 0 <= N < YYNSTATE Shift N. That is, push the lookahead +** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead ** token onto the stack and goto state N. ** -** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. +** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then +** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. ** -** N == YYNSTATE+YYNRULE A syntax error has occurred. +** N == YY_ERROR_ACTION A syntax error has occurred. ** -** N == YYNSTATE+YYNRULE+1 The parser accepts its input. +** N == YY_ACCEPT_ACTION The parser accepts its input. ** -** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused +** N == YY_NO_ACTION No such action. Denotes unused ** slots in the yy_action[] table. ** +** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE +** and YY_MAX_REDUCE +** ** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as +** Given state S and lookahead X, the action is computed as either: ** -** yy_action[ yy_shift_ofst[S] + X ] +** (A) N = yy_action[ yy_shift_ofst[S] + X ] +** (B) N = yy_default[S] ** -** If the index value yy_shift_ofst[S]+X is out of range or if the value -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] -** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. +** The (A) formula is preferred. The B formula is used instead if +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X. ** -** The formula above is for computing the action when the lookahead is +** The formulas above are for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after ** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. +** the yy_shift_ofst[] array. ** ** The following are the tables generated in this section: ** @@ -166,298 +202,273 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. -*/ -#define YY_ACTTAB_COUNT (811) +** +*********** Begin parsing tables **********************************************/ +#define YY_ACTTAB_COUNT (700) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 506, 47, 46, 523, 31, 45, 44, 43, 505, 242, - /* 10 */ 799, 326, 48, 49, 345, 52, 53, 246, 245, 223, - /* 20 */ 42, 8, 51, 274, 56, 54, 58, 55, 136, 134, - /* 30 */ 133, 398, 47, 46, 138, 61, 45, 44, 43, 48, - /* 40 */ 49, 509, 52, 53, 31, 302, 223, 42, 435, 51, - /* 50 */ 274, 56, 54, 58, 55, 234, 342, 119, 118, 47, - /* 60 */ 46, 17, 16, 45, 44, 43, 48, 49, 29, 52, - /* 70 */ 53, 280, 250, 223, 42, 383, 51, 274, 56, 54, - /* 80 */ 58, 55, 323, 322, 130, 298, 47, 46, 435, 508, - /* 90 */ 45, 44, 43, 48, 50, 497, 52, 53, 257, 256, - /* 100 */ 223, 42, 506, 51, 274, 56, 54, 58, 55, 71, - /* 110 */ 505, 382, 463, 47, 46, 465, 464, 45, 44, 43, - /* 120 */ 462, 221, 460, 459, 461, 236, 458, 457, 297, 296, - /* 130 */ 406, 384, 418, 417, 416, 415, 414, 413, 412, 411, - /* 140 */ 410, 409, 408, 407, 405, 404, 522, 521, 520, 519, - /* 150 */ 518, 517, 516, 515, 514, 513, 512, 511, 510, 325, - /* 160 */ 62, 49, 212, 52, 53, 6, 232, 223, 42, 86, - /* 170 */ 51, 274, 56, 54, 58, 55, 132, 380, 145, 379, - /* 180 */ 47, 46, 506, 63, 45, 44, 43, 52, 53, 279, - /* 190 */ 505, 223, 42, 87, 51, 274, 56, 54, 58, 55, - /* 200 */ 401, 400, 30, 394, 47, 46, 131, 13, 45, 44, - /* 210 */ 43, 88, 31, 85, 397, 45, 44, 43, 61, 24, - /* 220 */ 288, 319, 318, 287, 286, 285, 317, 284, 316, 315, - /* 230 */ 314, 283, 313, 312, 222, 370, 233, 89, 381, 292, - /* 240 */ 374, 377, 373, 376, 222, 370, 31, 354, 381, 269, - /* 250 */ 374, 440, 373, 294, 106, 105, 435, 31, 15, 14, - /* 260 */ 56, 54, 58, 55, 19, 65, 207, 208, 47, 46, - /* 270 */ 273, 399, 45, 44, 43, 31, 207, 208, 275, 300, - /* 280 */ 299, 197, 478, 506, 477, 25, 66, 293, 198, 378, - /* 290 */ 435, 505, 188, 122, 121, 196, 289, 24, 227, 319, - /* 300 */ 318, 435, 219, 363, 317, 31, 316, 315, 314, 61, - /* 310 */ 313, 312, 473, 107, 101, 112, 226, 145, 472, 435, - /* 320 */ 111, 117, 120, 110, 77, 471, 180, 178, 176, 114, - /* 330 */ 100, 99, 37, 175, 125, 124, 123, 57, 480, 334, - /* 340 */ 476, 483, 475, 482, 369, 481, 213, 57, 188, 435, - /* 350 */ 371, 656, 277, 375, 369, 249, 32, 69, 220, 363, - /* 360 */ 371, 393, 68, 204, 437, 32, 145, 372, 84, 237, - /* 370 */ 238, 5, 34, 162, 386, 359, 358, 372, 161, 96, - /* 380 */ 91, 95, 72, 368, 271, 364, 82, 20, 350, 20, - /* 390 */ 351, 347, 21, 75, 61, 140, 74, 70, 251, 77, - /* 400 */ 31, 253, 32, 109, 253, 3, 173, 37, 310, 453, - /* 410 */ 1, 160, 426, 172, 454, 235, 172, 333, 172, 395, - /* 420 */ 145, 342, 342, 188, 335, 320, 470, 230, 469, 332, - /* 430 */ 290, 468, 228, 217, 362, 83, 467, 215, 214, 211, - /* 440 */ 324, 466, 456, 452, 442, 451, 450, 479, 449, 448, - /* 450 */ 436, 474, 447, 474, 446, 445, 32, 441, 474, 474, - /* 460 */ 439, 229, 438, 104, 102, 98, 94, 60, 425, 424, - /* 470 */ 423, 422, 421, 420, 90, 88, 23, 278, 419, 22, - /* 480 */ 276, 12, 385, 7, 11, 361, 10, 337, 144, 355, - /* 490 */ 28, 27, 352, 265, 218, 81, 253, 349, 80, 76, - /* 500 */ 348, 141, 142, 331, 346, 79, 26, 330, 343, 255, - /* 510 */ 9, 329, 248, 244, 243, 328, 241, 327, 2, 135, - /* 520 */ 240, 4, 504, 503, 321, 129, 498, 455, 128, 307, - /* 530 */ 496, 311, 127, 126, 489, 309, 308, 170, 304, 306, - /* 540 */ 290, 305, 171, 108, 403, 155, 169, 167, 303, 168, - /* 550 */ 203, 210, 166, 93, 165, 41, 281, 443, 231, 92, - /* 560 */ 259, 151, 209, 154, 152, 262, 270, 800, 264, 267, - /* 570 */ 153, 357, 260, 216, 258, 800, 800, 800, 800, 261, - /* 580 */ 800, 266, 800, 800, 800, 268, 800, 800, 800, 800, - /* 590 */ 353, 800, 301, 272, 150, 800, 149, 78, 73, 59, - /* 600 */ 148, 252, 147, 64, 182, 146, 67, 507, 181, 391, - /* 610 */ 502, 501, 500, 800, 800, 800, 499, 179, 800, 177, - /* 620 */ 800, 495, 494, 800, 493, 492, 491, 490, 360, 800, - /* 630 */ 800, 800, 800, 800, 800, 800, 392, 800, 310, 800, - /* 640 */ 800, 225, 800, 800, 254, 341, 156, 800, 800, 800, - /* 650 */ 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, - /* 660 */ 800, 800, 800, 800, 40, 800, 174, 800, 239, 800, - /* 670 */ 488, 487, 116, 115, 486, 113, 485, 184, 39, 33, - /* 680 */ 800, 36, 444, 164, 434, 800, 433, 103, 432, 295, - /* 690 */ 163, 430, 429, 97, 428, 427, 291, 35, 800, 183, - /* 700 */ 800, 38, 800, 800, 800, 282, 402, 159, 158, 396, - /* 710 */ 157, 800, 263, 143, 139, 344, 340, 339, 338, 336, - /* 720 */ 137, 247, 800, 800, 800, 800, 800, 800, 800, 800, - /* 730 */ 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, - /* 740 */ 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, - /* 750 */ 800, 800, 800, 800, 800, 800, 800, 800, 390, 389, - /* 760 */ 224, 388, 387, 800, 800, 800, 800, 800, 800, 800, - /* 770 */ 800, 800, 484, 431, 800, 800, 800, 800, 800, 800, - /* 780 */ 800, 356, 800, 800, 800, 800, 800, 800, 800, 800, - /* 790 */ 800, 189, 199, 185, 200, 202, 201, 195, 194, 187, - /* 800 */ 193, 191, 190, 206, 205, 367, 366, 365, 192, 186, - /* 810 */ 18, + /* 0 */ 969, 571, 211, 324, 934, 18, 217, 186, 188, 572, + /* 10 */ 799, 326, 192, 48, 49, 145, 52, 53, 220, 1057, + /* 20 */ 223, 42, 275, 51, 274, 56, 54, 58, 55, 1053, + /* 30 */ 650, 188, 948, 47, 46, 188, 228, 45, 44, 43, + /* 40 */ 48, 49, 1056, 52, 53, 219, 1057, 223, 42, 571, + /* 50 */ 51, 274, 56, 54, 58, 55, 960, 572, 300, 299, + /* 60 */ 47, 46, 948, 966, 45, 44, 43, 49, 31, 52, + /* 70 */ 53, 138, 250, 223, 42, 1067, 51, 274, 56, 54, + /* 80 */ 58, 55, 271, 290, 82, 1052, 47, 46, 89, 234, + /* 90 */ 45, 44, 43, 524, 525, 526, 527, 528, 529, 530, + /* 100 */ 531, 532, 533, 534, 535, 536, 325, 571, 290, 212, + /* 110 */ 71, 571, 944, 48, 49, 572, 52, 53, 760, 572, + /* 120 */ 223, 42, 936, 51, 274, 56, 54, 58, 55, 45, + /* 130 */ 44, 43, 741, 47, 46, 257, 256, 45, 44, 43, + /* 140 */ 48, 50, 145, 52, 53, 1, 160, 223, 42, 145, + /* 150 */ 51, 274, 56, 54, 58, 55, 323, 322, 130, 236, + /* 160 */ 47, 46, 297, 296, 45, 44, 43, 24, 288, 319, + /* 170 */ 318, 287, 286, 285, 317, 284, 316, 315, 314, 283, + /* 180 */ 313, 312, 908, 31, 896, 897, 898, 899, 900, 901, + /* 190 */ 902, 903, 904, 905, 906, 907, 909, 910, 52, 53, + /* 200 */ 847, 960, 223, 42, 172, 51, 274, 56, 54, 58, + /* 210 */ 55, 1005, 19, 86, 25, 47, 46, 214, 83, 45, + /* 220 */ 44, 43, 222, 756, 213, 310, 745, 945, 748, 197, + /* 230 */ 751, 222, 756, 230, 13, 745, 198, 748, 88, 751, + /* 240 */ 85, 122, 121, 196, 931, 932, 30, 935, 56, 54, + /* 250 */ 58, 55, 3, 173, 207, 208, 47, 46, 273, 948, + /* 260 */ 45, 44, 43, 207, 208, 242, 232, 747, 24, 750, + /* 270 */ 319, 318, 77, 246, 245, 317, 689, 316, 315, 314, + /* 280 */ 37, 313, 312, 62, 916, 47, 46, 914, 915, 45, + /* 290 */ 44, 43, 917, 942, 919, 920, 918, 145, 921, 922, + /* 300 */ 107, 101, 112, 249, 31, 69, 63, 111, 117, 120, + /* 310 */ 110, 204, 674, 109, 235, 671, 114, 672, 310, 673, + /* 320 */ 5, 34, 162, 1051, 70, 57, 31, 161, 96, 91, + /* 330 */ 95, 31, 757, 31, 57, 229, 233, 31, 753, 292, + /* 340 */ 746, 757, 749, 237, 238, 226, 31, 753, 945, 946, + /* 350 */ 180, 178, 176, 205, 693, 752, 933, 175, 125, 124, + /* 360 */ 123, 136, 134, 133, 752, 77, 1006, 227, 269, 320, + /* 370 */ 945, 84, 293, 37, 294, 945, 856, 945, 298, 754, + /* 380 */ 172, 945, 848, 960, 686, 72, 172, 302, 722, 723, + /* 390 */ 945, 8, 251, 743, 74, 948, 32, 75, 221, 215, + /* 400 */ 705, 206, 253, 713, 140, 253, 714, 61, 777, 758, + /* 410 */ 21, 65, 20, 20, 660, 678, 277, 679, 32, 662, + /* 420 */ 32, 675, 279, 61, 661, 190, 87, 29, 61, 744, + /* 430 */ 280, 191, 66, 100, 99, 15, 14, 119, 118, 106, + /* 440 */ 105, 68, 6, 649, 17, 16, 676, 193, 677, 187, + /* 450 */ 194, 195, 755, 201, 202, 200, 185, 199, 189, 947, + /* 460 */ 1016, 1015, 224, 1012, 1011, 247, 137, 40, 225, 301, + /* 470 */ 968, 979, 976, 977, 981, 139, 143, 961, 254, 998, + /* 480 */ 997, 943, 263, 156, 135, 157, 704, 258, 311, 941, + /* 490 */ 912, 306, 108, 303, 155, 150, 148, 958, 158, 159, + /* 500 */ 859, 67, 146, 216, 282, 38, 260, 183, 35, 267, + /* 510 */ 291, 64, 855, 1072, 97, 59, 1071, 1069, 163, 295, + /* 520 */ 1066, 103, 1065, 1063, 164, 877, 36, 272, 33, 270, + /* 530 */ 268, 39, 184, 844, 113, 842, 115, 116, 840, 839, + /* 540 */ 239, 174, 837, 836, 835, 834, 833, 832, 177, 179, + /* 550 */ 829, 827, 825, 266, 823, 181, 820, 182, 264, 252, + /* 560 */ 73, 78, 262, 261, 999, 259, 41, 304, 305, 307, + /* 570 */ 209, 231, 308, 309, 281, 321, 797, 240, 241, 210, + /* 580 */ 796, 92, 93, 203, 244, 243, 795, 783, 782, 838, + /* 590 */ 248, 253, 681, 276, 126, 171, 166, 878, 167, 165, + /* 600 */ 168, 169, 831, 170, 9, 127, 128, 830, 76, 129, + /* 610 */ 822, 821, 2, 26, 4, 255, 79, 706, 153, 151, + /* 620 */ 149, 147, 152, 154, 141, 924, 709, 142, 80, 218, + /* 630 */ 711, 81, 265, 761, 715, 144, 90, 10, 11, 27, + /* 640 */ 759, 28, 7, 12, 22, 88, 23, 613, 278, 609, + /* 650 */ 607, 606, 605, 602, 575, 289, 94, 32, 60, 98, + /* 660 */ 652, 651, 648, 102, 597, 595, 104, 587, 593, 589, + /* 670 */ 591, 585, 583, 616, 615, 614, 612, 611, 610, 608, + /* 680 */ 604, 603, 573, 540, 538, 61, 801, 800, 800, 800, + /* 690 */ 800, 800, 800, 800, 800, 800, 800, 800, 131, 132, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 1, 33, 34, 0, 192, 37, 38, 39, 9, 136, - /* 10 */ 189, 190, 13, 14, 109, 16, 17, 144, 145, 20, - /* 20 */ 21, 116, 23, 24, 25, 26, 27, 28, 62, 63, - /* 30 */ 64, 105, 33, 34, 192, 109, 37, 38, 39, 13, - /* 40 */ 14, 59, 16, 17, 192, 233, 20, 21, 236, 23, - /* 50 */ 24, 25, 26, 27, 28, 68, 235, 76, 77, 33, - /* 60 */ 34, 139, 140, 37, 38, 39, 13, 14, 104, 16, - /* 70 */ 17, 107, 251, 20, 21, 1, 23, 24, 25, 26, - /* 80 */ 27, 28, 65, 66, 67, 233, 33, 34, 236, 60, - /* 90 */ 37, 38, 39, 13, 14, 80, 16, 17, 256, 257, - /* 100 */ 20, 21, 1, 23, 24, 25, 26, 27, 28, 110, - /* 110 */ 9, 37, 210, 33, 34, 213, 214, 37, 38, 39, - /* 120 */ 218, 60, 220, 221, 222, 138, 224, 225, 141, 142, - /* 130 */ 210, 105, 212, 213, 214, 215, 216, 217, 218, 219, - /* 140 */ 220, 221, 222, 223, 224, 225, 45, 46, 47, 48, - /* 150 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, - /* 160 */ 109, 14, 61, 16, 17, 104, 68, 20, 21, 198, - /* 170 */ 23, 24, 25, 26, 27, 28, 21, 5, 192, 7, - /* 180 */ 33, 34, 1, 132, 37, 38, 39, 16, 17, 105, - /* 190 */ 9, 20, 21, 109, 23, 24, 25, 26, 27, 28, - /* 200 */ 229, 230, 231, 232, 33, 34, 21, 104, 37, 38, - /* 210 */ 39, 108, 192, 110, 105, 37, 38, 39, 109, 88, - /* 220 */ 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, - /* 230 */ 99, 100, 101, 102, 1, 2, 138, 198, 5, 141, - /* 240 */ 7, 5, 9, 7, 1, 2, 192, 261, 5, 263, - /* 250 */ 7, 5, 9, 233, 139, 140, 236, 192, 139, 140, - /* 260 */ 25, 26, 27, 28, 44, 109, 33, 34, 33, 34, - /* 270 */ 37, 232, 37, 38, 39, 192, 33, 34, 15, 33, - /* 280 */ 34, 61, 5, 1, 7, 104, 130, 233, 68, 117, - /* 290 */ 236, 9, 254, 73, 74, 75, 15, 88, 233, 90, - /* 300 */ 91, 236, 264, 265, 95, 192, 97, 98, 99, 109, - /* 310 */ 101, 102, 5, 62, 63, 64, 233, 192, 5, 236, - /* 320 */ 69, 70, 71, 72, 104, 5, 62, 63, 64, 78, - /* 330 */ 139, 140, 112, 69, 70, 71, 72, 104, 2, 37, - /* 340 */ 5, 5, 7, 7, 111, 9, 233, 104, 254, 236, - /* 350 */ 117, 0, 105, 117, 111, 135, 109, 137, 264, 265, - /* 360 */ 117, 105, 104, 143, 106, 109, 192, 134, 238, 33, - /* 370 */ 34, 62, 63, 64, 111, 125, 126, 134, 69, 70, - /* 380 */ 71, 72, 252, 105, 259, 105, 261, 109, 105, 109, - /* 390 */ 105, 105, 109, 105, 109, 109, 105, 198, 105, 104, - /* 400 */ 192, 113, 109, 76, 113, 195, 196, 112, 81, 197, - /* 410 */ 199, 200, 197, 201, 197, 192, 201, 115, 201, 192, - /* 420 */ 192, 235, 235, 254, 192, 211, 5, 211, 5, 230, - /* 430 */ 79, 5, 211, 211, 265, 261, 5, 251, 251, 191, - /* 440 */ 192, 5, 5, 5, 236, 5, 5, 111, 5, 5, - /* 450 */ 227, 237, 5, 237, 5, 5, 109, 105, 237, 237, - /* 460 */ 5, 234, 5, 140, 140, 140, 76, 16, 80, 5, - /* 470 */ 5, 5, 5, 5, 76, 108, 104, 107, 9, 104, - /* 480 */ 107, 104, 111, 104, 124, 105, 124, 255, 104, 261, - /* 490 */ 109, 109, 105, 104, 1, 104, 113, 105, 104, 114, - /* 500 */ 105, 104, 109, 89, 105, 109, 104, 90, 105, 109, - /* 510 */ 104, 5, 136, 5, 146, 5, 5, 5, 199, 60, - /* 520 */ 146, 195, 193, 193, 79, 194, 193, 226, 194, 54, - /* 530 */ 193, 103, 194, 194, 193, 82, 84, 205, 50, 85, - /* 540 */ 79, 83, 202, 87, 226, 240, 204, 203, 86, 206, - /* 550 */ 193, 193, 207, 198, 208, 133, 193, 209, 193, 198, - /* 560 */ 118, 244, 193, 241, 243, 119, 127, 266, 120, 258, - /* 570 */ 242, 193, 258, 258, 258, 266, 266, 266, 266, 193, - /* 580 */ 266, 121, 266, 266, 266, 122, 266, 266, 266, 266, - /* 590 */ 117, 266, 228, 123, 245, 266, 246, 193, 193, 128, - /* 600 */ 247, 193, 248, 131, 192, 249, 129, 192, 192, 250, - /* 610 */ 192, 192, 192, 266, 266, 266, 192, 192, 266, 192, - /* 620 */ 266, 192, 192, 266, 192, 192, 192, 192, 262, 266, - /* 630 */ 266, 266, 266, 266, 266, 266, 235, 266, 81, 266, - /* 640 */ 266, 228, 266, 266, 235, 235, 239, 266, 266, 266, - /* 650 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, - /* 660 */ 266, 266, 266, 266, 253, 266, 192, 266, 192, 266, - /* 670 */ 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, - /* 680 */ 266, 192, 192, 192, 192, 266, 192, 192, 192, 192, - /* 690 */ 192, 192, 192, 192, 192, 192, 192, 192, 266, 192, - /* 700 */ 266, 192, 266, 266, 266, 192, 192, 192, 192, 192, - /* 710 */ 192, 266, 192, 192, 192, 192, 192, 192, 192, 192, - /* 720 */ 192, 192, 266, 266, 266, 266, 266, 266, 266, 266, + /* 0 */ 192, 1, 191, 192, 0, 254, 211, 254, 254, 9, + /* 10 */ 189, 190, 254, 13, 14, 192, 16, 17, 264, 265, + /* 20 */ 20, 21, 15, 23, 24, 25, 26, 27, 28, 254, + /* 30 */ 5, 254, 237, 33, 34, 254, 211, 37, 38, 39, + /* 40 */ 13, 14, 265, 16, 17, 264, 265, 20, 21, 1, + /* 50 */ 23, 24, 25, 26, 27, 28, 235, 9, 33, 34, + /* 60 */ 33, 34, 237, 255, 37, 38, 39, 14, 192, 16, + /* 70 */ 17, 192, 251, 20, 21, 237, 23, 24, 25, 26, + /* 80 */ 27, 28, 259, 79, 261, 254, 33, 34, 198, 68, + /* 90 */ 37, 38, 39, 45, 46, 47, 48, 49, 50, 51, + /* 100 */ 52, 53, 54, 55, 56, 57, 58, 1, 79, 61, + /* 110 */ 110, 1, 236, 13, 14, 9, 16, 17, 111, 9, + /* 120 */ 20, 21, 232, 23, 24, 25, 26, 27, 28, 37, + /* 130 */ 38, 39, 105, 33, 34, 256, 257, 37, 38, 39, + /* 140 */ 13, 14, 192, 16, 17, 199, 200, 20, 21, 192, + /* 150 */ 23, 24, 25, 26, 27, 28, 65, 66, 67, 138, + /* 160 */ 33, 34, 141, 142, 37, 38, 39, 88, 89, 90, + /* 170 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, + /* 180 */ 101, 102, 210, 192, 212, 213, 214, 215, 216, 217, + /* 190 */ 218, 219, 220, 221, 222, 223, 224, 225, 16, 17, + /* 200 */ 197, 235, 20, 21, 201, 23, 24, 25, 26, 27, + /* 210 */ 28, 261, 44, 198, 104, 33, 34, 251, 261, 37, + /* 220 */ 38, 39, 1, 2, 233, 81, 5, 236, 7, 61, + /* 230 */ 9, 1, 2, 211, 104, 5, 68, 7, 108, 9, + /* 240 */ 110, 73, 74, 75, 229, 230, 231, 232, 25, 26, + /* 250 */ 27, 28, 195, 196, 33, 34, 33, 34, 37, 237, + /* 260 */ 37, 38, 39, 33, 34, 136, 68, 5, 88, 7, + /* 270 */ 90, 91, 104, 144, 145, 95, 37, 97, 98, 99, + /* 280 */ 112, 101, 102, 109, 210, 33, 34, 213, 214, 37, + /* 290 */ 38, 39, 218, 192, 220, 221, 222, 192, 224, 225, + /* 300 */ 62, 63, 64, 135, 192, 137, 132, 69, 70, 71, + /* 310 */ 72, 143, 2, 76, 192, 5, 78, 7, 81, 9, + /* 320 */ 62, 63, 64, 254, 198, 104, 192, 69, 70, 71, + /* 330 */ 72, 192, 111, 192, 104, 234, 138, 192, 117, 141, + /* 340 */ 5, 111, 7, 33, 34, 233, 192, 117, 236, 227, + /* 350 */ 62, 63, 64, 254, 115, 134, 230, 69, 70, 71, + /* 360 */ 72, 62, 63, 64, 134, 104, 261, 233, 263, 211, + /* 370 */ 236, 238, 233, 112, 233, 236, 197, 236, 233, 117, + /* 380 */ 201, 236, 197, 235, 109, 252, 201, 233, 125, 126, + /* 390 */ 236, 116, 105, 1, 105, 237, 109, 105, 60, 251, + /* 400 */ 105, 254, 113, 105, 109, 113, 105, 109, 105, 105, + /* 410 */ 109, 109, 109, 109, 105, 5, 105, 7, 109, 105, + /* 420 */ 109, 111, 105, 109, 105, 254, 109, 104, 109, 37, + /* 430 */ 107, 254, 130, 139, 140, 139, 140, 76, 77, 139, + /* 440 */ 140, 104, 104, 106, 139, 140, 5, 254, 7, 254, + /* 450 */ 254, 254, 117, 254, 254, 254, 254, 254, 254, 237, + /* 460 */ 228, 228, 228, 228, 228, 192, 192, 253, 228, 228, + /* 470 */ 192, 192, 192, 192, 192, 192, 192, 235, 235, 262, + /* 480 */ 262, 235, 192, 239, 60, 192, 117, 258, 103, 192, + /* 490 */ 226, 85, 87, 86, 240, 245, 247, 250, 192, 192, + /* 500 */ 192, 129, 249, 258, 192, 192, 258, 192, 192, 258, + /* 510 */ 192, 131, 192, 192, 192, 128, 192, 192, 192, 192, + /* 520 */ 192, 192, 192, 192, 192, 192, 192, 123, 192, 127, + /* 530 */ 122, 192, 192, 192, 192, 192, 192, 192, 192, 192, + /* 540 */ 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, + /* 550 */ 192, 192, 192, 121, 192, 192, 192, 192, 120, 193, + /* 560 */ 193, 193, 119, 193, 193, 118, 133, 50, 83, 54, + /* 570 */ 193, 193, 84, 82, 193, 79, 5, 146, 5, 193, + /* 580 */ 5, 198, 198, 193, 5, 146, 5, 90, 89, 193, + /* 590 */ 136, 113, 105, 107, 194, 202, 207, 209, 203, 208, + /* 600 */ 206, 204, 193, 205, 104, 194, 194, 193, 114, 194, + /* 610 */ 193, 193, 199, 104, 195, 109, 109, 105, 242, 244, + /* 620 */ 246, 248, 243, 241, 104, 226, 105, 109, 104, 1, + /* 630 */ 105, 104, 104, 111, 105, 104, 76, 124, 124, 109, + /* 640 */ 105, 109, 104, 104, 104, 108, 104, 9, 107, 5, + /* 650 */ 5, 5, 5, 5, 80, 15, 76, 109, 16, 140, + /* 660 */ 5, 5, 105, 140, 5, 5, 140, 5, 5, 5, + /* 670 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + /* 680 */ 5, 5, 80, 60, 59, 109, 0, 266, 266, 266, + /* 690 */ 266, 266, 266, 266, 266, 266, 266, 266, 21, 21, + /* 700 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 710 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 720 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, /* 730 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, /* 740 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, - /* 750 */ 266, 266, 266, 266, 266, 266, 266, 266, 228, 228, - /* 760 */ 228, 228, 228, 266, 266, 266, 266, 266, 266, 266, - /* 770 */ 266, 266, 237, 237, 266, 266, 266, 266, 266, 266, - /* 780 */ 266, 262, 266, 266, 266, 266, 266, 266, 266, 266, - /* 790 */ 266, 254, 254, 254, 254, 254, 254, 254, 254, 254, - /* 800 */ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - /* 810 */ 254, + /* 750 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 760 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 770 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 780 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 790 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 800 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 810 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 820 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 830 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 840 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 850 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 860 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 870 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, + /* 880 */ 266, 266, 266, 266, 266, 266, 266, 266, }; -#define YY_SHIFT_USE_DFLT (-128) -#define YY_SHIFT_COUNT (326) -#define YY_SHIFT_MIN (-127) -#define YY_SHIFT_MAX (557) -static const short yy_shift_ofst[] = { - /* 0 */ 220, 131, 131, 209, 209, 461, 233, 243, 181, 282, - /* 10 */ 282, 282, 282, 282, 282, 282, 282, 282, -1, 101, - /* 20 */ 243, 336, 336, 336, 336, 295, 295, 282, 282, 282, - /* 30 */ 351, 282, 282, 327, 461, 557, 557, -128, -128, -128, - /* 40 */ 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - /* 50 */ 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, - /* 60 */ 336, 336, 246, 246, 246, 246, 246, 246, 246, 282, - /* 70 */ 282, 282, 302, 282, 282, 282, 295, 295, 282, 282, - /* 80 */ 282, 282, 250, 250, -95, 295, 282, 282, 282, 282, - /* 90 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, - /* 100 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, - /* 110 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, - /* 120 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, - /* 130 */ 282, 282, 282, 282, 282, 282, 282, 459, 459, 459, - /* 140 */ 473, 473, 473, 459, 473, 459, 477, 472, 471, 470, - /* 150 */ 439, 463, 460, 448, 446, 442, 422, 459, 459, 459, - /* 160 */ 428, 461, 461, 459, 459, 456, 462, 488, 458, 454, - /* 170 */ 475, 452, 453, 428, 459, 445, 445, 459, 445, 459, - /* 180 */ 445, 459, 459, -128, -128, 26, 53, 80, 53, 53, - /* 190 */ 147, 171, 235, 235, 235, 235, 251, 309, 264, -32, - /* 200 */ -32, -32, -32, -13, -127, 178, 178, 236, 172, 103, - /* 210 */ 98, 17, -34, 293, 291, 288, 286, 285, 283, 280, - /* 220 */ 278, 74, 61, 263, 51, 156, 256, 247, 109, 84, - /* 230 */ -74, -36, 191, 119, 115, 258, -78, 335, 277, -19, - /* 240 */ 512, 374, 511, 510, 368, 508, 506, 417, 414, 376, - /* 250 */ 383, 373, 406, 385, 403, 402, 400, 396, 399, 397, - /* 260 */ 395, 393, 394, 392, 391, 493, 389, 387, 384, 382, - /* 270 */ 362, 381, 360, 380, 379, 371, 377, 373, 375, 370, - /* 280 */ 372, 367, 398, 469, 468, 467, 466, 465, 464, 388, - /* 290 */ 281, 390, 325, 347, 347, 451, 324, 323, 347, 457, - /* 300 */ 455, 352, 347, 450, 449, 447, 444, 443, 441, 440, - /* 310 */ 438, 437, 436, 431, 426, 423, 421, 320, 313, 307, - /* 320 */ 200, 15, 185, 155, 29, -18, 3, +#define YY_SHIFT_COUNT (326) +#define YY_SHIFT_MIN (0) +#define YY_SHIFT_MAX (686) +static const unsigned short int yy_shift_ofst[] = { + /* 0 */ 168, 79, 79, 180, 180, 29, 221, 230, 110, 106, + /* 10 */ 106, 106, 106, 106, 106, 106, 106, 106, 0, 48, + /* 20 */ 230, 310, 310, 310, 310, 261, 261, 106, 106, 106, + /* 30 */ 4, 106, 106, 237, 29, 144, 144, 700, 700, 700, + /* 40 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, + /* 50 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, + /* 60 */ 310, 310, 25, 25, 25, 25, 25, 25, 25, 106, + /* 70 */ 106, 106, 239, 106, 106, 106, 261, 261, 106, 106, + /* 80 */ 106, 106, 263, 263, 275, 261, 106, 106, 106, 106, + /* 90 */ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + /* 100 */ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + /* 110 */ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + /* 120 */ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + /* 130 */ 106, 106, 106, 106, 106, 106, 106, 424, 424, 424, + /* 140 */ 369, 369, 369, 424, 369, 424, 372, 380, 387, 404, + /* 150 */ 402, 408, 432, 438, 443, 447, 433, 424, 424, 424, + /* 160 */ 385, 29, 29, 424, 424, 405, 407, 517, 485, 406, + /* 170 */ 515, 488, 491, 385, 424, 496, 496, 424, 496, 424, + /* 180 */ 496, 424, 424, 700, 700, 27, 100, 127, 100, 100, + /* 190 */ 53, 182, 223, 223, 223, 223, 238, 258, 288, 252, + /* 200 */ 252, 252, 252, 21, 129, 92, 92, 262, 335, 130, + /* 210 */ 198, 91, 299, 287, 289, 292, 295, 298, 301, 303, + /* 220 */ 304, 392, 338, 7, 174, 302, 309, 311, 314, 317, + /* 230 */ 319, 323, 294, 296, 300, 337, 305, 410, 441, 361, + /* 240 */ 571, 431, 573, 575, 439, 579, 581, 497, 499, 454, + /* 250 */ 478, 486, 500, 494, 487, 509, 506, 507, 512, 520, + /* 260 */ 521, 518, 524, 525, 527, 628, 528, 529, 531, 530, + /* 270 */ 513, 532, 514, 535, 538, 522, 539, 486, 540, 541, + /* 280 */ 542, 537, 560, 638, 644, 645, 646, 647, 648, 574, + /* 290 */ 640, 580, 519, 548, 548, 642, 523, 526, 548, 655, + /* 300 */ 656, 557, 548, 659, 660, 662, 663, 664, 665, 666, + /* 310 */ 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, + /* 320 */ 576, 602, 677, 678, 623, 625, 686, }; -#define YY_REDUCE_USE_DFLT (-189) #define YY_REDUCE_COUNT (184) -#define YY_REDUCE_MIN (-188) -#define YY_REDUCE_MAX (556) +#define YY_REDUCE_MIN (-249) +#define YY_REDUCE_MAX (419) static const short yy_reduce_ofst[] = { - /* 0 */ -179, -80, -80, -98, -98, -29, 94, 38, -158, 113, - /* 10 */ -14, 125, 83, 65, 54, 20, -148, -188, 232, 248, - /* 20 */ 169, 222, 221, 216, 214, 187, 186, 228, 174, 227, - /* 30 */ 39, 223, 208, 217, 199, 215, 212, 130, 211, 210, - /* 40 */ 556, 555, 554, 553, 552, 551, 550, 549, 548, 547, - /* 50 */ 546, 545, 544, 543, 542, 541, 540, 539, 538, 537, - /* 60 */ 536, 535, 534, 533, 532, 531, 530, 413, 364, 529, - /* 70 */ 528, 527, 411, 526, 525, 524, 410, 409, 523, 522, - /* 80 */ 521, 520, 519, 366, 407, 401, 518, 517, 516, 515, - /* 90 */ 514, 513, 509, 507, 505, 504, 503, 502, 501, 500, - /* 100 */ 499, 498, 497, 496, 495, 494, 492, 491, 490, 489, - /* 110 */ 487, 486, 485, 484, 483, 482, 481, 480, 479, 478, - /* 120 */ 476, 474, 435, 434, 433, 432, 430, 429, 427, 425, - /* 130 */ 424, 420, 419, 418, 416, 415, 412, 408, 405, 404, - /* 140 */ 316, 315, 314, 386, 311, 378, 359, 356, 354, 353, - /* 150 */ 350, 349, 317, 321, 328, 322, 305, 369, 365, 363, - /* 160 */ 318, 361, 355, 358, 357, 348, 346, 345, 344, 343, - /* 170 */ 342, 332, 340, 301, 341, 339, 338, 337, 334, 333, - /* 180 */ 331, 330, 329, 319, 326, + /* 0 */ -179, -28, -28, 74, 74, 15, -246, -219, -121, -9, + /* 10 */ 105, -177, 112, 134, 139, 141, 145, 154, -192, -189, + /* 20 */ -223, -205, -175, 22, 158, -34, 148, -50, -43, 101, + /* 30 */ -110, 122, -124, 3, 126, 179, 185, 133, -54, 57, + /* 40 */ -249, -247, -242, -225, -169, 69, 99, 147, 171, 177, + /* 50 */ 193, 195, 196, 197, 199, 200, 201, 202, 203, 204, + /* 60 */ -162, 222, 232, 233, 234, 235, 236, 240, 241, 273, + /* 70 */ 274, 278, 214, 279, 280, 281, 242, 243, 282, 283, + /* 80 */ 284, 290, 217, 218, 244, 246, 293, 297, 306, 307, + /* 90 */ 308, 312, 313, 315, 316, 318, 320, 321, 322, 324, + /* 100 */ 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + /* 110 */ 336, 339, 340, 341, 342, 343, 344, 345, 346, 347, + /* 120 */ 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + /* 130 */ 358, 359, 360, 362, 363, 364, 365, 366, 367, 368, + /* 140 */ 229, 245, 248, 370, 251, 371, 247, 253, 373, 249, + /* 150 */ 374, 250, 375, 379, 376, 382, 254, 377, 378, 381, + /* 160 */ 264, 383, 384, 386, 390, 388, 391, 389, 395, 394, + /* 170 */ 397, 398, 393, 399, 396, 400, 411, 409, 412, 414, + /* 180 */ 415, 417, 418, 413, 419, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 798, 633, 579, 645, 567, 576, 781, 781, 798, 798, - /* 10 */ 798, 798, 798, 798, 798, 798, 798, 798, 692, 539, - /* 20 */ 781, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 30 */ 576, 798, 798, 582, 576, 582, 582, 687, 617, 635, + /* 0 */ 798, 911, 857, 923, 845, 854, 1059, 1059, 798, 798, + /* 10 */ 798, 798, 798, 798, 798, 798, 798, 798, 970, 817, + /* 20 */ 1059, 798, 798, 798, 798, 798, 798, 798, 798, 798, + /* 30 */ 854, 798, 798, 860, 854, 860, 860, 965, 895, 913, /* 40 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, /* 50 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, /* 60 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 70 */ 798, 798, 694, 700, 697, 798, 798, 798, 702, 798, - /* 80 */ 798, 798, 724, 724, 685, 798, 798, 798, 798, 798, + /* 70 */ 798, 798, 972, 978, 975, 798, 798, 798, 980, 798, + /* 80 */ 798, 798, 1002, 1002, 963, 798, 798, 798, 798, 798, /* 90 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, /* 100 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 110 */ 798, 798, 798, 565, 798, 563, 798, 798, 798, 798, + /* 110 */ 798, 798, 798, 843, 798, 841, 798, 798, 798, 798, /* 120 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 130 */ 550, 798, 798, 798, 798, 798, 798, 541, 541, 541, - /* 140 */ 798, 798, 798, 541, 798, 541, 731, 735, 729, 717, - /* 150 */ 725, 716, 712, 710, 708, 707, 739, 541, 541, 541, - /* 160 */ 580, 576, 576, 541, 541, 598, 596, 594, 586, 592, - /* 170 */ 588, 590, 584, 568, 541, 574, 574, 541, 574, 541, - /* 180 */ 574, 541, 541, 617, 635, 798, 740, 798, 780, 730, - /* 190 */ 770, 769, 776, 768, 767, 766, 798, 798, 798, 762, - /* 200 */ 763, 765, 764, 798, 798, 772, 771, 798, 798, 798, + /* 130 */ 828, 798, 798, 798, 798, 798, 798, 819, 819, 819, + /* 140 */ 798, 798, 798, 819, 798, 819, 1009, 1013, 1007, 995, + /* 150 */ 1003, 994, 990, 988, 986, 985, 1017, 819, 819, 819, + /* 160 */ 858, 854, 854, 819, 819, 876, 874, 872, 864, 870, + /* 170 */ 866, 868, 862, 846, 819, 852, 852, 819, 852, 819, + /* 180 */ 852, 819, 819, 895, 913, 798, 1018, 798, 1058, 1008, + /* 190 */ 1048, 1047, 1054, 1046, 1045, 1044, 798, 798, 798, 1040, + /* 200 */ 1041, 1043, 1042, 798, 798, 1050, 1049, 798, 798, 798, /* 210 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 220 */ 798, 798, 742, 798, 736, 732, 798, 798, 798, 798, - /* 230 */ 798, 798, 798, 798, 798, 647, 798, 798, 798, 798, + /* 220 */ 798, 798, 1020, 798, 1014, 1010, 798, 798, 798, 798, + /* 230 */ 798, 798, 798, 798, 798, 925, 798, 798, 798, 798, /* 240 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 250 */ 684, 798, 798, 798, 798, 798, 696, 695, 798, 798, - /* 260 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 726, - /* 270 */ 798, 718, 798, 798, 798, 798, 798, 659, 798, 798, + /* 250 */ 962, 798, 798, 798, 798, 798, 974, 973, 798, 798, + /* 260 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 1004, + /* 270 */ 798, 996, 798, 798, 798, 798, 798, 937, 798, 798, /* 280 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 290 */ 798, 798, 798, 792, 790, 798, 798, 798, 786, 798, - /* 300 */ 798, 798, 784, 798, 798, 798, 798, 798, 798, 798, + /* 290 */ 798, 798, 798, 1070, 1068, 798, 798, 798, 1064, 798, + /* 300 */ 798, 798, 1062, 798, 798, 798, 798, 798, 798, 798, /* 310 */ 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, - /* 320 */ 601, 798, 548, 546, 798, 537, 798, 797, 796, 795, - /* 330 */ 783, 782, 655, 693, 689, 691, 690, 688, 701, 698, - /* 340 */ 699, 683, 682, 681, 703, 686, 706, 705, 709, 711, - /* 350 */ 714, 713, 715, 704, 728, 727, 720, 721, 723, 722, - /* 360 */ 719, 759, 778, 779, 777, 775, 774, 773, 758, 757, - /* 370 */ 756, 753, 752, 751, 748, 754, 750, 747, 755, 749, - /* 380 */ 746, 745, 744, 743, 741, 761, 760, 738, 737, 734, - /* 390 */ 733, 680, 665, 660, 657, 664, 663, 662, 661, 658, - /* 400 */ 654, 653, 581, 634, 632, 631, 630, 629, 628, 627, - /* 410 */ 626, 625, 624, 623, 622, 621, 620, 619, 618, 613, - /* 420 */ 609, 607, 606, 605, 602, 575, 578, 577, 794, 793, - /* 430 */ 791, 789, 788, 787, 785, 667, 668, 649, 652, 651, - /* 440 */ 650, 648, 666, 600, 599, 597, 595, 587, 593, 589, - /* 450 */ 591, 585, 583, 570, 569, 646, 616, 644, 643, 642, - /* 460 */ 641, 640, 639, 638, 637, 636, 615, 614, 612, 611, - /* 470 */ 610, 608, 604, 603, 670, 679, 678, 677, 676, 675, - /* 480 */ 674, 673, 672, 671, 669, 566, 564, 562, 561, 560, - /* 490 */ 559, 558, 557, 556, 555, 554, 553, 573, 552, 551, - /* 500 */ 549, 547, 545, 544, 543, 572, 571, 542, 540, 538, - /* 510 */ 536, 535, 534, 533, 532, 531, 530, 529, 528, 527, - /* 520 */ 526, 525, 524, + /* 320 */ 879, 798, 826, 824, 798, 815, 798, }; +/********** End of lemon-generated parsing tables *****************************/ -/* The next table maps tokens into fallback tokens. If a construct -** like the following: +/* The next table maps tokens (terminal symbols) into fallback tokens. +** If a construct like the following: ** ** %fallback ID X Y Z. ** @@ -465,6 +476,10 @@ static const YYACTIONTYPE yy_default[] = { ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser ** but it does not parse, the type of the token is changed to ID and ** the parse is retried before an error is thrown. +** +** This feature can be used, for example, to cause some keywords in a language +** to revert to identifiers if they keyword does not apply in the context where +** it appears. */ #ifdef YYFALLBACK static const YYCODETYPE yyFallback[] = { @@ -670,9 +685,13 @@ static const YYCODETYPE yyFallback[] = { ** + The semantic value stored at this level of the stack. This is ** the information used by the action routines in the grammar. ** It is sometimes called the "minor" token. +** +** After the "shift" half of a SHIFTREDUCE action, the stateno field +** actually contains the reduce action for the second half of the +** SHIFTREDUCE. */ struct yyStackEntry { - YYACTIONTYPE stateno; /* The state-number */ + YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */ YYCODETYPE major; /* The major token value. This is the code ** number for the token at this stack level */ YYMINORTYPE minor; /* The user-supplied minor token value. This @@ -683,17 +702,21 @@ typedef struct yyStackEntry yyStackEntry; /* The state of the parser is completely contained in an instance of ** the following structure */ struct yyParser { - int yyidx; /* Index of top element in stack */ + yyStackEntry *yytos; /* Pointer to top element of the stack */ #ifdef YYTRACKMAXSTACKDEPTH - int yyidxMax; /* Maximum value of yyidx */ + int yyhwm; /* High-water mark of the stack */ #endif +#ifndef YYNOERRORRECOVERY int yyerrcnt; /* Shifts left before out of the error */ +#endif ParseARG_SDECL /* A place to hold %extra_argument */ #if YYSTACKDEPTH<=0 int yystksz; /* Current side of the stack */ yyStackEntry *yystack; /* The parser's stack */ + yyStackEntry yystk0; /* First stack entry */ #else yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ + yyStackEntry *yystackEnd; /* Last entry in the stack */ #endif }; typedef struct yyParser yyParser; @@ -730,79 +753,278 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ } #endif /* NDEBUG */ -#ifndef NDEBUG +#if defined(YYCOVERAGE) || !defined(NDEBUG) /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { - "$", "ID", "BOOL", "TINYINT", - "SMALLINT", "INTEGER", "BIGINT", "FLOAT", - "DOUBLE", "STRING", "TIMESTAMP", "BINARY", - "NCHAR", "OR", "AND", "NOT", - "EQ", "NE", "ISNULL", "NOTNULL", - "IS", "LIKE", "GLOB", "BETWEEN", - "IN", "GT", "GE", "LT", - "LE", "BITAND", "BITOR", "LSHIFT", - "RSHIFT", "PLUS", "MINUS", "DIVIDE", - "TIMES", "STAR", "SLASH", "REM", - "CONCAT", "UMINUS", "UPLUS", "BITNOT", - "SHOW", "DATABASES", "TOPICS", "MNODES", - "DNODES", "ACCOUNTS", "USERS", "MODULES", - "QUERIES", "CONNECTIONS", "STREAMS", "VARIABLES", - "SCORES", "GRANTS", "VNODES", "IPTOKEN", - "DOT", "CREATE", "TABLE", "STABLE", - "DATABASE", "TABLES", "STABLES", "VGROUPS", - "DROP", "TOPIC", "DNODE", "USER", - "ACCOUNT", "USE", "DESCRIBE", "ALTER", - "PASS", "PRIVILEGE", "LOCAL", "IF", - "EXISTS", "PPS", "TSERIES", "DBS", - "STORAGE", "QTIME", "CONNS", "STATE", - "KEEP", "CACHE", "REPLICA", "QUORUM", - "DAYS", "MINROWS", "MAXROWS", "BLOCKS", - "CTIME", "WAL", "FSYNC", "COMP", - "PRECISION", "UPDATE", "CACHELAST", "PARTITIONS", - "LP", "RP", "UNSIGNED", "TAGS", - "USING", "COMMA", "AS", "NULL", - "SELECT", "UNION", "ALL", "DISTINCT", - "FROM", "VARIABLE", "INTERVAL", "SESSION", - "STATE_WINDOW", "FILL", "SLIDING", "ORDER", - "BY", "ASC", "DESC", "GROUP", - "HAVING", "LIMIT", "OFFSET", "SLIMIT", - "SOFFSET", "WHERE", "NOW", "RESET", - "QUERY", "SYNCDB", "ADD", "COLUMN", - "TAG", "CHANGE", "SET", "KILL", - "CONNECTION", "STREAM", "COLON", "ABORT", - "AFTER", "ATTACH", "BEFORE", "BEGIN", - "CASCADE", "CLUSTER", "CONFLICT", "COPY", - "DEFERRED", "DELIMITERS", "DETACH", "EACH", - "END", "EXPLAIN", "FAIL", "FOR", - "IGNORE", "IMMEDIATE", "INITIALLY", "INSTEAD", - "MATCH", "KEY", "OF", "RAISE", - "REPLACE", "RESTRICT", "ROW", "STATEMENT", - "TRIGGER", "VIEW", "SEMI", "NONE", - "PREV", "LINEAR", "IMPORT", "TBNAME", - "JOIN", "INSERT", "INTO", "VALUES", - "error", "program", "cmd", "dbPrefix", - "ids", "cpxName", "ifexists", "alter_db_optr", - "alter_topic_optr", "acct_optr", "ifnotexists", "db_optr", - "topic_optr", "pps", "tseries", "dbs", - "streams", "storage", "qtime", "users", - "conns", "state", "keep", "tagitemlist", - "cache", "replica", "quorum", "days", - "minrows", "maxrows", "blocks", "ctime", - "wal", "fsync", "comp", "prec", - "update", "cachelast", "partitions", "typename", - "signed", "create_table_args", "create_stable_args", "create_table_list", - "create_from_stable", "columnlist", "tagNamelist", "select", - "column", "tagitem", "selcollist", "from", - "where_opt", "interval_opt", "session_option", "windowstate_option", - "fill_opt", "sliding_opt", "groupby_opt", "orderby_opt", - "having_opt", "slimit_opt", "limit_opt", "union", - "sclp", "distinct", "expr", "as", - "tablelist", "sub", "tmvar", "sortlist", - "sortitem", "item", "sortorder", "grouplist", - "exprlist", "expritem", + /* 0 */ "$", + /* 1 */ "ID", + /* 2 */ "BOOL", + /* 3 */ "TINYINT", + /* 4 */ "SMALLINT", + /* 5 */ "INTEGER", + /* 6 */ "BIGINT", + /* 7 */ "FLOAT", + /* 8 */ "DOUBLE", + /* 9 */ "STRING", + /* 10 */ "TIMESTAMP", + /* 11 */ "BINARY", + /* 12 */ "NCHAR", + /* 13 */ "OR", + /* 14 */ "AND", + /* 15 */ "NOT", + /* 16 */ "EQ", + /* 17 */ "NE", + /* 18 */ "ISNULL", + /* 19 */ "NOTNULL", + /* 20 */ "IS", + /* 21 */ "LIKE", + /* 22 */ "GLOB", + /* 23 */ "BETWEEN", + /* 24 */ "IN", + /* 25 */ "GT", + /* 26 */ "GE", + /* 27 */ "LT", + /* 28 */ "LE", + /* 29 */ "BITAND", + /* 30 */ "BITOR", + /* 31 */ "LSHIFT", + /* 32 */ "RSHIFT", + /* 33 */ "PLUS", + /* 34 */ "MINUS", + /* 35 */ "DIVIDE", + /* 36 */ "TIMES", + /* 37 */ "STAR", + /* 38 */ "SLASH", + /* 39 */ "REM", + /* 40 */ "CONCAT", + /* 41 */ "UMINUS", + /* 42 */ "UPLUS", + /* 43 */ "BITNOT", + /* 44 */ "SHOW", + /* 45 */ "DATABASES", + /* 46 */ "TOPICS", + /* 47 */ "MNODES", + /* 48 */ "DNODES", + /* 49 */ "ACCOUNTS", + /* 50 */ "USERS", + /* 51 */ "MODULES", + /* 52 */ "QUERIES", + /* 53 */ "CONNECTIONS", + /* 54 */ "STREAMS", + /* 55 */ "VARIABLES", + /* 56 */ "SCORES", + /* 57 */ "GRANTS", + /* 58 */ "VNODES", + /* 59 */ "IPTOKEN", + /* 60 */ "DOT", + /* 61 */ "CREATE", + /* 62 */ "TABLE", + /* 63 */ "STABLE", + /* 64 */ "DATABASE", + /* 65 */ "TABLES", + /* 66 */ "STABLES", + /* 67 */ "VGROUPS", + /* 68 */ "DROP", + /* 69 */ "TOPIC", + /* 70 */ "DNODE", + /* 71 */ "USER", + /* 72 */ "ACCOUNT", + /* 73 */ "USE", + /* 74 */ "DESCRIBE", + /* 75 */ "ALTER", + /* 76 */ "PASS", + /* 77 */ "PRIVILEGE", + /* 78 */ "LOCAL", + /* 79 */ "IF", + /* 80 */ "EXISTS", + /* 81 */ "PPS", + /* 82 */ "TSERIES", + /* 83 */ "DBS", + /* 84 */ "STORAGE", + /* 85 */ "QTIME", + /* 86 */ "CONNS", + /* 87 */ "STATE", + /* 88 */ "KEEP", + /* 89 */ "CACHE", + /* 90 */ "REPLICA", + /* 91 */ "QUORUM", + /* 92 */ "DAYS", + /* 93 */ "MINROWS", + /* 94 */ "MAXROWS", + /* 95 */ "BLOCKS", + /* 96 */ "CTIME", + /* 97 */ "WAL", + /* 98 */ "FSYNC", + /* 99 */ "COMP", + /* 100 */ "PRECISION", + /* 101 */ "UPDATE", + /* 102 */ "CACHELAST", + /* 103 */ "PARTITIONS", + /* 104 */ "LP", + /* 105 */ "RP", + /* 106 */ "UNSIGNED", + /* 107 */ "TAGS", + /* 108 */ "USING", + /* 109 */ "COMMA", + /* 110 */ "AS", + /* 111 */ "NULL", + /* 112 */ "SELECT", + /* 113 */ "UNION", + /* 114 */ "ALL", + /* 115 */ "DISTINCT", + /* 116 */ "FROM", + /* 117 */ "VARIABLE", + /* 118 */ "INTERVAL", + /* 119 */ "SESSION", + /* 120 */ "STATE_WINDOW", + /* 121 */ "FILL", + /* 122 */ "SLIDING", + /* 123 */ "ORDER", + /* 124 */ "BY", + /* 125 */ "ASC", + /* 126 */ "DESC", + /* 127 */ "GROUP", + /* 128 */ "HAVING", + /* 129 */ "LIMIT", + /* 130 */ "OFFSET", + /* 131 */ "SLIMIT", + /* 132 */ "SOFFSET", + /* 133 */ "WHERE", + /* 134 */ "NOW", + /* 135 */ "RESET", + /* 136 */ "QUERY", + /* 137 */ "SYNCDB", + /* 138 */ "ADD", + /* 139 */ "COLUMN", + /* 140 */ "TAG", + /* 141 */ "CHANGE", + /* 142 */ "SET", + /* 143 */ "KILL", + /* 144 */ "CONNECTION", + /* 145 */ "STREAM", + /* 146 */ "COLON", + /* 147 */ "ABORT", + /* 148 */ "AFTER", + /* 149 */ "ATTACH", + /* 150 */ "BEFORE", + /* 151 */ "BEGIN", + /* 152 */ "CASCADE", + /* 153 */ "CLUSTER", + /* 154 */ "CONFLICT", + /* 155 */ "COPY", + /* 156 */ "DEFERRED", + /* 157 */ "DELIMITERS", + /* 158 */ "DETACH", + /* 159 */ "EACH", + /* 160 */ "END", + /* 161 */ "EXPLAIN", + /* 162 */ "FAIL", + /* 163 */ "FOR", + /* 164 */ "IGNORE", + /* 165 */ "IMMEDIATE", + /* 166 */ "INITIALLY", + /* 167 */ "INSTEAD", + /* 168 */ "MATCH", + /* 169 */ "KEY", + /* 170 */ "OF", + /* 171 */ "RAISE", + /* 172 */ "REPLACE", + /* 173 */ "RESTRICT", + /* 174 */ "ROW", + /* 175 */ "STATEMENT", + /* 176 */ "TRIGGER", + /* 177 */ "VIEW", + /* 178 */ "SEMI", + /* 179 */ "NONE", + /* 180 */ "PREV", + /* 181 */ "LINEAR", + /* 182 */ "IMPORT", + /* 183 */ "TBNAME", + /* 184 */ "JOIN", + /* 185 */ "INSERT", + /* 186 */ "INTO", + /* 187 */ "VALUES", + /* 188 */ "error", + /* 189 */ "program", + /* 190 */ "cmd", + /* 191 */ "dbPrefix", + /* 192 */ "ids", + /* 193 */ "cpxName", + /* 194 */ "ifexists", + /* 195 */ "alter_db_optr", + /* 196 */ "alter_topic_optr", + /* 197 */ "acct_optr", + /* 198 */ "ifnotexists", + /* 199 */ "db_optr", + /* 200 */ "topic_optr", + /* 201 */ "pps", + /* 202 */ "tseries", + /* 203 */ "dbs", + /* 204 */ "streams", + /* 205 */ "storage", + /* 206 */ "qtime", + /* 207 */ "users", + /* 208 */ "conns", + /* 209 */ "state", + /* 210 */ "keep", + /* 211 */ "tagitemlist", + /* 212 */ "cache", + /* 213 */ "replica", + /* 214 */ "quorum", + /* 215 */ "days", + /* 216 */ "minrows", + /* 217 */ "maxrows", + /* 218 */ "blocks", + /* 219 */ "ctime", + /* 220 */ "wal", + /* 221 */ "fsync", + /* 222 */ "comp", + /* 223 */ "prec", + /* 224 */ "update", + /* 225 */ "cachelast", + /* 226 */ "partitions", + /* 227 */ "typename", + /* 228 */ "signed", + /* 229 */ "create_table_args", + /* 230 */ "create_stable_args", + /* 231 */ "create_table_list", + /* 232 */ "create_from_stable", + /* 233 */ "columnlist", + /* 234 */ "tagNamelist", + /* 235 */ "select", + /* 236 */ "column", + /* 237 */ "tagitem", + /* 238 */ "selcollist", + /* 239 */ "from", + /* 240 */ "where_opt", + /* 241 */ "interval_opt", + /* 242 */ "session_option", + /* 243 */ "windowstate_option", + /* 244 */ "fill_opt", + /* 245 */ "sliding_opt", + /* 246 */ "groupby_opt", + /* 247 */ "orderby_opt", + /* 248 */ "having_opt", + /* 249 */ "slimit_opt", + /* 250 */ "limit_opt", + /* 251 */ "union", + /* 252 */ "sclp", + /* 253 */ "distinct", + /* 254 */ "expr", + /* 255 */ "as", + /* 256 */ "tablelist", + /* 257 */ "sub", + /* 258 */ "tmvar", + /* 259 */ "sortlist", + /* 260 */ "sortitem", + /* 261 */ "item", + /* 262 */ "sortorder", + /* 263 */ "grouplist", + /* 264 */ "exprlist", + /* 265 */ "expritem", }; -#endif /* NDEBUG */ +#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. @@ -1089,27 +1311,74 @@ static const char *const yyRuleName[] = { #if YYSTACKDEPTH<=0 /* -** Try to increase the size of the parser stack. +** Try to increase the size of the parser stack. Return the number +** of errors. Return 0 on success. */ -static void yyGrowStack(yyParser *p){ +static int yyGrowStack(yyParser *p){ int newSize; + int idx; yyStackEntry *pNew; newSize = p->yystksz*2 + 100; - pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; + if( p->yystack==&p->yystk0 ){ + pNew = malloc(newSize*sizeof(pNew[0])); + if( pNew ) pNew[0] = p->yystk0; + }else{ + pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + } if( pNew ){ p->yystack = pNew; - p->yystksz = newSize; + p->yytos = &p->yystack[idx]; #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", - yyTracePrompt, p->yystksz); + fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", + yyTracePrompt, p->yystksz, newSize); } #endif + p->yystksz = newSize; } + return pNew==0; } #endif +/* Datatype of the argument to the memory allocated passed as the +** second argument to ParseAlloc() below. This can be changed by +** putting an appropriate #define in the %include section of the input +** grammar. +*/ +#ifndef YYMALLOCARGTYPE +# define YYMALLOCARGTYPE size_t +#endif + +/* Initialize a new parser that has already been allocated. +*/ +void ParseInit(void *yypParser){ + yyParser *pParser = (yyParser*)yypParser; +#ifdef YYTRACKMAXSTACKDEPTH + pParser->yyhwm = 0; +#endif +#if YYSTACKDEPTH<=0 + pParser->yytos = NULL; + pParser->yystack = NULL; + pParser->yystksz = 0; + if( yyGrowStack(pParser) ){ + pParser->yystack = &pParser->yystk0; + pParser->yystksz = 1; + } +#endif +#ifndef YYNOERRORRECOVERY + pParser->yyerrcnt = -1; +#endif + pParser->yytos = pParser->yystack; + pParser->yystack[0].stateno = 0; + pParser->yystack[0].major = 0; +#if YYSTACKDEPTH>0 + pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1]; +#endif +} + +#ifndef Parse_ENGINEALWAYSONSTACK /* ** This function allocates a new parser. ** The only argument is a pointer to a function which works like @@ -1122,27 +1391,21 @@ static void yyGrowStack(yyParser *p){ ** A pointer to a parser. This pointer is used in subsequent calls ** to Parse and ParseFree. */ -void *ParseAlloc(void *(*mallocProc)(size_t)){ +void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; -#ifdef YYTRACKMAXSTACKDEPTH - pParser->yyidxMax = 0; -#endif -#if YYSTACKDEPTH<=0 - pParser->yystack = NULL; - pParser->yystksz = 0; - yyGrowStack(pParser); -#endif - } + pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); + if( pParser ) ParseInit(pParser); return pParser; } +#endif /* Parse_ENGINEALWAYSONSTACK */ -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "yymajor" is the symbol code, and "yypminor" is a pointer to -** the value. + +/* The following function deletes the "minor type" or semantic value +** associated with a symbol. The symbol can be either a terminal +** or nonterminal. "yymajor" is the symbol code, and "yypminor" is +** a pointer to the value to be deleted. The code used to do the +** deletions is derived from the %destructor and/or %token_destructor +** directives of the input grammar. */ static void yy_destructor( yyParser *yypParser, /* The parser */ @@ -1158,9 +1421,10 @@ static void yy_destructor( ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used + ** which appear on the RHS of the rule, but which are *not* used ** inside the C code. */ +/********* Begin destructor definitions ***************************************/ case 210: /* keep */ case 211: /* tagitemlist */ case 233: /* columnlist */ @@ -1216,6 +1480,7 @@ destroyAllSqlNode((yypminor->yy193)); tVariantDestroy(&(yypminor->yy442)); } break; +/********* End destructor definitions *****************************************/ default: break; /* If no destructor action specified: do nothing */ } } @@ -1225,51 +1490,53 @@ tVariantDestroy(&(yypminor->yy442)); ** ** If there is a destructor routine associated with the token which ** is popped from the stack, then call it. -** -** Return the major token number for the symbol popped. */ -static int yy_pop_parser_stack(yyParser *pParser){ - YYCODETYPE yymajor; - yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; - - if( pParser->yyidx<0 ) return 0; +static void yy_pop_parser_stack(yyParser *pParser){ + yyStackEntry *yytos; + assert( pParser->yytos!=0 ); + assert( pParser->yytos > pParser->yystack ); + yytos = pParser->yytos--; #ifndef NDEBUG - if( yyTraceFILE && pParser->yyidx>=0 ){ + if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", yyTracePrompt, yyTokenName[yytos->major]); } #endif - yymajor = yytos->major; - yy_destructor(pParser, yymajor, &yytos->minor); - pParser->yyidx--; - return yymajor; + yy_destructor(pParser, yytos->major, &yytos->minor); } +/* +** Clear all secondary memory allocations from the parser +*/ +void ParseFinalize(void *p){ + yyParser *pParser = (yyParser*)p; + while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); +#if YYSTACKDEPTH<=0 + if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); +#endif +} + +#ifndef Parse_ENGINEALWAYSONSTACK /* -** Deallocate and destroy a parser. Destructors are all called for +** Deallocate and destroy a parser. Destructors are called for ** all stack elements before shutting the parser down. ** -** Inputs: -**
    -**
  • A pointer to the parser. This should be a pointer -** obtained from ParseAlloc. -**
  • A pointer to a function used to reclaim memory obtained -** from malloc. -**
+** If the YYPARSEFREENEVERNULL macro exists (for example because it +** is defined in a %include section of the input grammar) then it is +** assumed that the input pointer is never NULL. */ void ParseFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ ){ - yyParser *pParser = (yyParser*)p; - if( pParser==0 ) return; - while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); -#if YYSTACKDEPTH<=0 - free(pParser->yystack); +#ifndef YYPARSEFREENEVERNULL + if( p==0 ) return; #endif - (*freeProc)((void*)pParser); + ParseFinalize(p); + (*freeProc)(p); } +#endif /* Parse_ENGINEALWAYSONSTACK */ /* ** Return the peak depth of the stack for a parser. @@ -1277,33 +1544,70 @@ void ParseFree( #ifdef YYTRACKMAXSTACKDEPTH int ParseStackPeak(void *p){ yyParser *pParser = (yyParser*)p; - return pParser->yyidxMax; + return pParser->yyhwm; +} +#endif + +/* This array of booleans keeps track of the parser statement +** coverage. The element yycoverage[X][Y] is set when the parser +** is in state X and has a lookahead token Y. In a well-tested +** systems, every element of this matrix should end up being set. +*/ +#if defined(YYCOVERAGE) +static unsigned char yycoverage[YYNSTATE][YYNTOKEN]; +#endif + +/* +** Write into out a description of every state/lookahead combination that +** +** (1) has not been used by the parser, and +** (2) is not a syntax error. +** +** Return the number of missed state/lookahead combinations. +*/ +#if defined(YYCOVERAGE) +int ParseCoverage(FILE *out){ + int stateno, iLookAhead, i; + int nMissed = 0; + for(stateno=0; statenoyystack[pParser->yyidx].stateno; + int stateno = pParser->yytos->stateno; - if( stateno>YY_SHIFT_COUNT - || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ - return yy_default[stateno]; - } - assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ + if( stateno>YY_MAX_SHIFT ) return stateno; + assert( stateno <= YY_SHIFT_COUNT ); +#if defined(YYCOVERAGE) + yycoverage[stateno][iLookAhead] = 1; +#endif + do{ + i = yy_shift_ofst[stateno]; + assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); + assert( iLookAhead!=YYNOCODE ); + assert( iLookAhead < YYNTOKEN ); + i += iLookAhead; + if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ if( iLookAhead=YY_ACTTAB_COUNT j0 ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); + yyTracePrompt, yyTokenName[iLookAhead], + yyTokenName[YYWILDCARD]); } #endif /* NDEBUG */ return yy_action[j]; } } #endif /* YYWILDCARD */ + return yy_default[stateno]; + }else{ + return yy_action[i]; } - return yy_default[stateno]; - }else{ - return yy_action[i]; - } + }while(1); } /* ** Find the appropriate action for a parser given the non-terminal ** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. */ static int yy_find_reduce_action( int stateno, /* Current state number */ @@ -1367,7 +1670,6 @@ static int yy_find_reduce_action( assert( stateno<=YY_REDUCE_COUNT ); #endif i = yy_reduce_ofst[stateno]; - assert( i!=YY_REDUCE_USE_DFLT ); assert( iLookAhead!=YYNOCODE ); i += iLookAhead; #ifdef YYERRORSYMBOL @@ -1384,20 +1686,42 @@ static int yy_find_reduce_action( /* ** The following routine is called if the stack overflows. */ -static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ +static void yyStackOverflow(yyParser *yypParser){ ParseARG_FETCH; - yypParser->yyidx--; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will execute if the parser ** stack every overflows */ +/******** Begin %stack_overflow code ******************************************/ +/******** End %stack_overflow code ********************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ } +/* +** Print tracing information for a SHIFT action +*/ +#ifndef NDEBUG +static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){ + if( yyTraceFILE ){ + if( yyNewStateyytos->major], + yyNewState); + }else{ + fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n", + yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], + yyNewState - YY_MIN_REDUCE); + } + } +} +#else +# define yyTraceShift(X,Y,Z) +#endif + /* ** Perform a shift action. */ @@ -1405,327 +1729,323 @@ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ int yyNewState, /* The new state to shift in */ int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ + ParseTOKENTYPE yyMinor /* The minor token to shift in */ ){ yyStackEntry *yytos; - yypParser->yyidx++; + yypParser->yytos++; #ifdef YYTRACKMAXSTACKDEPTH - if( yypParser->yyidx>yypParser->yyidxMax ){ - yypParser->yyidxMax = yypParser->yyidx; + if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); } #endif #if YYSTACKDEPTH>0 - if( yypParser->yyidx>=YYSTACKDEPTH ){ - yyStackOverflow(yypParser, yypMinor); + if( yypParser->yytos>yypParser->yystackEnd ){ + yypParser->yytos--; + yyStackOverflow(yypParser); return; } #else - if( yypParser->yyidx>=yypParser->yystksz ){ - yyGrowStack(yypParser); - if( yypParser->yyidx>=yypParser->yystksz ){ - yyStackOverflow(yypParser, yypMinor); + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ + if( yyGrowStack(yypParser) ){ + yypParser->yytos--; + yyStackOverflow(yypParser); return; } } #endif - yytos = &yypParser->yystack[yypParser->yyidx]; + if( yyNewState > YY_MAX_SHIFT ){ + yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; + } + yytos = yypParser->yytos; yytos->stateno = (YYACTIONTYPE)yyNewState; yytos->major = (YYCODETYPE)yyMajor; - yytos->minor = *yypMinor; -#ifndef NDEBUG - if( yyTraceFILE && yypParser->yyidx>0 ){ - int i; - fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); - fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); - for(i=1; i<=yypParser->yyidx; i++) - fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); - fprintf(yyTraceFILE,"\n"); - } -#endif + yytos->minor.yy0 = yyMinor; + yyTraceShift(yypParser, yyNewState, "Shift"); } /* The following table contains information about every rule that ** is used during the reduce. */ static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 189, 1 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 2 }, - { 190, 3 }, - { 191, 0 }, - { 191, 2 }, - { 193, 0 }, - { 193, 2 }, - { 190, 5 }, - { 190, 5 }, - { 190, 4 }, - { 190, 3 }, - { 190, 5 }, - { 190, 3 }, - { 190, 5 }, - { 190, 3 }, - { 190, 4 }, - { 190, 5 }, - { 190, 5 }, - { 190, 4 }, - { 190, 4 }, - { 190, 3 }, - { 190, 3 }, - { 190, 3 }, - { 190, 2 }, - { 190, 3 }, - { 190, 5 }, - { 190, 5 }, - { 190, 4 }, - { 190, 5 }, - { 190, 3 }, - { 190, 4 }, - { 190, 4 }, - { 190, 4 }, - { 190, 4 }, - { 190, 6 }, - { 192, 1 }, - { 192, 1 }, - { 194, 2 }, - { 194, 0 }, - { 198, 3 }, - { 198, 0 }, - { 190, 3 }, - { 190, 6 }, - { 190, 5 }, - { 190, 5 }, - { 190, 5 }, - { 201, 0 }, - { 201, 2 }, - { 202, 0 }, - { 202, 2 }, - { 203, 0 }, - { 203, 2 }, - { 204, 0 }, - { 204, 2 }, - { 205, 0 }, - { 205, 2 }, - { 206, 0 }, - { 206, 2 }, - { 207, 0 }, - { 207, 2 }, - { 208, 0 }, - { 208, 2 }, - { 209, 0 }, - { 209, 2 }, - { 197, 9 }, - { 210, 2 }, - { 212, 2 }, - { 213, 2 }, - { 214, 2 }, - { 215, 2 }, - { 216, 2 }, - { 217, 2 }, - { 218, 2 }, - { 219, 2 }, - { 220, 2 }, - { 221, 2 }, - { 222, 2 }, - { 223, 2 }, - { 224, 2 }, - { 225, 2 }, - { 226, 2 }, - { 199, 0 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 199, 2 }, - { 200, 1 }, - { 200, 2 }, - { 195, 0 }, - { 195, 2 }, - { 195, 2 }, - { 195, 2 }, - { 195, 2 }, - { 195, 2 }, - { 195, 2 }, - { 195, 2 }, - { 195, 2 }, - { 195, 2 }, - { 196, 1 }, - { 196, 2 }, - { 227, 1 }, - { 227, 4 }, - { 227, 2 }, - { 228, 1 }, - { 228, 2 }, - { 228, 2 }, - { 190, 3 }, - { 190, 3 }, - { 190, 3 }, - { 190, 3 }, - { 231, 1 }, - { 231, 2 }, - { 229, 6 }, - { 230, 10 }, - { 232, 10 }, - { 232, 13 }, - { 234, 3 }, - { 234, 1 }, - { 229, 5 }, - { 233, 3 }, - { 233, 1 }, - { 236, 2 }, - { 211, 3 }, - { 211, 1 }, - { 237, 1 }, - { 237, 1 }, - { 237, 1 }, - { 237, 1 }, - { 237, 1 }, - { 237, 2 }, - { 237, 2 }, - { 237, 2 }, - { 237, 2 }, - { 235, 14 }, - { 235, 3 }, - { 251, 1 }, - { 251, 4 }, - { 190, 1 }, - { 235, 2 }, - { 252, 2 }, - { 252, 0 }, - { 238, 4 }, - { 238, 2 }, - { 255, 2 }, - { 255, 1 }, - { 255, 0 }, - { 253, 1 }, - { 253, 0 }, - { 239, 2 }, - { 239, 2 }, - { 257, 3 }, - { 257, 4 }, - { 257, 6 }, - { 256, 2 }, - { 256, 3 }, - { 256, 4 }, - { 256, 5 }, - { 258, 1 }, - { 241, 4 }, - { 241, 6 }, - { 241, 0 }, - { 242, 0 }, - { 242, 7 }, - { 243, 0 }, - { 243, 4 }, - { 244, 0 }, - { 244, 6 }, - { 244, 4 }, - { 245, 4 }, - { 245, 0 }, - { 247, 0 }, - { 247, 3 }, - { 259, 4 }, - { 259, 2 }, - { 261, 2 }, - { 262, 1 }, - { 262, 1 }, - { 262, 0 }, - { 246, 0 }, - { 246, 3 }, - { 263, 3 }, - { 263, 1 }, - { 248, 0 }, - { 248, 2 }, - { 250, 0 }, - { 250, 2 }, - { 250, 4 }, - { 250, 4 }, - { 249, 0 }, - { 249, 2 }, - { 249, 4 }, - { 249, 4 }, - { 240, 0 }, - { 240, 2 }, - { 254, 3 }, - { 254, 1 }, - { 254, 3 }, - { 254, 3 }, - { 254, 1 }, - { 254, 2 }, - { 254, 2 }, - { 254, 1 }, - { 254, 2 }, - { 254, 2 }, - { 254, 1 }, - { 254, 1 }, - { 254, 1 }, - { 254, 2 }, - { 254, 2 }, - { 254, 1 }, - { 254, 1 }, - { 254, 4 }, - { 254, 4 }, - { 254, 3 }, - { 254, 4 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 5 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 3 }, - { 254, 5 }, - { 264, 3 }, - { 264, 1 }, - { 265, 1 }, - { 265, 0 }, - { 190, 3 }, - { 190, 3 }, - { 190, 7 }, - { 190, 7 }, - { 190, 7 }, - { 190, 7 }, - { 190, 8 }, - { 190, 9 }, - { 190, 7 }, - { 190, 7 }, - { 190, 7 }, - { 190, 7 }, - { 190, 8 }, - { 190, 3 }, - { 190, 5 }, - { 190, 5 }, + { 189, -1 }, /* (0) program ::= cmd */ + { 190, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 190, -2 }, /* (2) cmd ::= SHOW TOPICS */ + { 190, -2 }, /* (3) cmd ::= SHOW MNODES */ + { 190, -2 }, /* (4) cmd ::= SHOW DNODES */ + { 190, -2 }, /* (5) cmd ::= SHOW ACCOUNTS */ + { 190, -2 }, /* (6) cmd ::= SHOW USERS */ + { 190, -2 }, /* (7) cmd ::= SHOW MODULES */ + { 190, -2 }, /* (8) cmd ::= SHOW QUERIES */ + { 190, -2 }, /* (9) cmd ::= SHOW CONNECTIONS */ + { 190, -2 }, /* (10) cmd ::= SHOW STREAMS */ + { 190, -2 }, /* (11) cmd ::= SHOW VARIABLES */ + { 190, -2 }, /* (12) cmd ::= SHOW SCORES */ + { 190, -2 }, /* (13) cmd ::= SHOW GRANTS */ + { 190, -2 }, /* (14) cmd ::= SHOW VNODES */ + { 190, -3 }, /* (15) cmd ::= SHOW VNODES IPTOKEN */ + { 191, 0 }, /* (16) dbPrefix ::= */ + { 191, -2 }, /* (17) dbPrefix ::= ids DOT */ + { 193, 0 }, /* (18) cpxName ::= */ + { 193, -2 }, /* (19) cpxName ::= DOT ids */ + { 190, -5 }, /* (20) cmd ::= SHOW CREATE TABLE ids cpxName */ + { 190, -5 }, /* (21) cmd ::= SHOW CREATE STABLE ids cpxName */ + { 190, -4 }, /* (22) cmd ::= SHOW CREATE DATABASE ids */ + { 190, -3 }, /* (23) cmd ::= SHOW dbPrefix TABLES */ + { 190, -5 }, /* (24) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 190, -3 }, /* (25) cmd ::= SHOW dbPrefix STABLES */ + { 190, -5 }, /* (26) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 190, -3 }, /* (27) cmd ::= SHOW dbPrefix VGROUPS */ + { 190, -4 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS ids */ + { 190, -5 }, /* (29) cmd ::= DROP TABLE ifexists ids cpxName */ + { 190, -5 }, /* (30) cmd ::= DROP STABLE ifexists ids cpxName */ + { 190, -4 }, /* (31) cmd ::= DROP DATABASE ifexists ids */ + { 190, -4 }, /* (32) cmd ::= DROP TOPIC ifexists ids */ + { 190, -3 }, /* (33) cmd ::= DROP DNODE ids */ + { 190, -3 }, /* (34) cmd ::= DROP USER ids */ + { 190, -3 }, /* (35) cmd ::= DROP ACCOUNT ids */ + { 190, -2 }, /* (36) cmd ::= USE ids */ + { 190, -3 }, /* (37) cmd ::= DESCRIBE ids cpxName */ + { 190, -5 }, /* (38) cmd ::= ALTER USER ids PASS ids */ + { 190, -5 }, /* (39) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 190, -4 }, /* (40) cmd ::= ALTER DNODE ids ids */ + { 190, -5 }, /* (41) cmd ::= ALTER DNODE ids ids ids */ + { 190, -3 }, /* (42) cmd ::= ALTER LOCAL ids */ + { 190, -4 }, /* (43) cmd ::= ALTER LOCAL ids ids */ + { 190, -4 }, /* (44) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 190, -4 }, /* (45) cmd ::= ALTER TOPIC ids alter_topic_optr */ + { 190, -4 }, /* (46) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 190, -6 }, /* (47) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 192, -1 }, /* (48) ids ::= ID */ + { 192, -1 }, /* (49) ids ::= STRING */ + { 194, -2 }, /* (50) ifexists ::= IF EXISTS */ + { 194, 0 }, /* (51) ifexists ::= */ + { 198, -3 }, /* (52) ifnotexists ::= IF NOT EXISTS */ + { 198, 0 }, /* (53) ifnotexists ::= */ + { 190, -3 }, /* (54) cmd ::= CREATE DNODE ids */ + { 190, -6 }, /* (55) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 190, -5 }, /* (56) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 190, -5 }, /* (57) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + { 190, -5 }, /* (58) cmd ::= CREATE USER ids PASS ids */ + { 201, 0 }, /* (59) pps ::= */ + { 201, -2 }, /* (60) pps ::= PPS INTEGER */ + { 202, 0 }, /* (61) tseries ::= */ + { 202, -2 }, /* (62) tseries ::= TSERIES INTEGER */ + { 203, 0 }, /* (63) dbs ::= */ + { 203, -2 }, /* (64) dbs ::= DBS INTEGER */ + { 204, 0 }, /* (65) streams ::= */ + { 204, -2 }, /* (66) streams ::= STREAMS INTEGER */ + { 205, 0 }, /* (67) storage ::= */ + { 205, -2 }, /* (68) storage ::= STORAGE INTEGER */ + { 206, 0 }, /* (69) qtime ::= */ + { 206, -2 }, /* (70) qtime ::= QTIME INTEGER */ + { 207, 0 }, /* (71) users ::= */ + { 207, -2 }, /* (72) users ::= USERS INTEGER */ + { 208, 0 }, /* (73) conns ::= */ + { 208, -2 }, /* (74) conns ::= CONNS INTEGER */ + { 209, 0 }, /* (75) state ::= */ + { 209, -2 }, /* (76) state ::= STATE ids */ + { 197, -9 }, /* (77) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 210, -2 }, /* (78) keep ::= KEEP tagitemlist */ + { 212, -2 }, /* (79) cache ::= CACHE INTEGER */ + { 213, -2 }, /* (80) replica ::= REPLICA INTEGER */ + { 214, -2 }, /* (81) quorum ::= QUORUM INTEGER */ + { 215, -2 }, /* (82) days ::= DAYS INTEGER */ + { 216, -2 }, /* (83) minrows ::= MINROWS INTEGER */ + { 217, -2 }, /* (84) maxrows ::= MAXROWS INTEGER */ + { 218, -2 }, /* (85) blocks ::= BLOCKS INTEGER */ + { 219, -2 }, /* (86) ctime ::= CTIME INTEGER */ + { 220, -2 }, /* (87) wal ::= WAL INTEGER */ + { 221, -2 }, /* (88) fsync ::= FSYNC INTEGER */ + { 222, -2 }, /* (89) comp ::= COMP INTEGER */ + { 223, -2 }, /* (90) prec ::= PRECISION STRING */ + { 224, -2 }, /* (91) update ::= UPDATE INTEGER */ + { 225, -2 }, /* (92) cachelast ::= CACHELAST INTEGER */ + { 226, -2 }, /* (93) partitions ::= PARTITIONS INTEGER */ + { 199, 0 }, /* (94) db_optr ::= */ + { 199, -2 }, /* (95) db_optr ::= db_optr cache */ + { 199, -2 }, /* (96) db_optr ::= db_optr replica */ + { 199, -2 }, /* (97) db_optr ::= db_optr quorum */ + { 199, -2 }, /* (98) db_optr ::= db_optr days */ + { 199, -2 }, /* (99) db_optr ::= db_optr minrows */ + { 199, -2 }, /* (100) db_optr ::= db_optr maxrows */ + { 199, -2 }, /* (101) db_optr ::= db_optr blocks */ + { 199, -2 }, /* (102) db_optr ::= db_optr ctime */ + { 199, -2 }, /* (103) db_optr ::= db_optr wal */ + { 199, -2 }, /* (104) db_optr ::= db_optr fsync */ + { 199, -2 }, /* (105) db_optr ::= db_optr comp */ + { 199, -2 }, /* (106) db_optr ::= db_optr prec */ + { 199, -2 }, /* (107) db_optr ::= db_optr keep */ + { 199, -2 }, /* (108) db_optr ::= db_optr update */ + { 199, -2 }, /* (109) db_optr ::= db_optr cachelast */ + { 200, -1 }, /* (110) topic_optr ::= db_optr */ + { 200, -2 }, /* (111) topic_optr ::= topic_optr partitions */ + { 195, 0 }, /* (112) alter_db_optr ::= */ + { 195, -2 }, /* (113) alter_db_optr ::= alter_db_optr replica */ + { 195, -2 }, /* (114) alter_db_optr ::= alter_db_optr quorum */ + { 195, -2 }, /* (115) alter_db_optr ::= alter_db_optr keep */ + { 195, -2 }, /* (116) alter_db_optr ::= alter_db_optr blocks */ + { 195, -2 }, /* (117) alter_db_optr ::= alter_db_optr comp */ + { 195, -2 }, /* (118) alter_db_optr ::= alter_db_optr wal */ + { 195, -2 }, /* (119) alter_db_optr ::= alter_db_optr fsync */ + { 195, -2 }, /* (120) alter_db_optr ::= alter_db_optr update */ + { 195, -2 }, /* (121) alter_db_optr ::= alter_db_optr cachelast */ + { 196, -1 }, /* (122) alter_topic_optr ::= alter_db_optr */ + { 196, -2 }, /* (123) alter_topic_optr ::= alter_topic_optr partitions */ + { 227, -1 }, /* (124) typename ::= ids */ + { 227, -4 }, /* (125) typename ::= ids LP signed RP */ + { 227, -2 }, /* (126) typename ::= ids UNSIGNED */ + { 228, -1 }, /* (127) signed ::= INTEGER */ + { 228, -2 }, /* (128) signed ::= PLUS INTEGER */ + { 228, -2 }, /* (129) signed ::= MINUS INTEGER */ + { 190, -3 }, /* (130) cmd ::= CREATE TABLE create_table_args */ + { 190, -3 }, /* (131) cmd ::= CREATE TABLE create_stable_args */ + { 190, -3 }, /* (132) cmd ::= CREATE STABLE create_stable_args */ + { 190, -3 }, /* (133) cmd ::= CREATE TABLE create_table_list */ + { 231, -1 }, /* (134) create_table_list ::= create_from_stable */ + { 231, -2 }, /* (135) create_table_list ::= create_table_list create_from_stable */ + { 229, -6 }, /* (136) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 230, -10 }, /* (137) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 232, -10 }, /* (138) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + { 232, -13 }, /* (139) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + { 234, -3 }, /* (140) tagNamelist ::= tagNamelist COMMA ids */ + { 234, -1 }, /* (141) tagNamelist ::= ids */ + { 229, -5 }, /* (142) create_table_args ::= ifnotexists ids cpxName AS select */ + { 233, -3 }, /* (143) columnlist ::= columnlist COMMA column */ + { 233, -1 }, /* (144) columnlist ::= column */ + { 236, -2 }, /* (145) column ::= ids typename */ + { 211, -3 }, /* (146) tagitemlist ::= tagitemlist COMMA tagitem */ + { 211, -1 }, /* (147) tagitemlist ::= tagitem */ + { 237, -1 }, /* (148) tagitem ::= INTEGER */ + { 237, -1 }, /* (149) tagitem ::= FLOAT */ + { 237, -1 }, /* (150) tagitem ::= STRING */ + { 237, -1 }, /* (151) tagitem ::= BOOL */ + { 237, -1 }, /* (152) tagitem ::= NULL */ + { 237, -2 }, /* (153) tagitem ::= MINUS INTEGER */ + { 237, -2 }, /* (154) tagitem ::= MINUS FLOAT */ + { 237, -2 }, /* (155) tagitem ::= PLUS INTEGER */ + { 237, -2 }, /* (156) tagitem ::= PLUS FLOAT */ + { 235, -14 }, /* (157) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + { 235, -3 }, /* (158) select ::= LP select RP */ + { 251, -1 }, /* (159) union ::= select */ + { 251, -4 }, /* (160) union ::= union UNION ALL select */ + { 190, -1 }, /* (161) cmd ::= union */ + { 235, -2 }, /* (162) select ::= SELECT selcollist */ + { 252, -2 }, /* (163) sclp ::= selcollist COMMA */ + { 252, 0 }, /* (164) sclp ::= */ + { 238, -4 }, /* (165) selcollist ::= sclp distinct expr as */ + { 238, -2 }, /* (166) selcollist ::= sclp STAR */ + { 255, -2 }, /* (167) as ::= AS ids */ + { 255, -1 }, /* (168) as ::= ids */ + { 255, 0 }, /* (169) as ::= */ + { 253, -1 }, /* (170) distinct ::= DISTINCT */ + { 253, 0 }, /* (171) distinct ::= */ + { 239, -2 }, /* (172) from ::= FROM tablelist */ + { 239, -2 }, /* (173) from ::= FROM sub */ + { 257, -3 }, /* (174) sub ::= LP union RP */ + { 257, -4 }, /* (175) sub ::= LP union RP ids */ + { 257, -6 }, /* (176) sub ::= sub COMMA LP union RP ids */ + { 256, -2 }, /* (177) tablelist ::= ids cpxName */ + { 256, -3 }, /* (178) tablelist ::= ids cpxName ids */ + { 256, -4 }, /* (179) tablelist ::= tablelist COMMA ids cpxName */ + { 256, -5 }, /* (180) tablelist ::= tablelist COMMA ids cpxName ids */ + { 258, -1 }, /* (181) tmvar ::= VARIABLE */ + { 241, -4 }, /* (182) interval_opt ::= INTERVAL LP tmvar RP */ + { 241, -6 }, /* (183) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + { 241, 0 }, /* (184) interval_opt ::= */ + { 242, 0 }, /* (185) session_option ::= */ + { 242, -7 }, /* (186) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 243, 0 }, /* (187) windowstate_option ::= */ + { 243, -4 }, /* (188) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 244, 0 }, /* (189) fill_opt ::= */ + { 244, -6 }, /* (190) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 244, -4 }, /* (191) fill_opt ::= FILL LP ID RP */ + { 245, -4 }, /* (192) sliding_opt ::= SLIDING LP tmvar RP */ + { 245, 0 }, /* (193) sliding_opt ::= */ + { 247, 0 }, /* (194) orderby_opt ::= */ + { 247, -3 }, /* (195) orderby_opt ::= ORDER BY sortlist */ + { 259, -4 }, /* (196) sortlist ::= sortlist COMMA item sortorder */ + { 259, -2 }, /* (197) sortlist ::= item sortorder */ + { 261, -2 }, /* (198) item ::= ids cpxName */ + { 262, -1 }, /* (199) sortorder ::= ASC */ + { 262, -1 }, /* (200) sortorder ::= DESC */ + { 262, 0 }, /* (201) sortorder ::= */ + { 246, 0 }, /* (202) groupby_opt ::= */ + { 246, -3 }, /* (203) groupby_opt ::= GROUP BY grouplist */ + { 263, -3 }, /* (204) grouplist ::= grouplist COMMA item */ + { 263, -1 }, /* (205) grouplist ::= item */ + { 248, 0 }, /* (206) having_opt ::= */ + { 248, -2 }, /* (207) having_opt ::= HAVING expr */ + { 250, 0 }, /* (208) limit_opt ::= */ + { 250, -2 }, /* (209) limit_opt ::= LIMIT signed */ + { 250, -4 }, /* (210) limit_opt ::= LIMIT signed OFFSET signed */ + { 250, -4 }, /* (211) limit_opt ::= LIMIT signed COMMA signed */ + { 249, 0 }, /* (212) slimit_opt ::= */ + { 249, -2 }, /* (213) slimit_opt ::= SLIMIT signed */ + { 249, -4 }, /* (214) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 249, -4 }, /* (215) slimit_opt ::= SLIMIT signed COMMA signed */ + { 240, 0 }, /* (216) where_opt ::= */ + { 240, -2 }, /* (217) where_opt ::= WHERE expr */ + { 254, -3 }, /* (218) expr ::= LP expr RP */ + { 254, -1 }, /* (219) expr ::= ID */ + { 254, -3 }, /* (220) expr ::= ID DOT ID */ + { 254, -3 }, /* (221) expr ::= ID DOT STAR */ + { 254, -1 }, /* (222) expr ::= INTEGER */ + { 254, -2 }, /* (223) expr ::= MINUS INTEGER */ + { 254, -2 }, /* (224) expr ::= PLUS INTEGER */ + { 254, -1 }, /* (225) expr ::= FLOAT */ + { 254, -2 }, /* (226) expr ::= MINUS FLOAT */ + { 254, -2 }, /* (227) expr ::= PLUS FLOAT */ + { 254, -1 }, /* (228) expr ::= STRING */ + { 254, -1 }, /* (229) expr ::= NOW */ + { 254, -1 }, /* (230) expr ::= VARIABLE */ + { 254, -2 }, /* (231) expr ::= PLUS VARIABLE */ + { 254, -2 }, /* (232) expr ::= MINUS VARIABLE */ + { 254, -1 }, /* (233) expr ::= BOOL */ + { 254, -1 }, /* (234) expr ::= NULL */ + { 254, -4 }, /* (235) expr ::= ID LP exprlist RP */ + { 254, -4 }, /* (236) expr ::= ID LP STAR RP */ + { 254, -3 }, /* (237) expr ::= expr IS NULL */ + { 254, -4 }, /* (238) expr ::= expr IS NOT NULL */ + { 254, -3 }, /* (239) expr ::= expr LT expr */ + { 254, -3 }, /* (240) expr ::= expr GT expr */ + { 254, -3 }, /* (241) expr ::= expr LE expr */ + { 254, -3 }, /* (242) expr ::= expr GE expr */ + { 254, -3 }, /* (243) expr ::= expr NE expr */ + { 254, -3 }, /* (244) expr ::= expr EQ expr */ + { 254, -5 }, /* (245) expr ::= expr BETWEEN expr AND expr */ + { 254, -3 }, /* (246) expr ::= expr AND expr */ + { 254, -3 }, /* (247) expr ::= expr OR expr */ + { 254, -3 }, /* (248) expr ::= expr PLUS expr */ + { 254, -3 }, /* (249) expr ::= expr MINUS expr */ + { 254, -3 }, /* (250) expr ::= expr STAR expr */ + { 254, -3 }, /* (251) expr ::= expr SLASH expr */ + { 254, -3 }, /* (252) expr ::= expr REM expr */ + { 254, -3 }, /* (253) expr ::= expr LIKE expr */ + { 254, -5 }, /* (254) expr ::= expr IN LP exprlist RP */ + { 264, -3 }, /* (255) exprlist ::= exprlist COMMA expritem */ + { 264, -1 }, /* (256) exprlist ::= expritem */ + { 265, -1 }, /* (257) expritem ::= expr */ + { 265, 0 }, /* (258) expritem ::= */ + { 190, -3 }, /* (259) cmd ::= RESET QUERY CACHE */ + { 190, -3 }, /* (260) cmd ::= SYNCDB ids REPLICA */ + { 190, -7 }, /* (261) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 190, -7 }, /* (262) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 190, -7 }, /* (263) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 190, -7 }, /* (264) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 190, -8 }, /* (265) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 190, -9 }, /* (266) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 190, -7 }, /* (267) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 190, -7 }, /* (268) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 190, -7 }, /* (269) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 190, -7 }, /* (270) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 190, -8 }, /* (271) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 190, -3 }, /* (272) cmd ::= KILL CONNECTION INTEGER */ + { 190, -5 }, /* (273) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 190, -5 }, /* (274) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -1733,43 +2053,66 @@ static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. +** +** The yyLookahead and yyLookaheadToken parameters provide reduce actions +** access to the lookahead token (if any). The yyLookahead will be YYNOCODE +** if the lookahead token has already been consumed. As this procedure is +** only called from one place, optimizing compilers will in-line it, which +** means that the extra parameters have no performance impact. */ static void yy_reduce( yyParser *yypParser, /* The parser */ - int yyruleno /* Number of the rule by which to reduce */ + unsigned int yyruleno, /* Number of the rule by which to reduce */ + int yyLookahead, /* Lookahead token, or YYNOCODE if none */ + ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ ){ int yygoto; /* The next state */ int yyact; /* The next action */ - YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ ParseARG_FETCH; - yymsp = &yypParser->yystack[yypParser->yyidx]; + (void)yyLookahead; + (void)yyLookaheadToken; + yymsp = yypParser->yytos; #ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 - && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, - yyRuleName[yyruleno]); + if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + yysize = yyRuleInfo[yyruleno].nrhs; + if( yysize ){ + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + yyTracePrompt, + yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno); + }else{ + fprintf(yyTraceFILE, "%sReduce %d [%s].\n", + yyTracePrompt, yyruleno, yyRuleName[yyruleno]); + } } #endif /* NDEBUG */ - /* Silence complaints from purify about yygotominor being uninitialized - ** in some cases when it is copied into the stack after the following - ** switch. yygotominor is uninitialized when a rule reduces that does - ** not set the value of its left-hand side nonterminal. Leaving the - ** value of the nonterminal uninitialized is utterly harmless as long - ** as the value is never used. So really the only thing this code - ** accomplishes is to quieten purify. - ** - ** 2007-01-16: The wireshark project (www.wireshark.org) reports that - ** without this code, their parser segfaults. I'm not sure what there - ** parser is doing to make this happen. This is the second bug report - ** from wireshark this week. Clearly they are stressing Lemon in ways - ** that it has not been previously stressed... (SQLite ticket #2172) - */ - /*memset(&yygotominor, 0, sizeof(yygotominor));*/ - yygotominor = yyzerominor; - + /* Check that the stack is large enough to grow by a single entry + ** if the RHS of the rule is empty. This ensures that there is room + ** enough on the stack to push the LHS value */ + if( yyRuleInfo[yyruleno].nrhs==0 ){ +#ifdef YYTRACKMAXSTACKDEPTH + if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); + } +#endif +#if YYSTACKDEPTH>0 + if( yypParser->yytos>=yypParser->yystackEnd ){ + yyStackOverflow(yypParser); + return; + } +#else + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ + if( yyGrowStack(yypParser) ){ + yyStackOverflow(yypParser); + return; + } + yymsp = yypParser->yytos; + } +#endif + } switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example @@ -1780,7 +2123,12 @@ static void yy_reduce( ** #line ** break; */ +/********** Begin reduce actions **********************************************/ + YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ + case 130: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==130); + case 131: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==131); + case 132: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==132); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -1829,16 +2177,17 @@ static void yy_reduce( { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &yymsp[0].minor.yy0, 0); } break; case 16: /* dbPrefix ::= */ -{yygotominor.yy0.n = 0; yygotominor.yy0.type = 0;} +{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.type = 0;} break; case 17: /* dbPrefix ::= ids DOT */ -{yygotominor.yy0 = yymsp[-1].minor.yy0; } +{yylhsminor.yy0 = yymsp[-1].minor.yy0; } + yymsp[-1].minor.yy0 = yylhsminor.yy0; break; case 18: /* cpxName ::= */ -{yygotominor.yy0.n = 0; } +{yymsp[1].minor.yy0.n = 0; } break; case 19: /* cpxName ::= DOT ids */ -{yygotominor.yy0 = yymsp[0].minor.yy0; yygotominor.yy0.n += 1; } +{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n += 1; } break; case 20: /* cmd ::= SHOW CREATE TABLE ids cpxName */ { @@ -1959,16 +2308,19 @@ static void yy_reduce( break; case 48: /* ids ::= ID */ case 49: /* ids ::= STRING */ yytestcase(yyruleno==49); -{yygotominor.yy0 = yymsp[0].minor.yy0; } +{yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 50: /* ifexists ::= IF EXISTS */ - case 52: /* ifnotexists ::= IF NOT EXISTS */ yytestcase(yyruleno==52); -{ yygotominor.yy0.n = 1;} +{ yymsp[-1].minor.yy0.n = 1;} break; case 51: /* ifexists ::= */ case 53: /* ifnotexists ::= */ yytestcase(yyruleno==53); case 171: /* distinct ::= */ yytestcase(yyruleno==171); -{ yygotominor.yy0.n = 0;} +{ yymsp[1].minor.yy0.n = 0;} + break; + case 52: /* ifnotexists ::= IF NOT EXISTS */ +{ yymsp[-2].minor.yy0.n = 1;} break; case 54: /* cmd ::= CREATE DNODE ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} @@ -1992,7 +2344,7 @@ static void yy_reduce( case 71: /* users ::= */ yytestcase(yyruleno==71); case 73: /* conns ::= */ yytestcase(yyruleno==73); case 75: /* state ::= */ yytestcase(yyruleno==75); -{ yygotominor.yy0.n = 0; } +{ yymsp[1].minor.yy0.n = 0; } break; case 60: /* pps ::= PPS INTEGER */ case 62: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==62); @@ -2003,23 +2355,24 @@ static void yy_reduce( case 72: /* users ::= USERS INTEGER */ yytestcase(yyruleno==72); case 74: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==74); case 76: /* state ::= STATE ids */ yytestcase(yyruleno==76); -{ yygotominor.yy0 = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 77: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yygotominor.yy183.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yygotominor.yy183.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yygotominor.yy183.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yygotominor.yy183.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yygotominor.yy183.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yygotominor.yy183.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yygotominor.yy183.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yygotominor.yy183.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yygotominor.yy183.stat = yymsp[0].minor.yy0; + yylhsminor.yy183.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy183.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy183.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy183.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy183.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy183.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy183.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy183.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy183.stat = yymsp[0].minor.yy0; } + yymsp[-8].minor.yy183 = yylhsminor.yy183; break; case 78: /* keep ::= KEEP tagitemlist */ -{ yygotominor.yy193 = yymsp[0].minor.yy193; } +{ yymsp[-1].minor.yy193 = yymsp[0].minor.yy193; } break; case 79: /* cache ::= CACHE INTEGER */ case 80: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==80); @@ -2036,109 +2389,129 @@ static void yy_reduce( case 91: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==91); case 92: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==92); case 93: /* partitions ::= PARTITIONS INTEGER */ yytestcase(yyruleno==93); -{ yygotominor.yy0 = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 94: /* db_optr ::= */ -{setDefaultCreateDbOption(&yygotominor.yy114); yygotominor.yy114.dbType = TSDB_DB_TYPE_DEFAULT;} +{setDefaultCreateDbOption(&yymsp[1].minor.yy114); yymsp[1].minor.yy114.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 95: /* db_optr ::= db_optr cache */ -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 96: /* db_optr ::= db_optr replica */ case 113: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==113); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 97: /* db_optr ::= db_optr quorum */ case 114: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==114); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 98: /* db_optr ::= db_optr days */ -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 99: /* db_optr ::= db_optr minrows */ -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 100: /* db_optr ::= db_optr maxrows */ -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 101: /* db_optr ::= db_optr blocks */ case 116: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==116); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 102: /* db_optr ::= db_optr ctime */ -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 103: /* db_optr ::= db_optr wal */ case 118: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==118); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 104: /* db_optr ::= db_optr fsync */ case 119: /* alter_db_optr ::= alter_db_optr fsync */ yytestcase(yyruleno==119); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 105: /* db_optr ::= db_optr comp */ case 117: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==117); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 106: /* db_optr ::= db_optr prec */ -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.precision = yymsp[0].minor.yy0; } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 107: /* db_optr ::= db_optr keep */ case 115: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==115); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.keep = yymsp[0].minor.yy193; } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.keep = yymsp[0].minor.yy193; } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 108: /* db_optr ::= db_optr update */ case 120: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==120); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 109: /* db_optr ::= db_optr cachelast */ case 121: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==121); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 110: /* topic_optr ::= db_optr */ case 122: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==122); -{ yygotominor.yy114 = yymsp[0].minor.yy114; yygotominor.yy114.dbType = TSDB_DB_TYPE_TOPIC; } +{ yylhsminor.yy114 = yymsp[0].minor.yy114; yylhsminor.yy114.dbType = TSDB_DB_TYPE_TOPIC; } + yymsp[0].minor.yy114 = yylhsminor.yy114; break; case 111: /* topic_optr ::= topic_optr partitions */ case 123: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==123); -{ yygotominor.yy114 = yymsp[-1].minor.yy114; yygotominor.yy114.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy114 = yymsp[-1].minor.yy114; yylhsminor.yy114.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy114 = yylhsminor.yy114; break; case 112: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yygotominor.yy114); yygotominor.yy114.dbType = TSDB_DB_TYPE_DEFAULT;} +{ setDefaultCreateDbOption(&yymsp[1].minor.yy114); yymsp[1].minor.yy114.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 124: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yygotominor.yy27, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy27, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy27 = yylhsminor.yy27; break; case 125: /* typename ::= ids LP signed RP */ { if (yymsp[-1].minor.yy473 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yygotominor.yy27, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy27, &yymsp[-3].minor.yy0); } else { yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy473; // negative value of name length - tSetColumnType(&yygotominor.yy27, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy27, &yymsp[-3].minor.yy0); } } + yymsp[-3].minor.yy27 = yylhsminor.yy27; break; case 126: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); - tSetColumnType (&yygotominor.yy27, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy27, &yymsp[-1].minor.yy0); } + yymsp[-1].minor.yy27 = yylhsminor.yy27; break; case 127: /* signed ::= INTEGER */ - case 128: /* signed ::= PLUS INTEGER */ yytestcase(yyruleno==128); -{ yygotominor.yy473 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy473 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy473 = yylhsminor.yy473; + break; + case 128: /* signed ::= PLUS INTEGER */ +{ yymsp[-1].minor.yy473 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; case 129: /* signed ::= MINUS INTEGER */ - case 130: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==130); - case 131: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==131); - case 132: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==132); -{ yygotominor.yy473 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +{ yymsp[-1].minor.yy473 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; case 133: /* cmd ::= CREATE TABLE create_table_list */ { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy270;} @@ -2150,87 +2523,103 @@ static void yy_reduce( taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy192); pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; - yygotominor.yy270 = pCreateTable; + yylhsminor.yy270 = pCreateTable; } + yymsp[0].minor.yy270 = yylhsminor.yy270; break; case 135: /* create_table_list ::= create_table_list create_from_stable */ { taosArrayPush(yymsp[-1].minor.yy270->childTableInfo, &yymsp[0].minor.yy192); - yygotominor.yy270 = yymsp[-1].minor.yy270; + yylhsminor.yy270 = yymsp[-1].minor.yy270; } + yymsp[-1].minor.yy270 = yylhsminor.yy270; break; case 136: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yygotominor.yy270 = tSetCreateTableInfo(yymsp[-1].minor.yy193, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yygotominor.yy270, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy270 = tSetCreateTableInfo(yymsp[-1].minor.yy193, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy270, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); } + yymsp[-5].minor.yy270 = yylhsminor.yy270; break; case 137: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yygotominor.yy270 = tSetCreateTableInfo(yymsp[-5].minor.yy193, yymsp[-1].minor.yy193, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yygotominor.yy270, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy270 = tSetCreateTableInfo(yymsp[-5].minor.yy193, yymsp[-1].minor.yy193, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy270, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } + yymsp[-9].minor.yy270 = yylhsminor.yy270; break; case 138: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; - yygotominor.yy192 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy193, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy192 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy193, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } + yymsp[-9].minor.yy192 = yylhsminor.yy192; break; case 139: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; - yygotominor.yy192 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy193, yymsp[-1].minor.yy193, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy192 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy193, yymsp[-1].minor.yy193, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } + yymsp[-12].minor.yy192 = yylhsminor.yy192; break; case 140: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy193, &yymsp[0].minor.yy0); yygotominor.yy193 = yymsp[-2].minor.yy193; } +{taosArrayPush(yymsp[-2].minor.yy193, &yymsp[0].minor.yy0); yylhsminor.yy193 = yymsp[-2].minor.yy193; } + yymsp[-2].minor.yy193 = yylhsminor.yy193; break; case 141: /* tagNamelist ::= ids */ -{yygotominor.yy193 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yygotominor.yy193, &yymsp[0].minor.yy0);} +{yylhsminor.yy193 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy193, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy193 = yylhsminor.yy193; break; case 142: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yygotominor.yy270 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy124, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yygotominor.yy270, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy270 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy124, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy270, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } + yymsp[-4].minor.yy270 = yylhsminor.yy270; break; case 143: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy193, &yymsp[0].minor.yy27); yygotominor.yy193 = yymsp[-2].minor.yy193; } +{taosArrayPush(yymsp[-2].minor.yy193, &yymsp[0].minor.yy27); yylhsminor.yy193 = yymsp[-2].minor.yy193; } + yymsp[-2].minor.yy193 = yylhsminor.yy193; break; case 144: /* columnlist ::= column */ -{yygotominor.yy193 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yygotominor.yy193, &yymsp[0].minor.yy27);} +{yylhsminor.yy193 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy193, &yymsp[0].minor.yy27);} + yymsp[0].minor.yy193 = yylhsminor.yy193; break; case 145: /* column ::= ids typename */ { - tSetColumnInfo(&yygotominor.yy27, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy27); + tSetColumnInfo(&yylhsminor.yy27, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy27); } + yymsp[-1].minor.yy27 = yylhsminor.yy27; break; case 146: /* tagitemlist ::= tagitemlist COMMA tagitem */ -{ yygotominor.yy193 = tVariantListAppend(yymsp[-2].minor.yy193, &yymsp[0].minor.yy442, -1); } +{ yylhsminor.yy193 = tVariantListAppend(yymsp[-2].minor.yy193, &yymsp[0].minor.yy442, -1); } + yymsp[-2].minor.yy193 = yylhsminor.yy193; break; case 147: /* tagitemlist ::= tagitem */ -{ yygotominor.yy193 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); } +{ yylhsminor.yy193 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); } + yymsp[0].minor.yy193 = yylhsminor.yy193; break; case 148: /* tagitem ::= INTEGER */ case 149: /* tagitem ::= FLOAT */ yytestcase(yyruleno==149); case 150: /* tagitem ::= STRING */ yytestcase(yyruleno==150); case 151: /* tagitem ::= BOOL */ yytestcase(yyruleno==151); -{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yygotominor.yy442, &yymsp[0].minor.yy0); } +{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy442, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy442 = yylhsminor.yy442; break; case 152: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yygotominor.yy442, &yymsp[0].minor.yy0); } +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy442, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy442 = yylhsminor.yy442; break; case 153: /* tagitem ::= MINUS INTEGER */ case 154: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==154); @@ -2240,128 +2629,146 @@ static void yy_reduce( yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yygotominor.yy442, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy442, &yymsp[-1].minor.yy0); } + yymsp[-1].minor.yy442 = yylhsminor.yy442; break; case 157: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ { - yygotominor.yy124 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy193, yymsp[-11].minor.yy332, yymsp[-10].minor.yy454, yymsp[-4].minor.yy193, yymsp[-3].minor.yy193, &yymsp[-9].minor.yy392, &yymsp[-8].minor.yy447, &yymsp[-7].minor.yy76, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy193, &yymsp[0].minor.yy482, &yymsp[-1].minor.yy482, yymsp[-2].minor.yy454); + yylhsminor.yy124 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy193, yymsp[-11].minor.yy332, yymsp[-10].minor.yy454, yymsp[-4].minor.yy193, yymsp[-3].minor.yy193, &yymsp[-9].minor.yy392, &yymsp[-8].minor.yy447, &yymsp[-7].minor.yy76, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy193, &yymsp[0].minor.yy482, &yymsp[-1].minor.yy482, yymsp[-2].minor.yy454); } + yymsp[-13].minor.yy124 = yylhsminor.yy124; break; case 158: /* select ::= LP select RP */ -{yygotominor.yy124 = yymsp[-1].minor.yy124;} +{yymsp[-2].minor.yy124 = yymsp[-1].minor.yy124;} break; case 159: /* union ::= select */ -{ yygotominor.yy193 = setSubclause(NULL, yymsp[0].minor.yy124); } +{ yylhsminor.yy193 = setSubclause(NULL, yymsp[0].minor.yy124); } + yymsp[0].minor.yy193 = yylhsminor.yy193; break; case 160: /* union ::= union UNION ALL select */ -{ yygotominor.yy193 = appendSelectClause(yymsp[-3].minor.yy193, yymsp[0].minor.yy124); } +{ yylhsminor.yy193 = appendSelectClause(yymsp[-3].minor.yy193, yymsp[0].minor.yy124); } + yymsp[-3].minor.yy193 = yylhsminor.yy193; break; case 161: /* cmd ::= union */ { setSqlInfo(pInfo, yymsp[0].minor.yy193, NULL, TSDB_SQL_SELECT); } break; case 162: /* select ::= SELECT selcollist */ { - yygotominor.yy124 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy193, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy124 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy193, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } + yymsp[-1].minor.yy124 = yylhsminor.yy124; break; case 163: /* sclp ::= selcollist COMMA */ -{yygotominor.yy193 = yymsp[-1].minor.yy193;} +{yylhsminor.yy193 = yymsp[-1].minor.yy193;} + yymsp[-1].minor.yy193 = yylhsminor.yy193; break; case 164: /* sclp ::= */ case 194: /* orderby_opt ::= */ yytestcase(yyruleno==194); -{yygotominor.yy193 = 0;} +{yymsp[1].minor.yy193 = 0;} break; case 165: /* selcollist ::= sclp distinct expr as */ { - yygotominor.yy193 = tSqlExprListAppend(yymsp[-3].minor.yy193, yymsp[-1].minor.yy454, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy193 = tSqlExprListAppend(yymsp[-3].minor.yy193, yymsp[-1].minor.yy454, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } + yymsp[-3].minor.yy193 = yylhsminor.yy193; break; case 166: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yygotominor.yy193 = tSqlExprListAppend(yymsp[-1].minor.yy193, pNode, 0, 0); + yylhsminor.yy193 = tSqlExprListAppend(yymsp[-1].minor.yy193, pNode, 0, 0); } + yymsp[-1].minor.yy193 = yylhsminor.yy193; break; case 167: /* as ::= AS ids */ - case 168: /* as ::= ids */ yytestcase(yyruleno==168); -{ yygotominor.yy0 = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } + break; + case 168: /* as ::= ids */ +{ yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 169: /* as ::= */ -{ yygotominor.yy0.n = 0; } +{ yymsp[1].minor.yy0.n = 0; } break; case 170: /* distinct ::= DISTINCT */ -{ yygotominor.yy0 = yymsp[0].minor.yy0; } +{ yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 172: /* from ::= FROM tablelist */ case 173: /* from ::= FROM sub */ yytestcase(yyruleno==173); -{yygotominor.yy332 = yymsp[0].minor.yy332;} +{yymsp[-1].minor.yy332 = yymsp[0].minor.yy332;} break; case 174: /* sub ::= LP union RP */ -{yygotominor.yy332 = addSubqueryElem(NULL, yymsp[-1].minor.yy193, NULL);} +{yymsp[-2].minor.yy332 = addSubqueryElem(NULL, yymsp[-1].minor.yy193, NULL);} break; case 175: /* sub ::= LP union RP ids */ -{yygotominor.yy332 = addSubqueryElem(NULL, yymsp[-2].minor.yy193, &yymsp[0].minor.yy0);} +{yymsp[-3].minor.yy332 = addSubqueryElem(NULL, yymsp[-2].minor.yy193, &yymsp[0].minor.yy0);} break; case 176: /* sub ::= sub COMMA LP union RP ids */ -{yygotominor.yy332 = addSubqueryElem(yymsp[-5].minor.yy332, yymsp[-2].minor.yy193, &yymsp[0].minor.yy0);} +{yylhsminor.yy332 = addSubqueryElem(yymsp[-5].minor.yy332, yymsp[-2].minor.yy193, &yymsp[0].minor.yy0);} + yymsp[-5].minor.yy332 = yylhsminor.yy332; break; case 177: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yygotominor.yy332 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy332 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } + yymsp[-1].minor.yy332 = yylhsminor.yy332; break; case 178: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yygotominor.yy332 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy332 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy332 = yylhsminor.yy332; break; case 179: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yygotominor.yy332 = setTableNameList(yymsp[-3].minor.yy332, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy332 = setTableNameList(yymsp[-3].minor.yy332, &yymsp[-1].minor.yy0, NULL); } + yymsp[-3].minor.yy332 = yylhsminor.yy332; break; case 180: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yygotominor.yy332 = setTableNameList(yymsp[-4].minor.yy332, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy332 = setTableNameList(yymsp[-4].minor.yy332, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + yymsp[-4].minor.yy332 = yylhsminor.yy332; break; case 181: /* tmvar ::= VARIABLE */ -{yygotominor.yy0 = yymsp[0].minor.yy0;} +{yylhsminor.yy0 = yymsp[0].minor.yy0;} + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 182: /* interval_opt ::= INTERVAL LP tmvar RP */ -{yygotominor.yy392.interval = yymsp[-1].minor.yy0; yygotominor.yy392.offset.n = 0;} +{yymsp[-3].minor.yy392.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy392.offset.n = 0;} break; case 183: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ -{yygotominor.yy392.interval = yymsp[-3].minor.yy0; yygotominor.yy392.offset = yymsp[-1].minor.yy0;} +{yymsp[-5].minor.yy392.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy392.offset = yymsp[-1].minor.yy0;} break; case 184: /* interval_opt ::= */ -{memset(&yygotominor.yy392, 0, sizeof(yygotominor.yy392));} +{memset(&yymsp[1].minor.yy392, 0, sizeof(yymsp[1].minor.yy392));} break; case 185: /* session_option ::= */ -{yygotominor.yy447.col.n = 0; yygotominor.yy447.gap.n = 0;} +{yymsp[1].minor.yy447.col.n = 0; yymsp[1].minor.yy447.gap.n = 0;} break; case 186: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yygotominor.yy447.col = yymsp[-4].minor.yy0; - yygotominor.yy447.gap = yymsp[-1].minor.yy0; + yymsp[-6].minor.yy447.col = yymsp[-4].minor.yy0; + yymsp[-6].minor.yy447.gap = yymsp[-1].minor.yy0; } break; case 187: /* windowstate_option ::= */ -{yygotominor.yy76.col.n = 0;} +{yymsp[1].minor.yy76.col.n = 0;} break; case 188: /* windowstate_option ::= STATE_WINDOW LP ids RP */ { - yygotominor.yy76.col = yymsp[-1].minor.yy0; + yymsp[-3].minor.yy76.col = yymsp[-1].minor.yy0; } break; case 189: /* fill_opt ::= */ -{ yygotominor.yy193 = 0; } +{ yymsp[1].minor.yy193 = 0; } break; case 190: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { @@ -2370,205 +2777,251 @@ static void yy_reduce( tVariantCreate(&A, &yymsp[-3].minor.yy0); tVariantListInsert(yymsp[-1].minor.yy193, &A, -1, 0); - yygotominor.yy193 = yymsp[-1].minor.yy193; + yymsp[-5].minor.yy193 = yymsp[-1].minor.yy193; } break; case 191: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yygotominor.yy193 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy193 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; case 192: /* sliding_opt ::= SLIDING LP tmvar RP */ -{yygotominor.yy0 = yymsp[-1].minor.yy0; } +{yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; case 193: /* sliding_opt ::= */ -{yygotominor.yy0.n = 0; yygotominor.yy0.z = NULL; yygotominor.yy0.type = 0; } +{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; case 195: /* orderby_opt ::= ORDER BY sortlist */ -{yygotominor.yy193 = yymsp[0].minor.yy193;} +{yymsp[-2].minor.yy193 = yymsp[0].minor.yy193;} break; case 196: /* sortlist ::= sortlist COMMA item sortorder */ { - yygotominor.yy193 = tVariantListAppend(yymsp[-3].minor.yy193, &yymsp[-1].minor.yy442, yymsp[0].minor.yy312); + yylhsminor.yy193 = tVariantListAppend(yymsp[-3].minor.yy193, &yymsp[-1].minor.yy442, yymsp[0].minor.yy312); } + yymsp[-3].minor.yy193 = yylhsminor.yy193; break; case 197: /* sortlist ::= item sortorder */ { - yygotominor.yy193 = tVariantListAppend(NULL, &yymsp[-1].minor.yy442, yymsp[0].minor.yy312); + yylhsminor.yy193 = tVariantListAppend(NULL, &yymsp[-1].minor.yy442, yymsp[0].minor.yy312); } + yymsp[-1].minor.yy193 = yylhsminor.yy193; break; case 198: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yygotominor.yy442, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy442, &yymsp[-1].minor.yy0); } + yymsp[-1].minor.yy442 = yylhsminor.yy442; break; case 199: /* sortorder ::= ASC */ - case 201: /* sortorder ::= */ yytestcase(yyruleno==201); -{ yygotominor.yy312 = TSDB_ORDER_ASC; } +{ yymsp[0].minor.yy312 = TSDB_ORDER_ASC; } break; case 200: /* sortorder ::= DESC */ -{ yygotominor.yy312 = TSDB_ORDER_DESC;} +{ yymsp[0].minor.yy312 = TSDB_ORDER_DESC;} + break; + case 201: /* sortorder ::= */ +{ yymsp[1].minor.yy312 = TSDB_ORDER_ASC; } break; case 202: /* groupby_opt ::= */ -{ yygotominor.yy193 = 0;} +{ yymsp[1].minor.yy193 = 0;} break; case 203: /* groupby_opt ::= GROUP BY grouplist */ -{ yygotominor.yy193 = yymsp[0].minor.yy193;} +{ yymsp[-2].minor.yy193 = yymsp[0].minor.yy193;} break; case 204: /* grouplist ::= grouplist COMMA item */ { - yygotominor.yy193 = tVariantListAppend(yymsp[-2].minor.yy193, &yymsp[0].minor.yy442, -1); + yylhsminor.yy193 = tVariantListAppend(yymsp[-2].minor.yy193, &yymsp[0].minor.yy442, -1); } + yymsp[-2].minor.yy193 = yylhsminor.yy193; break; case 205: /* grouplist ::= item */ { - yygotominor.yy193 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); + yylhsminor.yy193 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); } + yymsp[0].minor.yy193 = yylhsminor.yy193; break; case 206: /* having_opt ::= */ case 216: /* where_opt ::= */ yytestcase(yyruleno==216); case 258: /* expritem ::= */ yytestcase(yyruleno==258); -{yygotominor.yy454 = 0;} +{yymsp[1].minor.yy454 = 0;} break; case 207: /* having_opt ::= HAVING expr */ case 217: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==217); - case 257: /* expritem ::= expr */ yytestcase(yyruleno==257); -{yygotominor.yy454 = yymsp[0].minor.yy454;} +{yymsp[-1].minor.yy454 = yymsp[0].minor.yy454;} break; case 208: /* limit_opt ::= */ case 212: /* slimit_opt ::= */ yytestcase(yyruleno==212); -{yygotominor.yy482.limit = -1; yygotominor.yy482.offset = 0;} +{yymsp[1].minor.yy482.limit = -1; yymsp[1].minor.yy482.offset = 0;} break; case 209: /* limit_opt ::= LIMIT signed */ case 213: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==213); -{yygotominor.yy482.limit = yymsp[0].minor.yy473; yygotominor.yy482.offset = 0;} +{yymsp[-1].minor.yy482.limit = yymsp[0].minor.yy473; yymsp[-1].minor.yy482.offset = 0;} break; case 210: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yygotominor.yy482.limit = yymsp[-2].minor.yy473; yygotominor.yy482.offset = yymsp[0].minor.yy473;} +{ yymsp[-3].minor.yy482.limit = yymsp[-2].minor.yy473; yymsp[-3].minor.yy482.offset = yymsp[0].minor.yy473;} break; case 211: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yygotominor.yy482.limit = yymsp[0].minor.yy473; yygotominor.yy482.offset = yymsp[-2].minor.yy473;} +{ yymsp[-3].minor.yy482.limit = yymsp[0].minor.yy473; yymsp[-3].minor.yy482.offset = yymsp[-2].minor.yy473;} break; case 214: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yygotominor.yy482.limit = yymsp[-2].minor.yy473; yygotominor.yy482.offset = yymsp[0].minor.yy473;} +{yymsp[-3].minor.yy482.limit = yymsp[-2].minor.yy473; yymsp[-3].minor.yy482.offset = yymsp[0].minor.yy473;} break; case 215: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yygotominor.yy482.limit = yymsp[0].minor.yy473; yygotominor.yy482.offset = yymsp[-2].minor.yy473;} +{yymsp[-3].minor.yy482.limit = yymsp[0].minor.yy473; yymsp[-3].minor.yy482.offset = yymsp[-2].minor.yy473;} break; case 218: /* expr ::= LP expr RP */ -{yygotominor.yy454 = yymsp[-1].minor.yy454; yygotominor.yy454->token.z = yymsp[-2].minor.yy0.z; yygotominor.yy454->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} +{yylhsminor.yy454 = yymsp[-1].minor.yy454; yylhsminor.yy454->token.z = yymsp[-2].minor.yy0.z; yylhsminor.yy454->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 219: /* expr ::= ID */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 220: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 221: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 222: /* expr ::= INTEGER */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 223: /* expr ::= MINUS INTEGER */ case 224: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==224); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy454 = yylhsminor.yy454; break; case 225: /* expr ::= FLOAT */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 226: /* expr ::= MINUS FLOAT */ case 227: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==227); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy454 = yylhsminor.yy454; break; case 228: /* expr ::= STRING */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 229: /* expr ::= NOW */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 230: /* expr ::= VARIABLE */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 231: /* expr ::= PLUS VARIABLE */ case 232: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==232); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} + yymsp[-1].minor.yy454 = yylhsminor.yy454; break; case 233: /* expr ::= BOOL */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 234: /* expr ::= NULL */ -{ yygotominor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} +{ yylhsminor.yy454 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 235: /* expr ::= ID LP exprlist RP */ -{ yygotominor.yy454 = tSqlExprCreateFunction(yymsp[-1].minor.yy193, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } +{ yylhsminor.yy454 = tSqlExprCreateFunction(yymsp[-1].minor.yy193, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy454 = yylhsminor.yy454; break; case 236: /* expr ::= ID LP STAR RP */ -{ yygotominor.yy454 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } +{ yylhsminor.yy454 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy454 = yylhsminor.yy454; break; case 237: /* expr ::= expr IS NULL */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, NULL, TK_ISNULL);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, NULL, TK_ISNULL);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 238: /* expr ::= expr IS NOT NULL */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-3].minor.yy454, NULL, TK_NOTNULL);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-3].minor.yy454, NULL, TK_NOTNULL);} + yymsp[-3].minor.yy454 = yylhsminor.yy454; break; case 239: /* expr ::= expr LT expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_LT);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_LT);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 240: /* expr ::= expr GT expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_GT);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_GT);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 241: /* expr ::= expr LE expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_LE);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_LE);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 242: /* expr ::= expr GE expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_GE);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_GE);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 243: /* expr ::= expr NE expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_NE);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_NE);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 244: /* expr ::= expr EQ expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_EQ);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_EQ);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 245: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy454); yygotominor.yy454 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy454, yymsp[-2].minor.yy454, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy454, TK_LE), TK_AND);} +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy454); yylhsminor.yy454 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy454, yymsp[-2].minor.yy454, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy454, TK_LE), TK_AND);} + yymsp[-4].minor.yy454 = yylhsminor.yy454; break; case 246: /* expr ::= expr AND expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_AND);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_AND);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 247: /* expr ::= expr OR expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_OR); } +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_OR); } + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 248: /* expr ::= expr PLUS expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_PLUS); } +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_PLUS); } + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 249: /* expr ::= expr MINUS expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_MINUS); } +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_MINUS); } + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 250: /* expr ::= expr STAR expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_STAR); } +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_STAR); } + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 251: /* expr ::= expr SLASH expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_DIVIDE);} +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_DIVIDE);} + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 252: /* expr ::= expr REM expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_REM); } +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_REM); } + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 253: /* expr ::= expr LIKE expr */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_LIKE); } +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-2].minor.yy454, yymsp[0].minor.yy454, TK_LIKE); } + yymsp[-2].minor.yy454 = yylhsminor.yy454; break; case 254: /* expr ::= expr IN LP exprlist RP */ -{yygotominor.yy454 = tSqlExprCreate(yymsp[-4].minor.yy454, (tSqlExpr*)yymsp[-1].minor.yy193, TK_IN); } +{yylhsminor.yy454 = tSqlExprCreate(yymsp[-4].minor.yy454, (tSqlExpr*)yymsp[-1].minor.yy193, TK_IN); } + yymsp[-4].minor.yy454 = yylhsminor.yy454; break; case 255: /* exprlist ::= exprlist COMMA expritem */ -{yygotominor.yy193 = tSqlExprListAppend(yymsp[-2].minor.yy193,yymsp[0].minor.yy454,0, 0);} +{yylhsminor.yy193 = tSqlExprListAppend(yymsp[-2].minor.yy193,yymsp[0].minor.yy454,0, 0);} + yymsp[-2].minor.yy193 = yylhsminor.yy193; break; case 256: /* exprlist ::= expritem */ -{yygotominor.yy193 = tSqlExprListAppend(0,yymsp[0].minor.yy454,0, 0);} +{yylhsminor.yy193 = tSqlExprListAppend(0,yymsp[0].minor.yy454,0, 0);} + yymsp[0].minor.yy193 = yylhsminor.yy193; + break; + case 257: /* expritem ::= expr */ +{yylhsminor.yy454 = yymsp[0].minor.yy454;} + yymsp[0].minor.yy454 = yylhsminor.yy454; break; case 259: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} @@ -2699,32 +3152,25 @@ static void yy_reduce( break; default: break; +/********** End reduce actions ************************************************/ }; + assert( yyrulenoyyidx -= yysize; - yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); - if( yyact < YYNSTATE ){ -#ifdef NDEBUG - /* If we are not debugging and the reduce action popped at least - ** one element off the stack, then we can push the new element back - ** onto the stack here, and skip the stack overflow test in yy_shift(). - ** That gives a significant speed improvement. */ - if( yysize ){ - yypParser->yyidx++; - yymsp -= yysize-1; - yymsp->stateno = (YYACTIONTYPE)yyact; - yymsp->major = (YYCODETYPE)yygoto; - yymsp->minor = yygotominor; - }else -#endif - { - yy_shift(yypParser,yyact,yygoto,&yygotominor); - } - }else{ - assert( yyact == YYNSTATE + YYNRULE + 1 ); - yy_accept(yypParser); - } + yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto); + + /* There are no SHIFTREDUCE actions on nonterminals because the table + ** generator has simplified them to pure REDUCE actions. */ + assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) ); + + /* It is not possible for a REDUCE to be followed by an error */ + assert( yyact!=YY_ERROR_ACTION ); + + yymsp += yysize+1; + yypParser->yytos = yymsp; + yymsp->stateno = (YYACTIONTYPE)yyact; + yymsp->major = (YYCODETYPE)yygoto; + yyTraceShift(yypParser, yyact, "... then shift"); } /* @@ -2740,9 +3186,11 @@ static void yy_parse_failed( fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser fails */ +/************ Begin %parse_failure code ***************************************/ +/************ End %parse_failure code *****************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } #endif /* YYNOERRORRECOVERY */ @@ -2753,10 +3201,11 @@ static void yy_parse_failed( static void yy_syntax_error( yyParser *yypParser, /* The parser */ int yymajor, /* The major type of the error token */ - YYMINORTYPE yyminor /* The minor type of the error token */ + ParseTOKENTYPE yyminor /* The minor type of the error token */ ){ ParseARG_FETCH; -#define TOKEN (yyminor.yy0) +#define TOKEN yyminor +/************ Begin %syntax_error code ****************************************/ pInfo->valid = false; int32_t outputBufLen = tListLen(pInfo->msg); @@ -2779,6 +3228,7 @@ static void yy_syntax_error( } assert(len <= outputBufLen); +/************ End %syntax_error code ******************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } @@ -2794,10 +3244,15 @@ static void yy_accept( fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif + assert( yypParser->yytos==yypParser->yystack ); /* Here code is inserted which will be executed whenever the ** parser accepts */ +/*********** Begin %parse_accept code *****************************************/ +/*********** End %parse_accept code *******************************************/ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ } @@ -2827,50 +3282,52 @@ void Parse( ParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; - int yyact; /* The parser action. */ + unsigned int yyact; /* The parser action. */ +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ +#endif #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif yyParser *yypParser; /* The parser */ - /* (re)initialize the parser, if necessary */ yypParser = (yyParser*)yyp; - if( yypParser->yyidx<0 ){ -#if YYSTACKDEPTH<=0 - if( yypParser->yystksz <=0 ){ - /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ - yyminorunion = yyzerominor; - yyStackOverflow(yypParser, &yyminorunion); - return; - } -#endif - yypParser->yyidx = 0; - yypParser->yyerrcnt = -1; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; - } - yyminorunion.yy0 = yyminor; + assert( yypParser->yytos!=0 ); +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); +#endif ParseARG_STORE; #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); + int stateno = yypParser->yytos->stateno; + if( stateno < YY_MIN_REDUCE ){ + fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno); + }else{ + fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE); + } } #endif do{ yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); - if( yyact= YY_MIN_REDUCE ){ + yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor); + }else if( yyact <= YY_MAX_SHIFTREDUCE ){ + yy_shift(yypParser,yyact,yymajor,yyminor); +#ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; +#endif yymajor = YYNOCODE; - }else if( yyact < YYNSTATE + YYNRULE ){ - yy_reduce(yypParser,yyact-YYNSTATE); + }else if( yyact==YY_ACCEPT_ACTION ){ + yypParser->yytos--; + yy_accept(yypParser); + return; }else{ assert( yyact == YY_ERROR_ACTION ); + yyminorunion.yy0 = yyminor; #ifdef YYERRORSYMBOL int yymx; #endif @@ -2900,9 +3357,9 @@ void Parse( ** */ if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor,yyminor); } - yymx = yypParser->yystack[yypParser->yyidx].major; + yymx = yypParser->yytos->major; if( yymx==YYERRORSYMBOL || yyerrorhit ){ #ifndef NDEBUG if( yyTraceFILE ){ @@ -2910,26 +3367,26 @@ void Parse( yyTracePrompt,yyTokenName[yymajor]); } #endif - yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); + yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); yymajor = YYNOCODE; }else{ - while( - yypParser->yyidx >= 0 && - yymx != YYERRORSYMBOL && - (yyact = yy_find_reduce_action( - yypParser->yystack[yypParser->yyidx].stateno, - YYERRORSYMBOL)) >= YYNSTATE + while( yypParser->yytos >= yypParser->yystack + && yymx != YYERRORSYMBOL + && (yyact = yy_find_reduce_action( + yypParser->yytos->stateno, + YYERRORSYMBOL)) >= YY_MIN_REDUCE ){ yy_pop_parser_stack(yypParser); } - if( yypParser->yyidx < 0 || yymajor==0 ){ + if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif yymajor = YYNOCODE; }else if( yymx!=YYERRORSYMBOL ){ - YYMINORTYPE u2; - u2.YYERRSYMDT = 0; - yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); + yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor); } } yypParser->yyerrcnt = 3; @@ -2942,7 +3399,7 @@ void Parse( ** Applications can set this macro (for example inside %include) if ** they intend to abandon the parse upon the first syntax error seen. */ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor, yyminor); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yymajor = YYNOCODE; @@ -2957,16 +3414,31 @@ void Parse( ** three input tokens have been successfully shifted. */ if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor, yyminor); } yypParser->yyerrcnt = 3; yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); if( yyendofinput ){ yy_parse_failed(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif } yymajor = YYNOCODE; #endif } - }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); + }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack ); +#ifndef NDEBUG + if( yyTraceFILE ){ + yyStackEntry *i; + char cDiv = '['; + fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); + for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){ + fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]); + cDiv = ' '; + } + fprintf(yyTraceFILE,"]\n"); + } +#endif return; } From 597e11a4492d094f0b96186ad0180396de29644b Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 31 May 2021 15:05:27 +0800 Subject: [PATCH 55/80] Hotfix/sangshuduo/td 4353 taosdemo subscribe resub (#6302) * [TD-4353]: taosdemo resub if resubAfterConsume != -1 * fix but resubafter use endafter section. Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 993bb40ee2..dcfed8bc2a 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -4401,8 +4401,9 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { cJSON* resubAfterConsume = cJSON_GetObjectItem(specifiedQuery, "resubAfterConsume"); - if (resubAfterConsume - && resubAfterConsume->type == cJSON_Number) { + if ((resubAfterConsume) + && (resubAfterConsume->type == cJSON_Number) + && (resubAfterConsume->valueint >= 0)) { g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = resubAfterConsume->valueint; } else if (!resubAfterConsume) { @@ -4563,14 +4564,15 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { } cJSON* superResubAfterConsume = - cJSON_GetObjectItem(superQuery, "endAfterConsume"); - if (superResubAfterConsume - && superResubAfterConsume->type == cJSON_Number) { - g_queryInfo.superQueryInfo.endAfterConsume = + cJSON_GetObjectItem(superQuery, "resubAfterConsume"); + if ((superResubAfterConsume) + && (superResubAfterConsume->type == cJSON_Number) + && (superResubAfterConsume->valueint >= 0)) { + g_queryInfo.superQueryInfo.resubAfterConsume = superResubAfterConsume->valueint; } else if (!superResubAfterConsume) { // default value is -1, which mean do not resub - g_queryInfo.superQueryInfo.endAfterConsume = -1; + g_queryInfo.superQueryInfo.resubAfterConsume = -1; } // supert table sqls From 3ac7f05f98fdf9e27caf26dd28c3de01eb9640e5 Mon Sep 17 00:00:00 2001 From: lichuang Date: Mon, 31 May 2021 15:12:52 +0800 Subject: [PATCH 56/80] [TD-3963]add community version macro in cmakefile,change keep option base on version --- CMakeLists.txt | 2 ++ src/mnode/src/mnodeDb.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f50aca079..b34d995d30 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,8 @@ IF (TD_WINDOWS OR TD_DARWIN) SET(TD_SOMODE_STATIC TRUE) ENDIF () +ADD_DEFINITIONS(-D_TD_COMMUNITY_VERSION) + INCLUDE(cmake/define.inc) INCLUDE(cmake/env.inc) INCLUDE(cmake/version.inc) diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 5e06faaad9..e6d82a6530 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -1060,6 +1060,13 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { newCfg.partitions = partitions; } +// community version can only change daysToKeep +// but enterprise version can change all daysToKeep options +#if defined(_TD_COMMUNITY_VERSION) && !defined(_TD_ENTERPRISE_VERSION) + newCfg.daysToKeep1 = newCfg.daysToKeep; + newCfg.daysToKeep2 = newCfg.daysToKeep; +#endif + return newCfg; } From ed9ff8917c03135e32a69f5a5df988024a216c41 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Mon, 31 May 2021 07:33:08 +0000 Subject: [PATCH 57/80] [TD-4447]import the same csv twice --- tests/pytest/import_merge/importCSV.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/pytest/import_merge/importCSV.py b/tests/pytest/import_merge/importCSV.py index b4441949a1..24ebffd485 100644 --- a/tests/pytest/import_merge/importCSV.py +++ b/tests/pytest/import_merge/importCSV.py @@ -82,6 +82,8 @@ class TDTestCase: tdSql.execute("import into tbx file \'%s\'"%(self.csvfile)) tdSql.query('select * from tbx') tdSql.checkRows(self.rows) + #TD-4447 import the same csv twice + tdSql.execute("import into tbx file \'%s\'"%(self.csvfile)) def stop(self): self.destroyCSVFile() From 37bde37c8532998aeb4752589266dd495a75c56e Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Mon, 31 May 2021 15:48:53 +0800 Subject: [PATCH 58/80] fix join time precision issue --- src/client/src/tscSubquery.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 3cb2b60ce2..08ade3acc5 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1489,6 +1489,8 @@ static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfR SSqlRes* pRes1 = &pParentSql->pSubs[i]->res; + pParentSql->res.precision = pRes1->precision; + if (pRes1->row > 0 && pRes1->numOfRows > 0) { tscDebug("0x%"PRIx64" sub:%p index:%d numOfRows:%d total:%"PRId64 " (not retrieve)", pParentSql->self, pParentSql->pSubs[i], i, pRes1->numOfRows, pRes1->numOfTotal); From d5965c461a1bc0519fee465c438b7b3e078299ce Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Mon, 31 May 2021 15:51:43 +0800 Subject: [PATCH 59/80] must ltime >0 to replace --- src/client/src/tscStream.c | 4 ++-- tests/pytest/util/dnodes.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 2226c3d95d..3998f99afe 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -576,8 +576,8 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) { // set stime with ltime if ltime > stime const char* dstTable = pStream->dstTable? pStream->dstTable: ""; tscDebug(" CQ table=%s ltime is %"PRId64, dstTable, pStream->ltime); - if(pStream->ltime > pStream->stime) { - tscWarn(" CQ set stream %s stime=%"PRId64" replace with ltime=%"PRId64" ", dstTable, pStream->stime, pStream->ltime); + if(pStream->ltime > 0 && pStream->ltime > pStream->stime) { + tscWarn(" CQ set stream %s stime=%"PRId64" replace with ltime=%"PRId64" if ltime>0 ", dstTable, pStream->stime, pStream->ltime); pStream->stime = pStream->ltime; } diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 6eaf4e18af..0f71ffd0a3 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -432,7 +432,7 @@ class TDDnodes: self.simDeployed = False def init(self, path): - psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'" + psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}'" processID = subprocess.check_output(psCmd, shell=True).decode("utf-8") while(processID): killCmd = "kill -TERM %s > /dev/null 2>&1" % processID @@ -545,14 +545,14 @@ class TDDnodes: for i in range(len(self.dnodes)): self.dnodes[i].stop() - psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep | awk '{print $2}'" + psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep| grep -v defunct | awk '{print $2}'" processID = subprocess.check_output(psCmd, shell=True).decode("utf-8") if processID: cmd = "sudo systemctl stop taosd" os.system(cmd) # if os.system(cmd) != 0 : # tdLog.exit(cmd) - psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'" + psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}'" processID = subprocess.check_output(psCmd, shell=True).decode("utf-8") while(processID): killCmd = "kill -TERM %s > /dev/null 2>&1" % processID From 23217b7ee6d9eee2fb53c0818ca709ededc9b558 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Mon, 31 May 2021 08:24:23 +0000 Subject: [PATCH 60/80] [TD-4447]import the same csv twice --- tests/pytest/import_merge/importCSV.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/pytest/import_merge/importCSV.py b/tests/pytest/import_merge/importCSV.py index b4441949a1..24ebffd485 100644 --- a/tests/pytest/import_merge/importCSV.py +++ b/tests/pytest/import_merge/importCSV.py @@ -82,6 +82,8 @@ class TDTestCase: tdSql.execute("import into tbx file \'%s\'"%(self.csvfile)) tdSql.query('select * from tbx') tdSql.checkRows(self.rows) + #TD-4447 import the same csv twice + tdSql.execute("import into tbx file \'%s\'"%(self.csvfile)) def stop(self): self.destroyCSVFile() From 0684dd5298547db0a97f8cf2020ef0754b9f6263 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Mon, 31 May 2021 16:45:49 +0800 Subject: [PATCH 61/80] fix bug --- src/client/src/tscPrepare.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index b80bdabbfc..631b0c7fb6 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1286,7 +1286,7 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { } sToken = tStrGetToken(pCmd->curSql, &index, false); - if (sToken.n <= 0 || sToken.type != TK_VALUES) { + if (sToken.n <= 0 || (sToken.type != TK_VALUES && sToken.type != TK_LP) { return TSDB_CODE_TSC_INVALID_OPERATION; } From 122241014aebdf8833d3163ff7245a6571f19c9b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 31 May 2021 18:53:51 +0800 Subject: [PATCH 62/80] change D_TD_COMMUNITY_VERSION to _STORAGE --- CMakeLists.txt | 2 -- src/mnode/src/mnodeDb.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b34d995d30..6f50aca079 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,6 @@ IF (TD_WINDOWS OR TD_DARWIN) SET(TD_SOMODE_STATIC TRUE) ENDIF () -ADD_DEFINITIONS(-D_TD_COMMUNITY_VERSION) - INCLUDE(cmake/define.inc) INCLUDE(cmake/env.inc) INCLUDE(cmake/version.inc) diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index e6d82a6530..b0ac1192bb 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -1062,7 +1062,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { // community version can only change daysToKeep // but enterprise version can change all daysToKeep options -#if defined(_TD_COMMUNITY_VERSION) && !defined(_TD_ENTERPRISE_VERSION) +#ifndef _STORAGE newCfg.daysToKeep1 = newCfg.daysToKeep; newCfg.daysToKeep2 = newCfg.daysToKeep; #endif From 3c01a2816f3814b26071224cc807e0856349b834 Mon Sep 17 00:00:00 2001 From: dapan1121 <72057773+dapan1121@users.noreply.github.com> Date: Mon, 31 May 2021 19:23:16 +0800 Subject: [PATCH 63/80] Update tscPrepare.c fix compile issue --- src/client/src/tscPrepare.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 631b0c7fb6..5ec0a786c6 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1286,7 +1286,7 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { } sToken = tStrGetToken(pCmd->curSql, &index, false); - if (sToken.n <= 0 || (sToken.type != TK_VALUES && sToken.type != TK_LP) { + if (sToken.n <= 0 || (sToken.type != TK_VALUES && sToken.type != TK_LP)) { return TSDB_CODE_TSC_INVALID_OPERATION; } From edd05ea486d618af8bbb7b8baaae115253ec7b09 Mon Sep 17 00:00:00 2001 From: tickduan <417921451@qq.com> Date: Mon, 31 May 2021 19:49:47 +0800 Subject: [PATCH 64/80] INT64_MIN default to ltime --- src/client/src/tscStream.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 3998f99afe..0401d1f3b2 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -576,7 +576,7 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) { // set stime with ltime if ltime > stime const char* dstTable = pStream->dstTable? pStream->dstTable: ""; tscDebug(" CQ table=%s ltime is %"PRId64, dstTable, pStream->ltime); - if(pStream->ltime > 0 && pStream->ltime > pStream->stime) { + if(pStream->ltime != INT64_MIN && pStream->ltime > pStream->stime) { tscWarn(" CQ set stream %s stime=%"PRId64" replace with ltime=%"PRId64" if ltime>0 ", dstTable, pStream->stime, pStream->ltime); pStream->stime = pStream->ltime; } @@ -678,6 +678,7 @@ TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* dstTable, const c return NULL; } + pStream->ltime = INT64_MIN; pStream->stime = stime; pStream->fp = fp; pStream->callback = callback; From de15453c0ef1dcb017223c119ea90474b5c45d06 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 31 May 2021 22:58:07 +0800 Subject: [PATCH 65/80] [td-4314]:support top/bottom query on main query. --- src/client/src/tscSQLParser.c | 14 +++++++++++--- src/client/src/tscServer.c | 1 - src/client/src/tscSql.c | 2 +- src/query/src/qAggMain.c | 11 ++++++----- src/query/src/qExecutor.c | 22 +++++++++++++--------- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 8dbbf9be2e..2a7678ffab 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7422,6 +7422,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf const char* msg1 = "point interpolation query needs timestamp"; const char* msg2 = "too many tables in from clause"; const char* msg3 = "start(end) time of query range required or time range too large"; + const char* msg4 = "interval query not supported, since the result of sub query not include valid timestamp column"; const char* msg9 = "only tag query not compatible with normal column filter"; int32_t code = TSDB_CODE_SUCCESS; @@ -7480,9 +7481,16 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf if (validateIntervalNode(pSql, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } else { - if (isTimeWindowQuery(pQueryInfo) && - (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_TSC_INVALID_OPERATION; + if (isTimeWindowQuery(pQueryInfo)) { + // check if the first column of the nest query result is timestamp column + SColumn* pCol = taosArrayGetP(pQueryInfo->colList, 0); + if (pCol->info.type != TSDB_DATA_TYPE_TIMESTAMP) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + } + + if (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } } } } else { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index b1d8f2f813..9e2fd72bca 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -477,7 +477,6 @@ int doBuildAndSendMsg(SSqlObj *pSql) { pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_CONNECT || pCmd->command == TSDB_SQL_HB || -// pCmd->command == TSDB_SQL_META || pCmd->command == TSDB_SQL_STABLEVGROUP) { pRes->code = tscBuildMsg[pCmd->command](pSql, NULL); } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 1ffa6416b2..554ce351eb 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -627,7 +627,7 @@ static bool hasAdditionalErrorInfo(int32_t code, SSqlCmd *pCmd) { char *z = NULL; if (len > 0) { - z = strstr(pCmd->payload, "invalid SQL"); + z = strstr(pCmd->payload, "invalid operation"); if (z == NULL) { z = strstr(pCmd->payload, "syntax error"); } diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 177cea8b62..8a38c56adc 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -2578,13 +2578,14 @@ static void top_function(SQLFunctionCtx *pCtx) { for (int32_t i = 0; i < pCtx->size; ++i) { char *data = GET_INPUT_DATA(pCtx, i); - TSKEY ts = GET_TS_DATA(pCtx, i); - if (pCtx->hasNull && isNull(data, pCtx->inputType)) { continue; } notNullElems++; + + // NOTE: Set the default timestamp if it is missing [todo refactor] + TSKEY ts = (pCtx->ptsList != NULL)? GET_TS_DATA(pCtx, i):0; do_top_function_add(pRes, (int32_t)pCtx->param[0].i64, data, ts, pCtx->inputType, &pCtx->tagInfo, NULL, 0); } @@ -2657,13 +2658,13 @@ static void bottom_function(SQLFunctionCtx *pCtx) { for (int32_t i = 0; i < pCtx->size; ++i) { char *data = GET_INPUT_DATA(pCtx, i); - TSKEY ts = GET_TS_DATA(pCtx, i); - if (pCtx->hasNull && isNull(data, pCtx->inputType)) { continue; } - + notNullElems++; + // NOTE: Set the default timestamp if it is missing [todo refactor] + TSKEY ts = (pCtx->ptsList != NULL)? GET_TS_DATA(pCtx, i):0; do_bottom_function_add(pRes, (int32_t)pCtx->param[0].i64, data, ts, pCtx->inputType, &pCtx->tagInfo, NULL, 0); } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 4a0fb06b48..6257750d61 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -947,7 +947,13 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, uint32_t status = aAggs[pCtx[i].functionId].status; if ((status & (TSDB_FUNCSTATE_SELECTIVITY | TSDB_FUNCSTATE_NEED_TS)) != 0) { SColumnInfoData* tsInfo = taosArrayGet(pBlock->pDataBlock, 0); - pCtx[i].ptsList = (int64_t*) tsInfo->pData; + // In case of the top/bottom query again the nest query result, which has no timestamp column + // don't set the ptsList attribute. + if (tsInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP) { + pCtx[i].ptsList = (int64_t*) tsInfo->pData; + } else { + pCtx[i].ptsList = NULL; + } } } else if (TSDB_COL_IS_UD_COL(pCol->flag) && (pOperator->pRuntimeEnv->scanFlag == MERGE_STAGE)) { SColIndex* pColIndex = &pOperator->pExpr[i].base.colInfo; @@ -4213,6 +4219,10 @@ static void updateTableIdInfo(STableQueryInfo* pTableQueryInfo, SSDataBlock* pBl int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); pTableQueryInfo->lastKey = ((order == TSDB_ORDER_ASC)? pBlock->info.window.ekey:pBlock->info.window.skey) + step; + if (pTableQueryInfo->pTable == NULL) { + return; + } + STableIdInfo tidInfo = createTableIdInfo(pTableQueryInfo); STableIdInfo *idinfo = taosHashGet(pTableIdInfo, &tidInfo.tid, sizeof(tidInfo.tid)); if (idinfo != NULL) { @@ -4880,10 +4890,7 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) { updateOutputBuf(&pArithInfo->binfo, &pArithInfo->bufCapacity, pBlock->info.rows); arithmeticApplyFunctions(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); - - if (pTableQueryInfo != NULL) { // TODO refactor - updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); - } + updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); pRes->info.rows = getNumOfResult(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { @@ -4924,10 +4931,7 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) { updateOutputBuf(&pArithInfo->binfo, &pArithInfo->bufCapacity, pBlock->info.rows); arithmeticApplyFunctions(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); - - if (pTableQueryInfo != NULL) { // TODO refactor - updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); - } + updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); pRes->info.rows = getNumOfResult(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); if (pRes->info.rows >= 1000/*pRuntimeEnv->resultInfo.threshold*/) { From a659870a2ad1a81dcdcb7856f00c046a0586925c Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 31 May 2021 23:01:21 +0800 Subject: [PATCH 66/80] [td-255]: fix crash caused by tag bind. --- .../com/taosdata/jdbc/TSDBJNIConnector.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index 179bad2ced..256e735285 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -16,13 +16,13 @@ */ package com.taosdata.jdbc; -import com.taosdata.jdbc.utils.TaosInfo; - import java.nio.ByteBuffer; import java.sql.SQLException; import java.sql.SQLWarning; import java.util.List; +import com.taosdata.jdbc.utils.TaosInfo; + /** * JNI connector */ @@ -276,23 +276,14 @@ public class TSDBJNIConnector { private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes); public long prepareStmt(String sql) throws SQLException { - Long stmt = 0L; - try { - stmt = prepareStmtImp(sql.getBytes(), this.taos); - } catch (Exception e) { - e.printStackTrace(); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING); - } - - if (stmt == TSDBConstants.JNI_CONNECTION_NULL) { + Long stmt = prepareStmtImp(sql.getBytes(), this.taos); + if (stmt == TSDBConstants.JNI_TDENGINE_ERROR) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL); + } else if (stmt == TSDBConstants.JNI_CONNECTION_NULL) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); - } - - if (stmt == TSDBConstants.JNI_SQL_NULL) { + } else if (stmt == TSDBConstants.JNI_SQL_NULL) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL); - } - - if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) { + } else if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY); } From 86b00102d8de99885a98960f058ea4ac5371ea42 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 1 Jun 2021 10:46:03 +0800 Subject: [PATCH 67/80] [td-255] fix bug found by regression test. --- src/query/src/qExecutor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6257750d61..ba3070e437 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -4890,7 +4890,9 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) { updateOutputBuf(&pArithInfo->binfo, &pArithInfo->bufCapacity, pBlock->info.rows); arithmeticApplyFunctions(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); - updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); + if (pTableQueryInfo != NULL) { + updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); + } pRes->info.rows = getNumOfResult(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { @@ -4931,7 +4933,9 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) { updateOutputBuf(&pArithInfo->binfo, &pArithInfo->bufCapacity, pBlock->info.rows); arithmeticApplyFunctions(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); - updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); + if (pTableQueryInfo != NULL) { + updateTableIdInfo(pTableQueryInfo, pBlock, pRuntimeEnv->pTableRetrieveTsMap, order); + } pRes->info.rows = getNumOfResult(pRuntimeEnv, pInfo->pCtx, pOperator->numOfOutput); if (pRes->info.rows >= 1000/*pRuntimeEnv->resultInfo.threshold*/) { From 764087a06497edd5df72e1857eb03ccc7bf91af2 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Tue, 1 Jun 2021 11:39:28 +0800 Subject: [PATCH 68/80] support bind multiple tables --- src/client/src/tscPrepare.c | 1 - tests/script/api/stmtBatchTest.c | 917 ++++++++++++++++++++++++++++++- 2 files changed, 909 insertions(+), 9 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 312a570f2c..e395f09bae 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1561,7 +1561,6 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags } pStmt->mtb.nameSet = true; - pStmt->mtb.tagSet = true; tscDebug("0x%"PRIx64" SQL: %s", pSql->self, pSql->sqlstr); diff --git a/tests/script/api/stmtBatchTest.c b/tests/script/api/stmtBatchTest.c index 8bd296db61..80848febd1 100644 --- a/tests/script/api/stmtBatchTest.c +++ b/tests/script/api/stmtBatchTest.c @@ -1450,6 +1450,47 @@ static void prepareV_long(TAOS *taos, int schemaCase, int tableNum, int lenO } +static void prepareVcolumn_autoCreateTbl(TAOS *taos, int schemaCase, int tableNum, int lenOfBinaryDef, char* dbName) { + TAOS_RES *result; + int code; + char sqlstr[1024] = {0}; + sprintf(sqlstr, "drop database if exists %s;", dbName); + result = taos_query(taos, sqlstr); + taos_free_result(result); + + sprintf(sqlstr, "create database %s;", dbName); + result = taos_query(taos, sqlstr); + code = taos_errno(result); + if (code != 0) { + printf("failed to create database, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + sprintf(sqlstr, "use %s;", dbName); + result = taos_query(taos, sqlstr); + taos_free_result(result); + + // create table + char buf[1024] = {0}; + //if (bigsize) { + sprintf(buf, "create stable stb1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp)" + " tags(id1 int, id2 bool, id3 tinyint, id4 smallint, id5 bigint, id6 float, id7 double, id8 binary(%d), id9 nchar(%d))", lenOfBinaryDef, lenOfBinaryDef, lenOfBinaryDef, lenOfBinaryDef) ; + //} else { + // sprintf(buf, "create stable stb1 (ts timestamp, b int) tags(id1 int, id2 bool, id3 tinyint, id4 smallint, id5 bigint, id6 float, id7 double, id8 binary(40), id9 nchar(40))") ; + //} + + result = taos_query(taos, buf); + code = taos_errno(result); + if (code != 0) { + printf("failed to create table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); +} + static void prepareVcolumn(TAOS *taos, int schemaCase, int tableNum, int lenOfBinaryDef, char* dbName) { TAOS_RES *result; @@ -3159,12 +3200,872 @@ static void SpecifyColumnBatchCase(TAOS *taos) { } + +/*=======================*/ +/* +test scene: insert into tb1 (ts,f1) values (?,?) +*/ +static int stmt_specifyCol_bind_case_001_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { + sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + + int totalRowsPerTbl = rowsOfPerColum * bingNum; + + v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + + int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + int one_not_null = 0; + + int64_t tts = 1591060628000; + + for (int i = 0; i < rowsOfPerColum; ++i) { + lb[i] = lenOfBinaryAct; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v->b[i] = (int8_t)(i % 2); + v->v1[i] = (int8_t)((i+1) % 2); + v->v2[i] = (int16_t)i; + v->v4[i] = (int32_t)(i+1); + v->v8[i] = (int64_t)(i+2); + v->f4[i] = (float)(i+3); + v->f8[i] = (double)(i+4); + char tbuf[MAX_BINARY_DEF_LEN]; + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "binary-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->br + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "nchar-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->nr + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + v->ts2[i] = tts + i; + } + + int i = 0; + for (int j = 0; j < bingNum * tableNum; j++) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v->ts[j*rowsOfPerColum]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = rowsOfPerColum; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v->b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = rowsOfPerColum; + + params[i+2].buffer_type = TSDB_DATA_TYPE_INT; + params[i+2].buffer_length = sizeof(int32_t); + params[i+2].buffer = v->v4; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = rowsOfPerColum; + + params[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+3].buffer_length = sizeof(float); + params[i+3].buffer = v->f4; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = rowsOfPerColum; + + params[i+4].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+4].buffer_length = (uintptr_t)lenOfBinaryDef; + params[i+4].buffer = v->br; + params[i+4].length = lb; + params[i+4].is_null = is_null; + params[i+4].num = rowsOfPerColum; + + i+=columnNum; + } + + //int64_t tts = 1591060628000; + for (int i = 0; i < totalRowsPerTbl * tableNum; ++i) { + v->ts[i] = tts + i; + } + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v->v4; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v->b; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v->v1; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v->v2; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v->v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v->f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v->f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v->br; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v->nr; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + +// create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp) + //char *sql = "insert into ? (ts,b,v4,f4,br) using stb1 tags (?,?,?,?,?,?,?,?,?) values(?,?,?,?,?)"; + char *sql = "insert into ? using stb1 tags (?,?,?,?,?,?,?,?,?) (ts,b,v4,f4,br) values(?,?,?,?,?)"; + + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + int id = 0; + for (int l = 0; l < bingNum; l++) { + for (int zz = 0; zz < tableNum; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + for (int col=0; col < columnNum; ++col) { + code = taos_stmt_bind_single_param_batch(stmt, params + id, col); + if (code != 0){ + printf("failed to execute taos_stmt_bind_single_param_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + id++; + } + + code = taos_stmt_add_batch(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_add_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_execute. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + unsigned long long endtime = getCurrentTime(); + unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); + printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); + + free(v->ts); + free(v->br); + free(v->nr); + free(v); + free(lb); + free(params); + free(tags); + free(is_null); + free(no_null); + + return 0; +} + +static int stmt_specifyCol_bind_case_002_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { + sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + + int totalRowsPerTbl = rowsOfPerColum * bingNum; + + v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + + int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + int one_not_null = 0; + + int64_t tts = 1591060628000; + + for (int i = 0; i < rowsOfPerColum; ++i) { + lb[i] = lenOfBinaryAct; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v->b[i] = (int8_t)(i % 2); + v->v1[i] = (int8_t)((i+1) % 2); + v->v2[i] = (int16_t)i; + v->v4[i] = (int32_t)(i+1); + v->v8[i] = (int64_t)(i+2); + v->f4[i] = (float)(i+3); + v->f8[i] = (double)(i+4); + char tbuf[MAX_BINARY_DEF_LEN]; + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "binary-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->br + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "nchar-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->nr + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + v->ts2[i] = tts + i; + } + + int i = 0; + for (int j = 0; j < bingNum * tableNum; j++) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v->ts[j*rowsOfPerColum]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = rowsOfPerColum; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v->b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = rowsOfPerColum; + + params[i+2].buffer_type = TSDB_DATA_TYPE_INT; + params[i+2].buffer_length = sizeof(int32_t); + params[i+2].buffer = v->v4; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = rowsOfPerColum; + + params[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+3].buffer_length = sizeof(float); + params[i+3].buffer = v->f4; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = rowsOfPerColum; + + params[i+4].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+4].buffer_length = (uintptr_t)lenOfBinaryDef; + params[i+4].buffer = v->br; + params[i+4].length = lb; + params[i+4].is_null = is_null; + params[i+4].num = rowsOfPerColum; + + i+=columnNum; + } + + //int64_t tts = 1591060628000; + for (int i = 0; i < totalRowsPerTbl * tableNum; ++i) { + v->ts[i] = tts + i; + } + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v->v4; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v->b; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v->v1; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v->v2; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v->v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v->f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v->f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v->br; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v->nr; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + +// create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp) + //char *sql = "insert into ? (ts,b,v4,f4,br) using stb1 tags (?,?,?,?,?,?,?,?,?) values(?,?,?,?,?)"; + char *sql = "insert into ? using stb1 tags (?,?,?,?,?,?,?,?,?) (ts,b,v4,f4,br) values(?,?,?,?,?)"; + + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + int id = 0; + for (int l = 0; l < bingNum; l++) { + for (int zz = 0; zz < tableNum; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + for (int col=0; col < columnNum; ++col) { + code = taos_stmt_bind_single_param_batch(stmt, params + id, col); + if (code != 0){ + printf("failed to execute taos_stmt_bind_single_param_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + id++; + } + + code = taos_stmt_add_batch(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_add_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_execute. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + unsigned long long endtime = getCurrentTime(); + unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); + printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); + + free(v->ts); + free(v->br); + free(v->nr); + free(v); + free(lb); + free(params); + free(tags); + free(is_null); + free(no_null); + + return 0; +} + +static int stmt_specifyCol_bind_case_003_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { + sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + + int totalRowsPerTbl = rowsOfPerColum * bingNum; + + v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + + int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + int one_not_null = 0; + + int64_t tts = 1591060628000; + + for (int i = 0; i < rowsOfPerColum; ++i) { + lb[i] = lenOfBinaryAct; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v->b[i] = (int8_t)(i % 2); + v->v1[i] = (int8_t)((i+1) % 2); + v->v2[i] = (int16_t)i; + v->v4[i] = (int32_t)(i+1); + v->v8[i] = (int64_t)(i+2); + v->f4[i] = (float)(i+3); + v->f8[i] = (double)(i+4); + char tbuf[MAX_BINARY_DEF_LEN]; + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "binary-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->br + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "nchar-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->nr + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + v->ts2[i] = tts + i; + } + + int i = 0; + for (int j = 0; j < bingNum * tableNum; j++) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v->ts[j*rowsOfPerColum]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = rowsOfPerColum; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v->b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = rowsOfPerColum; + + params[i+2].buffer_type = TSDB_DATA_TYPE_INT; + params[i+2].buffer_length = sizeof(int32_t); + params[i+2].buffer = v->v4; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = rowsOfPerColum; + + params[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+3].buffer_length = sizeof(float); + params[i+3].buffer = v->f4; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = rowsOfPerColum; + + params[i+4].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+4].buffer_length = (uintptr_t)lenOfBinaryDef; + params[i+4].buffer = v->br; + params[i+4].length = lb; + params[i+4].is_null = is_null; + params[i+4].num = rowsOfPerColum; + + i+=columnNum; + } + + //int64_t tts = 1591060628000; + for (int i = 0; i < totalRowsPerTbl * tableNum; ++i) { + v->ts[i] = tts + i; + } + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v->v4; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v->b; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v->v1; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v->v2; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v->v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v->f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v->f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v->br; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v->nr; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + +// create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp) + //char *sql = "insert into ? (ts,b,v4,f4,br) using stb1 tags (?,?,?,?,?,?,?,?,?) values(?,?,?,?,?)"; + char *sql = "insert into ? using stb1 tags (33,?,99,?,?,?,?,?,?) (ts,b,v4,f4,br) values(?,?,?,?,?)"; + + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + int id = 0; + for (int l = 0; l < bingNum; l++) { + for (int zz = 0; zz < tableNum; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + for (int col=0; col < columnNum; ++col) { + code = taos_stmt_bind_single_param_batch(stmt, params + id, col); + if (code != 0){ + printf("failed to execute taos_stmt_bind_single_param_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + id++; + } + + code = taos_stmt_add_batch(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_add_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_execute. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + unsigned long long endtime = getCurrentTime(); + unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); + printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); + + free(v->ts); + free(v->br); + free(v->nr); + free(v); + free(lb); + free(params); + free(tags); + free(is_null); + free(no_null); + + return 0; +} + +static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { + TAOS_STMT *stmt = NULL; + + int tableNum; + int lenOfBinaryDef; + int rowsOfPerColum; + int bingNum; + int lenOfBinaryAct; + int columnNum; + + int totalRowsPerTbl; + +//=======================================================================// +//=============================== single table ==========================// +//========== case 1: ======================// +#if 0 +{ + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 1; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db1"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 1 check result end\n\n"); +} +#endif + + //========== case 2: ======================// +#if 0 +{ + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 5; + bingNum = 1; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 15; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db2"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 2 check result end\n\n"); +} +#endif + + //========== case 2-1: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 32767; + bingNum = 1; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 15; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db2_1"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 2-1 check result end\n\n"); + } +#endif + //========== case 2-2: ======================// +#if 0 + { + printf("====case 2-2 error test start\n"); + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 32768; + bingNum = 1; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 15; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db2_2"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("====case 2-2 check result end\n\n"); + } +#endif + + + //========== case 3: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 1; + bingNum = 5; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 20; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db3"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 3 check result end\n\n"); + } +#endif + + //========== case 4: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 5; + bingNum = 5; + lenOfBinaryDef = 1000; + lenOfBinaryAct = 33; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db4"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + //checkResult(taos, "m1", 0, totalRowsPerTbl); + //checkResult(taos, "m2", 0, totalRowsPerTbl); + //checkResult(taos, "m3", 0, totalRowsPerTbl); + //checkResult(taos, "m4", 0, totalRowsPerTbl); + //checkResult(taos, "m5", 0, totalRowsPerTbl); + //checkResult(taos, "m6", 0, totalRowsPerTbl); + //checkResult(taos, "m7", 0, totalRowsPerTbl); + //checkResult(taos, "m8", 0, totalRowsPerTbl); + //checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 4 check result end\n\n"); + } +#endif + + //=======================================================================// + //=============================== multi-rows to single table ==========================// + //========== case 5: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 23740; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db5"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 5 check result end\n\n"); + } +#endif + +// ============== error test: 1.multi table, 2.specify some tags + //========== case 6: ======================// +#if 1 + { + stmt = taos_stmt_init(taos); + + tableNum = 2; + rowsOfPerColum = 5; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db6"); + stmt_specifyCol_bind_case_002_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 6 check result end\n\n"); + } +#endif + + //========== case 7: ======================// +#if 0 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 23740; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 1; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db6"); + stmt_specifyCol_bind_case_003_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 7 check result end\n\n"); + } +#endif + + return ; + +} + + int main(int argc, char *argv[]) { TAOS *taos; char host[32] = "127.0.0.1"; char* serverIp = NULL; - int threadNum = 1; + //int threadNum = 1; // connect to server if (argc == 1) { @@ -3173,10 +4074,10 @@ int main(int argc, char *argv[]) serverIp = argv[1]; } else if (argc == 3) { serverIp = argv[1]; - threadNum = atoi(argv[2]); + //threadNum = atoi(argv[2]); } else if (argc == 4) { serverIp = argv[1]; - threadNum = atoi(argv[2]); + //threadNum = atoi(argv[2]); g_runTimes = atoi(argv[3]); } @@ -3219,12 +4120,12 @@ int main(int argc, char *argv[]) if (taos == NULL) { printf("failed to connect to TDengine, reason:%s\n", taos_errstr(taos)); return -1; - } + } - runCase(taos); - runCase_long(taos); - SpecifyColumnBatchCase(taos); - + //runCase(taos); + //runCase_long(taos); + //SpecifyColumnBatchCase(taos); + SpecifyColumnBatchCase_autoCreateTbl(taos); return 0; } From 09c4c28169497ddded85c1a691efe3f3a9b8701a Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 1 Jun 2021 13:34:03 +0800 Subject: [PATCH 69/80] Feature/sangshuduo/td 3973 use jemalloc (#6319) * [TD-3973]: add jemalloc as submodule. * add macro definitions in cmake. * [TD-3973]: use jemalloc. build works as following instructions: cmake .. -DJEMALLOC_ENABLED=true make * fix jemalloc at tag 5.2.1 * link jemalloc works. * make install works. * support jemalloc in release.sh. Co-authored-by: Shuduo Sang --- .gitmodules | 3 + cmake/define.inc | 5 ++ cmake/input.inc | 5 ++ deps/CMakeLists.txt | 13 ++++ deps/jemalloc | 1 + packaging/release.sh | 42 +++++++----- packaging/tools/make_install.sh | 113 ++++++++++++++++++++++---------- src/dnode/CMakeLists.txt | 9 ++- src/kit/shell/CMakeLists.txt | 11 +++- src/kit/taosdemo/CMakeLists.txt | 13 +++- src/os/inc/osMemory.h | 4 ++ 11 files changed, 164 insertions(+), 55 deletions(-) create mode 160000 deps/jemalloc diff --git a/.gitmodules b/.gitmodules index 0e65b02221..346f5c0069 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "tests/examples/rust"] path = tests/examples/rust url = https://github.com/songtianyi/tdengine-rust-bindings.git +[submodule "deps/jemalloc"] + path = deps/jemalloc + url = https://github.com/jemalloc/jemalloc diff --git a/cmake/define.inc b/cmake/define.inc index 57351e5478..cc8bd0fc35 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -59,6 +59,11 @@ IF (TD_LINUX_64) MESSAGE(STATUS "linux64 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ADD_DEFINITIONS(-DUSE_LIBICONV) + + IF (JEMALLOC_ENABLED) + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) + ENDIF () + ENDIF () IF (TD_LINUX_32) diff --git a/cmake/input.inc b/cmake/input.inc index 00e0e1bc0f..543114ad09 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -72,3 +72,8 @@ IF (${RANDOM_NETWORK_FAIL} MATCHES "true") SET(TD_RANDOM_NETWORK_FAIL TRUE) MESSAGE(STATUS "build with random-network-fail enabled") ENDIF () + +IF (${JEMALLOC_ENABLED} MATCHES "true") + SET(TD_JEMALLOC_ENABLED TRUE) + MESSAGE(STATUS "build with jemalloc enabled") +ENDIF () diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index cfc17442f5..99152c6ce3 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -18,3 +18,16 @@ ENDIF () IF (TD_DARWIN AND TD_MQTT) ADD_SUBDIRECTORY(MQTT-C) ENDIF () + +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + MESSAGE("setup dpes/jemalloc, current source dir:" ${CMAKE_CURRENT_SOURCE_DIR}) + MESSAGE("binary dir:" ${CMAKE_BINARY_DIR}) + include(ExternalProject) + ExternalProject_Add(jemalloc + PREFIX "jemalloc" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ + BUILD_COMMAND ${MAKE} + ) +ENDIF () diff --git a/deps/jemalloc b/deps/jemalloc new file mode 160000 index 0000000000..ea6b3e973b --- /dev/null +++ b/deps/jemalloc @@ -0,0 +1 @@ +Subproject commit ea6b3e973b477b8061e0076bb257dbd7f3faa756 diff --git a/packaging/release.sh b/packaging/release.sh index 1e54bc2872..1d81f818a9 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -6,7 +6,7 @@ set -e #set -x # release.sh -v [cluster | edge] -# -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] +# -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] # -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...] # -V [stable | beta] # -l [full | lite] @@ -22,11 +22,12 @@ cpuType=x64 # [aarch32 | aarch64 | x64 | x86 | mips64 ...] osType=Linux # [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...] pagMode=full # [full | lite] soMode=dynamic # [static | dynamic] +allocator=glibc # [glibc | jemalloc] dbName=taos # [taos | power] verNumber="" verNumberComp="2.0.0.0" -while getopts "hv:V:c:o:l:s:d:n:m:" arg +while getopts "hv:V:c:o:l:s:d:a:n:m:" arg do case $arg in v) @@ -53,6 +54,10 @@ do #echo "dbName=$OPTARG" dbName=$(echo $OPTARG) ;; + a) + #echo "allocator=$OPTARG" + allocator=$(echo $OPTARG) + ;; n) #echo "verNumber=$OPTARG" verNumber=$(echo $OPTARG) @@ -71,20 +76,21 @@ do echo " -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...] " echo " -V [stable | beta] " echo " -l [full | lite] " + echo " -a [glibc | jemalloc] " echo " -s [static | dynamic] " echo " -d [taos | power] " echo " -n [version number] " echo " -m [compatible version number] " exit 0 ;; - ?) #unknow option + ?) #unknow option echo "unkonw argument" exit 1 ;; esac done -echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} soMode=${soMode} dbName=${dbName} verNumber=${verNumber} verNumberComp=${verNumberComp}" +echo "verMode=${verMode} verType=${verType} cpuType=${cpuType} osType=${osType} pagMode=${pagMode} soMode=${soMode} dbName=${dbName} allocator=${allocator} verNumber=${verNumber} verNumberComp=${verNumberComp}" curr_dir=$(pwd) @@ -118,7 +124,7 @@ function vercomp () { echo 0 exit 0 fi - + local IFS=. local i ver1=($1) ver2=($2) @@ -164,7 +170,7 @@ if [[ "$verMode" == "cluster" ]]; then else gitinfoOfInternal=NULL fi - + cd ${curr_dir} # 2. cmake executable file @@ -180,12 +186,18 @@ else fi cd ${compile_dir} +if [[ "$allocator" == "jemalloc" ]]; then + allocator_macro="-DJEMALLOC_ENABLED=true" +else + allocator_macro="" +fi + # check support cpu type if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "mips64" ]] ; then if [ "$verMode" != "cluster" ]; then - cmake ../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DDBNAME=${dbName} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} -DPAGMODE=${pagMode} + cmake ../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DDBNAME=${dbName} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} -DPAGMODE=${pagMode} ${allocator_macro} else - cmake ../../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DDBNAME=${dbName} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} + cmake ../../ -DCPUTYPE=${cpuType} -DOSTYPE=${osType} -DSOMODE=${soMode} -DDBNAME=${dbName} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} ${allocator_macro} fi else echo "input cpuType=${cpuType} error!!!" @@ -199,9 +211,9 @@ cd ${curr_dir} # 3. Call the corresponding script for packaging if [ "$osType" != "Darwin" ]; then if [[ "$verMode" != "cluster" ]] && [[ "$cpuType" == "x64" ]] && [[ "$dbName" == "taos" ]]; then - ret='0' + ret='0' command -v dpkg >/dev/null 2>&1 || { ret='1'; } - if [ "$ret" -eq 0 ]; then + if [ "$ret" -eq 0 ]; then echo "====do deb package for the ubuntu system====" output_dir="${top_dir}/debs" if [ -d ${output_dir} ]; then @@ -214,9 +226,9 @@ if [ "$osType" != "Darwin" ]; then echo "==========dpkg command not exist, so not release deb package!!!" fi - ret='0' + ret='0' command -v rpmbuild >/dev/null 2>&1 || { ret='1'; } - if [ "$ret" -eq 0 ]; then + if [ "$ret" -eq 0 ]; then echo "====do rpm package for the centos system====" output_dir="${top_dir}/rpms" if [ -d ${output_dir} ]; then @@ -229,11 +241,11 @@ if [ "$osType" != "Darwin" ]; then echo "==========rpmbuild command not exist, so not release rpm package!!!" fi fi - + echo "====do tar.gz package for all systems====" cd ${script_dir}/tools - - if [[ "$dbName" == "taos" ]]; then + + if [[ "$dbName" == "taos" ]]; then ${csudo} ./makepkg.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${csudo} ./makeclient.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} ${csudo} ./makearbi.sh ${compile_dir} ${verNumber} "${build_time}" ${cpuType} ${osType} ${verMode} ${verType} ${pagMode} diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index d6ace0a063..240804ed95 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -1,12 +1,12 @@ #!/bin/bash # -# This file is used to install TAOS time-series database on linux systems. The operating system +# This file is used to install TAOS time-series database on linux systems. The operating system # is required to use systemd to manage services at boot set -e # set -x -# -----------------------Variables definition--------------------- +# -----------------------Variables definition source_dir=$1 binary_dir=$2 osType=$3 @@ -71,9 +71,9 @@ if [ "$osType" != "Darwin" ]; then service_mod=0 elif $(which service &> /dev/null); then service_mod=1 - service_config_dir="/etc/init.d" + service_config_dir="/etc/init.d" if $(which chkconfig &> /dev/null); then - initd_mod=1 + initd_mod=1 elif $(which insserv &> /dev/null); then initd_mod=2 elif $(which update-rc.d &> /dev/null); then @@ -123,9 +123,9 @@ function kill_taosd() { function install_main_path() { #create install main dir and all sub dir ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} + ${csudo} mkdir -p ${install_main_dir} ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin + ${csudo} mkdir -p ${install_main_dir}/bin ${csudo} mkdir -p ${install_main_dir}/connector ${csudo} mkdir -p ${install_main_dir}/driver ${csudo} mkdir -p ${install_main_dir}/examples @@ -176,6 +176,49 @@ function install_bin() { [ -x ${install_main_dir}/bin/remove_client.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client.sh ${bin_link_dir}/rmtaos || : fi } +function install_jemalloc() { + if [ "$osType" != "Darwin" ]; then + /usr/bin/install -c -d /usr/local/bin + + if [ -f ${binary_dir}/build/bin/jemalloc-config ]; then + /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin + fi + if [ -f ${binary_dir}/build/bin/jemalloc.sh ]; then + /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin + fi + if [ -f ${binary_dir}/build/bin/jeprof ]; then + /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin + fi + if [ -f ${binary_dir}/build/include/jemalloc/jemalloc.h ]; then + /usr/bin/install -c -d /usr/local/include/jemalloc + /usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + fi + if [ -f ${binary_dir}/build/lib/libjemalloc.so.2 ]; then + /usr/bin/install -c -d /usr/local/lib + /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib + ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + /usr/bin/install -c -d /usr/local/lib + if [ -f ${binary_dir}/build/lib/libjemalloc.a ]; then + /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib + fi + if [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ]; then + /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib + fi + if [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ]; then + /usr/bin/install -c -d /usr/local/lib/pkgconfig + /usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + fi + fi + if [ -f ${binary_dir}/build/share/doc/jemalloc/jemalloc.html ]; then + /usr/bin/install -c -d /usr/local/share/doc/jemalloc + /usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + fi + if [ -f ${binary_dir}/build/share/man/man3/jemalloc.3 ]; then + /usr/bin/install -c -d /usr/local/share/man/man3 + /usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + fi + fi +} function install_lib() { # Remove links @@ -183,12 +226,12 @@ function install_lib() { if [ "$osType" != "Darwin" ]; then ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : fi - + if [ "$osType" != "Darwin" ]; then ${csudo} cp ${binary_dir}/build/lib/libtaos.so.${verNumber} ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 ${csudo} ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so - + if [ -d "${lib64_link_dir}" ]; then ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 ${csudo} ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so @@ -198,7 +241,9 @@ function install_lib() { ${csudo} ln -sf ${install_main_dir}/driver/libtaos.1.dylib ${lib_link_dir}/libtaos.1.dylib ${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib fi - + + install_jemalloc + if [ "$osType" != "Darwin" ]; then ${csudo} ldconfig fi @@ -206,26 +251,26 @@ function install_lib() { function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taoserror.h ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* + ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taoserror.h ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } function install_config() { #${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : - - if [ ! -f ${cfg_install_dir}/taos.cfg ]; then + + if [ ! -f ${cfg_install_dir}/taos.cfg ]; then ${csudo} mkdir -p ${cfg_install_dir} [ -f ${script_dir}/../cfg/taos.cfg ] && ${csudo} cp ${script_dir}/../cfg/taos.cfg ${cfg_install_dir} ${csudo} chmod 644 ${cfg_install_dir}/* - fi - + fi + ${csudo} cp -f ${script_dir}/../cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org - ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg + ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg } -function install_log() { +function install_log() { ${csudo} rm -rf ${log_dir} || : if [ "$osType" != "Darwin" ]; then @@ -239,7 +284,7 @@ function install_log() { function install_data() { ${csudo} mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo} ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { @@ -254,8 +299,8 @@ function install_connector() { echo "WARNING: go connector not found, please check if want to use it!" fi ${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector - - ${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null + + ${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null } function install_examples() { @@ -264,8 +309,8 @@ function install_examples() { function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : - + #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + if pidof taosd &> /dev/null; then ${csudo} service taosd stop || : fi @@ -277,9 +322,9 @@ function clean_service_on_sysvinit() { elif ((${initd_mod}==3)); then ${csudo} update-rc.d -f taosd remove || : fi - + ${csudo} rm -f ${service_config_dir}/taosd || : - + if $(which init &> /dev/null); then ${csudo} init q || : fi @@ -298,10 +343,10 @@ function install_service_on_sysvinit() { ${csudo} cp -f ${script_dir}/../rpm/taosd ${install_main_dir}/init.d ${csudo} cp ${script_dir}/../rpm/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd fi - + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" - + if ((${initd_mod}==1)); then ${csudo} chkconfig --add taosd || : ${csudo} chkconfig --level 2345 taosd on || : @@ -323,7 +368,7 @@ function clean_service_on_systemd() { ${csudo} systemctl disable taosd &> /dev/null || echo &> /dev/null ${csudo} rm -f ${taosd_service_config} -} +} # taos:2345:respawn:/etc/init.d/taosd start @@ -383,7 +428,7 @@ function update_TDengine() { sleep 1 fi fi - + install_main_path install_log @@ -431,16 +476,16 @@ function install_TDengine() { # Start to install if [ "$osType" != "Darwin" ]; then echo -e "${GREEN}Start to install TDEngine...${NC}" - else - echo -e "${GREEN}Start to install TDEngine Client ...${NC}" + else + echo -e "${GREEN}Start to install TDEngine Client ...${NC}" fi - install_main_path + install_main_path - if [ "$osType" != "Darwin" ]; then + if [ "$osType" != "Darwin" ]; then install_data fi - install_log + install_log install_header install_lib install_connector @@ -452,7 +497,7 @@ function install_TDengine() { install_service fi - install_config + install_config if [ "$osType" != "Darwin" ]; then # Ask if to start the service diff --git a/src/dnode/CMakeLists.txt b/src/dnode/CMakeLists.txt index dd18f00920..f8d8f88438 100644 --- a/src/dnode/CMakeLists.txt +++ b/src/dnode/CMakeLists.txt @@ -10,8 +10,15 @@ INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(src SRC) +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) + SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") +ELSE () + SET(LINK_JEMALLOC "") +ENDIF () + ADD_EXECUTABLE(taosd ${SRC}) -TARGET_LINK_LIBRARIES(taosd mnode monitor http tsdb twal vnode cJson lz4 balance sync) +TARGET_LINK_LIBRARIES(taosd mnode monitor http tsdb twal vnode cJson lz4 balance sync ${LINK_JEMALLOC}) IF (TD_SOMODE_STATIC) TARGET_LINK_LIBRARIES(taosd taos_static) diff --git a/src/kit/shell/CMakeLists.txt b/src/kit/shell/CMakeLists.txt index d36c1e3fcc..d904945435 100644 --- a/src/kit/shell/CMakeLists.txt +++ b/src/kit/shell/CMakeLists.txt @@ -11,10 +11,17 @@ IF (TD_LINUX) LIST(REMOVE_ITEM SRC ./src/shellDarwin.c) ADD_EXECUTABLE(shell ${SRC}) +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) + SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") +ELSE () + SET(LINK_JEMALLOC "") +ENDIF () + IF (TD_SOMODE_STATIC) - TARGET_LINK_LIBRARIES(shell taos_static) + TARGET_LINK_LIBRARIES(shell taos_static ${LINK_JEMALLOC}) ELSE () - TARGET_LINK_LIBRARIES(shell taos) + TARGET_LINK_LIBRARIES(shell taos ${LINK_JEMALLOC}) ENDIF () SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) diff --git a/src/kit/taosdemo/CMakeLists.txt b/src/kit/taosdemo/CMakeLists.txt index 5f75be0e19..091eecfe27 100644 --- a/src/kit/taosdemo/CMakeLists.txt +++ b/src/kit/taosdemo/CMakeLists.txt @@ -55,14 +55,21 @@ ENDIF () MESSAGE("TD_VERSION_NUMBER is:" ${TD_VERSION_NUMBER}) ADD_DEFINITIONS(-DTD_VERNUMBER="${TD_VERSION_NUMBER}") +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) + SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") +ELSE () + SET(LINK_JEMALLOC "") +ENDIF () + IF (TD_LINUX) AUX_SOURCE_DIRECTORY(. SRC) ADD_EXECUTABLE(taosdemo ${SRC}) IF (TD_SOMODE_STATIC) - TARGET_LINK_LIBRARIES(taosdemo taos_static cJson) + TARGET_LINK_LIBRARIES(taosdemo taos_static cJson ${LINK_JEMALLOC}) ELSE () - TARGET_LINK_LIBRARIES(taosdemo taos cJson) + TARGET_LINK_LIBRARIES(taosdemo taos cJson ${LINK_JEMALLOC}) ENDIF () ELSEIF (TD_WINDOWS) AUX_SOURCE_DIRECTORY(. SRC) @@ -71,7 +78,7 @@ ELSEIF (TD_WINDOWS) IF (TD_SOMODE_STATIC) TARGET_LINK_LIBRARIES(taosdemo taos_static cJson) ELSE () - TARGET_LINK_LIBRARIES(taosdemo taos cJson}) + TARGET_LINK_LIBRARIES(taosdemo taos cJson) ENDIF () ELSEIF (TD_DARWIN) # missing a few dependencies, such as diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h index 27efd9f505..793992c197 100644 --- a/src/os/inc/osMemory.h +++ b/src/os/inc/osMemory.h @@ -22,6 +22,10 @@ extern "C" { #endif +#ifdef TD_JEMALLOC_ENABLED +#include +#endif + typedef enum { TAOS_ALLOC_MODE_DEFAULT = 0, TAOS_ALLOC_MODE_RANDOM_FAIL = 1, From 68aeccbe7f3231319a6af06312c5d1a57221fc14 Mon Sep 17 00:00:00 2001 From: robotspace Date: Tue, 1 Jun 2021 13:35:19 +0800 Subject: [PATCH 70/80] Add support for async insert and connection pool. (#6244) * Add support for async query. Only insert result is parsed. * Add support for connection pool. * Add one case for lua connector in smoke test case list. * Build dymanic library for lua connector before smoke test. --- tests/examples/lua/OpenResty/conf/nginx.conf | 4 +- tests/examples/lua/OpenResty/rest/config.lua | 10 +++ .../lua/OpenResty/rest/tdpool/init.lua | 72 +++++++++++++++++ tests/examples/lua/OpenResty/rest/test.lua | 53 +++++++------ .../lua/OpenResty/so/luaconnector51.so | Bin 22472 -> 26696 bytes tests/examples/lua/lua51/lua_connector51.c | 60 +++++++++++++- tests/examples/lua/lua_connector.c | 59 ++++++++++++++ tests/examples/lua/test.lua | 23 +++++- tests/pytest/connector/lua.py | 73 ++++++++++++++++++ tests/pytest/smoketest.sh | 2 + 10 files changed, 328 insertions(+), 28 deletions(-) create mode 100644 tests/examples/lua/OpenResty/rest/config.lua create mode 100644 tests/examples/lua/OpenResty/rest/tdpool/init.lua create mode 100644 tests/pytest/connector/lua.py diff --git a/tests/examples/lua/OpenResty/conf/nginx.conf b/tests/examples/lua/OpenResty/conf/nginx.conf index 2f838c21fc..960cac606a 100644 --- a/tests/examples/lua/OpenResty/conf/nginx.conf +++ b/tests/examples/lua/OpenResty/conf/nginx.conf @@ -6,9 +6,9 @@ events { } http { - lua_package_path '$prefix/lua/?.lua;$prefix/rest/?.lua;/blah/?.lua;;'; + lua_package_path '$prefix/lua/?.lua;$prefix/rest/?.lua;$prefix/rest/?/init.lua;;'; lua_package_cpath "$prefix/so/?.so;;"; - lua_code_cache off; + lua_code_cache on; server { listen 7000; server_name restapi; diff --git a/tests/examples/lua/OpenResty/rest/config.lua b/tests/examples/lua/OpenResty/rest/config.lua new file mode 100644 index 0000000000..72a4fd8ec6 --- /dev/null +++ b/tests/examples/lua/OpenResty/rest/config.lua @@ -0,0 +1,10 @@ +local config = { + host = "127.0.0.1", + port = 6030, + database = "", + user = "root", + password = "taosdata", + max_packet_size = 1024 * 1024 , + connection_pool_size = 64 +} +return config diff --git a/tests/examples/lua/OpenResty/rest/tdpool/init.lua b/tests/examples/lua/OpenResty/rest/tdpool/init.lua new file mode 100644 index 0000000000..ebf8e91756 --- /dev/null +++ b/tests/examples/lua/OpenResty/rest/tdpool/init.lua @@ -0,0 +1,72 @@ +local _M = {} +local driver = require "luaconnector51" +local water_mark = 0 +local occupied = 0 +local connection_pool = {} + +function _M.new(o,config) + o = o or {} + o.connection_pool = connection_pool + o.water_mark = water_mark + o.occupied = occupied + if #connection_pool == 0 then + + for i = 1, config.connection_pool_size do + local res = driver.connect(config) + if res.code ~= 0 then + ngx.log(ngx.ERR, "connect--- failed:"..res.error) + return nil + else + local object = {obj = res.conn, state = 0} + table.insert(o.connection_pool,i, object) + ngx.log(ngx.INFO, "add connection, now pool size:"..#(o.connection_pool)) + end + end + + end + + return setmetatable(o, { __index = _M }) +end + +function _M:get_connection() + + local connection_obj + + for i = 1, #connection_pool do + connection_obj = connection_pool[i] + if connection_obj.state == 0 then + connection_obj.state = 1 + occupied = occupied +1 + if occupied > water_mark then + water_mark = occupied + end + return connection_obj["obj"] + end + end + + ngx.log(ngx.ERR,"ALERT! NO FREE CONNECTION.") + + return nil +end + +function _M:get_water_mark() + + return water_mark +end + +function _M:release_connection(conn) + + local connection_obj + + for i = 1, #connection_pool do + connection_obj = connection_pool[i] + + if connection_obj["obj"] == conn then + connection_obj["state"] = 0 + occupied = occupied -1 + return + end + end +end + +return _M diff --git a/tests/examples/lua/OpenResty/rest/test.lua b/tests/examples/lua/OpenResty/rest/test.lua index 179950cbe7..48aeef3fb4 100644 --- a/tests/examples/lua/OpenResty/rest/test.lua +++ b/tests/examples/lua/OpenResty/rest/test.lua @@ -1,26 +1,11 @@ local driver = require "luaconnector51" local cjson = require "cjson" +local Pool = require "tdpool" +local config = require "config" ngx.say("start time:"..os.time()) - -local config = { - host = "127.0.0.1", - port = 6030, - database = "", - user = "root", - password = "taosdata", - max_packet_size = 1024 * 1024 -} - -local conn -local res = driver.connect(config) -if res.code ~=0 then - ngx.say("connect--- failed: "..res.error) - return -else - conn = res.conn - ngx.say("connect--- pass.") -end +local pool = Pool.new(Pool,config) +local conn = pool:get_connection() local res = driver.query(conn,"drop database if exists nginx") if res.code ~=0 then @@ -51,7 +36,7 @@ else ngx.say("create table--- pass.") end -res = driver.query(conn,"insert into m1 values ('2019-09-01 00:00:00.001',0,'robotspace'), ('2019-09-01 00:00:00.002',1,'Hilink'),('2019-09-01 00:00:00.003',2,'Harmony')") +res = driver.query(conn,"insert into m1 values ('2019-09-01 00:00:00.001', 0, 'robotspace'), ('2019-09-01 00:00:00.002',1,'Hilink'),('2019-09-01 00:00:00.003',2,'Harmony')") if res.code ~=0 then ngx.say("insert records failed: "..res.error) return @@ -77,7 +62,29 @@ else end end -driver.close(conn) -ngx.say("end time:"..os.time()) ---ngx.log(ngx.ERR,"in test file.") +local flag = false +function query_callback(res) + if res.code ~=0 then + ngx.say("async_query_callback--- failed:"..res.error) + else + if(res.affected == 3) then + ngx.say("async_query_callback, insert records--- pass") + else + ngx.say("async_query_callback, insert records---failed: expect 3 affected records, actually affected "..res.affected) + end + end + flag = true +end + +driver.query_a(conn,"insert into m1 values ('2019-09-01 00:00:00.001', 3, 'robotspace'),('2019-09-01 00:00:00.006', 4, 'Hilink'),('2019-09-01 00:00:00.007', 6, 'Harmony')", query_callback) + +while not flag do +-- ngx.say("i am here once...") + ngx.sleep(0.001) -- time unit is second +end + +ngx.say("pool water_mark:"..pool:get_water_mark()) + +pool:release_connection(conn) +ngx.say("end time:"..os.time()) diff --git a/tests/examples/lua/OpenResty/so/luaconnector51.so b/tests/examples/lua/OpenResty/so/luaconnector51.so index 442de6e39f909e1aeb869988722b84795c048855..d8e4f00fec321ce5f48d4241176a59ee8df5d50c 100755 GIT binary patch literal 26696 zcmeHQYjhmNl`cuPacr=}!(a@=gL%XTqqPAMCx#$l%Zw8X6vt)>j~$Jqk)=hN5i=uf z6CO$ogh41#AP>my+2hRy4$Db44#_$S*|^IlDimbb4;zukO8d>vnZ@cg^(G?Tu?!S5{OgDOKu2irnZzgVfuKXx#3A z)T`y{J@`CTouXx@6|1J~b=DY2sIolUn9iyQKTsn2)1xn*V0fXfo^G$+%KPYrRR$O8 z>din^bCaoWzP^;svz>@YXRM!<5To9N)tj(-LPyyV6rnQ>t7wMXavBJrXBt=ur7TPH z%h`7B_cmyD3cb$2N~q|46ngaYFDDc181Boj*r1-tox1GO z!p*ll_uzY%@BF*lZi;_w)jRZs^|jcjNB@TIR%)h-Xbi0SD{Mc!zu~*je6z0Z&ATTD zi3OE!0z59D;)lSbFK+eq@HJWck zfW06;Zv!4=e_DwBCqm>`gvcKZY4;%f3~KkC5PU`m{#J-T_lDpwqaxV+J{@fSR z?$<-`njXkMkER&6=v$2?pty$j`Yfq#T8@n>uM0$PG%I;J$u|D3~oiKI5 zHLs; zt}B!5>uF7-ZI#1h64`93S7qa=Osp%}mDLh$=|nu6$ZGd!8O?Y?ZK-53(UvtDiF6vR zs9rRi?a->deVI-$iH)`~*e`m>O2;d*-CY|yvwfLFx;>taTlacXw2(GU+}M{$Z}D17 zrp&Ik8EZ@RC9NkNiELXZVufI2j7Yqr1AZpjW9ihUjOUxvbvB>u>ef{ZgYK>lgfRv^ z+gLi0h@}&mzV57wXSO8UV%n)#TfDowHQsiEwvdi*LYTVrJ}bDh7Fr#u2VAPnm@O@##ypAwXTNRH@CRYEjkI+Qz+$)a7f}T(&ZHe(m|Sb!Lbw4EfL!UKds)cm=Nc z=5GX$oXdUlyWXSF;~(P7i%A)EaNDG=+UMXWi7@DxgTK$g#~u6}2cOqsn4>@{96aLS zGLl%m$ib@!*s`?6?9h(f3lmx1!cV1$>*oy3DOKNMc8D_;Qlc$pk2p6e%`Ik+7zVCa zu5K~A#AkV^QY{WX+rc{>{AdU7b?{>xe6xekaqxZzuXgae9bC>eRu4J&u>@>+pvCOa zfA_v(n}Z*3MD*t)4sIXKG``)z=W4`!3_JLV4nE@G^BjDygP-i+qYggb!S^}%DGom7 z;HNtHxPzbO;1dr1UI(9a@C6R8;)Y?|A`U*&!B2Pa8V6tK;PV{(3pd5j61j-R8N8tY=0*9*K`*w8eYcrz*(|>TOQqem{vXzC= z=+9{Enz<;MyrXZ@0V1^H3U|CBtJ?(!p=f0ld|`R$s2 ziaeL<^4m23IC(D7<%cx?7+MTU#j^}k>?UzKBD=X$#dx~U!(anc`mu-mFEAJJeS(?6Gs4?)k>aAZ22+G zUqhZtYxz;luOrVTwfu7(;C=u&m*;B}wB^;jdYBT8lhzD=#Zxr%8NZn(gcN4xQP{H(1^9aP zl962FudR_0j4#iZHGU&k0|@rzZ;US!*373|GnIZb$A+3Y$(R|pX6jutPjFDU-al)) z6cCxwcXVXNv^ZnNK&}8dOlG`-)jT5PcJhPuPgs=u2j4Cfa*aP4X#92ccM#tu^lJmG z_0h4(hTJ4&t~HHdioJDIRp0pyni*&uWmUiK#%_$8&*1zujou>W_w1HK`_F&|ntnuA zFbwX7Xzs^U|D+Msrs}k*r?gD&1=ijVq^R}Rp4LZf173$-Eir$gC%6!J{vPA*uqS|hm13CAQaNCN7zKpb!JA1GtYWjJGIt^QO9q_tLXPbp6LA$9p-8AgQxAO(}Gjy z5okW*jl}0@F4xH6^~mE8RXcfIVl-amW`<^BTf=Nk9pC{l1DY9g64 zy88g_qtq|ZO0Mzwt+zg}s_z(}8C$VkH_zjF2=lc$o?jF5#pC%4Km$!^1&t2Q9fqh0 z;Wv#an%y&=(54tdIHr&1(?E(^pZ2sq0WBSu{6FEMyQlH6?wIu`sa<7wwdcFoLauSI z@Ucnu22%dm1OHo=-pxCsp);=->(8w_O~LR=^qF!&Ki3-rLWO1d+5 zG4^4sJccSs=j7K4wsgHB3%A;$cyYLwEfvoS=Ws*h#uG&;zOy&Uw8|m7l(*W z4R{B|j}e!mXlIDbPFxyrLhKp8i}e*lTN@`UU~@&|X!X6HHP?}%Oe}#6II^5=ID=o>z-3%AQ>J22bhNw%+<9wPiCzF}(MTpQPR8#B>dAM29(s$B!4K z;>1)BXrSpeHh^Kh0HVhAc_KPk*9DLk>tL}c`X}7(8qwdQ`2z`Qw{VEg=(*IJUw#FN zqUPhC=C_DLRuAI|JL&yPiSTw$_%7hZIAEA-r&@pxd6x%N?R9o>|1LftjNfjInJdM>1_*F??;F@~IL8CI z0Tue*0NwjZbYSlC^Nqc6*r2_R>VqS+IS%_~2<^pj_!6EiOmK&!-NCvy08;epXt5}I zqbHhxXzA6mS%)LnhZZ&r8}IcP(=9$s%cid$uP=lYK|>gv7!+nS?(^a~X8hh)IvT$W z)Lw?{tbO>;%-V-TX5n#f*2cM^FM>N68C*7kXKl*A>#Y4W9@}Kr{tou-tR3iIaT1Zn zPe;e>tR1Z3&Dx@I@Q=_ivv!~cLaT?n$nT=OnY9Du%^WDwpQE&ywF9M{SsN;Q#+YU*Y7%qq4yG;x~Kgg4~bYj>Fo#2V#K}gHQu#*cN4DPo9 znr9^5*!d=mPgBEA7*G6xZH?{1y^*VGQ6-l*6ORn>HH03njHChlz#r2Y*!0 zwmXd#dBpf0UE&;$s?&6pz9q#Hhne|LHs0ue&T_j*uF0>oBd!{FD`G4j}d{x#U((etiPQ*G4HJ#!N?V`SD3yrFJAA4uo9Kb@TV5>`ny~$Pyik~vFBIyr^9xG~a|iEK)z@M2`@2H5xmo~w3Yy8_P_{n+^A_!71nV0`B4#`bwji~ZmWbP@9c zUWteHoxEgUcX!0Tw^*y%@p5Oa?iAmYG;c7|a7SMu7PM38i1SH&q+E3U&H zf1t4a-wTD!peMgnC~N~=|8k))0(t`aI|iD;V+~)9`V<~}BB1xOKcLTH<)a1kc&xPa zgD$`-*fvlW{;+_h;^uX#VslN!DMueQa|m_(!X4lAs-*<&RWyIGf_W)`lCzQKgw%=74S`naf7RWi_s@kF69W6BT$Y&IRfPf zlp|1%Ksf^C2uK7Ze}z9^h1C10@z<>^i}(v~6v@djWb65y#PWjW@uiV2^DN~fiY_gNSTQwWE97~|npcvu zVzce2;Qh8C@pIA!hCeK4k@oN#RO7#u#}9@yFLA_Uh31b~Mf|Kx^VP=8|GUqL>w{go zC}Qx{mR@CPhov`JdY7eNwDe(1cUZdH(ibd!#nQJdopHL-u zWa(X&e$mp0E!|=1ZcAUV^c73rvUJ8m+rFh|TY8bDt1Z3C(hf^+vh*%Xzi8>hmhP~0 zx22b_T=~JsB4o;299fRkJIf;HFI~2L*|Mc|kwxpUt`d!B4SrtTVtuaY93B$A*BfihNK?EOz=PPD$B@-9A$uP@p* zO)tYgt1zoc-bGicN>zIEPAOicWWFiIr+M>IDL!4v`CW?7P%ScHITcmNC?oTW10y%$ zOeOPBDUQh_;v#0h3adtuKzz10K3uIT%;s`@N^#8U^)6!etJEAX-=texrK;6vgNulK zjgsqtTU(`$_2&Ol{5U1~no9BGRnRU9G;-@spIf8IuvkTEYuMcv{7Q35VctbO zzx!%7hRAOTk-sBE{!1bFS3~e`0FU^5A^St%L4Gp7Vh}zKJgC2iLU05v(9WC?{3PJV zVVwK(IxY#3zc>VM(srhHI36P36N29qf-`??P<-wW!M6ctzx;VA9|azn>Zamr6+!lQ zhu}X8!Cwl&Cx8bX$I7Z;{J0SOY~VqD)`j37(RQZh^K1>VpA5mbgy46F;12>1^7Ek( z`5nN6j>~9>{BJ_+^EqZ=!0|nLTChJS0}nbb=Z46uwsba=?d#~MZBxZ`rm-wCSu&w% z26<20Q?ZTRsn&RRtUa4bXJYZb&G;s)r?)$ST%5Jcpf>Z3*wXg~y)x0Ue>TScIE2TA8TA6Ti_i&2x@ROkAX zFBqM~pYN7-mKL1^qF~pu1(OW4XwW!lV{5aHI+1Y+t2H2SDNdL zXF64F`<5g$4Mn11U4!2dWV%wx5+;VabfP;>1-sXaY`wMm%&N^MHe+9(y0z()&NN(` zK(=5#!F0AmS2&|#<`$zN`_y6+FreLu_jI+vg%k|qqgJ=pn#rhIOm;n(z>IskPqpzZ z!r9uF#RU1kQ@DQoo}3VqA$2*r{ zHUnc!Wc|~-d58c+k#$zXmFBu7#&PKCMWu;Rj{sP^H9arD~|1+)=K}-GZZ}aKP zdWX>VKhr*+uelZ=<3pay<^O8<{S{v54(M`?SoCH6{OTrvC?aRLA}{z;sGy6YFVD9v zR)0toEsgm2=fHF9iN37I$p1Z&|8F93lXhhs?1Qe`zO37fTxl9wYKZqK`a)my>8lni z+H9!KFk>MS(G&WL#l(ME2kQK&Q4%@B8DC|e^Z+*c@Ap&mmr%$lG8}}yfjZ9LQe<7} z^S1qn2wDM&qsX(`8~Xx+4zDvz)PA49?^iCsCjF85ht<+|qhUYoz+dib(B}?To`Ut4 Nw-`IKd4DO(b{daT^c=ho4Vkck#3EGY-%a9pYOf*`*PpQ zdwO=y?&Z>Iw~bxg~(m|~=DxsJz4=W0Esq)Vm#c&3H+>laIQ z46RkLV9Itk!cNAi<)214?HhD`UU}K2<7cXyE88|5l~B6Yu5S=O_}-0I{py#GPCvJG z`qA44=3eyNO?zLa7|8qzY-A_ndq9YC;RmPiQxA;n{PCmJ&r87N=P6*iE7+tz2FGnM z1uIaYoBk6X`u8F*H~ol*AF9)DR;c%@pzjvXb`QM9qu!(N=N8XBz}@_x>*4=^hyFAV z{r5fUJ%u>k>ZJqghEMR&KkX6ELmoKX2tPJw`6d9jdUt!&`wt%Yau2*6xLf{@dEl2K z4{rJm9&yg`sQ2HY@8;)5k9uG5z!!SN^EV##e#yhnBE;jz<}9yx=%4T5zXlHGIGuoR z!RB@xZ}5o!b`SlxWIU5ZX11ziqMpCw($6F@RaaiE#6pC_o7 z+!9SiH^Uc5{-56<#N0rQ75^mlS3Ae@)k$CK`sEBt)YQxQK(dOGSTRS8h z-W<)e#-i~Sl7(aGbS4!`Y?e$W88^6CI?>tQ6isQ7!K9;^OtM2{BFS_(mWXAfMsq3} z$wV_UJo1ccET!gTA`xxQD2r$+g<3=hs?D@Y(~iz`8<^;3T^an3Mo2;^ zbTrix$wYK`9ZB+#QdQjE8BJ}qYD*;5uJjphPIe}AB(2d*a~pDnWTcf!q_q`sMq9$E z|Rp!(P( zQ%e^UTpOnBcP5(A{8$s21k%X>M6sr3+FK^p)~;K%I=m#XB(PNXTy$uU^52)RMTtBw zlUv&R7GNHeowH)+(%E~jR^{s@zP{-=Uj?&8Uq>-ssqroc&ioz+K0{yU>~-K#Tg@F$lxNee^<_!EYLx0%77Z~^j^@^c7F-2O%Z{XYuNI2iX`4X7$N(1L> zO~RKOxV(-h5T(k%sm)wM2F`tjWc3D)4ri5H41A)63ejlblMKAgz$Y7chk>7G;9CrQ zih*|-xX-{JFz^Zk-(}!a4g7HfH_z*P3|x0{X|>nD>AIRrkAcr%5OlwRf5yOj4g3NF z?>F$z8u);L&ob~q1J|ckDIGHK3l068fnQ|c!v?O0kd%%X_$7wExKT0GZ~X>dZs2<8 zN@<0G&oT5bFz`za+;8A>4Sc?V&ol5!1OF2PUvA*@4ZO<0&G8sA@P&qcy@6kD;I|k! zU5ou+m6N`UKMrmGO?jw${Oey3B6NRmrnE2++WvC+OR~zs(suwC<{iVY?~*F)5#L6# z{7?a9-dn`e6q6s2{2Rp6)ROO&{Hw&%l#=g}{9)p0D#`DW{0qd>6q4U1`KO7esUzPd z`6r2|?vU@0{I`jxDJ0)0`M)NfrjC5QzR?rxHIP`3=O=kk9u@{yO4msONhm zzlwMo;`u$2zlL}k+WB3QUqU=h{rN7*FC?CZc)mmObBL#*oo|%iUnQP~V7^E4hl!`5m)|4#7l@}Jm)|A%r-`RiT)s>4PZCc< zFW({gZxc^LF5d_~v~%S*0fcsr-%aG|k<1Kq<!xFKr^S z;B4s7*|Jb}ICLoYg;2?n(CcS2)8XJJ+Ch0?sMUALno)ZiFI_9=!B%u$-VoZp@=0il zQ1*CcGF%6)5hAw$S<1EG=g9a!;AvCIt*G0opX~E@Lf8Ns47~bKcH90?UvPke40Q+h zzd%FbAdRO`wlB95hk($~&KVnU%nrh^K={9E+yagPz}TH7U63zJ^4=LT365wt737B9 zf6eKp4k?A33rN}W5CZt2Z&7bH__lU3fc|7TS?6?e3jp_6zN}&y)^2v2Zc3eQrh2;h zjB=CHZt6`p2dGn+(Z8yi)!7l!`7>1srqpc%!gv2ak(=(|0ExO}GmfC&d<)}M zReCqO?>oZB`tJaB*S$uepc_06)$G5J`Clki>1wHTby(_TkCOCJAfr~BEh}mtsaXwr z&*pxOr8oz8{y`P)sP=_6?MasQDWrniwU?^Mn!!x41@jhWE7gR9(yC#=h@0{?8uzo7 z>Z4HIPyP0lm-NtS#L(Fb%e_`l{3*H12B~}PeF3WCAf1OO8^?bqC3Il4gv2B{K@y;} z|EJi`29Mz=lHzbkWiqR52LTO|)|;p$8~pk9Z9f;j`?|@E7WByK>3EhQY;`=p&+bQ$ z=bM1K>re|S-8rKlQ@KjUQ%V)p_T{3|6{Qe?$>aGFkWs5|SXN(wmCQ^2Z*h|C3!ae; z(-9?PsFYqA`HNITHrUU6a)es)GSy;rhZVNy7FzY3PdId&$r}eX#is1Hl;4G8Qd0+k zQ{4qL|2z)K_TZV44}A-RXOyeH+-X<+dZ2y55i-w5VTM5!dOWmq`akO??hln97`kTh z-B+dM2roMjIy5wnWQT@IRX^+}E^DSUBbzfq&GFFp?W?Nx?d#n>GST-zAH6-WJG$ z?Z9-B{%5`QL){g|VO&evC(tyHcux8%#7W;5d--rl{R7_mA3~pXXOr)TJ$216hM;<4 zvquc}h`)Xss-O2z9h>l0Qa_JF3Zb4|#2mz_0Ry5hw}a#*yS4{MO5k%vaKQJ_!|FUT zs?!7=7|DV3F70PAA8+5bACvkbr7J~~;CytP&cubC8r?tp$T@%2WB%$7WjlLA*@pe_ zjD0zEf$z&rS2fT)WbtxpA{9(rhyycJcYQg9bZ~f3wPQUhA;3QF%7N;ML64&|pE8cl zc#MmjHIC3$IV~+hoZT46?&FB`KXDu_z=bf6ql>Vw$B}D%qlc9%fA|#omKsOy7S=do zi(AP;jU!hJ9!IQy1?j7CLR*a^S8Zb)!35V2q_4)2tG*sbQuk-1tHzO= zE{!7&<8cH{BbAlAOlT8H}SdD}u+Y zaiqH>W+ZgpzTC4P!qhsGSILop5ny%XAmmwje(1N(?jHctL!{q+c0Wf+Xt4Ajq+3m@ zVh%uc)k>#YZ2_4Se)NGHC>U~mxvR0C4Gz7CvzN&IP`Oek`|buP$aHl#oXOUgcjMZC zrrA1(oX!0)OVJNJ|8*66f2;5PUaIGMoAN|U`6S}zHhzz4$eOW?x5e@%Zl_fXex$6B zPh13M>yhgQNBl)9=gfG6E1=RRsnAj}#d3*xvxT zOuy9)$NIR3!c+H7Is2UY40%U&p_s&24U zmqFE@Po!&`Or5>iKT>s%NHnx_>8+Qm$Qyub2LhK0`k9jT6p4Cyu@o~<%s?>%#S9cP zP|QFv1H}v!Gf>PxF$2X6{4q1omP}_vM>3TW^qOB&Bpns>a+~Ogq|(&_`<9e z3$L6z2dLD+-`C=iUl$51=+Rj9l!_gttIwNIwyX@Uq?``&_m33{z2i*zfpILq4{$B= zFW;@T?8jU7-+_D?^1qtmu;ka4vi-||H{k)n8c<7qFG*E=$3VA1KAGBV*`HIw_TzxZ zkeh0VE&1Kbo}gkWW}ujXVg`yCC}yCTfno-V87OAp|7!;LyBX(qGG6iW_c8oE41fQ^ z-@EYlE&M$Tf4{=ttMKwop?pdg?{G+plB=L>9K6?9=%CP=;gufwqK+E}CkY_YMNvR9^ z^PURb;>c33h*lGWTEO>H^g=lm{&r$eJ7Rpku88C8(TU-2RJcC8qblPs*ZO#&Nb;OV z+{#J*JK7Mhok^basG|5I{;qegdzn7oHJaY6X{)ApXu3mFdMSa*6PoVR^oXWMHGNmp z)0$48H|J4iYI>Qb%QUUg^kz+4HN8XA9hyF-=@Xjn)AWd@M>Ty{)6<$x&>!c_)buh< zmuXs~>CKw9YI=vJJ2ZVv(*Be_ z&CdpH&-8z)!?Di(gqS(jh^|vb?)_Va*^Ad%Fty4=sWrdY@iM{liX9(k%|CX0yx?(c z$0rCL|91Qw!Sje6FBd%D*l|n}Iv;j?qVT)oldS$>*Pkr-c-wKzI+Z4(_RGW+Yn=&G zS|)sA&tel{{R(ToH>G7_sx{Bs@o9p;|Fq-yEXHO2DZ^7Q{%+E)kGCo7O+@XNiJ7AD zMmL;ice|_%XN$Jm?HJA1j$0gf+PUC!jXZ$Mclo)aH z`JqPQWAjGOM#(>4FR-7jQh#jz9|!Ih|C8Dek7@Y~5ZE&s=j#ah><<{dsz&wl^@Dt- z2kcdiAM#@dMLx>|eG?n$^Yw>(h6n7|*h;XX0e|n?2%d^po{vkJPxLO4YPKJ@cAbPq zDXvbO{rq>*&)EJ(>r#}6vHi^_55(C1PwO<4h#6!0RY2p;ei#B?idAu(<97{kM;DQ8 zTMyi2NQ+G#`nP%L-{GO3^}zoMxL-zK|Do#}w|HLkz<&bVtzCm2_;C+ECq3{p9{6Nj z(7DBV5pcJ77JKNg^uTL8@S8mFW)Hjr_%w_Q=eiVk0e8!P*2B+Z9{6`X@TWcSUf^!| zdBX#L#{)m@;eR}?uicKzY~Yj!=Qv?YQjm z(0|Iqe=qPkW1A)3_R!CJ`2W3!zGzNm(wWZI)Z;jLT^9@o*RP=^S|~0G zIh_o*MG`HvGRvAx>#OV5tpu@ln4MJ-+0Ky_JY`V7ghE>(I;TvjdZVGM;Z>(Nb z8w{(JJ**{F^b#txx<^%&x$Fit$y|hm|GHGmmKf`Ne9{^+P1G3Wn!$AO2Uo>VC*ZGsMTJ^w!&@k6S)G3wL*<^aTse^n$cBN91G{DhB+5)8C}c9 zTDL_h+E$JkyCjUUT8mnKWlSS5`#DU{= zXr!6Bu#G(8t}6p6RbyEiYCicvB54Jnux;g_F|8b3H%L0Nj}UmWRuU3{^wxI#VGo)~ zDN0qyy+kq-4Qx(y2AVo!@s=xMEkbf_k#w5~v}{elQc)}rBqjJCKOIXZY)lxkR5TtT z1HIRQRdxb$+ypYwE!dX>GmuKk6@mg$tnwo#jJ6ioGN&xmT%jy@pRA|~IFR8)+GEWK zAqmI$3CP--(rFREK&%@wH~H*S?IpmEX%>rBPh1#`%{%^z4f5`97EFm$fp-&w5N7Ag5>|Y4^4Z& zwqv@78>Wr;+Jxyn4*OnxvBq?_&#Z0iwatAFd%iDX>U`eljQ>GxZ-rT@>(jK}(P23M z9Mx`zy>tCadMCy#&ieO2NL6tC{M>=*+)t^W?sMs$ocjkqkLGnPo$)fybRTRf#ca>d ztG8eU2P&+mxKW<*!w^u2Y|qa-y0m>48*1uz@IM7leUI&}=OWiC#R1)Z&KuXu{bvwr zX8rv9WB{vuP?@iY^~?55e+h|cZ{6QkDU(KBKRaMMrtd;P`y4+%k7=w{7Ocni4tL@N z1cY(7V?DNC#DJ!3&-4^state; + lua_rawgeti(L, LUA_REGISTRYINDEX, p->callback); + lua_newtable(L); + int table_index = lua_gettop(L); + if( code < 0){ + printf("failed, reason:%s\n", taos_errstr(result)); + lua_pushinteger(L, -1); + lua_setfield(L, table_index, "code"); + lua_pushstring(L,"something is wrong");// taos_errstr(taos)); + lua_setfield(L, table_index, "error"); + }else{ + //printf("success to async query.\n"); + const int affectRows = taos_affected_rows(result); + //printf(" affect rows:%d\r\n", affectRows); + lua_pushinteger(L, 0); + lua_setfield(L, table_index, "code"); + lua_pushinteger(L, affectRows); + lua_setfield(L, table_index, "affected"); + } + + lua_call(L, 1, 0); +} + +static int l_async_query(lua_State *L){ + int r = luaL_ref(L, LUA_REGISTRYINDEX); + TAOS * taos = (TAOS*)lua_topointer(L,1); + const char * sqlstr = lua_tostring(L,2); + // int stime = luaL_checknumber(L,3); + + lua_newtable(L); + int table_index = lua_gettop(L); + + struct async_query_callback_param *p = malloc(sizeof(struct async_query_callback_param)); + p->state = L; + p->callback=r; + // printf("r:%d, L:%d\n",r,L); + taos_query_a(taos,sqlstr,async_query_callback,p); + + lua_pushnumber(L, 0); + lua_setfield(L, table_index, "code"); + lua_pushstring(L, "ok"); + lua_setfield(L, table_index, "error"); + + return 1; +} + void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){ struct cb_param* p = (struct cb_param*) param; TAOS_FIELD *fields = taos_fetch_fields(result); @@ -308,6 +365,7 @@ static int l_close(lua_State *L){ static const struct luaL_Reg lib[] = { {"connect", l_connect}, {"query", l_query}, + {"query_a",l_async_query}, {"close", l_close}, {"open_stream", l_open_stream}, {"close_stream", l_close_stream}, diff --git a/tests/examples/lua/lua_connector.c b/tests/examples/lua/lua_connector.c index 8078ed2665..8c2ea3e9e8 100644 --- a/tests/examples/lua/lua_connector.c +++ b/tests/examples/lua/lua_connector.c @@ -13,6 +13,11 @@ struct cb_param{ void * stream; }; +struct async_query_callback_param{ + lua_State* state; + int callback; +}; + static int l_connect(lua_State *L){ TAOS * taos=NULL; const char* host; @@ -56,6 +61,7 @@ static int l_connect(lua_State *L){ lua_settop(L,0); taos_init(); + lua_newtable(L); int table_index = lua_gettop(L); @@ -177,6 +183,58 @@ static int l_query(lua_State *L){ return 1; } +void async_query_callback(void *param, TAOS_RES *result, int code){ + struct async_query_callback_param* p = (struct async_query_callback_param*) param; + + //printf("\nin c,numfields:%d\n", numFields); + //printf("\nin c, code:%d\n", code); + + lua_State *L = p->state; + lua_rawgeti(L, LUA_REGISTRYINDEX, p->callback); + lua_newtable(L); + int table_index = lua_gettop(L); + if( code < 0){ + printf("failed, reason:%s\n", taos_errstr(result)); + lua_pushinteger(L, -1); + lua_setfield(L, table_index, "code"); + lua_pushstring(L,"something is wrong");// taos_errstr(taos)); + lua_setfield(L, table_index, "error"); + }else{ + //printf("success to async query.\n"); + const int affectRows = taos_affected_rows(result); + //printf(" affect rows:%d\r\n", affectRows); + lua_pushinteger(L, 0); + lua_setfield(L, table_index, "code"); + lua_pushinteger(L, affectRows); + lua_setfield(L, table_index, "affected"); + } + + lua_call(L, 1, 0); +} + +static int l_async_query(lua_State *L){ + int r = luaL_ref(L, LUA_REGISTRYINDEX); + TAOS * taos = (TAOS*)lua_topointer(L,1); + const char * sqlstr = lua_tostring(L,2); + // int stime = luaL_checknumber(L,3); + + lua_newtable(L); + int table_index = lua_gettop(L); + + struct async_query_callback_param *p = malloc(sizeof(struct async_query_callback_param)); + p->state = L; + p->callback=r; + // printf("r:%d, L:%d\n",r,L); + taos_query_a(taos,sqlstr,async_query_callback,p); + + lua_pushnumber(L, 0); + lua_setfield(L, table_index, "code"); + lua_pushstring(L, "ok"); + lua_setfield(L, table_index, "error"); + + return 1; +} + void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){ struct cb_param* p = (struct cb_param*) param; TAOS_FIELD *fields = taos_fetch_fields(result); @@ -307,6 +365,7 @@ static int l_close(lua_State *L){ static const struct luaL_Reg lib[] = { {"connect", l_connect}, {"query", l_query}, + {"query_a",l_async_query}, {"close", l_close}, {"open_stream", l_open_stream}, {"close_stream", l_close_stream}, diff --git a/tests/examples/lua/test.lua b/tests/examples/lua/test.lua index 9f9c6934aa..89c0904c6a 100644 --- a/tests/examples/lua/test.lua +++ b/tests/examples/lua/test.lua @@ -110,7 +110,25 @@ else end end -function callback(t) +function async_query_callback(res) + if res.code ~=0 then + print("async_query_callback--- failed:"..res.error) + return + else + + if(res.affected == 3) then + print("async_query_callback, insert records--- pass") + else + print("async_query_callback, insert records---failed: expect 3 affected records, actually affected "..res.affected) + end + + end +end + +driver.query_a(conn,"INSERT INTO therm1 VALUES ('2019-09-01 00:00:00.005', 100),('2019-09-01 00:00:00.006', 101),('2019-09-01 00:00:00.007', 102)", async_query_callback) + + +function stream_callback(t) print("------------------------") print("continuous query result:") for key, value in pairs(t) do @@ -119,7 +137,7 @@ function callback(t) end local stream -res = driver.open_stream(conn,"SELECT COUNT(*) as count, AVG(degree) as avg, MAX(degree) as max, MIN(degree) as min FROM thermometer interval(2s) sliding(2s);)",0,callback) +res = driver.open_stream(conn,"SELECT COUNT(*) as count, AVG(degree) as avg, MAX(degree) as max, MIN(degree) as min FROM thermometer interval(2s) sliding(2s);)",0, stream_callback) if res.code ~=0 then print("open stream--- failed:"..res.error) return @@ -146,4 +164,5 @@ while loop_index < 30 do end driver.close_stream(stream) + driver.close(conn) diff --git a/tests/pytest/connector/lua.py b/tests/pytest/connector/lua.py new file mode 100644 index 0000000000..23f0602e12 --- /dev/null +++ b/tests/pytest/connector/lua.py @@ -0,0 +1,73 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def isLuaInstalled(self): + if not which('lua'): + tdLog.exit("Lua not found!") + return False + else: + return True + + def run(self): + tdSql.prepare() +# tdLog.info("Check if Lua installed") +# if not self.isLuaInstalled(): +# sys.exit(1) + + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + + targetPath = buildPath + "/../tests/examples/lua" + tdLog.info(targetPath) + currentPath = os.getcwd() + os.chdir(targetPath) + os.system('./build.sh') + os.system('lua test.lua') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +#tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/smoketest.sh b/tests/pytest/smoketest.sh index 0eb850749f..7f7cb2a89e 100755 --- a/tests/pytest/smoketest.sh +++ b/tests/pytest/smoketest.sh @@ -35,3 +35,5 @@ python3.8 ./test.py $1 -s && sleep 1 python3.8 ./test.py $1 -f client/client.py python3.8 ./test.py $1 -s && sleep 1 +# connector +python3.8 ./test.py $1 -f connector/lua.py From 3d2b864d7c3877976c9f3098040dcc40c7e5de51 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Tue, 1 Jun 2021 14:45:50 +0800 Subject: [PATCH 71/80] fix sqlstr released issue --- src/client/src/tscPrepare.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index e395f09bae..8966f3234a 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -48,6 +48,7 @@ typedef struct SMultiTbStmt { bool nameSet; bool tagSet; uint64_t currentUid; + char *sqlstr; uint32_t tbNum; SStrToken tbname; SStrToken stbname; @@ -1291,6 +1292,7 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { } pStmt->mtb.values = sToken; + } return TSDB_CODE_SUCCESS; @@ -1373,7 +1375,12 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO break; } - free(pSql->sqlstr); + if (pStmt->mtb.sqlstr == NULL) { + pStmt->mtb.sqlstr = pSql->sqlstr; + } else { + tfree(pSql->sqlstr); + } + pSql->sqlstr = str; return TSDB_CODE_SUCCESS; @@ -1633,6 +1640,7 @@ int taos_stmt_close(TAOS_STMT* stmt) { taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList); pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL; taosArrayDestroy(pStmt->mtb.tags); + tfree(pStmt->mtb.sqlstr); } } From 0763faeaaf16aae9f23baeb9d77c9a0b733207a1 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 1 Jun 2021 16:24:55 +0800 Subject: [PATCH 72/80] Hotfix/sangshuduo/td 4477 install dep for lua (#6329) * make lua build.sh install necessary lib and specify include path. * [TD-4477]: install dependency package for tests/examples/lua build.sh. Co-authored-by: Shuduo Sang --- tests/examples/lua/build.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/examples/lua/build.sh b/tests/examples/lua/build.sh index cbd47bdfd2..9d00c68425 100755 --- a/tests/examples/lua/build.sh +++ b/tests/examples/lua/build.sh @@ -1,2 +1,8 @@ -gcc -std=c99 lua_connector.c -fPIC -shared -o luaconnector.so -Wall -ltaos +lua_header_installed=`apt-cache policy liblua5.3-dev|grep Installed|grep none > /dev/null; echo $?` +if [ "$lua_header_installed" = "0" ]; then + echo "If need, please input root password to install liblua5.3-dev for build the connector.." + sudo apt install -y liblua5.3-dev +fi + +gcc -std=c99 lua_connector.c -fPIC -shared -o luaconnector.so -Wall -ltaos -I/usr/include/lua5.3 From e02653fb71f88aa70ed93036be710a41824b883a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 1 Jun 2021 16:35:20 +0800 Subject: [PATCH 73/80] [td-255] fix bug found by regression test. --- src/client/src/tscSQLParser.c | 9 ++++- src/client/src/tscUtil.c | 68 ++++++++++++++++++++++++++--------- src/query/src/qAggMain.c | 4 +-- 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 2a7678ffab..e192c143d9 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7493,6 +7493,13 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } } } + + // set order by info + STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; + if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != + TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } } else { pQueryInfo->command = TSDB_SQL_SELECT; @@ -7642,8 +7649,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf SExprInfo** p = NULL; int32_t numOfExpr = 0; + pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); code = createProjectionExpr(pQueryInfo, pTableMetaInfo, &p, &numOfExpr); - if (pQueryInfo->exprList1 == NULL) { pQueryInfo->exprList1 = taosArrayInit(4, POINTER_BYTES); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index c114bfd9b7..0f5fb8c2c8 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -777,7 +777,9 @@ SSDataBlock* doGetDataBlock(void* param, bool* newgroup) { SSqlRes* pRes = &pSql->res; SSDataBlock* pBlock = pInput->block; - pOperator->pRuntimeEnv->current = pInput->pTableQueryInfo; + if (pOperator->pRuntimeEnv != NULL) { + pOperator->pRuntimeEnv->current = pInput->pTableQueryInfo; + } pBlock->info.rows = pRes->numOfRows; if (pRes->numOfRows != 0) { @@ -801,6 +803,24 @@ SSDataBlock* doGetDataBlock(void* param, bool* newgroup) { return pBlock; } +static void fetchNextBlockIfCompleted(SOperatorInfo* pOperator, bool* newgroup) { + SJoinOperatorInfo* pJoinInfo = pOperator->info; + + for (int32_t i = 0; i < pOperator->numOfUpstream; ++i) { + SJoinStatus* pStatus = &pJoinInfo->status[i]; + if (pStatus->pBlock == NULL || pStatus->index >= pStatus->pBlock->info.rows) { + pStatus->pBlock = pOperator->upstream[i]->exec(pOperator->upstream[i], newgroup); + pStatus->index = 0; + + if (pStatus->pBlock == NULL) { + pOperator->status = OP_EXEC_DONE; + pJoinInfo->resultInfo.total += pJoinInfo->pRes->info.rows; + break; + } + } + } +} + SSDataBlock* doDataBlockJoin(void* param, bool* newgroup) { SOperatorInfo *pOperator = (SOperatorInfo*) param; if (pOperator->status == OP_EXEC_DONE) { @@ -813,19 +833,9 @@ SSDataBlock* doDataBlockJoin(void* param, bool* newgroup) { pJoinInfo->pRes->info.rows = 0; while(1) { - for (int32_t i = 0; i < pOperator->numOfUpstream; ++i) { - SJoinStatus* pStatus = &pJoinInfo->status[i]; - if (pStatus->pBlock == NULL || pStatus->index >= pStatus->pBlock->info.rows) { - pStatus->pBlock = pOperator->upstream[i]->exec(pOperator->upstream[i], newgroup); - pStatus->index = 0; - - if (pStatus->pBlock == NULL) { - pOperator->status = OP_EXEC_DONE; - - pJoinInfo->resultInfo.total += pJoinInfo->pRes->info.rows; - return pJoinInfo->pRes; - } - } + fetchNextBlockIfCompleted(pOperator, newgroup); + if (pOperator->status == OP_EXEC_DONE) { + return pJoinInfo->pRes; } SJoinStatus* st0 = &pJoinInfo->status[0]; @@ -844,8 +854,12 @@ SSDataBlock* doDataBlockJoin(void* param, bool* newgroup) { if (ts[st->index] < ts0[st0->index]) { // less than the first prefixEqual = false; + if ((++(st->index)) >= st->pBlock->info.rows) { - break; + fetchNextBlockIfCompleted(pOperator, newgroup); + if (pOperator->status == OP_EXEC_DONE) { + return pJoinInfo->pRes; + } } } else if (ts[st->index] > ts0[st0->index]) { // greater than the first; if (prefixEqual == true) { @@ -853,12 +867,19 @@ SSDataBlock* doDataBlockJoin(void* param, bool* newgroup) { for (int32_t j = 0; j < i; ++j) { SJoinStatus* stx = &pJoinInfo->status[j]; if ((++(stx->index)) >= stx->pBlock->info.rows) { - break; + + fetchNextBlockIfCompleted(pOperator, newgroup); + if (pOperator->status == OP_EXEC_DONE) { + return pJoinInfo->pRes; + } } } } else { if ((++(st0->index)) >= st0->pBlock->info.rows) { - break; + fetchNextBlockIfCompleted(pOperator, newgroup); + if (pOperator->status == OP_EXEC_DONE) { + return pJoinInfo->pRes; + } } } } @@ -1129,6 +1150,19 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue memcpy(schema, pSchema, numOfCol1*sizeof(SSchema)); } + // update the exprinfo + int32_t numOfOutput = (int32_t)tscNumOfExprs(px); + for(int32_t i = 0; i < numOfOutput; ++i) { + SExprInfo* pex = taosArrayGetP(px->exprList, i); + int32_t colId = pex->base.colInfo.colId; + for(int32_t j = 0; j < pSourceOperator->numOfOutput; ++j) { + if (colId == schema[j].colId) { + pex->base.colInfo.colIndex = j; + break; + } + } + } + px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN); tfree(pColumnInfo); tfree(schema); diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 8a38c56adc..ae8c717abd 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -2489,7 +2489,6 @@ static void buildTopBotStruct(STopBotInfo *pTopBotInfo, SQLFunctionCtx *pCtx) { tmp += POINTER_BYTES * pCtx->param[0].i64; size_t size = sizeof(tValuePair) + pCtx->tagInfo.tagsLen; -// assert(pCtx->param[0].i64 > 0); for (int32_t i = 0; i < pCtx->param[0].i64; ++i) { pTopBotInfo->res[i] = (tValuePair*) tmp; @@ -2498,7 +2497,6 @@ static void buildTopBotStruct(STopBotInfo *pTopBotInfo, SQLFunctionCtx *pCtx) { } } - bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const char *maxval) { SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); if (pResInfo == NULL) { @@ -2742,7 +2740,7 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) { if (pCtx->param[1].i64 == PRIMARYKEY_TIMESTAMP_COL_INDEX) { __compar_fn_t comparator = (pCtx->param[2].i64 == TSDB_ORDER_ASC) ? resAscComparFn : resDescComparFn; qsort(tvp, (size_t)pResInfo->numOfRes, POINTER_BYTES, comparator); - } else if (pCtx->param[1].i64 > PRIMARYKEY_TIMESTAMP_COL_INDEX) { + } else /*if (pCtx->param[1].i64 > PRIMARYKEY_TIMESTAMP_COL_INDEX)*/ { __compar_fn_t comparator = (pCtx->param[2].i64 == TSDB_ORDER_ASC) ? resDataAscComparFn : resDataDescComparFn; qsort(tvp, (size_t)pResInfo->numOfRes, POINTER_BYTES, comparator); } From b7c413a6e253ded8ed4cf353a47923972eb9695d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 1 Jun 2021 16:45:05 +0800 Subject: [PATCH 74/80] [td-255] update the test cases. --- tests/script/general/parser/function.sim | 3 +++ tests/script/general/parser/nestquery.sim | 3 +-- tests/script/general/parser/testSuite.sim | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 56ce15c36f..ee5a750c88 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -24,6 +24,9 @@ sql drop database if exists $db sql create database $db keep 36500 sql use $db +print =====================================> td-4481 +sql create database $db + print =====================================> test case for twa in single block sql create table t1 (ts timestamp, k float); diff --git a/tests/script/general/parser/nestquery.sim b/tests/script/general/parser/nestquery.sim index 9e2736833f..3d13ff504d 100644 --- a/tests/script/general/parser/nestquery.sim +++ b/tests/script/general/parser/nestquery.sim @@ -9,7 +9,7 @@ sql connect print ======================== dnode1 start -$dbPrefix = nest_query +$dbPrefix = nest_db $tbPrefix = nest_tb $mtPrefix = nest_mt $tbNum = 10 @@ -17,7 +17,6 @@ $rowNum = 10000 $totalNum = $tbNum * $rowNum print =============== nestquery.sim - $i = 0 $db = $dbPrefix . $i $mt = $mtPrefix . $i diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index afb76c799e..6265fc3a02 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -60,4 +60,5 @@ run general/parser/slimit_alter_tags.sim run general/parser/binary_escapeCharacter.sim run general/parser/between_and.sim run general/parser/last_cache.sim +run general/parser/nestquery.sim From 469f709521dc1a1a5e0fc1aef9c522a52709ae9e Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 1 Jun 2021 16:58:27 +0800 Subject: [PATCH 75/80] [TD-4474] adding test case for testing lastRow hot alter --- tests/pytest/alter/alter_cacheLastRow.py | 106 ++++++++++++++++++ tests/pytest/fulltest.sh | 2 +- .../tools/taosdemoAllTest/insert_5M_rows.json | 60 ++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 tests/pytest/alter/alter_cacheLastRow.py create mode 100644 tests/pytest/tools/taosdemoAllTest/insert_5M_rows.json diff --git a/tests/pytest/alter/alter_cacheLastRow.py b/tests/pytest/alter/alter_cacheLastRow.py new file mode 100644 index 0000000000..cd08fe4f37 --- /dev/null +++ b/tests/pytest/alter/alter_cacheLastRow.py @@ -0,0 +1,106 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import tdDnodes +from datetime import datetime + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def run(self): + tdSql.prepare() + tdSql.query('show databases') + tdSql.checkData(0,15,0) + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + binPath = buildPath + "/build/bin/" + + os.system("%staosdemo -f tools/taosdemoAllTest/insert_100M_rows.json -y " % binPath) + # tdSql.query('select * from stb') + # tdSql.checkRows(1000*10000) + tdDnodes.stop(1) + tdDnodes.start(1) + tdSql.execute('use db') + # tdSql.query('select * from stb') + # tdSql.checkRows(1000*10000) + tableName = [] + for i in range(500): + tableName.append(f"stb_{i}") + + tdSql.execute('use db') + lastRow_Off_start = datetime.now() + + slow = 0 + for i in range(5): + for i in range(100): + for i in range(500): + tdSql.execute(f'SELECT LAST_ROW(*) FROM {tableName[i]}') + lastRow_Off_end = datetime.now() + + tdLog.debug(f'time used:{lastRow_Off_end-lastRow_Off_start}') + + tdSql.execute('alter database db cachelast 1') + tdSql.query('show databases') + tdSql.checkData(0,15,1) + + # tdDnodes.stop(1) + # tdDnodes.start(1) + + tdSql.execute('use db') + lastRow_On_start = datetime.now() + for i in range(100): + for i in range(500): + tdSql.execute(f'SELECT LAST_ROW(*) FROM {tableName[i]}') + lastRow_On_end = datetime.now() + + tdLog.debug(f'time used:{lastRow_On_end-lastRow_On_start}') + + if (lastRow_Off_end-lastRow_Off_start > lastRow_On_end-lastRow_On_start): + pass + else: + slow += 1 + tdLog.debug(slow) + if slow > 1: + tdLog.exit('lastRow hot alter failed') + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index c93fbc5eb3..69405f7106 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -335,5 +335,5 @@ python3 ./test.py -f tag_lite/alter_tag.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py python3 test.py -f insert/insert_before_use_db.py - +python3 test.py -f alter/alter_cacheLastRow.py #======================p4-end=============== diff --git a/tests/pytest/tools/taosdemoAllTest/insert_5M_rows.json b/tests/pytest/tools/taosdemoAllTest/insert_5M_rows.json new file mode 100644 index 0000000000..4637009ca3 --- /dev/null +++ b/tests/pytest/tools/taosdemoAllTest/insert_5M_rows.json @@ -0,0 +1,60 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 100, + "num_of_records_per_req": 100, + "databases": [{ + "dbinfo": { + "name": "db", + "drop": "yes", + "replica": 1, + "days": 10, + "cache": 16, + "blocks": 8, + "precision": "ms", + "keep": 3650, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb", + "child_table_exists":"no", + "childtable_count": 500, + "childtable_prefix": "stb_", + "auto_create_table": "no", + "batch_create_tbl_num": 20, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 10000, + "childtable_limit": 10, + "childtable_offset":100, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 10, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}], + "tags": [{"type": "TINYINT", "count":2}] + }] + }] +} \ No newline at end of file From d7ff9c999aae5b370d55bdc00f8d64ccd0a6a8d2 Mon Sep 17 00:00:00 2001 From: bryanchang0603 Date: Tue, 1 Jun 2021 17:11:39 +0800 Subject: [PATCH 76/80] [TD-4474] moldifying the test case --- tests/pytest/alter/alter_cacheLastRow.py | 39 +++++++++++++----------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/pytest/alter/alter_cacheLastRow.py b/tests/pytest/alter/alter_cacheLastRow.py index cd08fe4f37..36a2864d0f 100644 --- a/tests/pytest/alter/alter_cacheLastRow.py +++ b/tests/pytest/alter/alter_cacheLastRow.py @@ -50,52 +50,55 @@ class TDTestCase: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" - os.system("%staosdemo -f tools/taosdemoAllTest/insert_100M_rows.json -y " % binPath) - # tdSql.query('select * from stb') - # tdSql.checkRows(1000*10000) + #write 5M rows into db, then restart to force the data move into disk. + #create 500 tables + os.system("%staosdemo -f tools/taosdemoAllTest/insert_5M_rows.json -y " % binPath) tdDnodes.stop(1) tdDnodes.start(1) tdSql.execute('use db') - # tdSql.query('select * from stb') - # tdSql.checkRows(1000*10000) + + #prepare to query 500 tables last_row() tableName = [] for i in range(500): tableName.append(f"stb_{i}") - tdSql.execute('use db') lastRow_Off_start = datetime.now() - slow = 0 - for i in range(5): - for i in range(100): - for i in range(500): - tdSql.execute(f'SELECT LAST_ROW(*) FROM {tableName[i]}') + slow = 0 #count time where lastRow on is slower + for i in range(5): + #switch lastRow to off and check + tdSql.execute('alter database db cachelast 0') + tdSql.query('show databases') + tdSql.checkData(0,15,0) + + #run last_row(*) query 500 times + for i in range(500): + tdSql.execute(f'SELECT LAST_ROW(*) FROM {tableName[i]}') lastRow_Off_end = datetime.now() tdLog.debug(f'time used:{lastRow_Off_end-lastRow_Off_start}') + #switch lastRow to on and check tdSql.execute('alter database db cachelast 1') tdSql.query('show databases') tdSql.checkData(0,15,1) - - # tdDnodes.stop(1) - # tdDnodes.start(1) + #run last_row(*) query 500 times tdSql.execute('use db') lastRow_On_start = datetime.now() - for i in range(100): - for i in range(500): - tdSql.execute(f'SELECT LAST_ROW(*) FROM {tableName[i]}') + for i in range(500): + tdSql.execute(f'SELECT LAST_ROW(*) FROM {tableName[i]}') lastRow_On_end = datetime.now() tdLog.debug(f'time used:{lastRow_On_end-lastRow_On_start}') + #check which one used more time if (lastRow_Off_end-lastRow_Off_start > lastRow_On_end-lastRow_On_start): pass else: slow += 1 tdLog.debug(slow) - if slow > 1: + if slow > 1: #tolerance for the first time tdLog.exit('lastRow hot alter failed') def stop(self): tdSql.close() From 37c1e1393d18927eeaf15f0ba9daf41d48a63035 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 1 Jun 2021 17:49:48 +0800 Subject: [PATCH 77/80] [td-255] fix bug found by regression test. --- src/client/src/tscPrepare.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 312a570f2c..0e740b36bf 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1203,7 +1203,6 @@ static int insertBatchStmtExecute(STscStmt* pStmt) { return pStmt->pSql->res.code; } - int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { SSqlCmd *pCmd = &pSql->cmd; int32_t ret = TSDB_CODE_SUCCESS; @@ -1233,28 +1232,28 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { pStmt->mtb.tagSet = true; sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); - if (sToken.n > 0 && sToken.type == TK_VALUES) { + if (sToken.n > 0 && (sToken.type == TK_VALUES || sToken.type == TK_LP)) { return TSDB_CODE_SUCCESS; } if (sToken.n <= 0 || sToken.type != TK_USING) { - return TSDB_CODE_TSC_INVALID_OPERATION; + return tscSQLSyntaxErrMsg(pCmd->payload, "keywords USING is expected", sToken.z); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || ((sToken.type != TK_ID) && (sToken.type != TK_STRING))) { - return TSDB_CODE_TSC_INVALID_OPERATION; + return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z); } pStmt->mtb.stbname = sToken; sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || sToken.type != TK_TAGS) { - return TSDB_CODE_TSC_INVALID_OPERATION; + return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || sToken.type != TK_LP) { - return TSDB_CODE_TSC_INVALID_OPERATION; + return tscSQLSyntaxErrMsg(pCmd->payload, ") expected", sToken.z); } pStmt->mtb.tags = taosArrayInit(4, sizeof(SStrToken)); @@ -1296,9 +1295,6 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { return TSDB_CODE_SUCCESS; } - - - int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAOS_BIND* tags) { size_t tagNum = taosArrayGetSize(pStmt->mtb.tags); size_t size = 1048576; @@ -1379,8 +1375,6 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO return TSDB_CODE_SUCCESS; } - - //////////////////////////////////////////////////////////////////////////////// // interface functions From b61cf07797dc428545c062b1b923e02f585c8c5c Mon Sep 17 00:00:00 2001 From: root Date: Tue, 1 Jun 2021 10:44:05 +0000 Subject: [PATCH 78/80] [TD-4440] --- tests/script/api/stmtBatchTest.c | 438 +++++++++++++++++++++++++++---- 1 file changed, 392 insertions(+), 46 deletions(-) diff --git a/tests/script/api/stmtBatchTest.c b/tests/script/api/stmtBatchTest.c index 80848febd1..24291adfa0 100644 --- a/tests/script/api/stmtBatchTest.c +++ b/tests/script/api/stmtBatchTest.c @@ -3486,6 +3486,204 @@ static int stmt_specifyCol_bind_case_002_autoCreateTbl(TAOS_STMT *stmt, int tabl v->ts[i] = tts + i; } + for (int i = 0; i < 1; ++i) { + //tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + //tags[i+0].buffer = v->v4; + //tags[i+0].is_null = &one_not_null; + //tags[i+0].length = NULL; + + tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+0].buffer = v->b; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + //tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + //tags[i+2].buffer = v->v1; + //tags[i+2].is_null = &one_not_null; + //tags[i+2].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+1].buffer = v->v2; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+2].buffer = v->v8; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+3].buffer = v->f4; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+4].buffer = v->f8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+5].buffer = v->br; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = (uintptr_t *)lb; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+6].buffer = v->nr; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + +// create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp) + //char *sql = "insert into ? (ts,b,v4,f4,br) using stb1 tags (?,?,?,?,?,?,?,?,?) values(?,?,?,?,?)"; + char *sql = "insert into ? using stb1 tags (33,?,99,?,?,?,?,?,?) (ts,b,v4,f4,br) values(?,?,?,?,?)"; + + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + int id = 0; + for (int l = 0; l < bingNum; l++) { + for (int zz = 0; zz < tableNum; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + + for (int col=0; col < columnNum; ++col) { + code = taos_stmt_bind_single_param_batch(stmt, params + id, col); + if (code != 0){ + printf("failed to execute taos_stmt_bind_single_param_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + id++; + } + + code = taos_stmt_add_batch(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_add_batch. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + printf("failed to execute taos_stmt_execute. code:0x%x[%s]\n", code, tstrerror(code)); + return -1; + } + } + + unsigned long long endtime = getCurrentTime(); + unsigned long long totalRows = (uint32_t)(totalRowsPerTbl * tableNum); + printf("insert total %d records, used %u seconds, avg:%u useconds per record\n", totalRows, (endtime-starttime)/1000000UL, (endtime-starttime)/totalRows); + + free(v->ts); + free(v->br); + free(v->nr); + free(v); + free(lb); + free(params); + free(tags); + free(is_null); + free(no_null); + + return 0; +} + +// some tags are null +static int stmt_specifyCol_bind_case_003_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { + sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); + + int totalRowsPerTbl = rowsOfPerColum * bingNum; + + v->ts = (int64_t *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * tableNum)); + v->br = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + v->nr = (char *)malloc(sizeof(int64_t) * (size_t)(totalRowsPerTbl * lenOfBinaryDef)); + + int *lb = (int *)malloc(MAX_ROWS_OF_PER_COLUMN * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * (size_t)(bingNum * columnNum * (tableNum+1) * rowsOfPerColum)); + char* is_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + char* no_null = malloc(sizeof(char) * MAX_ROWS_OF_PER_COLUMN); + int one_not_null = 0; + int one_is_null = 1; + + int64_t tts = 1591060628000; + + for (int i = 0; i < rowsOfPerColum; ++i) { + lb[i] = lenOfBinaryAct; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v->b[i] = (int8_t)(i % 2); + v->v1[i] = (int8_t)((i+1) % 2); + v->v2[i] = (int16_t)i; + v->v4[i] = (int32_t)(i+1); + v->v8[i] = (int64_t)(i+2); + v->f4[i] = (float)(i+3); + v->f8[i] = (double)(i+4); + char tbuf[MAX_BINARY_DEF_LEN]; + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "binary-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->br + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + memset(tbuf, 0, MAX_BINARY_DEF_LEN); + sprintf(tbuf, "nchar-%d-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i%10); + memcpy(v->nr + i*lenOfBinaryDef, tbuf, (size_t)lenOfBinaryAct); + v->ts2[i] = tts + i; + } + + int i = 0; + for (int j = 0; j < bingNum * tableNum; j++) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v->ts[j*rowsOfPerColum]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = rowsOfPerColum; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v->b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = rowsOfPerColum; + + params[i+2].buffer_type = TSDB_DATA_TYPE_INT; + params[i+2].buffer_length = sizeof(int32_t); + params[i+2].buffer = v->v4; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = rowsOfPerColum; + + params[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+3].buffer_length = sizeof(float); + params[i+3].buffer = v->f4; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = rowsOfPerColum; + + params[i+4].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+4].buffer_length = (uintptr_t)lenOfBinaryDef; + params[i+4].buffer = v->br; + params[i+4].length = lb; + params[i+4].is_null = is_null; + params[i+4].num = rowsOfPerColum; + + i+=columnNum; + } + + //int64_t tts = 1591060628000; + for (int i = 0; i < totalRowsPerTbl * tableNum; ++i) { + v->ts[i] = tts + i; + } + for (int i = 0; i < 1; ++i) { tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; tags[i+0].buffer = v->v4; @@ -3494,12 +3692,12 @@ static int stmt_specifyCol_bind_case_002_autoCreateTbl(TAOS_STMT *stmt, int tabl tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; tags[i+1].buffer = v->b; - tags[i+1].is_null = &one_not_null; + tags[i+1].is_null = &one_is_null; tags[i+1].length = NULL; tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; tags[i+2].buffer = v->v1; - tags[i+2].is_null = &one_not_null; + tags[i+2].is_null = &one_is_null; tags[i+2].length = NULL; tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; @@ -3514,7 +3712,7 @@ static int stmt_specifyCol_bind_case_002_autoCreateTbl(TAOS_STMT *stmt, int tabl tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; tags[i+5].buffer = v->f4; - tags[i+5].is_null = &one_not_null; + tags[i+5].is_null = &one_is_null; tags[i+5].length = NULL; tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; @@ -3597,7 +3795,8 @@ static int stmt_specifyCol_bind_case_002_autoCreateTbl(TAOS_STMT *stmt, int tabl return 0; } -static int stmt_specifyCol_bind_case_003_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { +// specify tags field, and not support , then is error case +static int stmt_specifyCol_bind_case_004_autoCreateTbl(TAOS_STMT *stmt, int tableNum, int rowsOfPerColum, int bingNum, int lenOfBinaryDef, int lenOfBinaryAct, int columnNum) { sampleValue* v = (sampleValue *)calloc(1, sizeof(sampleValue)); int totalRowsPerTbl = rowsOfPerColum * bingNum; @@ -3683,50 +3882,50 @@ static int stmt_specifyCol_bind_case_003_autoCreateTbl(TAOS_STMT *stmt, int tabl } for (int i = 0; i < 1; ++i) { - tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; - tags[i+0].buffer = v->v4; + //tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + //tags[i+0].buffer = v->v4; + //tags[i+0].is_null = &one_not_null; + //tags[i+0].length = NULL; + + tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+0].buffer = v->b; tags[i+0].is_null = &one_not_null; tags[i+0].length = NULL; - tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; - tags[i+1].buffer = v->b; + //tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + //tags[i+2].buffer = v->v1; + //tags[i+2].is_null = &one_not_null; + //tags[i+2].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+1].buffer = v->v2; tags[i+1].is_null = &one_not_null; tags[i+1].length = NULL; - tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; - tags[i+2].buffer = v->v1; + tags[i+2].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+2].buffer = v->v8; tags[i+2].is_null = &one_not_null; tags[i+2].length = NULL; - tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - tags[i+3].buffer = v->v2; + tags[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+3].buffer = v->f4; tags[i+3].is_null = &one_not_null; tags[i+3].length = NULL; - tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; - tags[i+4].buffer = v->v8; + tags[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+4].buffer = v->f8; tags[i+4].is_null = &one_not_null; tags[i+4].length = NULL; - tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; - tags[i+5].buffer = v->f4; + tags[i+5].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+5].buffer = v->br; tags[i+5].is_null = &one_not_null; - tags[i+5].length = NULL; + tags[i+5].length = (uintptr_t *)lb; - tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; - tags[i+6].buffer = v->f8; + tags[i+6].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+6].buffer = v->nr; tags[i+6].is_null = &one_not_null; - tags[i+6].length = NULL; - - tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; - tags[i+7].buffer = v->br; - tags[i+7].is_null = &one_not_null; - tags[i+7].length = (uintptr_t *)lb; - - tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; - tags[i+8].buffer = v->nr; - tags[i+8].is_null = &one_not_null; - tags[i+8].length = (uintptr_t *)lb; + tags[i+6].length = (uintptr_t *)lb; } @@ -3734,7 +3933,7 @@ static int stmt_specifyCol_bind_case_003_autoCreateTbl(TAOS_STMT *stmt, int tabl // create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, br binary(%d), nr nchar(%d), ts2 timestamp) //char *sql = "insert into ? (ts,b,v4,f4,br) using stb1 tags (?,?,?,?,?,?,?,?,?) values(?,?,?,?,?)"; - char *sql = "insert into ? using stb1 tags (33,?,99,?,?,?,?,?,?) (ts,b,v4,f4,br) values(?,?,?,?,?)"; + char *sql = "insert into ? using stb1 (id1, id2, id3, id4, id5, id6, id7, id8, id9) tags (33,?,99,?,?,?,?,?,?) (ts,b,v4,f4,br) values(?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ @@ -3808,7 +4007,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { //=======================================================================// //=============================== single table ==========================// //========== case 1: ======================// -#if 0 +#if 1 { stmt = taos_stmt_init(taos); @@ -3830,7 +4029,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { #endif //========== case 2: ======================// -#if 0 +#if 1 { stmt = taos_stmt_init(taos); @@ -3861,7 +4060,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { #endif //========== case 2-1: ======================// -#if 0 +#if 1 { stmt = taos_stmt_init(taos); @@ -3891,7 +4090,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { } #endif //========== case 2-2: ======================// -#if 0 +#if 1 { printf("====case 2-2 error test start\n"); stmt = taos_stmt_init(taos); @@ -3924,7 +4123,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { //========== case 3: ======================// -#if 0 +#if 1 { stmt = taos_stmt_init(taos); @@ -3955,7 +4154,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { #endif //========== case 4: ======================// -#if 0 +#if 1 { stmt = taos_stmt_init(taos); @@ -3988,7 +4187,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { //=======================================================================// //=============================== multi-rows to single table ==========================// //========== case 5: ======================// -#if 0 +#if 1 { stmt = taos_stmt_init(taos); @@ -4023,7 +4222,7 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { columnNum = 5; prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db6"); - stmt_specifyCol_bind_case_002_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); totalRowsPerTbl = rowsOfPerColum * bingNum; checkResult(taos, "m0", 0, totalRowsPerTbl); @@ -4033,28 +4232,175 @@ static void SpecifyColumnBatchCase_autoCreateTbl(TAOS *taos) { } #endif - //========== case 7: ======================// -#if 0 + //========== case 7: ======================// +#if 1 + { + stmt = taos_stmt_init(taos); + + tableNum = 200; + rowsOfPerColum = 60; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db7"); + stmt_specifyCol_bind_case_001_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + checkResult(taos, "m99", 0, totalRowsPerTbl); + checkResult(taos, "m139", 0, totalRowsPerTbl); + checkResult(taos, "m199", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 7 check result end\n\n"); + } +#endif + + //========== case 8: ======================// +#if 1 { stmt = taos_stmt_init(taos); tableNum = 1; - rowsOfPerColum = 23740; + rowsOfPerColum = 5; bingNum = 1; lenOfBinaryDef = 40; lenOfBinaryAct = 8; - columnNum = 1; + columnNum = 5; - prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db6"); - stmt_specifyCol_bind_case_003_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db8"); + stmt_specifyCol_bind_case_002_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); totalRowsPerTbl = rowsOfPerColum * bingNum; checkResult(taos, "m0", 0, totalRowsPerTbl); taos_stmt_close(stmt); - printf("case 7 check result end\n\n"); + printf("case 8 check result end\n\n"); } #endif + //========== case 9: ======================// + +#if 1 + { + stmt = taos_stmt_init(taos); + + tableNum = 10; + rowsOfPerColum = 5; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db9"); + stmt_specifyCol_bind_case_002_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m3", 0, totalRowsPerTbl); + checkResult(taos, "m6", 0, totalRowsPerTbl); + checkResult(taos, "m9", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 9 check result end\n\n"); + } +#endif + + //========== case 10: ======================// +#if 1 + { + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 23740; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db10"); + stmt_specifyCol_bind_case_003_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 10 check result end\n\n"); + } +#endif + + //========== case 11: ======================// +#if 1 + { + stmt = taos_stmt_init(taos); + + tableNum = 2; + rowsOfPerColum = 5; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db11"); + stmt_specifyCol_bind_case_003_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 11 check result end\n\n"); + } +#endif + + //========== case 12: ======================// +#if 1 + { + stmt = taos_stmt_init(taos); + + tableNum = 200; + rowsOfPerColum = 60; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db12"); + stmt_specifyCol_bind_case_003_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + checkResult(taos, "m1", 0, totalRowsPerTbl); + checkResult(taos, "m99", 0, totalRowsPerTbl); + checkResult(taos, "m139", 0, totalRowsPerTbl); + checkResult(taos, "m199", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("case 12 check result end\n\n"); + } +#endif + + + //========== case 13: ======================// +#if 1 + { + printf("====case 13 error test start\n"); + stmt = taos_stmt_init(taos); + + tableNum = 1; + rowsOfPerColum = 8; + bingNum = 1; + lenOfBinaryDef = 40; + lenOfBinaryAct = 8; + columnNum = 5; + + prepareVcolumn_autoCreateTbl(taos, 1, tableNum, lenOfBinaryDef, "db13"); + stmt_specifyCol_bind_case_004_autoCreateTbl(stmt, tableNum, rowsOfPerColum, bingNum, lenOfBinaryDef, lenOfBinaryAct, columnNum); + + totalRowsPerTbl = rowsOfPerColum * bingNum; + checkResult(taos, "m0", 0, totalRowsPerTbl); + taos_stmt_close(stmt); + printf("====case 13 check result end\n\n"); + } +#endif + return ; } From f7d725e34afdc3c8ca98630c559676c44e6eef3c Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Tue, 1 Jun 2021 20:48:09 +0800 Subject: [PATCH 79/80] [TD-3078]: fix arbitrator create time --- src/common/inc/tglobal.h | 1 + src/common/src/tglobal.c | 1 + src/inc/taosdef.h | 2 ++ src/mnode/src/mnodeDnode.c | 2 +- src/sync/src/syncMain.c | 7 ++++++- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 1e66ce3f0c..07d614d5ef 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -39,6 +39,7 @@ extern int8_t tsEnableTelemetryReporting; extern char tsEmail[]; extern char tsArbitrator[]; extern int8_t tsArbOnline; +extern int64_t tsArbOnlineTimestamp; extern int32_t tsDnodeId; // common diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index e2237bbee6..ed91695569 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -42,6 +42,7 @@ int32_t tsNumOfMnodes = 3; int8_t tsEnableVnodeBak = 1; int8_t tsEnableTelemetryReporting = 1; int8_t tsArbOnline = 0; +int64_t tsArbOnlineTimestamp = TSDB_ARB_DUMMY_TIME; char tsEmail[TSDB_FQDN_LEN] = {0}; int32_t tsDnodeId = 0; diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 024bc198df..672d460f2c 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -373,6 +373,8 @@ do { \ #define TSDB_MAX_WAL_SIZE (1024*1024*3) +#define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P + typedef enum { TAOS_QTYPE_RPC = 0, TAOS_QTYPE_FWD = 1, diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index b513da29f4..1acb91beab 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -941,7 +941,7 @@ static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, vo cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = 0; + *(int64_t *)pWrite = tsArbOnlineTimestamp; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index e44b76d9b0..8ce37cbf78 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -1150,7 +1150,12 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) { pPeer->peerFd = connFd; pPeer->role = TAOS_SYNC_ROLE_UNSYNCED; pPeer->pConn = syncAllocateTcpConn(tsTcpPool, pPeer->rid, connFd); - if (pPeer->isArb) tsArbOnline = 1; + if (pPeer->isArb) { + tsArbOnline = 1; + if (tsArbOnlineTimestamp == TSDB_ARB_DUMMY_TIME) { + tsArbOnlineTimestamp = taosGetTimestampMs(); + } + } } else { sDebug("%s, failed to setup peer connection to server since %s, try later", pPeer->id, strerror(errno)); taosCloseSocket(connFd); From 07c48dadd956439e2d29799f02579b5b54db93bb Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 1 Jun 2021 21:32:21 +0800 Subject: [PATCH 80/80] Feature/sangshuduo/td 3973 use jemalloc (#6334) * [TD-3973]: add jemalloc as submodule. * add macro definitions in cmake. * [TD-3973]: use jemalloc. build works as following instructions: cmake .. -DJEMALLOC_ENABLED=true make * fix jemalloc at tag 5.2.1 * link jemalloc works. * make install works. * support jemalloc in release.sh. * release script works. Co-authored-by: Shuduo Sang --- packaging/deb/makedeb.sh | 50 +++++- packaging/rpm/makerpm.sh | 6 +- packaging/rpm/tdengine.spec | 81 +++++++-- packaging/tools/install.sh | 309 ++++++++++++++++++-------------- packaging/tools/make_install.sh | 2 +- packaging/tools/makepkg.sh | 51 +++++- 6 files changed, 329 insertions(+), 170 deletions(-) diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index 28be037e6c..e6ddb6d742 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -24,14 +24,14 @@ echo "compile_dir: ${compile_dir}" echo "pkg_dir: ${pkg_dir}" if [ -d ${pkg_dir} ]; then - rm -rf ${pkg_dir} + rm -rf ${pkg_dir} fi mkdir -p ${pkg_dir} cd ${pkg_dir} libfile="libtaos.so.${tdengine_ver}" -# create install dir +# create install dir install_home_path="/usr/local/taos" mkdir -p ${pkg_dir}${install_home_path} mkdir -p ${pkg_dir}${install_home_path}/bin @@ -42,7 +42,7 @@ mkdir -p ${pkg_dir}${install_home_path}/examples mkdir -p ${pkg_dir}${install_home_path}/include mkdir -p ${pkg_dir}${install_home_path}/init.d mkdir -p ${pkg_dir}${install_home_path}/script - + cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d cp ${compile_dir}/../packaging/tools/post.sh ${pkg_dir}${install_home_path}/script @@ -54,7 +54,7 @@ cp ${compile_dir}/build/bin/taosdemo ${pkg_dir}${install_home_pat cp ${compile_dir}/build/bin/taosdump ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/bin/taosd ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/bin/taos ${pkg_dir}${install_home_path}/bin -cp ${compile_dir}/build/lib/${libfile} ${pkg_dir}${install_home_path}/driver +cp ${compile_dir}/build/lib/${libfile} ${pkg_dir}${install_home_path}/driver cp ${compile_dir}/../src/inc/taos.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../src/inc/taoserror.h ${pkg_dir}${install_home_path}/include cp -r ${top_dir}/tests/examples/* ${pkg_dir}${install_home_path}/examples @@ -67,7 +67,41 @@ fi cp -r ${top_dir}/src/connector/python ${pkg_dir}${install_home_path}/connector cp -r ${top_dir}/src/connector/go ${pkg_dir}${install_home_path}/connector cp -r ${top_dir}/src/connector/nodejs ${pkg_dir}${install_home_path}/connector -cp ${compile_dir}/build/lib/taos-jdbcdriver*dist.* ${pkg_dir}${install_home_path}/connector ||: +cp ${compile_dir}/build/lib/taos-jdbcdriver*.* ${pkg_dir}${install_home_path}/connector ||: + +if [ -f ${compile_dir}/build/bin/jemalloc-config ]; then + install_user_local_path="/usr/local" + mkdir -p ${pkg_dir}${install_user_local_path}/{bin,lib,lib/pkgconfig,include/jemalloc,share/doc/jemalloc,share/man/man3} + cp ${compile_dir}/build/bin/jemalloc-config ${pkg_dir}${install_user_local_path}/bin/ + if [ -f ${compile_dir}/build/bin/jemalloc.sh ]; then + cp ${compile_dir}/build/bin/jemalloc.sh ${pkg_dir}${install_user_local_path}/bin/ + fi + if [ -f ${compile_dir}/build/bin/jeprof ]; then + cp ${compile_dir}/build/bin/jeprof ${pkg_dir}${install_user_local_path}/bin/ + fi + if [ -f ${compile_dir}/build/include/jemalloc/jemalloc.h ]; then + cp ${compile_dir}/build/include/jemalloc/jemalloc.h ${pkg_dir}${install_user_local_path}/include/jemalloc/ + fi + if [ -f ${compile_dir}/build/lib/libjemalloc.so.2 ]; then + cp ${compile_dir}/build/lib/libjemalloc.so.2 ${pkg_dir}${install_user_local_path}/lib/ + ln -sf libjemalloc.so.2 ${pkg_dir}${install_user_local_path}/lib/libjemalloc.so + fi + if [ -f ${compile_dir}/build/lib/libjemalloc.a ]; then + cp ${compile_dir}/build/lib/libjemalloc.a ${pkg_dir}${install_user_local_path}/lib/ + fi + if [ -f ${compile_dir}/build/lib/libjemalloc_pic.a ]; then + cp ${compile_dir}/build/lib/libjemalloc_pic.a ${pkg_dir}${install_user_local_path}/lib/ + fi + if [ -f ${compile_dir}/build/lib/pkgconfig/jemalloc.pc ]; then + cp ${compile_dir}/build/lib/pkgconfig/jemalloc.pc ${pkg_dir}${install_user_local_path}/lib/pkgconfig/ + fi + if [ -f ${compile_dir}/build/share/doc/jemalloc/jemalloc.html ]; then + cp ${compile_dir}/build/share/doc/jemalloc/jemalloc.html ${pkg_dir}${install_user_local_path}/share/doc/jemalloc/ + fi + if [ -f ${compile_dir}/build/share/man/man3/jemalloc.3 ]; then + cp ${compile_dir}/build/share/man/man3/jemalloc.3 ${pkg_dir}${install_user_local_path}/share/man/man3/ + fi +fi cp -r ${compile_dir}/../packaging/deb/DEBIAN ${pkg_dir}/ chmod 755 ${pkg_dir}/DEBIAN/* @@ -75,7 +109,7 @@ chmod 755 ${pkg_dir}/DEBIAN/* # modify version of control debver="Version: "$tdengine_ver sed -i "2c$debver" ${pkg_dir}/DEBIAN/control - + #get taos version, then set deb name @@ -90,7 +124,7 @@ fi if [ "$verType" == "beta" ]; then debname=${debname}-${verType}".deb" -elif [ "$verType" == "stable" ]; then +elif [ "$verType" == "stable" ]; then debname=${debname}".deb" else echo "unknow verType, nor stabel or beta" @@ -101,7 +135,7 @@ fi dpkg -b ${pkg_dir} $debname echo "make deb package success!" -cp ${pkg_dir}/*.deb ${output_dir} +cp ${pkg_dir}/*.deb ${output_dir} # clean tmep dir rm -rf ${pkg_dir} diff --git a/packaging/rpm/makerpm.sh b/packaging/rpm/makerpm.sh index 678e75c500..7c3272f8d0 100755 --- a/packaging/rpm/makerpm.sh +++ b/packaging/rpm/makerpm.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Generate rpm package for centos +# Generate rpm package for centos set -e # set -x @@ -60,7 +60,7 @@ ${csudo} rpmbuild --define="_version ${tdengine_ver}" --define="_topdir ${pkg_di # copy rpm package to output_dir, and modify package name, then clean temp dir #${csudo} cp -rf RPMS/* ${output_dir} -cp_rpm_package ${pkg_dir}/RPMS +cp_rpm_package ${pkg_dir}/RPMS if [ "$verMode" == "cluster" ]; then @@ -74,7 +74,7 @@ fi if [ "$verType" == "beta" ]; then rpmname=${rpmname}-${verType}".rpm" -elif [ "$verType" == "stable" ]; then +elif [ "$verType" == "stable" ]; then rpmname=${rpmname}".rpm" else echo "unknow verType, nor stabel or beta" diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index 9910e20bfe..8a870286ab 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -1,4 +1,5 @@ %define homepath /usr/local/taos +%define userlocalpath /usr/local %define cfg_install_dir /etc/taos %define __strip /bin/true @@ -12,22 +13,22 @@ URL: www.taosdata.com AutoReqProv: no #BuildRoot: %_topdir/BUILDROOT -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root #Prefix: /usr/local/taos -#BuildRequires: -#Requires: +#BuildRequires: +#Requires: %description Big Data Platform Designed and Optimized for IoT -#"prep" Nothing needs to be done +#"prep" Nothing needs to be done #%prep #%setup -q -#%setup -T +#%setup -T -#"build" Nothing needs to be done +#"build" Nothing needs to be done #%build #%configure #make %{?_smp_mflags} @@ -75,9 +76,53 @@ fi cp -r %{_compiledir}/../src/connector/python %{buildroot}%{homepath}/connector cp -r %{_compiledir}/../src/connector/go %{buildroot}%{homepath}/connector cp -r %{_compiledir}/../src/connector/nodejs %{buildroot}%{homepath}/connector -cp %{_compiledir}/build/lib/taos-jdbcdriver*dist.* %{buildroot}%{homepath}/connector ||: +cp %{_compiledir}/build/lib/taos-jdbcdriver*.* %{buildroot}%{homepath}/connector ||: cp -r %{_compiledir}/../tests/examples/* %{buildroot}%{homepath}/examples + +if [ -f %{_compiledir}/build/bin/jemalloc-config ]; then + mkdir -p %{buildroot}%{userlocalpath}/bin + mkdir -p %{buildroot}%{userlocalpath}/lib + mkdir -p %{buildroot}%{userlocalpath}/lib/pkgconfig + mkdir -p %{buildroot}%{userlocalpath}/include + mkdir -p %{buildroot}%{userlocalpath}/include/jemalloc + mkdir -p %{buildroot}%{userlocalpath}/share + mkdir -p %{buildroot}%{userlocalpath}/share/doc + mkdir -p %{buildroot}%{userlocalpath}/share/doc/jemalloc + mkdir -p %{buildroot}%{userlocalpath}/share/man + mkdir -p %{buildroot}%{userlocalpath}/share/man/man3 + + cp %{_compiledir}/build/bin/jemalloc-config %{buildroot}%{userlocalpath}/bin/ + if [ -f %{_compiledir}/build/bin/jemalloc.sh ]; then + cp %{_compiledir}/build/bin/jemalloc.sh %{buildroot}%{userlocalpath}/bin/ + fi + if [ -f %{_compiledir}/build/bin/jeprof ]; then + cp %{_compiledir}/build/bin/jeprof %{buildroot}%{userlocalpath}/bin/ + fi + if [ -f %{_compiledir}/build/include/jemalloc/jemalloc.h ]; then + cp %{_compiledir}/build/include/jemalloc/jemalloc.h %{buildroot}%{userlocalpath}/include/jemalloc/ + fi + if [ -f %{_compiledir}/build/lib/libjemalloc.so.2 ]; then + cp %{_compiledir}/build/lib/libjemalloc.so.2 %{buildroot}%{userlocalpath}/lib/ + ln -sf libjemalloc.so.2 %{buildroot}%{userlocalpath}/lib/libjemalloc.so + fi + if [ -f %{_compiledir}/build/lib/libjemalloc.a ]; then + cp %{_compiledir}/build/lib/libjemalloc.a %{buildroot}%{userlocalpath}/lib/ + fi + if [ -f %{_compiledir}/build/lib/libjemalloc_pic.a ]; then + cp %{_compiledir}/build/lib/libjemalloc_pic.a %{buildroot}%{userlocalpath}/lib/ + fi + if [ -f %{_compiledir}/build/lib/pkgconfig/jemalloc.pc ]; then + cp %{_compiledir}/build/lib/pkgconfig/jemalloc.pc %{buildroot}%{userlocalpath}/lib/pkgconfig/ + fi + if [ -f %{_compiledir}/build/share/doc/jemalloc/jemalloc.html ]; then + cp %{_compiledir}/build/share/doc/jemalloc/jemalloc.html %{buildroot}%{userlocalpath}/share/doc/jemalloc/ + fi + if [ -f %{_compiledir}/build/share/man/man3/jemalloc.3 ]; then + cp %{_compiledir}/build/share/man/man3/jemalloc.3 %{buildroot}%{userlocalpath}/share/man/man3/ + fi +fi + #Scripts executed before installation %pre csudo="" @@ -103,7 +148,7 @@ fi # if taos.cfg already softlink, remove it if [ -f %{cfg_install_dir}/taos.cfg ]; then ${csudo} rm -f %{homepath}/cfg/taos.cfg || : -fi +fi # there can not libtaos.so*, otherwise ln -s error ${csudo} rm -f %{homepath}/driver/libtaos* || : @@ -116,18 +161,18 @@ if command -v sudo > /dev/null; then fi cd %{homepath}/script ${csudo} ./post.sh - + # Scripts executed before uninstall %preun csudo="" if command -v sudo > /dev/null; then csudo="sudo" fi -# only remove package to call preun.sh, not but update(2) +# only remove package to call preun.sh, not but update(2) if [ $1 -eq 0 ];then #cd %{homepath}/script #${csudo} ./preun.sh - + if [ -f %{homepath}/script/preun.sh ]; then cd %{homepath}/script ${csudo} ./preun.sh @@ -135,7 +180,7 @@ if [ $1 -eq 0 ];then bin_link_dir="/usr/bin" lib_link_dir="/usr/lib" inc_link_dir="/usr/include" - + data_link_dir="/usr/local/taos/data" log_link_dir="/usr/local/taos/log" cfg_link_dir="/usr/local/taos/cfg" @@ -149,20 +194,20 @@ if [ $1 -eq 0 ];then ${csudo} rm -f ${inc_link_dir}/taos.h || : ${csudo} rm -f ${inc_link_dir}/taoserror.h || : ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - + ${csudo} rm -f ${log_link_dir} || : ${csudo} rm -f ${data_link_dir} || : - + pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then ${csudo} kill -9 $pid || : - fi - fi + fi + fi fi - + # Scripts executed after uninstall %postun - + # clean build dir %clean csudo="" diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index 178a248cfe..325ac81053 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -59,11 +59,11 @@ initd_mod=0 service_mod=2 if pidof systemd &> /dev/null; then service_mod=0 -elif $(which service &> /dev/null); then +elif $(which service &> /dev/null); then service_mod=1 - service_config_dir="/etc/init.d" + service_config_dir="/etc/init.d" if $(which chkconfig &> /dev/null); then - initd_mod=1 + initd_mod=1 elif $(which insserv &> /dev/null); then initd_mod=2 elif $(which update-rc.d &> /dev/null); then @@ -71,7 +71,7 @@ elif $(which service &> /dev/null); then else service_mod=2 fi -else +else service_mod=2 fi @@ -103,7 +103,7 @@ elif echo $osinfo | grep -qwi "fedora" ; then os_type=2 else echo " osinfo: ${osinfo}" - echo " This is an officially unverified linux system," + echo " This is an officially unverified linux system," echo " if there are any problems with the installation and operation, " echo " please feel free to contact taosdata.com for support." os_type=1 @@ -138,7 +138,7 @@ do echo "Usage: `basename $0` -v [server | client] -e [yes | no]" exit 0 ;; - ?) #unknow option + ?) #unknow option echo "unkonw argument" exit 1 ;; @@ -157,9 +157,9 @@ function kill_process() { function install_main_path() { #create install main dir and all sub dir ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} + ${csudo} mkdir -p ${install_main_dir} ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin + ${csudo} mkdir -p ${install_main_dir}/bin ${csudo} mkdir -p ${install_main_dir}/connector ${csudo} mkdir -p ${install_main_dir}/driver ${csudo} mkdir -p ${install_main_dir}/examples @@ -168,10 +168,10 @@ function install_main_path() { if [ "$verMode" == "cluster" ]; then ${csudo} mkdir -p ${nginx_dir} fi - + if [[ -e ${script_dir}/email ]]; then - ${csudo} cp ${script_dir}/email ${install_main_dir}/ ||: - fi + ${csudo} cp ${script_dir}/email ${install_main_dir}/ ||: + fi } function install_bin() { @@ -207,29 +207,75 @@ function install_lib() { ${csudo} rm -f ${lib_link_dir}/libtaos.* || : ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : #${csudo} rm -rf ${v15_java_app_dir} || : - ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* - + ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so - + if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : ${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : fi - - #if [ "$verMode" == "cluster" ]; then + + #if [ "$verMode" == "cluster" ]; then # # Compatible with version 1.5 # ${csudo} mkdir -p ${v15_java_app_dir} # ${csudo} ln -s ${install_main_dir}/connector/taos-jdbcdriver-1.0.2-dist.jar ${v15_java_app_dir}/JDBCDriver-1.0.2-dist.jar # ${csudo} chmod 777 ${v15_java_app_dir} || : #fi - + ${csudo} ldconfig } +function install_jemalloc() { + jemalloc_dir=${script_dir}/jemalloc + + if [ -d ${jemalloc_dir} ]; then + ${csudo} /usr/bin/install -c -d /usr/local/bin + + if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then + ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin + fi + if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then + ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin + fi + if [ -f ${jemalloc_dir}/bin/jeprof ]; then + ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin + fi + if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then + ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc + fi + if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then + ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib + ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo} /usr/bin/install -c -d /usr/local/lib + if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then + ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib + fi + if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then + ${csudo} /usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib + fi + if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then + ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig + fi + fi + if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then + ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc + fi + if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then + ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo} /usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3 + fi + fi +} + function install_header() { ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* + ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } @@ -246,13 +292,13 @@ function add_newHostname_to_hosts() { if [[ "$s" == "$localIp" ]]; then return fi - done + done ${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||: } function set_hostname() { echo -e -n "${GREEN}Please enter one hostname(must not be 'localhost')${NC}:" - read newHostname + read newHostname while true; do if [[ ! -z "$newHostname" && "$newHostname" != "localhost" ]]; then break @@ -266,25 +312,25 @@ function set_hostname() { if [[ $retval != 0 ]]; then echo echo "set hostname fail!" - return + return fi #echo -e -n "$(hostnamectl status --static)" #echo -e -n "$(hostnamectl status --transient)" #echo -e -n "$(hostnamectl status --pretty)" - + #ubuntu/centos /etc/hostname if [[ -e /etc/hostname ]]; then ${csudo} echo $newHostname > /etc/hostname ||: fi - + #debian: #HOSTNAME=yourname if [[ -e /etc/sysconfig/network ]]; then ${csudo} sed -i -r "s/#*\s*(HOSTNAME=\s*).*/\1$newHostname/" /etc/sysconfig/network ||: fi ${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg - serverFqdn=$newHostname - + serverFqdn=$newHostname + if [[ -e /etc/hosts ]]; then add_newHostname_to_hosts $newHostname fi @@ -302,7 +348,7 @@ function is_correct_ipaddr() { return 0 fi done - + return 1 } @@ -316,13 +362,13 @@ function set_ipAsFqdn() { echo echo -e -n "${GREEN}Unable to get local ip, use 127.0.0.1${NC}" localFqdn="127.0.0.1" - # Write the local FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg + # Write the local FQDN to configuration file + ${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn echo return - fi - + fi + echo -e -n "${GREEN}Please choose an IP from local IP list${NC}:" echo echo -e -n "${GREEN}$iplist${NC}" @@ -331,15 +377,15 @@ function set_ipAsFqdn() { echo -e -n "${GREEN}Notes: if IP is used as the node name, data can NOT be migrated to other machine directly${NC}:" read localFqdn while true; do - if [ ! -z "$localFqdn" ]; then + if [ ! -z "$localFqdn" ]; then # Check if correct ip address is_correct_ipaddr $localFqdn retval=`echo $?` if [[ $retval != 0 ]]; then read -p "Please choose an IP from local IP list:" localFqdn else - # Write the local FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg + # Write the local FQDN to configuration file + ${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg serverFqdn=$localFqdn break fi @@ -354,59 +400,59 @@ function local_fqdn_check() { echo echo -e -n "System hostname is: ${GREEN}$serverFqdn${NC}" echo - if [[ "$serverFqdn" == "" ]] || [[ "$serverFqdn" == "localhost" ]]; then + if [[ "$serverFqdn" == "" ]] || [[ "$serverFqdn" == "localhost" ]]; then echo -e -n "${GREEN}It is strongly recommended to configure a hostname for this machine ${NC}" echo - + while true do - read -r -p "Set hostname now? [Y/n] " input - if [ ! -n "$input" ]; then - set_hostname - break - else - case $input in - [yY][eE][sS]|[yY]) - set_hostname - break - ;; - - [nN][oO]|[nN]) - set_ipAsFqdn - break - ;; - - *) - echo "Invalid input..." - ;; - esac - fi + read -r -p "Set hostname now? [Y/n] " input + if [ ! -n "$input" ]; then + set_hostname + break + else + case $input in + [yY][eE][sS]|[yY]) + set_hostname + break + ;; + + [nN][oO]|[nN]) + set_ipAsFqdn + break + ;; + + *) + echo "Invalid input..." + ;; + esac + fi done fi } function install_config() { #${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : - + if [ ! -f ${cfg_install_dir}/taos.cfg ]; then ${csudo} mkdir -p ${cfg_install_dir} [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} ${csudo} chmod 644 ${cfg_install_dir}/* - fi - + fi + ${csudo} cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg [ ! -z $1 ] && return 0 || : # only install client - + if ((${update_flag}==1)); then return 0 fi - + if [ "$interactiveFqdn" == "no" ]; then return 0 - fi - + fi + local_fqdn_check #FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" @@ -424,8 +470,8 @@ function install_config() { if [ ! -z "$firstEp" ]; then # check the format of the firstEp #if [[ $firstEp == $FQDN_PATTERN ]]; then - # Write the first FQDN to configuration file - ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg + # Write the first FQDN to configuration file + ${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg break #else # read -p "Please enter the correct FQDN:port: " firstEp @@ -433,9 +479,9 @@ function install_config() { else break fi - done + done - # user email + # user email #EMAIL_PATTERN='^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$' #EMAIL_PATTERN='^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$' #EMAIL_PATTERN="^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$" @@ -446,31 +492,31 @@ function install_config() { if [ ! -z "$emailAddr" ]; then # check the format of the emailAddr #if [[ "$emailAddr" =~ $EMAIL_PATTERN ]]; then - # Write the email address to temp file - email_file="${install_main_dir}/email" + # Write the email address to temp file + email_file="${install_main_dir}/email" ${csudo} bash -c "echo $emailAddr > ${email_file}" - break + break #else - # read -p "Please enter the correct email address: " emailAddr + # read -p "Please enter the correct email address: " emailAddr #fi else break fi - done + done } function install_log() { ${csudo} rm -rf ${log_dir} || : ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} - + ${csudo} ln -s ${log_dir} ${install_main_dir}/log } function install_data() { ${csudo} mkdir -p ${data_dir} - - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + + ${csudo} ln -s ${data_dir} ${install_main_dir}/data } function install_connector() { @@ -485,26 +531,26 @@ function install_examples() { function clean_service_on_sysvinit() { #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : - + #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + if pidof taosd &> /dev/null; then ${csudo} service taosd stop || : fi - + if pidof tarbitrator &> /dev/null; then ${csudo} service tarbitratord stop || : fi if ((${initd_mod}==1)); then - if [ -e ${service_config_dir}/taosd ]; then + if [ -e ${service_config_dir}/taosd ]; then ${csudo} chkconfig --del taosd || : fi - if [ -e ${service_config_dir}/tarbitratord ]; then + if [ -e ${service_config_dir}/tarbitratord ]; then ${csudo} chkconfig --del tarbitratord || : fi elif ((${initd_mod}==2)); then - if [ -e ${service_config_dir}/taosd ]; then + if [ -e ${service_config_dir}/taosd ]; then ${csudo} insserv -r taosd || : fi if [ -e ${service_config_dir}/tarbitratord ]; then @@ -518,10 +564,10 @@ function clean_service_on_sysvinit() { ${csudo} update-rc.d -f tarbitratord remove || : fi fi - + ${csudo} rm -f ${service_config_dir}/taosd || : ${csudo} rm -f ${service_config_dir}/tarbitratord || : - + if $(which init &> /dev/null); then ${csudo} init q || : fi @@ -544,10 +590,10 @@ function install_service_on_sysvinit() { ${csudo} cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord ${csudo} cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo} chmod a+x ${service_config_dir}/tarbitratord fi - + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" - + if ((${initd_mod}==1)); then ${csudo} chkconfig --add taosd || : ${csudo} chkconfig --level 2345 taosd on || : @@ -572,7 +618,7 @@ function clean_service_on_systemd() { fi ${csudo} systemctl disable taosd &> /dev/null || echo &> /dev/null ${csudo} rm -f ${taosd_service_config} - + tarbitratord_service_config="${service_config_dir}/tarbitratord.service" if systemctl is-active --quiet tarbitratord; then echo "tarbitrator is running, stopping it..." @@ -580,7 +626,7 @@ function clean_service_on_systemd() { fi ${csudo} systemctl disable tarbitratord &> /dev/null || echo &> /dev/null ${csudo} rm -f ${tarbitratord_service_config} - + if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" if systemctl is-active --quiet nginxd; then @@ -588,8 +634,8 @@ function clean_service_on_systemd() { ${csudo} systemctl stop nginxd &> /dev/null || echo &> /dev/null fi ${csudo} systemctl disable nginxd &> /dev/null || echo &> /dev/null - ${csudo} rm -f ${nginx_service_config} - fi + ${csudo} rm -f ${nginx_service_config} + fi } # taos:2345:respawn:/etc/init.d/taosd start @@ -621,7 +667,7 @@ function install_service_on_systemd() { ${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}" ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" ${csudo} systemctl enable taosd - + tarbitratord_service_config="${service_config_dir}/tarbitratord.service" ${csudo} bash -c "echo '[Unit]' >> ${tarbitratord_service_config}" ${csudo} bash -c "echo 'Description=TDengine arbitrator service' >> ${tarbitratord_service_config}" @@ -643,9 +689,9 @@ function install_service_on_systemd() { ${csudo} bash -c "echo >> ${tarbitratord_service_config}" ${csudo} bash -c "echo '[Install]' >> ${tarbitratord_service_config}" ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${tarbitratord_service_config}" - #${csudo} systemctl enable tarbitratord - - if [ "$verMode" == "cluster" ]; then + #${csudo} systemctl enable tarbitratord + + if [ "$verMode" == "cluster" ]; then nginx_service_config="${service_config_dir}/nginxd.service" ${csudo} bash -c "echo '[Unit]' >> ${nginx_service_config}" ${csudo} bash -c "echo 'Description=Nginx For TDengine Service' >> ${nginx_service_config}" @@ -674,7 +720,7 @@ function install_service_on_systemd() { ${csudo} systemctl enable nginxd fi ${csudo} systemctl start nginxd - fi + fi } function install_service() { @@ -757,7 +803,7 @@ function update_TDengine() { fi sleep 1 fi - + if [ "$verMode" == "cluster" ]; then if pidof nginx &> /dev/null; then if ((${service_mod}==0)); then @@ -770,12 +816,13 @@ function update_TDengine() { sleep 1 fi fi - + install_main_path install_log install_header install_lib + install_jemalloc if [ "$pagMode" != "lite" ]; then install_connector fi @@ -783,10 +830,10 @@ function update_TDengine() { if [ -z $1 ]; then install_bin install_service - install_config - + install_config + openresty_work=false - if [ "$verMode" == "cluster" ]; then + if [ "$verMode" == "cluster" ]; then # Check if openresty is installed # Check if nginx is installed successfully if type curl &> /dev/null; then @@ -797,7 +844,7 @@ function update_TDengine() { echo -e "\033[44;31;5mNginx for TDengine does not work! Please try again!\033[0m" fi fi - fi + fi #echo #echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" @@ -816,7 +863,7 @@ function update_TDengine() { else echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos -h $serverFqdn${NC} in shell${NC}" fi - + echo echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" else @@ -839,14 +886,14 @@ function install_TDengine() { tar -zxf taos.tar.gz echo -e "${GREEN}Start to install TDengine...${NC}" - - install_main_path - + + install_main_path + if [ -z $1 ]; then install_data - fi - - install_log + fi + + install_log install_header install_lib if [ "$pagMode" != "lite" ]; then @@ -871,8 +918,8 @@ function install_TDengine() { fi fi fi - - install_config + + install_config # Ask if to start the service #echo @@ -885,36 +932,36 @@ function install_TDengine() { echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" else echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}" - fi + fi #if [ ${openresty_work} = 'true' ]; then # echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}" #else # echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" #fi - + if [ ! -z "$firstEp" ]; then - tmpFqdn=${firstEp%%:*} - substr=":" - if [[ $firstEp =~ $substr ]];then - tmpPort=${firstEp#*:} - else - tmpPort="" - fi - if [[ "$tmpPort" != "" ]];then - echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}" - else - echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}" - fi - echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}" - echo + tmpFqdn=${firstEp%%:*} + substr=":" + if [[ $firstEp =~ $substr ]];then + tmpPort=${firstEp#*:} + else + tmpPort="" + fi + if [[ "$tmpPort" != "" ]];then + echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}" + else + echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}" + fi + echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}" + echo elif [ ! -z "$serverFqdn" ]; then - echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $serverFqdn${GREEN_DARK} to login into TDengine server${NC}" - echo + echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $serverFqdn${GREEN_DARK} to login into TDengine server${NC}" + echo fi - + echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" - echo + echo else # Only install client install_bin install_config @@ -945,6 +992,6 @@ elif [ "$verType" == "client" ]; then else install_TDengine client fi -else - echo "please input correct verType" +else + echo "please input correct verType" fi diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 240804ed95..0c755d9f72 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -204,7 +204,7 @@ function install_jemalloc() { if [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ]; then /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib fi - if [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ]; then + if [ -f ${binary_dir}/build/lib/pkgconfig/jemalloc.pc ]; then /usr/bin/install -c -d /usr/local/lib/pkgconfig /usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig fi diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index e4d2d71b01..624f72278a 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -30,12 +30,12 @@ else install_dir="${release_dir}/TDengine-server-${version}" fi -# Directories and files. +# Directories and files if [ "$pagMode" == "lite" ]; then - strip ${build_dir}/bin/taosd + strip ${build_dir}/bin/taosd strip ${build_dir}/bin/taos bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${script_dir}/remove.sh" -else +else bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${build_dir}/bin/tarbitrator\ ${script_dir}/remove.sh ${script_dir}/set_core.sh ${script_dir}/startPre.sh ${script_dir}/taosd-dump-cfg.gdb" fi @@ -73,10 +73,43 @@ mkdir -p ${install_dir}/init.d && cp ${init_file_rpm} ${install_dir}/init.d/taos mkdir -p ${install_dir}/init.d && cp ${init_file_tarbitrator_deb} ${install_dir}/init.d/tarbitratord.deb || : mkdir -p ${install_dir}/init.d && cp ${init_file_tarbitrator_rpm} ${install_dir}/init.d/tarbitratord.rpm || : +if [ -f ${build_dir}/bin/jemalloc-config ]; then + mkdir -p ${install_dir}/jemalloc/{bin,lib,lib/pkgconfig,include/jemalloc,share/doc/jemalloc,share/man/man3} + cp ${build_dir}/bin/jemalloc-config ${install_dir}/jemalloc/bin + if [ -f ${build_dir}/bin/jemalloc.sh ]; then + cp ${build_dir}/bin/jemalloc.sh ${install_dir}/jemalloc/bin + fi + if [ -f ${build_dir}/bin/jeprof ]; then + cp ${build_dir}/bin/jeprof ${install_dir}/jemalloc/bin + fi + if [ -f ${build_dir}/include/jemalloc/jemalloc.h ]; then + cp ${build_dir}/include/jemalloc/jemalloc.h ${install_dir}/jemalloc/include/jemalloc + fi + if [ -f ${build_dir}/lib/libjemalloc.so.2 ]; then + cp ${build_dir}/lib/libjemalloc.so.2 ${install_dir}/jemalloc/lib + ln -sf libjemalloc.so.2 ${install_dir}/jemalloc/lib/libjemalloc.so + fi + if [ -f ${build_dir}/lib/libjemalloc.a ]; then + cp ${build_dir}/lib/libjemalloc.a ${install_dir}/jemalloc/lib + fi + if [ -f ${build_dir}/lib/libjemalloc_pic.a ]; then + cp ${build_dir}/lib/libjemalloc_pic.a ${install_dir}/jemalloc/lib + fi + if [ -f ${build_dir}/lib/pkgconfig/jemalloc.pc ]; then + cp ${build_dir}/lib/pkgconfig/jemalloc.pc ${install_dir}/jemalloc/lib/pkgconfig + fi + if [ -f ${build_dir}/share/doc/jemalloc/jemalloc.html ]; then + cp ${build_dir}/share/doc/jemalloc/jemalloc.html ${install_dir}/jemalloc/share/doc/jemalloc + fi + if [ -f ${build_dir}/share/man/man3/jemalloc.3 ]; then + cp ${build_dir}/share/man/man3/jemalloc.3 ${install_dir}/jemalloc/share/man/man3 + fi +fi + if [ "$verMode" == "cluster" ]; then sed 's/verMode=edge/verMode=cluster/g' ${install_dir}/bin/remove.sh >> remove_temp.sh mv remove_temp.sh ${install_dir}/bin/remove.sh - + mkdir -p ${install_dir}/nginxd && cp -r ${nginx_dir}/* ${install_dir}/nginxd cp ${nginx_dir}/png/taos.png ${install_dir}/nginxd/admin/images/taos.png rm -rf ${install_dir}/nginxd/png @@ -132,7 +165,7 @@ if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then if [ -d ${examples_dir}/JDBC/taosdemo/target ]; then rm -rf ${examples_dir}/JDBC/taosdemo/target fi - + cp -r ${examples_dir}/JDBC ${install_dir}/examples cp -r ${examples_dir}/matlab ${install_dir}/examples cp -r ${examples_dir}/python ${install_dir}/examples @@ -142,7 +175,7 @@ if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then cp -r ${examples_dir}/C# ${install_dir}/examples fi # Copy driver -mkdir -p ${install_dir}/driver +mkdir -p ${install_dir}/driver cp ${lib_files} ${install_dir}/driver # Copy connector @@ -168,7 +201,7 @@ fi # exit 1 -cd ${release_dir} +cd ${release_dir} if [ "$verMode" == "cluster" ]; then pkg_name=${install_dir}-${osType}-${cpuType} @@ -185,8 +218,8 @@ fi if [ "$verType" == "beta" ]; then pkg_name=${pkg_name}-${verType} -elif [ "$verType" == "stable" ]; then - pkg_name=${pkg_name} +elif [ "$verType" == "stable" ]; then + pkg_name=${pkg_name} else echo "unknow verType, nor stabel or beta" exit 1