diff --git a/contrib/test/CMakeLists.txt b/contrib/test/CMakeLists.txt index eacaeb9524be5dde7a231cfd7090f8dfe45f61ae..f35cf0d13d7078e6e90f52f3b49a0c579f3d856b 100644 --- a/contrib/test/CMakeLists.txt +++ b/contrib/test/CMakeLists.txt @@ -24,3 +24,4 @@ if(${BUILD_WITH_TRAFT}) endif(${BUILD_WITH_TRAFT}) add_subdirectory(tdev) +add_subdirectory(lz4) diff --git a/contrib/test/lz4/CMakeLists.txt b/contrib/test/lz4/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..92ac2aa5b26a6714b4e52f0e66f82f6db4df45a9 --- /dev/null +++ b/contrib/test/lz4/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(lz4_test "") +target_sources(lz4_test + PRIVATE + "main.c" +) +target_link_libraries(lz4_test lz4_static) \ No newline at end of file diff --git a/contrib/test/lz4/main.c b/contrib/test/lz4/main.c new file mode 100644 index 0000000000000000000000000000000000000000..49a6d8da01c6186352936bd56180a496660cfef3 --- /dev/null +++ b/contrib/test/lz4/main.c @@ -0,0 +1,8 @@ +#include + +#include "lz4.h" + +int main(int argc, char const *argv[]) { + printf("%d\n", LZ4_compressBound(1024)); + return 0; +} diff --git a/examples/rust b/examples/rust index 1c8924dc668e6aa848214c2fc54e3ace3f5bf8df..7ed7a97715388fa144718764d6bf20f9bfc29a12 160000 --- a/examples/rust +++ b/examples/rust @@ -1 +1 @@ -Subproject commit 1c8924dc668e6aa848214c2fc54e3ace3f5bf8df +Subproject commit 7ed7a97715388fa144718764d6bf20f9bfc29a12 diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 4a06d81c7b8edcafadb91c04186e9cc21af29052..083ded88870f4430bd18a66e21ebd1f5c0e11e3f 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -73,15 +73,17 @@ typedef struct { uint64_t suid; } STableListInfo; +#pragma pack(push, 1) typedef struct SColumnDataAgg { int16_t colId; - int16_t maxIndex; int16_t minIndex; + int16_t maxIndex; int16_t numOfNull; int64_t sum; int64_t max; int64_t min; } SColumnDataAgg; +#pragma pack(pop) typedef struct SDataBlockInfo { STimeWindow window; @@ -122,13 +124,11 @@ typedef struct SColumnInfoData { } SColumnInfoData; typedef struct SQueryTableDataCond { - // STimeWindow twindow; uint64_t suid; int32_t order; // desc|asc order to iterate the data block int32_t numOfCols; SColumnInfo* colList; - bool loadExternalRows; // load external rows or not - int32_t type; // data block load type: + int32_t type; // data block load type: int32_t numOfTWindows; STimeWindow* twindows; int64_t startVersion; diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index e70008e4ef1b0b4dbc8f76ce170842abdbfa4882..eaa8ac5cc4d43dcbbfe5157a025f6a1bf5d3bea9 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -34,21 +34,40 @@ typedef struct SValue SValue; typedef struct SColVal SColVal; typedef struct STSRow2 STSRow2; typedef struct STSRowBuilder STSRowBuilder; -typedef struct SColData SColData; typedef struct STagVal STagVal; typedef struct STag STag; +// bitmap +#define N1(n) ((1 << (n)) - 1) +#define BIT1_SIZE(n) (((n)-1) / 8 + 1) +#define BIT2_SIZE(n) (((n)-1) / 4 + 1) +#define SET_BIT1(p, i, v) \ + do { \ + (p)[(i) / 8] &= N1((i) % 8); \ + (p)[(i) / 8] |= (((uint8_t)(v)) << (((i) % 8))); \ + } while (0) + +#define GET_BIT1(p, i) (((p)[(i) / 8] >> ((i) % 8)) & ((uint8_t)1)) +#define SET_BIT2(p, i, v) \ + do { \ + p[(i) / 4] &= N1((i) % 4 * 2); \ + (p)[(i) / 4] |= (((uint8_t)(v)) << (((i) % 4) * 2)); \ + } while (0) +#define GET_BIT2(p, i) (((p)[(i) / 4] >> (((i) % 4) * 2)) & ((uint8_t)3)) + // STSchema int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t nCols, STSchema **ppTSchema); void tTSchemaDestroy(STSchema *pTSchema); // SValue -int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); +int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type); +int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type); +int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); // STSRow2 -#define COL_VAL_NONE(CID) ((SColVal){.cid = (CID), .isNone = 1}) -#define COL_VAL_NULL(CID) ((SColVal){.cid = (CID), .isNull = 1}) -#define COL_VAL_VALUE(CID, V) ((SColVal){.cid = (CID), .value = (V)}) +#define COL_VAL_NONE(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .isNone = 1}) +#define COL_VAL_NULL(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .isNull = 1}) +#define COL_VAL_VALUE(CID, TYPE, V) ((SColVal){.cid = (CID), .type = (TYPE), .value = (V)}) int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow); int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow); @@ -140,6 +159,7 @@ struct SValue { struct SColVal { int16_t cid; + int8_t type; int8_t isNone; int8_t isNull; SValue value; @@ -172,12 +192,6 @@ struct STag { }; #pragma pack(pop) -struct SColData { - int16_t cid; - uint32_t nData; - uint8_t *pData; -}; - #if 1 //================================================================================================================================================ // Imported since 3.0 and use bitmap to demonstrate None/Null/Norm, while use Null/Norm below 3.0 without of bitmap. #define TD_SUPPORT_BITMAP diff --git a/include/common/tmsg.h b/include/common/tmsg.h index dedc06a2b968b9f9e1852a1b59db7c49fc60f7ca..8988459637bb486fd5357981d8eed695aaa3c7a9 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -3024,6 +3024,17 @@ typedef struct { int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq); int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq); +typedef struct SDeleteRes { + uint64_t suid; + SArray* uidList; + int64_t skey; + int64_t ekey; + int64_t affectedRows; +} SDeleteRes; + +int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes); +int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes); + #pragma pack(pop) #ifdef __cplusplus diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 2130a9c264484fa6156d331a3767580eaea0dfb3..806c0b51225ee1b7b3228a12aa3955d35adeb1bd 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -200,6 +200,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_TTL_TABLE, "drop-ttl-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_COMMIT, "commit vnode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_MAX_MSG, "vnd-max", NULL, NULL) TD_NEW_MSG_SEG(TDMT_SCH_MSG) diff --git a/include/common/trow.h b/include/common/trow.h index 4031946ee855d9d9622e8c5085f7288c03e40817..086a6ce6fb6b059fd4f05961ccd7bb16a5542b2c 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -299,6 +299,7 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t colType, int32_t offset, int16_t colIdx); int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int32_t offset, int16_t colIdx); +void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColVal); typedef struct { STSchema *pSchema; @@ -312,6 +313,7 @@ typedef struct { void tdSTSRowIterReset(STSRowIter *pIter, STSRow *pRow); void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema); +int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow); bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal); bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal); bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx, SCellVal *pVal); @@ -320,7 +322,7 @@ STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int32_t row, int8_t bitmapMode); bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t flen, uint32_t offset, col_id_t colIdx, SCellVal *pVal); -bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, uint32_t offset, col_id_t colIdx, SCellVal *pVal); +bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVal); int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, int8_t bitmapMode); void tdSCellValPrint(SCellVal *pVal, int8_t colType); void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index bd73e047465d40275e2e3c1449686e5f73ba76a7..a5651f96f472603412497a27d88c35b20666d343 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -73,200 +73,201 @@ #define TK_MNODE 55 #define TK_DATABASE 56 #define TK_USE 57 -#define TK_IF 58 -#define TK_NOT 59 -#define TK_EXISTS 60 -#define TK_BUFFER 61 -#define TK_CACHELAST 62 -#define TK_COMP 63 -#define TK_DURATION 64 -#define TK_NK_VARIABLE 65 -#define TK_FSYNC 66 -#define TK_MAXROWS 67 -#define TK_MINROWS 68 -#define TK_KEEP 69 -#define TK_PAGES 70 -#define TK_PAGESIZE 71 -#define TK_PRECISION 72 -#define TK_REPLICA 73 -#define TK_STRICT 74 -#define TK_WAL 75 -#define TK_VGROUPS 76 -#define TK_SINGLE_STABLE 77 -#define TK_RETENTIONS 78 -#define TK_SCHEMALESS 79 -#define TK_NK_COLON 80 -#define TK_TABLE 81 -#define TK_NK_LP 82 -#define TK_NK_RP 83 -#define TK_STABLE 84 -#define TK_ADD 85 -#define TK_COLUMN 86 -#define TK_MODIFY 87 -#define TK_RENAME 88 -#define TK_TAG 89 -#define TK_SET 90 -#define TK_NK_EQ 91 -#define TK_USING 92 -#define TK_TAGS 93 -#define TK_COMMENT 94 -#define TK_BOOL 95 -#define TK_TINYINT 96 -#define TK_SMALLINT 97 -#define TK_INT 98 -#define TK_INTEGER 99 -#define TK_BIGINT 100 -#define TK_FLOAT 101 -#define TK_DOUBLE 102 -#define TK_BINARY 103 -#define TK_TIMESTAMP 104 -#define TK_NCHAR 105 -#define TK_UNSIGNED 106 -#define TK_JSON 107 -#define TK_VARCHAR 108 -#define TK_MEDIUMBLOB 109 -#define TK_BLOB 110 -#define TK_VARBINARY 111 -#define TK_DECIMAL 112 -#define TK_MAX_DELAY 113 -#define TK_WATERMARK 114 -#define TK_ROLLUP 115 -#define TK_TTL 116 -#define TK_SMA 117 -#define TK_FIRST 118 -#define TK_LAST 119 -#define TK_SHOW 120 -#define TK_DATABASES 121 -#define TK_TABLES 122 -#define TK_STABLES 123 -#define TK_MNODES 124 -#define TK_MODULES 125 -#define TK_QNODES 126 -#define TK_FUNCTIONS 127 -#define TK_INDEXES 128 -#define TK_ACCOUNTS 129 -#define TK_APPS 130 -#define TK_CONNECTIONS 131 -#define TK_LICENCE 132 -#define TK_GRANTS 133 -#define TK_QUERIES 134 -#define TK_SCORES 135 -#define TK_TOPICS 136 -#define TK_VARIABLES 137 -#define TK_BNODES 138 -#define TK_SNODES 139 -#define TK_CLUSTER 140 -#define TK_TRANSACTIONS 141 -#define TK_DISTRIBUTED 142 -#define TK_CONSUMERS 143 -#define TK_SUBSCRIPTIONS 144 -#define TK_LIKE 145 -#define TK_INDEX 146 -#define TK_FUNCTION 147 -#define TK_INTERVAL 148 -#define TK_TOPIC 149 -#define TK_AS 150 -#define TK_WITH 151 -#define TK_META 152 -#define TK_CONSUMER 153 -#define TK_GROUP 154 -#define TK_DESC 155 -#define TK_DESCRIBE 156 -#define TK_RESET 157 -#define TK_QUERY 158 -#define TK_CACHE 159 -#define TK_EXPLAIN 160 -#define TK_ANALYZE 161 -#define TK_VERBOSE 162 -#define TK_NK_BOOL 163 -#define TK_RATIO 164 -#define TK_NK_FLOAT 165 -#define TK_COMPACT 166 -#define TK_VNODES 167 -#define TK_IN 168 -#define TK_OUTPUTTYPE 169 -#define TK_AGGREGATE 170 -#define TK_BUFSIZE 171 -#define TK_STREAM 172 -#define TK_INTO 173 -#define TK_TRIGGER 174 -#define TK_AT_ONCE 175 -#define TK_WINDOW_CLOSE 176 -#define TK_IGNORE 177 -#define TK_EXPIRED 178 -#define TK_KILL 179 -#define TK_CONNECTION 180 -#define TK_TRANSACTION 181 -#define TK_BALANCE 182 -#define TK_VGROUP 183 -#define TK_MERGE 184 -#define TK_REDISTRIBUTE 185 -#define TK_SPLIT 186 -#define TK_SYNCDB 187 -#define TK_DELETE 188 -#define TK_NULL 189 -#define TK_NK_QUESTION 190 -#define TK_NK_ARROW 191 -#define TK_ROWTS 192 -#define TK_TBNAME 193 -#define TK_QSTARTTS 194 -#define TK_QENDTS 195 -#define TK_WSTARTTS 196 -#define TK_WENDTS 197 -#define TK_WDURATION 198 -#define TK_CAST 199 -#define TK_NOW 200 -#define TK_TODAY 201 -#define TK_TIMEZONE 202 -#define TK_CLIENT_VERSION 203 -#define TK_SERVER_VERSION 204 -#define TK_SERVER_STATUS 205 -#define TK_CURRENT_USER 206 -#define TK_COUNT 207 -#define TK_LAST_ROW 208 -#define TK_BETWEEN 209 -#define TK_IS 210 -#define TK_NK_LT 211 -#define TK_NK_GT 212 -#define TK_NK_LE 213 -#define TK_NK_GE 214 -#define TK_NK_NE 215 -#define TK_MATCH 216 -#define TK_NMATCH 217 -#define TK_CONTAINS 218 -#define TK_JOIN 219 -#define TK_INNER 220 -#define TK_SELECT 221 -#define TK_DISTINCT 222 -#define TK_WHERE 223 -#define TK_PARTITION 224 -#define TK_BY 225 -#define TK_SESSION 226 -#define TK_STATE_WINDOW 227 -#define TK_SLIDING 228 -#define TK_FILL 229 -#define TK_VALUE 230 -#define TK_NONE 231 -#define TK_PREV 232 -#define TK_LINEAR 233 -#define TK_NEXT 234 -#define TK_HAVING 235 -#define TK_RANGE 236 -#define TK_EVERY 237 -#define TK_ORDER 238 -#define TK_SLIMIT 239 -#define TK_SOFFSET 240 -#define TK_LIMIT 241 -#define TK_OFFSET 242 -#define TK_ASC 243 -#define TK_NULLS 244 -#define TK_ID 245 -#define TK_NK_BITNOT 246 -#define TK_INSERT 247 -#define TK_VALUES 248 -#define TK_IMPORT 249 -#define TK_NK_SEMI 250 -#define TK_FILE 251 +#define TK_FLUSH 58 +#define TK_IF 59 +#define TK_NOT 60 +#define TK_EXISTS 61 +#define TK_BUFFER 62 +#define TK_CACHELAST 63 +#define TK_COMP 64 +#define TK_DURATION 65 +#define TK_NK_VARIABLE 66 +#define TK_FSYNC 67 +#define TK_MAXROWS 68 +#define TK_MINROWS 69 +#define TK_KEEP 70 +#define TK_PAGES 71 +#define TK_PAGESIZE 72 +#define TK_PRECISION 73 +#define TK_REPLICA 74 +#define TK_STRICT 75 +#define TK_WAL 76 +#define TK_VGROUPS 77 +#define TK_SINGLE_STABLE 78 +#define TK_RETENTIONS 79 +#define TK_SCHEMALESS 80 +#define TK_NK_COLON 81 +#define TK_TABLE 82 +#define TK_NK_LP 83 +#define TK_NK_RP 84 +#define TK_STABLE 85 +#define TK_ADD 86 +#define TK_COLUMN 87 +#define TK_MODIFY 88 +#define TK_RENAME 89 +#define TK_TAG 90 +#define TK_SET 91 +#define TK_NK_EQ 92 +#define TK_USING 93 +#define TK_TAGS 94 +#define TK_COMMENT 95 +#define TK_BOOL 96 +#define TK_TINYINT 97 +#define TK_SMALLINT 98 +#define TK_INT 99 +#define TK_INTEGER 100 +#define TK_BIGINT 101 +#define TK_FLOAT 102 +#define TK_DOUBLE 103 +#define TK_BINARY 104 +#define TK_TIMESTAMP 105 +#define TK_NCHAR 106 +#define TK_UNSIGNED 107 +#define TK_JSON 108 +#define TK_VARCHAR 109 +#define TK_MEDIUMBLOB 110 +#define TK_BLOB 111 +#define TK_VARBINARY 112 +#define TK_DECIMAL 113 +#define TK_MAX_DELAY 114 +#define TK_WATERMARK 115 +#define TK_ROLLUP 116 +#define TK_TTL 117 +#define TK_SMA 118 +#define TK_FIRST 119 +#define TK_LAST 120 +#define TK_SHOW 121 +#define TK_DATABASES 122 +#define TK_TABLES 123 +#define TK_STABLES 124 +#define TK_MNODES 125 +#define TK_MODULES 126 +#define TK_QNODES 127 +#define TK_FUNCTIONS 128 +#define TK_INDEXES 129 +#define TK_ACCOUNTS 130 +#define TK_APPS 131 +#define TK_CONNECTIONS 132 +#define TK_LICENCE 133 +#define TK_GRANTS 134 +#define TK_QUERIES 135 +#define TK_SCORES 136 +#define TK_TOPICS 137 +#define TK_VARIABLES 138 +#define TK_BNODES 139 +#define TK_SNODES 140 +#define TK_CLUSTER 141 +#define TK_TRANSACTIONS 142 +#define TK_DISTRIBUTED 143 +#define TK_CONSUMERS 144 +#define TK_SUBSCRIPTIONS 145 +#define TK_LIKE 146 +#define TK_INDEX 147 +#define TK_FUNCTION 148 +#define TK_INTERVAL 149 +#define TK_TOPIC 150 +#define TK_AS 151 +#define TK_WITH 152 +#define TK_META 153 +#define TK_CONSUMER 154 +#define TK_GROUP 155 +#define TK_DESC 156 +#define TK_DESCRIBE 157 +#define TK_RESET 158 +#define TK_QUERY 159 +#define TK_CACHE 160 +#define TK_EXPLAIN 161 +#define TK_ANALYZE 162 +#define TK_VERBOSE 163 +#define TK_NK_BOOL 164 +#define TK_RATIO 165 +#define TK_NK_FLOAT 166 +#define TK_COMPACT 167 +#define TK_VNODES 168 +#define TK_IN 169 +#define TK_OUTPUTTYPE 170 +#define TK_AGGREGATE 171 +#define TK_BUFSIZE 172 +#define TK_STREAM 173 +#define TK_INTO 174 +#define TK_TRIGGER 175 +#define TK_AT_ONCE 176 +#define TK_WINDOW_CLOSE 177 +#define TK_IGNORE 178 +#define TK_EXPIRED 179 +#define TK_KILL 180 +#define TK_CONNECTION 181 +#define TK_TRANSACTION 182 +#define TK_BALANCE 183 +#define TK_VGROUP 184 +#define TK_MERGE 185 +#define TK_REDISTRIBUTE 186 +#define TK_SPLIT 187 +#define TK_SYNCDB 188 +#define TK_DELETE 189 +#define TK_INSERT 190 +#define TK_NULL 191 +#define TK_NK_QUESTION 192 +#define TK_NK_ARROW 193 +#define TK_ROWTS 194 +#define TK_TBNAME 195 +#define TK_QSTARTTS 196 +#define TK_QENDTS 197 +#define TK_WSTARTTS 198 +#define TK_WENDTS 199 +#define TK_WDURATION 200 +#define TK_CAST 201 +#define TK_NOW 202 +#define TK_TODAY 203 +#define TK_TIMEZONE 204 +#define TK_CLIENT_VERSION 205 +#define TK_SERVER_VERSION 206 +#define TK_SERVER_STATUS 207 +#define TK_CURRENT_USER 208 +#define TK_COUNT 209 +#define TK_LAST_ROW 210 +#define TK_BETWEEN 211 +#define TK_IS 212 +#define TK_NK_LT 213 +#define TK_NK_GT 214 +#define TK_NK_LE 215 +#define TK_NK_GE 216 +#define TK_NK_NE 217 +#define TK_MATCH 218 +#define TK_NMATCH 219 +#define TK_CONTAINS 220 +#define TK_JOIN 221 +#define TK_INNER 222 +#define TK_SELECT 223 +#define TK_DISTINCT 224 +#define TK_WHERE 225 +#define TK_PARTITION 226 +#define TK_BY 227 +#define TK_SESSION 228 +#define TK_STATE_WINDOW 229 +#define TK_SLIDING 230 +#define TK_FILL 231 +#define TK_VALUE 232 +#define TK_NONE 233 +#define TK_PREV 234 +#define TK_LINEAR 235 +#define TK_NEXT 236 +#define TK_HAVING 237 +#define TK_RANGE 238 +#define TK_EVERY 239 +#define TK_ORDER 240 +#define TK_SLIMIT 241 +#define TK_SOFFSET 242 +#define TK_LIMIT 243 +#define TK_OFFSET 244 +#define TK_ASC 245 +#define TK_NULLS 246 +#define TK_ID 247 +#define TK_NK_BITNOT 248 +#define TK_VALUES 249 +#define TK_IMPORT 250 +#define TK_NK_SEMI 251 +#define TK_FILE 252 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/libs/command/command.h b/include/libs/command/command.h index aee6b837837d7b3d9e3cbf37cde21c7a626c1a4f..8a4ecad37da3089c32ff0e3fca7473dcc334971c 100644 --- a/include/libs/command/command.h +++ b/include/libs/command/command.h @@ -13,6 +13,9 @@ * along with this program. If not, see . */ +#ifndef TDENGINE_COMMAND_H +#define TDENGINE_COMMAND_H + #include "cmdnodes.h" #include "tmsg.h" #include "plannodes.h" @@ -27,4 +30,4 @@ int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp); int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp); void qExplainFreeCtx(SExplainCtx *pCtx); - +#endif diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 45fa94b3bf754d3ace94319b6f65a0ffd8336ff1..9d09861b8ef82f4e10f3619827c884c8a0db5900 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -36,6 +36,8 @@ typedef struct SReadHandle { void* vnode; void* mnd; SMsgCb* pMsgCb; + +// int8_t initTsdbReader; bool tqReader; } SReadHandle; diff --git a/include/libs/index/index.h b/include/libs/index/index.h index dd991b3d4f2034a423a4cdbd344069623c0fa520..c6641f8b020a94b4a25eea612ef74978bb0b7e38 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -227,7 +227,7 @@ int32_t doFilterTag(SNode* pFilterNode, SIndexMetaArg* metaArg, SArray* result, * destory index env * */ -void indexCleanUp(); +void indexCleanup(); #ifdef __cplusplus } diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 134cd8048705b8fe37b213c2ade7c431ca788c1a..90ccbb60cf851b38502325a76bdf0382a2b1aee9 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -97,6 +97,11 @@ typedef struct SAlterDatabaseStmt { SDatabaseOptions* pOptions; } SAlterDatabaseStmt; +typedef struct SFlushDatabaseStmt { + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; +} SFlushDatabaseStmt; + typedef struct STableOptions { ENodeType type; bool commentNull; diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index a8637228e451e6b4491452f9eb304ce283ef21c2..30bcf22989cf8b901084c7c587da738767e4423e 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -111,6 +111,7 @@ typedef enum ENodeType { QUERY_NODE_CREATE_DATABASE_STMT, QUERY_NODE_DROP_DATABASE_STMT, QUERY_NODE_ALTER_DATABASE_STMT, + QUERY_NODE_FLUSH_DATABASE_STMT, QUERY_NODE_CREATE_TABLE_STMT, QUERY_NODE_CREATE_SUBTABLE_CLAUSE, QUERY_NODE_CREATE_MULTI_TABLE_STMT, @@ -194,6 +195,7 @@ typedef enum ENodeType { QUERY_NODE_KILL_QUERY_STMT, QUERY_NODE_KILL_TRANSACTION_STMT, QUERY_NODE_DELETE_STMT, + QUERY_NODE_INSERT_STMT, QUERY_NODE_QUERY, // logic plan node @@ -247,6 +249,7 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC, QUERY_NODE_PHYSICAL_PLAN_DISPATCH, QUERY_NODE_PHYSICAL_PLAN_INSERT, + QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT, QUERY_NODE_PHYSICAL_PLAN_DELETE, QUERY_NODE_PHYSICAL_SUBPLAN, QUERY_NODE_PHYSICAL_PLAN diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index debfce5f2de31b127aa078c5bb19702dde4b1985..d3e984098776f71ac47662db27a1815793938ad6 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -128,9 +128,12 @@ typedef struct SVnodeModifyLogicNode { SVgDataBlocks* pVgDataBlocks; SNode* pAffectedRows; // SColumnNode uint64_t tableId; + uint64_t stableId; int8_t tableType; // table type char tableFName[TSDB_TABLE_FNAME_LEN]; STimeWindow deleteTimeRange; + SVgroupsInfo* pVgroupList; + SNodeList* pInsertCols; } SVnodeModifyLogicNode; typedef struct SExchangeLogicNode { @@ -456,6 +459,17 @@ typedef struct SDataInserterNode { char* pData; } SDataInserterNode; +typedef struct SQueryInserterNode { + SDataSinkNode sink; + SNodeList* pCols; + uint64_t tableId; + uint64_t stableId; + int8_t tableType; // table type + char tableFName[TSDB_TABLE_FNAME_LEN]; + int32_t vgId; + SEpSet epSet; +} SQueryInserterNode; + typedef struct SDataDeleterNode { SDataSinkNode sink; uint64_t tableId; diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index dd337bcee0c200ec42372638a29e98586cb0cce3..b9a0b90a9a8bdca9a912719c61b81b051c4959df 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -302,6 +302,14 @@ typedef struct SDeleteStmt { bool deleteZeroRows; } SDeleteStmt; +typedef struct SInsertStmt { + ENodeType type; // QUERY_NODE_INSERT_STMT + SNode* pTable; + SNodeList* pCols; + SNode* pQuery; + uint8_t precision; +} SInsertStmt; + typedef enum { PAYLOAD_TYPE_KV = 0, PAYLOAD_TYPE_RAW = 1, diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 6c2a9bb374c019040b246dac6bb3e8f44da93a57..c3007306aecc7772a39435b4d77508fc33c645ae 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -56,7 +56,7 @@ typedef struct SParseContext { } SParseContext; int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery); -bool qIsInsertSql(const char* pStr, size_t length); +bool qIsInsertValuesSql(const char* pStr, size_t length); // for async mode int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq); diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 8edb50baed42ec838bd0e7fe15ba231411295a1a..a93cf1f9b81faec1d0bdb60361a4de3b44749371 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -29,12 +29,13 @@ extern "C" { typedef enum { JOB_TASK_STATUS_NULL = 0, - JOB_TASK_STATUS_NOT_START = 1, - JOB_TASK_STATUS_EXECUTING, - JOB_TASK_STATUS_PARTIAL_SUCCEED, - JOB_TASK_STATUS_SUCCEED, - JOB_TASK_STATUS_FAILED, - JOB_TASK_STATUS_DROPPING, + JOB_TASK_STATUS_INIT, + JOB_TASK_STATUS_EXEC, + JOB_TASK_STATUS_PART_SUCC, + JOB_TASK_STATUS_SUCC, + JOB_TASK_STATUS_FAIL, + JOB_TASK_STATUS_DROP, + JOB_TASK_STATUS_MAX, } EJobTaskType; typedef enum { @@ -59,10 +60,6 @@ typedef struct STableComInfo { int32_t rowSize; // row size of the schema } STableComInfo; -typedef struct SQueryExecRes { - int32_t msgType; - void* res; -} SQueryExecRes; typedef struct SIndexMeta { #if defined(WINDOWS) || defined(_TD_DARWIN_64) @@ -71,6 +68,13 @@ typedef struct SIndexMeta { } SIndexMeta; +typedef struct SExecResult { + int32_t code; + uint64_t numOfRows; + int32_t msgType; + void* res; +} SExecResult; + typedef struct STbVerInfo { char tbFName[TSDB_TABLE_FNAME_LEN]; int32_t sversion; @@ -210,7 +214,7 @@ char* jobTaskStatusStr(int32_t status); SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name); -void destroyQueryExecRes(SQueryExecRes* pRes); +void destroyQueryExecRes(SExecResult* pRes); int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len); char* parseTagDatatoJson(void* p); int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst); diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index 36e9b3309c6dd1c2827b9e03ddbbeb80c721f797..71f7622f49f5c3ba376d24af03cc9d21604d1d35 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -20,9 +20,9 @@ extern "C" { #endif +#include "executor.h" #include "tmsgcb.h" #include "trpc.h" -#include "executor.h" enum { NODE_TYPE_VNODE = 1, @@ -31,13 +31,6 @@ enum { NODE_TYPE_MNODE, }; -typedef struct SDeleteRes { - uint64_t suid; - SArray* uidList; - int64_t skey; - int64_t ekey; -} SDeleteRes; - typedef struct SQWorkerCfg { uint32_t maxSchedulerNum; uint32_t maxTaskNum; @@ -46,19 +39,19 @@ typedef struct SQWorkerCfg { typedef struct { uint64_t cacheDataSize; - + uint64_t queryProcessed; uint64_t cqueryProcessed; uint64_t fetchProcessed; uint64_t dropProcessed; uint64_t hbProcessed; uint64_t deleteProcessed; - + uint64_t numOfQueryInQueue; uint64_t numOfFetchInQueue; uint64_t timeInQueryQueue; uint64_t timeInFetchQueue; - + uint64_t numOfErrors; } SQWorkerStat; @@ -82,7 +75,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int6 int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts); -int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *pRsp, SDeleteRes *pRes); +int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SDeleteRes *pRes); void qWorkerDestroy(void **qWorkerMgmt); diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index 1c73b2c2c896262d6e13cb54929cbc5617e5580d..70ac7a630460a2917f11b93984e4c1434567e6ef 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -53,12 +53,6 @@ typedef struct SQueryProfileSummary { uint64_t resultSize; // generated result size in Kb. } SQueryProfileSummary; -typedef struct SQueryResult { - int32_t code; - uint64_t numOfRows; - SQueryExecRes res; -} SQueryResult; - typedef struct STaskInfo { SQueryNodeAddr addr; SSubQueryMsg *msg; @@ -69,50 +63,34 @@ typedef struct SSchdFetchParam { int32_t* code; } SSchdFetchParam; -typedef void (*schedulerExecFp)(SQueryResult* pResult, void* param, int32_t code); +typedef void (*schedulerExecFp)(SExecResult* pResult, void* param, int32_t code); typedef void (*schedulerFetchFp)(void* pResult, void* param, int32_t code); typedef bool (*schedulerChkKillFp)(void* param); typedef struct SSchedulerReq { + bool syncReq; SRequestConnInfo *pConn; SArray *pNodeList; SQueryPlan *pDag; const char *sql; int64_t startTs; schedulerExecFp execFp; - void* execParam; + schedulerFetchFp fetchFp; + void* cbParam; schedulerChkKillFp chkKillFp; void* chkKillParam; + SExecResult* pExecRes; + void** pFetchRes; } SSchedulerReq; int32_t schedulerInit(SSchedulerCfg *cfg); -/** - * Process the query job, generated according to the query physical plan. - * This is a synchronized API, and is also thread-safety. - * @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr - * @return - */ -int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJob, SQueryResult *pRes); - -/** - * Process the query job, generated according to the query physical plan. - * This is a asynchronized API, and is also thread-safety. - * @param pNodeList Qnode/Vnode address list, element is SQueryNodeAddr - * @return - */ - int32_t schedulerAsyncExecJob(SSchedulerReq *pReq, int64_t *pJob); +int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJob); -/** - * Fetch query result from the remote query executor - * @param pJob - * @param data - * @return - */ -int32_t schedulerFetchRows(int64_t job, void **data); +int32_t schedulerFetchRows(int64_t jobId, SSchedulerReq *pReq); -void schedulerAsyncFetchRows(int64_t job, schedulerFetchFp fp, void* param); +void schedulerFetchRowsA(int64_t job, schedulerFetchFp fp, void* param); int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub); @@ -134,7 +112,7 @@ void schedulerFreeJob(int64_t* job, int32_t errCode); void schedulerDestroy(void); -void schdExecCallback(SQueryResult* pResult, void* param, int32_t code); +void schdExecCallback(SExecResult* pResult, void* param, int32_t code); #ifdef __cplusplus } diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index a93b359ef3e4d5cd9f9c9ee00f90d7b6df8430c4..8a6d6b7722807a004a3e46ec4ed24aa9b6875cbf 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -26,7 +26,7 @@ extern "C" { extern bool gRaftDetailLog; -#define SYNC_MAX_BATCH_SIZE 100 +#define SYNC_MAX_BATCH_SIZE 500 #define SYNC_INDEX_BEGIN 0 #define SYNC_INDEX_INVALID -1 #define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF @@ -215,6 +215,7 @@ int32_t syncProposeBatch(int64_t rid, SRpcMsg* pMsgArr, bool* pIsWeakArr, in bool syncEnvIsStart(); const char* syncStr(ESyncState state); bool syncIsRestoreFinish(int64_t rid); +int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot); int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg); diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 48550b890a2bbca16db9926fcd71c32cb1058cb8..d59a0a64b340c3ca8a39f31cf11c538fb2e88452 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -27,7 +27,7 @@ extern "C" { #define TAOS_CONN_SERVER 0 #define TAOS_CONN_CLIENT 1 -#define IsReq(pMsg) (pMsg->msgType & 1U) +#define IsReq(pMsg) (pMsg->msgType & 1U) extern int32_t tsRpcHeadSize; @@ -35,12 +35,13 @@ typedef struct { uint32_t clientIp; uint16_t clientPort; int64_t applyIndex; + uint64_t applyTerm; char user[TSDB_USER_LEN]; } SRpcConnInfo; typedef struct SRpcHandleInfo { // rpc info - void * handle; // rpc handle returned to app + void *handle; // rpc handle returned to app int64_t refId; // refid, used by server int32_t noResp; // has response or not(default 0, 0: resp, 1: no resp); int32_t persistHandle; // persist handle or not @@ -53,7 +54,7 @@ typedef struct SRpcHandleInfo { void *node; // node mgmt handle // resp info - void * rsp; + void *rsp; int32_t rspLen; // conn info @@ -62,7 +63,7 @@ typedef struct SRpcHandleInfo { typedef struct SRpcMsg { tmsg_t msgType; - void * pCont; + void *pCont; int32_t contLen; int32_t code; SRpcHandleInfo info; @@ -74,7 +75,7 @@ typedef bool (*RpcRfp)(int32_t code, tmsg_t msgType); typedef struct SRpcInit { char localFqdn[TSDB_FQDN_LEN]; uint16_t localPort; // local port - char * label; // for debug purpose + char *label; // for debug purpose int32_t numOfThreads; // number of threads to handle connections int32_t sessions; // number of sessions allowed int8_t connType; // TAOS_CONN_UDP, TAOS_CONN_TCPC, TAOS_CONN_TCPS @@ -99,12 +100,12 @@ typedef struct { typedef struct { int32_t msgType; - void * val; + void *val; int32_t (*clone)(void *src, void **dst); } SRpcBrokenlinkVal; typedef struct { - SHashObj * args; + SHashObj *args; SRpcBrokenlinkVal brokenVal; void (*freeFunc)(const void *arg); } SRpcCtx; diff --git a/include/os/osMemory.h b/include/os/osMemory.h index ba69a329417200f0cb4080288f83f1f96ef4b554..88dfe02074fa3d8940c71b5aa4354ab2871d070d 100644 --- a/include/os/osMemory.h +++ b/include/os/osMemory.h @@ -32,7 +32,7 @@ extern "C" { void *taosMemoryMalloc(int32_t size); void *taosMemoryCalloc(int32_t num, int32_t size); void *taosMemoryRealloc(void *ptr, int32_t size); -void *taosMemoryStrDup(void *ptr); +void *taosMemoryStrDup(const char *ptr); void taosMemoryFree(void *ptr); int32_t taosMemorySize(void *ptr); void taosPrintBackTrace(); diff --git a/include/util/tRealloc.h b/include/util/tRealloc.h new file mode 100644 index 0000000000000000000000000000000000000000..8d40f6cc5df71f183a8c8c4c4fcbe2ff12a1bf0f --- /dev/null +++ b/include/util/tRealloc.h @@ -0,0 +1,64 @@ +/* + * 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_UTIL_TREALLOC_H_ +#define _TD_UTIL_TREALLOC_H_ + +#include "os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static FORCE_INLINE int32_t tRealloc(uint8_t **ppBuf, int64_t size) { + int32_t code = 0; + int64_t bsize = 0; + uint8_t *pBuf; + + if (*ppBuf) { + bsize = *(int64_t *)((*ppBuf) - sizeof(int64_t)); + } + + if (bsize >= size) goto _exit; + + if (bsize == 0) bsize = 64; + while (bsize < size) { + bsize *= 2; + } + + pBuf = (uint8_t *)taosMemoryRealloc(*ppBuf ? (*ppBuf) - sizeof(int64_t) : *ppBuf, bsize + sizeof(int64_t)); + if (pBuf == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + *(int64_t *)pBuf = bsize; + *ppBuf = pBuf + sizeof(int64_t); + +_exit: + return code; +} + +static FORCE_INLINE void tFree(uint8_t *pBuf) { + if (pBuf) { + taosMemoryFree(pBuf - sizeof(int64_t)); + } +} + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_UTIL_TREALLOC_H_*/ diff --git a/include/util/taoserror.h b/include/util/taoserror.h index baa49650fa91a05fd80fb2bcfaf614c028ca7e23..41d59106250d9ea4e4f2e14a5f29d50100efb0e9 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -72,6 +72,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_INVALID_TIMESTAMP TAOS_DEF_ERROR_CODE(0, 0x0030) #define TSDB_CODE_MSG_DECODE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0031) #define TSDB_CODE_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0032) +#define TSDB_CODE_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0033) #define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0040) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0041) @@ -389,10 +390,10 @@ int32_t* taosGetErrno(); #define TSDB_CODE_QRY_TASK_MSG_ERROR TAOS_DEF_ERROR_CODE(0, 0x0719) #define TSDB_CODE_QRY_JOB_FREED TAOS_DEF_ERROR_CODE(0, 0x071A) #define TSDB_CODE_QRY_TASK_STATUS_ERROR TAOS_DEF_ERROR_CODE(0, 0x071B) -//json #define TSDB_CODE_QRY_JSON_IN_ERROR TAOS_DEF_ERROR_CODE(0, 0x071C) #define TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR TAOS_DEF_ERROR_CODE(0, 0x071D) #define TSDB_CODE_QRY_JSON_IN_GROUP_ERROR TAOS_DEF_ERROR_CODE(0, 0x071E) +#define TSDB_CODE_QRY_JOB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x071F) // grant #define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800) diff --git a/include/util/tmallocator.h b/include/util/tmallocator.h deleted file mode 100644 index e9eb3e1b727755fdcf34f5b9c78771362d6a0b6e..0000000000000000000000000000000000000000 --- a/include/util/tmallocator.h +++ /dev/null @@ -1,55 +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 . - */ - -#ifndef _TD_UTIL_MALLOCATOR_H_ -#define _TD_UTIL_MALLOCATOR_H_ - -#include "os.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Memory allocator -#define TD_MEM_ALCT(TYPE) \ - struct { \ - void *(*malloc_)(struct TYPE *, uint64_t size); \ - void (*free_)(struct TYPE *, void *ptr); \ - } -#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_ -#define TD_MA_FREE_FUNC(TMA) (TMA)->free_ - -#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE)) -#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR)) - -typedef struct SMemAllocator { - void *impl; - TD_MEM_ALCT(SMemAllocator); -} SMemAllocator; - -#define tMalloc(pMA, SIZE) TD_MA_MALLOC(PMA, SIZE) -#define tFree(pMA, PTR) TD_MA_FREE(PMA, PTR) - -typedef struct SMemAllocatorFactory { - void *impl; - SMemAllocator *(*create)(struct SMemAllocatorFactory *); - void (*destroy)(struct SMemAllocatorFactory *, SMemAllocator *); -} SMemAllocatorFactory; - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_UTIL_MALLOCATOR_H_*/ \ No newline at end of file diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index b930f57d92bab7e67662d9e2114d0c64c7da1a87..9380b73d2d26ecd4ca5b5e11145748f652e36ade 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -156,7 +156,7 @@ typedef struct SResultColumn { } SResultColumn; typedef struct SReqResultInfo { - SQueryExecRes execRes; + SExecResult execRes; const char* pRspMsg; const char* pData; TAOS_FIELD* fields; // todo, column names are not needed. diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 07a33a938c9f131d4ea5b0998aa463c68fa2e303..bff65d352755043292b8056f20ae9e27b0c27a8d 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -627,22 +627,26 @@ _return: int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) { void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter; - SQueryResult res = {0}; + SExecResult res = {0}; SRequestConnInfo conn = {.pTrans = pRequest->pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; - SSchedulerReq req = {.pConn = &conn, - .pNodeList = pNodeList, - .pDag = pDag, - .sql = pRequest->sqlstr, - .startTs = pRequest->metric.start, - .execFp = NULL, - .execParam = NULL, - .chkKillFp = chkRequestKilled, - .chkKillParam = (void*)pRequest->self}; - - int32_t code = schedulerExecJob(&req, &pRequest->body.queryJob, &res); - pRequest->body.resInfo.execRes = res.res; + SSchedulerReq req = { + .syncReq = true, + .pConn = &conn, + .pNodeList = pNodeList, + .pDag = pDag, + .sql = pRequest->sqlstr, + .startTs = pRequest->metric.start, + .execFp = NULL, + .cbParam = NULL, + .chkKillFp = chkRequestKilled, + .chkKillParam = (void*)pRequest->self, + .pExecRes = &res, + }; + + int32_t code = schedulerExecJob(&req, &pRequest->body.queryJob); + memcpy(&pRequest->body.resInfo.execRes, &res, sizeof(res)); if (code != TSDB_CODE_SUCCESS) { schedulerFreeJob(&pRequest->body.queryJob, 0); @@ -753,7 +757,7 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) { } SEpSet epset = getEpSet_s(&pAppInfo->mgmtEp); - SQueryExecRes* pRes = &pRequest->body.resInfo.execRes; + SExecResult* pRes = &pRequest->body.resInfo.execRes; switch (pRes->msgType) { case TDMT_VND_ALTER_TABLE: @@ -779,10 +783,10 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) { return code; } -void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) { +void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) { SRequestObj* pRequest = (SRequestObj*)param; pRequest->code = code; - pRequest->body.resInfo.execRes = pResult->res; + memcpy(&pRequest->body.resInfo.execRes, pResult, sizeof(*pResult)); if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_DELETE == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) { @@ -939,16 +943,20 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM SRequestConnInfo conn = { .pTrans = pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; - SSchedulerReq req = {.pConn = &conn, - .pNodeList = pNodeList, - .pDag = pDag, - .sql = pRequest->sqlstr, - .startTs = pRequest->metric.start, - .execFp = schedulerExecCb, - .execParam = pRequest, - .chkKillFp = chkRequestKilled, - .chkKillParam = (void*)pRequest->self}; - code = schedulerAsyncExecJob(&req, &pRequest->body.queryJob); + SSchedulerReq req = { + .syncReq = false, + .pConn = &conn, + .pNodeList = pNodeList, + .pDag = pDag, + .sql = pRequest->sqlstr, + .startTs = pRequest->metric.start, + .execFp = schedulerExecCb, + .cbParam = pRequest, + .chkKillFp = chkRequestKilled, + .chkKillParam = (void*)pRequest->self, + .pExecRes = NULL, + }; + code = schedulerExecJob(&req, &pRequest->body.queryJob); taosArrayDestroy(pNodeList); } else { tscDebug("0x%" PRIx64 " plan not executed, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), @@ -1387,7 +1395,11 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) } SReqResultInfo* pResInfo = &pRequest->body.resInfo; - pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData); + SSchedulerReq req = { + .syncReq = true, + .pFetchRes = (void**)&pResInfo->pData, + }; + pRequest->code = schedulerFetchRows(pRequest->body.queryJob, &req); if (pRequest->code != TSDB_CODE_SUCCESS) { pResultInfo->numOfRows = 0; return NULL; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index a30d60a589150944c0cf45ee3b38fc202805360a..e908046b1e3adfef72ceed24055d988e2fda9cb7 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -843,35 +843,46 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { pRequest->body.param = param; SReqResultInfo *pResultInfo = &pRequest->body.resInfo; - if (taos_num_fields(pRequest) == 0) { + + // this query has no results or error exists, return directly + if (taos_num_fields(pRequest) == 0 || pRequest->code != TSDB_CODE_SUCCESS) { pResultInfo->numOfRows = 0; pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); return; } - if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) { - // All data has returned to App already, no need to try again - if (pResultInfo->completed) { - pResultInfo->numOfRows = 0; - pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); - return; - } + // all data has returned to App already, no need to try again + if ((pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) && pResultInfo->completed) { + pResultInfo->numOfRows = 0; + pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); + return; + } + + // it is a local executed query, no need to do async fetch + if (pResultInfo->current < pResultInfo->numOfRows && pRequest->body.queryJob == 0) { + pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); + return; } - schedulerAsyncFetchRows(pRequest->body.queryJob, fetchCallback, pRequest); + SSchedulerReq req = { + .syncReq = false, + .fetchFp = fetchCallback, + .cbParam = pRequest, + }; + schedulerFetchRows(pRequest->body.queryJob, &req); } void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { ASSERT(res != NULL && fp != NULL); ASSERT(TD_RES_QUERY(res)); - SRequestObj *pRequest = res; - - pRequest->body.resInfo.convertUcs4 = false; + SRequestObj *pRequest = res; SReqResultInfo *pResultInfo = &pRequest->body.resInfo; // set the current block is all consumed pResultInfo->current = pResultInfo->numOfRows; + pResultInfo->convertUcs4 = false; + taos_fetch_rows_a(res, fp, param); } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 761eebee42e11b7db96900088454234dd0e915fa..dcccbb17c98472d1b1a13d3eea9a255be0763494 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -266,7 +266,7 @@ int32_t processAlterStbRsp(void* param, SDataBuf* pMsg, int32_t code) { } if (pRequest->body.queryFp != NULL) { - SQueryExecRes* pRes = &pRequest->body.resInfo.execRes; + SExecResult* pRes = &pRequest->body.resInfo.execRes; if (code == TSDB_CODE_SUCCESS) { SCatalog* pCatalog = NULL; diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 1c0caec8102b5b0311c4cfd7240ea78270163628..1e0f30695dca6a851cf0cafd85d1057635a9fc77 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -324,9 +324,9 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) { } int32_t stmtRebuildDataBlock(STscStmt* pStmt, STableDataBlocks* pDataBlock, STableDataBlocks** newBlock, uint64_t uid) { - SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); - SVgroupInfo vgInfo = {0}; - SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter, + SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); + SVgroupInfo vgInfo = {0}; + SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter, .requestId = pStmt->exec.pRequest->requestId, .requestObjRefId = pStmt->exec.pRequest->self, .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)}; @@ -391,13 +391,12 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STMT_RET(stmtCleanBindInfo(pStmt)); } - STableMeta* pTableMeta = NULL; - SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter, + STableMeta* pTableMeta = NULL; + SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter, .requestId = pStmt->exec.pRequest->requestId, .requestObjRefId = pStmt->exec.pRequest->self, .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)}; - int32_t code = - catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta); + int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta); if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { STMT_ERR_RET(stmtCleanBindInfo(pStmt)); @@ -849,7 +848,7 @@ int stmtIsInsert(TAOS_STMT* stmt, int* insert) { if (pStmt->sql.type) { *insert = (STMT_TYPE_INSERT == pStmt->sql.type || STMT_TYPE_MULTI_INSERT == pStmt->sql.type); } else { - *insert = qIsInsertSql(pStmt->sql.sqlStr, 0); + *insert = qIsInsertValuesSql(pStmt->sql.sqlStr, pStmt->sql.sqlLen); } return TSDB_CODE_SUCCESS; @@ -861,7 +860,7 @@ int stmtGetTagFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { if (STMT_TYPE_QUERY == pStmt->sql.type) { STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); } - + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && @@ -893,7 +892,7 @@ int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { if (STMT_TYPE_QUERY == pStmt->sql.type) { STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); } - + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && @@ -919,7 +918,6 @@ int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { return TSDB_CODE_SUCCESS; } - int stmtGetParamNum(TAOS_STMT* stmt, int* nums) { STscStmt* pStmt = (STscStmt*)stmt; @@ -952,13 +950,13 @@ int stmtGetParamNum(TAOS_STMT* stmt, int* nums) { return TSDB_CODE_SUCCESS; } -int stmtGetParam(TAOS_STMT *stmt, int idx, int *type, int *bytes) { +int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) { STscStmt* pStmt = (STscStmt*)stmt; if (STMT_TYPE_QUERY == pStmt->sql.type) { STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); } - + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && @@ -979,8 +977,8 @@ int stmtGetParam(TAOS_STMT *stmt, int idx, int *type, int *bytes) { STMT_ERR_RET(stmtParseSql(pStmt)); } - int32_t nums = 0; - TAOS_FIELD_E *pField = NULL; + int32_t nums = 0; + TAOS_FIELD_E* pField = NULL; STMT_ERR_RET(stmtFetchColFields(stmt, &nums, &pField)); if (idx >= nums) { tscError("idx %d is too big", idx); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 36dcab5c192ea42a6ac4a98da16b5a48fd642b1d..e8e3237b67af1b857708ee88ba949808452acbea 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -669,13 +669,13 @@ TEST(testCase, projection_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); -// TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); + TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); - TAOS_RES* pRes = taos_query(pConn, "use abc1"); + pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); pRes = taos_query(pConn, "create stable st1 (ts timestamp, k int) tags(a int)"); @@ -700,54 +700,55 @@ TEST(testCase, projection_query_tables) { printf("create table :%d\n", i); createNewTable(pConn, i); } -// pRes = taos_query(pConn, "select * from tu"); -// if (taos_errno(pRes) != 0) { -// printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); -// taos_free_result(pRes); -// ASSERT_TRUE(false); -// } -// TAOS_ROW pRow = NULL; -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while ((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } + pRes = taos_query(pConn, "select * from tu"); + if (taos_errno(pRes) != 0) { + printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } -// taos_free_result(pRes); + TAOS_ROW pRow = NULL; + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while ((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_free_result(pRes); taos_close(pConn); } -//TEST(testCase, projection_query_stables) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// ASSERT_NE(pConn, nullptr); -// -// TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "select ts from st1"); -// if (taos_errno(pRes) != 0) { -// printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); -// taos_free_result(pRes); -// ASSERT_TRUE(false); -// } -// -// TAOS_ROW pRow = NULL; -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while ((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} +TEST(testCase, projection_query_stables) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(pConn, nullptr); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + taos_free_result(pRes); + + pRes = taos_query(pConn, "select ts from st1"); + if (taos_errno(pRes) != 0) { + printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + TAOS_ROW pRow = NULL; + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while ((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_free_result(pRes); + taos_close(pConn); +} TEST(testCase, agg_query_tables) { @@ -773,7 +774,7 @@ TEST(testCase, agg_query_tables) { taos_free_result(pRes); taos_close(pConn); } -#endif + /* --- copy the following script in the shell to setup the environment --- @@ -819,5 +820,27 @@ TEST(testCase, async_api_test) { getchar(); taos_close(pConn); } +#endif + +TEST(testCase, update_test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(pConn, nullptr); + + taos_query(pConn, "use abc1"); + + TAOS_RES* pRes = taos_query(pConn, "create table tup (ts timestamp, k int);"); + if (taos_errno(pRes) != 0) { + printf("failed to create table, reason:%s", taos_errstr(pRes)); + } + + taos_free_result(pRes); + + char s[256] = {0}; + for(int32_t i = 0; i < 7000; ++i) { + sprintf(s, "insert into tup values('2020-1-1 1:1:1', %d)", i); + pRes = taos_query(pConn, s); + taos_free_result(pRes); + } +} #pragma GCC diagnostic pop diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index bca740e9cebf008273bcd04070ba5c67d7da050b..08275182af42778e626774b8bf2d8c8cb0f11ab1 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1831,6 +1831,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks pSubmitBlk->suid = suid; pSubmitBlk->uid = pDataBlock->info.groupId; pSubmitBlk->numOfRows = rows; + pSubmitBlk->sversion = pTSchema->version; msgLen += sizeof(SSubmitBlk); int32_t dataLen = 0; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 83ae442ae7545ca3a1b33ddd5c6a0f50980a54b6..ec7be79934bf2d42909716f267d276fae4448e8d 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -29,15 +29,9 @@ typedef struct { #pragma pack(pop) #define TSROW_IS_KV_ROW(r) ((r)->flags & TSROW_KV_ROW) -#define BIT1_SIZE(n) (((n)-1) / 8 + 1) -#define BIT2_SIZE(n) (((n)-1) / 4 + 1) -#define SET_BIT1(p, i, v) ((p)[(i) / 8] = (p)[(i) / 8] & (~(((uint8_t)1) << ((i) % 8))) | ((v) << ((i) % 8))) -#define SET_BIT2(p, i, v) ((p)[(i) / 4] = (p)[(i) / 4] & (~(((uint8_t)3) << ((i) % 4))) | ((v) << ((i) % 4))) -#define GET_BIT1(p, i) (((p)[(i) / 8] >> ((i) % 8)) & ((uint8_t)1)) -#define GET_BIT2(p, i) (((p)[(i) / 4] >> ((i) % 4)) & ((uint8_t)3)) // SValue -static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { +int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -88,7 +82,7 @@ static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { return n; } -static FORCE_INLINE int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { +int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -421,7 +415,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S _set_none: if ((flags & 0xf0) == 0) { setBitMap(pb, 0, iColumn - 1, flags); - if (flags & TSROW_HAS_VAL) { // set 0 + if (flags & TSROW_HAS_VAL) { // set 0 if (IS_VAR_DATA_TYPE(pTColumn->type)) { *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; } else { @@ -434,7 +428,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S _set_null: if ((flags & 0xf0) == 0) { setBitMap(pb, 1, iColumn - 1, flags); - if (flags & TSROW_HAS_VAL) { // set 0 + if (flags & TSROW_HAS_VAL) { // set 0 if (IS_VAR_DATA_TYPE(pTColumn->type)) { *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; } else { @@ -639,15 +633,15 @@ void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal } _return_none: - *pColVal = COL_VAL_NONE(pTColumn->colId); + *pColVal = COL_VAL_NONE(pTColumn->colId, pTColumn->type); return; _return_null: - *pColVal = COL_VAL_NULL(pTColumn->colId); + *pColVal = COL_VAL_NULL(pTColumn->colId, pTColumn->type); return; _return_value: - *pColVal = COL_VAL_VALUE(pTColumn->colId, value); + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value); return; } @@ -1105,9 +1099,9 @@ _err: #if 1 // =================================================================================================================== static void dataColSetNEleNull(SDataCol *pCol, int nEle); int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { - int spaceNeeded = pCol->bytes * maxPoints; - if (IS_VAR_DATA_TYPE(pCol->type)) { - spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; + int spaceNeeded = pCol->bytes * maxPoints; + if (IS_VAR_DATA_TYPE(pCol->type)) { + spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; } #ifdef TD_SUPPORT_BITMAP int32_t nBitmapBytes = (int32_t)TD_BITMAP_BYTES(maxPoints); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 8157ba4d92998875642a1ad646cc4bf1d27f055a..192a41a70ed5563c672e91db2ee1322907f99a17 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5445,6 +5445,37 @@ int32_t tDecodeSTqOffset(SDecoder *pDecoder, STqOffset *pOffset) { return 0; } +int32_t tEncodeDeleteRes(SEncoder *pCoder, const SDeleteRes *pRes) { + int32_t nUid = taosArrayGetSize(pRes->uidList); + + if (tEncodeU64(pCoder, pRes->suid) < 0) return -1; + if (tEncodeI32v(pCoder, nUid) < 0) return -1; + for (int32_t iUid = 0; iUid < nUid; iUid++) { + if (tEncodeU64(pCoder, *(uint64_t *)taosArrayGet(pRes->uidList, iUid)) < 0) return -1; + } + if (tEncodeI64(pCoder, pRes->skey) < 0) return -1; + if (tEncodeI64(pCoder, pRes->ekey) < 0) return -1; + if (tEncodeI64v(pCoder, pRes->affectedRows) < 0) return -1; + + return 0; +} + +int32_t tDecodeDeleteRes(SDecoder *pCoder, SDeleteRes *pRes) { + int32_t nUid; + uint64_t uid; + + if (tDecodeU64(pCoder, &pRes->suid) < 0) return -1; + if (tDecodeI32v(pCoder, &nUid) < 0) return -1; + for (int32_t iUid = 0; iUid < nUid; iUid++) { + if (tDecodeU64(pCoder, &uid) < 0) return -1; + taosArrayPush(pRes->uidList, &uid); + } + if (tDecodeI64(pCoder, &pRes->skey) < 0) return -1; + if (tDecodeI64(pCoder, &pRes->ekey) < 0) return -1; + if (tDecodeI64v(pCoder, &pRes->affectedRows) < 0) return -1; + + return 0; +} int32_t tEncodeSMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pRsp) { if (tEncodeSTqOffsetVal(pEncoder, &pRsp->reqOffset) < 0) return -1; if (tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset) < 0) return -1; diff --git a/source/common/src/trow.c b/source/common/src/trow.c index c8a28d7f28f747b65fae3802bc392ac6163e5e1e..052b6ffe585cf6e89944384f6a4c7e3c09ecb8cb 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -34,6 +34,7 @@ const uint8_t tdVTypeByte[2][3] = {{ // declaration static uint8_t tdGetBitmapByte(uint8_t byte); static int32_t tdCompareColId(const void *arg1, const void *arg2); +static FORCE_INLINE int32_t compareKvRowColId(const void *key1, const void *key2); // static void dataColSetNEleNull(SDataCol *pCol, int nEle); @@ -339,9 +340,9 @@ int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType, int8 } bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode) { - int32_t nBytes = (bitmapMode == 0 ? numOfBits / TD_VTYPE_PARTS : numOfBits / TD_VTYPE_PARTS_I); - uint8_t vTypeByte = tdVTypeByte[bitmapMode][TD_VTYPE_NORM]; - uint8_t *qBitmap = (uint8_t*)pBitmap; + int32_t nBytes = (bitmapMode == 0 ? numOfBits / TD_VTYPE_PARTS : numOfBits / TD_VTYPE_PARTS_I); + uint8_t vTypeByte = tdVTypeByte[bitmapMode][TD_VTYPE_NORM]; + uint8_t *qBitmap = (uint8_t *)pBitmap; for (int i = 0; i < nBytes; ++i) { if (*qBitmap != vTypeByte) { return false; @@ -1045,13 +1046,28 @@ int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, int8_t bitmapMode) { return result; } -bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, uint32_t offset, col_id_t colIdx, SCellVal *pVal) { +bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVal) { if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { tdRowSetVal(pVal, TD_VTYPE_NORM, TD_ROW_KEY_ADDR(pRow)); return true; } + int16_t nCols = tdRowGetNCols(pRow) - 1; + if (nCols <= 0) { + pVal->valType = TD_VTYPE_NONE; + return true; + } + + SKvRowIdx *pColIdx = + (SKvRowIdx *)taosbsearch(&colId, TD_ROW_COL_IDX(pRow), nCols, sizeof(SKvRowIdx), compareKvRowColId, TD_EQ); + + if (!pColIdx) { + pVal->valType = TD_VTYPE_NONE; + return true; + } + void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow)); - tdGetKvRowValOfCol(pVal, pRow, pBitmap, offset, colIdx); + tdGetKvRowValOfCol(pVal, pRow, pBitmap, pColIdx->offset, + POINTER_DISTANCE(pColIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx)); return true; } @@ -1204,6 +1220,112 @@ static FORCE_INLINE int32_t compareKvRowColId(const void *key1, const void *key2 } } +int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow) { + STColumn *pTColumn; + SColVal *pColVal; + int32_t nColVal = taosArrayGetSize(pArray); + int32_t varDataLen = 0; + int32_t maxVarDataLen = 0; + int32_t iColVal = 0; + void *varBuf = NULL; + + ASSERT(nColVal > 1); + + for (int32_t iColumn = 0; iColumn < pTSchema->numOfCols; ++iColumn) { + pTColumn = &pTSchema->columns[iColumn]; + if (iColVal < nColVal) { + pColVal = (SColVal *)taosArrayGet(pArray, iColVal); + } else { + pColVal = NULL; + } + + if (iColumn == 0) { + ASSERT(pColVal->cid == pTColumn->colId); + ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP); + ASSERT(pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID); + } else { + if (IS_VAR_DATA_TYPE(pTColumn->type)) { + if (pColVal) { + varDataLen += (pColVal->value.nData + sizeof(VarDataLenT)); + if (maxVarDataLen < (pColVal->value.nData + sizeof(VarDataLenT))) { + maxVarDataLen = pColVal->value.nData + sizeof(VarDataLenT); + } + } else { + varDataLen += sizeof(VarDataLenT); + if (pTColumn->type == TSDB_DATA_TYPE_VARCHAR) { + varDataLen += CHAR_BYTES; + if (maxVarDataLen < CHAR_BYTES + sizeof(VarDataLenT)) { + maxVarDataLen = CHAR_BYTES + sizeof(VarDataLenT); + } + } else { + varDataLen += INT_BYTES; + if (maxVarDataLen < INT_BYTES + sizeof(VarDataLenT)) { + maxVarDataLen = INT_BYTES + sizeof(VarDataLenT); + } + } + } + } + } + + ++iColVal; + } + + *ppRow = (STSRow *)taosMemoryCalloc( + 1, sizeof(STSRow) + pTSchema->flen + varDataLen + TD_BITMAP_BYTES(pTSchema->numOfCols - 1)); + + if (!(*ppRow)) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (maxVarDataLen > 0) { + varBuf = taosMemoryMalloc(maxVarDataLen); + if (!varBuf) { + taosMemoryFreeClear(*ppRow); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + } + + SRowBuilder rb = {0}; + tdSRowInit(&rb, pTSchema->version); + tdSRowSetInfo(&rb, pTSchema->numOfCols, pTSchema->numOfCols, pTSchema->flen); + tdSRowResetBuf(&rb, *ppRow); + + iColVal = 0; + for (int32_t iColumn = 0; iColumn < pTSchema->numOfCols; ++iColumn) { + pTColumn = &pTSchema->columns[iColumn]; + + TDRowValT valType = TD_VTYPE_NORM; + const void *val = NULL; + if (iColVal < nColVal) { + pColVal = (SColVal *)taosArrayGet(pArray, iColVal); + if (pColVal->isNone) { + valType = TD_VTYPE_NONE; + } else if (pColVal->isNull) { + valType = TD_VTYPE_NULL; + } else if (IS_VAR_DATA_TYPE(pTColumn->type)) { + varDataSetLen(varBuf, pColVal->value.nData); + memcpy(varDataVal(varBuf), pColVal->value.pData, pColVal->value.nData); + val = varBuf; + } else { + val = (const void *)&pColVal->value.i64; + } + } else { + pColVal = NULL; + valType = TD_VTYPE_NONE; + } + + tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, pTColumn->offset, iColVal); + + ++iColVal; + } + + taosMemoryFreeClear(varBuf); + + return 0; +} + bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal) { if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { pVal->val = &pIter->pRow->ts; @@ -1593,7 +1715,6 @@ int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBou } else { pBuilder->rowType = TD_ROW_TP; } - pBuilder->flen = flen; pBuilder->nCols = nCols; pBuilder->nBoundCols = nBoundCols; @@ -1855,4 +1976,36 @@ void tdSTSRowIterReset(STSRowIter *pIter, STSRow *pRow) { void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema) { pIter->pSchema = pSchema; pIter->maxColId = pSchema->columns[pSchema->numOfCols - 1].colId; -} \ No newline at end of file +} + +void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColVal) { + STColumn *pTColumn = &pTSchema->columns[iCol]; + SCellVal cv; + SValue value; + + ASSERT(iCol > 0); + + if (TD_IS_TP_ROW(pRow)) { + tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv); + } else if (TD_IS_KV_ROW(pRow)) { + ASSERT(iCol > 0); + tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv); + } else { + ASSERT(0); + } + + if (tdValTypeIsNone(cv.valType)) { + *pColVal = COL_VAL_NONE(pTColumn->colId, pTColumn->type); + } else if (tdValTypeIsNull(cv.valType)) { + *pColVal = COL_VAL_NULL(pTColumn->colId, pTColumn->type); + } else { + if (IS_VAR_DATA_TYPE(pTColumn->type)) { + value.nData = varDataLen(cv.val); + value.pData = varDataVal(cv.val); + } else { + tGetValue(cv.val, &value, pTColumn->type); + } + + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value); + } +} diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 5bc95825270439446802d38f3e9eaaec68eb2bdf..1f7347203dcada7e1ca1f1632ffd46941c98c27b 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -350,6 +350,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_COMMIT_OFFSET, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_COMMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index beefc502e77967d958b35ec3f84c024bf3650115..3913e3fda8a2598ddc4546899f57c904c07f8c69 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -107,7 +107,7 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf const STraceId *trace = &pMsg->info.traceId; dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg); - int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL); // no response here + int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL); // no response here dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index d70ed09920584c666a188e19e3c7e42beb29baa2..436282d9fedc03a7ec64d31f77aa6211a0c0f124 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "dmMgmt.h" #include "dmNodes.h" +#include "index.h" #include "qworker.h" static bool dmRequireNode(SDnode *pDnode, SMgmtWrapper *pWrapper) { @@ -213,6 +214,7 @@ void dmCleanupDnode(SDnode *pDnode) { dmCleanupServer(pDnode); dmClearVars(pDnode); rpcCleanup(); + indexCleanup(); dDebug("dnode is closed, ptr:%p", pDnode); } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 6770cd578aa512b639906a080d13d0a3f4d057be..156afb09fca3156dc47e1bf42bf4c42d25908ff9 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -1373,9 +1373,9 @@ char *buildRetension(SArray *pRetension) { static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, int32_t rows, int64_t numOfTables, bool sysDb, ESdbStatus objStatus, bool sysinfo) { int32_t cols = 0; + int32_t bytes = pShow->pMeta->pSchemas[cols].bytes; + char *buf = taosMemoryMalloc(bytes); - int32_t bytes = pShow->pMeta->pSchemas[cols].bytes; - char *buf = taosMemoryMalloc(bytes); const char *name = mndGetDbStr(pDb->name); if (name != NULL) { STR_WITH_MAXSIZE_TO_VARSTR(buf, name, bytes); @@ -1383,11 +1383,11 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in STR_WITH_MAXSIZE_TO_VARSTR(buf, "NULL", bytes); } - char *status = "ready"; - if (objStatus == SDB_STATUS_CREATING) status = "creating"; - if (objStatus == SDB_STATUS_DROPPING) status = "dropping"; - char statusB[24] = {0}; - STR_WITH_SIZE_TO_VARSTR(statusB, status, strlen(status)); + char *statusStr = "ready"; + if (objStatus == SDB_STATUS_CREATING) statusStr = "creating"; + if (objStatus == SDB_STATUS_DROPPING) statusStr = "dropping"; + char statusVstr[24] = {0}; + STR_WITH_SIZE_TO_VARSTR(statusVstr, statusStr, strlen(statusStr)); if (sysDb || !sysinfo) { for (int32_t i = 0; i < pShow->numOfColumns; ++i) { @@ -1397,7 +1397,7 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in } else if (i == 3) { colDataAppend(pColInfo, rows, (const char *)&numOfTables, false); } else if (i == 20) { - colDataAppend(pColInfo, rows, statusB, false); + colDataAppend(pColInfo, rows, statusVstr, false); } else { colDataAppendNULL(pColInfo, rows); } @@ -1405,7 +1405,6 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in } else { SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, buf, false); - taosMemoryFree(buf); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, (const char *)&pDb->createdTime, false); @@ -1419,30 +1418,29 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.replications, false); - const char *src = pDb->cfg.strict ? "strict" : "no_strict"; - char strict[24] = {0}; - STR_WITH_SIZE_TO_VARSTR(strict, src, strlen(src)); + const char *strictStr = pDb->cfg.strict ? "strict" : "no_strict"; + char strictVstr[24] = {0}; + STR_WITH_SIZE_TO_VARSTR(strictVstr, strictStr, strlen(strictStr)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)strict, false); + colDataAppend(pColInfo, rows, (const char *)strictVstr, false); - char tmp[128] = {0}; - int32_t len = 0; - len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%dm", pDb->cfg.daysPerFile); - varDataSetLen(tmp, len); + char durationVstr[128] = {0}; + int32_t len = sprintf(&durationVstr[VARSTR_HEADER_SIZE], "%dm", pDb->cfg.daysPerFile); + varDataSetLen(durationVstr, len); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)tmp, false); + colDataAppend(pColInfo, rows, (const char *)durationVstr, false); + char keepVstr[128] = {0}; if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { - len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, + len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep0); } else { - len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, + len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2); } - - varDataSetLen(tmp, len); + varDataSetLen(keepVstr, len); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)tmp, false); + colDataAppend(pColInfo, rows, (const char *)keepVstr, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.buffer, false); @@ -1469,68 +1467,49 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.compression, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - - STR_WITH_SIZE_TO_VARSTR(strict, src, strlen(src)); -#if 0 - char cacheModel[24] = {0}; - bool null = false; - if (pDb->cfg.cacheLastRow == 0) { - STR_TO_VARSTR(cacheModel, "no_cache"); - } else if (pDb->cfg.cacheLastRow == 1) { - STR_TO_VARSTR(cacheModel, "last_row_cache") - } else { - null = true; - } - colDataAppend(pColInfo, rows, cacheModel, null); -#endif colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheLastRow, false); - char *prec = NULL; + const char *precStr = NULL; switch (pDb->cfg.precision) { case TSDB_TIME_PRECISION_MILLI: - prec = TSDB_TIME_PRECISION_MILLI_STR; + precStr = TSDB_TIME_PRECISION_MILLI_STR; break; case TSDB_TIME_PRECISION_MICRO: - prec = TSDB_TIME_PRECISION_MICRO_STR; + precStr = TSDB_TIME_PRECISION_MICRO_STR; break; case TSDB_TIME_PRECISION_NANO: - prec = TSDB_TIME_PRECISION_NANO_STR; + precStr = TSDB_TIME_PRECISION_NANO_STR; break; default: - prec = "none"; + precStr = "none"; break; } - - char t[10] = {0}; - STR_WITH_SIZE_TO_VARSTR(t, prec, 2); + char precVstr[10] = {0}; + STR_WITH_SIZE_TO_VARSTR(precVstr, precStr, 2); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)t, false); + colDataAppend(pColInfo, rows, (const char *)precVstr, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.numOfStables, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)statusB, false); - - // pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - // colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.schemaless, false); - - char *p = buildRetension(pDb->cfg.pRetensions); + colDataAppend(pColInfo, rows, (const char *)statusVstr, false); + char *rentensionVstr = buildRetension(pDb->cfg.pRetensions); pColInfo = taosArrayGet(pBlock->pDataBlock, cols); - if (p == NULL) { + if (rentensionVstr == NULL) { colDataAppendNULL(pColInfo, rows); } else { - colDataAppend(pColInfo, rows, (const char *)p, false); - taosMemoryFree(p); + colDataAppend(pColInfo, rows, (const char *)rentensionVstr, false); + taosMemoryFree(rentensionVstr); } } + + taosMemoryFree(buf); } static void setInformationSchemaDbCfg(SDbObj *pDbObj) { - ASSERT(pDbObj != NULL); - strncpy(pDbObj->name, TSDB_INFORMATION_SCHEMA_DB, tListLen(pDbObj->name)); - + tstrncpy(pDbObj->name, TSDB_INFORMATION_SCHEMA_DB, tListLen(pDbObj->name)); pDbObj->createdTime = 0; pDbObj->cfg.numOfVgroups = 0; pDbObj->cfg.strict = 1; @@ -1539,9 +1518,7 @@ static void setInformationSchemaDbCfg(SDbObj *pDbObj) { } static void setPerfSchemaDbCfg(SDbObj *pDbObj) { - ASSERT(pDbObj != NULL); - strncpy(pDbObj->name, TSDB_PERFORMANCE_SCHEMA_DB, tListLen(pDbObj->name)); - + tstrncpy(pDbObj->name, TSDB_PERFORMANCE_SCHEMA_DB, tListLen(pDbObj->name)); pDbObj->createdTime = 0; pDbObj->cfg.numOfVgroups = 0; pDbObj->cfg.strict = 1; @@ -1585,14 +1562,11 @@ static int32_t mndRetrieveDbs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc while (numOfRows < rowsCapacity) { pShow->pIter = sdbFetchAll(pSdb, SDB_DB, pShow->pIter, (void **)&pDb, &objStatus); - if (pShow->pIter == NULL) { - break; - } + if (pShow->pIter == NULL) break; if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb) == 0) { int32_t numOfTables = 0; sdbTraverse(pSdb, SDB_VGROUP, mndGetTablesOfDbFp, &numOfTables, NULL, NULL); - dumpDbInfoData(pBlock, pDb, pShow, numOfRows, numOfTables, false, objStatus, sysinfo); numOfRows++; } diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 174fe6dab50b4c17743304a9054b4431318adc7d..24c4f2912c82ce001398340609f11d28d7111f15 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -44,8 +44,12 @@ target_sources( "src/tsdb/tsdbMemTable.c" "src/tsdb/tsdbRead.c" "src/tsdb/tsdbReadImpl.c" + "src/tsdb/tsdbCache.c" "src/tsdb/tsdbWrite.c" + "src/tsdb/tsdbReaderWriter.c" + "src/tsdb/tsdbUtil.c" "src/tsdb/tsdbSnapshot.c" + "src/tsdb/tsdbCacheRead.c" # tq "src/tq/tq.c" diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 4dc11a48158022c578ba2d5734a3f112c12a05c1..f0718e3cc48f0dfd0cf93291c1a4dfbc5d9e6ea2 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -28,7 +28,6 @@ #include "tcommon.h" #include "tfs.h" -#include "tmallocator.h" #include "tmsg.h" #include "trow.h" @@ -52,10 +51,10 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs); void vnodeDestroy(const char *path, STfs *pTfs); SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb); void vnodeClose(SVnode *pVnode); -int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg); +int32_t vnodePreProcessReq(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp); int32_t vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); -int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); @@ -70,6 +69,10 @@ int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader); int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData); int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen); +int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list); +int32_t vnodeGetCtbIdList(SVnode *pVnode, int64_t suid, SArray *list); +void * vnodeGetIdx(SVnode *pVnode); +void * vnodeGetIvtIdx(SVnode *pVnode); void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); @@ -89,7 +92,7 @@ typedef struct SMetaFltParam { tb_uid_t suid; int16_t cid; int16_t type; - char *val; + char * val; bool reverse; int (*filterFunc)(void *a, void *b, int16_t type); @@ -110,33 +113,33 @@ int32_t metaTbCursorNext(SMTbCursor *pTbCur); // tsdb // typedef struct STsdb STsdb; -typedef void *tsdbReaderT; - -#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1 -#define BLOCK_LOAD_TABLE_SEQ_ORDER 2 -#define BLOCK_LOAD_TABLE_RR_ORDER 3 - -int32_t tsdbSetTableId(tsdbReaderT reader, int64_t uid); -int32_t tsdbSetTableList(tsdbReaderT reader, SArray *tableList); -tsdbReaderT tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, SArray *tableList, uint64_t qId, - uint64_t taskId); -tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *groupList, uint64_t qId, - void *pMemRef); -int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo); -bool isTsdbCacheLastRow(tsdbReaderT *pReader); -int32_t tsdbGetAllTableList(SMeta *pMeta, uint64_t uid, SArray *list); -int32_t tsdbGetCtbIdList(SMeta *pMeta, int64_t suid, SArray *list); -int32_t tsdbGetStbIdList(SMeta *pMeta, int64_t suid, SArray *list); -void *tsdbGetIdx(SMeta *pMeta); -void *tsdbGetIvtIdx(SMeta *pMeta); -int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT *pHandle); - -bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle); -void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo); -int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg ***pBlockStatis, bool *allHave); -SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList); -void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond *pCond, int32_t tWinIdx); -void tsdbCleanupReadHandle(tsdbReaderT queryHandle); +typedef struct STsdbReader STsdbReader; + +#define BLOCK_LOAD_OFFSET_ORDER 1 +#define BLOCK_LOAD_TABLESEQ_ORDER 2 +#define BLOCK_LOAD_EXTERN_ORDER 3 + +#define LASTROW_RETRIEVE_TYPE_ALL 0x1 +#define LASTROW_RETRIEVE_TYPE_SINGLE 0x2 + +int32_t tsdbSetTableId(STsdbReader *pReader, int64_t uid); +int32_t tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, SArray *pTableList, STsdbReader **ppReader, + const char *idstr); +void tsdbReaderClose(STsdbReader *pReader); +bool tsdbNextDataBlock(STsdbReader *pReader); +void tsdbRetrieveDataBlockInfo(STsdbReader *pReader, SDataBlockInfo *pDataBlockInfo); +int32_t tsdbRetrieveDataBlockStatisInfo(STsdbReader *pReader, SColumnDataAgg ***pBlockStatis, bool *allHave); +SArray *tsdbRetrieveDataBlock(STsdbReader *pTsdbReadHandle, SArray *pColumnIdList); +int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond, int32_t tWinIdx); +int32_t tsdbGetFileBlocksDistInfo(STsdbReader *pReader, STableBlockDistInfo *pTableBlockInfo); +int64_t tsdbGetNumOfRowsInMemTable(STsdbReader *pHandle); +void * tsdbGetIdx(SMeta *pMeta); +void * tsdbGetIvtIdx(SMeta *pMeta); + +int32_t tsdbLastRowReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t *colId, int32_t numOfCols, + void **pReader); +int32_t tsdbRetrieveLastRow(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds); +int32_t tsdbLastrowReaderClose(void *pReader); // tq @@ -208,7 +211,7 @@ struct SMetaEntry { int8_t type; int8_t flags; // TODO: need refactor? tb_uid_t uid; - char *name; + char * name; union { struct { SSchemaWrapper schemaRow; @@ -219,7 +222,7 @@ struct SMetaEntry { int64_t ctime; int32_t ttlDays; int32_t commentLen; - char *comment; + char * comment; tb_uid_t suid; uint8_t *pTags; } ctbEntry; @@ -227,7 +230,7 @@ struct SMetaEntry { int64_t ctime; int32_t ttlDays; int32_t commentLen; - char *comment; + char * comment; int32_t ncid; // next column id SSchemaWrapper schemaRow; } ntbEntry; @@ -241,17 +244,17 @@ struct SMetaEntry { struct SMetaReader { int32_t flags; - SMeta *pMeta; + SMeta * pMeta; SDecoder coder; SMetaEntry me; - void *pBuf; + void * pBuf; int32_t szBuf; }; struct SMTbCursor { - TBC *pDbc; - void *pKey; - void *pVal; + TBC * pDbc; + void * pKey; + void * pVal; int32_t kLen; int32_t vLen; SMetaReader mr; diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h index 7f7b3fa88515c73f885d963e4073679578f71f5f..2d6edae0e7c12af6352571fb64c371133e33c14f 100644 --- a/source/dnode/vnode/src/inc/sma.h +++ b/source/dnode/vnode/src/inc/sma.h @@ -62,6 +62,7 @@ struct STSmaStat { struct SRSmaStat { SSma *pSma; + int64_t submitVer; int64_t refId; // shared by fetch tasks void *tmrHandle; // shared by fetch tasks int8_t triggerStat; // shared by fetch tasks @@ -84,6 +85,7 @@ struct SSmaStat { #define RSMA_TRIGGER_STAT(r) (&(r)->triggerStat) #define RSMA_RUNNING_STAT(r) (&(r)->runningStat) #define RSMA_REF_ID(r) ((r)->refId) +#define RSMA_SUBMIT_VER(r) ((r)->submitVer) enum { TASK_TRIGGER_STAT_INIT = 0, @@ -208,11 +210,15 @@ struct STFInfo { // specific fields union { struct { - int64_t applyVer[2]; + int64_t submitVer; } qTaskInfo; }; }; +enum { + TD_FTYPE_RSMA_QTASKINFO = 0, +}; + struct STFile { uint8_t state; STFInfo info; diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 657b55a0c651a360176cca30acf48ebda4ec1059..0f65a536e0538912637625bb8d9ee7de35a443f2 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -32,99 +32,220 @@ extern "C" { #define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) // clang-format on -typedef struct TSDBROW TSDBROW; -typedef struct TSDBKEY TSDBKEY; -typedef struct TABLEID TABLEID; -typedef struct SDelOp SDelOp; - -static int tsdbKeyCmprFn(const void *p1, const void *p2); - +typedef struct TSDBROW TSDBROW; +typedef struct TABLEID TABLEID; +typedef struct TSDBKEY TSDBKEY; +typedef struct SDelData SDelData; +typedef struct SDelIdx SDelIdx; +typedef struct STbData STbData; +typedef struct SMemTable SMemTable; +typedef struct STbDataIter STbDataIter; +typedef struct STable STable; +typedef struct SMapData SMapData; +typedef struct SBlockIdx SBlockIdx; +typedef struct SBlock SBlock; +typedef struct SBlockStatis SBlockStatis; +typedef struct SAggrBlkCol SAggrBlkCol; +typedef struct SColData SColData; +typedef struct SBlockDataHdr SBlockDataHdr; +typedef struct SBlockData SBlockData; +typedef struct SDelFile SDelFile; +typedef struct STsdbCacheFile STsdbCacheFile; +typedef struct SHeadFile SHeadFile; +typedef struct SDataFile SDataFile; +typedef struct SLastFile SLastFile; +typedef struct SSmaFile SSmaFile; +typedef struct SDFileSet SDFileSet; +typedef struct SDataFWriter SDataFWriter; +typedef struct SDataFReader SDataFReader; +typedef struct SDelFWriter SDelFWriter; +typedef struct SDelFReader SDelFReader; +typedef struct SRowIter SRowIter; +typedef struct STsdbFS STsdbFS; +typedef struct SRowMerger SRowMerger; +typedef struct STsdbFSState STsdbFSState; + +#define TSDB_MAX_SUBBLOCKS 8 +#define TSDB_FHDR_SIZE 512 + +#define HAS_NONE ((int8_t)0x1) +#define HAS_NULL ((int8_t)0x2) +#define HAS_VALUE ((int8_t)0x4) + +#define VERSION_MIN 0 +#define VERSION_MAX INT64_MAX + +#define TSDBKEY_MIN ((TSDBKEY){.ts = TSKEY_MIN, .version = VERSION_MIN}) +#define TSDBKEY_MAX ((TSDBKEY){.ts = TSKEY_MAX, .version = VERSION_MAX}) + +// tsdbUtil.c ============================================================================================== +// TSDBROW +#define TSDBROW_TS(ROW) (((ROW)->type == 0) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow]) +#define TSDBROW_VERSION(ROW) (((ROW)->type == 0) ? (ROW)->version : (ROW)->pBlockData->aVersion[(ROW)->iRow]) +#define TSDBROW_SVERSION(ROW) TD_ROW_SVER((ROW)->pTSRow) +#define TSDBROW_KEY(ROW) ((TSDBKEY){.version = TSDBROW_VERSION(ROW), .ts = TSDBROW_TS(ROW)}) +#define tsdbRowFromTSRow(VERSION, TSROW) ((TSDBROW){.type = 0, .version = (VERSION), .pTSRow = (TSROW)}) +#define tsdbRowFromBlockData(BLOCKDATA, IROW) ((TSDBROW){.type = 1, .pBlockData = (BLOCKDATA), .iRow = (IROW)}) +void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal); +int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow); +int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow); +int32_t tsdbRowCmprFn(const void *p1, const void *p2); +// SRowIter +void tRowIterInit(SRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema); +SColVal *tRowIterNext(SRowIter *pIter); +// SRowMerger +int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema); +void tRowMergerClear(SRowMerger *pMerger); +int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow); +int32_t tRowMergerGetRow(SRowMerger *pMerger, STSRow **ppRow); +// TABLEID +int32_t tTABLEIDCmprFn(const void *p1, const void *p2); +// TSDBKEY +int32_t tsdbKeyCmprFn(const void *p1, const void *p2); +#define MIN_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) < 0) ? (KEY1) : (KEY2)) +#define MAX_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) > 0) ? (KEY1) : (KEY2)) +// SBlockCol +int32_t tPutBlockCol(uint8_t *p, void *ph); +int32_t tGetBlockCol(uint8_t *p, void *ph); +int32_t tBlockColCmprFn(const void *p1, const void *p2); +// SBlock +void tBlockReset(SBlock *pBlock); +int32_t tPutBlock(uint8_t *p, void *ph); +int32_t tGetBlock(uint8_t *p, void *ph); +int32_t tBlockCmprFn(const void *p1, const void *p2); +bool tBlockHasSma(SBlock *pBlock); +// SBlockIdx +void tBlockIdxReset(SBlockIdx *pBlockIdx); +int32_t tPutBlockIdx(uint8_t *p, void *ph); +int32_t tGetBlockIdx(uint8_t *p, void *ph); +int32_t tCmprBlockIdx(void const *lhs, void const *rhs); +// SColdata +void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn); +void tColDataReset(SColData *pColData); +void tColDataClear(void *ph); +int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal); +int32_t tColDataGetValue(SColData *pColData, int32_t iRow, SColVal *pColVal); +int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest); +// SBlockData +#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0) +#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1) +#define tBlockDataFirstKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA)) +#define tBlockDataLastKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA)) +int32_t tBlockDataInit(SBlockData *pBlockData); +void tBlockDataReset(SBlockData *pBlockData); +int32_t tBlockDataSetSchema(SBlockData *pBlockData, STSchema *pTSchema); +void tBlockDataClearData(SBlockData *pBlockData); +void tBlockDataClear(SBlockData *pBlockData); +int32_t tBlockDataAddColData(SBlockData *pBlockData, int32_t iColData, SColData **ppColData); +int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema); +int32_t tBlockDataMerge(SBlockData *pBlockData1, SBlockData *pBlockData2, SBlockData *pBlockData); +int32_t tBlockDataCopy(SBlockData *pBlockDataSrc, SBlockData *pBlockDataDest); +SColData *tBlockDataGetColDataByIdx(SBlockData *pBlockData, int32_t idx); +void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData); +// SDelIdx +int32_t tPutDelIdx(uint8_t *p, void *ph); +int32_t tGetDelIdx(uint8_t *p, void *ph); +int32_t tCmprDelIdx(void const *lhs, void const *rhs); +// SDelData +int32_t tPutDelData(uint8_t *p, void *ph); +int32_t tGetDelData(uint8_t *p, void *ph); +// SMapData +#define tMapDataInit() ((SMapData){0}) +void tMapDataReset(SMapData *pMapData); +void tMapDataClear(SMapData *pMapData); +int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *)); +void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)); +int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *), + int32_t (*tItemCmprFn)(const void *, const void *), void *pItem); +int32_t tPutMapData(uint8_t *p, SMapData *pMapData); +int32_t tGetMapData(uint8_t *p, SMapData *pMapData); +// other +int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision); +void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey); +int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline); +void tsdbCalcColDataSMA(SColData *pColData, SColumnDataAgg *pColAgg); // tsdbMemTable ============================================================================================== -typedef struct STbData STbData; -typedef struct SMemTable SMemTable; -typedef struct STbDataIter STbDataIter; -typedef struct SMergeInfo SMergeInfo; -typedef struct STable STable; - // SMemTable int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable); void tsdbMemTableDestroy(SMemTable *pMemTable); void tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData); - // STbDataIter -int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter); -void *tsdbTbDataIterDestroy(STbDataIter *pIter); -void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter); -bool tsdbTbDataIterNext(STbDataIter *pIter); -bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow); - +int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter); +void *tsdbTbDataIterDestroy(STbDataIter *pIter); +void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter); +TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter); +bool tsdbTbDataIterNext(STbDataIter *pIter); +// STbData +int32_t tsdbGetNRowsInTbData(STbData *pTbData); // tsdbFile.c ============================================================================================== -typedef int32_t TSDB_FILE_T; -typedef struct SDFInfo SDFInfo; -typedef struct SDFile SDFile; -typedef struct SDFileSet SDFileSet; - -// SDFile -void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype); -void tsdbInitDFileEx(SDFile *pDFile, SDFile *pODFile); -int tsdbOpenDFile(SDFile *pDFile, int flags); -void tsdbCloseDFile(SDFile *pDFile); -int64_t tsdbSeekDFile(SDFile *pDFile, int64_t offset, int whence); -int64_t tsdbWriteDFile(SDFile *pDFile, void *buf, int64_t nbyte); -void tsdbUpdateDFileMagic(SDFile *pDFile, void *pCksm); -int tsdbAppendDFile(SDFile *pDFile, void *buf, int64_t nbyte, int64_t *offset); -int tsdbRemoveDFile(SDFile *pDFile); -int64_t tsdbReadDFile(SDFile *pDFile, void *buf, int64_t nbyte); -int tsdbCopyDFile(SDFile *pSrc, SDFile *pDest); -int tsdbEncodeSDFile(void **buf, SDFile *pDFile); -void *tsdbDecodeSDFile(STsdb *pRepo, void *buf, SDFile *pDFile); -int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType); -int tsdbUpdateDFileHeader(SDFile *pDFile); -int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo); -int tsdbParseDFilename(const char *fname, int *vid, int *fid, TSDB_FILE_T *ftype, uint32_t *version); - -// SDFileSet -void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint32_t ver); -void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet); -int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet); -void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet); -int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet); -void *tsdbDecodeDFileSetEx(void *buf, SDFileSet *pSet); -int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to); -int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet *pSet, bool updateHeader); -int tsdbUpdateDFileSetHeader(SDFileSet *pSet); -int tsdbScanAndTryFixDFileSet(STsdb *pRepo, SDFileSet *pSet); -void tsdbCloseDFileSet(SDFileSet *pSet); -int tsdbOpenDFileSet(SDFileSet *pSet, int flags); -void tsdbRemoveDFileSet(SDFileSet *pSet); -int tsdbCopyDFileSet(SDFileSet *pSrc, SDFileSet *pDest); -void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY *minKey, TSKEY *maxKey); - +typedef enum { TSDB_HEAD_FILE = 0, TSDB_DATA_FILE, TSDB_LAST_FILE, TSDB_SMA_FILE } EDataFileT; +void tsdbDataFileName(STsdb *pTsdb, SDFileSet *pDFileSet, EDataFileT ftype, char fname[]); +bool tsdbFileIsSame(SDFileSet *pDFileSet1, SDFileSet *pDFileSet2, EDataFileT ftype); +int32_t tsdbUpdateDFileHdr(TdFilePtr pFD, SDFileSet *pSet, EDataFileT ftype); +int32_t tsdbDFileRollback(STsdb *pTsdb, SDFileSet *pSet, EDataFileT ftype); +int32_t tPutDataFileHdr(uint8_t *p, SDFileSet *pSet, EDataFileT ftype); +int32_t tPutDelFile(uint8_t *p, SDelFile *pDelFile); +int32_t tGetDelFile(uint8_t *p, SDelFile *pDelFile); +int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet); +int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet); +// SDelFile +void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]); // tsdbFS.c ============================================================================================== -typedef struct STsdbFS STsdbFS; -typedef struct SFSIter SFSIter; -typedef struct STsdbFSMeta STsdbFSMeta; - -STsdbFS *tsdbNewFS(const STsdbKeepCfg *pCfg); -void *tsdbFreeFS(STsdbFS *pfs); -int tsdbOpenFS(STsdb *pRepo); -void tsdbCloseFS(STsdb *pRepo); -void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd); -int tsdbEndFSTxn(STsdb *pRepo); -int tsdbEndFSTxnWithError(STsdbFS *pfs); -void tsdbUpdateFSTxnMeta(STsdbFS *pfs, STsdbFSMeta *pMeta); -// void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile); -int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet); - -void tsdbFSIterInit(SFSIter *pIter, STsdbFS *pfs, int direction); -void tsdbFSIterSeek(SFSIter *pIter, int fid); -SDFileSet *tsdbFSIterNext(SFSIter *pIter); -int tsdbLoadMetaCache(STsdb *pRepo, bool recoverMeta); -int tsdbRLockFS(STsdbFS *pFs); -int tsdbWLockFS(STsdbFS *pFs); -int tsdbUnLockFS(STsdbFS *pFs); - -// structs +int32_t tsdbFSOpen(STsdb *pTsdb, STsdbFS **ppFS); +int32_t tsdbFSClose(STsdbFS *pFS); +int32_t tsdbFSBegin(STsdbFS *pFS); +int32_t tsdbFSCommit(STsdbFS *pFS); +int32_t tsdbFSRollback(STsdbFS *pFS); + +int32_t tsdbFSStateUpsertDelFile(STsdbFSState *pState, SDelFile *pDelFile); +int32_t tsdbFSStateUpsertDFileSet(STsdbFSState *pState, SDFileSet *pSet); +SDelFile *tsdbFSStateGetDelFile(STsdbFSState *pState); +SDFileSet *tsdbFSStateGetDFileSet(STsdbFSState *pState, int32_t fid); +// tsdbReaderWriter.c ============================================================================================== +// SDataFWriter +int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pSet); +int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync); +int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter); +int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx, uint8_t **ppBuf); +int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *pMapData, uint8_t **ppBuf, SBlockIdx *pBlockIdx); +int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2, + SBlockIdx *pBlockIdx, SBlock *pBlock, int8_t cmprAlg); + +SDFileSet *tsdbDataFWriterGetWSet(SDataFWriter *pWriter); +// SDataFReader +int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet); +int32_t tsdbDataFReaderClose(SDataFReader **ppReader); +int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx, uint8_t **ppBuf); +int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *pMapData, uint8_t **ppBuf); +int32_t tsdbReadColData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBlock, int16_t *aColId, int32_t nCol, + SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2); +int32_t tsdbReadBlockData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBlock, SBlockData *pBlockData, + uint8_t **ppBuf1, uint8_t **ppBuf2); +int32_t tsdbReadBlockSma(SDataFReader *pReader, SBlock *pBlock, SArray *aColumnDataAgg, uint8_t **ppBuf); +// SDelFWriter +int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb); +int32_t tsdbDelFWriterClose(SDelFWriter **ppWriter, int8_t sync); +int32_t tsdbWriteDelData(SDelFWriter *pWriter, SArray *aDelData, uint8_t **ppBuf, SDelIdx *pDelIdx); +int32_t tsdbWriteDelIdx(SDelFWriter *pWriter, SArray *aDelIdx, uint8_t **ppBuf); +int32_t tsdbUpdateDelFileHdr(SDelFWriter *pWriter); +// SDelFReader +int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb, uint8_t **ppBuf); +int32_t tsdbDelFReaderClose(SDelFReader **ppReader); +int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, uint8_t **ppBuf); +int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx, uint8_t **ppBuf); + +// tsdbCache +int32_t tsdbOpenCache(STsdb *pTsdb); +void tsdbCloseCache(SLRUCache *pCache); +int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row); +int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, STSRow *row, bool dup); +int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); +int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); +int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h); + +int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); + +// structs ======================= typedef struct { int minFid; int midFid; @@ -132,22 +253,19 @@ typedef struct { TSKEY minKey; } SRtn; -#define TSDB_DATA_DIR_LEN 6 // adapt accordingly struct STsdb { char *path; SVnode *pVnode; TdThreadMutex mutex; - char dir[TSDB_DATA_DIR_LEN]; bool repoLocked; STsdbKeepCfg keepCfg; SMemTable *mem; SMemTable *imem; SRtn rtn; STsdbFS *fs; + SLRUCache *lruCache; }; -#if 1 // ====================================== - struct STable { uint64_t suid; uint64_t uid; @@ -155,43 +273,6 @@ struct STable { STSchema *pCacheSchema; // cached cache }; -// int tsdbPrepareCommit(STsdb *pTsdb); -typedef enum { - TSDB_FILE_HEAD = 0, // .head - TSDB_FILE_DATA, // .data - TSDB_FILE_LAST, // .last - TSDB_FILE_SMAD, // .smad(Block-wise SMA) - TSDB_FILE_SMAL, // .smal(Block-wise SMA) - TSDB_FILE_MAX, // - TSDB_FILE_META, // meta -} E_TSDB_FILE_T; - -struct SDFInfo { - uint32_t magic; - uint32_t fver; - uint32_t len; - uint32_t totalBlocks; - uint32_t totalSubBlocks; - uint32_t offset; - uint64_t size; - uint64_t tombSize; -}; - -struct SDFile { - SDFInfo info; - STfsFile f; - TdFilePtr pFile; - uint8_t state; -}; - -struct SDFileSet { - int fid; - int8_t state; // -128~127 - uint8_t ver; // 0~255, DFileSet version - uint16_t reserve; - SDFile files[TSDB_FILE_MAX]; -}; - struct TSDBKEY { int64_t version; TSKEY ts; @@ -211,13 +292,21 @@ typedef struct SMemSkipList { SMemSkipListNode *pTail; } SMemSkipList; +struct SDelDataInfo { + tb_uid_t suid; + tb_uid_t uid; +}; + struct STbData { tb_uid_t suid; tb_uid_t uid; - TSDBKEY minKey; - TSDBKEY maxKey; - SDelOp *pHead; - SDelOp *pTail; + TSKEY minKey; + TSKEY maxKey; + int64_t minVersion; + int64_t maxVersion; + int32_t maxSkmVer; + SDelData *pHead; + SDelData *pTail; SMemSkipList sl; }; @@ -225,157 +314,87 @@ struct SMemTable { SRWLatch latch; STsdb *pTsdb; int32_t nRef; - TSDBKEY minKey; - TSDBKEY maxKey; + TSKEY minKey; + TSKEY maxKey; + int64_t minVersion; + int64_t maxVersion; int64_t nRow; - int64_t nDelOp; - SArray *aTbData; // SArray -}; - -struct STsdbFSMeta { - uint32_t version; // Commit version from 0 to increase - int64_t totalPoints; // total points - int64_t totalStorage; // Uncompressed total storage -}; - -// ================== -typedef struct { - STsdbFSMeta meta; // FS meta - SDFile cacheFile; // cache file - SDFile tombstone; // tomestome file - SArray *df; // data file array - SArray *sf; // sma data file array v2f1900.index_name_1 -} SFSStatus; - -struct STsdbFS { - TdThreadRwlock lock; - - SFSStatus *cstatus; // current status - bool intxn; - SFSStatus *nstatus; // new status + int64_t nDel; + SArray *aTbData; // SArray }; -#define REPO_ID(r) TD_VID((r)->pVnode) -#define REPO_CFG(r) (&(r)->pVnode->config.tsdbCfg) -#define REPO_KEEP_CFG(r) (&(r)->keepCfg) -#define REPO_FS(r) ((r)->fs) -#define REPO_META(r) ((r)->pVnode->pMeta) -#define REPO_TFS(r) ((r)->pVnode->pTfs) -#define IS_REPO_LOCKED(r) ((r)->repoLocked) - int tsdbLockRepo(STsdb *pTsdb); int tsdbUnlockRepo(STsdb *pTsdb); -static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STsdb *pTsdb, STable *pTable, bool lock, bool copy, - int32_t version) { - if ((version < 0) || (schemaVersion(pTable->pSchema) == version)) { - return pTable->pSchema; - } - - if (!pTable->pCacheSchema || (schemaVersion(pTable->pCacheSchema) != version)) { - taosMemoryFreeClear(pTable->pCacheSchema); - pTable->pCacheSchema = metaGetTbTSchema(REPO_META(pTsdb), pTable->uid, version); - } - return pTable->pCacheSchema; -} - -// tsdbMemTable.h -struct SMergeInfo { - int rowsInserted; - int rowsUpdated; - int rowsDeleteSucceed; - int rowsDeleteFailed; - int nOperations; - TSKEY keyFirst; - TSKEY keyLast; -}; - -static void *taosTMalloc(size_t size); -static void *taosTCalloc(size_t nmemb, size_t size); -static void *taosTRealloc(void *ptr, size_t size); -static void *taosTZfree(void *ptr); -static size_t taosTSizeof(void *ptr); -static void taosTMemset(void *ptr, int c); - struct TSDBROW { - int64_t version; - STSRow *pTSRow; + int8_t type; // 0 for row from tsRow, 1 for row from block data + union { + struct { + int64_t version; + STSRow *pTSRow; + }; + struct { + SBlockData *pBlockData; + int32_t iRow; + }; + }; }; -static FORCE_INLINE STSRow *tsdbNextIterRow(STbDataIter *pIter) { - TSDBROW row; - - if (pIter == NULL) return NULL; - - if (tsdbTbDataIterGet(pIter, &row)) { - return row.pTSRow; - } - - return NULL; -} - -static FORCE_INLINE TSKEY tsdbNextIterKey(STbDataIter *pIter) { - STSRow *row = tsdbNextIterRow(pIter); - if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL; - - return TD_ROW_KEY(row); -} - -// tsdbReadImpl -typedef struct SReadH SReadH; - -typedef struct { - uint64_t suid; - uint64_t uid; - uint32_t len; - uint32_t offset; - uint32_t hasLast : 2; - uint32_t numOfBlocks : 30; - TSDBKEY maxKey; -} SBlockIdx; - -typedef enum { - TSDB_SBLK_VER_0 = 0, - TSDB_SBLK_VER_MAX, -} ESBlockVer; - -#define SBlockVerLatest TSDB_SBLK_VER_0 - -typedef struct { - uint8_t last : 1; - uint8_t hasDupKey : 1; // 0: no dup TS key, 1: has dup TS key(since supporting Multi-Version) - uint8_t blkVer : 6; - uint8_t numOfSubBlocks; - col_id_t numOfCols; // not including timestamp column - uint32_t len; // data block length - uint32_t keyLen : 20; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols - uint32_t algorithm : 4; - uint32_t reserve : 8; - col_id_t numOfBSma; - uint16_t numOfRows; - int64_t offset; - uint64_t aggrStat : 1; - uint64_t aggrOffset : 63; - TSDBKEY minKey; - TSDBKEY maxKey; -} SBlock; +struct SBlockIdx { + int64_t suid; + int64_t uid; + TSKEY minKey; + TSKEY maxKey; + int64_t minVersion; + int64_t maxVersion; + int64_t offset; + int64_t size; +}; -typedef struct { - int32_t delimiter; // For recovery usage - uint64_t suid; - uint64_t uid; - SBlock blocks[]; -} SBlockInfo; +struct SMapData { + int32_t nItem; + int32_t *aOffset; + int32_t nData; + uint8_t *pData; +}; typedef struct { - int16_t colId; - uint16_t type : 6; - uint16_t blen : 10; // 0 no bitmap if all rows are NORM, > 0 bitmap length - uint32_t len; // data length + bitmap length - uint32_t offset; + int16_t cid; + int8_t type; + int8_t smaOn; + int8_t flag; // HAS_NONE|HAS_NULL|HAS_VALUE + int32_t offset; + int32_t szBitmap; // bitmap size + int32_t szOffset; // size of offset, only for variant-length data type + int32_t szValue; // compressed column value size + int32_t szOrigin; // original column value size (only save for variant data type) } SBlockCol; typedef struct { + int32_t nRow; + int8_t cmprAlg; + int64_t offset; // block data offset + int32_t szBlockCol; // SBlockCol size + int32_t szVersion; // VERSION size + int32_t szTSKEY; // TSKEY size + int32_t szBlock; // total block size + int64_t sOffset; // sma offset + int32_t nSma; // sma size +} SSubBlock; + +struct SBlock { + TSDBKEY minKey; + TSDBKEY maxKey; + int64_t minVersion; + int64_t maxVersion; + int32_t nRow; + int8_t last; + int8_t hasDup; + int8_t nSubBlock; + SSubBlock aSubBlock[TSDB_MAX_SUBBLOCKS]; +}; + +struct SAggrBlkCol { int16_t colId; int16_t maxIndex; int16_t minIndex; @@ -383,330 +402,139 @@ typedef struct { int64_t sum; int64_t max; int64_t min; -} SAggrBlkCol; - -typedef struct { - int32_t delimiter; // For recovery usage - int32_t numOfCols; // For recovery usage - uint64_t uid; // For recovery usage - SBlockCol cols[]; -} SBlockData; - -typedef void SAggrBlkData; // SBlockCol cols[]; - -struct SReadH { - STsdb *pRepo; - SDFileSet rSet; // FSET to read - SArray *aBlkIdx; // SBlockIdx array - STable *pTable; // table to read - SBlockIdx *pBlkIdx; // current reading table SBlockIdx - int cidx; - SBlockInfo *pBlkInfo; - SBlockData *pBlkData; // Block info - SAggrBlkData *pAggrBlkData; // Aggregate Block info - SDataCols *pDCols[2]; - void *pBuf; // buffer - void *pCBuf; // compression buffer - void *pExBuf; // extra buffer }; -#define TSDB_READ_REPO(rh) ((rh)->pRepo) -#define TSDB_READ_REPO_ID(rh) REPO_ID(TSDB_READ_REPO(rh)) -#define TSDB_READ_FSET(rh) (&((rh)->rSet)) -#define TSDB_READ_TABLE(rh) ((rh)->pTable) -#define TSDB_READ_TABLE_UID(rh) ((rh)->pTable->uid) -#define TSDB_READ_HEAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_HEAD) -#define TSDB_READ_DATA_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_DATA) -#define TSDB_READ_LAST_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_LAST) -#define TSDB_READ_SMAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAD) -#define TSDB_READ_SMAL_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAL) -#define TSDB_READ_BUF(rh) ((rh)->pBuf) -#define TSDB_READ_COMP_BUF(rh) ((rh)->pCBuf) -#define TSDB_READ_EXBUF(rh) ((rh)->pExBuf) - -#define TSDB_BLOCK_STATIS_SIZE(ncols, blkVer) (sizeof(SBlockData) + sizeof(SBlockCol) * (ncols) + sizeof(TSCKSUM)) - -static FORCE_INLINE size_t tsdbBlockStatisSize(int nCols, uint32_t blkVer) { - switch (blkVer) { - case TSDB_SBLK_VER_0: - default: - return TSDB_BLOCK_STATIS_SIZE(nCols, 0); - } -} - -#define TSDB_BLOCK_AGGR_SIZE(ncols, blkVer) (sizeof(SAggrBlkCol) * (ncols) + sizeof(TSCKSUM)) - -static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) { - switch (blkVer) { - case TSDB_SBLK_VER_0: - default: - return TSDB_BLOCK_AGGR_SIZE(nCols, 0); - } -} - -int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo); -void tsdbDestroyReadH(SReadH *pReadh); -int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); -void tsdbCloseAndUnsetFSet(SReadH *pReadh); -int tsdbLoadBlockIdx(SReadH *pReadh); -int tsdbSetReadTable(SReadH *pReadh, STable *pTable); -int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget); -int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlockInfo); -int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, int numOfColsIds, - bool mergeBitmap); -int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock); -int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx); -void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx); -void tsdbGetBlockStatis(SReadH *pReadh, SColumnDataAgg *pStatis, int numOfCols, SBlock *pBlock); - -static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) { - void *pBuf = *ppBuf; - size_t tsize = taosTSizeof(pBuf); - - if (tsize < size) { - if (tsize == 0) tsize = 1024; - - while (tsize < size) { - tsize *= 2; - } - - *ppBuf = taosTRealloc(pBuf, tsize); - if (*ppBuf == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - } - - return 0; -} - -// tsdbMemory -static FORCE_INLINE void *taosTMalloc(size_t size) { - if (size <= 0) return NULL; - - void *ret = taosMemoryMalloc(size + sizeof(size_t)); - if (ret == NULL) return NULL; - - *(size_t *)ret = size; - - return (void *)((char *)ret + sizeof(size_t)); -} - -static FORCE_INLINE void *taosTCalloc(size_t nmemb, size_t size) { - size_t tsize = nmemb * size; - void *ret = taosTMalloc(tsize); - if (ret == NULL) return NULL; - - taosTMemset(ret, 0); - return ret; -} - -static FORCE_INLINE size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; } - -static FORCE_INLINE void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); } - -static FORCE_INLINE void *taosTRealloc(void *ptr, size_t size) { - if (ptr == NULL) return taosTMalloc(size); - - if (size <= taosTSizeof(ptr)) return ptr; +struct SColData { + int16_t cid; + int8_t type; + int8_t smaOn; + int32_t nVal; + uint8_t flag; + uint8_t *pBitMap; + int32_t *aOffset; + int32_t nData; + uint8_t *pData; +}; - void *tptr = (void *)((char *)ptr - sizeof(size_t)); - size_t tsize = size + sizeof(size_t); - void *tptr1 = taosMemoryRealloc(tptr, tsize); - if (tptr1 == NULL) return NULL; - tptr = tptr1; +struct SBlockData { + int32_t nRow; + int64_t *aVersion; + TSKEY *aTSKEY; + SArray *aIdx; // SArray + SArray *aColData; // SArray +}; - *(size_t *)tptr = size; +// ================== TSDB global config +extern bool tsdbForceKeepFile; - return (void *)((char *)tptr + sizeof(size_t)); -} +#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC +#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC -static FORCE_INLINE void *taosTZfree(void *ptr) { - if (ptr) { - taosMemoryFree((void *)((char *)ptr - sizeof(size_t))); - } - return NULL; -} +struct TABLEID { + tb_uid_t suid; + tb_uid_t uid; +}; -// tsdbCommit +struct STbDataIter { + STbData *pTbData; + int8_t backward; + SMemSkipListNode *pNode; + TSDBROW *pRow; + TSDBROW row; +}; -void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn); +struct SDelData { + int64_t version; + TSKEY sKey; + TSKEY eKey; + SDelData *pNext; +}; -static FORCE_INLINE int TSDB_KEY_FID(TSKEY key, int32_t minutes, int8_t precision) { - if (key < 0) { - return (int)((key + 1) / tsTickPerMin[precision] / minutes - 1); - } else { - return (int)((key / tsTickPerMin[precision] / minutes)); - } -} +struct SDelIdx { + tb_uid_t suid; + tb_uid_t uid; + int64_t offset; + int64_t size; +}; -static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) { - if (fid >= pRtn->maxFid) { - return 0; - } else if (fid >= pRtn->midFid) { - return 1; - } else if (fid >= pRtn->minFid) { - return 2; - } else { - return -1; - } -} +struct SDelFile { + int64_t commitID; + int64_t size; + int64_t offset; +}; -// tsdbFile -#define TSDB_FILE_HEAD_SIZE 512 -#define TSDB_FILE_DELIMITER 0xF00AFA0F -#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF -#define TSDB_IVLD_FID INT_MIN -#define TSDB_FILE_STATE_OK 0 -#define TSDB_FILE_STATE_BAD 1 - -#define TSDB_FILE_F(tf) (&((tf)->f)) -#define TSDB_FILE_PFILE(tf) ((tf)->pFile) -#define TSDB_FILE_FULL_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_OPENED(tf) (TSDB_FILE_PFILE(tf) != NULL) -#define TSDB_FILE_CLOSED(tf) (!TSDB_FILE_OPENED(tf)) -#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_PFILE(f) = NULL) -#define TSDB_FILE_LEVEL(tf) (TSDB_FILE_F(tf)->did.level) -#define TSDB_FILE_ID(tf) (TSDB_FILE_F(tf)->did.id) -#define TSDB_FILE_DID(tf) (TSDB_FILE_F(tf)->did) -#define TSDB_FILE_REL_NAME(tf) (TSDB_FILE_F(tf)->rname) -#define TSDB_FILE_ABS_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_PFILE(tf)) -#define TSDB_FILE_STATE(tf) ((tf)->state) -#define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s)) -#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) -#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD) - -typedef enum { - TSDB_FS_VER_0 = 0, - TSDB_FS_VER_MAX, -} ETsdbFsVer; - -#define TSDB_LATEST_FVER TSDB_FS_VER_0 // latest version for DFile -#define TSDB_LATEST_SFS_VER TSDB_FS_VER_0 // latest version for 'current' file - -static FORCE_INLINE uint32_t tsdbGetDFSVersion(TSDB_FILE_T fType) { // latest version for DFile - switch (fType) { - case TSDB_FILE_HEAD: // .head - case TSDB_FILE_DATA: // .data - case TSDB_FILE_LAST: // .last - case TSDB_FILE_SMAD: // .smad(Block-wise SMA) - case TSDB_FILE_SMAL: // .smal(Block-wise SMA) - default: - return TSDB_LATEST_FVER; - } -} +#pragma pack(push, 1) +struct SBlockDataHdr { + uint32_t delimiter; + int64_t suid; + int64_t uid; +}; +#pragma pack(pop) -// =============== SDFileSet - -#define TSDB_LATEST_FSET_VER 0 -#define TSDB_FSET_FID(s) ((s)->fid) -#define TSDB_FSET_STATE(s) ((s)->state) -#define TSDB_FSET_VER(s) ((s)->ver) -#define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t)) -#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) -#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) -#define TSDB_FSET_SET_CLOSED(s) \ - do { \ - for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ - TSDB_FILE_SET_CLOSED(TSDB_DFILE_IN_SET(s, ftype)); \ - } \ - } while (0); -#define TSDB_FSET_FSYNC(s) \ - do { \ - for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ - TSDB_FILE_FSYNC(TSDB_DFILE_IN_SET(s, ftype)); \ - } \ - } while (0); - -static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet *pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (TSDB_FILE_IS_BAD(TSDB_DFILE_IN_SET(pSet, ftype))) { - return false; - } - } - - return true; -} +struct SHeadFile { + int64_t commitID; + int64_t size; + int64_t offset; +}; -// tsdbFS -// ================== TSDB global config -extern bool tsdbForceKeepFile; +struct SDataFile { + int64_t commitID; + int64_t size; +}; -// ================== CURRENT file header info -typedef struct { - uint32_t version; // Current file system version (relating to code) - uint32_t len; // Encode content length (including checksum) -} SFSHeader; - -// ================== TSDB File System Meta -#define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus) -#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) -#define FS_IN_TXN(pfs) (pfs)->intxn -#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) -#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) - -struct SFSIter { - int direction; - uint64_t version; // current FS version - STsdbFS *pfs; - int index; // used to position next fset when version the same - int fid; // used to seek when version is changed - SDFileSet *pSet; +struct SLastFile { + int64_t commitID; + int64_t size; }; -#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC -#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC +struct SSmaFile { + int64_t commitID; + int64_t size; +}; -struct TABLEID { - tb_uid_t suid; - tb_uid_t uid; +struct SDFileSet { + SDiskID diskId; + int32_t fid; + SHeadFile fHead; + SDataFile fData; + SLastFile fLast; + SSmaFile fSma; }; -struct SDelOp { - int64_t version; - TSKEY sKey; // included - TSKEY eKey; // included - SDelOp *pNext; +struct SRowIter { + TSDBROW *pRow; + STSchema *pTSchema; + SColVal colVal; + int32_t i; +}; +struct SRowMerger { + STSchema *pTSchema; + int64_t version; + SArray *pArray; // SArray }; -typedef struct { - tb_uid_t suid; - tb_uid_t uid; - int64_t version; - TSKEY sKey; - TSKEY eKey; -} SDelInfo; - -static FORCE_INLINE int tsdbKeyCmprFn(const void *p1, const void *p2) { - TSDBKEY *pKey1 = (TSDBKEY *)p1; - TSDBKEY *pKey2 = (TSDBKEY *)p2; - - if (pKey1->ts < pKey2->ts) { - return -1; - } else if (pKey1->ts > pKey2->ts) { - return 1; - } - - if (pKey1->version < pKey2->version) { - return -1; - } else if (pKey1->version > pKey2->version) { - return 1; - } - - return 0; -} +struct STsdbFSState { + SDelFile *pDelFile; + SArray *aDFileSet; // SArray + SDelFile delFile; +}; -struct STbDataIter { - STbData *pTbData; - int8_t backward; - SMemSkipListNode *pNode; +struct STsdbFS { + STsdb *pTsdb; + TdThreadRwlock lock; + int8_t inTxn; + STsdbFSState *cState; + STsdbFSState *nState; }; -#endif +struct SDelFWriter { + STsdb *pTsdb; + SDelFile fDel; + TdFilePtr pWriteH; +}; #ifdef __cplusplus } #endif -#endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file +#endif /*_TD_VNODE_TSDB_H_*/ diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 4f81e9d62a452ca697c6be0a2fad738bf40fd857..ae659dc396c4d34ab713126c5009741a338cd1eb 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -20,6 +20,7 @@ #include "filter.h" #include "qworker.h" #include "sync.h" +#include "tRealloc.h" #include "tchecksum.h" #include "tcoding.h" #include "tcompare.h" @@ -27,15 +28,15 @@ #include "tdatablock.h" #include "tdb.h" #include "tencode.h" -#include "tref.h" #include "tfs.h" #include "tglobal.h" #include "tjson.h" #include "tlist.h" #include "tlockfree.h" #include "tlosertree.h" -#include "tmallocator.h" +#include "tlrucache.h" #include "tmsgcb.h" +#include "tref.h" #include "tskiplist.h" #include "tstream.h" #include "ttime.h" @@ -94,6 +95,7 @@ int metaTtlDropTable(SMeta* pMeta, int64_t ttl, SArray* tbUids); int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp); SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline); STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver); +int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema); int metaGetTableEntryByName(SMetaReader* pReader, const char* name); tb_uid_t metaGetTableEntryUidByName(SMeta* pMeta, const char* name); int metaGetTbNum(SMeta* pMeta); @@ -127,9 +129,7 @@ int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSub int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkRsp* pRsp); int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); -tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* tableList, uint64_t qId, - uint64_t taskId); -tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, +STsdbReader tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, void* pMemRef); int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever); int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader); @@ -157,6 +157,7 @@ int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg); +int32_t tsdbGetStbIdList(SMeta* pMeta, int64_t suid, SArray* list); SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid, const char* stbFullName, int32_t vgId); @@ -171,6 +172,7 @@ int32_t smaPostCommit(SSma* pSma); int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg); int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg); +int64_t tdRSmaGetMaxSubmitVer(SSma* pSma, int8_t level); int32_t tdProcessRSmaCreate(SVnode* pVnode, SVCreateStbReq* pReq); int32_t tdProcessRSmaSubmit(SSma* pSma, void* pMsg, int32_t inputType); @@ -196,9 +198,9 @@ typedef struct { // SVState struct SVState { - // int64_t processed; int64_t committed; int64_t applied; + int64_t commitID; }; struct SVnodeInfo { @@ -240,7 +242,7 @@ struct SVnode { SSink* pSink; tsem_t canCommit; int64_t sync; - int32_t syncCount; + int32_t blockCount; tsem_t syncSem; SQHandle* pQuery; }; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 85106f46c2258ee726c82412993f44396ecfe391..a198f52beeda0e7600ae32e18eae7f0b8e4508dd 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -31,7 +31,7 @@ void metaReaderClear(SMetaReader *pReader) { } int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) { - SMeta * pMeta = pReader->pMeta; + SMeta *pMeta = pReader->pMeta; STbDbKey tbDbKey = {.version = version, .uid = uid}; // query table.db @@ -54,7 +54,7 @@ _err: } int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) { - SMeta * pMeta = pReader->pMeta; + SMeta *pMeta = pReader->pMeta; int64_t version; // query uid.idx @@ -68,7 +68,7 @@ int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) { } int metaGetTableEntryByName(SMetaReader *pReader, const char *name) { - SMeta * pMeta = pReader->pMeta; + SMeta *pMeta = pReader->pMeta; tb_uid_t uid; // query name.idx @@ -82,7 +82,7 @@ int metaGetTableEntryByName(SMetaReader *pReader, const char *name) { } tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) { - void * pData = NULL; + void *pData = NULL; int nData = 0; tb_uid_t uid = 0; @@ -138,7 +138,7 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) { int metaTbCursorNext(SMTbCursor *pTbCur) { int ret; - void * pBuf; + void *pBuf; STbCfg tbCfg; for (;;) { @@ -159,7 +159,7 @@ int metaTbCursorNext(SMTbCursor *pTbCur) { } SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { - void * pData = NULL; + void *pData = NULL; int nData = 0; int64_t version; SSchemaWrapper schema = {0}; @@ -218,9 +218,9 @@ _err: return NULL; } -int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){ - TBC * pCur; - int ret = tdbTbcOpen(pMeta->pTtlIdx, &pCur, NULL); +int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList) { + TBC *pCur; + int ret = tdbTbcOpen(pMeta->pTtlIdx, &pCur, NULL); if (ret < 0) { return ret; } @@ -235,13 +235,13 @@ int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){ } void *pKey = NULL; - int kLen = 0; - while(1){ + int kLen = 0; + while (1) { ret = tdbTbcPrev(pCur, &pKey, &kLen, NULL, NULL); if (ret < 0) { break; } - ttlKey = *(STtlIdxKey*)pKey; + ttlKey = *(STtlIdxKey *)pKey; taosArrayPush(uidList, &ttlKey.uid); } tdbTbcClose(pCur); @@ -252,11 +252,11 @@ int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){ } struct SMCtbCursor { - SMeta * pMeta; - TBC * pCur; + SMeta *pMeta; + TBC *pCur; tb_uid_t suid; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int kLen; int vLen; }; @@ -388,15 +388,15 @@ tb_uid_t metaStbCursorNext(SMStbCursor *pStbCur) { if (ret < 0) { return 0; } - return *(tb_uid_t*)pStbCur->pKey; + return *(tb_uid_t *)pStbCur->pKey; } STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { // SMetaReader mr = {0}; - STSchema * pTSchema = NULL; + STSchema *pTSchema = NULL; SSchemaWrapper *pSW = NULL; STSchemaBuilder sb = {0}; - SSchema * pSchema; + SSchema *pSchema; pSW = metaGetTableSchema(pMeta, uid, sver, 0); if (!pSW) return NULL; @@ -415,6 +415,51 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { return pTSchema; } +int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema **ppTSchema) { + int32_t code = 0; + STSchema *pTSchema = NULL; + SSkmDbKey skmDbKey = {.uid = suid ? suid : uid, .sver = sver}; + void *pData = NULL; + int nData = 0; + + // query + metaRLock(pMeta); + if (tdbTbGet(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), &pData, &nData) < 0) { + code = TSDB_CODE_NOT_FOUND; + metaULock(pMeta); + goto _err; + } + metaULock(pMeta); + + // decode + SDecoder dc = {0}; + SSchemaWrapper schema; + SSchemaWrapper *pSchemaWrapper = &schema; + + tDecoderInit(&dc, pData, nData); + tDecodeSSchemaWrapper(&dc, pSchemaWrapper); + tDecoderClear(&dc); + + // convert + STSchemaBuilder sb = {0}; + + tdInitTSchemaBuilder(&sb, pSchemaWrapper->version); + for (int i = 0; i < pSchemaWrapper->nCols; i++) { + SSchema *pSchema = pSchemaWrapper->pSchema + i; + tdAddColToSchema(&sb, pSchema->type, pSchema->flags, pSchema->colId, pSchema->bytes); + } + pTSchema = tdGetSchemaFromBuilder(&sb); + tdDestroyTSchemaBuilder(&sb); + + *ppTSchema = pTSchema; + taosMemoryFree(pSchemaWrapper->pSchema); + return code; + +_err: + *ppTSchema = NULL; + return code; +} + int metaGetTbNum(SMeta *pMeta) { // TODO // ASSERT(0); @@ -422,11 +467,11 @@ int metaGetTbNum(SMeta *pMeta) { } typedef struct { - SMeta * pMeta; - TBC * pCur; + SMeta *pMeta; + TBC *pCur; tb_uid_t uid; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int kLen; int vLen; } SMSmaCursor; @@ -498,7 +543,7 @@ tb_uid_t metaSmaCursorNext(SMSmaCursor *pSmaCur) { STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) { STSmaWrapper *pSW = NULL; - SArray * pSmaIds = NULL; + SArray *pSmaIds = NULL; if (!(pSmaIds = metaGetSmaIdsByTable(pMeta, uid))) { return NULL; @@ -522,7 +567,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) { metaReaderInit(&mr, pMeta, 0); int64_t smaId; int smaIdx = 0; - STSma * pTSma = NULL; + STSma *pTSma = NULL; for (int i = 0; i < pSW->number; ++i) { smaId = *(tb_uid_t *)taosArrayGet(pSmaIds, i); if (metaGetTableEntryByUid(&mr, smaId) < 0) { @@ -570,7 +615,7 @@ _err: } STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { - STSma * pTSma = NULL; + STSma *pTSma = NULL; SMetaReader mr = {0}; metaReaderInit(&mr, pMeta, 0); if (metaGetTableEntryByUid(&mr, indexUid) < 0) { @@ -592,7 +637,7 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { } SArray *metaGetSmaIdsByTable(SMeta *pMeta, tb_uid_t uid) { - SArray * pUids = NULL; + SArray *pUids = NULL; SSmaIdxKey *pSmaIdxKey = NULL; SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid); @@ -630,7 +675,7 @@ SArray *metaGetSmaIdsByTable(SMeta *pMeta, tb_uid_t uid) { } SArray *metaGetSmaTbUids(SMeta *pMeta) { - SArray * pUids = NULL; + SArray *pUids = NULL; SSmaIdxKey *pSmaIdxKey = NULL; tb_uid_t lastUid = 0; @@ -689,20 +734,20 @@ const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t type, STagVal *val) { } typedef struct { - SMeta * pMeta; - TBC * pCur; + SMeta *pMeta; + TBC *pCur; tb_uid_t suid; int16_t cid; int16_t type; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int32_t kLen; int32_t vLen; } SIdxCursor; int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { SIdxCursor *pCursor = NULL; - char * buf = NULL; + char *buf = NULL; int32_t maxSize = 0; int32_t ret = 0, valid = 0; @@ -721,7 +766,7 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { int32_t nKey = 0; int32_t nTagData = 0; - void * tagData = NULL; + void *tagData = NULL; if (param->val == NULL) { metaError("vgId:%d, failed to filter NULL data", TD_VID(pMeta->pVnode)); @@ -757,7 +802,7 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { goto END; } - void * entryKey = NULL, *entryVal = NULL; + void *entryKey = NULL, *entryVal = NULL; int32_t nEntryKey, nEntryVal; bool first = true; while (1) { diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 4e1b2db44a87457ab56a4d875411f54da6aad530..ff6915156c924968cef7bf9219d0a476d71ee6d5 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -523,6 +523,17 @@ static void tdDestroySDataBlockArray(SArray *pArray) { taosArrayDestroy(pArray); } +int64_t tdRSmaGetMaxSubmitVer(SSma *pSma, int8_t level) { + if (level == TSDB_RETENTION_L0) { + return pSma->pVnode->state.applied; + } + + SSmaEnv *pRSmaEnv = SMA_RSMA_ENV(pSma); + SRSmaStat *pRSmaStat = (SRSmaStat *)(SMA_ENV_STAT(pRSmaEnv)); + + return atomic_load_64(&pRSmaStat->submitVer); +} + static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) { SArray *pResult = NULL; SRSmaInfo *pRSmaInfo = pItem->pRsmaInfo; @@ -562,7 +573,7 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) goto _err; } - if (pReq && tdProcessSubmitReq(sinkTsdb, INT64_MAX, pReq) < 0) { + if (pReq && tdProcessSubmitReq(sinkTsdb, atomic_add_fetch_64(&pRSmaInfo->pStat->submitVer, 1), pReq) < 0) { taosMemoryFreeClear(pReq); goto _err; } @@ -814,6 +825,7 @@ static int32_t tdRSmaRestoreQTaskInfoReload(SSma *pSma, int64_t *committed) { } if (!taosCheckExistFile(TD_TFILE_FULL_NAME(&tFile))) { + *committed = 0; if (pVnode->state.committed > 0) { smaWarn("vgId:%d, rsma restore for version %" PRIi64 ", not start as %s not exist", TD_VID(pVnode), pVnode->state.committed, TD_TFILE_FULL_NAME(&tFile)); @@ -828,6 +840,18 @@ static int32_t tdRSmaRestoreQTaskInfoReload(SSma *pSma, int64_t *committed) { goto _err; } + STFInfo tFileInfo = {0}; + if (tdLoadTFileHeader(&tFile, &tFileInfo) < 0) { + goto _err; + } + + ASSERT(tFileInfo.qTaskInfo.submitVer > 0); + + SSmaEnv *pRSmaEnv = pSma->pRSmaEnv; + SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pRSmaEnv); + atomic_store_64(&pRSmaStat->submitVer, tFileInfo.qTaskInfo.submitVer); + smaDebug("%s:%d tFileInfo.qTaskInfo.submitVer = %" PRIi64, __func__, __LINE__, tFileInfo.qTaskInfo.submitVer); + SRSmaQTaskInfoIter fIter = {0}; if (tdRSmaQTaskInfoIterInit(&fIter, &tFile) < 0) { tdRSmaQTaskInfoIterDestroy(&fIter); @@ -1094,6 +1118,22 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat) { } STFile tFile = {0}; + if (RSMA_SUBMIT_VER(pRSmaStat) > 0) { + char qTaskInfoFName[TSDB_FILENAME_LEN]; + tdRSmaQTaskInfoGetFName(vid, pSma->pVnode->state.applied, qTaskInfoFName); + if (tdInitTFile(&tFile, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFName) < 0) { + smaError("vgId:%d, rsma persit, init %s failed since %s", vid, qTaskInfoFName, terrstr()); + goto _err; + } + if (tdCreateTFile(&tFile, true, TD_FTYPE_RSMA_QTASKINFO) < 0) { + smaError("vgId:%d, rsma persit, create %s failed since %s", vid, TD_TFILE_FULL_NAME(&tFile), terrstr()); + goto _err; + } + smaDebug("vgId:%d, rsma, serialize qTaskInfo, file %s created", vid, TD_TFILE_FULL_NAME(&tFile)); + + isFileCreated = true; + } + while (infoHash) { SRSmaInfo *pRSmaInfo = *(SRSmaInfo **)infoHash; for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) { @@ -1129,12 +1169,12 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat) { smaError("vgId:%d, rsma persit, init %s failed since %s", vid, qTaskInfoFName, terrstr()); goto _err; } - if (tdCreateTFile(&tFile, true, -1) < 0) { + if (tdCreateTFile(&tFile, true, TD_FTYPE_RSMA_QTASKINFO) < 0) { smaError("vgId:%d, rsma persit, create %s failed since %s", vid, TD_TFILE_FULL_NAME(&tFile), terrstr()); goto _err; } - smaDebug("vgId:%d, rsma, table %" PRIi64 " level %d serialize qTaskInfo, file %s created", vid, pRSmaInfo->suid, - i + 1, TD_TFILE_FULL_NAME(&tFile)); + smaDebug("vgId:%d, rsma, table %" PRIi64 " serialize qTaskInfo, file %s created", vid, pRSmaInfo->suid, + TD_TFILE_FULL_NAME(&tFile)); isFileCreated = true; } @@ -1161,6 +1201,7 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat) { } if (isFileCreated) { + tFile.info.qTaskInfo.submitVer = atomic_load_64(&pRSmaStat->submitVer); if (tdUpdateTFileHeader(&tFile) < 0) { smaError("vgId:%d, rsma, failed to update tfile %s header since %s", vid, TD_TFILE_FULL_NAME(&tFile), tstrerror(terrno)); diff --git a/source/dnode/vnode/src/sma/smaUtil.c b/source/dnode/vnode/src/sma/smaUtil.c index 14caf4144e831e44331b69c344bb65e297235870..2ce6d23648969eb965a43dcc97e91b450ffb21d1 100644 --- a/source/dnode/vnode/src/sma/smaUtil.c +++ b/source/dnode/vnode/src/sma/smaUtil.c @@ -32,6 +32,9 @@ static int32_t tdEncodeTFInfo(void **buf, STFInfo *pInfo) { tlen += taosEncodeFixedU32(buf, pInfo->ftype); tlen += taosEncodeFixedU32(buf, pInfo->fver); tlen += taosEncodeFixedI64(buf, pInfo->fsize); + if (pInfo->ftype == TD_FTYPE_RSMA_QTASKINFO) { + tlen += taosEncodeFixedI64(buf, pInfo->qTaskInfo.submitVer); + } return tlen; } @@ -41,6 +44,11 @@ static void *tdDecodeTFInfo(void *buf, STFInfo *pInfo) { buf = taosDecodeFixedU32(buf, &(pInfo->ftype)); buf = taosDecodeFixedU32(buf, &(pInfo->fver)); buf = taosDecodeFixedI64(buf, &(pInfo->fsize)); + // specific + if (pInfo->ftype == TD_FTYPE_RSMA_QTASKINFO) { + buf = taosDecodeFixedI64(buf, &(pInfo->qTaskInfo.submitVer)); + } + return buf; } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 5ce3cfab45f0c657c23fc861b06a352fc5317100..739c063f5aeaebe9a17b01cd3b7c551e09abff1a 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -462,8 +462,8 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { pHandle->execHandle.execTb.suid = req.suid; SArray* tbUidList = taosArrayInit(0, sizeof(int64_t)); - tsdbGetCtbIdList(pTq->pVnode->pMeta, req.suid, tbUidList); - tqDebug("vg %d, tq try get suid: %ld", TD_VID(pTq->pVnode), req.suid); + vnodeGetCtbIdList(pTq->pVnode, req.suid, tbUidList); + tqDebug("vg %d, tq try get suid: %ld", pTq->pVnode->config.vgId, req.suid); for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) { int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i); tqDebug("vg %d, idx %d, uid: %ld", TD_VID(pTq->pVnode), i, tbUid); diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index 398a09ecbc33dbd81efc344539159fc001c9b308..d46f12cf77577e1412fe0c6242da70c624467030 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -87,6 +87,7 @@ int32_t tqMetaOpen(STQ* pTq) { .reader = handle.execHandle.pExecReader[i], .meta = pTq->pVnode->pMeta, .pMsgCb = &pTq->pVnode->msgCb, + .vnode = pTq->pVnode, }; handle.execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(handle.execHandle.execCol.qmsg, &reader); ASSERT(handle.execHandle.execCol.task[i]); diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c index ef61897f914d1a95d1973a05291f59f4a39986a6..8561314431cc7e33e411408c4d68f3e6480552bc 100644 --- a/source/dnode/vnode/src/tq/tqOffset.c +++ b/source/dnode/vnode/src/tq/tqOffset.c @@ -85,6 +85,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) { void tqOffsetClose(STqOffsetStore* pStore) { tqOffsetSnapshot(pStore); taosHashCleanup(pStore->pHash); + taosMemoryFree(pStore); } STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey) { diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c new file mode 100644 index 0000000000000000000000000000000000000000..dc6fc36035de0f969b17df6a097db8c3145f7862 --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -0,0 +1,1178 @@ +/* + * 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 . + */ + +#include "tsdb.h" + +int32_t tsdbOpenCache(STsdb *pTsdb) { + int32_t code = 0; + SLRUCache *pCache = NULL; + // TODO: get cfg from vnode config: pTsdb->pVnode->config.lruCapacity + size_t cfgCapacity = 1024 * 1024; + + pCache = taosLRUCacheInit(cfgCapacity, -1, .5); + if (pCache == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + taosLRUCacheSetStrictCapacity(pCache, true); + +_err: + pTsdb->lruCache = pCache; + return code; +} + +void tsdbCloseCache(SLRUCache *pCache) { + if (pCache) { + taosLRUCacheEraseUnrefEntries(pCache); + + taosLRUCacheCleanup(pCache); + } +} + +static void getTableCacheKeyS(tb_uid_t uid, const char *cacheType, char *key, int *len) { + snprintf(key, 30, "%" PRIi64 "%s", uid, cacheType); + *len = strlen(key); +} + +static void getTableCacheKey(tb_uid_t uid, int cacheType, char *key, int *len) { + if (cacheType == 0) { // last_row + *(uint64_t *)key = (uint64_t)uid; + } else { // last + *(uint64_t *)key = ((uint64_t)uid) | 0x8000000000000000; + } + + *len = sizeof(uint64_t); +} + +static void deleteTableCacheLastrow(const void *key, size_t keyLen, void *value) { taosMemoryFree(value); } + +static int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + // getTableCacheKey(uid, "lr", key, &keyLen); + getTableCacheKey(uid, 0, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + STSRow *pRow = (STSRow *)taosLRUCacheValue(pCache, h); + if (pRow->ts <= eKey) { + taosLRUCacheRelease(pCache, h, true); + } else { + taosLRUCacheRelease(pCache, h, false); + } + + // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); + } + + return code; +} + +static int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + // getTableCacheKey(uid, "l", key, &keyLen); + getTableCacheKey(uid, 1, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + // clear last cache anyway, no matter where eKey ends. + taosLRUCacheRelease(pCache, h, true); + + // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); + } + + return code; +} + +int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, STSRow *row, bool dup) { + int32_t code = 0; + STSRow *cacheRow = NULL; + char key[32] = {0}; + int keyLen = 0; + + // getTableCacheKey(uid, "lr", key, &keyLen); + getTableCacheKey(uid, 0, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + cacheRow = (STSRow *)taosLRUCacheValue(pCache, h); + if (row->ts >= cacheRow->ts) { + if (row->ts == cacheRow->ts) { + STSRow *mergedRow; + SRowMerger merger = {0}; + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + + tRowMergerInit(&merger, &tsdbRowFromTSRow(0, cacheRow), pTSchema); + + tRowMerge(&merger, &tsdbRowFromTSRow(1, row)); + + tRowMergerGetRow(&merger, &mergedRow); + tRowMergerClear(&merger); + + taosMemoryFreeClear(pTSchema); + + row = mergedRow; + dup = false; + } + + if (TD_ROW_LEN(row) <= TD_ROW_LEN(cacheRow)) { + tdRowCpy(cacheRow, row); + if (!dup) { + taosMemoryFree(row); + } + + taosLRUCacheRelease(pCache, h, false); + } else { + taosLRUCacheRelease(pCache, h, true); + // tsdbCacheDeleteLastrow(pCache, uid, TSKEY_MAX); + if (dup) { + cacheRow = tdRowDup(row); + } else { + cacheRow = row; + } + _taos_lru_deleter_t deleter = deleteTableCacheLastrow; + LRUStatus status = taosLRUCacheInsert(pCache, key, keyLen, cacheRow, TD_ROW_LEN(cacheRow), deleter, NULL, + TAOS_LRU_PRIORITY_LOW); + if (status != TAOS_LRU_STATUS_OK) { + code = -1; + } + /* tsdbCacheInsertLastrow(pCache, uid, row, dup); */ + } + } + } else { + if (dup) { + cacheRow = tdRowDup(row); + } else { + cacheRow = row; + } + + _taos_lru_deleter_t deleter = deleteTableCacheLastrow; + LRUStatus status = + taosLRUCacheInsert(pCache, key, keyLen, cacheRow, TD_ROW_LEN(cacheRow), deleter, NULL, TAOS_LRU_PRIORITY_LOW); + if (status != TAOS_LRU_STATUS_OK) { + code = -1; + } + } + + return code; +} + +int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row) { + int32_t code = 0; + STSRow *cacheRow = NULL; + char key[32] = {0}; + int keyLen = 0; + + ((void)(row)); + + // getTableCacheKey(uid, "l", key, &keyLen); + getTableCacheKey(uid, 1, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + // clear last cache anyway, lazy load when get last lookup + taosLRUCacheRelease(pCache, h, true); + } + + return code; +} + +static tb_uid_t getTableSuidByUid(tb_uid_t uid, STsdb *pTsdb) { + tb_uid_t suid = 0; + + SMetaReader mr = {0}; + metaReaderInit(&mr, pTsdb->pVnode->pMeta, 0); + if (metaGetTableEntryByUid(&mr, uid) < 0) { + metaReaderClear(&mr); // table not esist + return 0; + } + + if (mr.me.type == TSDB_CHILD_TABLE) { + suid = mr.me.ctbEntry.suid; + } else if (mr.me.type == TSDB_NORMAL_TABLE) { + suid = 0; + } else { + suid = 0; + } + + metaReaderClear(&mr); + + return suid; +} + +static int32_t getTableDelDataFromDelIdx(SDelFReader *pDelReader, SDelIdx *pDelIdx, SArray *aDelData) { + int32_t code = 0; + + // SMapData delDataMap; + // SDelData delData; + + if (pDelIdx) { + // tMapDataReset(&delDataMap); + + // code = tsdbReadDelData(pDelReader, pDelIdx, &delDataMap, NULL); + code = tsdbReadDelData(pDelReader, pDelIdx, aDelData, NULL); + if (code) goto _err; + /* + for (int32_t iDelData = 0; iDelData < delDataMap.nItem; ++iDelData) { + code = tMapDataGetItemByIdx(&delDataMap, iDelData, &delData, tGetDelData); + if (code) goto _err; + + taosArrayPush(aDelData, &delData); + } + */ + } + +_err: + return code; +} + +static int32_t getTableDelDataFromTbData(STbData *pTbData, SArray *aDelData) { + int32_t code = 0; + SDelData *pDelData = pTbData ? pTbData->pHead : NULL; + + for (; pDelData; pDelData = pDelData->pNext) { + taosArrayPush(aDelData, pDelData); + } + + return code; +} + +static int32_t getTableDelData(STbData *pMem, STbData *pIMem, SDelFReader *pDelReader, SDelIdx *pDelIdx, + SArray *aDelData) { + int32_t code = 0; + + if (pMem) { + code = getTableDelDataFromTbData(pMem, aDelData); + if (code) goto _err; + } + + if (pIMem) { + code = getTableDelDataFromTbData(pIMem, aDelData); + if (code) goto _err; + } + + if (pDelIdx) { + code = getTableDelDataFromDelIdx(pDelReader, pDelIdx, aDelData); + if (code) goto _err; + } + +_err: + return code; +} + +static int32_t getTableDelSkyline(STbData *pMem, STbData *pIMem, SDelFReader *pDelReader, SDelIdx *pDelIdx, + SArray *aSkyline) { + int32_t code = 0; + SArray *aDelData = NULL; + + aDelData = taosArrayInit(32, sizeof(SDelData)); + code = getTableDelData(pMem, pIMem, pDelReader, pDelIdx, aDelData); + if (code) goto _err; + + size_t nDelData = taosArrayGetSize(aDelData); + if (nDelData > 0) { + code = tsdbBuildDeleteSkyline(aDelData, 0, (int32_t)(nDelData - 1), aSkyline); + if (code) goto _err; + } + + if (aDelData) { + taosArrayDestroy(aDelData); + } +_err: + return code; +} + +static int32_t getTableDelIdx(SDelFReader *pDelFReader, tb_uid_t suid, tb_uid_t uid, SDelIdx *pDelIdx) { + int32_t code = 0; + SArray *pDelIdxArray = NULL; + + // SMapData delIdxMap; + pDelIdxArray = taosArrayInit(32, sizeof(SDelIdx)); + SDelIdx idx = {.suid = suid, .uid = uid}; + + // tMapDataReset(&delIdxMap); + // code = tsdbReadDelIdx(pDelFReader, &delIdxMap, NULL); + code = tsdbReadDelIdx(pDelFReader, pDelIdxArray, NULL); + if (code) goto _err; + + // code = tMapDataSearch(&delIdxMap, &idx, tGetDelIdx, tCmprDelIdx, pDelIdx); + pDelIdx = taosArraySearch(pDelIdxArray, &idx, tCmprDelIdx, TD_EQ); + if (code) goto _err; + + if (pDelIdxArray) { + taosArrayDestroy(pDelIdxArray); + } +_err: + return code; +} + +typedef enum SFSNEXTROWSTATES { + SFSNEXTROW_FS, + SFSNEXTROW_FILESET, + SFSNEXTROW_BLOCKDATA, + SFSNEXTROW_BLOCKROW +} SFSNEXTROWSTATES; + +typedef struct SFSNextRowIter { + SFSNEXTROWSTATES state; // [input] + STsdb *pTsdb; // [input] + SBlockIdx *pBlockIdxExp; // [input] + int32_t nFileSet; + int32_t iFileSet; + SArray *aDFileSet; + SDataFReader *pDataFReader; + SArray *aBlockIdx; + // SMapData blockIdxMap; + // SBlockIdx blockIdx; + SBlockIdx *pBlockIdx; + SMapData blockMap; + int32_t nBlock; + int32_t iBlock; + SBlock block; + SBlockData blockData; + SBlockData *pBlockData; + int32_t nRow; + int32_t iRow; + TSDBROW row; +} SFSNextRowIter; + +static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) { + SFSNextRowIter *state = (SFSNextRowIter *)iter; + int32_t code = 0; + + switch (state->state) { + case SFSNEXTROW_FS: + state->aDFileSet = state->pTsdb->fs->cState->aDFileSet; + state->nFileSet = taosArrayGetSize(state->aDFileSet); + state->iFileSet = state->nFileSet - 1; + + state->pBlockData = NULL; + + case SFSNEXTROW_FILESET: { + SDFileSet *pFileSet = NULL; + if (--state->iFileSet >= 0) { + pFileSet = (SDFileSet *)taosArrayGet(state->aDFileSet, state->iFileSet); + } else { + // tBlockDataClear(&state->blockData); + if (state->pBlockData) { + tBlockDataClear(state->pBlockData); + state->pBlockData = NULL; + } + + *ppRow = NULL; + return code; + } + + code = tsdbDataFReaderOpen(&state->pDataFReader, state->pTsdb, pFileSet); + if (code) goto _err; + + // tMapDataReset(&state->blockIdxMap); + // code = tsdbReadBlockIdx(state->pDataFReader, &state->blockIdxMap, NULL); + if (!state->aBlockIdx) { + state->aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); + } else { + taosArrayClear(state->aBlockIdx); + } + code = tsdbReadBlockIdx(state->pDataFReader, state->aBlockIdx, NULL); + if (code) goto _err; + + /* if (state->pBlockIdx) { */ + /* tBlockIdxReset(state->blockIdx); */ + /* } */ + /* tBlockIdxReset(state->blockIdx); */ + /* code = tMapDataSearch(&state->blockIdxMap, state->pBlockIdxExp, tGetBlockIdx, tCmprBlockIdx, + * &state->blockIdx); + */ + state->pBlockIdx = taosArraySearch(state->aBlockIdx, state->pBlockIdxExp, tCmprBlockIdx, TD_EQ); + if (code) goto _err; + + tMapDataReset(&state->blockMap); + code = tsdbReadBlock(state->pDataFReader, state->pBlockIdx, &state->blockMap, NULL); + /* code = tsdbReadBlock(state->pDataFReader, &state->blockIdx, &state->blockMap, NULL); */ + if (code) goto _err; + + state->nBlock = state->blockMap.nItem; + state->iBlock = state->nBlock - 1; + + if (!state->pBlockData) { + state->pBlockData = &state->blockData; + + tBlockDataInit(&state->blockData); + } + } + case SFSNEXTROW_BLOCKDATA: + if (state->iBlock >= 0) { + SBlock block = {0}; + + tBlockReset(&block); + // tBlockDataReset(&state->blockData); + tBlockDataReset(state->pBlockData); + + tMapDataGetItemByIdx(&state->blockMap, state->iBlock, &block, tGetBlock); + /* code = tsdbReadBlockData(state->pDataFReader, &state->blockIdx, &block, &state->blockData, NULL, NULL); */ + code = tsdbReadBlockData(state->pDataFReader, state->pBlockIdx, &block, state->pBlockData, NULL, NULL); + if (code) goto _err; + + state->nRow = state->blockData.nRow; + state->iRow = state->nRow - 1; + + state->state = SFSNEXTROW_BLOCKROW; + } + case SFSNEXTROW_BLOCKROW: + if (state->iRow >= 0) { + state->row = tsdbRowFromBlockData(state->pBlockData, state->iRow); + *ppRow = &state->row; + + if (--state->iRow < 0) { + state->state = SFSNEXTROW_BLOCKDATA; + if (--state->iBlock < 0) { + tsdbDataFReaderClose(&state->pDataFReader); + state->pDataFReader = NULL; + + if (state->aBlockIdx) { + taosArrayDestroy(state->aBlockIdx); + state->aBlockIdx = NULL; + } + + state->state = SFSNEXTROW_FILESET; + } + } + } + + return code; + default: + ASSERT(0); + break; + } + +_err: + if (state->pDataFReader) { + tsdbDataFReaderClose(&state->pDataFReader); + state->pDataFReader = NULL; + } + if (state->aBlockIdx) { + taosArrayDestroy(state->aBlockIdx); + state->aBlockIdx = NULL; + } + if (state->pBlockData) { + // tBlockDataClear(&state->blockData); + tBlockDataClear(state->pBlockData); + state->pBlockData = NULL; + } + + *ppRow = NULL; + + return code; +} + +int32_t clearNextRowFromFS(void *iter) { + int32_t code = 0; + + SFSNextRowIter *state = (SFSNextRowIter *)iter; + if (!state) { + return code; + } + + if (state->pDataFReader) { + tsdbDataFReaderClose(&state->pDataFReader); + state->pDataFReader = NULL; + } + if (state->aBlockIdx) { + taosArrayDestroy(state->aBlockIdx); + state->aBlockIdx = NULL; + } + if (state->pBlockData) { + // tBlockDataClear(&state->blockData); + tBlockDataClear(state->pBlockData); + state->pBlockData = NULL; + } + + return code; +} + +typedef enum SMEMNEXTROWSTATES { + SMEMNEXTROW_ENTER, + SMEMNEXTROW_NEXT, +} SMEMNEXTROWSTATES; + +typedef struct SMemNextRowIter { + SMEMNEXTROWSTATES state; + STbData *pMem; // [input] + STbDataIter iter; // mem buffer skip list iterator +} SMemNextRowIter; + +static int32_t getNextRowFromMem(void *iter, TSDBROW **ppRow) { + SMemNextRowIter *state = (SMemNextRowIter *)iter; + int32_t code = 0; + + switch (state->state) { + case SMEMNEXTROW_ENTER: { + if (state->pMem != NULL) { + tsdbTbDataIterOpen(state->pMem, NULL, 1, &state->iter); + + TSDBROW *pMemRow = tsdbTbDataIterGet(&state->iter); + if (pMemRow) { + *ppRow = pMemRow; + state->state = SMEMNEXTROW_NEXT; + + return code; + } + } + + *ppRow = NULL; + + return code; + } + case SMEMNEXTROW_NEXT: + if (tsdbTbDataIterNext(&state->iter)) { + *ppRow = tsdbTbDataIterGet(&state->iter); + + return code; + } else { + *ppRow = NULL; + + return code; + } + default: + ASSERT(0); + break; + } + +_err: + *ppRow = NULL; + return code; +} + +static int32_t tsRowFromTsdbRow(STSchema *pTSchema, TSDBROW *pRow, STSRow **ppRow) { + int32_t code = 0; + + SColVal *pColVal = &(SColVal){0}; + + if (pRow->type == 0) { + *ppRow = tdRowDup(pRow->pTSRow); + } else { + SArray *pArray = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)); + if (pArray == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + TSDBKEY key = TSDBROW_KEY(pRow); + STColumn *pTColumn = &pTSchema->columns[0]; + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = key.ts}); + + if (taosArrayPush(pArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + for (int16_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) { + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + if (taosArrayPush(pArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + } + + code = tdSTSRowNew(pArray, pTSchema, ppRow); + if (code) goto _exit; + } + +_exit: + return code; +} + +static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int *iSkyline) { + bool deleted = false; + while (*iSkyline > 0) { + TSDBKEY *pItemBack = (TSDBKEY *)taosArrayGet(pSkyline, *iSkyline); + TSDBKEY *pItemFront = (TSDBKEY *)taosArrayGet(pSkyline, *iSkyline - 1); + + if (key->ts > pItemBack->ts) { + return false; + } else if (key->ts >= pItemFront->ts && key->ts <= pItemBack->ts) { + if ((key->version <= pItemFront->version || key->ts == pItemBack->ts && key->version <= pItemBack->version)) { + return true; + } else { + return false; + } + } else { + if (*iSkyline > 1) { + --*iSkyline; + } else { + return false; + } + } + } + + return deleted; +} + +typedef int32_t (*_next_row_fn_t)(void *iter, TSDBROW **ppRow); +typedef int32_t (*_next_row_clear_fn_t)(void *iter); + +typedef struct TsdbNextRowState { + TSDBROW *pRow; + bool stop; + bool next; + void *iter; + _next_row_fn_t nextRowFn; + _next_row_clear_fn_t nextRowClearFn; +} TsdbNextRowState; + +static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRow) { + int32_t code = 0; + SArray *pSkyline = NULL; + + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + int16_t nCol = pTSchema->numOfCols; + SArray *pColArray = taosArrayInit(nCol, sizeof(SColVal)); + + tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + STbData *pMem = NULL; + if (pTsdb->mem) { + tsdbGetTbDataFromMemTable(pTsdb->mem, suid, uid, &pMem); + } + + STbData *pIMem = NULL; + if (pTsdb->imem) { + tsdbGetTbDataFromMemTable(pTsdb->imem, suid, uid, &pIMem); + } + + *ppRow = NULL; + + pSkyline = taosArrayInit(32, sizeof(TSDBKEY)); + + SDelIdx delIdx; + + SDelFile *pDelFile = tsdbFSStateGetDelFile(pTsdb->fs->cState); + if (pDelFile) { + SDelFReader *pDelFReader; + + code = tsdbDelFReaderOpen(&pDelFReader, pDelFile, pTsdb, NULL); + if (code) goto _err; + + code = getTableDelIdx(pDelFReader, suid, uid, &delIdx); + if (code) goto _err; + + code = getTableDelSkyline(pMem, pIMem, pDelFReader, &delIdx, pSkyline); + if (code) goto _err; + + tsdbDelFReaderClose(&pDelFReader); + } else { + code = getTableDelSkyline(pMem, pIMem, NULL, NULL, pSkyline); + if (code) goto _err; + } + + int iSkyline = taosArrayGetSize(pSkyline) - 1; + + SBlockIdx idx = {.suid = suid, .uid = uid}; + + SFSNextRowIter fsState = {0}; + fsState.state = SFSNEXTROW_FS; + fsState.pTsdb = pTsdb; + fsState.pBlockIdxExp = &idx; + + SMemNextRowIter memState = {0}; + SMemNextRowIter imemState = {0}; + TSDBROW memRow, imemRow, fsRow; + + TsdbNextRowState input[3] = {{&memRow, true, false, &memState, getNextRowFromMem, NULL}, + {&imemRow, true, false, &imemState, getNextRowFromMem, NULL}, + {&fsRow, false, true, &fsState, getNextRowFromFS, clearNextRowFromFS}}; + + if (pMem) { + memState.pMem = pMem; + memState.state = SMEMNEXTROW_ENTER; + input[0].stop = false; + input[0].next = true; + } + if (pIMem) { + imemState.pMem = pIMem; + imemState.state = SMEMNEXTROW_ENTER; + input[1].stop = false; + input[1].next = true; + } + + int16_t nilColCount = nCol - 1; // count of null & none cols + int iCol = 0; // index of first nil col index from left to right + bool setICol = false; + + do { + for (int i = 0; i < 3; ++i) { + if (input[i].next && !input[i].stop) { + code = input[i].nextRowFn(input[i].iter, &input[i].pRow); + if (code) goto _err; + + if (input[i].pRow == NULL) { + input[i].stop = true; + input[i].next = false; + } + } + } + + if (input[0].stop && input[1].stop && input[2].stop) { + break; + } + + // select maxpoint(s) from mem, imem, fs + TSDBROW *max[3] = {0}; + int iMax[3] = {-1, -1, -1}; + int nMax = 0; + TSKEY maxKey = TSKEY_MIN; + + for (int i = 0; i < 3; ++i) { + if (!input[i].stop && input[i].pRow != NULL) { + TSDBKEY key = TSDBROW_KEY(input[i].pRow); + + // merging & deduplicating on client side + if (maxKey <= key.ts) { + if (maxKey < key.ts) { + nMax = 0; + maxKey = key.ts; + } + + iMax[nMax] = i; + max[nMax++] = input[i].pRow; + } + } + } + + // delete detection + TSDBROW *merge[3] = {0}; + // int iMerge[3] = {-1, -1, -1}; + int nMerge = 0; + for (int i = 0; i < nMax; ++i) { + TSDBKEY maxKey = TSDBROW_KEY(max[i]); + + // bool deleted = false; + bool deleted = tsdbKeyDeleted(&maxKey, pSkyline, &iSkyline); + if (!deleted) { + // iMerge[nMerge] = i; + merge[nMerge++] = max[i]; + } + + input[iMax[i]].next = deleted; + } + + // merge if nMerge > 1 + if (nMerge > 0) { + *dup = false; + + if (nMerge == 1) { + code = tsRowFromTsdbRow(pTSchema, merge[nMerge - 1], ppRow); + if (code) goto _err; + } else { + // merge 2 or 3 rows + SRowMerger merger = {0}; + + tRowMergerInit(&merger, merge[0], pTSchema); + for (int i = 1; i < nMerge; ++i) { + tRowMerge(&merger, merge[i]); + } + tRowMergerGetRow(&merger, ppRow); + tRowMergerClear(&merger); + } + } + + } while (*ppRow == NULL); + + for (int i = 0; i < 3; ++i) { + if (input[i].nextRowClearFn) { + input[i].nextRowClearFn(input[i].iter); + } + } + if (pSkyline) { + taosArrayDestroy(pSkyline); + } + taosMemoryFreeClear(pTSchema); + + return code; +_err: + for (int i = 0; i < 3; ++i) { + if (input[i].nextRowClearFn) { + input[i].nextRowClearFn(input[i].iter); + } + } + if (pSkyline) { + taosArrayDestroy(pSkyline); + } + taosMemoryFreeClear(pTSchema); + tsdbError("vgId:%d merge last_row failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, STSRow **ppRow) { + int32_t code = 0; + + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + int16_t nCol = pTSchema->numOfCols; + SArray *pColArray = taosArrayInit(nCol, sizeof(SColVal)); + + tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + STbData *pMem = NULL; + if (pTsdb->mem) { + tsdbGetTbDataFromMemTable(pTsdb->mem, suid, uid, &pMem); + } + + STbData *pIMem = NULL; + if (pTsdb->imem) { + tsdbGetTbDataFromMemTable(pTsdb->imem, suid, uid, &pIMem); + } + + *ppRow = NULL; + + SArray *pSkyline = taosArrayInit(32, sizeof(TSDBKEY)); + + SDelIdx delIdx; + + SDelFile *pDelFile = tsdbFSStateGetDelFile(pTsdb->fs->cState); + if (pDelFile) { + SDelFReader *pDelFReader; + + code = tsdbDelFReaderOpen(&pDelFReader, pDelFile, pTsdb, NULL); + if (code) goto _err; + + code = getTableDelIdx(pDelFReader, suid, uid, &delIdx); + if (code) goto _err; + + code = getTableDelSkyline(pMem, pIMem, pDelFReader, &delIdx, pSkyline); + if (code) goto _err; + + tsdbDelFReaderClose(&pDelFReader); + } else { + code = getTableDelSkyline(pMem, pIMem, NULL, NULL, pSkyline); + if (code) goto _err; + } + + int iSkyline = taosArrayGetSize(pSkyline) - 1; + + SBlockIdx idx = {.suid = suid, .uid = uid}; + + SFSNextRowIter fsState = {0}; + fsState.state = SFSNEXTROW_FS; + fsState.pTsdb = pTsdb; + fsState.pBlockIdxExp = &idx; + + SMemNextRowIter memState = {0}; + SMemNextRowIter imemState = {0}; + TSDBROW memRow, imemRow, fsRow; + + TsdbNextRowState input[3] = {{&memRow, true, false, &memState, getNextRowFromMem, NULL}, + {&imemRow, true, false, &imemState, getNextRowFromMem, NULL}, + {&fsRow, false, true, &fsState, getNextRowFromFS, clearNextRowFromFS}}; + + if (pMem) { + memState.pMem = pMem; + memState.state = SMEMNEXTROW_ENTER; + input[0].stop = false; + input[0].next = true; + } + if (pIMem) { + imemState.pMem = pIMem; + imemState.state = SMEMNEXTROW_ENTER; + input[1].stop = false; + input[1].next = true; + } + + int16_t nilColCount = nCol - 1; // count of null & none cols + int iCol = 0; // index of first nil col index from left to right + bool setICol = false; + + do { + for (int i = 0; i < 3; ++i) { + if (input[i].next && !input[i].stop) { + code = input[i].nextRowFn(input[i].iter, &input[i].pRow); + if (code) goto _err; + + if (input[i].pRow == NULL) { + input[i].stop = true; + input[i].next = false; + } + } + } + + if (input[0].stop && input[1].stop && input[2].stop) { + break; + } + + // select maxpoint(s) from mem, imem, fs + TSDBROW *max[3] = {0}; + int iMax[3] = {-1, -1, -1}; + int nMax = 0; + TSKEY maxKey = TSKEY_MIN; + + for (int i = 0; i < 3; ++i) { + if (!input[i].stop && input[i].pRow != NULL) { + TSDBKEY key = TSDBROW_KEY(input[i].pRow); + + // merging & deduplicating on client side + if (maxKey <= key.ts) { + if (maxKey < key.ts) { + nMax = 0; + maxKey = key.ts; + } + + iMax[nMax] = i; + max[nMax++] = input[i].pRow; + } + } + } + + // delete detection + TSDBROW *merge[3] = {0}; + int iMerge[3] = {-1, -1, -1}; + int nMerge = 0; + for (int i = 0; i < nMax; ++i) { + TSDBKEY maxKey = TSDBROW_KEY(max[i]); + + // bool deleted = false; + bool deleted = tsdbKeyDeleted(&maxKey, pSkyline, &iSkyline); + if (!deleted) { + iMerge[nMerge] = iMax[i]; + merge[nMerge++] = max[i]; + } + + input[iMax[i]].next = deleted; + } + + // merge if nMerge > 1 + if (nMerge > 0) { + if (nMerge == 1) { + code = tsRowFromTsdbRow(pTSchema, merge[nMerge - 1], ppRow); + if (code) goto _err; + } else { + // merge 2 or 3 rows + SRowMerger merger = {0}; + + tRowMergerInit(&merger, merge[0], pTSchema); + for (int i = 1; i < nMerge; ++i) { + tRowMerge(&merger, merge[i]); + } + tRowMergerGetRow(&merger, ppRow); + tRowMergerClear(&merger); + } + } else { + *ppRow = NULL; + return code; + } + + if (iCol == 0) { + STColumn *pTColumn = &pTSchema->columns[0]; + SColVal *pColVal = &(SColVal){0}; + + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = maxKey}); + + if (taosArrayPush(pColArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + ++iCol; + + setICol = false; + for (int16_t i = iCol; i < nCol; ++i) { + // tsdbRowGetColVal(*ppRow, pTSchema, i, pColVal); + tTSRowGetVal(*ppRow, pTSchema, i, pColVal); + if (taosArrayPush(pColArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + if (pColVal->isNull || pColVal->isNone) { + for (int j = 0; j < nMerge; ++j) { + SColVal jColVal = {0}; + tsdbRowGetColVal(merge[j], pTSchema, i, &jColVal); + if (jColVal.isNull || jColVal.isNone) { + input[iMerge[j]].next = true; + } + } + if (!setICol) { + iCol = i; + setICol = true; + } + } else { + --nilColCount; + } + } + /* + if (*ppRow) { + taosMemoryFreeClear(*ppRow); + } + */ + continue; + } + + setICol = false; + for (int16_t i = iCol; i < nCol; ++i) { + SColVal colVal = {0}; + tTSRowGetVal(*ppRow, pTSchema, i, &colVal); + + SColVal *tColVal = (SColVal *)taosArrayGet(pColArray, i); + + if (!colVal.isNone && !colVal.isNull) { + if (tColVal->isNull || tColVal->isNone) { + taosArraySet(pColArray, i, &colVal); + --nilColCount; + } + } else { + if ((tColVal->isNull || tColVal->isNone) && !setICol) { + iCol = i; + setICol = true; + + for (int j = 0; j < nMerge; ++j) { + SColVal jColVal = {0}; + tsdbRowGetColVal(merge[j], pTSchema, i, &jColVal); + if (jColVal.isNull || jColVal.isNone) { + input[iMerge[j]].next = true; + } + } + } + } + } + + if (*ppRow) { + taosMemoryFreeClear(*ppRow); + } + } while (nilColCount > 0); + + // if () new ts row from pColArray if non empty + if (taosArrayGetSize(pColArray) == nCol) { + code = tdSTSRowNew(pColArray, pTSchema, ppRow); + if (code) goto _err; + } + taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + + return code; +_err: + taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + tsdbError("vgId:%d merge last_row failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **handle) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + // getTableCacheKey(uid, "lr", key, &keyLen); + getTableCacheKey(uid, 0, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + } else { + STSRow *pRow = NULL; + bool dup = false; + code = mergeLastRow(uid, pTsdb, &dup, &pRow); + // if table's empty or error, return code of -1 + if (code < 0 || pRow == NULL) { + if (!dup && pRow) { + taosMemoryFree(pRow); + } + + *handle = NULL; + return 0; + } + + tsdbCacheInsertLastrow(pCache, pTsdb, uid, pRow, dup); + h = taosLRUCacheLookup(pCache, key, keyLen); + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + } + + *handle = h; + + return code; +} + +int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **handle) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + // getTableCacheKey(uid, "l", key, &keyLen); + getTableCacheKey(uid, 1, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + + } else { + STSRow *pRow = NULL; + code = mergeLast(uid, pTsdb, &pRow); + // if table's empty or error, return code of -1 + if (code < 0 || pRow == NULL) { + *handle = NULL; + return 0; + } + + _taos_lru_deleter_t deleter = deleteTableCacheLastrow; + LRUStatus status = + taosLRUCacheInsert(pCache, key, keyLen, pRow, TD_ROW_LEN(pRow), deleter, NULL, TAOS_LRU_PRIORITY_LOW); + if (status != TAOS_LRU_STATUS_OK) { + code = -1; + } + /* tsdbCacheInsertLast(pCache, uid, pRow); */ + h = taosLRUCacheLookup(pCache, key, keyLen); + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + } + + *handle = h; + + return code; +} + +int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + // getTableCacheKey(uid, "lr", key, &keyLen); + getTableCacheKey(uid, 0, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + STSRow *pRow = (STSRow *)taosLRUCacheValue(pCache, h); + if (pRow->ts <= eKey) { + taosLRUCacheRelease(pCache, h, true); + } else { + taosLRUCacheRelease(pCache, h, false); + } + + // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); + } + + // getTableCacheKey(uid, "l", key, &keyLen); + getTableCacheKey(uid, 1, key, &keyLen); + h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + // clear last cache anyway, no matter where eKey ends. + taosLRUCacheRelease(pCache, h, true); + + // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); + } + + return code; +} + +int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h) { + int32_t code = 0; + + taosLRUCacheRelease(pCache, h, false); + + return code; +} diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c new file mode 100644 index 0000000000000000000000000000000000000000..ce42b0ab67bf725cd8636872363b5380176e4c6e --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -0,0 +1,175 @@ +/* + * 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 . + */ + +#include "taoserror.h" +#include "tarray.h" +#include "tcommon.h" +#include "tsdb.h" + +typedef struct SLastrowReader { + SVnode* pVnode; + STSchema* pSchema; + uint64_t uid; + // int32_t* pSlotIds; + char** transferBuf; // todo remove it soon + int32_t numOfCols; + int32_t type; + int32_t tableIndex; // currently returned result tables + SArray* pTableList; // table id list +} SLastrowReader; + +static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReader, const int32_t* slotIds) { + int32_t numOfRows = pBlock->info.rows; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + + SColVal colVal = {0}; + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + + if (slotIds[i] == -1) { + colDataAppend(pColInfoData, numOfRows, (const char*)&pRow->ts, false); + } else { + tTSRowGetVal(pRow, pReader->pSchema, slotIds[i], &colVal); + + if (IS_VAR_DATA_TYPE(colVal.type)) { + if (colVal.isNull || colVal.isNone) { + colDataAppendNULL(pColInfoData, numOfRows); + } else { + varDataSetLen(pReader->transferBuf[i], colVal.value.nData); + memcpy(varDataVal(pReader->transferBuf[i]), colVal.value.pData, colVal.value.nData); + colDataAppend(pColInfoData, numOfRows, pReader->transferBuf[i], false); + } + } else { + colDataAppend(pColInfoData, numOfRows, (const char*)&colVal.value, colVal.isNull || colVal.isNone); + } + } + } + + pBlock->info.rows += 1; +} + +int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t* colId, int32_t numOfCols, + void** pReader) { + SLastrowReader* p = taosMemoryCalloc(1, sizeof(SLastrowReader)); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + p->type = type; + p->pVnode = pVnode; + p->numOfCols = numOfCols; + p->transferBuf = taosMemoryCalloc(p->numOfCols, POINTER_BYTES); + + STableKeyInfo* pKeyInfo = taosArrayGet(pTableIdList, 0); + p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, pKeyInfo->uid, -1); + p->pTableList = pTableIdList; + + for(int32_t i = 0; i < p->numOfCols; ++i) { + if (IS_VAR_DATA_TYPE(colId[i])) { + p->transferBuf[i] = taosMemoryMalloc(p->pSchema->columns[i].bytes); + } + } + + *pReader = p; + return TSDB_CODE_SUCCESS; +} + +int32_t tsdbLastrowReaderClose(void* pReader) { + SLastrowReader* p = pReader; + + for (int32_t i = 0; i < p->numOfCols; ++i) { + taosMemoryFreeClear(p->transferBuf[i]); + } + + taosMemoryFree(p->transferBuf); + taosMemoryFree(pReader); + return TSDB_CODE_SUCCESS; +} + +int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t* slotIds) { + if (pReader == NULL || pResBlock == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + SLastrowReader* pr = pReader; + + SLRUCache* lruCache = pr->pVnode->pTsdb->lruCache; + LRUHandle* h = NULL; + STSRow* pRow = NULL; + size_t numOfTables = taosArrayGetSize(pr->pTableList); + + // retrieve the only one last row of all tables in the uid list. + if (pr->type == LASTROW_RETRIEVE_TYPE_SINGLE) { + int64_t lastKey = INT64_MIN; + bool internalResult = false; + for (int32_t i = 0; i < numOfTables; ++i) { + STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i); + + int32_t code = tsdbCacheGetLastrowH(lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &h); + // int32_t code = tsdbCacheGetLastH(lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &h); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + if (h == NULL) { + continue; + } + + pRow = (STSRow*)taosLRUCacheValue(lruCache, h); + if (pRow->ts > lastKey) { + // Set result row into the same rowIndex repeatly, so we need to check if the internal result row has already + // appended or not. + if (internalResult) { + pResBlock->info.rows -= 1; + } + + saveOneRow(pRow, pResBlock, pr, slotIds); + internalResult = true; + lastKey = pRow->ts; + } + + tsdbCacheRelease(lruCache, h); + } + } else if (pr->type == LASTROW_RETRIEVE_TYPE_ALL) { + for (int32_t i = pr->tableIndex; i < numOfTables; ++i) { + STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i); + + int32_t code = tsdbCacheGetLastrowH(lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &h); + // int32_t code = tsdbCacheGetLastH(lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &h); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + // no data in the table of Uid + if (h == NULL) { + continue; + } + + pRow = (STSRow*)taosLRUCacheValue(lruCache, h); + saveOneRow(pRow, pResBlock, pr, slotIds); + + tsdbCacheRelease(lruCache, h); + + pr->tableIndex += 1; + if (pResBlock->info.rows >= pResBlock->info.capacity) { + return TSDB_CODE_SUCCESS; + } + } + } else { + return TSDB_CODE_INVALID_PARA; + } + + return TSDB_CODE_SUCCESS; +} diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index e98fd8ae1f6dc6cd0d6f47a2563055f7e452870a..008d7caff5d4afde87c941b61f59ee11c8aafe2d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -14,1824 +14,1148 @@ */ #include "tsdb.h" - -#define TSDB_MAX_SUBBLOCKS 8 - typedef struct { - STable *pTable; - STbDataIter *pIter; -} SCommitIter; + int64_t suid; + int64_t uid; + STSchema *pTSchema; +} SSkmInfo; typedef struct { - SRtn rtn; // retention snapshot - SFSIter fsIter; // tsdb file iterator - int niters; // memory iterators - SCommitIter *iters; - bool isRFileSet; // read and commit FSET - int32_t fid; - SDFileSet *pSet; - SReadH readh; - SDFileSet wSet; - bool isDFileSame; - bool isLFileSame; - TSKEY minKey; - TSKEY maxKey; - SArray *aBlkIdx; // SBlockIdx array - STable *pTable; - SArray *aSupBlk; // Table super-block array - SArray *aSubBlk; // table sub-block array - SDataCols *pDataCols; -} SCommitH; - -#define TSDB_DEFAULT_BLOCK_ROWS(maxRows) ((maxRows)*4 / 5) - -#define TSDB_COMMIT_REPO(ch) TSDB_READ_REPO(&(ch->readh)) -#define TSDB_COMMIT_REPO_ID(ch) REPO_ID(TSDB_READ_REPO(&(ch->readh))) -#define TSDB_COMMIT_WRITE_FSET(ch) (&((ch)->wSet)) -#define TSDB_COMMIT_TABLE(ch) ((ch)->pTable) -#define TSDB_COMMIT_HEAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_HEAD) -#define TSDB_COMMIT_DATA_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_DATA) -#define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST) -#define TSDB_COMMIT_SMAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAD) -#define TSDB_COMMIT_SMAL_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAL) -#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_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh)) -#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->pVnode->config.tsdbCfg.maxRows) -#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) - -static int32_t tsdbCommitData(SCommitH *pCommith); -static int32_t tsdbCommitDel(SCommitH *pCommith); -static int32_t tsdbCommitCache(SCommitH *pCommith); -static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitH *pCHandle); -static int32_t tsdbEndCommit(SCommitH *pCHandle, int eno); - -static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo); -static void tsdbSeekCommitIter(SCommitH *pCommith, TSKEY key); -static int tsdbNextCommitFid(SCommitH *pCommith); -static void tsdbDestroyCommitH(SCommitH *pCommith); -static int32_t tsdbCreateCommitIters(SCommitH *pCommith); -static void tsdbDestroyCommitIters(SCommitH *pCommith); -static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid); -static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid); -static int tsdbCommitToTable(SCommitH *pCommith, int tid); -static bool tsdbCommitIsSameFile(SCommitH *pCommith, int bidx); -static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx); -static int tsdbSetCommitTable(SCommitH *pCommith, STable *pTable); -static int tsdbComparKeyBlock(const void *arg1, const void *arg2); -static int tsdbWriteBlockInfo(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); -static int tsdbCommitAddBlock(SCommitH *pCommith, const SBlock *pSupBlock, const SBlock *pSubBlocks, int nSubBlocks); -static int tsdbMergeBlockData(SCommitH *pCommith, SCommitIter *pIter, SDataCols *pDataCols, TSKEY keyLimit, - bool isLastOneBlock); -static void tsdbResetCommitTable(SCommitH *pCommith); -static void tsdbCloseCommitFile(SCommitH *pCommith, bool hasError); -static bool tsdbCanAddSubBlock(SCommitH *pCommith, SBlock *pBlock, SMergeInfo *pInfo); -static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, - SDataCols *pTarget, TSKEY maxKey, int maxRows, int8_t update); -static int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf); -static int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn); -static int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, STbDataIter *pIter, TSKEY maxKey, int maxRowsToRead, - SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, - SMergeInfo *pMergeInfo); + STsdb *pTsdb; + /* commit data */ + int64_t commitID; + int32_t minutes; + int8_t precision; + int32_t minRow; + int32_t maxRow; + int8_t cmprAlg; + // -------------- + TSKEY nextKey; // reset by each table commit + int32_t commitFid; + TSKEY minKey; + TSKEY maxKey; + // commit file data + SDataFReader *pReader; + SArray *aBlockIdx; // SArray + SMapData oBlockMap; // SMapData, read from reader + SBlockData oBlockData; + SDataFWriter *pWriter; + SArray *aBlockIdxN; // SArray + SMapData nBlockMap; // SMapData + SBlockData nBlockData; + SSkmInfo skmTable; + SSkmInfo skmRow; + /* commit del */ + SDelFReader *pDelFReader; + SDelFWriter *pDelFWriter; + SArray *aDelIdx; // SArray + SArray *aDelIdxN; // SArray + SArray *aDelData; // SArray +} SCommitter; + +static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitter *pCommitter); +static int32_t tsdbCommitData(SCommitter *pCommitter); +static int32_t tsdbCommitDel(SCommitter *pCommitter); +static int32_t tsdbCommitCache(SCommitter *pCommitter); +static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno); int32_t tsdbBegin(STsdb *pTsdb) { - if (!pTsdb) return 0; + int32_t code = 0; - SMemTable *pMem; + if (!pTsdb) return code; - if (tsdbMemTableCreate(pTsdb, &pTsdb->mem) < 0) { - return -1; - } + code = tsdbMemTableCreate(pTsdb, &pTsdb->mem); + if (code) goto _err; + + return code; - return 0; +_err: + tsdbError("vgId:%d tsdb begin failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; } int32_t tsdbCommit(STsdb *pTsdb) { if (!pTsdb) return 0; int32_t code = 0; - SCommitH commith = {0}; - SDFileSet *pSet = NULL; - int fid; + SCommitter commith; + SMemTable *pMemTable = pTsdb->mem; - ASSERT(pTsdb->imem == NULL && pTsdb->mem); - pTsdb->imem = pTsdb->mem; - pTsdb->mem = NULL; + // check + if (pMemTable->nRow == 0 && pMemTable->nDel == 0) { + // TODO: lock? + pTsdb->mem = NULL; + tsdbMemTableDestroy(pMemTable); + goto _exit; + } // start commit code = tsdbStartCommit(pTsdb, &commith); - if (code) { - goto _err; - } + if (code) goto _err; // commit impl code = tsdbCommitData(&commith); - if (code) { - goto _err; - } + if (code) goto _err; code = tsdbCommitDel(&commith); - if (code) { - goto _err; - } + if (code) goto _err; code = tsdbCommitCache(&commith); - if (code) { - goto _err; - } + if (code) goto _err; // end commit code = tsdbEndCommit(&commith, 0); - if (code) { - goto _err; - } + if (code) goto _err; +_exit: return code; _err: + tsdbEndCommit(&commith, code); tsdbError("vgId:%d, failed to commit since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); return code; } -static int32_t tsdbCommitData(SCommitH *pCommith) { - int32_t fid; - SDFileSet *pSet = NULL; +static int32_t tsdbCommitDelStart(SCommitter *pCommitter) { int32_t code = 0; - STsdb *pTsdb = TSDB_COMMIT_REPO(pCommith); - - // Skip expired memory data and expired FSET - tsdbSeekCommitIter(pCommith, pCommith->rtn.minKey); - while ((pSet = tsdbFSIterNext(&(pCommith->fsIter)))) { - if (pSet->fid < pCommith->rtn.minFid) { - tsdbInfo("vgId:%d, FSET %d on level %d disk id %d expires, remove it", REPO_ID(pTsdb), pSet->fid, - TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet)); - } else { - break; - } + STsdb *pTsdb = pCommitter->pTsdb; + SMemTable *pMemTable = pTsdb->imem; + + pCommitter->aDelIdx = taosArrayInit(0, sizeof(SDelIdx)); + if (pCommitter->aDelIdx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; } - // commit - fid = tsdbNextCommitFid(pCommith); - while (true) { - // Loop over both on disk and memory - if (pSet == NULL && fid == TSDB_IVLD_FID) break; - - if (pSet && (fid == TSDB_IVLD_FID || pSet->fid < fid)) { - // Only has existing FSET but no memory data to commit in this - // existing FSET, only check if file in correct retention - if (tsdbApplyRtnOnFSet(TSDB_COMMIT_REPO(pCommith), pSet, &(pCommith->rtn)) < 0) { - tsdbDestroyCommitH(pCommith); - return -1; - } + pCommitter->aDelData = taosArrayInit(0, sizeof(SDelData)); + if (pCommitter->aDelData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } - pSet = tsdbFSIterNext(&(pCommith->fsIter)); - } else { - // Has memory data to commit - SDFileSet *pCSet; - int cfid; - - if (pSet == NULL || pSet->fid > fid) { - // Commit to a new FSET with fid: fid - pCSet = NULL; - cfid = fid; - } else { - // Commit to an existing FSET - pCSet = pSet; - cfid = pSet->fid; - pSet = tsdbFSIterNext(&(pCommith->fsIter)); - } + pCommitter->aDelIdxN = taosArrayInit(0, sizeof(SDelIdx)); + if (pCommitter->aDelIdxN == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } - if (tsdbCommitToFile(pCommith, pCSet, cfid) < 0) { - tsdbDestroyCommitH(pCommith); - return -1; - } + SDelFile *pDelFileR = pTsdb->fs->nState->pDelFile; + if (pDelFileR) { + code = tsdbDelFReaderOpen(&pCommitter->pDelFReader, pDelFileR, pTsdb, NULL); + if (code) goto _err; - fid = tsdbNextCommitFid(pCommith); - } + code = tsdbReadDelIdx(pCommitter->pDelFReader, pCommitter->aDelIdx, NULL); + if (code) goto _err; } - return code; -} + // prepare new + SDelFile wDelFile = {.commitID = pCommitter->commitID, .size = 0, .offset = 0}; + code = tsdbDelFWriterOpen(&pCommitter->pDelFWriter, &wDelFile, pTsdb); + if (code) goto _err; -static int32_t tsdbCommitDel(SCommitH *pCommith) { - int32_t code = 0; - // TODO +_exit: + tsdbDebug("vgId:%d commit del start", TD_VID(pTsdb->pVnode)); return code; -} -static int32_t tsdbCommitCache(SCommitH *pCommith) { - int32_t code = 0; - // TODO +_err: + tsdbError("vgId:%d commit del start failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); return code; } -static int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn) { - SDiskID did; - SDFileSet nSet = {0}; - STsdbFS *pfs = REPO_FS(pRepo); - int level; +static int32_t tsdbCommitTableDel(SCommitter *pCommitter, STbData *pTbData, SDelIdx *pDelIdx) { + int32_t code = 0; + SDelData *pDelData; + tb_uid_t suid; + tb_uid_t uid; - ASSERT(pSet->fid >= pRtn->minFid); + taosArrayClear(pCommitter->aDelData); - level = tsdbGetFidLevel(pSet->fid, pRtn); + if (pTbData) { + suid = pTbData->suid; + uid = pTbData->uid; - if (tfsAllocDisk(pRepo->pVnode->pTfs, level, &did) < 0) { - 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(pRepo, &nSet, did, 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 (pTbData->pHead == NULL) { + pTbData = NULL; } + } - if (tsdbUpdateDFileSet(pfs, &nSet) < 0) { - return -1; - } + if (pDelIdx) { + suid = pDelIdx->suid; + uid = pDelIdx->uid; - 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; - } + code = tsdbReadDelData(pCommitter->pDelFReader, pDelIdx, pCommitter->aDelData, NULL); + if (code) goto _err; } - return 0; -} + if (pTbData == NULL && pDelIdx == NULL) goto _exit; -void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) { - STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo); - TSKEY minKey, midKey, maxKey, now; - - now = taosGetTimestamp(pCfg->precision); - minKey = now - pCfg->keep2 * tsTickPerMin[pCfg->precision]; - midKey = now - pCfg->keep1 * tsTickPerMin[pCfg->precision]; - maxKey = now - pCfg->keep0 * tsTickPerMin[pCfg->precision]; - - pRtn->minKey = minKey; - pRtn->minFid = (int)(TSDB_KEY_FID(minKey, pCfg->days, pCfg->precision)); - pRtn->midFid = (int)(TSDB_KEY_FID(midKey, pCfg->days, pCfg->precision)); - pRtn->maxFid = (int)(TSDB_KEY_FID(maxKey, pCfg->days, pCfg->precision)); - tsdbDebug("vgId:%d, now:%" PRId64 " minKey:%" PRId64 " minFid:%d, midFid:%d, maxFid:%d", REPO_ID(pRepo), now, minKey, - pRtn->minFid, pRtn->midFid, pRtn->maxFid); -} + SDelIdx delIdx = {.suid = suid, .uid = uid}; -static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitH *pCHandle) { - int32_t code = 0; + // memory + pDelData = pTbData ? pTbData->pHead : NULL; + for (; pDelData; pDelData = pDelData->pNext) { + if (taosArrayPush(pCommitter->aDelData, pDelData) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } - tsdbInfo("vgId:%d, start to commit", REPO_ID(pTsdb)); + // write + code = tsdbWriteDelData(pCommitter->pDelFWriter, pCommitter->aDelData, NULL, &delIdx); + if (code) goto _err; - if (tsdbInitCommitH(pCHandle, pTsdb) < 0) { - return -1; + // put delIdx + if (taosArrayPush(pCommitter->aDelIdx, &delIdx) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; } - tsdbStartFSTxn(pTsdb, 0, 0); - +_exit: return code; -} - -static int32_t tsdbEndCommit(SCommitH *pCHandle, int eno) { - int32_t code = 0; - STsdb *pTsdb = TSDB_COMMIT_REPO(pCHandle); - - tsdbDestroyCommitH(pCHandle); - tsdbEndFSTxn(pTsdb); - tsdbMemTableDestroy(pTsdb->imem); - pTsdb->imem = NULL; - - tsdbInfo("vgId:%d, commit over, %s", REPO_ID(pTsdb), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed"); +_err: + tsdbError("vgId:%d commit table del failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); return code; } -static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo) { - STsdbCfg *pCfg = REPO_CFG(pRepo); - - memset(pCommith, 0, sizeof(*pCommith)); - tsdbGetRtnSnap(pRepo, &(pCommith->rtn)); - - TSDB_FSET_SET_CLOSED(TSDB_COMMIT_WRITE_FSET(pCommith)); +static int32_t tsdbCommitDelEnd(SCommitter *pCommitter) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; - // Init read handle - if (tsdbInitReadH(&(pCommith->readh), pRepo) < 0) { - return -1; - } + code = tsdbWriteDelIdx(pCommitter->pDelFWriter, pCommitter->aDelIdxN, NULL); + if (code) goto _err; - // Init file iterator - tsdbFSIterInit(&(pCommith->fsIter), REPO_FS(pRepo), TSDB_FS_ITER_FORWARD); + code = tsdbUpdateDelFileHdr(pCommitter->pDelFWriter); + if (code) goto _err; - if (tsdbCreateCommitIters(pCommith) < 0) { - tsdbDestroyCommitH(pCommith); - return -1; - } + code = tsdbFSStateUpsertDelFile(pTsdb->fs->nState, &pCommitter->pDelFWriter->fDel); + if (code) goto _err; - pCommith->aBlkIdx = taosArrayInit(1024, sizeof(SBlockIdx)); - if (pCommith->aBlkIdx == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tsdbDestroyCommitH(pCommith); - return -1; - } + code = tsdbDelFWriterClose(&pCommitter->pDelFWriter, 1); + if (code) goto _err; - pCommith->aSupBlk = taosArrayInit(1024, sizeof(SBlock)); - if (pCommith->aSupBlk == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tsdbDestroyCommitH(pCommith); - return -1; + if (pCommitter->pDelFReader) { + code = tsdbDelFReaderClose(&pCommitter->pDelFReader); + if (code) goto _err; } - pCommith->aSubBlk = taosArrayInit(1024, sizeof(SBlock)); - if (pCommith->aSubBlk == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tsdbDestroyCommitH(pCommith); - return -1; - } + taosArrayDestroy(pCommitter->aDelIdx); + taosArrayDestroy(pCommitter->aDelData); + taosArrayDestroy(pCommitter->aDelIdxN); - pCommith->pDataCols = tdNewDataCols(0, pCfg->maxRows); - if (pCommith->pDataCols == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tsdbDestroyCommitH(pCommith); - return -1; - } + return code; - return 0; +_err: + tsdbError("vgId:%d commit del end failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; } -// Skip all keys until key (not included) -static void tsdbSeekCommitIter(SCommitH *pCommith, TSKEY key) { - for (int i = 0; i < pCommith->niters; i++) { - SCommitIter *pIter = pCommith->iters + i; - if (pIter->pTable == NULL || pIter->pIter == NULL) continue; - - tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, pIter->pIter, key - 1, INT32_MAX, NULL, NULL, 0, - true, NULL); - } -} +static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; + SDFileSet *pRSet = NULL; + SDFileSet wSet; + + // memory + pCommitter->nextKey = TSKEY_MAX; + + // old + taosArrayClear(pCommitter->aBlockIdx); + tMapDataReset(&pCommitter->oBlockMap); + tBlockDataReset(&pCommitter->oBlockData); + pRSet = tsdbFSStateGetDFileSet(pTsdb->fs->nState, pCommitter->commitFid); + if (pRSet) { + code = tsdbDataFReaderOpen(&pCommitter->pReader, pTsdb, pRSet); + if (code) goto _err; + + code = tsdbReadBlockIdx(pCommitter->pReader, pCommitter->aBlockIdx, NULL); + if (code) goto _err; + } + + // new + taosArrayClear(pCommitter->aBlockIdxN); + tMapDataReset(&pCommitter->nBlockMap); + tBlockDataReset(&pCommitter->nBlockData); + if (pRSet) { + wSet = (SDFileSet){.diskId = pRSet->diskId, + .fid = pCommitter->commitFid, + .fHead = {.commitID = pCommitter->commitID, .offset = 0, .size = 0}, + .fData = pRSet->fData, + .fLast = {.commitID = pCommitter->commitID, .size = 0}, + .fSma = pRSet->fSma}; + } else { + STfs *pTfs = pTsdb->pVnode->pTfs; + SDiskID did = {.level = 0, .id = 0}; -static int tsdbNextCommitFid(SCommitH *pCommith) { - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo); - int fid = TSDB_IVLD_FID; + // TODO: alloc a new disk + // tfsAllocDisk(pTfs, 0, &did); - for (int i = 0; i < pCommith->niters; i++) { - SCommitIter *pIter = pCommith->iters + i; - // if (pIter->pTable == NULL || pIter->pIter == NULL) continue; + // create the directory + tfsMkdirRecurAt(pTfs, pTsdb->path, did); - TSKEY nextKey = tsdbNextIterKey(pIter->pIter); - if (nextKey == TSDB_DATA_TIMESTAMP_NULL) { - continue; - } else { - int tfid = (int)(TSDB_KEY_FID(nextKey, pCfg->days, pCfg->precision)); - if (fid == TSDB_IVLD_FID || fid > tfid) { - fid = tfid; - } - } + wSet = (SDFileSet){.diskId = did, + .fid = pCommitter->commitFid, + .fHead = {.commitID = pCommitter->commitID, .offset = 0, .size = 0}, + .fData = {.commitID = pCommitter->commitID, .size = 0}, + .fLast = {.commitID = pCommitter->commitID, .size = 0}, + .fSma = {.commitID = pCommitter->commitID, .size = 0}}; } + code = tsdbDataFWriterOpen(&pCommitter->pWriter, pTsdb, &wSet); + if (code) goto _err; - return fid; -} - -static void tsdbDestroyCommitH(SCommitH *pCommith) { - pCommith->pDataCols = tdFreeDataCols(pCommith->pDataCols); - pCommith->aSubBlk = taosArrayDestroy(pCommith->aSubBlk); - pCommith->aSupBlk = taosArrayDestroy(pCommith->aSupBlk); - pCommith->aBlkIdx = taosArrayDestroy(pCommith->aBlkIdx); - tsdbDestroyCommitIters(pCommith); - tsdbDestroyReadH(&(pCommith->readh)); - tsdbCloseDFileSet(TSDB_COMMIT_WRITE_FSET(pCommith)); -} - -static int32_t tsdbCommitToFileStart(SCommitH *pCHandle, SDFileSet *pSet, int32_t fid) { - int32_t code = 0; - STsdb *pRepo = TSDB_COMMIT_REPO(pCHandle); - STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo); - - ASSERT(pSet == NULL || pSet->fid == fid); - - pCHandle->fid = fid; - pCHandle->pSet = pSet; - pCHandle->isRFileSet = false; - pCHandle->isDFileSame = false; - pCHandle->isLFileSame = false; - taosArrayClear(pCHandle->aBlkIdx); - - tsdbGetFidKeyRange(pCfg->days, pCfg->precision, fid, &(pCHandle->minKey), &(pCHandle->maxKey)); - - code = tsdbSetAndOpenCommitFile(pCHandle, pSet, fid); - +_exit: return code; -} -static int32_t tsdbCommitToFileImpl(SCommitH *pCHandle) { - int32_t code = 0; - // TODO + +_err: + tsdbError("vgId:%d commit file data start failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); return code; } -static int32_t tsdbCommitToFileEnd(SCommitH *pCommith) { + +static int32_t tsdbCommitterUpdateTableSchema(SCommitter *pCommitter, int64_t suid, int64_t uid, int32_t sver) { int32_t code = 0; - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - - 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), pCommith->fid, - tstrerror(terrno)); - tsdbCloseCommitFile(pCommith, true); - // revert the file change - tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pCommith->pSet); - return -1; - } - if (tsdbUpdateDFileSetHeader(&(pCommith->wSet)) < 0) { - tsdbError("vgId:%d, failed to update FSET %d header since %s", REPO_ID(pRepo), pCommith->fid, tstrerror(terrno)); - tsdbCloseCommitFile(pCommith, true); - // revert the file change - tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pCommith->pSet); - return -1; + if (pCommitter->skmTable.pTSchema) { + if (pCommitter->skmTable.suid == suid) { + if (suid == 0) { + if (pCommitter->skmTable.uid == uid && sver == pCommitter->skmTable.pTSchema->version) goto _exit; + } else { + if (sver == pCommitter->skmTable.pTSchema->version) goto _exit; + } + } } - // Close commit file - tsdbCloseCommitFile(pCommith, false); - - if (tsdbUpdateDFileSet(REPO_FS(pRepo), &(pCommith->wSet)) < 0) { - return -1; - } + pCommitter->skmTable.suid = suid; + pCommitter->skmTable.uid = uid; + tTSchemaDestroy(pCommitter->skmTable.pTSchema); + code = metaGetTbTSchemaEx(pCommitter->pTsdb->pVnode->pMeta, suid, uid, sver, &pCommitter->skmTable.pTSchema); + if (code) goto _exit; +_exit: return code; } -static int32_t tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { - int32_t code = 0; - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo); - // commit to file start - code = tsdbCommitToFileStart(pCommith, pSet, fid); - if (code) { - goto _err; - } - - // Loop to commit each table data in mem and file - int mIter = 0, fIter = 0; - int nBlkIdx = taosArrayGetSize(pCommith->readh.aBlkIdx); - - while (true) { - SBlockIdx *pIdx = NULL; - SCommitIter *pIter = NULL; - if (mIter < pCommith->niters) { - pIter = pCommith->iters + mIter; - if (fIter < nBlkIdx) { - pIdx = taosArrayGet(pCommith->readh.aBlkIdx, fIter); - } - } else if (fIter < nBlkIdx) { - pIdx = taosArrayGet(pCommith->readh.aBlkIdx, fIter); - } else { - break; - } - - if (pIter && pIter->pTable && - (!pIdx || ((pIter->pTable->suid < pIdx->suid) || - ((pIter->pTable->suid == pIdx->suid) && (pIter->pTable->uid <= pIdx->uid))))) { - if (tsdbCommitToTable(pCommith, mIter) < 0) { - tsdbCloseCommitFile(pCommith, true); - // revert the file change - tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pSet); - return -1; - } +static int32_t tsdbCommitterUpdateRowSchema(SCommitter *pCommitter, int64_t suid, int64_t uid, int32_t sver) { + int32_t code = 0; - if (pIdx && ((pIter->pTable->uid == pIdx->uid) && (pIter->pTable->suid == pIdx->suid))) { - ++fIter; - } - ++mIter; - } else if (pIter && !pIter->pTable) { - // When table already dropped during commit, pIter is not NULL but pIter->pTable is NULL. - ++mIter; // skip the table and do nothing - } else if (pIdx) { - if (tsdbMoveBlkIdx(pCommith, pIdx) < 0) { - tsdbCloseCommitFile(pCommith, true); - // revert the file change - tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pSet); - return -1; + if (pCommitter->skmRow.pTSchema) { + if (pCommitter->skmRow.suid == suid) { + if (suid == 0) { + if (pCommitter->skmRow.uid == uid && sver == pCommitter->skmRow.pTSchema->version) goto _exit; + } else { + if (sver == pCommitter->skmRow.pTSchema->version) goto _exit; } - ++fIter; - } else { - ASSERT(0); } } - // commit to file end - code = tsdbCommitToFileEnd(pCommith); + pCommitter->skmRow.suid = suid; + pCommitter->skmRow.uid = uid; + tTSchemaDestroy(pCommitter->skmRow.pTSchema); + code = metaGetTbTSchemaEx(pCommitter->pTsdb->pVnode->pMeta, suid, uid, sver, &pCommitter->skmRow.pTSchema); if (code) { - goto _err; + goto _exit; } - return code; - -_err: +_exit: return code; } -static int32_t tsdbCreateCommitIters(SCommitH *pCommith) { - int32_t code = 0; - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - SMemTable *pMem = pRepo->imem; - STbData *pTbData; - SCommitIter *pCommitIter; - STSchema *pTSchema = NULL; - - pCommith->niters = taosArrayGetSize(pMem->aTbData); - pCommith->iters = (SCommitIter *)taosMemoryCalloc(pCommith->niters, sizeof(SCommitIter)); - if (pCommith->iters == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - - for (int32_t iIter = 0; iIter < pCommith->niters; iIter++) { - pTbData = (STbData *)taosArrayGetP(pMem->aTbData, iIter); - pCommitIter = &pCommith->iters[iIter]; - - pTSchema = metaGetTbTSchema(REPO_META(pRepo), pTbData->uid, -1); - if (pTSchema) { - tsdbTbDataIterCreate(pTbData, NULL, 0, &pCommitIter->pIter); +static int32_t tsdbCommitBlockData(SCommitter *pCommitter, SBlockData *pBlockData, SBlock *pBlock, SBlockIdx *pBlockIdx, + int8_t toDataOnly) { + int32_t code = 0; - pCommitIter->pTable = (STable *)taosMemoryMalloc(sizeof(STable)); - pCommitIter->pTable->uid = pTbData->uid; - pCommitIter->pTable->suid = pTbData->suid; - pCommitIter->pTable->pSchema = pTSchema; - pCommitIter->pTable->pCacheSchema = NULL; + if (pBlock->nSubBlock == 0) { + if (!toDataOnly && pBlockData->nRow < pCommitter->minRow) { + pBlock->last = 1; + } else { + pBlock->last = 0; } } + code = tsdbWriteBlockData(pCommitter->pWriter, pBlockData, NULL, NULL, pBlockIdx, pBlock, pCommitter->cmprAlg); + if (code) goto _err; + + code = tMapDataPutItem(&pCommitter->nBlockMap, pBlock, tPutBlock); + if (code) goto _err; + return code; _err: return code; } -static void tsdbDestroyCommitIters(SCommitH *pCommith) { - if (pCommith->iters == NULL) return; - - for (int i = 1; i < pCommith->niters; i++) { - tsdbTbDataIterDestroy(pCommith->iters[i].pIter); - if (pCommith->iters[i].pTable) { - tdFreeSchema(pCommith->iters[i].pTable->pSchema); - tdFreeSchema(pCommith->iters[i].pTable->pCacheSchema); - taosMemoryFreeClear(pCommith->iters[i].pTable); - } - } - - taosMemoryFree(pCommith->iters); - pCommith->iters = NULL; - pCommith->niters = 0; -} - -static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { - SDiskID did; - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - SDFileSet *pWSet = TSDB_COMMIT_WRITE_FSET(pCommith); - - if (tfsAllocDisk(REPO_TFS(pRepo), tsdbGetFidLevel(fid, &(pCommith->rtn)), &did) < 0) { - terrno = TSDB_CODE_TDB_NO_AVAIL_DISK; - return -1; - } - - // Open read FSET - if (pSet) { - if (tsdbSetAndOpenReadFSet(&(pCommith->readh), pSet) < 0) { - return -1; - } - - pCommith->isRFileSet = true; - - if (tsdbLoadBlockIdx(&(pCommith->readh)) < 0) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; +static int32_t tsdbMergeTableData(SCommitter *pCommitter, STbDataIter *pIter, SBlock *pBlockMerge, TSDBKEY toKey, + int8_t toDataOnly) { + int32_t code = 0; + SBlockIdx *pBlockIdx = &(SBlockIdx){.suid = pIter->pTbData->suid, .uid = pIter->pTbData->uid}; + SBlockData *pBlockDataMerge = &pCommitter->oBlockData; + SBlockData *pBlockData = &pCommitter->nBlockData; + SBlock block; + SBlock *pBlock = █ + TSDBROW *pRow1; + TSDBROW row2; + TSDBROW *pRow2 = &row2; + + // read SBlockData + code = tsdbReadBlockData(pCommitter->pReader, pBlockIdx, pBlockMerge, pBlockDataMerge, NULL, NULL); + if (code) goto _err; + + code = tBlockDataSetSchema(pBlockData, pCommitter->skmTable.pTSchema); + if (code) goto _err; + + // loop to merge + pRow1 = tsdbTbDataIterGet(pIter); + *pRow2 = tsdbRowFromBlockData(pBlockDataMerge, 0); + ASSERT(pRow1 && tsdbKeyCmprFn(&TSDBROW_KEY(pRow1), &toKey) < 0); + ASSERT(tsdbKeyCmprFn(&TSDBROW_KEY(pRow2), &toKey) < 0); + code = tsdbCommitterUpdateRowSchema(pCommitter, pBlockIdx->suid, pBlockIdx->uid, TSDBROW_SVERSION(pRow1)); + if (code) goto _err; + + tBlockReset(pBlock); + tBlockDataClearData(pBlockData); + while (true) { + if (pRow1 == NULL && pRow2 == NULL) { + if (pBlockData->nRow == 0) { + break; + } else { + goto _write_block; + } } - tsdbDebug("vgId:%d, FSET %d at level %d disk id %d is opened to read to commit", REPO_ID(pRepo), - TSDB_FSET_FID(pSet), TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet)); - } else { - pCommith->isRFileSet = false; - } - - // Set and open commit FSET - if (pSet == NULL || did.level > TSDB_FSET_LEVEL(pSet)) { - // Create a new FSET to write data - tsdbInitDFileSet(pRepo, pWSet, did, fid, FS_TXN_VERSION(REPO_FS(pRepo))); - - if (tsdbCreateDFileSet(pRepo, pWSet, true) < 0) { - tsdbError("vgId:%d, failed to create FSET %d at level %d disk id %d since %s", REPO_ID(pRepo), - TSDB_FSET_FID(pWSet), TSDB_FSET_LEVEL(pWSet), TSDB_FSET_ID(pWSet), tstrerror(terrno)); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); + if (pRow1 && pRow2) { + int32_t c = tsdbRowCmprFn(pRow1, pRow2); + if (c < 0) { + goto _append_mem_row; + } else if (c > 0) { + goto _append_block_row; + } else { + ASSERT(0); } - return -1; + } else if (pRow1) { + goto _append_mem_row; + } else { + goto _append_block_row; } - pCommith->isDFileSame = false; - pCommith->isLFileSame = false; + _append_mem_row: + code = tBlockDataAppendRow(pBlockData, pRow1, pCommitter->skmRow.pTSchema); + if (code) goto _err; - tsdbDebug("vgId:%d, FSET %d at level %d disk id %d is created to commit", REPO_ID(pRepo), TSDB_FSET_FID(pWSet), - TSDB_FSET_LEVEL(pWSet), TSDB_FSET_ID(pWSet)); - } else { - did.level = TSDB_FSET_LEVEL(pSet); - did.id = TSDB_FSET_ID(pSet); - - pCommith->wSet.fid = fid; - pCommith->wSet.state = 0; - - // TSDB_FILE_HEAD - SDFile *pWHeadf = TSDB_COMMIT_HEAD_FILE(pCommith); - tsdbInitDFile(pRepo, pWHeadf, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_HEAD); - if (tsdbCreateDFile(pRepo, pWHeadf, true, TSDB_FILE_HEAD) < 0) { - tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWHeadf), - tstrerror(terrno)); - - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; + tsdbTbDataIterNext(pIter); + pRow1 = tsdbTbDataIterGet(pIter); + if (pRow1) { + if (tsdbKeyCmprFn(&TSDBROW_KEY(pRow1), &toKey) < 0) { + code = tsdbCommitterUpdateRowSchema(pCommitter, pBlockIdx->suid, pBlockIdx->uid, TSDBROW_SVERSION(pRow1)); + if (code) goto _err; + } else { + pRow1 = NULL; } } - // TSDB_FILE_DATA - SDFile *pRDataf = TSDB_READ_DATA_FILE(&(pCommith->readh)); - SDFile *pWDataf = TSDB_COMMIT_DATA_FILE(pCommith); - tsdbInitDFileEx(pWDataf, pRDataf); - // if (tsdbOpenDFile(pWDataf, O_WRONLY) < 0) { - if (tsdbOpenDFile(pWDataf, TD_FILE_WRITE) < 0) { - tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWDataf), - tstrerror(terrno)); - - tsdbCloseDFileSet(pWSet); - tsdbRemoveDFile(pWHeadf); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; - } - } - pCommith->isDFileSame = true; - - // TSDB_FILE_LAST - SDFile *pRLastf = TSDB_READ_LAST_FILE(&(pCommith->readh)); - SDFile *pWLastf = TSDB_COMMIT_LAST_FILE(pCommith); - if (pRLastf->info.size < 32 * 1024) { - tsdbInitDFileEx(pWLastf, pRLastf); - pCommith->isLFileSame = true; - - // if (tsdbOpenDFile(pWLastf, O_WRONLY) < 0) { - if (tsdbOpenDFile(pWLastf, TD_FILE_WRITE) < 0) { - tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf), - tstrerror(terrno)); - - tsdbCloseDFileSet(pWSet); - tsdbRemoveDFile(pWHeadf); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; - } - } + if (pBlockData->nRow >= pCommitter->maxRow * 4 / 5) { + goto _write_block; } else { - tsdbInitDFile(pRepo, pWLastf, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_LAST); - pCommith->isLFileSame = false; - - if (tsdbCreateDFile(pRepo, pWLastf, true, TSDB_FILE_LAST) < 0) { - tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf), - tstrerror(terrno)); - - tsdbCloseDFileSet(pWSet); - (void)tsdbRemoveDFile(pWHeadf); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; - } - } + continue; } - // TSDB_FILE_SMAD - SDFile *pRSmadF = TSDB_READ_SMAD_FILE(&(pCommith->readh)); - SDFile *pWSmadF = TSDB_COMMIT_SMAD_FILE(pCommith); - - if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmadF))) { - tsdbDebug("vgId:%d, create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmadF)); - tsdbInitDFile(pRepo, pWSmadF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAD); + _append_block_row: + code = tBlockDataAppendRow(pBlockData, pRow2, NULL); + if (code) goto _err; - if (tsdbCreateDFile(pRepo, pWSmadF, true, TSDB_FILE_SMAD) < 0) { - tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF), - tstrerror(terrno)); - - tsdbCloseDFileSet(pWSet); - (void)tsdbRemoveDFile(pWHeadf); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; - } - } + if (pRow2->iRow + 1 < pBlockDataMerge->nRow) { + *pRow2 = tsdbRowFromBlockData(pBlockDataMerge, pRow2->iRow + 1); } else { - tsdbInitDFileEx(pWSmadF, pRSmadF); - if (tsdbOpenDFile(pWSmadF, O_RDWR) < 0) { - tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF), - tstrerror(terrno)); - - tsdbCloseDFileSet(pWSet); - tsdbRemoveDFile(pWHeadf); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; - } - } + pRow2 = NULL; } - // TSDB_FILE_SMAL - SDFile *pRSmalF = TSDB_READ_SMAL_FILE(&(pCommith->readh)); - SDFile *pWSmalF = TSDB_COMMIT_SMAL_FILE(pCommith); - - if ((pCommith->isLFileSame) && taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmalF))) { - tsdbInitDFileEx(pWSmalF, pRSmalF); - if (tsdbOpenDFile(pWSmalF, O_RDWR) < 0) { - tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF), - tstrerror(terrno)); - - tsdbCloseDFileSet(pWSet); - tsdbRemoveDFile(pWHeadf); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; - } - } + if (pBlockData->nRow >= pCommitter->maxRow * 4 / 5) { + goto _write_block; } else { - tsdbDebug("vgId:%d, create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmalF)); - tsdbInitDFile(pRepo, pWSmalF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAL); - - if (tsdbCreateDFile(pRepo, pWSmalF, true, TSDB_FILE_SMAL) < 0) { - tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF), - tstrerror(terrno)); - - tsdbCloseDFileSet(pWSet); - (void)tsdbRemoveDFile(pWHeadf); - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); - return -1; - } - } + continue; } - } - - return 0; -} -// extern int32_t tsTsdbMetaCompactRatio; + _write_block: + code = tsdbCommitBlockData(pCommitter, pBlockData, pBlock, pBlockIdx, toDataOnly); + if (code) goto _err; -static 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; + tBlockReset(pBlock); + tBlockDataClearData(pBlockData); } - 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->suid = pTable->suid; - pBlkInfo->uid = pTable->uid; - - memcpy((void *)(pBlkInfo->blocks), taosArrayGet(pSupA, 0), nSupBlocks * sizeof(SBlock)); - if (nSubBlocks > 0) { - memcpy((void *)(pBlkInfo->blocks + nSupBlocks), taosArrayGet(pSubA, 0), nSubBlocks * sizeof(SBlock)); + return code; - for (int i = 0; i < nSupBlocks; i++) { - pBlock = pBlkInfo->blocks + i; +_err: + tsdbError("vgId:%d tsdb merge block and mem failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; +} - if (pBlock->numOfSubBlocks > 1) { - pBlock->offset += (sizeof(SBlockInfo) + sizeof(SBlock) * nSupBlocks); +static int32_t tsdbCommitTableMemData(SCommitter *pCommitter, STbDataIter *pIter, TSDBKEY toKey, int8_t toDataOnly) { + int32_t code = 0; + TSDBROW *pRow; + SBlock block; + SBlock *pBlock = █ + SBlockData *pBlockData = &pCommitter->nBlockData; + int64_t suid = pIter->pTbData->suid; + int64_t uid = pIter->pTbData->uid; + + code = tBlockDataSetSchema(pBlockData, pCommitter->skmTable.pTSchema); + if (code) goto _err; + + tBlockReset(pBlock); + tBlockDataClearData(pBlockData); + pRow = tsdbTbDataIterGet(pIter); + ASSERT(pRow && tsdbKeyCmprFn(&TSDBROW_KEY(pRow), &toKey) < 0); + while (true) { + if (pRow == NULL) { + if (pBlockData->nRow > 0) { + goto _write_block; + } else { + break; } } - } - - 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); + // update schema + code = tsdbCommitterUpdateRowSchema(pCommitter, suid, uid, TSDBROW_SVERSION(pRow)); + if (code) goto _err; + + // append + code = tBlockDataAppendRow(pBlockData, pRow, pCommitter->skmRow.pTSchema); + if (code) goto _err; + + tsdbTbDataIterNext(pIter); + pRow = tsdbTbDataIterGet(pIter); + // if (pRow && tsdbKeyCmprFn(&TSDBROW_KEY(pRow), &toKey) >= 0) pRow = NULL; + // crash on CI, use the block following + if (pRow) { + TSDBKEY tmpKey = TSDBROW_KEY(pRow); + if (tsdbKeyCmprFn(&tmpKey, &toKey) >= 0) { + pRow = NULL; + } + } - pIdx->suid = pTable->suid; - pIdx->uid = pTable->uid; - pIdx->hasLast = pBlock->last ? 1 : 0; - pIdx->maxKey = pBlock->maxKey; - pIdx->numOfBlocks = (uint32_t)nSupBlocks; - pIdx->len = tlen; - pIdx->offset = (uint32_t)offset; + if (pBlockData->nRow >= pCommitter->maxRow * 4 / 5) goto _write_block; + continue; - return 0; -} + _write_block: + code = tsdbCommitBlockData(pCommitter, pBlockData, pBlock, &(SBlockIdx){.suid = suid, .uid = uid}, toDataOnly); + if (code) goto _err; -static 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; + tBlockReset(pBlock); + tBlockDataClearData(pBlockData); } - 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; + return code; - void *ptr = POINTER_SHIFT(*ppBuf, tlen); - tsdbEncodeSBlockIdx(&ptr, pBlkIdx); +_err: + tsdbError("vgId:%d tsdb commit table mem data failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; +} - tlen += size; - } +static int32_t tsdbCommitTableDiskData(SCommitter *pCommitter, SBlock *pBlock, SBlockIdx *pBlockIdx) { + int32_t code = 0; + SBlock block; - tlen += sizeof(TSCKSUM); - if (tsdbMakeRoom(ppBuf, tlen) < 0) return -1; - taosCalcChecksumAppend(0, (uint8_t *)(*ppBuf), tlen); + if (pBlock->last) { + code = tsdbReadBlockData(pCommitter->pReader, pBlockIdx, pBlock, &pCommitter->oBlockData, NULL, NULL); + if (code) goto _err; - if (tsdbAppendDFile(pHeadf, *ppBuf, tlen, &offset) < tlen) { - return -1; + tBlockReset(&block); + code = tsdbCommitBlockData(pCommitter, &pCommitter->oBlockData, &block, pBlockIdx, 0); + if (code) goto _err; + } else { + code = tMapDataPutItem(&pCommitter->nBlockMap, pBlock, tPutBlock); + if (code) goto _err; } - tsdbUpdateDFileMagic(pHeadf, POINTER_SHIFT(*ppBuf, tlen - sizeof(TSCKSUM))); - pHeadf->info.offset = (uint32_t)offset; - pHeadf->info.len = tlen; + return code; - return 0; +_err: + tsdbError("vgId:%d tsdb commit table disk data failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; } -// =================== Commit Time-Series Data -static int tsdbCommitToTable(SCommitH *pCommith, int tid) { - SCommitIter *pIter = pCommith->iters + tid; - TSKEY nextKey = tsdbNextIterKey(pIter->pIter); - - tsdbResetCommitTable(pCommith); +static int32_t tsdbCommitTableDataEnd(SCommitter *pCommitter, int64_t suid, int64_t uid) { + int32_t code = 0; + SBlockIdx blockIdx = {.suid = suid, .uid = uid}; + SBlockIdx *pBlockIdx = &blockIdx; - // Set commit table - if (tsdbSetCommitTable(pCommith, pIter->pTable) < 0) { - return -1; - } + code = tsdbWriteBlock(pCommitter->pWriter, &pCommitter->nBlockMap, NULL, pBlockIdx); + if (code) goto _err; - // No disk data and no memory data, just return - if (pCommith->readh.pBlkIdx == NULL && (nextKey == TSDB_DATA_TIMESTAMP_NULL || nextKey > pCommith->maxKey)) { - return 0; + if (taosArrayPush(pCommitter->aBlockIdxN, pBlockIdx) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; } - // Must has disk data or has memory data - int nBlocks; - int bidx = 0; - SBlock *pBlock; - - if (pCommith->readh.pBlkIdx) { - if (tsdbLoadBlockInfo(&(pCommith->readh), NULL) < 0) { - return -1; - } + return code; - nBlocks = pCommith->readh.pBlkIdx->numOfBlocks; - } else { - nBlocks = 0; - } +_err: + tsdbError("vgId:%d commit table data end failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; +} - if (bidx < nBlocks) { - pBlock = pCommith->readh.pBlkInfo->blocks + bidx; - } else { - pBlock = NULL; - } +static int32_t tsdbGetOvlpNRow(STbDataIter *pIter, SBlock *pBlock) { + int32_t nRow = 0; + TSDBROW *pRow; + TSDBKEY key; + int32_t c = 0; + STbDataIter iter = *pIter; + iter.pRow = NULL; while (true) { - if (pBlock == NULL && (nextKey == TSDB_DATA_TIMESTAMP_NULL || nextKey > pCommith->maxKey)) break; + pRow = tsdbTbDataIterGet(pIter); - if ((nextKey == TSDB_DATA_TIMESTAMP_NULL || nextKey > pCommith->maxKey) || - (pBlock && (!pBlock->last) && tsdbComparKeyBlock((void *)(&nextKey), pBlock) > 0)) { - if (tsdbMoveBlock(pCommith, bidx) < 0) { - return -1; - } + if (pRow == NULL) break; + key = TSDBROW_KEY(pRow); - bidx++; - if (bidx < nBlocks) { - pBlock = pCommith->readh.pBlkInfo->blocks + bidx; - } else { - pBlock = NULL; - } - } else if (pBlock && (pBlock->last || tsdbComparKeyBlock((void *)(&nextKey), pBlock) == 0)) { - // merge pBlock data and memory data - if (tsdbMergeMemData(pCommith, pIter, bidx) < 0) { - return -1; - } - - bidx++; - if (bidx < nBlocks) { - pBlock = pCommith->readh.pBlkInfo->blocks + bidx; - } else { - pBlock = NULL; - } - nextKey = tsdbNextIterKey(pIter->pIter); + c = tBlockCmprFn(&(SBlock){.maxKey = key, .minKey = key}, pBlock); + if (c == 0) { + nRow++; + tsdbTbDataIterNext(pIter); + } else if (c > 0) { + break; } else { - // Only commit memory data - if (pBlock == NULL) { - if (tsdbCommitMemData(pCommith, pIter, pCommith->maxKey, false) < 0) { - return -1; - } - } else { - if (tsdbCommitMemData(pCommith, pIter, pBlock->minKey.ts - 1, true) < 0) { - return -1; - } - } - nextKey = tsdbNextIterKey(pIter->pIter); + ASSERT(0); } } - if (tsdbWriteBlockInfo(pCommith) < 0) { - tsdbError("vgId:%d, failed to write SBlockInfo part into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith), - TSDB_FILE_FULL_NAME(TSDB_COMMIT_HEAD_FILE(pCommith)), tstrerror(terrno)); - return -1; - } - - return 0; + return nRow; } -static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx) { - SReadH *pReadh = &pCommith->readh; - STsdb *pTsdb = TSDB_READ_REPO(pReadh); - STSchema *pTSchema = NULL; - int nBlocks = pIdx->numOfBlocks; - int bidx = 0; - - tsdbResetCommitTable(pCommith); +static int32_t tsdbMergeAsSubBlock(SCommitter *pCommitter, STbDataIter *pIter, SBlock *pBlock) { + int32_t code = 0; + SBlockData *pBlockData = &pCommitter->nBlockData; + SBlockIdx *pBlockIdx = &(SBlockIdx){.suid = pIter->pTbData->suid, .uid = pIter->pTbData->uid}; + SBlock block; + TSDBROW *pRow; - pReadh->pBlkIdx = pIdx; - - if (tsdbLoadBlockInfo(pReadh, NULL) < 0) { - return -1; - } + code = tBlockDataSetSchema(pBlockData, pCommitter->skmTable.pTSchema); + if (code) goto _err; - STable table = {.suid = pIdx->suid, .uid = pIdx->uid, .pSchema = NULL}; - pCommith->pTable = &table; - - while (bidx < nBlocks) { - if (!pTSchema && !tsdbCommitIsSameFile(pCommith, bidx)) { - // Set commit table - pTSchema = metaGetTbTSchema(REPO_META(pTsdb), pIdx->uid, -1); // TODO: schema version - if (!pTSchema) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - table.pSchema = pTSchema; - if (tsdbSetCommitTable(pCommith, &table) < 0) { - taosMemoryFreeClear(pTSchema); - return -1; + pRow = tsdbTbDataIterGet(pIter); + code = tsdbCommitterUpdateRowSchema(pCommitter, pBlockIdx->suid, pBlockIdx->uid, TSDBROW_SVERSION(pRow)); + if (code) goto _err; + while (true) { + if (pRow) break; + code = tBlockDataAppendRow(pBlockData, pRow, pCommitter->skmRow.pTSchema); + if (code) goto _err; + + tsdbTbDataIterNext(pIter); + pRow = tsdbTbDataIterGet(pIter); + if (pRow) { + TSDBKEY key = TSDBROW_KEY(pRow); + int32_t c = tBlockCmprFn(&(SBlock){.minKey = key, .maxKey = key}, pBlock); + + if (c == 0) { + code = + tsdbCommitterUpdateRowSchema(pCommitter, pIter->pTbData->suid, pIter->pTbData->uid, TSDBROW_SVERSION(pRow)); + if (code) goto _err; + } else if (c > 0) { + pRow = NULL; + } else { + ASSERT(0); } } - - if (tsdbMoveBlock(pCommith, bidx) < 0) { - tsdbError("vgId:%d, failed to move block into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith), - TSDB_FILE_FULL_NAME(TSDB_COMMIT_HEAD_FILE(pCommith)), tstrerror(terrno)); - taosMemoryFreeClear(pTSchema); - return -1; - } - - ++bidx; } - if (tsdbWriteBlockInfo(pCommith) < 0) { - tsdbError("vgId:%d, failed to write SBlockInfo part into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith), - TSDB_FILE_FULL_NAME(TSDB_COMMIT_HEAD_FILE(pCommith)), tstrerror(terrno)); - taosMemoryFreeClear(pTSchema); - return -1; - } + block = *pBlock; + code = tsdbCommitBlockData(pCommitter, pBlockData, &block, pBlockIdx, 0); + if (code) goto _err; - taosMemoryFreeClear(pTSchema); - return 0; + return code; + +_err: + tsdbError("vgId:%d tsdb merge as subblock failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; } -static int tsdbSetCommitTable(SCommitH *pCommith, STable *pTable) { - STSchema *pSchema = tsdbGetTableSchemaImpl(TSDB_COMMIT_REPO(pCommith), pTable, false, false, -1); +static int32_t tsdbCommitTableData(SCommitter *pCommitter, STbData *pTbData, SBlockIdx *pBlockIdx) { + int32_t code = 0; + STbDataIter iter = {0}; + STbDataIter *pIter = &iter; + TSDBROW *pRow; + int32_t iBlock; + int32_t nBlock; + int64_t suid; + int64_t uid; + + if (pTbData) { + tsdbTbDataIterOpen(pTbData, &(TSDBKEY){.ts = pCommitter->minKey, .version = VERSION_MIN}, 0, pIter); + pRow = tsdbTbDataIterGet(pIter); + if (pRow && TSDBROW_TS(pRow) > pCommitter->maxKey) pRow = NULL; + + suid = pTbData->suid; + uid = pTbData->uid; + } else { + pIter = NULL; + pRow = NULL; + } - pCommith->pTable = pTable; + if (pBlockIdx) { + code = tsdbReadBlock(pCommitter->pReader, pBlockIdx, &pCommitter->oBlockMap, NULL); + if (code) goto _err; - if (tdInitDataCols(pCommith->pDataCols, pSchema) < 0) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } + nBlock = pCommitter->oBlockMap.nItem; + ASSERT(nBlock > 0); - if (pCommith->isRFileSet) { - if (tsdbSetReadTable(&(pCommith->readh), pTable) < 0) { - return -1; - } + suid = pBlockIdx->suid; + uid = pBlockIdx->uid; } else { - pCommith->readh.pBlkIdx = NULL; + nBlock = 0; } - return 0; -} -static int tsdbComparKeyBlock(const void *arg1, const void *arg2) { - TSKEY key = *(TSKEY *)arg1; - SBlock *pBlock = (SBlock *)arg2; + if (pRow == NULL && nBlock == 0) goto _exit; + + // start =========== + tMapDataReset(&pCommitter->nBlockMap); + SBlock block; + SBlock *pBlock = █ - if (key < pBlock->minKey.ts) { - return -1; - } else if (key > pBlock->maxKey.ts) { - return 1; + iBlock = 0; + if (iBlock < nBlock) { + tMapDataGetItemByIdx(&pCommitter->oBlockMap, iBlock, pBlock, tGetBlock); } else { - return 0; + pBlock = NULL; } -} -/** - * @brief Write SDataCols to data file. - * - * @param pRepo - * @param pTable - * @param pDFile - * @param pDFileAggr - * @param pDataCols The pDataCols would be generated from mem/imem directly with 2 bits bitmap or from tsdbRead - * interface with 1 bit bitmap. - * @param pBlock - * @param isLast - * @param isSuper - * @param ppBuf - * @param ppCBuf - * @param ppExBuf - * @return int - */ -static int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDFileAggr, SDataCols *pDataCols, - SBlock *pBlock, bool isLast, bool isSuper, void **ppBuf, void **ppCBuf, void **ppExBuf) { - STsdbCfg *pCfg = REPO_CFG(pRepo); - SBlockData *pBlockData = NULL; - SAggrBlkData *pAggrBlkData = NULL; - STSchema *pSchema = pTable->pSchema; - int64_t offset = 0, offsetAggr = 0; - int rowsToWrite = pDataCols->numOfRows; - - ASSERT(rowsToWrite > 0 && rowsToWrite <= pCfg->maxRows); - ASSERT((!isLast) || rowsToWrite < pCfg->minRows); - - // Make buffer space - if (tsdbMakeRoom(ppBuf, tsdbBlockStatisSize(pDataCols->numOfCols, SBlockVerLatest)) < 0) { - return -1; + if (pRow) { + code = tsdbCommitterUpdateTableSchema(pCommitter, pTbData->suid, pTbData->uid, pTbData->maxSkmVer); + if (code) goto _err; } - pBlockData = (SBlockData *)(*ppBuf); - if (tsdbMakeRoom(ppExBuf, tsdbBlockAggrSize(pDataCols->numOfCols, SBlockVerLatest)) < 0) { - return -1; - } - pAggrBlkData = (SAggrBlkData *)(*ppExBuf); - - // Get # of cols not all NULL(not including key column) - col_id_t nColsNotAllNull = 0; - col_id_t nColsOfBlockSma = 0; - for (int ncol = 1; ncol < pDataCols->numOfCols; ++ncol) { // ncol from 1, we skip the timestamp column - STColumn *pColumn = pSchema->columns + ncol; - SDataCol *pDataCol = pDataCols->cols + ncol; - SBlockCol *pBlockCol = pBlockData->cols + nColsNotAllNull; - SAggrBlkCol *pAggrBlkCol = (SAggrBlkCol *)pAggrBlkData + nColsOfBlockSma; - - if (isAllRowsNull(pDataCol)) { // all data to commit are NULL, just ignore it - continue; - } + // merge =========== + while (true) { + if (pRow == NULL && pBlock == NULL) break; + + if (pRow && pBlock) { + if (pBlock->last) { + code = tsdbMergeTableData(pCommitter, pIter, pBlock, + (TSDBKEY){.ts = pCommitter->maxKey + 1, .version = VERSION_MIN}, 0); + if (code) goto _err; + + pRow = tsdbTbDataIterGet(pIter); + if (pRow && TSDBROW_TS(pRow) > pCommitter->maxKey) pRow = NULL; + iBlock++; + if (iBlock < nBlock) { + tMapDataGetItemByIdx(&pCommitter->oBlockMap, iBlock, pBlock, tGetBlock); + } else { + pBlock = NULL; + } - memset(pBlockCol, 0, sizeof(*pBlockCol)); - memset(pAggrBlkCol, 0, sizeof(*pAggrBlkCol)); - - pBlockCol->colId = pDataCol->colId; - pBlockCol->type = pDataCol->type; - pAggrBlkCol->colId = pDataCol->colId; - - if (isSuper && IS_BSMA_ON(pColumn) && tDataTypes[pDataCol->type].statisFunc) { -#if 0 - (*tDataTypes[pDataCol->type].statisFunc)(pDataCol->pData, rowsToWrite, &(pBlockCol->min), &(pBlockCol->max), - &(pBlockCol->sum), &(pBlockCol->minIndex), &(pBlockCol->maxIndex), - &(pBlockCol->numOfNull)); -#endif - (*tDataTypes[pDataCol->type].statisFunc)(pDataCols->bitmapMode, pDataCol->pBitmap, pDataCol->pData, rowsToWrite, - &(pAggrBlkCol->min), &(pAggrBlkCol->max), &(pAggrBlkCol->sum), - &(pAggrBlkCol->minIndex), &(pAggrBlkCol->maxIndex), - &(pAggrBlkCol->numOfNull)); - - if (pAggrBlkCol->numOfNull == 0) { - pBlockCol->blen = 0; + ASSERT(pRow == NULL && pBlock == NULL); } else { - pBlockCol->blen = 1; - } - ++nColsOfBlockSma; - } else if (tdIsBitmapBlkNorm(pDataCol->pBitmap, rowsToWrite, pDataCols->bitmapMode)) { - // check if all rows normal - pBlockCol->blen = 0; - } else { - pBlockCol->blen = 1; - } - - ++nColsNotAllNull; - } - - ASSERT(nColsNotAllNull >= 0 && nColsNotAllNull <= pDataCols->numOfCols); - - // Compress the data if neccessary - int tcol = 0; // counter of not all NULL and written columns - uint32_t toffset = 0; - int32_t tsize = (int32_t)tsdbBlockStatisSize(nColsNotAllNull, SBlockVerLatest); - int32_t lsize = tsize; - uint32_t tsizeAggr = (uint32_t)tsdbBlockAggrSize(nColsOfBlockSma, SBlockVerLatest); - int32_t keyLen = 0; - int32_t nBitmaps = (int32_t)TD_BITMAP_BYTES(rowsToWrite); - int32_t sBitmaps = isSuper ? (int32_t)TD_BITMAP_BYTES_I(rowsToWrite) : nBitmaps; - - for (int ncol = 0; ncol < pDataCols->numOfCols; ++ncol) { - // All not NULL columns finish - if (ncol != 0 && tcol >= nColsNotAllNull) break; - - SDataCol *pDataCol = pDataCols->cols + ncol; - SBlockCol *pBlockCol = pBlockData->cols + tcol; - - if (ncol != 0 && (pDataCol->colId != pBlockCol->colId)) continue; - - int32_t flen; // final length - int32_t tlen = dataColGetNEleLen(pDataCol, rowsToWrite, pDataCols->bitmapMode); + int32_t c = tBlockCmprFn(&(SBlock){.maxKey = TSDBROW_KEY(pRow), .minKey = TSDBROW_KEY(pRow)}, pBlock); + if (c > 0) { + // only disk data + code = tsdbCommitTableDiskData(pCommitter, pBlock, pBlockIdx); + if (code) goto _err; + + iBlock++; + if (iBlock < nBlock) { + tMapDataGetItemByIdx(&pCommitter->oBlockMap, iBlock, pBlock, tGetBlock); + } else { + pBlock = NULL; + } + } else if (c < 0) { + // only memory data + code = tsdbCommitTableMemData(pCommitter, pIter, pBlock->minKey, 1); + if (code) goto _err; -#ifdef TD_SUPPORT_BITMAP - int32_t tBitmaps = 0; - int32_t tBitmapsLen = 0; - if ((ncol != 0) && (pBlockCol->blen > 0)) { - tBitmaps = isSuper ? sBitmaps : nBitmaps; - } -#endif + pRow = tsdbTbDataIterGet(pIter); + if (pRow && TSDBROW_TS(pRow) > pCommitter->maxKey) pRow = NULL; + } else { + // merge memory and disk + int32_t nOvlp = tsdbGetOvlpNRow(pIter, pBlock); + ASSERT(nOvlp); + if (pBlock->nRow + nOvlp <= pCommitter->maxRow && pBlock->nSubBlock < TSDB_MAX_SUBBLOCKS) { + code = tsdbMergeAsSubBlock(pCommitter, pIter, pBlock); + if (code) goto _err; + } else { + TSDBKEY toKey = {.ts = pCommitter->maxKey + 1, .version = VERSION_MIN}; + int8_t toDataOnly = 0; - void *tptr, *bptr; + if (iBlock < nBlock - 1) { + toDataOnly = 1; - // Make room - if (tsdbMakeRoom(ppBuf, lsize + tlen + tBitmaps + 2 * COMP_OVERFLOW_BYTES + sizeof(TSCKSUM)) < 0) { - return -1; - } - pBlockData = (SBlockData *)(*ppBuf); - pBlockCol = pBlockData->cols + tcol; - tptr = POINTER_SHIFT(pBlockData, lsize); + SBlock nextBlock = {0}; + tBlockReset(&nextBlock); + tMapDataGetItemByIdx(&pCommitter->oBlockMap, iBlock + 1, &nextBlock, tGetBlock); + toKey = nextBlock.minKey; + } - if (pCfg->compression == TWO_STAGE_COMP && tsdbMakeRoom(ppCBuf, tlen + COMP_OVERFLOW_BYTES) < 0) { - return -1; - } + code = tsdbMergeTableData(pCommitter, pIter, pBlock, toKey, toDataOnly); + if (code) goto _err; + } - // Compress or just copy - if (pCfg->compression) { -#if 0 - flen = (*(tDataTypes[pDataCol->type].compFunc))((char *)pDataCol->pData, tlen, rowsToWrite + tBitmaps, tptr, - tlen + COMP_OVERFLOW_BYTES, pCfg->compression, *ppCBuf, - tlen + COMP_OVERFLOW_BYTES); -#endif - flen = (*(tDataTypes[pDataCol->type].compFunc))((char *)pDataCol->pData, tlen, rowsToWrite, tptr, - tlen + COMP_OVERFLOW_BYTES, pCfg->compression, *ppCBuf, - tlen + COMP_OVERFLOW_BYTES); - if (tBitmaps > 0) { - bptr = POINTER_SHIFT(pBlockData, lsize + flen); - if (isSuper && !tdDataColsIsBitmapI(pDataCols)) { - tdMergeBitmap((uint8_t *)pDataCol->pBitmap, rowsToWrite, (uint8_t *)pDataCol->pBitmap); - } - tBitmapsLen = - tsCompressTinyint((char *)pDataCol->pBitmap, tBitmaps, tBitmaps, bptr, tBitmaps + COMP_OVERFLOW_BYTES, - pCfg->compression, *ppCBuf, tBitmaps + COMP_OVERFLOW_BYTES); - TASSERT((tBitmapsLen > 0) && (tBitmapsLen <= (tBitmaps + COMP_OVERFLOW_BYTES))); - flen += tBitmapsLen; - } - } else { - flen = tlen; - memcpy(tptr, pDataCol->pData, flen); - if (tBitmaps > 0) { - bptr = POINTER_SHIFT(pBlockData, lsize + flen); - if (isSuper && !tdDataColsIsBitmapI(pDataCols)) { - tdMergeBitmap((uint8_t *)pDataCol->pBitmap, rowsToWrite, (uint8_t *)pDataCol->pBitmap); + pRow = tsdbTbDataIterGet(pIter); + if (pRow && TSDBROW_TS(pRow) > pCommitter->maxKey) pRow = NULL; + iBlock++; + if (iBlock < nBlock) { + tMapDataGetItemByIdx(&pCommitter->oBlockMap, iBlock, pBlock, tGetBlock); + } else { + pBlock = NULL; + } } - memcpy(bptr, pDataCol->pBitmap, tBitmaps); - tBitmapsLen = tBitmaps; - flen += tBitmapsLen; } - } + } else if (pBlock) { + code = tsdbCommitTableDiskData(pCommitter, pBlock, pBlockIdx); + if (code) goto _err; - // Add checksum - ASSERT(flen > 0); - ASSERT(tBitmapsLen <= 1024); - flen += sizeof(TSCKSUM); - taosCalcChecksumAppend(0, (uint8_t *)tptr, flen); - tsdbUpdateDFileMagic(pDFile, POINTER_SHIFT(tptr, flen - sizeof(TSCKSUM))); - - if (ncol != 0) { - pBlockCol->offset = toffset; - pBlockCol->len = flen; // data + bitmaps - pBlockCol->blen = tBitmapsLen; - ++tcol; + iBlock++; + if (iBlock < nBlock) { + tMapDataGetItemByIdx(&pCommitter->oBlockMap, iBlock, pBlock, tGetBlock); + } else { + pBlock = NULL; + } } else { - keyLen = flen; - } + code = + tsdbCommitTableMemData(pCommitter, pIter, (TSDBKEY){.ts = pCommitter->maxKey + 1, .version = VERSION_MIN}, 0); + if (code) goto _err; - toffset += flen; - lsize += flen; + pRow = tsdbTbDataIterGet(pIter); + if (pRow && TSDBROW_TS(pRow) > pCommitter->maxKey) pRow = NULL; + ASSERT(pRow == NULL); + } } - pBlockData->delimiter = TSDB_FILE_DELIMITER; - pBlockData->uid = pTable->uid; - pBlockData->numOfCols = nColsNotAllNull; + // end ===================== + code = tsdbCommitTableDataEnd(pCommitter, suid, uid); + if (code) goto _err; - taosCalcChecksumAppend(0, (uint8_t *)pBlockData, tsize); - tsdbUpdateDFileMagic(pDFile, POINTER_SHIFT(pBlockData, tsize - sizeof(TSCKSUM))); - - // Write the whole block to file - if (tsdbAppendDFile(pDFile, (void *)pBlockData, lsize, &offset) < lsize) { - return -1; +_exit: + if (pIter) { + pRow = tsdbTbDataIterGet(pIter); + if (pRow) pCommitter->nextKey = TMIN(pCommitter->nextKey, TSDBROW_TS(pRow)); } + return code; - uint32_t aggrStatus = nColsOfBlockSma > 0 ? 1 : 0; - if (aggrStatus > 0) { - taosCalcChecksumAppend(0, (uint8_t *)pAggrBlkData, tsizeAggr); - tsdbUpdateDFileMagic(pDFileAggr, POINTER_SHIFT(pAggrBlkData, tsizeAggr - sizeof(TSCKSUM))); +_err: + tsdbError("vgId:%d tsdb commit table data failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; +} - // Write the whole block to file - if (tsdbAppendDFile(pDFileAggr, (void *)pAggrBlkData, tsizeAggr, &offsetAggr) < tsizeAggr) { - return -1; - } - } +static int32_t tsdbCommitFileDataEnd(SCommitter *pCommitter) { + int32_t code = 0; - // Update pBlock membership variables - pBlock->last = isLast; - pBlock->offset = offset; - pBlock->algorithm = pCfg->compression; - pBlock->numOfRows = rowsToWrite; - pBlock->len = lsize; - pBlock->keyLen = keyLen; - pBlock->numOfSubBlocks = isSuper ? 1 : 0; - pBlock->numOfCols = nColsNotAllNull; - pBlock->numOfBSma = nColsOfBlockSma; - pBlock->minKey.ts = dataColsKeyFirst(pDataCols); - pBlock->maxKey.ts = dataColsKeyLast(pDataCols); - pBlock->aggrStat = aggrStatus; - pBlock->blkVer = SBlockVerLatest; - pBlock->aggrOffset = (uint64_t)offsetAggr; - - tsdbDebug("vgId:%d, uid:%" PRId64 " a block of data is written to file %s, offset %" PRId64 - " numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64, - REPO_ID(pRepo), pTable->uid, TSDB_FILE_FULL_NAME(pDFile), offset, rowsToWrite, pBlock->len, - pBlock->numOfCols, pBlock->minKey.ts, pBlock->maxKey.ts); - - return 0; -} + // write blockIdx + code = tsdbWriteBlockIdx(pCommitter->pWriter, pCommitter->aBlockIdxN, NULL); + if (code) goto _err; -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, - isLast ? TSDB_COMMIT_SMAL_FILE(pCommith) : TSDB_COMMIT_SMAD_FILE(pCommith), pDataCols, - pBlock, isLast, isSuper, (void **)(&(TSDB_COMMIT_BUF(pCommith))), - (void **)(&(TSDB_COMMIT_COMP_BUF(pCommith))), (void **)(&(TSDB_COMMIT_EXBUF(pCommith)))); -} + // update file header + code = tsdbUpdateDFileSetHeader(pCommitter->pWriter); + if (code) goto _err; -static int tsdbWriteBlockInfo(SCommitH *pCommih) { - SDFile *pHeadf = TSDB_COMMIT_HEAD_FILE(pCommih); - SBlockIdx blkIdx; - STable *pTable = TSDB_COMMIT_TABLE(pCommih); + // upsert SDFileSet + code = tsdbFSStateUpsertDFileSet(pCommitter->pTsdb->fs->nState, tsdbDataFWriterGetWSet(pCommitter->pWriter)); + if (code) goto _err; - if (tsdbWriteBlockInfoImpl(pHeadf, pTable, pCommih->aSupBlk, pCommih->aSubBlk, (void **)(&(TSDB_COMMIT_BUF(pCommih))), - &blkIdx) < 0) { - return -1; - } + // close and sync + code = tsdbDataFWriterClose(&pCommitter->pWriter, 1); + if (code) goto _err; - if (blkIdx.numOfBlocks == 0) { - return 0; + if (pCommitter->pReader) { + code = tsdbDataFReaderClose(&pCommitter->pReader); + goto _err; } - if (taosArrayPush(pCommih->aBlkIdx, (void *)(&blkIdx)) == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } +_exit: + return code; - return 0; +_err: + tsdbError("vgId:%d commit file data end failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; } -static int tsdbCommitMemData(SCommitH *pCommith, SCommitIter *pIter, TSKEY keyLimit, bool toData) { - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - STsdbCfg *pCfg = REPO_CFG(pRepo); - SMergeInfo mInfo; - int32_t defaultRows = TSDB_COMMIT_DEFAULT_ROWS(pCommith); - SDFile *pDFile; - bool isLast; - SBlock block; - - while (true) { - tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, pIter->pIter, keyLimit, defaultRows, - pCommith->pDataCols, NULL, 0, pCfg->update, &mInfo); - - if (pCommith->pDataCols->numOfRows <= 0) break; - - if (toData || pCommith->pDataCols->numOfRows >= pCfg->minRows) { - pDFile = TSDB_COMMIT_DATA_FILE(pCommith); - isLast = false; +static int32_t tsdbCommitFileData(SCommitter *pCommitter) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; + SMemTable *pMemTable = pTsdb->imem; + + // commit file data start + code = tsdbCommitFileDataStart(pCommitter); + if (code) goto _err; + + // commit file data impl + int32_t iTbData = 0; + int32_t nTbData = taosArrayGetSize(pMemTable->aTbData); + int32_t iBlockIdx = 0; + int32_t nBlockIdx = taosArrayGetSize(pCommitter->aBlockIdx); + STbData *pTbData; + SBlockIdx *pBlockIdx; + + ASSERT(nTbData > 0); + + pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData); + pBlockIdx = (iBlockIdx < nBlockIdx) ? (SBlockIdx *)taosArrayGet(pCommitter->aBlockIdx, iBlockIdx) : NULL; + while (pTbData || pBlockIdx) { + if (pTbData && pBlockIdx) { + int32_t c = tTABLEIDCmprFn(pTbData, pBlockIdx); + + if (c == 0) { + goto _commit_table_mem_and_disk; + } else if (c < 0) { + goto _commit_table_mem_data; + } else { + goto _commit_table_disk_data; + } + } else if (pBlockIdx) { + goto _commit_table_disk_data; } else { - pDFile = TSDB_COMMIT_LAST_FILE(pCommith); - isLast = true; + goto _commit_table_mem_data; } - if (tsdbWriteBlock(pCommith, pDFile, pCommith->pDataCols, &block, isLast, true) < 0) return -1; + _commit_table_mem_data: + code = tsdbCommitTableData(pCommitter, pTbData, NULL); + if (code) goto _err; - if (tsdbCommitAddBlock(pCommith, &block, NULL, 0) < 0) { - return -1; - } - } + iTbData++; + pTbData = (iTbData < nTbData) ? (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData) : NULL; + continue; - return 0; -} + _commit_table_disk_data: + code = tsdbCommitTableData(pCommitter, NULL, pBlockIdx); + if (code) goto _err; -static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx) { - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - STsdbCfg *pCfg = REPO_CFG(pRepo); - int nBlocks = pCommith->readh.pBlkIdx->numOfBlocks; - SBlock *pBlock = pCommith->readh.pBlkInfo->blocks + bidx; - TSKEY keyLimit; - int16_t colId = PRIMARYKEY_TIMESTAMP_COL_ID; - SMergeInfo mInfo; - SBlock subBlocks[TSDB_MAX_SUBBLOCKS]; - SBlock block, supBlock; - SDFile *pDFile; - - if (bidx == nBlocks - 1) { - keyLimit = pCommith->maxKey; - } else { - keyLimit = pBlock[1].minKey.ts - 1; - } - - STbDataIter titer = *(pIter->pIter); - if (tsdbLoadBlockDataCols(&(pCommith->readh), pBlock, NULL, &colId, 1, false) < 0) return -1; + iBlockIdx++; + pBlockIdx = (iBlockIdx < nBlockIdx) ? (SBlockIdx *)taosArrayGet(pCommitter->aBlockIdx, iBlockIdx) : NULL; + continue; - tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, &titer, keyLimit, INT32_MAX, NULL, - pCommith->readh.pDCols[0]->cols[0].pData, pCommith->readh.pDCols[0]->numOfRows, pCfg->update, - &mInfo); + _commit_table_mem_and_disk: + code = tsdbCommitTableData(pCommitter, pTbData, pBlockIdx); + if (code) goto _err; - if (mInfo.nOperations == 0) { - // no new data to insert (all updates denied) - if (tsdbMoveBlock(pCommith, bidx) < 0) { - return -1; - } - *(pIter->pIter) = titer; - } else if (pBlock->numOfRows + mInfo.rowsInserted - mInfo.rowsDeleteSucceed == 0) { - // Ignore the block - ASSERT(0); - *(pIter->pIter) = titer; - } else if (tsdbCanAddSubBlock(pCommith, pBlock, &mInfo)) { - // Add a sub-block - tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, pIter->pIter, keyLimit, INT32_MAX, - pCommith->pDataCols, pCommith->readh.pDCols[0]->cols[0].pData, - pCommith->readh.pDCols[0]->numOfRows, pCfg->update, &mInfo); - if (pBlock->last) { - pDFile = TSDB_COMMIT_LAST_FILE(pCommith); - } else { - pDFile = TSDB_COMMIT_DATA_FILE(pCommith); - } + iBlockIdx++; + pBlockIdx = (iBlockIdx < nBlockIdx) ? (SBlockIdx *)taosArrayGet(pCommitter->aBlockIdx, iBlockIdx) : NULL; + iTbData++; + pTbData = (iTbData < nTbData) ? (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData) : NULL; + continue; + } - if (tsdbWriteBlock(pCommith, pDFile, pCommith->pDataCols, &block, pBlock->last, false) < 0) return -1; + // commit file data end + code = tsdbCommitFileDataEnd(pCommitter); + if (code) goto _err; - if (pBlock->numOfSubBlocks == 1) { - subBlocks[0] = *pBlock; - subBlocks[0].numOfSubBlocks = 0; - } else { - memcpy(subBlocks, POINTER_SHIFT(pCommith->readh.pBlkInfo, pBlock->offset), - sizeof(SBlock) * pBlock->numOfSubBlocks); - } - subBlocks[pBlock->numOfSubBlocks] = block; - supBlock = *pBlock; - supBlock.minKey.ts = mInfo.keyFirst; - supBlock.maxKey.ts = mInfo.keyLast; - supBlock.numOfSubBlocks++; - supBlock.numOfRows = pBlock->numOfRows + mInfo.rowsInserted - mInfo.rowsDeleteSucceed; - supBlock.offset = taosArrayGetSize(pCommith->aSubBlk) * sizeof(SBlock); - - if (tsdbCommitAddBlock(pCommith, &supBlock, subBlocks, supBlock.numOfSubBlocks) < 0) return -1; - } else { - if (tsdbLoadBlockData(&(pCommith->readh), pBlock, NULL) < 0) return -1; - if (tsdbMergeBlockData(pCommith, pIter, pCommith->readh.pDCols[0], keyLimit, bidx == (nBlocks - 1)) < 0) return -1; - } + return code; - return 0; +_err: + tsdbError("vgId:%d commit file data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + tsdbDataFReaderClose(&pCommitter->pReader); + tsdbDataFWriterClose(&pCommitter->pWriter, 0); + return code; } -static bool tsdbCommitIsSameFile(SCommitH *pCommith, int bidx) { - SBlock *pBlock = pCommith->readh.pBlkInfo->blocks + bidx; - if (pBlock->last) { - return pCommith->isLFileSame; - } - return pCommith->isDFileSame; -} +// ---------------------------------------------------------------------------- +static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitter *pCommitter) { + int32_t code = 0; -static int tsdbMoveBlock(SCommitH *pCommith, int bidx) { - SBlock *pBlock = pCommith->readh.pBlkInfo->blocks + bidx; - SDFile *pDFile; - SBlock block; - bool isSameFile; + memset(pCommitter, 0, sizeof(*pCommitter)); + ASSERT(pTsdb->mem && pTsdb->imem == NULL); - ASSERT(pBlock->numOfSubBlocks > 0); + // lock(); + pTsdb->imem = pTsdb->mem; + pTsdb->mem = NULL; + // unlock(); - if (pBlock->last) { - pDFile = TSDB_COMMIT_LAST_FILE(pCommith); - isSameFile = pCommith->isLFileSame; - } else { - pDFile = TSDB_COMMIT_DATA_FILE(pCommith); - isSameFile = pCommith->isDFileSame; - } + pCommitter->pTsdb = pTsdb; + pCommitter->commitID = pTsdb->pVnode->state.commitID; + pCommitter->minutes = pTsdb->keepCfg.days; + pCommitter->precision = pTsdb->keepCfg.precision; + pCommitter->minRow = pTsdb->pVnode->config.tsdbCfg.minRows; + pCommitter->maxRow = pTsdb->pVnode->config.tsdbCfg.maxRows; + pCommitter->cmprAlg = pTsdb->pVnode->config.tsdbCfg.compression; - if (isSameFile) { - if (pBlock->numOfSubBlocks == 1) { - if (tsdbCommitAddBlock(pCommith, pBlock, NULL, 0) < 0) { - return -1; - } - } else { - block = *pBlock; - block.offset = sizeof(SBlock) * taosArrayGetSize(pCommith->aSubBlk); + code = tsdbFSBegin(pTsdb->fs); + if (code) goto _err; - if (tsdbCommitAddBlock(pCommith, &block, POINTER_SHIFT(pCommith->readh.pBlkInfo, pBlock->offset), - pBlock->numOfSubBlocks) < 0) { - return -1; - } - } - } else { - if (tsdbLoadBlockData(&(pCommith->readh), pBlock, NULL) < 0) return -1; - if (tsdbWriteBlock(pCommith, pDFile, pCommith->readh.pDCols[0], &block, pBlock->last, true) < 0) return -1; - if (tsdbCommitAddBlock(pCommith, &block, NULL, 0) < 0) return -1; - } + return code; - return 0; +_err: + tsdbError("vgId:%d tsdb start commit failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; } -static int tsdbCommitAddBlock(SCommitH *pCommith, const SBlock *pSupBlock, const SBlock *pSubBlocks, int nSubBlocks) { - if (taosArrayPush(pCommith->aSupBlk, pSupBlock) == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; +static int32_t tsdbCommitDataStart(SCommitter *pCommitter) { + int32_t code = 0; + + pCommitter->aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); + if (pCommitter->aBlockIdx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; } - if (pSubBlocks && taosArrayAddBatch(pCommith->aSubBlk, pSubBlocks, nSubBlocks) == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; + pCommitter->aBlockIdxN = taosArrayInit(0, sizeof(SBlockIdx)); + if (pCommitter->aBlockIdxN == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; } - return 0; + code = tBlockDataInit(&pCommitter->oBlockData); + if (code) goto _exit; + + code = tBlockDataInit(&pCommitter->nBlockData); + if (code) goto _exit; + +_exit: + return code; } -static int tsdbMergeBlockData(SCommitH *pCommith, SCommitIter *pIter, SDataCols *pDataCols, TSKEY keyLimit, - bool isLastOneBlock) { - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - STsdbCfg *pCfg = REPO_CFG(pRepo); - SBlock block; - SDFile *pDFile; - bool isLast; - int32_t defaultRows = TSDB_COMMIT_DEFAULT_ROWS(pCommith); +static void tsdbCommitDataEnd(SCommitter *pCommitter) { + taosArrayDestroy(pCommitter->aBlockIdx); + tMapDataClear(&pCommitter->oBlockMap); + tBlockDataClear(&pCommitter->oBlockData); + taosArrayDestroy(pCommitter->aBlockIdxN); + tMapDataClear(&pCommitter->nBlockMap); + tBlockDataClear(&pCommitter->nBlockData); + tTSchemaDestroy(pCommitter->skmTable.pTSchema); + tTSchemaDestroy(pCommitter->skmRow.pTSchema); +} - int biter = 0; - while (true) { - tsdbLoadAndMergeFromCache(TSDB_COMMIT_REPO(pCommith), pCommith->readh.pDCols[0], &biter, pIter, pCommith->pDataCols, - keyLimit, defaultRows, pCfg->update); +static int32_t tsdbCommitData(SCommitter *pCommitter) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; + SMemTable *pMemTable = pTsdb->imem; - if (pCommith->pDataCols->numOfRows == 0) break; + // check + if (pMemTable->nRow == 0) goto _exit; - if (isLastOneBlock) { - if (pCommith->pDataCols->numOfRows < pCfg->minRows) { - pDFile = TSDB_COMMIT_LAST_FILE(pCommith); - isLast = true; - } else { - pDFile = TSDB_COMMIT_DATA_FILE(pCommith); - isLast = false; - } - } else { - pDFile = TSDB_COMMIT_DATA_FILE(pCommith); - isLast = false; - } + // start ==================== + code = tsdbCommitDataStart(pCommitter); + if (code) goto _err; - if (tsdbWriteBlock(pCommith, pDFile, pCommith->pDataCols, &block, isLast, true) < 0) return -1; - if (tsdbCommitAddBlock(pCommith, &block, NULL, 0) < 0) return -1; + // impl ==================== + pCommitter->nextKey = pMemTable->minKey; + while (pCommitter->nextKey < TSKEY_MAX) { + pCommitter->commitFid = tsdbKeyFid(pCommitter->nextKey, pCommitter->minutes, pCommitter->precision); + tsdbFidKeyRange(pCommitter->commitFid, pCommitter->minutes, pCommitter->precision, &pCommitter->minKey, + &pCommitter->maxKey); + code = tsdbCommitFileData(pCommitter); + if (code) goto _err; } - return 0; + // end ==================== + tsdbCommitDataEnd(pCommitter); + +_exit: + tsdbDebug("vgId:%d commit data done, nRow:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nRow); + return code; + +_err: + tsdbCommitDataEnd(pCommitter); + tsdbError("vgId:%d commit data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; } -static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, - SDataCols *pTarget, TSKEY maxKey, int maxRows, int8_t update) { - TSKEY key1 = INT64_MAX; - TSKEY key2 = INT64_MAX; - TSKEY lastKey = TSKEY_INITIAL_VAL; - STSchema *pSchema = NULL; +static int32_t tsdbCommitDel(SCommitter *pCommitter) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; + SMemTable *pMemTable = pTsdb->imem; - ASSERT(maxRows > 0 && dataColsKeyLast(pDataCols) <= maxKey); - tdResetDataCols(pTarget); + if (pMemTable->nDel == 0) { + goto _exit; + } - pTarget->bitmapMode = pDataCols->bitmapMode; - // TODO: filter Multi-Version - // TODO: support delete function - while (true) { - key1 = (*iter >= pDataCols->numOfRows) ? INT64_MAX : dataColsKeyAt(pDataCols, *iter); - STSRow *row = tsdbNextIterRow(pCommitIter->pIter); - if (row == NULL || TD_ROW_KEY(row) > maxKey) { - key2 = INT64_MAX; - } else { - key2 = TD_ROW_KEY(row); - } + // start + code = tsdbCommitDelStart(pCommitter); + if (code) { + goto _err; + } - if (key1 == INT64_MAX && key2 == INT64_MAX) break; + // impl + int32_t iDelIdx = 0; + int32_t nDelIdx = taosArrayGetSize(pCommitter->aDelIdx); + int32_t iTbData = 0; + int32_t nTbData = taosArrayGetSize(pMemTable->aTbData); + STbData *pTbData; + SDelIdx *pDelIdx; - if (key1 < key2) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++pTarget->numOfRows; - } - for (int i = 0; i < pDataCols->numOfCols; ++i) { - // TODO: dataColAppendVal may fail - SCellVal sVal = {0}; - if (tdGetColDataOfRow(&sVal, pDataCols->cols + i, *iter, pDataCols->bitmapMode) < 0) { - TASSERT(0); - } - tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints, - pTarget->bitmapMode, false); - } + ASSERT(nTbData > 0); - lastKey = key1; - ++(*iter); - } else if (key1 > key2) { - if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) { - pSchema = tsdbGetTableSchemaImpl(pTsdb, pCommitIter->pTable, false, false, TD_ROW_SVER(row)); - ASSERT(pSchema != NULL); - } + pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData); + pDelIdx = (iDelIdx < nDelIdx) ? (SDelIdx *)taosArrayGet(pCommitter->aDelIdx, iDelIdx) : NULL; + while (true) { + if (pTbData == NULL && pDelIdx == NULL) break; - if (key2 == lastKey) { - if (TD_SUPPORT_UPDATE(update)) { - tdAppendSTSRowToDataCol(row, pSchema, pTarget, true); - } + if (pTbData && pDelIdx) { + int32_t c = tTABLEIDCmprFn(pTbData, pDelIdx); + + if (c == 0) { + goto _commit_mem_and_disk_del; + } else if (c < 0) { + goto _commit_mem_del; } else { - if (lastKey != TSKEY_INITIAL_VAL) { - ++pTarget->numOfRows; - } - tdAppendSTSRowToDataCol(row, pSchema, pTarget, false); - lastKey = key2; + goto _commit_disk_del; } - - tsdbTbDataIterNext(pCommitIter->pIter); + } else if (pTbData) { + goto _commit_mem_del; } else { - if (lastKey != key1) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++pTarget->numOfRows; - } - lastKey = key1; - } - - // copy disk data - for (int i = 0; i < pDataCols->numOfCols; ++i) { - SCellVal sVal = {0}; - // no duplicated TS keys in pDataCols from file - if (tdGetColDataOfRow(&sVal, pDataCols->cols + i, *iter, pDataCols->bitmapMode) < 0) { - TASSERT(0); - } - // TODO: tdAppendValToDataCol may fail - tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints, - pTarget->bitmapMode, false); - } + goto _commit_disk_del; + } - if (TD_SUPPORT_UPDATE(update)) { - // copy mem data(Multi-Version) - if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) { - pSchema = tsdbGetTableSchemaImpl(pTsdb, pCommitIter->pTable, false, false, TD_ROW_SVER(row)); - ASSERT(pSchema != NULL); - } + _commit_mem_del: + code = tsdbCommitTableDel(pCommitter, pTbData, NULL); + if (code) goto _err; - // TODO: merge with Multi-Version - tdAppendSTSRowToDataCol(row, pSchema, pTarget, true); - } - ++(*iter); - tsdbTbDataIterNext(pCommitIter->pIter); - } + iTbData++; + pTbData = (iTbData < nTbData) ? (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData) : NULL; + continue; - if (pTarget->numOfRows >= (maxRows - 1)) break; - } + _commit_disk_del: + code = tsdbCommitTableDel(pCommitter, NULL, pDelIdx); + if (code) goto _err; - if (lastKey != TSKEY_INITIAL_VAL) { - ++pTarget->numOfRows; - } -} + iDelIdx++; + pDelIdx = (iDelIdx < nDelIdx) ? (SDelIdx *)taosArrayGet(pCommitter->aDelIdx, iDelIdx) : NULL; + continue; -static void tsdbResetCommitTable(SCommitH *pCommith) { - taosArrayClear(pCommith->aSubBlk); - taosArrayClear(pCommith->aSupBlk); - pCommith->pTable = NULL; -} + _commit_mem_and_disk_del: + code = tsdbCommitTableDel(pCommitter, pTbData, pDelIdx); + if (code) goto _err; -static void tsdbCloseCommitFile(SCommitH *pCommith, bool hasError) { - if (pCommith->isRFileSet) { - tsdbCloseAndUnsetFSet(&(pCommith->readh)); + iTbData++; + pTbData = (iTbData < nTbData) ? (STbData *)taosArrayGetP(pMemTable->aTbData, iTbData) : NULL; + iDelIdx++; + pDelIdx = (iDelIdx < nDelIdx) ? (SDelIdx *)taosArrayGet(pCommitter->aDelIdx, iDelIdx) : NULL; + continue; } - if (!hasError) { - TSDB_FSET_FSYNC(TSDB_COMMIT_WRITE_FSET(pCommith)); + // end + code = tsdbCommitDelEnd(pCommitter); + if (code) { + goto _err; } - tsdbCloseDFileSet(TSDB_COMMIT_WRITE_FSET(pCommith)); -} - -static bool tsdbCanAddSubBlock(SCommitH *pCommith, SBlock *pBlock, SMergeInfo *pInfo) { - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - STsdbCfg *pCfg = REPO_CFG(pRepo); - int mergeRows = pBlock->numOfRows + pInfo->rowsInserted - pInfo->rowsDeleteSucceed; - ASSERT(mergeRows > 0); - - if (pBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && pInfo->nOperations <= pCfg->maxRows) { - if (pBlock->last) { - if (pCommith->isLFileSame && mergeRows < pCfg->minRows) return true; - } else { - if (pCommith->isDFileSame && mergeRows <= pCfg->maxRows) return true; - } - } +_exit: + tsdbDebug("vgId:%d commit del done, nDel:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nDel); + return code; - return false; +_err: + tsdbError("vgId:%d commit del failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; } -static int tsdbAppendTableRowToCols(STsdb *pTsdb, STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, - bool merge) { - if (pCols) { - if (*ppSchema == NULL || schemaVersion(*ppSchema) != TD_ROW_SVER(row)) { - *ppSchema = tsdbGetTableSchemaImpl(pTsdb, pTable, false, false, TD_ROW_SVER(row)); - if (*ppSchema == NULL) { - ASSERT(false); - return -1; - } - } - - tdAppendSTSRowToDataCol(row, *ppSchema, pCols, merge); - } - - return 0; +static int32_t tsdbCommitCache(SCommitter *pCommitter) { + int32_t code = 0; + // TODO + return code; } -static int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, STbDataIter *pIter, TSKEY maxKey, int maxRowsToRead, - SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, - SMergeInfo *pMergeInfo) { - ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0); - if (pIter == NULL) return 0; - STSchema *pSchema = NULL; - TSKEY rowKey = 0; - TSKEY fKey = 0; - // only fetch lastKey from mem data as file data not used in this function actually - TSKEY lastKey = TSKEY_INITIAL_VAL; - bool isRowDel = false; - int filterIter = 0; - STSRow *row = NULL; - SMergeInfo mInfo; - - // TODO: support Multi-Version(the rows with the same TS keys in memory can't be merged if its version refered by - // query handle) - - if (pMergeInfo == NULL) pMergeInfo = &mInfo; - - memset(pMergeInfo, 0, sizeof(*pMergeInfo)); - pMergeInfo->keyFirst = INT64_MAX; - pMergeInfo->keyLast = INT64_MIN; - if (pCols) tdResetDataCols(pCols); - - row = tsdbNextIterRow(pIter); - if (row == NULL || TD_ROW_KEY(row) > maxKey) { - rowKey = INT64_MAX; - isRowDel = false; - } else { - rowKey = TD_ROW_KEY(row); - isRowDel = TD_ROW_IS_DELETED(row); - } +static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno) { + int32_t code = 0; + STsdb *pTsdb = pCommitter->pTsdb; + SMemTable *pMemTable = pTsdb->imem; - if (filterIter >= nFilterKeys) { - fKey = INT64_MAX; + if (eno == 0) { + code = tsdbFSCommit(pTsdb->fs); } else { - fKey = tdGetKey(filterKeys[filterIter]); + code = tsdbFSRollback(pTsdb->fs); } - // 1. fkey - no dup since merged up to maxVersion of each query handle by tsdbLoadBlockDataCols - // 2. rowKey - would dup since Multi-Version supported - while (true) { - if (fKey == INT64_MAX && rowKey == INT64_MAX) break; - - if (fKey < rowKey) { - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey); - filterIter++; - if (filterIter >= nFilterKeys) { - fKey = INT64_MAX; - } else { - fKey = tdGetKey(filterKeys[filterIter]); - } -#if 1 - } else if (fKey > rowKey) { - if (isRowDel) { - // TODO: support delete function - pMergeInfo->rowsDeleteFailed++; - } else { - if (pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed >= maxRowsToRead) break; - if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; - - if (lastKey != rowKey) { - pMergeInfo->rowsInserted++; - pMergeInfo->nOperations++; - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey); - if (pCols) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++pCols->numOfRows; - } - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); - } - lastKey = rowKey; - } else { - if (keepDup) { - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true); - } else { - // discard - } - } - } - - tsdbTbDataIterNext(pIter); - row = tsdbNextIterRow(pIter); - if (row == NULL || TD_ROW_KEY(row) > maxKey) { - rowKey = INT64_MAX; - isRowDel = false; - } else { - rowKey = TD_ROW_KEY(row); - isRowDel = TD_ROW_IS_DELETED(row); - } - } else { // fkey == rowKey - if (isRowDel) { // TODO: support delete function(How to stands for delete in file? rowVersion = -1?) - ASSERT(!keepDup); - if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; - pMergeInfo->rowsDeleteSucceed++; - pMergeInfo->nOperations++; - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); - } else { - if (keepDup) { - if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; - if (lastKey != rowKey) { - pMergeInfo->rowsUpdated++; - pMergeInfo->nOperations++; - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey); - if (pCols) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++pCols->numOfRows; - } - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); - } - lastKey = rowKey; - } else { - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true); - } - } else { - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey); - } - } - - tsdbTbDataIterNext(pIter); - row = tsdbNextIterRow(pIter); - if (row == NULL || TD_ROW_KEY(row) > maxKey) { - rowKey = INT64_MAX; - isRowDel = false; - } else { - rowKey = TD_ROW_KEY(row); - isRowDel = TD_ROW_IS_DELETED(row); - } + tsdbMemTableDestroy(pMemTable); + pTsdb->imem = NULL; - filterIter++; - if (filterIter >= nFilterKeys) { - fKey = INT64_MAX; - } else { - fKey = tdGetKey(filterKeys[filterIter]); - } - } -#endif - } - if (pCols && (lastKey != TSKEY_INITIAL_VAL)) { - ++pCols->numOfRows; - } + tsdbInfo("vgId:%d tsdb end commit", TD_VID(pTsdb->pVnode)); + return code; - return 0; -} \ No newline at end of file +_err: + tsdbError("vgId:%d tsdb end commit failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} diff --git a/source/dnode/vnode/src/tsdb/tsdbDelete.c b/source/dnode/vnode/src/tsdb/tsdbDelete.c deleted file mode 100644 index 6dea4a4e57392be988126c579648f39a8270b9bf..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/tsdb/tsdbDelete.c +++ /dev/null @@ -1,14 +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 . - */ \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 055b6c62de47a3cbf05870ad7e23d8ce23fa449b..d498fa71ab3cab764c240d7e08b52f36d952ace2 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -15,1054 +15,681 @@ #include "tsdb.h" -extern const char *TSDB_LEVEL_DNAME[]; - -typedef enum { TSDB_TXN_TEMP_FILE = 0, TSDB_TXN_CURR_FILE } TSDB_TXN_FILE_T; -static const char *tsdbTxnFname[] = {"current.t", "current"}; -#define TSDB_MAX_FSETS(keep, days) ((keep) / (days) + 3) -#define TSDB_MAX_INIT_FSETS (365000) - -static int tsdbComparFidFSet(const void *arg1, const void *arg2); -static void tsdbResetFSStatus(SFSStatus *pStatus); -static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus); -static void tsdbApplyFSTxnOnDisk(SFSStatus *pFrom, SFSStatus *pTo); -static void tsdbGetTxnFname(STsdb *pRepo, TSDB_TXN_FILE_T ftype, char fname[]); -static int tsdbOpenFSFromCurrent(STsdb *pRepo); -static int tsdbScanAndTryFixFS(STsdb *pRepo); -static int tsdbScanRootDir(STsdb *pRepo); -static int tsdbScanDataDir(STsdb *pRepo); -static bool tsdbIsTFileInFS(STsdbFS *pfs, const STfsFile *pf); -static int tsdbRestoreCurrent(STsdb *pRepo); -static int tsdbComparTFILE(const void *arg1, const void *arg2); -static void tsdbScanAndTryFixDFilesHeader(STsdb *pRepo, int32_t *nExpired); -// static int tsdbProcessExpiredFS(STsdb *pRepo); -// static int tsdbCreateMeta(STsdb *pRepo); - -static void tsdbGetRootDir(int repoid, const char *dir, char dirName[]) { - snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/%s", repoid, dir); -} - -static void tsdbGetDataDir(int repoid, const char *dir, char dirName[]) { - snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/%s/data", repoid, dir); -} - -// For backward compatibility -// ================== CURRENT file header info -static int tsdbEncodeFSHeader(void **buf, SFSHeader *pHeader) { - int tlen = 0; - - tlen += taosEncodeFixedU32(buf, pHeader->version); - tlen += taosEncodeFixedU32(buf, pHeader->len); - - return tlen; -} - -static void *tsdbDecodeFSHeader(void *buf, SFSHeader *pHeader) { - buf = taosDecodeFixedU32(buf, &(pHeader->version)); - buf = taosDecodeFixedU32(buf, &(pHeader->len)); - - return buf; -} - -// ================== STsdbFSMeta -static int tsdbEncodeFSMeta(void **buf, STsdbFSMeta *pMeta) { - int tlen = 0; - - tlen += taosEncodeFixedU32(buf, pMeta->version); - tlen += taosEncodeFixedI64(buf, pMeta->totalPoints); - tlen += taosEncodeFixedI64(buf, pMeta->totalStorage); - - return tlen; -} - -static void *tsdbDecodeFSMeta(void *buf, STsdbFSMeta *pMeta) { - buf = taosDecodeFixedU32(buf, &(pMeta->version)); - buf = taosDecodeFixedI64(buf, &(pMeta->totalPoints)); - buf = taosDecodeFixedI64(buf, &(pMeta->totalStorage)); - - return buf; -} - -// ================== SFSStatus -static int tsdbEncodeDFileSetArray(void **buf, SArray *pArray) { - int tlen = 0; - uint64_t nset = taosArrayGetSize(pArray); - - tlen += taosEncodeFixedU64(buf, nset); - for (size_t i = 0; i < nset; i++) { - SDFileSet *pSet = taosArrayGet(pArray, i); +// ================================================================================================= +static int32_t tPutFSState(uint8_t *p, STsdbFSState *pState) { + int32_t n = 0; + int8_t hasDel = pState->pDelFile ? 1 : 0; + uint32_t nDFileSet = taosArrayGetSize(pState->aDFileSet); - tlen += tsdbEncodeDFileSet(buf, pSet); + // SDelFile + n += tPutI8(p ? p + n : p, hasDel); + if (hasDel) { + n += tPutDelFile(p ? p + n : p, pState->pDelFile); } - return tlen; -} - -static void *tsdbDecodeDFileSetArray(STsdb *pRepo, void *buf, SArray *pArray) { - uint64_t nset = 0; - - taosArrayClear(pArray); - - buf = taosDecodeFixedU64(buf, &nset); - for (size_t i = 0; i < nset; i++) { - SDFileSet dset = {0}; - buf = tsdbDecodeDFileSet(pRepo, buf, &dset); - taosArrayPush(pArray, (void *)(&dset)); + // SArray + n += tPutU32v(p ? p + n : p, nDFileSet); + for (uint32_t iDFileSet = 0; iDFileSet < nDFileSet; iDFileSet++) { + n += tPutDFileSet(p ? p + n : p, (SDFileSet *)taosArrayGet(pState->aDFileSet, iDFileSet)); } - return buf; -} -static int tsdbEncodeFSStatus(void **buf, SFSStatus *pStatus) { - // ASSERT(pStatus->pmf); - - int tlen = 0; - - // tlen += tsdbEncodeSMFile(buf, pStatus->pmf); - tlen += tsdbEncodeDFileSetArray(buf, pStatus->df); - - return tlen; + return n; } -static void *tsdbDecodeFSStatus(STsdb *pRepo, void *buf, SFSStatus *pStatus) { - tsdbResetFSStatus(pStatus); - - // pStatus->pmf = &(pStatus->mf); - - // buf = tsdbDecodeSMFile(buf, pStatus->pmf); - buf = tsdbDecodeDFileSetArray(pRepo, buf, pStatus->df); - - return buf; -} - -static SFSStatus *tsdbNewFSStatus(int maxFSet) { - SFSStatus *pStatus = (SFSStatus *)taosMemoryCalloc(1, sizeof(*pStatus)); - if (pStatus == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return NULL; - } - - // TSDB_FILE_SET_CLOSED(&(pStatus->mf)); - - pStatus->df = taosArrayInit(maxFSet, sizeof(SDFileSet)); - if (pStatus->df == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - taosMemoryFree(pStatus); - return NULL; - } - - return pStatus; -} +static int32_t tGetFSState(uint8_t *p, STsdbFSState *pState) { + int32_t n = 0; + int8_t hasDel; + uint32_t nDFileSet; + SDFileSet *pSet = &(SDFileSet){0}; -static SFSStatus *tsdbFreeFSStatus(SFSStatus *pStatus) { - if (pStatus) { - pStatus->df = taosArrayDestroy(pStatus->df); - taosMemoryFree(pStatus); + // SDelFile + n += tGetI8(p + n, &hasDel); + if (hasDel) { + pState->pDelFile = &pState->delFile; + n += tGetDelFile(p + n, pState->pDelFile); + } else { + pState->pDelFile = NULL; } - return NULL; -} - -static void tsdbResetFSStatus(SFSStatus *pStatus) { - if (pStatus == NULL) { - return; + // SArray + taosArrayClear(pState->aDFileSet); + n += tGetU32v(p + n, &nDFileSet); + for (uint32_t iDFileSet = 0; iDFileSet < nDFileSet; iDFileSet++) { + n += tGetDFileSet(p + n, pSet); + taosArrayPush(pState->aDFileSet, pSet); } - // TSDB_FILE_SET_CLOSED(&(pStatus->mf)); - - // pStatus->pmf = NULL; - taosArrayClear(pStatus->df); + return n; } -// static void tsdbSetStatusMFile(SFSStatus *pStatus, const SMFile *pMFile) { -// ASSERT(pStatus->pmf == NULL); - -// pStatus->pmf = &(pStatus->mf); -// tsdbInitMFileEx(pStatus->pmf, (SMFile *)pMFile); -// } +static int32_t tsdbGnrtCurrent(const char *fname, STsdbFSState *pState) { + int32_t code = 0; + int64_t n; + int64_t size; + uint8_t *pData; + TdFilePtr pFD = NULL; -static int tsdbAddDFileSetToStatus(SFSStatus *pStatus, const SDFileSet *pSet) { - if (taosArrayPush(pStatus->df, (void *)pSet) == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - - TSDB_FSET_SET_CLOSED(((SDFileSet *)taosArrayGetLast(pStatus->df))); - - return 0; -} - -// ================== STsdbFS -STsdbFS *tsdbNewFS(const STsdbKeepCfg *pCfg) { - int keep = pCfg->keep2; - int days = pCfg->days; - int maxFSet = TSDB_MAX_FSETS(keep, days); - STsdbFS *pfs; - - pfs = (STsdbFS *)taosMemoryCalloc(1, sizeof(*pfs)); - if (pfs == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return NULL; - } - - int code = taosThreadRwlockInit(&(pfs->lock), NULL); - if (code) { - terrno = TAOS_SYSTEM_ERROR(code); - taosMemoryFree(pfs); - return NULL; - } - - if (maxFSet > TSDB_MAX_INIT_FSETS) { - maxFSet = TSDB_MAX_INIT_FSETS; + // to binary + size = tPutFSState(NULL, pState) + sizeof(TSCKSUM); + pData = taosMemoryMalloc(size); + if (pData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; } + n = tPutFSState(pData, pState); + ASSERT(n + sizeof(TSCKSUM) == size); + taosCalcChecksumAppend(0, pData, size); - pfs->cstatus = tsdbNewFSStatus(maxFSet); - if (pfs->cstatus == NULL) { - tsdbFreeFS(pfs); - return NULL; + // create and write + pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE); + if (pFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } - pfs->intxn = false; - pfs->nstatus = tsdbNewFSStatus(maxFSet); - if (pfs->nstatus == NULL) { - tsdbFreeFS(pfs); - return NULL; + n = taosWriteFile(pFD, pData, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } - return pfs; -} - -void *tsdbFreeFS(STsdbFS *pfs) { - if (pfs) { - pfs->nstatus = tsdbFreeFSStatus(pfs->nstatus); - pfs->cstatus = tsdbFreeFSStatus(pfs->cstatus); - taosThreadRwlockDestroy(&(pfs->lock)); - taosMemoryFree(pfs); + if (taosFsyncFile(pFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } - return NULL; -} + taosCloseFile(&pFD); -int tsdbOpenFS(STsdb *pRepo) { - STsdbFS *pfs = REPO_FS(pRepo); - char current[TSDB_FILENAME_LEN] = "\0"; - int nExpired = 0; - - ASSERT(pfs != NULL); - - tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current); - - tsdbGetRtnSnap(pRepo, &pRepo->rtn); - if (taosCheckExistFile(current)) { - if (tsdbOpenFSFromCurrent(pRepo) < 0) { - tsdbError("vgId:%d, failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno)); - return -1; - } + if (pData) taosMemoryFree(pData); + return code; - tsdbScanAndTryFixDFilesHeader(pRepo, &nExpired); - // if (nExpired > 0) { - // tsdbProcessExpiredFS(pRepo); - // } +_err: + tsdbError("tsdb gnrt current failed since %s", tstrerror(code)); + if (pData) taosMemoryFree(pData); + return code; +} + +static int32_t tsdbLoadCurrentState(STsdbFS *pFS, STsdbFSState *pState) { + int32_t code = 0; + int64_t size; + int64_t n; + char fname[TSDB_FILENAME_LEN]; + uint8_t *pData = NULL; + TdFilePtr pFD; + + snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pFS->pTsdb->pVnode->pTfs), TD_DIRSEP, + pFS->pTsdb->path, TD_DIRSEP); + + if (!taosCheckExistFile(fname)) { + // create an empry CURRENT file if not exists + code = tsdbGnrtCurrent(fname, pState); + if (code) goto _err; } else { - // should skip expired fileset inside of the function - if (tsdbRestoreCurrent(pRepo) < 0) { - tsdbError("vgId:%d, failed to restore current file since %s", REPO_ID(pRepo), tstrerror(terrno)); - return -1; + // open the file and load + pFD = taosOpenFile(fname, TD_FILE_READ); + if (pFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } - } - if (tsdbScanAndTryFixFS(pRepo) < 0) { - tsdbError("vgId:%d, failed to scan and fix FS since %s", REPO_ID(pRepo), tstrerror(terrno)); - return -1; - } - - // // Load meta cache if has meta file - // if ((!(pRepo->state & TSDB_STATE_BAD_META)) && tsdbLoadMetaCache(pRepo, true) < 0) { - // tsdbError("vgId:%d, failed to open FS while loading meta cache since %s", REPO_ID(pRepo), tstrerror(terrno)); - // return -1; - // } - - return 0; -} + if (taosFStatFile(pFD, &size, NULL) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } -void tsdbCloseFS(STsdb *pRepo) { - // Do nothing -} + pData = taosMemoryMalloc(size); + if (pData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } -// Start a new transaction to modify the file system -void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd) { - STsdbFS *pfs = REPO_FS(pRepo); - ASSERT(pfs->intxn == false); - - pfs->intxn = true; - tsdbResetFSStatus(pfs->nstatus); - pfs->nstatus->meta = pfs->cstatus->meta; - // if (pfs->cstatus->pmf == NULL) { - pfs->nstatus->meta.version += 1; - // } else { - // pfs->nstatus->meta.version = pfs->cstatus->meta.version + 1; - // } - pfs->nstatus->meta.totalPoints = pfs->cstatus->meta.totalPoints + pointsAdd; - pfs->nstatus->meta.totalStorage = pfs->cstatus->meta.totalStorage += storageAdd; -} + n = taosReadFile(pFD, pData, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } -void tsdbUpdateFSTxnMeta(STsdbFS *pfs, STsdbFSMeta *pMeta) { pfs->nstatus->meta = *pMeta; } + if (!taosCheckChecksumWhole(pData, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } -int tsdbEndFSTxn(STsdb *pRepo) { - STsdbFS *pfs = REPO_FS(pRepo); - ASSERT(FS_IN_TXN(pfs)); - SFSStatus *pStatus; + taosCloseFile(&pFD); - // Write current file system snapshot - if (tsdbSaveFSStatus(pRepo, pfs->nstatus) < 0) { - tsdbEndFSTxnWithError(pfs); - return -1; + // decode + tGetFSState(pData, pState); } - // Make new - tsdbWLockFS(pfs); - pStatus = pfs->cstatus; - pfs->cstatus = pfs->nstatus; - pfs->nstatus = pStatus; - tsdbUnLockFS(pfs); - - // Apply actual change to each file and SDFileSet - tsdbApplyFSTxnOnDisk(pfs->nstatus, pfs->cstatus); - - pfs->intxn = false; - return 0; -} + if (pData) taosMemoryFree(pData); + return code; -int tsdbEndFSTxnWithError(STsdbFS *pfs) { - tsdbApplyFSTxnOnDisk(pfs->nstatus, pfs->cstatus); - // TODO: if mf change, reload pfs->metaCache - pfs->intxn = false; - return 0; +_err: + tsdbError("vgId:%d tsdb load current state failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); + if (pData) taosMemoryFree(pData); + return code; } -// void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile) { tsdbSetStatusMFile(pfs->nstatus, pMFile); } - -int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet) { return tsdbAddDFileSetToStatus(pfs->nstatus, pSet); } - -static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) { - SFSHeader fsheader; - void *pBuf = NULL; - void *ptr; - char hbuf[TSDB_FILE_HEAD_SIZE] = "\0"; - char tfname[TSDB_FILENAME_LEN] = "\0"; - char cfname[TSDB_FILENAME_LEN] = "\0"; +static int32_t tsdbApplyDFileSetChange(STsdbFS *pFS, SDFileSet *pFrom, SDFileSet *pTo) { + int32_t code = 0; + char fname[TSDB_FILENAME_LEN]; - tsdbGetTxnFname(pRepo, TSDB_TXN_TEMP_FILE, tfname); - tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, cfname); - - TdFilePtr pFile = taosOpenFile(tfname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); - if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - fsheader.version = TSDB_LATEST_SFS_VER; - if (taosArrayGetSize(pStatus->df) == 0) { - fsheader.len = 0; - } else { - fsheader.len = tsdbEncodeFSStatus(NULL, pStatus) + sizeof(TSCKSUM); - } - - // Encode header part and write - ptr = hbuf; - tsdbEncodeFSHeader(&ptr, &fsheader); - tsdbEncodeFSMeta(&ptr, &(pStatus->meta)); - - taosCalcChecksumAppend(0, (uint8_t *)hbuf, TSDB_FILE_HEAD_SIZE); - - if (taosWriteFile(pFile, hbuf, TSDB_FILE_HEAD_SIZE) < TSDB_FILE_HEAD_SIZE) { - terrno = TAOS_SYSTEM_ERROR(errno); - taosCloseFile(&pFile); - taosRemoveFile(tfname); - return -1; - } - - // Encode file status and write to file - if (fsheader.len > 0) { - if (tsdbMakeRoom(&(pBuf), fsheader.len) < 0) { - taosCloseFile(&pFile); - taosRemoveFile(tfname); - return -1; + if (pFrom && pTo) { + // head + if (tsdbFileIsSame(pFrom, pTo, TSDB_HEAD_FILE)) { + ASSERT(pFrom->fHead.size == pTo->fHead.size); + ASSERT(pFrom->fHead.offset == pTo->fHead.offset); + } else { + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_HEAD_FILE, fname); + taosRemoveFile(fname); } - ptr = pBuf; - tsdbEncodeFSStatus(&ptr, pStatus); - taosCalcChecksumAppend(0, (uint8_t *)pBuf, fsheader.len); - - if (taosWriteFile(pFile, pBuf, fsheader.len) < fsheader.len) { - terrno = TAOS_SYSTEM_ERROR(errno); - taosCloseFile(&pFile); - (void)taosRemoveFile(tfname); - taosTZfree(pBuf); - return -1; + // data + if (tsdbFileIsSame(pFrom, pTo, TSDB_DATA_FILE)) { + if (pFrom->fData.size > pTo->fData.size) { + code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_DATA_FILE); + if (code) goto _err; + } + } else { + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_DATA_FILE, fname); + taosRemoveFile(fname); } - } - // fsync, close and rename - if (taosFsyncFile(pFile) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - taosCloseFile(&pFile); - taosRemoveFile(tfname); - taosTZfree(pBuf); - return -1; - } - - (void)taosCloseFile(&pFile); - (void)taosRenameFile(tfname, cfname); - taosTZfree(pBuf); - - return 0; -} - -static void tsdbApplyFSTxnOnDisk(SFSStatus *pFrom, SFSStatus *pTo) { - int ifrom = 0; - int ito = 0; - size_t sizeFrom, sizeTo; - SDFileSet *pSetFrom; - SDFileSet *pSetTo; + // last + if (tsdbFileIsSame(pFrom, pTo, TSDB_LAST_FILE)) { + if (pFrom->fLast.size > pTo->fLast.size) { + code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_LAST_FILE); + if (code) goto _err; + } + } else { + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_LAST_FILE, fname); + taosRemoveFile(fname); + } - sizeFrom = taosArrayGetSize(pFrom->df); - sizeTo = taosArrayGetSize(pTo->df); + // sma + if (tsdbFileIsSame(pFrom, pTo, TSDB_SMA_FILE)) { + if (pFrom->fSma.size > pTo->fSma.size) { + code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_SMA_FILE); + if (code) goto _err; + } + } else { + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_SMA_FILE, fname); + taosRemoveFile(fname); + } + } else if (pFrom) { + // head + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_HEAD_FILE, fname); + taosRemoveFile(fname); - // Apply meta file change - // (void)tsdbApplyMFileChange(pFrom->pmf, pTo->pmf); + // data + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_DATA_FILE, fname); + taosRemoveFile(fname); - // Apply SDFileSet change - if (ifrom >= sizeFrom) { - pSetFrom = NULL; - } else { - pSetFrom = taosArrayGet(pFrom->df, ifrom); - } + // last + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_LAST_FILE, fname); + taosRemoveFile(fname); - if (ito >= sizeTo) { - pSetTo = NULL; - } else { - pSetTo = taosArrayGet(pTo->df, ito); + // fsm + tsdbDataFileName(pFS->pTsdb, pFrom, TSDB_SMA_FILE, fname); + taosRemoveFile(fname); } - while (true) { - if ((pSetTo == NULL) && (pSetFrom == NULL)) break; - - if (pSetTo == NULL || (pSetFrom && pSetFrom->fid < pSetTo->fid)) { - tsdbApplyDFileSetChange(pSetFrom, NULL); + return code; - ifrom++; - if (ifrom >= sizeFrom) { - pSetFrom = NULL; - } else { - pSetFrom = taosArrayGet(pFrom->df, ifrom); - } - } else if (pSetFrom == NULL || pSetFrom->fid > pSetTo->fid) { - // Do nothing - ito++; - if (ito >= sizeTo) { - pSetTo = NULL; - } else { - pSetTo = taosArrayGet(pTo->df, ito); - } - } else { - tsdbApplyDFileSetChange(pSetFrom, pSetTo); +_err: + tsdbError("vgId:%d tsdb apply disk file set change failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); + return code; +} - ifrom++; - if (ifrom >= sizeFrom) { - pSetFrom = NULL; - } else { - pSetFrom = taosArrayGet(pFrom->df, ifrom); - } +static int32_t tsdbApplyDelFileChange(STsdbFS *pFS, SDelFile *pFrom, SDelFile *pTo) { + int32_t code = 0; + char fname[TSDB_FILENAME_LEN]; - ito++; - if (ito >= sizeTo) { - pSetTo = NULL; - } else { - pSetTo = taosArrayGet(pTo->df, ito); + if (pFrom && pTo) { + if (pFrom != pTo) { + tsdbDelFileName(pFS->pTsdb, pFrom, fname); + if (taosRemoveFile(fname) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } } + } else if (pFrom) { + tsdbDelFileName(pFS->pTsdb, pFrom, fname); + if (taosRemoveFile(fname) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + } else { + // do nothing } -} - -// ================== SFSIter -// ASSUMPTIONS: the FS Should be read locked when calling these functions -void tsdbFSIterInit(SFSIter *pIter, STsdbFS *pfs, int direction) { - pIter->pfs = pfs; - pIter->direction = direction; - size_t size = taosArrayGetSize(pfs->cstatus->df); + return code; - pIter->version = pfs->cstatus->meta.version; - - if (size == 0) { - pIter->index = -1; - pIter->fid = TSDB_IVLD_FID; - } else { - if (direction == TSDB_FS_ITER_FORWARD) { - pIter->index = 0; +_err: + tsdbError("vgId:%d tsdb apply del file change failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t tsdbFSApplyDiskChange(STsdbFS *pFS, STsdbFSState *pFrom, STsdbFSState *pTo) { + int32_t code = 0; + int32_t iFrom = 0; + int32_t nFrom = taosArrayGetSize(pFrom->aDFileSet); + int32_t iTo = 0; + int32_t nTo = taosArrayGetSize(pTo->aDFileSet); + SDFileSet *pDFileSetFrom; + SDFileSet *pDFileSetTo; + + // SDelFile + code = tsdbApplyDelFileChange(pFS, pFrom->pDelFile, pTo->pDelFile); + if (code) goto _err; + + // SDFileSet + while (iFrom < nFrom && iTo < nTo) { + pDFileSetFrom = (SDFileSet *)taosArrayGet(pFrom->aDFileSet, iFrom); + pDFileSetTo = (SDFileSet *)taosArrayGet(pTo->aDFileSet, iTo); + + if (pDFileSetFrom->fid == pDFileSetTo->fid) { + code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, pDFileSetTo); + if (code) goto _err; + + iFrom++; + iTo++; + } else if (pDFileSetFrom->fid < pDFileSetTo->fid) { + code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, NULL); + if (code) goto _err; + + iFrom++; } else { - pIter->index = (int)(size - 1); + iTo++; } - - pIter->fid = ((SDFileSet *)taosArrayGet(pfs->cstatus->df, pIter->index))->fid; } -} -void tsdbFSIterSeek(SFSIter *pIter, int fid) { - STsdbFS *pfs = pIter->pfs; - size_t size = taosArrayGetSize(pfs->cstatus->df); + while (iFrom < nFrom) { + pDFileSetFrom = (SDFileSet *)taosArrayGet(pFrom->aDFileSet, iFrom); + code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, NULL); + if (code) goto _err; - int flags; - if (pIter->direction == TSDB_FS_ITER_FORWARD) { - flags = TD_GE; - } else { - flags = TD_LE; + iFrom++; } - void *ptr = taosbsearch(&fid, pfs->cstatus->df->pData, size, sizeof(SDFileSet), tsdbComparFidFSet, flags); - if (ptr == NULL) { - pIter->index = -1; - pIter->fid = TSDB_IVLD_FID; - } else { - pIter->index = (int)(TARRAY_ELEM_IDX(pfs->cstatus->df, ptr)); - pIter->fid = ((SDFileSet *)ptr)->fid; - } -} +#if 0 + // do noting + while (iTo < nTo) { + pDFileSetTo = (SDFileSet *)taosArrayGetP(pTo->aDFileSet, iTo); + code = tsdbApplyDFileSetChange(pFS, NULL, pDFileSetTo); + if (code) goto _err; -SDFileSet *tsdbFSIterNext(SFSIter *pIter) { - STsdbFS *pfs = pIter->pfs; - SDFileSet *pSet; - - if (pIter->index < 0) { - ASSERT(pIter->fid == TSDB_IVLD_FID); - return NULL; + iTo++; } +#endif - ASSERT(pIter->fid != TSDB_IVLD_FID); - - if (pIter->version != pfs->cstatus->meta.version) { - pIter->version = pfs->cstatus->meta.version; - tsdbFSIterSeek(pIter, pIter->fid); - } + return code; - if (pIter->index < 0) { - return NULL; - } +_err: + tsdbError("vgId:%d tsdb fs apply disk change failed sicne %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); + return code; +} - pSet = (SDFileSet *)taosArrayGet(pfs->cstatus->df, pIter->index); - ASSERT(pSet->fid == pIter->fid); +static void tsdbFSDestroy(STsdbFS *pFS) { + if (pFS) { + if (pFS->nState) { + taosArrayDestroy(pFS->nState->aDFileSet); + taosMemoryFree(pFS->nState); + } - if (pIter->direction == TSDB_FS_ITER_FORWARD) { - pIter->index++; - if (pIter->index >= taosArrayGetSize(pfs->cstatus->df)) { - pIter->index = -1; + if (pFS->cState) { + taosArrayDestroy(pFS->cState->aDFileSet); + taosMemoryFree(pFS->cState); } - } else { - pIter->index--; - } - if (pIter->index >= 0) { - pIter->fid = ((SDFileSet *)taosArrayGet(pfs->cstatus->df, pIter->index))->fid; - } else { - pIter->fid = TSDB_IVLD_FID; + taosThreadRwlockDestroy(&pFS->lock); + taosMemoryFree(pFS); } - - return pSet; + // TODO } -static int tsdbComparFidFSet(const void *arg1, const void *arg2) { - int fid = *(int *)arg1; - SDFileSet *pSet = (SDFileSet *)arg2; +static int32_t tsdbFSCreate(STsdb *pTsdb, STsdbFS **ppFS) { + int32_t code = 0; + STsdbFS *pFS = NULL; - if (fid < pSet->fid) { - return -1; - } else if (fid == pSet->fid) { - return 0; - } else { - return 1; + pFS = (STsdbFS *)taosMemoryCalloc(1, sizeof(*pFS)); + if (pFS == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; } -} + pFS->pTsdb = pTsdb; -static void tsdbGetTxnFname(STsdb *pRepo, TSDB_TXN_FILE_T ftype, char fname[]) { - snprintf(fname, TSDB_FILENAME_LEN, "%s/vnode/vnode%d/%s/%s", tfsGetPrimaryPath(REPO_TFS(pRepo)), REPO_ID(pRepo), - pRepo->dir, tsdbTxnFname[ftype]); -} - -static int tsdbOpenFSFromCurrent(STsdb *pRepo) { - STsdbFS *pfs = REPO_FS(pRepo); - TdFilePtr pFile = NULL; - void *buffer = NULL; - SFSHeader fsheader; - char current[TSDB_FILENAME_LEN] = "\0"; - void *ptr; - - tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current); - - // current file exists, try to recover - pFile = taosOpenFile(current, TD_FILE_READ); - if (pFile == NULL) { - tsdbError("vgId:%d, failed to open file %s since %s", REPO_ID(pRepo), current, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); + code = taosThreadRwlockInit(&pFS->lock, NULL); + if (code) { + taosMemoryFree(pFS); + code = TAOS_SYSTEM_ERROR(code); goto _err; } - if (tsdbMakeRoom(&buffer, TSDB_FILE_HEAD_SIZE) < 0) { + pFS->inTxn = 0; + + pFS->cState = (STsdbFSState *)taosMemoryCalloc(1, sizeof(STsdbFSState)); + if (pFS->cState == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } - - int nread = (int)taosReadFile(pFile, buffer, TSDB_FILE_HEAD_SIZE); - if (nread < 0) { - tsdbError("vgId:%d, failed to read %d bytes from file %s since %s", REPO_ID(pRepo), TSDB_FILENAME_LEN, current, - strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); + pFS->cState->aDFileSet = taosArrayInit(0, sizeof(SDFileSet)); + if (pFS->cState->aDFileSet == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } - if (nread < TSDB_FILE_HEAD_SIZE) { - tsdbError("vgId:%d, failed to read header of file %s, read bytes:%d", REPO_ID(pRepo), current, nread); - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; + pFS->nState = (STsdbFSState *)taosMemoryCalloc(1, sizeof(STsdbFSState)); + if (pFS->nState == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } - - if (!taosCheckChecksumWhole((uint8_t *)buffer, TSDB_FILE_HEAD_SIZE)) { - tsdbError("vgId:%d, header of file %s failed checksum check", REPO_ID(pRepo), current); - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; + pFS->nState->aDFileSet = taosArrayInit(0, sizeof(SDFileSet)); + if (pFS->nState->aDFileSet == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } - SFSStatus *pStatus = pfs->cstatus; - ptr = buffer; - ptr = tsdbDecodeFSHeader(ptr, &fsheader); - ptr = tsdbDecodeFSMeta(ptr, &(pStatus->meta)); - - if (fsheader.version != TSDB_LATEST_SFS_VER) { - // TODO: handle file version change - } + *ppFS = pFS; + return code; - if (fsheader.len > 0) { - if (tsdbMakeRoom(&buffer, fsheader.len) < 0) { +_err: + tsdbError("vgId:%d tsdb fs create failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + tsdbFSDestroy(pFS); + *ppFS = NULL; + return code; +} + +static int32_t tsdbScanAndTryFixFS(STsdbFS *pFS, int8_t deepScan) { + int32_t code = 0; + STsdb *pTsdb = pFS->pTsdb; + STfs *pTfs = pTsdb->pVnode->pTfs; + int64_t size; + char fname[TSDB_FILENAME_LEN]; + char pHdr[TSDB_FHDR_SIZE]; + TdFilePtr pFD; + + // SDelFile + if (pFS->cState->pDelFile) { + tsdbDelFileName(pTsdb, pFS->cState->pDelFile, fname); + if (taosStatFile(fname, &size, NULL)) { + code = TAOS_SYSTEM_ERROR(errno); goto _err; } - nread = (int)taosReadFile(pFile, buffer, fsheader.len); - if (nread < 0) { - tsdbError("vgId:%d, failed to read file %s since %s", REPO_ID(pRepo), current, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); + if (size != pFS->cState->pDelFile->size) { + code = TSDB_CODE_FILE_CORRUPTED; goto _err; } - if (nread < fsheader.len) { - tsdbError("vgId:%d, failed to read %d bytes from file %s", REPO_ID(pRepo), fsheader.len, current); - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - goto _err; + if (deepScan) { + // TODO } + } + + // SArray + for (int32_t iSet = 0; iSet < taosArrayGetSize(pFS->cState->aDFileSet); iSet++) { + SDFileSet *pDFileSet = (SDFileSet *)taosArrayGet(pFS->cState->aDFileSet, iSet); - if (!taosCheckChecksumWhole((uint8_t *)buffer, fsheader.len)) { - tsdbError("vgId:%d, file %s is corrupted since wrong checksum", REPO_ID(pRepo), current); - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; + // head ========= + tsdbDataFileName(pTsdb, pDFileSet, TSDB_HEAD_FILE, fname); + if (taosStatFile(fname, &size, NULL)) { + code = TAOS_SYSTEM_ERROR(errno); goto _err; } - ptr = buffer; - ptr = tsdbDecodeFSStatus(pRepo, ptr, pStatus); - } else { - tsdbResetFSStatus(pStatus); - } + if (deepScan) { + // TODO + } - taosTZfree(buffer); - taosCloseFile(&pFile); + // data ========= + tsdbDataFileName(pTsdb, pDFileSet, TSDB_DATA_FILE, fname); + if (taosStatFile(fname, &size, NULL)) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } - return 0; + if (size < pDFileSet->fData.size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } else if (size > pDFileSet->fData.size) { + ASSERT(0); + // need to rollback the file + } -_err: - if (pFile != NULL) { - taosCloseFile(&pFile); - } - taosTZfree(buffer); - return -1; -} + if (deepScan) { + // TODO + } -// Scan and try to fix incorrect files -static int tsdbScanAndTryFixFS(STsdb *pRepo) { - STsdbFS *pfs = REPO_FS(pRepo); - SFSStatus *pStatus = pfs->cstatus; + // last =========== + tsdbDataFileName(pTsdb, pDFileSet, TSDB_LAST_FILE, fname); + if (taosStatFile(fname, &size, NULL)) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } - // if (tsdbScanAndTryFixMFile(pRepo) < 0) { - // tsdbError("vgId:%d, failed to fix MFile since %s", REPO_ID(pRepo), tstrerror(terrno)); - // return -1; - // } + if (size < pDFileSet->fLast.size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } else if (size > pDFileSet->fLast.size) { + ASSERT(0); + // need to rollback the file + } - size_t size = taosArrayGetSize(pStatus->df); + if (deepScan) { + // TODO + } - for (size_t i = 0; i < size; i++) { - SDFileSet *pSet = (SDFileSet *)taosArrayGet(pStatus->df, i); + // sma ============= + tsdbDataFileName(pTsdb, pDFileSet, TSDB_SMA_FILE, fname); + if (taosStatFile(fname, &size, NULL)) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } - if (tsdbScanAndTryFixDFileSet(pRepo, pSet) < 0) { - tsdbError("vgId:%d, failed to fix MFile since %s", REPO_ID(pRepo), tstrerror(terrno)); - return -1; + if (size < pDFileSet->fSma.size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } else if (size > pDFileSet->fSma.size) { + ASSERT(0); + // need to rollback the file } - } - // remove those unused files - tsdbScanRootDir(pRepo); - tsdbScanDataDir(pRepo); - return 0; -} + if (deepScan) { + // TODO + } + } -static int tsdbScanRootDir(STsdb *pRepo) { - char rootDir[TSDB_FILENAME_LEN]; - char bname[TSDB_FILENAME_LEN]; - STsdbFS *pfs = REPO_FS(pRepo); + // remove those invalid files (todo) +#if 0 + STfsDir *tdir; const STfsFile *pf; - tsdbGetRootDir(REPO_ID(pRepo), pRepo->dir, rootDir); - STfsDir *tdir = tfsOpendir(REPO_TFS(pRepo), rootDir); + tdir = tfsOpendir(pTfs, pTsdb->path); if (tdir == NULL) { - tsdbError("vgId:%d, failed to open directory %s since %s", REPO_ID(pRepo), rootDir, tstrerror(terrno)); - return -1; + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } while ((pf = tfsReaddir(tdir))) { - tfsBasename(pf, bname); - - if (strcmp(bname, tsdbTxnFname[TSDB_TXN_CURR_FILE]) == 0 || strcmp(bname, "data") == 0) { - // Skip current file and data directory - continue; - } - - // if (/*pfs->cstatus->pmf && */ tfsIsSameFile(pf, &(pfs->cstatus->pmf->f))) { - // continue; - // } - - (void)tfsRemoveFile(pf); - tsdbDebug("vgId:%d, invalid file %s is removed", REPO_ID(pRepo), pf->aname); + tfsBasename(pf, fname); } tfsClosedir(tdir); +#endif - return 0; -} + return code; -static int tsdbScanDataDir(STsdb *pRepo) { - char dataDir[TSDB_FILENAME_LEN]; - char bname[TSDB_FILENAME_LEN]; - STsdbFS *pfs = REPO_FS(pRepo); - const STfsFile *pf; +_err: + tsdbError("vgId:%d tsdb can and try fix fs failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} - tsdbGetDataDir(REPO_ID(pRepo), pRepo->dir, dataDir); - STfsDir *tdir = tfsOpendir(REPO_TFS(pRepo), dataDir); - if (tdir == NULL) { - tsdbError("vgId:%d, failed to open directory %s since %s", REPO_ID(pRepo), dataDir, tstrerror(terrno)); +static int32_t tDFileSetCmprFn(const void *p1, const void *p2) { + if (((SDFileSet *)p1)->fid < ((SDFileSet *)p2)->fid) { return -1; + } else if (((SDFileSet *)p1)->fid > ((SDFileSet *)p2)->fid) { + return 1; } - while ((pf = tfsReaddir(tdir))) { - tfsBasename(pf, bname); - - if (!tsdbIsTFileInFS(pfs, pf)) { - (void)tfsRemoveFile(pf); - tsdbDebug("vgId:%d, invalid file %s is removed", REPO_ID(pRepo), pf->aname); - } - } - - tfsClosedir(tdir); - return 0; } -static bool tsdbIsTFileInFS(STsdbFS *pfs, const STfsFile *pf) { - SFSIter fsiter; - tsdbFSIterInit(&fsiter, pfs, TSDB_FS_ITER_FORWARD); - SDFileSet *pSet; - - while ((pSet = tsdbFSIterNext(&fsiter))) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - SDFile *pDFile = TSDB_DFILE_IN_SET(pSet, ftype); - if (tfsIsSameFile(pf, TSDB_FILE_F(pDFile))) { - return true; - } - } - } - - return false; -} +// EXPOSED APIS ==================================================================================== +int32_t tsdbFSOpen(STsdb *pTsdb, STsdbFS **ppFS) { + int32_t code = 0; -static int tsdbRestoreDFileSet(STsdb *pRepo) { - char dataDir[TSDB_FILENAME_LEN]; - char bname[TSDB_FILENAME_LEN]; - STfsDir *tdir = NULL; - const STfsFile *pf = NULL; - const char *pattern = "^v[0-9]+f[0-9]+\\.(head|data|last|smad|smal)(-ver[0-9]+)?$"; - SArray *fArray = NULL; - regex_t regex; - STsdbFS *pfs = REPO_FS(pRepo); - - tsdbGetDataDir(REPO_ID(pRepo), pRepo->dir, dataDir); - - // Resource allocation and init - regcomp(®ex, pattern, REG_EXTENDED); - - fArray = taosArrayInit(1024, sizeof(STfsFile)); - if (fArray == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tsdbError("vgId:%d, failed to restore DFileSet while open directory %s since %s", REPO_ID(pRepo), dataDir, - tstrerror(terrno)); - regfree(®ex); - return -1; - } + // create handle + code = tsdbFSCreate(pTsdb, ppFS); + if (code) goto _err; - tdir = tfsOpendir(REPO_TFS(pRepo), dataDir); - if (tdir == NULL) { - tsdbError("vgId:%d, failed to restore DFileSet while open directory %s since %s", REPO_ID(pRepo), dataDir, - tstrerror(terrno)); - taosArrayDestroy(fArray); - regfree(®ex); - return -1; + // load current state + code = tsdbLoadCurrentState(*ppFS, (*ppFS)->cState); + if (code) { + tsdbFSDestroy(*ppFS); + goto _err; } - while ((pf = tfsReaddir(tdir))) { - tfsBasename(pf, bname); - - int code = regexec(®ex, bname, 0, NULL, 0); - if (code == 0) { - if (taosArrayPush(fArray, (void *)pf) == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tfsClosedir(tdir); - taosArrayDestroy(fArray); - regfree(®ex); - return -1; - } - } else if (code == REG_NOMATCH) { - // Not match - tsdbInfo("vgId:%d, invalid file %s exists, remove it", REPO_ID(pRepo), pf->aname); - (void)tfsRemoveFile(pf); - continue; - } else { - // Has other error - tsdbError("vgId:%d, failed to restore DFileSet Array while run regexec since %s", REPO_ID(pRepo), strerror(code)); - terrno = TAOS_SYSTEM_ERROR(code); - tfsClosedir(tdir); - taosArrayDestroy(fArray); - regfree(®ex); - return -1; - } + // scan and fix FS + code = tsdbScanAndTryFixFS(*ppFS, 0); + if (code) { + tsdbFSDestroy(*ppFS); + goto _err; } - tfsClosedir(tdir); - regfree(®ex); - - // Sort the array according to file name - taosArraySort(fArray, tsdbComparTFILE); - - size_t index = 0; - // Loop to recover each file set - for (;;) { - if (index >= taosArrayGetSize(fArray)) { - break; - } - - SDFileSet fset = {0}; + return code; - TSDB_FSET_SET_CLOSED(&fset); - - // Loop to recover ONE fset - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - SDFile *pDFile = TSDB_DFILE_IN_SET(&fset, ftype); - - if (index >= taosArrayGetSize(fArray)) { - tsdbError("vgId:%d, incomplete DFileSet, fid:%d", REPO_ID(pRepo), fset.fid); - taosArrayDestroy(fArray); - return -1; - } +_err: + *ppFS = NULL; + tsdbError("vgId:%d tsdb fs open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} - pf = taosArrayGet(fArray, index); +int32_t tsdbFSClose(STsdbFS *pFS) { + int32_t code = 0; + tsdbFSDestroy(pFS); + return code; +} - int tvid, tfid; - TSDB_FILE_T ttype; - uint32_t tversion; - char _bname[TSDB_FILENAME_LEN]; +int32_t tsdbFSBegin(STsdbFS *pFS) { + int32_t code = 0; - tfsBasename(pf, _bname); - tsdbParseDFilename(_bname, &tvid, &tfid, &ttype, &tversion); + ASSERT(!pFS->inTxn); - ASSERT(tvid == REPO_ID(pRepo)); + // SDelFile + pFS->nState->pDelFile = NULL; + if (pFS->cState->pDelFile) { + pFS->nState->delFile = pFS->cState->delFile; + pFS->nState->pDelFile = &pFS->nState->delFile; + } - if (tfid < pRepo->rtn.minFid) { // skip file expired - ++index; - continue; - } + // SArray + taosArrayClear(pFS->nState->aDFileSet); + for (int32_t iSet = 0; iSet < taosArrayGetSize(pFS->cState->aDFileSet); iSet++) { + SDFileSet *pDFileSet = (SDFileSet *)taosArrayGet(pFS->cState->aDFileSet, iSet); - if (ftype == 0) { - fset.fid = tfid; - } else { - if (tfid != fset.fid) { - tsdbError("vgId:%d, incomplete dFileSet, fid:%d", REPO_ID(pRepo), fset.fid); - taosArrayDestroy(fArray); - return -1; - } - } + if (taosArrayPush(pFS->nState->aDFileSet, pDFileSet) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } - if (ttype != ftype) { - tsdbError("vgId:%d, incomplete dFileSet, fid:%d", REPO_ID(pRepo), fset.fid); - taosArrayDestroy(fArray); - return -1; - } + pFS->inTxn = 1; + return code; - pDFile->f = *pf; +_err: + tsdbError("vgId:%d tsdb fs begin failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); + return code; +} - // if (tsdbOpenDFile(pDFile, O_RDONLY) < 0) { - if (tsdbOpenDFile(pDFile, TD_FILE_READ) < 0) { - tsdbError("vgId:%d, failed to open DFile %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), - tstrerror(terrno)); - taosArrayDestroy(fArray); - return -1; - } +int32_t tsdbFSCommit(STsdbFS *pFS) { + int32_t code = 0; + STsdbFSState *pState = pFS->nState; + char tfname[TSDB_FILENAME_LEN]; + char fname[TSDB_FILENAME_LEN]; - if (tsdbLoadDFileHeader(pDFile, &(pDFile->info)) < 0) { - tsdbError("vgId:%d, failed to load DFile %s header since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), - tstrerror(terrno)); - taosArrayDestroy(fArray); - return -1; - } + // need lock (todo) + pFS->nState = pFS->cState; + pFS->cState = pState; - if (tsdbForceKeepFile) { - int64_t file_size; - // Get real file size - if (taosFStatFile(pDFile->pFile, &file_size, NULL) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - taosArrayDestroy(fArray); - return -1; - } - - if (pDFile->info.size != file_size) { - int64_t tfsize = pDFile->info.size; - pDFile->info.size = file_size; - tsdbInfo("vgId:%d, file %s header size is changed from %" PRId64 " to %" PRId64, REPO_ID(pRepo), - TSDB_FILE_FULL_NAME(pDFile), tfsize, pDFile->info.size); - } - } + snprintf(tfname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT.t", tfsGetPrimaryPath(pFS->pTsdb->pVnode->pTfs), TD_DIRSEP, + pFS->pTsdb->path, TD_DIRSEP); + snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pFS->pTsdb->pVnode->pTfs), TD_DIRSEP, + pFS->pTsdb->path, TD_DIRSEP); - tsdbCloseDFile(pDFile); - index++; - } + // gnrt CURRENT.t + code = tsdbGnrtCurrent(tfname, pFS->cState); + if (code) goto _err; - tsdbInfo("vgId:%d, FSET %d is restored", REPO_ID(pRepo), fset.fid); - taosArrayPush(pfs->cstatus->df, &fset); + // rename + code = taosRenameFile(tfname, fname); + if (code) { + code = TAOS_SYSTEM_ERROR(code); + goto _err; } - // Resource release - taosArrayDestroy(fArray); - - return 0; -} + // apply commit on disk + code = tsdbFSApplyDiskChange(pFS, pFS->nState, pFS->cState); + if (code) goto _err; -static int tsdbRestoreCurrent(STsdb *pRepo) { - if (tsdbRestoreDFileSet(pRepo) < 0) { - tsdbError("vgId:%d, failed to restore DFileSet since %s", REPO_ID(pRepo), tstrerror(terrno)); - return -1; - } + pFS->inTxn = 0; - if (tsdbSaveFSStatus(pRepo, pRepo->fs->cstatus) < 0) { - tsdbError("vgId:%d, failed to restore current since %s", REPO_ID(pRepo), tstrerror(terrno)); - return -1; - } + return code; - return 0; +_err: + tsdbError("vgId:%d tsdb fs commit failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); + return code; } -static int tsdbComparTFILE(const void *arg1, const void *arg2) { - STfsFile *pf1 = (STfsFile *)arg1; - STfsFile *pf2 = (STfsFile *)arg2; +int32_t tsdbFSRollback(STsdbFS *pFS) { + int32_t code = 0; - int vid1, fid1, vid2, fid2; - TSDB_FILE_T ftype1, ftype2; - uint32_t version1, version2; - char bname1[TSDB_FILENAME_LEN]; - char bname2[TSDB_FILENAME_LEN]; + code = tsdbFSApplyDiskChange(pFS, pFS->nState, pFS->cState); + if (code) goto _err; - tfsBasename(pf1, bname1); - tfsBasename(pf2, bname2); - tsdbParseDFilename(bname1, &vid1, &fid1, &ftype1, &version1); - tsdbParseDFilename(bname2, &vid2, &fid2, &ftype2, &version2); + pFS->inTxn = 0; - if (fid1 < fid2) { - return -1; - } else if (fid1 > fid2) { - return 1; - } else { - if (ftype1 < ftype2) { - return -1; - } else if (ftype1 > ftype2) { - return 1; - } else { - return 0; - } - } + return code; + +_err: + tsdbError("vgId:%d tsdb fs rollback failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); + return code; } -static void tsdbScanAndTryFixDFilesHeader(STsdb *pRepo, int32_t *nExpired) { - STsdbFS *pfs = REPO_FS(pRepo); - SFSStatus *pStatus = pfs->cstatus; - SDFInfo info; +int32_t tsdbFSStateUpsertDelFile(STsdbFSState *pState, SDelFile *pDelFile) { + int32_t code = 0; + pState->delFile = *pDelFile; + pState->pDelFile = &pState->delFile; + return code; +} - for (size_t i = 0; i < taosArrayGetSize(pStatus->df); i++) { - SDFileSet fset; - tsdbInitDFileSetEx(&fset, (SDFileSet *)taosArrayGet(pStatus->df, i)); - if (fset.fid < pRepo->rtn.minFid) { - ++*nExpired; - } - tsdbDebug("vgId:%d, scan DFileSet %d header", REPO_ID(pRepo), fset.fid); +int32_t tsdbFSStateUpsertDFileSet(STsdbFSState *pState, SDFileSet *pSet) { + int32_t code = 0; + int32_t idx = taosArraySearchIdx(pState->aDFileSet, pSet, tDFileSetCmprFn, TD_GE); - // if (tsdbOpenDFileSet(&fset, O_RDWR) < 0) { - if (tsdbOpenDFileSet(&fset, TD_FILE_WRITE | TD_FILE_READ) < 0) { - tsdbError("vgId:%d, failed to open DFileSet %d since %s, continue", REPO_ID(pRepo), fset.fid, tstrerror(terrno)); - continue; + if (idx < 0) { + if (taosArrayPush(pState->aDFileSet, pSet) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; } - - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - SDFile *pDFile = TSDB_DFILE_IN_SET(&fset, ftype); - - if ((tsdbLoadDFileHeader(pDFile, &info) < 0) || pDFile->info.size != info.size || - pDFile->info.magic != info.magic) { - if (tsdbUpdateDFileHeader(pDFile) < 0) { - tsdbError("vgId:%d, failed to update DFile header of %s since %s, continue", REPO_ID(pRepo), - TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno)); - } else { - tsdbInfo("vgId:%d, DFile header of %s is updated", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile)); - TSDB_FILE_FSYNC(pDFile); - } - } else { - tsdbDebug("vgId:%d, DFile header of %s is correct", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile)); + } else { + SDFileSet *tDFileSet = (SDFileSet *)taosArrayGet(pState->aDFileSet, idx); + int32_t c = tDFileSetCmprFn(pSet, tDFileSet); + if (c == 0) { + taosArraySet(pState->aDFileSet, idx, pSet); + } else { + if (taosArrayInsert(pState->aDFileSet, idx, pSet) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; } } - - tsdbCloseDFileSet(&fset); } -} -int tsdbRLockFS(STsdbFS *pFs) { - int code = taosThreadRwlockRdlock(&(pFs->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; +_exit: + return code; } -int tsdbWLockFS(STsdbFS *pFs) { - int code = taosThreadRwlockWrlock(&(pFs->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} +SDelFile *tsdbFSStateGetDelFile(STsdbFSState *pState) { return pState->pDelFile; } -int tsdbUnLockFS(STsdbFS *pFs) { - int code = taosThreadRwlockUnlock(&(pFs->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} \ No newline at end of file +SDFileSet *tsdbFSStateGetDFileSet(STsdbFSState *pState, int32_t fid) { + return (SDFileSet *)taosArraySearch(pState->aDFileSet, &(SDFileSet){.fid = fid}, tDFileSetCmprFn, TD_EQ); +} diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 11d206dc35c7ea337d1f550124374e4cb5132572..e7f8cb4789042f32c55a126f19a7925bbe31ba53 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -15,568 +15,287 @@ #include "tsdb.h" -static const char *TSDB_FNAME_SUFFIX[] = { - "head", // TSDB_FILE_HEAD - "data", // TSDB_FILE_DATA - "last", // TSDB_FILE_LAST - "smad", // TSDB_FILE_SMAD - "smal", // TSDB_FILE_SMAL - "", // TSDB_FILE_MAX - "meta", // TSDB_FILE_META -}; - -static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char *dname, char *fname); -static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo); -static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo); -static int tsdbRollBackDFile(SDFile *pDFile); - -// ============== Operations on SDFile -void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype) { - char fname[TSDB_FILENAME_LEN]; - - TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_OK); - - TSDB_FILE_SET_CLOSED(pDFile); - - memset(&(pDFile->info), 0, sizeof(pDFile->info)); - pDFile->info.magic = TSDB_FILE_INIT_MAGIC; - pDFile->info.fver = tsdbGetDFSVersion(ftype); - - tsdbGetFilename(REPO_ID(pRepo), fid, ver, ftype, pRepo->dir, fname); - tfsInitFile(REPO_TFS(pRepo), &(pDFile->f), did, fname); -} - -void tsdbInitDFileEx(SDFile *pDFile, SDFile *pODFile) { - *pDFile = *pODFile; - TSDB_FILE_SET_CLOSED(pDFile); -} - -int tsdbEncodeSDFile(void **buf, SDFile *pDFile) { - int tlen = 0; - - tlen += tsdbEncodeDFInfo(buf, &(pDFile->info)); - tlen += tfsEncodeFile(buf, &(pDFile->f)); - - return tlen; -} +static int32_t tPutHeadFile(uint8_t *p, SHeadFile *pHeadFile) { + int32_t n = 0; -void *tsdbDecodeSDFile(STsdb *pRepo, void *buf, SDFile *pDFile) { - buf = tsdbDecodeDFInfo(buf, &(pDFile->info)); - buf = tfsDecodeFile(REPO_TFS(pRepo), buf, &(pDFile->f)); - TSDB_FILE_SET_CLOSED(pDFile); + n += tPutI64v(p ? p + n : p, pHeadFile->commitID); + n += tPutI64v(p ? p + n : p, pHeadFile->size); + n += tPutI64v(p ? p + n : p, pHeadFile->offset); - return buf; + return n; } -static int tsdbEncodeSDFileEx(void **buf, SDFile *pDFile) { - int tlen = 0; +static int32_t tGetHeadFile(uint8_t *p, SHeadFile *pHeadFile) { + int32_t n = 0; - tlen += tsdbEncodeDFInfo(buf, &(pDFile->info)); - tlen += taosEncodeString(buf, TSDB_FILE_FULL_NAME(pDFile)); + n += tGetI64v(p + n, &pHeadFile->commitID); + n += tGetI64v(p + n, &pHeadFile->size); + n += tGetI64v(p + n, &pHeadFile->offset); - return tlen; + return n; } -static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) { - char *aname = NULL; +static int32_t tPutDataFile(uint8_t *p, SDataFile *pDataFile) { + int32_t n = 0; - buf = tsdbDecodeDFInfo(buf, &(pDFile->info)); - buf = taosDecodeString(buf, &aname); - strncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN); - TSDB_FILE_SET_CLOSED(pDFile); - taosMemoryFreeClear(aname); + n += tPutI64v(p ? p + n : p, pDataFile->commitID); + n += tPutI64v(p ? p + n : p, pDataFile->size); - return buf; + return n; } -int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType) { - ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC); - - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); - if (pDFile->pFile == NULL) { - if (errno == ENOENT) { - // Try to create directory recursively - char *s = strdup(TSDB_FILE_REL_NAME(pDFile)); - if (tfsMkdirRecurAt(REPO_TFS(pRepo), taosDirName(s), TSDB_FILE_DID(pDFile)) < 0) { - taosMemoryFreeClear(s); - return -1; - } - taosMemoryFreeClear(s); - - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); - if (pDFile->pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - } else { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - } - - if (!updateHeader) { - return 0; - } +static int32_t tGetDataFile(uint8_t *p, SDataFile *pDataFile) { + int32_t n = 0; - pDFile->info.size += TSDB_FILE_HEAD_SIZE; - pDFile->info.fver = tsdbGetDFSVersion(fType); + n += tGetI64v(p + n, &pDataFile->commitID); + n += tGetI64v(p + n, &pDataFile->size); - if (tsdbUpdateDFileHeader(pDFile) < 0) { - tsdbCloseDFile(pDFile); - tsdbRemoveDFile(pDFile); - return -1; - } - - return 0; + return n; } -int tsdbUpdateDFileHeader(SDFile *pDFile) { - char buf[TSDB_FILE_HEAD_SIZE] = "\0"; - - if (tsdbSeekDFile(pDFile, 0, SEEK_SET) < 0) { - return -1; - } - - void *ptr = buf; - // taosEncodeFixedU32(&ptr, 0); // fver moved to SDFInfo and saved to current - tsdbEncodeDFInfo(&ptr, &(pDFile->info)); +static int32_t tPutLastFile(uint8_t *p, SLastFile *pLastFile) { + int32_t n = 0; - taosCalcChecksumAppend(0, (uint8_t *)buf, TSDB_FILE_HEAD_SIZE); - if (tsdbWriteDFile(pDFile, buf, TSDB_FILE_HEAD_SIZE) < 0) { - return -1; - } + n += tPutI64v(p ? p + n : p, pLastFile->commitID); + n += tPutI64v(p ? p + n : p, pLastFile->size); - return 0; + return n; } -int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) { - char buf[TSDB_FILE_HEAD_SIZE] = "\0"; - uint32_t _version; - - ASSERT(TSDB_FILE_OPENED(pDFile)); +static int32_t tGetLastFile(uint8_t *p, SLastFile *pLastFile) { + int32_t n = 0; - if (tsdbSeekDFile(pDFile, 0, SEEK_SET) < 0) { - return -1; - } - - if (tsdbReadDFile(pDFile, buf, TSDB_FILE_HEAD_SIZE) < 0) { - return -1; - } + n += tGetI64v(p + n, &pLastFile->commitID); + n += tGetI64v(p + n, &pLastFile->size); - if (!taosCheckChecksumWhole((uint8_t *)buf, TSDB_FILE_HEAD_SIZE)) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - return -1; - } - - void *pBuf = buf; - // pBuf = taosDecodeFixedU32(pBuf, &_version); - pBuf = tsdbDecodeDFInfo(pBuf, pInfo); - return 0; + return n; } -static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) { - SDFile df; - - tsdbInitDFileEx(&df, pDFile); - - if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pDFile))) { - tsdbError("vgId:%d, data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo), - TSDB_FILE_FULL_NAME(pDFile)); - // pRepo->state |= TSDB_STATE_BAD_DATA; - TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD); - return 0; - } - int64_t file_size = 0; - if (taosStatFile(TSDB_FILE_FULL_NAME(&df), &file_size, NULL) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } +static int32_t tPutSmaFile(uint8_t *p, SSmaFile *pSmaFile) { + int32_t n = 0; - if (pDFile->info.size < file_size) { - // if (tsdbOpenDFile(&df, O_WRONLY) < 0) { - if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) { - return -1; - } - - if (taosFtruncateFile(df.pFile, df.info.size) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - tsdbCloseDFile(&df); - return -1; - } - - if (tsdbUpdateDFileHeader(&df) < 0) { - tsdbCloseDFile(&df); - return -1; - } - - tsdbCloseDFile(&df); - tsdbInfo("vgId:%d, file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), - file_size, pDFile->info.size); - } else if (pDFile->info.size > file_size) { - tsdbError("vgId:%d, data file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it", - REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), file_size, pDFile->info.size); - // pRepo->state |= TSDB_STATE_BAD_DATA; - TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD); - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - return 0; - } else { - tsdbDebug("vgId:%d, file %s passes the scan", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile)); - } + n += tPutI64v(p ? p + n : p, pSmaFile->commitID); + n += tPutI64v(p ? p + n : p, pSmaFile->size); - return 0; + return n; } -static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo) { - int tlen = 0; +static int32_t tGetSmaFile(uint8_t *p, SSmaFile *pSmaFile) { + int32_t n = 0; - tlen += taosEncodeFixedU32(buf, pInfo->magic); - tlen += taosEncodeFixedU32(buf, pInfo->fver); - tlen += taosEncodeFixedU32(buf, pInfo->len); - tlen += taosEncodeFixedU32(buf, pInfo->totalBlocks); - tlen += taosEncodeFixedU32(buf, pInfo->totalSubBlocks); - tlen += taosEncodeFixedU32(buf, pInfo->offset); - tlen += taosEncodeFixedU64(buf, pInfo->size); - tlen += taosEncodeFixedU64(buf, pInfo->tombSize); + n += tGetI64v(p + n, &pSmaFile->commitID); + n += tGetI64v(p + n, &pSmaFile->size); - return tlen; + return n; } -static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo) { - buf = taosDecodeFixedU32(buf, &(pInfo->magic)); - buf = taosDecodeFixedU32(buf, &(pInfo->fver)); - buf = taosDecodeFixedU32(buf, &(pInfo->len)); - buf = taosDecodeFixedU32(buf, &(pInfo->totalBlocks)); - buf = taosDecodeFixedU32(buf, &(pInfo->totalSubBlocks)); - buf = taosDecodeFixedU32(buf, &(pInfo->offset)); - buf = taosDecodeFixedU64(buf, &(pInfo->size)); - buf = taosDecodeFixedU64(buf, &(pInfo->tombSize)); - - return buf; -} +// EXPOSED APIS ================================================== +void tsdbDataFileName(STsdb *pTsdb, SDFileSet *pDFileSet, EDataFileT ftype, char fname[]) { + STfs *pTfs = pTsdb->pVnode->pTfs; -static int tsdbApplyDFileChange(SDFile *from, SDFile *to) { - ASSERT(from != NULL || to != NULL); - - if (from != NULL) { - if (to == NULL) { - tsdbRemoveDFile(from); - } else { - if (tfsIsSameFile(TSDB_FILE_F(from), TSDB_FILE_F(to))) { - if (from->info.size > to->info.size) { - tsdbRollBackDFile(to); - } - } else { - (void)tsdbRemoveDFile(from); - } - } + switch (ftype) { + case TSDB_HEAD_FILE: + snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%df%dver%" PRId64 "%s", tfsGetDiskPath(pTfs, pDFileSet->diskId), + TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), pDFileSet->fid, pDFileSet->fHead.commitID, + ".head"); + break; + case TSDB_DATA_FILE: + snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%df%dver%" PRId64 "%s", tfsGetDiskPath(pTfs, pDFileSet->diskId), + TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), pDFileSet->fid, pDFileSet->fData.commitID, + ".data"); + break; + case TSDB_LAST_FILE: + snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%df%dver%" PRId64 "%s", tfsGetDiskPath(pTfs, pDFileSet->diskId), + TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), pDFileSet->fid, pDFileSet->fLast.commitID, + ".last"); + break; + case TSDB_SMA_FILE: + snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%df%dver%" PRId64 "%s", tfsGetDiskPath(pTfs, pDFileSet->diskId), + TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), pDFileSet->fid, pDFileSet->fSma.commitID, + ".sma"); + break; + default: + ASSERT(0); + break; } - - return 0; } -static int tsdbRollBackDFile(SDFile *pDFile) { - SDFile df = *pDFile; - - // if (tsdbOpenDFile(&df, O_WRONLY) < 0) { - if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) { - return -1; - } - - if (taosFtruncateFile(TSDB_FILE_PFILE(&df), pDFile->info.size) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - tsdbCloseDFile(&df); - return -1; +bool tsdbFileIsSame(SDFileSet *pDFileSet1, SDFileSet *pDFileSet2, EDataFileT ftype) { + if (pDFileSet1->diskId.level != pDFileSet2->diskId.level || pDFileSet1->diskId.id != pDFileSet2->diskId.id) { + return false; } - if (tsdbUpdateDFileHeader(&df) < 0) { - tsdbCloseDFile(&df); - return -1; + switch (ftype) { + case TSDB_HEAD_FILE: + return pDFileSet1->fHead.commitID == pDFileSet2->fHead.commitID; + case TSDB_DATA_FILE: + return pDFileSet1->fData.commitID == pDFileSet2->fData.commitID; + case TSDB_LAST_FILE: + return pDFileSet1->fLast.commitID == pDFileSet2->fLast.commitID; + case TSDB_SMA_FILE: + return pDFileSet1->fSma.commitID == pDFileSet2->fSma.commitID; + default: + ASSERT(0); + break; } - - TSDB_FILE_FSYNC(&df); - - tsdbCloseDFile(&df); - return 0; } -// ============== Operations on SDFileSet -void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint32_t ver) { - TSDB_FSET_FID(pSet) = fid; - TSDB_FSET_VER(pSet) = TSDB_LATEST_FSET_VER; - TSDB_FSET_STATE(pSet) = 0; - pSet->reserve = 0; +int32_t tsdbUpdateDFileHdr(TdFilePtr pFD, SDFileSet *pSet, EDataFileT ftype) { + int32_t code = 0; + int64_t n; + char hdr[TSDB_FHDR_SIZE]; - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - SDFile *pDFile = TSDB_DFILE_IN_SET(pSet, ftype); - tsdbInitDFile(pRepo, pDFile, did, fid, ver, ftype); - } -} + memset(hdr, 0, TSDB_FHDR_SIZE); + tPutDataFileHdr(hdr, pSet, ftype); + taosCalcChecksumAppend(0, hdr, TSDB_FHDR_SIZE); -void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet) { - TSDB_FSET_FID(pSet) = TSDB_FSET_FID(pOSet); - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - tsdbInitDFileEx(TSDB_DFILE_IN_SET(pSet, ftype), TSDB_DFILE_IN_SET(pOSet, ftype)); + n = taosLSeekFile(pFD, 0, SEEK_SET); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _exit; } -} -int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet) { - int tlen = 0; - - tlen += taosEncodeFixedI32(buf, TSDB_FSET_FID(pSet)); - // state not included - tlen += taosEncodeFixedU8(buf, TSDB_FSET_VER(pSet)); - tlen += taosEncodeFixedU16(buf, pSet->reserve); - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - tlen += tsdbEncodeSDFile(buf, TSDB_DFILE_IN_SET(pSet, ftype)); + n = taosWriteFile(pFD, hdr, TSDB_FHDR_SIZE); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _exit; } - return tlen; +_exit: + return code; } -void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet) { - buf = taosDecodeFixedI32(buf, &(TSDB_FSET_FID(pSet))); - TSDB_FSET_STATE(pSet) = 0; - buf = taosDecodeFixedU8(buf, &(TSDB_FSET_VER(pSet))); - buf = taosDecodeFixedU16(buf, &(pSet->reserve)); +int32_t tsdbDFileRollback(STsdb *pTsdb, SDFileSet *pSet, EDataFileT ftype) { + int32_t code = 0; + int64_t size; + TdFilePtr pFD; + char fname[TSDB_FILENAME_LEN]; - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - buf = tsdbDecodeSDFile(pRepo, buf, TSDB_DFILE_IN_SET(pSet, ftype)); - } - return buf; -} + tsdbDataFileName(pTsdb, pSet, ftype, fname); -int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet) { - int tlen = 0; - - tlen += taosEncodeFixedI32(buf, TSDB_FSET_FID(pSet)); - tlen += taosEncodeFixedU8(buf, TSDB_FSET_VER(pSet)); - tlen += taosEncodeFixedU16(buf, pSet->reserve); - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - tlen += tsdbEncodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype)); + // open + pFD = taosOpenFile(fname, TD_FILE_WRITE); + if (pFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } - return tlen; -} - -void *tsdbDecodeDFileSetEx(void *buf, SDFileSet *pSet) { - buf = taosDecodeFixedI32(buf, &(TSDB_FSET_FID(pSet))); - buf = taosDecodeFixedU8(buf, &(TSDB_FSET_VER(pSet))); - buf = taosDecodeFixedU16(buf, &(pSet->reserve)); - - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - buf = tsdbDecodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype)); + // truncate + switch (ftype) { + case TSDB_HEAD_FILE: + size = pSet->fHead.size; + break; + case TSDB_DATA_FILE: + size = pSet->fData.size; + break; + case TSDB_LAST_FILE: + size = pSet->fLast.size; + break; + case TSDB_SMA_FILE: + size = pSet->fSma.size; + break; + default: + ASSERT(0); } - return buf; -} - -int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - SDFile *pDFileFrom = (from) ? TSDB_DFILE_IN_SET(from, ftype) : NULL; - SDFile *pDFileTo = (to) ? TSDB_DFILE_IN_SET(to, ftype) : NULL; - if (tsdbApplyDFileChange(pDFileFrom, pDFileTo) < 0) { - return -1; - } + if (taosFtruncateFile(pFD, size) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } - return 0; -} + // update header + code = tsdbUpdateDFileHdr(pFD, pSet, ftype); + if (code) goto _err; -int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet *pSet, bool updateHeader) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (tsdbCreateDFile(pRepo, TSDB_DFILE_IN_SET(pSet, ftype), updateHeader, ftype) < 0) { - tsdbCloseDFileSet(pSet); - tsdbRemoveDFileSet(pSet); - return -1; - } + // sync + if (taosFsyncFile(pFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; } - return 0; -} + // close + taosCloseFile(&pFD); -int tsdbUpdateDFileSetHeader(SDFileSet *pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (tsdbUpdateDFileHeader(TSDB_DFILE_IN_SET(pSet, ftype)) < 0) { - return -1; - } - } - return 0; -} + return code; -int tsdbScanAndTryFixDFileSet(STsdb *pRepo, SDFileSet *pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (tsdbScanAndTryFixDFile(pRepo, TSDB_DFILE_IN_SET(pSet, ftype)) < 0) { - return -1; - } - } - return 0; +_err: + return code; } -int tsdbParseDFilename(const char *fname, int *vid, int *fid, TSDB_FILE_T *ftype, uint32_t *_version) { - char *p = NULL; - *_version = 0; - *ftype = TSDB_FILE_MAX; +int32_t tPutDataFileHdr(uint8_t *p, SDFileSet *pSet, EDataFileT ftype) { + int32_t n = 0; - sscanf(fname, "v%df%d.%m[a-z]-ver%" PRIu32, vid, fid, &p, _version); - for (TSDB_FILE_T i = 0; i < TSDB_FILE_MAX; i++) { - if (strcmp(p, TSDB_FNAME_SUFFIX[i]) == 0) { - *ftype = i; + switch (ftype) { + case TSDB_HEAD_FILE: + n += tPutHeadFile(p ? p + n : p, &pSet->fHead); break; - } - } - - taosMemoryFreeClear(p); - return 0; -} - -static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char *dname, char *fname) { - ASSERT(ftype != TSDB_FILE_MAX); - - if (ftype < TSDB_FILE_MAX) { - if (ver == 0) { - snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/%s/data/v%df%d.%s", vid, dname, vid, fid, - TSDB_FNAME_SUFFIX[ftype]); - } else { - snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/%s/data/v%df%d.%s-ver%" PRIu32, vid, dname, vid, fid, - TSDB_FNAME_SUFFIX[ftype], ver); - } - } else { - if (ver == 0) { - snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s", vid, TSDB_FNAME_SUFFIX[ftype]); - } else { - snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s-ver%" PRIu32, vid, TSDB_FNAME_SUFFIX[ftype], ver); - } - } -} - -int tsdbOpenDFile(SDFile *pDFile, int flags) { - ASSERT(!TSDB_FILE_OPENED(pDFile)); - - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), flags); - if (pDFile->pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return 0; -} - -void tsdbCloseDFile(SDFile *pDFile) { - if (TSDB_FILE_OPENED(pDFile)) { - taosCloseFile(&pDFile->pFile); - TSDB_FILE_SET_CLOSED(pDFile); - } -} - -int64_t tsdbSeekDFile(SDFile *pDFile, int64_t offset, int whence) { - // ASSERT(TSDB_FILE_OPENED(pDFile)); - - int64_t loffset = taosLSeekFile(TSDB_FILE_PFILE(pDFile), offset, whence); - if (loffset < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + case TSDB_DATA_FILE: + n += tPutDataFile(p ? p + n : p, &pSet->fData); + break; + case TSDB_LAST_FILE: + n += tPutLastFile(p ? p + n : p, &pSet->fLast); + break; + case TSDB_SMA_FILE: + n += tPutSmaFile(p ? p + n : p, &pSet->fSma); + break; + default: + ASSERT(0); } - return loffset; + return n; } -int64_t tsdbWriteDFile(SDFile *pDFile, void *buf, int64_t nbyte) { - ASSERT(TSDB_FILE_OPENED(pDFile)); +int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet) { + int32_t n = 0; - int64_t nwrite = taosWriteFile(pDFile->pFile, buf, nbyte); - if (nwrite < nbyte) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } + n += tPutI32v(p ? p + n : p, pSet->diskId.level); + n += tPutI32v(p ? p + n : p, pSet->diskId.id); + n += tPutI32v(p ? p + n : p, pSet->fid); + n += tPutHeadFile(p ? p + n : p, &pSet->fHead); + n += tPutDataFile(p ? p + n : p, &pSet->fData); + n += tPutLastFile(p ? p + n : p, &pSet->fLast); + n += tPutSmaFile(p ? p + n : p, &pSet->fSma); - return nwrite; + return n; } -void tsdbUpdateDFileMagic(SDFile *pDFile, void *pCksm) { - pDFile->info.magic = taosCalcChecksum(pDFile->info.magic, (uint8_t *)(pCksm), sizeof(TSCKSUM)); -} - -int tsdbAppendDFile(SDFile *pDFile, void *buf, int64_t nbyte, int64_t *offset) { - ASSERT(TSDB_FILE_OPENED(pDFile)); - - int64_t toffset; - - if ((toffset = tsdbSeekDFile(pDFile, 0, SEEK_END)) < 0) { - return -1; - } - - ASSERT(pDFile->info.size == toffset); - - if (offset) { - *offset = toffset; - } - - if (tsdbWriteDFile(pDFile, buf, nbyte) < 0) { - return -1; - } +int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) { + int32_t n = 0; - pDFile->info.size += nbyte; + n += tGetI32v(p + n, &pSet->diskId.level); + n += tGetI32v(p + n, &pSet->diskId.id); + n += tGetI32v(p + n, &pSet->fid); + n += tGetHeadFile(p + n, &pSet->fHead); + n += tGetDataFile(p + n, &pSet->fData); + n += tGetLastFile(p + n, &pSet->fLast); + n += tGetSmaFile(p + n, &pSet->fSma); - return (int)nbyte; + return n; } -int tsdbRemoveDFile(SDFile *pDFile) { return tfsRemoveFile(TSDB_FILE_F(pDFile)); } +// SDelFile =============================================== +void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]) { + STfs *pTfs = pTsdb->pVnode->pTfs; -int64_t tsdbReadDFile(SDFile *pDFile, void *buf, int64_t nbyte) { - ASSERT(TSDB_FILE_OPENED(pDFile)); - - int64_t nread = taosReadFile(pDFile->pFile, buf, nbyte); - if (nread < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return nread; + snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%dver%" PRId64 "%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, pTsdb->path, + TD_DIRSEP, TD_VID(pTsdb->pVnode), pFile->commitID, ".del"); } -int tsdbCopyDFile(SDFile *pSrc, SDFile *pDest) { - if (tfsCopyFile(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } +int32_t tPutDelFile(uint8_t *p, SDelFile *pDelFile) { + int32_t n = 0; - pDest->info = pSrc->info; - return 0; -} + n += tPutI64v(p ? p + n : p, pDelFile->commitID); + n += tPutI64v(p ? p + n : p, pDelFile->size); + n += tPutI64v(p ? p + n : p, pDelFile->offset); -void tsdbCloseDFileSet(SDFileSet *pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - tsdbCloseDFile(TSDB_DFILE_IN_SET(pSet, ftype)); - } + return n; } -int tsdbOpenDFileSet(SDFileSet *pSet, int flags) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (tsdbOpenDFile(TSDB_DFILE_IN_SET(pSet, ftype), flags) < 0) { - tsdbCloseDFileSet(pSet); - return -1; - } - } - return 0; -} - -void tsdbRemoveDFileSet(SDFileSet *pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - (void)tsdbRemoveDFile(TSDB_DFILE_IN_SET(pSet, ftype)); - } -} +int32_t tGetDelFile(uint8_t *p, SDelFile *pDelFile) { + int32_t n = 0; -int tsdbCopyDFileSet(SDFileSet *pSrc, SDFileSet *pDest) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (tsdbCopyDFile(TSDB_DFILE_IN_SET(pSrc, ftype), TSDB_DFILE_IN_SET(pDest, ftype)) < 0) { - tsdbRemoveDFileSet(pDest); - return -1; - } - } + n += tGetI64v(p + n, &pDelFile->commitID); + n += tGetI64v(p + n, &pDelFile->size); + n += tGetI64v(p + n, &pDelFile->offset); - return 0; + return n; } - -void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY *minKey, TSKEY *maxKey) { - *minKey = fid * days * tsTickPerMin[precision]; - *maxKey = *minKey + days * tsTickPerMin[precision] - 1; -} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index d8bc87d47142d59d3564c3cbcf89bfe4d6a0e84e..a50125cc4ba6bb011c9bba8bfe0c6b35f009b868 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -25,8 +25,6 @@ #define SL_MOVE_BACKWARD 0x1 #define SL_MOVE_FROM_POS 0x2 -static int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow); -static int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow); static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags); static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData); static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, int64_t version, @@ -44,10 +42,12 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) { taosInitRWLatch(&pMemTable->latch); pMemTable->pTsdb = pTsdb; pMemTable->nRef = 1; - pMemTable->minKey = (TSDBKEY){.ts = TSKEY_MAX, .version = INT64_MAX}; - pMemTable->maxKey = (TSDBKEY){.ts = TSKEY_MIN, .version = -1}; + pMemTable->minKey = TSKEY_MAX; + pMemTable->maxKey = TSKEY_MIN; + pMemTable->minVersion = VERSION_MAX; + pMemTable->maxVersion = VERSION_MIN; pMemTable->nRow = 0; - pMemTable->nDelOp = 0; + pMemTable->nDel = 0; pMemTable->aTbData = taosArrayInit(128, sizeof(STbData *)); if (pMemTable->aTbData == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -146,6 +146,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid SMemTable *pMemTable = pTsdb->mem; STbData *pTbData = NULL; SVBufPool *pPool = pTsdb->pVnode->inUse; + TSDBKEY lastKey = {.version = version, .ts = eKey}; // check if table exists (todo) @@ -155,26 +156,32 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid } // do delete - SDelOp *pDelOp = (SDelOp *)vnodeBufPoolMalloc(pPool, sizeof(*pDelOp)); - if (pDelOp == NULL) { + SDelData *pDelData = (SDelData *)vnodeBufPoolMalloc(pPool, sizeof(*pDelData)); + if (pDelData == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } - pDelOp->version = version; - pDelOp->sKey = sKey; - pDelOp->eKey = eKey; - pDelOp->pNext = NULL; + pDelData->version = version; + pDelData->sKey = sKey; + pDelData->eKey = eKey; + pDelData->pNext = NULL; if (pTbData->pHead == NULL) { ASSERT(pTbData->pTail == NULL); - pTbData->pHead = pTbData->pTail = pDelOp; + pTbData->pHead = pTbData->pTail = pDelData; } else { - pTbData->pTail->pNext = pDelOp; - pTbData->pTail = pDelOp; + pTbData->pTail->pNext = pDelData; + pTbData->pTail = pDelData; } // update the state of pMemTable and other (todo) - pMemTable->nDelOp++; + pMemTable->minVersion = TMIN(pMemTable->minVersion, version); + pMemTable->maxVersion = TMAX(pMemTable->maxVersion, version); + pMemTable->nDel++; + + if (tsdbKeyCmprFn(&lastKey, &pTbData->maxKey) >= 0) { + tsdbCacheDelete(pTsdb->lruCache, pTbData->uid, eKey); + } tsdbError("vgId:%d, delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64 " since %s", @@ -213,9 +220,15 @@ void *tsdbTbDataIterDestroy(STbDataIter *pIter) { void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter) { SMemSkipListNode *pos[SL_MAX_LEVEL]; + SMemSkipListNode *pHead; + SMemSkipListNode *pTail; + pHead = pTbData->sl.pHead; + pTail = pTbData->sl.pTail; pIter->pTbData = pTbData; pIter->backward = backward; + pIter->pRow = NULL; + pIter->row.type = 0; if (pFrom == NULL) { // create from head or tail if (backward) { @@ -239,6 +252,7 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) { SMemSkipListNode *pHead = pIter->pTbData->sl.pHead; SMemSkipListNode *pTail = pIter->pTbData->sl.pTail; + pIter->pRow = NULL; if (pIter->backward) { ASSERT(pIter->pNode != pTail); @@ -266,31 +280,29 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) { return true; } -bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow) { - SMemSkipListNode *pHead = pIter->pTbData->sl.pHead; - SMemSkipListNode *pTail = pIter->pTbData->sl.pTail; - TSDBROW row = {0}; +TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) { + // we add here for commit usage + if (pIter == NULL) return NULL; - if (pRow == NULL) { - pRow = &row; + if (pIter->pRow) { + goto _exit; } if (pIter->backward) { - ASSERT(pIter->pNode != pTail); - - if (pIter->pNode == pHead) { - return false; + if (pIter->pNode == pIter->pTbData->sl.pHead) { + goto _exit; } } else { - ASSERT(pIter->pNode != pHead); - - if (pIter->pNode == pTail) { - return false; + if (pIter->pNode == pIter->pTbData->sl.pTail) { + goto _exit; } } - tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), pRow); - return true; + tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), &pIter->row); + pIter->pRow = &pIter->row; + +_exit: + return pIter->pRow; } static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData) { @@ -317,8 +329,11 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid } pTbData->suid = suid; pTbData->uid = uid; - pTbData->minKey = (TSDBKEY){.ts = TSKEY_MAX, .version = INT64_MAX}; - pTbData->maxKey = (TSDBKEY){.ts = TSKEY_MIN, .version = -1}; + pTbData->minKey = TSKEY_MAX; + pTbData->maxKey = TSKEY_MIN; + pTbData->minVersion = VERSION_MAX; + pTbData->maxVersion = VERSION_MIN; + pTbData->maxSkmVer = -1; pTbData->pHead = NULL; pTbData->pTail = NULL; pTbData->sl.seed = taosRand(); @@ -493,8 +508,9 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i SSubmitBlkIter blkIter = {0}; TSDBKEY key = {.version = version}; SMemSkipListNode *pos[SL_MAX_LEVEL]; - TSDBROW row = {.version = version, .pTSRow = NULL}; + TSDBROW row = tsdbRowFromTSRow(version, NULL); int32_t nRow = 0; + STSRow *pLastRow = NULL; tInitSubmitBlkIter(pMsgIter, pBlock, &blkIter); @@ -508,13 +524,9 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i goto _err; } - if (tsdbKeyCmprFn(&key, &pTbData->minKey) < 0) { - pTbData->minKey = key; - } + pTbData->minKey = TMIN(pTbData->minKey, key.ts); - if (tsdbKeyCmprFn(&key, &pMemTable->minKey) < 0) { - pMemTable->minKey = key; - } + pLastRow = row.pTSRow; // forward put rest data row.pTSRow = tGetSubmitBlkNext(&blkIter); @@ -531,18 +543,35 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i goto _err; } + pLastRow = row.pTSRow; + row.pTSRow = tGetSubmitBlkNext(&blkIter); } while (row.pTSRow); } - if (tsdbKeyCmprFn(&key, &pTbData->maxKey) > 0) { - pTbData->maxKey = key; - } + if (key.ts >= pTbData->maxKey) { + if (key.ts > pTbData->maxKey) { + pTbData->maxKey = key.ts; + } - if (tsdbKeyCmprFn(&key, &pMemTable->maxKey) > 0) { - pMemTable->maxKey = key; + if (pLastRow != NULL) { + tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, pLastRow, true); + } } - pMemTable->nRef++; + + tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, pLastRow); + + pTbData->minVersion = TMIN(pTbData->minVersion, version); + pTbData->maxVersion = TMAX(pTbData->maxVersion, version); + pTbData->maxSkmVer = TMAX(pTbData->maxSkmVer, pMsgIter->sversion); + + // SMemTable + pMemTable->minKey = TMIN(pMemTable->minKey, pTbData->minKey); + pMemTable->maxKey = TMAX(pMemTable->maxKey, pTbData->maxKey); + pMemTable->minVersion = TMIN(pMemTable->minVersion, pTbData->minVersion); + pMemTable->maxVersion = TMAX(pMemTable->maxVersion, pTbData->maxVersion); + pMemTable->nRow += nRow; + pRsp->numOfRows = nRow; pRsp->affectedRows = nRow; @@ -552,22 +581,4 @@ _err: return code; } -static int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) { - int32_t n = 0; - - n += tPutI64(p, pRow->version); - if (p) memcpy(p + n, pRow->pTSRow, pRow->pTSRow->len); - n += pRow->pTSRow->len; - - return n; -} - -static int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow) { - int32_t n = 0; - - n += tGetI64(p, &pRow->version); - pRow->pTSRow = (STSRow *)(p + n); - n += pRow->pTSRow->len; - - return n; -} \ No newline at end of file +int32_t tsdbGetNRowsInTbData(STbData *pTbData) { return pTbData->sl.size; } diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index 943263e1a3c65ebf980b353e6a1b69ba52868a22..1fa582fae552e6fef224f0fb30c50a4eab421cc8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -17,7 +17,6 @@ static int tsdbSetKeepCfg(STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg); - // implementation static int tsdbSetKeepCfg(STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg) { @@ -42,7 +41,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee int slen = 0; *ppTsdb = NULL; - slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(dir) + 3; + slen = strlen(pVnode->path) + strlen(dir) + 2; // create handle pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(*pTsdb) + slen); @@ -51,10 +50,8 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee return -1; } - ASSERT(strlen(dir) < TSDB_DATA_DIR_LEN); - memcpy(pTsdb->dir, dir, strlen(dir)); pTsdb->path = (char *)&pTsdb[1]; - sprintf(pTsdb->path, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, dir); + sprintf(pTsdb->path, "%s%s%s", pVnode->path, TD_DIRSEP, dir); taosRealPath(pTsdb->path, NULL, slen); pTsdb->pVnode = pVnode; pTsdb->repoLocked = false; @@ -64,13 +61,17 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee } else { memcpy(&pTsdb->keepCfg, pKeepCfg, sizeof(STsdbKeepCfg)); } - pTsdb->fs = tsdbNewFS(REPO_KEEP_CFG(pTsdb)); + // pTsdb->fs = tsdbNewFS(REPO_KEEP_CFG(pTsdb)); - // create dir (TODO: use tfsMkdir) - taosMkDir(pTsdb->path); + // create dir + tfsMkdir(pVnode->pTfs, pTsdb->path); // open tsdb - if (tsdbOpenFS(pTsdb) < 0) { + if (tsdbFSOpen(pTsdb, &pTsdb->fs) < 0) { + goto _err; + } + + if (tsdbOpenCache(pTsdb) < 0) { goto _err; } @@ -87,10 +88,9 @@ _err: int tsdbClose(STsdb **pTsdb) { if (*pTsdb) { - // TODO: destroy mem/imem taosThreadMutexDestroy(&(*pTsdb)->mutex); - tsdbCloseFS(*pTsdb); - tsdbFreeFS((*pTsdb)->fs); + tsdbFSClose((*pTsdb)->fs); + tsdbCloseCache((*pTsdb)->lruCache); taosMemoryFreeClear(*pTsdb); } return 0; @@ -99,7 +99,7 @@ int tsdbClose(STsdb **pTsdb) { int tsdbLockRepo(STsdb *pTsdb) { int code = taosThreadMutexLock(&pTsdb->mutex); if (code != 0) { - tsdbError("vgId:%d, failed to lock tsdb since %s", REPO_ID(pTsdb), strerror(errno)); + tsdbError("vgId:%d, failed to lock tsdb since %s", TD_VID(pTsdb->pVnode), strerror(errno)); terrno = TAOS_SYSTEM_ERROR(code); return -1; } @@ -108,13 +108,13 @@ int tsdbLockRepo(STsdb *pTsdb) { } int tsdbUnlockRepo(STsdb *pTsdb) { - ASSERT(IS_REPO_LOCKED(pTsdb)); + // ASSERT(IS_REPO_LOCKED(pTsdb)); pTsdb->repoLocked = false; int code = taosThreadMutexUnlock(&pTsdb->mutex); if (code != 0) { - tsdbError("vgId:%d, failed to unlock tsdb since %s", REPO_ID(pTsdb), strerror(errno)); + tsdbError("vgId:%d, failed to unlock tsdb since %s", TD_VID(pTsdb->pVnode), strerror(errno)); terrno = TAOS_SYSTEM_ERROR(code); return -1; } return 0; -} \ No newline at end of file +} diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 4604e3699ff05b4236c4640202724cbe4fd49cb8..e53a1b43afd9e50c7a3a225909cc137574f433d8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -14,79 +14,36 @@ */ #include "tsdb.h" -#include "vnode.h" - -#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) -#define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pResBlock->pDataBlock))) - -#define GET_FILE_DATA_BLOCK_INFO(_checkInfo, _block) \ - ((SDataBlockInfo){.window = {.skey = (_block)->minKey.ts, .ekey = (_block)->maxKey.ts}, \ - .rows = (_block)->numOfRows, \ - .uid = (_checkInfo)->tableId}) - -enum { - TSDB_QUERY_TYPE_ALL = 1, - TSDB_QUERY_TYPE_LAST = 2, -}; - -enum { - TSDB_CACHED_TYPE_NONE = 0, - TSDB_CACHED_TYPE_LASTROW = 1, - TSDB_CACHED_TYPE_LAST = 2, -}; - -typedef struct SQueryFilePos { - int32_t fid; - int32_t slot; - int32_t pos; - int64_t lastKey; - int32_t rows; - bool mixBlock; - bool blockCompleted; - STimeWindow win; -} SQueryFilePos; - -typedef struct SDataBlockLoadInfo { - SDFileSet* fileGroup; - int32_t slot; - uint64_t uid; - SArray* pLoadedCols; -} SDataBlockLoadInfo; - -typedef struct SLoadCompBlockInfo { - int32_t tid; /* table tid */ - int32_t fileId; -} SLoadCompBlockInfo; - -enum { - CHECKINFO_CHOSEN_MEM = 0, - CHECKINFO_CHOSEN_IMEM = 1, - CHECKINFO_CHOSEN_BOTH = 2 // for update=2(merge case) -}; - -typedef struct STableCheckInfo { - uint64_t suid; - uint64_t tableId; - TSKEY lastKey; - SBlockInfo* pCompInfo; - int32_t compSize; - int32_t numOfBlocks : 29; // number of qualified data blocks not the original blocks - uint8_t chosen : 2; // indicate which iterator should move forward - bool initBuf : 1; // whether to initialize the in-memory skip list iterator or not - STbDataIter* iter; // mem buffer skip list iterator - STbDataIter* iiter; // imem buffer skip list iterator -} STableCheckInfo; - -typedef struct STableBlockInfo { - SBlock* compBlock; - STableCheckInfo* pTableCheckInfo; -} STableBlockInfo; +#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) + +typedef struct { + STbDataIter* iter; + int32_t index; + bool hasVal; +} SIterInfo; + +typedef struct STableBlockScanInfo { + uint64_t uid; + TSKEY lastKey; + SBlockIdx blockIdx; + SArray* pBlockList; // block data index list + SIterInfo iter; // mem buffer skip list iterator + SIterInfo iiter; // imem buffer skip list iterator + SArray* delSkyline; // delete info for this table + int32_t fileDelIndex; + bool iterInit; // whether to initialize the in-memory skip list iterator or not +} STableBlockScanInfo; + +typedef struct SBlockOrderWrapper { + int64_t uid; + SBlock* pBlock; +} SBlockOrderWrapper; typedef struct SBlockOrderSupporter { - int32_t numOfTables; - STableBlockInfo** pDataBlockInfo; - int32_t* blockIndexArray; - int32_t* numOfBlocksPerTable; + SBlockOrderWrapper** pDataBlockInfo; + int32_t* indexPerTable; + int32_t* numOfBlocksPerTable; + int32_t numOfTables; } SBlockOrderSupporter; typedef struct SIOCostSummary { @@ -100,2760 +57,2813 @@ typedef struct SIOCostSummary { typedef struct SBlockLoadSuppInfo { SColumnDataAgg* pstatis; SColumnDataAgg** plist; - SArray* defaultLoadColumn; // default load column - int32_t* slotIds; // colId to slotId + int16_t* colIds; // column ids for loading file block data + int32_t* slotIds; // colId to slotId + char** buildBuf; // build string tmp buffer, todo remove it later after all string format being updated. } SBlockLoadSuppInfo; -typedef struct STsdbReadHandle { - STsdb* pTsdb; - uint64_t suid; - SQueryFilePos cur; // current position - int16_t order; - STimeWindow window; // the primary query time window that applies to all queries - // SColumnDataAgg* statis; // query level statistics, only one table block statistics info exists at any time - // SColumnDataAgg** pstatis;// the ptr array list to return to caller - int32_t numOfBlocks; - SSDataBlock* pResBlock; - // SArray* pColumns; // column list, SColumnInfoData array list - bool locateStart; - int32_t outputCapacity; - int32_t realNumOfRows; - SArray* pTableCheckInfo; // SArray - int32_t activeIndex; - bool checkFiles; // check file stage - int8_t cachelastrow; // check if last row cached - bool loadExternalRow; // load time window external data rows - bool currentLoadExternalRows; // current load external rows - int32_t loadType; // block load type - char* idStr; // query info handle, for debug purpose - int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows - SDFileSet* pFileGroup; - SFSIter fileIter; - SReadH rhelper; - STableBlockInfo* pDataBlockInfo; +typedef struct SFilesetIter { + int32_t numOfFiles; // number of total files + int32_t index; // current accessed index in the list + SArray* pFileList; // data file list + int32_t order; +} SFilesetIter; + +typedef struct SFileDataBlockInfo { + int32_t + tbBlockIdx; // index position in STableBlockScanInfo in order to check whether neighbor block overlaps with it + uint64_t uid; +} SFileDataBlockInfo; + +typedef struct SDataBlockIter { + int32_t numOfBlocks; + int32_t index; + SArray* blockList; // SArray + int32_t order; +} SDataBlockIter; + +typedef struct SFileBlockDumpInfo { + int32_t totalRows; + int32_t rowIndex; + int64_t lastKey; + bool allDumped; +} SFileBlockDumpInfo; + +typedef struct SVersionRange { + uint64_t minVer; + uint64_t maxVer; +} SVersionRange; + +typedef struct SReaderStatus { + bool loadFromFile; // check file stage + SHashObj* pTableMap; // SHash + STableBlockScanInfo* pTableIter; // table iterator used in building in-memory buffer data blocks. + SFileBlockDumpInfo fBlockDumpInfo; + + SDFileSet* pCurrentFileset; // current opened file set + SBlockData fileBlockData; + SFilesetIter fileIter; + SDataBlockIter blockIter; + bool composedDataBlock; // the returned data block is a composed block or not +} SReaderStatus; + +struct STsdbReader { + STsdb* pTsdb; + uint64_t suid; + int16_t order; + STimeWindow window; // the primary query time window that applies to all queries + SSDataBlock* pResBlock; + int32_t capacity; + SReaderStatus status; + char* idStr; // query info handle, for debug purpose + int32_t type; // query type: 1. retrieve all data blocks, 2. retrieve direct prev|next rows + SBlockLoadSuppInfo suppInfo; + + SIOCostSummary cost; + STSchema* pSchema; + SDataFReader* pFileReader; + SVersionRange verRange; +#if 0 + SArray* prev; // previous row which is before than time window + SArray* next; // next row which is after the query time window + SFileBlockInfo* pDataBlockInfo; SDataCols* pDataCols; // in order to hold current file data block int32_t allocSize; // allocated data block size SDataBlockLoadInfo dataBlockLoadInfo; /* record current block load information */ SLoadCompBlockInfo compBlockLoadInfo; /* record current compblock information in SQueryAttr */ - SBlockLoadSuppInfo suppInfo; - SArray* prev; // previous row which is before than time window - SArray* next; // next row which is after the query time window - SIOCostSummary cost; - STSchema* pSchema; -} STsdbReadHandle; - -static STimeWindow updateLastrowForEachGroup(STableListInfo* pList); -static int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableListInfo* pList); -static int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle); -// static int32_t tsdbGetCachedLastRow(STable* pTable, STSRow** pRes, TSKEY* lastKey); - -static void changeQueryHandleForInterpQuery(tsdbReaderT pHandle); -static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock); -static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, - STsdbReadHandle* pTsdbReadHandle); -static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2); -// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, void* pMemRef); -// static void* doFreeColumnInfoData(SArray* pColumnInfoData); -// static void* destroyTableCheckInfo(SArray* pTableCheckInfo); -static bool tsdbGetExternalRow(tsdbReaderT pHandle); - -static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle, TSKEY winSKey, SRetention* retentions); - -static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) { - pBlockLoadInfo->slot = -1; - pBlockLoadInfo->uid = 0; - pBlockLoadInfo->fileGroup = NULL; -} - -static void tsdbInitCompBlockLoadInfo(SLoadCompBlockInfo* pCompBlockLoadInfo) { - pCompBlockLoadInfo->tid = -1; - pCompBlockLoadInfo->fileId = -1; -} - -static SArray* getColumnIdList(STsdbReadHandle* pTsdbReadHandle) { - size_t numOfCols = QH_GET_NUM_OF_COLS(pTsdbReadHandle); - assert(numOfCols <= TSDB_MAX_COLUMNS); - - SArray* pIdList = taosArrayInit(numOfCols, sizeof(int16_t)); - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pCol = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); - taosArrayPush(pIdList, &pCol->info.colId); - } - - return pIdList; -} - -static SArray* getDefaultLoadColumns(STsdbReadHandle* pTsdbReadHandle, bool loadTS) { - SArray* pLocalIdList = getColumnIdList(pTsdbReadHandle); - - // check if the primary time stamp column needs to load - int16_t colId = *(int16_t*)taosArrayGet(pLocalIdList, 0); - - // the primary timestamp column does not be included in the the specified load column list, add it - if (loadTS && colId != PRIMARYKEY_TIMESTAMP_COL_ID) { - int16_t columnId = PRIMARYKEY_TIMESTAMP_COL_ID; - taosArrayInsert(pLocalIdList, 0, &columnId); - } - - return pLocalIdList; -} - -int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; + // SDFileSet* pFileGroup; + // SFSIter fileIter; + // SReadH rhelper; + // SColumnDataAgg* statis; // query level statistics, only one table block statistics info exists at any time + // SColumnDataAgg** pstatis;// the ptr array list to return to caller +#endif +}; - int64_t rows = 0; - SMemTable* pMemTable = NULL; // pTsdbReadHandle->pMemTable; - if (pMemTable == NULL) { - return rows; +static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter); +static int buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity, + STsdbReader* pReader); +static TSDBROW* getValidRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader); +static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader, + SRowMerger* pMerger); +static int32_t doMergeRowsInBuf(SIterInfo* pIter, int64_t ts, SArray* pDelList, SRowMerger* pMerger, + STsdbReader* pReader); +static int32_t doAppendOneRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow); +static void setComposedBlockFlag(STsdbReader* pReader, bool composed); +static void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader); +static bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey); + +static void doMergeMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList, STSRow** pTSRow, + STsdbReader* pReader); +static void doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, + STSRow** pTSRow); +static int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, STbData* pMemTbData, + STbData* piMemTbData); +static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* retentions, const char* idstr, + int8_t* pLevel); +static SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level); + +static int32_t setColumnIdSlotList(STsdbReader* pReader, SSDataBlock* pBlock) { + SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + + size_t numOfCols = blockDataGetNumOfCols(pBlock); + + pSupInfo->colIds = taosMemoryMalloc(numOfCols * sizeof(int16_t)); + pSupInfo->buildBuf = taosMemoryCalloc(numOfCols, POINTER_BYTES); + if (pSupInfo->buildBuf == NULL || pSupInfo->colIds == NULL) { + taosMemoryFree(pSupInfo->colIds); + taosMemoryFree(pSupInfo->buildBuf); + return TSDB_CODE_OUT_OF_MEMORY; } - size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - for (int32_t i = 0; i < size; ++i) { - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); - - // if (pMemT && pCheckInfo->tableId < pMemT->maxTables) { - // pMem = pMemT->tData[pCheckInfo->tableId]; - // rows += (pMem && pMem->uid == pCheckInfo->tableId) ? pMem->numOfRows : 0; - // } - // if (pIMemT && pCheckInfo->tableId < pIMemT->maxTables) { - // pIMem = pIMemT->tData[pCheckInfo->tableId]; - // rows += (pIMem && pIMem->uid == pCheckInfo->tableId) ? pIMem->numOfRows : 0; - // } - } - return rows; -} + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i); + pSupInfo->colIds[i] = pCol->info.colId; -static SArray* createCheckInfoFromUid(STsdbReadHandle* pTsdbReadHandle, int64_t uid) { - SArray* pTableCheckInfo = taosArrayInit(1, sizeof(STableCheckInfo)); - if (pTableCheckInfo == NULL) { - return NULL; + if (IS_VAR_DATA_TYPE(pCol->info.type)) { + pSupInfo->buildBuf[i] = taosMemoryMalloc(pCol->info.bytes); + } } - STableCheckInfo info = { - .tableId = uid, - }; - info.suid = pTsdbReadHandle->suid; - taosArrayPush(pTableCheckInfo, &info); - tsdbDebug("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReadHandle, info.tableId, info.lastKey, - pTsdbReadHandle->idStr); - return pTableCheckInfo; + return TSDB_CODE_SUCCESS; } -static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, SArray* pTableList) { - size_t tableSize = taosArrayGetSize(pTableList); - +static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableKeyInfo* idList, int32_t numOfTables) { // allocate buffer in order to load data blocks from file - SArray* pTableCheckInfo = taosArrayInit(tableSize, sizeof(STableCheckInfo)); - if (pTableCheckInfo == NULL) { + // todo use simple hash instead + SHashObj* pTableMap = + taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (pTableMap == NULL) { return NULL; } // todo apply the lastkey of table check to avoid to load header file - for (int32_t j = 0; j < tableSize; ++j) { - STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(pTableList, j); - - STableCheckInfo info = {.lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid}; - info.suid = pTsdbReadHandle->suid; - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - if (info.lastKey == INT64_MIN || info.lastKey < pTsdbReadHandle->window.skey) { - info.lastKey = pTsdbReadHandle->window.skey; + for (int32_t j = 0; j < numOfTables; ++j) { + STableBlockScanInfo info = {.lastKey = 0, .uid = idList[j].uid}; + if (ASCENDING_TRAVERSE(pTsdbReader->order)) { + if (info.lastKey == INT64_MIN || info.lastKey < pTsdbReader->window.skey) { + info.lastKey = pTsdbReader->window.skey; } - assert(info.lastKey >= pTsdbReadHandle->window.skey && info.lastKey <= pTsdbReadHandle->window.ekey); + ASSERT(info.lastKey >= pTsdbReader->window.skey && info.lastKey <= pTsdbReader->window.ekey); } else { - info.lastKey = pTsdbReadHandle->window.skey; + info.lastKey = pTsdbReader->window.skey; } - taosArrayPush(pTableCheckInfo, &info); - tsdbDebug("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReadHandle, info.tableId, info.lastKey, - pTsdbReadHandle->idStr); + taosHashPut(pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info)); + tsdbDebug("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReader, info.uid, info.lastKey, + pTsdbReader->idStr); } - return pTableCheckInfo; + return pTableMap; } -static void resetCheckInfo(STsdbReadHandle* pTsdbReadHandle) { - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - assert(numOfTables >= 1); +static void resetDataBlockScanInfo(SHashObj* pTableMap) { + STableBlockScanInfo* p = NULL; - // todo apply the lastkey of table check to avoid to load header file - for (int32_t i = 0; i < numOfTables; ++i) { - STableCheckInfo* pCheckInfo = (STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); - pCheckInfo->lastKey = pTsdbReadHandle->window.skey; - pCheckInfo->iter = tsdbTbDataIterDestroy(pCheckInfo->iter); - pCheckInfo->iiter = tsdbTbDataIterDestroy(pCheckInfo->iiter); - pCheckInfo->initBuf = false; - - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - assert(pCheckInfo->lastKey >= pTsdbReadHandle->window.skey); - } else { - assert(pCheckInfo->lastKey <= pTsdbReadHandle->window.skey); + while ((p = taosHashIterate(pTableMap, p)) != NULL) { + p->iterInit = false; + p->iiter.hasVal = false; + if (p->iter.iter != NULL) { + tsdbTbDataIterDestroy(p->iter.iter); } - } -} -// only one table, not need to sort again -static SArray* createCheckInfoFromCheckInfo(STableCheckInfo* pCheckInfo, TSKEY skey, SArray** psTable) { - SArray* pNew = taosArrayInit(1, sizeof(STableCheckInfo)); - - STableCheckInfo info = {.lastKey = skey}; - - info.tableId = pCheckInfo->tableId; - taosArrayPush(pNew, &info); - return pNew; + taosArrayDestroy(p->delSkyline); + } } -static bool emptyQueryTimewindow(STsdbReadHandle* pTsdbReadHandle) { - assert(pTsdbReadHandle != NULL); - - STimeWindow* w = &pTsdbReadHandle->window; - bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); - - return ((asc && w->skey > w->ekey) || (!asc && w->ekey > w->skey)); +static bool isEmptyQueryTimeWindow(STimeWindow* pWindow) { + ASSERT(pWindow != NULL); + return pWindow->skey > pWindow->ekey; } // Update the query time window according to the data time to live(TTL) information, in order to avoid to return // the expired data to client, even it is queried already. -static int64_t getEarliestValidTimestamp(STsdb* pTsdb) { - STsdbKeepCfg* pCfg = REPO_KEEP_CFG(pTsdb); +static STimeWindow updateQueryTimeWindow(STsdb* pTsdb, STimeWindow* pWindow) { + STsdbKeepCfg* pCfg = &pTsdb->keepCfg; int64_t now = taosGetTimestamp(pCfg->precision); - return now - (tsTickPerMin[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick -} + int64_t earilyTs = now - (tsTickPerMin[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick -static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, SQueryTableDataCond* pCond, int32_t tWinIdx) { - pTsdbReadHandle->window = pCond->twindows[tWinIdx]; - - bool updateTs = false; - int64_t startTs = getEarliestValidTimestamp(pTsdbReadHandle->pTsdb); - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - if (startTs > pTsdbReadHandle->window.skey) { - pTsdbReadHandle->window.skey = startTs; - pCond->twindows[tWinIdx].skey = startTs; - updateTs = true; - } - } else { - if (startTs > pTsdbReadHandle->window.ekey) { - pTsdbReadHandle->window.ekey = startTs; - pCond->twindows[tWinIdx].ekey = startTs; - updateTs = true; - } + STimeWindow win = *pWindow; + if (win.skey < earilyTs) { + win.skey = earilyTs; } - if (updateTs) { - tsdbDebug("%p update the query time window, old:%" PRId64 " - %" PRId64 ", new:%" PRId64 " - %" PRId64 ", %s", - pTsdbReadHandle, pCond->twindows[tWinIdx].skey, pCond->twindows[tWinIdx].ekey, - pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr); - } + return win; } -static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle, TSKEY winSKey, SRetention* retentions) { - if (VND_IS_RSMA(pVnode)) { - int level = 0; - int64_t now = taosGetTimestamp(pVnode->config.tsdbCfg.precision); +// todo remove this +static void setQueryTimewindow(STsdbReader* pReader, SQueryTableDataCond* pCond, int32_t tWinIdx) { + // pReader->window = pCond->twindows[tWinIdx]; - for (int i = 0; i < TSDB_RETENTION_MAX; ++i) { - SRetention* pRetention = retentions + level; - if (pRetention->keep <= 0) { - if (level > 0) { - --level; - } - break; - } - if ((now - pRetention->keep) <= winSKey) { - break; - } - ++level; - } + // bool updateTs = false; + // int64_t startTs = updateQueryTimeWindow(pReader->pTsdb); + // if (ASCENDING_TRAVERSE(pReader->order)) { + // if (startTs > pReader->window.skey) { + // pReader->window.skey = startTs; + // pCond->twindows[tWinIdx].skey = startTs; + // updateTs = true; + // } + // } else { + // if (startTs > pReader->window.ekey) { + // pReader->window.ekey = startTs; + // pCond->twindows[tWinIdx].ekey = startTs; + // updateTs = true; + // } + // } - if (level == TSDB_RETENTION_L0) { - tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle, - TSDB_RETENTION_L0); - return VND_RSMA0(pVnode); - } else if (level == TSDB_RETENTION_L1) { - tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle, - TSDB_RETENTION_L1); - return VND_RSMA1(pVnode); - } else { - tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle, - TSDB_RETENTION_L2); - return VND_RSMA2(pVnode); - } - } - return VND_TSDB(pVnode); + // if (updateTs) { + // tsdbDebug("%p update the query time window, old:%" PRId64 " - %" PRId64 ", new:%" PRId64 " - %" PRId64 ", %s", + // pReader, pCond->twindows[tWinIdx].skey, pCond->twindows[tWinIdx].ekey, pReader->window.skey, + // pReader->window.ekey, pReader->idStr); + // } } -static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond* pCond, uint64_t qId, uint64_t taskId) { - STsdbReadHandle* pReadHandle = taosMemoryCalloc(1, sizeof(STsdbReadHandle)); - if (pReadHandle == NULL) { - goto _end; +static void limitOutputBufferSize(const SQueryTableDataCond* pCond, int32_t* capacity) { + int32_t rowLen = 0; + for (int32_t i = 0; i < pCond->numOfCols; ++i) { + rowLen += pCond->colList[i].bytes; + } + + // make sure the output SSDataBlock size be less than 2MB. + const int32_t TWOMB = 2 * 1024 * 1024; + if ((*capacity) * rowLen > TWOMB) { + (*capacity) = TWOMB / rowLen; } +} - STsdb* pTsdb = getTsdbByRetentions(pVnode, pReadHandle, pCond->twindows[0].skey, pVnode->config.tsdbCfg.retentions); +// init file iterator +static int32_t initFilesetIterator(SFilesetIter* pIter, const STsdbFSState* pFState, int32_t order, const char* idstr) { + size_t numOfFileset = taosArrayGetSize(pFState->aDFileSet); - pReadHandle->order = pCond->order; - pReadHandle->pTsdb = pTsdb; - pReadHandle->type = TSDB_QUERY_TYPE_ALL; - pReadHandle->cur.fid = INT32_MIN; - pReadHandle->cur.win = TSWINDOW_INITIALIZER; - pReadHandle->checkFiles = true; - pReadHandle->activeIndex = 0; // current active table index - pReadHandle->allocSize = 0; - pReadHandle->locateStart = false; - pReadHandle->loadType = pCond->type; + pIter->index = ASCENDING_TRAVERSE(order) ? -1 : numOfFileset; + pIter->order = order; + pIter->pFileList = taosArrayDup(pFState->aDFileSet); + pIter->numOfFiles = numOfFileset; - pReadHandle->suid = pCond->suid; - pReadHandle->outputCapacity = 4096; //((STsdb*)tsdb)->config.maxRowsPerFileBlock; - pReadHandle->loadExternalRow = pCond->loadExternalRows; - pReadHandle->currentLoadExternalRows = pCond->loadExternalRows; + tsdbDebug("init fileset iterator, total files:%d %s", pIter->numOfFiles, idstr); + return TSDB_CODE_SUCCESS; +} - char buf[128] = {0}; - snprintf(buf, tListLen(buf), "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, qId); - pReadHandle->idStr = strdup(buf); +static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) { + bool asc = ASCENDING_TRAVERSE(pIter->order); + int32_t step = asc ? 1 : -1; + pIter->index += step; - if (tsdbInitReadH(&pReadHandle->rhelper, pReadHandle->pTsdb) != 0) { - goto _end; + if ((asc && pIter->index >= pIter->numOfFiles) || ((!asc) && pIter->index < 0)) { + return false; } - assert(pCond != NULL); - setQueryTimewindow(pReadHandle, pCond, 0); + // check file the time range of coverage + STimeWindow win = {0}; - if (pCond->numOfCols > 0) { - int32_t rowLen = 0; - for (int32_t i = 0; i < pCond->numOfCols; ++i) { - rowLen += pCond->colList[i].bytes; - } + while (1) { + pReader->status.pCurrentFileset = (SDFileSet*)taosArrayGet(pIter->pFileList, pIter->index); - // make sure the output SSDataBlock size be less than 2MB. - int32_t TWOMB = 2 * 1024 * 1024; - if (pReadHandle->outputCapacity * rowLen > TWOMB) { - pReadHandle->outputCapacity = TWOMB / rowLen; + int32_t code = tsdbDataFReaderOpen(&pReader->pFileReader, pReader->pTsdb, pReader->status.pCurrentFileset); + if (code != TSDB_CODE_SUCCESS) { + goto _err; } - // allocate buffer in order to load data blocks from file - pReadHandle->suppInfo.pstatis = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnDataAgg)); - if (pReadHandle->suppInfo.pstatis == NULL) { - goto _end; - } + int32_t fid = pReader->status.pCurrentFileset->fid; + tsdbFidKeyRange(fid, pReader->pTsdb->keepCfg.days, pReader->pTsdb->keepCfg.precision, &win.skey, &win.ekey); - // todo: use list instead of array? - pReadHandle->pResBlock = createDataBlock(); - if (pReadHandle->pResBlock == NULL) { - goto _end; + // current file are no longer overlapped with query time window, ignore remain files + if ((asc && win.skey > pReader->window.ekey) || (!asc && win.ekey < pReader->window.skey)) { + tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pReader, + pReader->window.skey, pReader->window.ekey, pReader->idStr); + return false; } - for (int32_t i = 0; i < pCond->numOfCols; ++i) { - SColumnInfoData colInfo = {.info = pCond->colList[i], 0}; - int32_t code = blockDataAppendColInfo(pReadHandle->pResBlock, &colInfo); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + if ((asc && (win.ekey < pReader->window.skey)) || ((!asc) && (win.skey > pReader->window.ekey))) { + pIter->index += step; + continue; } - blockDataEnsureCapacity(pReadHandle->pResBlock, pReadHandle->outputCapacity); - - pReadHandle->suppInfo.defaultLoadColumn = getDefaultLoadColumns(pReadHandle, true); - - size_t size = taosArrayGetSize(pReadHandle->suppInfo.defaultLoadColumn); - pReadHandle->suppInfo.slotIds = taosMemoryCalloc(size, sizeof(int32_t)); - pReadHandle->suppInfo.plist = taosMemoryCalloc(size, POINTER_BYTES); - } - - pReadHandle->pDataCols = tdNewDataCols(1000, pVnode->config.tsdbCfg.maxRows); - if (pReadHandle->pDataCols == NULL) { - tsdbError("%p failed to malloc buf for pDataCols, %s", pReadHandle, pReadHandle->idStr); - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - goto _end; - } - - tsdbInitDataBlockLoadInfo(&pReadHandle->dataBlockLoadInfo); - tsdbInitCompBlockLoadInfo(&pReadHandle->compBlockLoadInfo); - - return (tsdbReaderT)pReadHandle; - -_end: - tsdbCleanupReadHandle(pReadHandle); - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return NULL; -} - -static int32_t setCurrentSchema(SVnode* pVnode, STsdbReadHandle* pTsdbReadHandle) { - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, 0); - - int32_t sversion = 1; - - SMetaReader mr = {0}; - metaReaderInit(&mr, pVnode->pMeta, 0); - int32_t code = metaGetTableEntryByUid(&mr, pCheckInfo->tableId); - if (code != TSDB_CODE_SUCCESS) { - terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; - metaReaderClear(&mr); - return terrno; - } - - if (mr.me.type == TSDB_CHILD_TABLE) { - tb_uid_t suid = mr.me.ctbEntry.suid; - code = metaGetTableEntryByUid(&mr, suid); - if (code != TSDB_CODE_SUCCESS) { - terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; - metaReaderClear(&mr); - return terrno; - } - sversion = mr.me.stbEntry.schemaRow.version; - } else { - ASSERT(mr.me.type == TSDB_NORMAL_TABLE); - sversion = mr.me.ntbEntry.schemaRow.version; + tsdbDebug("%p file found fid:%d for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pReader, fid, pReader->window.skey, + pReader->window.ekey, pReader->idStr); + return true; } - metaReaderClear(&mr); - pTsdbReadHandle->pSchema = metaGetTbTSchema(pVnode->pMeta, pCheckInfo->tableId, sversion); - return TSDB_CODE_SUCCESS; +_err: + return false; } -int32_t tsdbSetTableId(tsdbReaderT reader, int64_t uid) { - STsdbReadHandle* pTsdbReadHandle = reader; - if (pTsdbReadHandle->pTableCheckInfo) taosArrayDestroy(pTsdbReadHandle->pTableCheckInfo); - pTsdbReadHandle->pTableCheckInfo = createCheckInfoFromUid(pTsdbReadHandle, uid); - if (pTsdbReadHandle->pTableCheckInfo == NULL) { - return TSDB_CODE_TDB_OUT_OF_MEMORY; - } - return TDB_CODE_SUCCESS; +static void resetDataBlockIterator(SDataBlockIter* pIter, int32_t order) { + pIter->order = order; + pIter->index = -1; + pIter->numOfBlocks = -1; + pIter->blockList = taosArrayInit(4, sizeof(SFileDataBlockInfo)); } -int32_t tsdbSetTableList(tsdbReaderT reader, SArray* tableList) { - STsdbReadHandle* pTsdbReadHandle = reader; - if (pTsdbReadHandle->pTableCheckInfo) taosArrayDestroy(pTsdbReadHandle->pTableCheckInfo); - pTsdbReadHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pTsdbReadHandle, tableList); - if (pTsdbReadHandle->pTableCheckInfo == NULL) { - return TSDB_CODE_TDB_OUT_OF_MEMORY; - } - return TDB_CODE_SUCCESS; +static void initReaderStatus(SReaderStatus* pStatus) { + pStatus->pTableIter = NULL; + pStatus->loadFromFile = true; } -tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* tableList, uint64_t qId, - uint64_t taskId) { - if (taosArrayGetSize(tableList) == 0) { - return NULL; - } - STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(pVnode, pCond, qId, taskId); - if (pTsdbReadHandle == NULL) { +static SSDataBlock* createResBlock(SQueryTableDataCond* pCond, int32_t capacity) { + SSDataBlock* pResBlock = createDataBlock(); + if (pResBlock == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - if (emptyQueryTimewindow(pTsdbReadHandle)) { - return (tsdbReaderT)pTsdbReadHandle; - } - - // todo apply the lastkey of table check to avoid to load header file - pTsdbReadHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pTsdbReadHandle, tableList); - if (pTsdbReadHandle->pTableCheckInfo == NULL) { - // tsdbCleanupReadHandle(pTsdbReadHandle); - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return NULL; + for (int32_t i = 0; i < pCond->numOfCols; ++i) { + SColumnInfoData colInfo = {{0}, 0}; + colInfo.info = pCond->colList[i]; + blockDataAppendColInfo(pResBlock, &colInfo); } - int32_t code = setCurrentSchema(pVnode, pTsdbReadHandle); + int32_t code = blockDataEnsureCapacity(pResBlock, capacity); if (code != TSDB_CODE_SUCCESS) { terrno = code; + taosMemoryFree(pResBlock); return NULL; } - int32_t numOfCols = taosArrayGetSize(pTsdbReadHandle->suppInfo.defaultLoadColumn); - int16_t* ids = pTsdbReadHandle->suppInfo.defaultLoadColumn->pData; - - STSchema* pSchema = pTsdbReadHandle->pSchema; + return pResBlock; +} - int32_t i = 0, j = 0; - while (i < numOfCols && j < pSchema->numOfCols) { - if (ids[i] == pSchema->columns[j].colId) { - pTsdbReadHandle->suppInfo.slotIds[i] = j; - i++; - j++; - } else if (ids[i] > pSchema->columns[j].colId) { - j++; - } else { - // tsdbCleanupReadHandle(pTsdbReadHandle); - terrno = TSDB_CODE_INVALID_PARA; - return NULL; - } +static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsdbReader** ppReader, const char* idstr) { + int32_t code = 0; + int8_t level = 0; + STsdbReader* pReader = (STsdbReader*)taosMemoryCalloc(1, sizeof(*pReader)); + if (pReader == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; } - tsdbDebug("%p total numOfTable:%" PRIzu " in this query, table %" PRIzu " %s", pTsdbReadHandle, - taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), taosArrayGetSize(tableList), pTsdbReadHandle->idStr); + initReaderStatus(&pReader->status); - return (tsdbReaderT)pTsdbReadHandle; -} + pReader->pTsdb = + getTsdbByRetentions(pVnode, pCond->twindows[0].skey, pVnode->config.tsdbCfg.retentions, idstr, &level); + pReader->suid = pCond->suid; + pReader->order = pCond->order; + pReader->capacity = 4096; + pReader->idStr = (idstr != NULL) ? strdup(idstr) : NULL; + pReader->verRange = getQueryVerRange(pVnode, pCond, level); + pReader->type = pCond->type; + pReader->window = updateQueryTimeWindow(pVnode->pTsdb, pCond->twindows); -void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond* pCond, int32_t tWinIdx) { - STsdbReadHandle* pTsdbReadHandle = queryHandle; + // todo remove this + setQueryTimewindow(pReader, pCond, 0); + ASSERT(pCond->numOfCols > 0); - if (emptyQueryTimewindow(pTsdbReadHandle)) { - if (pCond->order != pTsdbReadHandle->order) { - pTsdbReadHandle->order = pCond->order; - TSWAP(pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey); - } + limitOutputBufferSize(pCond, &pReader->capacity); - return; + // allocate buffer in order to load data blocks from file + SBlockLoadSuppInfo* pSup = &pReader->suppInfo; + pSup->pstatis = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnDataAgg)); + pSup->plist = taosMemoryCalloc(pCond->numOfCols, POINTER_BYTES); + if (pSup->pstatis == NULL || pSup->plist == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; } - pTsdbReadHandle->order = pCond->order; - setQueryTimewindow(pTsdbReadHandle, pCond, tWinIdx); - pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; - pTsdbReadHandle->cur.fid = -1; - pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->activeIndex = 0; // current active table index - pTsdbReadHandle->locateStart = false; - pTsdbReadHandle->loadExternalRow = pCond->loadExternalRows; - - if (ASCENDING_TRAVERSE(pCond->order)) { - assert(pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); - } else { - assert(pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); + pReader->pResBlock = createResBlock(pCond, pReader->capacity); + if (pReader->pResBlock == NULL) { + code = terrno; + goto _end; } - // allocate buffer in order to load data blocks from file - memset(pTsdbReadHandle->suppInfo.pstatis, 0, sizeof(SColumnDataAgg)); - memset(pTsdbReadHandle->suppInfo.plist, 0, POINTER_BYTES); + setColumnIdSlotList(pReader, pReader->pResBlock); - tsdbInitDataBlockLoadInfo(&pTsdbReadHandle->dataBlockLoadInfo); - tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo); + *ppReader = pReader; + return code; - resetCheckInfo(pTsdbReadHandle); +_end: + tsdbReaderClose(pReader); + *ppReader = NULL; + return code; } -void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, SQueryTableDataCond* pCond, STableListInfo* tableList, - int32_t tWinIdx) { - STsdbReadHandle* pTsdbReadHandle = queryHandle; - - pTsdbReadHandle->order = pCond->order; - pTsdbReadHandle->window = pCond->twindows[tWinIdx]; - pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; - pTsdbReadHandle->cur.fid = -1; - pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->activeIndex = 0; // current active table index - pTsdbReadHandle->locateStart = false; - pTsdbReadHandle->loadExternalRow = pCond->loadExternalRows; - - if (ASCENDING_TRAVERSE(pCond->order)) { - assert(pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); - } else { - assert(pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); +// void tsdbResetQueryHandleForNewTable(STsdbReader* queryHandle, SQueryTableDataCond* pCond, STableListInfo* tableList, +// int32_t tWinIdx) { +// STsdbReader* pTsdbReadHandle = queryHandle; + +// pTsdbReadHandle->order = pCond->order; +// pTsdbReadHandle->window = pCond->twindows[tWinIdx]; +// pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; +// pTsdbReadHandle->cur.fid = -1; +// pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; +// pTsdbReadHandle->checkFiles = true; +// pTsdbReadHandle->activeIndex = 0; // current active table index +// pTsdbReadHandle->locateStart = false; +// pTsdbReadHandle->loadExternalRow = pCond->loadExternalRows; + +// if (ASCENDING_TRAVERSE(pCond->order)) { +// assert(pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); +// } else { +// assert(pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); +// } + +// // allocate buffer in order to load data blocks from file +// memset(pTsdbReadHandle->suppInfo.pstatis, 0, sizeof(SColumnDataAgg)); +// memset(pTsdbReadHandle->suppInfo.plist, 0, POINTER_BYTES); + +// tsdbInitDataBlockLoadInfo(&pTsdbReadHandle->dataBlockLoadInfo); +// tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo); + +// SArray* pTable = NULL; +// // STsdbMeta* pMeta = tsdbGetMeta(pTsdbReadHandle->pTsdb); + +// // pTsdbReadHandle->pTableCheckInfo = destroyTableCheckInfo(pTsdbReadHandle->pTableCheckInfo); + +// pTsdbReadHandle->pTableCheckInfo = NULL; // createDataBlockScanInfo(pTsdbReadHandle, groupList, pMeta, +// // &pTable); +// if (pTsdbReadHandle->pTableCheckInfo == NULL) { +// // tsdbReaderClose(pTsdbReadHandle); +// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; +// } + +// // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); +// // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); +// } + +// SArray* tsdbGetQueriedTableList(STsdbReader** pHandle) { +// assert(pHandle != NULL); + +// STsdbReader* pTsdbReadHandle = (STsdbReader*)pHandle; + +// size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); +// SArray* res = taosArrayInit(size, POINTER_BYTES); +// return res; +// } + +// static TSKEY extractFirstTraverseKey(STableBlockScanInfo* pCheckInfo, int32_t order, int32_t update, TDRowVerT +// maxVer) { +// TSDBROW row = {0}; +// STSRow *rmem = NULL, *rimem = NULL; + +// if (pCheckInfo->iter) { +// if (tsdbTbDataIterGet(pCheckInfo->iter, &row)) { +// rmem = row.pTSRow; +// } +// } + +// if (pCheckInfo->iiter) { +// if (tsdbTbDataIterGet(pCheckInfo->iiter, &row)) { +// rimem = row.pTSRow; +// } +// } + +// if (rmem == NULL && rimem == NULL) { +// return TSKEY_INITIAL_VAL; +// } + +// if (rmem != NULL && rimem == NULL) { +// pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; +// return TD_ROW_KEY(rmem); +// } + +// if (rmem == NULL && rimem != NULL) { +// pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; +// return TD_ROW_KEY(rimem); +// } + +// TSKEY r1 = TD_ROW_KEY(rmem); +// TSKEY r2 = TD_ROW_KEY(rimem); + +// if (r1 == r2) { +// if (TD_SUPPORT_UPDATE(update)) { +// pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; +// } else { +// pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; +// tsdbTbDataIterNext(pCheckInfo->iter); +// } +// return r1; +// } else if (r1 < r2 && ASCENDING_TRAVERSE(order)) { +// pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; +// return r1; +// } else { +// pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; +// return r2; +// } +// } + +// static bool moveToNextRowInMem(STableBlockScanInfo* pCheckInfo) { +// bool hasNext = false; +// if (pCheckInfo->chosen == CHECKINFO_CHOSEN_MEM) { +// if (pCheckInfo->iter != NULL) { +// hasNext = tsdbTbDataIterNext(pCheckInfo->iter); +// } + +// if (hasNext) { +// return hasNext; +// } + +// if (pCheckInfo->iiter != NULL) { +// return tsdbTbDataIterGet(pCheckInfo->iiter, NULL); +// } +// } else if (pCheckInfo->chosen == CHECKINFO_CHOSEN_IMEM) { +// if (pCheckInfo->iiter != NULL) { +// hasNext = tsdbTbDataIterNext(pCheckInfo->iiter); +// } + +// if (hasNext) { +// return hasNext; +// } + +// if (pCheckInfo->iter != NULL) { +// return tsdbTbDataIterGet(pCheckInfo->iter, NULL); +// } +// } else { +// if (pCheckInfo->iter != NULL) { +// hasNext = tsdbTbDataIterNext(pCheckInfo->iter); +// } +// if (pCheckInfo->iiter != NULL) { +// hasNext = tsdbTbDataIterNext(pCheckInfo->iiter) || hasNext; +// } +// } + +// return hasNext; +// } + +// static int32_t binarySearchForBlock(SBlock* pBlock, int32_t numOfBlocks, TSKEY skey, int32_t order) { +// int32_t firstSlot = 0; +// int32_t lastSlot = numOfBlocks - 1; + +// int32_t midSlot = firstSlot; + +// while (1) { +// numOfBlocks = lastSlot - firstSlot + 1; +// midSlot = (firstSlot + (numOfBlocks >> 1)); + +// if (numOfBlocks == 1) break; + +// if (skey > pBlock[midSlot].maxKey.ts) { +// if (numOfBlocks == 2) break; +// if ((order == TSDB_ORDER_DESC) && (skey < pBlock[midSlot + 1].minKey.ts)) break; +// firstSlot = midSlot + 1; +// } else if (skey < pBlock[midSlot].minKey.ts) { +// if ((order == TSDB_ORDER_ASC) && (skey > pBlock[midSlot - 1].maxKey.ts)) break; +// lastSlot = midSlot - 1; +// } else { +// break; // got the slot +// } +// } + +// return midSlot; +// } + +static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFReader* pFileReader, SArray* pIndexList) { + SArray* aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); + + int32_t code = tsdbReadBlockIdx(pFileReader, aBlockIdx, NULL); + if (code != TSDB_CODE_SUCCESS) { + goto _end; } - // allocate buffer in order to load data blocks from file - memset(pTsdbReadHandle->suppInfo.pstatis, 0, sizeof(SColumnDataAgg)); - memset(pTsdbReadHandle->suppInfo.plist, 0, POINTER_BYTES); - - tsdbInitDataBlockLoadInfo(&pTsdbReadHandle->dataBlockLoadInfo); - tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo); - - SArray* pTable = NULL; - // STsdbMeta* pMeta = tsdbGetMeta(pTsdbReadHandle->pTsdb); - - // pTsdbReadHandle->pTableCheckInfo = destroyTableCheckInfo(pTsdbReadHandle->pTableCheckInfo); - - pTsdbReadHandle->pTableCheckInfo = NULL; // createCheckInfoFromTableGroup(pTsdbReadHandle, groupList, pMeta, - // &pTable); - if (pTsdbReadHandle->pTableCheckInfo == NULL) { - // tsdbCleanupReadHandle(pTsdbReadHandle); - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + if (taosArrayGetSize(aBlockIdx) == 0) { + taosArrayClear(aBlockIdx); + return TSDB_CODE_SUCCESS; } - // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); - // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); -} + SBlockIdx* pBlockIdx; + for (int32_t i = 0; i < taosArrayGetSize(aBlockIdx); ++i) { + pBlockIdx = (SBlockIdx*)taosArrayGet(aBlockIdx, i); -tsdbReaderT tsdbQueryLastRow(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* pList, uint64_t qId, - uint64_t taskId) { - pCond->twindows[0] = updateLastrowForEachGroup(pList); + // uid check + if (pBlockIdx->suid != pReader->suid) { + continue; + } - // no qualified table - if (taosArrayGetSize(pList->pTableList) == 0) { - return NULL; - } + // this block belongs to a table that is not queried. + void* p = taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(uint64_t)); + if (p == NULL) { + continue; + } - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbReaderOpen(pVnode, pCond, pList->pTableList, qId, taskId); - if (pTsdbReadHandle == NULL) { - return NULL; - } + // todo: not valid info in bockIndex + // time range check + // if (pBlockIdx->minKey > pReader->window.ekey || pBlockIdx->maxKey < pReader->window.skey) { + // continue; + // } - int32_t code = checkForCachedLastRow(pTsdbReadHandle, pList); - if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 - terrno = code; - return NULL; - } + // version check + // if (pBlockIdx->minVersion > pReader->verRange.maxVer || pBlockIdx->maxVersion < pReader->verRange.minVer) { + // continue; + // } + + STableBlockScanInfo* pScanInfo = p; + if (pScanInfo->pBlockList == NULL) { + pScanInfo->pBlockList = taosArrayInit(16, sizeof(SBlock)); + } - assert(pCond->order == TSDB_ORDER_ASC && pCond->twindows[0].skey <= pCond->twindows[0].ekey); - if (pTsdbReadHandle->cachelastrow) { - pTsdbReadHandle->type = TSDB_QUERY_TYPE_LAST; + pScanInfo->blockIdx = *pBlockIdx; + taosArrayPush(pIndexList, pBlockIdx); } - return pTsdbReadHandle; +_end: + taosArrayDestroy(aBlockIdx); + return code; } -#if 0 -tsdbReaderT tsdbQueryCacheLastT(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, SMemTable* pMemRef) { - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTablesT(tsdb, pCond, groupList, qId, pMemRef); - if (pTsdbReadHandle == NULL) { - return NULL; - } +static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, uint32_t* numOfValidTables, + int32_t* numOfBlocks) { + size_t numOfTables = taosArrayGetSize(pIndexList); - int32_t code = checkForCachedLast(pTsdbReadHandle); - if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 - terrno = code; - return NULL; - } + *numOfValidTables = 0; - if (pTsdbReadHandle->cachelastrow) { - pTsdbReadHandle->type = TSDB_QUERY_TYPE_LAST; - } - - return pTsdbReadHandle; -} + STableBlockScanInfo* px = NULL; + while (1) { + px = taosHashIterate(pReader->status.pTableMap, px); + if (px == NULL) { + break; + } -#endif -SArray* tsdbGetQueriedTableList(tsdbReaderT* pHandle) { - assert(pHandle != NULL); + taosArrayClear(px->pBlockList); + } - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; + for (int32_t i = 0; i < numOfTables; ++i) { + SBlockIdx* pBlockIdx = taosArrayGet(pIndexList, i); - size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - SArray* res = taosArrayInit(size, POINTER_BYTES); - return res; -} + SMapData mapData = {0}; + tMapDataReset(&mapData); + tsdbReadBlock(pReader->pFileReader, pBlockIdx, &mapData, NULL); -// leave only one table for each group -// static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGroupList) { -// assert(pGroupList); -// size_t numOfGroup = taosArrayGetSize(pGroupList->pGroupList); -// -// STableGroupInfo* pNew = taosMemoryCalloc(1, sizeof(STableGroupInfo)); -// pNew->pGroupList = taosArrayInit(numOfGroup, POINTER_BYTES); -// -// for (int32_t i = 0; i < numOfGroup; ++i) { -// SArray* oneGroup = taosArrayGetP(pGroupList->pGroupList, i); -// size_t numOfTables = taosArrayGetSize(oneGroup); -// -// SArray* px = taosArrayInit(4, sizeof(STableKeyInfo)); -// for (int32_t j = 0; j < numOfTables; ++j) { -// STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(oneGroup, j); -// // if (window->skey <= pInfo->lastKey && ((STable*)pInfo->pTable)->lastKey != TSKEY_INITIAL_VAL) { -// // taosArrayPush(px, pInfo); -// // pNew->numOfTables += 1; -// // break; -// // } -// } -// -// // there are no data in this group -// if (taosArrayGetSize(px) == 0) { -// taosArrayDestroy(px); -// } else { -// taosArrayPush(pNew->pGroupList, &px); -// } -// } -// -// return pNew; -//} + STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(int64_t)); + for (int32_t j = 0; j < mapData.nItem; ++j) { + SBlock block = {0}; -// tsdbReaderT tsdbQueryRowsInExternalWindow(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList, -// uint64_t qId, uint64_t taskId) { -// STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList); -// -// if (pNew->numOfTables == 0) { -// tsdbDebug("update query time range to invalidate time window"); -// -// assert(taosArrayGetSize(pNew->pGroupList) == 0); -// bool asc = ASCENDING_TRAVERSE(pCond->order); -// if (asc) { -// pCond->twindow.ekey = pCond->twindow.skey - 1; -// } else { -// pCond->twindow.skey = pCond->twindow.ekey - 1; -// } -// } -// -// STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(pVnode, pCond, pNew, qId, taskId); -// pTsdbReadHandle->loadExternalRow = true; -// pTsdbReadHandle->currentLoadExternalRows = true; -// -// return pTsdbReadHandle; -//} + tMapDataGetItemByIdx(&mapData, j, &block, tGetBlock); -static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pCheckInfo) { - if (pCheckInfo->initBuf) { - return true; - } + // 1. time range check + if (block.minKey.ts > pReader->window.ekey || block.maxKey.ts < pReader->window.skey) { + continue; + } - pCheckInfo->initBuf = true; - int32_t order = pHandle->order; + // 2. version range check + if (block.minVersion > pReader->verRange.maxVer || block.maxVersion < pReader->verRange.minVer) { + continue; + } - STbData* pMem = NULL; - STbData* pIMem = NULL; - int8_t backward = (pHandle->order == TSDB_ORDER_DESC) ? 1 : 0; + void* p = taosArrayPush(pScanInfo->pBlockList, &block); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } - TSKEY tLastKey = keyToTkey(pCheckInfo->lastKey); - if (pHandle->pTsdb->mem != NULL) { - tsdbGetTbDataFromMemTable(pHandle->pTsdb->mem, pCheckInfo->suid, pCheckInfo->tableId, &pMem); - if (pMem != NULL) { - tsdbTbDataIterCreate(pMem, &(TSDBKEY){.version = 0, .ts = tLastKey}, backward, &pCheckInfo->iter); + (*numOfBlocks) += 1; } - } - if (pHandle->pTsdb->imem != NULL) { - tsdbGetTbDataFromMemTable(pHandle->pTsdb->mem, pCheckInfo->suid, pCheckInfo->tableId, &pIMem); - if (pIMem != NULL) { - tsdbTbDataIterCreate(pIMem, &(TSDBKEY){.version = 0, .ts = tLastKey}, backward, &pCheckInfo->iiter); + if (pScanInfo->pBlockList != NULL && taosArrayGetSize(pScanInfo->pBlockList) > 0) { + (*numOfValidTables) += 1; } } - // both iterators are NULL, no data in buffer right now - if (pCheckInfo->iter == NULL && pCheckInfo->iiter == NULL) { - return false; - } - - bool memEmpty = - (pCheckInfo->iter == NULL) || (pCheckInfo->iter != NULL && !tsdbTbDataIterGet(pCheckInfo->iter, NULL)); - bool imemEmpty = - (pCheckInfo->iiter == NULL) || (pCheckInfo->iiter != NULL && !tsdbTbDataIterGet(pCheckInfo->iiter, NULL)); - if (memEmpty && imemEmpty) { // buffer is empty - return false; - } + return TSDB_CODE_SUCCESS; +} - if (!memEmpty) { - TSDBROW row; +// todo remove pblock parameter +static void setBlockAllDumped(SFileBlockDumpInfo* pDumpInfo, SBlock* pBlock, int32_t order) { + int32_t step = ASCENDING_TRAVERSE(order) ? 1 : -1; - tsdbTbDataIterGet(pCheckInfo->iter, &row); - TSKEY key = row.pTSRow->ts; // first timestamp in buffer - tsdbDebug("%p uid:%" PRId64 ", check data in mem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 - "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", - pHandle, pCheckInfo->tableId, key, order, pMem->minKey.ts, pMem->maxKey.ts, pCheckInfo->lastKey, - pMem->sl.size, pHandle->idStr); + pDumpInfo->allDumped = true; + pDumpInfo->lastKey = pBlock->maxKey.ts + step; +} - if (ASCENDING_TRAVERSE(order)) { - assert(pCheckInfo->lastKey <= key); +static void doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int32_t colIndex, SColVal* pColVal, + SBlockLoadSuppInfo* pSup) { + if (IS_VAR_DATA_TYPE(pColVal->type)) { + if (pColVal->isNull || pColVal->isNone) { + colDataAppendNULL(pColInfoData, rowIndex); } else { - assert(pCheckInfo->lastKey >= key); + varDataSetLen(pSup->buildBuf[colIndex], pColVal->value.nData); + memcpy(varDataVal(pSup->buildBuf[colIndex]), pColVal->value.pData, pColVal->value.nData); + colDataAppend(pColInfoData, rowIndex, pSup->buildBuf[colIndex], false); } - } else { - tsdbDebug("%p uid:%" PRId64 ", no data in mem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); + colDataAppend(pColInfoData, rowIndex, (const char*)&pColVal->value, pColVal->isNull || pColVal->isNone); } +} - if (!imemEmpty) { - TSDBROW row; +static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo) { + SReaderStatus* pStatus = &pReader->status; + SDataBlockIter* pBlockIter = &pStatus->blockIter; - tsdbTbDataIterGet(pCheckInfo->iter, &row); - TSKEY key = row.pTSRow->ts; // first timestamp in buffer - tsdbDebug("%p uid:%" PRId64 ", check data in imem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 - "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", - pHandle, pCheckInfo->tableId, key, order, pIMem->minKey.ts, pIMem->maxKey.ts, pCheckInfo->lastKey, - pIMem->sl.size, pHandle->idStr); + SBlockData* pBlockData = &pStatus->fileBlockData; + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(pBlockIter); + SBlock* pBlock = taosArrayGet(pBlockScanInfo->pBlockList, pFBlock->tbBlockIdx); + SSDataBlock* pResBlock = pReader->pResBlock; + int32_t numOfCols = blockDataGetNumOfCols(pResBlock); - if (ASCENDING_TRAVERSE(order)) { - assert(pCheckInfo->lastKey <= key); - } else { - assert(pCheckInfo->lastKey >= key); - } - } else { - tsdbDebug("%p uid:%" PRId64 ", no data in imem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); - } + SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - return true; -} + int64_t st = taosGetTimestampUs(); -static void destroyTableMemIterator(STableCheckInfo* pCheckInfo) { - tsdbTbDataIterDestroy(pCheckInfo->iter); - tsdbTbDataIterDestroy(pCheckInfo->iiter); -} + SColVal cv = {0}; + int32_t colIndex = 0; -static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, TDRowVerT maxVer) { - TSDBROW row = {0}; - STSRow *rmem = NULL, *rimem = NULL; + bool asc = ASCENDING_TRAVERSE(pReader->order); + int32_t step = asc ? 1 : -1; - if (pCheckInfo->iter) { - if (tsdbTbDataIterGet(pCheckInfo->iter, &row)) { - rmem = row.pTSRow; - } + int32_t rowIndex = 0; + int32_t remain = asc ? (pBlockData->nRow - pDumpInfo->rowIndex) : (pDumpInfo->rowIndex + 1); + + int32_t endIndex = 0; + if (remain <= pReader->capacity) { + endIndex = pBlockData->nRow; + } else { + endIndex = pDumpInfo->rowIndex + step * pReader->capacity; + remain = pReader->capacity; } - if (pCheckInfo->iiter) { - if (tsdbTbDataIterGet(pCheckInfo->iiter, &row)) { - rimem = row.pTSRow; + int32_t i = 0; + SColumnInfoData* pColData = taosArrayGet(pResBlock->pDataBlock, i); + if (pColData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) { + for (int32_t j = pDumpInfo->rowIndex; j < endIndex && j >= 0; j += step) { + colDataAppend(pColData, rowIndex++, (const char*)&pBlockData->aTSKEY[j], false); } + i += 1; } - if (rmem == NULL && rimem == NULL) { - return TSKEY_INITIAL_VAL; - } + while (i < numOfCols && colIndex < taosArrayGetSize(pBlockData->aIdx)) { + rowIndex = 0; + pColData = taosArrayGet(pResBlock->pDataBlock, i); + + SColData* pData = tBlockDataGetColDataByIdx(pBlockData, colIndex); + + if (pData->cid == pColData->info.colId) { + for (int32_t j = pDumpInfo->rowIndex; j < endIndex && j >= 0; j += step) { + tColDataGetValue(pData, j, &cv); + doCopyColVal(pColData, rowIndex++, i, &cv, pSupInfo); + } + colIndex += 1; + } else { // the specified column does not exist in file block, fill with null data + colDataAppendNNULL(pColData, 0, remain); + } - if (rmem != NULL && rimem == NULL) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; - return TD_ROW_KEY(rmem); + ASSERT(rowIndex == remain); + i += 1; } - if (rmem == NULL && rimem != NULL) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return TD_ROW_KEY(rimem); + while (i < numOfCols) { + pColData = taosArrayGet(pResBlock->pDataBlock, i); + colDataAppendNNULL(pColData, 0, remain); + i += 1; } - TSKEY r1 = TD_ROW_KEY(rmem); - TSKEY r2 = TD_ROW_KEY(rimem); + pResBlock->info.rows = remain; + pDumpInfo->rowIndex += step * remain; - if (r1 == r2) { -#if 0 - if (update == TD_ROW_DISCARD_UPDATE) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - tSkipListIterNext(pCheckInfo->iter); - } else if (update == TD_ROW_OVERWRITE_UPDATE) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; - tSkipListIterNext(pCheckInfo->iiter); - } else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; - } -#endif - if (TD_SUPPORT_UPDATE(update)) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; - } else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - tsdbTbDataIterNext(pCheckInfo->iter); - } - return r1; - } else if (r1 < r2 && ASCENDING_TRAVERSE(order)) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; - return r1; - } else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return r2; - } -} + setBlockAllDumped(pDumpInfo, pBlock, pReader->order); -static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, STSRow** extraRow, - TDRowVerT maxVer) { - TSDBROW row; - STSRow *rmem = NULL, *rimem = NULL; - if (pCheckInfo->iter) { - if (tsdbTbDataIterGet(pCheckInfo->iter, &row)) { - rmem = row.pTSRow; - } - } + int64_t elapsedTime = (taosGetTimestampUs() - st); + pReader->cost.blockLoadTime += elapsedTime; - if (pCheckInfo->iiter) { - if (tsdbTbDataIterGet(pCheckInfo->iiter, &row)) { - rimem = row.pTSRow; - } - } + int32_t unDumpedRows = asc ? pBlock->nRow - pDumpInfo->rowIndex : pDumpInfo->rowIndex + 1; + tsdbDebug("%p load file block into buffer, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64 + ", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%" PRId64 " us, %s", + pReader, pBlockIter->index, pFBlock->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, remain, unDumpedRows, + pBlock->minVersion, pBlock->maxVersion, elapsedTime, pReader->idStr); - if (rmem == NULL && rimem == NULL) { - return NULL; - } + return TSDB_CODE_SUCCESS; +} - if (rmem != NULL && rimem == NULL) { - pCheckInfo->chosen = 0; - return rmem; - } +// todo consider the output buffer size +static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockIter, + STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData) { + int64_t st = taosGetTimestampUs(); - if (rmem == NULL && rimem != NULL) { - pCheckInfo->chosen = 1; - return rimem; - } + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(pBlockIter); + SBlock* pBlock = taosArrayGet(pBlockScanInfo->pBlockList, pFBlock->tbBlockIdx); + SSDataBlock* pResBlock = pReader->pResBlock; + int32_t numOfCols = blockDataGetNumOfCols(pResBlock); - TSKEY r1 = TD_ROW_KEY(rmem); - TSKEY r2 = TD_ROW_KEY(rimem); + SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - if (r1 == r2) { -#if 0 - if (update == TD_ROW_DISCARD_UPDATE) { - tSkipListIterNext(pCheckInfo->iter); - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return rimem; - } else if (update == TD_ROW_OVERWRITE_UPDATE) { - tSkipListIterNext(pCheckInfo->iiter); - pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; - return rmem; - } else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; - *extraRow = rimem; - return rmem; - } -#endif - if (TD_SUPPORT_UPDATE(update)) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; - *extraRow = rimem; - return rmem; - } else { - tsdbTbDataIterNext(pCheckInfo->iter); - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return rimem; - } - } else { - if (ASCENDING_TRAVERSE(order)) { - if (r1 < r2) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; - return rmem; - } else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return rimem; - } - } else { - if (r1 < r2) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return rimem; - } else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - return rmem; - } - } + uint8_t *pb = NULL, *pb1 = NULL; + int32_t code = tsdbReadColData(pReader->pFileReader, &pBlockScanInfo->blockIdx, pBlock, pSupInfo->colIds, numOfCols, + pBlockData, &pb, &pb1); + if (code != TSDB_CODE_SUCCESS) { + goto _error; } -} - -static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { - bool hasNext = false; - if (pCheckInfo->chosen == CHECKINFO_CHOSEN_MEM) { - if (pCheckInfo->iter != NULL) { - hasNext = tsdbTbDataIterNext(pCheckInfo->iter); - } - if (hasNext) { - return hasNext; - } + int64_t elapsedTime = (taosGetTimestampUs() - st); + pReader->cost.blockLoadTime += elapsedTime; - if (pCheckInfo->iiter != NULL) { - return tsdbTbDataIterGet(pCheckInfo->iiter, NULL); - } - } else if (pCheckInfo->chosen == CHECKINFO_CHOSEN_IMEM) { - if (pCheckInfo->iiter != NULL) { - hasNext = tsdbTbDataIterNext(pCheckInfo->iiter); - } + pDumpInfo->allDumped = false; + tsdbDebug("%p load file block into buffer, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64 + ", rows:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%" PRId64 " us, %s", + pReader, pBlockIter->index, pFBlock->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, pBlock->nRow, + pBlock->minVersion, pBlock->maxVersion, elapsedTime, pReader->idStr); + return TSDB_CODE_SUCCESS; - if (hasNext) { - return hasNext; - } +_error: + tsdbError("%p error occurs in loading file block, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64 + ", rows:%d, %s", + pReader, pBlockIter->index, pFBlock->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, pBlock->nRow, + pReader->idStr); + return code; +} - if (pCheckInfo->iter != NULL) { - return tsdbTbDataIterGet(pCheckInfo->iter, NULL); - } - } else { - if (pCheckInfo->iter != NULL) { - hasNext = tsdbTbDataIterNext(pCheckInfo->iter); - } - if (pCheckInfo->iiter != NULL) { - hasNext = tsdbTbDataIterNext(pCheckInfo->iiter) || hasNext; - } +// static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) { +// int firstPos, lastPos, midPos = -1; +// int numOfRows; +// TSKEY* keyList; + +// assert(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC); + +// if (num <= 0) return -1; + +// keyList = (TSKEY*)pValue; +// firstPos = 0; +// lastPos = num - 1; + +// if (order == TSDB_ORDER_DESC) { +// // find the first position which is smaller than the key +// while (1) { +// if (key >= keyList[lastPos]) return lastPos; +// if (key == keyList[firstPos]) return firstPos; +// if (key < keyList[firstPos]) return firstPos - 1; + +// numOfRows = lastPos - firstPos + 1; +// midPos = (numOfRows >> 1) + firstPos; + +// if (key < keyList[midPos]) { +// lastPos = midPos - 1; +// } else if (key > keyList[midPos]) { +// firstPos = midPos + 1; +// } else { +// break; +// } +// } + +// } else { +// // find the first position which is bigger than the key +// while (1) { +// if (key <= keyList[firstPos]) return firstPos; +// if (key == keyList[lastPos]) return lastPos; + +// if (key > keyList[lastPos]) { +// lastPos = lastPos + 1; +// if (lastPos >= num) +// return -1; +// else +// return lastPos; +// } + +// numOfRows = lastPos - firstPos + 1; +// midPos = (numOfRows >> 1) + firstPos; + +// if (key < keyList[midPos]) { +// lastPos = midPos - 1; +// } else if (key > keyList[midPos]) { +// firstPos = midPos + 1; +// } else { +// break; +// } +// } +// } + +// return midPos; +// } +// static int32_t mergeTwoRowFromMem(STsdbReader* pTsdbReadHandle, int32_t capacity, int32_t* curRow, STSRow* row1, +// STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* +// pSchema2, bool update, TSKEY* lastRowKey) { +// #if 1 +// STSchema* pSchema; +// STSRow* row; +// int16_t colId; +// int16_t offset; + +// bool isRow1DataRow = TD_IS_TP_ROW(row1); +// bool isRow2DataRow; +// bool isChosenRowDataRow; +// int32_t chosen_itr; +// SCellVal sVal = {0}; +// TSKEY rowKey = TSKEY_INITIAL_VAL; +// int32_t nResult = 0; +// int32_t mergeOption = 0; // 0 discard 1 overwrite 2 merge + +// // the schema version info is embeded in STSRow +// int32_t numOfColsOfRow1 = 0; + +// if (pSchema1 == NULL) { +// pSchema1 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row1)); +// } + +// #ifdef TD_DEBUG_PRINT_ROW +// char flags[70] = {0}; +// STsdb* pTsdb = pTsdbReadHandle->rhelper.pRepo; +// snprintf(flags, 70, "%s:%d vgId:%d dir:%s row1%s=NULL,row2%s=NULL", __func__, __LINE__, TD_VID(pTsdb->pVnode), +// pTsdb->dir, row1 ? "!" : "", row2 ? "!" : ""); +// tdSRowPrint(row1, pSchema1, flags); +// #endif + +// if (isRow1DataRow) { +// numOfColsOfRow1 = schemaNCols(pSchema1); +// } else { +// numOfColsOfRow1 = tdRowGetNCols(row1); +// } + +// int32_t numOfColsOfRow2 = 0; +// if (row2) { +// isRow2DataRow = TD_IS_TP_ROW(row2); +// if (pSchema2 == NULL) { +// pSchema2 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row2)); +// } +// if (isRow2DataRow) { +// numOfColsOfRow2 = schemaNCols(pSchema2); +// } else { +// numOfColsOfRow2 = tdRowGetNCols(row2); +// } +// } + +// int32_t i = 0, j = 0, k = 0; +// while (i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { +// SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); + +// int32_t colIdOfRow1; +// if (j >= numOfColsOfRow1) { +// colIdOfRow1 = INT32_MAX; +// } else if (isRow1DataRow) { +// colIdOfRow1 = pSchema1->columns[j].colId; +// } else { +// colIdOfRow1 = tdKvRowColIdAt(row1, j); +// } + +// int32_t colIdOfRow2; +// if (k >= numOfColsOfRow2) { +// colIdOfRow2 = INT32_MAX; +// } else if (isRow2DataRow) { +// colIdOfRow2 = pSchema2->columns[k].colId; +// } else { +// colIdOfRow2 = tdKvRowColIdAt(row2, k); +// } + +// if (colIdOfRow1 < colIdOfRow2) { // the most probability +// if (colIdOfRow1 < pColInfo->info.colId) { +// ++j; +// continue; +// } +// row = row1; +// pSchema = pSchema1; +// isChosenRowDataRow = isRow1DataRow; +// chosen_itr = j; +// } else if (colIdOfRow1 == colIdOfRow2) { +// if (colIdOfRow1 < pColInfo->info.colId) { +// ++j; +// ++k; +// continue; +// } +// row = row1; +// pSchema = pSchema1; +// isChosenRowDataRow = isRow1DataRow; +// chosen_itr = j; +// } else { +// if (colIdOfRow2 < pColInfo->info.colId) { +// ++k; +// continue; +// } +// row = row2; +// pSchema = pSchema2; +// chosen_itr = k; +// isChosenRowDataRow = isRow2DataRow; +// } + +// if (isChosenRowDataRow) { +// colId = pSchema->columns[chosen_itr].colId; +// offset = pSchema->columns[chosen_itr].offset; +// // TODO: use STSRowIter +// tdSTpRowGetVal(row, colId, pSchema->columns[chosen_itr].type, pSchema->flen, offset, chosen_itr - 1, &sVal); +// if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { +// rowKey = *(TSKEY*)sVal.val; +// if (rowKey != *lastRowKey) { +// mergeOption = 1; +// if (*lastRowKey != TSKEY_INITIAL_VAL) { +// ++(*curRow); +// } +// *lastRowKey = rowKey; +// ++nResult; +// } else if (update) { +// mergeOption = 2; +// } else { +// mergeOption = 0; +// break; +// } +// } +// } else { +// // TODO: use STSRowIter +// if (chosen_itr == 0) { +// colId = PRIMARYKEY_TIMESTAMP_COL_ID; +// tdSKvRowGetVal(row, PRIMARYKEY_TIMESTAMP_COL_ID, -1, -1, &sVal); +// rowKey = *(TSKEY*)sVal.val; +// if (rowKey != *lastRowKey) { +// mergeOption = 1; +// if (*lastRowKey != TSKEY_INITIAL_VAL) { +// ++(*curRow); +// } +// *lastRowKey = rowKey; +// ++nResult; +// } else if (update) { +// mergeOption = 2; +// } else { +// mergeOption = 0; +// break; +// } +// } else { +// SKvRowIdx* pColIdx = tdKvRowColIdxAt(row, chosen_itr - 1); +// colId = pColIdx->colId; +// offset = pColIdx->offset; +// tdSKvRowGetVal(row, colId, offset, chosen_itr - 1, &sVal); +// } +// } + +// ASSERT(rowKey != TSKEY_INITIAL_VAL); + +// if (colId == pColInfo->info.colId) { +// if (tdValTypeIsNorm(sVal.valType)) { +// colDataAppend(pColInfo, *curRow, sVal.val, false); +// } else if (tdValTypeIsNull(sVal.valType)) { +// colDataAppend(pColInfo, *curRow, NULL, true); +// } else if (tdValTypeIsNone(sVal.valType)) { +// // TODO: Set null if nothing append for this row +// if (mergeOption == 1) { +// colDataAppend(pColInfo, *curRow, NULL, true); +// } +// } else { +// ASSERT(0); +// } + +// ++i; + +// if (row == row1) { +// ++j; +// } else { +// ++k; +// } +// } else { +// if (mergeOption == 1) { +// colDataAppend(pColInfo, *curRow, NULL, true); +// } +// ++i; +// } +// } + +// if (mergeOption == 1) { +// while (i < numOfCols) { // the remain columns are all null data +// SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); +// colDataAppend(pColInfo, *curRow, NULL, true); +// ++i; +// } +// } + +// return nResult; +// #endif +// } + +// static void doCheckGeneratedBlockRange(STsdbReader* pTsdbReadHandle) { +// SQueryFilePos* cur = &pTsdbReadHandle->cur; + +// if (cur->rows > 0) { +// if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { +// assert(cur->win.skey >= pTsdbReadHandle->window.skey && cur->win.ekey <= pTsdbReadHandle->window.ekey); +// } else { +// assert(cur->win.skey >= pTsdbReadHandle->window.ekey && cur->win.ekey <= pTsdbReadHandle->window.skey); +// } + +// SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, 0); +// assert(cur->win.skey == ((TSKEY*)pColInfoData->pData)[0] && +// cur->win.ekey == ((TSKEY*)pColInfoData->pData)[cur->rows - 1]); +// } else { +// cur->win = pTsdbReadHandle->window; + +// int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; +// cur->lastKey = pTsdbReadHandle->window.ekey + step; +// } +// } + +// static void copyAllRemainRowsFromFileBlock(STsdbReader* pTsdbReadHandle, STableBlockScanInfo* pCheckInfo, +// SDataBlockInfo* pBlockInfo, int32_t endPos) { +// SQueryFilePos* cur = &pTsdbReadHandle->cur; + +// SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; +// TSKEY* tsArray = pCols->cols[0].pData; + +// bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + +// int32_t step = ascScan ? 1 : -1; + +// int32_t start = cur->pos; +// int32_t end = endPos; + +// if (!ascScan) { +// TSWAP(start, end); +// } + +// assert(pTsdbReadHandle->outputCapacity >= (end - start + 1)); +// int32_t numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, start, end); + +// // the time window should always be ascending order: skey <= ekey +// cur->win = (STimeWindow){.skey = tsArray[start], .ekey = tsArray[end]}; +// cur->mixBlock = (numOfRows != pBlockInfo->rows); +// cur->lastKey = tsArray[endPos] + step; +// cur->blockCompleted = (ascScan ? (endPos == pBlockInfo->rows - 1) : (endPos == 0)); + +// // The value of pos may be -1 or pBlockInfo->rows, and it is invalid in both cases. +// int32_t pos = endPos + step; +// updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); +// doCheckGeneratedBlockRange(pTsdbReadHandle); + +// tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", +// pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, +// pTsdbReadHandle->idStr); +// } + +// // only return the qualified data to client in terms of query time window, data rows in the same block but do not +// // be included in the query time window will be discarded +// static void doMergeTwoLevelData(STsdbReader* pTsdbReadHandle, STableBlockScanInfo* pCheckInfo, SBlock* pBlock) { +// SQueryFilePos* cur = &pTsdbReadHandle->cur; +// SDataBlockInfo blockInfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); +// STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); + +// initTableMemIterator(pTsdbReadHandle, pCheckInfo); + +// SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; +// assert(pCols->cols[0].type == TSDB_DATA_TYPE_TIMESTAMP && pCols->cols[0].colId == PRIMARYKEY_TIMESTAMP_COL_ID && +// cur->pos >= 0 && cur->pos < pBlock->numOfRows); +// // Even Multi-Version supported, the records with duplicated TSKEY would be merged inside of tsdbLoadData +// interface. TSKEY* tsArray = pCols->cols[0].pData; assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == +// pBlock->minKey.ts && +// tsArray[pBlock->numOfRows - 1] == pBlock->maxKey.ts); + +// bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); +// int32_t step = ascScan ? 1 : -1; + +// // for search the endPos, so the order needs to reverse +// int32_t order = ascScan ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; + +// int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); +// int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &blockInfo); + +// STimeWindow* pWin = &blockInfo.window; +// tsdbDebug("%p uid:%" PRIu64 " start merge data block, file block range:%" PRIu64 "-%" PRIu64 +// " rows:%d, start:%d, end:%d, %s", +// pTsdbReadHandle, pCheckInfo->tableId, pWin->skey, pWin->ekey, blockInfo.rows, cur->pos, endPos, +// pTsdbReadHandle->idStr); + +// // compared with the data from in-memory buffer, to generate the correct timestamp array list +// int32_t numOfRows = 0; +// int32_t curRow = 0; + +// int16_t rv1 = -1; +// int16_t rv2 = -1; +// STSchema* pSchema1 = NULL; +// STSchema* pSchema2 = NULL; + +// int32_t pos = cur->pos; +// cur->win = TSWINDOW_INITIALIZER; +// bool adjustPos = false; + +// // no data in buffer, load data from file directly +// if (pCheckInfo->iiter == NULL && pCheckInfo->iter == NULL) { +// copyAllRemainRowsFromFileBlock(pTsdbReadHandle, pCheckInfo, &blockInfo, endPos); +// return; +// } else if (pCheckInfo->iter != NULL || pCheckInfo->iiter != NULL) { +// SSkipListNode* node = NULL; +// TSKEY lastKeyAppend = TSKEY_INITIAL_VAL; + +// do { +// STSRow* row2 = NULL; +// STSRow* row1 = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, &row2, TD_VER_MAX); +// if (row1 == NULL) { +// break; +// } + +// TSKEY key = TD_ROW_KEY(row1); +// if ((key > pTsdbReadHandle->window.ekey && ascScan) || (key < pTsdbReadHandle->window.ekey && !ascScan)) { +// break; +// } + +// if (adjustPos) { +// if (key == lastKeyAppend) { +// pos -= step; +// } +// adjustPos = false; +// } + +// if (((pos > endPos || tsArray[pos] > pTsdbReadHandle->window.ekey) && ascScan) || +// ((pos < endPos || tsArray[pos] < pTsdbReadHandle->window.ekey) && !ascScan)) { +// break; +// } + +// if ((key < tsArray[pos] && ascScan) || (key > tsArray[pos] && !ascScan)) { +// if (rv1 != TD_ROW_SVER(row1)) { +// // pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); +// rv1 = TD_ROW_SVER(row1); +// } +// if (row2 && rv2 != TD_ROW_SVER(row2)) { +// // pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); +// rv2 = TD_ROW_SVER(row2); +// } + +// numOfRows += +// mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols, +// pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend); +// if (cur->win.skey == TSKEY_INITIAL_VAL) { +// cur->win.skey = key; +// } + +// cur->win.ekey = key; +// cur->lastKey = key + step; +// cur->mixBlock = true; +// moveToNextRowInMem(pCheckInfo); +// } else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it +// if (TD_SUPPORT_UPDATE(pCfg->update)) { +// if (lastKeyAppend != key) { +// if (lastKeyAppend != TSKEY_INITIAL_VAL) { +// ++curRow; +// } +// lastKeyAppend = key; +// } +// // load data from file firstly +// numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos); + +// if (rv1 != TD_ROW_SVER(row1)) { +// rv1 = TD_ROW_SVER(row1); +// } +// if (row2 && rv2 != TD_ROW_SVER(row2)) { +// rv2 = TD_ROW_SVER(row2); +// } + +// // still assign data into current row +// numOfRows += +// mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols, +// pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend); + +// if (cur->win.skey == TSKEY_INITIAL_VAL) { +// cur->win.skey = key; +// } + +// cur->win.ekey = key; +// cur->lastKey = key + step; +// cur->mixBlock = true; + +// moveToNextRowInMem(pCheckInfo); + +// pos += step; +// adjustPos = true; +// } else { +// // discard the memory record +// moveToNextRowInMem(pCheckInfo); +// } +// } else if ((key > tsArray[pos] && ascScan) || (key < tsArray[pos] && !ascScan)) { +// if (cur->win.skey == TSKEY_INITIAL_VAL) { +// cur->win.skey = tsArray[pos]; +// } + +// int32_t end = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, key, order); +// assert(end != -1); + +// if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it +// #if 0 +// if (pCfg->update == TD_ROW_DISCARD_UPDATE) { +// moveToNextRowInMem(pCheckInfo); +// } else { +// end -= step; +// } +// #endif +// if (!TD_SUPPORT_UPDATE(pCfg->update)) { +// moveToNextRowInMem(pCheckInfo); +// } else { +// end -= step; +// } +// } + +// int32_t qstart = 0, qend = 0; +// getQualifiedRowsPos(pTsdbReadHandle, pos, end, numOfRows, &qstart, &qend); + +// if ((lastKeyAppend != TSKEY_INITIAL_VAL) && (lastKeyAppend != (ascScan ? tsArray[qstart] : tsArray[qend]))) { +// ++curRow; +// } + +// numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, qstart, qend); +// pos += (qend - qstart + 1) * step; +// if (numOfRows > 0) { +// curRow = numOfRows - 1; +// } + +// cur->win.ekey = ascScan ? tsArray[qend] : tsArray[qstart]; +// cur->lastKey = cur->win.ekey + step; +// lastKeyAppend = cur->win.ekey; +// } +// } while (numOfRows < pTsdbReadHandle->outputCapacity); + +// if (numOfRows < pTsdbReadHandle->outputCapacity) { +// /** +// * if cache is empty, load remain file block data. In contrast, if there are remain data in cache, do NOT +// * copy them all to result buffer, since it may be overlapped with file data block. +// */ +// if (node == NULL || ((TD_ROW_KEY((STSRow*)SL_GET_NODE_DATA(node)) > pTsdbReadHandle->window.ekey) && ascScan) +// || +// ((TD_ROW_KEY((STSRow*)SL_GET_NODE_DATA(node)) < pTsdbReadHandle->window.ekey) && !ascScan)) { +// // no data in cache or data in cache is greater than the ekey of time window, load data from file block +// if (cur->win.skey == TSKEY_INITIAL_VAL) { +// cur->win.skey = tsArray[pos]; +// } + +// int32_t start = -1, end = -1; +// getQualifiedRowsPos(pTsdbReadHandle, pos, endPos, numOfRows, &start, &end); + +// numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, start, end); +// pos += (end - start + 1) * step; + +// cur->win.ekey = ascScan ? tsArray[end] : tsArray[start]; +// cur->lastKey = cur->win.ekey + step; +// cur->mixBlock = true; +// } +// } +// } + +// cur->blockCompleted = (((pos > endPos || cur->lastKey > pTsdbReadHandle->window.ekey) && ascScan) || +// ((pos < endPos || cur->lastKey < pTsdbReadHandle->window.ekey) && !ascScan)); + +// if (!ascScan) { +// TSWAP(cur->win.skey, cur->win.ekey); +// } + +// updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); +// doCheckGeneratedBlockRange(pTsdbReadHandle); + +// tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", +// pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, +// pTsdbReadHandle->idStr); +// } + +// int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { +// int firstPos, lastPos, midPos = -1; +// int numOfRows; +// TSKEY* keyList; + +// if (num <= 0) return -1; + +// keyList = (TSKEY*)pValue; +// firstPos = 0; +// lastPos = num - 1; + +// if (order == TSDB_ORDER_DESC) { +// // find the first position which is smaller than the key +// while (1) { +// if (key >= keyList[lastPos]) return lastPos; +// if (key == keyList[firstPos]) return firstPos; +// if (key < keyList[firstPos]) return firstPos - 1; + +// numOfRows = lastPos - firstPos + 1; +// midPos = (numOfRows >> 1) + firstPos; + +// if (key < keyList[midPos]) { +// lastPos = midPos - 1; +// } else if (key > keyList[midPos]) { +// firstPos = midPos + 1; +// } else { +// break; +// } +// } + +// } else { +// // find the first position which is bigger than the key +// while (1) { +// if (key <= keyList[firstPos]) return firstPos; +// if (key == keyList[lastPos]) return lastPos; + +// if (key > keyList[lastPos]) { +// lastPos = lastPos + 1; +// if (lastPos >= num) +// return -1; +// else +// return lastPos; +// } + +// numOfRows = lastPos - firstPos + 1; +// midPos = (numOfRows >> 1) + firstPos; + +// if (key < keyList[midPos]) { +// lastPos = midPos - 1; +// } else if (key > keyList[midPos]) { +// firstPos = midPos + 1; +// } else { +// break; +// } +// } +// } + +// return midPos; +// } + +static void cleanupBlockOrderSupporter(SBlockOrderSupporter* pSup) { + taosMemoryFreeClear(pSup->numOfBlocksPerTable); + taosMemoryFreeClear(pSup->indexPerTable); + + for (int32_t i = 0; i < pSup->numOfTables; ++i) { + SBlockOrderWrapper* pBlockInfo = pSup->pDataBlockInfo[i]; + taosMemoryFreeClear(pBlockInfo); } - return hasNext; + taosMemoryFreeClear(pSup->pDataBlockInfo); } -static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { - STsdbCfg* pCfg = REPO_CFG(pHandle->pTsdb); - size_t size = taosArrayGetSize(pHandle->pTableCheckInfo); - assert(pHandle->activeIndex < size && pHandle->activeIndex >= 0 && size >= 1); - pHandle->cur.fid = INT32_MIN; +static int32_t initBlockOrderSupporter(SBlockOrderSupporter* pSup, int32_t numOfTables) { + ASSERT(numOfTables >= 1); - STableCheckInfo* pCheckInfo = taosArrayGet(pHandle->pTableCheckInfo, pHandle->activeIndex); - if (!pCheckInfo->initBuf) { - initTableMemIterator(pHandle, pCheckInfo); - } + pSup->numOfBlocksPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); + pSup->indexPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); + pSup->pDataBlockInfo = taosMemoryCalloc(1, POINTER_BYTES * numOfTables); - STSRow* row = getSRowInTableMem(pCheckInfo, pHandle->order, pCfg->update, NULL, TD_VER_MAX); - if (row == NULL) { - return false; + if (pSup->numOfBlocksPerTable == NULL || pSup->indexPerTable == NULL || pSup->pDataBlockInfo == NULL) { + cleanupBlockOrderSupporter(pSup); + return TSDB_CODE_OUT_OF_MEMORY; } - pCheckInfo->lastKey = TD_ROW_KEY(row); // first timestamp in buffer - tsdbDebug("%p uid:%" PRId64 ", check data in buffer from skey:%" PRId64 ", order:%d, %s", pHandle, - pCheckInfo->tableId, pCheckInfo->lastKey, pHandle->order, pHandle->idStr); + return TSDB_CODE_SUCCESS; +} - // all data in mem are checked already. - if ((pCheckInfo->lastKey > pHandle->window.ekey && ASCENDING_TRAVERSE(pHandle->order)) || - (pCheckInfo->lastKey < pHandle->window.ekey && !ASCENDING_TRAVERSE(pHandle->order))) { - return false; - } +static int32_t fileDataBlockOrderCompar(const void* pLeft, const void* pRight, void* param) { + int32_t leftIndex = *(int32_t*)pLeft; + int32_t rightIndex = *(int32_t*)pRight; - int32_t step = ASCENDING_TRAVERSE(pHandle->order) ? 1 : -1; - STimeWindow* win = &pHandle->cur.win; - pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey, pHandle->outputCapacity, win, pHandle); + SBlockOrderSupporter* pSupporter = (SBlockOrderSupporter*)param; - // update the last key value - pCheckInfo->lastKey = win->ekey + step; - pHandle->cur.lastKey = win->ekey + step; - pHandle->cur.mixBlock = true; + int32_t leftTableBlockIndex = pSupporter->indexPerTable[leftIndex]; + int32_t rightTableBlockIndex = pSupporter->indexPerTable[rightIndex]; - if (!ASCENDING_TRAVERSE(pHandle->order)) { - TSWAP(win->skey, win->ekey); + if (leftTableBlockIndex > pSupporter->numOfBlocksPerTable[leftIndex]) { + /* left block is empty */ + return 1; + } else if (rightTableBlockIndex > pSupporter->numOfBlocksPerTable[rightIndex]) { + /* right block is empty */ + return -1; } - return true; -} - -static int32_t getFileIdFromKey(TSKEY key, int32_t daysPerFile, int32_t precision) { - assert(precision >= TSDB_TIME_PRECISION_MICRO || precision <= TSDB_TIME_PRECISION_NANO); - if (key == TSKEY_INITIAL_VAL) { - return INT32_MIN; - } + SBlockOrderWrapper* pLeftBlock = &pSupporter->pDataBlockInfo[leftIndex][leftTableBlockIndex]; + SBlockOrderWrapper* pRightBlock = &pSupporter->pDataBlockInfo[rightIndex][rightTableBlockIndex]; - if (key < 0) { - key -= (daysPerFile * tsTickPerMin[precision]); - } + return pLeftBlock->pBlock->aSubBlock[0].offset > pRightBlock->pBlock->aSubBlock[0].offset ? 1 : -1; +} - int64_t fid = (int64_t)(key / (daysPerFile * tsTickPerMin[precision])); // set the starting fileId - if (fid < 0LL && llabs(fid) > INT32_MAX) { // data value overflow for INT32 - fid = INT32_MIN; - } +static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks) { + bool asc = ASCENDING_TRAVERSE(pReader->order); - if (fid > 0LL && fid > INT32_MAX) { - fid = INT32_MAX; - } + pBlockIter->numOfBlocks = numOfBlocks; + taosArrayClear(pBlockIter->blockList); - return (int32_t)fid; -} + // access data blocks according to the offset of each block in asc/desc order. + int32_t numOfTables = (int32_t)taosHashGetSize(pReader->status.pTableMap); -static int32_t binarySearchForBlock(SBlock* pBlock, int32_t numOfBlocks, TSKEY skey, int32_t order) { - int32_t firstSlot = 0; - int32_t lastSlot = numOfBlocks - 1; + SBlockOrderSupporter sup = {0}; - int32_t midSlot = firstSlot; + int32_t code = initBlockOrderSupporter(&sup, numOfTables); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + int32_t cnt = 0; + void* ptr = NULL; while (1) { - numOfBlocks = lastSlot - firstSlot + 1; - midSlot = (firstSlot + (numOfBlocks >> 1)); - - if (numOfBlocks == 1) break; - - if (skey > pBlock[midSlot].maxKey.ts) { - if (numOfBlocks == 2) break; - if ((order == TSDB_ORDER_DESC) && (skey < pBlock[midSlot + 1].minKey.ts)) break; - firstSlot = midSlot + 1; - } else if (skey < pBlock[midSlot].minKey.ts) { - if ((order == TSDB_ORDER_ASC) && (skey > pBlock[midSlot - 1].maxKey.ts)) break; - lastSlot = midSlot - 1; - } else { - break; // got the slot + ptr = taosHashIterate(pReader->status.pTableMap, ptr); + if (ptr == NULL) { + break; } - } - return midSlot; -} - -static int32_t loadBlockInfo(STsdbReadHandle* pTsdbReadHandle, int32_t index, int32_t* numOfBlocks) { - int32_t code = 0; + STableBlockScanInfo* pTableScanInfo = (STableBlockScanInfo*)ptr; + if (pTableScanInfo->pBlockList == NULL || taosArrayGetSize(pTableScanInfo->pBlockList) == 0) { + continue; + } - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, index); - pCheckInfo->numOfBlocks = 0; + size_t num = taosArrayGetSize(pTableScanInfo->pBlockList); + sup.numOfBlocksPerTable[sup.numOfTables] = num; - STable table = {.uid = pCheckInfo->tableId, .suid = pCheckInfo->suid}; - table.pSchema = pTsdbReadHandle->pSchema; + char* buf = taosMemoryMalloc(sizeof(SBlockOrderWrapper) * num); + if (buf == NULL) { + cleanupBlockOrderSupporter(&sup); + return TSDB_CODE_TDB_OUT_OF_MEMORY; + } - if (tsdbSetReadTable(&pTsdbReadHandle->rhelper, &table) != TSDB_CODE_SUCCESS) { - code = terrno; - return code; - } + sup.pDataBlockInfo[sup.numOfTables] = (SBlockOrderWrapper*)buf; + for (int32_t k = 0; k < num; ++k) { + SBlockOrderWrapper wrapper = {0}; + wrapper.pBlock = (SBlock*)taosArrayGet(pTableScanInfo->pBlockList, k); + wrapper.uid = pTableScanInfo->uid; - SBlockIdx* compIndex = pTsdbReadHandle->rhelper.pBlkIdx; + sup.pDataBlockInfo[sup.numOfTables][k] = wrapper; + cnt++; + } - // no data block in this file, try next file - if (compIndex == NULL || compIndex->uid != pCheckInfo->tableId) { - return 0; // no data blocks in the file belongs to pCheckInfo->pTable + sup.numOfTables += 1; } - if (pCheckInfo->compSize < (int32_t)compIndex->len) { - assert(compIndex->len > 0); + ASSERT(numOfBlocks == cnt); - char* t = taosMemoryRealloc(pCheckInfo->pCompInfo, compIndex->len); - if (t == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - code = TSDB_CODE_TDB_OUT_OF_MEMORY; - return code; + // since there is only one table qualified, blocks are not sorted + if (sup.numOfTables == 1) { + for (int32_t i = 0; i < numOfBlocks; ++i) { + SFileDataBlockInfo blockInfo = {.uid = sup.pDataBlockInfo[0][i].uid, .tbBlockIdx = i}; + taosArrayPush(pBlockIter->blockList, &blockInfo); } + tsdbDebug("%p create blocks info struct completed for one table, %d blocks not sorted %s", pReader, cnt, + pReader->idStr); - pCheckInfo->pCompInfo = (SBlockInfo*)t; - pCheckInfo->compSize = compIndex->len; + pBlockIter->index = asc ? 0 : (numOfBlocks - 1); + return TSDB_CODE_SUCCESS; } - if (tsdbLoadBlockInfo(&(pTsdbReadHandle->rhelper), (void*)(pCheckInfo->pCompInfo)) < 0) { - return terrno; - } - SBlockInfo* pCompInfo = pCheckInfo->pCompInfo; + tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pReader, cnt, sup.numOfTables, + pReader->idStr); - TSKEY s = TSKEY_INITIAL_VAL, e = TSKEY_INITIAL_VAL; + assert(cnt <= numOfBlocks && sup.numOfTables <= numOfTables); - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - assert(pCheckInfo->lastKey <= pTsdbReadHandle->window.ekey && - pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); - } else { - assert(pCheckInfo->lastKey >= pTsdbReadHandle->window.ekey && - pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); + SMultiwayMergeTreeInfo* pTree = NULL; + uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, fileDataBlockOrderCompar); + if (ret != TSDB_CODE_SUCCESS) { + cleanupBlockOrderSupporter(&sup); + return TSDB_CODE_TDB_OUT_OF_MEMORY; } - s = TMIN(pCheckInfo->lastKey, pTsdbReadHandle->window.ekey); - e = TMAX(pCheckInfo->lastKey, pTsdbReadHandle->window.ekey); + int32_t numOfTotal = 0; + while (numOfTotal < cnt) { + int32_t pos = tMergeTreeGetChosenIndex(pTree); + int32_t index = sup.indexPerTable[pos]++; - // discard the unqualified data block based on the query time window - int32_t start = binarySearchForBlock(pCompInfo->blocks, compIndex->numOfBlocks, s, TSDB_ORDER_ASC); - int32_t end = start; + SFileDataBlockInfo blockInfo = {.uid = sup.pDataBlockInfo[pos][index].uid, .tbBlockIdx = index}; + taosArrayPush(pBlockIter->blockList, &blockInfo); - if (s > pCompInfo->blocks[start].maxKey.ts) { - return 0; - } + // set data block index overflow, in order to disable the offset comparator + if (sup.indexPerTable[pos] >= sup.numOfBlocksPerTable[pos]) { + sup.indexPerTable[pos] = sup.numOfBlocksPerTable[pos] + 1; + } - // todo speedup the procedure of located end block - while (end < (int32_t)compIndex->numOfBlocks && (pCompInfo->blocks[end].minKey.ts <= e)) { - end += 1; + numOfTotal += 1; + tMergeTreeAdjust(pTree, tMergeTreeGetAdjustIndex(pTree)); } - pCheckInfo->numOfBlocks = (end - start); - - if (start > 0) { - memmove(pCompInfo->blocks, &pCompInfo->blocks[start], pCheckInfo->numOfBlocks * sizeof(SBlock)); - } + tsdbDebug("%p %d data blocks sort completed, %s", pReader, cnt, pReader->idStr); + cleanupBlockOrderSupporter(&sup); + taosMemoryFree(pTree); - (*numOfBlocks) += pCheckInfo->numOfBlocks; - return 0; + pBlockIter->index = asc ? 0 : (numOfBlocks - 1); + return TSDB_CODE_SUCCESS; } -static int32_t getFileCompInfo(STsdbReadHandle* pTsdbReadHandle, int32_t* numOfBlocks) { - // load all the comp offset value for all tables in this file - int32_t code = TSDB_CODE_SUCCESS; - *numOfBlocks = 0; - - pTsdbReadHandle->cost.headFileLoad += 1; - int64_t s = taosGetTimestampUs(); - - size_t numOfTables = 0; - if (pTsdbReadHandle->loadType == BLOCK_LOAD_TABLE_SEQ_ORDER) { - code = loadBlockInfo(pTsdbReadHandle, pTsdbReadHandle->activeIndex, numOfBlocks); - } else if (pTsdbReadHandle->loadType == BLOCK_LOAD_OFFSET_SEQ_ORDER) { - numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - - for (int32_t i = 0; i < numOfTables; ++i) { - code = loadBlockInfo(pTsdbReadHandle, i, numOfBlocks); - if (code != TSDB_CODE_SUCCESS) { - int64_t e = taosGetTimestampUs(); +static bool blockIteratorNext(SDataBlockIter* pBlockIter) { + bool asc = ASCENDING_TRAVERSE(pBlockIter->order); - pTsdbReadHandle->cost.headFileLoadTime += (e - s); - return code; - } - } - } else { - assert(0); + int32_t step = asc ? 1 : -1; + if ((pBlockIter->index >= pBlockIter->numOfBlocks - 1 && asc) || (pBlockIter->index <= 0 && (!asc))) { + return false; } - int64_t e = taosGetTimestampUs(); - pTsdbReadHandle->cost.headFileLoadTime += (e - s); - return code; + pBlockIter->index += step; + return true; } -static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, - int32_t slotIndex) { - int64_t st = taosGetTimestampUs(); - - int32_t code = tdInitDataCols(pTsdbReadHandle->pDataCols, pTsdbReadHandle->pSchema); - if (code != TSDB_CODE_SUCCESS) { - tsdbError("%p failed to malloc buf for pDataCols, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - goto _error; - } +/** + * This is an two rectangles overlap cases. + */ +static int32_t dataBlockPartiallyRequired(STimeWindow* pWindow, SVersionRange* pVerRange, SBlock* pBlock) { + return (pWindow->ekey < pBlock->maxKey.ts && pWindow->ekey >= pBlock->minKey.ts) || + (pWindow->skey > pBlock->minKey.ts && pWindow->skey <= pBlock->maxKey.ts) || + (pVerRange->minVer > pBlock->minVersion && pVerRange->minVer <= pBlock->maxVersion) || + (pVerRange->maxVer < pBlock->maxVersion && pVerRange->maxVer >= pBlock->minVersion); +} - code = tdInitDataCols(pTsdbReadHandle->rhelper.pDCols[0], pTsdbReadHandle->pSchema); - if (code != TSDB_CODE_SUCCESS) { - tsdbError("%p failed to malloc buf for rhelper.pDataCols[0], %s", pTsdbReadHandle, pTsdbReadHandle->idStr); - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - goto _error; - } +static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter) { + SFileDataBlockInfo* pFBlockInfo = taosArrayGet(pBlockIter->blockList, pBlockIter->index); + return pFBlockInfo; +} - code = tdInitDataCols(pTsdbReadHandle->rhelper.pDCols[1], pTsdbReadHandle->pSchema); - if (code != TSDB_CODE_SUCCESS) { - tsdbError("%p failed to malloc buf for rhelper.pDataCols[1], %s", pTsdbReadHandle, pTsdbReadHandle->idStr); - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - goto _error; +static SBlock* getNeighborBlockOfSameTable(SFileDataBlockInfo* pFBlockInfo, STableBlockScanInfo* pTableBlockScanInfo, + int32_t* nextIndex, int32_t order) { + bool asc = ASCENDING_TRAVERSE(order); + if (asc && pFBlockInfo->tbBlockIdx >= taosArrayGetSize(pTableBlockScanInfo->pBlockList) - 1) { + return NULL; } - int16_t* colIds = pTsdbReadHandle->suppInfo.defaultLoadColumn->pData; - - int32_t ret = tsdbLoadBlockDataCols(&(pTsdbReadHandle->rhelper), pBlock, pCheckInfo->pCompInfo, colIds, - (int)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)), true); - if (ret != TSDB_CODE_SUCCESS) { - int32_t c = terrno; - assert(c != TSDB_CODE_SUCCESS); - goto _error; + if (!asc && pFBlockInfo->tbBlockIdx == 0) { + return NULL; } - SDataBlockLoadInfo* pBlockLoadInfo = &pTsdbReadHandle->dataBlockLoadInfo; + int32_t step = asc ? 1 : -1; - pBlockLoadInfo->fileGroup = pTsdbReadHandle->pFileGroup; - pBlockLoadInfo->slot = pTsdbReadHandle->cur.slot; - pBlockLoadInfo->uid = pCheckInfo->tableId; + *nextIndex = pFBlockInfo->tbBlockIdx + step; + SBlock* pNext = taosArrayGet(pTableBlockScanInfo->pBlockList, *nextIndex); + return pNext; +} - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - assert(pCols->numOfRows != 0 && pCols->numOfRows <= pBlock->numOfRows); +static int32_t findFileBlockInfoIndex(SDataBlockIter* pBlockIter, SFileDataBlockInfo* pFBlockInfo) { + ASSERT(pBlockIter != NULL && pFBlockInfo != NULL); - pBlock->numOfRows = pCols->numOfRows; + int32_t step = ASCENDING_TRAVERSE(pBlockIter->order) ? 1 : -1; + int32_t index = pBlockIter->index; - // Convert from TKEY to TSKEY for primary timestamp column if current block has timestamp before 1970-01-01T00:00:00Z - if (pBlock->minKey.ts < 0 && colIds[0] == PRIMARYKEY_TIMESTAMP_COL_ID) { - int64_t* src = pCols->cols[0].pData; - for (int32_t i = 0; i < pBlock->numOfRows; ++i) { - src[i] = tdGetKey(src[i]); + while (index < pBlockIter->numOfBlocks && index >= 0) { + SFileDataBlockInfo* pFBlock = taosArrayGet(pBlockIter->blockList, index); + if (pFBlock->uid == pFBlockInfo->uid && pFBlock->tbBlockIdx == pFBlockInfo->tbBlockIdx) { + return index; } - } - - int64_t elapsedTime = (taosGetTimestampUs() - st); - pTsdbReadHandle->cost.blockLoadTime += elapsedTime; - - tsdbDebug("%p load file block into buffer, index:%d, brange:%" PRId64 "-%" PRId64 ", rows:%d, elapsed time:%" PRId64 - " us, %s", - pTsdbReadHandle, slotIndex, pBlock->minKey.ts, pBlock->maxKey.ts, pBlock->numOfRows, elapsedTime, - pTsdbReadHandle->idStr); - return TSDB_CODE_SUCCESS; -_error: - pBlock->numOfRows = 0; + index += step; + } - tsdbError("%p error occurs in loading file block, index:%d, brange:%" PRId64 "-%" PRId64 ", rows:%d, %s", - pTsdbReadHandle, slotIndex, pBlock->minKey.ts, pBlock->maxKey.ts, pBlock->numOfRows, - pTsdbReadHandle->idStr); - return terrno; + ASSERT(0); + return -1; } -static int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* pBlockInfo); -static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, - int32_t start, int32_t end); -static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle); -static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, - SDataBlockInfo* pBlockInfo, int32_t endPos); - -static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo) { - SQueryFilePos* cur = &pTsdbReadHandle->cur; - STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); - SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); - TSKEY key; - int32_t code = TSDB_CODE_SUCCESS; +static int32_t setFileBlockActiveInBlockIter(SDataBlockIter* pBlockIter, int32_t index, int32_t step) { + if (index < 0 || index >= pBlockIter->numOfBlocks) { + return -1; + } - /*bool hasData = */ initTableMemIterator(pTsdbReadHandle, pCheckInfo); - assert(cur->pos >= 0 && cur->pos <= binfo.rows); + SFileDataBlockInfo fblock = *(SFileDataBlockInfo*)taosArrayGet(pBlockIter->blockList, index); + pBlockIter->index += step; - key = extractFirstTraverseKey(pCheckInfo, pTsdbReadHandle->order, pCfg->update, TD_VER_MAX); + if (index != pBlockIter->index) { + taosArrayRemove(pBlockIter->blockList, index); + taosArrayInsert(pBlockIter->blockList, pBlockIter->index, &fblock); - if (key != TSKEY_INITIAL_VAL) { - tsdbDebug("%p key in mem:%" PRId64 ", %s", pTsdbReadHandle, key, pTsdbReadHandle->idStr); - } else { - tsdbDebug("%p no data in mem, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); + SFileDataBlockInfo* pBlockInfo = taosArrayGet(pBlockIter->blockList, pBlockIter->index); + ASSERT(pBlockInfo->uid == fblock.uid && pBlockInfo->tbBlockIdx == fblock.tbBlockIdx); } - bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + return TSDB_CODE_SUCCESS; +} - if ((ascScan && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || - (!ascScan && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) { - bool cacheDataInFileBlockHole = (ascScan && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) || - (!ascScan && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey)); - if (cacheDataInFileBlockHole) { - // do not load file block into buffer - int32_t step = ascScan ? 1 : -1; +static bool overlapWithNeighborBlock(SBlock* pBlock, SBlock* pNeighbor, int32_t order) { + // it is the last block in current file, no chance to overlap with neighbor blocks. + if (ASCENDING_TRAVERSE(order)) { + return pBlock->maxKey.ts == pNeighbor->minKey.ts; + } else { + return pBlock->minKey.ts == pNeighbor->maxKey.ts; + } +} - TSKEY maxKey = ascScan ? (binfo.window.skey - step) : (binfo.window.ekey - step); - cur->rows = - tsdbReadRowsFromCache(pCheckInfo, maxKey, pTsdbReadHandle->outputCapacity, &cur->win, pTsdbReadHandle); - pTsdbReadHandle->realNumOfRows = cur->rows; +static bool bufferDataInFileBlockGap(int32_t order, TSDBKEY key, SBlock* pBlock) { + bool ascScan = ASCENDING_TRAVERSE(order); - // update the last key value - pCheckInfo->lastKey = cur->win.ekey + step; + return (ascScan && (key.ts != TSKEY_INITIAL_VAL && key.ts <= pBlock->minKey.ts)) || + (!ascScan && (key.ts != TSKEY_INITIAL_VAL && key.ts >= pBlock->maxKey.ts)); +} - if (!ascScan) { - TSWAP(cur->win.skey, cur->win.ekey); - } +static bool keyOverlapFileBlock(TSDBKEY key, SBlock* pBlock, SVersionRange* pVerRange) { + return (key.ts >= pBlock->minKey.ts && key.ts <= pBlock->maxKey.ts) && (pBlock->maxVersion >= pVerRange->minVer) && + (pBlock->minVersion <= pVerRange->maxVer); +} - cur->mixBlock = true; - cur->blockCompleted = false; - return code; - } +// 1. the version of all rows should be less than the endVersion +// 2. current block should not overlap with next neighbor block +// 3. current timestamp should not be overlap with each other +// 4. output buffer should be large enough to hold all rows in current block +static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pFBlock, SBlock* pBlock, + STableBlockScanInfo* pScanInfo, TSDBKEY key) { + int32_t neighborIndex = 0; + SBlock* pNeighbor = getNeighborBlockOfSameTable(pFBlock, pScanInfo, &neighborIndex, pReader->order); - // return error, add test cases - if ((code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot)) != TSDB_CODE_SUCCESS) { - return code; - } + bool overlapWithNeighbor = false; + if (pNeighbor) { + overlapWithNeighbor = overlapWithNeighborBlock(pBlock, pNeighbor, pReader->order); + } - doMergeTwoLevelData(pTsdbReadHandle, pCheckInfo, pBlock); + bool hasDup = false; + if (pBlock->nSubBlock == 1) { + hasDup = pBlock->hasDup; } else { - /* - * no data in cache, only load data from file - * during the query processing, data in cache will not be checked anymore. - * Here the buffer is not enough, so only part of file block can be loaded into memory buffer - */ - int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &binfo); - - bool wholeBlockReturned = ((abs(cur->pos - endPos) + 1) == binfo.rows); - if (wholeBlockReturned) { - pTsdbReadHandle->realNumOfRows = binfo.rows; - - cur->rows = binfo.rows; - cur->win = binfo.window; - cur->mixBlock = false; - cur->blockCompleted = true; - - if (ascScan) { - cur->lastKey = binfo.window.ekey + 1; - cur->pos = binfo.rows; - } else { - cur->lastKey = binfo.window.skey - 1; - cur->pos = -1; - } - } else { // partially copy to dest buffer - // make sure to only load once - bool firstTimeExtract = ((cur->pos == 0 && ascScan) || (cur->pos == binfo.rows - 1 && (!ascScan))); - if (pTsdbReadHandle->outputCapacity < binfo.rows && firstTimeExtract) { - code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } - - copyAllRemainRowsFromFileBlock(pTsdbReadHandle, pCheckInfo, &binfo, endPos); - cur->mixBlock = true; - } - - if (pTsdbReadHandle->outputCapacity >= binfo.rows) { - ASSERT(cur->blockCompleted || cur->mixBlock); - } - - if (cur->rows == binfo.rows) { - tsdbDebug("%p whole file block qualified, brange:%" PRId64 "-%" PRId64 ", rows:%d, lastKey:%" PRId64 ", %s", - pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pTsdbReadHandle->idStr); - } else { - tsdbDebug("%p create data block from remain file block, brange:%" PRId64 "-%" PRId64 - ", rows:%d, total:%d, lastKey:%" PRId64 ", %s", - pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, binfo.rows, cur->lastKey, - pTsdbReadHandle->idStr); - } + hasDup = true; } - return code; + return (overlapWithNeighbor || hasDup || dataBlockPartiallyRequired(&pReader->window, &pReader->verRange, pBlock) || + keyOverlapFileBlock(key, pBlock, &pReader->verRange) || (pBlock->nRow > pReader->capacity)); } -static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); - -static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, - bool* exists) { - SQueryFilePos* cur = &pTsdbReadHandle->cur; - int32_t code = TSDB_CODE_SUCCESS; - bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); - - if (asc) { - // query ended in/started from current block - if (pTsdbReadHandle->window.ekey < pBlock->maxKey.ts || pCheckInfo->lastKey > pBlock->minKey.ts) { - if ((code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot)) != TSDB_CODE_SUCCESS) { - *exists = false; - return code; - } - - SDataCols* pTSCol = pTsdbReadHandle->rhelper.pDCols[0]; - assert(pTSCol->cols->type == TSDB_DATA_TYPE_TIMESTAMP && pTSCol->numOfRows == pBlock->numOfRows); +static int32_t buildDataBlockFromBuf(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, int64_t endKey) { + if (!(pBlockScanInfo->iiter.hasVal || pBlockScanInfo->iter.hasVal)) { + return TSDB_CODE_SUCCESS; + } - if (pCheckInfo->lastKey > pBlock->minKey.ts) { - cur->pos = - binarySearchForKey(pTSCol->cols[0].pData, pBlock->numOfRows, pCheckInfo->lastKey, pTsdbReadHandle->order); - } else { - cur->pos = 0; - } + SSDataBlock* pBlock = pReader->pResBlock; - assert(pCheckInfo->lastKey <= pBlock->maxKey.ts); - doMergeTwoLevelData(pTsdbReadHandle, pCheckInfo, pBlock); - } else { // the whole block is loaded in to buffer - cur->pos = asc ? 0 : (pBlock->numOfRows - 1); - code = handleDataMergeIfNeeded(pTsdbReadHandle, pBlock, pCheckInfo); - } - } else { // desc order, query ended in current block - if (pTsdbReadHandle->window.ekey > pBlock->minKey.ts || pCheckInfo->lastKey < pBlock->maxKey.ts) { - if ((code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot)) != TSDB_CODE_SUCCESS) { - *exists = false; - return code; - } + int64_t st = taosGetTimestampUs(); + int32_t code = buildDataBlockFromBufImpl(pBlockScanInfo, endKey, pReader->capacity, pReader); - SDataCols* pTsCol = pTsdbReadHandle->rhelper.pDCols[0]; - if (pCheckInfo->lastKey < pBlock->maxKey.ts) { - cur->pos = - binarySearchForKey(pTsCol->cols[0].pData, pBlock->numOfRows, pCheckInfo->lastKey, pTsdbReadHandle->order); - } else { - cur->pos = pBlock->numOfRows - 1; - } + blockDataUpdateTsWindow(pBlock, 0); + pBlock->info.uid = pBlockScanInfo->uid; - assert(pCheckInfo->lastKey >= pBlock->minKey.ts); - doMergeTwoLevelData(pTsdbReadHandle, pCheckInfo, pBlock); - } else { - cur->pos = asc ? 0 : (pBlock->numOfRows - 1); - code = handleDataMergeIfNeeded(pTsdbReadHandle, pBlock, pCheckInfo); - } - } + setComposedBlockFlag(pReader, true); - *exists = pTsdbReadHandle->realNumOfRows > 0; + int64_t elapsedTime = taosGetTimestampUs() - st; + tsdbDebug("%p build data block from cache completed, elapsed time:%" PRId64 + " us, numOfRows:%d, numOfCols:%d, brange: %" PRId64 " - %" PRId64 " %s", + pReader, elapsedTime, pBlock->info.rows, (int32_t)blockDataGetNumOfCols(pBlock), pBlock->info.window.skey, + pBlock->info.window.ekey, pReader->idStr); return code; } -static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) { - int firstPos, lastPos, midPos = -1; - int numOfRows; - TSKEY* keyList; - - assert(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC); +static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, TSDBROW* pRow, + STSRow* pTSRow, SIterInfo* pIter, int64_t key) { + SRowMerger merge = {0}; + SBlockData* pBlockData = &pReader->status.fileBlockData; + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - if (num <= 0) return -1; + TSDBKEY k = TSDBROW_KEY(pRow); + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); + SArray* pDelList = pBlockScanInfo->delSkyline; - keyList = (TSKEY*)pValue; - firstPos = 0; - lastPos = num - 1; + // ascending order traverse + if (ASCENDING_TRAVERSE(pReader->order)) { + if (key < k.ts) { + tRowMergerInit(&merge, &fRow, pReader->pSchema); - if (order == TSDB_ORDER_DESC) { - // find the first position which is smaller than the key - while (1) { - if (key >= keyList[lastPos]) return lastPos; - if (key == keyList[firstPos]) return firstPos; - if (key < keyList[firstPos]) return firstPos - 1; + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); + tRowMergerGetRow(&merge, &pTSRow); + } else if (k.ts < key) { // k.ts < key + doMergeMultiRows(pRow, pBlockScanInfo->uid, pIter, pDelList, &pTSRow, pReader); + } else { // k.ts == key, ascending order: file block ----> imem rows -----> mem rows + tRowMergerInit(&merge, &fRow, pReader->pSchema); + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); - numOfRows = lastPos - firstPos + 1; - midPos = (numOfRows >> 1) + firstPos; + tRowMerge(&merge, pRow); + doMergeRowsInBuf(pIter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); - if (key < keyList[midPos]) { - lastPos = midPos - 1; - } else if (key > keyList[midPos]) { - firstPos = midPos + 1; - } else { - break; - } + tRowMergerGetRow(&merge, &pTSRow); } + } else { // descending order scan + if (key < k.ts) { + doMergeMultiRows(pRow, pBlockScanInfo->uid, pIter, pDelList, &pTSRow, pReader); + } else if (k.ts < key) { + tRowMergerInit(&merge, &fRow, pReader->pSchema); - } else { - // find the first position which is bigger than the key - while (1) { - if (key <= keyList[firstPos]) return firstPos; - if (key == keyList[lastPos]) return lastPos; - - if (key > keyList[lastPos]) { - lastPos = lastPos + 1; - if (lastPos >= num) - return -1; - else - return lastPos; - } + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); + tRowMergerGetRow(&merge, &pTSRow); + } else { // descending order: mem rows -----> imem rows ------> file block + updateSchema(pRow, pBlockScanInfo->uid, pReader); - numOfRows = lastPos - firstPos + 1; - midPos = (numOfRows >> 1) + firstPos; + tRowMergerInit(&merge, pRow, pReader->pSchema); + doMergeRowsInBuf(pIter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); - if (key < keyList[midPos]) { - lastPos = midPos - 1; - } else if (key > keyList[midPos]) { - firstPos = midPos + 1; - } else { - break; - } + tRowMerge(&merge, &fRow); + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); + + tRowMergerGetRow(&merge, &pTSRow); } } - return midPos; + tRowMergerClear(&merge); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; } -static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, - int32_t start, int32_t end) { - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - TSKEY* tsArray = pCols->cols[0].pData; - - int32_t num = end - start + 1; - assert(num >= 0); +static int32_t doMergeThreeLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo) { + SRowMerger merge = {0}; + STSRow* pTSRow = NULL; - if (num == 0) { - return numOfRows; - } + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + SBlockData* pBlockData = &pReader->status.fileBlockData; + SArray* pDelList = pBlockScanInfo->delSkyline; - bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); - int32_t trueStart = ascScan ? start : end; - int32_t trueEnd = ascScan ? end : start; - int32_t step = ascScan ? 1 : -1; + TSDBROW* pRow = getValidRow(&pBlockScanInfo->iter, pDelList, pReader); + TSDBROW* piRow = getValidRow(&pBlockScanInfo->iiter, pDelList, pReader); + ASSERT(pRow != NULL && piRow != NULL); - int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pResBlock->pDataBlock); + int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex]; - // data in buffer has greater timestamp, copy data in file block - int32_t i = 0, j = 0; - while (i < requiredNumOfCols && j < pCols->numOfCols) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); + uint64_t uid = pBlockScanInfo->uid; - SDataCol* src = &pCols->cols[j]; - if (src->colId < pColInfo->info.colId) { - j++; - continue; - } + TSDBKEY k = TSDBROW_KEY(pRow); + TSDBKEY ik = TSDBROW_KEY(piRow); - if (!isAllRowsNull(src) && pColInfo->info.colId == src->colId) { - if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance - // memmove(pData, (char*)src->pData + bytes * start, bytes * num); - int32_t rowIndex = numOfRows; - for (int32_t k = trueStart; ((ascScan && k <= trueEnd) || (!ascScan && k >= trueEnd)); k += step, ++rowIndex) { - SCellVal sVal = {0}; - if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { - TASSERT(0); - } + if (ASCENDING_TRAVERSE(pReader->order)) { + // [1&2] key <= [k.ts && ik.ts] + if (key <= k.ts && key <= ik.ts) { + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); + tRowMergerInit(&merge, &fRow, pReader->pSchema); - if (sVal.valType == TD_VTYPE_NORM) { - colDataAppend(pColInfo, rowIndex, sVal.val, false); - } else { - colDataAppendNULL(pColInfo, rowIndex); - } - } - } else { // handle the var-string - int32_t rowIndex = numOfRows; - - // todo refactor, only copy one-by-one - for (int32_t k = trueStart; ((ascScan && k <= trueEnd) || (!ascScan && k >= trueEnd)); k += step, ++rowIndex) { - SCellVal sVal = {0}; - if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { - TASSERT(0); - } + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); - if (sVal.valType == TD_VTYPE_NORM) { - colDataAppend(pColInfo, rowIndex, sVal.val, false); - } else { - colDataAppendNULL(pColInfo, rowIndex); - } - } + if (ik.ts == key) { + tRowMerge(&merge, piRow); + doMergeRowsInBuf(&pBlockScanInfo->iiter, key, pBlockScanInfo->delSkyline, &merge, pReader); } - j++; - i++; - } else { // pColInfo->info.colId < src->colId, it is a NULL data - colDataAppendNNULL(pColInfo, numOfRows, num); - i++; - } - } - - while (i < requiredNumOfCols) { // the remain columns are all null data - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); - colDataAppendNNULL(pColInfo, numOfRows, num); - i++; - } - - pTsdbReadHandle->cur.win.ekey = tsArray[trueEnd]; - pTsdbReadHandle->cur.lastKey = tsArray[trueEnd] + step; - - return numOfRows + num; -} - -/** - * @brief // TODO fix bug for reverse copy data problem - * Note: row1 always has high priority - * - * @param pTsdbReadHandle - * @param capacity - * @param curRow - * @param row1 - * @param row2 - * @param numOfCols - * @param uid - * @param pSchema1 - * @param pSchema2 - * @param update - * @param lastRowKey - * @return int32_t The quantity of rows appended - */ -static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t* curRow, STSRow* row1, - STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2, - bool update, TSKEY* lastRowKey) { -#if 1 - STSchema* pSchema; - STSRow* row; - int16_t colId; - int16_t offset; - - bool isRow1DataRow = TD_IS_TP_ROW(row1); - bool isRow2DataRow; - bool isChosenRowDataRow; - int32_t chosen_itr; - SCellVal sVal = {0}; - TSKEY rowKey = TSKEY_INITIAL_VAL; - int32_t nResult = 0; - int32_t mergeOption = 0; // 0 discard 1 overwrite 2 merge - - // the schema version info is embeded in STSRow - int32_t numOfColsOfRow1 = 0; - - if (pSchema1 == NULL) { - pSchema1 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row1)); - } - -#ifdef TD_DEBUG_PRINT_ROW - char flags[70] = {0}; - STsdb* pTsdb = pTsdbReadHandle->rhelper.pRepo; - snprintf(flags, 70, "%s:%d vgId:%d dir:%s row1%s=NULL,row2%s=NULL", __func__, __LINE__, TD_VID(pTsdb->pVnode), - pTsdb->dir, row1 ? "!" : "", row2 ? "!" : ""); - tdSRowPrint(row1, pSchema1, flags); -#endif + if (k.ts == key) { + tRowMerge(&merge, pRow); + doMergeRowsInBuf(&pBlockScanInfo->iter, key, pBlockScanInfo->delSkyline, &merge, pReader); + } - if (isRow1DataRow) { - numOfColsOfRow1 = schemaNCols(pSchema1); - } else { - numOfColsOfRow1 = tdRowGetNCols(row1); - } + tRowMergerGetRow(&merge, &pTSRow); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; + } else { // key > ik.ts || key > k.ts + ASSERT(key != ik.ts); + + // [3] ik.ts < key <= k.ts + // [4] ik.ts < k.ts <= key + if (ik.ts < k.ts) { + doMergeMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, &pTSRow, pReader); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; + } - int32_t numOfColsOfRow2 = 0; - if (row2) { - isRow2DataRow = TD_IS_TP_ROW(row2); - if (pSchema2 == NULL) { - pSchema2 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row2)); - } - if (isRow2DataRow) { - numOfColsOfRow2 = schemaNCols(pSchema2); - } else { - numOfColsOfRow2 = tdRowGetNCols(row2); - } - } + // [5] k.ts < key <= ik.ts + // [6] k.ts < ik.ts <= key + if (k.ts < ik.ts) { + doMergeMultiRows(pRow, uid, &pBlockScanInfo->iter, pDelList, &pTSRow, pReader); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; + } - int32_t i = 0, j = 0, k = 0; - while (i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); + // [7] k.ts == ik.ts < key + if (k.ts == ik.ts) { + ASSERT(key > ik.ts && key > k.ts); - int32_t colIdOfRow1; - if (j >= numOfColsOfRow1) { - colIdOfRow1 = INT32_MAX; - } else if (isRow1DataRow) { - colIdOfRow1 = pSchema1->columns[j].colId; - } else { - colIdOfRow1 = tdKvRowColIdAt(row1, j); + doMergeMemIMemRows(pRow, piRow, pBlockScanInfo, pReader, &pTSRow); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; + } } + } else { // descending order scan + // [1/2] k.ts >= ik.ts && k.ts >= key + if (k.ts >= ik.ts && k.ts >= key) { + updateSchema(pRow, uid, pReader); - int32_t colIdOfRow2; - if (k >= numOfColsOfRow2) { - colIdOfRow2 = INT32_MAX; - } else if (isRow2DataRow) { - colIdOfRow2 = pSchema2->columns[k].colId; - } else { - colIdOfRow2 = tdKvRowColIdAt(row2, k); - } + tRowMergerInit(&merge, pRow, pReader->pSchema); + doMergeRowsInBuf(&pBlockScanInfo->iter, key, pBlockScanInfo->delSkyline, &merge, pReader); - if (colIdOfRow1 < colIdOfRow2) { // the most probability - if (colIdOfRow1 < pColInfo->info.colId) { - ++j; - continue; - } - row = row1; - pSchema = pSchema1; - isChosenRowDataRow = isRow1DataRow; - chosen_itr = j; - } else if (colIdOfRow1 == colIdOfRow2) { - if (colIdOfRow1 < pColInfo->info.colId) { - ++j; - ++k; - continue; + if (ik.ts == k.ts) { + tRowMerge(&merge, piRow); + doMergeRowsInBuf(&pBlockScanInfo->iiter, key, pBlockScanInfo->delSkyline, &merge, pReader); } - row = row1; - pSchema = pSchema1; - isChosenRowDataRow = isRow1DataRow; - chosen_itr = j; - } else { - if (colIdOfRow2 < pColInfo->info.colId) { - ++k; - continue; - } - row = row2; - pSchema = pSchema2; - chosen_itr = k; - isChosenRowDataRow = isRow2DataRow; - } - - if (isChosenRowDataRow) { - colId = pSchema->columns[chosen_itr].colId; - offset = pSchema->columns[chosen_itr].offset; - // TODO: use STSRowIter - tdSTpRowGetVal(row, colId, pSchema->columns[chosen_itr].type, pSchema->flen, offset, chosen_itr - 1, &sVal); - if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { - rowKey = *(TSKEY*)sVal.val; - if (rowKey != *lastRowKey) { - mergeOption = 1; - if (*lastRowKey != TSKEY_INITIAL_VAL) { - ++(*curRow); - } - *lastRowKey = rowKey; - ++nResult; - } else if (update) { - mergeOption = 2; - } else { - mergeOption = 0; - break; - } + + if (k.ts == key) { + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); + tRowMerge(&merge, &fRow); + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); } + + tRowMergerGetRow(&merge, &pTSRow); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; } else { - // TODO: use STSRowIter - if (chosen_itr == 0) { - colId = PRIMARYKEY_TIMESTAMP_COL_ID; - tdSKvRowGetVal(row, PRIMARYKEY_TIMESTAMP_COL_ID, -1, -1, &sVal); - rowKey = *(TSKEY*)sVal.val; - if (rowKey != *lastRowKey) { - mergeOption = 1; - if (*lastRowKey != TSKEY_INITIAL_VAL) { - ++(*curRow); - } - *lastRowKey = rowKey; - ++nResult; - } else if (update) { - mergeOption = 2; - } else { - mergeOption = 0; - break; - } - } else { - SKvRowIdx* pColIdx = tdKvRowColIdxAt(row, chosen_itr - 1); - colId = pColIdx->colId; - offset = pColIdx->offset; - tdSKvRowGetVal(row, colId, offset, chosen_itr - 1, &sVal); + ASSERT(ik.ts != k.ts); // this case has been included in the previous if branch + + // [3] ik.ts > k.ts >= Key + // [4] ik.ts > key >= k.ts + if (ik.ts > key) { + doMergeMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, &pTSRow, pReader); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; } - } - ASSERT(rowKey != TSKEY_INITIAL_VAL); + // [5] key > ik.ts > k.ts + // [6] key > k.ts > ik.ts + if (key > ik.ts) { + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); + tRowMergerInit(&merge, &fRow, pReader->pSchema); - if (colId == pColInfo->info.colId) { - if (tdValTypeIsNorm(sVal.valType)) { - colDataAppend(pColInfo, *curRow, sVal.val, false); - } else if (tdValTypeIsNull(sVal.valType)) { - colDataAppend(pColInfo, *curRow, NULL, true); - } else if (tdValTypeIsNone(sVal.valType)) { - // TODO: Set null if nothing append for this row - if (mergeOption == 1) { - colDataAppend(pColInfo, *curRow, NULL, true); - } - } else { - ASSERT(0); + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); + tRowMergerGetRow(&merge, &pTSRow); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; } - ++i; + //[7] key = ik.ts > k.ts + if (key == ik.ts) { + doMergeMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, &pTSRow, pReader); - if (row == row1) { - ++j; - } else { - ++k; + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); + tRowMerge(&merge, &fRow); + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); + tRowMergerGetRow(&merge, &pTSRow); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; } - } else { - if (mergeOption == 1) { - colDataAppend(pColInfo, *curRow, NULL, true); - } - ++i; - } - } - - if (mergeOption == 1) { - while (i < numOfCols) { // the remain columns are all null data - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); - colDataAppend(pColInfo, *curRow, NULL, true); - ++i; } } - return nResult; -#endif + ASSERT(0); } -static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startPos, int32_t endPos, - int32_t numOfExisted, int32_t* start, int32_t* end) { - *start = -1; - - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - int32_t remain = endPos - startPos + 1; - if (remain + numOfExisted > pTsdbReadHandle->outputCapacity) { - *end = (pTsdbReadHandle->outputCapacity - numOfExisted) + startPos - 1; - } else { - *end = endPos; - } - - *start = startPos; - } else { - int32_t remain = (startPos - endPos) + 1; - if (remain + numOfExisted > pTsdbReadHandle->outputCapacity) { - *end = startPos + 1 - (pTsdbReadHandle->outputCapacity - numOfExisted); - } else { - *end = endPos; - } - - *start = *end; - *end = startPos; +static bool isValidFileBlockRow(SBlockData* pBlockData, SFileBlockDumpInfo* pDumpInfo, + STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader) { + // check for version and time range + int64_t ver = pBlockData->aVersion[pDumpInfo->rowIndex]; + if (ver > pReader->verRange.maxVer || ver < pReader->verRange.minVer) { + return false; } -} - -static void updateInfoAfterMerge(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, int32_t numOfRows, - int32_t endPos) { - SQueryFilePos* cur = &pTsdbReadHandle->cur; - - pCheckInfo->lastKey = cur->lastKey; - pTsdbReadHandle->realNumOfRows = numOfRows; - cur->rows = numOfRows; - cur->pos = endPos; -} - -static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle) { - SQueryFilePos* cur = &pTsdbReadHandle->cur; - - if (cur->rows > 0) { - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - assert(cur->win.skey >= pTsdbReadHandle->window.skey && cur->win.ekey <= pTsdbReadHandle->window.ekey); - } else { - assert(cur->win.skey >= pTsdbReadHandle->window.ekey && cur->win.ekey <= pTsdbReadHandle->window.skey); - } - SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, 0); - assert(cur->win.skey == ((TSKEY*)pColInfoData->pData)[0] && - cur->win.ekey == ((TSKEY*)pColInfoData->pData)[cur->rows - 1]); - } else { - cur->win = pTsdbReadHandle->window; - - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; - cur->lastKey = pTsdbReadHandle->window.ekey + step; + int64_t ts = pBlockData->aTSKEY[pDumpInfo->rowIndex]; + if (ts > pReader->window.ekey || ts < pReader->window.skey) { + return false; } -} - -static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, - SDataBlockInfo* pBlockInfo, int32_t endPos) { - SQueryFilePos* cur = &pTsdbReadHandle->cur; - - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - TSKEY* tsArray = pCols->cols[0].pData; - - bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); - int32_t step = ascScan ? 1 : -1; - - int32_t start = cur->pos; - int32_t end = endPos; - - if (!ascScan) { - TSWAP(start, end); + TSDBKEY k = {.ts = ts, .version = ver}; + if (hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, &k)) { + return false; } - assert(pTsdbReadHandle->outputCapacity >= (end - start + 1)); - int32_t numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, start, end); - - // the time window should always be ascending order: skey <= ekey - cur->win = (STimeWindow){.skey = tsArray[start], .ekey = tsArray[end]}; - cur->mixBlock = (numOfRows != pBlockInfo->rows); - cur->lastKey = tsArray[endPos] + step; - cur->blockCompleted = (ascScan ? (endPos == pBlockInfo->rows - 1) : (endPos == 0)); + return true; +} - // The value of pos may be -1 or pBlockInfo->rows, and it is invalid in both cases. - int32_t pos = endPos + step; - updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); - doCheckGeneratedBlockRange(pTsdbReadHandle); +static bool outOfTimeWindow(int64_t ts, STimeWindow* pWindow) { return (ts > pWindow->ekey) || (ts < pWindow->skey); } - tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, - pTsdbReadHandle->idStr); -} +static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo) { + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + SBlockData* pBlockData = &pReader->status.fileBlockData; -int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* pBlockInfo) { - // NOTE: reverse the order to find the end position in data block - int32_t endPos = -1; - bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); - int32_t order = ascScan ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; + SRowMerger merge = {0}; + STSRow* pTSRow = NULL; - SQueryFilePos* cur = &pTsdbReadHandle->cur; - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; + int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex]; + TSDBROW* pRow = getValidRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader); + TSDBROW* piRow = getValidRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader); - if (pTsdbReadHandle->outputCapacity >= pBlockInfo->rows) { - if (ascScan && pTsdbReadHandle->window.ekey >= pBlockInfo->window.ekey) { - endPos = pBlockInfo->rows - 1; - cur->mixBlock = (cur->pos != 0); - } else if ((!ascScan) && pTsdbReadHandle->window.ekey <= pBlockInfo->window.skey) { - endPos = 0; - cur->mixBlock = (cur->pos != pBlockInfo->rows - 1); - } else { - assert(pCols->numOfRows > 0); - endPos = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pTsdbReadHandle->window.ekey, order); - cur->mixBlock = true; - } + if (pBlockScanInfo->iter.hasVal && pBlockScanInfo->iiter.hasVal) { + return doMergeThreeLevelRows(pReader, pBlockScanInfo); } else { - if (ascScan && pTsdbReadHandle->window.ekey >= pBlockInfo->window.ekey) { - endPos = TMIN(cur->pos + pTsdbReadHandle->outputCapacity - 1, pBlockInfo->rows - 1); - } else if ((!ascScan) && pTsdbReadHandle->window.ekey <= pBlockInfo->window.skey) { - endPos = TMAX(cur->pos - pTsdbReadHandle->outputCapacity + 1, 0); - } else { - ASSERT(pCols->numOfRows > 0); - endPos = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pTsdbReadHandle->window.ekey, order); - - // current data is more than the capacity - int32_t size = abs(cur->pos - endPos) + 1; - if (size > pTsdbReadHandle->outputCapacity) { - int32_t delta = size - pTsdbReadHandle->outputCapacity; - if (ascScan) { - endPos -= delta; - } else { - endPos += delta; - } - } + // imem + file + if (pBlockScanInfo->iiter.hasVal) { + return doMergeBufAndFileRows(pReader, pBlockScanInfo, piRow, pTSRow, &pBlockScanInfo->iiter, key); } - cur->mixBlock = true; - } - - return endPos; -} - -// only return the qualified data to client in terms of query time window, data rows in the same block but do not -// be included in the query time window will be discarded -static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock) { - SQueryFilePos* cur = &pTsdbReadHandle->cur; - SDataBlockInfo blockInfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); - STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); - - initTableMemIterator(pTsdbReadHandle, pCheckInfo); - - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - assert(pCols->cols[0].type == TSDB_DATA_TYPE_TIMESTAMP && pCols->cols[0].colId == PRIMARYKEY_TIMESTAMP_COL_ID && - cur->pos >= 0 && cur->pos < pBlock->numOfRows); - // Even Multi-Version supported, the records with duplicated TSKEY would be merged inside of tsdbLoadData interface. - TSKEY* tsArray = pCols->cols[0].pData; - assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == pBlock->minKey.ts && - tsArray[pBlock->numOfRows - 1] == pBlock->maxKey.ts); - - bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); - int32_t step = ascScan ? 1 : -1; - - // for search the endPos, so the order needs to reverse - int32_t order = ascScan ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; - - int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); - int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &blockInfo); - - STimeWindow* pWin = &blockInfo.window; - tsdbDebug("%p uid:%" PRIu64 " start merge data block, file block range:%" PRIu64 "-%" PRIu64 - " rows:%d, start:%d, end:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, pWin->skey, pWin->ekey, blockInfo.rows, cur->pos, endPos, - pTsdbReadHandle->idStr); - - // compared with the data from in-memory buffer, to generate the correct timestamp array list - int32_t numOfRows = 0; - int32_t curRow = 0; - - int16_t rv1 = -1; - int16_t rv2 = -1; - STSchema* pSchema1 = NULL; - STSchema* pSchema2 = NULL; - - int32_t pos = cur->pos; - cur->win = TSWINDOW_INITIALIZER; - bool adjustPos = false; - - // no data in buffer, load data from file directly - if (pCheckInfo->iiter == NULL && pCheckInfo->iter == NULL) { - copyAllRemainRowsFromFileBlock(pTsdbReadHandle, pCheckInfo, &blockInfo, endPos); - return; - } else if (pCheckInfo->iter != NULL || pCheckInfo->iiter != NULL) { - SSkipListNode* node = NULL; - TSKEY lastKeyAppend = TSKEY_INITIAL_VAL; - - do { - STSRow* row2 = NULL; - STSRow* row1 = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, &row2, TD_VER_MAX); - if (row1 == NULL) { - break; - } - - TSKEY key = TD_ROW_KEY(row1); - if ((key > pTsdbReadHandle->window.ekey && ascScan) || (key < pTsdbReadHandle->window.ekey && !ascScan)) { - break; - } - - if (adjustPos) { - if (key == lastKeyAppend) { - pos -= step; - } - adjustPos = false; - } - - if (((pos > endPos || tsArray[pos] > pTsdbReadHandle->window.ekey) && ascScan) || - ((pos < endPos || tsArray[pos] < pTsdbReadHandle->window.ekey) && !ascScan)) { - break; - } - - if ((key < tsArray[pos] && ascScan) || (key > tsArray[pos] && !ascScan)) { - if (rv1 != TD_ROW_SVER(row1)) { - // pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); - rv1 = TD_ROW_SVER(row1); - } - if (row2 && rv2 != TD_ROW_SVER(row2)) { - // pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); - rv2 = TD_ROW_SVER(row2); - } - - numOfRows += - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols, - pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend); - if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = key; - } - - cur->win.ekey = key; - cur->lastKey = key + step; - cur->mixBlock = true; - moveToNextRowInMem(pCheckInfo); - } else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it -#if 0 - if (pCfg->update) { - if (pCfg->update == TD_ROW_PARTIAL_UPDATE) { - doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, pos, pos); - } - if (rv1 != TD_ROW_SVER(row1)) { - // pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); - rv1 = TD_ROW_SVER(row1); - } - if (row2 && rv2 != TD_ROW_SVER(row2)) { - // pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); - rv2 = TD_ROW_SVER(row2); - } - - bool forceSetNull = pCfg->update != TD_ROW_PARTIAL_UPDATE; - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, - pCheckInfo->tableId, pSchema1, pSchema2, forceSetNull, &lastRowKey); - numOfRows += 1; - if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = key; - } - - cur->win.ekey = key; - cur->lastKey = key + step; - cur->mixBlock = true; - moveToNextRowInMem(pCheckInfo); - pos += step; - } else { - moveToNextRowInMem(pCheckInfo); - } -#endif - if (TD_SUPPORT_UPDATE(pCfg->update)) { - if (lastKeyAppend != key) { - if (lastKeyAppend != TSKEY_INITIAL_VAL) { - ++curRow; - } - lastKeyAppend = key; - } - // load data from file firstly - numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos); - - if (rv1 != TD_ROW_SVER(row1)) { - rv1 = TD_ROW_SVER(row1); - } - if (row2 && rv2 != TD_ROW_SVER(row2)) { - rv2 = TD_ROW_SVER(row2); - } - - // still assign data into current row - numOfRows += - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols, - pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend); - - if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = key; - } - - cur->win.ekey = key; - cur->lastKey = key + step; - cur->mixBlock = true; + // mem + file + if (pBlockScanInfo->iter.hasVal) { + return doMergeBufAndFileRows(pReader, pBlockScanInfo, pRow, pTSRow, &pBlockScanInfo->iter, key); + } - moveToNextRowInMem(pCheckInfo); + // imem & mem are all empty, only file exist + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); + tRowMergerInit(&merge, &fRow, pReader->pSchema); + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); + tRowMergerGetRow(&merge, &pTSRow); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); - pos += step; - adjustPos = true; - } else { - // discard the memory record - moveToNextRowInMem(pCheckInfo); - } - } else if ((key > tsArray[pos] && ascScan) || (key < tsArray[pos] && !ascScan)) { - if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = tsArray[pos]; - } + return TSDB_CODE_SUCCESS; + } +} - int32_t end = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, key, order); - assert(end != -1); +static int32_t buildComposedDataBlock(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo) { + SSDataBlock* pResBlock = pReader->pResBlock; - if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it -#if 0 - if (pCfg->update == TD_ROW_DISCARD_UPDATE) { - moveToNextRowInMem(pCheckInfo); - } else { - end -= step; - } -#endif - if (!TD_SUPPORT_UPDATE(pCfg->update)) { - moveToNextRowInMem(pCheckInfo); - } else { - end -= step; - } - } + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + SBlockData* pBlockData = &pReader->status.fileBlockData; + int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1; - int32_t qstart = 0, qend = 0; - getQualifiedRowsPos(pTsdbReadHandle, pos, end, numOfRows, &qstart, &qend); + while (1) { + // todo check the validate of row in file block + { + if (!isValidFileBlockRow(pBlockData, pDumpInfo, pBlockScanInfo, pReader)) { + pDumpInfo->rowIndex += step; - if ((lastKeyAppend != TSKEY_INITIAL_VAL) && (lastKeyAppend != (ascScan ? tsArray[qstart] : tsArray[qend]))) { - ++curRow; - } + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pReader->status.blockIter); + SBlock* pBlock = taosArrayGet(pBlockScanInfo->pBlockList, pFBlock->tbBlockIdx); - numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, qstart, qend); - pos += (qend - qstart + 1) * step; - if (numOfRows > 0) { - curRow = numOfRows - 1; + if (pDumpInfo->rowIndex >= pBlock->nRow || pDumpInfo->rowIndex < 0) { + setBlockAllDumped(pDumpInfo, pBlock, pReader->order); + break; } - cur->win.ekey = ascScan ? tsArray[qend] : tsArray[qstart]; - cur->lastKey = cur->win.ekey + step; - lastKeyAppend = cur->win.ekey; + continue; } - } while (numOfRows < pTsdbReadHandle->outputCapacity); - - if (numOfRows < pTsdbReadHandle->outputCapacity) { - /** - * if cache is empty, load remain file block data. In contrast, if there are remain data in cache, do NOT - * copy them all to result buffer, since it may be overlapped with file data block. - */ - if (node == NULL || ((TD_ROW_KEY((STSRow*)SL_GET_NODE_DATA(node)) > pTsdbReadHandle->window.ekey) && ascScan) || - ((TD_ROW_KEY((STSRow*)SL_GET_NODE_DATA(node)) < pTsdbReadHandle->window.ekey) && !ascScan)) { - // no data in cache or data in cache is greater than the ekey of time window, load data from file block - if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = tsArray[pos]; - } + } - int32_t start = -1, end = -1; - getQualifiedRowsPos(pTsdbReadHandle, pos, endPos, numOfRows, &start, &end); + buildComposedDataBlockImpl(pReader, pBlockScanInfo); - numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, start, end); - pos += (end - start + 1) * step; + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pReader->status.blockIter); + SBlock* pBlock = taosArrayGet(pBlockScanInfo->pBlockList, pFBlock->tbBlockIdx); - cur->win.ekey = ascScan ? tsArray[end] : tsArray[start]; - cur->lastKey = cur->win.ekey + step; - cur->mixBlock = true; - } + // currently loaded file data block is consumed + if (pDumpInfo->rowIndex >= pBlock->nRow || pDumpInfo->rowIndex < 0) { + setBlockAllDumped(pDumpInfo, pBlock, pReader->order); + break; + } + + if (pResBlock->info.rows >= pReader->capacity) { + break; } } - cur->blockCompleted = (((pos > endPos || cur->lastKey > pTsdbReadHandle->window.ekey) && ascScan) || - ((pos < endPos || cur->lastKey < pTsdbReadHandle->window.ekey) && !ascScan)); + pResBlock->info.uid = pBlockScanInfo->uid; + blockDataUpdateTsWindow(pResBlock, 0); - if (!ascScan) { - TSWAP(cur->win.skey, cur->win.ekey); - } + setComposedBlockFlag(pReader, true); - updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); - doCheckGeneratedBlockRange(pTsdbReadHandle); + tsdbDebug("%p uid:%" PRIu64 ", composed data block created, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", pReader, + pBlockScanInfo->uid, pResBlock->info.window.skey, pResBlock->info.window.ekey, pResBlock->info.rows, + pReader->idStr); - tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, - pTsdbReadHandle->idStr); + return TSDB_CODE_SUCCESS; } -int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { - int firstPos, lastPos, midPos = -1; - int numOfRows; - TSKEY* keyList; +void setComposedBlockFlag(STsdbReader* pReader, bool composed) { pReader->status.composedDataBlock = composed; } - if (num <= 0) return -1; +static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader) { + if (pBlockScanInfo->iterInit) { + return TSDB_CODE_SUCCESS; + } - keyList = (TSKEY*)pValue; - firstPos = 0; - lastPos = num - 1; + int32_t code = TSDB_CODE_SUCCESS; - if (order == TSDB_ORDER_DESC) { - // find the first position which is smaller than the key - while (1) { - if (key >= keyList[lastPos]) return lastPos; - if (key == keyList[firstPos]) return firstPos; - if (key < keyList[firstPos]) return firstPos - 1; + TSDBKEY startKey = {0}; + if (ASCENDING_TRAVERSE(pReader->order)) { + startKey = (TSDBKEY){.ts = pReader->window.skey, .version = pReader->verRange.minVer}; + } else { + startKey = (TSDBKEY){.ts = pReader->window.ekey, .version = pReader->verRange.maxVer}; + } + + int32_t backward = (!ASCENDING_TRAVERSE(pReader->order)); - numOfRows = lastPos - firstPos + 1; - midPos = (numOfRows >> 1) + firstPos; + STbData* d = NULL; + if (pReader->pTsdb->mem != NULL) { + tsdbGetTbDataFromMemTable(pReader->pTsdb->mem, pReader->suid, pBlockScanInfo->uid, &d); + if (d != NULL) { + code = tsdbTbDataIterCreate(d, &startKey, backward, &pBlockScanInfo->iter.iter); + if (code == TSDB_CODE_SUCCESS) { + pBlockScanInfo->iter.hasVal = (tsdbTbDataIterGet(pBlockScanInfo->iter.iter) != NULL); - if (key < keyList[midPos]) { - lastPos = midPos - 1; - } else if (key > keyList[midPos]) { - firstPos = midPos + 1; + tsdbDebug("%p uid:%" PRId64 ", check data in mem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 + "-%" PRId64 " %s", + pReader, pBlockScanInfo->uid, startKey.ts, pReader->order, d->minKey, d->maxKey, pReader->idStr); } else { - break; + tsdbError("%p uid:%" PRId64 ", failed to create iterator for imem, code:%s, %s", pReader, pBlockScanInfo->uid, + tstrerror(code), pReader->idStr); + return code; } } - } else { - // find the first position which is bigger than the key - while (1) { - if (key <= keyList[firstPos]) return firstPos; - if (key == keyList[lastPos]) return lastPos; - - if (key > keyList[lastPos]) { - lastPos = lastPos + 1; - if (lastPos >= num) - return -1; - else - return lastPos; - } + tsdbDebug("%p uid:%" PRId64 ", no data in mem, %s", pReader, pBlockScanInfo->uid, pReader->idStr); + } - numOfRows = lastPos - firstPos + 1; - midPos = (numOfRows >> 1) + firstPos; + STbData* di = NULL; + if (pReader->pTsdb->imem != NULL) { + tsdbGetTbDataFromMemTable(pReader->pTsdb->imem, pReader->suid, pBlockScanInfo->uid, &di); + if (di != NULL) { + code = tsdbTbDataIterCreate(di, &startKey, backward, &pBlockScanInfo->iiter.iter); + if (code == TSDB_CODE_SUCCESS) { + pBlockScanInfo->iiter.hasVal = (tsdbTbDataIterGet(pBlockScanInfo->iiter.iter) != NULL); - if (key < keyList[midPos]) { - lastPos = midPos - 1; - } else if (key > keyList[midPos]) { - firstPos = midPos + 1; + tsdbDebug("%p uid:%" PRId64 ", check data in imem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 + "-%" PRId64 " %s", + pReader, pBlockScanInfo->uid, startKey.ts, pReader->order, di->minKey, di->maxKey, pReader->idStr); } else { - break; + tsdbError("%p uid:%" PRId64 ", failed to create iterator for mem, code:%s, %s", pReader, pBlockScanInfo->uid, + tstrerror(code), pReader->idStr); + return code; } } + } else { + tsdbDebug("%p uid:%" PRId64 ", no data in imem, %s", pReader, pBlockScanInfo->uid, pReader->idStr); } - return midPos; -} + initDelSkylineIterator(pBlockScanInfo, pReader, d, di); -static void cleanBlockOrderSupporter(SBlockOrderSupporter* pSupporter, int32_t numOfTables) { - taosMemoryFreeClear(pSupporter->numOfBlocksPerTable); - taosMemoryFreeClear(pSupporter->blockIndexArray); + pBlockScanInfo->iterInit = true; + return TSDB_CODE_SUCCESS; +} - for (int32_t i = 0; i < numOfTables; ++i) { - STableBlockInfo* pBlockInfo = pSupporter->pDataBlockInfo[i]; - taosMemoryFreeClear(pBlockInfo); +int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, STbData* pMemTbData, + STbData* piMemTbData) { + if (pBlockScanInfo->delSkyline != NULL) { + return TSDB_CODE_SUCCESS; } - taosMemoryFreeClear(pSupporter->pDataBlockInfo); -} + int32_t code = 0; + STsdb* pTsdb = pReader->pTsdb; -static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* param) { - int32_t leftTableIndex = *(int32_t*)pLeft; - int32_t rightTableIndex = *(int32_t*)pRight; + SArray* pDelData = taosArrayInit(4, sizeof(SDelData)); - SBlockOrderSupporter* pSupporter = (SBlockOrderSupporter*)param; + SDelFile* pDelFile = tsdbFSStateGetDelFile(pTsdb->fs->cState); + if (pDelFile) { + SDelFReader* pDelFReader = NULL; + code = tsdbDelFReaderOpen(&pDelFReader, pDelFile, pTsdb, NULL); + if (code) { + goto _err; + } - int32_t leftTableBlockIndex = pSupporter->blockIndexArray[leftTableIndex]; - int32_t rightTableBlockIndex = pSupporter->blockIndexArray[rightTableIndex]; + SArray* aDelIdx = taosArrayInit(4, sizeof(SDelIdx)); + if (aDelIdx == NULL) { + goto _err; + } - if (leftTableBlockIndex > pSupporter->numOfBlocksPerTable[leftTableIndex]) { - /* left block is empty */ - return 1; - } else if (rightTableBlockIndex > pSupporter->numOfBlocksPerTable[rightTableIndex]) { - /* right block is empty */ - return -1; - } + code = tsdbReadDelIdx(pDelFReader, aDelIdx, NULL); + if (code) { + goto _err; + } - STableBlockInfo* pLeftBlockInfoEx = &pSupporter->pDataBlockInfo[leftTableIndex][leftTableBlockIndex]; - STableBlockInfo* pRightBlockInfoEx = &pSupporter->pDataBlockInfo[rightTableIndex][rightTableBlockIndex]; + SDelIdx idx = {.suid = pReader->suid, .uid = pBlockScanInfo->uid}; + SDelIdx* pIdx = taosArraySearch(aDelIdx, &idx, tCmprDelIdx, TD_EQ); - // assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset); -#if 0 // TODO: temporarily comment off requested by Dr. Liao - if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset && - pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) { - tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset); + code = tsdbReadDelData(pDelFReader, pIdx, pDelData, NULL); + if (code != TSDB_CODE_SUCCESS) { + goto _err; + } } -#endif - - return pLeftBlockInfoEx->compBlock->offset > pRightBlockInfoEx->compBlock->offset ? 1 : -1; -} -static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t numOfBlocks, int32_t* numOfAllocBlocks) { - size_t size = sizeof(STableBlockInfo) * numOfBlocks; + SDelData* p = NULL; + if (pMemTbData != NULL) { + p = pMemTbData->pHead; + while (p) { + taosArrayPush(pDelData, p); + p = p->pNext; + } + } - if (pTsdbReadHandle->allocSize < size) { - pTsdbReadHandle->allocSize = (int32_t)size; - char* tmp = taosMemoryRealloc(pTsdbReadHandle->pDataBlockInfo, pTsdbReadHandle->allocSize); - if (tmp == NULL) { - return TSDB_CODE_TDB_OUT_OF_MEMORY; + if (piMemTbData != NULL) { + p = piMemTbData->pHead; + while (p) { + taosArrayPush(pDelData, p); + p = p->pNext; } + } - pTsdbReadHandle->pDataBlockInfo = (STableBlockInfo*)tmp; + if (taosArrayGetSize(pDelData) > 0) { + pBlockScanInfo->delSkyline = taosArrayInit(4, sizeof(TSDBKEY)); + code = tsdbBuildDeleteSkyline(pDelData, 0, (int32_t)(taosArrayGetSize(pDelData) - 1), pBlockScanInfo->delSkyline); } - memset(pTsdbReadHandle->pDataBlockInfo, 0, size); - *numOfAllocBlocks = numOfBlocks; + taosArrayDestroy(pDelData); + pBlockScanInfo->iter.index = + ASCENDING_TRAVERSE(pReader->order) ? 0 : taosArrayGetSize(pBlockScanInfo->delSkyline) - 1; + pBlockScanInfo->iiter.index = pBlockScanInfo->iter.index; + pBlockScanInfo->fileDelIndex = pBlockScanInfo->iter.index; + return code; - // access data blocks according to the offset of each block in asc/desc order. - int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); +_err: + taosArrayDestroy(pDelData); + return code; +} - SBlockOrderSupporter sup = {0}; - sup.numOfTables = numOfTables; - sup.numOfBlocksPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); - sup.blockIndexArray = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); - sup.pDataBlockInfo = taosMemoryCalloc(1, POINTER_BYTES * numOfTables); +static TSDBKEY getCurrentKeyInBuf(SDataBlockIter* pBlockIter, STsdbReader* pReader) { + TSDBKEY key = {.ts = TSKEY_INITIAL_VAL}; - if (sup.numOfBlocksPerTable == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) { - cleanBlockOrderSupporter(&sup, 0); - return TSDB_CODE_TDB_OUT_OF_MEMORY; - } + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(pBlockIter); + STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pFBlock->uid, sizeof(pFBlock->uid)); - int32_t cnt = 0; - int32_t numOfQualTables = 0; + initMemDataIterator(pScanInfo, pReader); + TSDBROW* pRow = getValidRow(&pScanInfo->iter, pScanInfo->delSkyline, pReader); + if (pRow != NULL) { + key = TSDBROW_KEY(pRow); + } - for (int32_t j = 0; j < numOfTables; ++j) { - STableCheckInfo* pTableCheck = (STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, j); - if (pTableCheck->numOfBlocks <= 0) { - continue; + pRow = getValidRow(&pScanInfo->iiter, pScanInfo->delSkyline, pReader); + if (pRow != NULL) { + TSDBKEY k = TSDBROW_KEY(pRow); + if (key.ts > k.ts) { + key = k; } + } - SBlock* pBlock = pTableCheck->pCompInfo->blocks; - sup.numOfBlocksPerTable[numOfQualTables] = pTableCheck->numOfBlocks; + return key; +} - char* buf = taosMemoryMalloc(sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); - if (buf == NULL) { - cleanBlockOrderSupporter(&sup, numOfQualTables); - return TSDB_CODE_TDB_OUT_OF_MEMORY; +static int32_t moveToNextFile(STsdbReader* pReader, int32_t* numOfBlocks) { + SReaderStatus* pStatus = &pReader->status; + + while (1) { + bool hasNext = filesetIteratorNext(&pStatus->fileIter, pReader); + if (!hasNext) { // no data files on disk + break; } - sup.pDataBlockInfo[numOfQualTables] = (STableBlockInfo*)buf; + SArray* pIndexList = taosArrayInit(4, sizeof(SBlockIdx)); + int32_t code = doLoadBlockIndex(pReader, pReader->pFileReader, pIndexList); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - for (int32_t k = 0; k < pTableCheck->numOfBlocks; ++k) { - STableBlockInfo* pBlockInfo = &sup.pDataBlockInfo[numOfQualTables][k]; + if (taosArrayGetSize(pIndexList) > 0) { + uint32_t numOfValidTable = 0; + code = doLoadFileBlock(pReader, pIndexList, &numOfValidTable, numOfBlocks); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - pBlockInfo->compBlock = &pBlock[k]; - pBlockInfo->pTableCheckInfo = pTableCheck; - cnt++; + if (numOfValidTable > 0) { + break; + } } - numOfQualTables++; + // no blocks in current file, try next files } - assert(numOfBlocks == cnt); + return TSDB_CODE_SUCCESS; +} - // since there is only one table qualified, blocks are not sorted - if (numOfQualTables == 1) { - memcpy(pTsdbReadHandle->pDataBlockInfo, sup.pDataBlockInfo[0], sizeof(STableBlockInfo) * numOfBlocks); - cleanBlockOrderSupporter(&sup, numOfQualTables); +static int32_t doBuildDataBlock(STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; - tsdbDebug("%p create data blocks info struct completed for 1 table, %d blocks not sorted %s", pTsdbReadHandle, cnt, - pTsdbReadHandle->idStr); - return TSDB_CODE_SUCCESS; - } + SReaderStatus* pStatus = &pReader->status; + SDataBlockIter* pBlockIter = &pStatus->blockIter; - tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pTsdbReadHandle, cnt, - numOfQualTables, pTsdbReadHandle->idStr); + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(pBlockIter); + STableBlockScanInfo* pScanInfo = taosHashGet(pStatus->pTableMap, &pFBlock->uid, sizeof(pFBlock->uid)); - assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pTableQueryInfo[j]->numOfBlocks may be 0 - sup.numOfTables = numOfQualTables; + SBlock* pBlock = taosArrayGet(pScanInfo->pBlockList, pFBlock->tbBlockIdx); - SMultiwayMergeTreeInfo* pTree = NULL; - uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); - if (ret != TSDB_CODE_SUCCESS) { - cleanBlockOrderSupporter(&sup, numOfTables); - return TSDB_CODE_TDB_OUT_OF_MEMORY; + TSDBKEY key = getCurrentKeyInBuf(pBlockIter, pReader); + if (fileBlockShouldLoad(pReader, pFBlock, pBlock, pScanInfo, key)) { + tBlockDataInit(&pStatus->fileBlockData); + code = doLoadFileBlockData(pReader, pBlockIter, pScanInfo, &pStatus->fileBlockData); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + // build composed data block + code = buildComposedDataBlock(pReader, pScanInfo); + } else if (bufferDataInFileBlockGap(pReader->order, key, pBlock)) { + // data in memory that are earlier than current file block + // todo rows in buffer should be less than the file block in asc, greater than file block in desc + int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? pBlock->minKey.ts : pBlock->maxKey.ts; + code = buildDataBlockFromBuf(pReader, pScanInfo, endKey); + } else { // whole block is required, return it directly + SDataBlockInfo* pInfo = &pReader->pResBlock->info; + pInfo->rows = pBlock->nRow; + pInfo->uid = pScanInfo->uid; + pInfo->window = (STimeWindow){.skey = pBlock->minKey.ts, .ekey = pBlock->maxKey.ts}; + setComposedBlockFlag(pReader, false); + setBlockAllDumped(&pStatus->fBlockDumpInfo, pBlock, pReader->order); } - int32_t numOfTotal = 0; + return code; +} - while (numOfTotal < cnt) { - int32_t pos = tMergeTreeGetChosenIndex(pTree); - int32_t index = sup.blockIndexArray[pos]++; +static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader) { + SReaderStatus* pStatus = &pReader->status; + + while (1) { + if (pStatus->pTableIter == NULL) { + pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL); + if (pStatus->pTableIter == NULL) { + return TSDB_CODE_SUCCESS; + } + } - STableBlockInfo* pBlocksInfo = sup.pDataBlockInfo[pos]; - pTsdbReadHandle->pDataBlockInfo[numOfTotal++] = pBlocksInfo[index]; + STableBlockScanInfo* pBlockScanInfo = pStatus->pTableIter; + initMemDataIterator(pBlockScanInfo, pReader); - // set data block index overflow, in order to disable the offset comparator - if (sup.blockIndexArray[pos] >= sup.numOfBlocksPerTable[pos]) { - sup.blockIndexArray[pos] = sup.numOfBlocksPerTable[pos] + 1; + int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? INT64_MAX : INT64_MIN; + int32_t code = buildDataBlockFromBuf(pReader, pBlockScanInfo, endKey); + if (code != TSDB_CODE_SUCCESS) { + return code; } - tMergeTreeAdjust(pTree, tMergeTreeGetAdjustIndex(pTree)); + if (pReader->pResBlock->info.rows > 0) { + return TSDB_CODE_SUCCESS; + } + + // current table is exhausted, let's try the next table + pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, pStatus->pTableIter); + if (pStatus->pTableIter == NULL) { + return TSDB_CODE_SUCCESS; + } } +} - /* - * available when no import exists - * for(int32_t i = 0; i < cnt - 1; ++i) { - * assert((*pDataBlockInfo)[i].compBlock->offset < (*pDataBlockInfo)[i+1].compBlock->offset); - * } - */ +// set the correct start position in case of the first/last file block, according to the query time window +static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter) { + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(pBlockIter); + STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pFBlock->uid, sizeof(pFBlock->uid)); + SBlock* pBlock = taosArrayGet(pScanInfo->pBlockList, pFBlock->tbBlockIdx); - tsdbDebug("%p %d data blocks sort completed, %s", pTsdbReadHandle, cnt, pTsdbReadHandle->idStr); - cleanBlockOrderSupporter(&sup, numOfTables); - taosMemoryFree(pTree); + SReaderStatus* pStatus = &pReader->status; - return TSDB_CODE_SUCCESS; + SFileBlockDumpInfo* pDumpInfo = &pStatus->fBlockDumpInfo; + + pDumpInfo->totalRows = pBlock->nRow; + pDumpInfo->allDumped = false; + pDumpInfo->rowIndex = ASCENDING_TRAVERSE(pReader->order) ? 0 : pBlock->nRow - 1; } -static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exists); +static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBlockIter) { + int32_t numOfBlocks = 0; + int32_t code = moveToNextFile(pReader, &numOfBlocks); + if (code != TSDB_CODE_SUCCESS) { + return code; + } -static int32_t getDataBlock(STsdbReadHandle* pTsdbReadHandle, STableBlockInfo* pNext, bool* exists) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; - SQueryFilePos* cur = &pTsdbReadHandle->cur; + // all data files are consumed, try data in buffer + if (numOfBlocks == 0) { + pReader->status.loadFromFile = false; + return code; + } - while (1) { - int32_t code = loadFileDataBlock(pTsdbReadHandle, pNext->compBlock, pNext->pTableCheckInfo, exists); - if (code != TSDB_CODE_SUCCESS || *exists) { - return code; - } + // initialize the block iterator for a new fileset + code = initBlockIterator(pReader, pBlockIter, numOfBlocks); - if ((cur->slot == pTsdbReadHandle->numOfBlocks - 1 && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || - (cur->slot == 0 && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { - // all data blocks in current file has been checked already, try next file if exists - return getFirstFileDataBlock(pTsdbReadHandle, exists); - } else { // next block of the same file - cur->slot += step; - cur->mixBlock = false; - cur->blockCompleted = false; - pNext = &pTsdbReadHandle->pDataBlockInfo[cur->slot]; - } - } + // set the correct start position according to the query time window + initBlockDumpInfo(pReader, pBlockIter); + return code; } -static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exists) { - pTsdbReadHandle->numOfBlocks = 0; - SQueryFilePos* cur = &pTsdbReadHandle->cur; +static bool fileBlockPartiallyRead(SFileBlockDumpInfo* pDumpInfo, bool asc) { + return (!pDumpInfo->allDumped) && + ((pDumpInfo->rowIndex > 0 && asc) || (pDumpInfo->rowIndex < (pDumpInfo->totalRows - 1) && (!asc))); +} +static int32_t buildBlockFromFiles(STsdbReader* pReader) { int32_t code = TSDB_CODE_SUCCESS; + bool asc = ASCENDING_TRAVERSE(pReader->order); - int32_t numOfBlocks = 0; - int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - - STsdbKeepCfg* pCfg = REPO_KEEP_CFG(pTsdbReadHandle->pTsdb); - STimeWindow win = TSWINDOW_INITIALIZER; + SDataBlockIter* pBlockIter = &pReader->status.blockIter; - while (true) { - tsdbRLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - - if ((pTsdbReadHandle->pFileGroup = tsdbFSIterNext(&pTsdbReadHandle->fileIter)) == NULL) { - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - break; - } + while (1) { + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pReader->status.blockIter); + STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pFBlock->uid, sizeof(pFBlock->uid)); - tsdbGetFidKeyRange(pCfg->days, pCfg->precision, pTsdbReadHandle->pFileGroup->fid, &win.skey, &win.ekey); + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - // current file are not overlapped with query time window, ignore remain files - if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && win.skey > pTsdbReadHandle->window.ekey) || - (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && win.ekey < pTsdbReadHandle->window.ekey)) { - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pTsdbReadHandle, - pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr); - pTsdbReadHandle->pFileGroup = NULL; - assert(pTsdbReadHandle->numOfBlocks == 0); - break; - } + if (fileBlockPartiallyRead(pDumpInfo, asc)) { // file data block is partially loaded + code = buildComposedDataBlock(pReader, pScanInfo); + } else { + // current block are exhausted, try the next file block + if (pDumpInfo->allDumped) { + // try next data block in current file + bool hasNext = blockIteratorNext(&pReader->status.blockIter); + if (hasNext) { // check for the next block in the block accessed order list + initBlockDumpInfo(pReader, pBlockIter); + } else { // data blocks in current file are exhausted, let's try the next file now + code = initForFirstBlockInFile(pReader, pBlockIter); + + // error happens or all the data files are completely checked + if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) { + return code; + } + } + } - if (tsdbSetAndOpenReadFSet(&pTsdbReadHandle->rhelper, pTsdbReadHandle->pFileGroup) < 0) { - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - code = terrno; - break; + // current block is not loaded yet, or data in buffer may overlap with the file block. + code = doBuildDataBlock(pReader); } - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - - if (tsdbLoadBlockIdx(&pTsdbReadHandle->rhelper) < 0) { - code = terrno; - break; + if (code != TSDB_CODE_SUCCESS) { + return code; } - if ((code = getFileCompInfo(pTsdbReadHandle, &numOfBlocks)) != TSDB_CODE_SUCCESS) { - break; + if (pReader->pResBlock->info.rows > 0) { + return TSDB_CODE_SUCCESS; } + } +} - tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pTsdbReadHandle, numOfBlocks, numOfTables, - pTsdbReadHandle->pFileGroup->fid, pTsdbReadHandle->idStr); +static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* retentions, const char* idStr, + int8_t* pLevel) { + if (VND_IS_RSMA(pVnode)) { + int8_t level = 0; + int64_t now = taosGetTimestamp(pVnode->config.tsdbCfg.precision); - assert(numOfBlocks >= 0); - if (numOfBlocks == 0) { - continue; + for (int8_t i = 0; i < TSDB_RETENTION_MAX; ++i) { + SRetention* pRetention = retentions + level; + if (pRetention->keep <= 0) { + if (level > 0) { + --level; + } + break; + } + if ((now - pRetention->keep) <= winSKey) { + break; + } + ++level; } - // todo return error code to query engine - if ((code = createDataBlocksInfo(pTsdbReadHandle, numOfBlocks, &pTsdbReadHandle->numOfBlocks)) != - TSDB_CODE_SUCCESS) { - break; - } + int32_t vgId = TD_VID(pVnode); + const char* str = (idStr != NULL) ? idStr : ""; - assert(numOfBlocks >= pTsdbReadHandle->numOfBlocks); - if (pTsdbReadHandle->numOfBlocks > 0) { - break; + if (level == TSDB_RETENTION_L0) { + *pLevel = TSDB_RETENTION_L0; + tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L0, str); + return VND_RSMA0(pVnode); + } else if (level == TSDB_RETENTION_L1) { + *pLevel = TSDB_RETENTION_L1; + tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L1, str); + return VND_RSMA1(pVnode); + } else { + *pLevel = TSDB_RETENTION_L2; + tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L2, str); + return VND_RSMA2(pVnode); } } - // no data in file anymore - if (pTsdbReadHandle->numOfBlocks <= 0 || code != TSDB_CODE_SUCCESS) { - if (code == TSDB_CODE_SUCCESS) { - assert(pTsdbReadHandle->pFileGroup == NULL); - } + return VND_TSDB(pVnode); +} - cur->fid = INT32_MIN; // denote that there are no data in file anymore - *exists = false; - return code; +static SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level) { + if (VND_IS_RSMA(pVnode)) { + return (SVersionRange){.minVer = pCond->startVersion, .maxVer = tdRSmaGetMaxSubmitVer(pVnode->pSma, level)}; } - assert(pTsdbReadHandle->pFileGroup != NULL && pTsdbReadHandle->numOfBlocks > 0); - cur->slot = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 0 : pTsdbReadHandle->numOfBlocks - 1; - cur->fid = pTsdbReadHandle->pFileGroup->fid; - - STableBlockInfo* pBlockInfo = &pTsdbReadHandle->pDataBlockInfo[cur->slot]; - return getDataBlock(pTsdbReadHandle, pBlockInfo, exists); + return (SVersionRange){.minVer = pCond->startVersion, .maxVer = pVnode->state.applied}; } -static bool isEndFileDataBlock(SQueryFilePos* cur, int32_t numOfBlocks, bool ascTrav) { - assert(cur != NULL && numOfBlocks > 0); - return (cur->slot == numOfBlocks - 1 && ascTrav) || (cur->slot == 0 && !ascTrav); -} +// // todo not unref yet, since it is not support multi-group interpolation query +// static UNUSED_FUNC void changeQueryHandleForInterpQuery(STsdbReader* pHandle) { +// // filter the queried time stamp in the first place +// STsdbReader* pTsdbReadHandle = (STsdbReader*)pHandle; -static void moveToNextDataBlockInCurrentFile(STsdbReadHandle* pTsdbReadHandle) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; +// // starts from the buffer in case of descending timestamp order check data blocks +// size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - SQueryFilePos* cur = &pTsdbReadHandle->cur; - assert(cur->slot < pTsdbReadHandle->numOfBlocks && cur->slot >= 0); +// int32_t i = 0; +// while (i < numOfTables) { +// STableBlockScanInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); - cur->slot += step; - cur->mixBlock = false; - cur->blockCompleted = false; -} +// // the first qualified table for interpolation query +// // if ((pTsdbReadHandle->window.skey <= pCheckInfo->pTableObj->lastKey) && +// // (pCheckInfo->pTableObj->lastKey != TSKEY_INITIAL_VAL)) { +// // break; +// // } -static int32_t getBucketIndex(int32_t startRow, int32_t bucketRange, int32_t numOfRows) { - return (numOfRows - startRow) / bucketRange; -} +// i++; +// } -int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* pTableBlockInfo) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)queryHandle; +// // there are no data in all the tables +// if (i == numOfTables) { +// return; +// } - pTableBlockInfo->totalSize = 0; - pTableBlockInfo->totalRows = 0; +// STableBlockScanInfo info = *(STableBlockScanInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); +// taosArrayClear(pTsdbReadHandle->pTableCheckInfo); - STsdbFS* pFileHandle = REPO_FS(pTsdbReadHandle->pTsdb); +// info.lastKey = pTsdbReadHandle->window.skey; +// taosArrayPush(pTsdbReadHandle->pTableCheckInfo, &info); +// } - // find the start data block in file - pTsdbReadHandle->locateStart = true; - STsdbKeepCfg* pCfg = REPO_KEEP_CFG(pTsdbReadHandle->pTsdb); - int32_t fid = getFileIdFromKey(pTsdbReadHandle->window.skey, pCfg->days, pCfg->precision); +bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey) { + ASSERT(pKey != NULL); + if (pDelList == NULL) { + return false; + } - tsdbRLockFS(pFileHandle); - tsdbFSIterInit(&pTsdbReadHandle->fileIter, pFileHandle, pTsdbReadHandle->order); - tsdbFSIterSeek(&pTsdbReadHandle->fileIter, fid); - tsdbUnLockFS(pFileHandle); + if (*index >= taosArrayGetSize(pDelList) - 1) { + TSDBKEY* last = taosArrayGetLast(pDelList); + if (pKey->ts > last->ts) { + return false; + } else if (pKey->ts == last->ts) { + size_t size = taosArrayGetSize(pDelList); + TSDBKEY* prev = taosArrayGet(pDelList, size - 2); + if (prev->version >= pKey->version) { + return true; + } else { + return false; + } + } else { + ASSERT(0); + } + } else { + TSDBKEY* pCurrent = taosArrayGet(pDelList, *index); + TSDBKEY* pNext = taosArrayGet(pDelList, (*index) + 1); - STsdbCfg* pc = REPO_CFG(pTsdbReadHandle->pTsdb); - pTableBlockInfo->defMinRows = pc->minRows; - pTableBlockInfo->defMaxRows = pc->maxRows; + if (pCurrent->ts <= pKey->ts && pNext->ts >= pKey->ts && pCurrent->version >= pKey->version) { + return true; + } else { + while (pNext->ts < pKey->ts && (*index) < taosArrayGetSize(pDelList) - 1) { + (*index) += 1; + } - int32_t bucketRange = ceil((pc->maxRows - pc->minRows) / 20.0); + return false; + } + } +} - pTableBlockInfo->numOfFiles += 1; +TSDBROW* getValidRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader) { + if (!pIter->hasVal) { + return NULL; + } - int32_t code = TSDB_CODE_SUCCESS; - int32_t numOfBlocks = 0; - int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - int defaultRows = 4096; - STimeWindow win = TSWINDOW_INITIALIZER; + TSDBROW* pRow = tsdbTbDataIterGet(pIter->iter); + TSDBKEY key = TSDBROW_KEY(pRow); + if (outOfTimeWindow(key.ts, &pReader->window)) { + pIter->hasVal = false; + return NULL; + } - while (true) { - numOfBlocks = 0; - tsdbRLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); + // it is a valid data version + if ((key.version <= pReader->verRange.maxVer && key.version >= pReader->verRange.minVer) && + (!hasBeenDropped(pDelList, &pIter->index, &key))) { + return pRow; + } - if ((pTsdbReadHandle->pFileGroup = tsdbFSIterNext(&pTsdbReadHandle->fileIter)) == NULL) { - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - break; + while (1) { + pIter->hasVal = tsdbTbDataIterNext(pIter->iter); + if (!pIter->hasVal) { + return NULL; } - tsdbGetFidKeyRange(pCfg->days, pCfg->precision, pTsdbReadHandle->pFileGroup->fid, &win.skey, &win.ekey); + pRow = tsdbTbDataIterGet(pIter->iter); - // current file are not overlapped with query time window, ignore remain files - if ((win.skey > pTsdbReadHandle->window.ekey) /* || (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)*/) { - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pTsdbReadHandle, - pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr); - pTsdbReadHandle->pFileGroup = NULL; - break; + key = TSDBROW_KEY(pRow); + if (outOfTimeWindow(key.ts, &pReader->window)) { + pIter->hasVal = false; + return NULL; } - pTableBlockInfo->numOfFiles += 1; - if (tsdbSetAndOpenReadFSet(&pTsdbReadHandle->rhelper, pTsdbReadHandle->pFileGroup) < 0) { - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); - code = terrno; - break; + if (key.version <= pReader->verRange.maxVer && key.version >= pReader->verRange.minVer && + (!hasBeenDropped(pDelList, &pIter->index, &key))) { + return pRow; } + } +} - tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); +int32_t doMergeRowsInBuf(SIterInfo* pIter, int64_t ts, SArray* pDelList, SRowMerger* pMerger, STsdbReader* pReader) { + while (1) { + pIter->hasVal = tsdbTbDataIterNext(pIter->iter); + if (!pIter->hasVal) { + break; + } - if (tsdbLoadBlockIdx(&pTsdbReadHandle->rhelper) < 0) { - code = terrno; + // data exists but not valid + TSDBROW* pRow = getValidRow(pIter, pDelList, pReader); + if (pRow == NULL) { break; } - if ((code = getFileCompInfo(pTsdbReadHandle, &numOfBlocks)) != TSDB_CODE_SUCCESS) { + // ts is not identical, quit + TSDBKEY k = TSDBROW_KEY(pRow); + if (k.ts != ts) { break; } - tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pTsdbReadHandle, numOfBlocks, numOfTables, - pTsdbReadHandle->pFileGroup->fid, pTsdbReadHandle->idStr); + tRowMerge(pMerger, pRow); + } + + return TSDB_CODE_SUCCESS; +} - if (numOfBlocks == 0) { +static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowIndex, int64_t key, SRowMerger* pMerger, + SVersionRange* pVerRange, int32_t step) { + while (pBlockData->aTSKEY[rowIndex] == key && rowIndex < pBlockData->nRow && rowIndex >= 0) { + if (pBlockData->aVersion[rowIndex] > pVerRange->maxVer || pBlockData->aVersion[rowIndex] < pVerRange->minVer) { continue; } - pTableBlockInfo->numOfBlocks += numOfBlocks; + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex); + tRowMerge(pMerger, &fRow); + rowIndex += step; + } + + return rowIndex; +} - for (int32_t i = 0; i < numOfTables; ++i) { - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); +typedef enum { + CHECK_FILEBLOCK_CONT = 0x1, + CHECK_FILEBLOCK_QUIT = 0x2, +} CHECK_FILEBLOCK_STATE; - SBlock* pBlock = pCheckInfo->pCompInfo->blocks; +static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanInfo* pScanInfo, SBlock* pBlock, + SFileDataBlockInfo* pFBlock, SRowMerger* pMerger, int64_t key, + CHECK_FILEBLOCK_STATE* state) { + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + SBlockData* pBlockData = &pReader->status.fileBlockData; - for (int32_t j = 0; j < pCheckInfo->numOfBlocks; ++j) { - pTableBlockInfo->totalSize += pBlock[j].len; + *state = CHECK_FILEBLOCK_QUIT; + int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1; - int32_t numOfRows = pBlock[j].numOfRows; - pTableBlockInfo->totalRows += numOfRows; + int32_t nextIndex = -1; + SBlock* pNeighborBlock = getNeighborBlockOfSameTable(pFBlock, pScanInfo, &nextIndex, pReader->order); + if (pNeighborBlock == NULL) { // do nothing + return 0; + } - if (numOfRows > pTableBlockInfo->maxRows) { - pTableBlockInfo->maxRows = numOfRows; - } + bool overlap = overlapWithNeighborBlock(pBlock, pNeighborBlock, pReader->order); + if (overlap) { // load next block + SReaderStatus* pStatus = &pReader->status; + SDataBlockIter* pBlockIter = &pStatus->blockIter; - if (numOfRows < pTableBlockInfo->minRows) { - pTableBlockInfo->minRows = numOfRows; - } + // 1. find the next neighbor block in the scan block list + SFileDataBlockInfo fb = {.uid = pFBlock->uid, .tbBlockIdx = nextIndex}; + int32_t neighborIndex = findFileBlockInfoIndex(pBlockIter, &fb); - if (numOfRows < defaultRows) { - pTableBlockInfo->numOfSmallBlocks += 1; - } + // 2. remove it from the scan block list + setFileBlockActiveInBlockIter(pBlockIter, neighborIndex, step); + + // 3. load the neighbor block, and set it to be the currently accessed file data block + int32_t code = doLoadFileBlockData(pReader, pBlockIter, pScanInfo, &pStatus->fileBlockData); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + // 4. check the data values + initBlockDumpInfo(pReader, pBlockIter); + + pDumpInfo->rowIndex = + doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, key, pMerger, &pReader->verRange, step); + + if (pDumpInfo->rowIndex >= pBlock->nRow) { + *state = CHECK_FILEBLOCK_CONT; + } + } + + return TSDB_CODE_SUCCESS; +} + +int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader, + SRowMerger* pMerger) { + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + + bool asc = ASCENDING_TRAVERSE(pReader->order); + int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex]; + int32_t step = asc ? 1 : -1; + + pDumpInfo->rowIndex += step; + if (pDumpInfo->rowIndex <= pBlockData->nRow - 1) { + pDumpInfo->rowIndex = + doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, key, pMerger, &pReader->verRange, step); + } + + // all rows are consumed, let's try next file block + if ((pDumpInfo->rowIndex >= pBlockData->nRow && asc) || (pDumpInfo->rowIndex < 0 && !asc)) { + while (1) { + CHECK_FILEBLOCK_STATE st; - int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows); - pTableBlockInfo->blockRowsHisto[bucketIndex]++; + SFileDataBlockInfo* pFileBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter); + SBlock* pCurrentBlock = taosArrayGet(pScanInfo->pBlockList, pFileBlockInfo->tbBlockIdx); + checkForNeighborFileBlock(pReader, pScanInfo, pCurrentBlock, pFileBlockInfo, pMerger, key, &st); + if (st == CHECK_FILEBLOCK_QUIT) { + break; } } } - pTableBlockInfo->numOfTables = numOfTables; - return code; + return TSDB_CODE_SUCCESS; +} + +void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { + int32_t sversion = TSDBROW_SVERSION(pRow); + + if (pReader->pSchema == NULL) { + pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + } else if (pReader->pSchema->version != sversion) { + taosMemoryFreeClear(pReader->pSchema); + pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + } +} + +void doMergeMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList, STSRow** pTSRow, + STsdbReader* pReader) { + SRowMerger merge = {0}; + + TSDBKEY k = TSDBROW_KEY(pRow); + updateSchema(pRow, uid, pReader); + + tRowMergerInit(&merge, pRow, pReader->pSchema); + doMergeRowsInBuf(pIter, k.ts, pDelList, &merge, pReader); + tRowMergerGetRow(&merge, pTSRow); } -static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exists) { - STsdbFS* pFileHandle = REPO_FS(pTsdbReadHandle->pTsdb); - SQueryFilePos* cur = &pTsdbReadHandle->cur; +void doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, + STSRow** pTSRow) { + SRowMerger merge = {0}; + + TSDBKEY k = TSDBROW_KEY(pRow); + TSDBKEY ik = TSDBROW_KEY(piRow); - // find the start data block in file - if (!pTsdbReadHandle->locateStart) { - pTsdbReadHandle->locateStart = true; - STsdbKeepCfg* pCfg = REPO_KEEP_CFG(pTsdbReadHandle->pTsdb); - int32_t fid = getFileIdFromKey(pTsdbReadHandle->window.skey, pCfg->days, pCfg->precision); + if (ASCENDING_TRAVERSE(pReader->order)) { // ascending order imem --> mem + updateSchema(piRow, pBlockScanInfo->uid, pReader); - tsdbRLockFS(pFileHandle); - tsdbFSIterInit(&pTsdbReadHandle->fileIter, pFileHandle, pTsdbReadHandle->order); - tsdbFSIterSeek(&pTsdbReadHandle->fileIter, fid); - tsdbUnLockFS(pFileHandle); + tRowMergerInit(&merge, piRow, pReader->pSchema); + doMergeRowsInBuf(&pBlockScanInfo->iiter, ik.ts, pBlockScanInfo->delSkyline, &merge, pReader); - return getFirstFileDataBlock(pTsdbReadHandle, exists); + tRowMerge(&merge, pRow); + doMergeRowsInBuf(&pBlockScanInfo->iter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); } else { - // check if current file block is all consumed - STableBlockInfo* pBlockInfo = &pTsdbReadHandle->pDataBlockInfo[cur->slot]; - STableCheckInfo* pCheckInfo = pBlockInfo->pTableCheckInfo; + updateSchema(pRow, pBlockScanInfo->uid, pReader); + + tRowMergerInit(&merge, pRow, pReader->pSchema); + doMergeRowsInBuf(&pBlockScanInfo->iter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); + + tRowMerge(&merge, piRow); + doMergeRowsInBuf(&pBlockScanInfo->iiter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); + } + + tRowMergerGetRow(&merge, pTSRow); +} - // current block is done, try next - if ((!cur->mixBlock) || cur->blockCompleted) { - // all data blocks in current file has been checked already, try next file if exists - } else { - tsdbDebug("%p continue in current data block, index:%d, pos:%d, %s", pTsdbReadHandle, cur->slot, cur->pos, - pTsdbReadHandle->idStr); - int32_t code = handleDataMergeIfNeeded(pTsdbReadHandle, pBlockInfo->compBlock, pCheckInfo); - *exists = (pTsdbReadHandle->realNumOfRows > 0); +int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, STSRow** pTSRow, + int64_t endKey) { + TSDBROW* pRow = getValidRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader); + TSDBROW* piRow = getValidRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader); + SArray* pDelList = pBlockScanInfo->delSkyline; - if (code != TSDB_CODE_SUCCESS || *exists) { - return code; - } + // todo refactor + bool asc = ASCENDING_TRAVERSE(pReader->order); + if (pBlockScanInfo->iter.hasVal) { + TSDBKEY k = TSDBROW_KEY(pRow); + if ((k.ts >= endKey && asc) || (k.ts <= endKey && !asc)) { + pRow = NULL; } + } - // current block is empty, try next block in file - // all data blocks in current file has been checked already, try next file if exists - if (isEndFileDataBlock(cur, pTsdbReadHandle->numOfBlocks, ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { - return getFirstFileDataBlock(pTsdbReadHandle, exists); - } else { - moveToNextDataBlockInCurrentFile(pTsdbReadHandle); - STableBlockInfo* pNext = &pTsdbReadHandle->pDataBlockInfo[cur->slot]; - return getDataBlock(pTsdbReadHandle, pNext, exists); + if (pBlockScanInfo->iiter.hasVal) { + TSDBKEY k = TSDBROW_KEY(piRow); + if ((k.ts >= endKey && asc) || (k.ts <= endKey && !asc)) { + piRow = NULL; } } -} -static bool doHasDataInBuffer(STsdbReadHandle* pTsdbReadHandle) { - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); + if (pBlockScanInfo->iter.hasVal && pBlockScanInfo->iiter.hasVal && pRow != NULL && piRow != NULL) { + TSDBKEY k = TSDBROW_KEY(pRow); + TSDBKEY ik = TSDBROW_KEY(piRow); - while (pTsdbReadHandle->activeIndex < numOfTables) { - if (hasMoreDataInCache(pTsdbReadHandle)) { - return true; + if (ik.ts < k.ts) { // ik.ts < k.ts + doMergeMultiRows(piRow, pBlockScanInfo->uid, &pBlockScanInfo->iiter, pDelList, pTSRow, pReader); + } else if (k.ts < ik.ts) { + doMergeMultiRows(pRow, pBlockScanInfo->uid, &pBlockScanInfo->iter, pDelList, pTSRow, pReader); + } else { // ik.ts == k.ts + doMergeMemIMemRows(pRow, piRow, pBlockScanInfo, pReader, pTSRow); } - pTsdbReadHandle->activeIndex += 1; + return TSDB_CODE_SUCCESS; } - return false; -} + if (pBlockScanInfo->iter.hasVal && pRow != NULL) { + doMergeMultiRows(pRow, pBlockScanInfo->uid, &pBlockScanInfo->iter, pDelList, pTSRow, pReader); + return TSDB_CODE_SUCCESS; + } + + if (pBlockScanInfo->iiter.hasVal && piRow != NULL) { + doMergeMultiRows(piRow, pBlockScanInfo->uid, &pBlockScanInfo->iiter, pDelList, pTSRow, pReader); + return TSDB_CODE_SUCCESS; + } -// todo not unref yet, since it is not support multi-group interpolation query -static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) { - // filter the queried time stamp in the first place - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; + return TSDB_CODE_SUCCESS; +} - // starts from the buffer in case of descending timestamp order check data blocks - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); +int32_t doAppendOneRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow) { + int32_t numOfRows = pBlock->info.rows; + int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock); - int32_t i = 0; - while (i < numOfTables) { - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + STSchema* pSchema = pReader->pSchema; - // the first qualified table for interpolation query - // if ((pTsdbReadHandle->window.skey <= pCheckInfo->pTableObj->lastKey) && - // (pCheckInfo->pTableObj->lastKey != TSKEY_INITIAL_VAL)) { - // break; - // } + SColVal colVal = {0}; + int32_t i = 0, j = 0; - i++; + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + if (pColInfoData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) { + colDataAppend(pColInfoData, numOfRows, (const char*)&pTSRow->ts, false); + i += 1; } - // there are no data in all the tables - if (i == numOfTables) { - return; + while (i < numOfCols && j < pSchema->numOfCols) { + pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + col_id_t colId = pColInfoData->info.colId; + + if (colId == pSchema->columns[j].colId) { + tTSRowGetVal(pTSRow, pReader->pSchema, j, &colVal); + doCopyColVal(pColInfoData, numOfRows, i, &colVal, pSupInfo); + i += 1; + j += 1; + } else if (colId < pSchema->columns[j].colId) { + colDataAppendNULL(pColInfoData, numOfRows); + i += 1; + } else if (colId > pSchema->columns[j].colId) { + j += 1; + } } - STableCheckInfo info = *(STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); - taosArrayClear(pTsdbReadHandle->pTableCheckInfo); + // set null value since current column does not exist in the "pSchema" + while (i < numOfCols) { + pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + colDataAppendNULL(pColInfoData, numOfRows); + i += 1; + } - info.lastKey = pTsdbReadHandle->window.skey; - taosArrayPush(pTsdbReadHandle->pTableCheckInfo, &info); + pBlock->info.rows += 1; + return TSDB_CODE_SUCCESS; } -static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, - STsdbReadHandle* pTsdbReadHandle) { - int numOfRows = 0; - int curRows = 0; - int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pResBlock->pDataBlock); - STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); - win->skey = TSKEY_INITIAL_VAL; - - int64_t st = taosGetTimestampUs(); - int16_t rv = -1; - STSchema* pSchema = NULL; - TSKEY lastRowKey = TSKEY_INITIAL_VAL; +int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity, + STsdbReader* pReader) { + SSDataBlock* pBlock = pReader->pResBlock; do { - STSRow* row = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, NULL, TD_VER_MAX); - if (row == NULL) { + STSRow* pTSRow = NULL; + tsdbGetNextRowInMem(pBlockScanInfo, pReader, &pTSRow, endKey); + if (pTSRow == NULL) { break; } - TSKEY key = TD_ROW_KEY(row); - if ((key > maxKey && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || - (key < maxKey && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { - tsdbDebug("%p key:%" PRIu64 " beyond qrange:%" PRId64 " - %" PRId64 ", no more data in buffer", pTsdbReadHandle, - key, pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey); + doAppendOneRow(pBlock, pReader, pTSRow); + // no data in buffer, return immediately + if (!(pBlockScanInfo->iter.hasVal || pBlockScanInfo->iiter.hasVal)) { break; } - if (win->skey == INT64_MIN) { - win->skey = key; - } - - win->ekey = key; - if (rv != TD_ROW_SVER(row)) { - pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, TD_ROW_SVER(row)); - rv = TD_ROW_SVER(row); - } - numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, &curRows, row, NULL, numOfCols, pCheckInfo->tableId, - pSchema, NULL, pCfg->update, &lastRowKey); - - if (numOfRows >= maxRowsToRead) { - moveToNextRowInMem(pCheckInfo); + if (pBlock->info.rows >= capacity) { break; } + } while (1); - } while (moveToNextRowInMem(pCheckInfo)); - - taosMemoryFreeClear(pSchema); // free the STSChema - assert(numOfRows <= maxRowsToRead); + ASSERT(pBlock->info.rows <= capacity); + return TSDB_CODE_SUCCESS; +} - int64_t elapsedTime = taosGetTimestampUs() - st; - tsdbDebug("%p build data block from cache completed, elapsed time:%" PRId64 " us, numOfRows:%d, numOfCols:%d, %s", - pTsdbReadHandle, elapsedTime, numOfRows, numOfCols, pTsdbReadHandle->idStr); +// todo refactor, use arraylist instead +int32_t tsdbSetTableId(STsdbReader* pReader, int64_t uid) { + ASSERT(pReader != NULL); + taosHashClear(pReader->status.pTableMap); - return numOfRows; + STableBlockScanInfo info = {.lastKey = 0, .uid = uid}; + taosHashPut(pReader->status.pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info)); + return TDB_CODE_SUCCESS; } void* tsdbGetIdx(SMeta* pMeta) { @@ -2862,44 +2872,13 @@ void* tsdbGetIdx(SMeta* pMeta) { } return metaGetIdx(pMeta); } + void* tsdbGetIvtIdx(SMeta* pMeta) { if (pMeta == NULL) { return NULL; } return metaGetIvtIdx(pMeta); } -int32_t tsdbGetAllTableList(SMeta* pMeta, uint64_t uid, SArray* list) { - SMCtbCursor* pCur = metaOpenCtbCursor(pMeta, uid); - - while (1) { - tb_uid_t id = metaCtbCursorNext(pCur); - if (id == 0) { - break; - } - - STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, uid = id, .groupId = 0}; - taosArrayPush(list, &info); - } - - metaCloseCtbCursor(pCur); - return TSDB_CODE_SUCCESS; -} - -int32_t tsdbGetCtbIdList(SMeta* pMeta, int64_t suid, SArray* list) { - SMCtbCursor* pCur = metaOpenCtbCursor(pMeta, suid); - - while (1) { - tb_uid_t id = metaCtbCursorNext(pCur); - if (id == 0) { - break; - } - - taosArrayPush(list, &id); - } - - metaCloseCtbCursor(pCur); - return TSDB_CODE_SUCCESS; -} /** * @brief Get all suids since suid @@ -2928,852 +2907,587 @@ int32_t tsdbGetStbIdList(SMeta* pMeta, int64_t suid, SArray* list) { return TSDB_CODE_SUCCESS; } -static void destroyHelper(void* param) { - if (param == NULL) { - return; - } - - // tQueryInfo* pInfo = (tQueryInfo*)param; - // if (pInfo->optr != TSDB_RELATION_IN) { - // taosMemoryFreeClear(pInfo->q); - // } else { - // taosHashCleanup((SHashObj *)(pInfo->q)); - // } +// static void destroyHelper(void* param) { +// if (param == NULL) { +// return; +// } - taosMemoryFree(param); -} +// // tQueryInfo* pInfo = (tQueryInfo*)param; +// // if (pInfo->optr != TSDB_RELATION_IN) { +// // taosMemoryFreeClear(pInfo->q); +// // } else { +// // taosHashCleanup((SHashObj *)(pInfo->q)); +// // } -#define TSDB_PREV_ROW 0x1 -#define TSDB_NEXT_ROW 0x2 +// taosMemoryFree(param); +// } -static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { - if (pTsdbReadHandle->checkFiles) { - // check if the query range overlaps with the file data block - bool exists = true; +// #define TSDB_PREV_ROW 0x1 +// #define TSDB_NEXT_ROW 0x2 - int32_t code = getDataBlocksInFiles(pTsdbReadHandle, &exists); - if (code != TSDB_CODE_SUCCESS) { - pTsdbReadHandle->checkFiles = false; - return false; - } +// static bool loadBlockOfActiveTable(STsdbReader* pTsdbReadHandle) { +// if (pTsdbReadHandle->checkFiles) { +// // check if the query range overlaps with the file data block +// bool exists = true; - if (exists) { - tsdbRetrieveDataBlock((tsdbReaderT*)pTsdbReadHandle, NULL); - if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, 0); - assert(*(int64_t*)pColInfo->pData == pTsdbReadHandle->window.skey); - } +// int32_t code = buildBlockFromFiles(pTsdbReadHandle, &exists); +// if (code != TSDB_CODE_SUCCESS) { +// pTsdbReadHandle->checkFiles = false; +// return false; +// } - pTsdbReadHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. - return exists; - } +// if (exists) { +// tsdbRetrieveDataBlock((STsdbReader**)pTsdbReadHandle, NULL); +// if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey) { +// SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, 0); +// assert(*(int64_t*)pColInfo->pData == pTsdbReadHandle->window.skey); +// } - pTsdbReadHandle->checkFiles = false; - } +// pTsdbReadHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. +// return exists; +// } - if (hasMoreDataInCache(pTsdbReadHandle)) { - pTsdbReadHandle->currentLoadExternalRows = false; - return true; - } +// pTsdbReadHandle->checkFiles = false; +// } - // current result is empty - if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey && - pTsdbReadHandle->cur.rows == 0) { - // SMemTable* pMemRef = pTsdbReadHandle->pMemTable; +// if (hasMoreDataInCache(pTsdbReadHandle)) { +// pTsdbReadHandle->currentLoadExternalRows = false; +// return true; +// } + +// // current result is empty +// if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey && +// pTsdbReadHandle->cur.rows == 0) { +// // SMemTable* pMemRef = pTsdbReadHandle->pMemTable; - // doGetExternalRow(pTsdbReadHandle, TSDB_PREV_ROW, pMemRef); - // doGetExternalRow(pTsdbReadHandle, TSDB_NEXT_ROW, pMemRef); +// // doGetExternalRow(pTsdbReadHandle, TSDB_PREV_ROW, pMemRef); +// // doGetExternalRow(pTsdbReadHandle, TSDB_NEXT_ROW, pMemRef); - bool result = tsdbGetExternalRow(pTsdbReadHandle); +// bool result = tsdbGetExternalRow(pTsdbReadHandle); + +// // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); +// // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); +// pTsdbReadHandle->currentLoadExternalRows = false; + +// return result; +// } - // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); - // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); - pTsdbReadHandle->currentLoadExternalRows = false; +// return false; +// } + +// static bool loadDataBlockFromTableSeq(STsdbReader* pTsdbReadHandle) { +// size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); +// assert(numOfTables > 0); - return result; - } +// int64_t stime = taosGetTimestampUs(); + +// while (pTsdbReadHandle->activeIndex < numOfTables) { +// if (loadBlockOfActiveTable(pTsdbReadHandle)) { +// return true; +// } + +// STableBlockScanInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); +// pCheckInfo->numOfBlocks = 0; + +// pTsdbReadHandle->activeIndex += 1; +// pTsdbReadHandle->locateStart = false; +// pTsdbReadHandle->checkFiles = true; +// pTsdbReadHandle->cur.rows = 0; +// pTsdbReadHandle->currentLoadExternalRows = pTsdbReadHandle->loadExternalRow; + +// terrno = TSDB_CODE_SUCCESS; + +// int64_t elapsedTime = taosGetTimestampUs() - stime; +// pTsdbReadHandle->cost.checkForNextTime += elapsedTime; +// } + +// return false; +// } + +// bool tsdbGetExternalRow(STsdbReader* pHandle) { +// STsdbReader* pTsdbReadHandle = (STsdbReader*)pHandle; +// SQueryFilePos* cur = &pTsdbReadHandle->cur; + +// cur->fid = INT32_MIN; +// cur->mixBlock = true; +// if (pTsdbReadHandle->prev == NULL || pTsdbReadHandle->next == NULL) { +// cur->rows = 0; +// return false; +// } + +// int32_t numOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); +// for (int32_t i = 0; i < numOfCols; ++i) { +// SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, i); +// SColumnInfoData* first = taosArrayGet(pTsdbReadHandle->prev, i); + +// memcpy(pColInfoData->pData, first->pData, pColInfoData->info.bytes); + +// SColumnInfoData* sec = taosArrayGet(pTsdbReadHandle->next, i); +// memcpy(((char*)pColInfoData->pData) + pColInfoData->info.bytes, sec->pData, pColInfoData->info.bytes); + +// if (i == 0 && pColInfoData->info.type == TSDB_DATA_TYPE_TIMESTAMP) { +// cur->win.skey = *(TSKEY*)pColInfoData->pData; +// cur->win.ekey = *(TSKEY*)(((char*)pColInfoData->pData) + TSDB_KEYSIZE); +// } +// } + +// cur->rows = 2; +// return true; +// } + +// static void* doFreeColumnInfoData(SArray* pColumnInfoData) { +// if (pColumnInfoData == NULL) { +// return NULL; +// } - return false; -} +// size_t cols = taosArrayGetSize(pColumnInfoData); +// for (int32_t i = 0; i < cols; ++i) { +// SColumnInfoData* pColInfo = taosArrayGet(pColumnInfoData, i); +// colDataDestroy(pColInfo); +// } -static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { - // the last row is cached in buffer, return it directly. - // here note that the pTsdbReadHandle->window must be the TS_INITIALIZER - int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - assert(numOfTables > 0 && numOfCols > 0); +// taosArrayDestroy(pColumnInfoData); +// return NULL; +// } - SQueryFilePos* cur = &pTsdbReadHandle->cur; +// static void* destroyTableCheckInfo(SArray* pTableCheckInfo) { +// size_t size = taosArrayGetSize(pTableCheckInfo); +// for (int32_t i = 0; i < size; ++i) { +// STableBlockScanInfo* p = taosArrayGet(pTableCheckInfo, i); +// destroyTableMemIterator(p); - STSRow* pRow = NULL; - TSKEY key = TSKEY_INITIAL_VAL; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; - TSKEY lastRowKey = TSKEY_INITIAL_VAL; - int32_t curRow = 0; +// taosMemoryFreeClear(p->pCompInfo); +// } - if (++pTsdbReadHandle->activeIndex < numOfTables) { - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); - // int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key); - // if (ret != TSDB_CODE_SUCCESS) { - // return false; - // } - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, pRow, NULL, numOfCols, - pCheckInfo->tableId, NULL, NULL, true, &lastRowKey); - taosMemoryFreeClear(pRow); +// taosArrayDestroy(pTableCheckInfo); +// return NULL; +// } - // update the last key value - pCheckInfo->lastKey = key + step; +// ====================================== EXPOSED APIs ====================================== +int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTableList, STsdbReader** ppReader, + const char* idstr) { + int32_t code = tsdbReaderCreate(pVnode, pCond, ppReader, idstr); + if (code) { + goto _err; + } + + if (pCond->suid != 0) { + (*ppReader)->pSchema = metaGetTbTSchema((*ppReader)->pTsdb->pVnode->pMeta, (*ppReader)->suid, -1); + ASSERT((*ppReader)->pSchema); + } else if (taosArrayGetSize(pTableList) > 0) { + STableKeyInfo* pKey = taosArrayGet(pTableList, 0); + (*ppReader)->pSchema = metaGetTbTSchema((*ppReader)->pTsdb->pVnode->pMeta, pKey->uid, -1); + } + + STsdbReader* pReader = *ppReader; + if (isEmptyQueryTimeWindow(&pReader->window)) { + tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pReader, pReader->idStr); + return TSDB_CODE_SUCCESS; + } - cur->rows = 1; // only one row - cur->lastKey = key + step; - cur->mixBlock = true; - cur->win.skey = key; - cur->win.ekey = key; + int32_t numOfTables = taosArrayGetSize(pTableList); + pReader->status.pTableMap = createDataBlockScanInfo(pReader, pTableList->pData, numOfTables); + if (pReader->status.pTableMap == NULL) { + tsdbReaderClose(pReader); + *ppReader = NULL; - return true; + code = TSDB_CODE_TDB_OUT_OF_MEMORY; + goto _err; } - return false; -} + SDataBlockIter* pBlockIter = &pReader->status.blockIter; -// static bool loadCachedLast(STsdbReadHandle* pTsdbReadHandle) { -// // the last row is cached in buffer, return it directly. -// // here note that the pTsdbReadHandle->window must be the TS_INITIALIZER -// int32_t tgNumOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); -// size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); -// int32_t numOfRows = 0; -// assert(numOfTables > 0 && tgNumOfCols > 0); -// SQueryFilePos* cur = &pTsdbReadHandle->cur; -// TSKEY priKey = TSKEY_INITIAL_VAL; -// int32_t priIdx = -1; -// SColumnInfoData* pColInfo = NULL; -// -// while (++pTsdbReadHandle->activeIndex < numOfTables) { -// STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); -// STable* pTable = pCheckInfo->pTableObj; -// char* pData = NULL; -// -// int32_t numOfCols = pTable->maxColNum; -// -// if (pTable->lastCols == NULL || pTable->maxColNum <= 0) { -// tsdbWarn("no last cached for table %s, uid:%" PRIu64 ",tid:%d", pTable->name->data, pTable->uid, -// pTable->tableId); continue; -// } -// -// int32_t i = 0, j = 0; -// while(i < tgNumOfCols && j < numOfCols) { -// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); -// if (pTable->lastCols[j].colId < pColInfo->info.colId) { -// j++; -// continue; -// } else if (pTable->lastCols[j].colId > pColInfo->info.colId) { -// i++; -// continue; -// } -// -// pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; -// -// if (pTable->lastCols[j].bytes > 0) { -// void* value = pTable->lastCols[j].pData; -// switch (pColInfo->info.type) { -// case TSDB_DATA_TYPE_BINARY: -// case TSDB_DATA_TYPE_NCHAR: -// memcpy(pData, value, varDataTLen(value)); -// break; -// case TSDB_DATA_TYPE_NULL: -// case TSDB_DATA_TYPE_BOOL: -// case TSDB_DATA_TYPE_TINYINT: -// case TSDB_DATA_TYPE_UTINYINT: -// *(uint8_t *)pData = *(uint8_t *)value; -// break; -// case TSDB_DATA_TYPE_SMALLINT: -// case TSDB_DATA_TYPE_USMALLINT: -// *(uint16_t *)pData = *(uint16_t *)value; -// break; -// case TSDB_DATA_TYPE_INT: -// case TSDB_DATA_TYPE_UINT: -// *(uint32_t *)pData = *(uint32_t *)value; -// break; -// case TSDB_DATA_TYPE_BIGINT: -// case TSDB_DATA_TYPE_UBIGINT: -// *(uint64_t *)pData = *(uint64_t *)value; -// break; -// case TSDB_DATA_TYPE_FLOAT: -// SET_FLOAT_PTR(pData, value); -// break; -// case TSDB_DATA_TYPE_DOUBLE: -// SET_DOUBLE_PTR(pData, value); -// break; -// case TSDB_DATA_TYPE_TIMESTAMP: -// if (pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) { -// priKey = tdGetKey(*(TKEY *)value); -// priIdx = i; -// -// i++; -// j++; -// continue; -// } else { -// *(TSKEY *)pData = *(TSKEY *)value; -// } -// break; -// default: -// memcpy(pData, value, pColInfo->info.bytes); -// } -// -// for (int32_t n = 0; n < tgNumOfCols; ++n) { -// if (n == i) { -// continue; -// } -// -// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, n); -// pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;; -// -// if (pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) { -//// *(TSKEY *)pData = pTable->lastCols[j].ts; -// continue; -// } -// -// if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { -// setVardataNull(pData, pColInfo->info.type); -// } else { -// setNull(pData, pColInfo->info.type, pColInfo->info.bytes); -// } -// } -// -// numOfRows++; -// assert(numOfRows < pTsdbReadHandle->outputCapacity); -// } -// -// i++; -// j++; -// } -// -// // leave the real ts column as the last row, because last function only (not stable) use the last row as res -// if (priKey != TSKEY_INITIAL_VAL) { -// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, priIdx); -// pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; -// -// *(TSKEY *)pData = priKey; -// -// for (int32_t n = 0; n < tgNumOfCols; ++n) { -// if (n == priIdx) { -// continue; -// } -// -// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, n); -// pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;; -// -// assert (pColInfo->info.colId != PRIMARYKEY_TIMESTAMP_COL_ID); -// -// if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { -// setVardataNull(pData, pColInfo->info.type); -// } else { -// setNull(pData, pColInfo->info.type, pColInfo->info.bytes); -// } -// } -// -// numOfRows++; -// } -// -// if (numOfRows > 0) { -// cur->rows = numOfRows; -// cur->mixBlock = true; -// -// return true; -// } -// } -// -// return false; -//} + STsdbFSState* pFState = pReader->pTsdb->fs->cState; + initFilesetIterator(&pReader->status.fileIter, pFState, pReader->order, pReader->idStr); + resetDataBlockIterator(&pReader->status.blockIter, pReader->order); -static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - assert(numOfTables > 0); + // no data in files, let's try buffer in memory + if (pReader->status.fileIter.numOfFiles == 0) { + pReader->status.loadFromFile = false; + } else { + code = initForFirstBlockInFile(pReader, pBlockIter); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + } - int64_t stime = taosGetTimestampUs(); + tsdbDebug("%p total numOfTable:%d in this query %s", pReader, numOfTables, pReader->idStr); + return code; - while (pTsdbReadHandle->activeIndex < numOfTables) { - if (loadBlockOfActiveTable(pTsdbReadHandle)) { - return true; - } +_err: + tsdbError("failed to create data reader, code: %s %s", tstrerror(code), pReader->idStr); + return code; +} - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); - pCheckInfo->numOfBlocks = 0; +void tsdbReaderClose(STsdbReader* pReader) { + if (pReader == NULL) { + return; + } - pTsdbReadHandle->activeIndex += 1; - pTsdbReadHandle->locateStart = false; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->cur.rows = 0; - pTsdbReadHandle->currentLoadExternalRows = pTsdbReadHandle->loadExternalRow; + blockDataDestroy(pReader->pResBlock); - terrno = TSDB_CODE_SUCCESS; + taosMemoryFreeClear(pReader->suppInfo.pstatis); + taosMemoryFreeClear(pReader->suppInfo.plist); + taosMemoryFree(pReader->suppInfo.slotIds); - int64_t elapsedTime = taosGetTimestampUs() - stime; - pTsdbReadHandle->cost.checkForNextTime += elapsedTime; + if (!isEmptyQueryTimeWindow(&pReader->window)) { + // tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); + } else { + ASSERT(pReader->status.pTableMap == NULL); } +#if 0 +// if (pReader->status.pTableScanInfo != NULL) { +// pReader->status.pTableScanInfo = destroyTableCheckInfo(pReader->status.pTableScanInfo); +// } - return false; -} +// tsdbDestroyReadH(&pReader->rhelper); -// handle data in cache situation -// bool tsdbNextDataBlock(tsdbReaderT pHandle, uint64_t uid) -bool tsdbNextDataBlock(tsdbReaderT pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; +// tdFreeDataCols(pReader->pDataCols); +// pReader->pDataCols = NULL; +// +// pReader->prev = doFreeColumnInfoData(pReader->prev); +// pReader->next = doFreeColumnInfoData(pReader->next); +#endif - size_t numOfCols = taosArrayGetSize(pTsdbReadHandle->pResBlock->pDataBlock); - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); - colInfoDataCleanup(pColInfo, pTsdbReadHandle->outputCapacity); - } + SIOCostSummary* pCost = &pReader->cost; - if (emptyQueryTimewindow(pTsdbReadHandle)) { - tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pTsdbReadHandle, - pTsdbReadHandle->idStr); - return false; - } + tsdbDebug("%p :io-cost summary: head-file read cnt:%" PRIu64 ", head-file time:%" PRIu64 " us, statis-info:%" PRId64 + " us, datablock:%" PRId64 " us, check data:%" PRId64 " us, %s", + pReader, pCost->headFileLoad, pCost->headFileLoadTime, pCost->statisInfoLoadTime, pCost->blockLoadTime, + pCost->checkForNextTime, pReader->idStr); - int64_t stime = taosGetTimestampUs(); - int64_t elapsedTime = stime; + taosMemoryFree(pReader->idStr); + taosMemoryFree(pReader->pSchema); + taosMemoryFreeClear(pReader); +} - // TODO refactor: remove "type" - if (pTsdbReadHandle->type == TSDB_QUERY_TYPE_LAST) { - if (pTsdbReadHandle->cachelastrow == TSDB_CACHED_TYPE_LASTROW) { - // return loadCachedLastRow(pTsdbReadHandle); - } else if (pTsdbReadHandle->cachelastrow == TSDB_CACHED_TYPE_LAST) { - // return loadCachedLast(pTsdbReadHandle); - } +bool tsdbNextDataBlock(STsdbReader* pReader) { + if (isEmptyQueryTimeWindow(&pReader->window)) { + return false; } - if (pTsdbReadHandle->loadType == BLOCK_LOAD_TABLE_SEQ_ORDER) { - return loadDataBlockFromTableSeq(pTsdbReadHandle); - } else { // loadType == RR and Offset Order - if (pTsdbReadHandle->checkFiles) { - // check if the query range overlaps with the file data block - bool exists = true; + // cleanup the data that belongs to the previous data block + SSDataBlock* pBlock = pReader->pResBlock; + blockDataCleanup(pBlock); - int32_t code = getDataBlocksInFiles(pTsdbReadHandle, &exists); - if (code != TSDB_CODE_SUCCESS) { - pTsdbReadHandle->activeIndex = 0; - pTsdbReadHandle->checkFiles = false; + int64_t stime = taosGetTimestampUs(); + int64_t elapsedTime = stime; + SReaderStatus* pStatus = &pReader->status; + if (pReader->type == BLOCK_LOAD_OFFSET_ORDER) { + if (pStatus->loadFromFile) { + int32_t code = buildBlockFromFiles(pReader); + if (code != TSDB_CODE_SUCCESS) { return false; } - if (exists) { - pTsdbReadHandle->cost.checkForNextTime += (taosGetTimestampUs() - stime); - return exists; + if (pBlock->info.rows > 0) { + return true; + } else { + buildBlockFromBufferSequentially(pReader); + return pBlock->info.rows > 0; } - - pTsdbReadHandle->activeIndex = 0; - pTsdbReadHandle->checkFiles = false; + } else { // no data in files, let's try the buffer + buildBlockFromBufferSequentially(pReader); + return pBlock->info.rows > 0; } - - // TODO: opt by consider the scan order - bool ret = doHasDataInBuffer(pTsdbReadHandle); - terrno = TSDB_CODE_SUCCESS; - - elapsedTime = taosGetTimestampUs() - stime; - pTsdbReadHandle->cost.checkForNextTime += elapsedTime; - return ret; + } else if (pReader->type == BLOCK_LOAD_TABLESEQ_ORDER) { + } else if (pReader->type == BLOCK_LOAD_EXTERN_ORDER) { + } else { + ASSERT(0); } + return false; } -// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, SMemTable* pMemRef) { -// STsdbReadHandle* pSecQueryHandle = NULL; -// -// if (type == TSDB_PREV_ROW && pTsdbReadHandle->prev) { -// return TSDB_CODE_SUCCESS; -// } -// -// if (type == TSDB_NEXT_ROW && pTsdbReadHandle->next) { -// return TSDB_CODE_SUCCESS; -// } -// -// // prepare the structure -// int32_t numOfCols = (int32_t) QH_GET_NUM_OF_COLS(pTsdbReadHandle); -// -// if (type == TSDB_PREV_ROW) { -// pTsdbReadHandle->prev = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); -// if (pTsdbReadHandle->prev == NULL) { -// terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; -// goto out_of_memory; -// } -// } else { -// pTsdbReadHandle->next = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); -// if (pTsdbReadHandle->next == NULL) { -// terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; -// goto out_of_memory; -// } -// } -// -// SArray* row = (type == TSDB_PREV_ROW)? pTsdbReadHandle->prev : pTsdbReadHandle->next; -// -// for (int32_t i = 0; i < numOfCols; ++i) { -// SColumnInfoData* pCol = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); -// -// SColumnInfoData colInfo = {{0}, 0}; -// colInfo.info = pCol->info; -// colInfo.pData = taosMemoryCalloc(1, pCol->info.bytes); -// if (colInfo.pData == NULL) { -// terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; -// goto out_of_memory; -// } -// -// taosArrayPush(row, &colInfo); -// } -// -// // load the previous row -// SQueryTableDataCond cond = {.numOfCols = numOfCols, .loadExternalRows = false, .type = BLOCK_LOAD_OFFSET_SEQ_ORDER}; -// if (type == TSDB_PREV_ROW) { -// cond.order = TSDB_ORDER_DESC; -// cond.twindow = (STimeWindow){pTsdbReadHandle->window.skey, INT64_MIN}; -// } else { -// cond.order = TSDB_ORDER_ASC; -// cond.twindow = (STimeWindow){pTsdbReadHandle->window.skey, INT64_MAX}; -// } -// -// cond.colList = taosMemoryCalloc(cond.numOfCols, sizeof(SColumnInfo)); -// if (cond.colList == NULL) { -// terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; -// goto out_of_memory; -// } -// -// for (int32_t i = 0; i < cond.numOfCols; ++i) { -// SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); -// memcpy(&cond.colList[i], &pColInfoData->info, sizeof(SColumnInfo)); -// } -// -// pSecQueryHandle = tsdbQueryTablesImpl(pTsdbReadHandle->pTsdb, &cond, pTsdbReadHandle->idStr, pMemRef); -// taosMemoryFreeClear(cond.colList); -// -// // current table, only one table -// STableCheckInfo* pCurrent = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); -// -// SArray* psTable = NULL; -// pSecQueryHandle->pTableCheckInfo = createCheckInfoFromCheckInfo(pCurrent, pSecQueryHandle->window.skey, &psTable); -// if (pSecQueryHandle->pTableCheckInfo == NULL) { -// taosArrayDestroy(psTable); -// terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; -// goto out_of_memory; -// } -// -// -// tsdbMayTakeMemSnapshot(pSecQueryHandle, psTable); -// if (!tsdbNextDataBlock((void*)pSecQueryHandle)) { -// // no result in current query, free the corresponding result rows structure -// if (type == TSDB_PREV_ROW) { -// pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); -// } else { -// pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); -// } -// -// goto out_of_memory; -// } -// -// SDataBlockInfo blockInfo = {{0}, 0}; -// tsdbRetrieveDataBlockInfo((void*)pSecQueryHandle, &blockInfo); -// tsdbRetrieveDataBlock((void*)pSecQueryHandle, pSecQueryHandle->defaultLoadColumn); -// -// row = (type == TSDB_PREV_ROW)? pTsdbReadHandle->prev:pTsdbReadHandle->next; -// int32_t pos = (type == TSDB_PREV_ROW)?pSecQueryHandle->cur.rows - 1:0; -// -// for (int32_t i = 0; i < numOfCols; ++i) { -// SColumnInfoData* pCol = taosArrayGet(row, i); -// SColumnInfoData* s = taosArrayGet(pSecQueryHandle->pColumns, i); -// memcpy((char*)pCol->pData, (char*)s->pData + s->info.bytes * pos, pCol->info.bytes); -// } -// -// out_of_memory: -// tsdbCleanupReadHandle(pSecQueryHandle); -// return terrno; -//} - -bool tsdbGetExternalRow(tsdbReaderT pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - SQueryFilePos* cur = &pTsdbReadHandle->cur; - - cur->fid = INT32_MIN; - cur->mixBlock = true; - if (pTsdbReadHandle->prev == NULL || pTsdbReadHandle->next == NULL) { - cur->rows = 0; - return false; - } - - int32_t numOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); - SColumnInfoData* first = taosArrayGet(pTsdbReadHandle->prev, i); - - memcpy(pColInfoData->pData, first->pData, pColInfoData->info.bytes); +void tsdbRetrieveDataBlockInfo(STsdbReader* pReader, SDataBlockInfo* pDataBlockInfo) { + ASSERT(pDataBlockInfo != NULL && pReader != NULL); + pDataBlockInfo->rows = pReader->pResBlock->info.rows; + pDataBlockInfo->uid = pReader->pResBlock->info.uid; + pDataBlockInfo->window = pReader->pResBlock->info.window; +} - SColumnInfoData* sec = taosArrayGet(pTsdbReadHandle->next, i); - memcpy(((char*)pColInfoData->pData) + pColInfoData->info.bytes, sec->pData, pColInfoData->info.bytes); +int32_t tsdbRetrieveDataBlockStatisInfo(STsdbReader* pReader, SColumnDataAgg*** pBlockStatis, bool* allHave) { + int32_t code = 0; + *allHave = false; - if (i == 0 && pColInfoData->info.type == TSDB_DATA_TYPE_TIMESTAMP) { - cur->win.skey = *(TSKEY*)pColInfoData->pData; - cur->win.ekey = *(TSKEY*)(((char*)pColInfoData->pData) + TSDB_KEYSIZE); - } + if (pReader->status.composedDataBlock) { + *pBlockStatis = NULL; + return TSDB_CODE_SUCCESS; } - cur->rows = 2; - return true; + // SFileBlockInfo* pBlockInfo = &pReader->pDataBlockInfo[c->slot]; + // assert((c->slot >= 0 && c->slot < pReader->numOfBlocks) || ((c->slot == pReader->numOfBlocks) && (c->slot == 0))); + + // // file block with sub-blocks has no statistics data + // if (pBlockInfo->compBlock->numOfSubBlocks > 1) { + // *pBlockStatis = NULL; + // return TSDB_CODE_SUCCESS; + // } + + // int64_t stime = taosGetTimestampUs(); + // int statisStatus = tsdbLoadBlockStatis(&pReader->rhelper, pBlockInfo->compBlock); + // if (statisStatus < TSDB_STATIS_OK) { + // return terrno; + // } else if (statisStatus > TSDB_STATIS_OK) { + // *pBlockStatis = NULL; + // return TSDB_CODE_SUCCESS; + // } + + // tsdbDebug("vgId:%d, succeed to load block statis part for uid %" PRIu64, REPO_ID(pReader->pTsdb), + // TSDB_READ_TABLE_UID(&pReader->rhelper)); + + // int16_t* colIds = pReader->suppInfo.defaultLoadColumn->pData; + + // size_t numOfCols = QH_GET_NUM_OF_COLS(pReader); + // memset(pReader->suppInfo.plist, 0, numOfCols * POINTER_BYTES); + // memset(pReader->suppInfo.pstatis, 0, numOfCols * sizeof(SColumnDataAgg)); + + // for (int32_t i = 0; i < numOfCols; ++i) { + // pReader->suppInfo.pstatis[i].colId = colIds[i]; + // } + + // *allHave = true; + // tsdbGetBlockStatis(&pReader->rhelper, pReader->suppInfo.pstatis, (int)numOfCols, pBlockInfo->compBlock); + + // // always load the first primary timestamp column data + // SColumnDataAgg* pPrimaryColStatis = &pReader->suppInfo.pstatis[0]; + // assert(pPrimaryColStatis->colId == PRIMARYKEY_TIMESTAMP_COL_ID); + + // pPrimaryColStatis->numOfNull = 0; + // pPrimaryColStatis->min = pBlockInfo->compBlock->minKey.ts; + // pPrimaryColStatis->max = pBlockInfo->compBlock->maxKey.ts; + // pReader->suppInfo.plist[0] = &pReader->suppInfo.pstatis[0]; + + // // update the number of NULL data rows + // int32_t* slotIds = pReader->suppInfo.slotIds; + // for (int32_t i = 1; i < numOfCols; ++i) { + // ASSERT(colIds[i] == pReader->pSchema->columns[slotIds[i]].colId); + // if (IS_BSMA_ON(&(pReader->pSchema->columns[slotIds[i]]))) { + // if (pReader->suppInfo.pstatis[i].numOfNull == -1) { // set the column data are all NULL + // pReader->suppInfo.pstatis[i].numOfNull = pBlockInfo->compBlock->numOfRows; + // } + + // pReader->suppInfo.plist[i] = &pReader->suppInfo.pstatis[i]; + // } else { + // *allHave = false; + // } + // } + + // int64_t elapsed = taosGetTimestampUs() - stime; + // pReader->cost.statisInfoLoadTime += elapsed; + + // *pBlockStatis = pReader->suppInfo.plist; + return code; } -/* - * if lastRow == NULL, return TSDB_CODE_TDB_NO_CACHE_LAST_ROW - * else set pRes and return TSDB_CODE_SUCCESS and save lastKey - */ -// int32_t tsdbGetCachedLastRow(STable* pTable, STSRow** pRes, TSKEY* lastKey) { -// int32_t code = TSDB_CODE_SUCCESS; -// -// TSDB_RLOCK_TABLE(pTable); -// -// if (!pTable->lastRow) { -// code = TSDB_CODE_TDB_NO_CACHE_LAST_ROW; -// goto out; -// } -// -// if (pRes) { -// *pRes = tdMemRowDup(pTable->lastRow); -// if (*pRes == NULL) { -// code = TSDB_CODE_TDB_OUT_OF_MEMORY; -// } -// } -// -// out: -// TSDB_RUNLOCK_TABLE(pTable); -// return code; -//} - -bool isTsdbCacheLastRow(tsdbReaderT* pReader) { - return ((STsdbReadHandle*)pReader)->cachelastrow > TSDB_CACHED_TYPE_NONE; -} - -int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableListInfo* tableList) { - assert(pTsdbReadHandle != NULL && tableList != NULL); - - // TSKEY key = TSKEY_INITIAL_VAL; - // - // SArray* group = taosArrayGetP(groupList->pGroupList, 0); - // assert(group != NULL); - // - // STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(group, 0); - // - // int32_t code = 0; - // - // if (((STable*)pInfo->pTable)->lastRow) { - // code = tsdbGetCachedLastRow(pInfo->pTable, NULL, &key); - // if (code != TSDB_CODE_SUCCESS) { - // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_NONE; - // } else { - // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LASTROW; - // } - // } - // - // // update the tsdb query time range - // if (pTsdbReadHandle->cachelastrow != TSDB_CACHED_TYPE_NONE) { - // pTsdbReadHandle->window = TSWINDOW_INITIALIZER; - // pTsdbReadHandle->checkFiles = false; - // pTsdbReadHandle->activeIndex = -1; // start from -1 - // } +SArray* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) { + SReaderStatus* pStatus = &pReader->status; - return TSDB_CODE_SUCCESS; -} + if (pStatus->composedDataBlock) { + return pReader->pResBlock->pDataBlock; + } -int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle) { - assert(pTsdbReadHandle != NULL); + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pStatus->blockIter); + STableBlockScanInfo* pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pFBlock->uid, sizeof(pFBlock->uid)); - int32_t code = 0; - // if (pTsdbReadHandle->pTsdb && atomic_load_8(&pTsdbReadHandle->pTsdb->hasCachedLastColumn)){ - // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LAST; - // } + int32_t code = tBlockDataInit(&pStatus->fileBlockData); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return NULL; + } - // update the tsdb query time range - if (pTsdbReadHandle->cachelastrow) { - pTsdbReadHandle->checkFiles = false; - pTsdbReadHandle->activeIndex = -1; // start from -1 + code = doLoadFileBlockData(pReader, &pStatus->blockIter, pBlockScanInfo, &pStatus->fileBlockData); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return NULL; } - return code; + copyBlockDataToSDataBlock(pReader, pBlockScanInfo); + return pReader->pResBlock->pDataBlock; } -STimeWindow updateLastrowForEachGroup(STableListInfo* pList) { - STimeWindow window = {INT64_MAX, INT64_MIN}; - - // int32_t totalNumOfTable = 0; - // SArray* emptyGroup = taosArrayInit(16, sizeof(int32_t)); - // - // // NOTE: starts from the buffer in case of descending timestamp order check data blocks - // size_t numOfGroups = taosArrayGetSize(groupList->pGroupList); - // for (int32_t j = 0; j < numOfGroups; ++j) { - // SArray* pGroup = taosArrayGetP(groupList->pGroupList, j); - // TSKEY key = TSKEY_INITIAL_VAL; - // - // STableKeyInfo keyInfo = {0}; - // - // size_t numOfTables = taosArrayGetSize(pGroup); - // for (int32_t i = 0; i < numOfTables; ++i) { - // STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(pGroup, i); - // - // // if the lastKey equals to INT64_MIN, there is no data in this table - // TSKEY lastKey = 0; //((STable*)(pInfo->pTable))->lastKey; - // if (key < lastKey) { - // key = lastKey; - // - // // keyInfo.pTable = pInfo->pTable; - // keyInfo.lastKey = key; - // pInfo->lastKey = key; - // - // if (key < window.skey) { - // window.skey = key; - // } - // - // if (key > window.ekey) { - // window.ekey = key; - // } - // } - // } - // - // // more than one table in each group, only one table left for each group - // // if (keyInfo.pTable != NULL) { - // // totalNumOfTable++; - // // if (taosArrayGetSize(pGroup) == 1) { - // // // do nothing - // // } else { - // // taosArrayClear(pGroup); - // // taosArrayPush(pGroup, &keyInfo); - // // } - // // } else { // mark all the empty groups, and remove it later - // // taosArrayDestroy(pGroup); - // // taosArrayPush(emptyGroup, &j); - // // } - // } - // - // // window does not being updated, so set the original - // if (window.skey == INT64_MAX && window.ekey == INT64_MIN) { - // window = TSWINDOW_INITIALIZER; - // assert(totalNumOfTable == 0 && taosArrayGetSize(groupList->pGroupList) == numOfGroups); - // } - // - // taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t)taosArrayGetSize(emptyGroup)); - // taosArrayDestroy(emptyGroup); - // - // groupList->numOfTables = totalNumOfTable; - return window; -} - -void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDataBlockInfo) { - STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; - SQueryFilePos* cur = &pHandle->cur; - - uint64_t uid = 0; - - // there are data in file - if (pHandle->cur.fid != INT32_MIN) { - STableBlockInfo* pBlockInfo = &pHandle->pDataBlockInfo[cur->slot]; - uid = pBlockInfo->pTableCheckInfo->tableId; - } else { - STableCheckInfo* pCheckInfo = taosArrayGet(pHandle->pTableCheckInfo, pHandle->activeIndex); - uid = pCheckInfo->tableId; +int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond, int32_t tWinIdx) { + if (isEmptyQueryTimeWindow(&pReader->window)) { + return TSDB_CODE_SUCCESS; } - tsdbDebug("data block generated, uid:%" PRIu64 " numOfRows:%d, tsrange:%" PRId64 " - %" PRId64 " %s", uid, cur->rows, - cur->win.skey, cur->win.ekey, pHandle->idStr); + setQueryTimewindow(pReader, pCond, tWinIdx); - pDataBlockInfo->uid = uid; + pReader->order = pCond->order; + pReader->type = BLOCK_LOAD_OFFSET_ORDER; + pReader->status.loadFromFile = true; + pReader->status.pTableIter = NULL; -#if 0 - // for multi-group data query processing test purpose - pDataBlockInfo->groupId = uid; -#endif + pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows[tWinIdx]); - pDataBlockInfo->rows = cur->rows; - pDataBlockInfo->window = cur->win; -} + // allocate buffer in order to load data blocks from file + memset(pReader->suppInfo.pstatis, 0, sizeof(SColumnDataAgg)); + memset(pReader->suppInfo.plist, 0, POINTER_BYTES); -/* - * return null for mixed data block, if not a complete file data block, the statistics value will always return NULL - */ -int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SColumnDataAgg*** pBlockStatis, bool* allHave) { - STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; - *allHave = false; + // todo set the correct numOfTables + int32_t numOfTables = 1; + SDataBlockIter* pBlockIter = &pReader->status.blockIter; - SQueryFilePos* c = &pHandle->cur; - if (c->mixBlock) { - *pBlockStatis = NULL; - return TSDB_CODE_SUCCESS; + STsdbFSState* pFState = pReader->pTsdb->fs->cState; + initFilesetIterator(&pReader->status.fileIter, pFState, pReader->order, pReader->idStr); + resetDataBlockIterator(&pReader->status.blockIter, pReader->order); + resetDataBlockScanInfo(pReader->status.pTableMap); + + int32_t code = 0; + // no data in files, let's try buffer in memory + if (pReader->status.fileIter.numOfFiles == 0) { + pReader->status.loadFromFile = false; + } else { + code = initForFirstBlockInFile(pReader, pBlockIter); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } - STableBlockInfo* pBlockInfo = &pHandle->pDataBlockInfo[c->slot]; - assert((c->slot >= 0 && c->slot < pHandle->numOfBlocks) || ((c->slot == pHandle->numOfBlocks) && (c->slot == 0))); + tsdbDebug("%p reset reader, suid:%" PRIu64 ", numOfTables:%d, query range:%" PRId64 " - %" PRId64 " in query %s", + pReader, pReader->suid, numOfTables, pReader->window.skey, pReader->window.ekey, pReader->idStr); + return code; +} - // file block with sub-blocks has no statistics data - if (pBlockInfo->compBlock->numOfSubBlocks > 1) { - *pBlockStatis = NULL; - return TSDB_CODE_SUCCESS; - } +int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTableBlockInfo) { + int32_t code = 0; + // pTableBlockInfo->totalSize = 0; + // pTableBlockInfo->totalRows = 0; - int64_t stime = taosGetTimestampUs(); - int statisStatus = tsdbLoadBlockStatis(&pHandle->rhelper, pBlockInfo->compBlock); - if (statisStatus < TSDB_STATIS_OK) { - return terrno; - } else if (statisStatus > TSDB_STATIS_OK) { - *pBlockStatis = NULL; - return TSDB_CODE_SUCCESS; - } + // STsdbFS* pFileHandle = REPO_FS(pReader->pTsdb); - tsdbDebug("vgId:%d, succeed to load block statis part for uid %" PRIu64, REPO_ID(pHandle->pTsdb), - TSDB_READ_TABLE_UID(&pHandle->rhelper)); + // // find the start data block in file + // pReader->locateStart = true; + // STsdbKeepCfg* pCfg = REPO_KEEP_CFG(pReader->pTsdb); + // int32_t fid = getFileIdFromKey(pReader->window.skey, pCfg->days, pCfg->precision); - int16_t* colIds = pHandle->suppInfo.defaultLoadColumn->pData; + // tsdbRLockFS(pFileHandle); + // tsdbFSIterInit(&pReader->fileIter, pFileHandle, pReader->order); + // tsdbFSIterSeek(&pReader->fileIter, fid); + // tsdbUnLockFS(pFileHandle); - size_t numOfCols = QH_GET_NUM_OF_COLS(pHandle); - memset(pHandle->suppInfo.plist, 0, numOfCols * POINTER_BYTES); - memset(pHandle->suppInfo.pstatis, 0, numOfCols * sizeof(SColumnDataAgg)); + // STsdbCfg* pc = REPO_CFG(pReader->pTsdb); + // pTableBlockInfo->defMinRows = pc->minRows; + // pTableBlockInfo->defMaxRows = pc->maxRows; - for (int32_t i = 0; i < numOfCols; ++i) { - pHandle->suppInfo.pstatis[i].colId = colIds[i]; - } + // int32_t bucketRange = ceil((pc->maxRows - pc->minRows) / 20.0); - *allHave = true; - tsdbGetBlockStatis(&pHandle->rhelper, pHandle->suppInfo.pstatis, (int)numOfCols, pBlockInfo->compBlock); + // pTableBlockInfo->numOfFiles += 1; - // always load the first primary timestamp column data - SColumnDataAgg* pPrimaryColStatis = &pHandle->suppInfo.pstatis[0]; - assert(pPrimaryColStatis->colId == PRIMARYKEY_TIMESTAMP_COL_ID); + // int32_t code = TSDB_CODE_SUCCESS; + // int32_t numOfBlocks = 0; + // int32_t numOfTables = (int32_t)taosArrayGetSize(pReader->pTableCheckInfo); + // int defaultRows = 4096; + // STimeWindow win = TSWINDOW_INITIALIZER; - pPrimaryColStatis->numOfNull = 0; - pPrimaryColStatis->min = pBlockInfo->compBlock->minKey.ts; - pPrimaryColStatis->max = pBlockInfo->compBlock->maxKey.ts; - pHandle->suppInfo.plist[0] = &pHandle->suppInfo.pstatis[0]; + // while (true) { + // numOfBlocks = 0; + // tsdbRLockFS(REPO_FS(pReader->pTsdb)); - // update the number of NULL data rows - int32_t* slotIds = pHandle->suppInfo.slotIds; - for (int32_t i = 1; i < numOfCols; ++i) { - ASSERT(colIds[i] == pHandle->pSchema->columns[slotIds[i]].colId); - if (IS_BSMA_ON(&(pHandle->pSchema->columns[slotIds[i]]))) { - if (pHandle->suppInfo.pstatis[i].numOfNull == -1) { // set the column data are all NULL - pHandle->suppInfo.pstatis[i].numOfNull = pBlockInfo->compBlock->numOfRows; - } + // if ((pReader->pFileGroup = tsdbFSIterNext(&pReader->fileIter)) == NULL) { + // tsdbUnLockFS(REPO_FS(pReader->pTsdb)); + // break; + // } - pHandle->suppInfo.plist[i] = &pHandle->suppInfo.pstatis[i]; - } else { - *allHave = false; - } - } + // tsdbGetFidKeyRange(pCfg->days, pCfg->precision, pReader->pFileGroup->fid, &win.skey, &win.ekey); - int64_t elapsed = taosGetTimestampUs() - stime; - pHandle->cost.statisInfoLoadTime += elapsed; + // // current file are not overlapped with query time window, ignore remain files + // if ((win.skey > pReader->window.ekey) /* || (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)*/) { + // tsdbUnLockFS(REPO_FS(pReader->pTsdb)); + // tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pReader, + // pReader->window.skey, pReader->window.ekey, pReader->idStr); + // pReader->pFileGroup = NULL; + // break; + // } - *pBlockStatis = pHandle->suppInfo.plist; - return TSDB_CODE_SUCCESS; -} + // pTableBlockInfo->numOfFiles += 1; + // if (tsdbSetAndOpenReadFSet(&pReader->rhelper, pReader->pFileGroup) < 0) { + // tsdbUnLockFS(REPO_FS(pReader->pTsdb)); + // code = terrno; + // break; + // } -SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) { - /** - * In the following two cases, the data has been loaded to SColumnInfoData. - * 1. data is from cache, 2. data block is not completed qualified to query time range - */ - STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; - if (pHandle->cur.fid == INT32_MIN) { - return pHandle->pResBlock->pDataBlock; - } else { - STableBlockInfo* pBlockInfo = &pHandle->pDataBlockInfo[pHandle->cur.slot]; - STableCheckInfo* pCheckInfo = pBlockInfo->pTableCheckInfo; + // tsdbUnLockFS(REPO_FS(pReader->pTsdb)); - if (pHandle->cur.mixBlock) { - return pHandle->pResBlock->pDataBlock; - } else { - SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlockInfo->compBlock); - assert(pHandle->realNumOfRows <= binfo.rows); - - // data block has been loaded, todo extract method - SDataBlockLoadInfo* pBlockLoadInfo = &pHandle->dataBlockLoadInfo; - - if (pBlockLoadInfo->slot == pHandle->cur.slot && pBlockLoadInfo->fileGroup->fid == pHandle->cur.fid && - pBlockLoadInfo->uid == pCheckInfo->tableId) { - return pHandle->pResBlock->pDataBlock; - } else { // only load the file block - SBlock* pBlock = pBlockInfo->compBlock; - if (doLoadFileDataBlock(pHandle, pBlock, pCheckInfo, pHandle->cur.slot) != TSDB_CODE_SUCCESS) { - return NULL; - } + // if (tsdbLoadBlockIdx(&pReader->rhelper) < 0) { + // code = terrno; + // break; + // } - int32_t numOfRows = doCopyRowsFromFileBlock(pHandle, pHandle->outputCapacity, 0, 0, pBlock->numOfRows - 1); - return pHandle->pResBlock->pDataBlock; - } - } - } -} + // if ((code = getFileCompInfo(pReader, &numOfBlocks)) != TSDB_CODE_SUCCESS) { + // break; + // } -static void* doFreeColumnInfoData(SArray* pColumnInfoData) { - if (pColumnInfoData == NULL) { - return NULL; - } + // tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pReader, numOfBlocks, numOfTables, + // pReader->pFileGroup->fid, pReader->idStr); - size_t cols = taosArrayGetSize(pColumnInfoData); - for (int32_t i = 0; i < cols; ++i) { - SColumnInfoData* pColInfo = taosArrayGet(pColumnInfoData, i); - colDataDestroy(pColInfo); - } + // if (numOfBlocks == 0) { + // continue; + // } - taosArrayDestroy(pColumnInfoData); - return NULL; -} + // pTableBlockInfo->numOfBlocks += numOfBlocks; -static void* destroyTableCheckInfo(SArray* pTableCheckInfo) { - size_t size = taosArrayGetSize(pTableCheckInfo); - for (int32_t i = 0; i < size; ++i) { - STableCheckInfo* p = taosArrayGet(pTableCheckInfo, i); - destroyTableMemIterator(p); + // for (int32_t i = 0; i < numOfTables; ++i) { + // STableBlockScanInfo* pCheckInfo = taosArrayGet(pReader->pTableCheckInfo, i); - taosMemoryFreeClear(p->pCompInfo); - } + // SBlock* pBlock = pCheckInfo->pCompInfo->blocks; - taosArrayDestroy(pTableCheckInfo); - return NULL; -} + // for (int32_t j = 0; j < pCheckInfo->numOfBlocks; ++j) { + // pTableBlockInfo->totalSize += pBlock[j].len; -void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)queryHandle; - if (pTsdbReadHandle == NULL) { - return; - } + // int32_t numOfRows = pBlock[j].numOfRows; + // pTableBlockInfo->totalRows += numOfRows; - pTsdbReadHandle->pResBlock->pDataBlock = doFreeColumnInfoData(pTsdbReadHandle->pResBlock->pDataBlock); + // if (numOfRows > pTableBlockInfo->maxRows) { + // pTableBlockInfo->maxRows = numOfRows; + // } - taosArrayDestroy(pTsdbReadHandle->suppInfo.defaultLoadColumn); - taosMemoryFreeClear(pTsdbReadHandle->pDataBlockInfo); - taosMemoryFreeClear(pTsdbReadHandle->suppInfo.pstatis); - taosMemoryFreeClear(pTsdbReadHandle->suppInfo.plist); - taosMemoryFree(pTsdbReadHandle->suppInfo.slotIds); + // if (numOfRows < pTableBlockInfo->minRows) { + // pTableBlockInfo->minRows = numOfRows; + // } - if (!emptyQueryTimewindow(pTsdbReadHandle)) { - // tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); - } else { - assert(pTsdbReadHandle->pTableCheckInfo == NULL); - } + // if (numOfRows < defaultRows) { + // pTableBlockInfo->numOfSmallBlocks += 1; + // } - if (pTsdbReadHandle->pTableCheckInfo != NULL) { - pTsdbReadHandle->pTableCheckInfo = destroyTableCheckInfo(pTsdbReadHandle->pTableCheckInfo); - } + // int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows); + // pTableBlockInfo->blockRowsHisto[bucketIndex]++; + // } + // } + // } - tsdbDestroyReadH(&pTsdbReadHandle->rhelper); + // pTableBlockInfo->numOfTables = numOfTables; + return code; +} - tdFreeDataCols(pTsdbReadHandle->pDataCols); - pTsdbReadHandle->pDataCols = NULL; +int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) { + int64_t rows = 0; - pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); - pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); + SReaderStatus* pStatus = &pReader->status; + pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL); - SIOCostSummary* pCost = &pTsdbReadHandle->cost; + while (pStatus->pTableIter != NULL) { + STableBlockScanInfo* pBlockScanInfo = pStatus->pTableIter; - tsdbDebug("%p :io-cost summary: head-file read cnt:%" PRIu64 ", head-file time:%" PRIu64 " us, statis-info:%" PRId64 - " us, datablock:%" PRId64 " us, check data:%" PRId64 " us, %s", - pTsdbReadHandle, pCost->headFileLoad, pCost->headFileLoadTime, pCost->statisInfoLoadTime, - pCost->blockLoadTime, pCost->checkForNextTime, pTsdbReadHandle->idStr); + STbData* d = NULL; + if (pReader->pTsdb->mem != NULL) { + tsdbGetTbDataFromMemTable(pReader->pTsdb->mem, pReader->suid, pBlockScanInfo->uid, &d); + if (d != NULL) { + rows += tsdbGetNRowsInTbData(d); + } + } + + STbData* di = NULL; + if (pReader->pTsdb->imem != NULL) { + tsdbGetTbDataFromMemTable(pReader->pTsdb->imem, pReader->suid, pBlockScanInfo->uid, &di); + if (di != NULL) { + rows += tsdbGetNRowsInTbData(di); + } + } + + // current table is exhausted, let's try the next table + pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, pStatus->pTableIter); + } - taosMemoryFree(pTsdbReadHandle->idStr); - taosMemoryFree(pTsdbReadHandle->pSchema); - taosMemoryFreeClear(pTsdbReadHandle); + return rows; } diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index 1c2514d46f2c04125b2d763ca5ffa2fb68d307cb..fe0d3a1b6f093a64e595c85f6ba97fecee3a5200 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -14,964 +14,3 @@ */ #include "tsdb.h" - -#define TSDB_KEY_COL_OFFSET 0 - -static void tsdbResetReadTable(SReadH *pReadh); -static void tsdbResetReadFile(SReadH *pReadh); -static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock); -static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, int8_t bitmapMode); -static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32_t len, int32_t bitmapLen, int8_t comp, - int numOfRows, int numOfBitmaps, int maxPoints, char *buffer, int bufferSize); -static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, const int16_t *colIds, - int numOfColIds, int8_t bitmapMode); -static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBlockCol *pBlockCol, SDataCol *pDataCol); - -int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo) { - ASSERT(pReadh != NULL && pRepo != NULL); - - STsdbCfg *pCfg = REPO_CFG(pRepo); - - memset((void *)pReadh, 0, sizeof(*pReadh)); - pReadh->pRepo = pRepo; - - TSDB_FSET_SET_CLOSED(TSDB_READ_FSET(pReadh)); - - pReadh->aBlkIdx = taosArrayInit(1024, sizeof(SBlockIdx)); - if (pReadh->aBlkIdx == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - - pReadh->pDCols[0] = tdNewDataCols(0, pCfg->maxRows); - if (pReadh->pDCols[0] == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tsdbDestroyReadH(pReadh); - return -1; - } - - pReadh->pDCols[1] = tdNewDataCols(0, pCfg->maxRows); - if (pReadh->pDCols[1] == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - tsdbDestroyReadH(pReadh); - return -1; - } - - return 0; -} - -void tsdbDestroyReadH(SReadH *pReadh) { - if (pReadh == NULL) return; - - pReadh->pExBuf = taosTZfree(pReadh->pExBuf); - pReadh->pCBuf = taosTZfree(pReadh->pCBuf); - pReadh->pBuf = taosTZfree(pReadh->pBuf); - pReadh->pDCols[0] = tdFreeDataCols(pReadh->pDCols[0]); - pReadh->pDCols[1] = tdFreeDataCols(pReadh->pDCols[1]); - pReadh->pAggrBlkData = taosTZfree(pReadh->pAggrBlkData); - pReadh->pBlkData = taosTZfree(pReadh->pBlkData); - pReadh->pBlkInfo = taosTZfree(pReadh->pBlkInfo); - pReadh->cidx = 0; - pReadh->pBlkIdx = NULL; - pReadh->pTable = NULL; - pReadh->aBlkIdx = taosArrayDestroy(pReadh->aBlkIdx); - tsdbCloseDFileSet(TSDB_READ_FSET(pReadh)); - pReadh->pRepo = NULL; -} - -int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet) { - ASSERT(pSet != NULL); - tsdbResetReadFile(pReadh); - - pReadh->rSet = *pSet; - TSDB_FSET_SET_CLOSED(TSDB_READ_FSET(pReadh)); - // if (tsdbOpenDFileSet(TSDB_READ_FSET(pReadh), O_RDONLY) < 0) { - if (tsdbOpenDFileSet(TSDB_READ_FSET(pReadh), TD_FILE_READ) < 0) { - tsdbError("vgId:%d, failed to open file set %d since %s", TSDB_READ_REPO_ID(pReadh), TSDB_FSET_FID(pSet), - tstrerror(terrno)); - return -1; - } - - return 0; -} - -void tsdbCloseAndUnsetFSet(SReadH *pReadh) { tsdbResetReadFile(pReadh); } - -int tsdbLoadBlockIdx(SReadH *pReadh) { - SDFile *pHeadf = TSDB_READ_HEAD_FILE(pReadh); - SBlockIdx blkIdx; - - ASSERT(taosArrayGetSize(pReadh->aBlkIdx) == 0); - - // No data at all, just return - if (pHeadf->info.offset <= 0) return 0; - - if (tsdbSeekDFile(pHeadf, pHeadf->info.offset, SEEK_SET) < 0) { - tsdbError("vgId:%d, failed to load SBlockIdx part while seek file %s since %s, offset:%u len :%u", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pHeadf->info.offset, - pHeadf->info.len); - return -1; - } - - if (tsdbMakeRoom((void **)(&TSDB_READ_BUF(pReadh)), pHeadf->info.len) < 0) return -1; - - int64_t nread = tsdbReadDFile(pHeadf, TSDB_READ_BUF(pReadh), pHeadf->info.len); - if (nread < 0) { - tsdbError("vgId:%d, failed to load SBlockIdx part while read file %s since %s, offset:%u len :%u", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pHeadf->info.offset, - pHeadf->info.len); - return -1; - } - - if (nread < pHeadf->info.len) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, SBlockIdx part in file %s is corrupted, offset:%u expected bytes:%u read bytes: %" PRId64, - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pHeadf->info.offset, pHeadf->info.len, nread); - return -1; - } - - if (!taosCheckChecksumWhole((uint8_t *)TSDB_READ_BUF(pReadh), pHeadf->info.len)) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, SBlockIdx part in file %s is corrupted since wrong checksum, offset:%u len :%u", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pHeadf->info.offset, pHeadf->info.len); - return -1; - } - - void *ptr = TSDB_READ_BUF(pReadh); - int tsize = 0; - while (POINTER_DISTANCE(ptr, TSDB_READ_BUF(pReadh)) < (pHeadf->info.len - sizeof(TSCKSUM))) { - ptr = tsdbDecodeSBlockIdx(ptr, &blkIdx); - ASSERT(ptr != NULL); - - if (taosArrayPush(pReadh->aBlkIdx, (void *)(&blkIdx)) == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - - tsize++; - // ASSERT(tsize == 1 || ((SBlockIdx *)taosArrayGet(pReadh->aBlkIdx, tsize - 2))->tid < - // ((SBlockIdx *)taosArrayGet(pReadh->aBlkIdx, tsize - 1))->tid); - } - - return 0; -} - -static int32_t tsdbBlockIdxCmprFn(const void *p1, const void *p2) { - SBlockIdx *pBlockIdx1 = (SBlockIdx *)p1; - SBlockIdx *pBlockIdx2 = (SBlockIdx *)p2; - - if (pBlockIdx1->suid < pBlockIdx2->suid) { - return -1; - } else if (pBlockIdx1->suid > pBlockIdx2->suid) { - return 1; - } - - if (pBlockIdx1->uid < pBlockIdx2->uid) { - return -1; - } else if (pBlockIdx1->uid > pBlockIdx2->uid) { - return 1; - } - - return 0; -} -int tsdbSetReadTable(SReadH *pReadh, STable *pTable) { - STSchema *pSchema = tsdbGetTableSchemaImpl(TSDB_READ_REPO(pReadh), pTable, false, false, -1); - - pReadh->pTable = pTable; - - if (tdInitDataCols(pReadh->pDCols[0], pSchema) < 0) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - - if (tdInitDataCols(pReadh->pDCols[1], pSchema) < 0) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - - uint8_t *p = taosArraySearch(pReadh->aBlkIdx, &(SBlockIdx){.suid = pTable->suid, .uid = pTable->uid}, - tsdbBlockIdxCmprFn, TD_EQ); - if (p == NULL) { - pReadh->pBlkIdx = NULL; - } else { - pReadh->pBlkIdx = (SBlockIdx *)p; - } - - return 0; -} - -int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget) { - ASSERT(pReadh->pBlkIdx != NULL); - - SDFile *pHeadf = TSDB_READ_HEAD_FILE(pReadh); - SBlockIdx *pBlkIdx = pReadh->pBlkIdx; - - if (tsdbSeekDFile(pHeadf, pBlkIdx->offset, SEEK_SET) < 0) { - tsdbError("vgId:%d, failed to load SBlockInfo part while seek file %s since %s, offset:%u len:%u", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pBlkIdx->offset, pBlkIdx->len); - return -1; - } - - if (tsdbMakeRoom((void **)(&(pReadh->pBlkInfo)), pBlkIdx->len) < 0) return -1; - - int64_t nread = tsdbReadDFile(pHeadf, (void *)(pReadh->pBlkInfo), pBlkIdx->len); - if (nread < 0) { - tsdbError("vgId:%d, failed to load SBlockInfo part while read file %s since %s, offset:%u len :%u", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pBlkIdx->offset, pBlkIdx->len); - return -1; - } - - if (nread < pBlkIdx->len) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, SBlockInfo part in file %s is corrupted, offset:%u expected bytes:%u read bytes:%" PRId64, - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pBlkIdx->offset, pBlkIdx->len, nread); - return -1; - } - - if (!taosCheckChecksumWhole((uint8_t *)(pReadh->pBlkInfo), pBlkIdx->len)) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, SBlockInfo part in file %s is corrupted since wrong checksum, offset:%u len :%u", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pBlkIdx->offset, pBlkIdx->len); - return -1; - } - - // ASSERT(pBlkIdx->tid == pReadh->pBlkInfo->tid && pBlkIdx->uid == pReadh->pBlkInfo->uid); - - if (pTarget) { - memcpy(pTarget, (void *)(pReadh->pBlkInfo), pBlkIdx->len); - } - - return 0; -} - -static FORCE_INLINE void tsdbSwapDataCols(SDataCols *pDest, SDataCols *pSrc) { - SDataCol *pCols = pDest->cols; - memcpy(pDest, pSrc, sizeof(SDataCols)); - pSrc->cols = pCols; -} - -static void printTsdbLoadBlkData(SReadH *readh, SDataCols *pDCols, SBlock *pBlock, const char *tag, int32_t ln) { - printf("%s:%d:%" PRIi64 " ================\n", tag, ln, taosGetSelfPthreadId()); - if (pBlock) { - SDFile *pHeadf = TSDB_READ_HEAD_FILE(readh); - printf("%s:%d:%" PRIi64 ":%p:%d %s\n", tag, ln, taosGetSelfPthreadId(), pBlock, (int32_t)pBlock->len, - pHeadf->f.aname); - SDFile *pDFile = pBlock->last ? TSDB_READ_LAST_FILE(readh) : TSDB_READ_DATA_FILE(readh); - printf("%s:%d:%" PRIi64 ":%p:%d %s\n", tag, ln, taosGetSelfPthreadId(), pBlock, (int32_t)pBlock->len, - pDFile->f.aname); - } - SDataCol *pDCol = pDCols->cols + 0; - if (TSKEY_MIN == *(int64_t *)pDCol->pData) { - ASSERT(0); - } - - int rows = pDCols->numOfRows; - for (int r = 0; r < rows; ++r) { - if (pBlock) { - printf("%s:%d:%" PRIi64 ":%p:%d rows[%d][%d] ", tag, ln, taosGetSelfPthreadId(), pBlock, (int32_t)pBlock->len, - rows, r); - } else { - printf("%s:%d:%" PRIi64 ":%s rows[%d][%d] ", tag, ln, taosGetSelfPthreadId(), "=== merge === ", rows, r); - } - - int nDataCols = pDCols->numOfCols; - int j = 0; - SCellVal sVal = {0}; - while (j < nDataCols) { - SDataCol *pDataCol = pDCols->cols + j; - tdGetColDataOfRow(&sVal, pDataCol, r, pDCols->bitmapMode); - tdSCellValPrint(&sVal, pDataCol->type); - ++j; - } - printf("\n"); - } - - fflush(stdout); -} - -int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) { - ASSERT(pBlock->numOfSubBlocks > 0); - STsdbCfg *pCfg = REPO_CFG(pReadh->pRepo); - int8_t update = pCfg->update; - - SBlock *iBlock = pBlock; - if (pBlock->numOfSubBlocks > 1) { - if (pBlkInfo) { - iBlock = (SBlock *)POINTER_SHIFT(pBlkInfo, pBlock->offset); - } else { - iBlock = (SBlock *)POINTER_SHIFT(pReadh->pBlkInfo, pBlock->offset); - } - } - - if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[0], TSDB_BITMODE_ONE_BIT) < 0) return -1; -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkData(pReadh, pReadh->pDCols[0], iBlock, __func__, __LINE__); -#endif - for (int i = 1; i < pBlock->numOfSubBlocks; i++) { - iBlock++; - if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1], TSDB_BITMODE_DEFAULT) < 0) return -1; -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkData(pReadh, pReadh->pDCols[1], iBlock, __func__, __LINE__); -#endif - // TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version - if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL, - TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0) - return -1; -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkData(pReadh, pReadh->pDCols[0], iBlock, " === MERGE === ", __LINE__); -#endif - } - // if ((pBlock->numOfSubBlocks == 1) && (iBlock->hasDupKey)) { // TODO: use this line - if (pBlock->numOfSubBlocks == 1) { - tdResetDataCols(pReadh->pDCols[1]); - pReadh->pDCols[1]->bitmapMode = pReadh->pDCols[0]->bitmapMode; - if (tdMergeDataCols(pReadh->pDCols[1], pReadh->pDCols[0], pReadh->pDCols[0]->numOfRows, NULL, - TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0) { - return -1; - } - tsdbSwapDataCols(pReadh->pDCols[0], pReadh->pDCols[1]); - ASSERT(pReadh->pDCols[0]->bitmapMode != 0); -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkData(pReadh, pReadh->pDCols[0], iBlock, " === UPDATE FILTER === ", __LINE__); -#endif - } - - ASSERT(pReadh->pDCols[0]->numOfRows <= pBlock->numOfRows); - ASSERT(dataColsKeyFirst(pReadh->pDCols[0]) == pBlock->minKey.ts); - ASSERT(dataColsKeyLast(pReadh->pDCols[0]) == pBlock->maxKey.ts); - - return 0; -} - -static void printTsdbLoadBlkDataCols(SReadH *readh, SDataCols *pDCols, SBlock *pBlock, const int16_t *colIds, - int numOfColsIds, const char *tag, int32_t ln) { - printf("%s:%d:%" PRIi64 " ================\n", tag, ln, taosGetSelfPthreadId()); - if (pBlock) { - SDFile *pHeadf = TSDB_READ_HEAD_FILE(readh); - printf("%s:%d:%" PRIi64 ":%p:%d %s\n", tag, ln, taosGetSelfPthreadId(), pBlock, (int32_t)pBlock->len, - pHeadf->f.aname); - SDFile *pDFile = pBlock->last ? TSDB_READ_LAST_FILE(readh) : TSDB_READ_DATA_FILE(readh); - printf("%s:%d:%" PRIi64 ":%p:%d %s\n", tag, ln, taosGetSelfPthreadId(), pBlock, (int32_t)pBlock->len, - pDFile->f.aname); - } - - int rows = pDCols->numOfRows; - for (int r = 0; r < rows; ++r) { - if (pBlock) { - printf("%s:%d:%" PRIi64 ":%p:%d rows[%d][%d] ", tag, ln, taosGetSelfPthreadId(), pBlock, (int32_t)pBlock->len, - rows, r); - } else { - printf("%s:%d:%" PRIi64 ":%s rows[%d][%d] ", tag, ln, taosGetSelfPthreadId(), "=== merge === ", rows, r); - } - - int nDataCols = pDCols->numOfCols; - int j = 0, k = 0; - SCellVal sVal = {0}; - while (j < nDataCols) { - if (k >= numOfColsIds) break; - SDataCol *pDataCol = pDCols->cols + j; - int16_t colId1 = pDataCol->colId; - int16_t colId2 = *(colIds + k); - if (colId1 < colId2) { - ++j; - } else if (colId1 > colId2) { - ++k; // colId2 not exists in SDataCols - printf("NotExists "); - } else { - tdGetColDataOfRow(&sVal, pDataCol, r, pDCols->bitmapMode); - tdSCellValPrint(&sVal, pDataCol->type); - ++j; - ++k; - } - } - printf("\n"); - } - - fflush(stdout); -} - -// TODO: filter by Multi-Version -int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, int numOfColsIds, - bool mergeBitmap) { - ASSERT(pBlock->numOfSubBlocks > 0); - int8_t update = pReadh->pRepo->pVnode->config.tsdbCfg.update; - - SBlock *iBlock = pBlock; - if (pBlock->numOfSubBlocks > 1) { - if (pBlkInfo) { - iBlock = POINTER_SHIFT(pBlkInfo, pBlock->offset); - } else { - iBlock = POINTER_SHIFT(pReadh->pBlkInfo, pBlock->offset); - } - } - - if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[0], colIds, numOfColsIds, TSDB_BITMODE_ONE_BIT) < 0) - return -1; -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkDataCols(pReadh, pReadh->pDCols[0], iBlock, colIds, numOfColsIds, __func__, __LINE__); -#endif - for (int i = 1; i < pBlock->numOfSubBlocks; i++) { - iBlock++; - if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds, TSDB_BITMODE_DEFAULT) < 0) - return -1; -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkDataCols(pReadh, pReadh->pDCols[1], iBlock, colIds, numOfColsIds, __func__, __LINE__); -#endif - // TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version - if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL, - TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0) - return -1; -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkDataCols(pReadh, pReadh->pDCols[0], NULL, colIds, numOfColsIds, __func__, __LINE__); -#endif - } - // if ((pBlock->numOfSubBlocks == 1) && (iBlock->hasDupKey)) { // TODO: use this line - if (pBlock->numOfSubBlocks == 1) { - tdResetDataCols(pReadh->pDCols[1]); - pReadh->pDCols[1]->bitmapMode = pReadh->pDCols[0]->bitmapMode; - if (tdMergeDataCols(pReadh->pDCols[1], pReadh->pDCols[0], pReadh->pDCols[0]->numOfRows, NULL, - TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0) { - return -1; - } - tsdbSwapDataCols(pReadh->pDCols[0], pReadh->pDCols[1]); - ASSERT(pReadh->pDCols[0]->bitmapMode != 0); -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkDataCols(pReadh, pReadh->pDCols[0], NULL, colIds, numOfColsIds, - " === update filter === ", __LINE__); -#endif - } - - if (mergeBitmap && !tdDataColsIsBitmapI(pReadh->pDCols[0])) { - for (int i = 0; i < numOfColsIds; ++i) { - SDataCol *pDataCol = pReadh->pDCols[0]->cols + i; - if (pDataCol->len > 0 && pDataCol->bitmap) { - tdMergeBitmap(pDataCol->pBitmap, pReadh->pDCols[0]->numOfRows, pDataCol->pBitmap); - tdDataColsSetBitmapI(pReadh->pDCols[0]); - } - } -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printTsdbLoadBlkDataCols(pReadh, pReadh->pDCols[0], NULL, colIds, numOfColsIds, " === merge bitmap === ", __LINE__); -#endif - } - - ASSERT(pReadh->pDCols[0]->numOfRows <= pBlock->numOfRows); - ASSERT(dataColsKeyFirst(pReadh->pDCols[0]) == pBlock->minKey.ts); - ASSERT(dataColsKeyLast(pReadh->pDCols[0]) == pBlock->maxKey.ts); - - return 0; -} - -int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) { - ASSERT(pBlock->numOfSubBlocks <= 1); - - if (!pBlock->aggrStat) { - tsdbDebug("vgId:%d, no need to load block statis part for uid %" PRIu64 " since not exist", REPO_ID(pReadh->pRepo), - TSDB_READ_TABLE_UID(pReadh)); - return TSDB_STATIS_NONE; - } - - SDFile *pDFileAggr = pBlock->last ? TSDB_READ_SMAL_FILE(pReadh) : TSDB_READ_SMAD_FILE(pReadh); - - if (tsdbSeekDFile(pDFileAggr, pBlock->aggrOffset, SEEK_SET) < 0) { - tsdbError("vgId:%d, failed to load block statis part for uid %" PRIu64 " while seek file %s to offset %" PRIu64 - " since %s", - TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), - (uint64_t)pBlock->aggrOffset, tstrerror(terrno)); - return -1; - } - - size_t sizeAggr = tsdbBlockAggrSize(pBlock->numOfBSma, (uint32_t)pBlock->blkVer); - if (tsdbMakeRoom((void **)(&(pReadh->pAggrBlkData)), sizeAggr) < 0) return -1; - - int64_t nreadAggr = tsdbReadDFile(pDFileAggr, (void *)(pReadh->pAggrBlkData), sizeAggr); - if (nreadAggr < 0) { - tsdbError("vgId:%d, failed to load block statis part for uid %" PRIu64 - " while read file %s since %s, offset:%" PRIu64 " len :%" PRIzu, - TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), - tstrerror(terrno), (uint64_t)pBlock->aggrOffset, sizeAggr); - return -1; - } - - if (nreadAggr < sizeAggr) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, block statis part for uid %" PRIu64 " in file %s is corrupted, offset:%" PRIu64 - " expected bytes:%" PRIzu " read bytes: %" PRId64, - TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), - (uint64_t)pBlock->aggrOffset, sizeAggr, nreadAggr); - return -1; - } - - if (!taosCheckChecksumWhole((uint8_t *)(pReadh->pAggrBlkData), (uint32_t)sizeAggr)) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, block statis part for uid %" PRIu64 - "in file %s is corrupted since wrong checksum, offset:%" PRIu64 " len :%" PRIzu, - TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), - (uint64_t)pBlock->aggrOffset, sizeAggr); - return -1; - } - return 0; -} - -static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock) { - ASSERT(pBlock->numOfSubBlocks <= 1); - SDFile *pDFile = (pBlock->last) ? TSDB_READ_LAST_FILE(pReadh) : TSDB_READ_DATA_FILE(pReadh); - if (tsdbSeekDFile(pDFile, pBlock->offset, SEEK_SET) < 0) { - tsdbError("vgId:%d, failed to load block head part while seek file %s to offset %" PRId64 " since %s", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tstrerror(terrno)); - return -1; - } - - size_t size = tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer); - if (tsdbMakeRoom((void **)(&(pReadh->pBlkData)), size) < 0) return -1; - - int64_t nread = tsdbReadDFile(pDFile, (void *)(pReadh->pBlkData), size); - if (nread < 0) { - tsdbError("vgId:%d, failed to load block head part while read file %s since %s, offset:%" PRId64 " len :%" PRIzu, - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno), (int64_t)pBlock->offset, size); - return -1; - } - - if (nread < size) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, block head part in file %s is corrupted, offset:%" PRId64 " expected bytes:%" PRIzu - " read bytes: %" PRId64, - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, size, nread); - return -1; - } - - if (!taosCheckChecksumWhole((uint8_t *)(pReadh->pBlkData), (uint32_t)size)) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, block head part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%" PRIzu, - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, size); - return -1; - } - return 0; -} - -int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx) { - int tlen = 0; - - tlen += taosEncodeFixedU64(buf, pIdx->suid); - tlen += taosEncodeFixedU64(buf, pIdx->uid); - tlen += taosEncodeVariantU32(buf, pIdx->len); - tlen += taosEncodeVariantU32(buf, pIdx->offset); - tlen += taosEncodeFixedU8(buf, pIdx->hasLast); - tlen += taosEncodeVariantU32(buf, pIdx->numOfBlocks); - tlen += taosEncodeFixedU64(buf, pIdx->maxKey.ts); - - return tlen; -} - -void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx) { - uint8_t hasLast = 0; - uint32_t numOfBlocks = 0; - uint64_t value = 0; - - // if ((buf = taosDecodeVariantI32(buf, &(pIdx->tid))) == NULL) return NULL; - if ((buf = taosDecodeFixedU64(buf, &value)) == NULL) return NULL; - pIdx->suid = (int64_t)value; - if ((buf = taosDecodeFixedU64(buf, &value)) == NULL) return NULL; - pIdx->uid = (int64_t)value; - if ((buf = taosDecodeVariantU32(buf, &(pIdx->len))) == NULL) return NULL; - if ((buf = taosDecodeVariantU32(buf, &(pIdx->offset))) == NULL) return NULL; - if ((buf = taosDecodeFixedU8(buf, &(hasLast))) == NULL) return NULL; - pIdx->hasLast = hasLast; - if ((buf = taosDecodeVariantU32(buf, &(numOfBlocks))) == NULL) return NULL; - pIdx->numOfBlocks = numOfBlocks; - if ((buf = taosDecodeFixedU64(buf, &value)) == NULL) return NULL; - pIdx->maxKey.ts = (TSKEY)value; - - return buf; -} - -void tsdbGetBlockStatis(SReadH *pReadh, SColumnDataAgg *pStatis, int numOfCols, SBlock *pBlock) { -#ifdef TD_REFACTOR_3 - SBlockData *pBlockData = pReadh->pBlkData; - - for (int i = 0, j = 0; i < numOfCols;) { - if (j >= pBlockData->numOfCols) { - pStatis[i].numOfNull = -1; - ++i; - continue; - } - - if (pStatis[i].colId == pBlockData->cols[j].colId) { - pStatis[i].sum = pBlockData->cols[j].sum; - pStatis[i].max = pBlockData->cols[j].max; - pStatis[i].min = pBlockData->cols[j].min; - pStatis[i].maxIndex = pBlockData->cols[j].maxIndex; - pStatis[i].minIndex = pBlockData->cols[j].minIndex; - pStatis[i].numOfNull = pBlockData->cols[j].numOfNull; - ++i; - ++j; - } else if (pStatis[i].colId < pBlockData->cols[j].colId) { - pStatis[i].numOfNull = -1; - ++i; - } else { - ++j; - } - } -#else - if (pBlock->aggrStat) { - SAggrBlkData *pAggrBlkData = pReadh->pAggrBlkData; - - for (int i = 0, j = 0; i < numOfCols;) { - if (j >= pBlock->numOfBSma) { - pStatis[i].numOfNull = -1; - ++i; - continue; - } - SAggrBlkCol *pAggrBlkCol = ((SAggrBlkCol *)(pAggrBlkData)) + j; - if (pStatis[i].colId == pAggrBlkCol->colId) { - pStatis[i].sum = pAggrBlkCol->sum; - pStatis[i].max = pAggrBlkCol->max; - pStatis[i].min = pAggrBlkCol->min; - pStatis[i].maxIndex = pAggrBlkCol->maxIndex; - pStatis[i].minIndex = pAggrBlkCol->minIndex; - pStatis[i].numOfNull = pAggrBlkCol->numOfNull; - ++i; - ++j; - } else if (pStatis[i].colId < pAggrBlkCol->colId) { - pStatis[i].numOfNull = -1; - ++i; - } else { - ++j; - } - } - } - -#endif -} - -static void tsdbResetReadTable(SReadH *pReadh) { - tdResetDataCols(pReadh->pDCols[0]); - tdResetDataCols(pReadh->pDCols[1]); - pReadh->cidx = 0; - pReadh->pBlkIdx = NULL; - pReadh->pTable = NULL; -} - -static void tsdbResetReadFile(SReadH *pReadh) { - tsdbResetReadTable(pReadh); - taosArrayClear(pReadh->aBlkIdx); - tsdbCloseDFileSet(TSDB_READ_FSET(pReadh)); -} - -static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, int8_t bitmapMode) { - ASSERT(pBlock->numOfSubBlocks == 0 || pBlock->numOfSubBlocks == 1); - - SDFile *pDFile = (pBlock->last) ? TSDB_READ_LAST_FILE(pReadh) : TSDB_READ_DATA_FILE(pReadh); - - tdResetDataCols(pDataCols); - - pDataCols->bitmapMode = bitmapMode; - - if (tsdbMakeRoom((void **)(&TSDB_READ_BUF(pReadh)), pBlock->len) < 0) return -1; - - SBlockData *pBlockData = (SBlockData *)TSDB_READ_BUF(pReadh); - - if (tsdbSeekDFile(pDFile, pBlock->offset, SEEK_SET) < 0) { - tsdbError("vgId:%d, failed to load block data part while seek file %s to offset %" PRId64 " since %s", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tstrerror(terrno)); - return -1; - } - - int64_t nread = tsdbReadDFile(pDFile, TSDB_READ_BUF(pReadh), pBlock->len); - if (nread < 0) { - tsdbError("vgId:%d, failed to load block data part while read file %s since %s, offset:%" PRId64 " len :%d", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno), (int64_t)pBlock->offset, - pBlock->len); - return -1; - } - - if (nread < pBlock->len) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, block data part in file %s is corrupted, offset:%" PRId64 - " expected bytes:%d read bytes: %" PRId64, - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, pBlock->len, nread); - return -1; - } - - int32_t tsize = (int32_t)tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer); - if (!taosCheckChecksumWhole((uint8_t *)TSDB_READ_BUF(pReadh), tsize)) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, block head part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%d", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tsize); - return -1; - } - - ASSERT(tsize < pBlock->len); - ASSERT(pBlockData->numOfCols == pBlock->numOfCols); - - pDataCols->numOfRows = pBlock->numOfRows; - - // Recover the data - int ccol = 0; // loop iter for SBlockCol object - int dcol = 0; // loop iter for SDataCols object - int nBitmaps = (int)TD_BITMAP_BYTES(pBlock->numOfRows); - SBlockCol *pBlockCol = NULL; - while (dcol < pDataCols->numOfCols) { - SDataCol *pDataCol = &(pDataCols->cols[dcol]); - if (dcol != 0 && ccol >= pBlockData->numOfCols) { - // Set current column as NULL and forward - dataColReset(pDataCol); - ++dcol; - continue; - } - - int16_t tcolId = PRIMARYKEY_TIMESTAMP_COL_ID; - uint32_t toffset = TSDB_KEY_COL_OFFSET; - int32_t tlen = pBlock->keyLen; - - if (dcol != 0) { - pBlockCol = &(pBlockData->cols[ccol]); - tcolId = pBlockCol->colId; - toffset = pBlockCol->offset; - tlen = pBlockCol->len; - pDataCol->bitmap = pBlockCol->blen > 0 ? 1 : 0; - } else { - ASSERT(pDataCol->colId == tcolId); - TD_SET_COL_ROWS_NORM(pDataCol); - } - - // int32_t tBitmaps = 0; - int32_t tLenBitmap = 0; - if ((dcol != 0) && (pBlockCol->blen > 0)) { - tLenBitmap = nBitmaps; - } - - if (tcolId == pDataCol->colId) { - if (pBlock->algorithm == TWO_STAGE_COMP) { - int zsize = pDataCol->bytes * pBlock->numOfRows + tLenBitmap + 2 * COMP_OVERFLOW_BYTES; - if (tsdbMakeRoom((void **)(&TSDB_READ_COMP_BUF(pReadh)), zsize) < 0) return -1; - } - - if (tsdbCheckAndDecodeColumnData(pDataCol, POINTER_SHIFT(pBlockData, tsize + toffset), tlen, - pBlockCol ? pBlockCol->blen : 0, pBlock->algorithm, pBlock->numOfRows, - tLenBitmap, pDataCols->maxPoints, TSDB_READ_COMP_BUF(pReadh), - (int)taosTSizeof(TSDB_READ_COMP_BUF(pReadh))) < 0) { - tsdbError("vgId:%d, file %s is broken at column %d block offset %" PRId64 " column offset %u", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tcolId, (int64_t)pBlock->offset, toffset); - return -1; - } - - if (dcol != 0) { - ++ccol; - } - ++dcol; - } else if (tcolId < pDataCol->colId) { - ++ccol; - } else { - // Set current column as NULL and forward - dataColReset(pDataCol); - ++dcol; - } - } - - return 0; -} - -static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32_t len, int32_t bitmapLen, int8_t comp, - int numOfRows, int numOfBitmaps, int maxPoints, char *buffer, int bufferSize) { - if (!taosCheckChecksumWhole((uint8_t *)content, len)) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - return -1; - } - - tdAllocMemForCol(pDataCol, maxPoints); - - // Decode the data - if (comp) { - // Need to decompress - int tlen = - (*(tDataTypes[pDataCol->type].decompFunc))(content, len - bitmapLen - sizeof(TSCKSUM), numOfRows, - pDataCol->pData, pDataCol->spaceSize, comp, buffer, bufferSize); - if (tlen <= 0) { - tsdbError( - "Failed to decompress column data, file corrupted, len:%d comp:%d numOfRows:%d maxPoints:%d bufferSize:%d", - (int32_t)(len - bitmapLen - sizeof(TSCKSUM)), comp, numOfRows, maxPoints, bufferSize); - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - return -1; - } - pDataCol->len = tlen; - - if (numOfBitmaps > 0) { - tlen = tsDecompressTinyint(POINTER_SHIFT(content, len - bitmapLen - sizeof(TSCKSUM)), bitmapLen, numOfBitmaps, - pDataCol->pBitmap, pDataCol->spaceSize, comp, buffer, bufferSize); - if (tlen <= 0) { - tsdbError( - "Failed to decompress column bitmap, file corrupted, len:%d comp:%d numOfRows:%d maxPoints:%d " - "bufferSize:%d", - bitmapLen, comp, numOfBitmaps, maxPoints, bufferSize); - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - return -1; - } - // pDataCol->blen = tlen; - } - } else { - // No need to decompress, just memcpy it - pDataCol->len = len - bitmapLen - sizeof(TSCKSUM); - memcpy(pDataCol->pData, content, pDataCol->len); - if (numOfBitmaps > 0) { - // pDataCol->blen = bitmapLen; - memcpy(pDataCol->pBitmap, POINTER_SHIFT(content, len - bitmapLen - sizeof(TSCKSUM)), bitmapLen); - } - } - -#if 0 - if (lenOfBitmaps > 0) { - pDataCol->len -= lenOfBitmaps; - - void *pSrcBitmap = NULL; - if (IS_VAR_DATA_TYPE(pDataCol->type)) { - pSrcBitmap = dataColSetOffset(pDataCol, numOfRows); - } else { - pSrcBitmap = POINTER_SHIFT(pDataCol->pData, numOfRows * TYPE_BYTES[pDataCol->type]); - } - void *pDestBitmap = POINTER_SHIFT(pDataCol->pData, pDataCol->bytes * maxPoints); - // restore the bitmap parts - memcpy(pDestBitmap, pSrcBitmap, lenOfBitmaps); - } else if (IS_VAR_DATA_TYPE(pDataCol->type)) { - dataColSetOffset(pDataCol, numOfRows); - } -#endif - if (IS_VAR_DATA_TYPE(pDataCol->type)) { - dataColSetOffset(pDataCol, numOfRows); - } - return 0; -} - -static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, const int16_t *colIds, - int numOfColIds, int8_t bitmapMode) { - ASSERT(pBlock->numOfSubBlocks == 0 || pBlock->numOfSubBlocks == 1); - ASSERT(colIds[0] == PRIMARYKEY_TIMESTAMP_COL_ID); - - SDFile *pDFile = (pBlock->last) ? TSDB_READ_LAST_FILE(pReadh) : TSDB_READ_DATA_FILE(pReadh); - SBlockCol blockCol = {0}; - - tdResetDataCols(pDataCols); - - pDataCols->bitmapMode = bitmapMode; - - // If only load timestamp column, no need to load SBlockData part - if (numOfColIds > 1 && tsdbLoadBlockOffset(pReadh, pBlock) < 0) return -1; - - pDataCols->numOfRows = pBlock->numOfRows; - - int dcol = 0; - int ccol = 0; - for (int i = 0; i < numOfColIds; i++) { - int16_t colId = colIds[i]; - SDataCol *pDataCol = NULL; - SBlockCol *pBlockCol = NULL; - - while (true) { - if (dcol >= pDataCols->numOfCols) { - pDataCol = NULL; - break; - } - pDataCol = &pDataCols->cols[dcol]; - if (pDataCol->colId > colId) { - pDataCol = NULL; - break; - } else { - dcol++; - if (pDataCol->colId == colId) break; - } - } - - if (pDataCol == NULL) continue; - ASSERT(pDataCol->colId == colId); - - if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { // load the key row - blockCol.colId = colId; - blockCol.blen = 0; // default is NORM for the primary key column - blockCol.len = pBlock->keyLen; - blockCol.type = pDataCol->type; - blockCol.offset = TSDB_KEY_COL_OFFSET; - pBlockCol = &blockCol; - } else { // load non-key rows - while (true) { - if (ccol >= pBlock->numOfCols) { - pBlockCol = NULL; - break; - } - - pBlockCol = &(pReadh->pBlkData->cols[ccol]); - if (pBlockCol->colId > colId) { - pBlockCol = NULL; - break; - } else { - ccol++; - if (pBlockCol->colId == colId) break; - } - } - - if (pBlockCol == NULL) { - dataColReset(pDataCol); - continue; - } - - ASSERT(pBlockCol->colId == pDataCol->colId); - } - // set the bitmap - pDataCol->bitmap = pBlockCol->blen > 0 ? 1 : 0; - - if (tsdbLoadColData(pReadh, pDFile, pBlock, pBlockCol, pDataCol) < 0) return -1; - } - - return 0; -} - -static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBlockCol *pBlockCol, SDataCol *pDataCol) { - ASSERT(pDataCol->colId == pBlockCol->colId); - - STsdb *pRepo = TSDB_READ_REPO(pReadh); - STsdbCfg *pCfg = REPO_CFG(pRepo); - - int nBitmaps = (int)TD_BITMAP_BYTES(pBlock->numOfRows); - // int32_t tBitmaps = 0; - int32_t tLenBitmap = 0; - - if (pBlockCol->blen) { - tLenBitmap = nBitmaps; - } - - int tsize = pDataCol->bytes * pBlock->numOfRows + tLenBitmap + 2 * COMP_OVERFLOW_BYTES; - - if (tsdbMakeRoom((void **)(&TSDB_READ_BUF(pReadh)), pBlockCol->len) < 0) return -1; - if (tsdbMakeRoom((void **)(&TSDB_READ_COMP_BUF(pReadh)), tsize) < 0) return -1; - - int64_t offset = - pBlock->offset + tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer) + pBlockCol->offset; - if (tsdbSeekDFile(pDFile, offset, SEEK_SET) < 0) { - tsdbError("vgId:%d, failed to load block column data while seek file %s to offset %" PRId64 " since %s", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), offset, tstrerror(terrno)); - return -1; - } - - int64_t nread = tsdbReadDFile(pDFile, TSDB_READ_BUF(pReadh), pBlockCol->len); - if (nread < 0) { - tsdbError("vgId:%d, failed to load block column data while read file %s since %s, offset:%" PRId64 " len :%d", - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno), offset, pBlockCol->len); - return -1; - } - - if (nread < pBlockCol->len) { - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbError("vgId:%d, block column data in file %s is corrupted, offset:%" PRId64 " expected bytes:%d" PRIzu - " read bytes: %" PRId64, - TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), offset, pBlockCol->len, nread); - return -1; - } - - if (tsdbCheckAndDecodeColumnData(pDataCol, pReadh->pBuf, pBlockCol->len, pBlockCol->blen, pBlock->algorithm, - pBlock->numOfRows, tLenBitmap, pCfg->maxRows, pReadh->pCBuf, - (int32_t)taosTSizeof(pReadh->pCBuf)) < 0) { - tsdbError("vgId:%d, file %s is broken at column %d offset %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), - pBlockCol->colId, offset); - return -1; - } - - return 0; -} diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c new file mode 100644 index 0000000000000000000000000000000000000000..c22d1a4064d306b7a96d6908a801df1138d8a27a --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -0,0 +1,1906 @@ +/* + * 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 . + */ + +#include "tsdb.h" + +#define TSDB_FILE_DLMT ((uint32_t)0xF00AFA0F) + +// SDelFWriter ==================================================== +int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb) { + int32_t code = 0; + char fname[TSDB_FILENAME_LEN]; + char hdr[TSDB_FHDR_SIZE] = {0}; + SDelFWriter *pDelFWriter; + int64_t n; + + // alloc + pDelFWriter = (SDelFWriter *)taosMemoryCalloc(1, sizeof(*pDelFWriter)); + if (pDelFWriter == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pDelFWriter->pTsdb = pTsdb; + pDelFWriter->fDel = *pFile; + + tsdbDelFileName(pTsdb, pFile, fname); + pDelFWriter->pWriteH = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE); + if (pDelFWriter->pWriteH == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // update header + n = taosWriteFile(pDelFWriter->pWriteH, &hdr, TSDB_FHDR_SIZE); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + pDelFWriter->fDel.size = TSDB_FHDR_SIZE; + pDelFWriter->fDel.size = 0; + + *ppWriter = pDelFWriter; + return code; + +_err: + tsdbError("vgId:%d failed to open del file writer since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + *ppWriter = NULL; + return code; +} + +int32_t tsdbDelFWriterClose(SDelFWriter **ppWriter, int8_t sync) { + int32_t code = 0; + SDelFWriter *pWriter = *ppWriter; + + // sync + if (sync && taosFsyncFile(pWriter->pWriteH) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // close + if (taosCloseFile(&pWriter->pWriteH) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + *ppWriter = NULL; + return code; + +_err: + tsdbError("vgId:%d failed to close del file writer since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; +} + +int32_t tsdbWriteDelData(SDelFWriter *pWriter, SArray *aDelData, uint8_t **ppBuf, SDelIdx *pDelIdx) { + int32_t code = 0; + uint8_t *pBuf = NULL; + int64_t size; + int64_t n; + SBlockDataHdr hdr = {.delimiter = TSDB_FILE_DLMT, .suid = pDelIdx->suid, .uid = pDelIdx->uid}; + + if (!ppBuf) ppBuf = &pBuf; + + // prepare + size = sizeof(hdr); + for (int32_t iDelData = 0; iDelData < taosArrayGetSize(aDelData); iDelData++) { + size += tPutDelData(NULL, taosArrayGet(aDelData, iDelData)); + } + size += sizeof(TSCKSUM); + + // alloc + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // build + n = 0; + *(SBlockDataHdr *)(*ppBuf) = hdr; + n += sizeof(hdr); + for (int32_t iDelData = 0; iDelData < taosArrayGetSize(aDelData); iDelData++) { + n += tPutDelData(*ppBuf + n, taosArrayGet(aDelData, iDelData)); + } + taosCalcChecksumAppend(0, *ppBuf, size); + + ASSERT(n + sizeof(TSCKSUM) == size); + + // write + n = taosWriteFile(pWriter->pWriteH, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + ASSERT(n == size); + + // update + pDelIdx->offset = pWriter->fDel.size; + pDelIdx->size = size; + pWriter->fDel.size += size; + + tFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d failed to write del data since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf); + return code; +} + +int32_t tsdbWriteDelIdx(SDelFWriter *pWriter, SArray *aDelIdx, uint8_t **ppBuf) { + int32_t code = 0; + int64_t size; + int64_t n; + uint8_t *pBuf = NULL; + SDelIdx *pDelIdx; + + if (!ppBuf) ppBuf = &pBuf; + + // prepare + size = 0; + size += tPutU32(NULL, TSDB_FILE_DLMT); + for (int32_t iDelIdx = 0; iDelIdx < taosArrayGetSize(aDelIdx); iDelIdx++) { + size += tPutDelIdx(NULL, taosArrayGet(aDelIdx, iDelIdx)); + } + size += sizeof(TSCKSUM); + + // alloc + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // build + n = 0; + n += tPutU32(*ppBuf + n, TSDB_FILE_DLMT); + for (int32_t iDelIdx = 0; iDelIdx < taosArrayGetSize(aDelIdx); iDelIdx++) { + n += tPutDelIdx(*ppBuf + n, taosArrayGet(aDelIdx, iDelIdx)); + } + taosCalcChecksumAppend(0, *ppBuf, size); + + ASSERT(n + sizeof(TSCKSUM) == size); + + // write + n = taosWriteFile(pWriter->pWriteH, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // update + pWriter->fDel.offset = pWriter->fDel.size; + pWriter->fDel.size += size; + + tFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d write del idx failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf); + return code; +} + +int32_t tsdbUpdateDelFileHdr(SDelFWriter *pWriter) { + int32_t code = 0; + char hdr[TSDB_FHDR_SIZE]; + int64_t size = TSDB_FHDR_SIZE; + int64_t n; + + // build + memset(hdr, 0, size); + tPutDelFile(hdr, &pWriter->fDel); + taosCalcChecksumAppend(0, hdr, size); + + // seek + if (taosLSeekFile(pWriter->pWriteH, 0, SEEK_SET) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // write + n = taosWriteFile(pWriter->pWriteH, hdr, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + return code; + +_err: + tsdbError("vgId:%d update del file hdr failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; +} + +// SDelFReader ==================================================== +struct SDelFReader { + STsdb *pTsdb; + SDelFile fDel; + TdFilePtr pReadH; +}; + +int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb, uint8_t **ppBuf) { + int32_t code = 0; + char fname[TSDB_FILENAME_LEN]; + SDelFReader *pDelFReader; + int64_t n; + + // alloc + pDelFReader = (SDelFReader *)taosMemoryCalloc(1, sizeof(*pDelFReader)); + if (pDelFReader == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + // open impl + pDelFReader->pTsdb = pTsdb; + pDelFReader->fDel = *pFile; + + tsdbDelFileName(pTsdb, pFile, fname); + pDelFReader->pReadH = taosOpenFile(fname, TD_FILE_READ); + if (pDelFReader == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + taosMemoryFree(pDelFReader); + goto _err; + } + +#if 0 + // load and check hdr if buffer is given + if (ppBuf) { + code = tRealloc(ppBuf, TSDB_FHDR_SIZE); + if (code) { + goto _err; + } + + n = taosReadFile(pDelFReader->pReadH, *ppBuf, TSDB_FHDR_SIZE); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < TSDB_FHDR_SIZE) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + if (!taosCheckChecksumWhole(*ppBuf, TSDB_FHDR_SIZE)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // TODO: check the content + } +#endif + +_exit: + *ppReader = pDelFReader; + return code; + +_err: + tsdbError("vgId:%d del file reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + *ppReader = NULL; + return code; +} + +int32_t tsdbDelFReaderClose(SDelFReader **ppReader) { + int32_t code = 0; + SDelFReader *pReader = *ppReader; + + if (pReader) { + if (taosCloseFile(&pReader->pReadH) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _exit; + } + taosMemoryFree(pReader); + } + *ppReader = NULL; + +_exit: + return code; +} + +int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, uint8_t **ppBuf) { + int32_t code = 0; + int64_t offset = pDelIdx->offset; + int64_t size = pDelIdx->size; + int64_t n; + uint8_t *pBuf = NULL; + SBlockDataHdr *pHdr; + SDelData *pDelData = &(SDelData){0}; + + if (!ppBuf) ppBuf = &pBuf; + + // seek + if (taosLSeekFile(pReader->pReadH, offset, SEEK_SET) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // alloc + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // read + n = taosReadFile(pReader->pReadH, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // check + if (!taosCheckChecksumWhole(*ppBuf, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // // decode + n = 0; + pHdr = (SBlockDataHdr *)(*ppBuf + n); + ASSERT(pHdr->delimiter == TSDB_FILE_DLMT); + ASSERT(pHdr->suid == pDelIdx->suid); + ASSERT(pHdr->uid == pDelIdx->uid); + n += sizeof(*pHdr); + taosArrayClear(aDelData); + while (n < size - sizeof(TSCKSUM)) { + n += tGetDelData(*ppBuf + n, pDelData); + + if (taosArrayPush(aDelData, pDelData) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + ASSERT(n == size - sizeof(TSCKSUM)); + + tFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d read del data failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf); + return code; +} + +int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx, uint8_t **ppBuf) { + int32_t code = 0; + int32_t n; + int64_t offset = pReader->fDel.offset; + int64_t size = pReader->fDel.size - offset; + uint32_t delimiter; + uint8_t *pBuf = NULL; + SDelIdx *pDelIdx = &(SDelIdx){0}; + + if (!ppBuf) ppBuf = &pBuf; + + // seek + if (taosLSeekFile(pReader->pReadH, offset, SEEK_SET) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // alloc + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // read + n = taosReadFile(pReader->pReadH, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // check + if (!taosCheckChecksumWhole(*ppBuf, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // decode + n = 0; + n += tGetU32(*ppBuf + n, &delimiter); + ASSERT(delimiter == TSDB_FILE_DLMT); + + taosArrayClear(aDelIdx); + while (n < size - sizeof(TSCKSUM)) { + n += tGetDelIdx(*ppBuf + n, pDelIdx); + + if (taosArrayPush(aDelIdx, pDelIdx) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + ASSERT(n == size - sizeof(TSCKSUM)); + + return code; + +_err: + tsdbError("vgId:%d read del idx failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + return code; +} + +// SDataFReader ==================================================== +struct SDataFReader { + STsdb *pTsdb; + SDFileSet *pSet; + TdFilePtr pHeadFD; + TdFilePtr pDataFD; + TdFilePtr pLastFD; + TdFilePtr pSmaFD; +}; + +int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet) { + int32_t code = 0; + SDataFReader *pReader; + char fname[TSDB_FILENAME_LEN]; + + // alloc + pReader = (SDataFReader *)taosMemoryCalloc(1, sizeof(*pReader)); + if (pReader == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pReader->pTsdb = pTsdb; + pReader->pSet = pSet; + + // open impl + // head + tsdbDataFileName(pTsdb, pSet, TSDB_HEAD_FILE, fname); + pReader->pHeadFD = taosOpenFile(fname, TD_FILE_READ); + if (pReader->pHeadFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // data + tsdbDataFileName(pTsdb, pSet, TSDB_DATA_FILE, fname); + pReader->pDataFD = taosOpenFile(fname, TD_FILE_READ); + if (pReader->pDataFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // last + tsdbDataFileName(pTsdb, pSet, TSDB_LAST_FILE, fname); + pReader->pLastFD = taosOpenFile(fname, TD_FILE_READ); + if (pReader->pLastFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // sma + tsdbDataFileName(pTsdb, pSet, TSDB_SMA_FILE, fname); + pReader->pSmaFD = taosOpenFile(fname, TD_FILE_READ); + if (pReader->pSmaFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + *ppReader = pReader; + return code; + +_err: + tsdbError("vgId:%d tsdb data file reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + *ppReader = NULL; + return code; +} + +int32_t tsdbDataFReaderClose(SDataFReader **ppReader) { + int32_t code = 0; + if (*ppReader == NULL) goto _exit; + + if (taosCloseFile(&(*ppReader)->pHeadFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosCloseFile(&(*ppReader)->pDataFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosCloseFile(&(*ppReader)->pLastFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosCloseFile(&(*ppReader)->pSmaFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + taosMemoryFree(*ppReader); + +_exit: + *ppReader = NULL; + return code; + +_err: + tsdbError("vgId:%d data file reader close failed since %s", TD_VID((*ppReader)->pTsdb->pVnode), tstrerror(code)); + return code; +} + +int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx, uint8_t **ppBuf) { + int32_t code = 0; + int64_t offset = pReader->pSet->fHead.offset; + int64_t size = pReader->pSet->fHead.size - offset; + uint8_t *pBuf = NULL; + int64_t n; + uint32_t delimiter; + SBlockIdx blockIdx; + + if (!ppBuf) ppBuf = &pBuf; + + // alloc + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // seek + if (taosLSeekFile(pReader->pHeadFD, offset, SEEK_SET) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // read + n = taosReadFile(pReader->pHeadFD, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // check + if (!taosCheckChecksumWhole(*ppBuf, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // decode + n = 0; + n = tGetU32(*ppBuf + n, &delimiter); + ASSERT(delimiter == TSDB_FILE_DLMT); + + taosArrayClear(aBlockIdx); + while (n < size - sizeof(TSCKSUM)) { + n += tGetBlockIdx(*ppBuf + n, &blockIdx); + + if (taosArrayPush(aBlockIdx, &blockIdx) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + ASSERT(n + sizeof(TSCKSUM) == size); + + tFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d read block idx failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf); + return code; +} + +int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mBlock, uint8_t **ppBuf) { + int32_t code = 0; + int64_t offset = pBlockIdx->offset; + int64_t size = pBlockIdx->size; + uint8_t *pBuf = NULL; + int64_t n; + int64_t tn; + SBlockDataHdr hdr; + + if (!ppBuf) ppBuf = &pBuf; + + // alloc + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // seek + if (taosLSeekFile(pReader->pHeadFD, offset, SEEK_SET) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // read + n = taosReadFile(pReader->pHeadFD, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // check + if (!taosCheckChecksumWhole(*ppBuf, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // decode + hdr = *(SBlockDataHdr *)(*ppBuf); + ASSERT(hdr.delimiter == TSDB_FILE_DLMT); + ASSERT(hdr.suid == pBlockIdx->suid); + ASSERT(hdr.uid == pBlockIdx->uid); + + n = sizeof(hdr); + tn = tGetMapData(*ppBuf + n, mBlock); + if (tn < 0) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + n += tn; + ASSERT(n + sizeof(TSCKSUM) == size); + + tFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d read block failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf); + return code; +} + +static int32_t tsdbReadBlockDataKey(SBlockData *pBlockData, SSubBlock *pSubBlock, uint8_t *pBuf, uint8_t **ppBuf) { + int32_t code = 0; + int64_t size = pSubBlock->szVersion + pSubBlock->szTSKEY + sizeof(TSCKSUM); + int64_t n; + + if (!taosCheckChecksumWhole(pBuf, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + code = tRealloc((uint8_t **)&pBlockData->aVersion, sizeof(int64_t) * pSubBlock->nRow); + if (code) goto _err; + code = tRealloc((uint8_t **)&pBlockData->aTSKEY, sizeof(TSKEY) * pSubBlock->nRow); + if (code) goto _err; + + if (pSubBlock->cmprAlg == NO_COMPRESSION) { + ASSERT(pSubBlock->szVersion == sizeof(int64_t) * pSubBlock->nRow); + ASSERT(pSubBlock->szTSKEY == sizeof(TSKEY) * pSubBlock->nRow); + + // VERSION + memcpy(pBlockData->aVersion, pBuf, pSubBlock->szVersion); + + // TSKEY + memcpy(pBlockData->aTSKEY, pBuf + pSubBlock->szVersion, pSubBlock->szTSKEY); + } else { + size = sizeof(int64_t) * pSubBlock->nRow + COMP_OVERFLOW_BYTES; + if (pSubBlock->cmprAlg == TWO_STAGE_COMP) { + code = tRealloc(ppBuf, size); + if (code) goto _err; + } + + // VERSION + n = tsDecompressBigint(pBuf, pSubBlock->szVersion, pSubBlock->nRow, (char *)pBlockData->aVersion, + sizeof(int64_t) * pSubBlock->nRow, pSubBlock->cmprAlg, *ppBuf, size); + if (n < 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + + // TSKEY + n = tsDecompressTimestamp(pBuf + pSubBlock->szVersion, pSubBlock->szTSKEY, pSubBlock->nRow, + (char *)pBlockData->aTSKEY, sizeof(TSKEY) * pSubBlock->nRow, pSubBlock->cmprAlg, *ppBuf, + size); + if (n < 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + } + + return code; + +_err: + return code; +} + +static int32_t tsdbReadColDataImpl(SSubBlock *pSubBlock, SBlockCol *pBlockCol, SColData *pColData, uint8_t *pBuf, + uint8_t **ppBuf) { + int32_t code = 0; + int64_t size; + int64_t n; + + if (!taosCheckChecksumWhole(pBuf, pBlockCol->szBitmap + pBlockCol->szOffset + pBlockCol->szValue + sizeof(TSCKSUM))) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + pColData->nVal = pSubBlock->nRow; + pColData->flag = pBlockCol->flag; + + // BITMAP + if (pBlockCol->flag != HAS_VALUE) { + ASSERT(pBlockCol->szBitmap); + + size = BIT2_SIZE(pColData->nVal); + code = tRealloc(&pColData->pBitMap, size); + if (code) goto _err; + + code = tRealloc(ppBuf, size + COMP_OVERFLOW_BYTES); + if (code) goto _err; + + n = tsDecompressTinyint(pBuf, pBlockCol->szBitmap, size, pColData->pBitMap, size, TWO_STAGE_COMP, *ppBuf, + size + COMP_OVERFLOW_BYTES); + if (n <= 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + + ASSERT(n == size); + } else { + ASSERT(pBlockCol->szBitmap == 0); + } + pBuf = pBuf + pBlockCol->szBitmap; + + // OFFSET + if (IS_VAR_DATA_TYPE(pColData->type)) { + ASSERT(pBlockCol->szOffset); + + size = sizeof(int32_t) * pColData->nVal; + code = tRealloc((uint8_t **)&pColData->aOffset, size); + if (code) goto _err; + + code = tRealloc(ppBuf, size + COMP_OVERFLOW_BYTES); + if (code) goto _err; + + n = tsDecompressInt(pBuf, pBlockCol->szOffset, pColData->nVal, (char *)pColData->aOffset, size, TWO_STAGE_COMP, + *ppBuf, size + COMP_OVERFLOW_BYTES); + if (n <= 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + + ASSERT(n == size); + } else { + ASSERT(pBlockCol->szOffset == 0); + } + pBuf = pBuf + pBlockCol->szOffset; + + // VALUE + pColData->nData = pBlockCol->szOrigin; + + code = tRealloc(&pColData->pData, pColData->nData); + if (code) goto _err; + + if (pSubBlock->cmprAlg == NO_COMPRESSION) { + memcpy(pColData->pData, pBuf, pColData->nData); + } else { + if (pSubBlock->cmprAlg == TWO_STAGE_COMP) { + code = tRealloc(ppBuf, pColData->nData + COMP_OVERFLOW_BYTES); + if (code) goto _err; + } + + n = tDataTypes[pBlockCol->type].decompFunc(pBuf, pBlockCol->szValue, pSubBlock->nRow, pColData->pData, + pColData->nData, pSubBlock->cmprAlg, *ppBuf, + pColData->nData + COMP_OVERFLOW_BYTES); + if (n < 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + + ASSERT(n == pColData->nData); + } + + return code; + +_err: + return code; +} + +static int32_t tsdbReadBlockCol(SSubBlock *pSubBlock, uint8_t *p, SArray *aBlockCol) { + int32_t code = 0; + int32_t n = 0; + SBlockCol blockCol; + SBlockCol *pBlockCol = &blockCol; + + if (!taosCheckChecksumWhole(p, pSubBlock->szBlockCol + sizeof(TSCKSUM))) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + n += sizeof(SBlockDataHdr); + while (n < pSubBlock->szBlockCol) { + n += tGetBlockCol(p + n, pBlockCol); + + if (taosArrayPush(aBlockCol, pBlockCol) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + ASSERT(n == pSubBlock->szBlockCol); + + return code; + +_err: + return code; +} + +static int32_t tsdbReadSubColData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBlock, int32_t iSubBlock, + int16_t *aColId, int32_t nCol, SBlockData *pBlockData, uint8_t **ppBuf1, + uint8_t **ppBuf2) { + TdFilePtr pFD = pBlock->last ? pReader->pLastFD : pReader->pDataFD; + SSubBlock *pSubBlock = &pBlock->aSubBlock[iSubBlock]; + SArray *aBlockCol = NULL; + int32_t code = 0; + int64_t offset; + int64_t size; + int64_t n; + + tBlockDataReset(pBlockData); + pBlockData->nRow = pSubBlock->nRow; + + // TSDBKEY and SBlockCol + if (nCol == 1) { + offset = pSubBlock->offset + pSubBlock->szBlockCol + sizeof(TSCKSUM); + size = pSubBlock->szVersion + pSubBlock->szTSKEY + sizeof(TSCKSUM); + } else { + offset = pSubBlock->offset; + size = pSubBlock->szBlockCol + sizeof(TSCKSUM) + pSubBlock->szVersion + pSubBlock->szTSKEY + sizeof(TSCKSUM); + } + + code = tRealloc(ppBuf1, size); + if (code) goto _err; + + n = taosLSeekFile(pFD, offset, SEEK_SET); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + n = taosReadFile(pFD, *ppBuf1, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + if (nCol == 1) { + code = tsdbReadBlockDataKey(pBlockData, pSubBlock, *ppBuf1, ppBuf2); + if (code) goto _err; + + goto _exit; + } else { + aBlockCol = taosArrayInit(0, sizeof(SBlockCol)); + if (aBlockCol == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + code = tsdbReadBlockCol(pSubBlock, *ppBuf1, aBlockCol); + if (code) goto _err; + + code = tsdbReadBlockDataKey(pBlockData, pSubBlock, *ppBuf1 + pSubBlock->szBlockCol + sizeof(TSCKSUM), ppBuf2); + if (code) goto _err; + } + + for (int32_t iCol = 1; iCol < nCol; iCol++) { + void *p = taosArraySearch(aBlockCol, &(SBlockCol){.cid = aColId[iCol]}, tBlockColCmprFn, TD_EQ); + + if (p) { + SBlockCol *pBlockCol = (SBlockCol *)p; + SColData *pColData; + + ASSERT(pBlockCol->flag && pBlockCol->flag != HAS_NONE); + + code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + if (code) goto _err; + + tColDataInit(pColData, pBlockCol->cid, pBlockCol->type, pBlockCol->smaOn); + if (pBlockCol->flag == HAS_NULL) { + for (int32_t iRow = 0; iRow < pSubBlock->nRow; iRow++) { + code = tColDataAppendValue(pColData, &COL_VAL_NULL(pBlockCol->cid, pBlockCol->type)); + if (code) goto _err; + } + } else { + offset = pSubBlock->offset + pSubBlock->szBlockCol + sizeof(TSCKSUM) + pSubBlock->szVersion + + pSubBlock->szTSKEY + sizeof(TSCKSUM) + pBlockCol->offset; + size = pBlockCol->szBitmap + pBlockCol->szOffset + pBlockCol->szValue + sizeof(TSCKSUM); + + code = tRealloc(ppBuf1, size); + if (code) goto _err; + + // seek + n = taosLSeekFile(pFD, offset, SEEK_SET); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // read + n = taosReadFile(pFD, *ppBuf1, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < size) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + code = tsdbReadColDataImpl(pSubBlock, pBlockCol, pColData, *ppBuf1, ppBuf2); + if (code) goto _err; + } + } + } + +_exit: + taosArrayDestroy(aBlockCol); + return code; + +_err: + taosArrayDestroy(aBlockCol); + return code; +} + +int32_t tsdbReadColData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBlock, int16_t *aColId, int32_t nCol, + SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2) { + int32_t code = 0; + uint8_t *pBuf1 = NULL; + uint8_t *pBuf2 = NULL; + + ASSERT(aColId[0] == PRIMARYKEY_TIMESTAMP_COL_ID); + + if (!ppBuf1) ppBuf1 = &pBuf1; + if (!ppBuf2) ppBuf2 = &pBuf2; + + code = tsdbReadSubColData(pReader, pBlockIdx, pBlock, 0, aColId, nCol, pBlockData, ppBuf1, ppBuf2); + if (code) goto _err; + + if (pBlock->nSubBlock > 1) { + SBlockData *pBlockData1 = &(SBlockData){0}; + SBlockData *pBlockData2 = &(SBlockData){0}; + + for (int32_t iSubBlock = 1; iSubBlock < pBlock->nSubBlock; iSubBlock++) { + code = tsdbReadSubColData(pReader, pBlockIdx, pBlock, iSubBlock, aColId, nCol, pBlockData1, ppBuf1, ppBuf2); + if (code) goto _err; + + code = tBlockDataCopy(pBlockData, pBlockData2); + if (code) { + tBlockDataClear(pBlockData1); + tBlockDataClear(pBlockData2); + goto _err; + } + + code = tBlockDataMerge(pBlockData1, pBlockData2, pBlockData); + if (code) { + tBlockDataClear(pBlockData1); + tBlockDataClear(pBlockData2); + goto _err; + } + } + + tBlockDataClear(pBlockData1); + tBlockDataClear(pBlockData2); + } + + tFree(pBuf1); + tFree(pBuf2); + return code; + +_err: + tsdbError("vgId:%d tsdb read col data failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf1); + tFree(pBuf2); + return code; +} + +static int32_t tsdbReadSubBlockData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBlock, int32_t iSubBlock, + SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2) { + int32_t code = 0; + uint8_t *p; + int64_t size; + int64_t n; + TdFilePtr pFD = pBlock->last ? pReader->pLastFD : pReader->pDataFD; + SSubBlock *pSubBlock = &pBlock->aSubBlock[iSubBlock]; + SArray *aBlockCol = NULL; + + tBlockDataReset(pBlockData); + + // realloc + code = tRealloc(ppBuf1, pSubBlock->szBlock); + if (code) goto _err; + + // seek + n = taosLSeekFile(pFD, pSubBlock->offset, SEEK_SET); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // read + n = taosReadFile(pFD, *ppBuf1, pSubBlock->szBlock); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } else if (n < pSubBlock->szBlock) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + pBlockData->nRow = pSubBlock->nRow; + + // TSDBKEY + p = *ppBuf1 + pSubBlock->szBlockCol + sizeof(TSCKSUM); + code = tsdbReadBlockDataKey(pBlockData, pSubBlock, p, ppBuf2); + if (code) goto _err; + + // COLUMNS + aBlockCol = taosArrayInit(0, sizeof(SBlockCol)); + if (aBlockCol == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + code = tsdbReadBlockCol(pSubBlock, *ppBuf1, aBlockCol); + if (code) goto _err; + + for (int32_t iBlockCol = 0; iBlockCol < taosArrayGetSize(aBlockCol); iBlockCol++) { + SColData *pColData; + SBlockCol *pBlockCol = (SBlockCol *)taosArrayGet(aBlockCol, iBlockCol); + + ASSERT(pBlockCol->flag && pBlockCol->flag != HAS_NONE); + + code = tBlockDataAddColData(pBlockData, iBlockCol, &pColData); + if (code) goto _err; + + tColDataInit(pColData, pBlockCol->cid, pBlockCol->type, pBlockCol->smaOn); + if (pBlockCol->flag == HAS_NULL) { + for (int32_t iRow = 0; iRow < pSubBlock->nRow; iRow++) { + code = tColDataAppendValue(pColData, &COL_VAL_NULL(pBlockCol->cid, pBlockCol->type)); + if (code) goto _err; + } + } else { + p = *ppBuf1 + pSubBlock->szBlockCol + sizeof(TSCKSUM) + pSubBlock->szVersion + pSubBlock->szTSKEY + + sizeof(TSCKSUM) + pBlockCol->offset; + code = tsdbReadColDataImpl(pSubBlock, pBlockCol, pColData, p, ppBuf2); + if (code) goto _err; + } + } + + taosArrayDestroy(aBlockCol); + return code; + +_err: + tsdbError("vgId:%d tsdb read sub block data failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + taosArrayDestroy(aBlockCol); + return code; +} + +int32_t tsdbReadBlockData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBlock, SBlockData *pBlockData, + uint8_t **ppBuf1, uint8_t **ppBuf2) { + int32_t code = 0; + TdFilePtr pFD = pBlock->last ? pReader->pLastFD : pReader->pDataFD; + uint8_t *pBuf1 = NULL; + uint8_t *pBuf2 = NULL; + int32_t iSubBlock; + + if (!ppBuf1) ppBuf1 = &pBuf1; + if (!ppBuf2) ppBuf2 = &pBuf2; + + // read the first sub-block + iSubBlock = 0; + code = tsdbReadSubBlockData(pReader, pBlockIdx, pBlock, iSubBlock, pBlockData, ppBuf1, ppBuf2); + if (code) goto _err; + + // read remain block data and do merg + if (pBlock->nSubBlock > 1) { + SBlockData *pBlockData1 = &(SBlockData){0}; + SBlockData *pBlockData2 = &(SBlockData){0}; + + for (iSubBlock = 1; iSubBlock < pBlock->nSubBlock; iSubBlock++) { + code = tsdbReadSubBlockData(pReader, pBlockIdx, pBlock, iSubBlock, pBlockData1, ppBuf1, ppBuf2); + if (code) { + tBlockDataClear(pBlockData1); + tBlockDataClear(pBlockData2); + goto _err; + } + + code = tBlockDataCopy(pBlockData, pBlockData2); + if (code) { + tBlockDataClear(pBlockData1); + tBlockDataClear(pBlockData2); + goto _err; + } + + // merge two block data + code = tBlockDataMerge(pBlockData1, pBlockData2, pBlockData); + if (code) { + tBlockDataClear(pBlockData1); + tBlockDataClear(pBlockData2); + goto _err; + } + } + + tBlockDataClear(pBlockData1); + tBlockDataClear(pBlockData2); + } + + ASSERT(pBlock->nRow == pBlockData->nRow); + ASSERT(tsdbKeyCmprFn(&pBlock->minKey, &TSDBROW_KEY(&tBlockDataFirstRow(pBlockData))) == 0); + ASSERT(tsdbKeyCmprFn(&pBlock->maxKey, &TSDBROW_KEY(&tBlockDataLastRow(pBlockData))) == 0); + + if (pBuf1) tFree(pBuf1); + if (pBuf2) tFree(pBuf2); + return code; + +_err: + tsdbError("vgId:%d tsdb read block data failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + if (pBuf1) tFree(pBuf1); + if (pBuf2) tFree(pBuf2); + return code; +} + +int32_t tsdbReadBlockSma(SDataFReader *pReader, SBlock *pBlock, SArray *aColumnDataAgg, uint8_t **ppBuf) { + int32_t code = 0; + TdFilePtr pFD = pReader->pSmaFD; + int64_t offset = pBlock->aSubBlock[0].offset; + int64_t size = pBlock->aSubBlock[0].nSma * sizeof(SColumnDataAgg) + sizeof(TSCKSUM); + uint8_t *pBuf = NULL; + int64_t n; + + ASSERT(tBlockHasSma(pBlock)); + + if (!ppBuf) ppBuf = &pBuf; + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // lseek + n = taosLSeekFile(pFD, offset, SEEK_SET); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // read + n = taosReadFile(pFD, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // check + if (!taosCheckChecksumWhole(NULL, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + goto _err; + } + + // decode + taosArrayClear(aColumnDataAgg); + for (int32_t iSma = 0; iSma < pBlock->aSubBlock[0].nSma; iSma++) { + if (taosArrayPush(aColumnDataAgg, &((SColumnDataAgg *)(*ppBuf))[iSma]) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + tFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d read block sma failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf); + return code; +} + +// SDataFWriter ==================================================== +struct SDataFWriter { + STsdb *pTsdb; + SDFileSet wSet; + TdFilePtr pHeadFD; + TdFilePtr pDataFD; + TdFilePtr pLastFD; + TdFilePtr pSmaFD; +}; + +SDFileSet *tsdbDataFWriterGetWSet(SDataFWriter *pWriter) { return &pWriter->wSet; } + +int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pSet) { + int32_t code = 0; + int32_t flag; + int64_t n; + SDataFWriter *pWriter = NULL; + char fname[TSDB_FILENAME_LEN]; + char hdr[TSDB_FHDR_SIZE] = {0}; + + // alloc + pWriter = taosMemoryCalloc(1, sizeof(*pWriter)); + if (pWriter == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pWriter->pTsdb = pTsdb; + pWriter->wSet = *pSet; + pSet = &pWriter->wSet; + + // head + flag = TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC; + tsdbDataFileName(pTsdb, pSet, TSDB_HEAD_FILE, fname); + pWriter->pHeadFD = taosOpenFile(fname, flag); + if (pWriter->pHeadFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + n = taosWriteFile(pWriter->pHeadFD, hdr, TSDB_FHDR_SIZE); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + ASSERT(n == TSDB_FHDR_SIZE); + + pSet->fHead.size += TSDB_FHDR_SIZE; + + // data + if (pSet->fData.size == 0) { + flag = TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC; + } else { + flag = TD_FILE_WRITE; + } + tsdbDataFileName(pTsdb, pSet, TSDB_DATA_FILE, fname); + pWriter->pDataFD = taosOpenFile(fname, flag); + if (pWriter->pDataFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + if (pSet->fData.size == 0) { + n = taosWriteFile(pWriter->pDataFD, hdr, TSDB_FHDR_SIZE); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + pSet->fData.size += TSDB_FHDR_SIZE; + } else { + n = taosLSeekFile(pWriter->pDataFD, 0, SEEK_END); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + ASSERT(n == pSet->fData.size); + } + + // last + if (pSet->fLast.size == 0) { + flag = TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC; + } else { + flag = TD_FILE_WRITE; + } + tsdbDataFileName(pTsdb, pSet, TSDB_LAST_FILE, fname); + pWriter->pLastFD = taosOpenFile(fname, flag); + if (pWriter->pLastFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + if (pSet->fLast.size == 0) { + n = taosWriteFile(pWriter->pLastFD, hdr, TSDB_FHDR_SIZE); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + pSet->fLast.size += TSDB_FHDR_SIZE; + } else { + n = taosLSeekFile(pWriter->pLastFD, 0, SEEK_END); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + ASSERT(n == pSet->fLast.size); + } + + // sma + if (pSet->fSma.size == 0) { + flag = TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC; + } else { + flag = TD_FILE_WRITE; + } + tsdbDataFileName(pTsdb, pSet, TSDB_SMA_FILE, fname); + pWriter->pSmaFD = taosOpenFile(fname, flag); + if (pWriter->pSmaFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + if (pSet->fSma.size == 0) { + n = taosWriteFile(pWriter->pSmaFD, hdr, TSDB_FHDR_SIZE); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + pSet->fSma.size += TSDB_FHDR_SIZE; + } else { + n = taosLSeekFile(pWriter->pSmaFD, 0, SEEK_END); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + ASSERT(n == pSet->fSma.size); + } + + *ppWriter = pWriter; + return code; + +_err: + tsdbError("vgId:%d tsdb data file writer open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + *ppWriter = NULL; + return code; +} + +int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync) { + int32_t code = 0; + STsdb *pTsdb = (*ppWriter)->pTsdb; + + if (*ppWriter == NULL) goto _exit; + + if (sync) { + if (taosFsyncFile((*ppWriter)->pHeadFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosFsyncFile((*ppWriter)->pDataFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosFsyncFile((*ppWriter)->pLastFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosFsyncFile((*ppWriter)->pSmaFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + } + + if (taosCloseFile(&(*ppWriter)->pHeadFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosCloseFile(&(*ppWriter)->pDataFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosCloseFile(&(*ppWriter)->pLastFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosCloseFile(&(*ppWriter)->pSmaFD) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + taosMemoryFree(*ppWriter); +_exit: + *ppWriter = NULL; + return code; + +_err: + tsdbError("vgId:%d data file writer close failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter) { + int32_t code = 0; + + // head ============== + code = tsdbUpdateDFileHdr(pWriter->pHeadFD, &pWriter->wSet, TSDB_HEAD_FILE); + if (code) goto _err; + + // data ============== + code = tsdbUpdateDFileHdr(pWriter->pHeadFD, &pWriter->wSet, TSDB_DATA_FILE); + if (code) goto _err; + + // last ============== + code = tsdbUpdateDFileHdr(pWriter->pHeadFD, &pWriter->wSet, TSDB_LAST_FILE); + if (code) goto _err; + + // sma ============== + code = tsdbUpdateDFileHdr(pWriter->pHeadFD, &pWriter->wSet, TSDB_SMA_FILE); + if (code) goto _err; + + return code; + +_err: + tsdbError("vgId:%d update DFileSet header failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; +} + +int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx, uint8_t **ppBuf) { + int32_t code = 0; + SHeadFile *pHeadFile = &pWriter->wSet.fHead; + uint8_t *pBuf = NULL; + int64_t size; + int64_t n; + + if (!ppBuf) ppBuf = &pBuf; + + // prepare + size = tPutU32(NULL, TSDB_FILE_DLMT); + for (int32_t iBlockIdx = 0; iBlockIdx < taosArrayGetSize(aBlockIdx); iBlockIdx++) { + size += tPutBlockIdx(NULL, taosArrayGet(aBlockIdx, iBlockIdx)); + } + size += sizeof(TSCKSUM); + + // alloc + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // build + n = 0; + n = tPutU32(*ppBuf + n, TSDB_FILE_DLMT); + for (int32_t iBlockIdx = 0; iBlockIdx < taosArrayGetSize(aBlockIdx); iBlockIdx++) { + n += tPutBlockIdx(*ppBuf + n, taosArrayGet(aBlockIdx, iBlockIdx)); + } + taosCalcChecksumAppend(0, *ppBuf, size); + + ASSERT(n + sizeof(TSCKSUM) == size); + + // write + n = taosWriteFile(pWriter->pHeadFD, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // update + pHeadFile->offset = pHeadFile->size; + pHeadFile->size += size; + + tFree(pBuf); + return code; + +_err: + tsdbError("vgId:%d write block idx failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf); + return code; +} + +int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *mBlock, uint8_t **ppBuf, SBlockIdx *pBlockIdx) { + int32_t code = 0; + SHeadFile *pHeadFile = &pWriter->wSet.fHead; + SBlockDataHdr hdr = {.delimiter = TSDB_FILE_DLMT, .suid = pBlockIdx->suid, .uid = pBlockIdx->uid}; + uint8_t *pBuf = NULL; + int64_t size; + int64_t n; + + ASSERT(mBlock->nItem > 0); + + // prepare + size = sizeof(SBlockDataHdr) + tPutMapData(NULL, mBlock) + sizeof(TSCKSUM); + + // alloc + if (!ppBuf) ppBuf = &pBuf; + code = tRealloc(ppBuf, size); + if (code) goto _err; + + // build + n = 0; + *(SBlockDataHdr *)(*ppBuf) = hdr; + n += sizeof(hdr); + n += tPutMapData(*ppBuf + n, mBlock); + taosCalcChecksumAppend(0, *ppBuf, size); + + ASSERT(n + sizeof(TSCKSUM) == size); + + // write + n = taosWriteFile(pWriter->pHeadFD, *ppBuf, size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // update + pBlockIdx->offset = pHeadFile->size; + pBlockIdx->size = size; + pHeadFile->size += size; + + tFree(pBuf); + tsdbTrace("vgId:%d write block, offset:%" PRId64 " size:%" PRId64, TD_VID(pWriter->pTsdb->pVnode), pBlockIdx->offset, + pBlockIdx->size); + return code; + +_err: + tFree(pBuf); + tsdbError("vgId:%d write block failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; +} + +static void tsdbUpdateBlockInfo(SBlockData *pBlockData, SBlock *pBlock) { + for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) { + TSDBKEY key = {.ts = pBlockData->aTSKEY[iRow], .version = pBlockData->aVersion[iRow]}; + + if (iRow == 0) { + if (tsdbKeyCmprFn(&pBlock->minKey, &key) > 0) { + pBlock->minKey = key; + } + } else { + if (pBlockData->aTSKEY[iRow] == pBlockData->aTSKEY[iRow - 1]) { + pBlock->hasDup = 1; + } + } + + if (iRow == pBlockData->nRow - 1 && tsdbKeyCmprFn(&pBlock->maxKey, &key) < 0) { + pBlock->maxKey = key; + } + + pBlock->minVersion = TMIN(pBlock->minVersion, key.version); + pBlock->maxVersion = TMAX(pBlock->maxVersion, key.version); + } + pBlock->nRow += pBlockData->nRow; +} + +static int32_t tsdbWriteBlockDataKey(SSubBlock *pSubBlock, SBlockData *pBlockData, uint8_t **ppBuf1, int64_t *nDataP, + uint8_t **ppBuf2) { + int32_t code = 0; + int64_t size; + int64_t tsize; + + if (pSubBlock->cmprAlg == NO_COMPRESSION) { + pSubBlock->szVersion = sizeof(int64_t) * pSubBlock->nRow; + pSubBlock->szTSKEY = sizeof(TSKEY) * pSubBlock->nRow; + + code = tRealloc(ppBuf1, *nDataP + pSubBlock->szVersion + pSubBlock->szTSKEY + sizeof(TSCKSUM)); + if (code) goto _err; + + // VERSION + memcpy(*ppBuf1 + *nDataP, pBlockData->aVersion, pSubBlock->szVersion); + + // TSKEY + memcpy(*ppBuf1 + *nDataP + pSubBlock->szVersion, pBlockData->aTSKEY, pSubBlock->szTSKEY); + } else { + size = (sizeof(int64_t) + sizeof(TSKEY)) * pSubBlock->nRow + COMP_OVERFLOW_BYTES * 2; + + code = tRealloc(ppBuf1, *nDataP + size + sizeof(TSCKSUM)); + if (code) goto _err; + + tsize = sizeof(int64_t) * pSubBlock->nRow + COMP_OVERFLOW_BYTES; + if (pSubBlock->cmprAlg == TWO_STAGE_COMP) { + code = tRealloc(ppBuf2, tsize); + if (code) goto _err; + } + + // VERSION + pSubBlock->szVersion = + tsCompressBigint((char *)pBlockData->aVersion, sizeof(int64_t) * pBlockData->nRow, pBlockData->nRow, + *ppBuf1 + *nDataP, size, pSubBlock->cmprAlg, *ppBuf2, tsize); + if (pSubBlock->szVersion <= 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + + // TSKEY + pSubBlock->szTSKEY = tsCompressTimestamp((char *)pBlockData->aTSKEY, sizeof(TSKEY) * pBlockData->nRow, + pBlockData->nRow, *ppBuf1 + *nDataP + pSubBlock->szVersion, + size - pSubBlock->szVersion, pSubBlock->cmprAlg, *ppBuf2, tsize); + if (pSubBlock->szTSKEY <= 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + + ASSERT(pSubBlock->szVersion + pSubBlock->szTSKEY <= size); + } + + // checksum + size = pSubBlock->szVersion + pSubBlock->szTSKEY + sizeof(TSCKSUM); + taosCalcChecksumAppend(0, *ppBuf1 + *nDataP, size); + + *nDataP += size; + return code; + +_err: + return code; +} + +static int32_t tsdbWriteColData(SColData *pColData, SBlockCol *pBlockCol, SSubBlock *pSubBlock, uint8_t **ppBuf1, + int64_t *nDataP, uint8_t **ppBuf2) { + int32_t code = 0; + int64_t size; + int64_t n = 0; + + // BITMAP + if (pColData->flag != HAS_VALUE) { + size = BIT2_SIZE(pColData->nVal) + COMP_OVERFLOW_BYTES; + + code = tRealloc(ppBuf1, *nDataP + n + size); + if (code) goto _err; + + code = tRealloc(ppBuf2, size); + if (code) goto _err; + + pBlockCol->szBitmap = + tsCompressTinyint((char *)pColData->pBitMap, BIT2_SIZE(pColData->nVal), BIT2_SIZE(pColData->nVal), + *ppBuf1 + *nDataP + n, size, TWO_STAGE_COMP, *ppBuf2, size); + if (pBlockCol->szBitmap <= 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + } else { + pBlockCol->szBitmap = 0; + } + n += pBlockCol->szBitmap; + + // OFFSET + if (IS_VAR_DATA_TYPE(pColData->type)) { + size = sizeof(int32_t) * pColData->nVal + COMP_OVERFLOW_BYTES; + + code = tRealloc(ppBuf1, *nDataP + n + size); + if (code) goto _err; + + code = tRealloc(ppBuf2, size); + if (code) goto _err; + + pBlockCol->szOffset = tsCompressInt((char *)pColData->aOffset, sizeof(int32_t) * pColData->nVal, pColData->nVal, + *ppBuf1 + *nDataP + n, size, TWO_STAGE_COMP, *ppBuf2, size); + if (pBlockCol->szOffset <= 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + } else { + pBlockCol->szOffset = 0; + } + n += pBlockCol->szOffset; + + // VALUE + if (pSubBlock->cmprAlg == NO_COMPRESSION) { + pBlockCol->szValue = pColData->nData; + + code = tRealloc(ppBuf1, *nDataP + n + pBlockCol->szValue + sizeof(TSCKSUM)); + if (code) goto _err; + + memcpy(*ppBuf1 + *nDataP + n, pColData->pData, pBlockCol->szValue); + } else { + size = pColData->nData + COMP_OVERFLOW_BYTES; + + code = tRealloc(ppBuf1, *nDataP + n + size + sizeof(TSCKSUM)); + if (code) goto _err; + + if (pSubBlock->cmprAlg == TWO_STAGE_COMP) { + code = tRealloc(ppBuf2, size); + if (code) goto _err; + } + + pBlockCol->szValue = + tDataTypes[pColData->type].compFunc((char *)pColData->pData, pColData->nData, pColData->nVal, + *ppBuf1 + *nDataP + n, size, pSubBlock->cmprAlg, *ppBuf2, size); + if (pBlockCol->szValue <= 0) { + code = TSDB_CODE_COMPRESS_ERROR; + goto _err; + } + } + n += pBlockCol->szValue; + pBlockCol->szOrigin = pColData->nData; + + // checksum + n += sizeof(TSCKSUM); + taosCalcChecksumAppend(0, *ppBuf1 + *nDataP, n); + + *nDataP += n; + + return code; + +_err: + return code; +} + +static int32_t tsdbWriteBlockDataImpl(TdFilePtr pFD, SSubBlock *pSubBlock, SBlockDataHdr hdr, SArray *aBlockCol, + uint8_t *pData, int64_t nData, uint8_t **ppBuf) { + int32_t code = 0; + int32_t nBlockCol = taosArrayGetSize(aBlockCol); + int64_t size; + int64_t n; + + // HDR + SArray + pSubBlock->szBlockCol = sizeof(hdr); + for (int32_t iBlockCol = 0; iBlockCol < nBlockCol; iBlockCol++) { + pSubBlock->szBlockCol += tPutBlockCol(NULL, taosArrayGet(aBlockCol, iBlockCol)); + } + + code = tRealloc(ppBuf, pSubBlock->szBlockCol + sizeof(TSCKSUM)); + if (code) goto _err; + + n = 0; + memcpy(*ppBuf, &hdr, sizeof(hdr)); + n += sizeof(hdr); + for (int32_t iBlockCol = 0; iBlockCol < nBlockCol; iBlockCol++) { + n += tPutBlockCol(*ppBuf + n, taosArrayGet(aBlockCol, iBlockCol)); + } + taosCalcChecksumAppend(0, *ppBuf, pSubBlock->szBlockCol + sizeof(TSCKSUM)); + + ASSERT(n == pSubBlock->szBlockCol); + + n = taosWriteFile(pFD, *ppBuf, pSubBlock->szBlockCol + sizeof(TSCKSUM)); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // SBlockData + n = taosWriteFile(pFD, pData, nData); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + return code; + +_err: + return code; +} + +static int32_t tsdbWriteBlockSma(TdFilePtr pFD, SBlockData *pBlockData, SSubBlock *pSubBlock, uint8_t **ppBuf) { + int32_t code = 0; + int64_t n; + SColData *pColData; + + // prepare + pSubBlock->nSma = 0; + for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { + pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); + + if (IS_VAR_DATA_TYPE(pColData->type) || (!pColData->smaOn)) continue; + + pSubBlock->nSma++; + } + if (pSubBlock->nSma == 0) goto _exit; + + // calc + code = tRealloc(ppBuf, sizeof(SColumnDataAgg) * pSubBlock->nSma + sizeof(TSCKSUM)); + if (code) goto _err; + n = 0; + for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { + pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); + + if (IS_VAR_DATA_TYPE(pColData->type) || (!pColData->smaOn)) continue; + + tsdbCalcColDataSMA(pColData, &((SColumnDataAgg *)(*ppBuf))[n]); + n++; + } + taosCalcChecksumAppend(0, *ppBuf, sizeof(SColumnDataAgg) * pSubBlock->nSma + sizeof(TSCKSUM)); + + // write + n = taosWriteFile(pFD, *ppBuf, sizeof(SColumnDataAgg) * pSubBlock->nSma + sizeof(TSCKSUM)); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + +_exit: + return code; + +_err: + return code; +} + +int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2, + SBlockIdx *pBlockIdx, SBlock *pBlock, int8_t cmprAlg) { + int32_t code = 0; + SSubBlock *pSubBlock = &pBlock->aSubBlock[pBlock->nSubBlock++]; + SBlockCol blockCol; + SBlockCol *pBlockCol = &blockCol; + int64_t n; + TdFilePtr pFileFD = pBlock->last ? pWriter->pLastFD : pWriter->pDataFD; + SBlockDataHdr hdr = {.delimiter = TSDB_FILE_DLMT, .suid = pBlockIdx->suid, .uid = pBlockIdx->uid}; + uint8_t *p; + int64_t nData; + uint8_t *pBuf1 = NULL; + uint8_t *pBuf2 = NULL; + SArray *aBlockCol = NULL; + + if (!ppBuf1) ppBuf1 = &pBuf1; + if (!ppBuf2) ppBuf2 = &pBuf2; + + tsdbUpdateBlockInfo(pBlockData, pBlock); + + pSubBlock->nRow = pBlockData->nRow; + pSubBlock->cmprAlg = cmprAlg; + if (pBlock->last) { + pSubBlock->offset = pWriter->wSet.fLast.size; + } else { + pSubBlock->offset = pWriter->wSet.fData.size; + } + + // ======================= BLOCK DATA ======================= + // TSDBKEY + nData = 0; + code = tsdbWriteBlockDataKey(pSubBlock, pBlockData, ppBuf1, &nData, ppBuf2); + if (code) goto _err; + + // COLUMNS + aBlockCol = taosArrayInit(taosArrayGetSize(pBlockData->aIdx), sizeof(SBlockCol)); + if (aBlockCol == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + int32_t offset = 0; + for (int32_t iCol = 0; iCol < taosArrayGetSize(pBlockData->aIdx); iCol++) { + SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iCol); + + ASSERT(pColData->flag); + + if (pColData->flag == HAS_NONE) continue; + + pBlockCol->cid = pColData->cid; + pBlockCol->type = pColData->type; + pBlockCol->smaOn = pColData->smaOn; + pBlockCol->flag = pColData->flag; + + if (pColData->flag != HAS_NULL) { + code = tsdbWriteColData(pColData, pBlockCol, pSubBlock, ppBuf1, &nData, ppBuf2); + if (code) goto _err; + + pBlockCol->offset = offset; + offset = offset + pBlockCol->szBitmap + pBlockCol->szOffset + pBlockCol->szValue + sizeof(TSCKSUM); + } + + if (taosArrayPush(aBlockCol, pBlockCol) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + // write + code = tsdbWriteBlockDataImpl(pFileFD, pSubBlock, hdr, aBlockCol, *ppBuf1, nData, ppBuf2); + if (code) goto _err; + + pSubBlock->szBlock = pSubBlock->szBlockCol + sizeof(TSCKSUM) + nData; + if (pBlock->last) { + pWriter->wSet.fLast.size += pSubBlock->szBlock; + } else { + pWriter->wSet.fData.size += pSubBlock->szBlock; + } + + // ======================= BLOCK SMA ======================= + pSubBlock->sOffset = 0; + pSubBlock->nSma = 0; + + if (pBlock->nSubBlock > 1 || pBlock->last || pBlock->hasDup) goto _exit; + + code = tsdbWriteBlockSma(pWriter->pSmaFD, pBlockData, pSubBlock, ppBuf1); + if (code) goto _err; + + if (pSubBlock->nSma > 0) { + pSubBlock->sOffset = pWriter->wSet.fSma.size; + pWriter->wSet.fSma.size += (sizeof(SColumnDataAgg) * pSubBlock->nSma + sizeof(TSCKSUM)); + } + +_exit: + tFree(pBuf1); + tFree(pBuf2); + taosArrayDestroy(aBlockCol); + return code; + +_err: + tsdbError("vgId:%d write block data failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tFree(pBuf1); + tFree(pBuf2); + taosArrayDestroy(aBlockCol); + return code; +} diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c new file mode 100644 index 0000000000000000000000000000000000000000..f906ef1b54e72e5b0a229bcce3f6842e120c31ce --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -0,0 +1,1270 @@ +/* + * 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 . + */ + +#include "tsdb.h" + +// SMapData ======================================================================= +void tMapDataReset(SMapData *pMapData) { + pMapData->nItem = 0; + pMapData->nData = 0; +} + +void tMapDataClear(SMapData *pMapData) { + tFree((uint8_t *)pMapData->aOffset); + tFree(pMapData->pData); +} + +int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *)) { + int32_t code = 0; + int32_t offset = pMapData->nData; + int32_t nItem = pMapData->nItem; + + pMapData->nItem++; + pMapData->nData += tPutItemFn(NULL, pItem); + + // alloc + code = tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem); + if (code) goto _err; + code = tRealloc(&pMapData->pData, pMapData->nData); + if (code) goto _err; + + // put + pMapData->aOffset[nItem] = offset; + tPutItemFn(pMapData->pData + offset, pItem); + +_err: + return code; +} + +int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *), + int32_t (*tItemCmprFn)(const void *, const void *), void *pItem) { + int32_t code = 0; + int32_t lidx = 0; + int32_t ridx = pMapData->nItem - 1; + int32_t midx; + int32_t c; + + while (lidx <= ridx) { + midx = (lidx + ridx) / 2; + + tMapDataGetItemByIdx(pMapData, midx, pItem, tGetItemFn); + + c = tItemCmprFn(pSearchItem, pItem); + if (c == 0) { + goto _exit; + } else if (c < 0) { + ridx = midx - 1; + } else { + lidx = midx + 1; + } + } + + code = TSDB_CODE_NOT_FOUND; + +_exit: + return code; +} + +void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) { + ASSERT(idx >= 0 && idx < pMapData->nItem); + tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem); +} + +int32_t tPutMapData(uint8_t *p, SMapData *pMapData) { + int32_t n = 0; + + n += tPutI32v(p ? p + n : p, pMapData->nItem); + if (pMapData->nItem) { + for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) { + n += tPutI32v(p ? p + n : p, pMapData->aOffset[iItem]); + } + + n += tPutI32v(p ? p + n : p, pMapData->nData); + if (p) { + memcpy(p + n, pMapData->pData, pMapData->nData); + } + n += pMapData->nData; + } + + return n; +} + +int32_t tGetMapData(uint8_t *p, SMapData *pMapData) { + int32_t n = 0; + int32_t offset; + + tMapDataReset(pMapData); + + n += tGetI32v(p + n, &pMapData->nItem); + if (pMapData->nItem) { + if (tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem)) return -1; + + for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) { + n += tGetI32v(p + n, &pMapData->aOffset[iItem]); + } + + n += tGetI32v(p + n, &pMapData->nData); + if (tRealloc(&pMapData->pData, pMapData->nData)) return -1; + memcpy(pMapData->pData, p + n, pMapData->nData); + n += pMapData->nData; + } + + return n; +} + +// TABLEID ======================================================================= +int32_t tTABLEIDCmprFn(const void *p1, const void *p2) { + TABLEID *pId1 = (TABLEID *)p1; + TABLEID *pId2 = (TABLEID *)p2; + + if (pId1->suid < pId2->suid) { + return -1; + } else if (pId1->suid > pId2->suid) { + return 1; + } + + if (pId1->uid < pId2->uid) { + return -1; + } else if (pId1->uid > pId2->uid) { + return 1; + } + + return 0; +} + +// TSDBKEY ======================================================================= +int32_t tsdbKeyCmprFn(const void *p1, const void *p2) { + TSDBKEY *pKey1 = (TSDBKEY *)p1; + TSDBKEY *pKey2 = (TSDBKEY *)p2; + + if (pKey1->ts < pKey2->ts) { + return -1; + } else if (pKey1->ts > pKey2->ts) { + return 1; + } + + if (pKey1->version < pKey2->version) { + return -1; + } else if (pKey1->version > pKey2->version) { + return 1; + } + + return 0; +} + +// TSDBKEY ====================================================== +static FORCE_INLINE int32_t tPutTSDBKEY(uint8_t *p, TSDBKEY *pKey) { + int32_t n = 0; + + n += tPutI64v(p ? p + n : p, pKey->version); + n += tPutI64(p ? p + n : p, pKey->ts); + + return n; +} + +static FORCE_INLINE int32_t tGetTSDBKEY(uint8_t *p, TSDBKEY *pKey) { + int32_t n = 0; + + n += tGetI64v(p + n, &pKey->version); + n += tGetI64(p + n, &pKey->ts); + + return n; +} + +// SBlockIdx ====================================================== +void tBlockIdxReset(SBlockIdx *pBlockIdx) { + pBlockIdx->minKey = TSKEY_MAX; + pBlockIdx->maxKey = TSKEY_MIN; + pBlockIdx->minVersion = VERSION_MAX; + pBlockIdx->maxVersion = VERSION_MIN; + pBlockIdx->offset = -1; + pBlockIdx->size = -1; +} + +int32_t tPutBlockIdx(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockIdx *pBlockIdx = (SBlockIdx *)ph; + + n += tPutI64(p ? p + n : p, pBlockIdx->suid); + n += tPutI64(p ? p + n : p, pBlockIdx->uid); + n += tPutI64(p ? p + n : p, pBlockIdx->minKey); + n += tPutI64(p ? p + n : p, pBlockIdx->maxKey); + n += tPutI64v(p ? p + n : p, pBlockIdx->minVersion); + n += tPutI64v(p ? p + n : p, pBlockIdx->maxVersion); + n += tPutI64v(p ? p + n : p, pBlockIdx->offset); + n += tPutI64v(p ? p + n : p, pBlockIdx->size); + + return n; +} + +int32_t tGetBlockIdx(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockIdx *pBlockIdx = (SBlockIdx *)ph; + + n += tGetI64(p + n, &pBlockIdx->suid); + n += tGetI64(p + n, &pBlockIdx->uid); + n += tGetI64(p + n, &pBlockIdx->minKey); + n += tGetI64(p + n, &pBlockIdx->maxKey); + n += tGetI64v(p + n, &pBlockIdx->minVersion); + n += tGetI64v(p + n, &pBlockIdx->maxVersion); + n += tGetI64v(p + n, &pBlockIdx->offset); + n += tGetI64v(p + n, &pBlockIdx->size); + + return n; +} + +int32_t tCmprBlockIdx(void const *lhs, void const *rhs) { + SBlockIdx *lBlockIdx = (SBlockIdx *)lhs; + SBlockIdx *rBlockIdx = (SBlockIdx *)rhs; + + if (lBlockIdx->suid < rBlockIdx->suid) { + return -1; + } else if (lBlockIdx->suid > rBlockIdx->suid) { + return 1; + } + + if (lBlockIdx->uid < rBlockIdx->uid) { + return -1; + } else if (lBlockIdx->uid > rBlockIdx->uid) { + return 1; + } + + return 0; +} + +// SBlock ====================================================== +void tBlockReset(SBlock *pBlock) { + *pBlock = + (SBlock){.minKey = TSDBKEY_MAX, .maxKey = TSDBKEY_MIN, .minVersion = VERSION_MAX, .maxVersion = VERSION_MIN}; +} + +int32_t tPutBlock(uint8_t *p, void *ph) { + int32_t n = 0; + SBlock *pBlock = (SBlock *)ph; + + n += tPutTSDBKEY(p ? p + n : p, &pBlock->minKey); + n += tPutTSDBKEY(p ? p + n : p, &pBlock->maxKey); + n += tPutI64v(p ? p + n : p, pBlock->minVersion); + n += tPutI64v(p ? p + n : p, pBlock->maxVersion); + n += tPutI32v(p ? p + n : p, pBlock->nRow); + n += tPutI8(p ? p + n : p, pBlock->last); + n += tPutI8(p ? p + n : p, pBlock->hasDup); + n += tPutI8(p ? p + n : p, pBlock->nSubBlock); + for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) { + n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].nRow); + n += tPutI8(p ? p + n : p, pBlock->aSubBlock[iSubBlock].cmprAlg); + n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].offset); + n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szBlockCol); + n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szVersion); + n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szTSKEY); + n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szBlock); + n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].sOffset); + n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].nSma); + } + + return n; +} + +int32_t tGetBlock(uint8_t *p, void *ph) { + int32_t n = 0; + SBlock *pBlock = (SBlock *)ph; + + n += tGetTSDBKEY(p + n, &pBlock->minKey); + n += tGetTSDBKEY(p + n, &pBlock->maxKey); + n += tGetI64v(p + n, &pBlock->minVersion); + n += tGetI64v(p + n, &pBlock->maxVersion); + n += tGetI32v(p + n, &pBlock->nRow); + n += tGetI8(p + n, &pBlock->last); + n += tGetI8(p + n, &pBlock->hasDup); + n += tGetI8(p + n, &pBlock->nSubBlock); + for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) { + n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].nRow); + n += tGetI8(p + n, &pBlock->aSubBlock[iSubBlock].cmprAlg); + n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].offset); + n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szBlockCol); + n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szVersion); + n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szTSKEY); + n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szBlock); + n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].sOffset); + n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].nSma); + } + + return n; +} + +int32_t tBlockCmprFn(const void *p1, const void *p2) { + SBlock *pBlock1 = (SBlock *)p1; + SBlock *pBlock2 = (SBlock *)p2; + + if (tsdbKeyCmprFn(&pBlock1->maxKey, &pBlock2->minKey) < 0) { + return -1; + } else if (tsdbKeyCmprFn(&pBlock1->minKey, &pBlock2->maxKey) > 0) { + return 1; + } + + return 0; +} + +bool tBlockHasSma(SBlock *pBlock) { + if (pBlock->nSubBlock > 1) return false; + if (pBlock->last) return false; + if (pBlock->hasDup) return false; + + return pBlock->aSubBlock[0].nSma > 0; +} + +// SBlockCol ====================================================== +int32_t tPutBlockCol(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockCol *pBlockCol = (SBlockCol *)ph; + + ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE)); + + n += tPutI16v(p ? p + n : p, pBlockCol->cid); + n += tPutI8(p ? p + n : p, pBlockCol->type); + n += tPutI8(p ? p + n : p, pBlockCol->smaOn); + n += tPutI8(p ? p + n : p, pBlockCol->flag); + + if (pBlockCol->flag != HAS_NULL) { + n += tPutI32v(p ? p + n : p, pBlockCol->offset); + n += tPutI32v(p ? p + n : p, pBlockCol->szBitmap); + n += tPutI32v(p ? p + n : p, pBlockCol->szOffset); + n += tPutI32v(p ? p + n : p, pBlockCol->szValue); + n += tPutI32v(p ? p + n : p, pBlockCol->szOrigin); + } + + return n; +} + +int32_t tGetBlockCol(uint8_t *p, void *ph) { + int32_t n = 0; + SBlockCol *pBlockCol = (SBlockCol *)ph; + + n += tGetI16v(p + n, &pBlockCol->cid); + n += tGetI8(p + n, &pBlockCol->type); + n += tGetI8(p + n, &pBlockCol->smaOn); + n += tGetI8(p + n, &pBlockCol->flag); + + ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE)); + + if (pBlockCol->flag != HAS_NULL) { + n += tGetI32v(p + n, &pBlockCol->offset); + n += tGetI32v(p + n, &pBlockCol->szBitmap); + n += tGetI32v(p + n, &pBlockCol->szOffset); + n += tGetI32v(p + n, &pBlockCol->szValue); + n += tGetI32v(p + n, &pBlockCol->szOrigin); + } + + return n; +} + +int32_t tBlockColCmprFn(const void *p1, const void *p2) { + if (((SBlockCol *)p1)->cid < ((SBlockCol *)p2)->cid) { + return -1; + } else if (((SBlockCol *)p1)->cid > ((SBlockCol *)p2)->cid) { + return 1; + } + + return 0; +} + +// SDelIdx ====================================================== +int32_t tCmprDelIdx(void const *lhs, void const *rhs) { + SDelIdx *lDelIdx = (SDelIdx *)lhs; + SDelIdx *rDelIdx = (SDelIdx *)rhs; + + if (lDelIdx->suid < rDelIdx->suid) { + return -1; + } else if (lDelIdx->suid > rDelIdx->suid) { + return 1; + } + + if (lDelIdx->uid < rDelIdx->uid) { + return -1; + } else if (lDelIdx->uid > rDelIdx->uid) { + return 1; + } + + return 0; +} + +int32_t tPutDelIdx(uint8_t *p, void *ph) { + SDelIdx *pDelIdx = (SDelIdx *)ph; + int32_t n = 0; + + n += tPutI64(p ? p + n : p, pDelIdx->suid); + n += tPutI64(p ? p + n : p, pDelIdx->uid); + n += tPutI64v(p ? p + n : p, pDelIdx->offset); + n += tPutI64v(p ? p + n : p, pDelIdx->size); + + return n; +} + +int32_t tGetDelIdx(uint8_t *p, void *ph) { + SDelIdx *pDelIdx = (SDelIdx *)ph; + int32_t n = 0; + + n += tGetI64(p + n, &pDelIdx->suid); + n += tGetI64(p + n, &pDelIdx->uid); + n += tGetI64v(p + n, &pDelIdx->offset); + n += tGetI64v(p + n, &pDelIdx->size); + + return n; +} + +// SDelData ====================================================== +int32_t tPutDelData(uint8_t *p, void *ph) { + SDelData *pDelData = (SDelData *)ph; + int32_t n = 0; + + n += tPutI64v(p ? p + n : p, pDelData->version); + n += tPutI64(p ? p + n : p, pDelData->sKey); + n += tPutI64(p ? p + n : p, pDelData->eKey); + + return n; +} + +int32_t tGetDelData(uint8_t *p, void *ph) { + SDelData *pDelData = (SDelData *)ph; + int32_t n = 0; + + n += tGetI64v(p + n, &pDelData->version); + n += tGetI64(p + n, &pDelData->sKey); + n += tGetI64(p + n, &pDelData->eKey); + + return n; +} + +int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision) { + if (key < 0) { + return (int)((key + 1) / tsTickPerMin[precision] / minutes - 1); + } else { + return (int)((key / tsTickPerMin[precision] / minutes)); + } +} + +void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey) { + *minKey = fid * minutes * tsTickPerMin[precision]; + *maxKey = *minKey + minutes * tsTickPerMin[precision] - 1; +} + +// int tsdFidLevel(int fid, TSKEY now, minute) { +// if (fid >= pRtn->maxFid) { +// return 0; +// } else if (fid >= pRtn->midFid) { +// return 1; +// } else if (fid >= pRtn->minFid) { +// return 2; +// } else { +// return -1; +// } +// } + +// TSDBROW ====================================================== +void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { + STColumn *pTColumn = &pTSchema->columns[iCol]; + SValue value; + + ASSERT(iCol > 0); + + if (pRow->type == 0) { + tTSRowGetVal(pRow->pTSRow, pTSchema, iCol, pColVal); + } else if (pRow->type == 1) { + SColData *pColData; + + tBlockDataGetColData(pRow->pBlockData, pTColumn->colId, &pColData); + + if (pColData) { + tColDataGetValue(pColData, pRow->iRow, pColVal); + } else { + *pColVal = COL_VAL_NONE(pTColumn->colId, pTColumn->type); + } + } else { + ASSERT(0); + } +} + +int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) { + int32_t n = 0; + + n += tPutI64(p, pRow->version); + if (p) memcpy(p + n, pRow->pTSRow, pRow->pTSRow->len); + n += pRow->pTSRow->len; + + return n; +} + +int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow) { + int32_t n = 0; + + n += tGetI64(p, &pRow->version); + pRow->pTSRow = (STSRow *)(p + n); + n += pRow->pTSRow->len; + + return n; +} + +int32_t tsdbRowCmprFn(const void *p1, const void *p2) { + return tsdbKeyCmprFn(&TSDBROW_KEY((TSDBROW *)p1), &TSDBROW_KEY((TSDBROW *)p2)); +} + +// SRowIter ====================================================== +void tRowIterInit(SRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) { + pIter->pRow = pRow; + if (pRow->type == 0) { + ASSERT(pTSchema); + pIter->pTSchema = pTSchema; + pIter->i = 1; + } else if (pRow->type == 1) { + pIter->pTSchema = NULL; + pIter->i = 0; + } else { + ASSERT(0); + } +} + +SColVal *tRowIterNext(SRowIter *pIter) { + if (pIter->pRow->type == 0) { + if (pIter->i < pIter->pTSchema->numOfCols) { + tsdbRowGetColVal(pIter->pRow, pIter->pTSchema, pIter->i, &pIter->colVal); + pIter->i++; + + return &pIter->colVal; + } + } else { + if (pIter->i < taosArrayGetSize(pIter->pRow->pBlockData->aIdx)) { + SColData *pColData = tBlockDataGetColDataByIdx(pIter->pRow->pBlockData, pIter->i); + + tColDataGetValue(pColData, pIter->pRow->iRow, &pIter->colVal); + pIter->i++; + + return &pIter->colVal; + } + } + + return NULL; +} + +// SRowMerger ====================================================== +int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) { + int32_t code = 0; + TSDBKEY key = TSDBROW_KEY(pRow); + SColVal *pColVal = &(SColVal){0}; + STColumn *pTColumn; + + pMerger->pTSchema = pTSchema; + pMerger->version = key.version; + + pMerger->pArray = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)); + if (pMerger->pArray == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + // ts + pTColumn = &pTSchema->columns[0]; + + ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP); + + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = key.ts}); + if (taosArrayPush(pMerger->pArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + // other + for (int16_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) { + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + if (taosArrayPush(pMerger->pArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + } + +_exit: + return code; +} + +void tRowMergerClear(SRowMerger *pMerger) { taosArrayDestroy(pMerger->pArray); } + +int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow) { + int32_t code = 0; + TSDBKEY key = TSDBROW_KEY(pRow); + SColVal *pColVal = &(SColVal){0}; + + ASSERT(((SColVal *)pMerger->pArray->pData)->value.ts == key.ts); + + for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) { + tsdbRowGetColVal(pRow, pMerger->pTSchema, iCol, pColVal); + + if (key.version > pMerger->version) { + if (!pColVal->isNone) { + taosArraySet(pMerger->pArray, iCol, pColVal); + } + } else if (key.version < pMerger->version) { + SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol); + if (tColVal->isNone && !pColVal->isNone) { + taosArraySet(pMerger->pArray, iCol, pColVal); + } + } else { + ASSERT(0); + } + } + + pMerger->version = key.version; + +_exit: + return code; +} + +int32_t tRowMergerGetRow(SRowMerger *pMerger, STSRow **ppRow) { + int32_t code = 0; + + code = tdSTSRowNew(pMerger->pArray, pMerger->pTSchema, ppRow); + + return code; +} + +// delete skyline ====================================================== +static int32_t tsdbMergeSkyline(SArray *aSkyline1, SArray *aSkyline2, SArray *aSkyline) { + int32_t code = 0; + int32_t i1 = 0; + int32_t n1 = taosArrayGetSize(aSkyline1); + int32_t i2 = 0; + int32_t n2 = taosArrayGetSize(aSkyline2); + TSDBKEY *pSkyline1; + TSDBKEY *pSkyline2; + TSDBKEY item; + int64_t version1 = 0; + int64_t version2 = 0; + + ASSERT(n1 > 0 && n2 > 0); + + taosArrayClear(aSkyline); + + while (i1 < n1 && i2 < n2) { + pSkyline1 = (TSDBKEY *)taosArrayGet(aSkyline1, i1); + pSkyline2 = (TSDBKEY *)taosArrayGet(aSkyline2, i2); + + if (pSkyline1->ts < pSkyline2->ts) { + version1 = pSkyline1->version; + i1++; + } else if (pSkyline1->ts > pSkyline2->ts) { + version2 = pSkyline2->version; + i2++; + } else { + version1 = pSkyline1->version; + version2 = pSkyline2->version; + i1++; + i2++; + } + + item.ts = TMIN(pSkyline1->ts, pSkyline2->ts); + item.version = TMAX(version1, version2); + if (taosArrayPush(aSkyline, &item) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + } + + while (i1 < n1) { + pSkyline1 = (TSDBKEY *)taosArrayGet(aSkyline1, i1); + item.ts = pSkyline1->ts; + item.version = pSkyline1->version; + if (taosArrayPush(aSkyline, &item) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + i1++; + } + + while (i2 < n2) { + pSkyline2 = (TSDBKEY *)taosArrayGet(aSkyline2, i2); + item.ts = pSkyline2->ts; + item.version = pSkyline2->version; + if (taosArrayPush(aSkyline, &item) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + i2++; + } + +_exit: + return code; +} +int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline) { + int32_t code = 0; + SDelData *pDelData; + int32_t midx; + + taosArrayClear(aSkyline); + if (sidx == eidx) { + pDelData = (SDelData *)taosArrayGet(aDelData, sidx); + taosArrayPush(aSkyline, &(TSDBKEY){.ts = pDelData->sKey, .version = pDelData->version}); + taosArrayPush(aSkyline, &(TSDBKEY){.ts = pDelData->eKey, .version = 0}); + } else { + SArray *aSkyline1 = NULL; + SArray *aSkyline2 = NULL; + + aSkyline1 = taosArrayInit(0, sizeof(TSDBKEY)); + aSkyline2 = taosArrayInit(0, sizeof(TSDBKEY)); + if (aSkyline1 == NULL || aSkyline2 == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _clear; + } + + midx = (sidx + eidx) / 2; + + code = tsdbBuildDeleteSkyline(aDelData, sidx, midx, aSkyline1); + if (code) goto _clear; + + code = tsdbBuildDeleteSkyline(aDelData, midx + 1, eidx, aSkyline2); + if (code) goto _clear; + + code = tsdbMergeSkyline(aSkyline1, aSkyline2, aSkyline); + + _clear: + taosArrayDestroy(aSkyline1); + taosArrayDestroy(aSkyline2); + } + + return code; +} + +// SColData ======================================== +void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn) { + pColData->cid = cid; + pColData->type = type; + pColData->smaOn = smaOn; + tColDataReset(pColData); +} + +void tColDataReset(SColData *pColData) { + pColData->nVal = 0; + pColData->flag = 0; + pColData->nData = 0; +} + +void tColDataClear(void *ph) { + SColData *pColData = (SColData *)ph; + + tFree(pColData->pBitMap); + tFree((uint8_t *)pColData->aOffset); + tFree(pColData->pData); +} + +int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal) { + int32_t code = 0; + int64_t size; + SValue value = {0}; + SValue *pValue = &value; + + ASSERT(pColVal->cid == pColData->cid); + ASSERT(pColVal->type == pColData->type); + + // realloc bitmap + size = BIT2_SIZE(pColData->nVal + 1); + code = tRealloc(&pColData->pBitMap, size); + if (code) goto _exit; + + // put value + if (pColVal->isNone) { + pColData->flag |= HAS_NONE; + SET_BIT2(pColData->pBitMap, pColData->nVal, 0); + } else if (pColVal->isNull) { + pColData->flag |= HAS_NULL; + SET_BIT2(pColData->pBitMap, pColData->nVal, 1); + } else { + pColData->flag |= HAS_VALUE; + SET_BIT2(pColData->pBitMap, pColData->nVal, 2); + pValue = &pColVal->value; + } + + if (IS_VAR_DATA_TYPE(pColData->type)) { + // offset + code = tRealloc((uint8_t **)&pColData->aOffset, sizeof(int32_t) * (pColData->nVal + 1)); + if (code) goto _exit; + pColData->aOffset[pColData->nVal] = pColData->nData; + + // value + if ((!pColVal->isNone) && (!pColVal->isNull)) { + code = tRealloc(&pColData->pData, pColData->nData + pColVal->value.nData); + if (code) goto _exit; + memcpy(pColData->pData + pColData->nData, pColVal->value.pData, pColVal->value.nData); + pColData->nData += pColVal->value.nData; + } + } else { + code = tRealloc(&pColData->pData, pColData->nData + tPutValue(NULL, pValue, pColVal->type)); + if (code) goto _exit; + pColData->nData += tPutValue(pColData->pData + pColData->nData, pValue, pColVal->type); + } + + pColData->nVal++; + +_exit: + return code; +} + +int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest) { + int32_t code = 0; + int32_t size; + + pColDataDest->cid = pColDataSrc->cid; + pColDataDest->type = pColDataSrc->type; + pColDataDest->smaOn = pColDataSrc->smaOn; + pColDataDest->nVal = pColDataSrc->nVal; + pColDataDest->flag = pColDataSrc->flag; + + size = BIT2_SIZE(pColDataSrc->nVal); + code = tRealloc(&pColDataDest->pBitMap, size); + if (code) goto _exit; + memcpy(pColDataDest->pBitMap, pColDataSrc->pBitMap, size); + + if (IS_VAR_DATA_TYPE(pColDataDest->type)) { + size = sizeof(int32_t) * pColDataSrc->nVal; + + code = tRealloc((uint8_t **)&pColDataDest->aOffset, size); + if (code) goto _exit; + + memcpy(pColDataDest->aOffset, pColDataSrc->aOffset, size); + } + + code = tRealloc(&pColDataDest->pData, pColDataSrc->nData); + if (code) goto _exit; + pColDataDest->nData = pColDataSrc->nData; + memcpy(pColDataDest->pData, pColDataSrc->pData, pColDataDest->nData); + +_exit: + return code; +} + +int32_t tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) { + int32_t code = 0; + + ASSERT(iVal < pColData->nVal); + ASSERT(pColData->flag); + + if (pColData->flag == HAS_NONE) { + *pColVal = COL_VAL_NONE(pColData->cid, pColData->type); + goto _exit; + } else if (pColData->flag == HAS_NULL) { + *pColVal = COL_VAL_NULL(pColData->cid, pColData->type); + goto _exit; + } else if (pColData->flag != HAS_VALUE) { + uint8_t v = GET_BIT2(pColData->pBitMap, iVal); + if (v == 0) { + *pColVal = COL_VAL_NONE(pColData->cid, pColData->type); + goto _exit; + } else if (v == 1) { + *pColVal = COL_VAL_NULL(pColData->cid, pColData->type); + goto _exit; + } + } + + // get value + SValue value; + if (IS_VAR_DATA_TYPE(pColData->type)) { + if (iVal + 1 < pColData->nVal) { + value.nData = pColData->aOffset[iVal + 1] - pColData->aOffset[iVal]; + } else { + value.nData = pColData->nData - pColData->aOffset[iVal]; + } + + value.pData = pColData->pData + pColData->aOffset[iVal]; + } else { + tGetValue(pColData->pData + tDataTypes[pColData->type].bytes * iVal, &value, pColData->type); + } + *pColVal = COL_VAL_VALUE(pColData->cid, pColData->type, value); + +_exit: + return code; +} + +static FORCE_INLINE int32_t tColDataCmprFn(const void *p1, const void *p2) { + SColData *pColData1 = (SColData *)p1; + SColData *pColData2 = (SColData *)p2; + + if (pColData1->cid < pColData2->cid) { + return -1; + } else if (pColData1->cid > pColData2->cid) { + return 1; + } + + return 0; +} + +// SBlockData ====================================================== +int32_t tBlockDataInit(SBlockData *pBlockData) { + int32_t code = 0; + + pBlockData->nRow = 0; + pBlockData->aVersion = NULL; + pBlockData->aTSKEY = NULL; + pBlockData->aIdx = taosArrayInit(0, sizeof(int32_t)); + if (pBlockData->aIdx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + pBlockData->aColData = taosArrayInit(0, sizeof(SColData)); + if (pBlockData->aColData == NULL) { + taosArrayDestroy(pBlockData->aIdx); + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + +_exit: + return code; +} + +void tBlockDataReset(SBlockData *pBlockData) { + pBlockData->nRow = 0; + taosArrayClear(pBlockData->aIdx); +} + +void tBlockDataClear(SBlockData *pBlockData) { + tFree((uint8_t *)pBlockData->aVersion); + tFree((uint8_t *)pBlockData->aTSKEY); + taosArrayDestroy(pBlockData->aIdx); + taosArrayDestroyEx(pBlockData->aColData, tColDataClear); +} + +int32_t tBlockDataSetSchema(SBlockData *pBlockData, STSchema *pTSchema) { + int32_t code = 0; + SColData *pColData; + STColumn *pTColumn; + + tBlockDataReset(pBlockData); + for (int32_t iColumn = 1; iColumn < pTSchema->numOfCols; iColumn++) { + pTColumn = &pTSchema->columns[iColumn]; + + code = tBlockDataAddColData(pBlockData, iColumn - 1, &pColData); + if (code) goto _exit; + + tColDataInit(pColData, pTColumn->colId, pTColumn->type, (pTColumn->flags & COL_SMA_ON) != 0); + } + +_exit: + return code; +} + +void tBlockDataClearData(SBlockData *pBlockData) { + pBlockData->nRow = 0; + for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { + SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); + tColDataReset(pColData); + } +} + +int32_t tBlockDataAddColData(SBlockData *pBlockData, int32_t iColData, SColData **ppColData) { + int32_t code = 0; + SColData *pColData = NULL; + int32_t idx = taosArrayGetSize(pBlockData->aIdx); + + if (idx >= taosArrayGetSize(pBlockData->aColData)) { + if (taosArrayPush(pBlockData->aColData, &((SColData){0})) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + pColData = (SColData *)taosArrayGet(pBlockData->aColData, idx); + + if (taosArrayInsert(pBlockData->aIdx, iColData, &idx) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + *ppColData = pColData; + return code; + +_err: + *ppColData = NULL; + return code; +} + +int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema) { + int32_t code = 0; + + // TSDBKEY + code = tRealloc((uint8_t **)&pBlockData->aVersion, sizeof(int64_t) * (pBlockData->nRow + 1)); + if (code) goto _err; + code = tRealloc((uint8_t **)&pBlockData->aTSKEY, sizeof(TSKEY) * (pBlockData->nRow + 1)); + if (code) goto _err; + pBlockData->aVersion[pBlockData->nRow] = TSDBROW_VERSION(pRow); + pBlockData->aTSKEY[pBlockData->nRow] = TSDBROW_TS(pRow); + + // OTHER + int32_t iColData = 0; + int32_t nColData = taosArrayGetSize(pBlockData->aIdx); + SRowIter iter = {0}; + SRowIter *pIter = &iter; + SColData *pColData; + SColVal *pColVal; + + ASSERT(nColData > 0); + + tRowIterInit(pIter, pRow, pTSchema); + pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); + pColVal = tRowIterNext(pIter); + + while (pColData) { + if (pColVal) { + if (pColData->cid == pColVal->cid) { + code = tColDataAppendValue(pColData, pColVal); + if (code) goto _err; + + pColVal = tRowIterNext(pIter); + pColData = ((++iColData) < nColData) ? tBlockDataGetColDataByIdx(pBlockData, iColData) : NULL; + } else if (pColData->cid < pColVal->cid) { + code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type)); + if (code) goto _err; + + pColData = ((++iColData) < nColData) ? tBlockDataGetColDataByIdx(pBlockData, iColData) : NULL; + } else { + pColVal = tRowIterNext(pIter); + } + } else { + code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type)); + if (code) goto _err; + + pColData = ((++iColData) < nColData) ? tBlockDataGetColDataByIdx(pBlockData, iColData) : NULL; + } + } + + pBlockData->nRow++; + return code; + +_err: + return code; +} + +int32_t tBlockDataMerge(SBlockData *pBlockData1, SBlockData *pBlockData2, SBlockData *pBlockData) { + int32_t code = 0; + + // set target + int32_t iColData1 = 0; + int32_t nColData1 = taosArrayGetSize(pBlockData1->aIdx); + int32_t iColData2 = 0; + int32_t nColData2 = taosArrayGetSize(pBlockData2->aIdx); + SColData *pColData1; + SColData *pColData2; + SColData *pColData; + + tBlockDataReset(pBlockData); + while (iColData1 < nColData1 && iColData2 < nColData2) { + pColData1 = tBlockDataGetColDataByIdx(pBlockData1, iColData1); + pColData2 = tBlockDataGetColDataByIdx(pBlockData2, iColData2); + + if (pColData1->cid == pColData2->cid) { + code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + if (code) goto _exit; + tColDataInit(pColData, pColData2->cid, pColData2->type, pColData2->smaOn); + + iColData1++; + iColData2++; + } else if (pColData1->cid < pColData2->cid) { + code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + if (code) goto _exit; + tColDataInit(pColData, pColData1->cid, pColData1->type, pColData1->smaOn); + + iColData1++; + } else { + code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + if (code) goto _exit; + tColDataInit(pColData, pColData2->cid, pColData2->type, pColData2->smaOn); + + iColData2++; + } + } + + while (iColData1 < nColData1) { + code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + if (code) goto _exit; + tColDataInit(pColData, pColData1->cid, pColData1->type, pColData1->smaOn); + + iColData1++; + } + + while (iColData2 < nColData2) { + code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + if (code) goto _exit; + tColDataInit(pColData, pColData2->cid, pColData2->type, pColData2->smaOn); + + iColData2++; + } + + // loop to merge + int32_t iRow1 = 0; + int32_t nRow1 = pBlockData1->nRow; + int32_t iRow2 = 0; + int32_t nRow2 = pBlockData2->nRow; + TSDBROW row1; + TSDBROW row2; + int32_t c; + + while (iRow1 < nRow1 && iRow2 < nRow2) { + row1 = tsdbRowFromBlockData(pBlockData1, iRow1); + row2 = tsdbRowFromBlockData(pBlockData2, iRow2); + + c = tsdbKeyCmprFn(&TSDBROW_KEY(&row1), &TSDBROW_KEY(&row2)); + if (c < 0) { + code = tBlockDataAppendRow(pBlockData, &row1, NULL); + if (code) goto _exit; + iRow1++; + } else if (c > 0) { + code = tBlockDataAppendRow(pBlockData, &row2, NULL); + if (code) goto _exit; + iRow2++; + } else { + ASSERT(0); + } + } + + while (iRow1 < nRow1) { + row1 = tsdbRowFromBlockData(pBlockData1, iRow1); + code = tBlockDataAppendRow(pBlockData, &row1, NULL); + if (code) goto _exit; + iRow1++; + } + + while (iRow2 < nRow2) { + row2 = tsdbRowFromBlockData(pBlockData2, iRow2); + code = tBlockDataAppendRow(pBlockData, &row2, NULL); + if (code) goto _exit; + iRow2++; + } + +_exit: + return code; +} + +int32_t tBlockDataCopy(SBlockData *pBlockDataSrc, SBlockData *pBlockDataDest) { + int32_t code = 0; + SColData *pColDataSrc; + SColData *pColDataDest; + + ASSERT(pBlockDataSrc->nRow > 0); + + tBlockDataReset(pBlockDataDest); + + pBlockDataDest->nRow = pBlockDataSrc->nRow; + // TSDBKEY + code = tRealloc((uint8_t **)&pBlockDataDest->aVersion, sizeof(int64_t) * pBlockDataSrc->nRow); + if (code) goto _exit; + code = tRealloc((uint8_t **)&pBlockDataDest->aTSKEY, sizeof(TSKEY) * pBlockDataSrc->nRow); + if (code) goto _exit; + memcpy(pBlockDataDest->aVersion, pBlockDataSrc->aVersion, sizeof(int64_t) * pBlockDataSrc->nRow); + memcpy(pBlockDataDest->aTSKEY, pBlockDataSrc->aTSKEY, sizeof(TSKEY) * pBlockDataSrc->nRow); + + // other + for (size_t iColData = 0; iColData < taosArrayGetSize(pBlockDataSrc->aIdx); iColData++) { + pColDataSrc = tBlockDataGetColDataByIdx(pBlockDataSrc, iColData); + code = tBlockDataAddColData(pBlockDataDest, iColData, &pColDataDest); + if (code) goto _exit; + + code = tColDataCopy(pColDataSrc, pColDataDest); + if (code) goto _exit; + } + +_exit: + return code; +} + +SColData *tBlockDataGetColDataByIdx(SBlockData *pBlockData, int32_t idx) { + ASSERT(idx >= 0 && idx < taosArrayGetSize(pBlockData->aIdx)); + return (SColData *)taosArrayGet(pBlockData->aColData, *(int32_t *)taosArrayGet(pBlockData->aIdx, idx)); +} + +void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData) { + ASSERT(cid != PRIMARYKEY_TIMESTAMP_COL_ID); + int32_t lidx = 0; + int32_t ridx = taosArrayGetSize(pBlockData->aIdx) - 1; + + while (lidx <= ridx) { + int32_t midx = (lidx + ridx) / 2; + SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, midx); + int32_t c = tColDataCmprFn(pColData, &(SColData){.cid = cid}); + + if (c == 0) { + *ppColData = pColData; + return; + } else if (c < 0) { + lidx = midx + 1; + } else { + ridx = midx - 1; + } + } + + *ppColData = NULL; +} + +// ALGORITHM ============================== +void tsdbCalcColDataSMA(SColData *pColData, SColumnDataAgg *pColAgg) { + SColVal colVal; + SColVal *pColVal = &colVal; + + *pColAgg = (SColumnDataAgg){.colId = pColData->cid}; + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + tColDataGetValue(pColData, iVal, pColVal); + + if (pColVal->isNone || pColVal->isNull) { + pColAgg->numOfNull++; + } else { + switch (pColData->type) { + case TSDB_DATA_TYPE_NULL: + break; + case TSDB_DATA_TYPE_BOOL: + break; + case TSDB_DATA_TYPE_TINYINT: + break; + case TSDB_DATA_TYPE_SMALLINT: + break; + case TSDB_DATA_TYPE_INT: + break; + case TSDB_DATA_TYPE_BIGINT: + break; + case TSDB_DATA_TYPE_FLOAT: + break; + case TSDB_DATA_TYPE_DOUBLE: + break; + case TSDB_DATA_TYPE_VARCHAR: + break; + case TSDB_DATA_TYPE_TIMESTAMP: + break; + case TSDB_DATA_TYPE_NCHAR: + break; + case TSDB_DATA_TYPE_UTINYINT: + break; + case TSDB_DATA_TYPE_USMALLINT: + break; + case TSDB_DATA_TYPE_UINT: + break; + case TSDB_DATA_TYPE_UBIGINT: + break; + case TSDB_DATA_TYPE_JSON: + break; + case TSDB_DATA_TYPE_VARBINARY: + break; + case TSDB_DATA_TYPE_DECIMAL: + break; + case TSDB_DATA_TYPE_BLOB: + break; + case TSDB_DATA_TYPE_MEDIUMBLOB: + break; + default: + ASSERT(0); + } + } + } +} diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index e184763bc812c7a9ca11db2e9a0432073c1df07c..a221bc17957b36a43e3847a33346ae1b05f8794c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -28,7 +28,7 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp * // scan and convert if (tsdbScanAndConvertSubmitMsg(pTsdb, pMsg) < 0) { if (terrno != TSDB_CODE_TDB_TABLE_RECONFIGURE) { - tsdbError("vgId:%d, failed to insert data since %s", REPO_ID(pTsdb), tstrerror(terrno)); + tsdbError("vgId:%d, failed to insert data since %s", TD_VID(pTsdb->pVnode), tstrerror(terrno)); } return -1; } @@ -77,7 +77,7 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, STSRow *ro if (rowKey < minKey || rowKey > maxKey) { tsdbError("vgId:%d, table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64 " maxKey %" PRId64 " row key %" PRId64, - REPO_ID(pTsdb), uid, now, minKey, maxKey, rowKey); + TD_VID(pTsdb->pVnode), uid, now, minKey, maxKey, rowKey); terrno = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE; return -1; } @@ -92,7 +92,7 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) { SSubmitBlk *pBlock = NULL; SSubmitBlkIter blkIter = {0}; STSRow *row = NULL; - STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pTsdb); + STsdbKeepCfg *pCfg = &pTsdb->keepCfg; TSKEY now = taosGetTimestamp(pCfg->precision); TSKEY minKey = now - tsTickPerMin[pCfg->precision] * pCfg->keep2; TSKEY maxKey = now + tsTickPerMin[pCfg->precision] * pCfg->days; diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 40112a1ee85670102ba3a1c1fd704feb2314935b..21db14f0dfec36e24601295ac9784501fca2446a 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -40,6 +40,7 @@ int vnodeBegin(SVnode *pVnode) { /* pthread_mutex_unlock(); */ + pVnode->state.commitID++; // begin meta if (metaBegin(pVnode->pMeta) < 0) { vError("vgId:%d, failed to begin meta since %s", TD_VID(pVnode), tstrerror(terrno)); @@ -47,26 +48,21 @@ int vnodeBegin(SVnode *pVnode) { } // begin tsdb - if (pVnode->pSma) { - if (tsdbBegin(VND_RSMA0(pVnode)) < 0) { - vError("vgId:%d, failed to begin rsma0 since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } + if (tsdbBegin(pVnode->pTsdb) < 0) { + vError("vgId:%d, failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); + return -1; + } - if (tsdbBegin(VND_RSMA1(pVnode)) < 0) { + if (pVnode->pSma) { + if (VND_RSMA1(pVnode) && tsdbBegin(VND_RSMA1(pVnode)) < 0) { vError("vgId:%d, failed to begin rsma1 since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } - if (tsdbBegin(VND_RSMA2(pVnode)) < 0) { + if (VND_RSMA2(pVnode) && tsdbBegin(VND_RSMA2(pVnode)) < 0) { vError("vgId:%d, failed to begin rsma2 since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } - } else { - if (tsdbBegin(pVnode->pTsdb) < 0) { - vError("vgId:%d, failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } } // begin sma @@ -218,7 +214,8 @@ int vnodeCommit(SVnode *pVnode) { SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN]; - vInfo("vgId:%d, start to commit, version: %" PRId64, TD_VID(pVnode), pVnode->state.applied); + vInfo("vgId:%d, start to commit, commit ID:%" PRId64 " version:%" PRId64, TD_VID(pVnode), pVnode->state.commitID, + pVnode->state.applied); pVnode->onCommit = pVnode->inUse; pVnode->inUse = NULL; @@ -226,6 +223,7 @@ int vnodeCommit(SVnode *pVnode) { // save info info.config = pVnode->config; info.state.committed = pVnode->state.applied; + info.state.commitID = pVnode->state.commitID; snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path); if (vnodeSaveInfo(dir, &info) < 0) { ASSERT(0); @@ -294,7 +292,7 @@ static int vnodeCommitImpl(void *arg) { // metaCommit(pVnode->pMeta); tqCommit(pVnode->pTq); - tsdbCommit(pVnode->pTsdb); + // tsdbCommit(pVnode->pTsdb, ); // vnodeBufPoolRecycle(pVnode); tsem_post(&(pVnode->canCommit)); @@ -317,7 +315,7 @@ static int vnodeEncodeState(const void *pObj, SJson *pJson) { const SVState *pState = (SVState *)pObj; if (tjsonAddIntegerToObject(pJson, "commit version", pState->committed) < 0) return -1; - if (tjsonAddIntegerToObject(pJson, "applied version", pState->applied) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "commit ID", pState->commitID) < 0) return -1; return 0; } @@ -327,9 +325,9 @@ static int vnodeDecodeState(const SJson *pJson, void *pObj) { int32_t code; tjsonGetNumberValue(pJson, "commit version", pState->committed, code); - if(code < 0) return -1; - tjsonGetNumberValue(pJson, "applied version", pState->applied, code); - if(code < 0) return -1; + if (code < 0) return -1; + tjsonGetNumberValue(pJson, "commit ID", pState->commitID, code); + if (code < 0) return -1; return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 0c654bee1ffbf35851e5d49d7f42132136e4dd29..4267dd9b1f560ae10f83fb8b27d79b211490961e 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -37,6 +37,7 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { info.config = *pCfg; info.state.committed = -1; info.state.applied = -1; + info.state.commitID = 0; if (vnodeSaveInfo(dir, &info) < 0 || vnodeCommitInfo(dir, &info) < 0) { vError("vgId:%d, failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno)); @@ -79,9 +80,10 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { pVnode->config = info.config; pVnode->state.committed = info.state.committed; pVnode->state.applied = info.state.committed; + pVnode->state.commitID = info.state.commitID; pVnode->pTfs = pTfs; pVnode->msgCb = msgCb; - pVnode->syncCount = 0; + pVnode->blockCount = 0; tsem_init(&pVnode->syncSem, 0, 0); tsem_init(&(pVnode->canCommit), 0, 1); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 5aa6762e8329e166ab7027580dd89b45e846b406..5b807d60e30b2ec20d70520a992a4e5c55dcff9f 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -261,11 +261,49 @@ void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) { } } -// wrapper of tsdb read interface -tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableList, uint64_t qId, - void *pMemRef) { -#if 0 - return tsdbQueryCacheLastT(pVnode->pTsdb, pCond, groupList, qId, pMemRef); -#endif - return 0; +int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) { + SMCtbCursor *pCur = metaOpenCtbCursor(pVnode->pMeta, uid); + + while (1) { + tb_uid_t id = metaCtbCursorNext(pCur); + if (id == 0) { + break; + } + + STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, uid = id}; + taosArrayPush(list, &info); + } + + metaCloseCtbCursor(pCur); + return TSDB_CODE_SUCCESS; +} + +int32_t vnodeGetCtbIdList(SVnode *pVnode, int64_t suid, SArray *list) { + SMCtbCursor *pCur = metaOpenCtbCursor(pVnode->pMeta, suid); + + while (1) { + tb_uid_t id = metaCtbCursorNext(pCur); + if (id == 0) { + break; + } + + taosArrayPush(list, &id); + } + + metaCloseCtbCursor(pCur); + return TSDB_CODE_SUCCESS; +} + +void *vnodeGetIdx(SVnode *pVnode) { + if (pVnode == NULL) { + return NULL; + } + return metaGetIdx(pVnode->pMeta); +} + +void *vnodeGetIvtIdx(SVnode *pVnode) { + if (pVnode == NULL) { + return NULL; + } + return metaGetIvtIdx(pVnode->pMeta); } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 649e8299f44e131a963cac689bbd0ad65d479ce1..4530eee4a5b9f1272d49f5213612ce8f0539b5a1 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -25,10 +25,10 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); -static int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp); static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); +static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); -int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { +int32_t vnodePreProcessReq(SVnode *pVnode, SRpcMsg *pMsg) { int32_t code = 0; SDecoder dc = {0}; @@ -93,11 +93,44 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { } } break; + case TDMT_VND_DELETE: { + int32_t size; + int32_t ret; + uint8_t *pCont; + SEncoder *pCoder = &(SEncoder){0}; + SDeleteRes res = {0}; + SReadHandle handle = { + .meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode, .pMsgCb = &pVnode->msgCb}; + + code = qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, &res); + if (code) goto _err; + + // malloc and encode + tEncodeSize(tEncodeDeleteRes, &res, size, ret); + pCont = rpcMallocCont(size + sizeof(SMsgHead)); + + ((SMsgHead *)pCont)->contLen = htonl(size + sizeof(SMsgHead)); + ((SMsgHead *)pCont)->vgId = htonl(TD_VID(pVnode)); + + tEncoderInit(pCoder, pCont + sizeof(SMsgHead), size); + tEncodeDeleteRes(pCoder, &res); + tEncoderClear(pCoder); + + rpcFreeCont(pMsg->pCont); + pMsg->pCont = pCont; + pMsg->contLen = size + sizeof(SMsgHead); + + taosArrayDestroy(res.uidList); + } break; default: break; } return code; + +_err: + vError("vgId%d, preprocess request failed since %s", TD_VID(pVnode), tstrerror(code)); + return code; } int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp) { @@ -146,7 +179,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp if (vnodeProcessSubmitReq(pVnode, version, pMsg->pCont, pMsg->contLen, pRsp) < 0) goto _err; break; case TDMT_VND_DELETE: - if (vnodeProcessWriteMsg(pVnode, version, pMsg, pRsp) < 0) goto _err; + if (vnodeProcessDeleteReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; break; /* TQ */ case TDMT_VND_MQ_VG_CHANGE: @@ -185,6 +218,8 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp break; case TDMT_VND_ALTER_CONFIG: break; + case TDMT_VND_COMMIT: + goto _do_commit; default: ASSERT(0); break; @@ -199,6 +234,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp // commit if need if (vnodeShouldCommit(pVnode)) { + _do_commit: vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), version); // commit current change vnodeCommit(pVnode); @@ -280,22 +316,6 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { } } -int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp) { - vTrace("message in write queue is processing"); - char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); - SDeleteRes res = {0}; - SReadHandle handle = {.meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode, .pMsgCb = &pVnode->msgCb}; - - switch (pMsg->msgType) { - case TDMT_VND_DELETE: - return qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, pRsp, &res); - default: - vError("unknown msg type:%d in write queue", pMsg->msgType); - return TSDB_CODE_VND_APP_ERROR; - } -} - // TODO: remove the function void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { // TODO @@ -316,7 +336,7 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *p if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY; int32_t t = ntohl(*(int32_t *)pReq); - vDebug("vgId:%d, recv ttl msg, time:%d", pVnode->config.vgId, t); + vError("rec ttl time:%d", t); int32_t ret = metaTtlDropTable(pVnode->pMeta, t, tbUids); if (ret != 0) { goto end; @@ -856,3 +876,31 @@ static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, vo // 3. reload sync return 0; } + +static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { + int32_t code = 0; + SDecoder *pCoder = &(SDecoder){0}; + SDeleteRes *pRes = &(SDeleteRes){0}; + + pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t)); + if (pRes->uidList == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + tDecoderInit(pCoder, pReq, len); + tDecodeDeleteRes(pCoder, pRes); + + for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) { + code = tsdbDeleteTableData(pVnode->pTsdb, version, pRes->suid, *(uint64_t *)taosArrayGet(pRes->uidList, iUid), + pRes->skey, pRes->ekey); + if (code) goto _err; + } + + tDecoderClear(pCoder); + taosArrayDestroy(pRes->uidList); + return code; + +_err: + return code; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index 0445eda7af3811b882c40f0e4c6df69b43496a12..399a5b62992186cab23db9640f519f43ac99e0fc 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -25,12 +25,12 @@ static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; } static inline void vnodeAccumBlockMsg(SVnode *pVnode, tmsg_t type) { if (!vnodeIsMsgBlock(type)) return; - int32_t count = atomic_add_fetch_32(&pVnode->syncCount, 1); + int32_t count = atomic_add_fetch_32(&pVnode->blockCount, 1); vTrace("vgId:%d, accum block, count:%d type:%s", pVnode->config.vgId, count, TMSG_INFO(type)); } static inline void vnodeWaitBlockMsg(SVnode *pVnode) { - int32_t count = atomic_load_32(&pVnode->syncCount); + int32_t count = atomic_load_32(&pVnode->blockCount); if (count <= 0) return; vTrace("vgId:%d, wait block finish, count:%d", pVnode->config.vgId, count); @@ -40,10 +40,10 @@ static inline void vnodeWaitBlockMsg(SVnode *pVnode) { static inline void vnodePostBlockMsg(SVnode *pVnode, tmsg_t type) { if (!vnodeIsMsgBlock(type)) return; - int32_t count = atomic_load_32(&pVnode->syncCount); + int32_t count = atomic_load_32(&pVnode->blockCount); if (count <= 0) return; - count = atomic_sub_fetch_32(&pVnode->syncCount, 1); + count = atomic_sub_fetch_32(&pVnode->blockCount, 1); vTrace("vgId:%d, post block, count:%d type:%s", pVnode->config.vgId, count, TMSG_INFO(type)); if (count <= 0) { tsem_post(&pVnode->syncSem); @@ -84,8 +84,10 @@ static int32_t vnodeProcessAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) { terrno = TSDB_CODE_INVALID_MSG; return TSDB_CODE_INVALID_MSG; } - STraceId *trace = &pMsg->info.traceId; + + const STraceId *trace = &pMsg->info.traceId; vGTrace("vgId:%d, start to alter vnode replica to %d, handle:%p", TD_VID(pVnode), req.replica, pMsg->info.handle); + SSyncCfg cfg = {.replicaNum = req.replica, .myIndex = req.selfIndex}; for (int32_t r = 0; r < req.replica; ++r) { SNodeInfo *pNode = &cfg.nodeInfo[r]; @@ -126,32 +128,23 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { for (int32_t m = 0; m < numOfMsgs; m++) { if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; - STraceId *trace = &pMsg->info.traceId; + const STraceId *trace = &pMsg->info.traceId; vGTrace("vgId:%d, msg:%p get from vnode-write queue handle:%p", vgId, pMsg, pMsg->info.handle); - if (pMsg->msgType == TDMT_VND_ALTER_REPLICA) { - code = vnodeProcessAlterReplicaReq(pVnode, pMsg); + code = vnodePreProcessReq(pVnode, pMsg); + if (code != 0) { + vError("vgId:%d, msg:%p failed to pre-process since %s", vgId, pMsg, terrstr()); } else { - code = vnodePreprocessReq(pVnode, pMsg); - if (code != 0) { - vError("vgId:%d, failed to pre-process msg:%p since %s", vgId, pMsg, terrstr()); + if (pMsg->msgType == TDMT_VND_ALTER_REPLICA) { + code = vnodeProcessAlterReplicaReq(pVnode, pMsg); } else { code = syncPropose(pVnode->sync, pMsg, vnodeIsMsgWeak(pMsg->msgType)); - if (code == 1) { - do { - static int32_t cnt = 0; - if (cnt++ % 1000 == 1) { - vInfo("vgId:%d, msg:%p apply right now, apply index:%ld, msgtype:%s,%d", vgId, pMsg, - pMsg->info.conn.applyIndex, TMSG_INFO(pMsg->msgType), pMsg->msgType); - } - } while (0); - + if (code > 0) { SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info}; if (vnodeProcessWriteReq(pVnode, pMsg, pMsg->info.conn.applyIndex, &rsp) < 0) { rsp.code = terrno; - vInfo("vgId:%d, msg:%p failed to apply right now since %s", vgId, pMsg, terrstr()); + vError("vgId:%d, msg:%p failed to apply right now since %s", vgId, pMsg, terrstr()); } - if (rsp.info.handle != NULL) { tmsgSendRsp(&rsp); } @@ -161,33 +154,27 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { if (code == 0) { vnodeAccumBlockMsg(pVnode, pMsg->msgType); - } else if (code == -1 && terrno == TSDB_CODE_SYN_NOT_LEADER) { - SEpSet newEpSet = {0}; - syncGetRetryEpSet(pVnode->sync, &newEpSet); - - /* - syncGetEpSet(pVnode->sync, &newEpSet); - SEp *pEp = &newEpSet.eps[newEpSet.inUse]; - if (pEp->port == tsServerPort && strcmp(pEp->fqdn, tsLocalFqdn) == 0) { - newEpSet.inUse = (newEpSet.inUse + 1) % newEpSet.numOfEps; - } - */ - - vGTrace("vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d", vgId, pMsg, newEpSet.numOfEps, - newEpSet.inUse); - for (int32_t i = 0; i < newEpSet.numOfEps; ++i) { - vGTrace("vgId:%d, msg:%p redirect:%d ep:%s:%u", vgId, pMsg, i, newEpSet.eps[i].fqdn, newEpSet.eps[i].port); - } - pMsg->info.hasEpSet = 1; - SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info}; - tmsgSendRedirectRsp(&rsp, &newEpSet); - } else { - if (code != 1) { + } else if (code < 0) { + if (terrno == TSDB_CODE_SYN_NOT_LEADER) { + SEpSet newEpSet = {0}; + syncGetRetryEpSet(pVnode->sync, &newEpSet); + vGTrace("vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d", vgId, pMsg, newEpSet.numOfEps, + newEpSet.inUse); + for (int32_t i = 0; i < newEpSet.numOfEps; ++i) { + vGTrace("vgId:%d, msg:%p redirect:%d ep:%s:%u", vgId, pMsg, i, newEpSet.eps[i].fqdn, newEpSet.eps[i].port); + } + pMsg->info.hasEpSet = 1; + SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info}; + tmsgSendRedirectRsp(&rsp, &newEpSet); + } else { if (terrno != 0) code = terrno; vError("vgId:%d, msg:%p failed to propose since %s, code:0x%x", vgId, pMsg, tstrerror(code), code); SRpcMsg rsp = {.code = code, .info = pMsg->info}; - tmsgSendRsp(&rsp); + if (rsp.info.handle != NULL) { + tmsgSendRsp(&rsp); + } } + } else { } vGTrace("vgId:%d, msg:%p is freed, code:0x%x", vgId, pMsg, code); @@ -206,7 +193,7 @@ void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { for (int32_t i = 0; i < numOfMsgs; ++i) { if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; - STraceId *trace = &pMsg->info.traceId; + const STraceId *trace = &pMsg->info.traceId; vGTrace("vgId:%d, msg:%p get from vnode-apply queue, type:%s handle:%p", vgId, pMsg, TMSG_INFO(pMsg->msgType), pMsg->info.handle); @@ -229,172 +216,148 @@ void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { } } -int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - int32_t ret = 0; - - if (syncEnvIsStart()) { - SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); - assert(pSyncNode != NULL); +int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + int32_t code = 0; + const STraceId *trace = &pMsg->info.traceId; - SMsgHead *pHead = pMsg->pCont; - STraceId *trace = &pMsg->info.traceId; + if (!syncEnvIsStart()) { + vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId); + terrno = TSDB_CODE_APP_ERROR; + return -1; + } - do { - char *syncNodeStr = sync2SimpleStr(pVnode->sync); - static int64_t vndTick = 0; - if (++vndTick % 10 == 1) { - vGTrace("vgId:%d, sync trace msg:%s, %s", syncGetVgId(pVnode->sync), TMSG_INFO(pMsg->msgType), syncNodeStr); - } - if (gRaftDetailLog) { - char logBuf[512] = {0}; - snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, - syncNodeStr); - syncRpcMsgLog2(logBuf, pMsg); - } - taosMemoryFree(syncNodeStr); - } while (0); - - SRpcMsg *pRpcMsg = pMsg; - - // ToDo: ugly! use function pointer - // use different strategy - if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_NO_SNAPSHOT) { - if (pRpcMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { - SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_SET_VNODE_STANDBY) { - ret = vnodeSetStandBy(pVnode); - if (ret != 0 && terrno != 0) ret = terrno; - SRpcMsg rsp = {.code = ret, .info = pMsg->info}; - tmsgSendRsp(&rsp); - } else { - vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType); - ret = -1; - } + SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); + if (pSyncNode == NULL) { + vGError("vgId:%d, msg:%p failed to process since invalid sync node", pVnode->config.vgId); + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } +#if 1 + do { + char *syncNodeStr = sync2SimpleStr(pVnode->sync); + static int64_t vndTick = 0; + if (++vndTick % 10 == 1) { + vGTrace("vgId:%d, sync trace msg:%s, %s", syncGetVgId(pVnode->sync), TMSG_INFO(pMsg->msgType), syncNodeStr); + } + taosMemoryFree(syncNodeStr); + } while (0); +#endif + + if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_NO_SNAPSHOT) { + if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { + SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); + syncTimeoutDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_PING) { + SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnPingCb(pSyncNode, pSyncMsg); + syncPingDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { + SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); + syncPingReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { + SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); + syncClientRequestDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { + SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); + syncRequestVoteDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { + SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); + syncRequestVoteReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { + SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg); + syncAppendEntriesDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { + SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg); + syncAppendEntriesReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_SET_VNODE_STANDBY) { + code = vnodeSetStandBy(pVnode); + if (code != 0 && terrno != 0) code = terrno; + SRpcMsg rsp = {.code = code, .info = pMsg->info}; + tmsgSendRsp(&rsp); } else { - // use wal first strategy - - if (pRpcMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_BATCH) { - SyncClientRequestBatch *pSyncMsg = syncClientRequestBatchFromRpcMsg(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg); - syncClientRequestBatchDestroyDeep(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_BATCH) { - SyncAppendEntriesBatch *pSyncMsg = syncAppendEntriesBatchFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnAppendEntriesSnapshot2Cb(pSyncNode, pSyncMsg); - syncAppendEntriesBatchDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - ret = syncNodeOnAppendEntriesReplySnapshot2Cb(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_SET_VNODE_STANDBY) { - ret = vnodeSetStandBy(pVnode); - if (ret != 0 && terrno != 0) ret = terrno; - SRpcMsg rsp = {.code = ret, .info = pMsg->info}; - tmsgSendRsp(&rsp); - } else { - vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType); - ret = -1; - } + vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg->msgType); + code = -1; } - syncNodeRelease(pSyncNode); - } else { - vError("==vnodeProcessSyncReq== error syncEnv stop"); - ret = -1; + } else if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_WAL_FIRST) { + // use wal first strategy + if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { + SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); + syncTimeoutDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_PING) { + SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnPingCb(pSyncNode, pSyncMsg); + syncPingDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { + SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); + syncPingReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { + SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); + syncClientRequestDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_BATCH) { + SyncClientRequestBatch *pSyncMsg = syncClientRequestBatchFromRpcMsg(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg); + syncClientRequestBatchDestroyDeep(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { + SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); + syncRequestVoteDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { + SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); + syncRequestVoteReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_BATCH) { + SyncAppendEntriesBatch *pSyncMsg = syncAppendEntriesBatchFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnAppendEntriesSnapshot2Cb(pSyncNode, pSyncMsg); + syncAppendEntriesBatchDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { + SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnAppendEntriesReplySnapshot2Cb(pSyncNode, pSyncMsg); + syncAppendEntriesReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_SET_VNODE_STANDBY) { + code = vnodeSetStandBy(pVnode); + if (code != 0 && terrno != 0) code = terrno; + SRpcMsg rsp = {.code = code, .info = pMsg->info}; + tmsgSendRsp(&rsp); + } else { + vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg->msgType); + code = -1; + } } - if (ret != 0 && terrno == 0) { + syncNodeRelease(pSyncNode); + if (code != 0 && terrno == 0) { terrno = TSDB_CODE_SYN_INTERNAL_ERROR; } - return ret; + return code; } static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { @@ -427,7 +390,7 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon syncGetAndDelRespRpc(pVnode->sync, cbMeta.newCfgSeqNum, &rpcMsg.info); rpcMsg.info.conn.applyIndex = cbMeta.index; - STraceId *trace = (STraceId *)&pMsg->info.traceId; + const STraceId *trace = (STraceId *)&pMsg->info.traceId; vGTrace("vgId:%d, alter vnode replica is confirmed, type:%s contLen:%d seq:%" PRIu64 " handle:%p", TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pMsg->contLen, cbMeta.seqNum, rpcMsg.info.handle); if (rpcMsg.info.handle != NULL) { @@ -438,45 +401,53 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon } static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - SVnode *pVnode = pFsm->data; - SSnapshot snapshot = {0}; - SyncIndex beginIndex = SYNC_INDEX_INVALID; - char logBuf[256] = {0}; - - snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== execute, pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, beginIndex :%ld\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - beginIndex); - syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); + SVnode *pVnode = pFsm->data; + vTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", + syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, + syncUtilState2String(cbMeta.state), pMsg->msgType, TMSG_INFO(pMsg->msgType)); SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen}; rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen); syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info); rpcMsg.info.conn.applyIndex = cbMeta.index; + rpcMsg.info.conn.applyTerm = cbMeta.term; tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg); } static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); - syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); + SVnode *pVnode = pFsm->data; + vTrace("vgId:%d, pre-commit-cb is excuted, fsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", + syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, + syncUtilState2String(cbMeta.state), pMsg->msgType, TMSG_INFO(pMsg->msgType)); } static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); - syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); + SVnode *pVnode = pFsm->data; + vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", + syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, + syncUtilState2String(cbMeta.state), pMsg->msgType, TMSG_INFO(pMsg->msgType)); } -static int32_t vnodeSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) { return 0; } +static int32_t vnodeSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) { + SVnode *pVnode = pFsm->data; + SSnapshotParam *pSnapshotParam = pParam; + int32_t code = + vnodeSnapshotReaderOpen(pVnode, (SVSnapshotReader **)ppReader, pSnapshotParam->start, pSnapshotParam->end); + return code; +} -static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { return 0; } +static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { + SVnode *pVnode = pFsm->data; + int32_t code = vnodeSnapshotReaderClose(pReader); + return code; +} -static int32_t vnodeSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) { return 0; } +static int32_t vnodeSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) { + SVnode *pVnode = pFsm->data; + int32_t code = vnodeSnapshotRead(pReader, (const void **)ppBuf, len); + return code; +} static int32_t vnodeSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void **ppWriter) { return 0; } diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index fc3e3cbc8af5f55a51f3b25f6521de73bec7589f..7f70a78b1271f5615be560cfb5999405b4d9c3e0 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -565,7 +565,6 @@ static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** p } int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) { - int32_t numOfCols = LIST_LENGTH(pProjects); blockDataEnsureCapacity(pBlock, 1); int32_t index = 0; @@ -579,7 +578,6 @@ int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) { } pBlock->info.rows = 1; - return TSDB_CODE_SUCCESS; } diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index df961c00fa79ed1ab13debea876f4e46079eea5e..2c8fbe9206b0fe53d5e0d642981cf91b1b3db844 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -106,7 +106,7 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo); SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode); EDealRes doTranslateTagExpr(SNode** pNode, void* pContext); -int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo); +int32_t getTableList(void* metaHandle, void* vnode, SScanPhysiNode* pScanNode, STableListInfo* pListInfo); SArray* createSortInfo(SNodeList* pNodeList); SArray* extractPartitionColInfo(SNodeList* pNodeList); SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 00f2e09e0c8e9b9e3604a24916b511f7deb915dd..cea1bbbb5aea7cf7ab9f4859004c37a5f676e49d 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -149,8 +149,8 @@ typedef struct SExecTaskInfo { struct { char *tablename; char *dbname; - int32_t sversion; int32_t tversion; + SSchemaWrapper*sw; } schemaVer; STableListInfo tableqinfoList; // this is a table list @@ -240,7 +240,7 @@ typedef struct SColMatchInfo { int32_t srcSlotId; // source slot id int32_t colId; int32_t targetSlotId; - bool output; + bool output; // todo remove this? bool reserved; int32_t matchType; // determinate the source according to col id or slot id } SColMatchInfo; @@ -261,7 +261,7 @@ enum { }; typedef struct STableScanInfo { - void* dataReader; + STsdbReader* dataReader; SReadHandle readHandle; SFileBlockLoadRecorder readRecorder; @@ -306,6 +306,15 @@ typedef struct STagScanInfo { STableListInfo *pTableList; } STagScanInfo; +typedef struct SLastrowScanInfo { + SSDataBlock *pRes; + SArray *pTableList; + SReadHandle readHandle; + void *pLastrowReader; + SArray *pColMatchInfo; + int32_t *pSlotIds; +} SLastrowScanInfo; + typedef enum EStreamScanMode { STREAM_SCAN_FROM_READERHANDLE = 1, STREAM_SCAN_FROM_RES, @@ -442,6 +451,8 @@ typedef struct SIntervalAggOperatorInfo { SArray* pDelWins; // SWinRes int32_t delIndex; SSDataBlock* pDelRes; + + SNode *pCondition; } SIntervalAggOperatorInfo; typedef struct SStreamFinalIntervalOperatorInfo { @@ -479,6 +490,8 @@ typedef struct SAggOperatorInfo { uint64_t groupId; SGroupResInfo groupResInfo; SExprSupp scalarExprSup; + + SNode *pCondition; } SAggOperatorInfo; typedef struct SProjectOperatorInfo { @@ -680,6 +693,8 @@ typedef struct SSortOperatorInfo { int64_t startTs; // sort start time uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included. + + SNode* pCondition; } SSortOperatorInfo; typedef struct STagFilterOperatorInfo { @@ -753,12 +768,12 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, SExecTaskInfo* pTaskInfo, uint64_t queryId, uint64_t taskId); +SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, SExecTaskInfo* pTaskInfo); SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode *pScanPhyNode, const char* pUser, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo, +SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo); SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode *pNode, SExecTaskInfo* pTaskInfo); @@ -766,6 +781,8 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortPhyNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** dowStreams, size_t numStreams, SMergePhysiNode* pMergePhysiNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createLastrowScanOperator(SLastRowScanPhysiNode* pTableScanNode, SReadHandle* readHandle, + SArray* pTableList, SExecTaskInfo* pTaskInfo); SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c new file mode 100644 index 0000000000000000000000000000000000000000..c424cb33fa1a79b50d1b24d13f2e34d0588816b3 --- /dev/null +++ b/source/libs/executor/src/dataInserter.c @@ -0,0 +1,254 @@ +/* + * 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 . + */ + +#include "dataSinkInt.h" +#include "dataSinkMgt.h" +#include "executorimpl.h" +#include "planner.h" +#include "tcompression.h" +#include "tdatablock.h" +#include "tglobal.h" +#include "tqueue.h" + +extern SDataSinkStat gDataSinkStat; + +typedef struct SDataInserterBuf { + int32_t useSize; + int32_t allocSize; + char* pData; +} SDataInserterBuf; + +typedef struct SDataCacheEntry { + int32_t dataLen; + int32_t numOfRows; + int32_t numOfCols; + int8_t compressed; + char data[]; +} SDataCacheEntry; + +typedef struct SDataInserterHandle { + SDataSinkHandle sink; + SDataSinkManager* pManager; + SDataBlockDescNode* pSchema; + SDataDeleterNode* pDeleter; + SDeleterParam* pParam; + STaosQueue* pDataBlocks; + SDataInserterBuf nextOutput; + int32_t status; + bool queryEnd; + uint64_t useconds; + uint64_t cachedSize; + TdThreadMutex mutex; +} SDataInserterHandle; + +static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) { + if (tsCompressColData < 0 || 0 == pData->info.rows) { + return false; + } + + for (int32_t col = 0; col < numOfCols; ++col) { + SColumnInfoData* pColRes = taosArrayGet(pData->pDataBlock, col); + int32_t colSize = pColRes->info.bytes * pData->info.rows; + if (NEEDTO_COMPRESS_QUERY(colSize)) { + return true; + } + } + + return false; +} + +static void toDataCacheEntry(SDataInserterHandle* pHandle, const SInputData* pInput, SDataInserterBuf* pBuf) { + int32_t numOfCols = LIST_LENGTH(pHandle->pSchema->pSlots); + + SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData; + pEntry->compressed = 0; + pEntry->numOfRows = pInput->pData->info.rows; + pEntry->numOfCols = taosArrayGetSize(pInput->pData->pDataBlock); + pEntry->dataLen = sizeof(SDeleterRes); + + ASSERT(1 == pEntry->numOfRows); + ASSERT(1 == pEntry->numOfCols); + + pBuf->useSize = sizeof(SDataCacheEntry); + + SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pInput->pData->pDataBlock, 0); + + SDeleterRes* pRes = (SDeleterRes*)pEntry->data; + pRes->suid = pHandle->pParam->suid; + pRes->uidList = pHandle->pParam->pUidList; + pRes->skey = pHandle->pDeleter->deleteTimeRange.skey; + pRes->ekey = pHandle->pDeleter->deleteTimeRange.ekey; + pRes->affectedRows = *(int64_t*)pColRes->pData; + + pBuf->useSize += pEntry->dataLen; + + atomic_add_fetch_64(&pHandle->cachedSize, pEntry->dataLen); + atomic_add_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen); +} + +static bool allocBuf(SDataInserterHandle* pDeleter, const SInputData* pInput, SDataInserterBuf* pBuf) { + uint32_t capacity = pDeleter->pManager->cfg.maxDataBlockNumPerQuery; + if (taosQueueItemSize(pDeleter->pDataBlocks) > capacity) { + qError("SinkNode queue is full, no capacity, max:%d, current:%d, no capacity", capacity, + taosQueueItemSize(pDeleter->pDataBlocks)); + return false; + } + + pBuf->allocSize = sizeof(SDataCacheEntry) + sizeof(SDeleterRes); + + pBuf->pData = taosMemoryMalloc(pBuf->allocSize); + if (pBuf->pData == NULL) { + qError("SinkNode failed to malloc memory, size:%d, code:%d", pBuf->allocSize, TAOS_SYSTEM_ERROR(errno)); + } + + return NULL != pBuf->pData; +} + +static int32_t updateStatus(SDataInserterHandle* pDeleter) { + taosThreadMutexLock(&pDeleter->mutex); + int32_t blockNums = taosQueueItemSize(pDeleter->pDataBlocks); + int32_t status = + (0 == blockNums ? DS_BUF_EMPTY + : (blockNums < pDeleter->pManager->cfg.maxDataBlockNumPerQuery ? DS_BUF_LOW : DS_BUF_FULL)); + pDeleter->status = status; + taosThreadMutexUnlock(&pDeleter->mutex); + return status; +} + +static int32_t getStatus(SDataInserterHandle* pDeleter) { + taosThreadMutexLock(&pDeleter->mutex); + int32_t status = pDeleter->status; + taosThreadMutexUnlock(&pDeleter->mutex); + return status; +} + +static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) { + SDataInserterHandle* pDeleter = (SDataInserterHandle*)pHandle; + SDataInserterBuf* pBuf = taosAllocateQitem(sizeof(SDataInserterBuf), DEF_QITEM); + if (NULL == pBuf || !allocBuf(pDeleter, pInput, pBuf)) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + toDataCacheEntry(pDeleter, pInput, pBuf); + taosWriteQitem(pDeleter->pDataBlocks, pBuf); + *pContinue = (DS_BUF_LOW == updateStatus(pDeleter) ? true : false); + return TSDB_CODE_SUCCESS; +} + +static void endPut(struct SDataSinkHandle* pHandle, uint64_t useconds) { + SDataInserterHandle* pDeleter = (SDataInserterHandle*)pHandle; + taosThreadMutexLock(&pDeleter->mutex); + pDeleter->queryEnd = true; + pDeleter->useconds = useconds; + taosThreadMutexUnlock(&pDeleter->mutex); +} + +static void getDataLength(SDataSinkHandle* pHandle, int32_t* pLen, bool* pQueryEnd) { + SDataInserterHandle* pDeleter = (SDataInserterHandle*)pHandle; + if (taosQueueEmpty(pDeleter->pDataBlocks)) { + *pQueryEnd = pDeleter->queryEnd; + *pLen = 0; + return; + } + + SDataInserterBuf* pBuf = NULL; + taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); + memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataInserterBuf)); + taosFreeQitem(pBuf); + *pLen = ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->dataLen; + *pQueryEnd = pDeleter->queryEnd; + qDebug("got data len %d, row num %d in sink", *pLen, ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->numOfRows); +} + +static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { + SDataInserterHandle* pDeleter = (SDataInserterHandle*)pHandle; + if (NULL == pDeleter->nextOutput.pData) { + assert(pDeleter->queryEnd); + pOutput->useconds = pDeleter->useconds; + pOutput->precision = pDeleter->pSchema->precision; + pOutput->bufStatus = DS_BUF_EMPTY; + pOutput->queryEnd = pDeleter->queryEnd; + return TSDB_CODE_SUCCESS; + } + SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDeleter->nextOutput.pData); + memcpy(pOutput->pData, pEntry->data, pEntry->dataLen); + pOutput->numOfRows = pEntry->numOfRows; + pOutput->numOfCols = pEntry->numOfCols; + pOutput->compressed = pEntry->compressed; + + atomic_sub_fetch_64(&pDeleter->cachedSize, pEntry->dataLen); + atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen); + + taosMemoryFreeClear(pDeleter->nextOutput.pData); // todo persistent + pOutput->bufStatus = updateStatus(pDeleter); + taosThreadMutexLock(&pDeleter->mutex); + pOutput->queryEnd = pDeleter->queryEnd; + pOutput->useconds = pDeleter->useconds; + pOutput->precision = pDeleter->pSchema->precision; + taosThreadMutexUnlock(&pDeleter->mutex); + + return TSDB_CODE_SUCCESS; +} + +static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { + SDataInserterHandle* pDeleter = (SDataInserterHandle*)pHandle; + atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pDeleter->cachedSize); + taosMemoryFreeClear(pDeleter->nextOutput.pData); + while (!taosQueueEmpty(pDeleter->pDataBlocks)) { + SDataInserterBuf* pBuf = NULL; + taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); + taosMemoryFreeClear(pBuf->pData); + taosFreeQitem(pBuf); + } + taosCloseQueue(pDeleter->pDataBlocks); + taosThreadMutexDestroy(&pDeleter->mutex); + return TSDB_CODE_SUCCESS; +} + +static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) { + SDataInserterHandle* pDispatcher = (SDataInserterHandle*)pHandle; + + *size = atomic_load_64(&pDispatcher->cachedSize); + return TSDB_CODE_SUCCESS; +} + +int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam) { + SDataInserterHandle* inserter = taosMemoryCalloc(1, sizeof(SDataInserterHandle)); + if (NULL == inserter) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + + SDataDeleterNode* pDeleterNode = (SDataDeleterNode *)pDataSink; + inserter->sink.fPut = putDataBlock; + inserter->sink.fEndPut = endPut; + inserter->sink.fGetLen = getDataLength; + inserter->sink.fGetData = getDataBlock; + inserter->sink.fDestroy = destroyDataSinker; + inserter->sink.fGetCacheSize = getCacheSize; + inserter->pManager = pManager; + inserter->pDeleter = pDeleterNode; + inserter->pSchema = pDataSink->pInputDataBlockDesc; + inserter->pParam = pParam; + inserter->status = DS_BUF_EMPTY; + inserter->queryEnd = false; + inserter->pDataBlocks = taosOpenQueue(); + taosThreadMutexInit(&inserter->mutex, NULL); + if (NULL == inserter->pDataBlocks) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + *pHandle = inserter; + return TSDB_CODE_SUCCESS; +} diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 96338f4a6408ddcf8f14b8617a19ed9fdef17dfe..4e5458e6208bd95c160a629b365a516e173aa555 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -289,10 +289,13 @@ static bool isTableOk(STableKeyInfo* info, SNode* pTagCond, SMeta* metaHandle) { return result; } -int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo) { +int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, STableListInfo* pListInfo) { int32_t code = TSDB_CODE_SUCCESS; + pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo)); - if (pListInfo->pTableList == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (pListInfo->pTableList == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } uint64_t tableUid = pScanNode->uid; @@ -302,6 +305,7 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo SNode* pTagIndexCond = (SNode*)pListInfo->pTagIndexCond; if (pScanNode->tableType == TSDB_SUPER_TABLE) { if (pTagIndexCond) { + ///<<<<<<< HEAD SIndexMetaArg metaArg = { .metaEx = metaHandle, .idx = tsdbGetIdx(metaHandle), .ivtIdx = tsdbGetIvtIdx(metaHandle), .suid = tableUid}; @@ -311,8 +315,13 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo if (code != 0 || status == SFLT_NOT_INDEX) { code = TSDB_CODE_INDEX_REBUILDING; } + //======= + // SArray* res = taosArrayInit(8, sizeof(uint64_t)); + // // code = doFilterTag(pTagIndexCond, &metaArg, res); + // code = TSDB_CODE_INDEX_REBUILDING; + //>>>>>>> dvv if (code == TSDB_CODE_INDEX_REBUILDING) { - code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); + code = vnodeGetAllTableList(pVnode, tableUid, pListInfo->pTableList); } else if (code != TSDB_CODE_SUCCESS) { qError("failed to get tableIds, reason: %s, suid: %" PRIu64 "", tstrerror(code), tableUid); taosArrayDestroy(res); @@ -328,7 +337,7 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo } taosArrayDestroy(res); } else { - code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); + code = vnodeGetAllTableList(pVnode, tableUid, pListInfo->pTableList); } if (code != TSDB_CODE_SUCCESS) { @@ -354,8 +363,11 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo STableKeyInfo info = {.lastKey = 0, .uid = tableUid, .groupId = 0}; taosArrayPush(pListInfo->pTableList, &info); } + pListInfo->pGroupList = taosArrayInit(4, POINTER_BYTES); - if (pListInfo->pGroupList == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (pListInfo->pGroupList == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } // put into list as default group, remove it if grouping sorting is required later taosArrayPush(pListInfo->pGroupList, &pListInfo->pTableList); @@ -704,7 +716,7 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray while (i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) { SColumnInfoData* p = taosArrayGet(pCols, i); SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, j); - if (!outputEveryColumn && !pmInfo->output) { + if (!outputEveryColumn && pmInfo->reserved) { j++; continue; } @@ -746,8 +758,6 @@ SColumn extractColumnFromColumnNode(SColumnNode* pColNode) { } int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode) { - pCond->loadExternalRows = false; - pCond->order = pTableScanNode->scanSeq[0] > 0 ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; pCond->numOfCols = LIST_LENGTH(pTableScanNode->scan.pScanCols); pCond->colList = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnInfo)); @@ -763,25 +773,7 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi pCond->twindows[0] = pTableScanNode->scanRange; pCond->suid = pTableScanNode->scan.suid; -#if 1 - // todo work around a problem, remove it later - for (int32_t i = 0; i < pCond->numOfTWindows; ++i) { - if ((pCond->order == TSDB_ORDER_ASC && pCond->twindows[i].skey > pCond->twindows[i].ekey) || - (pCond->order == TSDB_ORDER_DESC && pCond->twindows[i].skey < pCond->twindows[i].ekey)) { - TSWAP(pCond->twindows[i].skey, pCond->twindows[i].ekey); - } - } -#endif - - for (int32_t i = 0; i < pCond->numOfTWindows; ++i) { - if ((pCond->order == TSDB_ORDER_ASC && pCond->twindows[i].skey > pCond->twindows[i].ekey) || - (pCond->order == TSDB_ORDER_DESC && pCond->twindows[i].skey < pCond->twindows[i].ekey)) { - TSWAP(pCond->twindows[i].skey, pCond->twindows[i].ekey); - } - } - taosqsort(pCond->twindows, pCond->numOfTWindows, sizeof(STimeWindow), pCond, compareTimeWindow); - - pCond->type = BLOCK_LOAD_OFFSET_SEQ_ORDER; + pCond->type = BLOCK_LOAD_OFFSET_ORDER; // pCond->type = pTableScanNode->scanFlag; int32_t j = 0; @@ -802,10 +794,7 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi return TSDB_CODE_SUCCESS; } -void cleanupQueryTableDataCond(SQueryTableDataCond* pCond) { - taosMemoryFree(pCond->twindows); - taosMemoryFree(pCond->colList); -} +void cleanupQueryTableDataCond(SQueryTableDataCond* pCond) { taosMemoryFree(pCond->colList); } int32_t convertFillType(int32_t mode) { int32_t type = TSDB_FILL_NONE; diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 0e76607c8f4dcc8478c55d7615c549b176115ec8..be50a1d3bd2b7eeefdd2e730af8a52f189e74ff8 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -189,7 +189,11 @@ int32_t qGetQueriedTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tab ASSERT(tinfo != NULL && dbName != NULL && tableName != NULL); SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - *sversion = pTaskInfo->schemaVer.sversion; + if (pTaskInfo->schemaVer.sw == NULL) { + return TSDB_CODE_SUCCESS; + } + + *sversion = pTaskInfo->schemaVer.sw->version; *tversion = pTaskInfo->schemaVer.tversion; if (pTaskInfo->schemaVer.dbname) { strcpy(dbName, pTaskInfo->schemaVer.dbname); diff --git a/source/libs/executor/src/executorMain.c b/source/libs/executor/src/executorMain.c index 2d5ccf8568555939d2725a0cb905ce7e575ed278..7f84b4c1743e49c8cd6c42d452c970bc5ecb49a7 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -27,6 +27,10 @@ static TdThreadOnce initPoolOnce = PTHREAD_ONCE_INIT; int32_t exchangeObjRefPool = -1; static void initRefPool() { exchangeObjRefPool = taosOpenRef(1024, doDestroyExchangeOperatorInfo); } +static void cleanupRefPool() { + int32_t ref = atomic_val_compare_exchange_32(&exchangeObjRefPool, exchangeObjRefPool, 0); + taosCloseRef(ref); +} int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, const char* sql, EOPTR_EXEC_MODEL model) { @@ -34,7 +38,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo; taosThreadOnce(&initPoolOnce, initRefPool); - + atexit(cleanupRefPool); int32_t code = createExecTaskInfoImpl(pSubplan, pTask, readHandle, taskId, sql, model); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -139,6 +143,7 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) { qDebug("%s execTask is launched", GET_TASKID(pTaskInfo)); int64_t st = taosGetTimestampUs(); + *pRes = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot); uint64_t el = (taosGetTimestampUs() - st); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 25b61e15c3e87954c9eb6ac7794f76b470b5fcf3..9afe9278252ab04b8e4ad581a9f61e05833633a4 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -2823,7 +2823,7 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan int32_t type = pOperator->operatorType; if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE || type == QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN || - type == QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN) { + type == QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN) { *order = TSDB_ORDER_ASC; *scanFlag = MAIN_SCAN; return TSDB_CODE_SUCCESS; @@ -2885,7 +2885,7 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) { tsdbSetTableId(pInfo->dataReader, uid); int64_t oldSkey = pInfo->cond.twindows[0].skey; pInfo->cond.twindows[0].skey = ts + 1; - tsdbResetReadHandle(pInfo->dataReader, &pInfo->cond, 0); + tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); pInfo->cond.twindows[0].skey = oldSkey; pInfo->scanTimes = 0; pInfo->curTWinIdx = 0; @@ -3012,11 +3012,19 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) { } blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); - doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf); - if (pInfo->pRes->info.rows == 0 || !hasDataInGroupInfo(&pAggInfo->groupResInfo)) { - doSetOperatorCompleted(pOperator); - } + while (1) { + doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf); + doFilter(pAggInfo->pCondition, pInfo->pRes); + + if (!hasDataInGroupInfo(&pAggInfo->groupResInfo)) { + doSetOperatorCompleted(pOperator); + break; + } + if (pInfo->pRes->info.rows > 0) { + break; + } + } size_t rows = blockDataGetNumOfRows(pInfo->pRes); pOperator->resultInfo.totalRows += rows; @@ -3557,7 +3565,7 @@ int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr) { } SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo, + SSDataBlock* pResultBlock, SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo) { SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); @@ -3581,6 +3589,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* } pInfo->groupId = INT32_MIN; + pInfo->pCondition = pCondition; pOperator->name = "TableAggregate"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_AGG; pOperator->blocking = true; @@ -3880,6 +3889,7 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; + pOperator->exprSupp.pExprInfo = pExprInfo; pOperator->exprSupp.numOfExprs = numOfExpr; pOperator->pTaskInfo = pTaskInfo; @@ -3982,29 +3992,32 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT return pTaskInfo; } +static STsdbReader* doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, + STableListInfo* pTableListInfo, const char* idstr); + static SArray* extractColumnInfo(SNodeList* pNodeList); int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskInfo* pTaskInfo) { SMetaReader mr = {0}; metaReaderInit(&mr, pHandle->meta, 0); int32_t code = metaGetTableEntryByUid(&mr, uid); - if (code) { + if (code != TSDB_CODE_SUCCESS) { metaReaderClear(&mr); - return code; + return terrno; } pTaskInfo->schemaVer.tablename = strdup(mr.me.name); if (mr.me.type == TSDB_SUPER_TABLE) { - pTaskInfo->schemaVer.sversion = mr.me.stbEntry.schemaRow.version; + pTaskInfo->schemaVer.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow); pTaskInfo->schemaVer.tversion = mr.me.stbEntry.schemaTag.version; } else if (mr.me.type == TSDB_CHILD_TABLE) { tb_uid_t suid = mr.me.ctbEntry.suid; metaGetTableEntryByUid(&mr, suid); - pTaskInfo->schemaVer.sversion = mr.me.stbEntry.schemaRow.version; + pTaskInfo->schemaVer.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow); pTaskInfo->schemaVer.tversion = mr.me.stbEntry.schemaTag.version; } else { - pTaskInfo->schemaVer.sversion = mr.me.ntbEntry.schemaRow.version; + pTaskInfo->schemaVer.sw = tCloneSSchemaWrapper(&mr.me.ntbEntry.schemaRow); } metaReaderClear(&mr); @@ -4184,13 +4197,14 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pTaskInfo->code = code; return NULL; } + code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo); if (code) { pTaskInfo->code = terrno; return NULL; } - SOperatorInfo* pOperator = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo, queryId, taskId); + SOperatorInfo* pOperator = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo); STableScanInfo* pScanInfo = pOperator->info; pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder; return pOperator; @@ -4243,20 +4257,19 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) { STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode; - int32_t code = getTableList(pHandle->meta, pScanPhyNode, pTableListInfo); + int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanPhyNode, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = terrno; return NULL; } return createTagScanOperatorInfo(pHandle, pScanPhyNode, pTableListInfo, pTaskInfo); - } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) { SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode; pTableListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo)); if (pBlockNode->tableType == TSDB_SUPER_TABLE) { - int32_t code = tsdbGetAllTableList(pHandle->meta, pBlockNode->uid, pTableListInfo->pTableList); + int32_t code = vnodeGetAllTableList(pHandle->vnode, pBlockNode->uid, pTableListInfo->pTableList); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = terrno; return NULL; @@ -4285,12 +4298,42 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo cond.twindows = taosMemoryCalloc(1, sizeof(STimeWindow)); cond.twindows[0] = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; cond.suid = pBlockNode->suid; - cond.type = BLOCK_LOAD_OFFSET_SEQ_ORDER; + cond.type = BLOCK_LOAD_OFFSET_ORDER; } - tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, queryId, taskId); + + STsdbReader* pReader = NULL; + tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, &pReader, ""); cleanupQueryTableDataCond(&cond); return createDataBlockInfoScanOperator(pReader, pHandle, cond.suid, pBlockNode, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN == type) { + SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode; + +// int32_t code = createScanTableListInfo(pTableScanNode, pHandle, pTableListInfo, queryId, taskId); +// if (code) { +// pTaskInfo->code = code; +// return NULL; +// } + + int32_t code = extractTableSchemaVersion(pHandle, pScanNode->uid, pTaskInfo); + if (code != TSDB_CODE_SUCCESS) { + pTaskInfo->code = code; + return NULL; + } + + pTableListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo)); + if (pScanNode->tableType == TSDB_SUPER_TABLE) { + code = vnodeGetAllTableList(pHandle->vnode, pScanNode->uid, pTableListInfo->pTableList); + if (code != TSDB_CODE_SUCCESS) { + pTaskInfo->code = terrno; + return NULL; + } + } else { // Create one table group. + STableKeyInfo info = {.lastKey = 0, .uid = pScanNode->uid, .groupId = 0}; + taosArrayPush(pTableListInfo->pTableList, &info); + } + + return createLastrowScanOperator(pScanNode, pHandle, pTableListInfo->pTableList, pTaskInfo); } else { ASSERT(0); } @@ -4328,7 +4371,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pScalarExprInfo, numOfScalarExpr, pTaskInfo); } else { pOptr = - createAggregateOperatorInfo(ops[0], pExprInfo, num, pResBlock, pScalarExprInfo, numOfScalarExpr, pTaskInfo); + createAggregateOperatorInfo(ops[0], pExprInfo, num, pResBlock, pAggNode->node.pConditions, pScalarExprInfo, numOfScalarExpr, pTaskInfo); } } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type || QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type) { SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode; @@ -4495,16 +4538,15 @@ SArray* extractColumnInfo(SNodeList* pNodeList) { return pList; } -tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, - STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId) { - int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo); +STsdbReader* doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableListInfo* pTableListInfo, const char* idstr) { + int32_t code = getTableList(pHandle->meta, pHandle->vnode, &pTableScanNode->scan, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { goto _error; } if (taosArrayGetSize(pTableListInfo->pTableList) == 0) { code = 0; - qDebug("no table qualified for query, TID:0x%" PRIx64 ", QID:0x%" PRIx64, taskId, queryId); + qDebug("no table qualified for query, %s", idstr); goto _error; } @@ -4514,7 +4556,12 @@ tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* goto _error; } - tsdbReaderT pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, queryId, taskId); + STsdbReader* pReader; + code = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, &pReader, idstr); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + cleanupQueryTableDataCond(&cond); return pReader; @@ -4577,10 +4624,10 @@ int32_t rebuildReader(SOperatorInfo* pOperator, SSubplan* plan, SReadHandle* pHa ASSERT(0); } - tsdbCleanupReadHandle(pTableScanInfo->dataReader); + tsdbReaderClose(pTableScanInfo->dataReader); STableListInfo info = {0}; - pTableScanInfo->dataReader = doCreateDataReader(pNode, pHandle, &info, 0, 0); + pTableScanInfo->dataReader = doCreateDataReader(pNode, pHandle, &info, NULL); if (pTableScanInfo->dataReader == NULL) { ASSERT(0); qError("failed to create data reader"); @@ -4735,6 +4782,7 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead (*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &(*pTaskInfo)->tableqinfoList, pPlan->user); + if (NULL == (*pTaskInfo)->pRoot) { code = (*pTaskInfo)->code; goto _complete; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index f1965d4e68eab538379ac53763270ea7c0bdac92..b3a00cd6f237d900d4dd7511aca75ae4bf030eb0 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -13,15 +13,12 @@ * along with this program. If not, see . */ -#include -#include -#include "filter.h" +#include "executorimpl.h" #include "function.h" #include "functionMgt.h" #include "os.h" #include "querynodes.h" #include "systable.h" -#include "tglobal.h" #include "tname.h" #include "ttime.h" @@ -35,8 +32,6 @@ #include "ttypes.h" #include "vnode.h" -#include "executorInt.h" - #define SET_REVERSE_SCAN_FLAG(_info) ((_info)->scanFlag = REVERSE_SCAN) #define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) @@ -445,7 +440,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { } pTableScanInfo->curTWinIdx += 1; if (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); } } @@ -460,7 +455,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); } // do prepare for the next round table scan operation - tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); pTableScanInfo->curTWinIdx = 0; } } @@ -469,7 +464,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { if (pTableScanInfo->scanTimes < total) { if (pTableScanInfo->cond.order == TSDB_ORDER_ASC) { prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, 0); - tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); pTableScanInfo->curTWinIdx = 0; } @@ -487,7 +482,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { } pTableScanInfo->curTWinIdx += 1; if (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); } } @@ -503,7 +498,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); } - tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); pTableScanInfo->curTWinIdx = 0; } } @@ -531,7 +526,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { } STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, pInfo->currentTable); tsdbSetTableId(pInfo->dataReader, pTableInfo->uid); - tsdbResetReadHandle(pInfo->dataReader, &pInfo->cond, 0); + tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); pInfo->scanTimes = 0; pInfo->curTWinIdx = 0; } @@ -543,11 +538,12 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { setTaskStatus(pTaskInfo, TASK_COMPLETED); return NULL; } + SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId); - tsdbCleanupReadHandle(pInfo->dataReader); - tsdbReaderT* pReader = - tsdbReaderOpen(pInfo->readHandle.vnode, &pInfo->cond, tableList, pInfo->queryId, pInfo->taskId); - pInfo->dataReader = pReader; + tsdbReaderClose(pInfo->dataReader); + + int32_t code = tsdbReaderOpen(pInfo->readHandle.vnode, &pInfo->cond, tableList, (STsdbReader**)&pInfo->dataReader, + GET_TASKID(pTaskInfo)); } SSDataBlock* result = doTableScanGroup(pOperator); @@ -562,9 +558,9 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { } SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId); - tsdbSetTableList(pInfo->dataReader, tableList); + // tsdbSetTableList(pInfo->dataReader, tableList); - tsdbResetReadHandle(pInfo->dataReader, &pInfo->cond, 0); + tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); pInfo->curTWinIdx = 0; pInfo->scanTimes = 0; @@ -591,7 +587,7 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) { blockDataDestroy(pTableScanInfo->pResBlock); cleanupQueryTableDataCond(&pTableScanInfo->cond); - tsdbCleanupReadHandle(pTableScanInfo->dataReader); + tsdbReaderClose(pTableScanInfo->dataReader); if (pTableScanInfo->pColMatchInfo != NULL) { taosArrayDestroy(pTableScanInfo->pColMatchInfo); @@ -599,15 +595,13 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) { } SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle, - SExecTaskInfo* pTaskInfo, uint64_t queryId, uint64_t taskId) { + SExecTaskInfo* pTaskInfo) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - // taosSsleep(20); - SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; int32_t numOfCols = 0; SArray* pColList = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); @@ -637,8 +631,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, pInfo->scanFlag = MAIN_SCAN; pInfo->pColMatchInfo = pColList; pInfo->curTWinIdx = 0; - pInfo->queryId = queryId; - pInfo->taskId = taskId; pInfo->currentGroupId = -1; pOperator->name = "TableScanOperator"; // for debug purpose @@ -889,7 +881,7 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo, SSDataBlock* pSDB, int3 STableScanInfo* pTableScanInfo = pInfo->pSnapshotReadOp->info; pTableScanInfo->cond.twindows[0] = win; pTableScanInfo->curTWinIdx = 0; - // tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); + // tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); // if (!pTableScanInfo->dataReader) { // return false; // } @@ -1295,13 +1287,13 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys } if (pHandle) { - SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo, queryId, taskId); + SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo); STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info; SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, 0); if (pHandle->tqReader) { pSTInfo->scanMode = TABLE_SCAN__TABLE_ORDER; - pSTInfo->dataReader = tsdbReaderOpen(pHandle->vnode, &pSTInfo->cond, tableList, 0, 0); + tsdbReaderOpen(pHandle->vnode, &pSTInfo->cond, tableList, &pSTInfo->dataReader, 0); } if (pSTInfo->interval.interval > 0) { @@ -1375,6 +1367,7 @@ static void destroySysScanOperator(void* param, int32_t numOfOutput) { } taosArrayDestroy(pInfo->scanCols); + taosMemoryFreeClear(pInfo->pUser); } static int32_t getSysTableDbNameColId(const char* pTable) { @@ -2157,7 +2150,7 @@ typedef struct STableMergeScanInfo { int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId) { - int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo); + int32_t code = getTableList(pHandle->meta, pHandle->vnode, &pTableScanNode->scan, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -2176,13 +2169,13 @@ int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle } int32_t createMultipleDataReaders(SQueryTableDataCond* pQueryCond, SReadHandle* pHandle, STableListInfo* pTableListInfo, - int32_t tableStartIdx, int32_t tableEndIdx, SArray* arrayReader, uint64_t queryId, - uint64_t taskId) { + int32_t tableStartIdx, int32_t tableEndIdx, SArray* arrayReader, const char* idstr) { for (int32_t i = tableStartIdx; i <= tableEndIdx; ++i) { SArray* subTableList = taosArrayInit(1, sizeof(STableKeyInfo)); taosArrayPush(subTableList, taosArrayGet(pTableListInfo->pTableList, i)); - tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, pQueryCond, subTableList, queryId, taskId); + STsdbReader* pReader = NULL; + tsdbReaderOpen(pHandle->vnode, pQueryCond, subTableList, &pReader, idstr); taosArrayPush(arrayReader, &pReader); taosArrayDestroy(subTableList); @@ -2233,7 +2226,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc bool allColumnsHaveAgg = true; SColumnDataAgg** pColAgg = NULL; - tsdbReaderT* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); + STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); tsdbRetrieveDataBlockStatisInfo(reader, &pColAgg, &allColumnsHaveAgg); if (allColumnsHaveAgg == true) { @@ -2274,7 +2267,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc pCost->totalCheckedRows += pBlock->info.rows; pCost->loadBlocks += 1; - tsdbReaderT* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); + STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); SArray* pCols = tsdbRetrieveDataBlock(reader, NULL); if (pCols == NULL) { return terrno; @@ -2320,7 +2313,7 @@ static SSDataBlock* getTableDataBlock(void* param) { blockDataCleanup(pBlock); - tsdbReaderT* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); + STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); while (tsdbNextDataBlock(reader)) { if (isTaskKilled(pOperator->pTaskInfo)) { longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED); @@ -2398,7 +2391,7 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) { STableListInfo* tableListInfo = pInfo->tableListInfo; createMultipleDataReaders(&pInfo->cond, &pInfo->readHandle, tableListInfo, tableStartIdx, tableEndIdx, - pInfo->dataReaders, pInfo->queryId, pInfo->taskId); + pInfo->dataReaders, GET_TASKID(pTaskInfo)); // todo the total available buffer should be determined by total capacity of buffer of this task. // the additional one is reserved for merge result @@ -2442,11 +2435,12 @@ int32_t stopGroupTableMergeScan(SOperatorInfo* pOperator) { taosArrayClear(pInfo->sortSourceParams); for (int32_t i = 0; i < taosArrayGetSize(pInfo->dataReaders); ++i) { - tsdbReaderT* reader = taosArrayGetP(pInfo->dataReaders, i); - tsdbCleanupReadHandle(reader); + STsdbReader* reader = taosArrayGetP(pInfo->dataReaders, i); + tsdbReaderClose(reader); } - taosArrayDestroy(pInfo->dataReaders); + taosArrayDestroy(pInfo->dataReaders); + pInfo->dataReaders = NULL; return TSDB_CODE_SUCCESS; } @@ -2528,6 +2522,12 @@ void destroyTableMergeScanOperatorInfo(void* param, int32_t numOfOutput) { STableMergeScanInfo* pTableScanInfo = (STableMergeScanInfo*)param; cleanupQueryTableDataCond(&pTableScanInfo->cond); + for (int32_t i = 0; i < taosArrayGetSize(pTableScanInfo->dataReaders); ++i) { + STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, i); + tsdbReaderClose(reader); + } + taosArrayDestroy(pTableScanInfo->dataReaders); + if (pTableScanInfo->pColMatchInfo != NULL) { taosArrayDestroy(pTableScanInfo->pColMatchInfo); } @@ -2636,3 +2636,100 @@ _error: taosMemoryFree(pOperator); return NULL; } + +static SSDataBlock* doScanLastrow(SOperatorInfo* pOperator) { + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + SLastrowScanInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + int32_t size = taosArrayGetSize(pInfo->pTableList); + if (size == 0) { + setTaskStatus(pTaskInfo, TASK_COMPLETED); + return NULL; + } + + // check if it is a group by tbname + if (size == taosArrayGetSize(pInfo->pTableList)) { + blockDataCleanup(pInfo->pRes); + tsdbRetrieveLastRow(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds); + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; + } else { + // todo fetch the result for each group + } + + return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; +} + +static void destroyLastrowScanOperator(void* param, int32_t numOfOutput) { + SLastrowScanInfo* pInfo = (SLastrowScanInfo*)param; + blockDataDestroy(pInfo->pRes); + tsdbLastrowReaderClose(pInfo->pLastrowReader); +} + +SOperatorInfo* createLastrowScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandle* readHandle, SArray* pTableList, + SExecTaskInfo* pTaskInfo) { + SLastrowScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SLastrowScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pInfo == NULL || pOperator == NULL) { + goto _error; + } + + pInfo->pTableList = pTableList; + pInfo->readHandle = *readHandle; + pInfo->pRes = createResDataBlock(pScanNode->node.pOutputDataBlockDesc); + + int32_t numOfCols = 0; + pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->pScanCols, pScanNode->node.pOutputDataBlockDesc, &numOfCols, + COL_MATCH_FROM_COL_ID); + int32_t* pCols = taosMemoryMalloc(numOfCols * sizeof(int32_t)); + for (int32_t i = 0; i < numOfCols; ++i) { + SColMatchInfo* pColMatch = taosArrayGet(pInfo->pColMatchInfo, i); + pCols[i] = pColMatch->colId; + } + + pInfo->pSlotIds = taosMemoryMalloc(numOfCols * sizeof(pInfo->pSlotIds[0])); + for (int32_t i = 0; i < numOfCols; ++i) { + SColMatchInfo* pColMatch = taosArrayGet(pInfo->pColMatchInfo, i); + for (int32_t j = 0; j < pTaskInfo->schemaVer.sw->nCols; ++j) { + if (pColMatch->colId == pTaskInfo->schemaVer.sw->pSchema[j].colId && + pColMatch->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { + pInfo->pSlotIds[pColMatch->targetSlotId] = -1; + break; + } + + if (pColMatch->colId == pTaskInfo->schemaVer.sw->pSchema[j].colId) { + pInfo->pSlotIds[pColMatch->targetSlotId] = j; + break; + } + } + } + + tsdbLastRowReaderOpen(readHandle->vnode, LASTROW_RETRIEVE_TYPE_ALL, pTableList, pCols, numOfCols, + &pInfo->pLastrowReader); + taosMemoryFree(pCols); + + pOperator->name = "LastrowScanOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); + + initResultSizeInfo(pOperator, 1024); + blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); + + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doScanLastrow, NULL, NULL, destroyLastrowScanOperator, NULL, NULL, NULL); + pOperator->cost.openCost = 0; + return pOperator; + +_error: + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + return NULL; +} diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 44ff4c1c9099c70f40601b2e2de847ff0becd103..2dc8ced737798f8ebd0bfa75db097e324c4f9cdd 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -46,7 +46,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* initResultSizeInfo(pOperator, 1024); pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys); - ; + pInfo->pCondition = pSortPhyNode->node.pConditions; pInfo->pColMatchInfo = pColMatchColInfo; pOperator->name = "SortOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; @@ -205,14 +205,27 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { longjmp(pTaskInfo->env, code); } - SSDataBlock* pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, - pInfo->pColMatchInfo, pInfo); + SSDataBlock* pBlock = NULL; + while (1) { + pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, + pInfo->pColMatchInfo, pInfo); + if (pBlock != NULL) { + doFilter(pInfo->pCondition, pBlock); + } + + if (pBlock == NULL) { + doSetOperatorCompleted(pOperator); + break; + } + if (blockDataGetNumOfRows(pBlock) > 0) { + break; + } + } if (pBlock != NULL) { pOperator->resultInfo.totalRows += pBlock->info.rows; - } else { - doSetOperatorCompleted(pOperator); } + return pBlock; } diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index fdef432d9596552a61b210120c1ea384ed269731..4683d662608b0be761f0de42f7dfa19a9fe19d5a 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1208,10 +1208,17 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) { } blockDataEnsureCapacity(pBlock, pOperator->resultInfo.capacity); - doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - - if (pBlock->info.rows == 0 || !hasDataInGroupInfo(&pInfo->groupResInfo)) { - doSetOperatorCompleted(pOperator); + while (1) { + doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); + doFilter(pInfo->pCondition, pBlock); + bool hasRemain = hasDataInGroupInfo(&pInfo->groupResInfo); + if (!hasRemain) { + doSetOperatorCompleted(pOperator); + break; + } + if (pBlock->info.rows > 0) { + break; + } } size_t rows = pBlock->info.rows; @@ -1662,6 +1669,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pInfo->execModel = pTaskInfo->execModel; pInfo->twAggSup = *pTwAggSupp; pInfo->ignoreExpiredData = pPhyNode->window.igExpired; + pInfo->pCondition = pPhyNode->window.node.pConditions; if (pPhyNode->window.pExprs != NULL) { int32_t numOfScalar = 0; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 8ee6d18b9897f02e630f5d21cdcc6ef9893a9e25..8779fe54152aeb6ae26b08dccbfcf7db03b88bf2 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -545,6 +545,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { return 0; } +// TODO consider the page meta size int32_t getProperSortPageSize(size_t rowSize) { uint32_t defaultPageSize = 4096; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 8eafb0703e5246be7ab5331dbf70b0f2c8f1283b..06944edadd0505cefb85bc6185fc7a1a39bb3869 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -106,6 +106,8 @@ bool irateFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo); int32_t irateFunction(SqlFunctionCtx *pCtx); int32_t irateFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +int32_t lastrowFunction(SqlFunctionCtx* pCtx); + bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t firstFunction(SqlFunctionCtx *pCtx); int32_t firstFunctionMerge(SqlFunctionCtx *pCtx); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index d9a05973ced6d55252a01f983789ccfe117a6acc..1e7e7e57c3d1c9333afaef5969bca49a2ec20ee6 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -605,7 +605,7 @@ static int32_t translateTopBot(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } SValueNode* pValue = (SValueNode*)pParamNode1; - if (pValue->node.resType.type != TSDB_DATA_TYPE_BIGINT) { + if (!IS_INTEGER_TYPE(pValue->node.resType.type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -1615,26 +1615,27 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } SExprNode* pPara0 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - SExprNode* p1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 1); + SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 1); - uint8_t para1Type = p1->resType.type; - if (!IS_VAR_DATA_TYPE(pPara0->resType.type) || !IS_INTEGER_TYPE(para1Type)) { + uint8_t para0Type = pPara0->resType.type; + uint8_t para1Type = pPara1->resType.type; + if (!IS_VAR_DATA_TYPE(para0Type) || !IS_INTEGER_TYPE(para1Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - if (((SValueNode*)p1)->datum.i < 1) { + if (((SValueNode*)pPara1)->datum.i == 0) { return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); } if (3 == numOfParams) { - SExprNode* p2 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 2); - uint8_t para2Type = p2->resType.type; + SExprNode* pPara2 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 2); + uint8_t para2Type = pPara2->resType.type; if (!IS_INTEGER_TYPE(para2Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - int64_t v = ((SValueNode*)p1)->datum.i; - if (v < 0 || v > INT16_MAX) { + int64_t v = ((SValueNode*)pPara2)->datum.i; + if (v < 0) { return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); } } @@ -2210,22 +2211,12 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "last_row", .type = FUNCTION_TYPE_LAST_ROW, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC, .translateFunc = translateFirstLast, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, - .processFunc = lastRowFunction, - .finalizeFunc = lastRowFinalize, - }, - { - .name = "_cache_last_row", - .type = FUNCTION_TYPE_CACHE_LAST_ROW, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, - .translateFunc = translateLastRow, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = minmaxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize + .processFunc = lastrowFunction, + .finalizeFunc = firstLastFinalize }, { .name = "first", diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index cf4a7634234223b778741a41ceb42141e9c840ac..f94522f0d8bde5df192d6481f2c2a9ae4cc57291 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -90,12 +90,14 @@ typedef struct SStddevRes { double result; int64_t count; union { - double quadraticDSum; - int64_t quadraticISum; + double quadraticDSum; + int64_t quadraticISum; + uint64_t quadraticUSum; }; union { - double dsum; - int64_t isum; + double dsum; + int64_t isum; + uint64_t usum; }; int16_t type; } SStddevRes; @@ -1729,6 +1731,68 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { break; } + case TSDB_DATA_TYPE_UTINYINT: { + uint8_t* plist = (uint8_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + start; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->usum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + + break; + } + + case TSDB_DATA_TYPE_USMALLINT: { + uint16_t* plist = (uint16_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->usum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + break; + } + + case TSDB_DATA_TYPE_UINT: { + uint32_t* plist = (uint32_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->usum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + + break; + } + + case TSDB_DATA_TYPE_UBIGINT: { + uint64_t* plist = (uint64_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->usum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + break; + } + case TSDB_DATA_TYPE_FLOAT: { float* plist = (float*)pCol->pData; for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { @@ -1771,9 +1835,12 @@ _stddev_over: static void stddevTransferInfo(SStddevRes* pInput, SStddevRes* pOutput) { pOutput->type = pInput->type; - if (IS_INTEGER_TYPE(pOutput->type)) { + if (IS_SIGNED_NUMERIC_TYPE(pOutput->type)) { pOutput->quadraticISum += pInput->quadraticISum; pOutput->isum += pInput->isum; + } else if (IS_UNSIGNED_NUMERIC_TYPE(pOutput->type)) { + pOutput->quadraticUSum += pInput->quadraticUSum; + pOutput->usum += pInput->usum; } else { pOutput->quadraticDSum += pInput->quadraticDSum; pOutput->dsum += pInput->dsum; @@ -1848,6 +1915,22 @@ int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) { LIST_STDDEV_SUB_N(pStddevRes->isum, int64_t); break; } + case TSDB_DATA_TYPE_UTINYINT: { + LIST_STDDEV_SUB_N(pStddevRes->isum, uint8_t); + break; + } + case TSDB_DATA_TYPE_USMALLINT: { + LIST_STDDEV_SUB_N(pStddevRes->isum, uint16_t); + break; + } + case TSDB_DATA_TYPE_UINT: { + LIST_STDDEV_SUB_N(pStddevRes->isum, uint32_t); + break; + } + case TSDB_DATA_TYPE_UBIGINT: { + LIST_STDDEV_SUB_N(pStddevRes->isum, uint64_t); + break; + } case TSDB_DATA_TYPE_FLOAT: { LIST_STDDEV_SUB_N(pStddevRes->dsum, float); break; @@ -1871,9 +1954,12 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t type = pStddevRes->type; double avg; - if (IS_INTEGER_TYPE(type)) { + if (IS_SIGNED_NUMERIC_TYPE(type)) { avg = pStddevRes->isum / ((double)pStddevRes->count); pStddevRes->result = sqrt(fabs(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg)); + } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { + avg = pStddevRes->usum / ((double)pStddevRes->count); + pStddevRes->result = sqrt(fabs(pStddevRes->quadraticUSum / ((double)pStddevRes->count) - avg * avg)); } else { avg = pStddevRes->dsum / ((double)pStddevRes->count); pStddevRes->result = sqrt(fabs(pStddevRes->quadraticDSum / ((double)pStddevRes->count) - avg * avg)); @@ -1913,9 +1999,12 @@ int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) { SResultRowEntryInfo* pSResInfo = GET_RES_INFO(pSourceCtx); SStddevRes* pSBuf = GET_ROWCELL_INTERBUF(pSResInfo); - if (IS_INTEGER_TYPE(type)) { + if (IS_SIGNED_NUMERIC_TYPE(type)) { pDBuf->isum += pSBuf->isum; pDBuf->quadraticISum += pSBuf->quadraticISum; + } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { + pDBuf->usum += pSBuf->usum; + pDBuf->quadraticUSum += pSBuf->quadraticUSum; } else { pDBuf->dsum += pSBuf->dsum; pDBuf->quadraticDSum += pSBuf->quadraticDSum; @@ -5848,3 +5937,43 @@ int32_t interpFunction(SqlFunctionCtx* pCtx) { return TSDB_CODE_SUCCESS; } + +int32_t lastrowFunction(SqlFunctionCtx* pCtx) { + int32_t numOfElems = 0; + + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(pResInfo); + + SInputColumnInfoData* pInput = &pCtx->input; + SColumnInfoData* pInputCol = pInput->pData[0]; + + int32_t type = pInputCol->info.type; + int32_t bytes = pInputCol->info.bytes; + pInfo->bytes = bytes; + + for (int32_t i = pInput->numOfRows + pInput->startRowIndex - 1; i >= pInput->startRowIndex; --i) { + if (pInputCol->hasNull && colDataIsNull_s(pInputCol, i)) { + continue; + } + + numOfElems++; + + char* data = colDataGetData(pInputCol, i); + TSKEY cts = getRowPTs(pInput->pPTS, i); + if (pResInfo->numOfRes == 0 || *(TSKEY*)(pInfo->buf + bytes) < cts) { + if (IS_VAR_DATA_TYPE(type)) { + bytes = varDataTLen(data); + pInfo->bytes = bytes; + } + + memcpy(pInfo->buf, data, bytes); + *(TSKEY*)(pInfo->buf + bytes) = cts; + + pInfo->hasResult = true; + pResInfo->numOfRes = 1; + } + } + + SET_VAL(pResInfo, numOfElems, 1); + return TSDB_CODE_SUCCESS; +} diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 26a1548e7cd5af3a2b30ef2a3ca8f3ce06e230c6..e3d367e59c2a484ea471d06199fd236ff7c1d930 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -65,9 +65,10 @@ void indexInit() { indexQhandle = taosInitScheduler(INDEX_QUEUE_SIZE, INDEX_NUM_OF_THREADS, "index"); indexRefMgt = taosOpenRef(1000, indexDestroy); } -void indexCleanUp() { +void indexCleanup() { // refacto later taosCleanUpScheduler(indexQhandle); + taosCloseRef(indexRefMgt); } typedef struct SIdxColInfo { diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 25a41fb15c5478126966886b0a82e9a2a658b117..a1b0cc59470d387d4bb865ca622e473b2d066376 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -165,7 +165,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { memcpy(pDst->datum.p, pSrc->datum.p, len); break; } - case TSDB_DATA_TYPE_JSON:{ + case TSDB_DATA_TYPE_JSON: { int32_t len = getJsonValueLen(pSrc->datum.p); pDst->datum.p = taosMemoryCalloc(1, len); if (NULL == pDst->datum.p) { @@ -394,9 +394,12 @@ static int32_t logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModi COPY_SCALAR_FIELD(msgType); CLONE_NODE_FIELD(pAffectedRows); COPY_SCALAR_FIELD(tableId); + COPY_SCALAR_FIELD(stableId); COPY_SCALAR_FIELD(tableType); COPY_CHAR_ARRAY_FIELD(tableFName); COPY_OBJECT_FIELD(deleteTimeRange, sizeof(STimeWindow)); + CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone); + CLONE_NODE_LIST_FIELD(pInsertCols); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 34f92dac0b0fb099228df512d07237b93f528121..0bff063ea1a5fbb168472c978580f5b15cc348d3 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -19,8 +19,8 @@ #include "query.h" #include "querynodes.h" #include "taoserror.h" -#include "tjson.h" #include "tdatablock.h" +#include "tjson.h" static int32_t nodeToJson(const void* pObj, SJson* pJson); static int32_t jsonToNode(const SJson* pJson, void* pObj); @@ -179,6 +179,8 @@ const char* nodesNodeName(ENodeType type) { return "ShowVnodeStmt"; case QUERY_NODE_DELETE_STMT: return "DeleteStmt"; + case QUERY_NODE_INSERT_STMT: + return "InsertStmt"; case QUERY_NODE_LOGIC_PLAN_SCAN: return "LogicScan"; case QUERY_NODE_LOGIC_PLAN_JOIN: @@ -271,6 +273,8 @@ const char* nodesNodeName(ENodeType type) { return "PhysiDispatch"; case QUERY_NODE_PHYSICAL_PLAN_INSERT: return "PhysiInsert"; + case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: + return "PhysiQueryInsert"; case QUERY_NODE_PHYSICAL_PLAN_DELETE: return "PhysiDelete"; case QUERY_NODE_PHYSICAL_SUBPLAN: @@ -2210,6 +2214,72 @@ static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { return jsonToPhysicDataSinkNode(pJson, pObj); } +static const char* jkQueryInsertPhysiPlanInsertCols = "InsertCols"; +static const char* jkQueryInsertPhysiPlanStableId = "StableId"; +static const char* jkQueryInsertPhysiPlanTableId = "TableId"; +static const char* jkQueryInsertPhysiPlanTableType = "TableType"; +static const char* jkQueryInsertPhysiPlanTableFName = "TableFName"; +static const char* jkQueryInsertPhysiPlanVgId = "VgId"; +static const char* jkQueryInsertPhysiPlanEpSet = "EpSet"; + +static int32_t physiQueryInsertNodeToJson(const void* pObj, SJson* pJson) { + const SQueryInserterNode* pNode = (const SQueryInserterNode*)pObj; + + int32_t code = physicDataSinkNodeToJson(pObj, pJson); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkQueryInsertPhysiPlanInsertCols, pNode->pCols); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanStableId, pNode->stableId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanTableId, pNode->tableId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanTableType, pNode->tableType); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddStringToObject(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableFName); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanVgId, pNode->vgId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkQueryInsertPhysiPlanEpSet, epSetToJson, &pNode->epSet); + } + + return code; +} + +static int32_t jsonToPhysiQueryInsertNode(const SJson* pJson, void* pObj) { + SQueryInserterNode* pNode = (SQueryInserterNode*)pObj; + + int32_t code = jsonToPhysicDataSinkNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkQueryInsertPhysiPlanInsertCols, &pNode->pCols); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUBigIntValue(pJson, jkQueryInsertPhysiPlanStableId, &pNode->stableId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUBigIntValue(pJson, jkQueryInsertPhysiPlanTableId, &pNode->tableId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetTinyIntValue(pJson, jkQueryInsertPhysiPlanTableType, &pNode->tableType); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetStringValue(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableFName); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkQueryInsertPhysiPlanVgId, &pNode->vgId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonToObject(pJson, jkQueryInsertPhysiPlanEpSet, jsonToEpSet, &pNode->epSet); + } + + return code; +} + static const char* jkDeletePhysiPlanTableId = "TableId"; static const char* jkDeletePhysiPlanTableType = "TableType"; static const char* jkDeletePhysiPlanTableFName = "TableFName"; @@ -2641,9 +2711,9 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) { case TSDB_DATA_TYPE_VARBINARY: code = tjsonAddStringToObject(pJson, jkValueDatum, varDataVal(pNode->datum.p)); break; - case TSDB_DATA_TYPE_JSON:{ + case TSDB_DATA_TYPE_JSON: { int32_t len = getJsonValueLen(pNode->datum.p); - char* buf = taosMemoryCalloc( len * 2 + 1, sizeof(char)); + char* buf = taosMemoryCalloc(len * 2 + 1, sizeof(char)); code = taosHexEncode(pNode->datum.p, buf, len); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(buf); @@ -2775,7 +2845,7 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) { } break; } - case TSDB_DATA_TYPE_JSON:{ + case TSDB_DATA_TYPE_JSON: { pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes); if (NULL == pNode->datum.p) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -4232,6 +4302,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { return physiDispatchNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_INSERT: break; + case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: + return physiQueryInsertNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_DELETE: return physiDeleteNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_SUBPLAN: @@ -4374,6 +4446,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToPhysiInterpFuncNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return jsonToPhysiDispatchNode(pJson, pObj); + case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: + return jsonToPhysiQueryInsertNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_DELETE: return jsonToPhysiDeleteNode(pJson, pObj); case QUERY_NODE_PHYSICAL_SUBPLAN: diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 118cd808075e9ba091f677539350a43e340c6829..e15375e6effbec711d958baf6f4d9d6eed6e801d 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -103,6 +103,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SDropDatabaseStmt)); case QUERY_NODE_ALTER_DATABASE_STMT: return makeNode(type, sizeof(SAlterDatabaseStmt)); + case QUERY_NODE_FLUSH_DATABASE_STMT: + return makeNode(type, sizeof(SFlushDatabaseStmt)); case QUERY_NODE_CREATE_TABLE_STMT: return makeNode(type, sizeof(SCreateTableStmt)); case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: @@ -229,6 +231,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SKillStmt)); case QUERY_NODE_DELETE_STMT: return makeNode(type, sizeof(SDeleteStmt)); + case QUERY_NODE_INSERT_STMT: + return makeNode(type, sizeof(SInsertStmt)); case QUERY_NODE_QUERY: return makeNode(type, sizeof(SQuery)); case QUERY_NODE_LOGIC_PLAN_SCAN: @@ -325,6 +329,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SDataDispatcherNode)); case QUERY_NODE_PHYSICAL_PLAN_INSERT: return makeNode(type, sizeof(SDataInserterNode)); + case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: + return makeNode(type, sizeof(SQueryInserterNode)); case QUERY_NODE_PHYSICAL_PLAN_DELETE: return makeNode(type, sizeof(SDataDeleterNode)); case QUERY_NODE_PHYSICAL_SUBPLAN: @@ -541,6 +547,8 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_ALTER_DATABASE_STMT: nodesDestroyNode((SNode*)((SAlterDatabaseStmt*)pNode)->pOptions); break; + case QUERY_NODE_FLUSH_DATABASE_STMT: // no pointer field + break; case QUERY_NODE_CREATE_TABLE_STMT: { SCreateTableStmt* pStmt = (SCreateTableStmt*)pNode; nodesDestroyList(pStmt->pCols); @@ -690,6 +698,13 @@ void nodesDestroyNode(SNode* pNode) { nodesDestroyNode(pStmt->pTagCond); break; } + case QUERY_NODE_INSERT_STMT: { + SInsertStmt* pStmt = (SInsertStmt*)pNode; + nodesDestroyNode(pStmt->pTable); + nodesDestroyList(pStmt->pCols); + nodesDestroyNode(pStmt->pQuery); + break; + } case QUERY_NODE_QUERY: { SQuery* pQuery = (SQuery*)pNode; nodesDestroyNode(pQuery->pRoot); @@ -925,6 +940,11 @@ void nodesDestroyNode(SNode* pNode) { taosMemoryFreeClear(pSink->pData); break; } + case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: { + SQueryInserterNode* pSink = (SQueryInserterNode*)pNode; + destroyDataSinkNode((SDataSinkNode*)pSink); + break; + } case QUERY_NODE_PHYSICAL_PLAN_DELETE: { SDataDeleterNode* pSink = (SDataDeleterNode*)pNode; destroyDataSinkNode((SDataSinkNode*)pSink); @@ -1524,7 +1544,6 @@ int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, EColle } return TSDB_CODE_SUCCESS; - } typedef struct SCollectFuncsCxt { diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 0c9156fc4c96f81e3308c331573b8443018b2557..835f8098a365bf63a26a8e7b94ac19012f55c95c 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -135,6 +135,7 @@ SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOp SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); +SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createDefaultTableOptions(SAstCreateContext* pCxt); SNode* createAlterTableOptions(SAstCreateContext* pCxt); SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal); @@ -210,6 +211,7 @@ SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName); SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName); SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName); SNode* createDeleteStmt(SAstCreateContext* pCxt, SNode* pTable, SNode* pWhere); +SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols, SNode* pQuery); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 19b327f8c6cf689081971d196592a32e80cd3c4d..3c173aead9c0820aa2dea86483ffede66cea1daf 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -157,6 +157,7 @@ cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); } cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); } cmd ::= ALTER DATABASE db_name(A) alter_db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); } +cmd ::= FLUSH DATABASE db_name(A). { pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &A); } %type not_exists_opt { bool } %destructor not_exists_opt { } @@ -259,7 +260,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C). create_subtable_clause(A) ::= not_exists_opt(B) full_table_name(C) USING full_table_name(D) - specific_tags_opt(E) TAGS NK_LP expression_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); } + specific_cols_opt(E) TAGS NK_LP expression_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); } %type multi_drop_clause { SNodeList* } %destructor multi_drop_clause { nodesDestroyList($$); } @@ -268,10 +269,10 @@ multi_drop_clause(A) ::= multi_drop_clause(B) drop_table_clause(C). drop_table_clause(A) ::= exists_opt(B) full_table_name(C). { A = createDropTableClause(pCxt, B, C); } -%type specific_tags_opt { SNodeList* } -%destructor specific_tags_opt { nodesDestroyList($$); } -specific_tags_opt(A) ::= . { A = NULL; } -specific_tags_opt(A) ::= NK_LP col_name_list(B) NK_RP. { A = B; } +%type specific_cols_opt { SNodeList* } +%destructor specific_cols_opt { nodesDestroyList($$); } +specific_cols_opt(A) ::= . { A = NULL; } +specific_cols_opt(A) ::= NK_LP col_name_list(B) NK_RP. { A = B; } full_table_name(A) ::= table_name(B). { A = createRealTableNode(pCxt, NULL, &B, NULL); } full_table_name(A) ::= db_name(B) NK_DOT table_name(C). { A = createRealTableNode(pCxt, &B, &C, NULL); } @@ -515,6 +516,9 @@ cmd ::= DELETE FROM full_table_name(A) where_clause_opt(B). /************************************************ select **************************************************************/ cmd ::= query_expression(A). { pCxt->pRootNode = A; } +/************************************************ insert **************************************************************/ +cmd ::= INSERT INTO full_table_name(A) specific_cols_opt(B) query_expression(C). { pCxt->pRootNode = createInsertStmt(pCxt, A, B, C); } + /************************************************ literal *************************************************************/ literal(A) ::= NK_INTEGER(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); } literal(A) ::= NK_FLOAT(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B)); } @@ -973,4 +977,4 @@ null_ordering_opt(A) ::= . null_ordering_opt(A) ::= NULLS FIRST. { A = NULL_ORDER_FIRST; } null_ordering_opt(A) ::= NULLS LAST. { A = NULL_ORDER_LAST; } -%fallback ID NK_BITNOT INSERT VALUES IMPORT NK_SEMI FILE. +%fallback ID NK_BITNOT VALUES IMPORT NK_SEMI FILE. diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 104241197409bbd47a4d3bce25128be8c20b8d7d..29396f4101ebe4a697c6e3f69d0db23c3ba6b9ad 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -912,6 +912,17 @@ SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* return (SNode*)pStmt; } +SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) { + CHECK_PARSER_STATUS(pCxt); + if (!checkDbName(pCxt, pDbName, false)) { + return NULL; + } + SAlterDatabaseStmt* pStmt = (SAlterDatabaseStmt*)nodesMakeNode(QUERY_NODE_FLUSH_DATABASE_STMT); + CHECK_OUT_OF_MEM(pStmt); + COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName); + return (SNode*)pStmt; +} + SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { CHECK_PARSER_STATUS(pCxt); STableOptions* pOptions = (STableOptions*)nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); @@ -1662,3 +1673,18 @@ SNode* createDeleteStmt(SAstCreateContext* pCxt, SNode* pTable, SNode* pWhere) { } return (SNode*)pStmt; } + +SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols, SNode* pQuery) { + CHECK_PARSER_STATUS(pCxt); + SInsertStmt* pStmt = (SInsertStmt*)nodesMakeNode(QUERY_NODE_INSERT_STMT); + CHECK_OUT_OF_MEM(pStmt); + pStmt->pTable = pTable; + pStmt->pCols = pCols; + pStmt->pQuery = pQuery; + if (QUERY_NODE_SELECT_STMT == nodeType(pQuery)) { + strcpy(((SSelectStmt*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias); + } else if (QUERY_NODE_SET_OPERATOR == nodeType(pQuery)) { + strcpy(((SSetOperator*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias); + } + return (SNode*)pStmt; +} diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 9cc822ee38e7ff37deb6c3eb962a6060914245a5..f38def0b1dd167bece9e768669239bd5e7bc1b07 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -195,6 +195,10 @@ static int32_t collectMetaKeyFromAlterDatabase(SCollectMetaKeyCxt* pCxt, SAlterD return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); } +static int32_t collectMetaKeyFromFlushDatabase(SCollectMetaKeyCxt* pCxt, SFlushDatabaseStmt* pStmt) { + return reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); +} + static int32_t collectMetaKeyFromCreateTable(SCollectMetaKeyCxt* pCxt, SCreateTableStmt* pStmt) { int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); if (TSDB_CODE_SUCCESS == code && NULL == pStmt->pTags) { @@ -447,6 +451,14 @@ static int32_t collectMetaKeyFromDelete(SCollectMetaKeyCxt* pCxt, SDeleteStmt* p return collectMetaKeyFromRealTableImpl(pCxt, (SRealTableNode*)pStmt->pFromTable, AUTH_TYPE_WRITE); } +static int32_t collectMetaKeyFromInsert(SCollectMetaKeyCxt* pCxt, SInsertStmt* pStmt) { + int32_t code = collectMetaKeyFromRealTableImpl(pCxt, (SRealTableNode*)pStmt->pTable, AUTH_TYPE_WRITE); + if (TSDB_CODE_SUCCESS == code) { + code = collectMetaKeyFromQuery(pCxt, pStmt->pQuery); + } + return code; +} + static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTableDistributedStmt* pStmt) { SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId}; strcpy(name.dbname, pStmt->dbName); @@ -479,6 +491,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromSelect(pCxt, (SSelectStmt*)pStmt); case QUERY_NODE_ALTER_DATABASE_STMT: return collectMetaKeyFromAlterDatabase(pCxt, (SAlterDatabaseStmt*)pStmt); + case QUERY_NODE_FLUSH_DATABASE_STMT: + return collectMetaKeyFromFlushDatabase(pCxt, (SFlushDatabaseStmt*)pStmt); case QUERY_NODE_CREATE_TABLE_STMT: return collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt); case QUERY_NODE_CREATE_MULTI_TABLE_STMT: @@ -554,6 +568,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromShowTransactions(pCxt, (SShowStmt*)pStmt); case QUERY_NODE_DELETE_STMT: return collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt); + case QUERY_NODE_INSERT_STMT: + return collectMetaKeyFromInsert(pCxt, (SInsertStmt*)pStmt); case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: return collectMetaKeyFromShowBlockDist(pCxt, (SShowTableDistributedStmt*)pStmt); case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: diff --git a/source/libs/parser/src/parAuthenticator.c b/source/libs/parser/src/parAuthenticator.c index 068ac4c94d2fb84e5a5992b5744d13f876cc5d75..befc822808c7b50eeaea5753a61bb10ffef81523 100644 --- a/source/libs/parser/src/parAuthenticator.c +++ b/source/libs/parser/src/parAuthenticator.c @@ -39,7 +39,7 @@ static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, AUTH_TYPE type) { if (NULL != pCxt->pMetaCache) { code = getUserAuthFromCache(pCxt->pMetaCache, pParseCxt->pUser, dbFname, type, &pass); } else { - SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter, + SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter, .requestId = pParseCxt->requestId, .requestObjRefId = pParseCxt->requestRid, .mgmtEps = pParseCxt->mgmtEpSet}; @@ -88,6 +88,14 @@ static int32_t authDelete(SAuthCxt* pCxt, SDeleteStmt* pDelete) { return checkAuth(pCxt, ((SRealTableNode*)pDelete->pFromTable)->table.dbName, AUTH_TYPE_WRITE); } +static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) { + int32_t code = checkAuth(pCxt, ((SRealTableNode*)pInsert->pTable)->table.dbName, AUTH_TYPE_WRITE); + if (TSDB_CODE_SUCCESS == code) { + code = authQuery(pCxt, pInsert->pQuery); + } + return code; +} + static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) { switch (nodeType(pStmt)) { case QUERY_NODE_SET_OPERATOR: @@ -98,6 +106,8 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) { return authDropUser(pCxt, (SDropUserStmt*)pStmt); case QUERY_NODE_DELETE_STMT: return authDelete(pCxt, (SDeleteStmt*)pStmt); + case QUERY_NODE_INSERT_STMT: + return authInsert(pCxt, (SInsertStmt*)pStmt); default: break; } diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index dcdf73630f5325a198c8cf3e2ee6d0c9d3f9d0a4..6c670b3f01502104ca5d347e04bb1456b74aad13 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -300,6 +300,14 @@ static int32_t calcConstDelete(SCalcConstContext* pCxt, SDeleteStmt* pDelete) { return code; } +static int32_t calcConstInsert(SCalcConstContext* pCxt, SInsertStmt* pInsert) { + int32_t code = calcConstFromTable(pCxt, pInsert->pTable); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstQuery(pCxt, pInsert->pQuery, false); + } + return code; +} + static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pStmt)) { @@ -320,6 +328,9 @@ static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subque case QUERY_NODE_DELETE_STMT: code = calcConstDelete(pCxt, (SDeleteStmt*)pStmt); break; + case QUERY_NODE_INSERT_STMT: + code = calcConstInsert(pCxt, (SInsertStmt*)pStmt); + break; default: break; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index a286531588fa98beded99f880ab4d1731cecd7c0..a5cf755a74107f586f4d34c9b586de2208c6fb94 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -110,7 +110,7 @@ typedef struct SMemParam { static int32_t skipInsertInto(char** pSql, SMsgBuf* pMsg) { SToken sToken; NEXT_TOKEN(*pSql, sToken); - if (TK_INSERT != sToken.type) { + if (TK_INSERT != sToken.type && TK_IMPORT != sToken.type) { return buildSyntaxErrMsg(pMsg, "keyword INSERT is expected", sToken.z); } NEXT_TOKEN(*pSql, sToken); diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 6736fea6356021a0b5826ec5c73b3ef9998fa678..38fe8ffc242c4304b771e23651e1dbdacc37cac8 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -91,6 +91,7 @@ static SKeyword keywordTable[] = { {"FILL", TK_FILL}, {"FIRST", TK_FIRST}, {"FLOAT", TK_FLOAT}, + {"FLUSH", TK_FLUSH}, {"FROM", TK_FROM}, {"FSYNC", TK_FSYNC}, {"FUNCTION", TK_FUNCTION}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 4bccb75dcffa44416dc7f08c83058f588b382020..0975fe7309189512503285930f7475c432c3e48c 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2839,6 +2839,91 @@ static int32_t translateDelete(STranslateContext* pCxt, SDeleteStmt* pDelete) { return code; } +static int32_t translateInsertCols(STranslateContext* pCxt, SInsertStmt* pInsert) { + if (NULL == pInsert->pCols) { + return createAllColumns(pCxt, false, &pInsert->pCols); + } + return translateExprList(pCxt, pInsert->pCols); +} + +static int32_t translateInsertQuery(STranslateContext* pCxt, SInsertStmt* pInsert) { + int32_t code = resetTranslateNamespace(pCxt); + if (TSDB_CODE_SUCCESS == code) { + code = translateQuery(pCxt, pInsert->pQuery); + } + return code; +} + +static int32_t addOrderByPrimaryKeyToQueryImpl(STranslateContext* pCxt, SNode* pPrimaryKeyExpr, + SNodeList** pOrderByList) { + SOrderByExprNode* pOrderByExpr = (SOrderByExprNode*)nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR); + if (NULL == pOrderByExpr) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pOrderByExpr->nullOrder = NULL_ORDER_FIRST; + pOrderByExpr->order = ORDER_ASC; + pOrderByExpr->pExpr = nodesCloneNode(pPrimaryKeyExpr); + if (NULL == pOrderByExpr->pExpr) { + nodesDestroyNode((SNode*)pOrderByExpr); + return TSDB_CODE_OUT_OF_MEMORY; + } + ((SExprNode*)pOrderByExpr->pExpr)->orderAlias = true; + NODES_DESTORY_LIST(*pOrderByList); + return nodesListMakeStrictAppend(pOrderByList, (SNode*)pOrderByExpr); +} + +static int32_t addOrderByPrimaryKeyToQuery(STranslateContext* pCxt, SNode* pPrimaryKeyExpr, SNode* pStmt) { + if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { + return addOrderByPrimaryKeyToQueryImpl(pCxt, pPrimaryKeyExpr, &((SSelectStmt*)pStmt)->pOrderByList); + } + return addOrderByPrimaryKeyToQueryImpl(pCxt, pPrimaryKeyExpr, &((SSetOperator*)pStmt)->pOrderByList); +} + +static int32_t translateInsertProject(STranslateContext* pCxt, SInsertStmt* pInsert) { + SNodeList* pProjects = getProjectList(pInsert->pQuery); + if (LIST_LENGTH(pInsert->pCols) != LIST_LENGTH(pProjects)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMNS_NUM, "Illegal number of columns"); + } + + SNode* pPrimaryKeyExpr = NULL; + SNode* pBoundCol = NULL; + SNode* pProj = NULL; + FORBOTH(pBoundCol, pInsert->pCols, pProj, pProjects) { + SColumnNode* pCol = (SColumnNode*)pBoundCol; + SExprNode* pExpr = (SExprNode*)pProj; + if (!dataTypeEqual(&pCol->node.resType, &pExpr->resType)) { + SNode* pFunc = NULL; + int32_t code = createCastFunc(pCxt, pProj, pCol->node.resType, &pFunc); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + REPLACE_LIST2_NODE(pFunc); + pExpr = (SExprNode*)pFunc; + } + snprintf(pExpr->aliasName, sizeof(pExpr->aliasName), "%s", pCol->colName); + if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId) { + pPrimaryKeyExpr = pProj; + } + } + + return addOrderByPrimaryKeyToQuery(pCxt, pPrimaryKeyExpr, pInsert->pQuery); +} + +static int32_t translateInsert(STranslateContext* pCxt, SInsertStmt* pInsert) { + pCxt->pCurrStmt = (SNode*)pInsert; + int32_t code = translateFrom(pCxt, pInsert->pTable); + if (TSDB_CODE_SUCCESS == code) { + code = translateInsertCols(pCxt, pInsert); + } + if (TSDB_CODE_SUCCESS == code) { + code = translateInsertQuery(pCxt, pInsert); + } + if (TSDB_CODE_SUCCESS == code) { + code = translateInsertProject(pCxt, pInsert); + } + return code; +} + static int64_t getUnitPerMinute(uint8_t precision) { switch (precision) { case TSDB_TIME_PRECISION_MILLI: @@ -4608,6 +4693,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_DELETE_STMT: code = translateDelete(pCxt, (SDeleteStmt*)pNode); break; + case QUERY_NODE_INSERT_STMT: + code = translateInsert(pCxt, (SInsertStmt*)pNode); + break; case QUERY_NODE_CREATE_DATABASE_STMT: code = translateCreateDatabase(pCxt, (SCreateDatabaseStmt*)pNode); break; @@ -6111,6 +6199,67 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) { return code; } +static int32_t serializeFlushVgroup(SVgroupInfo* pVg, SArray* pBufArray) { + int32_t len = sizeof(SMsgHead); + void* buf = taosMemoryMalloc(len); + if (NULL == buf) { + return TSDB_CODE_OUT_OF_MEMORY; + } + ((SMsgHead*)buf)->vgId = htonl(pVg->vgId); + ((SMsgHead*)buf)->contLen = htonl(len); + + SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); + if (NULL == pVgData) { + taosMemoryFree(buf); + return TSDB_CODE_OUT_OF_MEMORY; + } + pVgData->vg = *pVg; + pVgData->pData = buf; + pVgData->size = len; + taosArrayPush(pBufArray, &pVgData); + + return TSDB_CODE_SUCCESS; +} + +static int32_t serializeFlushDb(SArray* pVgs, SArray** pOutput) { + int32_t numOfVgs = taosArrayGetSize(pVgs); + + SArray* pBufArray = taosArrayInit(numOfVgs, sizeof(void*)); + if (NULL == pBufArray) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + for (int32_t i = 0; i < numOfVgs; ++i) { + int32_t code = serializeFlushVgroup((SVgroupInfo*)taosArrayGet(pVgs, i), pBufArray); + if (TSDB_CODE_SUCCESS != code) { + taosArrayDestroy(pBufArray); + return code; + } + } + + *pOutput = pBufArray; + return TSDB_CODE_SUCCESS; +} + +static int32_t rewriteFlushDatabase(STranslateContext* pCxt, SQuery* pQuery) { + SFlushDatabaseStmt* pStmt = (SFlushDatabaseStmt*)pQuery->pRoot; + + SArray* pBufArray = NULL; + SArray* pVgs = NULL; + int32_t code = getDBVgInfo(pCxt, pStmt->dbName, &pVgs); + if (TSDB_CODE_SUCCESS == code) { + code = serializeFlushDb(pVgs, &pBufArray); + } + if (TSDB_CODE_SUCCESS == code) { + code = rewriteToVnodeModifyOpStmt(pQuery, pBufArray); + } + if (TSDB_CODE_SUCCESS != code) { + taosArrayDestroy(pBufArray); + } + taosArrayDestroy(pVgs); + return code; +} + static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pQuery->pRoot)) { @@ -6159,6 +6308,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_ALTER_TABLE_STMT: code = rewriteAlterTable(pCxt, pQuery); break; + case QUERY_NODE_FLUSH_DATABASE_STMT: + code = rewriteFlushDatabase(pCxt, pQuery); + break; default: break; } @@ -6224,6 +6376,10 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; pQuery->msgType = TDMT_VND_DELETE; break; + case QUERY_NODE_INSERT_STMT: + pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; + pQuery->msgType = TDMT_VND_SUBMIT; + break; case QUERY_NODE_VNODE_MODIF_STMT: pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; pQuery->msgType = toMsgType(((SVnodeModifOpStmt*)pQuery->pRoot)->sqlNodeType); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 27a91024224027390afe437f22c0bf8f3890e23f..7a23338035b12fc6f325b9b60fd9a6226fab0a76 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -376,8 +376,6 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi char* jsonKey = item->string; if (!isValidateTag(jsonKey)) { - fprintf(stdout, "%s(%d) %s %08" PRId64 "\n", __FILE__, __LINE__, __func__, taosGetSelfPthreadId()); - fflush(stdout); retCode = buildSyntaxErrMsg(pMsgBuf, "json key not validate", jsonKey); goto end; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 538404798d699b98ab5e91e5aa725fac147dc4c1..4f8ea002719df5c37ee3ba53a4622742f3ad1dbb 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -19,19 +19,28 @@ #include "parInt.h" #include "parToken.h" -bool qIsInsertSql(const char* pStr, size_t length) { +bool qIsInsertValuesSql(const char* pStr, size_t length) { if (NULL == pStr) { return false; } + const char* pSql = pStr; + int32_t index = 0; + SToken t = tStrGetToken((char*)pStr, &index, false); + if (TK_INSERT != t.type && TK_IMPORT != t.type) { + return false; + } do { - SToken t0 = tStrGetToken((char*)pStr, &index, false); - if (t0.type != TK_NK_LP) { - return t0.type == TK_INSERT || t0.type == TK_IMPORT; + pStr += index; + index = 0; + t = tStrGetToken((char*)pStr, &index, false); + if (TK_USING == t.type || TK_VALUES == t.type) { + return true; } - } while (1); + } while (pStr - pSql < length); + return false; } static int32_t analyseSemantic(SParseContext* pCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) { @@ -148,7 +157,7 @@ static void rewriteExprAlias(SNode* pRoot) { int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery) { int32_t code = TSDB_CODE_SUCCESS; - if (qIsInsertSql(pCxt->pSql, pCxt->sqlLen)) { + if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) { code = parseInsertSql(pCxt, pQuery, NULL); } else { code = parseSqlIntoAst(pCxt, pQuery); @@ -160,7 +169,7 @@ int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery) { int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) { SParseMetaCache metaCache = {0}; int32_t code = TSDB_CODE_SUCCESS; - if (qIsInsertSql(pCxt->pSql, pCxt->sqlLen)) { + if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) { code = parseInsertSyntax(pCxt, pQuery, &metaCache); } else { code = parseSqlSyntax(pCxt, pQuery, &metaCache); diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index fe6e36bf5b5eaa203abf2fa09c501e841b1d68b5..1bc204b9d9a9f2cc45d4ec3d61e5ca30e943f4ca 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -104,26 +104,26 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 375 +#define YYNOCODE 376 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SDataType yy34; - EJoinType yy162; - EOrder yy188; - SNode* yy212; - SAlterOption yy245; - EOperatorType yy290; - EFillMode yy294; - SToken yy329; - SNodeList* yy424; - ENullOrder yy607; - int64_t yy609; - int32_t yy610; - int8_t yy653; - bool yy737; + EJoinType yy52; + bool yy89; + SDataType yy224; + int32_t yy228; + SNode* yy248; + SAlterOption yy301; + ENullOrder yy345; + SToken yy401; + EOrder yy482; + int64_t yy525; + SNodeList* yy552; + EFillMode yy582; + int8_t yy695; + EOperatorType yy716; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -139,17 +139,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 653 -#define YYNRULE 483 -#define YYNTOKEN 252 -#define YY_MAX_SHIFT 652 -#define YY_MIN_SHIFTREDUCE 954 -#define YY_MAX_SHIFTREDUCE 1436 -#define YY_ERROR_ACTION 1437 -#define YY_ACCEPT_ACTION 1438 -#define YY_NO_ACTION 1439 -#define YY_MIN_REDUCE 1440 -#define YY_MAX_REDUCE 1922 +#define YYNSTATE 661 +#define YYNRULE 485 +#define YYNTOKEN 253 +#define YY_MAX_SHIFT 660 +#define YY_MIN_SHIFTREDUCE 962 +#define YY_MAX_SHIFTREDUCE 1446 +#define YY_ERROR_ACTION 1447 +#define YY_ACCEPT_ACTION 1448 +#define YY_NO_ACTION 1449 +#define YY_MIN_REDUCE 1450 +#define YY_MAX_REDUCE 1934 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -216,703 +216,658 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2609) +#define YY_ACTTAB_COUNT (2363) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 422, 1563, 423, 1475, 1900, 430, 1438, 423, 1475, 69, - /* 10 */ 69, 379, 40, 38, 1744, 141, 1775, 1899, 541, 1531, - /* 20 */ 333, 1897, 1238, 115, 534, 1741, 41, 39, 37, 36, - /* 30 */ 35, 1570, 1569, 1313, 101, 1236, 1565, 100, 99, 98, - /* 40 */ 97, 96, 95, 94, 93, 92, 120, 1741, 297, 544, - /* 50 */ 1745, 1737, 1743, 322, 338, 1757, 1308, 1619, 1621, 14, - /* 60 */ 544, 1741, 533, 562, 439, 1244, 343, 546, 1263, 40, - /* 70 */ 38, 1376, 541, 1737, 1743, 1552, 1900, 333, 140, 1238, - /* 80 */ 1452, 167, 1, 1775, 544, 562, 118, 1737, 1743, 158, - /* 90 */ 1313, 569, 1236, 1897, 373, 464, 1727, 1900, 568, 562, - /* 100 */ 120, 245, 1842, 540, 649, 539, 67, 1900, 1900, 66, - /* 110 */ 1898, 44, 546, 1308, 1897, 1056, 14, 463, 1315, 1316, - /* 120 */ 157, 159, 1244, 1788, 1897, 1897, 1263, 87, 1758, 571, - /* 130 */ 1760, 1761, 567, 439, 562, 1900, 60, 1834, 1380, 2, - /* 140 */ 118, 300, 1830, 541, 1262, 1058, 43, 1262, 157, 151, - /* 150 */ 652, 210, 1897, 1900, 543, 153, 1842, 1843, 1004, 1847, - /* 160 */ 1003, 649, 1613, 1239, 262, 1237, 159, 31, 255, 987, - /* 170 */ 1897, 120, 535, 458, 320, 1315, 1316, 60, 149, 73, - /* 180 */ 604, 203, 138, 642, 638, 634, 630, 260, 1005, 1242, - /* 190 */ 1243, 1576, 1291, 1292, 1294, 1295, 1296, 1297, 1298, 564, - /* 200 */ 560, 1306, 1307, 1309, 1310, 1311, 1312, 1314, 1317, 991, - /* 210 */ 992, 118, 85, 1323, 421, 225, 372, 425, 371, 1262, - /* 220 */ 1239, 160, 1237, 412, 1136, 1137, 154, 1842, 1843, 1261, - /* 230 */ 1847, 34, 33, 310, 505, 41, 39, 37, 36, 35, - /* 240 */ 71, 299, 319, 541, 507, 1671, 1242, 1243, 514, 1291, - /* 250 */ 1292, 1294, 1295, 1296, 1297, 1298, 564, 560, 1306, 1307, - /* 260 */ 1309, 1310, 1311, 1312, 1314, 1317, 40, 38, 1440, 171, - /* 270 */ 170, 120, 1626, 1674, 333, 160, 1238, 216, 217, 321, - /* 280 */ 212, 311, 301, 309, 308, 160, 462, 1313, 1624, 1236, - /* 290 */ 464, 530, 110, 109, 108, 107, 106, 105, 104, 103, - /* 300 */ 102, 1211, 1463, 205, 517, 429, 1276, 517, 425, 517, - /* 310 */ 1308, 118, 463, 14, 1335, 111, 160, 1293, 111, 1244, - /* 320 */ 162, 61, 460, 40, 38, 465, 155, 1842, 1843, 60, - /* 330 */ 1847, 333, 1574, 1238, 1502, 1574, 2, 1574, 299, 427, - /* 340 */ 1462, 507, 1244, 1727, 1313, 1260, 1236, 1094, 593, 592, - /* 350 */ 591, 1098, 590, 1100, 1101, 589, 1103, 586, 649, 1109, - /* 360 */ 583, 1111, 1112, 580, 577, 1550, 517, 1308, 1336, 536, - /* 370 */ 531, 600, 1315, 1316, 1617, 1461, 1244, 377, 37, 36, - /* 380 */ 35, 1727, 34, 33, 1620, 1621, 41, 39, 37, 36, - /* 390 */ 35, 1341, 1293, 8, 1574, 626, 625, 624, 341, 60, - /* 400 */ 623, 622, 621, 121, 616, 615, 614, 613, 612, 611, - /* 410 */ 610, 609, 131, 605, 596, 649, 1727, 1239, 1849, 1237, - /* 420 */ 34, 33, 1397, 604, 41, 39, 37, 36, 35, 1315, - /* 430 */ 1316, 1551, 30, 331, 1330, 1331, 1332, 1333, 1334, 1338, - /* 440 */ 1339, 1340, 1846, 1242, 1243, 607, 1291, 1292, 1294, 1295, - /* 450 */ 1296, 1297, 1298, 564, 560, 1306, 1307, 1309, 1310, 1311, - /* 460 */ 1312, 1314, 1317, 527, 1395, 1396, 1398, 1399, 160, 517, - /* 470 */ 474, 473, 471, 470, 1239, 472, 1237, 1559, 116, 469, - /* 480 */ 378, 84, 468, 467, 466, 34, 33, 11, 10, 41, - /* 490 */ 39, 37, 36, 35, 117, 1407, 1004, 1574, 1003, 209, - /* 500 */ 1242, 1243, 1566, 1291, 1292, 1294, 1295, 1296, 1297, 1298, - /* 510 */ 564, 560, 1306, 1307, 1309, 1310, 1311, 1312, 1314, 1317, - /* 520 */ 40, 38, 1318, 336, 479, 602, 1005, 72, 333, 1433, - /* 530 */ 1238, 138, 160, 1505, 504, 189, 301, 1561, 160, 489, - /* 540 */ 1576, 1313, 339, 1236, 129, 128, 599, 598, 597, 144, - /* 550 */ 138, 517, 497, 202, 456, 452, 448, 444, 188, 1576, - /* 560 */ 77, 517, 382, 517, 1308, 620, 618, 482, 1335, 1349, - /* 570 */ 490, 476, 397, 1244, 398, 1900, 201, 40, 38, 1574, - /* 580 */ 1626, 1567, 517, 70, 58, 333, 186, 1238, 157, 1574, - /* 590 */ 9, 1574, 1897, 438, 474, 473, 1625, 364, 1313, 472, - /* 600 */ 1236, 55, 116, 469, 54, 517, 468, 467, 466, 7, - /* 610 */ 1574, 1900, 649, 1670, 517, 294, 1571, 1432, 517, 366, - /* 620 */ 362, 1308, 1336, 1373, 157, 1703, 1315, 1316, 1897, 498, - /* 630 */ 1244, 34, 33, 1574, 1460, 41, 39, 37, 36, 35, - /* 640 */ 991, 992, 1574, 1626, 1459, 1341, 1574, 9, 185, 178, - /* 650 */ 337, 183, 1849, 1264, 517, 435, 34, 33, 1458, 1624, - /* 660 */ 41, 39, 37, 36, 35, 502, 23, 1664, 517, 649, - /* 670 */ 1669, 1239, 294, 1237, 176, 1727, 1845, 215, 169, 515, - /* 680 */ 1457, 550, 1574, 1315, 1316, 1727, 30, 331, 1330, 1331, - /* 690 */ 1332, 1333, 1334, 1338, 1339, 1340, 1574, 1242, 1243, 1727, - /* 700 */ 1291, 1292, 1294, 1295, 1296, 1297, 1298, 564, 560, 1306, - /* 710 */ 1307, 1309, 1310, 1311, 1312, 1314, 1317, 1441, 34, 33, - /* 720 */ 488, 1727, 41, 39, 37, 36, 35, 1849, 1239, 601, - /* 730 */ 1237, 1387, 1617, 486, 267, 484, 1456, 1604, 101, 1219, - /* 740 */ 1220, 100, 99, 98, 97, 96, 95, 94, 93, 92, - /* 750 */ 608, 1844, 1546, 541, 1242, 1243, 1715, 1291, 1292, 1294, - /* 760 */ 1295, 1296, 1297, 1298, 564, 560, 1306, 1307, 1309, 1310, - /* 770 */ 1311, 1312, 1314, 1317, 40, 38, 296, 1727, 1260, 553, - /* 780 */ 517, 120, 333, 247, 1238, 405, 1453, 1455, 417, 517, - /* 790 */ 1369, 516, 602, 1276, 1454, 1313, 1265, 1236, 1557, 505, - /* 800 */ 256, 1337, 546, 352, 1451, 390, 1262, 418, 1574, 392, - /* 810 */ 1672, 129, 128, 599, 598, 597, 1247, 1574, 1308, 548, - /* 820 */ 517, 118, 1854, 1369, 1342, 45, 4, 1244, 1727, 52, - /* 830 */ 501, 340, 1450, 138, 1449, 1727, 245, 1842, 540, 383, - /* 840 */ 539, 1372, 1577, 1900, 2, 1727, 34, 33, 1574, 528, - /* 850 */ 41, 39, 37, 36, 35, 194, 157, 206, 192, 1448, - /* 860 */ 1897, 1238, 1447, 34, 33, 28, 649, 41, 39, 37, - /* 870 */ 36, 35, 1446, 1727, 1236, 1727, 563, 1246, 551, 416, - /* 880 */ 1315, 1316, 411, 410, 409, 408, 407, 404, 403, 402, - /* 890 */ 401, 400, 396, 395, 394, 393, 387, 386, 385, 384, - /* 900 */ 1727, 381, 380, 1727, 1244, 27, 1445, 11, 10, 139, - /* 910 */ 619, 34, 33, 1727, 273, 41, 39, 37, 36, 35, - /* 920 */ 1549, 196, 1435, 1436, 195, 1239, 227, 1237, 271, 57, - /* 930 */ 1444, 1492, 56, 1443, 198, 200, 42, 197, 199, 558, - /* 940 */ 1532, 1747, 214, 649, 1757, 595, 1250, 1727, 172, 250, - /* 950 */ 367, 1242, 1243, 475, 1291, 1292, 1294, 1295, 1296, 1297, - /* 960 */ 1298, 564, 560, 1306, 1307, 1309, 1310, 1311, 1312, 1314, - /* 970 */ 1317, 1727, 1775, 60, 1727, 123, 1187, 1749, 554, 1293, - /* 980 */ 569, 491, 218, 29, 1487, 1727, 1485, 568, 137, 34, - /* 990 */ 33, 457, 126, 41, 39, 37, 36, 35, 127, 50, - /* 1000 */ 231, 546, 1239, 42, 1237, 42, 477, 1249, 480, 42, - /* 1010 */ 239, 86, 1788, 575, 602, 510, 87, 1758, 571, 1760, - /* 1020 */ 1761, 567, 1757, 562, 1481, 1776, 1834, 342, 1242, 1243, - /* 1030 */ 300, 1830, 224, 129, 128, 599, 598, 597, 1087, 1394, - /* 1040 */ 234, 126, 1900, 1343, 127, 1299, 64, 63, 376, 266, - /* 1050 */ 1775, 166, 112, 1115, 83, 157, 1028, 370, 545, 1897, - /* 1060 */ 1476, 1614, 126, 1727, 80, 568, 1864, 542, 244, 1327, - /* 1070 */ 295, 249, 644, 360, 252, 358, 354, 350, 163, 345, - /* 1080 */ 254, 1119, 3, 1757, 1126, 5, 1029, 1260, 347, 344, - /* 1090 */ 1788, 351, 1124, 306, 88, 1758, 571, 1760, 1761, 567, - /* 1100 */ 1757, 562, 130, 1056, 1834, 307, 1203, 263, 326, 1830, - /* 1110 */ 152, 1775, 160, 399, 1666, 168, 406, 413, 414, 545, - /* 1120 */ 415, 419, 156, 1266, 1727, 420, 568, 428, 1775, 1269, - /* 1130 */ 1860, 175, 431, 177, 1268, 432, 569, 433, 1270, 180, - /* 1140 */ 434, 1727, 436, 568, 182, 1267, 184, 437, 68, 440, - /* 1150 */ 187, 1788, 461, 1757, 459, 88, 1758, 571, 1760, 1761, - /* 1160 */ 567, 1564, 562, 492, 264, 1834, 124, 191, 1788, 326, - /* 1170 */ 1830, 152, 88, 1758, 571, 1760, 1761, 567, 298, 562, - /* 1180 */ 91, 1775, 1834, 1560, 193, 132, 326, 1830, 1913, 569, - /* 1190 */ 133, 1861, 1562, 1558, 1727, 134, 568, 1868, 135, 324, - /* 1200 */ 323, 1708, 204, 207, 493, 499, 496, 503, 1757, 1252, - /* 1210 */ 525, 211, 506, 511, 1707, 316, 512, 220, 1676, 508, - /* 1220 */ 1313, 1788, 1245, 318, 222, 88, 1758, 571, 1760, 1761, - /* 1230 */ 567, 125, 562, 513, 76, 1834, 1775, 265, 1575, 326, - /* 1240 */ 1830, 1913, 1265, 1308, 569, 1865, 521, 529, 1875, 1727, - /* 1250 */ 1891, 568, 1244, 1874, 1856, 229, 538, 523, 233, 524, - /* 1260 */ 325, 532, 6, 522, 520, 519, 1369, 119, 1264, 552, - /* 1270 */ 555, 19, 1757, 146, 238, 243, 1788, 1850, 327, 78, - /* 1280 */ 88, 1758, 571, 1760, 1761, 567, 1757, 562, 240, 242, - /* 1290 */ 1834, 526, 241, 248, 326, 1830, 1913, 1896, 1757, 573, - /* 1300 */ 1775, 1618, 268, 549, 645, 1853, 1547, 251, 569, 556, - /* 1310 */ 1916, 253, 259, 1727, 1775, 568, 646, 1815, 648, 51, - /* 1320 */ 145, 270, 569, 272, 1721, 281, 1775, 1727, 291, 568, - /* 1330 */ 290, 1720, 62, 1719, 569, 346, 1716, 348, 349, 1727, - /* 1340 */ 1788, 568, 1231, 546, 284, 1758, 571, 1760, 1761, 567, - /* 1350 */ 1253, 562, 1248, 1232, 1788, 546, 164, 353, 280, 1758, - /* 1360 */ 571, 1760, 1761, 567, 1714, 562, 1788, 1757, 357, 355, - /* 1370 */ 280, 1758, 571, 1760, 1761, 567, 1256, 562, 356, 1713, - /* 1380 */ 1712, 359, 537, 361, 1900, 1711, 1710, 560, 1306, 1307, - /* 1390 */ 1309, 1310, 1311, 1312, 363, 1775, 1900, 159, 365, 1693, - /* 1400 */ 368, 1897, 165, 569, 369, 1206, 1205, 1687, 1727, 157, - /* 1410 */ 568, 1686, 374, 1897, 375, 1685, 1684, 1175, 1659, 1658, - /* 1420 */ 1657, 65, 1656, 1655, 1757, 1654, 1653, 1652, 388, 389, - /* 1430 */ 1651, 391, 1650, 1649, 1648, 1788, 1647, 1646, 1645, 89, - /* 1440 */ 1758, 571, 1760, 1761, 567, 1757, 562, 1644, 1643, 1834, - /* 1450 */ 1642, 1641, 1775, 1833, 1830, 1640, 1639, 1638, 1637, 122, - /* 1460 */ 569, 1636, 1635, 1634, 1633, 1727, 1632, 568, 1631, 1630, - /* 1470 */ 1629, 1177, 1628, 1775, 150, 424, 1471, 173, 113, 994, - /* 1480 */ 174, 566, 1627, 1504, 1472, 993, 1727, 426, 568, 1701, - /* 1490 */ 1695, 114, 1788, 179, 181, 1682, 89, 1758, 571, 1760, - /* 1500 */ 1761, 567, 1683, 562, 1668, 1757, 1834, 1553, 1503, 1501, - /* 1510 */ 557, 1830, 441, 1788, 443, 1499, 1497, 288, 1758, 571, - /* 1520 */ 1760, 1761, 567, 565, 562, 559, 1806, 1022, 442, 445, - /* 1530 */ 447, 449, 446, 1775, 450, 1495, 451, 455, 453, 454, - /* 1540 */ 1484, 569, 1483, 1468, 1555, 1130, 1727, 1129, 568, 190, - /* 1550 */ 49, 1554, 1055, 1054, 1053, 1052, 617, 619, 1049, 1048, - /* 1560 */ 1493, 1757, 1047, 312, 1488, 1486, 481, 313, 314, 1467, - /* 1570 */ 478, 483, 1466, 1788, 485, 1465, 487, 142, 1758, 571, - /* 1580 */ 1760, 1761, 567, 1757, 562, 1700, 90, 1213, 1694, 1775, - /* 1590 */ 136, 1681, 53, 494, 495, 1679, 315, 569, 1680, 1678, - /* 1600 */ 208, 1677, 1727, 1675, 568, 213, 1223, 1667, 15, 221, - /* 1610 */ 219, 1775, 74, 226, 75, 16, 317, 42, 1254, 569, - /* 1620 */ 1409, 547, 1914, 48, 1727, 500, 568, 509, 17, 1788, - /* 1630 */ 80, 24, 223, 89, 1758, 571, 1760, 1761, 567, 228, - /* 1640 */ 562, 230, 1391, 1834, 1757, 232, 237, 236, 1831, 13, - /* 1650 */ 143, 1788, 1747, 26, 246, 289, 1758, 571, 1760, 1761, - /* 1660 */ 567, 235, 562, 25, 1757, 1393, 1386, 1366, 79, 47, - /* 1670 */ 1365, 1746, 1775, 147, 18, 1426, 1415, 518, 1421, 10, - /* 1680 */ 569, 1420, 328, 1425, 1424, 1727, 329, 568, 1328, 1284, - /* 1690 */ 572, 1791, 1775, 20, 1303, 561, 32, 46, 1301, 1300, - /* 1700 */ 569, 148, 161, 12, 21, 1727, 22, 568, 574, 335, - /* 1710 */ 578, 1116, 1788, 1113, 576, 579, 289, 1758, 571, 1760, - /* 1720 */ 1761, 567, 1110, 562, 570, 581, 584, 582, 587, 1757, - /* 1730 */ 1093, 594, 1788, 1125, 1121, 1104, 142, 1758, 571, 1760, - /* 1740 */ 1761, 567, 585, 562, 1102, 588, 1108, 1107, 1757, 1020, - /* 1750 */ 81, 82, 59, 257, 603, 1044, 606, 1775, 258, 1106, - /* 1760 */ 1105, 1062, 330, 1042, 1041, 569, 1040, 1039, 1038, 1037, - /* 1770 */ 1727, 1036, 568, 1035, 1059, 1057, 1775, 1032, 1031, 1030, - /* 1780 */ 1027, 1915, 1500, 1026, 566, 1025, 627, 1498, 628, 1727, - /* 1790 */ 631, 568, 629, 632, 1496, 633, 635, 1788, 637, 636, - /* 1800 */ 1494, 289, 1758, 571, 1760, 1761, 567, 639, 562, 640, - /* 1810 */ 641, 1482, 643, 984, 1464, 261, 1788, 1757, 647, 650, - /* 1820 */ 288, 1758, 571, 1760, 1761, 567, 1240, 562, 269, 1807, - /* 1830 */ 651, 1439, 1439, 1757, 1439, 1439, 1439, 1439, 1439, 1439, - /* 1840 */ 1439, 1439, 1439, 1439, 1439, 1775, 1439, 1439, 1439, 1439, - /* 1850 */ 332, 1439, 1439, 569, 1439, 1439, 1439, 1439, 1727, 1439, - /* 1860 */ 568, 1775, 1439, 1439, 1439, 1439, 334, 1439, 1439, 569, - /* 1870 */ 1439, 1439, 1439, 1439, 1727, 1757, 568, 1439, 1439, 1439, - /* 1880 */ 1439, 1439, 1439, 1439, 1439, 1788, 1439, 1439, 1439, 289, - /* 1890 */ 1758, 571, 1760, 1761, 567, 1439, 562, 1439, 1439, 1757, - /* 1900 */ 1439, 1788, 1439, 1775, 1439, 289, 1758, 571, 1760, 1761, - /* 1910 */ 567, 569, 562, 1439, 1439, 1439, 1727, 1439, 568, 1439, - /* 1920 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1775, 1439, 1439, - /* 1930 */ 1439, 1439, 1439, 1439, 1439, 569, 1439, 1439, 1439, 1439, - /* 1940 */ 1727, 1757, 568, 1788, 1439, 1439, 1439, 274, 1758, 571, - /* 1950 */ 1760, 1761, 567, 1439, 562, 1439, 1439, 1439, 1439, 1439, - /* 1960 */ 1439, 1757, 1439, 1439, 1439, 1439, 1439, 1788, 1439, 1775, - /* 1970 */ 1439, 275, 1758, 571, 1760, 1761, 567, 569, 562, 1439, - /* 1980 */ 1439, 1439, 1727, 1439, 568, 1439, 1439, 1439, 1439, 1775, - /* 1990 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 569, 1439, 1439, - /* 2000 */ 1439, 1439, 1727, 1439, 568, 1439, 1439, 1439, 1439, 1788, - /* 2010 */ 1439, 1439, 1439, 276, 1758, 571, 1760, 1761, 567, 1439, - /* 2020 */ 562, 1757, 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1788, - /* 2030 */ 1439, 1439, 1439, 283, 1758, 571, 1760, 1761, 567, 1439, - /* 2040 */ 562, 1439, 1439, 1439, 1439, 1757, 1439, 1439, 1439, 1775, - /* 2050 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 569, 1439, 1439, - /* 2060 */ 1439, 1439, 1727, 1439, 568, 1439, 1439, 1439, 1439, 1439, - /* 2070 */ 1439, 1439, 1439, 1775, 1439, 1439, 1439, 1439, 1439, 1439, - /* 2080 */ 1439, 569, 1439, 1439, 1439, 1439, 1727, 1439, 568, 1788, - /* 2090 */ 1439, 1439, 1439, 285, 1758, 571, 1760, 1761, 567, 1439, - /* 2100 */ 562, 1757, 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1439, - /* 2110 */ 1439, 1439, 1439, 1788, 1439, 1439, 1439, 277, 1758, 571, - /* 2120 */ 1760, 1761, 567, 1439, 562, 1757, 1439, 1439, 1439, 1775, - /* 2130 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 569, 1439, 1439, - /* 2140 */ 1439, 1439, 1727, 1439, 568, 1439, 1439, 1439, 1439, 1439, - /* 2150 */ 1439, 1439, 1439, 1775, 1439, 1439, 1439, 1439, 1439, 1439, - /* 2160 */ 1439, 569, 1439, 1439, 1439, 1439, 1727, 1757, 568, 1788, - /* 2170 */ 1439, 1439, 1439, 286, 1758, 571, 1760, 1761, 567, 1439, - /* 2180 */ 562, 1439, 1439, 1757, 1439, 1439, 1439, 1439, 1439, 1439, - /* 2190 */ 1439, 1439, 1439, 1788, 1439, 1775, 1439, 278, 1758, 571, - /* 2200 */ 1760, 1761, 567, 569, 562, 1439, 1439, 1439, 1727, 1439, - /* 2210 */ 568, 1775, 1439, 1439, 1439, 1439, 1439, 1439, 1439, 569, - /* 2220 */ 1439, 1439, 1439, 1439, 1727, 1757, 568, 1439, 1439, 1439, - /* 2230 */ 1439, 1439, 1439, 1439, 1439, 1788, 1439, 1439, 1439, 287, - /* 2240 */ 1758, 571, 1760, 1761, 567, 1757, 562, 1439, 1439, 1439, - /* 2250 */ 1439, 1788, 1439, 1775, 1439, 279, 1758, 571, 1760, 1761, - /* 2260 */ 567, 569, 562, 1439, 1439, 1439, 1727, 1439, 568, 1439, - /* 2270 */ 1439, 1439, 1439, 1775, 1439, 1439, 1439, 1439, 1439, 1439, - /* 2280 */ 1439, 569, 1439, 1439, 1439, 1439, 1727, 1439, 568, 1439, - /* 2290 */ 1439, 1439, 1439, 1788, 1439, 1439, 1439, 292, 1758, 571, - /* 2300 */ 1760, 1761, 567, 1439, 562, 1757, 1439, 1439, 1439, 1439, - /* 2310 */ 1439, 1439, 1439, 1788, 1439, 1439, 1439, 293, 1758, 571, - /* 2320 */ 1760, 1761, 567, 1439, 562, 1439, 1439, 1439, 1439, 1757, - /* 2330 */ 1439, 1439, 1439, 1775, 1439, 1439, 1439, 1439, 1439, 1439, - /* 2340 */ 1439, 569, 1439, 1439, 1439, 1439, 1727, 1439, 568, 1439, - /* 2350 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1775, 1439, 1439, - /* 2360 */ 1439, 1439, 1439, 1439, 1439, 569, 1439, 1439, 1439, 1439, - /* 2370 */ 1727, 1439, 568, 1788, 1439, 1439, 1439, 1769, 1758, 571, - /* 2380 */ 1760, 1761, 567, 1439, 562, 1757, 1439, 1439, 1439, 1439, - /* 2390 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1788, 1439, 1439, - /* 2400 */ 1439, 1768, 1758, 571, 1760, 1761, 567, 1439, 562, 1757, - /* 2410 */ 1439, 1439, 1439, 1775, 1439, 1439, 1439, 1439, 1439, 1439, - /* 2420 */ 1439, 569, 1439, 1439, 1439, 1439, 1727, 1439, 568, 1439, - /* 2430 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1775, 1439, 1439, - /* 2440 */ 1439, 1439, 1439, 1439, 1439, 569, 1439, 1439, 1439, 1439, - /* 2450 */ 1727, 1757, 568, 1788, 1439, 1439, 1439, 1767, 1758, 571, - /* 2460 */ 1760, 1761, 567, 1439, 562, 1439, 1439, 1757, 1439, 1439, - /* 2470 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1788, 1439, 1775, - /* 2480 */ 1439, 304, 1758, 571, 1760, 1761, 567, 569, 562, 1439, - /* 2490 */ 1439, 1439, 1727, 1439, 568, 1775, 1439, 1439, 1439, 1439, - /* 2500 */ 1439, 1439, 1439, 569, 1439, 1439, 1439, 1439, 1727, 1757, - /* 2510 */ 568, 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1788, - /* 2520 */ 1439, 1439, 1439, 303, 1758, 571, 1760, 1761, 567, 1757, - /* 2530 */ 562, 1439, 1439, 1439, 1439, 1788, 1439, 1775, 1439, 305, - /* 2540 */ 1758, 571, 1760, 1761, 567, 569, 562, 1439, 1439, 1439, - /* 2550 */ 1727, 1439, 568, 1439, 1439, 1439, 1439, 1775, 1439, 1439, - /* 2560 */ 1439, 1439, 1439, 1439, 1439, 569, 1439, 1439, 1439, 1439, - /* 2570 */ 1727, 1439, 568, 1439, 1439, 1439, 1439, 1788, 1439, 1439, - /* 2580 */ 1439, 302, 1758, 571, 1760, 1761, 567, 1439, 562, 1439, - /* 2590 */ 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1788, 1439, 1439, - /* 2600 */ 1439, 282, 1758, 571, 1760, 1761, 567, 1439, 562, + /* 0 */ 430, 549, 431, 1485, 438, 1685, 431, 1485, 1576, 549, + /* 10 */ 34, 33, 40, 38, 41, 39, 37, 36, 35, 1753, + /* 20 */ 337, 71, 1248, 1451, 379, 1756, 435, 342, 552, 122, + /* 30 */ 1630, 1632, 1270, 1323, 117, 1246, 1753, 122, 41, 39, + /* 40 */ 37, 36, 35, 1580, 103, 1749, 1755, 102, 101, 100, + /* 50 */ 99, 98, 97, 96, 95, 94, 1318, 570, 554, 1912, + /* 60 */ 14, 1448, 1749, 1755, 326, 1912, 1254, 1769, 62, 120, + /* 70 */ 385, 1012, 1911, 1011, 570, 447, 1909, 120, 159, 40, + /* 80 */ 38, 1386, 1909, 1, 156, 1854, 1855, 337, 1859, 1248, + /* 90 */ 1273, 44, 249, 1854, 548, 1787, 547, 995, 513, 1912, + /* 100 */ 1323, 1013, 1246, 577, 1473, 657, 323, 301, 1739, 1682, + /* 110 */ 576, 142, 161, 1462, 61, 1912, 1909, 482, 481, 1325, + /* 120 */ 1326, 349, 480, 1318, 554, 118, 477, 14, 160, 476, + /* 130 */ 475, 474, 1909, 1254, 1681, 1800, 298, 999, 1000, 89, + /* 140 */ 1770, 579, 1772, 1773, 575, 1739, 570, 61, 610, 1846, + /* 150 */ 2, 34, 33, 304, 1842, 41, 39, 37, 36, 35, + /* 160 */ 220, 221, 1912, 1912, 1249, 1912, 1247, 131, 130, 607, + /* 170 */ 606, 605, 657, 1512, 552, 159, 1910, 1637, 161, 1909, + /* 180 */ 1909, 143, 1909, 418, 325, 1542, 1325, 1326, 1450, 1145, + /* 190 */ 1146, 1252, 1253, 1635, 1301, 1302, 1304, 1305, 1306, 1307, + /* 200 */ 1308, 572, 568, 1316, 1317, 1319, 1320, 1321, 1322, 1324, + /* 210 */ 1327, 61, 112, 111, 110, 109, 108, 107, 106, 105, + /* 220 */ 104, 303, 558, 162, 515, 31, 259, 1417, 214, 174, + /* 230 */ 173, 1249, 219, 1247, 71, 634, 633, 632, 345, 1407, + /* 240 */ 631, 630, 629, 123, 624, 623, 622, 621, 620, 619, + /* 250 */ 618, 617, 133, 613, 162, 61, 1581, 75, 1252, 1253, + /* 260 */ 1273, 1301, 1302, 1304, 1305, 1306, 1307, 1308, 572, 568, + /* 270 */ 1316, 1317, 1319, 1320, 1321, 1322, 1324, 1327, 40, 38, + /* 280 */ 535, 1405, 1406, 1408, 1409, 549, 337, 162, 1248, 627, + /* 290 */ 512, 378, 347, 377, 1228, 1229, 1631, 1632, 370, 1323, + /* 300 */ 1563, 1246, 1103, 601, 600, 599, 1107, 598, 1109, 1110, + /* 310 */ 597, 1112, 594, 122, 1118, 591, 1120, 1121, 588, 585, + /* 320 */ 372, 368, 1318, 498, 479, 478, 14, 525, 1561, 525, + /* 330 */ 373, 1912, 1254, 1912, 554, 40, 38, 1769, 164, 1248, + /* 340 */ 113, 86, 1272, 337, 159, 1248, 159, 468, 1909, 2, + /* 350 */ 1909, 162, 1246, 120, 119, 1585, 1323, 1585, 1246, 447, + /* 360 */ 543, 1012, 1577, 1011, 1912, 1787, 207, 1472, 249, 1854, + /* 370 */ 548, 657, 547, 577, 1787, 1912, 466, 159, 1739, 1318, + /* 380 */ 576, 1909, 542, 1254, 552, 1325, 1326, 612, 159, 1254, + /* 390 */ 1471, 1013, 1909, 103, 554, 162, 102, 101, 100, 99, + /* 400 */ 98, 97, 96, 95, 94, 1800, 8, 1757, 1739, 89, + /* 410 */ 1770, 579, 1772, 1773, 575, 1065, 570, 538, 1753, 1846, + /* 420 */ 541, 559, 657, 304, 1842, 73, 303, 612, 657, 515, + /* 430 */ 1249, 1739, 1247, 34, 33, 1912, 496, 41, 39, 37, + /* 440 */ 36, 35, 1325, 1326, 1749, 1755, 1067, 43, 159, 494, + /* 450 */ 1470, 492, 1909, 1390, 1274, 1037, 570, 1252, 1253, 1272, + /* 460 */ 1301, 1302, 1304, 1305, 1306, 1307, 1308, 572, 568, 1316, + /* 470 */ 1317, 1319, 1320, 1321, 1322, 1324, 1327, 11, 10, 549, + /* 480 */ 1562, 1249, 525, 1247, 525, 549, 1038, 1249, 153, 1247, + /* 490 */ 79, 1739, 1861, 165, 1726, 383, 544, 539, 34, 33, + /* 500 */ 314, 1624, 41, 39, 37, 36, 35, 122, 1252, 1253, + /* 510 */ 1585, 1578, 1585, 122, 1252, 1253, 1858, 1301, 1302, 1304, + /* 520 */ 1305, 1306, 1307, 1308, 572, 568, 1316, 1317, 1319, 1320, + /* 530 */ 1321, 1322, 1324, 1327, 40, 38, 1328, 525, 37, 36, + /* 540 */ 35, 358, 337, 1769, 1248, 525, 162, 120, 384, 315, + /* 550 */ 305, 313, 312, 120, 470, 1323, 388, 1246, 472, 324, + /* 560 */ 1359, 551, 155, 1854, 1855, 1585, 1859, 140, 157, 1854, + /* 570 */ 1855, 1787, 1859, 1585, 1286, 610, 1587, 1271, 1318, 553, + /* 580 */ 471, 1443, 1345, 1333, 1739, 251, 576, 162, 1254, 1272, + /* 590 */ 85, 40, 38, 1515, 131, 130, 607, 606, 605, 337, + /* 600 */ 82, 1248, 34, 33, 1861, 9, 41, 39, 37, 36, + /* 610 */ 35, 1800, 1323, 566, 1246, 90, 1770, 579, 1772, 1773, + /* 620 */ 575, 525, 570, 429, 170, 1846, 433, 657, 1857, 330, + /* 630 */ 1842, 154, 113, 525, 1303, 1318, 1346, 23, 1680, 473, + /* 640 */ 298, 1325, 1326, 158, 403, 1254, 525, 1675, 1469, 1585, + /* 650 */ 69, 1872, 1254, 68, 525, 482, 481, 404, 172, 1351, + /* 660 */ 480, 1585, 9, 118, 477, 446, 1275, 476, 475, 474, + /* 670 */ 1442, 34, 33, 340, 1585, 41, 39, 37, 36, 35, + /* 680 */ 1637, 140, 1585, 525, 657, 604, 1249, 341, 1247, 1739, + /* 690 */ 1587, 615, 1468, 616, 1582, 1557, 1635, 1383, 1325, 1326, + /* 700 */ 1560, 30, 335, 1340, 1341, 1342, 1343, 1344, 1348, 1349, + /* 710 */ 1350, 1585, 437, 1252, 1253, 433, 1301, 1302, 1304, 1305, + /* 720 */ 1306, 1307, 1308, 572, 568, 1316, 1317, 1319, 1320, 1321, + /* 730 */ 1322, 1324, 1327, 1739, 34, 33, 628, 626, 41, 39, + /* 740 */ 37, 36, 35, 1249, 1337, 1247, 27, 1397, 608, 999, + /* 750 */ 1000, 1628, 34, 33, 140, 29, 41, 39, 37, 36, + /* 760 */ 35, 34, 33, 1588, 1303, 41, 39, 37, 36, 35, + /* 770 */ 1252, 1253, 59, 1301, 1302, 1304, 1305, 1306, 1307, 1308, + /* 780 */ 572, 568, 1316, 1317, 1319, 1320, 1321, 1322, 1324, 1327, + /* 790 */ 40, 38, 300, 1272, 1270, 610, 660, 231, 337, 1769, + /* 800 */ 1248, 411, 1574, 1347, 423, 1467, 1466, 1465, 525, 525, + /* 810 */ 266, 1323, 1464, 1246, 131, 130, 607, 606, 605, 1714, + /* 820 */ 506, 396, 1461, 424, 151, 398, 1352, 1787, 7, 650, + /* 830 */ 646, 642, 638, 264, 1318, 577, 1585, 1585, 525, 1460, + /* 840 */ 1739, 525, 576, 343, 1254, 1570, 1739, 1739, 1739, 510, + /* 850 */ 42, 140, 523, 1739, 513, 609, 389, 561, 1628, 87, + /* 860 */ 1587, 2, 229, 1739, 1861, 1683, 1585, 1800, 28, 1585, + /* 870 */ 472, 91, 1770, 579, 1772, 1773, 575, 139, 570, 1459, + /* 880 */ 1739, 1846, 1458, 657, 1457, 1845, 1842, 271, 1856, 1456, + /* 890 */ 1615, 1196, 471, 1866, 1379, 522, 422, 1325, 1326, 417, + /* 900 */ 416, 415, 414, 413, 410, 409, 408, 407, 406, 402, + /* 910 */ 401, 400, 399, 393, 392, 391, 390, 1382, 387, 386, + /* 920 */ 1739, 1455, 1454, 1739, 1637, 1739, 141, 216, 34, 33, + /* 930 */ 1739, 277, 41, 39, 37, 36, 35, 45, 4, 1502, + /* 940 */ 1636, 1572, 1249, 525, 1247, 275, 58, 1568, 1220, 57, + /* 950 */ 209, 34, 33, 1453, 524, 41, 39, 37, 36, 35, + /* 960 */ 210, 483, 1739, 1739, 1769, 176, 426, 1497, 1303, 1252, + /* 970 */ 1253, 1585, 1301, 1302, 1304, 1305, 1306, 1307, 1308, 572, + /* 980 */ 568, 1316, 1317, 1319, 1320, 1321, 1322, 1324, 1327, 485, + /* 990 */ 198, 61, 1787, 196, 1739, 525, 200, 525, 202, 199, + /* 1000 */ 553, 201, 1495, 305, 1286, 1739, 260, 576, 344, 556, + /* 1010 */ 204, 1379, 218, 203, 125, 213, 52, 509, 128, 129, + /* 1020 */ 1759, 50, 1257, 1585, 488, 1585, 235, 11, 10, 88, + /* 1030 */ 571, 603, 1800, 1256, 505, 1345, 90, 1770, 579, 1772, + /* 1040 */ 1773, 575, 1769, 570, 74, 1463, 1846, 1445, 1446, 42, + /* 1050 */ 330, 1842, 154, 222, 1543, 518, 254, 1761, 562, 228, + /* 1060 */ 1096, 42, 1404, 42, 66, 65, 382, 238, 583, 169, + /* 1070 */ 1787, 536, 1873, 465, 499, 376, 243, 1788, 577, 128, + /* 1080 */ 346, 129, 114, 1739, 1491, 576, 128, 1486, 299, 1346, + /* 1090 */ 1353, 366, 1625, 364, 360, 356, 166, 351, 348, 1876, + /* 1100 */ 550, 248, 1309, 253, 270, 256, 258, 3, 53, 1124, + /* 1110 */ 1800, 80, 1351, 5, 90, 1770, 579, 1772, 1773, 575, + /* 1120 */ 1128, 570, 1135, 1133, 1846, 328, 327, 132, 330, 1842, + /* 1130 */ 1925, 162, 652, 350, 1270, 1262, 353, 357, 310, 1880, + /* 1140 */ 1769, 1065, 1212, 311, 267, 405, 1323, 1677, 1255, 171, + /* 1150 */ 412, 193, 419, 1260, 30, 335, 1340, 1341, 1342, 1343, + /* 1160 */ 1344, 1348, 1349, 1350, 1259, 146, 1769, 420, 1787, 1318, + /* 1170 */ 464, 460, 456, 452, 192, 1276, 577, 487, 421, 1254, + /* 1180 */ 425, 1739, 427, 576, 428, 436, 1279, 439, 440, 179, + /* 1190 */ 181, 1278, 497, 442, 1787, 1280, 1277, 441, 184, 444, + /* 1200 */ 72, 186, 577, 190, 445, 188, 206, 1739, 1800, 576, + /* 1210 */ 70, 448, 90, 1770, 579, 1772, 1773, 575, 534, 570, + /* 1220 */ 490, 191, 1846, 467, 484, 469, 330, 1842, 1925, 205, + /* 1230 */ 1575, 1719, 195, 1769, 1800, 1571, 197, 1903, 90, 1770, + /* 1240 */ 579, 1772, 1773, 575, 134, 570, 135, 1573, 1846, 93, + /* 1250 */ 1569, 302, 330, 1842, 1925, 56, 136, 137, 55, 268, + /* 1260 */ 208, 1787, 501, 1865, 500, 189, 182, 504, 187, 577, + /* 1270 */ 211, 507, 443, 511, 1739, 533, 576, 1263, 215, 1258, + /* 1280 */ 519, 514, 320, 1718, 224, 1687, 1769, 126, 516, 127, + /* 1290 */ 554, 180, 322, 226, 269, 520, 1769, 78, 1275, 537, + /* 1300 */ 1586, 1800, 521, 6, 1266, 284, 1770, 579, 1772, 1773, + /* 1310 */ 575, 233, 570, 529, 1787, 568, 1316, 1317, 1319, 1320, + /* 1320 */ 1321, 1322, 577, 1877, 1787, 237, 531, 1739, 530, 576, + /* 1330 */ 532, 1912, 577, 546, 329, 528, 527, 1739, 540, 576, + /* 1340 */ 121, 1379, 1887, 554, 161, 247, 1274, 563, 1909, 560, + /* 1350 */ 1886, 1769, 19, 581, 1800, 331, 1629, 245, 284, 1770, + /* 1360 */ 579, 1772, 1773, 575, 1800, 570, 272, 1769, 91, 1770, + /* 1370 */ 579, 1772, 1773, 575, 1868, 570, 246, 242, 1846, 1787, + /* 1380 */ 1862, 244, 565, 1842, 1912, 1928, 1558, 574, 1827, 263, + /* 1390 */ 653, 656, 1739, 252, 576, 1787, 654, 159, 51, 147, + /* 1400 */ 285, 1909, 148, 577, 1908, 557, 295, 294, 1739, 274, + /* 1410 */ 576, 276, 1733, 255, 63, 1732, 564, 1769, 257, 1800, + /* 1420 */ 1731, 1730, 64, 292, 1770, 579, 1772, 1773, 575, 573, + /* 1430 */ 570, 567, 1818, 1769, 352, 1800, 1727, 355, 354, 144, + /* 1440 */ 1770, 579, 1772, 1773, 575, 1787, 570, 359, 1240, 1241, + /* 1450 */ 1725, 167, 361, 577, 362, 363, 1724, 365, 1739, 1723, + /* 1460 */ 576, 1787, 367, 1722, 369, 1721, 321, 371, 1704, 577, + /* 1470 */ 168, 374, 375, 1215, 1739, 1769, 576, 1214, 1698, 1697, + /* 1480 */ 380, 381, 1696, 555, 1926, 1800, 1695, 1184, 1670, 91, + /* 1490 */ 1770, 579, 1772, 1773, 575, 1769, 570, 1669, 1668, 1846, + /* 1500 */ 67, 1800, 1667, 1787, 1843, 293, 1770, 579, 1772, 1773, + /* 1510 */ 575, 577, 570, 1666, 1665, 1664, 1739, 1663, 576, 394, + /* 1520 */ 395, 1662, 397, 1787, 1661, 1660, 1659, 1658, 526, 1657, + /* 1530 */ 1656, 577, 124, 1647, 1646, 1645, 1739, 1655, 576, 1654, + /* 1540 */ 1653, 1652, 1651, 1800, 1650, 1649, 1648, 288, 1770, 579, + /* 1550 */ 1772, 1773, 575, 1769, 570, 1644, 1643, 1642, 1186, 1641, + /* 1560 */ 1640, 1639, 1638, 1800, 1516, 1769, 175, 293, 1770, 579, + /* 1570 */ 1772, 1773, 575, 1514, 570, 1769, 1482, 1002, 1481, 1001, + /* 1580 */ 177, 1787, 115, 1712, 1706, 545, 1694, 1693, 178, 577, + /* 1590 */ 152, 116, 185, 1787, 1739, 432, 576, 434, 334, 1679, + /* 1600 */ 1564, 577, 1513, 1787, 1511, 183, 1739, 449, 576, 451, + /* 1610 */ 1509, 574, 453, 455, 450, 1031, 1739, 1507, 576, 459, + /* 1620 */ 457, 1800, 454, 1505, 1494, 144, 1770, 579, 1772, 1773, + /* 1630 */ 575, 461, 570, 1800, 1493, 1769, 458, 293, 1770, 579, + /* 1640 */ 1772, 1773, 575, 1800, 570, 462, 463, 292, 1770, 579, + /* 1650 */ 1772, 1773, 575, 1478, 570, 1566, 1819, 1139, 1769, 194, + /* 1660 */ 49, 1138, 1565, 1787, 1064, 1063, 1062, 1061, 336, 625, + /* 1670 */ 1927, 577, 1058, 1057, 1503, 1056, 1739, 1498, 576, 627, + /* 1680 */ 316, 317, 486, 1496, 489, 318, 1787, 1477, 1476, 491, + /* 1690 */ 1475, 338, 493, 495, 577, 92, 1711, 1705, 138, 1739, + /* 1700 */ 1769, 576, 1222, 1800, 502, 1692, 212, 293, 1770, 579, + /* 1710 */ 1772, 1773, 575, 1690, 570, 1691, 1689, 1769, 15, 1686, + /* 1720 */ 1678, 82, 54, 1688, 225, 217, 1800, 223, 1787, 1232, + /* 1730 */ 293, 1770, 579, 1772, 1773, 575, 577, 570, 230, 503, + /* 1740 */ 1419, 1739, 319, 576, 76, 1787, 508, 42, 77, 16, + /* 1750 */ 517, 24, 227, 577, 234, 232, 241, 1401, 1739, 236, + /* 1760 */ 576, 1264, 1403, 145, 48, 1396, 1431, 1769, 1800, 239, + /* 1770 */ 240, 1759, 278, 1770, 579, 1772, 1773, 575, 25, 570, + /* 1780 */ 26, 81, 250, 1376, 1375, 1800, 47, 1758, 1769, 279, + /* 1790 */ 1770, 579, 1772, 1773, 575, 1787, 570, 149, 1436, 18, + /* 1800 */ 1430, 1425, 46, 577, 332, 1435, 17, 1434, 1739, 1769, + /* 1810 */ 576, 333, 10, 1803, 20, 569, 1787, 13, 1338, 1313, + /* 1820 */ 150, 163, 1311, 32, 577, 1294, 1310, 580, 12, 1739, + /* 1830 */ 21, 576, 22, 582, 1125, 1800, 578, 1787, 584, 280, + /* 1840 */ 1770, 579, 1772, 1773, 575, 577, 570, 339, 1122, 586, + /* 1850 */ 1739, 1769, 576, 589, 592, 595, 1800, 1119, 1102, 1117, + /* 1860 */ 287, 1770, 579, 1772, 1773, 575, 587, 570, 1769, 590, + /* 1870 */ 1116, 1113, 593, 1115, 1111, 596, 602, 1800, 83, 1787, + /* 1880 */ 84, 289, 1770, 579, 1772, 1773, 575, 577, 570, 1114, + /* 1890 */ 1134, 60, 1739, 261, 576, 1130, 1787, 1071, 1029, 611, + /* 1900 */ 1053, 262, 614, 1051, 577, 1050, 1049, 1048, 1046, 1739, + /* 1910 */ 1047, 576, 1045, 1044, 1068, 1066, 1041, 1040, 1039, 1800, + /* 1920 */ 1769, 636, 1036, 281, 1770, 579, 1772, 1773, 575, 1035, + /* 1930 */ 570, 1034, 1510, 635, 637, 1508, 1800, 639, 640, 641, + /* 1940 */ 290, 1770, 579, 1772, 1773, 575, 1506, 570, 1787, 643, + /* 1950 */ 644, 645, 1504, 647, 648, 649, 577, 1492, 651, 992, + /* 1960 */ 1474, 1739, 265, 576, 655, 1449, 1250, 273, 658, 659, + /* 1970 */ 1449, 1449, 1449, 1449, 1769, 1449, 1449, 1449, 1449, 1449, + /* 1980 */ 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1800, 1449, + /* 1990 */ 1769, 1449, 282, 1770, 579, 1772, 1773, 575, 1449, 570, + /* 2000 */ 1769, 1449, 1787, 1449, 1449, 1449, 1449, 1449, 1449, 1449, + /* 2010 */ 577, 1449, 1449, 1449, 1449, 1739, 1449, 576, 1787, 1449, + /* 2020 */ 1449, 1449, 1449, 1449, 1449, 1449, 577, 1449, 1787, 1449, + /* 2030 */ 1449, 1739, 1449, 576, 1449, 1449, 577, 1449, 1449, 1449, + /* 2040 */ 1449, 1739, 1800, 576, 1449, 1449, 291, 1770, 579, 1772, + /* 2050 */ 1773, 575, 1769, 570, 1449, 1449, 1449, 1449, 1800, 1449, + /* 2060 */ 1449, 1449, 283, 1770, 579, 1772, 1773, 575, 1800, 570, + /* 2070 */ 1449, 1449, 296, 1770, 579, 1772, 1773, 575, 1449, 570, + /* 2080 */ 1787, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 577, 1449, + /* 2090 */ 1449, 1449, 1449, 1739, 1769, 576, 1449, 1449, 1449, 1449, + /* 2100 */ 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1769, 1449, + /* 2110 */ 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1769, 1449, + /* 2120 */ 1800, 1449, 1787, 1449, 297, 1770, 579, 1772, 1773, 575, + /* 2130 */ 577, 570, 1449, 1449, 1449, 1739, 1787, 576, 1449, 1449, + /* 2140 */ 1449, 1449, 1449, 1449, 577, 1449, 1787, 1449, 1449, 1739, + /* 2150 */ 1449, 576, 1449, 1449, 577, 1449, 1449, 1449, 1449, 1739, + /* 2160 */ 1449, 576, 1800, 1449, 1449, 1449, 1781, 1770, 579, 1772, + /* 2170 */ 1773, 575, 1449, 570, 1449, 1449, 1800, 1769, 1449, 1449, + /* 2180 */ 1780, 1770, 579, 1772, 1773, 575, 1800, 570, 1449, 1449, + /* 2190 */ 1779, 1770, 579, 1772, 1773, 575, 1449, 570, 1769, 1449, + /* 2200 */ 1449, 1449, 1449, 1449, 1449, 1787, 1449, 1449, 1449, 1449, + /* 2210 */ 1449, 1449, 1449, 577, 1449, 1449, 1449, 1449, 1739, 1449, + /* 2220 */ 576, 1449, 1449, 1449, 1449, 1449, 1787, 1449, 1449, 1449, + /* 2230 */ 1449, 1449, 1449, 1449, 577, 1449, 1449, 1449, 1449, 1739, + /* 2240 */ 1449, 576, 1449, 1449, 1449, 1800, 1449, 1449, 1449, 308, + /* 2250 */ 1770, 579, 1772, 1773, 575, 1449, 570, 1769, 1449, 1449, + /* 2260 */ 1449, 1449, 1449, 1449, 1449, 1449, 1800, 1769, 1449, 1449, + /* 2270 */ 307, 1770, 579, 1772, 1773, 575, 1449, 570, 1449, 1449, + /* 2280 */ 1449, 1449, 1449, 1769, 1449, 1787, 1449, 1449, 1449, 1449, + /* 2290 */ 1449, 1449, 1449, 577, 1449, 1787, 1449, 1449, 1739, 1449, + /* 2300 */ 576, 1449, 1449, 577, 1449, 1449, 1449, 1449, 1739, 1449, + /* 2310 */ 576, 1787, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 577, + /* 2320 */ 1449, 1449, 1449, 1449, 1739, 1800, 576, 1449, 1449, 309, + /* 2330 */ 1770, 579, 1772, 1773, 575, 1800, 570, 1449, 1449, 306, + /* 2340 */ 1770, 579, 1772, 1773, 575, 1449, 570, 1449, 1449, 1449, + /* 2350 */ 1449, 1800, 1449, 1449, 1449, 286, 1770, 579, 1772, 1773, + /* 2360 */ 575, 1449, 570, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 259, 284, 261, 262, 353, 259, 252, 261, 262, 267, - /* 10 */ 267, 263, 12, 13, 285, 268, 283, 366, 263, 272, - /* 20 */ 20, 370, 22, 280, 291, 296, 12, 13, 14, 15, - /* 30 */ 16, 289, 289, 33, 21, 35, 285, 24, 25, 26, - /* 40 */ 27, 28, 29, 30, 31, 32, 291, 296, 300, 20, - /* 50 */ 285, 322, 323, 324, 294, 255, 56, 297, 298, 59, - /* 60 */ 20, 296, 329, 334, 58, 65, 312, 312, 20, 12, - /* 70 */ 13, 14, 263, 322, 323, 0, 353, 20, 254, 22, - /* 80 */ 256, 56, 82, 283, 20, 334, 331, 322, 323, 366, - /* 90 */ 33, 291, 35, 370, 312, 94, 296, 353, 298, 334, - /* 100 */ 291, 346, 347, 348, 104, 350, 81, 353, 353, 84, - /* 110 */ 366, 82, 312, 56, 370, 35, 59, 116, 118, 119, - /* 120 */ 366, 366, 65, 323, 370, 370, 20, 327, 328, 329, - /* 130 */ 330, 331, 332, 58, 334, 353, 82, 337, 14, 82, - /* 140 */ 331, 341, 342, 263, 20, 65, 82, 20, 366, 282, - /* 150 */ 19, 56, 370, 353, 345, 346, 347, 348, 20, 350, - /* 160 */ 22, 104, 295, 163, 33, 165, 366, 338, 339, 4, - /* 170 */ 370, 291, 20, 35, 275, 118, 119, 82, 47, 84, - /* 180 */ 58, 114, 283, 52, 53, 54, 55, 56, 50, 189, - /* 190 */ 190, 292, 192, 193, 194, 195, 196, 197, 198, 199, - /* 200 */ 200, 201, 202, 203, 204, 205, 206, 207, 208, 44, - /* 210 */ 45, 331, 81, 14, 260, 84, 162, 263, 164, 20, - /* 220 */ 163, 221, 165, 76, 118, 119, 346, 347, 348, 20, - /* 230 */ 350, 8, 9, 37, 298, 12, 13, 14, 15, 16, - /* 240 */ 173, 174, 306, 263, 177, 309, 189, 190, 117, 192, - /* 250 */ 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, - /* 260 */ 203, 204, 205, 206, 207, 208, 12, 13, 0, 122, - /* 270 */ 123, 291, 283, 0, 20, 221, 22, 113, 114, 290, - /* 280 */ 149, 85, 59, 87, 88, 221, 90, 33, 299, 35, - /* 290 */ 94, 148, 24, 25, 26, 27, 28, 29, 30, 31, - /* 300 */ 32, 170, 255, 172, 263, 260, 83, 263, 263, 263, - /* 310 */ 56, 331, 116, 59, 91, 274, 221, 193, 274, 65, - /* 320 */ 274, 4, 281, 12, 13, 281, 346, 347, 348, 82, - /* 330 */ 350, 20, 291, 22, 0, 291, 82, 291, 174, 14, - /* 340 */ 255, 177, 65, 296, 33, 20, 35, 95, 96, 97, - /* 350 */ 98, 99, 100, 101, 102, 103, 104, 105, 104, 107, - /* 360 */ 108, 109, 110, 111, 112, 0, 263, 56, 145, 226, - /* 370 */ 227, 293, 118, 119, 296, 255, 65, 274, 14, 15, - /* 380 */ 16, 296, 8, 9, 297, 298, 12, 13, 14, 15, - /* 390 */ 16, 168, 193, 82, 291, 61, 62, 63, 64, 82, - /* 400 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, - /* 410 */ 76, 77, 78, 79, 93, 104, 296, 163, 325, 165, - /* 420 */ 8, 9, 189, 58, 12, 13, 14, 15, 16, 118, - /* 430 */ 119, 0, 209, 210, 211, 212, 213, 214, 215, 216, - /* 440 */ 217, 218, 349, 189, 190, 65, 192, 193, 194, 195, - /* 450 */ 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, - /* 460 */ 206, 207, 208, 230, 231, 232, 233, 234, 221, 263, - /* 470 */ 61, 62, 269, 270, 163, 66, 165, 284, 69, 70, - /* 480 */ 274, 265, 73, 74, 75, 8, 9, 1, 2, 12, - /* 490 */ 13, 14, 15, 16, 278, 83, 20, 291, 22, 56, - /* 500 */ 189, 190, 286, 192, 193, 194, 195, 196, 197, 198, - /* 510 */ 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, - /* 520 */ 12, 13, 14, 275, 4, 94, 50, 84, 20, 155, - /* 530 */ 22, 283, 221, 0, 312, 33, 59, 284, 221, 19, - /* 540 */ 292, 33, 275, 35, 113, 114, 115, 116, 117, 47, - /* 550 */ 283, 263, 316, 33, 52, 53, 54, 55, 56, 292, - /* 560 */ 265, 263, 274, 263, 56, 269, 270, 47, 91, 83, - /* 570 */ 312, 51, 274, 65, 274, 353, 56, 12, 13, 291, - /* 580 */ 283, 286, 263, 81, 3, 20, 84, 22, 366, 291, - /* 590 */ 82, 291, 370, 274, 61, 62, 299, 158, 33, 66, - /* 600 */ 35, 81, 69, 70, 84, 263, 73, 74, 75, 39, - /* 610 */ 291, 353, 104, 308, 263, 310, 274, 243, 263, 180, - /* 620 */ 181, 56, 145, 4, 366, 274, 118, 119, 370, 274, - /* 630 */ 65, 8, 9, 291, 255, 12, 13, 14, 15, 16, - /* 640 */ 44, 45, 291, 283, 255, 168, 291, 82, 146, 147, - /* 650 */ 290, 149, 325, 20, 263, 153, 8, 9, 255, 299, - /* 660 */ 12, 13, 14, 15, 16, 274, 43, 291, 263, 104, - /* 670 */ 308, 163, 310, 165, 172, 296, 349, 113, 302, 274, - /* 680 */ 255, 43, 291, 118, 119, 296, 209, 210, 211, 212, - /* 690 */ 213, 214, 215, 216, 217, 218, 291, 189, 190, 296, - /* 700 */ 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, - /* 710 */ 202, 203, 204, 205, 206, 207, 208, 0, 8, 9, - /* 720 */ 21, 296, 12, 13, 14, 15, 16, 325, 163, 293, - /* 730 */ 165, 83, 296, 34, 276, 36, 255, 279, 21, 175, - /* 740 */ 176, 24, 25, 26, 27, 28, 29, 30, 31, 32, - /* 750 */ 271, 349, 273, 263, 189, 190, 0, 192, 193, 194, - /* 760 */ 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, - /* 770 */ 205, 206, 207, 208, 12, 13, 18, 296, 20, 43, - /* 780 */ 263, 291, 20, 150, 22, 27, 256, 255, 30, 263, - /* 790 */ 220, 274, 94, 83, 255, 33, 20, 35, 284, 298, - /* 800 */ 274, 145, 312, 47, 255, 47, 20, 49, 291, 51, - /* 810 */ 309, 113, 114, 115, 116, 117, 35, 291, 56, 238, - /* 820 */ 263, 331, 219, 220, 168, 42, 43, 65, 296, 150, - /* 830 */ 151, 274, 255, 283, 255, 296, 346, 347, 348, 81, - /* 840 */ 350, 222, 292, 353, 82, 296, 8, 9, 291, 364, - /* 850 */ 12, 13, 14, 15, 16, 86, 366, 284, 89, 255, - /* 860 */ 370, 22, 255, 8, 9, 209, 104, 12, 13, 14, - /* 870 */ 15, 16, 255, 296, 35, 296, 284, 35, 240, 121, - /* 880 */ 118, 119, 124, 125, 126, 127, 128, 129, 130, 131, - /* 890 */ 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - /* 900 */ 296, 143, 144, 296, 65, 2, 255, 1, 2, 18, - /* 910 */ 43, 8, 9, 296, 23, 12, 13, 14, 15, 16, - /* 920 */ 0, 86, 118, 119, 89, 163, 150, 165, 37, 38, - /* 930 */ 255, 0, 41, 255, 86, 86, 43, 89, 89, 59, - /* 940 */ 272, 46, 43, 104, 255, 284, 165, 296, 57, 373, - /* 950 */ 83, 189, 190, 22, 192, 193, 194, 195, 196, 197, - /* 960 */ 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, - /* 970 */ 208, 296, 283, 82, 296, 43, 83, 82, 242, 193, - /* 980 */ 291, 319, 83, 2, 0, 296, 0, 298, 150, 8, - /* 990 */ 9, 264, 43, 12, 13, 14, 15, 16, 43, 43, - /* 1000 */ 43, 312, 163, 43, 165, 43, 22, 165, 22, 43, - /* 1010 */ 360, 120, 323, 43, 94, 83, 327, 328, 329, 330, - /* 1020 */ 331, 332, 255, 334, 0, 283, 337, 264, 189, 190, - /* 1030 */ 341, 342, 83, 113, 114, 115, 116, 117, 83, 83, - /* 1040 */ 83, 43, 353, 83, 43, 83, 155, 156, 157, 83, - /* 1050 */ 283, 160, 43, 83, 82, 366, 35, 166, 291, 370, - /* 1060 */ 262, 295, 43, 296, 92, 298, 326, 351, 344, 189, - /* 1070 */ 179, 367, 48, 182, 367, 184, 185, 186, 187, 188, - /* 1080 */ 367, 83, 354, 255, 83, 223, 65, 20, 263, 321, - /* 1090 */ 323, 47, 83, 320, 327, 328, 329, 330, 331, 332, - /* 1100 */ 255, 334, 83, 35, 337, 269, 161, 314, 341, 342, - /* 1110 */ 343, 283, 221, 263, 263, 42, 303, 301, 145, 291, - /* 1120 */ 301, 263, 355, 20, 296, 257, 298, 257, 283, 20, - /* 1130 */ 363, 267, 318, 267, 20, 298, 291, 311, 20, 267, - /* 1140 */ 313, 296, 311, 298, 267, 20, 267, 304, 267, 263, - /* 1150 */ 267, 323, 283, 255, 257, 327, 328, 329, 330, 331, - /* 1160 */ 332, 283, 334, 171, 318, 337, 307, 283, 323, 341, - /* 1170 */ 342, 343, 327, 328, 329, 330, 331, 332, 257, 334, - /* 1180 */ 263, 283, 337, 283, 283, 283, 341, 342, 343, 291, - /* 1190 */ 283, 363, 283, 283, 296, 283, 298, 352, 283, 12, - /* 1200 */ 13, 296, 265, 265, 317, 263, 298, 263, 255, 22, - /* 1210 */ 228, 265, 296, 147, 296, 311, 305, 291, 296, 296, - /* 1220 */ 33, 323, 35, 296, 265, 327, 328, 329, 330, 331, - /* 1230 */ 332, 307, 334, 304, 265, 337, 283, 279, 291, 341, - /* 1240 */ 342, 343, 20, 56, 291, 326, 296, 229, 359, 296, - /* 1250 */ 352, 298, 65, 359, 362, 307, 154, 296, 307, 296, - /* 1260 */ 296, 296, 235, 237, 236, 224, 220, 291, 20, 239, - /* 1270 */ 241, 82, 255, 359, 361, 321, 323, 325, 244, 82, - /* 1280 */ 327, 328, 329, 330, 331, 332, 255, 334, 358, 356, - /* 1290 */ 337, 104, 357, 368, 341, 342, 343, 369, 255, 287, - /* 1300 */ 283, 296, 263, 369, 36, 352, 273, 368, 291, 369, - /* 1310 */ 374, 368, 265, 296, 283, 298, 258, 340, 257, 315, - /* 1320 */ 310, 266, 291, 253, 0, 277, 283, 296, 277, 298, - /* 1330 */ 277, 0, 42, 0, 291, 73, 0, 35, 183, 296, - /* 1340 */ 323, 298, 35, 312, 327, 328, 329, 330, 331, 332, - /* 1350 */ 163, 334, 165, 35, 323, 312, 35, 183, 327, 328, - /* 1360 */ 329, 330, 331, 332, 0, 334, 323, 255, 183, 35, - /* 1370 */ 327, 328, 329, 330, 331, 332, 189, 334, 35, 0, - /* 1380 */ 0, 183, 365, 35, 353, 0, 0, 200, 201, 202, - /* 1390 */ 203, 204, 205, 206, 22, 283, 353, 366, 35, 0, - /* 1400 */ 168, 370, 82, 291, 167, 165, 163, 0, 296, 366, - /* 1410 */ 298, 0, 159, 370, 158, 0, 0, 46, 0, 0, - /* 1420 */ 0, 142, 0, 0, 255, 0, 0, 0, 137, 35, - /* 1430 */ 0, 137, 0, 0, 0, 323, 0, 0, 0, 327, - /* 1440 */ 328, 329, 330, 331, 332, 255, 334, 0, 0, 337, - /* 1450 */ 0, 0, 283, 341, 342, 0, 0, 0, 0, 42, - /* 1460 */ 291, 0, 0, 0, 0, 296, 0, 298, 0, 0, - /* 1470 */ 0, 22, 0, 283, 43, 46, 0, 42, 39, 14, - /* 1480 */ 40, 291, 0, 0, 0, 14, 296, 46, 298, 0, - /* 1490 */ 0, 39, 323, 39, 154, 0, 327, 328, 329, 330, - /* 1500 */ 331, 332, 0, 334, 0, 255, 337, 0, 0, 0, - /* 1510 */ 341, 342, 35, 323, 39, 0, 0, 327, 328, 329, - /* 1520 */ 330, 331, 332, 333, 334, 335, 336, 60, 47, 35, - /* 1530 */ 39, 35, 47, 283, 47, 0, 39, 39, 35, 47, - /* 1540 */ 0, 291, 0, 0, 0, 35, 296, 22, 298, 89, - /* 1550 */ 91, 0, 35, 35, 35, 35, 43, 43, 35, 35, - /* 1560 */ 0, 255, 35, 22, 0, 0, 35, 22, 22, 0, - /* 1570 */ 49, 35, 0, 323, 35, 0, 22, 327, 328, 329, - /* 1580 */ 330, 331, 332, 255, 334, 0, 20, 35, 0, 283, - /* 1590 */ 169, 0, 150, 22, 150, 0, 150, 291, 0, 0, - /* 1600 */ 147, 0, 296, 0, 298, 83, 178, 0, 82, 39, - /* 1610 */ 82, 283, 82, 46, 82, 225, 288, 43, 22, 291, - /* 1620 */ 83, 371, 372, 43, 296, 152, 298, 148, 225, 323, - /* 1630 */ 92, 82, 146, 327, 328, 329, 330, 331, 332, 82, - /* 1640 */ 334, 83, 83, 337, 255, 82, 46, 43, 342, 225, - /* 1650 */ 82, 323, 46, 43, 46, 327, 328, 329, 330, 331, - /* 1660 */ 332, 82, 334, 82, 255, 83, 83, 83, 82, 43, - /* 1670 */ 83, 46, 283, 46, 43, 83, 83, 288, 35, 2, - /* 1680 */ 291, 35, 35, 35, 35, 296, 35, 298, 189, 22, - /* 1690 */ 93, 82, 283, 43, 83, 82, 82, 219, 83, 83, - /* 1700 */ 291, 46, 46, 82, 82, 296, 82, 298, 35, 35, - /* 1710 */ 35, 83, 323, 83, 82, 82, 327, 328, 329, 330, - /* 1720 */ 331, 332, 83, 334, 191, 35, 35, 82, 35, 255, - /* 1730 */ 22, 94, 323, 35, 22, 83, 327, 328, 329, 330, - /* 1740 */ 331, 332, 82, 334, 83, 82, 106, 106, 255, 60, - /* 1750 */ 82, 82, 82, 43, 59, 35, 80, 283, 43, 106, - /* 1760 */ 106, 65, 288, 35, 35, 291, 35, 35, 35, 22, - /* 1770 */ 296, 35, 298, 35, 65, 35, 283, 35, 35, 35, - /* 1780 */ 35, 372, 0, 35, 291, 35, 35, 0, 47, 296, - /* 1790 */ 35, 298, 39, 47, 0, 39, 35, 323, 39, 47, - /* 1800 */ 0, 327, 328, 329, 330, 331, 332, 35, 334, 47, - /* 1810 */ 39, 0, 35, 35, 0, 22, 323, 255, 21, 21, - /* 1820 */ 327, 328, 329, 330, 331, 332, 22, 334, 22, 336, - /* 1830 */ 20, 375, 375, 255, 375, 375, 375, 375, 375, 375, - /* 1840 */ 375, 375, 375, 375, 375, 283, 375, 375, 375, 375, - /* 1850 */ 288, 375, 375, 291, 375, 375, 375, 375, 296, 375, - /* 1860 */ 298, 283, 375, 375, 375, 375, 288, 375, 375, 291, - /* 1870 */ 375, 375, 375, 375, 296, 255, 298, 375, 375, 375, - /* 1880 */ 375, 375, 375, 375, 375, 323, 375, 375, 375, 327, - /* 1890 */ 328, 329, 330, 331, 332, 375, 334, 375, 375, 255, - /* 1900 */ 375, 323, 375, 283, 375, 327, 328, 329, 330, 331, - /* 1910 */ 332, 291, 334, 375, 375, 375, 296, 375, 298, 375, - /* 1920 */ 375, 375, 375, 375, 375, 375, 375, 283, 375, 375, - /* 1930 */ 375, 375, 375, 375, 375, 291, 375, 375, 375, 375, - /* 1940 */ 296, 255, 298, 323, 375, 375, 375, 327, 328, 329, - /* 1950 */ 330, 331, 332, 375, 334, 375, 375, 375, 375, 375, - /* 1960 */ 375, 255, 375, 375, 375, 375, 375, 323, 375, 283, - /* 1970 */ 375, 327, 328, 329, 330, 331, 332, 291, 334, 375, - /* 1980 */ 375, 375, 296, 375, 298, 375, 375, 375, 375, 283, - /* 1990 */ 375, 375, 375, 375, 375, 375, 375, 291, 375, 375, - /* 2000 */ 375, 375, 296, 375, 298, 375, 375, 375, 375, 323, - /* 2010 */ 375, 375, 375, 327, 328, 329, 330, 331, 332, 375, - /* 2020 */ 334, 255, 375, 375, 375, 375, 375, 375, 375, 323, - /* 2030 */ 375, 375, 375, 327, 328, 329, 330, 331, 332, 375, - /* 2040 */ 334, 375, 375, 375, 375, 255, 375, 375, 375, 283, - /* 2050 */ 375, 375, 375, 375, 375, 375, 375, 291, 375, 375, - /* 2060 */ 375, 375, 296, 375, 298, 375, 375, 375, 375, 375, - /* 2070 */ 375, 375, 375, 283, 375, 375, 375, 375, 375, 375, - /* 2080 */ 375, 291, 375, 375, 375, 375, 296, 375, 298, 323, - /* 2090 */ 375, 375, 375, 327, 328, 329, 330, 331, 332, 375, - /* 2100 */ 334, 255, 375, 375, 375, 375, 375, 375, 375, 375, - /* 2110 */ 375, 375, 375, 323, 375, 375, 375, 327, 328, 329, - /* 2120 */ 330, 331, 332, 375, 334, 255, 375, 375, 375, 283, - /* 2130 */ 375, 375, 375, 375, 375, 375, 375, 291, 375, 375, - /* 2140 */ 375, 375, 296, 375, 298, 375, 375, 375, 375, 375, - /* 2150 */ 375, 375, 375, 283, 375, 375, 375, 375, 375, 375, - /* 2160 */ 375, 291, 375, 375, 375, 375, 296, 255, 298, 323, - /* 2170 */ 375, 375, 375, 327, 328, 329, 330, 331, 332, 375, - /* 2180 */ 334, 375, 375, 255, 375, 375, 375, 375, 375, 375, - /* 2190 */ 375, 375, 375, 323, 375, 283, 375, 327, 328, 329, - /* 2200 */ 330, 331, 332, 291, 334, 375, 375, 375, 296, 375, - /* 2210 */ 298, 283, 375, 375, 375, 375, 375, 375, 375, 291, - /* 2220 */ 375, 375, 375, 375, 296, 255, 298, 375, 375, 375, - /* 2230 */ 375, 375, 375, 375, 375, 323, 375, 375, 375, 327, - /* 2240 */ 328, 329, 330, 331, 332, 255, 334, 375, 375, 375, - /* 2250 */ 375, 323, 375, 283, 375, 327, 328, 329, 330, 331, - /* 2260 */ 332, 291, 334, 375, 375, 375, 296, 375, 298, 375, - /* 2270 */ 375, 375, 375, 283, 375, 375, 375, 375, 375, 375, - /* 2280 */ 375, 291, 375, 375, 375, 375, 296, 375, 298, 375, - /* 2290 */ 375, 375, 375, 323, 375, 375, 375, 327, 328, 329, - /* 2300 */ 330, 331, 332, 375, 334, 255, 375, 375, 375, 375, - /* 2310 */ 375, 375, 375, 323, 375, 375, 375, 327, 328, 329, - /* 2320 */ 330, 331, 332, 375, 334, 375, 375, 375, 375, 255, - /* 2330 */ 375, 375, 375, 283, 375, 375, 375, 375, 375, 375, - /* 2340 */ 375, 291, 375, 375, 375, 375, 296, 375, 298, 375, - /* 2350 */ 375, 375, 375, 375, 375, 375, 375, 283, 375, 375, - /* 2360 */ 375, 375, 375, 375, 375, 291, 375, 375, 375, 375, - /* 2370 */ 296, 375, 298, 323, 375, 375, 375, 327, 328, 329, - /* 2380 */ 330, 331, 332, 375, 334, 255, 375, 375, 375, 375, - /* 2390 */ 375, 375, 375, 375, 375, 375, 375, 323, 375, 375, - /* 2400 */ 375, 327, 328, 329, 330, 331, 332, 375, 334, 255, - /* 2410 */ 375, 375, 375, 283, 375, 375, 375, 375, 375, 375, - /* 2420 */ 375, 291, 375, 375, 375, 375, 296, 375, 298, 375, - /* 2430 */ 375, 375, 375, 375, 375, 375, 375, 283, 375, 375, - /* 2440 */ 375, 375, 375, 375, 375, 291, 375, 375, 375, 375, - /* 2450 */ 296, 255, 298, 323, 375, 375, 375, 327, 328, 329, - /* 2460 */ 330, 331, 332, 375, 334, 375, 375, 255, 375, 375, - /* 2470 */ 375, 375, 375, 375, 375, 375, 375, 323, 375, 283, - /* 2480 */ 375, 327, 328, 329, 330, 331, 332, 291, 334, 375, - /* 2490 */ 375, 375, 296, 375, 298, 283, 375, 375, 375, 375, - /* 2500 */ 375, 375, 375, 291, 375, 375, 375, 375, 296, 255, - /* 2510 */ 298, 375, 375, 375, 375, 375, 375, 375, 375, 323, - /* 2520 */ 375, 375, 375, 327, 328, 329, 330, 331, 332, 255, - /* 2530 */ 334, 375, 375, 375, 375, 323, 375, 283, 375, 327, - /* 2540 */ 328, 329, 330, 331, 332, 291, 334, 375, 375, 375, - /* 2550 */ 296, 375, 298, 375, 375, 375, 375, 283, 375, 375, - /* 2560 */ 375, 375, 375, 375, 375, 291, 375, 375, 375, 375, - /* 2570 */ 296, 375, 298, 375, 375, 375, 375, 323, 375, 375, - /* 2580 */ 375, 327, 328, 329, 330, 331, 332, 375, 334, 375, - /* 2590 */ 375, 375, 375, 375, 375, 375, 375, 323, 375, 375, - /* 2600 */ 375, 327, 328, 329, 330, 331, 332, 375, 334, + /* 0 */ 260, 264, 262, 263, 260, 0, 262, 263, 286, 264, + /* 10 */ 8, 9, 12, 13, 12, 13, 14, 15, 16, 297, + /* 20 */ 20, 268, 22, 0, 313, 286, 14, 295, 20, 292, + /* 30 */ 298, 299, 20, 33, 281, 35, 297, 292, 12, 13, + /* 40 */ 14, 15, 16, 290, 21, 323, 324, 24, 25, 26, + /* 50 */ 27, 28, 29, 30, 31, 32, 56, 335, 313, 354, + /* 60 */ 60, 253, 323, 324, 325, 354, 66, 256, 4, 332, + /* 70 */ 264, 20, 367, 22, 335, 59, 371, 332, 367, 12, + /* 80 */ 13, 14, 371, 83, 347, 348, 349, 20, 351, 22, + /* 90 */ 20, 83, 347, 348, 349, 284, 351, 4, 299, 354, + /* 100 */ 33, 50, 35, 292, 256, 105, 307, 301, 297, 310, + /* 110 */ 299, 255, 367, 257, 83, 354, 371, 62, 63, 119, + /* 120 */ 120, 313, 67, 56, 313, 70, 71, 60, 367, 74, + /* 130 */ 75, 76, 371, 66, 309, 324, 311, 44, 45, 328, + /* 140 */ 329, 330, 331, 332, 333, 297, 335, 83, 95, 338, + /* 150 */ 83, 8, 9, 342, 343, 12, 13, 14, 15, 16, + /* 160 */ 114, 115, 354, 354, 164, 354, 166, 114, 115, 116, + /* 170 */ 117, 118, 105, 0, 20, 367, 367, 284, 367, 371, + /* 180 */ 371, 269, 371, 77, 291, 273, 119, 120, 0, 119, + /* 190 */ 120, 191, 192, 300, 194, 195, 196, 197, 198, 199, + /* 200 */ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, + /* 210 */ 210, 83, 24, 25, 26, 27, 28, 29, 30, 31, + /* 220 */ 32, 175, 43, 223, 178, 339, 340, 84, 56, 123, + /* 230 */ 124, 164, 114, 166, 268, 62, 63, 64, 65, 191, + /* 240 */ 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + /* 250 */ 77, 78, 79, 80, 223, 83, 290, 85, 191, 192, + /* 260 */ 20, 194, 195, 196, 197, 198, 199, 200, 201, 202, + /* 270 */ 203, 204, 205, 206, 207, 208, 209, 210, 12, 13, + /* 280 */ 232, 233, 234, 235, 236, 264, 20, 223, 22, 43, + /* 290 */ 313, 163, 313, 165, 176, 177, 298, 299, 159, 33, + /* 300 */ 0, 35, 96, 97, 98, 99, 100, 101, 102, 103, + /* 310 */ 104, 105, 106, 292, 108, 109, 110, 111, 112, 113, + /* 320 */ 181, 182, 56, 313, 270, 271, 60, 264, 0, 264, + /* 330 */ 84, 354, 66, 354, 313, 12, 13, 256, 275, 22, + /* 340 */ 275, 266, 20, 20, 367, 22, 367, 282, 371, 83, + /* 350 */ 371, 223, 35, 332, 279, 292, 33, 292, 35, 59, + /* 360 */ 20, 20, 287, 22, 354, 284, 115, 256, 347, 348, + /* 370 */ 349, 105, 351, 292, 284, 354, 35, 367, 297, 56, + /* 380 */ 299, 371, 292, 66, 20, 119, 120, 59, 367, 66, + /* 390 */ 256, 50, 371, 21, 313, 223, 24, 25, 26, 27, + /* 400 */ 28, 29, 30, 31, 32, 324, 83, 286, 297, 328, + /* 410 */ 329, 330, 331, 332, 333, 35, 335, 149, 297, 338, + /* 420 */ 330, 242, 105, 342, 343, 174, 175, 59, 105, 178, + /* 430 */ 164, 297, 166, 8, 9, 354, 21, 12, 13, 14, + /* 440 */ 15, 16, 119, 120, 323, 324, 66, 83, 367, 34, + /* 450 */ 256, 36, 371, 14, 20, 35, 335, 191, 192, 20, + /* 460 */ 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, + /* 470 */ 204, 205, 206, 207, 208, 209, 210, 1, 2, 264, + /* 480 */ 0, 164, 264, 166, 264, 264, 66, 164, 283, 166, + /* 490 */ 266, 297, 326, 275, 0, 275, 228, 229, 8, 9, + /* 500 */ 37, 296, 12, 13, 14, 15, 16, 292, 191, 192, + /* 510 */ 292, 287, 292, 292, 191, 192, 350, 194, 195, 196, + /* 520 */ 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, + /* 530 */ 207, 208, 209, 210, 12, 13, 14, 264, 14, 15, + /* 540 */ 16, 47, 20, 256, 22, 264, 223, 332, 275, 86, + /* 550 */ 60, 88, 89, 332, 91, 33, 275, 35, 95, 276, + /* 560 */ 84, 346, 347, 348, 349, 292, 351, 284, 347, 348, + /* 570 */ 349, 284, 351, 292, 84, 95, 293, 20, 56, 292, + /* 580 */ 117, 156, 92, 14, 297, 151, 299, 223, 66, 20, + /* 590 */ 83, 12, 13, 0, 114, 115, 116, 117, 118, 20, + /* 600 */ 93, 22, 8, 9, 326, 83, 12, 13, 14, 15, + /* 610 */ 16, 324, 33, 60, 35, 328, 329, 330, 331, 332, + /* 620 */ 333, 264, 335, 261, 56, 338, 264, 105, 350, 342, + /* 630 */ 343, 344, 275, 264, 195, 56, 146, 43, 309, 282, + /* 640 */ 311, 119, 120, 356, 275, 66, 264, 292, 256, 292, + /* 650 */ 82, 364, 66, 85, 264, 62, 63, 275, 303, 169, + /* 660 */ 67, 292, 83, 70, 71, 275, 20, 74, 75, 76, + /* 670 */ 245, 8, 9, 276, 292, 12, 13, 14, 15, 16, + /* 680 */ 284, 284, 292, 264, 105, 94, 164, 291, 166, 297, + /* 690 */ 293, 66, 256, 272, 275, 274, 300, 4, 119, 120, + /* 700 */ 0, 211, 212, 213, 214, 215, 216, 217, 218, 219, + /* 710 */ 220, 292, 261, 191, 192, 264, 194, 195, 196, 197, + /* 720 */ 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, + /* 730 */ 208, 209, 210, 297, 8, 9, 270, 271, 12, 13, + /* 740 */ 14, 15, 16, 164, 191, 166, 2, 84, 294, 44, + /* 750 */ 45, 297, 8, 9, 284, 2, 12, 13, 14, 15, + /* 760 */ 16, 8, 9, 293, 195, 12, 13, 14, 15, 16, + /* 770 */ 191, 192, 3, 194, 195, 196, 197, 198, 199, 200, + /* 780 */ 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, + /* 790 */ 12, 13, 18, 20, 20, 95, 19, 151, 20, 256, + /* 800 */ 22, 27, 285, 146, 30, 256, 256, 256, 264, 264, + /* 810 */ 33, 33, 256, 35, 114, 115, 116, 117, 118, 275, + /* 820 */ 275, 47, 256, 49, 47, 51, 169, 284, 39, 52, + /* 830 */ 53, 54, 55, 56, 56, 292, 292, 292, 264, 256, + /* 840 */ 297, 264, 299, 276, 66, 285, 297, 297, 297, 275, + /* 850 */ 43, 284, 275, 297, 299, 294, 82, 43, 297, 82, + /* 860 */ 293, 83, 85, 297, 326, 310, 292, 324, 211, 292, + /* 870 */ 95, 328, 329, 330, 331, 332, 333, 151, 335, 256, + /* 880 */ 297, 338, 256, 105, 256, 342, 343, 277, 350, 256, + /* 890 */ 280, 84, 117, 221, 222, 118, 122, 119, 120, 125, + /* 900 */ 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, + /* 910 */ 136, 137, 138, 139, 140, 141, 142, 224, 144, 145, + /* 920 */ 297, 256, 256, 297, 284, 297, 18, 150, 8, 9, + /* 930 */ 297, 23, 12, 13, 14, 15, 16, 42, 43, 0, + /* 940 */ 300, 285, 164, 264, 166, 37, 38, 285, 171, 41, + /* 950 */ 173, 8, 9, 256, 275, 12, 13, 14, 15, 16, + /* 960 */ 285, 22, 297, 297, 256, 57, 58, 0, 195, 191, + /* 970 */ 192, 292, 194, 195, 196, 197, 198, 199, 200, 201, + /* 980 */ 202, 203, 204, 205, 206, 207, 208, 209, 210, 22, + /* 990 */ 87, 83, 284, 90, 297, 264, 87, 264, 87, 90, + /* 1000 */ 292, 90, 0, 60, 84, 297, 275, 299, 275, 240, + /* 1010 */ 87, 222, 43, 90, 43, 56, 151, 152, 43, 43, + /* 1020 */ 46, 43, 35, 292, 22, 292, 43, 1, 2, 121, + /* 1030 */ 285, 285, 324, 35, 317, 92, 328, 329, 330, 331, + /* 1040 */ 332, 333, 256, 335, 85, 257, 338, 119, 120, 43, + /* 1050 */ 342, 343, 344, 84, 273, 84, 374, 83, 244, 84, + /* 1060 */ 84, 43, 84, 43, 156, 157, 158, 84, 43, 161, + /* 1070 */ 284, 365, 364, 265, 320, 167, 361, 284, 292, 43, + /* 1080 */ 265, 43, 43, 297, 0, 299, 43, 263, 180, 146, + /* 1090 */ 84, 183, 296, 185, 186, 187, 188, 189, 190, 327, + /* 1100 */ 352, 345, 84, 368, 84, 368, 368, 355, 288, 84, + /* 1110 */ 324, 83, 169, 225, 328, 329, 330, 331, 332, 333, + /* 1120 */ 84, 335, 84, 84, 338, 12, 13, 84, 342, 343, + /* 1130 */ 344, 223, 48, 322, 20, 22, 264, 47, 321, 353, + /* 1140 */ 256, 35, 162, 270, 315, 264, 33, 264, 35, 42, + /* 1150 */ 304, 33, 302, 166, 211, 212, 213, 214, 215, 216, + /* 1160 */ 217, 218, 219, 220, 166, 47, 256, 146, 284, 56, + /* 1170 */ 52, 53, 54, 55, 56, 20, 292, 4, 302, 66, + /* 1180 */ 264, 297, 264, 299, 258, 258, 20, 319, 299, 268, + /* 1190 */ 268, 20, 19, 314, 284, 20, 20, 312, 268, 312, + /* 1200 */ 82, 268, 292, 85, 305, 268, 33, 297, 324, 299, + /* 1210 */ 268, 264, 328, 329, 330, 331, 332, 333, 105, 335, + /* 1220 */ 47, 268, 338, 258, 51, 284, 342, 343, 344, 56, + /* 1230 */ 284, 297, 284, 256, 324, 284, 284, 353, 328, 329, + /* 1240 */ 330, 331, 332, 333, 284, 335, 284, 284, 338, 264, + /* 1250 */ 284, 258, 342, 343, 344, 82, 284, 284, 85, 319, + /* 1260 */ 266, 284, 318, 353, 172, 147, 148, 299, 150, 292, + /* 1270 */ 266, 264, 154, 264, 297, 230, 299, 164, 266, 166, + /* 1280 */ 148, 297, 312, 297, 292, 297, 256, 308, 297, 308, + /* 1290 */ 313, 173, 297, 266, 280, 306, 256, 266, 20, 231, + /* 1300 */ 292, 324, 305, 237, 191, 328, 329, 330, 331, 332, + /* 1310 */ 333, 308, 335, 297, 284, 202, 203, 204, 205, 206, + /* 1320 */ 207, 208, 292, 327, 284, 308, 297, 297, 239, 299, + /* 1330 */ 297, 354, 292, 155, 297, 238, 226, 297, 297, 299, + /* 1340 */ 292, 222, 360, 313, 367, 322, 20, 243, 371, 241, + /* 1350 */ 360, 256, 83, 288, 324, 246, 297, 358, 328, 329, + /* 1360 */ 330, 331, 332, 333, 324, 335, 264, 256, 328, 329, + /* 1370 */ 330, 331, 332, 333, 363, 335, 357, 362, 338, 284, + /* 1380 */ 326, 359, 342, 343, 354, 375, 274, 292, 341, 266, + /* 1390 */ 36, 258, 297, 369, 299, 284, 259, 367, 316, 311, + /* 1400 */ 278, 371, 360, 292, 370, 370, 278, 278, 297, 267, + /* 1410 */ 299, 254, 0, 369, 174, 0, 370, 256, 369, 324, + /* 1420 */ 0, 0, 42, 328, 329, 330, 331, 332, 333, 334, + /* 1430 */ 335, 336, 337, 256, 74, 324, 0, 184, 35, 328, + /* 1440 */ 329, 330, 331, 332, 333, 284, 335, 184, 35, 35, + /* 1450 */ 0, 35, 35, 292, 35, 184, 0, 184, 297, 0, + /* 1460 */ 299, 284, 35, 0, 22, 0, 289, 35, 0, 292, + /* 1470 */ 83, 169, 168, 166, 297, 256, 299, 164, 0, 0, + /* 1480 */ 160, 159, 0, 372, 373, 324, 0, 46, 0, 328, + /* 1490 */ 329, 330, 331, 332, 333, 256, 335, 0, 0, 338, + /* 1500 */ 143, 324, 0, 284, 343, 328, 329, 330, 331, 332, + /* 1510 */ 333, 292, 335, 0, 0, 0, 297, 0, 299, 138, + /* 1520 */ 35, 0, 138, 284, 0, 0, 0, 0, 289, 0, + /* 1530 */ 0, 292, 42, 0, 0, 0, 297, 0, 299, 0, + /* 1540 */ 0, 0, 0, 324, 0, 0, 0, 328, 329, 330, + /* 1550 */ 331, 332, 333, 256, 335, 0, 0, 0, 22, 0, + /* 1560 */ 0, 0, 0, 324, 0, 256, 56, 328, 329, 330, + /* 1570 */ 331, 332, 333, 0, 335, 256, 0, 14, 0, 14, + /* 1580 */ 42, 284, 39, 0, 0, 366, 0, 0, 40, 292, + /* 1590 */ 43, 39, 155, 284, 297, 46, 299, 46, 289, 0, + /* 1600 */ 0, 292, 0, 284, 0, 39, 297, 35, 299, 39, + /* 1610 */ 0, 292, 35, 39, 47, 61, 297, 0, 299, 39, + /* 1620 */ 35, 324, 47, 0, 0, 328, 329, 330, 331, 332, + /* 1630 */ 333, 35, 335, 324, 0, 256, 47, 328, 329, 330, + /* 1640 */ 331, 332, 333, 324, 335, 47, 39, 328, 329, 330, + /* 1650 */ 331, 332, 333, 0, 335, 0, 337, 35, 256, 90, + /* 1660 */ 92, 22, 0, 284, 35, 35, 35, 35, 289, 43, + /* 1670 */ 373, 292, 35, 35, 0, 35, 297, 0, 299, 43, + /* 1680 */ 22, 22, 49, 0, 35, 22, 284, 0, 0, 35, + /* 1690 */ 0, 289, 35, 22, 292, 20, 0, 0, 170, 297, + /* 1700 */ 256, 299, 35, 324, 22, 0, 148, 328, 329, 330, + /* 1710 */ 331, 332, 333, 0, 335, 0, 0, 256, 83, 0, + /* 1720 */ 0, 93, 151, 0, 39, 84, 324, 83, 284, 179, + /* 1730 */ 328, 329, 330, 331, 332, 333, 292, 335, 46, 151, + /* 1740 */ 84, 297, 151, 299, 83, 284, 153, 43, 83, 227, + /* 1750 */ 149, 83, 147, 292, 84, 83, 46, 84, 297, 83, + /* 1760 */ 299, 22, 84, 83, 43, 84, 35, 256, 324, 83, + /* 1770 */ 43, 46, 328, 329, 330, 331, 332, 333, 83, 335, + /* 1780 */ 43, 83, 46, 84, 84, 324, 43, 46, 256, 328, + /* 1790 */ 329, 330, 331, 332, 333, 284, 335, 46, 84, 43, + /* 1800 */ 35, 84, 221, 292, 35, 35, 227, 35, 297, 256, + /* 1810 */ 299, 35, 2, 83, 43, 83, 284, 227, 191, 84, + /* 1820 */ 46, 46, 84, 83, 292, 22, 84, 94, 83, 297, + /* 1830 */ 83, 299, 83, 35, 84, 324, 193, 284, 83, 328, + /* 1840 */ 329, 330, 331, 332, 333, 292, 335, 35, 84, 35, + /* 1850 */ 297, 256, 299, 35, 35, 35, 324, 84, 22, 107, + /* 1860 */ 328, 329, 330, 331, 332, 333, 83, 335, 256, 83, + /* 1870 */ 107, 84, 83, 107, 84, 83, 95, 324, 83, 284, + /* 1880 */ 83, 328, 329, 330, 331, 332, 333, 292, 335, 107, + /* 1890 */ 35, 83, 297, 43, 299, 22, 284, 66, 61, 60, + /* 1900 */ 35, 43, 81, 35, 292, 35, 35, 35, 22, 297, + /* 1910 */ 35, 299, 35, 35, 66, 35, 35, 35, 35, 324, + /* 1920 */ 256, 47, 35, 328, 329, 330, 331, 332, 333, 35, + /* 1930 */ 335, 35, 0, 35, 39, 0, 324, 35, 47, 39, + /* 1940 */ 328, 329, 330, 331, 332, 333, 0, 335, 284, 35, + /* 1950 */ 47, 39, 0, 35, 47, 39, 292, 0, 35, 35, + /* 1960 */ 0, 297, 22, 299, 21, 376, 22, 22, 21, 20, + /* 1970 */ 376, 376, 376, 376, 256, 376, 376, 376, 376, 376, + /* 1980 */ 376, 376, 376, 376, 376, 376, 376, 376, 324, 376, + /* 1990 */ 256, 376, 328, 329, 330, 331, 332, 333, 376, 335, + /* 2000 */ 256, 376, 284, 376, 376, 376, 376, 376, 376, 376, + /* 2010 */ 292, 376, 376, 376, 376, 297, 376, 299, 284, 376, + /* 2020 */ 376, 376, 376, 376, 376, 376, 292, 376, 284, 376, + /* 2030 */ 376, 297, 376, 299, 376, 376, 292, 376, 376, 376, + /* 2040 */ 376, 297, 324, 299, 376, 376, 328, 329, 330, 331, + /* 2050 */ 332, 333, 256, 335, 376, 376, 376, 376, 324, 376, + /* 2060 */ 376, 376, 328, 329, 330, 331, 332, 333, 324, 335, + /* 2070 */ 376, 376, 328, 329, 330, 331, 332, 333, 376, 335, + /* 2080 */ 284, 376, 376, 376, 376, 376, 376, 376, 292, 376, + /* 2090 */ 376, 376, 376, 297, 256, 299, 376, 376, 376, 376, + /* 2100 */ 376, 376, 376, 376, 376, 376, 376, 376, 256, 376, + /* 2110 */ 376, 376, 376, 376, 376, 376, 376, 376, 256, 376, + /* 2120 */ 324, 376, 284, 376, 328, 329, 330, 331, 332, 333, + /* 2130 */ 292, 335, 376, 376, 376, 297, 284, 299, 376, 376, + /* 2140 */ 376, 376, 376, 376, 292, 376, 284, 376, 376, 297, + /* 2150 */ 376, 299, 376, 376, 292, 376, 376, 376, 376, 297, + /* 2160 */ 376, 299, 324, 376, 376, 376, 328, 329, 330, 331, + /* 2170 */ 332, 333, 376, 335, 376, 376, 324, 256, 376, 376, + /* 2180 */ 328, 329, 330, 331, 332, 333, 324, 335, 376, 376, + /* 2190 */ 328, 329, 330, 331, 332, 333, 376, 335, 256, 376, + /* 2200 */ 376, 376, 376, 376, 376, 284, 376, 376, 376, 376, + /* 2210 */ 376, 376, 376, 292, 376, 376, 376, 376, 297, 376, + /* 2220 */ 299, 376, 376, 376, 376, 376, 284, 376, 376, 376, + /* 2230 */ 376, 376, 376, 376, 292, 376, 376, 376, 376, 297, + /* 2240 */ 376, 299, 376, 376, 376, 324, 376, 376, 376, 328, + /* 2250 */ 329, 330, 331, 332, 333, 376, 335, 256, 376, 376, + /* 2260 */ 376, 376, 376, 376, 376, 376, 324, 256, 376, 376, + /* 2270 */ 328, 329, 330, 331, 332, 333, 376, 335, 376, 376, + /* 2280 */ 376, 376, 376, 256, 376, 284, 376, 376, 376, 376, + /* 2290 */ 376, 376, 376, 292, 376, 284, 376, 376, 297, 376, + /* 2300 */ 299, 376, 376, 292, 376, 376, 376, 376, 297, 376, + /* 2310 */ 299, 284, 376, 376, 376, 376, 376, 376, 376, 292, + /* 2320 */ 376, 376, 376, 376, 297, 324, 299, 376, 376, 328, + /* 2330 */ 329, 330, 331, 332, 333, 324, 335, 376, 376, 328, + /* 2340 */ 329, 330, 331, 332, 333, 376, 335, 376, 376, 376, + /* 2350 */ 376, 324, 376, 376, 376, 328, 329, 330, 331, 332, + /* 2360 */ 333, 376, 335, }; -#define YY_SHIFT_COUNT (652) +#define YY_SHIFT_COUNT (660) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1814) +#define YY_SHIFT_MAX (1960) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 891, 0, 0, 57, 57, 254, 254, 254, 311, 311, - /* 10 */ 254, 254, 508, 565, 762, 565, 565, 565, 565, 565, - /* 20 */ 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, - /* 30 */ 565, 565, 565, 565, 565, 565, 565, 565, 565, 565, - /* 40 */ 565, 565, 565, 64, 64, 29, 29, 29, 1187, 1187, - /* 50 */ 1187, 54, 95, 247, 40, 40, 165, 165, 317, 106, - /* 60 */ 247, 247, 40, 40, 40, 40, 40, 40, 40, 40, - /* 70 */ 6, 40, 40, 40, 48, 127, 40, 40, 127, 152, - /* 80 */ 40, 127, 127, 127, 40, 122, 758, 223, 477, 477, - /* 90 */ 13, 409, 839, 839, 839, 839, 839, 839, 839, 839, - /* 100 */ 839, 839, 839, 839, 839, 839, 839, 839, 839, 839, - /* 110 */ 839, 196, 106, 325, 325, 75, 80, 365, 633, 633, - /* 120 */ 633, 80, 209, 48, 273, 273, 127, 127, 277, 277, - /* 130 */ 321, 380, 252, 252, 252, 252, 252, 252, 252, 131, - /* 140 */ 717, 533, 374, 233, 138, 67, 143, 124, 199, 476, - /* 150 */ 596, 1, 776, 603, 570, 603, 783, 581, 581, 581, - /* 160 */ 619, 786, 862, 1067, 1044, 1068, 945, 1067, 1067, 1073, - /* 170 */ 973, 973, 1067, 1103, 1103, 1109, 6, 48, 6, 1114, - /* 180 */ 1118, 6, 1114, 6, 1125, 6, 6, 1067, 6, 1103, - /* 190 */ 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, - /* 200 */ 127, 1067, 1103, 277, 1109, 122, 992, 48, 122, 1067, - /* 210 */ 1067, 1114, 122, 982, 277, 277, 277, 277, 982, 277, - /* 220 */ 1066, 209, 1125, 122, 321, 122, 209, 1222, 277, 1018, - /* 230 */ 982, 277, 277, 1018, 982, 277, 277, 127, 1027, 1102, - /* 240 */ 1018, 1026, 1028, 1041, 862, 1046, 209, 1248, 1029, 1030, - /* 250 */ 1034, 1029, 1030, 1029, 1030, 1189, 1197, 277, 380, 1067, - /* 260 */ 122, 1268, 1103, 2609, 2609, 2609, 2609, 2609, 2609, 2609, - /* 270 */ 334, 502, 268, 520, 412, 623, 648, 903, 981, 838, - /* 280 */ 710, 431, 855, 855, 855, 855, 855, 855, 855, 855, - /* 290 */ 920, 698, 14, 14, 164, 439, 25, 147, 699, 564, - /* 300 */ 486, 656, 364, 364, 364, 364, 756, 867, 769, 835, - /* 310 */ 848, 849, 931, 984, 986, 443, 679, 893, 899, 932, - /* 320 */ 949, 955, 956, 781, 842, 957, 906, 804, 638, 736, - /* 330 */ 960, 880, 962, 895, 966, 970, 998, 1001, 1009, 1019, - /* 340 */ 972, 1021, 1024, 1324, 1331, 1290, 1333, 1262, 1336, 1302, - /* 350 */ 1155, 1307, 1318, 1321, 1174, 1364, 1334, 1343, 1185, 1379, - /* 360 */ 1198, 1380, 1348, 1385, 1372, 1386, 1363, 1399, 1320, 1232, - /* 370 */ 1237, 1240, 1243, 1407, 1411, 1253, 1256, 1415, 1416, 1371, - /* 380 */ 1418, 1419, 1420, 1279, 1422, 1423, 1425, 1426, 1427, 1291, - /* 390 */ 1394, 1430, 1294, 1432, 1433, 1434, 1436, 1437, 1438, 1447, - /* 400 */ 1448, 1450, 1451, 1455, 1456, 1457, 1458, 1417, 1461, 1462, - /* 410 */ 1463, 1464, 1466, 1468, 1449, 1469, 1470, 1472, 1482, 1483, - /* 420 */ 1484, 1435, 1439, 1431, 1465, 1429, 1471, 1441, 1476, 1440, - /* 430 */ 1452, 1489, 1490, 1502, 1454, 1340, 1495, 1504, 1507, 1467, - /* 440 */ 1508, 1509, 1477, 1481, 1475, 1515, 1494, 1485, 1491, 1516, - /* 450 */ 1496, 1487, 1497, 1535, 1503, 1492, 1498, 1540, 1542, 1543, - /* 460 */ 1544, 1459, 1460, 1510, 1525, 1551, 1517, 1518, 1519, 1520, - /* 470 */ 1513, 1514, 1523, 1524, 1527, 1560, 1541, 1564, 1545, 1521, - /* 480 */ 1565, 1546, 1531, 1569, 1536, 1572, 1539, 1575, 1554, 1566, - /* 490 */ 1585, 1442, 1552, 1588, 1421, 1571, 1444, 1453, 1591, 1595, - /* 500 */ 1446, 1473, 1598, 1599, 1601, 1526, 1522, 1428, 1603, 1528, - /* 510 */ 1479, 1530, 1607, 1570, 1486, 1532, 1538, 1567, 1574, 1390, - /* 520 */ 1549, 1537, 1557, 1558, 1559, 1563, 1596, 1580, 1582, 1568, - /* 530 */ 1579, 1581, 1583, 1604, 1600, 1606, 1586, 1610, 1403, 1584, - /* 540 */ 1587, 1608, 1478, 1626, 1625, 1627, 1592, 1631, 1424, 1593, - /* 550 */ 1643, 1646, 1647, 1648, 1649, 1651, 1593, 1677, 1499, 1650, - /* 560 */ 1609, 1611, 1613, 1615, 1614, 1616, 1655, 1621, 1622, 1656, - /* 570 */ 1667, 1533, 1624, 1597, 1628, 1673, 1674, 1632, 1630, 1675, - /* 580 */ 1633, 1639, 1690, 1645, 1652, 1691, 1660, 1661, 1693, 1663, - /* 590 */ 1640, 1641, 1653, 1654, 1708, 1637, 1668, 1669, 1698, 1670, - /* 600 */ 1710, 1710, 1712, 1689, 1695, 1720, 1696, 1676, 1715, 1728, - /* 610 */ 1729, 1731, 1732, 1733, 1747, 1736, 1738, 1709, 1513, 1740, - /* 620 */ 1514, 1742, 1743, 1744, 1745, 1748, 1750, 1782, 1751, 1741, - /* 630 */ 1753, 1787, 1755, 1746, 1756, 1794, 1761, 1752, 1759, 1800, - /* 640 */ 1772, 1762, 1771, 1811, 1777, 1778, 1814, 1793, 1797, 1804, - /* 650 */ 1806, 1798, 1810, + /* 0 */ 908, 0, 0, 67, 67, 266, 266, 266, 323, 323, + /* 10 */ 266, 266, 522, 579, 778, 579, 579, 579, 579, 579, + /* 20 */ 579, 579, 579, 579, 579, 579, 579, 579, 579, 579, + /* 30 */ 579, 579, 579, 579, 579, 579, 579, 579, 579, 579, + /* 40 */ 579, 579, 579, 364, 364, 8, 8, 8, 1113, 1113, + /* 50 */ 1113, 128, 172, 31, 31, 154, 154, 93, 93, 64, + /* 60 */ 70, 31, 31, 154, 154, 154, 154, 154, 154, 154, + /* 70 */ 154, 154, 16, 154, 154, 154, 240, 322, 154, 154, + /* 80 */ 322, 340, 154, 322, 322, 322, 154, 368, 774, 490, + /* 90 */ 943, 943, 372, 55, 317, 317, 317, 317, 317, 317, + /* 100 */ 317, 317, 317, 317, 317, 317, 317, 317, 317, 317, + /* 110 */ 317, 317, 317, 463, 70, 12, 12, 300, 380, 328, + /* 120 */ 434, 434, 434, 380, 557, 240, 5, 5, 322, 322, + /* 130 */ 586, 586, 591, 625, 206, 206, 206, 206, 206, 206, + /* 140 */ 206, 777, 23, 593, 425, 48, 341, 251, 268, 439, + /* 150 */ 569, 51, 705, 775, 646, 672, 789, 672, 895, 769, + /* 160 */ 769, 769, 693, 773, 1028, 888, 1114, 1090, 1106, 980, + /* 170 */ 1114, 1114, 1107, 1021, 1021, 1114, 1114, 1155, 1155, 1166, + /* 180 */ 16, 240, 16, 1171, 1175, 16, 1171, 16, 1176, 16, + /* 190 */ 16, 1114, 16, 1155, 322, 322, 322, 322, 322, 322, + /* 200 */ 322, 322, 322, 322, 322, 1114, 1155, 586, 1166, 368, + /* 210 */ 1092, 240, 368, 1114, 1114, 1171, 368, 1045, 586, 586, + /* 220 */ 586, 586, 1045, 586, 1132, 557, 1176, 368, 591, 368, + /* 230 */ 557, 1278, 586, 1068, 1045, 586, 586, 1068, 1045, 586, + /* 240 */ 586, 322, 1066, 1178, 1068, 1089, 1097, 1110, 888, 1119, + /* 250 */ 557, 1326, 1104, 1108, 1109, 1104, 1108, 1104, 1108, 1269, + /* 260 */ 1028, 586, 625, 1114, 368, 1354, 1155, 2363, 2363, 2363, + /* 270 */ 2363, 2363, 2363, 2363, 173, 1118, 188, 1173, 143, 594, + /* 280 */ 663, 744, 753, 726, 920, 480, 2, 2, 2, 2, + /* 290 */ 2, 2, 2, 2, 700, 53, 26, 26, 46, 139, + /* 300 */ 568, 106, 415, 118, 476, 657, 524, 524, 524, 524, + /* 310 */ 494, 246, 903, 909, 911, 923, 939, 967, 1002, 959, + /* 320 */ 865, 807, 969, 971, 975, 976, 978, 987, 998, 983, + /* 330 */ 1026, 928, 179, 814, 1006, 553, 1018, 974, 1020, 1025, + /* 340 */ 1036, 1038, 1039, 1043, 507, 420, 1084, 1412, 1240, 1415, + /* 350 */ 1420, 1380, 1421, 1360, 1436, 1403, 1253, 1413, 1414, 1416, + /* 360 */ 1263, 1450, 1417, 1419, 1271, 1456, 1273, 1459, 1427, 1463, + /* 370 */ 1442, 1465, 1432, 1468, 1387, 1302, 1304, 1307, 1313, 1478, + /* 380 */ 1479, 1320, 1322, 1482, 1486, 1441, 1488, 1497, 1498, 1357, + /* 390 */ 1502, 1513, 1514, 1515, 1517, 1381, 1485, 1521, 1384, 1524, + /* 400 */ 1525, 1526, 1527, 1529, 1530, 1537, 1539, 1540, 1541, 1542, + /* 410 */ 1544, 1545, 1546, 1490, 1533, 1534, 1535, 1555, 1556, 1557, + /* 420 */ 1536, 1559, 1560, 1561, 1562, 1564, 1510, 1573, 1576, 1538, + /* 430 */ 1543, 1547, 1563, 1549, 1565, 1551, 1578, 1548, 1552, 1583, + /* 440 */ 1584, 1586, 1566, 1437, 1587, 1599, 1600, 1554, 1602, 1604, + /* 450 */ 1572, 1567, 1570, 1610, 1577, 1575, 1574, 1617, 1585, 1589, + /* 460 */ 1580, 1623, 1596, 1598, 1607, 1624, 1634, 1653, 1655, 1568, + /* 470 */ 1569, 1622, 1639, 1662, 1629, 1630, 1631, 1632, 1626, 1636, + /* 480 */ 1637, 1638, 1640, 1674, 1658, 1677, 1659, 1633, 1683, 1663, + /* 490 */ 1649, 1687, 1654, 1688, 1657, 1690, 1671, 1675, 1696, 1571, + /* 500 */ 1667, 1697, 1528, 1682, 1588, 1558, 1705, 1713, 1591, 1593, + /* 510 */ 1715, 1716, 1723, 1635, 1641, 1550, 1719, 1644, 1601, 1661, + /* 520 */ 1720, 1685, 1605, 1665, 1628, 1692, 1704, 1522, 1668, 1656, + /* 530 */ 1672, 1670, 1673, 1676, 1739, 1721, 1678, 1680, 1686, 1695, + /* 540 */ 1681, 1727, 1710, 1725, 1698, 1737, 1579, 1699, 1700, 1736, + /* 550 */ 1581, 1743, 1741, 1751, 1714, 1756, 1590, 1717, 1731, 1765, + /* 560 */ 1769, 1770, 1772, 1776, 1717, 1810, 1627, 1771, 1730, 1735, + /* 570 */ 1732, 1738, 1740, 1742, 1774, 1745, 1747, 1775, 1803, 1643, + /* 580 */ 1749, 1733, 1750, 1798, 1812, 1755, 1764, 1814, 1783, 1773, + /* 590 */ 1818, 1786, 1787, 1819, 1789, 1790, 1820, 1792, 1752, 1763, + /* 600 */ 1766, 1782, 1836, 1781, 1795, 1797, 1855, 1808, 1850, 1850, + /* 610 */ 1873, 1837, 1839, 1865, 1831, 1821, 1858, 1868, 1870, 1871, + /* 620 */ 1872, 1875, 1886, 1877, 1878, 1848, 1626, 1880, 1636, 1881, + /* 630 */ 1882, 1883, 1887, 1894, 1896, 1932, 1898, 1874, 1895, 1935, + /* 640 */ 1902, 1891, 1900, 1946, 1914, 1903, 1912, 1952, 1918, 1907, + /* 650 */ 1916, 1957, 1923, 1924, 1960, 1940, 1943, 1944, 1945, 1947, + /* 660 */ 1949, }; -#define YY_REDUCE_COUNT (269) -#define YY_REDUCE_MIN (-349) -#define YY_REDUCE_MAX (2274) +#define YY_REDUCE_COUNT (273) +#define YY_REDUCE_MIN (-295) +#define YY_REDUCE_MAX (2027) static const short yy_reduce_ofst[] = { - /* 0 */ -246, -200, 689, 767, 828, 845, 898, 953, 1031, 1043, - /* 10 */ 1112, 1169, 1190, 1250, 1306, 1328, 1389, 1017, 1409, 1474, - /* 20 */ 1493, 1562, 1578, 1620, 1644, 1686, 1706, 1766, 1790, 1846, - /* 30 */ 1870, 1912, 1928, 1970, 1990, 2050, 2074, 2130, 2154, 2196, - /* 40 */ 2212, 2254, 2274, -245, 490, -191, -120, -20, -271, -249, - /* 50 */ -235, -218, 222, 258, 41, 44, -259, -254, -349, -240, - /* 60 */ -277, -256, 46, 103, 206, 288, 298, 300, 319, 342, - /* 70 */ -257, 351, 355, 391, -64, -101, 405, 517, -11, -267, - /* 80 */ 526, 248, 360, 267, 557, 216, -252, -171, -171, -171, - /* 90 */ -176, -253, 47, 85, 120, 379, 389, 403, 425, 481, - /* 100 */ 532, 539, 549, 577, 579, 604, 607, 617, 651, 675, - /* 110 */ 678, -133, 87, -46, 45, -258, 203, 295, 93, 327, - /* 120 */ 402, 296, 376, 501, 305, 362, 550, 297, 78, 436, - /* 130 */ 458, 479, -283, 193, 253, 514, 573, 592, 661, 236, - /* 140 */ 530, 668, 576, 485, 727, 662, 650, 742, 742, 763, - /* 150 */ 798, 766, 740, 716, 716, 716, 724, 704, 707, 713, - /* 160 */ 728, 742, 768, 825, 773, 836, 793, 850, 851, 813, - /* 170 */ 816, 819, 858, 868, 870, 814, 864, 837, 866, 826, - /* 180 */ 827, 872, 831, 877, 843, 879, 881, 886, 883, 897, - /* 190 */ 869, 878, 884, 900, 901, 902, 907, 909, 910, 912, - /* 200 */ 915, 917, 921, 905, 846, 937, 887, 908, 938, 942, - /* 210 */ 944, 904, 946, 859, 916, 918, 922, 923, 924, 927, - /* 220 */ 911, 926, 929, 959, 958, 969, 947, 919, 950, 889, - /* 230 */ 948, 961, 963, 894, 951, 964, 965, 742, 892, 913, - /* 240 */ 914, 930, 935, 933, 954, 716, 976, 952, 928, 925, - /* 250 */ 936, 934, 939, 940, 943, 977, 1012, 1005, 1033, 1039, - /* 260 */ 1047, 1058, 1061, 1004, 1010, 1048, 1051, 1053, 1055, 1070, + /* 0 */ -192, -189, 81, 287, 708, 786, 884, 910, 977, 1030, + /* 10 */ 543, 1040, 1095, 1111, 1161, 1177, 1239, 1219, 1297, 1309, + /* 20 */ 1319, 1379, 1402, 1444, 1461, 1511, 1532, 1553, 1595, 1612, + /* 30 */ 1664, 1718, 1734, 1744, 1796, 1838, 1852, 1862, 1921, 1942, + /* 40 */ 2001, 2011, 2027, -255, 21, 215, -263, 221, -261, -278, + /* 50 */ 121, -289, -23, -21, 10, 65, 357, -260, -256, -295, + /* 60 */ -268, -239, -191, 63, 218, 220, 273, 281, 369, 382, + /* 70 */ 390, 419, -247, 544, 545, 574, -201, 283, 577, 679, + /* 80 */ -107, 90, 731, 397, 396, 567, 733, 75, -194, -114, + /* 90 */ -114, -114, -144, -88, -152, 111, 134, 194, 392, 436, + /* 100 */ 549, 550, 551, 556, 566, 583, 623, 626, 628, 633, + /* 110 */ 665, 666, 697, 205, -2, 362, 451, -34, 54, 224, + /* 120 */ 166, 278, 538, 466, 355, 555, -175, 329, 470, 640, + /* 130 */ 454, 561, 610, 421, 517, 560, 656, 662, 675, 745, + /* 140 */ 746, 717, 788, 781, 682, 706, 808, 754, 715, 793, + /* 150 */ 793, 815, 824, 796, 772, 748, 748, 748, 756, 735, + /* 160 */ 737, 738, 752, 793, 820, 811, 872, 817, 873, 829, + /* 170 */ 881, 883, 846, 850, 876, 916, 918, 926, 927, 868, + /* 180 */ 921, 889, 922, 885, 879, 930, 887, 933, 899, 937, + /* 190 */ 942, 947, 953, 965, 941, 946, 948, 951, 952, 960, + /* 200 */ 962, 963, 966, 972, 973, 985, 993, 934, 940, 994, + /* 210 */ 944, 968, 1004, 1007, 1009, 970, 1012, 979, 984, 986, + /* 220 */ 988, 991, 981, 995, 989, 992, 997, 1027, 1014, 1031, + /* 230 */ 1008, 996, 1016, 982, 1003, 1029, 1033, 990, 1017, 1037, + /* 240 */ 1041, 793, 1011, 1015, 1042, 1022, 999, 1019, 1023, 748, + /* 250 */ 1048, 1054, 1034, 1024, 1010, 1035, 1044, 1046, 1049, 1047, + /* 260 */ 1065, 1059, 1112, 1102, 1123, 1137, 1133, 1082, 1088, 1122, + /* 270 */ 1128, 1129, 1142, 1157, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 10 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 20 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 30 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 40 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 50 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 60 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 70 */ 1509, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 80 */ 1437, 1437, 1437, 1437, 1437, 1507, 1660, 1437, 1836, 1437, - /* 90 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 100 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 110 */ 1437, 1437, 1437, 1437, 1437, 1509, 1437, 1507, 1848, 1848, - /* 120 */ 1848, 1437, 1437, 1437, 1704, 1704, 1437, 1437, 1437, 1437, - /* 130 */ 1603, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1696, - /* 140 */ 1437, 1437, 1917, 1437, 1437, 1702, 1871, 1437, 1437, 1437, - /* 150 */ 1437, 1556, 1863, 1840, 1854, 1841, 1838, 1902, 1902, 1902, - /* 160 */ 1857, 1437, 1867, 1437, 1437, 1437, 1688, 1437, 1437, 1665, - /* 170 */ 1662, 1662, 1437, 1437, 1437, 1437, 1509, 1437, 1509, 1437, - /* 180 */ 1437, 1509, 1437, 1509, 1437, 1509, 1509, 1437, 1509, 1437, - /* 190 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 200 */ 1437, 1437, 1437, 1437, 1437, 1507, 1698, 1437, 1507, 1437, - /* 210 */ 1437, 1437, 1507, 1876, 1437, 1437, 1437, 1437, 1876, 1437, - /* 220 */ 1437, 1437, 1437, 1507, 1437, 1507, 1437, 1437, 1437, 1878, - /* 230 */ 1876, 1437, 1437, 1878, 1876, 1437, 1437, 1437, 1890, 1886, - /* 240 */ 1878, 1894, 1892, 1869, 1867, 1854, 1437, 1437, 1908, 1904, - /* 250 */ 1920, 1908, 1904, 1908, 1904, 1437, 1572, 1437, 1437, 1437, - /* 260 */ 1507, 1469, 1437, 1690, 1704, 1606, 1606, 1606, 1510, 1442, - /* 270 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 280 */ 1437, 1437, 1774, 1889, 1888, 1812, 1811, 1810, 1808, 1773, - /* 290 */ 1437, 1568, 1772, 1771, 1437, 1437, 1437, 1437, 1437, 1437, - /* 300 */ 1437, 1437, 1765, 1766, 1764, 1763, 1437, 1437, 1437, 1437, - /* 310 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 320 */ 1437, 1437, 1437, 1437, 1437, 1437, 1837, 1437, 1905, 1909, - /* 330 */ 1437, 1437, 1437, 1748, 1437, 1437, 1437, 1437, 1437, 1437, - /* 340 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 350 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 360 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 370 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 380 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 390 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 400 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 410 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 420 */ 1437, 1437, 1437, 1474, 1437, 1437, 1437, 1437, 1437, 1437, - /* 430 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 440 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 450 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 460 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 470 */ 1537, 1536, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 480 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 490 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 500 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1708, 1437, - /* 510 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1870, 1437, - /* 520 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 530 */ 1437, 1437, 1437, 1437, 1437, 1748, 1437, 1887, 1437, 1847, - /* 540 */ 1843, 1437, 1437, 1839, 1747, 1437, 1437, 1903, 1437, 1437, - /* 550 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1832, 1437, 1805, - /* 560 */ 1790, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 570 */ 1437, 1759, 1437, 1437, 1437, 1437, 1437, 1600, 1437, 1437, - /* 580 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 590 */ 1585, 1583, 1582, 1581, 1437, 1578, 1437, 1437, 1437, 1437, - /* 600 */ 1609, 1608, 1437, 1437, 1437, 1437, 1437, 1437, 1529, 1437, - /* 610 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1520, 1437, - /* 620 */ 1519, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 630 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 640 */ 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, - /* 650 */ 1437, 1437, 1437, + /* 0 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 10 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 20 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 30 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 40 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 50 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 60 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 70 */ 1447, 1447, 1520, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 80 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1518, 1671, 1447, + /* 90 */ 1848, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 100 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 110 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1520, 1447, 1518, + /* 120 */ 1860, 1860, 1860, 1447, 1447, 1447, 1715, 1715, 1447, 1447, + /* 130 */ 1447, 1447, 1614, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 140 */ 1447, 1707, 1447, 1447, 1929, 1447, 1447, 1713, 1883, 1447, + /* 150 */ 1447, 1447, 1447, 1567, 1875, 1852, 1866, 1853, 1850, 1914, + /* 160 */ 1914, 1914, 1869, 1447, 1583, 1879, 1447, 1447, 1447, 1699, + /* 170 */ 1447, 1447, 1676, 1673, 1673, 1447, 1447, 1447, 1447, 1447, + /* 180 */ 1520, 1447, 1520, 1447, 1447, 1520, 1447, 1520, 1447, 1520, + /* 190 */ 1520, 1447, 1520, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 200 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1518, + /* 210 */ 1709, 1447, 1518, 1447, 1447, 1447, 1518, 1888, 1447, 1447, + /* 220 */ 1447, 1447, 1888, 1447, 1447, 1447, 1447, 1518, 1447, 1518, + /* 230 */ 1447, 1447, 1447, 1890, 1888, 1447, 1447, 1890, 1888, 1447, + /* 240 */ 1447, 1447, 1902, 1898, 1890, 1906, 1904, 1881, 1879, 1866, + /* 250 */ 1447, 1447, 1920, 1916, 1932, 1920, 1916, 1920, 1916, 1447, + /* 260 */ 1583, 1447, 1447, 1447, 1518, 1479, 1447, 1701, 1715, 1617, + /* 270 */ 1617, 1617, 1521, 1452, 1447, 1447, 1447, 1447, 1447, 1447, + /* 280 */ 1447, 1447, 1447, 1447, 1447, 1447, 1786, 1901, 1900, 1824, + /* 290 */ 1823, 1822, 1820, 1785, 1447, 1579, 1784, 1783, 1447, 1447, + /* 300 */ 1447, 1447, 1447, 1447, 1447, 1447, 1777, 1778, 1776, 1775, + /* 310 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 320 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 330 */ 1849, 1447, 1917, 1921, 1447, 1447, 1447, 1760, 1447, 1447, + /* 340 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 350 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 360 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 370 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 380 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 390 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 400 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 410 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 420 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 430 */ 1447, 1484, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 440 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 450 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 460 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 470 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1548, 1547, + /* 480 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 490 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 500 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 510 */ 1447, 1447, 1447, 1447, 1447, 1447, 1719, 1447, 1447, 1447, + /* 520 */ 1447, 1447, 1447, 1447, 1447, 1447, 1882, 1447, 1447, 1447, + /* 530 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 540 */ 1447, 1447, 1447, 1760, 1447, 1899, 1447, 1859, 1855, 1447, + /* 550 */ 1447, 1851, 1759, 1447, 1447, 1915, 1447, 1447, 1447, 1447, + /* 560 */ 1447, 1447, 1447, 1447, 1447, 1844, 1447, 1817, 1802, 1447, + /* 570 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1771, + /* 580 */ 1447, 1447, 1447, 1447, 1447, 1611, 1447, 1447, 1447, 1447, + /* 590 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1596, 1594, + /* 600 */ 1593, 1592, 1447, 1589, 1447, 1447, 1447, 1447, 1620, 1619, + /* 610 */ 1447, 1447, 1447, 1447, 1447, 1447, 1540, 1447, 1447, 1447, + /* 620 */ 1447, 1447, 1447, 1447, 1447, 1447, 1531, 1447, 1530, 1447, + /* 630 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 640 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 650 */ 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, 1447, + /* 660 */ 1447, }; /********** End of lemon-generated parsing tables *****************************/ @@ -990,6 +945,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* MNODE => nothing */ 0, /* DATABASE => nothing */ 0, /* USE => nothing */ + 0, /* FLUSH => nothing */ 0, /* IF => nothing */ 0, /* NOT => nothing */ 0, /* EXISTS => nothing */ @@ -1121,6 +1077,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* SPLIT => nothing */ 0, /* SYNCDB => nothing */ 0, /* DELETE => nothing */ + 0, /* INSERT => nothing */ 0, /* NULL => nothing */ 0, /* NK_QUESTION => nothing */ 0, /* NK_ARROW => nothing */ @@ -1178,12 +1135,11 @@ static const YYCODETYPE yyFallback[] = { 0, /* ASC => nothing */ 0, /* NULLS => nothing */ 0, /* ID => nothing */ - 245, /* NK_BITNOT => ID */ - 245, /* INSERT => ID */ - 245, /* VALUES => ID */ - 245, /* IMPORT => ID */ - 245, /* NK_SEMI => ID */ - 245, /* FILE => ID */ + 247, /* NK_BITNOT => ID */ + 247, /* VALUES => ID */ + 247, /* IMPORT => ID */ + 247, /* NK_SEMI => ID */ + 247, /* FILE => ID */ }; #endif /* YYFALLBACK */ @@ -1329,323 +1285,324 @@ static const char *const yyTokenName[] = { /* 55 */ "MNODE", /* 56 */ "DATABASE", /* 57 */ "USE", - /* 58 */ "IF", - /* 59 */ "NOT", - /* 60 */ "EXISTS", - /* 61 */ "BUFFER", - /* 62 */ "CACHELAST", - /* 63 */ "COMP", - /* 64 */ "DURATION", - /* 65 */ "NK_VARIABLE", - /* 66 */ "FSYNC", - /* 67 */ "MAXROWS", - /* 68 */ "MINROWS", - /* 69 */ "KEEP", - /* 70 */ "PAGES", - /* 71 */ "PAGESIZE", - /* 72 */ "PRECISION", - /* 73 */ "REPLICA", - /* 74 */ "STRICT", - /* 75 */ "WAL", - /* 76 */ "VGROUPS", - /* 77 */ "SINGLE_STABLE", - /* 78 */ "RETENTIONS", - /* 79 */ "SCHEMALESS", - /* 80 */ "NK_COLON", - /* 81 */ "TABLE", - /* 82 */ "NK_LP", - /* 83 */ "NK_RP", - /* 84 */ "STABLE", - /* 85 */ "ADD", - /* 86 */ "COLUMN", - /* 87 */ "MODIFY", - /* 88 */ "RENAME", - /* 89 */ "TAG", - /* 90 */ "SET", - /* 91 */ "NK_EQ", - /* 92 */ "USING", - /* 93 */ "TAGS", - /* 94 */ "COMMENT", - /* 95 */ "BOOL", - /* 96 */ "TINYINT", - /* 97 */ "SMALLINT", - /* 98 */ "INT", - /* 99 */ "INTEGER", - /* 100 */ "BIGINT", - /* 101 */ "FLOAT", - /* 102 */ "DOUBLE", - /* 103 */ "BINARY", - /* 104 */ "TIMESTAMP", - /* 105 */ "NCHAR", - /* 106 */ "UNSIGNED", - /* 107 */ "JSON", - /* 108 */ "VARCHAR", - /* 109 */ "MEDIUMBLOB", - /* 110 */ "BLOB", - /* 111 */ "VARBINARY", - /* 112 */ "DECIMAL", - /* 113 */ "MAX_DELAY", - /* 114 */ "WATERMARK", - /* 115 */ "ROLLUP", - /* 116 */ "TTL", - /* 117 */ "SMA", - /* 118 */ "FIRST", - /* 119 */ "LAST", - /* 120 */ "SHOW", - /* 121 */ "DATABASES", - /* 122 */ "TABLES", - /* 123 */ "STABLES", - /* 124 */ "MNODES", - /* 125 */ "MODULES", - /* 126 */ "QNODES", - /* 127 */ "FUNCTIONS", - /* 128 */ "INDEXES", - /* 129 */ "ACCOUNTS", - /* 130 */ "APPS", - /* 131 */ "CONNECTIONS", - /* 132 */ "LICENCE", - /* 133 */ "GRANTS", - /* 134 */ "QUERIES", - /* 135 */ "SCORES", - /* 136 */ "TOPICS", - /* 137 */ "VARIABLES", - /* 138 */ "BNODES", - /* 139 */ "SNODES", - /* 140 */ "CLUSTER", - /* 141 */ "TRANSACTIONS", - /* 142 */ "DISTRIBUTED", - /* 143 */ "CONSUMERS", - /* 144 */ "SUBSCRIPTIONS", - /* 145 */ "LIKE", - /* 146 */ "INDEX", - /* 147 */ "FUNCTION", - /* 148 */ "INTERVAL", - /* 149 */ "TOPIC", - /* 150 */ "AS", - /* 151 */ "WITH", - /* 152 */ "META", - /* 153 */ "CONSUMER", - /* 154 */ "GROUP", - /* 155 */ "DESC", - /* 156 */ "DESCRIBE", - /* 157 */ "RESET", - /* 158 */ "QUERY", - /* 159 */ "CACHE", - /* 160 */ "EXPLAIN", - /* 161 */ "ANALYZE", - /* 162 */ "VERBOSE", - /* 163 */ "NK_BOOL", - /* 164 */ "RATIO", - /* 165 */ "NK_FLOAT", - /* 166 */ "COMPACT", - /* 167 */ "VNODES", - /* 168 */ "IN", - /* 169 */ "OUTPUTTYPE", - /* 170 */ "AGGREGATE", - /* 171 */ "BUFSIZE", - /* 172 */ "STREAM", - /* 173 */ "INTO", - /* 174 */ "TRIGGER", - /* 175 */ "AT_ONCE", - /* 176 */ "WINDOW_CLOSE", - /* 177 */ "IGNORE", - /* 178 */ "EXPIRED", - /* 179 */ "KILL", - /* 180 */ "CONNECTION", - /* 181 */ "TRANSACTION", - /* 182 */ "BALANCE", - /* 183 */ "VGROUP", - /* 184 */ "MERGE", - /* 185 */ "REDISTRIBUTE", - /* 186 */ "SPLIT", - /* 187 */ "SYNCDB", - /* 188 */ "DELETE", - /* 189 */ "NULL", - /* 190 */ "NK_QUESTION", - /* 191 */ "NK_ARROW", - /* 192 */ "ROWTS", - /* 193 */ "TBNAME", - /* 194 */ "QSTARTTS", - /* 195 */ "QENDTS", - /* 196 */ "WSTARTTS", - /* 197 */ "WENDTS", - /* 198 */ "WDURATION", - /* 199 */ "CAST", - /* 200 */ "NOW", - /* 201 */ "TODAY", - /* 202 */ "TIMEZONE", - /* 203 */ "CLIENT_VERSION", - /* 204 */ "SERVER_VERSION", - /* 205 */ "SERVER_STATUS", - /* 206 */ "CURRENT_USER", - /* 207 */ "COUNT", - /* 208 */ "LAST_ROW", - /* 209 */ "BETWEEN", - /* 210 */ "IS", - /* 211 */ "NK_LT", - /* 212 */ "NK_GT", - /* 213 */ "NK_LE", - /* 214 */ "NK_GE", - /* 215 */ "NK_NE", - /* 216 */ "MATCH", - /* 217 */ "NMATCH", - /* 218 */ "CONTAINS", - /* 219 */ "JOIN", - /* 220 */ "INNER", - /* 221 */ "SELECT", - /* 222 */ "DISTINCT", - /* 223 */ "WHERE", - /* 224 */ "PARTITION", - /* 225 */ "BY", - /* 226 */ "SESSION", - /* 227 */ "STATE_WINDOW", - /* 228 */ "SLIDING", - /* 229 */ "FILL", - /* 230 */ "VALUE", - /* 231 */ "NONE", - /* 232 */ "PREV", - /* 233 */ "LINEAR", - /* 234 */ "NEXT", - /* 235 */ "HAVING", - /* 236 */ "RANGE", - /* 237 */ "EVERY", - /* 238 */ "ORDER", - /* 239 */ "SLIMIT", - /* 240 */ "SOFFSET", - /* 241 */ "LIMIT", - /* 242 */ "OFFSET", - /* 243 */ "ASC", - /* 244 */ "NULLS", - /* 245 */ "ID", - /* 246 */ "NK_BITNOT", - /* 247 */ "INSERT", - /* 248 */ "VALUES", - /* 249 */ "IMPORT", - /* 250 */ "NK_SEMI", - /* 251 */ "FILE", - /* 252 */ "cmd", - /* 253 */ "account_options", - /* 254 */ "alter_account_options", - /* 255 */ "literal", - /* 256 */ "alter_account_option", - /* 257 */ "user_name", - /* 258 */ "sysinfo_opt", - /* 259 */ "privileges", - /* 260 */ "priv_level", - /* 261 */ "priv_type_list", - /* 262 */ "priv_type", - /* 263 */ "db_name", - /* 264 */ "dnode_endpoint", - /* 265 */ "not_exists_opt", - /* 266 */ "db_options", - /* 267 */ "exists_opt", - /* 268 */ "alter_db_options", - /* 269 */ "integer_list", - /* 270 */ "variable_list", - /* 271 */ "retention_list", - /* 272 */ "alter_db_option", - /* 273 */ "retention", - /* 274 */ "full_table_name", - /* 275 */ "column_def_list", - /* 276 */ "tags_def_opt", - /* 277 */ "table_options", - /* 278 */ "multi_create_clause", - /* 279 */ "tags_def", - /* 280 */ "multi_drop_clause", - /* 281 */ "alter_table_clause", - /* 282 */ "alter_table_options", - /* 283 */ "column_name", - /* 284 */ "type_name", - /* 285 */ "signed_literal", - /* 286 */ "create_subtable_clause", - /* 287 */ "specific_tags_opt", - /* 288 */ "expression_list", - /* 289 */ "drop_table_clause", - /* 290 */ "col_name_list", - /* 291 */ "table_name", - /* 292 */ "column_def", - /* 293 */ "duration_list", - /* 294 */ "rollup_func_list", - /* 295 */ "alter_table_option", - /* 296 */ "duration_literal", - /* 297 */ "rollup_func_name", - /* 298 */ "function_name", - /* 299 */ "col_name", - /* 300 */ "db_name_cond_opt", - /* 301 */ "like_pattern_opt", - /* 302 */ "table_name_cond", - /* 303 */ "from_db_opt", - /* 304 */ "index_name", - /* 305 */ "index_options", - /* 306 */ "func_list", - /* 307 */ "sliding_opt", - /* 308 */ "sma_stream_opt", - /* 309 */ "func", - /* 310 */ "stream_options", - /* 311 */ "topic_name", - /* 312 */ "query_expression", - /* 313 */ "cgroup_name", - /* 314 */ "analyze_opt", - /* 315 */ "explain_options", - /* 316 */ "agg_func_opt", - /* 317 */ "bufsize_opt", - /* 318 */ "stream_name", - /* 319 */ "into_opt", - /* 320 */ "dnode_list", - /* 321 */ "where_clause_opt", - /* 322 */ "signed", - /* 323 */ "literal_func", - /* 324 */ "literal_list", - /* 325 */ "table_alias", - /* 326 */ "column_alias", - /* 327 */ "expression", - /* 328 */ "pseudo_column", - /* 329 */ "column_reference", - /* 330 */ "function_expression", - /* 331 */ "subquery", - /* 332 */ "star_func", - /* 333 */ "star_func_para_list", - /* 334 */ "noarg_func", - /* 335 */ "other_para_list", - /* 336 */ "star_func_para", - /* 337 */ "predicate", - /* 338 */ "compare_op", - /* 339 */ "in_op", - /* 340 */ "in_predicate_value", - /* 341 */ "boolean_value_expression", - /* 342 */ "boolean_primary", - /* 343 */ "common_expression", - /* 344 */ "from_clause_opt", - /* 345 */ "table_reference_list", - /* 346 */ "table_reference", - /* 347 */ "table_primary", - /* 348 */ "joined_table", - /* 349 */ "alias_opt", - /* 350 */ "parenthesized_joined_table", - /* 351 */ "join_type", - /* 352 */ "search_condition", - /* 353 */ "query_specification", - /* 354 */ "set_quantifier_opt", - /* 355 */ "select_list", - /* 356 */ "partition_by_clause_opt", - /* 357 */ "range_opt", - /* 358 */ "every_opt", - /* 359 */ "fill_opt", - /* 360 */ "twindow_clause_opt", - /* 361 */ "group_by_clause_opt", - /* 362 */ "having_clause_opt", - /* 363 */ "select_item", - /* 364 */ "fill_mode", - /* 365 */ "group_by_list", - /* 366 */ "query_expression_body", - /* 367 */ "order_by_clause_opt", - /* 368 */ "slimit_clause_opt", - /* 369 */ "limit_clause_opt", - /* 370 */ "query_primary", - /* 371 */ "sort_specification_list", - /* 372 */ "sort_specification", - /* 373 */ "ordering_specification_opt", - /* 374 */ "null_ordering_opt", + /* 58 */ "FLUSH", + /* 59 */ "IF", + /* 60 */ "NOT", + /* 61 */ "EXISTS", + /* 62 */ "BUFFER", + /* 63 */ "CACHELAST", + /* 64 */ "COMP", + /* 65 */ "DURATION", + /* 66 */ "NK_VARIABLE", + /* 67 */ "FSYNC", + /* 68 */ "MAXROWS", + /* 69 */ "MINROWS", + /* 70 */ "KEEP", + /* 71 */ "PAGES", + /* 72 */ "PAGESIZE", + /* 73 */ "PRECISION", + /* 74 */ "REPLICA", + /* 75 */ "STRICT", + /* 76 */ "WAL", + /* 77 */ "VGROUPS", + /* 78 */ "SINGLE_STABLE", + /* 79 */ "RETENTIONS", + /* 80 */ "SCHEMALESS", + /* 81 */ "NK_COLON", + /* 82 */ "TABLE", + /* 83 */ "NK_LP", + /* 84 */ "NK_RP", + /* 85 */ "STABLE", + /* 86 */ "ADD", + /* 87 */ "COLUMN", + /* 88 */ "MODIFY", + /* 89 */ "RENAME", + /* 90 */ "TAG", + /* 91 */ "SET", + /* 92 */ "NK_EQ", + /* 93 */ "USING", + /* 94 */ "TAGS", + /* 95 */ "COMMENT", + /* 96 */ "BOOL", + /* 97 */ "TINYINT", + /* 98 */ "SMALLINT", + /* 99 */ "INT", + /* 100 */ "INTEGER", + /* 101 */ "BIGINT", + /* 102 */ "FLOAT", + /* 103 */ "DOUBLE", + /* 104 */ "BINARY", + /* 105 */ "TIMESTAMP", + /* 106 */ "NCHAR", + /* 107 */ "UNSIGNED", + /* 108 */ "JSON", + /* 109 */ "VARCHAR", + /* 110 */ "MEDIUMBLOB", + /* 111 */ "BLOB", + /* 112 */ "VARBINARY", + /* 113 */ "DECIMAL", + /* 114 */ "MAX_DELAY", + /* 115 */ "WATERMARK", + /* 116 */ "ROLLUP", + /* 117 */ "TTL", + /* 118 */ "SMA", + /* 119 */ "FIRST", + /* 120 */ "LAST", + /* 121 */ "SHOW", + /* 122 */ "DATABASES", + /* 123 */ "TABLES", + /* 124 */ "STABLES", + /* 125 */ "MNODES", + /* 126 */ "MODULES", + /* 127 */ "QNODES", + /* 128 */ "FUNCTIONS", + /* 129 */ "INDEXES", + /* 130 */ "ACCOUNTS", + /* 131 */ "APPS", + /* 132 */ "CONNECTIONS", + /* 133 */ "LICENCE", + /* 134 */ "GRANTS", + /* 135 */ "QUERIES", + /* 136 */ "SCORES", + /* 137 */ "TOPICS", + /* 138 */ "VARIABLES", + /* 139 */ "BNODES", + /* 140 */ "SNODES", + /* 141 */ "CLUSTER", + /* 142 */ "TRANSACTIONS", + /* 143 */ "DISTRIBUTED", + /* 144 */ "CONSUMERS", + /* 145 */ "SUBSCRIPTIONS", + /* 146 */ "LIKE", + /* 147 */ "INDEX", + /* 148 */ "FUNCTION", + /* 149 */ "INTERVAL", + /* 150 */ "TOPIC", + /* 151 */ "AS", + /* 152 */ "WITH", + /* 153 */ "META", + /* 154 */ "CONSUMER", + /* 155 */ "GROUP", + /* 156 */ "DESC", + /* 157 */ "DESCRIBE", + /* 158 */ "RESET", + /* 159 */ "QUERY", + /* 160 */ "CACHE", + /* 161 */ "EXPLAIN", + /* 162 */ "ANALYZE", + /* 163 */ "VERBOSE", + /* 164 */ "NK_BOOL", + /* 165 */ "RATIO", + /* 166 */ "NK_FLOAT", + /* 167 */ "COMPACT", + /* 168 */ "VNODES", + /* 169 */ "IN", + /* 170 */ "OUTPUTTYPE", + /* 171 */ "AGGREGATE", + /* 172 */ "BUFSIZE", + /* 173 */ "STREAM", + /* 174 */ "INTO", + /* 175 */ "TRIGGER", + /* 176 */ "AT_ONCE", + /* 177 */ "WINDOW_CLOSE", + /* 178 */ "IGNORE", + /* 179 */ "EXPIRED", + /* 180 */ "KILL", + /* 181 */ "CONNECTION", + /* 182 */ "TRANSACTION", + /* 183 */ "BALANCE", + /* 184 */ "VGROUP", + /* 185 */ "MERGE", + /* 186 */ "REDISTRIBUTE", + /* 187 */ "SPLIT", + /* 188 */ "SYNCDB", + /* 189 */ "DELETE", + /* 190 */ "INSERT", + /* 191 */ "NULL", + /* 192 */ "NK_QUESTION", + /* 193 */ "NK_ARROW", + /* 194 */ "ROWTS", + /* 195 */ "TBNAME", + /* 196 */ "QSTARTTS", + /* 197 */ "QENDTS", + /* 198 */ "WSTARTTS", + /* 199 */ "WENDTS", + /* 200 */ "WDURATION", + /* 201 */ "CAST", + /* 202 */ "NOW", + /* 203 */ "TODAY", + /* 204 */ "TIMEZONE", + /* 205 */ "CLIENT_VERSION", + /* 206 */ "SERVER_VERSION", + /* 207 */ "SERVER_STATUS", + /* 208 */ "CURRENT_USER", + /* 209 */ "COUNT", + /* 210 */ "LAST_ROW", + /* 211 */ "BETWEEN", + /* 212 */ "IS", + /* 213 */ "NK_LT", + /* 214 */ "NK_GT", + /* 215 */ "NK_LE", + /* 216 */ "NK_GE", + /* 217 */ "NK_NE", + /* 218 */ "MATCH", + /* 219 */ "NMATCH", + /* 220 */ "CONTAINS", + /* 221 */ "JOIN", + /* 222 */ "INNER", + /* 223 */ "SELECT", + /* 224 */ "DISTINCT", + /* 225 */ "WHERE", + /* 226 */ "PARTITION", + /* 227 */ "BY", + /* 228 */ "SESSION", + /* 229 */ "STATE_WINDOW", + /* 230 */ "SLIDING", + /* 231 */ "FILL", + /* 232 */ "VALUE", + /* 233 */ "NONE", + /* 234 */ "PREV", + /* 235 */ "LINEAR", + /* 236 */ "NEXT", + /* 237 */ "HAVING", + /* 238 */ "RANGE", + /* 239 */ "EVERY", + /* 240 */ "ORDER", + /* 241 */ "SLIMIT", + /* 242 */ "SOFFSET", + /* 243 */ "LIMIT", + /* 244 */ "OFFSET", + /* 245 */ "ASC", + /* 246 */ "NULLS", + /* 247 */ "ID", + /* 248 */ "NK_BITNOT", + /* 249 */ "VALUES", + /* 250 */ "IMPORT", + /* 251 */ "NK_SEMI", + /* 252 */ "FILE", + /* 253 */ "cmd", + /* 254 */ "account_options", + /* 255 */ "alter_account_options", + /* 256 */ "literal", + /* 257 */ "alter_account_option", + /* 258 */ "user_name", + /* 259 */ "sysinfo_opt", + /* 260 */ "privileges", + /* 261 */ "priv_level", + /* 262 */ "priv_type_list", + /* 263 */ "priv_type", + /* 264 */ "db_name", + /* 265 */ "dnode_endpoint", + /* 266 */ "not_exists_opt", + /* 267 */ "db_options", + /* 268 */ "exists_opt", + /* 269 */ "alter_db_options", + /* 270 */ "integer_list", + /* 271 */ "variable_list", + /* 272 */ "retention_list", + /* 273 */ "alter_db_option", + /* 274 */ "retention", + /* 275 */ "full_table_name", + /* 276 */ "column_def_list", + /* 277 */ "tags_def_opt", + /* 278 */ "table_options", + /* 279 */ "multi_create_clause", + /* 280 */ "tags_def", + /* 281 */ "multi_drop_clause", + /* 282 */ "alter_table_clause", + /* 283 */ "alter_table_options", + /* 284 */ "column_name", + /* 285 */ "type_name", + /* 286 */ "signed_literal", + /* 287 */ "create_subtable_clause", + /* 288 */ "specific_cols_opt", + /* 289 */ "expression_list", + /* 290 */ "drop_table_clause", + /* 291 */ "col_name_list", + /* 292 */ "table_name", + /* 293 */ "column_def", + /* 294 */ "duration_list", + /* 295 */ "rollup_func_list", + /* 296 */ "alter_table_option", + /* 297 */ "duration_literal", + /* 298 */ "rollup_func_name", + /* 299 */ "function_name", + /* 300 */ "col_name", + /* 301 */ "db_name_cond_opt", + /* 302 */ "like_pattern_opt", + /* 303 */ "table_name_cond", + /* 304 */ "from_db_opt", + /* 305 */ "index_name", + /* 306 */ "index_options", + /* 307 */ "func_list", + /* 308 */ "sliding_opt", + /* 309 */ "sma_stream_opt", + /* 310 */ "func", + /* 311 */ "stream_options", + /* 312 */ "topic_name", + /* 313 */ "query_expression", + /* 314 */ "cgroup_name", + /* 315 */ "analyze_opt", + /* 316 */ "explain_options", + /* 317 */ "agg_func_opt", + /* 318 */ "bufsize_opt", + /* 319 */ "stream_name", + /* 320 */ "into_opt", + /* 321 */ "dnode_list", + /* 322 */ "where_clause_opt", + /* 323 */ "signed", + /* 324 */ "literal_func", + /* 325 */ "literal_list", + /* 326 */ "table_alias", + /* 327 */ "column_alias", + /* 328 */ "expression", + /* 329 */ "pseudo_column", + /* 330 */ "column_reference", + /* 331 */ "function_expression", + /* 332 */ "subquery", + /* 333 */ "star_func", + /* 334 */ "star_func_para_list", + /* 335 */ "noarg_func", + /* 336 */ "other_para_list", + /* 337 */ "star_func_para", + /* 338 */ "predicate", + /* 339 */ "compare_op", + /* 340 */ "in_op", + /* 341 */ "in_predicate_value", + /* 342 */ "boolean_value_expression", + /* 343 */ "boolean_primary", + /* 344 */ "common_expression", + /* 345 */ "from_clause_opt", + /* 346 */ "table_reference_list", + /* 347 */ "table_reference", + /* 348 */ "table_primary", + /* 349 */ "joined_table", + /* 350 */ "alias_opt", + /* 351 */ "parenthesized_joined_table", + /* 352 */ "join_type", + /* 353 */ "search_condition", + /* 354 */ "query_specification", + /* 355 */ "set_quantifier_opt", + /* 356 */ "select_list", + /* 357 */ "partition_by_clause_opt", + /* 358 */ "range_opt", + /* 359 */ "every_opt", + /* 360 */ "fill_opt", + /* 361 */ "twindow_clause_opt", + /* 362 */ "group_by_clause_opt", + /* 363 */ "having_clause_opt", + /* 364 */ "select_item", + /* 365 */ "fill_mode", + /* 366 */ "group_by_list", + /* 367 */ "query_expression_body", + /* 368 */ "order_by_clause_opt", + /* 369 */ "slimit_clause_opt", + /* 370 */ "limit_clause_opt", + /* 371 */ "query_primary", + /* 372 */ "sort_specification_list", + /* 373 */ "sort_specification", + /* 374 */ "ordering_specification_opt", + /* 375 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1719,423 +1676,425 @@ static const char *const yyRuleName[] = { /* 63 */ "cmd ::= DROP DATABASE exists_opt db_name", /* 64 */ "cmd ::= USE db_name", /* 65 */ "cmd ::= ALTER DATABASE db_name alter_db_options", - /* 66 */ "not_exists_opt ::= IF NOT EXISTS", - /* 67 */ "not_exists_opt ::=", - /* 68 */ "exists_opt ::= IF EXISTS", - /* 69 */ "exists_opt ::=", - /* 70 */ "db_options ::=", - /* 71 */ "db_options ::= db_options BUFFER NK_INTEGER", - /* 72 */ "db_options ::= db_options CACHELAST NK_INTEGER", - /* 73 */ "db_options ::= db_options COMP NK_INTEGER", - /* 74 */ "db_options ::= db_options DURATION NK_INTEGER", - /* 75 */ "db_options ::= db_options DURATION NK_VARIABLE", - /* 76 */ "db_options ::= db_options FSYNC NK_INTEGER", - /* 77 */ "db_options ::= db_options MAXROWS NK_INTEGER", - /* 78 */ "db_options ::= db_options MINROWS NK_INTEGER", - /* 79 */ "db_options ::= db_options KEEP integer_list", - /* 80 */ "db_options ::= db_options KEEP variable_list", - /* 81 */ "db_options ::= db_options PAGES NK_INTEGER", - /* 82 */ "db_options ::= db_options PAGESIZE NK_INTEGER", - /* 83 */ "db_options ::= db_options PRECISION NK_STRING", - /* 84 */ "db_options ::= db_options REPLICA NK_INTEGER", - /* 85 */ "db_options ::= db_options STRICT NK_INTEGER", - /* 86 */ "db_options ::= db_options WAL NK_INTEGER", - /* 87 */ "db_options ::= db_options VGROUPS NK_INTEGER", - /* 88 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", - /* 89 */ "db_options ::= db_options RETENTIONS retention_list", - /* 90 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", - /* 91 */ "alter_db_options ::= alter_db_option", - /* 92 */ "alter_db_options ::= alter_db_options alter_db_option", - /* 93 */ "alter_db_option ::= BUFFER NK_INTEGER", - /* 94 */ "alter_db_option ::= CACHELAST NK_INTEGER", - /* 95 */ "alter_db_option ::= FSYNC NK_INTEGER", - /* 96 */ "alter_db_option ::= KEEP integer_list", - /* 97 */ "alter_db_option ::= KEEP variable_list", - /* 98 */ "alter_db_option ::= PAGES NK_INTEGER", - /* 99 */ "alter_db_option ::= REPLICA NK_INTEGER", - /* 100 */ "alter_db_option ::= STRICT NK_INTEGER", - /* 101 */ "alter_db_option ::= WAL NK_INTEGER", - /* 102 */ "integer_list ::= NK_INTEGER", - /* 103 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", - /* 104 */ "variable_list ::= NK_VARIABLE", - /* 105 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", - /* 106 */ "retention_list ::= retention", - /* 107 */ "retention_list ::= retention_list NK_COMMA retention", - /* 108 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", - /* 109 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 110 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 111 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 112 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 113 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 114 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 115 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 116 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 117 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 118 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 119 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 120 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 121 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 122 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 123 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 124 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 125 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", - /* 126 */ "multi_create_clause ::= create_subtable_clause", - /* 127 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 128 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP expression_list NK_RP table_options", - /* 129 */ "multi_drop_clause ::= drop_table_clause", - /* 130 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 131 */ "drop_table_clause ::= exists_opt full_table_name", - /* 132 */ "specific_tags_opt ::=", - /* 133 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", - /* 134 */ "full_table_name ::= table_name", - /* 135 */ "full_table_name ::= db_name NK_DOT table_name", - /* 136 */ "column_def_list ::= column_def", - /* 137 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 138 */ "column_def ::= column_name type_name", - /* 139 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 140 */ "type_name ::= BOOL", - /* 141 */ "type_name ::= TINYINT", - /* 142 */ "type_name ::= SMALLINT", - /* 143 */ "type_name ::= INT", - /* 144 */ "type_name ::= INTEGER", - /* 145 */ "type_name ::= BIGINT", - /* 146 */ "type_name ::= FLOAT", - /* 147 */ "type_name ::= DOUBLE", - /* 148 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 149 */ "type_name ::= TIMESTAMP", - /* 150 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 151 */ "type_name ::= TINYINT UNSIGNED", - /* 152 */ "type_name ::= SMALLINT UNSIGNED", - /* 153 */ "type_name ::= INT UNSIGNED", - /* 154 */ "type_name ::= BIGINT UNSIGNED", - /* 155 */ "type_name ::= JSON", - /* 156 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 157 */ "type_name ::= MEDIUMBLOB", - /* 158 */ "type_name ::= BLOB", - /* 159 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 160 */ "type_name ::= DECIMAL", - /* 161 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 162 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 163 */ "tags_def_opt ::=", - /* 164 */ "tags_def_opt ::= tags_def", - /* 165 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 166 */ "table_options ::=", - /* 167 */ "table_options ::= table_options COMMENT NK_STRING", - /* 168 */ "table_options ::= table_options MAX_DELAY duration_list", - /* 169 */ "table_options ::= table_options WATERMARK duration_list", - /* 170 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", - /* 171 */ "table_options ::= table_options TTL NK_INTEGER", - /* 172 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 173 */ "alter_table_options ::= alter_table_option", - /* 174 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 175 */ "alter_table_option ::= COMMENT NK_STRING", - /* 176 */ "alter_table_option ::= TTL NK_INTEGER", - /* 177 */ "duration_list ::= duration_literal", - /* 178 */ "duration_list ::= duration_list NK_COMMA duration_literal", - /* 179 */ "rollup_func_list ::= rollup_func_name", - /* 180 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", - /* 181 */ "rollup_func_name ::= function_name", - /* 182 */ "rollup_func_name ::= FIRST", - /* 183 */ "rollup_func_name ::= LAST", - /* 184 */ "col_name_list ::= col_name", - /* 185 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 186 */ "col_name ::= column_name", - /* 187 */ "cmd ::= SHOW DNODES", - /* 188 */ "cmd ::= SHOW USERS", - /* 189 */ "cmd ::= SHOW DATABASES", - /* 190 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 191 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 192 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 193 */ "cmd ::= SHOW MNODES", - /* 194 */ "cmd ::= SHOW MODULES", - /* 195 */ "cmd ::= SHOW QNODES", - /* 196 */ "cmd ::= SHOW FUNCTIONS", - /* 197 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 198 */ "cmd ::= SHOW STREAMS", - /* 199 */ "cmd ::= SHOW ACCOUNTS", - /* 200 */ "cmd ::= SHOW APPS", - /* 201 */ "cmd ::= SHOW CONNECTIONS", - /* 202 */ "cmd ::= SHOW LICENCE", - /* 203 */ "cmd ::= SHOW GRANTS", - /* 204 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 205 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 206 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 207 */ "cmd ::= SHOW QUERIES", - /* 208 */ "cmd ::= SHOW SCORES", - /* 209 */ "cmd ::= SHOW TOPICS", - /* 210 */ "cmd ::= SHOW VARIABLES", - /* 211 */ "cmd ::= SHOW LOCAL VARIABLES", - /* 212 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", - /* 213 */ "cmd ::= SHOW BNODES", - /* 214 */ "cmd ::= SHOW SNODES", - /* 215 */ "cmd ::= SHOW CLUSTER", - /* 216 */ "cmd ::= SHOW TRANSACTIONS", - /* 217 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", - /* 218 */ "cmd ::= SHOW CONSUMERS", - /* 219 */ "cmd ::= SHOW SUBSCRIPTIONS", - /* 220 */ "db_name_cond_opt ::=", - /* 221 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 222 */ "like_pattern_opt ::=", - /* 223 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 224 */ "table_name_cond ::= table_name", - /* 225 */ "from_db_opt ::=", - /* 226 */ "from_db_opt ::= FROM db_name", - /* 227 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 228 */ "cmd ::= DROP INDEX exists_opt index_name", - /* 229 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", - /* 230 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", - /* 231 */ "func_list ::= func", - /* 232 */ "func_list ::= func_list NK_COMMA func", - /* 233 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 234 */ "sma_stream_opt ::=", - /* 235 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", - /* 236 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", - /* 237 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 238 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", - /* 239 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", - /* 240 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", - /* 241 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", - /* 242 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 243 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", - /* 244 */ "cmd ::= DESC full_table_name", - /* 245 */ "cmd ::= DESCRIBE full_table_name", - /* 246 */ "cmd ::= RESET QUERY CACHE", - /* 247 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 248 */ "analyze_opt ::=", - /* 249 */ "analyze_opt ::= ANALYZE", - /* 250 */ "explain_options ::=", - /* 251 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 252 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 253 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 254 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 255 */ "cmd ::= DROP FUNCTION exists_opt function_name", - /* 256 */ "agg_func_opt ::=", - /* 257 */ "agg_func_opt ::= AGGREGATE", - /* 258 */ "bufsize_opt ::=", - /* 259 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 260 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", - /* 261 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 262 */ "into_opt ::=", - /* 263 */ "into_opt ::= INTO full_table_name", - /* 264 */ "stream_options ::=", - /* 265 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 266 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 267 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", - /* 268 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 269 */ "stream_options ::= stream_options IGNORE EXPIRED", - /* 270 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 271 */ "cmd ::= KILL QUERY NK_STRING", - /* 272 */ "cmd ::= KILL TRANSACTION NK_INTEGER", - /* 273 */ "cmd ::= BALANCE VGROUP", - /* 274 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 275 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 276 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 277 */ "dnode_list ::= DNODE NK_INTEGER", - /* 278 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 279 */ "cmd ::= SYNCDB db_name REPLICA", - /* 280 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", - /* 281 */ "cmd ::= query_expression", - /* 282 */ "literal ::= NK_INTEGER", - /* 283 */ "literal ::= NK_FLOAT", - /* 284 */ "literal ::= NK_STRING", - /* 285 */ "literal ::= NK_BOOL", - /* 286 */ "literal ::= TIMESTAMP NK_STRING", - /* 287 */ "literal ::= duration_literal", - /* 288 */ "literal ::= NULL", - /* 289 */ "literal ::= NK_QUESTION", - /* 290 */ "duration_literal ::= NK_VARIABLE", - /* 291 */ "signed ::= NK_INTEGER", - /* 292 */ "signed ::= NK_PLUS NK_INTEGER", - /* 293 */ "signed ::= NK_MINUS NK_INTEGER", - /* 294 */ "signed ::= NK_FLOAT", - /* 295 */ "signed ::= NK_PLUS NK_FLOAT", - /* 296 */ "signed ::= NK_MINUS NK_FLOAT", - /* 297 */ "signed_literal ::= signed", - /* 298 */ "signed_literal ::= NK_STRING", - /* 299 */ "signed_literal ::= NK_BOOL", - /* 300 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 301 */ "signed_literal ::= duration_literal", - /* 302 */ "signed_literal ::= NULL", - /* 303 */ "signed_literal ::= literal_func", - /* 304 */ "literal_list ::= signed_literal", - /* 305 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 306 */ "db_name ::= NK_ID", - /* 307 */ "table_name ::= NK_ID", - /* 308 */ "column_name ::= NK_ID", - /* 309 */ "function_name ::= NK_ID", - /* 310 */ "table_alias ::= NK_ID", - /* 311 */ "column_alias ::= NK_ID", - /* 312 */ "user_name ::= NK_ID", - /* 313 */ "index_name ::= NK_ID", - /* 314 */ "topic_name ::= NK_ID", - /* 315 */ "stream_name ::= NK_ID", - /* 316 */ "cgroup_name ::= NK_ID", - /* 317 */ "expression ::= literal", - /* 318 */ "expression ::= pseudo_column", - /* 319 */ "expression ::= column_reference", - /* 320 */ "expression ::= function_expression", - /* 321 */ "expression ::= subquery", - /* 322 */ "expression ::= NK_LP expression NK_RP", - /* 323 */ "expression ::= NK_PLUS expression", - /* 324 */ "expression ::= NK_MINUS expression", - /* 325 */ "expression ::= expression NK_PLUS expression", - /* 326 */ "expression ::= expression NK_MINUS expression", - /* 327 */ "expression ::= expression NK_STAR expression", - /* 328 */ "expression ::= expression NK_SLASH expression", - /* 329 */ "expression ::= expression NK_REM expression", - /* 330 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 331 */ "expression ::= expression NK_BITAND expression", - /* 332 */ "expression ::= expression NK_BITOR expression", - /* 333 */ "expression_list ::= expression", - /* 334 */ "expression_list ::= expression_list NK_COMMA expression", - /* 335 */ "column_reference ::= column_name", - /* 336 */ "column_reference ::= table_name NK_DOT column_name", - /* 337 */ "pseudo_column ::= ROWTS", - /* 338 */ "pseudo_column ::= TBNAME", - /* 339 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 340 */ "pseudo_column ::= QSTARTTS", - /* 341 */ "pseudo_column ::= QENDTS", - /* 342 */ "pseudo_column ::= WSTARTTS", - /* 343 */ "pseudo_column ::= WENDTS", - /* 344 */ "pseudo_column ::= WDURATION", - /* 345 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 346 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 347 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 348 */ "function_expression ::= literal_func", - /* 349 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 350 */ "literal_func ::= NOW", - /* 351 */ "noarg_func ::= NOW", - /* 352 */ "noarg_func ::= TODAY", - /* 353 */ "noarg_func ::= TIMEZONE", - /* 354 */ "noarg_func ::= DATABASE", - /* 355 */ "noarg_func ::= CLIENT_VERSION", - /* 356 */ "noarg_func ::= SERVER_VERSION", - /* 357 */ "noarg_func ::= SERVER_STATUS", - /* 358 */ "noarg_func ::= CURRENT_USER", - /* 359 */ "noarg_func ::= USER", - /* 360 */ "star_func ::= COUNT", - /* 361 */ "star_func ::= FIRST", - /* 362 */ "star_func ::= LAST", - /* 363 */ "star_func ::= LAST_ROW", - /* 364 */ "star_func_para_list ::= NK_STAR", - /* 365 */ "star_func_para_list ::= other_para_list", - /* 366 */ "other_para_list ::= star_func_para", - /* 367 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 368 */ "star_func_para ::= expression", - /* 369 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 370 */ "predicate ::= expression compare_op expression", - /* 371 */ "predicate ::= expression BETWEEN expression AND expression", - /* 372 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 373 */ "predicate ::= expression IS NULL", - /* 374 */ "predicate ::= expression IS NOT NULL", - /* 375 */ "predicate ::= expression in_op in_predicate_value", - /* 376 */ "compare_op ::= NK_LT", - /* 377 */ "compare_op ::= NK_GT", - /* 378 */ "compare_op ::= NK_LE", - /* 379 */ "compare_op ::= NK_GE", - /* 380 */ "compare_op ::= NK_NE", - /* 381 */ "compare_op ::= NK_EQ", - /* 382 */ "compare_op ::= LIKE", - /* 383 */ "compare_op ::= NOT LIKE", - /* 384 */ "compare_op ::= MATCH", - /* 385 */ "compare_op ::= NMATCH", - /* 386 */ "compare_op ::= CONTAINS", - /* 387 */ "in_op ::= IN", - /* 388 */ "in_op ::= NOT IN", - /* 389 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 390 */ "boolean_value_expression ::= boolean_primary", - /* 391 */ "boolean_value_expression ::= NOT boolean_primary", - /* 392 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 393 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 394 */ "boolean_primary ::= predicate", - /* 395 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 396 */ "common_expression ::= expression", - /* 397 */ "common_expression ::= boolean_value_expression", - /* 398 */ "from_clause_opt ::=", - /* 399 */ "from_clause_opt ::= FROM table_reference_list", - /* 400 */ "table_reference_list ::= table_reference", - /* 401 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 402 */ "table_reference ::= table_primary", - /* 403 */ "table_reference ::= joined_table", - /* 404 */ "table_primary ::= table_name alias_opt", - /* 405 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 406 */ "table_primary ::= subquery alias_opt", - /* 407 */ "table_primary ::= parenthesized_joined_table", - /* 408 */ "alias_opt ::=", - /* 409 */ "alias_opt ::= table_alias", - /* 410 */ "alias_opt ::= AS table_alias", - /* 411 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 412 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 413 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 414 */ "join_type ::=", - /* 415 */ "join_type ::= INNER", - /* 416 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 417 */ "set_quantifier_opt ::=", - /* 418 */ "set_quantifier_opt ::= DISTINCT", - /* 419 */ "set_quantifier_opt ::= ALL", - /* 420 */ "select_list ::= select_item", - /* 421 */ "select_list ::= select_list NK_COMMA select_item", - /* 422 */ "select_item ::= NK_STAR", - /* 423 */ "select_item ::= common_expression", - /* 424 */ "select_item ::= common_expression column_alias", - /* 425 */ "select_item ::= common_expression AS column_alias", - /* 426 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 427 */ "where_clause_opt ::=", - /* 428 */ "where_clause_opt ::= WHERE search_condition", - /* 429 */ "partition_by_clause_opt ::=", - /* 430 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 431 */ "twindow_clause_opt ::=", - /* 432 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 433 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 434 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 435 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 436 */ "sliding_opt ::=", - /* 437 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 438 */ "fill_opt ::=", - /* 439 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 440 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 441 */ "fill_mode ::= NONE", - /* 442 */ "fill_mode ::= PREV", - /* 443 */ "fill_mode ::= NULL", - /* 444 */ "fill_mode ::= LINEAR", - /* 445 */ "fill_mode ::= NEXT", - /* 446 */ "group_by_clause_opt ::=", - /* 447 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 448 */ "group_by_list ::= expression", - /* 449 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 450 */ "having_clause_opt ::=", - /* 451 */ "having_clause_opt ::= HAVING search_condition", - /* 452 */ "range_opt ::=", - /* 453 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", - /* 454 */ "every_opt ::=", - /* 455 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", - /* 456 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 457 */ "query_expression_body ::= query_primary", - /* 458 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 459 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 460 */ "query_primary ::= query_specification", - /* 461 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", - /* 462 */ "order_by_clause_opt ::=", - /* 463 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 464 */ "slimit_clause_opt ::=", - /* 465 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 466 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 467 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 468 */ "limit_clause_opt ::=", - /* 469 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 470 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 471 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 472 */ "subquery ::= NK_LP query_expression NK_RP", - /* 473 */ "search_condition ::= common_expression", - /* 474 */ "sort_specification_list ::= sort_specification", - /* 475 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 476 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 477 */ "ordering_specification_opt ::=", - /* 478 */ "ordering_specification_opt ::= ASC", - /* 479 */ "ordering_specification_opt ::= DESC", - /* 480 */ "null_ordering_opt ::=", - /* 481 */ "null_ordering_opt ::= NULLS FIRST", - /* 482 */ "null_ordering_opt ::= NULLS LAST", + /* 66 */ "cmd ::= FLUSH DATABASE db_name", + /* 67 */ "not_exists_opt ::= IF NOT EXISTS", + /* 68 */ "not_exists_opt ::=", + /* 69 */ "exists_opt ::= IF EXISTS", + /* 70 */ "exists_opt ::=", + /* 71 */ "db_options ::=", + /* 72 */ "db_options ::= db_options BUFFER NK_INTEGER", + /* 73 */ "db_options ::= db_options CACHELAST NK_INTEGER", + /* 74 */ "db_options ::= db_options COMP NK_INTEGER", + /* 75 */ "db_options ::= db_options DURATION NK_INTEGER", + /* 76 */ "db_options ::= db_options DURATION NK_VARIABLE", + /* 77 */ "db_options ::= db_options FSYNC NK_INTEGER", + /* 78 */ "db_options ::= db_options MAXROWS NK_INTEGER", + /* 79 */ "db_options ::= db_options MINROWS NK_INTEGER", + /* 80 */ "db_options ::= db_options KEEP integer_list", + /* 81 */ "db_options ::= db_options KEEP variable_list", + /* 82 */ "db_options ::= db_options PAGES NK_INTEGER", + /* 83 */ "db_options ::= db_options PAGESIZE NK_INTEGER", + /* 84 */ "db_options ::= db_options PRECISION NK_STRING", + /* 85 */ "db_options ::= db_options REPLICA NK_INTEGER", + /* 86 */ "db_options ::= db_options STRICT NK_INTEGER", + /* 87 */ "db_options ::= db_options WAL NK_INTEGER", + /* 88 */ "db_options ::= db_options VGROUPS NK_INTEGER", + /* 89 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", + /* 90 */ "db_options ::= db_options RETENTIONS retention_list", + /* 91 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", + /* 92 */ "alter_db_options ::= alter_db_option", + /* 93 */ "alter_db_options ::= alter_db_options alter_db_option", + /* 94 */ "alter_db_option ::= BUFFER NK_INTEGER", + /* 95 */ "alter_db_option ::= CACHELAST NK_INTEGER", + /* 96 */ "alter_db_option ::= FSYNC NK_INTEGER", + /* 97 */ "alter_db_option ::= KEEP integer_list", + /* 98 */ "alter_db_option ::= KEEP variable_list", + /* 99 */ "alter_db_option ::= PAGES NK_INTEGER", + /* 100 */ "alter_db_option ::= REPLICA NK_INTEGER", + /* 101 */ "alter_db_option ::= STRICT NK_INTEGER", + /* 102 */ "alter_db_option ::= WAL NK_INTEGER", + /* 103 */ "integer_list ::= NK_INTEGER", + /* 104 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", + /* 105 */ "variable_list ::= NK_VARIABLE", + /* 106 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", + /* 107 */ "retention_list ::= retention", + /* 108 */ "retention_list ::= retention_list NK_COMMA retention", + /* 109 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", + /* 110 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 111 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 112 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 113 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 114 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 115 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 116 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 117 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 118 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 119 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 120 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 121 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 122 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 123 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 124 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 125 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 126 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", + /* 127 */ "multi_create_clause ::= create_subtable_clause", + /* 128 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 129 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options", + /* 130 */ "multi_drop_clause ::= drop_table_clause", + /* 131 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 132 */ "drop_table_clause ::= exists_opt full_table_name", + /* 133 */ "specific_cols_opt ::=", + /* 134 */ "specific_cols_opt ::= NK_LP col_name_list NK_RP", + /* 135 */ "full_table_name ::= table_name", + /* 136 */ "full_table_name ::= db_name NK_DOT table_name", + /* 137 */ "column_def_list ::= column_def", + /* 138 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 139 */ "column_def ::= column_name type_name", + /* 140 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 141 */ "type_name ::= BOOL", + /* 142 */ "type_name ::= TINYINT", + /* 143 */ "type_name ::= SMALLINT", + /* 144 */ "type_name ::= INT", + /* 145 */ "type_name ::= INTEGER", + /* 146 */ "type_name ::= BIGINT", + /* 147 */ "type_name ::= FLOAT", + /* 148 */ "type_name ::= DOUBLE", + /* 149 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 150 */ "type_name ::= TIMESTAMP", + /* 151 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 152 */ "type_name ::= TINYINT UNSIGNED", + /* 153 */ "type_name ::= SMALLINT UNSIGNED", + /* 154 */ "type_name ::= INT UNSIGNED", + /* 155 */ "type_name ::= BIGINT UNSIGNED", + /* 156 */ "type_name ::= JSON", + /* 157 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 158 */ "type_name ::= MEDIUMBLOB", + /* 159 */ "type_name ::= BLOB", + /* 160 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 161 */ "type_name ::= DECIMAL", + /* 162 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 163 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 164 */ "tags_def_opt ::=", + /* 165 */ "tags_def_opt ::= tags_def", + /* 166 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 167 */ "table_options ::=", + /* 168 */ "table_options ::= table_options COMMENT NK_STRING", + /* 169 */ "table_options ::= table_options MAX_DELAY duration_list", + /* 170 */ "table_options ::= table_options WATERMARK duration_list", + /* 171 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", + /* 172 */ "table_options ::= table_options TTL NK_INTEGER", + /* 173 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 174 */ "alter_table_options ::= alter_table_option", + /* 175 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 176 */ "alter_table_option ::= COMMENT NK_STRING", + /* 177 */ "alter_table_option ::= TTL NK_INTEGER", + /* 178 */ "duration_list ::= duration_literal", + /* 179 */ "duration_list ::= duration_list NK_COMMA duration_literal", + /* 180 */ "rollup_func_list ::= rollup_func_name", + /* 181 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", + /* 182 */ "rollup_func_name ::= function_name", + /* 183 */ "rollup_func_name ::= FIRST", + /* 184 */ "rollup_func_name ::= LAST", + /* 185 */ "col_name_list ::= col_name", + /* 186 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 187 */ "col_name ::= column_name", + /* 188 */ "cmd ::= SHOW DNODES", + /* 189 */ "cmd ::= SHOW USERS", + /* 190 */ "cmd ::= SHOW DATABASES", + /* 191 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 192 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 193 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 194 */ "cmd ::= SHOW MNODES", + /* 195 */ "cmd ::= SHOW MODULES", + /* 196 */ "cmd ::= SHOW QNODES", + /* 197 */ "cmd ::= SHOW FUNCTIONS", + /* 198 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 199 */ "cmd ::= SHOW STREAMS", + /* 200 */ "cmd ::= SHOW ACCOUNTS", + /* 201 */ "cmd ::= SHOW APPS", + /* 202 */ "cmd ::= SHOW CONNECTIONS", + /* 203 */ "cmd ::= SHOW LICENCE", + /* 204 */ "cmd ::= SHOW GRANTS", + /* 205 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 206 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 207 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 208 */ "cmd ::= SHOW QUERIES", + /* 209 */ "cmd ::= SHOW SCORES", + /* 210 */ "cmd ::= SHOW TOPICS", + /* 211 */ "cmd ::= SHOW VARIABLES", + /* 212 */ "cmd ::= SHOW LOCAL VARIABLES", + /* 213 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", + /* 214 */ "cmd ::= SHOW BNODES", + /* 215 */ "cmd ::= SHOW SNODES", + /* 216 */ "cmd ::= SHOW CLUSTER", + /* 217 */ "cmd ::= SHOW TRANSACTIONS", + /* 218 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", + /* 219 */ "cmd ::= SHOW CONSUMERS", + /* 220 */ "cmd ::= SHOW SUBSCRIPTIONS", + /* 221 */ "db_name_cond_opt ::=", + /* 222 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 223 */ "like_pattern_opt ::=", + /* 224 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 225 */ "table_name_cond ::= table_name", + /* 226 */ "from_db_opt ::=", + /* 227 */ "from_db_opt ::= FROM db_name", + /* 228 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 229 */ "cmd ::= DROP INDEX exists_opt index_name", + /* 230 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", + /* 231 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", + /* 232 */ "func_list ::= func", + /* 233 */ "func_list ::= func_list NK_COMMA func", + /* 234 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 235 */ "sma_stream_opt ::=", + /* 236 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", + /* 237 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", + /* 238 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 239 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", + /* 240 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", + /* 241 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", + /* 242 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", + /* 243 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 244 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", + /* 245 */ "cmd ::= DESC full_table_name", + /* 246 */ "cmd ::= DESCRIBE full_table_name", + /* 247 */ "cmd ::= RESET QUERY CACHE", + /* 248 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 249 */ "analyze_opt ::=", + /* 250 */ "analyze_opt ::= ANALYZE", + /* 251 */ "explain_options ::=", + /* 252 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 253 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 254 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 255 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 256 */ "cmd ::= DROP FUNCTION exists_opt function_name", + /* 257 */ "agg_func_opt ::=", + /* 258 */ "agg_func_opt ::= AGGREGATE", + /* 259 */ "bufsize_opt ::=", + /* 260 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 261 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", + /* 262 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 263 */ "into_opt ::=", + /* 264 */ "into_opt ::= INTO full_table_name", + /* 265 */ "stream_options ::=", + /* 266 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 267 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 268 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", + /* 269 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 270 */ "stream_options ::= stream_options IGNORE EXPIRED", + /* 271 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 272 */ "cmd ::= KILL QUERY NK_STRING", + /* 273 */ "cmd ::= KILL TRANSACTION NK_INTEGER", + /* 274 */ "cmd ::= BALANCE VGROUP", + /* 275 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 276 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 277 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 278 */ "dnode_list ::= DNODE NK_INTEGER", + /* 279 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 280 */ "cmd ::= SYNCDB db_name REPLICA", + /* 281 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", + /* 282 */ "cmd ::= query_expression", + /* 283 */ "cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression", + /* 284 */ "literal ::= NK_INTEGER", + /* 285 */ "literal ::= NK_FLOAT", + /* 286 */ "literal ::= NK_STRING", + /* 287 */ "literal ::= NK_BOOL", + /* 288 */ "literal ::= TIMESTAMP NK_STRING", + /* 289 */ "literal ::= duration_literal", + /* 290 */ "literal ::= NULL", + /* 291 */ "literal ::= NK_QUESTION", + /* 292 */ "duration_literal ::= NK_VARIABLE", + /* 293 */ "signed ::= NK_INTEGER", + /* 294 */ "signed ::= NK_PLUS NK_INTEGER", + /* 295 */ "signed ::= NK_MINUS NK_INTEGER", + /* 296 */ "signed ::= NK_FLOAT", + /* 297 */ "signed ::= NK_PLUS NK_FLOAT", + /* 298 */ "signed ::= NK_MINUS NK_FLOAT", + /* 299 */ "signed_literal ::= signed", + /* 300 */ "signed_literal ::= NK_STRING", + /* 301 */ "signed_literal ::= NK_BOOL", + /* 302 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 303 */ "signed_literal ::= duration_literal", + /* 304 */ "signed_literal ::= NULL", + /* 305 */ "signed_literal ::= literal_func", + /* 306 */ "literal_list ::= signed_literal", + /* 307 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 308 */ "db_name ::= NK_ID", + /* 309 */ "table_name ::= NK_ID", + /* 310 */ "column_name ::= NK_ID", + /* 311 */ "function_name ::= NK_ID", + /* 312 */ "table_alias ::= NK_ID", + /* 313 */ "column_alias ::= NK_ID", + /* 314 */ "user_name ::= NK_ID", + /* 315 */ "index_name ::= NK_ID", + /* 316 */ "topic_name ::= NK_ID", + /* 317 */ "stream_name ::= NK_ID", + /* 318 */ "cgroup_name ::= NK_ID", + /* 319 */ "expression ::= literal", + /* 320 */ "expression ::= pseudo_column", + /* 321 */ "expression ::= column_reference", + /* 322 */ "expression ::= function_expression", + /* 323 */ "expression ::= subquery", + /* 324 */ "expression ::= NK_LP expression NK_RP", + /* 325 */ "expression ::= NK_PLUS expression", + /* 326 */ "expression ::= NK_MINUS expression", + /* 327 */ "expression ::= expression NK_PLUS expression", + /* 328 */ "expression ::= expression NK_MINUS expression", + /* 329 */ "expression ::= expression NK_STAR expression", + /* 330 */ "expression ::= expression NK_SLASH expression", + /* 331 */ "expression ::= expression NK_REM expression", + /* 332 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 333 */ "expression ::= expression NK_BITAND expression", + /* 334 */ "expression ::= expression NK_BITOR expression", + /* 335 */ "expression_list ::= expression", + /* 336 */ "expression_list ::= expression_list NK_COMMA expression", + /* 337 */ "column_reference ::= column_name", + /* 338 */ "column_reference ::= table_name NK_DOT column_name", + /* 339 */ "pseudo_column ::= ROWTS", + /* 340 */ "pseudo_column ::= TBNAME", + /* 341 */ "pseudo_column ::= table_name NK_DOT TBNAME", + /* 342 */ "pseudo_column ::= QSTARTTS", + /* 343 */ "pseudo_column ::= QENDTS", + /* 344 */ "pseudo_column ::= WSTARTTS", + /* 345 */ "pseudo_column ::= WENDTS", + /* 346 */ "pseudo_column ::= WDURATION", + /* 347 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 348 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 349 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 350 */ "function_expression ::= literal_func", + /* 351 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 352 */ "literal_func ::= NOW", + /* 353 */ "noarg_func ::= NOW", + /* 354 */ "noarg_func ::= TODAY", + /* 355 */ "noarg_func ::= TIMEZONE", + /* 356 */ "noarg_func ::= DATABASE", + /* 357 */ "noarg_func ::= CLIENT_VERSION", + /* 358 */ "noarg_func ::= SERVER_VERSION", + /* 359 */ "noarg_func ::= SERVER_STATUS", + /* 360 */ "noarg_func ::= CURRENT_USER", + /* 361 */ "noarg_func ::= USER", + /* 362 */ "star_func ::= COUNT", + /* 363 */ "star_func ::= FIRST", + /* 364 */ "star_func ::= LAST", + /* 365 */ "star_func ::= LAST_ROW", + /* 366 */ "star_func_para_list ::= NK_STAR", + /* 367 */ "star_func_para_list ::= other_para_list", + /* 368 */ "other_para_list ::= star_func_para", + /* 369 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 370 */ "star_func_para ::= expression", + /* 371 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 372 */ "predicate ::= expression compare_op expression", + /* 373 */ "predicate ::= expression BETWEEN expression AND expression", + /* 374 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 375 */ "predicate ::= expression IS NULL", + /* 376 */ "predicate ::= expression IS NOT NULL", + /* 377 */ "predicate ::= expression in_op in_predicate_value", + /* 378 */ "compare_op ::= NK_LT", + /* 379 */ "compare_op ::= NK_GT", + /* 380 */ "compare_op ::= NK_LE", + /* 381 */ "compare_op ::= NK_GE", + /* 382 */ "compare_op ::= NK_NE", + /* 383 */ "compare_op ::= NK_EQ", + /* 384 */ "compare_op ::= LIKE", + /* 385 */ "compare_op ::= NOT LIKE", + /* 386 */ "compare_op ::= MATCH", + /* 387 */ "compare_op ::= NMATCH", + /* 388 */ "compare_op ::= CONTAINS", + /* 389 */ "in_op ::= IN", + /* 390 */ "in_op ::= NOT IN", + /* 391 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 392 */ "boolean_value_expression ::= boolean_primary", + /* 393 */ "boolean_value_expression ::= NOT boolean_primary", + /* 394 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 395 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 396 */ "boolean_primary ::= predicate", + /* 397 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 398 */ "common_expression ::= expression", + /* 399 */ "common_expression ::= boolean_value_expression", + /* 400 */ "from_clause_opt ::=", + /* 401 */ "from_clause_opt ::= FROM table_reference_list", + /* 402 */ "table_reference_list ::= table_reference", + /* 403 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 404 */ "table_reference ::= table_primary", + /* 405 */ "table_reference ::= joined_table", + /* 406 */ "table_primary ::= table_name alias_opt", + /* 407 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 408 */ "table_primary ::= subquery alias_opt", + /* 409 */ "table_primary ::= parenthesized_joined_table", + /* 410 */ "alias_opt ::=", + /* 411 */ "alias_opt ::= table_alias", + /* 412 */ "alias_opt ::= AS table_alias", + /* 413 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 414 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 415 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 416 */ "join_type ::=", + /* 417 */ "join_type ::= INNER", + /* 418 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 419 */ "set_quantifier_opt ::=", + /* 420 */ "set_quantifier_opt ::= DISTINCT", + /* 421 */ "set_quantifier_opt ::= ALL", + /* 422 */ "select_list ::= select_item", + /* 423 */ "select_list ::= select_list NK_COMMA select_item", + /* 424 */ "select_item ::= NK_STAR", + /* 425 */ "select_item ::= common_expression", + /* 426 */ "select_item ::= common_expression column_alias", + /* 427 */ "select_item ::= common_expression AS column_alias", + /* 428 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 429 */ "where_clause_opt ::=", + /* 430 */ "where_clause_opt ::= WHERE search_condition", + /* 431 */ "partition_by_clause_opt ::=", + /* 432 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 433 */ "twindow_clause_opt ::=", + /* 434 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 435 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 436 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 437 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 438 */ "sliding_opt ::=", + /* 439 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 440 */ "fill_opt ::=", + /* 441 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 442 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 443 */ "fill_mode ::= NONE", + /* 444 */ "fill_mode ::= PREV", + /* 445 */ "fill_mode ::= NULL", + /* 446 */ "fill_mode ::= LINEAR", + /* 447 */ "fill_mode ::= NEXT", + /* 448 */ "group_by_clause_opt ::=", + /* 449 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 450 */ "group_by_list ::= expression", + /* 451 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 452 */ "having_clause_opt ::=", + /* 453 */ "having_clause_opt ::= HAVING search_condition", + /* 454 */ "range_opt ::=", + /* 455 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", + /* 456 */ "every_opt ::=", + /* 457 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", + /* 458 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 459 */ "query_expression_body ::= query_primary", + /* 460 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 461 */ "query_expression_body ::= query_expression_body UNION query_expression_body", + /* 462 */ "query_primary ::= query_specification", + /* 463 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", + /* 464 */ "order_by_clause_opt ::=", + /* 465 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 466 */ "slimit_clause_opt ::=", + /* 467 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 468 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 469 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 470 */ "limit_clause_opt ::=", + /* 471 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 472 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 473 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 474 */ "subquery ::= NK_LP query_expression NK_RP", + /* 475 */ "search_condition ::= common_expression", + /* 476 */ "sort_specification_list ::= sort_specification", + /* 477 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 478 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 479 */ "ordering_specification_opt ::=", + /* 480 */ "ordering_specification_opt ::= ASC", + /* 481 */ "ordering_specification_opt ::= DESC", + /* 482 */ "null_ordering_opt ::=", + /* 483 */ "null_ordering_opt ::= NULLS FIRST", + /* 484 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -2262,181 +2221,181 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 252: /* cmd */ - case 255: /* literal */ - case 266: /* db_options */ - case 268: /* alter_db_options */ - case 273: /* retention */ - case 274: /* full_table_name */ - case 277: /* table_options */ - case 281: /* alter_table_clause */ - case 282: /* alter_table_options */ - case 285: /* signed_literal */ - case 286: /* create_subtable_clause */ - case 289: /* drop_table_clause */ - case 292: /* column_def */ - case 296: /* duration_literal */ - case 297: /* rollup_func_name */ - case 299: /* col_name */ - case 300: /* db_name_cond_opt */ - case 301: /* like_pattern_opt */ - case 302: /* table_name_cond */ - case 303: /* from_db_opt */ - case 305: /* index_options */ - case 307: /* sliding_opt */ - case 308: /* sma_stream_opt */ - case 309: /* func */ - case 310: /* stream_options */ - case 312: /* query_expression */ - case 315: /* explain_options */ - case 319: /* into_opt */ - case 321: /* where_clause_opt */ - case 322: /* signed */ - case 323: /* literal_func */ - case 327: /* expression */ - case 328: /* pseudo_column */ - case 329: /* column_reference */ - case 330: /* function_expression */ - case 331: /* subquery */ - case 336: /* star_func_para */ - case 337: /* predicate */ - case 340: /* in_predicate_value */ - case 341: /* boolean_value_expression */ - case 342: /* boolean_primary */ - case 343: /* common_expression */ - case 344: /* from_clause_opt */ - case 345: /* table_reference_list */ - case 346: /* table_reference */ - case 347: /* table_primary */ - case 348: /* joined_table */ - case 350: /* parenthesized_joined_table */ - case 352: /* search_condition */ - case 353: /* query_specification */ - case 357: /* range_opt */ - case 358: /* every_opt */ - case 359: /* fill_opt */ - case 360: /* twindow_clause_opt */ - case 362: /* having_clause_opt */ - case 363: /* select_item */ - case 366: /* query_expression_body */ - case 368: /* slimit_clause_opt */ - case 369: /* limit_clause_opt */ - case 370: /* query_primary */ - case 372: /* sort_specification */ + case 253: /* cmd */ + case 256: /* literal */ + case 267: /* db_options */ + case 269: /* alter_db_options */ + case 274: /* retention */ + case 275: /* full_table_name */ + case 278: /* table_options */ + case 282: /* alter_table_clause */ + case 283: /* alter_table_options */ + case 286: /* signed_literal */ + case 287: /* create_subtable_clause */ + case 290: /* drop_table_clause */ + case 293: /* column_def */ + case 297: /* duration_literal */ + case 298: /* rollup_func_name */ + case 300: /* col_name */ + case 301: /* db_name_cond_opt */ + case 302: /* like_pattern_opt */ + case 303: /* table_name_cond */ + case 304: /* from_db_opt */ + case 306: /* index_options */ + case 308: /* sliding_opt */ + case 309: /* sma_stream_opt */ + case 310: /* func */ + case 311: /* stream_options */ + case 313: /* query_expression */ + case 316: /* explain_options */ + case 320: /* into_opt */ + case 322: /* where_clause_opt */ + case 323: /* signed */ + case 324: /* literal_func */ + case 328: /* expression */ + case 329: /* pseudo_column */ + case 330: /* column_reference */ + case 331: /* function_expression */ + case 332: /* subquery */ + case 337: /* star_func_para */ + case 338: /* predicate */ + case 341: /* in_predicate_value */ + case 342: /* boolean_value_expression */ + case 343: /* boolean_primary */ + case 344: /* common_expression */ + case 345: /* from_clause_opt */ + case 346: /* table_reference_list */ + case 347: /* table_reference */ + case 348: /* table_primary */ + case 349: /* joined_table */ + case 351: /* parenthesized_joined_table */ + case 353: /* search_condition */ + case 354: /* query_specification */ + case 358: /* range_opt */ + case 359: /* every_opt */ + case 360: /* fill_opt */ + case 361: /* twindow_clause_opt */ + case 363: /* having_clause_opt */ + case 364: /* select_item */ + case 367: /* query_expression_body */ + case 369: /* slimit_clause_opt */ + case 370: /* limit_clause_opt */ + case 371: /* query_primary */ + case 373: /* sort_specification */ { - nodesDestroyNode((yypminor->yy212)); + nodesDestroyNode((yypminor->yy248)); } break; - case 253: /* account_options */ - case 254: /* alter_account_options */ - case 256: /* alter_account_option */ - case 317: /* bufsize_opt */ + case 254: /* account_options */ + case 255: /* alter_account_options */ + case 257: /* alter_account_option */ + case 318: /* bufsize_opt */ { } break; - case 257: /* user_name */ - case 260: /* priv_level */ - case 263: /* db_name */ - case 264: /* dnode_endpoint */ - case 283: /* column_name */ - case 291: /* table_name */ - case 298: /* function_name */ - case 304: /* index_name */ - case 311: /* topic_name */ - case 313: /* cgroup_name */ - case 318: /* stream_name */ - case 325: /* table_alias */ - case 326: /* column_alias */ - case 332: /* star_func */ - case 334: /* noarg_func */ - case 349: /* alias_opt */ + case 258: /* user_name */ + case 261: /* priv_level */ + case 264: /* db_name */ + case 265: /* dnode_endpoint */ + case 284: /* column_name */ + case 292: /* table_name */ + case 299: /* function_name */ + case 305: /* index_name */ + case 312: /* topic_name */ + case 314: /* cgroup_name */ + case 319: /* stream_name */ + case 326: /* table_alias */ + case 327: /* column_alias */ + case 333: /* star_func */ + case 335: /* noarg_func */ + case 350: /* alias_opt */ { } break; - case 258: /* sysinfo_opt */ + case 259: /* sysinfo_opt */ { } break; - case 259: /* privileges */ - case 261: /* priv_type_list */ - case 262: /* priv_type */ + case 260: /* privileges */ + case 262: /* priv_type_list */ + case 263: /* priv_type */ { } break; - case 265: /* not_exists_opt */ - case 267: /* exists_opt */ - case 314: /* analyze_opt */ - case 316: /* agg_func_opt */ - case 354: /* set_quantifier_opt */ + case 266: /* not_exists_opt */ + case 268: /* exists_opt */ + case 315: /* analyze_opt */ + case 317: /* agg_func_opt */ + case 355: /* set_quantifier_opt */ { } break; - case 269: /* integer_list */ - case 270: /* variable_list */ - case 271: /* retention_list */ - case 275: /* column_def_list */ - case 276: /* tags_def_opt */ - case 278: /* multi_create_clause */ - case 279: /* tags_def */ - case 280: /* multi_drop_clause */ - case 287: /* specific_tags_opt */ - case 288: /* expression_list */ - case 290: /* col_name_list */ - case 293: /* duration_list */ - case 294: /* rollup_func_list */ - case 306: /* func_list */ - case 320: /* dnode_list */ - case 324: /* literal_list */ - case 333: /* star_func_para_list */ - case 335: /* other_para_list */ - case 355: /* select_list */ - case 356: /* partition_by_clause_opt */ - case 361: /* group_by_clause_opt */ - case 365: /* group_by_list */ - case 367: /* order_by_clause_opt */ - case 371: /* sort_specification_list */ + case 270: /* integer_list */ + case 271: /* variable_list */ + case 272: /* retention_list */ + case 276: /* column_def_list */ + case 277: /* tags_def_opt */ + case 279: /* multi_create_clause */ + case 280: /* tags_def */ + case 281: /* multi_drop_clause */ + case 288: /* specific_cols_opt */ + case 289: /* expression_list */ + case 291: /* col_name_list */ + case 294: /* duration_list */ + case 295: /* rollup_func_list */ + case 307: /* func_list */ + case 321: /* dnode_list */ + case 325: /* literal_list */ + case 334: /* star_func_para_list */ + case 336: /* other_para_list */ + case 356: /* select_list */ + case 357: /* partition_by_clause_opt */ + case 362: /* group_by_clause_opt */ + case 366: /* group_by_list */ + case 368: /* order_by_clause_opt */ + case 372: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy424)); + nodesDestroyList((yypminor->yy552)); } break; - case 272: /* alter_db_option */ - case 295: /* alter_table_option */ + case 273: /* alter_db_option */ + case 296: /* alter_table_option */ { } break; - case 284: /* type_name */ + case 285: /* type_name */ { } break; - case 338: /* compare_op */ - case 339: /* in_op */ + case 339: /* compare_op */ + case 340: /* in_op */ { } break; - case 351: /* join_type */ + case 352: /* join_type */ { } break; - case 364: /* fill_mode */ + case 365: /* fill_mode */ { } break; - case 373: /* ordering_specification_opt */ + case 374: /* ordering_specification_opt */ { } break; - case 374: /* null_ordering_opt */ + case 375: /* null_ordering_opt */ { } @@ -2735,489 +2694,491 @@ 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[] = { - { 252, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 252, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 253, 0 }, /* (2) account_options ::= */ - { 253, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 253, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 253, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 253, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 253, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 253, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 253, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 253, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 253, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 254, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 254, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 256, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 256, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 256, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 256, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 256, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 256, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 256, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 256, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 256, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 256, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 252, -6 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ - { 252, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 252, -5 }, /* (26) cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ - { 252, -5 }, /* (27) cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ - { 252, -3 }, /* (28) cmd ::= DROP USER user_name */ - { 258, 0 }, /* (29) sysinfo_opt ::= */ - { 258, -2 }, /* (30) sysinfo_opt ::= SYSINFO NK_INTEGER */ - { 252, -6 }, /* (31) cmd ::= GRANT privileges ON priv_level TO user_name */ - { 252, -6 }, /* (32) cmd ::= REVOKE privileges ON priv_level FROM user_name */ - { 259, -1 }, /* (33) privileges ::= ALL */ - { 259, -1 }, /* (34) privileges ::= priv_type_list */ - { 261, -1 }, /* (35) priv_type_list ::= priv_type */ - { 261, -3 }, /* (36) priv_type_list ::= priv_type_list NK_COMMA priv_type */ - { 262, -1 }, /* (37) priv_type ::= READ */ - { 262, -1 }, /* (38) priv_type ::= WRITE */ - { 260, -3 }, /* (39) priv_level ::= NK_STAR NK_DOT NK_STAR */ - { 260, -3 }, /* (40) priv_level ::= db_name NK_DOT NK_STAR */ - { 252, -3 }, /* (41) cmd ::= CREATE DNODE dnode_endpoint */ - { 252, -5 }, /* (42) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ - { 252, -3 }, /* (43) cmd ::= DROP DNODE NK_INTEGER */ - { 252, -3 }, /* (44) cmd ::= DROP DNODE dnode_endpoint */ - { 252, -4 }, /* (45) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 252, -5 }, /* (46) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 252, -4 }, /* (47) cmd ::= ALTER ALL DNODES NK_STRING */ - { 252, -5 }, /* (48) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 264, -1 }, /* (49) dnode_endpoint ::= NK_STRING */ - { 264, -1 }, /* (50) dnode_endpoint ::= NK_ID */ - { 264, -1 }, /* (51) dnode_endpoint ::= NK_IPTOKEN */ - { 252, -3 }, /* (52) cmd ::= ALTER LOCAL NK_STRING */ - { 252, -4 }, /* (53) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 252, -5 }, /* (54) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (55) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (56) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (57) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (58) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (59) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (60) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (61) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ - { 252, -5 }, /* (62) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 252, -4 }, /* (63) cmd ::= DROP DATABASE exists_opt db_name */ - { 252, -2 }, /* (64) cmd ::= USE db_name */ - { 252, -4 }, /* (65) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 265, -3 }, /* (66) not_exists_opt ::= IF NOT EXISTS */ - { 265, 0 }, /* (67) not_exists_opt ::= */ - { 267, -2 }, /* (68) exists_opt ::= IF EXISTS */ - { 267, 0 }, /* (69) exists_opt ::= */ - { 266, 0 }, /* (70) db_options ::= */ - { 266, -3 }, /* (71) db_options ::= db_options BUFFER NK_INTEGER */ - { 266, -3 }, /* (72) db_options ::= db_options CACHELAST NK_INTEGER */ - { 266, -3 }, /* (73) db_options ::= db_options COMP NK_INTEGER */ - { 266, -3 }, /* (74) db_options ::= db_options DURATION NK_INTEGER */ - { 266, -3 }, /* (75) db_options ::= db_options DURATION NK_VARIABLE */ - { 266, -3 }, /* (76) db_options ::= db_options FSYNC NK_INTEGER */ - { 266, -3 }, /* (77) db_options ::= db_options MAXROWS NK_INTEGER */ - { 266, -3 }, /* (78) db_options ::= db_options MINROWS NK_INTEGER */ - { 266, -3 }, /* (79) db_options ::= db_options KEEP integer_list */ - { 266, -3 }, /* (80) db_options ::= db_options KEEP variable_list */ - { 266, -3 }, /* (81) db_options ::= db_options PAGES NK_INTEGER */ - { 266, -3 }, /* (82) db_options ::= db_options PAGESIZE NK_INTEGER */ - { 266, -3 }, /* (83) db_options ::= db_options PRECISION NK_STRING */ - { 266, -3 }, /* (84) db_options ::= db_options REPLICA NK_INTEGER */ - { 266, -3 }, /* (85) db_options ::= db_options STRICT NK_INTEGER */ - { 266, -3 }, /* (86) db_options ::= db_options WAL NK_INTEGER */ - { 266, -3 }, /* (87) db_options ::= db_options VGROUPS NK_INTEGER */ - { 266, -3 }, /* (88) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 266, -3 }, /* (89) db_options ::= db_options RETENTIONS retention_list */ - { 266, -3 }, /* (90) db_options ::= db_options SCHEMALESS NK_INTEGER */ - { 268, -1 }, /* (91) alter_db_options ::= alter_db_option */ - { 268, -2 }, /* (92) alter_db_options ::= alter_db_options alter_db_option */ - { 272, -2 }, /* (93) alter_db_option ::= BUFFER NK_INTEGER */ - { 272, -2 }, /* (94) alter_db_option ::= CACHELAST NK_INTEGER */ - { 272, -2 }, /* (95) alter_db_option ::= FSYNC NK_INTEGER */ - { 272, -2 }, /* (96) alter_db_option ::= KEEP integer_list */ - { 272, -2 }, /* (97) alter_db_option ::= KEEP variable_list */ - { 272, -2 }, /* (98) alter_db_option ::= PAGES NK_INTEGER */ - { 272, -2 }, /* (99) alter_db_option ::= REPLICA NK_INTEGER */ - { 272, -2 }, /* (100) alter_db_option ::= STRICT NK_INTEGER */ - { 272, -2 }, /* (101) alter_db_option ::= WAL NK_INTEGER */ - { 269, -1 }, /* (102) integer_list ::= NK_INTEGER */ - { 269, -3 }, /* (103) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 270, -1 }, /* (104) variable_list ::= NK_VARIABLE */ - { 270, -3 }, /* (105) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 271, -1 }, /* (106) retention_list ::= retention */ - { 271, -3 }, /* (107) retention_list ::= retention_list NK_COMMA retention */ - { 273, -3 }, /* (108) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 252, -9 }, /* (109) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 252, -3 }, /* (110) cmd ::= CREATE TABLE multi_create_clause */ - { 252, -9 }, /* (111) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 252, -3 }, /* (112) cmd ::= DROP TABLE multi_drop_clause */ - { 252, -4 }, /* (113) cmd ::= DROP STABLE exists_opt full_table_name */ - { 252, -3 }, /* (114) cmd ::= ALTER TABLE alter_table_clause */ - { 252, -3 }, /* (115) cmd ::= ALTER STABLE alter_table_clause */ - { 281, -2 }, /* (116) alter_table_clause ::= full_table_name alter_table_options */ - { 281, -5 }, /* (117) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 281, -4 }, /* (118) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 281, -5 }, /* (119) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 281, -5 }, /* (120) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 281, -5 }, /* (121) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 281, -4 }, /* (122) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 281, -5 }, /* (123) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 281, -5 }, /* (124) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 281, -6 }, /* (125) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ - { 278, -1 }, /* (126) multi_create_clause ::= create_subtable_clause */ - { 278, -2 }, /* (127) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 286, -10 }, /* (128) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP expression_list NK_RP table_options */ - { 280, -1 }, /* (129) multi_drop_clause ::= drop_table_clause */ - { 280, -2 }, /* (130) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 289, -2 }, /* (131) drop_table_clause ::= exists_opt full_table_name */ - { 287, 0 }, /* (132) specific_tags_opt ::= */ - { 287, -3 }, /* (133) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 274, -1 }, /* (134) full_table_name ::= table_name */ - { 274, -3 }, /* (135) full_table_name ::= db_name NK_DOT table_name */ - { 275, -1 }, /* (136) column_def_list ::= column_def */ - { 275, -3 }, /* (137) column_def_list ::= column_def_list NK_COMMA column_def */ - { 292, -2 }, /* (138) column_def ::= column_name type_name */ - { 292, -4 }, /* (139) column_def ::= column_name type_name COMMENT NK_STRING */ - { 284, -1 }, /* (140) type_name ::= BOOL */ - { 284, -1 }, /* (141) type_name ::= TINYINT */ - { 284, -1 }, /* (142) type_name ::= SMALLINT */ - { 284, -1 }, /* (143) type_name ::= INT */ - { 284, -1 }, /* (144) type_name ::= INTEGER */ - { 284, -1 }, /* (145) type_name ::= BIGINT */ - { 284, -1 }, /* (146) type_name ::= FLOAT */ - { 284, -1 }, /* (147) type_name ::= DOUBLE */ - { 284, -4 }, /* (148) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 284, -1 }, /* (149) type_name ::= TIMESTAMP */ - { 284, -4 }, /* (150) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 284, -2 }, /* (151) type_name ::= TINYINT UNSIGNED */ - { 284, -2 }, /* (152) type_name ::= SMALLINT UNSIGNED */ - { 284, -2 }, /* (153) type_name ::= INT UNSIGNED */ - { 284, -2 }, /* (154) type_name ::= BIGINT UNSIGNED */ - { 284, -1 }, /* (155) type_name ::= JSON */ - { 284, -4 }, /* (156) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 284, -1 }, /* (157) type_name ::= MEDIUMBLOB */ - { 284, -1 }, /* (158) type_name ::= BLOB */ - { 284, -4 }, /* (159) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 284, -1 }, /* (160) type_name ::= DECIMAL */ - { 284, -4 }, /* (161) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 284, -6 }, /* (162) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 276, 0 }, /* (163) tags_def_opt ::= */ - { 276, -1 }, /* (164) tags_def_opt ::= tags_def */ - { 279, -4 }, /* (165) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 277, 0 }, /* (166) table_options ::= */ - { 277, -3 }, /* (167) table_options ::= table_options COMMENT NK_STRING */ - { 277, -3 }, /* (168) table_options ::= table_options MAX_DELAY duration_list */ - { 277, -3 }, /* (169) table_options ::= table_options WATERMARK duration_list */ - { 277, -5 }, /* (170) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ - { 277, -3 }, /* (171) table_options ::= table_options TTL NK_INTEGER */ - { 277, -5 }, /* (172) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 282, -1 }, /* (173) alter_table_options ::= alter_table_option */ - { 282, -2 }, /* (174) alter_table_options ::= alter_table_options alter_table_option */ - { 295, -2 }, /* (175) alter_table_option ::= COMMENT NK_STRING */ - { 295, -2 }, /* (176) alter_table_option ::= TTL NK_INTEGER */ - { 293, -1 }, /* (177) duration_list ::= duration_literal */ - { 293, -3 }, /* (178) duration_list ::= duration_list NK_COMMA duration_literal */ - { 294, -1 }, /* (179) rollup_func_list ::= rollup_func_name */ - { 294, -3 }, /* (180) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ - { 297, -1 }, /* (181) rollup_func_name ::= function_name */ - { 297, -1 }, /* (182) rollup_func_name ::= FIRST */ - { 297, -1 }, /* (183) rollup_func_name ::= LAST */ - { 290, -1 }, /* (184) col_name_list ::= col_name */ - { 290, -3 }, /* (185) col_name_list ::= col_name_list NK_COMMA col_name */ - { 299, -1 }, /* (186) col_name ::= column_name */ - { 252, -2 }, /* (187) cmd ::= SHOW DNODES */ - { 252, -2 }, /* (188) cmd ::= SHOW USERS */ - { 252, -2 }, /* (189) cmd ::= SHOW DATABASES */ - { 252, -4 }, /* (190) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 252, -4 }, /* (191) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 252, -3 }, /* (192) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 252, -2 }, /* (193) cmd ::= SHOW MNODES */ - { 252, -2 }, /* (194) cmd ::= SHOW MODULES */ - { 252, -2 }, /* (195) cmd ::= SHOW QNODES */ - { 252, -2 }, /* (196) cmd ::= SHOW FUNCTIONS */ - { 252, -5 }, /* (197) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 252, -2 }, /* (198) cmd ::= SHOW STREAMS */ - { 252, -2 }, /* (199) cmd ::= SHOW ACCOUNTS */ - { 252, -2 }, /* (200) cmd ::= SHOW APPS */ - { 252, -2 }, /* (201) cmd ::= SHOW CONNECTIONS */ - { 252, -2 }, /* (202) cmd ::= SHOW LICENCE */ - { 252, -2 }, /* (203) cmd ::= SHOW GRANTS */ - { 252, -4 }, /* (204) cmd ::= SHOW CREATE DATABASE db_name */ - { 252, -4 }, /* (205) cmd ::= SHOW CREATE TABLE full_table_name */ - { 252, -4 }, /* (206) cmd ::= SHOW CREATE STABLE full_table_name */ - { 252, -2 }, /* (207) cmd ::= SHOW QUERIES */ - { 252, -2 }, /* (208) cmd ::= SHOW SCORES */ - { 252, -2 }, /* (209) cmd ::= SHOW TOPICS */ - { 252, -2 }, /* (210) cmd ::= SHOW VARIABLES */ - { 252, -3 }, /* (211) cmd ::= SHOW LOCAL VARIABLES */ - { 252, -4 }, /* (212) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ - { 252, -2 }, /* (213) cmd ::= SHOW BNODES */ - { 252, -2 }, /* (214) cmd ::= SHOW SNODES */ - { 252, -2 }, /* (215) cmd ::= SHOW CLUSTER */ - { 252, -2 }, /* (216) cmd ::= SHOW TRANSACTIONS */ - { 252, -4 }, /* (217) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ - { 252, -2 }, /* (218) cmd ::= SHOW CONSUMERS */ - { 252, -2 }, /* (219) cmd ::= SHOW SUBSCRIPTIONS */ - { 300, 0 }, /* (220) db_name_cond_opt ::= */ - { 300, -2 }, /* (221) db_name_cond_opt ::= db_name NK_DOT */ - { 301, 0 }, /* (222) like_pattern_opt ::= */ - { 301, -2 }, /* (223) like_pattern_opt ::= LIKE NK_STRING */ - { 302, -1 }, /* (224) table_name_cond ::= table_name */ - { 303, 0 }, /* (225) from_db_opt ::= */ - { 303, -2 }, /* (226) from_db_opt ::= FROM db_name */ - { 252, -8 }, /* (227) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 252, -4 }, /* (228) cmd ::= DROP INDEX exists_opt index_name */ - { 305, -10 }, /* (229) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ - { 305, -12 }, /* (230) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ - { 306, -1 }, /* (231) func_list ::= func */ - { 306, -3 }, /* (232) func_list ::= func_list NK_COMMA func */ - { 309, -4 }, /* (233) func ::= function_name NK_LP expression_list NK_RP */ - { 308, 0 }, /* (234) sma_stream_opt ::= */ - { 308, -3 }, /* (235) sma_stream_opt ::= stream_options WATERMARK duration_literal */ - { 308, -3 }, /* (236) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ - { 252, -6 }, /* (237) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 252, -7 }, /* (238) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ - { 252, -9 }, /* (239) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ - { 252, -7 }, /* (240) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ - { 252, -9 }, /* (241) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ - { 252, -4 }, /* (242) cmd ::= DROP TOPIC exists_opt topic_name */ - { 252, -7 }, /* (243) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ - { 252, -2 }, /* (244) cmd ::= DESC full_table_name */ - { 252, -2 }, /* (245) cmd ::= DESCRIBE full_table_name */ - { 252, -3 }, /* (246) cmd ::= RESET QUERY CACHE */ - { 252, -4 }, /* (247) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ - { 314, 0 }, /* (248) analyze_opt ::= */ - { 314, -1 }, /* (249) analyze_opt ::= ANALYZE */ - { 315, 0 }, /* (250) explain_options ::= */ - { 315, -3 }, /* (251) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 315, -3 }, /* (252) explain_options ::= explain_options RATIO NK_FLOAT */ - { 252, -6 }, /* (253) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ - { 252, -10 }, /* (254) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 252, -4 }, /* (255) cmd ::= DROP FUNCTION exists_opt function_name */ - { 316, 0 }, /* (256) agg_func_opt ::= */ - { 316, -1 }, /* (257) agg_func_opt ::= AGGREGATE */ - { 317, 0 }, /* (258) bufsize_opt ::= */ - { 317, -2 }, /* (259) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 252, -8 }, /* (260) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ - { 252, -4 }, /* (261) cmd ::= DROP STREAM exists_opt stream_name */ - { 319, 0 }, /* (262) into_opt ::= */ - { 319, -2 }, /* (263) into_opt ::= INTO full_table_name */ - { 310, 0 }, /* (264) stream_options ::= */ - { 310, -3 }, /* (265) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 310, -3 }, /* (266) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 310, -4 }, /* (267) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ - { 310, -3 }, /* (268) stream_options ::= stream_options WATERMARK duration_literal */ - { 310, -3 }, /* (269) stream_options ::= stream_options IGNORE EXPIRED */ - { 252, -3 }, /* (270) cmd ::= KILL CONNECTION NK_INTEGER */ - { 252, -3 }, /* (271) cmd ::= KILL QUERY NK_STRING */ - { 252, -3 }, /* (272) cmd ::= KILL TRANSACTION NK_INTEGER */ - { 252, -2 }, /* (273) cmd ::= BALANCE VGROUP */ - { 252, -4 }, /* (274) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 252, -4 }, /* (275) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 252, -3 }, /* (276) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 320, -2 }, /* (277) dnode_list ::= DNODE NK_INTEGER */ - { 320, -3 }, /* (278) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 252, -3 }, /* (279) cmd ::= SYNCDB db_name REPLICA */ - { 252, -4 }, /* (280) cmd ::= DELETE FROM full_table_name where_clause_opt */ - { 252, -1 }, /* (281) cmd ::= query_expression */ - { 255, -1 }, /* (282) literal ::= NK_INTEGER */ - { 255, -1 }, /* (283) literal ::= NK_FLOAT */ - { 255, -1 }, /* (284) literal ::= NK_STRING */ - { 255, -1 }, /* (285) literal ::= NK_BOOL */ - { 255, -2 }, /* (286) literal ::= TIMESTAMP NK_STRING */ - { 255, -1 }, /* (287) literal ::= duration_literal */ - { 255, -1 }, /* (288) literal ::= NULL */ - { 255, -1 }, /* (289) literal ::= NK_QUESTION */ - { 296, -1 }, /* (290) duration_literal ::= NK_VARIABLE */ - { 322, -1 }, /* (291) signed ::= NK_INTEGER */ - { 322, -2 }, /* (292) signed ::= NK_PLUS NK_INTEGER */ - { 322, -2 }, /* (293) signed ::= NK_MINUS NK_INTEGER */ - { 322, -1 }, /* (294) signed ::= NK_FLOAT */ - { 322, -2 }, /* (295) signed ::= NK_PLUS NK_FLOAT */ - { 322, -2 }, /* (296) signed ::= NK_MINUS NK_FLOAT */ - { 285, -1 }, /* (297) signed_literal ::= signed */ - { 285, -1 }, /* (298) signed_literal ::= NK_STRING */ - { 285, -1 }, /* (299) signed_literal ::= NK_BOOL */ - { 285, -2 }, /* (300) signed_literal ::= TIMESTAMP NK_STRING */ - { 285, -1 }, /* (301) signed_literal ::= duration_literal */ - { 285, -1 }, /* (302) signed_literal ::= NULL */ - { 285, -1 }, /* (303) signed_literal ::= literal_func */ - { 324, -1 }, /* (304) literal_list ::= signed_literal */ - { 324, -3 }, /* (305) literal_list ::= literal_list NK_COMMA signed_literal */ - { 263, -1 }, /* (306) db_name ::= NK_ID */ - { 291, -1 }, /* (307) table_name ::= NK_ID */ - { 283, -1 }, /* (308) column_name ::= NK_ID */ - { 298, -1 }, /* (309) function_name ::= NK_ID */ - { 325, -1 }, /* (310) table_alias ::= NK_ID */ - { 326, -1 }, /* (311) column_alias ::= NK_ID */ - { 257, -1 }, /* (312) user_name ::= NK_ID */ - { 304, -1 }, /* (313) index_name ::= NK_ID */ - { 311, -1 }, /* (314) topic_name ::= NK_ID */ - { 318, -1 }, /* (315) stream_name ::= NK_ID */ - { 313, -1 }, /* (316) cgroup_name ::= NK_ID */ - { 327, -1 }, /* (317) expression ::= literal */ - { 327, -1 }, /* (318) expression ::= pseudo_column */ - { 327, -1 }, /* (319) expression ::= column_reference */ - { 327, -1 }, /* (320) expression ::= function_expression */ - { 327, -1 }, /* (321) expression ::= subquery */ - { 327, -3 }, /* (322) expression ::= NK_LP expression NK_RP */ - { 327, -2 }, /* (323) expression ::= NK_PLUS expression */ - { 327, -2 }, /* (324) expression ::= NK_MINUS expression */ - { 327, -3 }, /* (325) expression ::= expression NK_PLUS expression */ - { 327, -3 }, /* (326) expression ::= expression NK_MINUS expression */ - { 327, -3 }, /* (327) expression ::= expression NK_STAR expression */ - { 327, -3 }, /* (328) expression ::= expression NK_SLASH expression */ - { 327, -3 }, /* (329) expression ::= expression NK_REM expression */ - { 327, -3 }, /* (330) expression ::= column_reference NK_ARROW NK_STRING */ - { 327, -3 }, /* (331) expression ::= expression NK_BITAND expression */ - { 327, -3 }, /* (332) expression ::= expression NK_BITOR expression */ - { 288, -1 }, /* (333) expression_list ::= expression */ - { 288, -3 }, /* (334) expression_list ::= expression_list NK_COMMA expression */ - { 329, -1 }, /* (335) column_reference ::= column_name */ - { 329, -3 }, /* (336) column_reference ::= table_name NK_DOT column_name */ - { 328, -1 }, /* (337) pseudo_column ::= ROWTS */ - { 328, -1 }, /* (338) pseudo_column ::= TBNAME */ - { 328, -3 }, /* (339) pseudo_column ::= table_name NK_DOT TBNAME */ - { 328, -1 }, /* (340) pseudo_column ::= QSTARTTS */ - { 328, -1 }, /* (341) pseudo_column ::= QENDTS */ - { 328, -1 }, /* (342) pseudo_column ::= WSTARTTS */ - { 328, -1 }, /* (343) pseudo_column ::= WENDTS */ - { 328, -1 }, /* (344) pseudo_column ::= WDURATION */ - { 330, -4 }, /* (345) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 330, -4 }, /* (346) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 330, -6 }, /* (347) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 330, -1 }, /* (348) function_expression ::= literal_func */ - { 323, -3 }, /* (349) literal_func ::= noarg_func NK_LP NK_RP */ - { 323, -1 }, /* (350) literal_func ::= NOW */ - { 334, -1 }, /* (351) noarg_func ::= NOW */ - { 334, -1 }, /* (352) noarg_func ::= TODAY */ - { 334, -1 }, /* (353) noarg_func ::= TIMEZONE */ - { 334, -1 }, /* (354) noarg_func ::= DATABASE */ - { 334, -1 }, /* (355) noarg_func ::= CLIENT_VERSION */ - { 334, -1 }, /* (356) noarg_func ::= SERVER_VERSION */ - { 334, -1 }, /* (357) noarg_func ::= SERVER_STATUS */ - { 334, -1 }, /* (358) noarg_func ::= CURRENT_USER */ - { 334, -1 }, /* (359) noarg_func ::= USER */ - { 332, -1 }, /* (360) star_func ::= COUNT */ - { 332, -1 }, /* (361) star_func ::= FIRST */ - { 332, -1 }, /* (362) star_func ::= LAST */ - { 332, -1 }, /* (363) star_func ::= LAST_ROW */ - { 333, -1 }, /* (364) star_func_para_list ::= NK_STAR */ - { 333, -1 }, /* (365) star_func_para_list ::= other_para_list */ - { 335, -1 }, /* (366) other_para_list ::= star_func_para */ - { 335, -3 }, /* (367) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 336, -1 }, /* (368) star_func_para ::= expression */ - { 336, -3 }, /* (369) star_func_para ::= table_name NK_DOT NK_STAR */ - { 337, -3 }, /* (370) predicate ::= expression compare_op expression */ - { 337, -5 }, /* (371) predicate ::= expression BETWEEN expression AND expression */ - { 337, -6 }, /* (372) predicate ::= expression NOT BETWEEN expression AND expression */ - { 337, -3 }, /* (373) predicate ::= expression IS NULL */ - { 337, -4 }, /* (374) predicate ::= expression IS NOT NULL */ - { 337, -3 }, /* (375) predicate ::= expression in_op in_predicate_value */ - { 338, -1 }, /* (376) compare_op ::= NK_LT */ - { 338, -1 }, /* (377) compare_op ::= NK_GT */ - { 338, -1 }, /* (378) compare_op ::= NK_LE */ - { 338, -1 }, /* (379) compare_op ::= NK_GE */ - { 338, -1 }, /* (380) compare_op ::= NK_NE */ - { 338, -1 }, /* (381) compare_op ::= NK_EQ */ - { 338, -1 }, /* (382) compare_op ::= LIKE */ - { 338, -2 }, /* (383) compare_op ::= NOT LIKE */ - { 338, -1 }, /* (384) compare_op ::= MATCH */ - { 338, -1 }, /* (385) compare_op ::= NMATCH */ - { 338, -1 }, /* (386) compare_op ::= CONTAINS */ - { 339, -1 }, /* (387) in_op ::= IN */ - { 339, -2 }, /* (388) in_op ::= NOT IN */ - { 340, -3 }, /* (389) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 341, -1 }, /* (390) boolean_value_expression ::= boolean_primary */ - { 341, -2 }, /* (391) boolean_value_expression ::= NOT boolean_primary */ - { 341, -3 }, /* (392) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 341, -3 }, /* (393) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 342, -1 }, /* (394) boolean_primary ::= predicate */ - { 342, -3 }, /* (395) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 343, -1 }, /* (396) common_expression ::= expression */ - { 343, -1 }, /* (397) common_expression ::= boolean_value_expression */ - { 344, 0 }, /* (398) from_clause_opt ::= */ - { 344, -2 }, /* (399) from_clause_opt ::= FROM table_reference_list */ - { 345, -1 }, /* (400) table_reference_list ::= table_reference */ - { 345, -3 }, /* (401) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 346, -1 }, /* (402) table_reference ::= table_primary */ - { 346, -1 }, /* (403) table_reference ::= joined_table */ - { 347, -2 }, /* (404) table_primary ::= table_name alias_opt */ - { 347, -4 }, /* (405) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 347, -2 }, /* (406) table_primary ::= subquery alias_opt */ - { 347, -1 }, /* (407) table_primary ::= parenthesized_joined_table */ - { 349, 0 }, /* (408) alias_opt ::= */ - { 349, -1 }, /* (409) alias_opt ::= table_alias */ - { 349, -2 }, /* (410) alias_opt ::= AS table_alias */ - { 350, -3 }, /* (411) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 350, -3 }, /* (412) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 348, -6 }, /* (413) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 351, 0 }, /* (414) join_type ::= */ - { 351, -1 }, /* (415) join_type ::= INNER */ - { 353, -12 }, /* (416) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 354, 0 }, /* (417) set_quantifier_opt ::= */ - { 354, -1 }, /* (418) set_quantifier_opt ::= DISTINCT */ - { 354, -1 }, /* (419) set_quantifier_opt ::= ALL */ - { 355, -1 }, /* (420) select_list ::= select_item */ - { 355, -3 }, /* (421) select_list ::= select_list NK_COMMA select_item */ - { 363, -1 }, /* (422) select_item ::= NK_STAR */ - { 363, -1 }, /* (423) select_item ::= common_expression */ - { 363, -2 }, /* (424) select_item ::= common_expression column_alias */ - { 363, -3 }, /* (425) select_item ::= common_expression AS column_alias */ - { 363, -3 }, /* (426) select_item ::= table_name NK_DOT NK_STAR */ - { 321, 0 }, /* (427) where_clause_opt ::= */ - { 321, -2 }, /* (428) where_clause_opt ::= WHERE search_condition */ - { 356, 0 }, /* (429) partition_by_clause_opt ::= */ - { 356, -3 }, /* (430) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 360, 0 }, /* (431) twindow_clause_opt ::= */ - { 360, -6 }, /* (432) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 360, -4 }, /* (433) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 360, -6 }, /* (434) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 360, -8 }, /* (435) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 307, 0 }, /* (436) sliding_opt ::= */ - { 307, -4 }, /* (437) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 359, 0 }, /* (438) fill_opt ::= */ - { 359, -4 }, /* (439) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 359, -6 }, /* (440) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 364, -1 }, /* (441) fill_mode ::= NONE */ - { 364, -1 }, /* (442) fill_mode ::= PREV */ - { 364, -1 }, /* (443) fill_mode ::= NULL */ - { 364, -1 }, /* (444) fill_mode ::= LINEAR */ - { 364, -1 }, /* (445) fill_mode ::= NEXT */ - { 361, 0 }, /* (446) group_by_clause_opt ::= */ - { 361, -3 }, /* (447) group_by_clause_opt ::= GROUP BY group_by_list */ - { 365, -1 }, /* (448) group_by_list ::= expression */ - { 365, -3 }, /* (449) group_by_list ::= group_by_list NK_COMMA expression */ - { 362, 0 }, /* (450) having_clause_opt ::= */ - { 362, -2 }, /* (451) having_clause_opt ::= HAVING search_condition */ - { 357, 0 }, /* (452) range_opt ::= */ - { 357, -6 }, /* (453) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ - { 358, 0 }, /* (454) every_opt ::= */ - { 358, -4 }, /* (455) every_opt ::= EVERY NK_LP duration_literal NK_RP */ - { 312, -4 }, /* (456) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 366, -1 }, /* (457) query_expression_body ::= query_primary */ - { 366, -4 }, /* (458) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 366, -3 }, /* (459) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 370, -1 }, /* (460) query_primary ::= query_specification */ - { 370, -6 }, /* (461) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ - { 367, 0 }, /* (462) order_by_clause_opt ::= */ - { 367, -3 }, /* (463) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 368, 0 }, /* (464) slimit_clause_opt ::= */ - { 368, -2 }, /* (465) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 368, -4 }, /* (466) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 368, -4 }, /* (467) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 369, 0 }, /* (468) limit_clause_opt ::= */ - { 369, -2 }, /* (469) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 369, -4 }, /* (470) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 369, -4 }, /* (471) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 331, -3 }, /* (472) subquery ::= NK_LP query_expression NK_RP */ - { 352, -1 }, /* (473) search_condition ::= common_expression */ - { 371, -1 }, /* (474) sort_specification_list ::= sort_specification */ - { 371, -3 }, /* (475) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 372, -3 }, /* (476) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 373, 0 }, /* (477) ordering_specification_opt ::= */ - { 373, -1 }, /* (478) ordering_specification_opt ::= ASC */ - { 373, -1 }, /* (479) ordering_specification_opt ::= DESC */ - { 374, 0 }, /* (480) null_ordering_opt ::= */ - { 374, -2 }, /* (481) null_ordering_opt ::= NULLS FIRST */ - { 374, -2 }, /* (482) null_ordering_opt ::= NULLS LAST */ + { 253, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 253, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 254, 0 }, /* (2) account_options ::= */ + { 254, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 254, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 254, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 254, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 254, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 254, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 254, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 254, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 254, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 255, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 255, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 257, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 257, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 257, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 257, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 257, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 257, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 257, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 257, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 257, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 257, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 253, -6 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ + { 253, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 253, -5 }, /* (26) cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ + { 253, -5 }, /* (27) cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ + { 253, -3 }, /* (28) cmd ::= DROP USER user_name */ + { 259, 0 }, /* (29) sysinfo_opt ::= */ + { 259, -2 }, /* (30) sysinfo_opt ::= SYSINFO NK_INTEGER */ + { 253, -6 }, /* (31) cmd ::= GRANT privileges ON priv_level TO user_name */ + { 253, -6 }, /* (32) cmd ::= REVOKE privileges ON priv_level FROM user_name */ + { 260, -1 }, /* (33) privileges ::= ALL */ + { 260, -1 }, /* (34) privileges ::= priv_type_list */ + { 262, -1 }, /* (35) priv_type_list ::= priv_type */ + { 262, -3 }, /* (36) priv_type_list ::= priv_type_list NK_COMMA priv_type */ + { 263, -1 }, /* (37) priv_type ::= READ */ + { 263, -1 }, /* (38) priv_type ::= WRITE */ + { 261, -3 }, /* (39) priv_level ::= NK_STAR NK_DOT NK_STAR */ + { 261, -3 }, /* (40) priv_level ::= db_name NK_DOT NK_STAR */ + { 253, -3 }, /* (41) cmd ::= CREATE DNODE dnode_endpoint */ + { 253, -5 }, /* (42) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ + { 253, -3 }, /* (43) cmd ::= DROP DNODE NK_INTEGER */ + { 253, -3 }, /* (44) cmd ::= DROP DNODE dnode_endpoint */ + { 253, -4 }, /* (45) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 253, -5 }, /* (46) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 253, -4 }, /* (47) cmd ::= ALTER ALL DNODES NK_STRING */ + { 253, -5 }, /* (48) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 265, -1 }, /* (49) dnode_endpoint ::= NK_STRING */ + { 265, -1 }, /* (50) dnode_endpoint ::= NK_ID */ + { 265, -1 }, /* (51) dnode_endpoint ::= NK_IPTOKEN */ + { 253, -3 }, /* (52) cmd ::= ALTER LOCAL NK_STRING */ + { 253, -4 }, /* (53) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 253, -5 }, /* (54) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (55) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (56) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (57) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (58) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (59) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (60) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (61) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + { 253, -5 }, /* (62) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 253, -4 }, /* (63) cmd ::= DROP DATABASE exists_opt db_name */ + { 253, -2 }, /* (64) cmd ::= USE db_name */ + { 253, -4 }, /* (65) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 253, -3 }, /* (66) cmd ::= FLUSH DATABASE db_name */ + { 266, -3 }, /* (67) not_exists_opt ::= IF NOT EXISTS */ + { 266, 0 }, /* (68) not_exists_opt ::= */ + { 268, -2 }, /* (69) exists_opt ::= IF EXISTS */ + { 268, 0 }, /* (70) exists_opt ::= */ + { 267, 0 }, /* (71) db_options ::= */ + { 267, -3 }, /* (72) db_options ::= db_options BUFFER NK_INTEGER */ + { 267, -3 }, /* (73) db_options ::= db_options CACHELAST NK_INTEGER */ + { 267, -3 }, /* (74) db_options ::= db_options COMP NK_INTEGER */ + { 267, -3 }, /* (75) db_options ::= db_options DURATION NK_INTEGER */ + { 267, -3 }, /* (76) db_options ::= db_options DURATION NK_VARIABLE */ + { 267, -3 }, /* (77) db_options ::= db_options FSYNC NK_INTEGER */ + { 267, -3 }, /* (78) db_options ::= db_options MAXROWS NK_INTEGER */ + { 267, -3 }, /* (79) db_options ::= db_options MINROWS NK_INTEGER */ + { 267, -3 }, /* (80) db_options ::= db_options KEEP integer_list */ + { 267, -3 }, /* (81) db_options ::= db_options KEEP variable_list */ + { 267, -3 }, /* (82) db_options ::= db_options PAGES NK_INTEGER */ + { 267, -3 }, /* (83) db_options ::= db_options PAGESIZE NK_INTEGER */ + { 267, -3 }, /* (84) db_options ::= db_options PRECISION NK_STRING */ + { 267, -3 }, /* (85) db_options ::= db_options REPLICA NK_INTEGER */ + { 267, -3 }, /* (86) db_options ::= db_options STRICT NK_INTEGER */ + { 267, -3 }, /* (87) db_options ::= db_options WAL NK_INTEGER */ + { 267, -3 }, /* (88) db_options ::= db_options VGROUPS NK_INTEGER */ + { 267, -3 }, /* (89) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 267, -3 }, /* (90) db_options ::= db_options RETENTIONS retention_list */ + { 267, -3 }, /* (91) db_options ::= db_options SCHEMALESS NK_INTEGER */ + { 269, -1 }, /* (92) alter_db_options ::= alter_db_option */ + { 269, -2 }, /* (93) alter_db_options ::= alter_db_options alter_db_option */ + { 273, -2 }, /* (94) alter_db_option ::= BUFFER NK_INTEGER */ + { 273, -2 }, /* (95) alter_db_option ::= CACHELAST NK_INTEGER */ + { 273, -2 }, /* (96) alter_db_option ::= FSYNC NK_INTEGER */ + { 273, -2 }, /* (97) alter_db_option ::= KEEP integer_list */ + { 273, -2 }, /* (98) alter_db_option ::= KEEP variable_list */ + { 273, -2 }, /* (99) alter_db_option ::= PAGES NK_INTEGER */ + { 273, -2 }, /* (100) alter_db_option ::= REPLICA NK_INTEGER */ + { 273, -2 }, /* (101) alter_db_option ::= STRICT NK_INTEGER */ + { 273, -2 }, /* (102) alter_db_option ::= WAL NK_INTEGER */ + { 270, -1 }, /* (103) integer_list ::= NK_INTEGER */ + { 270, -3 }, /* (104) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 271, -1 }, /* (105) variable_list ::= NK_VARIABLE */ + { 271, -3 }, /* (106) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 272, -1 }, /* (107) retention_list ::= retention */ + { 272, -3 }, /* (108) retention_list ::= retention_list NK_COMMA retention */ + { 274, -3 }, /* (109) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 253, -9 }, /* (110) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 253, -3 }, /* (111) cmd ::= CREATE TABLE multi_create_clause */ + { 253, -9 }, /* (112) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 253, -3 }, /* (113) cmd ::= DROP TABLE multi_drop_clause */ + { 253, -4 }, /* (114) cmd ::= DROP STABLE exists_opt full_table_name */ + { 253, -3 }, /* (115) cmd ::= ALTER TABLE alter_table_clause */ + { 253, -3 }, /* (116) cmd ::= ALTER STABLE alter_table_clause */ + { 282, -2 }, /* (117) alter_table_clause ::= full_table_name alter_table_options */ + { 282, -5 }, /* (118) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 282, -4 }, /* (119) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 282, -5 }, /* (120) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 282, -5 }, /* (121) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 282, -5 }, /* (122) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 282, -4 }, /* (123) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 282, -5 }, /* (124) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 282, -5 }, /* (125) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 282, -6 }, /* (126) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ + { 279, -1 }, /* (127) multi_create_clause ::= create_subtable_clause */ + { 279, -2 }, /* (128) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 287, -10 }, /* (129) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ + { 281, -1 }, /* (130) multi_drop_clause ::= drop_table_clause */ + { 281, -2 }, /* (131) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 290, -2 }, /* (132) drop_table_clause ::= exists_opt full_table_name */ + { 288, 0 }, /* (133) specific_cols_opt ::= */ + { 288, -3 }, /* (134) specific_cols_opt ::= NK_LP col_name_list NK_RP */ + { 275, -1 }, /* (135) full_table_name ::= table_name */ + { 275, -3 }, /* (136) full_table_name ::= db_name NK_DOT table_name */ + { 276, -1 }, /* (137) column_def_list ::= column_def */ + { 276, -3 }, /* (138) column_def_list ::= column_def_list NK_COMMA column_def */ + { 293, -2 }, /* (139) column_def ::= column_name type_name */ + { 293, -4 }, /* (140) column_def ::= column_name type_name COMMENT NK_STRING */ + { 285, -1 }, /* (141) type_name ::= BOOL */ + { 285, -1 }, /* (142) type_name ::= TINYINT */ + { 285, -1 }, /* (143) type_name ::= SMALLINT */ + { 285, -1 }, /* (144) type_name ::= INT */ + { 285, -1 }, /* (145) type_name ::= INTEGER */ + { 285, -1 }, /* (146) type_name ::= BIGINT */ + { 285, -1 }, /* (147) type_name ::= FLOAT */ + { 285, -1 }, /* (148) type_name ::= DOUBLE */ + { 285, -4 }, /* (149) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 285, -1 }, /* (150) type_name ::= TIMESTAMP */ + { 285, -4 }, /* (151) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 285, -2 }, /* (152) type_name ::= TINYINT UNSIGNED */ + { 285, -2 }, /* (153) type_name ::= SMALLINT UNSIGNED */ + { 285, -2 }, /* (154) type_name ::= INT UNSIGNED */ + { 285, -2 }, /* (155) type_name ::= BIGINT UNSIGNED */ + { 285, -1 }, /* (156) type_name ::= JSON */ + { 285, -4 }, /* (157) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 285, -1 }, /* (158) type_name ::= MEDIUMBLOB */ + { 285, -1 }, /* (159) type_name ::= BLOB */ + { 285, -4 }, /* (160) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 285, -1 }, /* (161) type_name ::= DECIMAL */ + { 285, -4 }, /* (162) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 285, -6 }, /* (163) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 277, 0 }, /* (164) tags_def_opt ::= */ + { 277, -1 }, /* (165) tags_def_opt ::= tags_def */ + { 280, -4 }, /* (166) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 278, 0 }, /* (167) table_options ::= */ + { 278, -3 }, /* (168) table_options ::= table_options COMMENT NK_STRING */ + { 278, -3 }, /* (169) table_options ::= table_options MAX_DELAY duration_list */ + { 278, -3 }, /* (170) table_options ::= table_options WATERMARK duration_list */ + { 278, -5 }, /* (171) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ + { 278, -3 }, /* (172) table_options ::= table_options TTL NK_INTEGER */ + { 278, -5 }, /* (173) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 283, -1 }, /* (174) alter_table_options ::= alter_table_option */ + { 283, -2 }, /* (175) alter_table_options ::= alter_table_options alter_table_option */ + { 296, -2 }, /* (176) alter_table_option ::= COMMENT NK_STRING */ + { 296, -2 }, /* (177) alter_table_option ::= TTL NK_INTEGER */ + { 294, -1 }, /* (178) duration_list ::= duration_literal */ + { 294, -3 }, /* (179) duration_list ::= duration_list NK_COMMA duration_literal */ + { 295, -1 }, /* (180) rollup_func_list ::= rollup_func_name */ + { 295, -3 }, /* (181) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ + { 298, -1 }, /* (182) rollup_func_name ::= function_name */ + { 298, -1 }, /* (183) rollup_func_name ::= FIRST */ + { 298, -1 }, /* (184) rollup_func_name ::= LAST */ + { 291, -1 }, /* (185) col_name_list ::= col_name */ + { 291, -3 }, /* (186) col_name_list ::= col_name_list NK_COMMA col_name */ + { 300, -1 }, /* (187) col_name ::= column_name */ + { 253, -2 }, /* (188) cmd ::= SHOW DNODES */ + { 253, -2 }, /* (189) cmd ::= SHOW USERS */ + { 253, -2 }, /* (190) cmd ::= SHOW DATABASES */ + { 253, -4 }, /* (191) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 253, -4 }, /* (192) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 253, -3 }, /* (193) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 253, -2 }, /* (194) cmd ::= SHOW MNODES */ + { 253, -2 }, /* (195) cmd ::= SHOW MODULES */ + { 253, -2 }, /* (196) cmd ::= SHOW QNODES */ + { 253, -2 }, /* (197) cmd ::= SHOW FUNCTIONS */ + { 253, -5 }, /* (198) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 253, -2 }, /* (199) cmd ::= SHOW STREAMS */ + { 253, -2 }, /* (200) cmd ::= SHOW ACCOUNTS */ + { 253, -2 }, /* (201) cmd ::= SHOW APPS */ + { 253, -2 }, /* (202) cmd ::= SHOW CONNECTIONS */ + { 253, -2 }, /* (203) cmd ::= SHOW LICENCE */ + { 253, -2 }, /* (204) cmd ::= SHOW GRANTS */ + { 253, -4 }, /* (205) cmd ::= SHOW CREATE DATABASE db_name */ + { 253, -4 }, /* (206) cmd ::= SHOW CREATE TABLE full_table_name */ + { 253, -4 }, /* (207) cmd ::= SHOW CREATE STABLE full_table_name */ + { 253, -2 }, /* (208) cmd ::= SHOW QUERIES */ + { 253, -2 }, /* (209) cmd ::= SHOW SCORES */ + { 253, -2 }, /* (210) cmd ::= SHOW TOPICS */ + { 253, -2 }, /* (211) cmd ::= SHOW VARIABLES */ + { 253, -3 }, /* (212) cmd ::= SHOW LOCAL VARIABLES */ + { 253, -4 }, /* (213) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + { 253, -2 }, /* (214) cmd ::= SHOW BNODES */ + { 253, -2 }, /* (215) cmd ::= SHOW SNODES */ + { 253, -2 }, /* (216) cmd ::= SHOW CLUSTER */ + { 253, -2 }, /* (217) cmd ::= SHOW TRANSACTIONS */ + { 253, -4 }, /* (218) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ + { 253, -2 }, /* (219) cmd ::= SHOW CONSUMERS */ + { 253, -2 }, /* (220) cmd ::= SHOW SUBSCRIPTIONS */ + { 301, 0 }, /* (221) db_name_cond_opt ::= */ + { 301, -2 }, /* (222) db_name_cond_opt ::= db_name NK_DOT */ + { 302, 0 }, /* (223) like_pattern_opt ::= */ + { 302, -2 }, /* (224) like_pattern_opt ::= LIKE NK_STRING */ + { 303, -1 }, /* (225) table_name_cond ::= table_name */ + { 304, 0 }, /* (226) from_db_opt ::= */ + { 304, -2 }, /* (227) from_db_opt ::= FROM db_name */ + { 253, -8 }, /* (228) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 253, -4 }, /* (229) cmd ::= DROP INDEX exists_opt index_name */ + { 306, -10 }, /* (230) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ + { 306, -12 }, /* (231) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ + { 307, -1 }, /* (232) func_list ::= func */ + { 307, -3 }, /* (233) func_list ::= func_list NK_COMMA func */ + { 310, -4 }, /* (234) func ::= function_name NK_LP expression_list NK_RP */ + { 309, 0 }, /* (235) sma_stream_opt ::= */ + { 309, -3 }, /* (236) sma_stream_opt ::= stream_options WATERMARK duration_literal */ + { 309, -3 }, /* (237) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ + { 253, -6 }, /* (238) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 253, -7 }, /* (239) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ + { 253, -9 }, /* (240) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ + { 253, -7 }, /* (241) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ + { 253, -9 }, /* (242) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ + { 253, -4 }, /* (243) cmd ::= DROP TOPIC exists_opt topic_name */ + { 253, -7 }, /* (244) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ + { 253, -2 }, /* (245) cmd ::= DESC full_table_name */ + { 253, -2 }, /* (246) cmd ::= DESCRIBE full_table_name */ + { 253, -3 }, /* (247) cmd ::= RESET QUERY CACHE */ + { 253, -4 }, /* (248) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 315, 0 }, /* (249) analyze_opt ::= */ + { 315, -1 }, /* (250) analyze_opt ::= ANALYZE */ + { 316, 0 }, /* (251) explain_options ::= */ + { 316, -3 }, /* (252) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 316, -3 }, /* (253) explain_options ::= explain_options RATIO NK_FLOAT */ + { 253, -6 }, /* (254) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + { 253, -10 }, /* (255) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 253, -4 }, /* (256) cmd ::= DROP FUNCTION exists_opt function_name */ + { 317, 0 }, /* (257) agg_func_opt ::= */ + { 317, -1 }, /* (258) agg_func_opt ::= AGGREGATE */ + { 318, 0 }, /* (259) bufsize_opt ::= */ + { 318, -2 }, /* (260) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 253, -8 }, /* (261) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ + { 253, -4 }, /* (262) cmd ::= DROP STREAM exists_opt stream_name */ + { 320, 0 }, /* (263) into_opt ::= */ + { 320, -2 }, /* (264) into_opt ::= INTO full_table_name */ + { 311, 0 }, /* (265) stream_options ::= */ + { 311, -3 }, /* (266) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 311, -3 }, /* (267) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 311, -4 }, /* (268) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ + { 311, -3 }, /* (269) stream_options ::= stream_options WATERMARK duration_literal */ + { 311, -3 }, /* (270) stream_options ::= stream_options IGNORE EXPIRED */ + { 253, -3 }, /* (271) cmd ::= KILL CONNECTION NK_INTEGER */ + { 253, -3 }, /* (272) cmd ::= KILL QUERY NK_STRING */ + { 253, -3 }, /* (273) cmd ::= KILL TRANSACTION NK_INTEGER */ + { 253, -2 }, /* (274) cmd ::= BALANCE VGROUP */ + { 253, -4 }, /* (275) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 253, -4 }, /* (276) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 253, -3 }, /* (277) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 321, -2 }, /* (278) dnode_list ::= DNODE NK_INTEGER */ + { 321, -3 }, /* (279) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 253, -3 }, /* (280) cmd ::= SYNCDB db_name REPLICA */ + { 253, -4 }, /* (281) cmd ::= DELETE FROM full_table_name where_clause_opt */ + { 253, -1 }, /* (282) cmd ::= query_expression */ + { 253, -5 }, /* (283) cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ + { 256, -1 }, /* (284) literal ::= NK_INTEGER */ + { 256, -1 }, /* (285) literal ::= NK_FLOAT */ + { 256, -1 }, /* (286) literal ::= NK_STRING */ + { 256, -1 }, /* (287) literal ::= NK_BOOL */ + { 256, -2 }, /* (288) literal ::= TIMESTAMP NK_STRING */ + { 256, -1 }, /* (289) literal ::= duration_literal */ + { 256, -1 }, /* (290) literal ::= NULL */ + { 256, -1 }, /* (291) literal ::= NK_QUESTION */ + { 297, -1 }, /* (292) duration_literal ::= NK_VARIABLE */ + { 323, -1 }, /* (293) signed ::= NK_INTEGER */ + { 323, -2 }, /* (294) signed ::= NK_PLUS NK_INTEGER */ + { 323, -2 }, /* (295) signed ::= NK_MINUS NK_INTEGER */ + { 323, -1 }, /* (296) signed ::= NK_FLOAT */ + { 323, -2 }, /* (297) signed ::= NK_PLUS NK_FLOAT */ + { 323, -2 }, /* (298) signed ::= NK_MINUS NK_FLOAT */ + { 286, -1 }, /* (299) signed_literal ::= signed */ + { 286, -1 }, /* (300) signed_literal ::= NK_STRING */ + { 286, -1 }, /* (301) signed_literal ::= NK_BOOL */ + { 286, -2 }, /* (302) signed_literal ::= TIMESTAMP NK_STRING */ + { 286, -1 }, /* (303) signed_literal ::= duration_literal */ + { 286, -1 }, /* (304) signed_literal ::= NULL */ + { 286, -1 }, /* (305) signed_literal ::= literal_func */ + { 325, -1 }, /* (306) literal_list ::= signed_literal */ + { 325, -3 }, /* (307) literal_list ::= literal_list NK_COMMA signed_literal */ + { 264, -1 }, /* (308) db_name ::= NK_ID */ + { 292, -1 }, /* (309) table_name ::= NK_ID */ + { 284, -1 }, /* (310) column_name ::= NK_ID */ + { 299, -1 }, /* (311) function_name ::= NK_ID */ + { 326, -1 }, /* (312) table_alias ::= NK_ID */ + { 327, -1 }, /* (313) column_alias ::= NK_ID */ + { 258, -1 }, /* (314) user_name ::= NK_ID */ + { 305, -1 }, /* (315) index_name ::= NK_ID */ + { 312, -1 }, /* (316) topic_name ::= NK_ID */ + { 319, -1 }, /* (317) stream_name ::= NK_ID */ + { 314, -1 }, /* (318) cgroup_name ::= NK_ID */ + { 328, -1 }, /* (319) expression ::= literal */ + { 328, -1 }, /* (320) expression ::= pseudo_column */ + { 328, -1 }, /* (321) expression ::= column_reference */ + { 328, -1 }, /* (322) expression ::= function_expression */ + { 328, -1 }, /* (323) expression ::= subquery */ + { 328, -3 }, /* (324) expression ::= NK_LP expression NK_RP */ + { 328, -2 }, /* (325) expression ::= NK_PLUS expression */ + { 328, -2 }, /* (326) expression ::= NK_MINUS expression */ + { 328, -3 }, /* (327) expression ::= expression NK_PLUS expression */ + { 328, -3 }, /* (328) expression ::= expression NK_MINUS expression */ + { 328, -3 }, /* (329) expression ::= expression NK_STAR expression */ + { 328, -3 }, /* (330) expression ::= expression NK_SLASH expression */ + { 328, -3 }, /* (331) expression ::= expression NK_REM expression */ + { 328, -3 }, /* (332) expression ::= column_reference NK_ARROW NK_STRING */ + { 328, -3 }, /* (333) expression ::= expression NK_BITAND expression */ + { 328, -3 }, /* (334) expression ::= expression NK_BITOR expression */ + { 289, -1 }, /* (335) expression_list ::= expression */ + { 289, -3 }, /* (336) expression_list ::= expression_list NK_COMMA expression */ + { 330, -1 }, /* (337) column_reference ::= column_name */ + { 330, -3 }, /* (338) column_reference ::= table_name NK_DOT column_name */ + { 329, -1 }, /* (339) pseudo_column ::= ROWTS */ + { 329, -1 }, /* (340) pseudo_column ::= TBNAME */ + { 329, -3 }, /* (341) pseudo_column ::= table_name NK_DOT TBNAME */ + { 329, -1 }, /* (342) pseudo_column ::= QSTARTTS */ + { 329, -1 }, /* (343) pseudo_column ::= QENDTS */ + { 329, -1 }, /* (344) pseudo_column ::= WSTARTTS */ + { 329, -1 }, /* (345) pseudo_column ::= WENDTS */ + { 329, -1 }, /* (346) pseudo_column ::= WDURATION */ + { 331, -4 }, /* (347) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 331, -4 }, /* (348) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 331, -6 }, /* (349) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + { 331, -1 }, /* (350) function_expression ::= literal_func */ + { 324, -3 }, /* (351) literal_func ::= noarg_func NK_LP NK_RP */ + { 324, -1 }, /* (352) literal_func ::= NOW */ + { 335, -1 }, /* (353) noarg_func ::= NOW */ + { 335, -1 }, /* (354) noarg_func ::= TODAY */ + { 335, -1 }, /* (355) noarg_func ::= TIMEZONE */ + { 335, -1 }, /* (356) noarg_func ::= DATABASE */ + { 335, -1 }, /* (357) noarg_func ::= CLIENT_VERSION */ + { 335, -1 }, /* (358) noarg_func ::= SERVER_VERSION */ + { 335, -1 }, /* (359) noarg_func ::= SERVER_STATUS */ + { 335, -1 }, /* (360) noarg_func ::= CURRENT_USER */ + { 335, -1 }, /* (361) noarg_func ::= USER */ + { 333, -1 }, /* (362) star_func ::= COUNT */ + { 333, -1 }, /* (363) star_func ::= FIRST */ + { 333, -1 }, /* (364) star_func ::= LAST */ + { 333, -1 }, /* (365) star_func ::= LAST_ROW */ + { 334, -1 }, /* (366) star_func_para_list ::= NK_STAR */ + { 334, -1 }, /* (367) star_func_para_list ::= other_para_list */ + { 336, -1 }, /* (368) other_para_list ::= star_func_para */ + { 336, -3 }, /* (369) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 337, -1 }, /* (370) star_func_para ::= expression */ + { 337, -3 }, /* (371) star_func_para ::= table_name NK_DOT NK_STAR */ + { 338, -3 }, /* (372) predicate ::= expression compare_op expression */ + { 338, -5 }, /* (373) predicate ::= expression BETWEEN expression AND expression */ + { 338, -6 }, /* (374) predicate ::= expression NOT BETWEEN expression AND expression */ + { 338, -3 }, /* (375) predicate ::= expression IS NULL */ + { 338, -4 }, /* (376) predicate ::= expression IS NOT NULL */ + { 338, -3 }, /* (377) predicate ::= expression in_op in_predicate_value */ + { 339, -1 }, /* (378) compare_op ::= NK_LT */ + { 339, -1 }, /* (379) compare_op ::= NK_GT */ + { 339, -1 }, /* (380) compare_op ::= NK_LE */ + { 339, -1 }, /* (381) compare_op ::= NK_GE */ + { 339, -1 }, /* (382) compare_op ::= NK_NE */ + { 339, -1 }, /* (383) compare_op ::= NK_EQ */ + { 339, -1 }, /* (384) compare_op ::= LIKE */ + { 339, -2 }, /* (385) compare_op ::= NOT LIKE */ + { 339, -1 }, /* (386) compare_op ::= MATCH */ + { 339, -1 }, /* (387) compare_op ::= NMATCH */ + { 339, -1 }, /* (388) compare_op ::= CONTAINS */ + { 340, -1 }, /* (389) in_op ::= IN */ + { 340, -2 }, /* (390) in_op ::= NOT IN */ + { 341, -3 }, /* (391) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 342, -1 }, /* (392) boolean_value_expression ::= boolean_primary */ + { 342, -2 }, /* (393) boolean_value_expression ::= NOT boolean_primary */ + { 342, -3 }, /* (394) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 342, -3 }, /* (395) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 343, -1 }, /* (396) boolean_primary ::= predicate */ + { 343, -3 }, /* (397) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 344, -1 }, /* (398) common_expression ::= expression */ + { 344, -1 }, /* (399) common_expression ::= boolean_value_expression */ + { 345, 0 }, /* (400) from_clause_opt ::= */ + { 345, -2 }, /* (401) from_clause_opt ::= FROM table_reference_list */ + { 346, -1 }, /* (402) table_reference_list ::= table_reference */ + { 346, -3 }, /* (403) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 347, -1 }, /* (404) table_reference ::= table_primary */ + { 347, -1 }, /* (405) table_reference ::= joined_table */ + { 348, -2 }, /* (406) table_primary ::= table_name alias_opt */ + { 348, -4 }, /* (407) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 348, -2 }, /* (408) table_primary ::= subquery alias_opt */ + { 348, -1 }, /* (409) table_primary ::= parenthesized_joined_table */ + { 350, 0 }, /* (410) alias_opt ::= */ + { 350, -1 }, /* (411) alias_opt ::= table_alias */ + { 350, -2 }, /* (412) alias_opt ::= AS table_alias */ + { 351, -3 }, /* (413) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 351, -3 }, /* (414) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 349, -6 }, /* (415) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 352, 0 }, /* (416) join_type ::= */ + { 352, -1 }, /* (417) join_type ::= INNER */ + { 354, -12 }, /* (418) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 355, 0 }, /* (419) set_quantifier_opt ::= */ + { 355, -1 }, /* (420) set_quantifier_opt ::= DISTINCT */ + { 355, -1 }, /* (421) set_quantifier_opt ::= ALL */ + { 356, -1 }, /* (422) select_list ::= select_item */ + { 356, -3 }, /* (423) select_list ::= select_list NK_COMMA select_item */ + { 364, -1 }, /* (424) select_item ::= NK_STAR */ + { 364, -1 }, /* (425) select_item ::= common_expression */ + { 364, -2 }, /* (426) select_item ::= common_expression column_alias */ + { 364, -3 }, /* (427) select_item ::= common_expression AS column_alias */ + { 364, -3 }, /* (428) select_item ::= table_name NK_DOT NK_STAR */ + { 322, 0 }, /* (429) where_clause_opt ::= */ + { 322, -2 }, /* (430) where_clause_opt ::= WHERE search_condition */ + { 357, 0 }, /* (431) partition_by_clause_opt ::= */ + { 357, -3 }, /* (432) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 361, 0 }, /* (433) twindow_clause_opt ::= */ + { 361, -6 }, /* (434) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 361, -4 }, /* (435) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + { 361, -6 }, /* (436) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 361, -8 }, /* (437) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 308, 0 }, /* (438) sliding_opt ::= */ + { 308, -4 }, /* (439) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 360, 0 }, /* (440) fill_opt ::= */ + { 360, -4 }, /* (441) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 360, -6 }, /* (442) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 365, -1 }, /* (443) fill_mode ::= NONE */ + { 365, -1 }, /* (444) fill_mode ::= PREV */ + { 365, -1 }, /* (445) fill_mode ::= NULL */ + { 365, -1 }, /* (446) fill_mode ::= LINEAR */ + { 365, -1 }, /* (447) fill_mode ::= NEXT */ + { 362, 0 }, /* (448) group_by_clause_opt ::= */ + { 362, -3 }, /* (449) group_by_clause_opt ::= GROUP BY group_by_list */ + { 366, -1 }, /* (450) group_by_list ::= expression */ + { 366, -3 }, /* (451) group_by_list ::= group_by_list NK_COMMA expression */ + { 363, 0 }, /* (452) having_clause_opt ::= */ + { 363, -2 }, /* (453) having_clause_opt ::= HAVING search_condition */ + { 358, 0 }, /* (454) range_opt ::= */ + { 358, -6 }, /* (455) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ + { 359, 0 }, /* (456) every_opt ::= */ + { 359, -4 }, /* (457) every_opt ::= EVERY NK_LP duration_literal NK_RP */ + { 313, -4 }, /* (458) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 367, -1 }, /* (459) query_expression_body ::= query_primary */ + { 367, -4 }, /* (460) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 367, -3 }, /* (461) query_expression_body ::= query_expression_body UNION query_expression_body */ + { 371, -1 }, /* (462) query_primary ::= query_specification */ + { 371, -6 }, /* (463) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ + { 368, 0 }, /* (464) order_by_clause_opt ::= */ + { 368, -3 }, /* (465) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 369, 0 }, /* (466) slimit_clause_opt ::= */ + { 369, -2 }, /* (467) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 369, -4 }, /* (468) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 369, -4 }, /* (469) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 370, 0 }, /* (470) limit_clause_opt ::= */ + { 370, -2 }, /* (471) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 370, -4 }, /* (472) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 370, -4 }, /* (473) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 332, -3 }, /* (474) subquery ::= NK_LP query_expression NK_RP */ + { 353, -1 }, /* (475) search_condition ::= common_expression */ + { 372, -1 }, /* (476) sort_specification_list ::= sort_specification */ + { 372, -3 }, /* (477) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 373, -3 }, /* (478) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 374, 0 }, /* (479) ordering_specification_opt ::= */ + { 374, -1 }, /* (480) ordering_specification_opt ::= ASC */ + { 374, -1 }, /* (481) ordering_specification_opt ::= DESC */ + { 375, 0 }, /* (482) null_ordering_opt ::= */ + { 375, -2 }, /* (483) null_ordering_opt ::= NULLS FIRST */ + { 375, -2 }, /* (484) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3306,11 +3267,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,253,&yymsp[0].minor); + yy_destructor(yypParser,254,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,254,&yymsp[0].minor); + yy_destructor(yypParser,255,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3324,20 +3285,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,253,&yymsp[-2].minor); +{ yy_destructor(yypParser,254,&yymsp[-2].minor); { } - yy_destructor(yypParser,255,&yymsp[0].minor); + yy_destructor(yypParser,256,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,256,&yymsp[0].minor); +{ yy_destructor(yypParser,257,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,254,&yymsp[-1].minor); +{ yy_destructor(yypParser,255,&yymsp[-1].minor); { } - yy_destructor(yypParser,256,&yymsp[0].minor); + yy_destructor(yypParser,257,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3351,72 +3312,72 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,255,&yymsp[0].minor); + yy_destructor(yypParser,256,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy329, &yymsp[-1].minor.yy0, yymsp[0].minor.yy653); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy401, &yymsp[-1].minor.yy0, yymsp[0].minor.yy695); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy329, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy401, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy329, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy401, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy329, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy401, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } break; case 28: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy329); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy401); } break; case 29: /* sysinfo_opt ::= */ -{ yymsp[1].minor.yy653 = 1; } +{ yymsp[1].minor.yy695 = 1; } break; case 30: /* sysinfo_opt ::= SYSINFO NK_INTEGER */ -{ yymsp[-1].minor.yy653 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy695 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } break; case 31: /* cmd ::= GRANT privileges ON priv_level TO user_name */ -{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy609, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy329); } +{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy525, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy401); } break; case 32: /* cmd ::= REVOKE privileges ON priv_level FROM user_name */ -{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy609, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy329); } +{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy525, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy401); } break; case 33: /* privileges ::= ALL */ -{ yymsp[0].minor.yy609 = PRIVILEGE_TYPE_ALL; } +{ yymsp[0].minor.yy525 = PRIVILEGE_TYPE_ALL; } break; case 34: /* privileges ::= priv_type_list */ case 35: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==35); -{ yylhsminor.yy609 = yymsp[0].minor.yy609; } - yymsp[0].minor.yy609 = yylhsminor.yy609; +{ yylhsminor.yy525 = yymsp[0].minor.yy525; } + yymsp[0].minor.yy525 = yylhsminor.yy525; break; case 36: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */ -{ yylhsminor.yy609 = yymsp[-2].minor.yy609 | yymsp[0].minor.yy609; } - yymsp[-2].minor.yy609 = yylhsminor.yy609; +{ yylhsminor.yy525 = yymsp[-2].minor.yy525 | yymsp[0].minor.yy525; } + yymsp[-2].minor.yy525 = yylhsminor.yy525; break; case 37: /* priv_type ::= READ */ -{ yymsp[0].minor.yy609 = PRIVILEGE_TYPE_READ; } +{ yymsp[0].minor.yy525 = PRIVILEGE_TYPE_READ; } break; case 38: /* priv_type ::= WRITE */ -{ yymsp[0].minor.yy609 = PRIVILEGE_TYPE_WRITE; } +{ yymsp[0].minor.yy525 = PRIVILEGE_TYPE_WRITE; } break; case 39: /* priv_level ::= NK_STAR NK_DOT NK_STAR */ -{ yylhsminor.yy329 = yymsp[-2].minor.yy0; } - yymsp[-2].minor.yy329 = yylhsminor.yy329; +{ yylhsminor.yy401 = yymsp[-2].minor.yy0; } + yymsp[-2].minor.yy401 = yylhsminor.yy401; break; case 40: /* priv_level ::= db_name NK_DOT NK_STAR */ -{ yylhsminor.yy329 = yymsp[-2].minor.yy329; } - yymsp[-2].minor.yy329 = yylhsminor.yy329; +{ yylhsminor.yy401 = yymsp[-2].minor.yy401; } + yymsp[-2].minor.yy401 = yylhsminor.yy401; break; case 41: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy329, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy401, NULL); } break; case 42: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy0); } break; case 43: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 44: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy329); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy401); } break; case 45: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3433,32 +3394,32 @@ static YYACTIONTYPE yy_reduce( case 49: /* dnode_endpoint ::= NK_STRING */ case 50: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==50); case 51: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==51); - case 306: /* db_name ::= NK_ID */ yytestcase(yyruleno==306); - case 307: /* table_name ::= NK_ID */ yytestcase(yyruleno==307); - case 308: /* column_name ::= NK_ID */ yytestcase(yyruleno==308); - case 309: /* function_name ::= NK_ID */ yytestcase(yyruleno==309); - case 310: /* table_alias ::= NK_ID */ yytestcase(yyruleno==310); - case 311: /* column_alias ::= NK_ID */ yytestcase(yyruleno==311); - case 312: /* user_name ::= NK_ID */ yytestcase(yyruleno==312); - case 313: /* index_name ::= NK_ID */ yytestcase(yyruleno==313); - case 314: /* topic_name ::= NK_ID */ yytestcase(yyruleno==314); - case 315: /* stream_name ::= NK_ID */ yytestcase(yyruleno==315); - case 316: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==316); - case 351: /* noarg_func ::= NOW */ yytestcase(yyruleno==351); - case 352: /* noarg_func ::= TODAY */ yytestcase(yyruleno==352); - case 353: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==353); - case 354: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==354); - case 355: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==355); - case 356: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==356); - case 357: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==357); - case 358: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==358); - case 359: /* noarg_func ::= USER */ yytestcase(yyruleno==359); - case 360: /* star_func ::= COUNT */ yytestcase(yyruleno==360); - case 361: /* star_func ::= FIRST */ yytestcase(yyruleno==361); - case 362: /* star_func ::= LAST */ yytestcase(yyruleno==362); - case 363: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==363); -{ yylhsminor.yy329 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy329 = yylhsminor.yy329; + case 308: /* db_name ::= NK_ID */ yytestcase(yyruleno==308); + case 309: /* table_name ::= NK_ID */ yytestcase(yyruleno==309); + case 310: /* column_name ::= NK_ID */ yytestcase(yyruleno==310); + case 311: /* function_name ::= NK_ID */ yytestcase(yyruleno==311); + case 312: /* table_alias ::= NK_ID */ yytestcase(yyruleno==312); + case 313: /* column_alias ::= NK_ID */ yytestcase(yyruleno==313); + case 314: /* user_name ::= NK_ID */ yytestcase(yyruleno==314); + case 315: /* index_name ::= NK_ID */ yytestcase(yyruleno==315); + case 316: /* topic_name ::= NK_ID */ yytestcase(yyruleno==316); + case 317: /* stream_name ::= NK_ID */ yytestcase(yyruleno==317); + case 318: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==318); + case 353: /* noarg_func ::= NOW */ yytestcase(yyruleno==353); + case 354: /* noarg_func ::= TODAY */ yytestcase(yyruleno==354); + case 355: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==355); + case 356: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==356); + case 357: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==357); + case 358: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==358); + case 359: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==359); + case 360: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==360); + case 361: /* noarg_func ::= USER */ yytestcase(yyruleno==361); + case 362: /* star_func ::= COUNT */ yytestcase(yyruleno==362); + case 363: /* star_func ::= FIRST */ yytestcase(yyruleno==363); + case 364: /* star_func ::= LAST */ yytestcase(yyruleno==364); + case 365: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==365); +{ yylhsminor.yy401 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy401 = yylhsminor.yy401; break; case 52: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -3491,1221 +3452,1227 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; case 62: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy737, &yymsp[-1].minor.yy329, yymsp[0].minor.yy212); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy89, &yymsp[-1].minor.yy401, yymsp[0].minor.yy248); } break; case 63: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy737, &yymsp[0].minor.yy329); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy401); } break; case 64: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy329); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy401); } break; case 65: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy329, yymsp[0].minor.yy212); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy401, yymsp[0].minor.yy248); } + break; + case 66: /* cmd ::= FLUSH DATABASE db_name */ +{ pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &yymsp[0].minor.yy401); } + break; + case 67: /* not_exists_opt ::= IF NOT EXISTS */ +{ yymsp[-2].minor.yy89 = true; } + break; + case 68: /* not_exists_opt ::= */ + case 70: /* exists_opt ::= */ yytestcase(yyruleno==70); + case 249: /* analyze_opt ::= */ yytestcase(yyruleno==249); + case 257: /* agg_func_opt ::= */ yytestcase(yyruleno==257); + case 419: /* set_quantifier_opt ::= */ yytestcase(yyruleno==419); +{ yymsp[1].minor.yy89 = false; } break; - case 66: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy737 = true; } + case 69: /* exists_opt ::= IF EXISTS */ +{ yymsp[-1].minor.yy89 = true; } break; - case 67: /* not_exists_opt ::= */ - case 69: /* exists_opt ::= */ yytestcase(yyruleno==69); - case 248: /* analyze_opt ::= */ yytestcase(yyruleno==248); - case 256: /* agg_func_opt ::= */ yytestcase(yyruleno==256); - case 417: /* set_quantifier_opt ::= */ yytestcase(yyruleno==417); -{ yymsp[1].minor.yy737 = false; } + case 71: /* db_options ::= */ +{ yymsp[1].minor.yy248 = createDefaultDatabaseOptions(pCxt); } break; - case 68: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy737 = true; } + case 72: /* db_options ::= db_options BUFFER NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 70: /* db_options ::= */ -{ yymsp[1].minor.yy212 = createDefaultDatabaseOptions(pCxt); } + case 73: /* db_options ::= db_options CACHELAST NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 71: /* db_options ::= db_options BUFFER NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 74: /* db_options ::= db_options COMP NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 72: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 75: /* db_options ::= db_options DURATION NK_INTEGER */ + case 76: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==76); +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 73: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 77: /* db_options ::= db_options FSYNC NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 74: /* db_options ::= db_options DURATION NK_INTEGER */ - case 75: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==75); -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 78: /* db_options ::= db_options MAXROWS NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 76: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 79: /* db_options ::= db_options MINROWS NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 77: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 80: /* db_options ::= db_options KEEP integer_list */ + case 81: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==81); +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_KEEP, yymsp[0].minor.yy552); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 78: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 82: /* db_options ::= db_options PAGES NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 79: /* db_options ::= db_options KEEP integer_list */ - case 80: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==80); -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_KEEP, yymsp[0].minor.yy424); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 81: /* db_options ::= db_options PAGES NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 82: /* db_options ::= db_options PAGESIZE NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 83: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 84: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 85: /* db_options ::= db_options STRICT NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 86: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 87: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 88: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 89: /* db_options ::= db_options RETENTIONS retention_list */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_RETENTIONS, yymsp[0].minor.yy424); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 90: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ -{ yylhsminor.yy212 = setDatabaseOption(pCxt, yymsp[-2].minor.yy212, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 91: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy212 = createAlterDatabaseOptions(pCxt); yylhsminor.yy212 = setAlterDatabaseOption(pCxt, yylhsminor.yy212, &yymsp[0].minor.yy245); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 92: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy212 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy212, &yymsp[0].minor.yy245); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; - break; - case 93: /* alter_db_option ::= BUFFER NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } - break; - case 94: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } - break; - case 95: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } - break; - case 96: /* alter_db_option ::= KEEP integer_list */ - case 97: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==97); -{ yymsp[-1].minor.yy245.type = DB_OPTION_KEEP; yymsp[-1].minor.yy245.pList = yymsp[0].minor.yy424; } - break; - case 98: /* alter_db_option ::= PAGES NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = DB_OPTION_PAGES; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } - break; - case 99: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } - break; - case 100: /* alter_db_option ::= STRICT NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = DB_OPTION_STRICT; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } - break; - case 101: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = DB_OPTION_WAL; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } - break; - case 102: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy424 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy424 = yylhsminor.yy424; - break; - case 103: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 278: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==278); -{ yylhsminor.yy424 = addNodeToList(pCxt, yymsp[-2].minor.yy424, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy424 = yylhsminor.yy424; - break; - case 104: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy424 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy424 = yylhsminor.yy424; - break; - case 105: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy424 = addNodeToList(pCxt, yymsp[-2].minor.yy424, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy424 = yylhsminor.yy424; - break; - case 106: /* retention_list ::= retention */ - case 126: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==126); - case 129: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==129); - case 136: /* column_def_list ::= column_def */ yytestcase(yyruleno==136); - case 179: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==179); - case 184: /* col_name_list ::= col_name */ yytestcase(yyruleno==184); - case 231: /* func_list ::= func */ yytestcase(yyruleno==231); - case 304: /* literal_list ::= signed_literal */ yytestcase(yyruleno==304); - case 366: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==366); - case 420: /* select_list ::= select_item */ yytestcase(yyruleno==420); - case 474: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==474); -{ yylhsminor.yy424 = createNodeList(pCxt, yymsp[0].minor.yy212); } - yymsp[0].minor.yy424 = yylhsminor.yy424; - break; - case 107: /* retention_list ::= retention_list NK_COMMA retention */ - case 137: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==137); - case 180: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==180); - case 185: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==185); - case 232: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==232); - case 305: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==305); - case 367: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==367); - case 421: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==421); - case 475: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==475); -{ yylhsminor.yy424 = addNodeToList(pCxt, yymsp[-2].minor.yy424, yymsp[0].minor.yy212); } - yymsp[-2].minor.yy424 = yylhsminor.yy424; - break; - case 108: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy212 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 109: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 111: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==111); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy737, yymsp[-5].minor.yy212, yymsp[-3].minor.yy424, yymsp[-1].minor.yy424, yymsp[0].minor.yy212); } - break; - case 110: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy424); } - break; - case 112: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy424); } - break; - case 113: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy737, yymsp[0].minor.yy212); } - break; - case 114: /* cmd ::= ALTER TABLE alter_table_clause */ - case 281: /* cmd ::= query_expression */ yytestcase(yyruleno==281); -{ pCxt->pRootNode = yymsp[0].minor.yy212; } - break; - case 115: /* cmd ::= ALTER STABLE alter_table_clause */ -{ pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy212); } - break; - case 116: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy212 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy212, yymsp[0].minor.yy212); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 83: /* db_options ::= db_options PAGESIZE NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 84: /* db_options ::= db_options PRECISION NK_STRING */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 85: /* db_options ::= db_options REPLICA NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 86: /* db_options ::= db_options STRICT NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 87: /* db_options ::= db_options WAL NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 88: /* db_options ::= db_options VGROUPS NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 89: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 90: /* db_options ::= db_options RETENTIONS retention_list */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_RETENTIONS, yymsp[0].minor.yy552); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 91: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ +{ yylhsminor.yy248 = setDatabaseOption(pCxt, yymsp[-2].minor.yy248, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 92: /* alter_db_options ::= alter_db_option */ +{ yylhsminor.yy248 = createAlterDatabaseOptions(pCxt); yylhsminor.yy248 = setAlterDatabaseOption(pCxt, yylhsminor.yy248, &yymsp[0].minor.yy301); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 93: /* alter_db_options ::= alter_db_options alter_db_option */ +{ yylhsminor.yy248 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy248, &yymsp[0].minor.yy301); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; + break; + case 94: /* alter_db_option ::= BUFFER NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } + break; + case 95: /* alter_db_option ::= CACHELAST NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } + break; + case 96: /* alter_db_option ::= FSYNC NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } + break; + case 97: /* alter_db_option ::= KEEP integer_list */ + case 98: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==98); +{ yymsp[-1].minor.yy301.type = DB_OPTION_KEEP; yymsp[-1].minor.yy301.pList = yymsp[0].minor.yy552; } + break; + case 99: /* alter_db_option ::= PAGES NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = DB_OPTION_PAGES; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } + break; + case 100: /* alter_db_option ::= REPLICA NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } + break; + case 101: /* alter_db_option ::= STRICT NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = DB_OPTION_STRICT; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } + break; + case 102: /* alter_db_option ::= WAL NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = DB_OPTION_WAL; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } + break; + case 103: /* integer_list ::= NK_INTEGER */ +{ yylhsminor.yy552 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy552 = yylhsminor.yy552; + break; + case 104: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ + case 279: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==279); +{ yylhsminor.yy552 = addNodeToList(pCxt, yymsp[-2].minor.yy552, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy552 = yylhsminor.yy552; + break; + case 105: /* variable_list ::= NK_VARIABLE */ +{ yylhsminor.yy552 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy552 = yylhsminor.yy552; + break; + case 106: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ +{ yylhsminor.yy552 = addNodeToList(pCxt, yymsp[-2].minor.yy552, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy552 = yylhsminor.yy552; + break; + case 107: /* retention_list ::= retention */ + case 127: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==127); + case 130: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==130); + case 137: /* column_def_list ::= column_def */ yytestcase(yyruleno==137); + case 180: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==180); + case 185: /* col_name_list ::= col_name */ yytestcase(yyruleno==185); + case 232: /* func_list ::= func */ yytestcase(yyruleno==232); + case 306: /* literal_list ::= signed_literal */ yytestcase(yyruleno==306); + case 368: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==368); + case 422: /* select_list ::= select_item */ yytestcase(yyruleno==422); + case 476: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==476); +{ yylhsminor.yy552 = createNodeList(pCxt, yymsp[0].minor.yy248); } + yymsp[0].minor.yy552 = yylhsminor.yy552; + break; + case 108: /* retention_list ::= retention_list NK_COMMA retention */ + case 138: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==138); + case 181: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==181); + case 186: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==186); + case 233: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==233); + case 307: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==307); + case 369: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==369); + case 423: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==423); + case 477: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==477); +{ yylhsminor.yy552 = addNodeToList(pCxt, yymsp[-2].minor.yy552, yymsp[0].minor.yy248); } + yymsp[-2].minor.yy552 = yylhsminor.yy552; + break; + case 109: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ +{ yylhsminor.yy248 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 110: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 112: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==112); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy89, yymsp[-5].minor.yy248, yymsp[-3].minor.yy552, yymsp[-1].minor.yy552, yymsp[0].minor.yy248); } + break; + case 111: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy552); } + break; + case 113: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy552); } + break; + case 114: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy89, yymsp[0].minor.yy248); } + break; + case 115: /* cmd ::= ALTER TABLE alter_table_clause */ + case 282: /* cmd ::= query_expression */ yytestcase(yyruleno==282); +{ pCxt->pRootNode = yymsp[0].minor.yy248; } + break; + case 116: /* cmd ::= ALTER STABLE alter_table_clause */ +{ pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy248); } + break; + case 117: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy248 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy248, yymsp[0].minor.yy248); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 117: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy212 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy212, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy329, yymsp[0].minor.yy34); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 118: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ +{ yylhsminor.yy248 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy248, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy401, yymsp[0].minor.yy224); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 118: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy212 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy212, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy329); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; - break; - case 119: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy212 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy212, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy329, yymsp[0].minor.yy34); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 119: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ +{ yylhsminor.yy248 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy248, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy401); } + yymsp[-3].minor.yy248 = yylhsminor.yy248; + break; + case 120: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ +{ yylhsminor.yy248 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy248, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy401, yymsp[0].minor.yy224); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 120: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy212 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy212, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy329, &yymsp[0].minor.yy329); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 121: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ +{ yylhsminor.yy248 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy248, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy401, &yymsp[0].minor.yy401); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 121: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy212 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy212, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy329, yymsp[0].minor.yy34); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 122: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ +{ yylhsminor.yy248 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy248, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy401, yymsp[0].minor.yy224); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 122: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy212 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy212, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy329); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + case 123: /* alter_table_clause ::= full_table_name DROP TAG column_name */ +{ yylhsminor.yy248 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy248, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy401); } + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 123: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy212 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy212, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy329, yymsp[0].minor.yy34); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 124: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ +{ yylhsminor.yy248 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy248, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy401, yymsp[0].minor.yy224); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 124: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy212 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy212, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy329, &yymsp[0].minor.yy329); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 125: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ +{ yylhsminor.yy248 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy248, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy401, &yymsp[0].minor.yy401); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 125: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ -{ yylhsminor.yy212 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy212, &yymsp[-2].minor.yy329, yymsp[0].minor.yy212); } - yymsp[-5].minor.yy212 = yylhsminor.yy212; + case 126: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ +{ yylhsminor.yy248 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy248, &yymsp[-2].minor.yy401, yymsp[0].minor.yy248); } + yymsp[-5].minor.yy248 = yylhsminor.yy248; break; - case 127: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 130: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==130); -{ yylhsminor.yy424 = addNodeToList(pCxt, yymsp[-1].minor.yy424, yymsp[0].minor.yy212); } - yymsp[-1].minor.yy424 = yylhsminor.yy424; + case 128: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 131: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==131); +{ yylhsminor.yy552 = addNodeToList(pCxt, yymsp[-1].minor.yy552, yymsp[0].minor.yy248); } + yymsp[-1].minor.yy552 = yylhsminor.yy552; break; - case 128: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP expression_list NK_RP table_options */ -{ yylhsminor.yy212 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy737, yymsp[-8].minor.yy212, yymsp[-6].minor.yy212, yymsp[-5].minor.yy424, yymsp[-2].minor.yy424, yymsp[0].minor.yy212); } - yymsp[-9].minor.yy212 = yylhsminor.yy212; + case 129: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ +{ yylhsminor.yy248 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy89, yymsp[-8].minor.yy248, yymsp[-6].minor.yy248, yymsp[-5].minor.yy552, yymsp[-2].minor.yy552, yymsp[0].minor.yy248); } + yymsp[-9].minor.yy248 = yylhsminor.yy248; break; - case 131: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy212 = createDropTableClause(pCxt, yymsp[-1].minor.yy737, yymsp[0].minor.yy212); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 132: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy248 = createDropTableClause(pCxt, yymsp[-1].minor.yy89, yymsp[0].minor.yy248); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 132: /* specific_tags_opt ::= */ - case 163: /* tags_def_opt ::= */ yytestcase(yyruleno==163); - case 429: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==429); - case 446: /* group_by_clause_opt ::= */ yytestcase(yyruleno==446); - case 462: /* order_by_clause_opt ::= */ yytestcase(yyruleno==462); -{ yymsp[1].minor.yy424 = NULL; } + case 133: /* specific_cols_opt ::= */ + case 164: /* tags_def_opt ::= */ yytestcase(yyruleno==164); + case 431: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==431); + case 448: /* group_by_clause_opt ::= */ yytestcase(yyruleno==448); + case 464: /* order_by_clause_opt ::= */ yytestcase(yyruleno==464); +{ yymsp[1].minor.yy552 = NULL; } break; - case 133: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy424 = yymsp[-1].minor.yy424; } + case 134: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy552 = yymsp[-1].minor.yy552; } break; - case 134: /* full_table_name ::= table_name */ -{ yylhsminor.yy212 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy329, NULL); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 135: /* full_table_name ::= table_name */ +{ yylhsminor.yy248 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy401, NULL); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 135: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy212 = createRealTableNode(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy329, NULL); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 136: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy248 = createRealTableNode(pCxt, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy401, NULL); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 138: /* column_def ::= column_name type_name */ -{ yylhsminor.yy212 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy329, yymsp[0].minor.yy34, NULL); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 139: /* column_def ::= column_name type_name */ +{ yylhsminor.yy248 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy401, yymsp[0].minor.yy224, NULL); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 139: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy212 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy329, yymsp[-2].minor.yy34, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + case 140: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy248 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy401, yymsp[-2].minor.yy224, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 140: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 141: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 141: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 142: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 142: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 143: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 143: /* type_name ::= INT */ - case 144: /* type_name ::= INTEGER */ yytestcase(yyruleno==144); -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_INT); } + case 144: /* type_name ::= INT */ + case 145: /* type_name ::= INTEGER */ yytestcase(yyruleno==145); +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 145: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 146: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 146: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 147: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 147: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 148: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 148: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy34 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 149: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 149: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 150: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 150: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy34 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 151: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 151: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy34 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 152: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 152: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy34 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 153: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 153: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy34 = createDataType(TSDB_DATA_TYPE_UINT); } + case 154: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 154: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy34 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 155: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 155: /* type_name ::= JSON */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_JSON); } + case 156: /* type_name ::= JSON */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 156: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy34 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 157: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 157: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 158: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 158: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 159: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 159: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy34 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 160: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 160: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy34 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 161: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 161: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy34 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 162: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 162: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy34 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 163: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy224 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 164: /* tags_def_opt ::= tags_def */ - case 365: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==365); -{ yylhsminor.yy424 = yymsp[0].minor.yy424; } - yymsp[0].minor.yy424 = yylhsminor.yy424; + case 165: /* tags_def_opt ::= tags_def */ + case 367: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==367); +{ yylhsminor.yy552 = yymsp[0].minor.yy552; } + yymsp[0].minor.yy552 = yylhsminor.yy552; break; - case 165: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy424 = yymsp[-1].minor.yy424; } + case 166: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy552 = yymsp[-1].minor.yy552; } break; - case 166: /* table_options ::= */ -{ yymsp[1].minor.yy212 = createDefaultTableOptions(pCxt); } + case 167: /* table_options ::= */ +{ yymsp[1].minor.yy248 = createDefaultTableOptions(pCxt); } break; - case 167: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy212 = setTableOption(pCxt, yymsp[-2].minor.yy212, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 168: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy248 = setTableOption(pCxt, yymsp[-2].minor.yy248, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 168: /* table_options ::= table_options MAX_DELAY duration_list */ -{ yylhsminor.yy212 = setTableOption(pCxt, yymsp[-2].minor.yy212, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy424); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 169: /* table_options ::= table_options MAX_DELAY duration_list */ +{ yylhsminor.yy248 = setTableOption(pCxt, yymsp[-2].minor.yy248, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy552); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 169: /* table_options ::= table_options WATERMARK duration_list */ -{ yylhsminor.yy212 = setTableOption(pCxt, yymsp[-2].minor.yy212, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy424); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 170: /* table_options ::= table_options WATERMARK duration_list */ +{ yylhsminor.yy248 = setTableOption(pCxt, yymsp[-2].minor.yy248, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy552); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 170: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ -{ yylhsminor.yy212 = setTableOption(pCxt, yymsp[-4].minor.yy212, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy424); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 171: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ +{ yylhsminor.yy248 = setTableOption(pCxt, yymsp[-4].minor.yy248, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy552); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 171: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy212 = setTableOption(pCxt, yymsp[-2].minor.yy212, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 172: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy248 = setTableOption(pCxt, yymsp[-2].minor.yy248, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 172: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy212 = setTableOption(pCxt, yymsp[-4].minor.yy212, TABLE_OPTION_SMA, yymsp[-1].minor.yy424); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + case 173: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy248 = setTableOption(pCxt, yymsp[-4].minor.yy248, TABLE_OPTION_SMA, yymsp[-1].minor.yy552); } + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 173: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy212 = createAlterTableOptions(pCxt); yylhsminor.yy212 = setTableOption(pCxt, yylhsminor.yy212, yymsp[0].minor.yy245.type, &yymsp[0].minor.yy245.val); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 174: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy248 = createAlterTableOptions(pCxt); yylhsminor.yy248 = setTableOption(pCxt, yylhsminor.yy248, yymsp[0].minor.yy301.type, &yymsp[0].minor.yy301.val); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 174: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy212 = setTableOption(pCxt, yymsp[-1].minor.yy212, yymsp[0].minor.yy245.type, &yymsp[0].minor.yy245.val); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 175: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy248 = setTableOption(pCxt, yymsp[-1].minor.yy248, yymsp[0].minor.yy301.type, &yymsp[0].minor.yy301.val); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 175: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy245.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } + case 176: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy301.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } break; - case 176: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy245.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy245.val = yymsp[0].minor.yy0; } + case 177: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy301.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy301.val = yymsp[0].minor.yy0; } break; - case 177: /* duration_list ::= duration_literal */ - case 333: /* expression_list ::= expression */ yytestcase(yyruleno==333); -{ yylhsminor.yy424 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy212)); } - yymsp[0].minor.yy424 = yylhsminor.yy424; + case 178: /* duration_list ::= duration_literal */ + case 335: /* expression_list ::= expression */ yytestcase(yyruleno==335); +{ yylhsminor.yy552 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy248)); } + yymsp[0].minor.yy552 = yylhsminor.yy552; break; - case 178: /* duration_list ::= duration_list NK_COMMA duration_literal */ - case 334: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==334); -{ yylhsminor.yy424 = addNodeToList(pCxt, yymsp[-2].minor.yy424, releaseRawExprNode(pCxt, yymsp[0].minor.yy212)); } - yymsp[-2].minor.yy424 = yylhsminor.yy424; + case 179: /* duration_list ::= duration_list NK_COMMA duration_literal */ + case 336: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==336); +{ yylhsminor.yy552 = addNodeToList(pCxt, yymsp[-2].minor.yy552, releaseRawExprNode(pCxt, yymsp[0].minor.yy248)); } + yymsp[-2].minor.yy552 = yylhsminor.yy552; break; - case 181: /* rollup_func_name ::= function_name */ -{ yylhsminor.yy212 = createFunctionNode(pCxt, &yymsp[0].minor.yy329, NULL); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 182: /* rollup_func_name ::= function_name */ +{ yylhsminor.yy248 = createFunctionNode(pCxt, &yymsp[0].minor.yy401, NULL); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 182: /* rollup_func_name ::= FIRST */ - case 183: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==183); -{ yylhsminor.yy212 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 183: /* rollup_func_name ::= FIRST */ + case 184: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==184); +{ yylhsminor.yy248 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 186: /* col_name ::= column_name */ -{ yylhsminor.yy212 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy329); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 187: /* col_name ::= column_name */ +{ yylhsminor.yy248 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy401); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 187: /* cmd ::= SHOW DNODES */ + case 188: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } break; - case 188: /* cmd ::= SHOW USERS */ + case 189: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } break; - case 189: /* cmd ::= SHOW DATABASES */ + case 190: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } break; - case 190: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy212, yymsp[0].minor.yy212, OP_TYPE_LIKE); } + case 191: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy248, yymsp[0].minor.yy248, OP_TYPE_LIKE); } break; - case 191: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy212, yymsp[0].minor.yy212, OP_TYPE_LIKE); } + case 192: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy248, yymsp[0].minor.yy248, OP_TYPE_LIKE); } break; - case 192: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy212, NULL, OP_TYPE_LIKE); } + case 193: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy248, NULL, OP_TYPE_LIKE); } break; - case 193: /* cmd ::= SHOW MNODES */ + case 194: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } break; - case 194: /* cmd ::= SHOW MODULES */ + case 195: /* cmd ::= SHOW MODULES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT); } break; - case 195: /* cmd ::= SHOW QNODES */ + case 196: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } break; - case 196: /* cmd ::= SHOW FUNCTIONS */ + case 197: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } break; - case 197: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy212, yymsp[-1].minor.yy212, OP_TYPE_EQUAL); } + case 198: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy248, yymsp[-1].minor.yy248, OP_TYPE_EQUAL); } break; - case 198: /* cmd ::= SHOW STREAMS */ + case 199: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } break; - case 199: /* cmd ::= SHOW ACCOUNTS */ + case 200: /* cmd ::= SHOW ACCOUNTS */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; - case 200: /* cmd ::= SHOW APPS */ + case 201: /* cmd ::= SHOW APPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } break; - case 201: /* cmd ::= SHOW CONNECTIONS */ + case 202: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } break; - case 202: /* cmd ::= SHOW LICENCE */ - case 203: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==203); + case 203: /* cmd ::= SHOW LICENCE */ + case 204: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==204); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT); } break; - case 204: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy329); } + case 205: /* cmd ::= SHOW CREATE DATABASE db_name */ +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy401); } break; - case 205: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy212); } + case 206: /* cmd ::= SHOW CREATE TABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy248); } break; - case 206: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy212); } + case 207: /* cmd ::= SHOW CREATE STABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy248); } break; - case 207: /* cmd ::= SHOW QUERIES */ + case 208: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } break; - case 208: /* cmd ::= SHOW SCORES */ + case 209: /* cmd ::= SHOW SCORES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } break; - case 209: /* cmd ::= SHOW TOPICS */ + case 210: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } break; - case 210: /* cmd ::= SHOW VARIABLES */ + case 211: /* cmd ::= SHOW VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } break; - case 211: /* cmd ::= SHOW LOCAL VARIABLES */ + case 212: /* cmd ::= SHOW LOCAL VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } break; - case 212: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + case 213: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-1].minor.yy0)); } break; - case 213: /* cmd ::= SHOW BNODES */ + case 214: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } break; - case 214: /* cmd ::= SHOW SNODES */ + case 215: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } break; - case 215: /* cmd ::= SHOW CLUSTER */ + case 216: /* cmd ::= SHOW CLUSTER */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } break; - case 216: /* cmd ::= SHOW TRANSACTIONS */ + case 217: /* cmd ::= SHOW TRANSACTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } break; - case 217: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ -{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy212); } + case 218: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ +{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy248); } break; - case 218: /* cmd ::= SHOW CONSUMERS */ + case 219: /* cmd ::= SHOW CONSUMERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } break; - case 219: /* cmd ::= SHOW SUBSCRIPTIONS */ + case 220: /* cmd ::= SHOW SUBSCRIPTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } break; - case 220: /* db_name_cond_opt ::= */ - case 225: /* from_db_opt ::= */ yytestcase(yyruleno==225); -{ yymsp[1].minor.yy212 = createDefaultDatabaseCondValue(pCxt); } + case 221: /* db_name_cond_opt ::= */ + case 226: /* from_db_opt ::= */ yytestcase(yyruleno==226); +{ yymsp[1].minor.yy248 = createDefaultDatabaseCondValue(pCxt); } break; - case 221: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy329); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 222: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy401); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 222: /* like_pattern_opt ::= */ - case 262: /* into_opt ::= */ yytestcase(yyruleno==262); - case 398: /* from_clause_opt ::= */ yytestcase(yyruleno==398); - case 427: /* where_clause_opt ::= */ yytestcase(yyruleno==427); - case 431: /* twindow_clause_opt ::= */ yytestcase(yyruleno==431); - case 436: /* sliding_opt ::= */ yytestcase(yyruleno==436); - case 438: /* fill_opt ::= */ yytestcase(yyruleno==438); - case 450: /* having_clause_opt ::= */ yytestcase(yyruleno==450); - case 452: /* range_opt ::= */ yytestcase(yyruleno==452); - case 454: /* every_opt ::= */ yytestcase(yyruleno==454); - case 464: /* slimit_clause_opt ::= */ yytestcase(yyruleno==464); - case 468: /* limit_clause_opt ::= */ yytestcase(yyruleno==468); -{ yymsp[1].minor.yy212 = NULL; } + case 223: /* like_pattern_opt ::= */ + case 263: /* into_opt ::= */ yytestcase(yyruleno==263); + case 400: /* from_clause_opt ::= */ yytestcase(yyruleno==400); + case 429: /* where_clause_opt ::= */ yytestcase(yyruleno==429); + case 433: /* twindow_clause_opt ::= */ yytestcase(yyruleno==433); + case 438: /* sliding_opt ::= */ yytestcase(yyruleno==438); + case 440: /* fill_opt ::= */ yytestcase(yyruleno==440); + case 452: /* having_clause_opt ::= */ yytestcase(yyruleno==452); + case 454: /* range_opt ::= */ yytestcase(yyruleno==454); + case 456: /* every_opt ::= */ yytestcase(yyruleno==456); + case 466: /* slimit_clause_opt ::= */ yytestcase(yyruleno==466); + case 470: /* limit_clause_opt ::= */ yytestcase(yyruleno==470); +{ yymsp[1].minor.yy248 = NULL; } break; - case 223: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 224: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 224: /* table_name_cond ::= table_name */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy329); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 225: /* table_name_cond ::= table_name */ +{ yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy401); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 226: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy329); } + case 227: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy401); } break; - case 227: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy737, &yymsp[-3].minor.yy329, &yymsp[-1].minor.yy329, NULL, yymsp[0].minor.yy212); } + case 228: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy89, &yymsp[-3].minor.yy401, &yymsp[-1].minor.yy401, NULL, yymsp[0].minor.yy248); } break; - case 228: /* cmd ::= DROP INDEX exists_opt index_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy737, &yymsp[0].minor.yy329); } + case 229: /* cmd ::= DROP INDEX exists_opt index_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy401); } break; - case 229: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ -{ yymsp[-9].minor.yy212 = createIndexOption(pCxt, yymsp[-7].minor.yy424, releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), NULL, yymsp[-1].minor.yy212, yymsp[0].minor.yy212); } + case 230: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-9].minor.yy248 = createIndexOption(pCxt, yymsp[-7].minor.yy552, releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), NULL, yymsp[-1].minor.yy248, yymsp[0].minor.yy248); } break; - case 230: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ -{ yymsp[-11].minor.yy212 = createIndexOption(pCxt, yymsp[-9].minor.yy424, releaseRawExprNode(pCxt, yymsp[-5].minor.yy212), releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), yymsp[-1].minor.yy212, yymsp[0].minor.yy212); } + case 231: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-11].minor.yy248 = createIndexOption(pCxt, yymsp[-9].minor.yy552, releaseRawExprNode(pCxt, yymsp[-5].minor.yy248), releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), yymsp[-1].minor.yy248, yymsp[0].minor.yy248); } break; - case 233: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy212 = createFunctionNode(pCxt, &yymsp[-3].minor.yy329, yymsp[-1].minor.yy424); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + case 234: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy248 = createFunctionNode(pCxt, &yymsp[-3].minor.yy401, yymsp[-1].minor.yy552); } + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 234: /* sma_stream_opt ::= */ - case 264: /* stream_options ::= */ yytestcase(yyruleno==264); -{ yymsp[1].minor.yy212 = createStreamOptions(pCxt); } + case 235: /* sma_stream_opt ::= */ + case 265: /* stream_options ::= */ yytestcase(yyruleno==265); +{ yymsp[1].minor.yy248 = createStreamOptions(pCxt); } break; - case 235: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ - case 268: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==268); -{ ((SStreamOptions*)yymsp[-2].minor.yy212)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy212); yylhsminor.yy212 = yymsp[-2].minor.yy212; } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 236: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ + case 269: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==269); +{ ((SStreamOptions*)yymsp[-2].minor.yy248)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy248); yylhsminor.yy248 = yymsp[-2].minor.yy248; } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 236: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-2].minor.yy212)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy212); yylhsminor.yy212 = yymsp[-2].minor.yy212; } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 237: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-2].minor.yy248)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy248); yylhsminor.yy248 = yymsp[-2].minor.yy248; } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 237: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy737, &yymsp[-2].minor.yy329, yymsp[0].minor.yy212); } + case 238: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy89, &yymsp[-2].minor.yy401, yymsp[0].minor.yy248); } break; - case 238: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy737, &yymsp[-3].minor.yy329, &yymsp[0].minor.yy329, false); } + case 239: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy89, &yymsp[-3].minor.yy401, &yymsp[0].minor.yy401, false); } break; - case 239: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy737, &yymsp[-5].minor.yy329, &yymsp[0].minor.yy329, true); } + case 240: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy89, &yymsp[-5].minor.yy401, &yymsp[0].minor.yy401, true); } break; - case 240: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy737, &yymsp[-3].minor.yy329, yymsp[0].minor.yy212, false); } + case 241: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy89, &yymsp[-3].minor.yy401, yymsp[0].minor.yy248, false); } break; - case 241: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy737, &yymsp[-5].minor.yy329, yymsp[0].minor.yy212, true); } + case 242: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy89, &yymsp[-5].minor.yy401, yymsp[0].minor.yy248, true); } break; - case 242: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy737, &yymsp[0].minor.yy329); } + case 243: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy401); } break; - case 243: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ -{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy737, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy329); } + case 244: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ +{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy89, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy401); } break; - case 244: /* cmd ::= DESC full_table_name */ - case 245: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==245); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy212); } + case 245: /* cmd ::= DESC full_table_name */ + case 246: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==246); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy248); } break; - case 246: /* cmd ::= RESET QUERY CACHE */ + case 247: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 247: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy737, yymsp[-1].minor.yy212, yymsp[0].minor.yy212); } + case 248: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy89, yymsp[-1].minor.yy248, yymsp[0].minor.yy248); } break; - case 249: /* analyze_opt ::= ANALYZE */ - case 257: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==257); - case 418: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==418); -{ yymsp[0].minor.yy737 = true; } + case 250: /* analyze_opt ::= ANALYZE */ + case 258: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==258); + case 420: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==420); +{ yymsp[0].minor.yy89 = true; } break; - case 250: /* explain_options ::= */ -{ yymsp[1].minor.yy212 = createDefaultExplainOptions(pCxt); } + case 251: /* explain_options ::= */ +{ yymsp[1].minor.yy248 = createDefaultExplainOptions(pCxt); } break; - case 251: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy212 = setExplainVerbose(pCxt, yymsp[-2].minor.yy212, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 252: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy248 = setExplainVerbose(pCxt, yymsp[-2].minor.yy248, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 252: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy212 = setExplainRatio(pCxt, yymsp[-2].minor.yy212, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 253: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy248 = setExplainRatio(pCxt, yymsp[-2].minor.yy248, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 253: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy424); } + case 254: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy552); } break; - case 254: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy737, yymsp[-8].minor.yy737, &yymsp[-5].minor.yy329, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy34, yymsp[0].minor.yy610); } + case 255: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy89, yymsp[-8].minor.yy89, &yymsp[-5].minor.yy401, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy224, yymsp[0].minor.yy228); } break; - case 255: /* cmd ::= DROP FUNCTION exists_opt function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy737, &yymsp[0].minor.yy329); } + case 256: /* cmd ::= DROP FUNCTION exists_opt function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy401); } break; - case 258: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy610 = 0; } + case 259: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy228 = 0; } break; - case 259: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy610 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } + case 260: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy228 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 260: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy737, &yymsp[-4].minor.yy329, yymsp[-2].minor.yy212, yymsp[-3].minor.yy212, yymsp[0].minor.yy212); } + case 261: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy89, &yymsp[-4].minor.yy401, yymsp[-2].minor.yy248, yymsp[-3].minor.yy248, yymsp[0].minor.yy248); } break; - case 261: /* cmd ::= DROP STREAM exists_opt stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy737, &yymsp[0].minor.yy329); } + case 262: /* cmd ::= DROP STREAM exists_opt stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy401); } break; - case 263: /* into_opt ::= INTO full_table_name */ - case 399: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==399); - case 428: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==428); - case 451: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==451); -{ yymsp[-1].minor.yy212 = yymsp[0].minor.yy212; } + case 264: /* into_opt ::= INTO full_table_name */ + case 401: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==401); + case 430: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==430); + case 453: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==453); +{ yymsp[-1].minor.yy248 = yymsp[0].minor.yy248; } break; - case 265: /* stream_options ::= stream_options TRIGGER AT_ONCE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy212)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy212 = yymsp[-2].minor.yy212; } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 266: /* stream_options ::= stream_options TRIGGER AT_ONCE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy248)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy248 = yymsp[-2].minor.yy248; } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 266: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy212)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy212 = yymsp[-2].minor.yy212; } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 267: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy248)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy248 = yymsp[-2].minor.yy248; } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 267: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-3].minor.yy212)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy212)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy212); yylhsminor.yy212 = yymsp[-3].minor.yy212; } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + case 268: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-3].minor.yy248)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy248)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy248); yylhsminor.yy248 = yymsp[-3].minor.yy248; } + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 269: /* stream_options ::= stream_options IGNORE EXPIRED */ -{ ((SStreamOptions*)yymsp[-2].minor.yy212)->ignoreExpired = true; yylhsminor.yy212 = yymsp[-2].minor.yy212; } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 270: /* stream_options ::= stream_options IGNORE EXPIRED */ +{ ((SStreamOptions*)yymsp[-2].minor.yy248)->ignoreExpired = true; yylhsminor.yy248 = yymsp[-2].minor.yy248; } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 270: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 271: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 271: /* cmd ::= KILL QUERY NK_STRING */ + case 272: /* cmd ::= KILL QUERY NK_STRING */ { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 272: /* cmd ::= KILL TRANSACTION NK_INTEGER */ + case 273: /* cmd ::= KILL TRANSACTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } break; - case 273: /* cmd ::= BALANCE VGROUP */ + case 274: /* cmd ::= BALANCE VGROUP */ { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } break; - case 274: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 275: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 275: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy424); } + case 276: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy552); } break; - case 276: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 277: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 277: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy424 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - break; - case 279: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy329); } - break; - case 280: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ -{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy212, yymsp[0].minor.yy212); } - break; - case 282: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 283: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 284: /* literal ::= NK_STRING */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 285: /* literal ::= NK_BOOL */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 286: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; - break; - case 287: /* literal ::= duration_literal */ - case 297: /* signed_literal ::= signed */ yytestcase(yyruleno==297); - case 317: /* expression ::= literal */ yytestcase(yyruleno==317); - case 318: /* expression ::= pseudo_column */ yytestcase(yyruleno==318); - case 319: /* expression ::= column_reference */ yytestcase(yyruleno==319); - case 320: /* expression ::= function_expression */ yytestcase(yyruleno==320); - case 321: /* expression ::= subquery */ yytestcase(yyruleno==321); - case 348: /* function_expression ::= literal_func */ yytestcase(yyruleno==348); - case 390: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==390); - case 394: /* boolean_primary ::= predicate */ yytestcase(yyruleno==394); - case 396: /* common_expression ::= expression */ yytestcase(yyruleno==396); - case 397: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==397); - case 400: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==400); - case 402: /* table_reference ::= table_primary */ yytestcase(yyruleno==402); - case 403: /* table_reference ::= joined_table */ yytestcase(yyruleno==403); - case 407: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==407); - case 457: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==457); - case 460: /* query_primary ::= query_specification */ yytestcase(yyruleno==460); -{ yylhsminor.yy212 = yymsp[0].minor.yy212; } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 288: /* literal ::= NULL */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 289: /* literal ::= NK_QUESTION */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 290: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 291: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 292: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - break; - case 293: /* signed ::= NK_MINUS NK_INTEGER */ + case 278: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy552 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + break; + case 280: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy401); } + break; + case 281: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ +{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy248, yymsp[0].minor.yy248); } + break; + case 283: /* cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ +{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-2].minor.yy248, yymsp[-1].minor.yy552, yymsp[0].minor.yy248); } + break; + case 284: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 285: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 286: /* literal ::= NK_STRING */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 287: /* literal ::= NK_BOOL */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 288: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; + break; + case 289: /* literal ::= duration_literal */ + case 299: /* signed_literal ::= signed */ yytestcase(yyruleno==299); + case 319: /* expression ::= literal */ yytestcase(yyruleno==319); + case 320: /* expression ::= pseudo_column */ yytestcase(yyruleno==320); + case 321: /* expression ::= column_reference */ yytestcase(yyruleno==321); + case 322: /* expression ::= function_expression */ yytestcase(yyruleno==322); + case 323: /* expression ::= subquery */ yytestcase(yyruleno==323); + case 350: /* function_expression ::= literal_func */ yytestcase(yyruleno==350); + case 392: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==392); + case 396: /* boolean_primary ::= predicate */ yytestcase(yyruleno==396); + case 398: /* common_expression ::= expression */ yytestcase(yyruleno==398); + case 399: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==399); + case 402: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==402); + case 404: /* table_reference ::= table_primary */ yytestcase(yyruleno==404); + case 405: /* table_reference ::= joined_table */ yytestcase(yyruleno==405); + case 409: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==409); + case 459: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==459); + case 462: /* query_primary ::= query_specification */ yytestcase(yyruleno==462); +{ yylhsminor.yy248 = yymsp[0].minor.yy248; } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 290: /* literal ::= NULL */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 291: /* literal ::= NK_QUESTION */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 292: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 293: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 294: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + break; + case 295: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 294: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 296: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 295: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 297: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 296: /* signed ::= NK_MINUS NK_FLOAT */ + case 298: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 298: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 300: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 299: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 301: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 300: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 302: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 301: /* signed_literal ::= duration_literal */ - case 303: /* signed_literal ::= literal_func */ yytestcase(yyruleno==303); - case 368: /* star_func_para ::= expression */ yytestcase(yyruleno==368); - case 423: /* select_item ::= common_expression */ yytestcase(yyruleno==423); - case 473: /* search_condition ::= common_expression */ yytestcase(yyruleno==473); -{ yylhsminor.yy212 = releaseRawExprNode(pCxt, yymsp[0].minor.yy212); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 303: /* signed_literal ::= duration_literal */ + case 305: /* signed_literal ::= literal_func */ yytestcase(yyruleno==305); + case 370: /* star_func_para ::= expression */ yytestcase(yyruleno==370); + case 425: /* select_item ::= common_expression */ yytestcase(yyruleno==425); + case 475: /* search_condition ::= common_expression */ yytestcase(yyruleno==475); +{ yylhsminor.yy248 = releaseRawExprNode(pCxt, yymsp[0].minor.yy248); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 302: /* signed_literal ::= NULL */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 304: /* signed_literal ::= NULL */ +{ yylhsminor.yy248 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 322: /* expression ::= NK_LP expression NK_RP */ - case 395: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==395); -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy212)); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 324: /* expression ::= NK_LP expression NK_RP */ + case 397: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==397); +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy248)); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 323: /* expression ::= NK_PLUS expression */ + case 325: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy212)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy248)); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 324: /* expression ::= NK_MINUS expression */ + case 326: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy212), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy248), NULL)); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 325: /* expression ::= expression NK_PLUS expression */ + case 327: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 326: /* expression ::= expression NK_MINUS expression */ + case 328: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 327: /* expression ::= expression NK_STAR expression */ + case 329: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 328: /* expression ::= expression NK_SLASH expression */ + case 330: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 329: /* expression ::= expression NK_REM expression */ + case 331: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 330: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 332: /* expression ::= column_reference NK_ARROW NK_STRING */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 331: /* expression ::= expression NK_BITAND expression */ + case 333: /* expression ::= expression NK_BITAND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 332: /* expression ::= expression NK_BITOR expression */ + case 334: /* expression ::= expression NK_BITOR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 335: /* column_reference ::= column_name */ -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy329, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy329)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 336: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy329, createColumnNode(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy329)); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 337: /* pseudo_column ::= ROWTS */ - case 338: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==338); - case 340: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==340); - case 341: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==341); - case 342: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==342); - case 343: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==343); - case 344: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==344); - case 350: /* literal_func ::= NOW */ yytestcase(yyruleno==350); -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 339: /* pseudo_column ::= table_name NK_DOT TBNAME */ -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy329)))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 345: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 346: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==346); -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy329, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy329, yymsp[-1].minor.yy424)); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; - break; - case 347: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), yymsp[-1].minor.yy34)); } - yymsp[-5].minor.yy212 = yylhsminor.yy212; - break; - case 349: /* literal_func ::= noarg_func NK_LP NK_RP */ -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy329, NULL)); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 364: /* star_func_para_list ::= NK_STAR */ -{ yylhsminor.yy424 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy424 = yylhsminor.yy424; - break; - case 369: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 426: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==426); -{ yylhsminor.yy212 = createColumnNode(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 370: /* predicate ::= expression compare_op expression */ - case 375: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==375); + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 337: /* column_reference ::= column_name */ +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy401, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy401)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 338: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy401, createColumnNode(pCxt, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy401)); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 339: /* pseudo_column ::= ROWTS */ + case 340: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==340); + case 342: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==342); + case 343: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==343); + case 344: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==344); + case 345: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==345); + case 346: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==346); + case 352: /* literal_func ::= NOW */ yytestcase(yyruleno==352); +{ yylhsminor.yy248 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy248 = yylhsminor.yy248; + break; + case 341: /* pseudo_column ::= table_name NK_DOT TBNAME */ +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy401)))); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 347: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 348: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==348); +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy401, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy401, yymsp[-1].minor.yy552)); } + yymsp[-3].minor.yy248 = yylhsminor.yy248; + break; + case 349: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), yymsp[-1].minor.yy224)); } + yymsp[-5].minor.yy248 = yylhsminor.yy248; + break; + case 351: /* literal_func ::= noarg_func NK_LP NK_RP */ +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy401, NULL)); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 366: /* star_func_para_list ::= NK_STAR */ +{ yylhsminor.yy552 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy552 = yylhsminor.yy552; + break; + case 371: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 428: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==428); +{ yylhsminor.yy248 = createColumnNode(pCxt, &yymsp[-2].minor.yy401, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; + break; + case 372: /* predicate ::= expression compare_op expression */ + case 377: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==377); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy290, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy716, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 371: /* predicate ::= expression BETWEEN expression AND expression */ + case 373: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy212), releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy248), releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-4].minor.yy212 = yylhsminor.yy212; + yymsp[-4].minor.yy248 = yylhsminor.yy248; break; - case 372: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 374: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy212), releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy248), releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-5].minor.yy212 = yylhsminor.yy212; + yymsp[-5].minor.yy248 = yylhsminor.yy248; break; - case 373: /* predicate ::= expression IS NULL */ + case 375: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), NULL)); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 374: /* predicate ::= expression IS NOT NULL */ + case 376: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), NULL)); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 376: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy290 = OP_TYPE_LOWER_THAN; } + case 378: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy716 = OP_TYPE_LOWER_THAN; } break; - case 377: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy290 = OP_TYPE_GREATER_THAN; } + case 379: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy716 = OP_TYPE_GREATER_THAN; } break; - case 378: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy290 = OP_TYPE_LOWER_EQUAL; } + case 380: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy716 = OP_TYPE_LOWER_EQUAL; } break; - case 379: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy290 = OP_TYPE_GREATER_EQUAL; } + case 381: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy716 = OP_TYPE_GREATER_EQUAL; } break; - case 380: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy290 = OP_TYPE_NOT_EQUAL; } + case 382: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy716 = OP_TYPE_NOT_EQUAL; } break; - case 381: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy290 = OP_TYPE_EQUAL; } + case 383: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy716 = OP_TYPE_EQUAL; } break; - case 382: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy290 = OP_TYPE_LIKE; } + case 384: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy716 = OP_TYPE_LIKE; } break; - case 383: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy290 = OP_TYPE_NOT_LIKE; } + case 385: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy716 = OP_TYPE_NOT_LIKE; } break; - case 384: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy290 = OP_TYPE_MATCH; } + case 386: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy716 = OP_TYPE_MATCH; } break; - case 385: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy290 = OP_TYPE_NMATCH; } + case 387: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy716 = OP_TYPE_NMATCH; } break; - case 386: /* compare_op ::= CONTAINS */ -{ yymsp[0].minor.yy290 = OP_TYPE_JSON_CONTAINS; } + case 388: /* compare_op ::= CONTAINS */ +{ yymsp[0].minor.yy716 = OP_TYPE_JSON_CONTAINS; } break; - case 387: /* in_op ::= IN */ -{ yymsp[0].minor.yy290 = OP_TYPE_IN; } + case 389: /* in_op ::= IN */ +{ yymsp[0].minor.yy716 = OP_TYPE_IN; } break; - case 388: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy290 = OP_TYPE_NOT_IN; } + case 390: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy716 = OP_TYPE_NOT_IN; } break; - case 389: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy424)); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 391: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy552)); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 391: /* boolean_value_expression ::= NOT boolean_primary */ + case 393: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy212), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy248), NULL)); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 392: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 394: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 393: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 395: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy212); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy212); - yylhsminor.yy212 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy248); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy248); + yylhsminor.yy248 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 401: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy212 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy212, yymsp[0].minor.yy212, NULL); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 403: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy248 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy248, yymsp[0].minor.yy248, NULL); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 404: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy212 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy329, &yymsp[0].minor.yy329); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 406: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy248 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy401, &yymsp[0].minor.yy401); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 405: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy212 = createRealTableNode(pCxt, &yymsp[-3].minor.yy329, &yymsp[-1].minor.yy329, &yymsp[0].minor.yy329); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + case 407: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy248 = createRealTableNode(pCxt, &yymsp[-3].minor.yy401, &yymsp[-1].minor.yy401, &yymsp[0].minor.yy401); } + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 406: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy212 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy212), &yymsp[0].minor.yy329); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 408: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy248 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy248), &yymsp[0].minor.yy401); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 408: /* alias_opt ::= */ -{ yymsp[1].minor.yy329 = nil_token; } + case 410: /* alias_opt ::= */ +{ yymsp[1].minor.yy401 = nil_token; } break; - case 409: /* alias_opt ::= table_alias */ -{ yylhsminor.yy329 = yymsp[0].minor.yy329; } - yymsp[0].minor.yy329 = yylhsminor.yy329; + case 411: /* alias_opt ::= table_alias */ +{ yylhsminor.yy401 = yymsp[0].minor.yy401; } + yymsp[0].minor.yy401 = yylhsminor.yy401; break; - case 410: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy329 = yymsp[0].minor.yy329; } + case 412: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy401 = yymsp[0].minor.yy401; } break; - case 411: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 412: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==412); -{ yymsp[-2].minor.yy212 = yymsp[-1].minor.yy212; } + case 413: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 414: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==414); +{ yymsp[-2].minor.yy248 = yymsp[-1].minor.yy248; } break; - case 413: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy212 = createJoinTableNode(pCxt, yymsp[-4].minor.yy162, yymsp[-5].minor.yy212, yymsp[-2].minor.yy212, yymsp[0].minor.yy212); } - yymsp[-5].minor.yy212 = yylhsminor.yy212; + case 415: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy248 = createJoinTableNode(pCxt, yymsp[-4].minor.yy52, yymsp[-5].minor.yy248, yymsp[-2].minor.yy248, yymsp[0].minor.yy248); } + yymsp[-5].minor.yy248 = yylhsminor.yy248; break; - case 414: /* join_type ::= */ -{ yymsp[1].minor.yy162 = JOIN_TYPE_INNER; } + case 416: /* join_type ::= */ +{ yymsp[1].minor.yy52 = JOIN_TYPE_INNER; } break; - case 415: /* join_type ::= INNER */ -{ yymsp[0].minor.yy162 = JOIN_TYPE_INNER; } + case 417: /* join_type ::= INNER */ +{ yymsp[0].minor.yy52 = JOIN_TYPE_INNER; } break; - case 416: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 418: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-11].minor.yy212 = createSelectStmt(pCxt, yymsp[-10].minor.yy737, yymsp[-9].minor.yy424, yymsp[-8].minor.yy212); - yymsp[-11].minor.yy212 = addWhereClause(pCxt, yymsp[-11].minor.yy212, yymsp[-7].minor.yy212); - yymsp[-11].minor.yy212 = addPartitionByClause(pCxt, yymsp[-11].minor.yy212, yymsp[-6].minor.yy424); - yymsp[-11].minor.yy212 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy212, yymsp[-2].minor.yy212); - yymsp[-11].minor.yy212 = addGroupByClause(pCxt, yymsp[-11].minor.yy212, yymsp[-1].minor.yy424); - yymsp[-11].minor.yy212 = addHavingClause(pCxt, yymsp[-11].minor.yy212, yymsp[0].minor.yy212); - yymsp[-11].minor.yy212 = addRangeClause(pCxt, yymsp[-11].minor.yy212, yymsp[-5].minor.yy212); - yymsp[-11].minor.yy212 = addEveryClause(pCxt, yymsp[-11].minor.yy212, yymsp[-4].minor.yy212); - yymsp[-11].minor.yy212 = addFillClause(pCxt, yymsp[-11].minor.yy212, yymsp[-3].minor.yy212); + yymsp[-11].minor.yy248 = createSelectStmt(pCxt, yymsp[-10].minor.yy89, yymsp[-9].minor.yy552, yymsp[-8].minor.yy248); + yymsp[-11].minor.yy248 = addWhereClause(pCxt, yymsp[-11].minor.yy248, yymsp[-7].minor.yy248); + yymsp[-11].minor.yy248 = addPartitionByClause(pCxt, yymsp[-11].minor.yy248, yymsp[-6].minor.yy552); + yymsp[-11].minor.yy248 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy248, yymsp[-2].minor.yy248); + yymsp[-11].minor.yy248 = addGroupByClause(pCxt, yymsp[-11].minor.yy248, yymsp[-1].minor.yy552); + yymsp[-11].minor.yy248 = addHavingClause(pCxt, yymsp[-11].minor.yy248, yymsp[0].minor.yy248); + yymsp[-11].minor.yy248 = addRangeClause(pCxt, yymsp[-11].minor.yy248, yymsp[-5].minor.yy248); + yymsp[-11].minor.yy248 = addEveryClause(pCxt, yymsp[-11].minor.yy248, yymsp[-4].minor.yy248); + yymsp[-11].minor.yy248 = addFillClause(pCxt, yymsp[-11].minor.yy248, yymsp[-3].minor.yy248); } break; - case 419: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy737 = false; } + case 421: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy89 = false; } break; - case 422: /* select_item ::= NK_STAR */ -{ yylhsminor.yy212 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy212 = yylhsminor.yy212; + case 424: /* select_item ::= NK_STAR */ +{ yylhsminor.yy248 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy248 = yylhsminor.yy248; break; - case 424: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy212 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy212), &yymsp[0].minor.yy329); } - yymsp[-1].minor.yy212 = yylhsminor.yy212; + case 426: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy248 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy248), &yymsp[0].minor.yy401); } + yymsp[-1].minor.yy248 = yylhsminor.yy248; break; - case 425: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy212 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), &yymsp[0].minor.yy329); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 427: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy248 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), &yymsp[0].minor.yy401); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 430: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 447: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==447); - case 463: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==463); -{ yymsp[-2].minor.yy424 = yymsp[0].minor.yy424; } + case 432: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 449: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==449); + case 465: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==465); +{ yymsp[-2].minor.yy552 = yymsp[0].minor.yy552; } break; - case 432: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy212 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), releaseRawExprNode(pCxt, yymsp[-1].minor.yy212)); } + case 434: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy248 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), releaseRawExprNode(pCxt, yymsp[-1].minor.yy248)); } break; - case 433: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy212 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy212)); } + case 435: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy248 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy248)); } break; - case 434: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy212 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), NULL, yymsp[-1].minor.yy212, yymsp[0].minor.yy212); } + case 436: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy248 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), NULL, yymsp[-1].minor.yy248, yymsp[0].minor.yy248); } break; - case 435: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy212 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy212), releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), yymsp[-1].minor.yy212, yymsp[0].minor.yy212); } + case 437: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy248 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy248), releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), yymsp[-1].minor.yy248, yymsp[0].minor.yy248); } break; - case 437: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - case 455: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==455); -{ yymsp[-3].minor.yy212 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy212); } + case 439: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + case 457: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==457); +{ yymsp[-3].minor.yy248 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy248); } break; - case 439: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy212 = createFillNode(pCxt, yymsp[-1].minor.yy294, NULL); } + case 441: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy248 = createFillNode(pCxt, yymsp[-1].minor.yy582, NULL); } break; - case 440: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy212 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy424)); } + case 442: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy248 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy552)); } break; - case 441: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy294 = FILL_MODE_NONE; } + case 443: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy582 = FILL_MODE_NONE; } break; - case 442: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy294 = FILL_MODE_PREV; } + case 444: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy582 = FILL_MODE_PREV; } break; - case 443: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy294 = FILL_MODE_NULL; } + case 445: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy582 = FILL_MODE_NULL; } break; - case 444: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy294 = FILL_MODE_LINEAR; } + case 446: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy582 = FILL_MODE_LINEAR; } break; - case 445: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy294 = FILL_MODE_NEXT; } + case 447: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy582 = FILL_MODE_NEXT; } break; - case 448: /* group_by_list ::= expression */ -{ yylhsminor.yy424 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); } - yymsp[0].minor.yy424 = yylhsminor.yy424; + case 450: /* group_by_list ::= expression */ +{ yylhsminor.yy552 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } + yymsp[0].minor.yy552 = yylhsminor.yy552; break; - case 449: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy424 = addNodeToList(pCxt, yymsp[-2].minor.yy424, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy212))); } - yymsp[-2].minor.yy424 = yylhsminor.yy424; + case 451: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy552 = addNodeToList(pCxt, yymsp[-2].minor.yy552, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy248))); } + yymsp[-2].minor.yy552 = yylhsminor.yy552; break; - case 453: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ -{ yymsp[-5].minor.yy212 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy212), releaseRawExprNode(pCxt, yymsp[-1].minor.yy212)); } + case 455: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ +{ yymsp[-5].minor.yy248 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy248), releaseRawExprNode(pCxt, yymsp[-1].minor.yy248)); } break; - case 456: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 458: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy212 = addOrderByClause(pCxt, yymsp[-3].minor.yy212, yymsp[-2].minor.yy424); - yylhsminor.yy212 = addSlimitClause(pCxt, yylhsminor.yy212, yymsp[-1].minor.yy212); - yylhsminor.yy212 = addLimitClause(pCxt, yylhsminor.yy212, yymsp[0].minor.yy212); + yylhsminor.yy248 = addOrderByClause(pCxt, yymsp[-3].minor.yy248, yymsp[-2].minor.yy552); + yylhsminor.yy248 = addSlimitClause(pCxt, yylhsminor.yy248, yymsp[-1].minor.yy248); + yylhsminor.yy248 = addLimitClause(pCxt, yylhsminor.yy248, yymsp[0].minor.yy248); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 458: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy212 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy212, yymsp[0].minor.yy212); } - yymsp[-3].minor.yy212 = yylhsminor.yy212; + case 460: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy248 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy248, yymsp[0].minor.yy248); } + yymsp[-3].minor.yy248 = yylhsminor.yy248; break; - case 459: /* query_expression_body ::= query_expression_body UNION query_expression_body */ -{ yylhsminor.yy212 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy212, yymsp[0].minor.yy212); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 461: /* query_expression_body ::= query_expression_body UNION query_expression_body */ +{ yylhsminor.yy248 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy248, yymsp[0].minor.yy248); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 461: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ -{ yymsp[-5].minor.yy212 = yymsp[-4].minor.yy212; } - yy_destructor(yypParser,367,&yymsp[-3].minor); - yy_destructor(yypParser,368,&yymsp[-2].minor); - yy_destructor(yypParser,369,&yymsp[-1].minor); + case 463: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ +{ yymsp[-5].minor.yy248 = yymsp[-4].minor.yy248; } + yy_destructor(yypParser,368,&yymsp[-3].minor); + yy_destructor(yypParser,369,&yymsp[-2].minor); + yy_destructor(yypParser,370,&yymsp[-1].minor); break; - case 465: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 469: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==469); -{ yymsp[-1].minor.yy212 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 467: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 471: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==471); +{ yymsp[-1].minor.yy248 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 466: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 470: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==470); -{ yymsp[-3].minor.yy212 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 468: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 472: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==472); +{ yymsp[-3].minor.yy248 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 467: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 471: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==471); -{ yymsp[-3].minor.yy212 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 469: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 473: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==473); +{ yymsp[-3].minor.yy248 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 472: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy212 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy212); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 474: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy248 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy248); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 476: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy212 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy212), yymsp[-1].minor.yy188, yymsp[0].minor.yy607); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; + case 478: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy248 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy248), yymsp[-1].minor.yy482, yymsp[0].minor.yy345); } + yymsp[-2].minor.yy248 = yylhsminor.yy248; break; - case 477: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy188 = ORDER_ASC; } + case 479: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy482 = ORDER_ASC; } break; - case 478: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy188 = ORDER_ASC; } + case 480: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy482 = ORDER_ASC; } break; - case 479: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy188 = ORDER_DESC; } + case 481: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy482 = ORDER_DESC; } break; - case 480: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy607 = NULL_ORDER_DEFAULT; } + case 482: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy345 = NULL_ORDER_DEFAULT; } break; - case 481: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy607 = NULL_ORDER_FIRST; } + case 483: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy345 = NULL_ORDER_FIRST; } break; - case 482: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy607 = NULL_ORDER_LAST; } + case 484: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy345 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parExplainToSyncdbTest.cpp b/source/libs/parser/test/parExplainToSyncdbTest.cpp index 4a5a92e62165bc3cec5868e3adf8f3d4246508a2..72083c68cafa78ed483217a42e2d374032cbf7f6 100644 --- a/source/libs/parser/test/parExplainToSyncdbTest.cpp +++ b/source/libs/parser/test/parExplainToSyncdbTest.cpp @@ -40,6 +40,12 @@ TEST_F(ParserExplainToSyncdbTest, grant) { run("GRANT READ, WRITE ON test.* TO wxy"); } +TEST_F(ParserExplainToSyncdbTest, insert) { + useDb("root", "test"); + + run("INSERT INTO t1 SELECT * FROM t1"); +} + // todo kill connection // todo kill query // todo kill stream diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 56353f70953423e0b4945099eb3954aa58ffd6d1..e7589fb0df363bd0cf6c9c5945cd80d6da9bca00 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -26,6 +26,7 @@ typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, void*, SLogicNode**); typedef int32_t (*FCreateSelectLogicNode)(SLogicPlanContext*, SSelectStmt*, SLogicNode**); typedef int32_t (*FCreateSetOpLogicNode)(SLogicPlanContext*, SSetOperator*, SLogicNode**); typedef int32_t (*FCreateDeleteLogicNode)(SLogicPlanContext*, SDeleteStmt*, SLogicNode**); +typedef int32_t (*FCreateInsertLogicNode)(SLogicPlanContext*, SInsertStmt*, SLogicNode**); static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode); @@ -1137,6 +1138,8 @@ static int32_t getMsgType(ENodeType sqlType) { return TDMT_VND_DROP_TABLE; case QUERY_NODE_ALTER_TABLE_STMT: return TDMT_VND_ALTER_TABLE; + case QUERY_NODE_FLUSH_DATABASE_STMT: + return TDMT_VND_COMMIT; default: break; } @@ -1262,6 +1265,53 @@ static int32_t createDeleteLogicNode(SLogicPlanContext* pCxt, SDeleteStmt* pDele return code; } +static int32_t creatInsertRootLogicNode(SLogicPlanContext* pCxt, SInsertStmt* pInsert, FCreateInsertLogicNode func, + SLogicNode** pRoot) { + return createRootLogicNode(pCxt, pInsert, pInsert->precision, (FCreateLogicNode)func, pRoot); +} + +static int32_t createVnodeModifLogicNodeByInsert(SLogicPlanContext* pCxt, SInsertStmt* pInsert, + SLogicNode** pLogicNode) { + SVnodeModifyLogicNode* pModify = (SVnodeModifyLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY); + if (NULL == pModify) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + SRealTableNode* pRealTable = (SRealTableNode*)pInsert->pTable; + + pModify->modifyType = MODIFY_TABLE_TYPE_INSERT; + pModify->tableId = pRealTable->pMeta->uid; + pModify->stableId = pRealTable->pMeta->suid; + pModify->tableType = pRealTable->pMeta->tableType; + snprintf(pModify->tableFName, sizeof(pModify->tableFName), "%d.%s.%s", pCxt->pPlanCxt->acctId, + pRealTable->table.dbName, pRealTable->table.tableName); + TSWAP(pModify->pVgroupList, pRealTable->pVgroupList); + pModify->pInsertCols = nodesCloneList(pInsert->pCols); + if (NULL == pModify->pInsertCols) { + nodesDestroyNode((SNode*)pModify); + return TSDB_CODE_OUT_OF_MEMORY; + } + + *pLogicNode = (SLogicNode*)pModify; + return TSDB_CODE_SUCCESS; +} + +static int32_t createInsertLogicNode(SLogicPlanContext* pCxt, SInsertStmt* pInsert, SLogicNode** pLogicNode) { + SLogicNode* pRoot = NULL; + int32_t code = createQueryLogicNode(pCxt, pInsert->pQuery, &pRoot); + if (TSDB_CODE_SUCCESS == code) { + code = creatInsertRootLogicNode(pCxt, pInsert, createVnodeModifLogicNodeByInsert, &pRoot); + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = pRoot; + } else { + nodesDestroyNode((SNode*)pRoot); + } + + return code; +} + static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode) { switch (nodeType(pStmt)) { case QUERY_NODE_SELECT_STMT: @@ -1274,6 +1324,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi return createSetOperatorLogicNode(pCxt, (SSetOperator*)pStmt, pLogicNode); case QUERY_NODE_DELETE_STMT: return createDeleteLogicNode(pCxt, (SDeleteStmt*)pStmt, pLogicNode); + case QUERY_NODE_INSERT_STMT: + return createInsertLogicNode(pCxt, (SInsertStmt*)pStmt, pLogicNode); default: break; } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 202e590955443cf97fa586b5c2f60b80ecf9030e..458e0f545dc95424b0f02a229280e05b982c01a4 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -485,7 +485,7 @@ static int32_t pushDownCondOptPushCondToProject(SOptimizeContext* pCxt, SProject return pushDownCondOptAppendCond(&pProject->node.pConditions, pCond); } -static int32_t pushDownCondOptPushCondToJoin(SOptimizeContext* pCxt, SJoinLogicNode * pJoin, SNode** pCond) { +static int32_t pushDownCondOptPushCondToJoin(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, SNode** pCond) { return pushDownCondOptAppendCond(&pJoin->node.pConditions, pCond); } @@ -557,9 +557,9 @@ static int32_t pushDownCondOptCheckJoinOnCond(SOptimizeContext* pCxt, SJoinLogic static int32_t pushDownCondOptPartJoinOnCondLogicCond(SJoinLogicNode* pJoin, SNode** ppMergeCond, SNode** ppOnCond) { SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(pJoin->pOnConditions); - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SNodeList* pOnConds = NULL; - SNode* pCond = NULL; + SNode* pCond = NULL; FOREACH(pCond, pLogicCond->pParameterList) { if (pushDownCondOptIsPriKeyEqualCond(pJoin, pCond)) { *ppMergeCond = nodesCloneNode(pCond); @@ -604,8 +604,8 @@ static int32_t pushDownCondOptPartJoinOnCond(SJoinLogicNode* pJoin, SNode** ppMe static int32_t pushDownCondOptJoinExtractMergeCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) { int32_t code = pushDownCondOptCheckJoinOnCond(pCxt, pJoin); - SNode* pJoinMergeCond = NULL; - SNode* pJoinOnCond = NULL; + SNode* pJoinMergeCond = NULL; + SNode* pJoinOnCond = NULL; if (TSDB_CODE_SUCCESS == code) { code = pushDownCondOptPartJoinOnCond(pJoin, &pJoinMergeCond, &pJoinOnCond); } @@ -820,12 +820,12 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg typedef struct SRewriteProjCondContext { SProjectLogicNode* pProj; - int32_t errCode; -}SRewriteProjCondContext; + int32_t errCode; +} SRewriteProjCondContext; static EDealRes rewriteProjectCondForPushDownImpl(SNode** ppNode, void* pContext) { SRewriteProjCondContext* pCxt = pContext; - SProjectLogicNode* pProj = pCxt->pProj; + SProjectLogicNode* pProj = pCxt->pProj; if (QUERY_NODE_COLUMN == nodeType(*ppNode)) { SNode* pTarget = NULL; FOREACH(pTarget, pProj->node.pTargets) { @@ -840,18 +840,19 @@ static EDealRes rewriteProjectCondForPushDownImpl(SNode** ppNode, void* pContext } nodesDestroyNode(*ppNode); *ppNode = pExpr; - } // end if expr alias name equal column name - } // end for each project - } // end if target node equals cond column node - } // end for each targets + } // end if expr alias name equal column name + } // end for each project + } // end if target node equals cond column node + } // end for each targets return DEAL_RES_IGNORE_CHILD; } return DEAL_RES_CONTINUE; } -static int32_t rewriteProjectCondForPushDown(SOptimizeContext* pCxt, SProjectLogicNode* pProject, SNode** ppProjectCond) { +static int32_t rewriteProjectCondForPushDown(SOptimizeContext* pCxt, SProjectLogicNode* pProject, + SNode** ppProjectCond) { SRewriteProjCondContext cxt = {.pProj = pProject, .errCode = TSDB_CODE_SUCCESS}; - SNode* pProjectCond = pProject->node.pConditions; + SNode* pProjectCond = pProject->node.pConditions; nodesRewriteExpr(&pProjectCond, rewriteProjectCondForPushDownImpl, &cxt); *ppProjectCond = pProjectCond; pProject->node.pConditions = NULL; @@ -873,7 +874,7 @@ static int32_t pushDownCondOptDealProject(SOptimizeContext* pCxt, SProjectLogicN } int32_t code = TSDB_CODE_SUCCESS; - SNode* pProjCond = NULL; + SNode* pProjCond = NULL; code = rewriteProjectCondForPushDown(pCxt, pProject, &pProjCond); if (TSDB_CODE_SUCCESS == code) { SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pProject->node.pChildren, 0); @@ -889,6 +890,20 @@ static int32_t pushDownCondOptDealProject(SOptimizeContext* pCxt, SProjectLogicN return code; } +static int32_t pushDownCondOptDealLogicNode(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { + if (NULL == pLogicNode->pConditions || + OPTIMIZE_FLAG_TEST_MASK(pLogicNode->optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE)) { + return TSDB_CODE_SUCCESS; + } + SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pLogicNode->pChildren, 0); + int32_t code = pushDownCondOptPushCondToChild(pCxt, pChild, &pLogicNode->pConditions); + if (TSDB_CODE_SUCCESS == code) { + OPTIMIZE_FLAG_SET_MASK(pLogicNode->optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE); + pCxt->optimized = true; + } + return code; +} + static int32_t pushDownCondOptimizeImpl(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pLogicNode)) { @@ -904,6 +919,10 @@ static int32_t pushDownCondOptimizeImpl(SOptimizeContext* pCxt, SLogicNode* pLog case QUERY_NODE_LOGIC_PLAN_PROJECT: code = pushDownCondOptDealProject(pCxt, (SProjectLogicNode*)pLogicNode); break; + case QUERY_NODE_LOGIC_PLAN_SORT: + case QUERY_NODE_LOGIC_PLAN_PARTITION: + code = pushDownCondOptDealLogicNode(pCxt, pLogicNode); + break; default: break; } @@ -2082,13 +2101,18 @@ static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimi static void dumpLogicSubplan(const char* pRuleName, SLogicSubplan* pSubplan) { char* pStr = NULL; nodesNodeToString((SNode*)pSubplan, false, &pStr, NULL); - qDebugL("apply optimize %s rule: %s", pRuleName, pStr); + if (NULL == pRuleName) { + qDebugL("before optimize: %s", pStr); + } else { + qDebugL("apply optimize %s rule: %s", pRuleName, pStr); + } taosMemoryFree(pStr); } static int32_t applyOptimizeRule(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan) { SOptimizeContext cxt = {.pPlanCxt = pCxt, .optimized = false}; bool optimized = false; + dumpLogicSubplan(NULL, pLogicSubplan); do { optimized = false; for (int32_t i = 0; i < optimizeRuleNum; ++i) { diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index d10908c519bef68029c86f0f7d2efaa213bf0d4b..2356eb368e61035307f97665c2f2ce183ab99a9f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -632,8 +632,8 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren } if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pOnConditions) { - code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, pJoinLogicNode->pOnConditions, - &pJoin->pOnConditions); + code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, + pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); } if (TSDB_CODE_SUCCESS == code) { @@ -1496,12 +1496,63 @@ static SSubplan* makeSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubpl return pSubplan; } -static int32_t buildInsertSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { +static int32_t buildInsertValuesSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { pSubplan->msgType = pModify->msgType; pSubplan->execNode.epSet = pModify->pVgDataBlocks->vg.epSet; return createDataInserter(pCxt, pModify->pVgDataBlocks, &pSubplan->pDataSink); } +static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan, + SDataSinkNode** pSink) { + SQueryInserterNode* pInserter = (SQueryInserterNode*)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT); + if (NULL == pInserter) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pInserter->tableId = pModify->tableId; + pInserter->stableId = pModify->stableId; + pInserter->tableType = pModify->tableType; + strcpy(pInserter->tableFName, pModify->tableFName); + pInserter->vgId = pModify->pVgroupList->vgroups[0].vgId; + pInserter->epSet = pModify->pVgroupList->vgroups[0].epSet; + vgroupInfoToNodeAddr(pModify->pVgroupList->vgroups, &pSubplan->execNode); + + int32_t code = setListSlotId(pCxt, pSubplan->pNode->pOutputDataBlockDesc->dataBlockId, -1, pModify->pInsertCols, + &pInserter->pCols); + if (TSDB_CODE_SUCCESS == code) { + pInserter->sink.pInputDataBlockDesc = + (SDataBlockDescNode*)nodesCloneNode((SNode*)pSubplan->pNode->pOutputDataBlockDesc); + if (NULL == pInserter->sink.pInputDataBlockDesc) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + + if (TSDB_CODE_SUCCESS == code) { + *pSink = (SDataSinkNode*)pInserter; + } else { + nodesDestroyNode((SNode*)pInserter); + } + + return code; +} + +static int32_t buildInsertSelectSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { + int32_t code = + createPhysiNode(pCxt, (SLogicNode*)nodesListGetNode(pModify->node.pChildren, 0), pSubplan, &pSubplan->pNode); + if (TSDB_CODE_SUCCESS == code) { + code = createQueryInserter(pCxt, pModify, pSubplan, &pSubplan->pDataSink); + } + pSubplan->msgType = TDMT_VND_SUBMIT; + return code; +} + +static int32_t buildInsertSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { + if (NULL == pModify->node.pChildren) { + return buildInsertValuesSubplan(pCxt, pModify, pSubplan); + } + return buildInsertSelectSubplan(pCxt, pModify, pSubplan); +} + static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, const SPhysiNode* pRoot, SDataSinkNode** pSink) { SDataDeleterNode* pDeleter = (SDataDeleterNode*)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DELETE); diff --git a/source/libs/planner/src/planScaleOut.c b/source/libs/planner/src/planScaleOut.c index a0b63ad6ff9d987fef2e31d7b0abdcf14d9b541b..1f43d543333c21bc27bf35dd582950a8601219d6 100644 --- a/source/libs/planner/src/planScaleOut.c +++ b/source/libs/planner/src/planScaleOut.c @@ -82,29 +82,41 @@ static int32_t scaleOutByVgroups(SScaleOutContext* pCxt, SLogicSubplan* pSubplan return code; } -static int32_t scaleOutForModify(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { +static int32_t scaleOutForMerge(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { + return nodesListStrictAppend(pGroup, (SNode*)singleCloneSubLogicPlan(pCxt, pSubplan, level)); +} + +static int32_t scaleOutForInsertValues(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, + SNodeList* pGroup) { SVnodeModifyLogicNode* pNode = (SVnodeModifyLogicNode*)pSubplan->pNode; - if (MODIFY_TABLE_TYPE_DELETE == pNode->modifyType) { - return scaleOutByVgroups(pCxt, pSubplan, level, pGroup); - } else { - size_t numOfVgroups = taosArrayGetSize(pNode->pDataBlocks); - for (int32_t i = 0; i < numOfVgroups; ++i) { - SLogicSubplan* pNewSubplan = singleCloneSubLogicPlan(pCxt, pSubplan, level); - if (NULL == pNewSubplan) { - return TSDB_CODE_OUT_OF_MEMORY; - } - ((SVnodeModifyLogicNode*)pNewSubplan->pNode)->pVgDataBlocks = - (SVgDataBlocks*)taosArrayGetP(pNode->pDataBlocks, i); - if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pGroup, (SNode*)pNewSubplan)) { - return TSDB_CODE_OUT_OF_MEMORY; - } + size_t numOfVgroups = taosArrayGetSize(pNode->pDataBlocks); + for (int32_t i = 0; i < numOfVgroups; ++i) { + SLogicSubplan* pNewSubplan = singleCloneSubLogicPlan(pCxt, pSubplan, level); + if (NULL == pNewSubplan) { + return TSDB_CODE_OUT_OF_MEMORY; + } + ((SVnodeModifyLogicNode*)pNewSubplan->pNode)->pVgDataBlocks = (SVgDataBlocks*)taosArrayGetP(pNode->pDataBlocks, i); + if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pGroup, (SNode*)pNewSubplan)) { + return TSDB_CODE_OUT_OF_MEMORY; } - return TSDB_CODE_SUCCESS; } + return TSDB_CODE_SUCCESS; } -static int32_t scaleOutForMerge(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { - return nodesListStrictAppend(pGroup, (SNode*)singleCloneSubLogicPlan(pCxt, pSubplan, level)); +static int32_t scaleOutForInsert(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { + SVnodeModifyLogicNode* pNode = (SVnodeModifyLogicNode*)pSubplan->pNode; + if (NULL == pNode->node.pChildren) { + return scaleOutForInsertValues(pCxt, pSubplan, level, pGroup); + } + return scaleOutForMerge(pCxt, pSubplan, level, pGroup); +} + +static int32_t scaleOutForModify(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { + SVnodeModifyLogicNode* pNode = (SVnodeModifyLogicNode*)pSubplan->pNode; + if (MODIFY_TABLE_TYPE_DELETE == pNode->modifyType) { + return scaleOutByVgroups(pCxt, pSubplan, level, pGroup); + } + return scaleOutForInsert(pCxt, pSubplan, level, pGroup); } static int32_t scaleOutForScan(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 7644fc3b19fe774eacf3946044296eb5b943ced0..0863b5f21f2a1236560ab91b49635bdf2576883d 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -20,6 +20,7 @@ #define SPLIT_FLAG_MASK(n) (1 << n) #define SPLIT_FLAG_STABLE_SPLIT SPLIT_FLAG_MASK(0) +#define SPLIT_FLAG_INSERT_SPLIT SPLIT_FLAG_MASK(1) #define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask) #define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) @@ -1196,6 +1197,41 @@ static int32_t smaIndexSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { return code; } +typedef struct SInsertSelectSplitInfo { + SLogicNode* pQueryRoot; + SLogicSubplan* pSubplan; +} SInsertSelectSplitInfo; + +static bool insSelSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pNode, + SInsertSelectSplitInfo* pInfo) { + if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY == nodeType(pNode) && 1 == LIST_LENGTH(pNode->pChildren) && + MODIFY_TABLE_TYPE_INSERT == ((SVnodeModifyLogicNode*)pNode)->modifyType) { + pInfo->pQueryRoot = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0); + pInfo->pSubplan = pSubplan; + return true; + } + return false; +} + +static int32_t insertSelectSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { + SInsertSelectSplitInfo info = {0}; + if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_INSERT_SPLIT, (FSplFindSplitNode)insSelSplFindSplitNode, &info)) { + return TSDB_CODE_SUCCESS; + } + + int32_t code = splCreateExchangeNodeForSubplan(pCxt, info.pSubplan, info.pQueryRoot, info.pSubplan->subplanType); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, (SNode*)splCreateScanSubplan(pCxt, info.pQueryRoot, 0)); + } + if (TSDB_CODE_SUCCESS == code) { + info.pSubplan->subplanType = SUBPLAN_TYPE_MODIFY; + SPLIT_FLAG_SET_MASK(info.pSubplan->splitFlag, SPLIT_FLAG_INSERT_SPLIT); + } + ++(pCxt->groupId); + pCxt->split = true; + return code; +} + typedef struct SQnodeSplitInfo { SLogicNode* pSplitNode; SLogicSubplan* pSubplan; @@ -1249,7 +1285,8 @@ static const SSplitRule splitRuleSet[] = { {.pName = "SingleTableJoinSplit", .splitFunc = singleTableJoinSplit}, {.pName = "UnionAllSplit", .splitFunc = unionAllSplit}, {.pName = "UnionDistinctSplit", .splitFunc = unionDistinctSplit}, - {.pName = "SmaIndexSplit", .splitFunc = smaIndexSplit} + {.pName = "SmaIndexSplit", .splitFunc = smaIndexSplit}, + {.pName = "InsertSelectSplit", .splitFunc = insertSelectSplit} }; // clang-format on @@ -1258,7 +1295,11 @@ static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule)); static void dumpLogicSubplan(const char* pRuleName, SLogicSubplan* pSubplan) { char* pStr = NULL; nodesNodeToString((SNode*)pSubplan, false, &pStr, NULL); - qDebugL("apply split %s rule: %s", pRuleName, pStr); + if (NULL == pRuleName) { + qDebugL("before split: %s", pStr); + } else { + qDebugL("apply split %s rule: %s", pRuleName, pStr); + } taosMemoryFree(pStr); } @@ -1266,6 +1307,7 @@ static int32_t applySplitRule(SPlanContext* pCxt, SLogicSubplan* pSubplan) { SSplitContext cxt = { .pPlanCxt = pCxt, .queryId = pSubplan->id.queryId, .groupId = pSubplan->id.groupId + 1, .split = false}; bool split = false; + dumpLogicSubplan(NULL, pSubplan); do { split = false; for (int32_t i = 0; i < splitRuleNum; ++i) { @@ -1293,8 +1335,16 @@ static void setVgroupsInfo(SLogicNode* pNode, SLogicSubplan* pSubplan) { FOREACH(pChild, pNode->pChildren) { setVgroupsInfo((SLogicNode*)pChild, pSubplan); } } +static bool needSplitSubplan(SLogicSubplan* pLogicSubplan) { + if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY != nodeType(pLogicSubplan->pNode)) { + return true; + } + SVnodeModifyLogicNode* pModify = (SVnodeModifyLogicNode*)pLogicSubplan->pNode; + return (MODIFY_TABLE_TYPE_INSERT == pModify->modifyType && NULL != pModify->node.pChildren); +} + int32_t splitLogicPlan(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan) { - if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY == nodeType(pLogicSubplan->pNode)) { + if (!needSplitSubplan(pLogicSubplan)) { setVgroupsInfo(pLogicSubplan->pNode, pLogicSubplan); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/test/planOtherTest.cpp b/source/libs/planner/test/planOtherTest.cpp index 2c031aa3a8a57dfa9f7de0de4dc22b0c5d8c824a..6add1cf630416b7adaff1394f2af0e2791a9e3f6 100644 --- a/source/libs/planner/test/planOtherTest.cpp +++ b/source/libs/planner/test/planOtherTest.cpp @@ -91,3 +91,13 @@ TEST_F(PlanOtherTest, delete) { run("DELETE FROM st1 WHERE ts > now - 2d and ts < now - 1d AND tag1 = 10"); } + +TEST_F(PlanOtherTest, insert) { + useDb("root", "test"); + + run("INSERT INTO t1 SELECT * FROM t1"); + + run("INSERT INTO t1 (ts, c1, c2) SELECT ts, c1, c2 FROM st1"); + + run("INSERT INTO t1 (ts, c1, c2) SELECT ts, c1, c2 FROM st1s1 UNION ALL SELECT ts, c1, c2 FROM st2"); +} diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index a3a15869eb535d70d0a6d8b88a627c555be1294e..923224688cf509e7cc1a8c6e94a4ff2b77a81211 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -171,17 +171,17 @@ char* jobTaskStatusStr(int32_t status) { switch (status) { case JOB_TASK_STATUS_NULL: return "NULL"; - case JOB_TASK_STATUS_NOT_START: - return "NOT_START"; - case JOB_TASK_STATUS_EXECUTING: + case JOB_TASK_STATUS_INIT: + return "INIT"; + case JOB_TASK_STATUS_EXEC: return "EXECUTING"; - case JOB_TASK_STATUS_PARTIAL_SUCCEED: + case JOB_TASK_STATUS_PART_SUCC: return "PARTIAL_SUCCEED"; - case JOB_TASK_STATUS_SUCCEED: + case JOB_TASK_STATUS_SUCC: return "SUCCEED"; - case JOB_TASK_STATUS_FAILED: + case JOB_TASK_STATUS_FAIL: return "FAILED"; - case JOB_TASK_STATUS_DROPPING: + case JOB_TASK_STATUS_DROP: return "DROPPING"; default: break; @@ -200,7 +200,7 @@ SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* nam return s; } -void destroyQueryExecRes(SQueryExecRes* pRes) { +void destroyQueryExecRes(SExecResult* pRes) { if (NULL == pRes || NULL == pRes->res) { return; } diff --git a/source/libs/qworker/inc/qwInt.h b/source/libs/qworker/inc/qwInt.h index 6faffa13b34addf06923efbac467ff1b783778ea..eb10a2fdd6e05a81f0c9f291f79b414c6112015f 100644 --- a/source/libs/qworker/inc/qwInt.h +++ b/source/libs/qworker/inc/qwInt.h @@ -226,8 +226,8 @@ typedef struct SQWorkerMgmt { #define QW_TASK_NOT_EXIST(code) (TSDB_CODE_QRY_SCH_NOT_EXIST == (code) || TSDB_CODE_QRY_TASK_NOT_EXIST == (code)) #define QW_TASK_ALREADY_EXIST(code) (TSDB_CODE_QRY_TASK_ALREADY_EXIST == (code)) #define QW_TASK_READY(status) \ - (status == JOB_TASK_STATUS_SUCCEED || status == JOB_TASK_STATUS_FAILED || status == JOB_TASK_STATUS_CANCELLED || \ - status == JOB_TASK_STATUS_PARTIAL_SUCCEED) + (status == JOB_TASK_STATUS_SUCC || status == JOB_TASK_STATUS_FAIL || status == JOB_TASK_STATUS_CANCELLED || \ + status == JOB_TASK_STATUS_PART_SUCC) #define QW_SET_QTID(id, qId, tId, eId) \ do { \ *(uint64_t *)(id) = (qId); \ diff --git a/source/libs/qworker/inc/qwMsg.h b/source/libs/qworker/inc/qwMsg.h index 9e9d1f44cbaccd9ffabe1adbd747ba06287cf60d..75b11c1b0b659e508ce412a113173b143d31724c 100644 --- a/source/libs/qworker/inc/qwMsg.h +++ b/source/libs/qworker/inc/qwMsg.h @@ -31,7 +31,7 @@ int32_t qwProcessReady(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessHb(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req); -int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes *pRes); +int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SDeleteRes *pRes); int32_t qwBuildAndSendDropRsp(SRpcHandleInfo *pConn, int32_t code); int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code); diff --git a/source/libs/qworker/src/qwDbg.c b/source/libs/qworker/src/qwDbg.c index 68058334ab6985d13eed6edc2c80a86ffbeb0c86..dfe5a04d19575c11983d07976e425e1bd537802b 100644 --- a/source/libs/qworker/src/qwDbg.c +++ b/source/libs/qworker/src/qwDbg.c @@ -19,7 +19,7 @@ int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, int32_t code = 0; if (oriStatus == newStatus) { - if (newStatus == JOB_TASK_STATUS_EXECUTING || newStatus == JOB_TASK_STATUS_FAILED) { + if (newStatus == JOB_TASK_STATUS_EXEC || newStatus == JOB_TASK_STATUS_FAIL) { *ignore = true; return TSDB_CODE_SUCCESS; } @@ -29,47 +29,47 @@ int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, switch (oriStatus) { case JOB_TASK_STATUS_NULL: - if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_FAILED && - newStatus != JOB_TASK_STATUS_NOT_START) { + if (newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_FAIL && + newStatus != JOB_TASK_STATUS_INIT) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_NOT_START: - if (newStatus != JOB_TASK_STATUS_DROPPING && newStatus != JOB_TASK_STATUS_EXECUTING - && newStatus != JOB_TASK_STATUS_FAILED) { + case JOB_TASK_STATUS_INIT: + if (newStatus != JOB_TASK_STATUS_DROP && newStatus != JOB_TASK_STATUS_EXEC + && newStatus != JOB_TASK_STATUS_FAIL) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_EXECUTING: - if (newStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED && newStatus != JOB_TASK_STATUS_SUCCEED && - newStatus != JOB_TASK_STATUS_FAILED && newStatus != JOB_TASK_STATUS_DROPPING) { + case JOB_TASK_STATUS_EXEC: + if (newStatus != JOB_TASK_STATUS_PART_SUCC && newStatus != JOB_TASK_STATUS_SUCC && + newStatus != JOB_TASK_STATUS_FAIL && newStatus != JOB_TASK_STATUS_DROP) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_PARTIAL_SUCCEED: - if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_SUCCEED && - newStatus != JOB_TASK_STATUS_FAILED && newStatus != JOB_TASK_STATUS_DROPPING) { + case JOB_TASK_STATUS_PART_SUCC: + if (newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_SUCC && + newStatus != JOB_TASK_STATUS_FAIL && newStatus != JOB_TASK_STATUS_DROP) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_SUCCEED: - if (newStatus != JOB_TASK_STATUS_DROPPING && newStatus != JOB_TASK_STATUS_FAILED) { + case JOB_TASK_STATUS_SUCC: + if (newStatus != JOB_TASK_STATUS_DROP && newStatus != JOB_TASK_STATUS_FAIL) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_FAILED: - if (newStatus != JOB_TASK_STATUS_DROPPING) { + case JOB_TASK_STATUS_FAIL: + if (newStatus != JOB_TASK_STATUS_DROP) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_DROPPING: - if (newStatus != JOB_TASK_STATUS_FAILED && newStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { + case JOB_TASK_STATUS_DROP: + if (newStatus != JOB_TASK_STATUS_FAIL && newStatus != JOB_TASK_STATUS_PART_SUCC) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c index cc4228f7c7b3377848f07adf792b142d5d15f96d..8df3ac90facb187ce14b69730c7ad6fbe94c4273 100644 --- a/source/libs/qworker/src/qwMsg.c +++ b/source/libs/qworker/src/qwMsg.c @@ -583,8 +583,8 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_ } -int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *pRsp, SDeleteRes *pRes) { - if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == pRsp) { +int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SDeleteRes *pRes) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -606,7 +606,7 @@ int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SR QW_SCH_TASK_DLOG("processDelete start, node:%p, handle:%p, sql:%s", node, pMsg->info.handle, req.sql); taosMemoryFreeClear(req.sql); - QW_ERR_JRET(qwProcessDelete(QW_FPARAMS(), &qwMsg, pRsp, pRes)); + QW_ERR_JRET(qwProcessDelete(QW_FPARAMS(), &qwMsg, pRes)); QW_SCH_TASK_DLOG("processDelete end, node:%p", node); diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index 1fb0a343147821bd60ea9960f568fc04eecd272e..5aaf2b80381986ff1120bf527e81d5c537eab834 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -433,8 +433,8 @@ void qwSetHbParam(int64_t refId, SQWHbParam **pParam) { } void qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx) { - char dbFName[TSDB_DB_FNAME_LEN]; - char tbName[TSDB_TABLE_NAME_LEN]; + char dbFName[TSDB_DB_FNAME_LEN] = {0}; + char tbName[TSDB_TABLE_NAME_LEN] = {0}; qGetQueriedTableSchemaVersion(pTaskInfo, dbFName, tbName, &ctx->tbInfo.sversion, &ctx->tbInfo.tversion); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 949b67249fbfff0819d3fa7c3de0e1c03f172272..5ba525329f5912019b2145d6f6170fec0a445551 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -206,7 +206,7 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, QW_TASK_DLOG_E("no data in sink and query end"); - qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCCEED); + qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC); QW_ERR_RET(qwMallocFetchRsp(len, &rsp)); *rspMsg = rsp; @@ -236,15 +236,14 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, if (DS_BUF_EMPTY == pOutput->bufStatus && pOutput->queryEnd) { QW_TASK_DLOG_E("task all data fetched, done"); - qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCCEED); + qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC); } return TSDB_CODE_SUCCESS; } -int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void **rspMsg, SDeleteRes *pRes) { +int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, SDeleteRes *pRes) { int32_t len = 0; - SVDeleteRsp rsp = {0}; bool queryEnd = false; int32_t code = 0; SOutputData output = {0}; @@ -270,21 +269,11 @@ int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen SDeleterRes* pDelRes = (SDeleterRes*)output.pData; - rsp.affectedRows = pDelRes->affectedRows; pRes->suid = pDelRes->suid; pRes->uidList = pDelRes->uidList; pRes->skey = pDelRes->skey; pRes->ekey = pDelRes->ekey; - - SEncoder coder = {0}; - tEncodeSize(tEncodeSVDeleteRsp, &rsp, len, code); - void *msg = rpcMallocCont(len); - tEncoderInit(&coder, msg, len); - tEncodeSVDeleteRsp(&coder, &rsp); - tEncoderClear(&coder); - - *rspMsg = msg; - *dataLen = len; + pRes->affectedRows = pDelRes->affectedRows; return TSDB_CODE_SUCCESS; } @@ -330,7 +319,7 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu break; } - QW_ERR_JRET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXECUTING)); + QW_ERR_JRET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXEC)); break; } case QW_PHASE_PRE_FETCH: { @@ -447,7 +436,7 @@ int32_t qwHandlePostPhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inp _return: if (TSDB_CODE_SUCCESS == code && QW_PHASE_POST_QUERY == phase) { - qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_PARTIAL_SUCCEED); + qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_PART_SUCC); } if (rspConnection) { @@ -467,7 +456,7 @@ _return: } if (code) { - qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAILED); + qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL); } QW_TASK_DLOG("end to handle event at phase %s, code:%x - %s", qwPhaseStr(phase), code, tstrerror(code)); @@ -499,7 +488,7 @@ int32_t qwPrerocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) { ctx->ctrlConnInfo = qwMsg->connInfo; - QW_ERR_JRET(qwAddTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_NOT_START)); + QW_ERR_JRET(qwAddTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_INIT)); _return: @@ -698,7 +687,7 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg) { if (QW_IS_QUERY_RUNNING(ctx)) { atomic_store_8((int8_t *)&ctx->queryContinue, 1); } else if (0 == atomic_load_8((int8_t *)&ctx->queryInQueue)) { - qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXECUTING); + qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXEC); atomic_store_8((int8_t *)&ctx->queryInQueue, 1); @@ -749,7 +738,7 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) { if (QW_IS_QUERY_RUNNING(ctx)) { QW_ERR_JRET(qwKillTaskHandle(QW_FPARAMS(), ctx)); - qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROPPING); + qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROP); } else if (ctx->phase > 0) { QW_ERR_JRET(qwDropTask(QW_FPARAMS())); rsped = true; @@ -770,7 +759,7 @@ _return: QW_UPDATE_RSP_CODE(ctx, code); } - qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAILED); + qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL); } if (locked) { @@ -926,7 +915,7 @@ _return: qwRelease(refId); } -int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes *pRes) { +int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SDeleteRes *pRes) { int32_t code = 0; SSubplan *plan = NULL; qTaskInfo_t pTaskInfo = NULL; @@ -941,7 +930,7 @@ int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes } ctx.plan = plan; - + code = qCreateExecTask(qwMsg->node, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle, NULL, OPTR_EXEC_MODEL_BATCH); if (code) { QW_TASK_ELOG("qCreateExecTask failed, code:%x - %s", code, tstrerror(code)); @@ -958,7 +947,7 @@ int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes QW_ERR_JRET(qwExecTask(QW_FPARAMS(), &ctx, NULL)); - QW_ERR_JRET(qwGetDeleteResFromSink(QW_FPARAMS(), &ctx, &pRsp->contLen, &pRsp->pCont, pRes)); + QW_ERR_JRET(qwGetDeleteResFromSink(QW_FPARAMS(), &ctx, pRes)); _return: diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schInt.h similarity index 81% rename from source/libs/scheduler/inc/schedulerInt.h rename to source/libs/scheduler/inc/schInt.h index cf6acc584398bb44c08e341ca0c45f0689831958..8e8652aab56b6159fe4c2a603cde29e40ef9d85c 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schInt.h @@ -52,6 +52,7 @@ typedef enum { SCH_OP_NULL = 0, SCH_OP_EXEC, SCH_OP_FETCH, + SCH_OP_GET_STATUS, } SCH_OP_TYPE; typedef struct SSchTrans { @@ -97,13 +98,30 @@ typedef struct SSchStat { } SSchStat; typedef struct SSchResInfo { - SQueryResult* queryRes; + SExecResult* execRes; void** fetchRes; schedulerExecFp execFp; schedulerFetchFp fetchFp; - void* userParam; + void* cbParam; } SSchResInfo; +typedef struct SSchOpEvent { + SCH_OP_TYPE type; + bool begin; + SSchedulerReq *pReq; +} SSchOpEvent; + +typedef int32_t (*schStatusEnterFp)(void* pHandle, void* pParam); +typedef int32_t (*schStatusLeaveFp)(void* pHandle, void* pParam); +typedef int32_t (*schStatusEventFp)(void* pHandle, void* pParam, void* pEvent); + +typedef struct SSchStatusFps { + EJobTaskType status; + schStatusEnterFp enterFp; + schStatusLeaveFp leaveFp; + schStatusEventFp eventFp; +} SSchStatusFps; + typedef struct SSchedulerMgmt { uint64_t taskId; // sequential taksId uint64_t sId; // schedulerId @@ -157,7 +175,7 @@ typedef struct SSchLevel { int32_t taskNum; int32_t taskLaunchedNum; int32_t taskDoneNum; - SArray *subTasks; // Element is SQueryTask + SArray *subTasks; // Element is SSchTask } SSchLevel; typedef struct SSchTaskProfile { @@ -195,12 +213,13 @@ typedef struct SSchTask { typedef struct SSchJobAttr { EExplainMode explainMode; bool queryJob; + bool needFetch; bool needFlowCtrl; } SSchJobAttr; typedef struct { int32_t op; - bool sync; + bool syncReq; } SSchOpStatus; typedef struct SSchJob { @@ -231,7 +250,7 @@ typedef struct SSchJob { SSchTask *fetchTask; int32_t errCode; SRWLatch resLock; - SQueryExecRes execRes; + SExecResult execRes; void *resData; //TODO free it or not int32_t resNumOfRows; SSchResInfo userRes; @@ -292,19 +311,19 @@ extern SSchedulerMgmt schMgmt; #define SCH_GET_JOB_STATUS(job) atomic_load_8(&(job)->status) #define SCH_GET_JOB_STATUS_STR(job) jobTaskStatusStr(SCH_GET_JOB_STATUS(job)) -#define SCH_JOB_IN_SYNC_OP(job) ((job)->opStatus.op && (job)->opStatus.sync) -#define SCH_JOB_IN_ASYNC_EXEC_OP(job) (((job)->opStatus.op == SCH_OP_EXEC) && (!(job)->opStatus.sync)) -#define SCH_JOB_IN_ASYNC_FETCH_OP(job) (((job)->opStatus.op == SCH_OP_FETCH) && (!(job)->opStatus.sync)) +#define SCH_JOB_IN_SYNC_OP(job) ((job)->opStatus.op && (job)->opStatus.syncReq) +#define SCH_JOB_IN_ASYNC_EXEC_OP(job) ((SCH_OP_EXEC == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_EXEC, SCH_OP_NULL)) && (!(job)->opStatus.syncReq)) +#define SCH_JOB_IN_ASYNC_FETCH_OP(job) ((SCH_OP_FETCH == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_FETCH, SCH_OP_NULL)) && (!(job)->opStatus.syncReq)) #define SCH_SET_JOB_NEED_FLOW_CTRL(_job) (_job)->attr.needFlowCtrl = true #define SCH_JOB_NEED_FLOW_CTRL(_job) ((_job)->attr.needFlowCtrl) #define SCH_TASK_NEED_FLOW_CTRL(_job, _task) (SCH_IS_DATA_SRC_QRY_TASK(_task) && SCH_JOB_NEED_FLOW_CTRL(_job) && SCH_IS_LEVEL_UNFINISHED((_task)->level)) -#define SCH_SET_JOB_TYPE(_job, type) (_job)->attr.queryJob = ((type) != SUBPLAN_TYPE_MODIFY) +#define SCH_SET_JOB_TYPE(_job, type) do { if ((type) != SUBPLAN_TYPE_MODIFY) { (_job)->attr.queryJob = true; } } while (0) #define SCH_IS_QUERY_JOB(_job) ((_job)->attr.queryJob) -#define SCH_JOB_NEED_FETCH(_job) SCH_IS_QUERY_JOB(_job) -#define SCH_IS_WAIT_ALL_JOB(_job) (!SCH_IS_QUERY_JOB(_job)) -#define SCH_IS_NEED_DROP_JOB(_job) (SCH_IS_QUERY_JOB(_job)) +#define SCH_JOB_NEED_FETCH(_job) ((_job)->attr.needFetch) +#define SCH_JOB_NEED_WAIT(_job) (!SCH_IS_QUERY_JOB(_job)) +#define SCH_JOB_NEED_DROP(_job) (SCH_IS_QUERY_JOB(_job)) #define SCH_IS_EXPLAIN_JOB(_job) (EXPLAIN_MODE_ANALYZE == (_job)->attr.explainMode) #define SCH_NETWORK_ERR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL) #define SCH_SUB_TASK_NETWORK_ERR(_code, _len) (SCH_NETWORK_ERR(_code) && ((_len) > 0)) @@ -329,9 +348,10 @@ extern SSchedulerMgmt schMgmt; #define SCH_TASK_WLOG(param, ...) \ qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__) -#define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define SCH_SET_ERRNO(_err) do { if (TSDB_CODE_SCH_IGNORE_ERROR != (_err)) { terrno = (_err); } } while (0) +#define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); return _code; } } while (0) +#define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); } return _code; } while (0) +#define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(code); goto _return; } } while (0) #define SCH_LOCK(type, _lock) (SCH_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock)) #define SCH_UNLOCK(type, _lock) (SCH_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock)) @@ -349,7 +369,7 @@ int32_t schDecTaskFlowQuota(SSchJob *pJob, SSchTask *pTask); int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough); int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask); int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask); -int32_t schFetchFromRemote(SSchJob *pJob); +int32_t schLaunchFetchTask(SSchJob *pJob); int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode); int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray* taskAction); int32_t schCloneSMsgSendInfo(void *src, void **dst); @@ -371,25 +391,45 @@ void schFreeRpcCtxVal(const void *arg); int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb); int32_t schAppendTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t execId); int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync); -int32_t schExecJobImpl(SSchedulerReq *pReq, SSchJob *pJob, bool sync); int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus); int32_t schCancelJob(SSchJob *pJob); int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode); uint64_t schGenTaskId(void); void schCloseJobRef(void); -int32_t schExecJob(SSchedulerReq *pReq, int64_t *pJob, SQueryResult *pRes); int32_t schAsyncExecJob(SSchedulerReq *pReq, int64_t *pJob); -int32_t schFetchRows(SSchJob *pJob); -int32_t schAsyncFetchRows(SSchJob *pJob); +int32_t schJobFetchRows(SSchJob *pJob); +int32_t schJobFetchRowsA(SSchJob *pJob); int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, void *handle, int32_t execId); int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList); void schFreeSMsgSendInfo(SMsgSendInfo *msgSendInfo); char* schGetOpStr(SCH_OP_TYPE type); int32_t schBeginOperation(SSchJob *pJob, SCH_OP_TYPE type, bool sync); -int32_t schInitJob(SSchedulerReq *pReq, SSchJob **pSchJob); -int32_t schSetJobQueryRes(SSchJob* pJob, SQueryResult* pRes); +int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq); +int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq); +int32_t schDumpJobExecRes(SSchJob* pJob, SExecResult* pRes); int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSet); int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode); +void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode); +int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq); +void schProcessOnCbEnd(SSchJob *pJob, SSchTask *pTask, int32_t errCode); +int32_t schProcessOnCbBegin(SSchJob** job, SSchTask** task, uint64_t qId, int64_t rId, uint64_t tId); +void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask); +bool schJobDone(SSchJob *pJob); +int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask); +int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask); +int32_t schSwitchJobStatus(SSchJob* pJob, int32_t status, void* param); +int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SSchedulerReq* pReq); +int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode); +int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask); +void schUpdateJobErrCode(SSchJob *pJob, int32_t errCode); +int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry); +int32_t schProcessOnJobFailure(SSchJob *pJob, int32_t errCode); +int32_t schProcessOnJobPartialSuccess(SSchJob *pJob); +void schFreeTask(SSchJob *pJob, SSchTask *pTask); +void schDropTaskInHashList(SSchJob *pJob, SHashObj *list); +int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level); +int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask); +int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel); #ifdef __cplusplus diff --git a/source/libs/scheduler/src/schDbg.c b/source/libs/scheduler/src/schDbg.c index 5c0c6fbb76974f87e06b5ba1cbcb761b864fd163..7f013b8f32d2b11f0c718910d2584aead9f49fe6 100644 --- a/source/libs/scheduler/src/schDbg.c +++ b/source/libs/scheduler/src/schDbg.c @@ -14,16 +14,16 @@ */ #include "query.h" -#include "schedulerInt.h" +#include "schInt.h" tsem_t schdRspSem; -void schdExecCallback(SQueryResult* pResult, void* param, int32_t code) { +void schdExecCallback(SExecResult* pResult, void* param, int32_t code) { if (code) { pResult->code = code; } - *(SQueryResult*)param = *pResult; + *(SExecResult*)param = *pResult; taosMemoryFree(pResult); diff --git a/source/libs/scheduler/src/schFlowCtrl.c b/source/libs/scheduler/src/schFlowCtrl.c index 85d205f5f2eba00a2f6bd741b891b26f30488d05..6b34a394b6751b04af22c5c6fbaea314805b86b2 100644 --- a/source/libs/scheduler/src/schFlowCtrl.c +++ b/source/libs/scheduler/src/schFlowCtrl.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "schedulerInt.h" +#include "schInt.h" #include "tmsg.h" #include "query.h" #include "catalog.h" diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 56ebc2156839d1bda46206395ae556f29184aaf6..858f68e7ae4cfbb23efb7b25fc38582c8435d155 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -16,135 +16,11 @@ #include "catalog.h" #include "command.h" #include "query.h" -#include "schedulerInt.h" +#include "schInt.h" #include "tmsg.h" #include "tref.h" #include "trpc.h" -FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) { qDebug("sch acquire jobId:0x%"PRIx64, refId); return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId); } - -FORCE_INLINE int32_t schReleaseJob(int64_t refId) { qDebug("sch release jobId:0x%"PRIx64, refId); return taosReleaseRef(schMgmt.jobRef, refId); } - -int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel) { - pTask->plan = pPlan; - pTask->level = pLevel; - pTask->execId = -1; - pTask->maxExecTimes = SCH_TASK_MAX_EXEC_TIMES; - pTask->timeoutUsec = SCH_DEFAULT_TASK_TIMEOUT_USEC; - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_NOT_START); - pTask->taskId = schGenTaskId(); - pTask->execNodes = taosHashInit(SCH_MAX_CANDIDATE_EP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (NULL == pTask->execNodes) { - SCH_TASK_ELOG("taosHashInit %d execNodes failed", SCH_MAX_CANDIDATE_EP_NUM); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t schInitJob(SSchedulerReq *pReq, SSchJob **pSchJob) { - int32_t code = 0; - int64_t refId = -1; - SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob)); - if (NULL == pJob) { - qError("QID:0x%" PRIx64 " calloc %d failed", pReq->pDag->queryId, (int32_t)sizeof(SSchJob)); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - pJob->attr.explainMode = pReq->pDag->explainInfo.mode; - pJob->conn = *pReq->pConn; - pJob->sql = pReq->sql; - pJob->pDag = pReq->pDag; - pJob->chkKillFp = pReq->chkKillFp; - pJob->chkKillParam = pReq->chkKillParam; - pJob->userRes.execFp = pReq->execFp; - pJob->userRes.userParam = pReq->execParam; - - if (pReq->pNodeList == NULL || taosArrayGetSize(pReq->pNodeList) <= 0) { - qDebug("QID:0x%" PRIx64 " input exec nodeList is empty", pReq->pDag->queryId); - } else { - pJob->nodeList = taosArrayDup(pReq->pNodeList); - } - - pJob->taskList = - taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); - if (NULL == pJob->taskList) { - SCH_JOB_ELOG("taosHashInit %d taskList failed", pReq->pDag->numOfSubplans); - SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - SCH_ERR_JRET(schValidateAndBuildJob(pReq->pDag, pJob)); - - if (SCH_IS_EXPLAIN_JOB(pJob)) { - SCH_ERR_JRET(qExecExplainBegin(pReq->pDag, &pJob->explainCtx, pReq->startTs)); - } - - pJob->execTasks = - taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); - if (NULL == pJob->execTasks) { - SCH_JOB_ELOG("taosHashInit %d execTasks failed", pReq->pDag->numOfSubplans); - SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - tsem_init(&pJob->rspSem, 0, 0); - - refId = taosAddRef(schMgmt.jobRef, pJob); - if (refId < 0) { - SCH_JOB_ELOG("taosAddRef job failed, error:%s", tstrerror(terrno)); - SCH_ERR_JRET(terrno); - } - - atomic_add_fetch_32(&schMgmt.jobNum, 1); - - if (NULL == schAcquireJob(refId)) { - SCH_JOB_ELOG("schAcquireJob job failed, refId:0x%" PRIx64, refId); - SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); - } - - pJob->refId = refId; - - SCH_JOB_DLOG("job refId:0x%" PRIx64" created", pJob->refId); - - schUpdateJobStatus(pJob, JOB_TASK_STATUS_NOT_START); - - *pSchJob = pJob; - - return TSDB_CODE_SUCCESS; - -_return: - - if (refId < 0) { - schFreeJobImpl(pJob); - } else { - taosRemoveRef(schMgmt.jobRef, refId); - } - SCH_RET(code); -} - - -void schFreeTask(SSchJob *pJob, SSchTask *pTask) { - schDeregisterTaskHb(pJob, pTask); - - if (pTask->candidateAddrs) { - taosArrayDestroy(pTask->candidateAddrs); - } - - taosMemoryFreeClear(pTask->msg); - - if (pTask->children) { - taosArrayDestroy(pTask->children); - } - - if (pTask->parents) { - taosArrayDestroy(pTask->parents); - } - - if (pTask->execNodes) { - taosHashCleanup(pTask->execNodes); - } -} - - void schUpdateJobErrCode(SSchJob *pJob, int32_t errCode) { if (TSDB_CODE_SUCCESS == errCode) { return; @@ -175,7 +51,12 @@ _return: SCH_JOB_DLOG("job errCode updated to %x - %s", errCode, tstrerror(errCode)); } - +bool schJobDone(SSchJob *pJob) { + int8_t status = SCH_GET_JOB_STATUS(pJob); + + return (status == JOB_TASK_STATUS_FAIL || status == JOB_TASK_STATUS_DROP || + status == JOB_TASK_STATUS_SUCC); +} FORCE_INLINE bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus) { int8_t status = SCH_GET_JOB_STATUS(pJob); @@ -183,13 +64,16 @@ FORCE_INLINE bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus) { *pStatus = status; } + if (schJobDone(pJob)) { + return true; + } + if ((*pJob->chkKillFp)(pJob->chkKillParam)) { schUpdateJobErrCode(pJob, TSDB_CODE_TSC_QUERY_KILLED); return true; - } + } - return (status == JOB_TASK_STATUS_FAILED || status == JOB_TASK_STATUS_DROPPING || - status == JOB_TASK_STATUS_SUCCEED); + return false; } int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus) { @@ -201,48 +85,44 @@ int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus) { oriStatus = SCH_GET_JOB_STATUS(pJob); if (oriStatus == newStatus) { - if (newStatus == JOB_TASK_STATUS_DROPPING) { - SCH_ERR_JRET(TSDB_CODE_SCH_JOB_IS_DROPPING); - } - SCH_ERR_JRET(TSDB_CODE_SCH_IGNORE_ERROR); } switch (oriStatus) { case JOB_TASK_STATUS_NULL: - if (newStatus != JOB_TASK_STATUS_NOT_START) { + if (newStatus != JOB_TASK_STATUS_INIT) { SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_NOT_START: - if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_DROPPING) { + case JOB_TASK_STATUS_INIT: + if (newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_DROP) { SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_EXECUTING: - if (newStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED && newStatus != JOB_TASK_STATUS_FAILED && - newStatus != JOB_TASK_STATUS_DROPPING) { + case JOB_TASK_STATUS_EXEC: + if (newStatus != JOB_TASK_STATUS_PART_SUCC && newStatus != JOB_TASK_STATUS_FAIL && + newStatus != JOB_TASK_STATUS_DROP) { SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_PARTIAL_SUCCEED: - if (newStatus != JOB_TASK_STATUS_FAILED && newStatus != JOB_TASK_STATUS_SUCCEED && - newStatus != JOB_TASK_STATUS_DROPPING) { + case JOB_TASK_STATUS_PART_SUCC: + if (newStatus != JOB_TASK_STATUS_FAIL && newStatus != JOB_TASK_STATUS_SUCC && + newStatus != JOB_TASK_STATUS_DROP) { SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_SUCCEED: - case JOB_TASK_STATUS_FAILED: - if (newStatus != JOB_TASK_STATUS_DROPPING) { + case JOB_TASK_STATUS_SUCC: + case JOB_TASK_STATUS_FAIL: + if (newStatus != JOB_TASK_STATUS_DROP) { SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; - case JOB_TASK_STATUS_DROPPING: + case JOB_TASK_STATUS_DROP: SCH_ERR_JRET(TSDB_CODE_QRY_JOB_FREED); break; @@ -264,67 +144,11 @@ int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus) { _return: - SCH_JOB_ELOG("invalid job status update, from %s to %s", jobTaskStatusStr(oriStatus), jobTaskStatusStr(newStatus)); - SCH_RET(code); -} - - -void schEndOperation(SSchJob *pJob) { - int32_t op = atomic_load_32(&pJob->opStatus.op); - if (SCH_OP_NULL == op) { - SCH_JOB_DLOG("job already not in any operation, status:%s", jobTaskStatusStr(pJob->status)); - return; - } - - atomic_store_32(&pJob->opStatus.op, SCH_OP_NULL); - - SCH_JOB_DLOG("job end %s operation", schGetOpStr(op)); -} - -int32_t schBeginOperation(SSchJob *pJob, SCH_OP_TYPE type, bool sync) { - int32_t code = 0; - int8_t status = 0; - - if (schJobNeedToStop(pJob, &status)) { - SCH_JOB_ELOG("abort op %s cause of job need to stop", schGetOpStr(type)); - SCH_ERR_JRET(pJob->errCode); - } - - if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) { - SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op)); - SCH_ERR_JRET(TSDB_CODE_TSC_APP_ERROR); - } - - SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op)); - - pJob->opStatus.sync = sync; - - switch (type) { - case SCH_OP_EXEC: - SCH_ERR_JRET(schUpdateJobStatus(pJob, JOB_TASK_STATUS_EXECUTING)); - break; - case SCH_OP_FETCH: - if (!SCH_JOB_NEED_FETCH(pJob)) { - SCH_JOB_ELOG("no need to fetch data, status:%s", SCH_GET_JOB_STATUS_STR(pJob)); - SCH_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); - } - - if (status != JOB_TASK_STATUS_PARTIAL_SUCCEED) { - SCH_JOB_ELOG("job status error for fetch, status:%s", jobTaskStatusStr(status)); - SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); - } - break; - default: - SCH_JOB_ELOG("unknown operation type %d", type); - SCH_ERR_JRET(TSDB_CODE_TSC_APP_ERROR); + if (TSDB_CODE_SCH_IGNORE_ERROR == code) { + SCH_JOB_DLOG("ignore job status update, from %s to %s", jobTaskStatusStr(oriStatus), jobTaskStatusStr(newStatus)); + } else { + SCH_JOB_ELOG("invalid job status update, from %s to %s", jobTaskStatusStr(oriStatus), jobTaskStatusStr(newStatus)); } - - return TSDB_CODE_SUCCESS; - -_return: - - schEndOperation(pJob); - SCH_RET(code); } @@ -406,86 +230,23 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { } SSchLevel *pLevel = taosArrayGet(pJob->levels, 0); - if (SCH_IS_QUERY_JOB(pJob) && pLevel->taskNum > 1) { - SCH_JOB_ELOG("invalid query plan, level:0, taskNum:%d", pLevel->taskNum); - SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t schRecordTaskSucceedNode(SSchJob *pJob, SSchTask *pTask) { - SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); - if (NULL == addr) { - SCH_TASK_ELOG("taosArrayGet candidate addr failed, idx:%d, size:%d", pTask->candidateIdx, - (int32_t)taosArrayGetSize(pTask->candidateAddrs)); - SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); - } - - pTask->succeedAddr = *addr; - - return TSDB_CODE_SUCCESS; -} - -int32_t schAppendTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t execId) { - SSchNodeInfo nodeInfo = {.addr = *addr, .handle = NULL}; - - if (taosHashPut(pTask->execNodes, &execId, sizeof(execId), &nodeInfo, sizeof(nodeInfo))) { - SCH_TASK_ELOG("taosHashPut nodeInfo to execNodes failed, errno:%d", errno); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - SCH_TASK_DLOG("task execNode added, execId:%d", execId); - - return TSDB_CODE_SUCCESS; -} - -int32_t schDropTaskExecNode(SSchJob *pJob, SSchTask *pTask, void *handle, int32_t execId) { - if (NULL == pTask->execNodes) { - return TSDB_CODE_SUCCESS; - } - - if (taosHashRemove(pTask->execNodes, &execId, sizeof(execId))) { - SCH_TASK_ELOG("fail to remove execId %d from execNodeList", execId); - } else { - SCH_TASK_DLOG("execId %d removed from execNodeList", execId); - } - - if (execId != pTask->execId) { // ignore it - SCH_TASK_DLOG("execId %d is not current execId %d", execId, pTask->execId); - SCH_RET(TSDB_CODE_SCH_IGNORE_ERROR); - } - - return TSDB_CODE_SUCCESS; -} - -int32_t schUpdateTaskExecNode(SSchJob *pJob, SSchTask *pTask, void *handle, int32_t execId) { - if (taosHashGetSize(pTask->execNodes) <= 0) { - return TSDB_CODE_SUCCESS; - } - - SSchNodeInfo *nodeInfo = taosHashGet(pTask->execNodes, &execId, sizeof(execId)); - nodeInfo->handle = handle; - - SCH_TASK_DLOG("handle updated to %p for execId %d", handle, execId); - - return TSDB_CODE_SUCCESS; -} + if (SCH_IS_QUERY_JOB(pJob)) { + if (pLevel->taskNum > 1) { + SCH_JOB_ELOG("invalid query plan, level:0, taskNum:%d", pLevel->taskNum); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); + } -int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, void *handle, int32_t execId) { - if (dropExecNode) { - SCH_RET(schDropTaskExecNode(pJob, pTask, handle, execId)); + SSchTask* pTask = taosArrayGet(pLevel->subTasks, 0); + if (SUBPLAN_TYPE_MODIFY != pTask->plan->subplanType) { + pJob->attr.needFetch = true; + } } - SCH_SET_TASK_HANDLE(pTask, handle); - - schUpdateTaskExecNode(pJob, pTask, handle, execId); - return TSDB_CODE_SUCCESS; } -int32_t schRecordQueryDataSrc(SSchJob *pJob, SSchTask *pTask) { +int32_t schAppendJobDataSrc(SSchJob *pJob, SSchTask *pTask) { if (!SCH_IS_DATA_SRC_QRY_TASK(pTask)) { return TSDB_CODE_SUCCESS; } @@ -539,7 +300,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { int32_t taskNum = 0; SSchLevel *pLevel = NULL; - level.status = JOB_TASK_STATUS_NOT_START; + level.status = JOB_TASK_STATUS_INIT; for (int32_t i = 0; i < levelNum; ++i) { if (NULL == taosArrayPush(pJob->levels, &level)) { @@ -584,7 +345,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_ERR_JRET(schRecordQueryDataSrc(pJob, pTask)); + SCH_ERR_JRET(schAppendJobDataSrc(pJob, pTask)); if (0 != taosHashPut(planToTask, &plan, POINTER_BYTES, &pTask, POINTER_BYTES)) { SCH_TASK_ELOG("taosHashPut to planToTaks failed, taskIdx:%d", n); @@ -613,356 +374,83 @@ _return: SCH_RET(code); } -int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { - int32_t addNum = 0; - int32_t nodeNum = 0; - - if (pJob->nodeList) { - nodeNum = taosArrayGetSize(pJob->nodeList); - - for (int32_t i = 0; i < nodeNum && addNum < SCH_MAX_CANDIDATE_EP_NUM; ++i) { - SQueryNodeLoad *nload = taosArrayGet(pJob->nodeList, i); - SQueryNodeAddr *naddr = &nload->addr; - - if (NULL == taosArrayPush(pTask->candidateAddrs, naddr)) { - SCH_TASK_ELOG("taosArrayPush execNode to candidate addrs failed, addNum:%d, errno:%d", addNum, errno); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - SCH_TASK_DLOG("set %dth candidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, SCH_GET_CUR_EP(naddr)->port); - - ++addNum; - } - } +int32_t schDumpJobExecRes(SSchJob* pJob, SExecResult* pRes) { + pRes->code = atomic_load_32(&pJob->errCode); + pRes->numOfRows = pJob->resNumOfRows; + pRes->res = pJob->execRes.res; + pRes->msgType = pJob->execRes.msgType; + pJob->execRes.res = NULL; - if (addNum <= 0) { - SCH_TASK_ELOG("no available execNode as candidates, nodeNum:%d", nodeNum); - SCH_ERR_RET(TSDB_CODE_TSC_NO_EXEC_NODE); - } + SCH_JOB_DLOG("execRes dumped, code: %s", tstrerror(pRes->code)); return TSDB_CODE_SUCCESS; } - -int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) { - if (NULL != pTask->candidateAddrs) { - return TSDB_CODE_SUCCESS; - } - - pTask->candidateIdx = 0; - pTask->candidateAddrs = taosArrayInit(SCH_MAX_CANDIDATE_EP_NUM, sizeof(SQueryNodeAddr)); - if (NULL == pTask->candidateAddrs) { - SCH_TASK_ELOG("taosArrayInit %d condidate addrs failed", SCH_MAX_CANDIDATE_EP_NUM); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); +int32_t schDumpJobFetchRes(SSchJob* pJob, void** pData) { + int32_t code = 0; + if (pJob->resData && ((SRetrieveTableRsp *)pJob->resData)->completed) { + SCH_ERR_RET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_SUCC, NULL)); } - if (pTask->plan->execNode.epSet.numOfEps > 0) { - if (NULL == taosArrayPush(pTask->candidateAddrs, &pTask->plan->execNode)) { - SCH_TASK_ELOG("taosArrayPush execNode to candidate addrs failed, errno:%d", errno); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + while (true) { + *pData = atomic_load_ptr(&pJob->resData); + if (*pData != atomic_val_compare_exchange_ptr(&pJob->resData, *pData, NULL)) { + continue; } - SCH_TASK_DLOG("use execNode in plan as candidate addr, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps); - - return TSDB_CODE_SUCCESS; - } - - if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { - SCH_TASK_ELOG("no execNode specifed for data src task, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps); - SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + break; } - SCH_ERR_RET(schSetAddrsFromNodeList(pJob, pTask)); - - /* - for (int32_t i = 0; i < job->dataSrcEps.numOfEps && addNum < SCH_MAX_CANDIDATE_EP_NUM; ++i) { - strncpy(epSet->fqdn[epSet->numOfEps], job->dataSrcEps.fqdn[i], sizeof(job->dataSrcEps.fqdn[i])); - epSet->port[epSet->numOfEps] = job->dataSrcEps.port[i]; - - ++epSet->numOfEps; + if (NULL == *pData) { + SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp)); + if (rsp) { + rsp->completed = 1; } - */ - - return TSDB_CODE_SUCCESS; -} -int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSet) { - if (NULL == pTask->candidateAddrs || 1 != taosArrayGetSize(pTask->candidateAddrs)) { - SCH_TASK_ELOG("not able to update cndidate addr, addr num %d", (int32_t)(pTask->candidateAddrs ? taosArrayGetSize(pTask->candidateAddrs): 0)); - SCH_ERR_RET(TSDB_CODE_APP_ERROR); + *pData = rsp; + SCH_JOB_DLOG("empty res and set query complete, code:%x", code); } - SQueryNodeAddr* pAddr = taosArrayGet(pTask->candidateAddrs, 0); - - SEp* pOld = &pAddr->epSet.eps[pAddr->epSet.inUse]; - SEp* pNew = &pEpSet->eps[pEpSet->inUse]; - - SCH_TASK_DLOG("update task ep from %s:%d to %s:%d", pOld->fqdn, pOld->port, pNew->fqdn, pNew->port); - - memcpy(&pAddr->epSet, pEpSet, sizeof(pAddr->epSet)); + SCH_JOB_DLOG("fetch done, totalRows:%d", pJob->resNumOfRows); return TSDB_CODE_SUCCESS; } - -int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask) { - int32_t code = taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId)); - if (code) { - SCH_TASK_ELOG("task failed to rm from execTask list, code:%x", code); - SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); +int32_t schNotifyUserExecRes(SSchJob* pJob) { + SExecResult* pRes = taosMemoryCalloc(1, sizeof(SExecResult)); + if (pRes) { + schDumpJobExecRes(pJob, pRes); } + SCH_JOB_DLOG("sch start to invoke exec cb, code: %s", tstrerror(pJob->errCode)); + (*pJob->userRes.execFp)(pRes, pJob->userRes.cbParam, atomic_load_32(&pJob->errCode)); + SCH_JOB_DLOG("sch end from exec cb, code: %s", tstrerror(pJob->errCode)); + return TSDB_CODE_SUCCESS; } +int32_t schNotifyUserFetchRes(SSchJob* pJob) { + void* pRes = NULL; + + schDumpJobFetchRes(pJob, &pRes); -int32_t schPushTaskToExecList(SSchJob *pJob, SSchTask *pTask) { - int32_t code = taosHashPut(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); - if (0 != code) { - if (HASH_NODE_EXIST(code)) { - SCH_TASK_ELOG("task already in execTask list, code:%x", code); - SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); - } - - SCH_TASK_ELOG("taosHashPut task to execTask list failed, errno:%d", errno); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - SCH_TASK_DLOG("task added to execTask list, numOfTasks:%d", taosHashGetSize(pJob->execTasks)); + SCH_JOB_DLOG("sch start to invoke fetch cb, code: %s", tstrerror(pJob->errCode)); + (*pJob->userRes.fetchFp)(pRes, pJob->userRes.cbParam, atomic_load_32(&pJob->errCode)); + SCH_JOB_DLOG("sch end from fetch cb, code: %s", tstrerror(pJob->errCode)); return TSDB_CODE_SUCCESS; } -/* -int32_t schMoveTaskToSuccList(SSchJob *pJob, SSchTask *pTask, bool *moved) { - if (0 != taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId))) { - SCH_TASK_WLOG("remove task from execTask list failed, may not exist, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - } else { - SCH_TASK_DLOG("task removed from execTask list, numOfTasks:%d", taosHashGetSize(pJob->execTasks)); +void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) { + if (SCH_OP_NULL == pJob->opStatus.op) { + SCH_JOB_DLOG("job not in any operation, no need to post job res, status:%s", jobTaskStatusStr(pJob->status)); + return; } - - int32_t code = taosHashPut(pJob->succTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); - if (0 != code) { - if (HASH_NODE_EXIST(code)) { - *moved = true; - SCH_TASK_ELOG("task already in succTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); - } - - SCH_TASK_ELOG("taosHashPut task to succTask list failed, errno:%d", errno); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - *moved = true; - - SCH_TASK_DLOG("task moved to succTask list, numOfTasks:%d", taosHashGetSize(pJob->succTasks)); - - return TSDB_CODE_SUCCESS; -} - -int32_t schMoveTaskToFailList(SSchJob *pJob, SSchTask *pTask, bool *moved) { - *moved = false; - - if (0 != taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId))) { - SCH_TASK_WLOG("remove task from execTask list failed, may not exist, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - } - - int32_t code = taosHashPut(pJob->failTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); - if (0 != code) { - if (HASH_NODE_EXIST(code)) { - *moved = true; - - SCH_TASK_WLOG("task already in failTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); - } - - SCH_TASK_ELOG("taosHashPut task to failTask list failed, errno:%d", errno); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - *moved = true; - - SCH_TASK_DLOG("task moved to failTask list, numOfTasks:%d", taosHashGetSize(pJob->failTasks)); - - return TSDB_CODE_SUCCESS; -} - -int32_t schMoveTaskToExecList(SSchJob *pJob, SSchTask *pTask, bool *moved) { - if (0 != taosHashRemove(pJob->succTasks, &pTask->taskId, sizeof(pTask->taskId))) { - SCH_TASK_WLOG("remove task from succTask list failed, may not exist, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - } - - int32_t code = taosHashPut(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); - if (0 != code) { - if (HASH_NODE_EXIST(code)) { - *moved = true; - - SCH_TASK_ELOG("task already in execTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); - } - - SCH_TASK_ELOG("taosHashPut task to execTask list failed, errno:%d", errno); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - *moved = true; - - SCH_TASK_DLOG("task moved to execTask list, numOfTasks:%d", taosHashGetSize(pJob->execTasks)); - - return TSDB_CODE_SUCCESS; -} -*/ - -int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry) { - if (TSDB_CODE_SCH_TIMEOUT_ERROR == errCode) { - pTask->maxExecTimes++; - if (pTask->timeoutUsec < SCH_MAX_TASK_TIMEOUT_USEC) { - pTask->timeoutUsec *= 2; - if (pTask->timeoutUsec > SCH_MAX_TASK_TIMEOUT_USEC) { - pTask->timeoutUsec = SCH_MAX_TASK_TIMEOUT_USEC; - } - } - } - - if ((pTask->execId + 1) >= pTask->maxExecTimes) { - *needRetry = false; - SCH_TASK_DLOG("task no more retry since reach max try times, execId:%d", pTask->execId); - return TSDB_CODE_SUCCESS; - } - - if (!SCH_NEED_RETRY(pTask->lastMsgType, errCode)) { - *needRetry = false; - SCH_TASK_DLOG("task no more retry cause of errCode, errCode:%x - %s", errCode, tstrerror(errCode)); - return TSDB_CODE_SUCCESS; - } - - if (SCH_IS_DATA_SRC_TASK(pTask)) { - if ((pTask->execId + 1) >= SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)) { - *needRetry = false; - SCH_TASK_DLOG("task no more retry since all ep tried, execId:%d, epNum:%d", pTask->execId, - SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)); - return TSDB_CODE_SUCCESS; - } - } else { - int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); - - if ((pTask->candidateIdx + 1) >= candidateNum && (TSDB_CODE_SCH_TIMEOUT_ERROR != errCode)) { - *needRetry = false; - SCH_TASK_DLOG("task no more retry since all candiates tried, candidateIdx:%d, candidateNum:%d", - pTask->candidateIdx, candidateNum); - return TSDB_CODE_SUCCESS; - } - } - - *needRetry = true; - SCH_TASK_DLOG("task need the %dth retry, errCode:%x - %s", pTask->execId + 1, errCode, tstrerror(errCode)); - - return TSDB_CODE_SUCCESS; -} - -int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) { - atomic_sub_fetch_32(&pTask->level->taskLaunchedNum, 1); - - SCH_ERR_RET(schRemoveTaskFromExecList(pJob, pTask)); - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_NOT_START); - - if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { - SCH_ERR_RET(schLaunchTasksInFlowCtrlList(pJob, pTask)); - } - - schDeregisterTaskHb(pJob, pTask); - - if (SCH_IS_DATA_SRC_TASK(pTask)) { - SCH_SWITCH_EPSET(&pTask->plan->execNode); - } else { - int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); - if (++pTask->candidateIdx >= candidateNum) { - pTask->candidateIdx = 0; - } - } - - SCH_ERR_RET(schLaunchTask(pJob, pTask)); - - return TSDB_CODE_SUCCESS; -} - -int32_t schSetJobQueryRes(SSchJob* pJob, SQueryResult* pRes) { - pRes->code = atomic_load_32(&pJob->errCode); - pRes->numOfRows = pJob->resNumOfRows; - pRes->res = pJob->execRes; - pJob->execRes.res = NULL; - - return TSDB_CODE_SUCCESS; -} - -int32_t schSetJobFetchRes(SSchJob* pJob, void** pData) { - int32_t code = 0; - if (pJob->resData && ((SRetrieveTableRsp *)pJob->resData)->completed) { - SCH_ERR_RET(schUpdateJobStatus(pJob, JOB_TASK_STATUS_SUCCEED)); - } - - while (true) { - *pData = atomic_load_ptr(&pJob->resData); - if (*pData != atomic_val_compare_exchange_ptr(&pJob->resData, *pData, NULL)) { - continue; - } - - break; - } - - if (NULL == *pData) { - SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp)); - if (rsp) { - rsp->completed = 1; - } - - *pData = rsp; - SCH_JOB_DLOG("empty res and set query complete, code:%x", code); - } - - SCH_JOB_DLOG("fetch done, totalRows:%d", pJob->resNumOfRows); - - return TSDB_CODE_SUCCESS; -} - -int32_t schNotifyUserExecRes(SSchJob* pJob) { - SQueryResult* pRes = taosMemoryCalloc(1, sizeof(SQueryResult)); - if (pRes) { - schSetJobQueryRes(pJob, pRes); - } - - schEndOperation(pJob); - - SCH_JOB_DLOG("sch start to invoke exec cb, code: %s", tstrerror(pJob->errCode)); - (*pJob->userRes.execFp)(pRes, pJob->userRes.userParam, atomic_load_32(&pJob->errCode)); - SCH_JOB_DLOG("sch end from query cb, code: %s", tstrerror(pJob->errCode)); - - return TSDB_CODE_SUCCESS; -} - -int32_t schNotifyUserFetchRes(SSchJob* pJob) { - void* pRes = NULL; - - schSetJobFetchRes(pJob, &pRes); - - schEndOperation(pJob); - - SCH_JOB_DLOG("sch start to invoke fetch cb, code: %s", tstrerror(pJob->errCode)); - (*pJob->userRes.fetchFp)(pRes, pJob->userRes.userParam, atomic_load_32(&pJob->errCode)); - SCH_JOB_DLOG("sch end from fetch cb, code: %s", tstrerror(pJob->errCode)); - - return TSDB_CODE_SUCCESS; -} - -void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) { - if (SCH_OP_NULL == pJob->opStatus.op) { - SCH_JOB_DLOG("job not in any op, no need to post job res, status:%s", jobTaskStatusStr(pJob->status)); - return; - } - - if (op && pJob->opStatus.op != op) { - SCH_JOB_ELOG("job in op %s mis-match with expected %s", schGetOpStr(pJob->opStatus.op), schGetOpStr(op)); - return; + + if (op && pJob->opStatus.op != op) { + SCH_JOB_ELOG("job in operation %s mis-match with expected %s", schGetOpStr(pJob->opStatus.op), schGetOpStr(op)); + return; } if (SCH_JOB_IN_SYNC_OP(pJob)) { @@ -977,9 +465,6 @@ void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) { } int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCode) { - // if already FAILED, no more processing - SCH_ERR_RET(schUpdateJobStatus(pJob, status)); - schUpdateJobErrCode(pJob, errCode); int32_t code = atomic_load_32(&pJob->errCode); @@ -989,97 +474,49 @@ int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCod schPostJobRes(pJob, 0); - SCH_RET(code); + SCH_RET(TSDB_CODE_SCH_IGNORE_ERROR); } // Note: no more task error processing, handled in function internal int32_t schProcessOnJobFailure(SSchJob *pJob, int32_t errCode) { - SCH_RET(schProcessOnJobFailureImpl(pJob, JOB_TASK_STATUS_FAILED, errCode)); + if (TSDB_CODE_SCH_IGNORE_ERROR == errCode) { + return TSDB_CODE_SCH_IGNORE_ERROR; + } + + schProcessOnJobFailureImpl(pJob, JOB_TASK_STATUS_FAIL, errCode); + return TSDB_CODE_SCH_IGNORE_ERROR; } // Note: no more error processing, handled in function internal int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode) { - SCH_RET(schProcessOnJobFailureImpl(pJob, JOB_TASK_STATUS_DROPPING, errCode)); + SCH_RET(schProcessOnJobFailureImpl(pJob, JOB_TASK_STATUS_DROP, errCode)); } -// Note: no more task error processing, handled in function internal int32_t schProcessOnJobPartialSuccess(SSchJob *pJob) { - int32_t code = 0; - - SCH_ERR_RET(schUpdateJobStatus(pJob, JOB_TASK_STATUS_PARTIAL_SUCCEED)); - schPostJobRes(pJob, SCH_OP_EXEC); return TSDB_CODE_SUCCESS; - -_return: - - SCH_RET(schProcessOnJobFailure(pJob, code)); } void schProcessOnDataFetched(SSchJob *pJob) { schPostJobRes(pJob, SCH_OP_FETCH); } -// Note: no more task error processing, handled in function internal -int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode) { - int8_t status = 0; - - if (errCode == TSDB_CODE_SCH_TIMEOUT_ERROR) { - SCH_LOG_TASK_WAIT_TS(pTask); - } else { - SCH_LOG_TASK_END_TS(pTask); - } - - if (schJobNeedToStop(pJob, &status)) { - SCH_TASK_DLOG("task failed not processed cause of job status, job status:%s", jobTaskStatusStr(status)); - SCH_RET(atomic_load_32(&pJob->errCode)); - } - - bool needRetry = false; - bool moved = false; - int32_t taskDone = 0; - int32_t code = 0; - - SCH_TASK_DLOG("taskOnFailure, code:%s", tstrerror(errCode)); - - SCH_ERR_JRET(schTaskCheckSetRetry(pJob, pTask, errCode, &needRetry)); - - if (!needRetry) { - SCH_TASK_ELOG("task failed and no more retry, code:%s", tstrerror(errCode)); - - if (SCH_GET_TASK_STATUS(pTask) != JOB_TASK_STATUS_EXECUTING) { - SCH_TASK_ELOG("task not in executing list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); - } - - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_FAILED); - - if (SCH_IS_WAIT_ALL_JOB(pJob)) { - SCH_LOCK(SCH_WRITE, &pTask->level->lock); - pTask->level->taskFailed++; - taskDone = pTask->level->taskSucceed + pTask->level->taskFailed; - SCH_UNLOCK(SCH_WRITE, &pTask->level->lock); - - schUpdateJobErrCode(pJob, errCode); +int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRsp *pRsp) { + SCH_TASK_DLOG("got explain rsp, rows:%d, complete:%d", htonl(pRsp->numOfRows), pRsp->completed); - if (taskDone < pTask->level->taskNum) { - SCH_TASK_DLOG("need to wait other tasks, doneNum:%d, allNum:%d", taskDone, pTask->level->taskNum); - SCH_RET(errCode); - } - } - } else { - SCH_ERR_JRET(schHandleTaskRetry(pJob, pTask)); + atomic_store_32(&pJob->resNumOfRows, htonl(pRsp->numOfRows)); + atomic_store_ptr(&pJob->resData, pRsp); - return TSDB_CODE_SUCCESS; - } + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_SUCC); -_return: + schProcessOnDataFetched(pJob); - SCH_RET(schProcessOnJobFailure(pJob, errCode)); + return TSDB_CODE_SUCCESS; } -int32_t schLaunchNextLevelTasks(SSchJob *pJob, SSchTask *pTask) { + +int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask) { if (!SCH_IS_QUERY_JOB(pJob)) { return TSDB_CODE_SUCCESS; } @@ -1104,217 +541,6 @@ int32_t schLaunchNextLevelTasks(SSchJob *pJob, SSchTask *pTask) { return TSDB_CODE_SUCCESS; } - -// Note: no more task error processing, handled in function internal -int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { - bool moved = false; - int32_t code = 0; - - SCH_TASK_DLOG("taskOnSuccess, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - - SCH_LOG_TASK_END_TS(pTask); - - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_PARTIAL_SUCCEED); - - SCH_ERR_JRET(schRecordTaskSucceedNode(pJob, pTask)); - - SCH_ERR_JRET(schLaunchTasksInFlowCtrlList(pJob, pTask)); - - int32_t parentNum = pTask->parents ? (int32_t)taosArrayGetSize(pTask->parents) : 0; - if (parentNum == 0) { - int32_t taskDone = 0; - if (SCH_IS_WAIT_ALL_JOB(pJob)) { - SCH_LOCK(SCH_WRITE, &pTask->level->lock); - pTask->level->taskSucceed++; - taskDone = pTask->level->taskSucceed + pTask->level->taskFailed; - SCH_UNLOCK(SCH_WRITE, &pTask->level->lock); - - if (taskDone < pTask->level->taskNum) { - SCH_TASK_DLOG("wait all tasks, done:%d, all:%d", taskDone, pTask->level->taskNum); - return TSDB_CODE_SUCCESS; - } else if (taskDone > pTask->level->taskNum) { - SCH_TASK_ELOG("taskDone number invalid, done:%d, total:%d", taskDone, pTask->level->taskNum); - } - - if (pTask->level->taskFailed > 0) { - SCH_RET(schProcessOnJobFailure(pJob, 0)); - } else { - SCH_RET(schProcessOnJobPartialSuccess(pJob)); - } - } else { - pJob->resNode = pTask->succeedAddr; - } - - pJob->fetchTask = pTask; - - SCH_RET(schProcessOnJobPartialSuccess(pJob)); - } - - /* - if (SCH_IS_DATA_SRC_TASK(task) && job->dataSrcEps.numOfEps < SCH_MAX_CANDIDATE_EP_NUM) { - strncpy(job->dataSrcEps.fqdn[job->dataSrcEps.numOfEps], task->execAddr.fqdn, sizeof(task->execAddr.fqdn)); - job->dataSrcEps.port[job->dataSrcEps.numOfEps] = task->execAddr.port; - - ++job->dataSrcEps.numOfEps; - } - */ - - for (int32_t i = 0; i < parentNum; ++i) { - SSchTask *parent = *(SSchTask **)taosArrayGet(pTask->parents, i); - int32_t readyNum = atomic_add_fetch_32(&parent->childReady, 1); - - SCH_LOCK(SCH_WRITE, &parent->lock); - SDownstreamSourceNode source = {.type = QUERY_NODE_DOWNSTREAM_SOURCE, - .taskId = pTask->taskId, - .schedId = schMgmt.sId, - .execId = pTask->execId, - .addr = pTask->succeedAddr}; - qSetSubplanExecutionNode(parent->plan, pTask->plan->id.groupId, &source); - SCH_UNLOCK(SCH_WRITE, &parent->lock); - - if (SCH_TASK_READY_FOR_LAUNCH(readyNum, parent)) { - SCH_TASK_DLOG("all %d children task done, start to launch parent task 0x%" PRIx64, readyNum, parent->taskId); - SCH_ERR_RET(schLaunchTask(pJob, parent)); - } - } - - SCH_ERR_RET(schLaunchNextLevelTasks(pJob, pTask)); - - return TSDB_CODE_SUCCESS; - -_return: - - SCH_RET(schProcessOnJobFailure(pJob, code)); -} - -// Note: no more error processing, handled in function internal -int32_t schFetchFromRemote(SSchJob *pJob) { - int32_t code = 0; - - void *resData = atomic_load_ptr(&pJob->resData); - if (resData) { - SCH_JOB_DLOG("res already fetched, res:%p", resData); - return TSDB_CODE_SUCCESS; - } - - SCH_ERR_JRET(schBuildAndSendMsg(pJob, pJob->fetchTask, &pJob->resNode, TDMT_SCH_FETCH)); - - return TSDB_CODE_SUCCESS; - -_return: - - SCH_RET(schProcessOnTaskFailure(pJob, pJob->fetchTask, code)); -} - -int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRsp *pRsp) { - SCH_TASK_DLOG("got explain rsp, rows:%d, complete:%d", htonl(pRsp->numOfRows), pRsp->completed); - - atomic_store_32(&pJob->resNumOfRows, htonl(pRsp->numOfRows)); - atomic_store_ptr(&pJob->resData, pRsp); - - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_SUCCEED); - - schProcessOnDataFetched(pJob); - - return TSDB_CODE_SUCCESS; -} - -void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask) { - if (NULL == pTask->execNodes) { - SCH_TASK_DLOG("no exec address, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - return; - } - - int32_t size = (int32_t)taosHashGetSize(pTask->execNodes); - - if (size <= 0) { - SCH_TASK_DLOG("task has no execNodes, no need to drop it, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - return; - } - - SSchNodeInfo *nodeInfo = taosHashIterate(pTask->execNodes, NULL); - while (nodeInfo) { - SCH_SET_TASK_HANDLE(pTask, nodeInfo->handle); - - schBuildAndSendMsg(pJob, pTask, &nodeInfo->addr, TDMT_SCH_DROP_TASK); - - nodeInfo = taosHashIterate(pTask->execNodes, nodeInfo); - } - - SCH_TASK_DLOG("task has been dropped on %d exec nodes", size); -} - - -int32_t schRescheduleTask(SSchJob *pJob, SSchTask *pTask) { - if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { - return TSDB_CODE_SUCCESS; - } - - SCH_LOCK_TASK(pTask); - if (SCH_TASK_TIMEOUT(pTask) && JOB_TASK_STATUS_EXECUTING == pTask->status && - pJob->fetchTask != pTask && taosArrayGetSize(pTask->candidateAddrs) > 1) { - SCH_TASK_DLOG("task execId %d will be rescheduled now", pTask->execId); - schDropTaskOnExecNode(pJob, pTask); - taosHashClear(pTask->execNodes); - schProcessOnTaskFailure(pJob, pTask, TSDB_CODE_SCH_TIMEOUT_ERROR); - } - SCH_UNLOCK_TASK(pTask); - - return TSDB_CODE_SUCCESS; -} - -int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList) { - int32_t taskNum = (int32_t)taosArrayGetSize(pStatusList); - SSchTask *pTask = NULL; - - qDebug("%d task status in hb rsp from nodeId:%d, fqdn:%s, port:%d", taskNum, pEpId->nodeId, pEpId->ep.fqdn, pEpId->ep.port); - - for (int32_t i = 0; i < taskNum; ++i) { - STaskStatus *taskStatus = taosArrayGet(pStatusList, i); - - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s", - taskStatus->queryId, taskStatus->taskId, taskStatus->execId, jobTaskStatusStr(taskStatus->status)); - - SSchJob *pJob = schAcquireJob(taskStatus->refId); - if (NULL == pJob) { - qWarn("job not found, refId:0x%" PRIx64 ",QID:0x%" PRIx64 ",TID:0x%" PRIx64, taskStatus->refId, - taskStatus->queryId, taskStatus->taskId); - // TODO DROP TASK FROM SERVER!!!! - continue; - } - - pTask = NULL; - schGetTaskInJob(pJob, taskStatus->taskId, &pTask); - if (NULL == pTask) { - // TODO DROP TASK FROM SERVER!!!! - schReleaseJob(taskStatus->refId); - continue; - } - - if (taskStatus->execId != pTask->execId) { - // TODO DROP TASK FROM SERVER!!!! - SCH_TASK_DLOG("EID %d in hb rsp mis-match", taskStatus->execId); - schReleaseJob(taskStatus->refId); - continue; - } - - if (taskStatus->status == JOB_TASK_STATUS_FAILED) { - // RECORD AND HANDLE ERROR!!!! - schReleaseJob(taskStatus->refId); - continue; - } - - if (taskStatus->status == JOB_TASK_STATUS_NOT_START) { - schRescheduleTask(pJob, pTask); - } - - schReleaseJob(taskStatus->refId); - } - - return TSDB_CODE_SUCCESS; -} - - int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { if (rsp->tbFName[0]) { if (NULL == pJob->execRes.res) { @@ -1336,22 +562,6 @@ int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { return TSDB_CODE_SUCCESS; } -int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask) { - int32_t s = taosHashGetSize(pTaskList); - if (s <= 0) { - return TSDB_CODE_SUCCESS; - } - - SSchTask **task = taosHashGet(pTaskList, &taskId, sizeof(taskId)); - if (NULL == task || NULL == (*task)) { - return TSDB_CODE_SUCCESS; - } - - *pTask = *task; - - return TSDB_CODE_SUCCESS; -} - int32_t schGetTaskInJob(SSchJob *pJob, uint64_t taskId, SSchTask **pTask) { schGetTaskFromList(pJob->taskList, taskId, pTask); if (NULL == *pTask) { @@ -1362,112 +572,19 @@ int32_t schGetTaskInJob(SSchJob *pJob, uint64_t taskId, SSchTask **pTask) { return TSDB_CODE_SUCCESS; } -int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask) { - int8_t status = 0; - int32_t code = 0; - - atomic_add_fetch_32(&pTask->level->taskLaunchedNum, 1); - pTask->execId++; - - SCH_TASK_DLOG("start to launch task's %dth exec", pTask->execId); - - SCH_LOG_TASK_START_TS(pTask); - - if (schJobNeedToStop(pJob, &status)) { - SCH_TASK_DLOG("no need to launch task cause of job status, job status:%s", jobTaskStatusStr(status)); - - SCH_RET(atomic_load_32(&pJob->errCode)); - } - - // NOTE: race condition: the task should be put into the hash table before send msg to server - if (SCH_GET_TASK_STATUS(pTask) != JOB_TASK_STATUS_EXECUTING) { - SCH_ERR_RET(schPushTaskToExecList(pJob, pTask)); - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_EXECUTING); - } - - SSubplan *plan = pTask->plan; - - if (NULL == pTask->msg) { // TODO add more detailed reason for failure - code = qSubPlanToString(plan, &pTask->msg, &pTask->msgLen); - if (TSDB_CODE_SUCCESS != code) { - SCH_TASK_ELOG("failed to create physical plan, code:%s, msg:%p, len:%d", tstrerror(code), pTask->msg, - pTask->msgLen); - SCH_ERR_RET(code); - } else { - SCH_TASK_DLOGL("physical plan len:%d, %s", pTask->msgLen, pTask->msg); - } - } - - SCH_ERR_RET(schSetTaskCandidateAddrs(pJob, pTask)); - - if (SCH_IS_QUERY_JOB(pJob)) { - SCH_ERR_RET(schEnsureHbConnection(pJob, pTask)); - } - - SCH_ERR_RET(schBuildAndSendMsg(pJob, pTask, NULL, plan->msgType)); - - return TSDB_CODE_SUCCESS; -} - -// Note: no more error processing, handled in function internal -int32_t schLaunchTask(SSchJob *pJob, SSchTask *pTask) { - bool enough = false; - int32_t code = 0; - - SCH_SET_TASK_HANDLE(pTask, NULL); - if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { - SCH_ERR_JRET(schCheckIncTaskFlowQuota(pJob, pTask, &enough)); - - if (enough) { - SCH_ERR_JRET(schLaunchTaskImpl(pJob, pTask)); - } +int32_t schLaunchJob(SSchJob *pJob) { + if (EXPLAIN_MODE_STATIC == pJob->attr.explainMode) { + SCH_ERR_RET(qExecStaticExplain(pJob->pDag, (SRetrieveTableRsp **)&pJob->resData)); + SCH_ERR_RET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_PART_SUCC, NULL)); } else { - SCH_ERR_JRET(schLaunchTaskImpl(pJob, pTask)); - } - - return TSDB_CODE_SUCCESS; - -_return: - - SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); -} - -int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level) { - for (int32_t i = 0; i < level->taskNum; ++i) { - SSchTask *pTask = taosArrayGet(level->subTasks, i); - - SCH_ERR_RET(schLaunchTask(pJob, pTask)); + SSchLevel *level = taosArrayGet(pJob->levels, pJob->levelIdx); + SCH_ERR_RET(schLaunchLevelTasks(pJob, level)); } return TSDB_CODE_SUCCESS; } -int32_t schLaunchJob(SSchJob *pJob) { - SSchLevel *level = taosArrayGet(pJob->levels, pJob->levelIdx); - - SCH_ERR_RET(schChkJobNeedFlowCtrl(pJob, level)); - - SCH_ERR_RET(schLaunchLevelTasks(pJob, level)); - - return TSDB_CODE_SUCCESS; -} - - -void schDropTaskInHashList(SSchJob *pJob, SHashObj *list) { - if (!SCH_IS_NEED_DROP_JOB(pJob)) { - return; - } - - void *pIter = taosHashIterate(list, NULL); - while (pIter) { - SSchTask *pTask = *(SSchTask **)pIter; - - schDropTaskOnExecNode(pJob, pTask); - - pIter = taosHashIterate(list, pIter); - } -} void schDropJobAllTasks(SSchJob *pJob) { schDropTaskInHashList(pJob, pJob->execTasks); @@ -1475,12 +592,6 @@ void schDropJobAllTasks(SSchJob *pJob) { // schDropTaskInHashList(pJob, pJob->failTasks); } -int32_t schCancelJob(SSchJob *pJob) { - // TODO - return TSDB_CODE_SUCCESS; - // TODO MOVE ALL TASKS FROM EXEC LIST TO FAIL LIST -} - void schFreeJobImpl(void *job) { if (NULL == job) { return; @@ -1492,10 +603,6 @@ void schFreeJobImpl(void *job) { qDebug("QID:0x%" PRIx64 " begin to free sch job, refId:0x%" PRIx64 ", pointer:%p", queryId, refId, pJob); - if (pJob->status == JOB_TASK_STATUS_EXECUTING) { - schCancelJob(pJob); - } - schDropJobAllTasks(pJob); int32_t numOfLevels = taosArrayGetSize(pJob->levels); @@ -1528,7 +635,7 @@ void schFreeJobImpl(void *job) { qDestroyQueryPlan(pJob->pDag); - taosMemoryFreeClear(pJob->userRes.queryRes); + taosMemoryFreeClear(pJob->userRes.execRes); taosMemoryFreeClear(pJob->resData); taosMemoryFree(pJob); @@ -1540,228 +647,259 @@ void schFreeJobImpl(void *job) { qDebug("QID:0x%" PRIx64 " sch job freed, refId:0x%" PRIx64 ", pointer:%p", queryId, refId, pJob); } -int32_t schLaunchStaticExplainJob(SSchedulerReq *pReq, SSchJob *pJob, bool sync) { - qDebug("QID:0x%" PRIx64 " job started", pReq->pDag->queryId); +int32_t schJobFetchRows(SSchJob *pJob) { + int32_t code = 0; + + if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) { + SCH_ERR_RET(schLaunchFetchTask(pJob)); + + if (pJob->opStatus.syncReq) { + SCH_JOB_DLOG("sync wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); + tsem_wait(&pJob->rspSem); + SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes)); + } + } else { + if (pJob->opStatus.syncReq) { + SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes)); + } else { + schPostJobRes(pJob, SCH_OP_FETCH); + } + } + + SCH_RET(code); +} +int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { int32_t code = 0; -/* + int64_t refId = -1; SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob)); if (NULL == pJob) { qError("QID:0x%" PRIx64 " calloc %d failed", pReq->pDag->queryId, (int32_t)sizeof(SSchJob)); - code = TSDB_CODE_QRY_OUT_OF_MEMORY; - pReq->fp(NULL, pReq->cbParam, code); - SCH_ERR_RET(code); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + pJob->attr.explainMode = pReq->pDag->explainInfo.mode; + pJob->conn = *pReq->pConn; pJob->sql = pReq->sql; - pJob->reqKilled = pReq->reqKilled; pJob->pDag = pReq->pDag; - pJob->attr.queryJob = true; - pJob->attr.explainMode = pReq->pDag->explainInfo.mode; - pJob->queryId = pReq->pDag->queryId; - pJob->userRes.execFp = pReq->fp; - pJob->userRes.userParam = pReq->cbParam; - - schUpdateJobStatus(pJob, JOB_TASK_STATUS_NOT_START); + pJob->chkKillFp = pReq->chkKillFp; + pJob->chkKillParam = pReq->chkKillParam; + pJob->userRes.execFp = pReq->execFp; + pJob->userRes.cbParam = pReq->cbParam; - code = schBeginOperation(pJob, SCH_OP_EXEC, sync); - if (code) { - pReq->fp(NULL, pReq->cbParam, code); - schFreeJobImpl(pJob); - SCH_ERR_RET(code); + if (pReq->pNodeList == NULL || taosArrayGetSize(pReq->pNodeList) <= 0) { + qDebug("QID:0x%" PRIx64 " input exec nodeList is empty", pReq->pDag->queryId); + } else { + pJob->nodeList = taosArrayDup(pReq->pNodeList); + } + + pJob->taskList = + taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); + if (NULL == pJob->taskList) { + SCH_JOB_ELOG("taosHashInit %d taskList failed", pReq->pDag->numOfSubplans); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } -*/ - SCH_ERR_JRET(qExecStaticExplain(pReq->pDag, (SRetrieveTableRsp **)&pJob->resData)); + SCH_ERR_JRET(schValidateAndBuildJob(pReq->pDag, pJob)); -/* - int64_t refId = taosAddRef(schMgmt.jobRef, pJob); - if (refId < 0) { - SCH_JOB_ELOG("taosAddRef job failed, error:%s", tstrerror(terrno)); - SCH_ERR_JRET(terrno); + if (SCH_IS_EXPLAIN_JOB(pJob)) { + SCH_ERR_JRET(qExecExplainBegin(pReq->pDag, &pJob->explainCtx, pReq->startTs)); } - if (NULL == schAcquireJob(refId)) { - SCH_JOB_ELOG("schAcquireJob job failed, refId:0x%" PRIx64, refId); - SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); + pJob->execTasks = + taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); + if (NULL == pJob->execTasks) { + SCH_JOB_ELOG("taosHashInit %d execTasks failed", pReq->pDag->numOfSubplans); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - pJob->refId = refId; - - SCH_JOB_DLOG("job refId:0x%" PRIx64, pJob->refId); -*/ + tsem_init(&pJob->rspSem, 0, 0); - pJob->status = JOB_TASK_STATUS_PARTIAL_SUCCEED; - - SCH_JOB_DLOG("job exec done, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); - - if (!sync) { - schPostJobRes(pJob, SCH_OP_EXEC); - } else { - schEndOperation(pJob); + pJob->refId = taosAddRef(schMgmt.jobRef, pJob); + if (pJob->refId < 0) { + SCH_JOB_ELOG("taosAddRef job failed, error:%s", tstrerror(terrno)); + SCH_ERR_JRET(terrno); } -// schReleaseJob(pJob->refId); + atomic_add_fetch_32(&schMgmt.jobNum, 1); + + *pJobId = pJob->refId; - SCH_RET(code); + SCH_JOB_DLOG("job refId:0x%" PRIx64" created", pJob->refId); + + return TSDB_CODE_SUCCESS; _return: - schEndOperation(pJob); - if (!sync) { - pReq->execFp(NULL, pReq->execParam, code); + if (NULL == pJob) { + qDestroyQueryPlan(pReq->pDag); + } else if (pJob->refId < 0) { + schFreeJobImpl(pJob); + } else { + taosRemoveRef(schMgmt.jobRef, pJob->refId); } - schFreeJobImpl(pJob); - SCH_RET(code); } -int32_t schFetchRows(SSchJob *pJob) { - int32_t code = 0; +int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq) { + int32_t code = 0; + qDebug("QID:0x%" PRIx64 " sch job refId 0x%"PRIx64 " started", pReq->pDag->queryId, pJob->refId); - if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) { - SCH_ERR_JRET(schFetchFromRemote(pJob)); + SCH_ERR_RET(schLaunchJob(pJob)); + + if (pReq->syncReq) { + SCH_JOB_DLOG("sync wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); tsem_wait(&pJob->rspSem); } - SCH_ERR_JRET(schSetJobFetchRes(pJob, pJob->userRes.fetchRes)); - -_return: - - schEndOperation(pJob); - - SCH_RET(code); + SCH_JOB_DLOG("job exec done, job status:%s, jobId:0x%" PRIx64, SCH_GET_JOB_STATUS_STR(pJob), pJob->refId); + + return TSDB_CODE_SUCCESS; } -int32_t schAsyncFetchRows(SSchJob *pJob) { - int32_t code = 0; - if (pJob->attr.explainMode == EXPLAIN_MODE_STATIC) { - schPostJobRes(pJob, SCH_OP_FETCH); - return TSDB_CODE_SUCCESS; - } +void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode) { + int32_t op = 0; - SCH_ERR_RET(schFetchFromRemote(pJob)); - - return TSDB_CODE_SUCCESS; -} + switch (type) { + case SCH_OP_EXEC: + if (pReq && pReq->syncReq) { + op = atomic_val_compare_exchange_32(&pJob->opStatus.op, type, SCH_OP_NULL); + if (SCH_OP_NULL == op || op != type) { + SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), jobTaskStatusStr(pJob->status)); + } + schDumpJobExecRes(pJob, pReq->pExecRes); + } + break; + case SCH_OP_FETCH: + if (pReq && pReq->syncReq) { + op = atomic_val_compare_exchange_32(&pJob->opStatus.op, type, SCH_OP_NULL); + if (SCH_OP_NULL == op || op != type) { + SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), jobTaskStatusStr(pJob->status)); + } + } + break; + case SCH_OP_GET_STATUS: + errCode = TSDB_CODE_SUCCESS; + break; + default: + break; + } + if (errCode) { + schSwitchJobStatus(pJob, JOB_TASK_STATUS_FAIL, (void*)&errCode); + } -int32_t schExecJobImpl(SSchedulerReq *pReq, SSchJob *pJob, bool sync) { - int32_t code = 0; + SCH_JOB_DLOG("job end %s operation with code %s", schGetOpStr(type), tstrerror(errCode)); +} - qDebug("QID:0x%" PRIx64 " sch job refId 0x%"PRIx64 " started", pReq->pDag->queryId, pJob->refId); +int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq) { + int32_t code = 0; + int8_t status = 0; - SCH_ERR_JRET(schBeginOperation(pJob, SCH_OP_EXEC, sync)); + if (schJobNeedToStop(pJob, &status)) { + SCH_JOB_ELOG("abort op %s cause of job need to stop, status:%s", schGetOpStr(type), jobTaskStatusStr(status)); + SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); + } + + switch (type) { + case SCH_OP_EXEC: + if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) { + SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op)); + SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); + } + + SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op)); + + pJob->opStatus.syncReq = pReq->syncReq; + break; + case SCH_OP_FETCH: + if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) { + SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op)); + SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); + } + + SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op)); + + pJob->opStatus.syncReq = pReq->syncReq; + + if (!SCH_JOB_NEED_FETCH(pJob)) { + SCH_JOB_ELOG("no need to fetch data, status:%s", SCH_GET_JOB_STATUS_STR(pJob)); + SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } - if (EXPLAIN_MODE_STATIC == pReq->pDag->explainInfo.mode) { - code = schLaunchStaticExplainJob(pReq, pJob, sync); - } else { - code = schLaunchJob(pJob); - if (sync) { - SCH_JOB_DLOG("will wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); - tsem_wait(&pJob->rspSem); + if (status != JOB_TASK_STATUS_PART_SUCC) { + SCH_JOB_ELOG("job status error for fetch, status:%s", jobTaskStatusStr(status)); + SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + } - schEndOperation(pJob); - } else if (code) { - schPostJobRes(pJob, SCH_OP_EXEC); - } + pJob->userRes.fetchRes = pReq->pFetchRes; + pJob->userRes.fetchFp = pReq->fetchFp; + pJob->userRes.cbParam = pReq->cbParam; + + break; + case SCH_OP_GET_STATUS: + if (pJob->status < JOB_TASK_STATUS_INIT || pJob->levelNum <= 0 || NULL == pJob->levels) { + qDebug("job not initialized or not executable job, refId:0x%" PRIx64, pJob->refId); + SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + break; + default: + SCH_JOB_ELOG("unknown operation type %d", type); + SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } - SCH_JOB_DLOG("job exec done, job status:%s, jobId:0x%" PRIx64, SCH_GET_JOB_STATUS_STR(pJob), pJob->refId); - - SCH_RET(code); + return TSDB_CODE_SUCCESS; +} -_return: +void schProcessOnCbEnd(SSchJob *pJob, SSchTask *pTask, int32_t errCode) { + if (pTask) { + SCH_UNLOCK_TASK(pTask); + } - if (!sync) { - pReq->execFp(NULL, pReq->execParam, code); + if (errCode) { + schSwitchJobStatus(pJob, JOB_TASK_STATUS_FAIL, (void*)&errCode); } - SCH_RET(code); + if (pJob) { + schReleaseJob(pJob->refId); + } } -int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) { +int32_t schProcessOnCbBegin(SSchJob** job, SSchTask** task, uint64_t qId, int64_t rId, uint64_t tId) { int32_t code = 0; - - if ((pTask->execId + 1) >= pTask->maxExecTimes) { - SCH_TASK_DLOG("task no more retry since reach max try times, execId:%d", pTask->execId); - schProcessOnJobFailure(pJob, rspCode); - return TSDB_CODE_SUCCESS; - } + int8_t status = 0; - SCH_TASK_DLOG("task will be redirected now, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - - schDropTaskOnExecNode(pJob, pTask); - taosHashClear(pTask->execNodes); - SCH_ERR_JRET(schRemoveTaskFromExecList(pJob, pTask)); - schDeregisterTaskHb(pJob, pTask); - atomic_sub_fetch_32(&pTask->level->taskLaunchedNum, 1); - taosMemoryFreeClear(pTask->msg); - pTask->msgLen = 0; - pTask->lastMsgType = 0; - memset(&pTask->succeedAddr, 0, sizeof(pTask->succeedAddr)); - - if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { - if (pData) { - SCH_ERR_JRET(schUpdateTaskCandidateAddr(pJob, pTask, pData->pEpSet)); - } + SSchTask *pTask = NULL; + SSchJob *pJob = schAcquireJob(rId); + if (NULL == pJob) { + qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, qId, tId, rId); + SCH_ERR_RET(TSDB_CODE_QRY_JOB_NOT_EXIST); + } - if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { - if (JOB_TASK_STATUS_EXECUTING == SCH_GET_TASK_STATUS(pTask)) { - SCH_ERR_JRET(schLaunchTasksInFlowCtrlList(pJob, pTask)); - } - } - - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_NOT_START); - - SCH_ERR_JRET(schLaunchTask(pJob, pTask)); - - return TSDB_CODE_SUCCESS; + if (schJobNeedToStop(pJob, &status)) { + SCH_TASK_ELOG("will not do further processing cause of job status %s", jobTaskStatusStr(status)); + SCH_ERR_JRET(TSDB_CODE_SCH_IGNORE_ERROR); } + SCH_ERR_JRET(schGetTaskInJob(pJob, tId, &pTask)); - // merge plan - - pTask->childReady = 0; - - qClearSubplanExecutionNode(pTask->plan); + SCH_LOCK_TASK(pTask); - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_NOT_START); - - int32_t childrenNum = taosArrayGetSize(pTask->children); - for (int32_t i = 0; i < childrenNum; ++i) { - SSchTask* pChild = taosArrayGetP(pTask->children, i); - SCH_LOCK_TASK(pChild); - schDoTaskRedirect(pJob, pChild, NULL, rspCode); - SCH_UNLOCK_TASK(pChild); - } + *job = pJob; + *task = pTask; return TSDB_CODE_SUCCESS; _return: - code = schProcessOnTaskFailure(pJob, pTask, code); - - SCH_RET(code); -} - -int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) { - int32_t code = 0; - - if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { - if (NULL == pData->pEpSet) { - SCH_TASK_ELOG("no epset updated while got error %s", tstrerror(rspCode)); - SCH_ERR_JRET(rspCode); - } + if (pTask) { + SCH_UNLOCK_TASK(pTask); + } + if (pJob) { + schReleaseJob(rId); } - - SCH_RET(schDoTaskRedirect(pJob, pTask, pData, rspCode)); - -_return: - - schProcessOnTaskFailure(pJob, pTask, code); SCH_RET(code); } diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 32f151f8af0fce50f2cbd61ef5d24cf9cac946d7..bf85d09e004c2bf882512ae61f365f1c7f82699d 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -16,12 +16,11 @@ #include "catalog.h" #include "command.h" #include "query.h" -#include "schedulerInt.h" +#include "schInt.h" #include "tmsg.h" #include "tref.h" #include "trpc.h" - int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgType) { int32_t lastMsgType = pTask->lastMsgType; int32_t taskStatus = SCH_GET_TASK_STATUS(pTask); @@ -37,12 +36,12 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy TMSG_INFO(msgType)); } - if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { + if (taskStatus != JOB_TASK_STATUS_EXEC && taskStatus != JOB_TASK_STATUS_PART_SUCC) { SCH_TASK_DLOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); } - //SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); + // SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); return TSDB_CODE_SUCCESS; case TDMT_SCH_FETCH_RSP: if (lastMsgType != reqMsgType && -1 != lastMsgType) { @@ -51,19 +50,20 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { + if (taskStatus != JOB_TASK_STATUS_EXEC && taskStatus != JOB_TASK_STATUS_PART_SUCC) { SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - //SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); + // SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); return TSDB_CODE_SUCCESS; case TDMT_VND_CREATE_TABLE_RSP: case TDMT_VND_DROP_TABLE_RSP: case TDMT_VND_ALTER_TABLE_RSP: case TDMT_VND_SUBMIT_RSP: case TDMT_VND_DELETE_RSP: + case TDMT_VND_COMMIT_RSP: break; default: SCH_TASK_ELOG("unknown rsp msg, type:%s, status:%s", TMSG_INFO(msgType), jobTaskStatusStr(taskStatus)); @@ -76,23 +76,40 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) { + if (taskStatus != JOB_TASK_STATUS_EXEC && taskStatus != JOB_TASK_STATUS_PART_SUCC) { SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - //SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); + // SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); return TSDB_CODE_SUCCESS; } // Note: no more task error processing, handled in function internal -int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, char *msg, int32_t msgSize, - int32_t rspCode) { +int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; + char *msg = pMsg->pData; + int32_t msgSize = pMsg->len; + int32_t msgType = pMsg->msgType; + + bool dropExecNode = (msgType == TDMT_SCH_LINK_BROKEN || SCH_NETWORK_ERR(rspCode)); + SCH_ERR_JRET(schUpdateTaskHandle(pJob, pTask, dropExecNode, pMsg->handle, execId)); + + SCH_ERR_JRET(schValidateReceivedMsgType(pJob, pTask, msgType)); + + int32_t reqType = IsReq(pMsg) ? pMsg->msgType : (pMsg->msgType - 1); + if (SCH_NEED_REDIRECT(reqType, rspCode, pMsg->len)) { + SCH_RET(schHandleRedirect(pJob, pTask, (SDataBuf *)pMsg, rspCode)); + } switch (msgType) { + case TDMT_VND_COMMIT_RSP: { + SCH_ERR_JRET(rspCode); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + break; + } case TDMT_VND_CREATE_TABLE_RSP: { SVCreateTbBatchRsp batchRsp = {0}; if (msg) { @@ -114,8 +131,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch } SCH_ERR_JRET(rspCode); - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -140,8 +157,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch } SCH_ERR_JRET(rspCode); - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -154,7 +171,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch tDecoderClear(&coder); SCH_ERR_JRET(code); SCH_ERR_JRET(rsp.code); - + pJob->execRes.res = rsp.pMeta; pJob->execRes.msgType = TDMT_VND_ALTER_TABLE; } @@ -165,8 +182,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -214,7 +231,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_UNLOCK(SCH_WRITE, &pJob->resLock); } - taosMemoryFreeClear(msg); + taosMemoryFreeClear(msg); SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); @@ -224,7 +241,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_ERR_JRET(rspCode); if (msg) { - SDecoder coder = {0}; + SDecoder coder = {0}; SVDeleteRsp rsp = {0}; tDecoderInit(&coder, msg, msgSize); tDecodeSVDeleteRsp(&coder, &rsp); @@ -238,7 +255,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; - } + } case TDMT_SCH_QUERY_RSP: case TDMT_SCH_MERGE_QUERY_RSP: { SQueryTableRsp *rsp = (SQueryTableRsp *)msg; @@ -251,8 +268,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_ERR_JRET(schSaveJobQueryRes(pJob, rsp)); - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; @@ -303,14 +320,14 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_ERR_JRET(schProcessOnExplainDone(pJob, pTask, pRsp)); } - taosMemoryFreeClear(msg); + taosMemoryFreeClear(msg); return TSDB_CODE_SUCCESS; } - SCH_ERR_JRET(schFetchFromRemote(pJob)); + SCH_ERR_JRET(schLaunchFetchTask(pJob)); - taosMemoryFreeClear(msg); + taosMemoryFreeClear(msg); return TSDB_CODE_SUCCESS; } @@ -325,12 +342,12 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch atomic_add_fetch_32(&pJob->resNumOfRows, htonl(rsp->numOfRows)); if (rsp->completed) { - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_SUCCEED); + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_SUCC); } SCH_TASK_DLOG("got fetch rsp, rows:%d, complete:%d", htonl(rsp->numOfRows), rsp->completed); - msg = NULL; + msg = NULL; schProcessOnDataFetched(pJob); break; @@ -359,74 +376,33 @@ _return: SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); } - int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; - int32_t msgType = pMsg->msgType; SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; SSchTask *pTask = NULL; + SSchJob *pJob = NULL; - SSchJob *pJob = schAcquireJob(pParam->refId); - if (NULL == pJob) { - qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "taosAcquireRef job failed, may be dropped, refId:0x%" PRIx64, - pParam->queryId, pParam->taskId, pParam->refId); - SCH_ERR_JRET(TSDB_CODE_QRY_JOB_FREED); - } - - SCH_ERR_JRET(schGetTaskInJob(pJob, pParam->taskId, &pTask)); + qDebug("begin to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, tstrerror(rspCode)); - SCH_LOCK_TASK(pTask); - - SCH_TASK_DLOG("rsp msg received, type:%s, handle:%p, code:%s", TMSG_INFO(msgType), pMsg->handle, tstrerror(rspCode)); - - if (pParam->execId != pTask->execId) { - SCH_TASK_DLOG("execId %d mis-match current execId %d", pParam->execId, pTask->execId); - goto _return; - } - - bool dropExecNode = (msgType == TDMT_SCH_LINK_BROKEN || SCH_NETWORK_ERR(rspCode)); - SCH_ERR_JRET(schUpdateTaskHandle(pJob, pTask, dropExecNode, pMsg->handle, pParam->execId)); + SCH_ERR_RET(schProcessOnCbBegin(&pJob, &pTask, pParam->queryId, pParam->refId, pParam->taskId)); - int8_t status = 0; - if (schJobNeedToStop(pJob, &status)) { - SCH_TASK_ELOG("rsp will not be processed cause of job status %s, rspCode:0x%x", jobTaskStatusStr(status), rspCode); - code = atomic_load_32(&pJob->errCode); - goto _return; - } - - SCH_ERR_JRET(schValidateReceivedMsgType(pJob, pTask, msgType)); - - int32_t reqType = IsReq(pMsg) ? pMsg->msgType : (pMsg->msgType - 1); - if (SCH_NEED_REDIRECT(reqType, rspCode, pMsg->len)) { - code = schHandleRedirect(pJob, pTask, (SDataBuf *)pMsg, rspCode); - goto _return; - } - - schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode); + code = schHandleResponseMsg(pJob, pTask, pParam->execId, pMsg, rspCode); pMsg->pData = NULL; -_return: - - if (pTask) { - if (code) { - schProcessOnTaskFailure(pJob, pTask, code); - } - - SCH_UNLOCK_TASK(pTask); - } - - if (pJob) { - schReleaseJob(pParam->refId); - } + schProcessOnCbEnd(pJob, pTask, code); taosMemoryFreeClear(pMsg->pData); taosMemoryFreeClear(param); + + qDebug("end to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, tstrerror(rspCode)); + SCH_RET(code); } int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) { SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " drop task rsp received, code:0x%x", pParam->queryId, pParam->taskId, code); + qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " drop task rsp received, code:0x%x", pParam->queryId, pParam->taskId, + code); taosMemoryFreeClear(param); return TSDB_CODE_SUCCESS; } @@ -450,6 +426,40 @@ int32_t schHandleLinkBrokenCallback(void *param, SDataBuf *pMsg, int32_t code) { return TSDB_CODE_SUCCESS; } +int32_t schHandleCommitCallback(void *param, SDataBuf *pMsg, int32_t code) { + return schHandleCallback(param, pMsg, code); +} + +int32_t schHandleHbCallback(void *param, SDataBuf *pMsg, int32_t code) { + SSchedulerHbRsp rsp = {0}; + SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; + + if (code) { + qError("hb rsp error:%s", tstrerror(code)); + SCH_ERR_JRET(code); + } + + if (tDeserializeSSchedulerHbRsp(pMsg->pData, pMsg->len, &rsp)) { + qError("invalid hb rsp msg, size:%d", pMsg->len); + SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } + + SSchTrans trans = {0}; + trans.pTrans = pParam->pTrans; + trans.pHandle = pMsg->handle; + + SCH_ERR_JRET(schUpdateHbConnection(&rsp.epId, &trans)); + + SCH_ERR_JRET(schProcessOnTaskStatusRsp(&rsp.epId, rsp.taskStatus)); + +_return: + + tFreeSSchedulerHbRsp(&rsp); + taosMemoryFree(param); + + SCH_RET(code); +} + int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bool isHb, SSchTrans *trans, void **pParam) { if (!isHb) { @@ -458,7 +468,7 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchTaskCallbackParam)); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - + param->queryId = pJob->queryId; param->refId = pJob->refId; param->taskId = SCH_TASK_ID(pTask); @@ -475,19 +485,19 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchHbCallbackParam)); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - + param->head.isHbParam = true; - + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); param->nodeEpId.nodeId = addr->nodeId; - SEp* pEp = SCH_GET_CUR_EP(addr); + SEp *pEp = SCH_GET_CUR_EP(addr); strcpy(param->nodeEpId.ep.fqdn, pEp->fqdn); param->nodeEpId.ep.port = pEp->port; param->pTrans = trans->pTrans; *pParam = param; return TSDB_CODE_SUCCESS; - } + } // hb msg SSchTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam)); @@ -495,14 +505,15 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo qError("calloc SSchTaskCallbackParam failed"); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - + param->pTrans = trans->pTrans; *pParam = param; return TSDB_CODE_SUCCESS; } -int32_t schGenerateCallBackInfo(SSchJob *pJob, SSchTask *pTask, void* msg, uint32_t msgSize, int32_t msgType, SSchTrans *trans, bool isHb, SMsgSendInfo **pMsgSendInfo) { +int32_t schGenerateCallBackInfo(SSchJob *pJob, SSchTask *pTask, void *msg, uint32_t msgSize, int32_t msgType, + SSchTrans *trans, bool isHb, SMsgSendInfo **pMsgSendInfo) { int32_t code = 0; SMsgSendInfo *msgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == msgSendInfo) { @@ -517,7 +528,7 @@ int32_t schGenerateCallBackInfo(SSchJob *pJob, SSchTask *pTask, void* msg, uint3 msgSendInfo->requestId = pJob->conn.requestId; msgSendInfo->requestObjRefId = pJob->conn.requestObjRefId; } - + if (TDMT_SCH_LINK_BROKEN != msgType) { msgSendInfo->msgInfo.pData = msg; msgSendInfo->msgInfo.len = msgSize; @@ -536,7 +547,6 @@ _return: SCH_RET(code); } - int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { switch (msgType) { case TDMT_VND_CREATE_TABLE: @@ -556,6 +566,9 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { case TDMT_SCH_QUERY_HEARTBEAT: *fp = schHandleHbCallback; break; + case TDMT_VND_COMMIT: + *fp = schHandleCommitCallback; + break; case TDMT_SCH_LINK_BROKEN: *fp = schHandleLinkBrokenCallback; break; @@ -633,7 +646,6 @@ _return: SCH_RET(code); } - int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { int32_t code = 0; SSchHbCallbackParam *param = NULL; @@ -692,40 +704,10 @@ _return: SCH_RET(code); } -int32_t schHandleHbCallback(void *param, SDataBuf *pMsg, int32_t code) { - SSchedulerHbRsp rsp = {0}; - SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; - - if (code) { - qError("hb rsp error:%s", tstrerror(code)); - SCH_ERR_JRET(code); - } - - if (tDeserializeSSchedulerHbRsp(pMsg->pData, pMsg->len, &rsp)) { - qError("invalid hb rsp msg, size:%d", pMsg->len); - SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); - } - - SSchTrans trans = {0}; - trans.pTrans = pParam->pTrans; - trans.pHandle = pMsg->handle; - - SCH_ERR_JRET(schUpdateHbConnection(&rsp.epId, &trans)); - - SCH_ERR_JRET(schProcessOnTaskStatusRsp(&rsp.epId, rsp.taskStatus)); - -_return: - - tFreeSSchedulerHbRsp(&rsp); - taosMemoryFree(param); - - SCH_RET(code); -} - int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb) { - int32_t code = 0; - int32_t msgType = TDMT_SCH_LINK_BROKEN; - SSchTrans trans = {.pTrans = pJob->conn.pTrans}; + int32_t code = 0; + int32_t msgType = TDMT_SCH_LINK_BROKEN; + SSchTrans trans = {.pTrans = pJob->conn.pTrans}; SMsgSendInfo *pMsgSendInfo = NULL; SCH_ERR_JRET(schGenerateCallBackInfo(pJob, pTask, NULL, 0, msgType, &trans, isHb, &pMsgSendInfo)); @@ -846,19 +828,18 @@ int32_t schUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, SQueryNodeAddr *addr return TSDB_CODE_SUCCESS; } -int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, SSchTrans *trans, SQueryNodeAddr *addr, int32_t msgType, void *msg, - uint32_t msgSize, bool persistHandle, SRpcCtx *ctx) { +int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, SSchTrans *trans, SQueryNodeAddr *addr, int32_t msgType, + void *msg, uint32_t msgSize, bool persistHandle, SRpcCtx *ctx) { int32_t code = 0; SEpSet *epSet = &addr->epSet; SMsgSendInfo *pMsgSendInfo = NULL; - bool isHb = (TDMT_SCH_QUERY_HEARTBEAT == msgType); + bool isHb = (TDMT_SCH_QUERY_HEARTBEAT == msgType); SCH_ERR_JRET(schGenerateCallBackInfo(pJob, pTask, msg, msgSize, msgType, trans, isHb, &pMsgSendInfo)); - SCH_ERR_JRET(schUpdateSendTargetInfo(pMsgSendInfo, addr, pTask)); + SCH_ERR_JRET(schUpdateSendTargetInfo(pMsgSendInfo, addr, pTask)); - qDebug("start to send %s msg to node[%d,%s,%d], pTrans:%p, pHandle:%p", TMSG_INFO(msgType), - addr->nodeId, epSet->eps[epSet->inUse].fqdn, epSet->eps[epSet->inUse].port, - trans->pTrans, trans->pHandle); + qDebug("start to send %s msg to node[%d,%s,%d], pTrans:%p, pHandle:%p", TMSG_INFO(msgType), addr->nodeId, + epSet->eps[epSet->inUse].fqdn, epSet->eps[epSet->inUse].port, trans->pTrans, trans->pHandle); if (pTask) { pTask->lastMsgType = msgType; @@ -893,8 +874,7 @@ _return: SCH_RET(code); } - -int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray* taskAction) { +int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray *taskAction) { SSchedulerHbReq req = {0}; int32_t code = 0; SRpcCtx rpcCtx = {0}; @@ -938,7 +918,7 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray* taskAction) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - int64_t transporterId = 0; + int64_t transporterId = 0; SQueryNodeAddr addr = {.nodeId = nodeEpId->nodeId}; addr.epSet.inUse = 0; addr.epSet.numOfEps = 1; @@ -973,7 +953,8 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, case TDMT_VND_CREATE_TABLE: case TDMT_VND_DROP_TABLE: case TDMT_VND_ALTER_TABLE: - case TDMT_VND_SUBMIT: { + case TDMT_VND_SUBMIT: + case TDMT_VND_COMMIT: { msgSize = pTask->msgLen; msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { @@ -993,7 +974,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, req.taskId = pTask->taskId; req.phyLen = pTask->msgLen; req.sqlLen = strlen(pJob->sql); - req.sql = (char*)pJob->sql; + req.sql = (char *)pJob->sql; req.msg = pTask->msg; msgSize = tSerializeSVDeleteReq(NULL, 0, &req); msg = taosMemoryCalloc(1, msgSize); @@ -1005,7 +986,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, tSerializeSVDeleteReq(msg, msgSize, &req); break; } - case TDMT_SCH_QUERY: + case TDMT_SCH_QUERY: case TDMT_SCH_MERGE_QUERY: { SCH_ERR_RET(schMakeQueryRpcCtx(pJob, pTask, &rpcCtx)); @@ -1107,8 +1088,8 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, } SSchTrans trans = {.pTrans = pJob->conn.pTrans, .pHandle = SCH_GET_TASK_HANDLE(pTask)}; - SCH_ERR_JRET(schAsyncSendMsg(pJob, pTask, &trans, addr, msgType, msg, msgSize, persistHandle, - (rpcCtx.args ? &rpcCtx : NULL))); + SCH_ERR_JRET( + schAsyncSendMsg(pJob, pTask, &trans, addr, msgType, msg, msgSize, persistHandle, (rpcCtx.args ? &rpcCtx : NULL))); if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY) { SCH_ERR_RET(schAppendTaskExecNode(pJob, pTask, addr, pTask->execId)); @@ -1124,6 +1105,3 @@ _return: taosMemoryFreeClear(msg); SCH_RET(code); } - - - diff --git a/source/libs/scheduler/src/schStatus.c b/source/libs/scheduler/src/schStatus.c new file mode 100644 index 0000000000000000000000000000000000000000..091b1359e0f447813648720f482df31b6fe5290e --- /dev/null +++ b/source/libs/scheduler/src/schStatus.c @@ -0,0 +1,94 @@ +/* + * 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 . + */ + +#include "catalog.h" +#include "command.h" +#include "query.h" +#include "schInt.h" +#include "tmsg.h" +#include "tref.h" +#include "trpc.h" + +int32_t schSwitchJobStatus(SSchJob* pJob, int32_t status, void* param) { + int32_t code = 0; + SCH_ERR_JRET(schUpdateJobStatus(pJob, status)); + + switch (status) { + case JOB_TASK_STATUS_INIT: + break; + case JOB_TASK_STATUS_EXEC: + SCH_ERR_JRET(schExecJob(pJob, (SSchedulerReq*)param)); + break; + case JOB_TASK_STATUS_PART_SUCC: + SCH_ERR_JRET(schProcessOnJobPartialSuccess(pJob)); + break; + case JOB_TASK_STATUS_SUCC: + break; + case JOB_TASK_STATUS_FAIL: + SCH_RET(schProcessOnJobFailure(pJob, (param ? *(int32_t*)param : 0))); + break; + case JOB_TASK_STATUS_DROP: + schProcessOnJobDropped(pJob, *(int32_t*)param); + + if (taosRemoveRef(schMgmt.jobRef, pJob->refId)) { + SCH_JOB_ELOG("remove job from job list failed, refId:0x%" PRIx64, pJob->refId); + } else { + SCH_JOB_DLOG("job removed from jobRef list, refId:0x%" PRIx64, pJob->refId); + } + break; + default: { + SCH_JOB_ELOG("unknown job status %d", status); + SCH_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + } + + return TSDB_CODE_SUCCESS; + +_return: + + SCH_RET(schProcessOnJobFailure(pJob, code)); +} + +int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SSchedulerReq* pReq) { + SSchJob *pJob = schAcquireJob(jobId); + if (NULL == pJob) { + qError("Acquire sch job failed, may be dropped, jobId:0x%" PRIx64, jobId); + SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + + *job = pJob; + + SCH_RET(schProcessOnOpBegin(pJob, type, pReq)); +} + +int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode) { + int32_t code = errCode; + + if (NULL == pJob) { + SCH_RET(code); + } + + schProcessOnOpEnd(pJob, type, pReq, errCode); + + if (TSDB_CODE_SCH_IGNORE_ERROR == errCode) { + code = pJob->errCode; + } + + schReleaseJob(pJob->refId); + + return code; +} + + diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c new file mode 100644 index 0000000000000000000000000000000000000000..e60006d75c4eb5a8d8b3b2f63182f74485c07e6a --- /dev/null +++ b/source/libs/scheduler/src/schTask.c @@ -0,0 +1,830 @@ +/* + * 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 . + */ + +#include "catalog.h" +#include "command.h" +#include "query.h" +#include "schInt.h" +#include "tmsg.h" +#include "tref.h" +#include "trpc.h" + + + +void schFreeTask(SSchJob *pJob, SSchTask *pTask) { + schDeregisterTaskHb(pJob, pTask); + + if (pTask->candidateAddrs) { + taosArrayDestroy(pTask->candidateAddrs); + } + + taosMemoryFreeClear(pTask->msg); + + if (pTask->children) { + taosArrayDestroy(pTask->children); + } + + if (pTask->parents) { + taosArrayDestroy(pTask->parents); + } + + if (pTask->execNodes) { + taosHashCleanup(pTask->execNodes); + } +} + + +int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel) { + pTask->plan = pPlan; + pTask->level = pLevel; + pTask->execId = -1; + pTask->maxExecTimes = SCH_TASK_MAX_EXEC_TIMES; + pTask->timeoutUsec = SCH_DEFAULT_TASK_TIMEOUT_USEC; + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); + pTask->taskId = schGenTaskId(); + pTask->execNodes = taosHashInit(SCH_MAX_CANDIDATE_EP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + if (NULL == pTask->execNodes) { + SCH_TASK_ELOG("taosHashInit %d execNodes failed", SCH_MAX_CANDIDATE_EP_NUM); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t schRecordTaskSucceedNode(SSchJob *pJob, SSchTask *pTask) { + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); + if (NULL == addr) { + SCH_TASK_ELOG("taosArrayGet candidate addr failed, idx:%d, size:%d", pTask->candidateIdx, + (int32_t)taosArrayGetSize(pTask->candidateAddrs)); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + + pTask->succeedAddr = *addr; + + return TSDB_CODE_SUCCESS; +} + +int32_t schAppendTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t execId) { + SSchNodeInfo nodeInfo = {.addr = *addr, .handle = NULL}; + + if (taosHashPut(pTask->execNodes, &execId, sizeof(execId), &nodeInfo, sizeof(nodeInfo))) { + SCH_TASK_ELOG("taosHashPut nodeInfo to execNodes failed, errno:%d", errno); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SCH_TASK_DLOG("task execNode added, execId:%d", execId); + + return TSDB_CODE_SUCCESS; +} + +int32_t schDropTaskExecNode(SSchJob *pJob, SSchTask *pTask, void *handle, int32_t execId) { + if (NULL == pTask->execNodes) { + return TSDB_CODE_SUCCESS; + } + + if (taosHashRemove(pTask->execNodes, &execId, sizeof(execId))) { + SCH_TASK_ELOG("fail to remove execId %d from execNodeList", execId); + } else { + SCH_TASK_DLOG("execId %d removed from execNodeList", execId); + } + + if (execId != pTask->execId) { // ignore it + SCH_TASK_DLOG("execId %d is not current execId %d", execId, pTask->execId); + SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t schUpdateTaskExecNode(SSchJob *pJob, SSchTask *pTask, void *handle, int32_t execId) { + if (taosHashGetSize(pTask->execNodes) <= 0) { + return TSDB_CODE_SUCCESS; + } + + SSchNodeInfo *nodeInfo = taosHashGet(pTask->execNodes, &execId, sizeof(execId)); + nodeInfo->handle = handle; + + SCH_TASK_DLOG("handle updated to %p for execId %d", handle, execId); + + return TSDB_CODE_SUCCESS; +} + +int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, void *handle, int32_t execId) { + if (dropExecNode) { + SCH_RET(schDropTaskExecNode(pJob, pTask, handle, execId)); + } + + SCH_SET_TASK_HANDLE(pTask, handle); + + schUpdateTaskExecNode(pJob, pTask, handle, execId); + + return TSDB_CODE_SUCCESS; +} + +// Note: no more task error processing, handled in function internal +int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode) { + if (TSDB_CODE_SCH_IGNORE_ERROR == errCode) { + return TSDB_CODE_SCH_IGNORE_ERROR; + } + + int8_t status = 0; + if (schJobNeedToStop(pJob, &status)) { + SCH_TASK_DLOG("no more task failure processing cause of job status %s", jobTaskStatusStr(status)); + SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); + } + + if (SCH_GET_TASK_STATUS(pTask) != JOB_TASK_STATUS_EXEC) { + SCH_TASK_ELOG("task already not in EXEC status, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + + if (errCode == TSDB_CODE_SCH_TIMEOUT_ERROR) { + SCH_LOG_TASK_WAIT_TS(pTask); + } else { + SCH_LOG_TASK_END_TS(pTask); + } + + bool needRetry = false; + bool moved = false; + int32_t taskDone = 0; + + SCH_TASK_DLOG("taskOnFailure, code:%s", tstrerror(errCode)); + + SCH_ERR_RET(schTaskCheckSetRetry(pJob, pTask, errCode, &needRetry)); + + if (!needRetry) { + SCH_TASK_ELOG("task failed and no more retry, code:%s", tstrerror(errCode)); + + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_FAIL); + + if (SCH_JOB_NEED_WAIT(pJob)) { + SCH_LOCK(SCH_WRITE, &pTask->level->lock); + pTask->level->taskFailed++; + taskDone = pTask->level->taskSucceed + pTask->level->taskFailed; + SCH_UNLOCK(SCH_WRITE, &pTask->level->lock); + + schUpdateJobErrCode(pJob, errCode); + + if (taskDone < pTask->level->taskNum) { + SCH_TASK_DLOG("need to wait other tasks, doneNum:%d, allNum:%d", taskDone, pTask->level->taskNum); + SCH_RET(TSDB_CODE_SCH_IGNORE_ERROR); + } + + SCH_RET(atomic_load_32(&pJob->errCode)); + } + } else { + SCH_ERR_RET(schHandleTaskRetry(pJob, pTask)); + + return TSDB_CODE_SUCCESS; + } + + SCH_RET(errCode); +} + + + +// Note: no more task error processing, handled in function internal +int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { + bool moved = false; + int32_t code = 0; + + SCH_TASK_DLOG("taskOnSuccess, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + + SCH_LOG_TASK_END_TS(pTask); + + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_PART_SUCC); + + SCH_ERR_RET(schRecordTaskSucceedNode(pJob, pTask)); + + SCH_ERR_RET(schLaunchTasksInFlowCtrlList(pJob, pTask)); + + int32_t parentNum = pTask->parents ? (int32_t)taosArrayGetSize(pTask->parents) : 0; + if (parentNum == 0) { + int32_t taskDone = 0; + if (SCH_JOB_NEED_WAIT(pJob)) { + SCH_LOCK(SCH_WRITE, &pTask->level->lock); + pTask->level->taskSucceed++; + taskDone = pTask->level->taskSucceed + pTask->level->taskFailed; + SCH_UNLOCK(SCH_WRITE, &pTask->level->lock); + + if (taskDone < pTask->level->taskNum) { + SCH_TASK_DLOG("wait all tasks, done:%d, all:%d", taskDone, pTask->level->taskNum); + return TSDB_CODE_SUCCESS; + } else if (taskDone > pTask->level->taskNum) { + SCH_TASK_ELOG("taskDone number invalid, done:%d, total:%d", taskDone, pTask->level->taskNum); + } + + if (pTask->level->taskFailed > 0) { + SCH_RET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_FAIL, NULL)); + } else { + SCH_RET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_PART_SUCC, NULL)); + } + } else { + pJob->resNode = pTask->succeedAddr; + } + + pJob->fetchTask = pTask; + + SCH_RET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_PART_SUCC, NULL)); + } + + /* + if (SCH_IS_DATA_SRC_TASK(task) && job->dataSrcEps.numOfEps < SCH_MAX_CANDIDATE_EP_NUM) { + strncpy(job->dataSrcEps.fqdn[job->dataSrcEps.numOfEps], task->execAddr.fqdn, sizeof(task->execAddr.fqdn)); + job->dataSrcEps.port[job->dataSrcEps.numOfEps] = task->execAddr.port; + + ++job->dataSrcEps.numOfEps; + } + */ + + for (int32_t i = 0; i < parentNum; ++i) { + SSchTask *parent = *(SSchTask **)taosArrayGet(pTask->parents, i); + int32_t readyNum = atomic_add_fetch_32(&parent->childReady, 1); + + SCH_LOCK(SCH_WRITE, &parent->lock); + SDownstreamSourceNode source = {.type = QUERY_NODE_DOWNSTREAM_SOURCE, + .taskId = pTask->taskId, + .schedId = schMgmt.sId, + .execId = pTask->execId, + .addr = pTask->succeedAddr}; + qSetSubplanExecutionNode(parent->plan, pTask->plan->id.groupId, &source); + SCH_UNLOCK(SCH_WRITE, &parent->lock); + + if (SCH_TASK_READY_FOR_LAUNCH(readyNum, parent)) { + SCH_TASK_DLOG("all %d children task done, start to launch parent task 0x%" PRIx64, readyNum, parent->taskId); + SCH_ERR_RET(schLaunchTask(pJob, parent)); + } + } + + SCH_ERR_RET(schLaunchJobLowerLevel(pJob, pTask)); + + return TSDB_CODE_SUCCESS; +} + +int32_t schRescheduleTask(SSchJob *pJob, SSchTask *pTask) { + if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { + return TSDB_CODE_SUCCESS; + } + + if (SCH_TASK_TIMEOUT(pTask) && JOB_TASK_STATUS_EXEC == pTask->status && + pJob->fetchTask != pTask && taosArrayGetSize(pTask->candidateAddrs) > 1) { + SCH_TASK_DLOG("task execId %d will be rescheduled now", pTask->execId); + schDropTaskOnExecNode(pJob, pTask); + taosHashClear(pTask->execNodes); + + SCH_ERR_RET(schProcessOnTaskFailure(pJob, pTask, TSDB_CODE_SCH_TIMEOUT_ERROR)); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) { + int32_t code = 0; + + if ((pTask->execId + 1) >= pTask->maxExecTimes) { + SCH_TASK_DLOG("task no more retry since reach max try times, execId:%d", pTask->execId); + schSwitchJobStatus(pJob, JOB_TASK_STATUS_FAIL, (void*)&rspCode); + return TSDB_CODE_SUCCESS; + } + + SCH_TASK_DLOG("task will be redirected now, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + + schDropTaskOnExecNode(pJob, pTask); + taosHashClear(pTask->execNodes); + SCH_ERR_JRET(schRemoveTaskFromExecList(pJob, pTask)); + schDeregisterTaskHb(pJob, pTask); + atomic_sub_fetch_32(&pTask->level->taskLaunchedNum, 1); + taosMemoryFreeClear(pTask->msg); + pTask->msgLen = 0; + pTask->lastMsgType = 0; + memset(&pTask->succeedAddr, 0, sizeof(pTask->succeedAddr)); + + if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { + if (pData) { + SCH_ERR_JRET(schUpdateTaskCandidateAddr(pJob, pTask, pData->pEpSet)); + } + + if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { + if (JOB_TASK_STATUS_EXEC == SCH_GET_TASK_STATUS(pTask)) { + SCH_ERR_JRET(schLaunchTasksInFlowCtrlList(pJob, pTask)); + } + } + + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); + + SCH_ERR_JRET(schLaunchTask(pJob, pTask)); + + return TSDB_CODE_SUCCESS; + } + + + // merge plan + + pTask->childReady = 0; + + qClearSubplanExecutionNode(pTask->plan); + + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); + + int32_t childrenNum = taosArrayGetSize(pTask->children); + for (int32_t i = 0; i < childrenNum; ++i) { + SSchTask* pChild = taosArrayGetP(pTask->children, i); + SCH_LOCK_TASK(pChild); + schDoTaskRedirect(pJob, pChild, NULL, rspCode); + SCH_UNLOCK_TASK(pChild); + } + + return TSDB_CODE_SUCCESS; + +_return: + + SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); +} + +int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) { + int32_t code = 0; + + if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { + if (NULL == pData->pEpSet) { + SCH_TASK_ELOG("no epset updated while got error %s", tstrerror(rspCode)); + SCH_ERR_JRET(rspCode); + } + } + + SCH_RET(schDoTaskRedirect(pJob, pTask, pData, rspCode)); + +_return: + + SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); +} + +int32_t schPushTaskToExecList(SSchJob *pJob, SSchTask *pTask) { + int32_t code = taosHashPut(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); + if (0 != code) { + if (HASH_NODE_EXIST(code)) { + SCH_TASK_ELOG("task already in execTask list, code:%x", code); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + + SCH_TASK_ELOG("taosHashPut task to execTask list failed, errno:%d", errno); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SCH_TASK_DLOG("task added to execTask list, numOfTasks:%d", taosHashGetSize(pJob->execTasks)); + + return TSDB_CODE_SUCCESS; +} + +/* +int32_t schMoveTaskToSuccList(SSchJob *pJob, SSchTask *pTask, bool *moved) { + if (0 != taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId))) { + SCH_TASK_WLOG("remove task from execTask list failed, may not exist, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + } else { + SCH_TASK_DLOG("task removed from execTask list, numOfTasks:%d", taosHashGetSize(pJob->execTasks)); + } + + int32_t code = taosHashPut(pJob->succTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); + if (0 != code) { + if (HASH_NODE_EXIST(code)) { + *moved = true; + SCH_TASK_ELOG("task already in succTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + + SCH_TASK_ELOG("taosHashPut task to succTask list failed, errno:%d", errno); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + *moved = true; + + SCH_TASK_DLOG("task moved to succTask list, numOfTasks:%d", taosHashGetSize(pJob->succTasks)); + + return TSDB_CODE_SUCCESS; +} + +int32_t schMoveTaskToFailList(SSchJob *pJob, SSchTask *pTask, bool *moved) { + *moved = false; + + if (0 != taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId))) { + SCH_TASK_WLOG("remove task from execTask list failed, may not exist, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + } + + int32_t code = taosHashPut(pJob->failTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); + if (0 != code) { + if (HASH_NODE_EXIST(code)) { + *moved = true; + + SCH_TASK_WLOG("task already in failTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + + SCH_TASK_ELOG("taosHashPut task to failTask list failed, errno:%d", errno); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + *moved = true; + + SCH_TASK_DLOG("task moved to failTask list, numOfTasks:%d", taosHashGetSize(pJob->failTasks)); + + return TSDB_CODE_SUCCESS; +} + +int32_t schMoveTaskToExecList(SSchJob *pJob, SSchTask *pTask, bool *moved) { + if (0 != taosHashRemove(pJob->succTasks, &pTask->taskId, sizeof(pTask->taskId))) { + SCH_TASK_WLOG("remove task from succTask list failed, may not exist, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + } + + int32_t code = taosHashPut(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES); + if (0 != code) { + if (HASH_NODE_EXIST(code)) { + *moved = true; + + SCH_TASK_ELOG("task already in execTask list, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + } + + SCH_TASK_ELOG("taosHashPut task to execTask list failed, errno:%d", errno); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + *moved = true; + + SCH_TASK_DLOG("task moved to execTask list, numOfTasks:%d", taosHashGetSize(pJob->execTasks)); + + return TSDB_CODE_SUCCESS; +} +*/ + +int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry) { + if (TSDB_CODE_SCH_TIMEOUT_ERROR == errCode) { + pTask->maxExecTimes++; + if (pTask->timeoutUsec < SCH_MAX_TASK_TIMEOUT_USEC) { + pTask->timeoutUsec *= 2; + if (pTask->timeoutUsec > SCH_MAX_TASK_TIMEOUT_USEC) { + pTask->timeoutUsec = SCH_MAX_TASK_TIMEOUT_USEC; + } + } + } + + if ((pTask->execId + 1) >= pTask->maxExecTimes) { + *needRetry = false; + SCH_TASK_DLOG("task no more retry since reach max try times, execId:%d", pTask->execId); + return TSDB_CODE_SUCCESS; + } + + if (!SCH_NEED_RETRY(pTask->lastMsgType, errCode)) { + *needRetry = false; + SCH_TASK_DLOG("task no more retry cause of errCode, errCode:%x - %s", errCode, tstrerror(errCode)); + return TSDB_CODE_SUCCESS; + } + + if (SCH_IS_DATA_SRC_TASK(pTask)) { + if ((pTask->execId + 1) >= SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)) { + *needRetry = false; + SCH_TASK_DLOG("task no more retry since all ep tried, execId:%d, epNum:%d", pTask->execId, + SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)); + return TSDB_CODE_SUCCESS; + } + } else { + int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); + + if ((pTask->candidateIdx + 1) >= candidateNum && (TSDB_CODE_SCH_TIMEOUT_ERROR != errCode)) { + *needRetry = false; + SCH_TASK_DLOG("task no more retry since all candiates tried, candidateIdx:%d, candidateNum:%d", + pTask->candidateIdx, candidateNum); + return TSDB_CODE_SUCCESS; + } + } + + *needRetry = true; + SCH_TASK_DLOG("task need the %dth retry, errCode:%x - %s", pTask->execId + 1, errCode, tstrerror(errCode)); + + return TSDB_CODE_SUCCESS; +} + +int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) { + atomic_sub_fetch_32(&pTask->level->taskLaunchedNum, 1); + + SCH_ERR_RET(schRemoveTaskFromExecList(pJob, pTask)); + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); + + if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { + SCH_ERR_RET(schLaunchTasksInFlowCtrlList(pJob, pTask)); + } + + schDeregisterTaskHb(pJob, pTask); + + if (SCH_IS_DATA_SRC_TASK(pTask)) { + SCH_SWITCH_EPSET(&pTask->plan->execNode); + } else { + int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); + if (++pTask->candidateIdx >= candidateNum) { + pTask->candidateIdx = 0; + } + } + + SCH_ERR_RET(schLaunchTask(pJob, pTask)); + + return TSDB_CODE_SUCCESS; +} + +int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { + int32_t addNum = 0; + int32_t nodeNum = 0; + + if (pJob->nodeList) { + nodeNum = taosArrayGetSize(pJob->nodeList); + + for (int32_t i = 0; i < nodeNum && addNum < SCH_MAX_CANDIDATE_EP_NUM; ++i) { + SQueryNodeLoad *nload = taosArrayGet(pJob->nodeList, i); + SQueryNodeAddr *naddr = &nload->addr; + + if (NULL == taosArrayPush(pTask->candidateAddrs, naddr)) { + SCH_TASK_ELOG("taosArrayPush execNode to candidate addrs failed, addNum:%d, errno:%d", addNum, errno); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SCH_TASK_DLOG("set %dth candidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, SCH_GET_CUR_EP(naddr)->port); + + ++addNum; + } + } + + if (addNum <= 0) { + SCH_TASK_ELOG("no available execNode as candidates, nodeNum:%d", nodeNum); + SCH_ERR_RET(TSDB_CODE_TSC_NO_EXEC_NODE); + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) { + if (NULL != pTask->candidateAddrs) { + return TSDB_CODE_SUCCESS; + } + + pTask->candidateIdx = 0; + pTask->candidateAddrs = taosArrayInit(SCH_MAX_CANDIDATE_EP_NUM, sizeof(SQueryNodeAddr)); + if (NULL == pTask->candidateAddrs) { + SCH_TASK_ELOG("taosArrayInit %d condidate addrs failed", SCH_MAX_CANDIDATE_EP_NUM); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + if (pTask->plan->execNode.epSet.numOfEps > 0) { + if (NULL == taosArrayPush(pTask->candidateAddrs, &pTask->plan->execNode)) { + SCH_TASK_ELOG("taosArrayPush execNode to candidate addrs failed, errno:%d", errno); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SCH_TASK_DLOG("use execNode in plan as candidate addr, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps); + + return TSDB_CODE_SUCCESS; + } + + if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) { + SCH_TASK_ELOG("no execNode specifed for data src task, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps); + SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + SCH_ERR_RET(schSetAddrsFromNodeList(pJob, pTask)); + + /* + for (int32_t i = 0; i < job->dataSrcEps.numOfEps && addNum < SCH_MAX_CANDIDATE_EP_NUM; ++i) { + strncpy(epSet->fqdn[epSet->numOfEps], job->dataSrcEps.fqdn[i], sizeof(job->dataSrcEps.fqdn[i])); + epSet->port[epSet->numOfEps] = job->dataSrcEps.port[i]; + + ++epSet->numOfEps; + } + */ + + return TSDB_CODE_SUCCESS; +} + +int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSet) { + if (NULL == pTask->candidateAddrs || 1 != taosArrayGetSize(pTask->candidateAddrs)) { + SCH_TASK_ELOG("not able to update cndidate addr, addr num %d", (int32_t)(pTask->candidateAddrs ? taosArrayGetSize(pTask->candidateAddrs): 0)); + SCH_ERR_RET(TSDB_CODE_APP_ERROR); + } + + SQueryNodeAddr* pAddr = taosArrayGet(pTask->candidateAddrs, 0); + + SEp* pOld = &pAddr->epSet.eps[pAddr->epSet.inUse]; + SEp* pNew = &pEpSet->eps[pEpSet->inUse]; + + SCH_TASK_DLOG("update task ep from %s:%d to %s:%d", pOld->fqdn, pOld->port, pNew->fqdn, pNew->port); + + memcpy(&pAddr->epSet, pEpSet, sizeof(pAddr->epSet)); + + return TSDB_CODE_SUCCESS; +} + + +int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask) { + int32_t code = taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId)); + if (code) { + SCH_TASK_ELOG("task failed to rm from execTask list, code:%x", code); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + + return TSDB_CODE_SUCCESS; +} + +void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask) { + if (NULL == pTask->execNodes) { + SCH_TASK_DLOG("no exec address, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + return; + } + + int32_t size = (int32_t)taosHashGetSize(pTask->execNodes); + + if (size <= 0) { + SCH_TASK_DLOG("task has no execNodes, no need to drop it, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); + return; + } + + SSchNodeInfo *nodeInfo = taosHashIterate(pTask->execNodes, NULL); + while (nodeInfo) { + SCH_SET_TASK_HANDLE(pTask, nodeInfo->handle); + + schBuildAndSendMsg(pJob, pTask, &nodeInfo->addr, TDMT_SCH_DROP_TASK); + + nodeInfo = taosHashIterate(pTask->execNodes, nodeInfo); + } + + SCH_TASK_DLOG("task has been dropped on %d exec nodes", size); +} + + + +int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList) { + int32_t taskNum = (int32_t)taosArrayGetSize(pStatusList); + SSchTask *pTask = NULL; + SSchJob *pJob = NULL; + + qDebug("%d task status in hb rsp from nodeId:%d, fqdn:%s, port:%d", taskNum, pEpId->nodeId, pEpId->ep.fqdn, pEpId->ep.port); + + for (int32_t i = 0; i < taskNum; ++i) { + STaskStatus *pStatus = taosArrayGet(pStatusList, i); + int32_t code = 0; + + qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s", + pStatus->queryId, pStatus->taskId, pStatus->execId, jobTaskStatusStr(pStatus->status)); + + if (schProcessOnCbBegin(&pJob, &pTask, pStatus->queryId, pStatus->refId, pStatus->taskId)) { + continue; + } + + if (pStatus->execId != pTask->execId) { + //TODO + SCH_TASK_DLOG("execId %d mis-match current execId %d", pStatus->execId, pTask->execId); + schProcessOnCbEnd(pJob, pTask, 0); + continue; + } + + if (pStatus->status == JOB_TASK_STATUS_FAIL) { + // RECORD AND HANDLE ERROR!!!! + schProcessOnCbEnd(pJob, pTask, 0); + continue; + } + + if (pStatus->status == JOB_TASK_STATUS_INIT) { + code = schRescheduleTask(pJob, pTask); + } + + schProcessOnCbEnd(pJob, pTask, code); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask) { + int8_t status = 0; + int32_t code = 0; + + atomic_add_fetch_32(&pTask->level->taskLaunchedNum, 1); + pTask->execId++; + + SCH_TASK_DLOG("start to launch task's %dth exec", pTask->execId); + + SCH_LOG_TASK_START_TS(pTask); + + if (schJobNeedToStop(pJob, &status)) { + SCH_TASK_DLOG("no need to launch task cause of job status %s", jobTaskStatusStr(status)); + SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); + } + + // NOTE: race condition: the task should be put into the hash table before send msg to server + if (SCH_GET_TASK_STATUS(pTask) != JOB_TASK_STATUS_EXEC) { + SCH_ERR_RET(schPushTaskToExecList(pJob, pTask)); + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_EXEC); + } + + SSubplan *plan = pTask->plan; + + if (NULL == pTask->msg) { // TODO add more detailed reason for failure + code = qSubPlanToString(plan, &pTask->msg, &pTask->msgLen); + if (TSDB_CODE_SUCCESS != code) { + SCH_TASK_ELOG("failed to create physical plan, code:%s, msg:%p, len:%d", tstrerror(code), pTask->msg, + pTask->msgLen); + SCH_ERR_RET(code); + } else { + SCH_TASK_DLOGL("physical plan len:%d, %s", pTask->msgLen, pTask->msg); + } + } + + SCH_ERR_RET(schSetTaskCandidateAddrs(pJob, pTask)); + + if (SCH_IS_QUERY_JOB(pJob)) { + SCH_ERR_RET(schEnsureHbConnection(pJob, pTask)); + } + + SCH_ERR_RET(schBuildAndSendMsg(pJob, pTask, NULL, plan->msgType)); + + return TSDB_CODE_SUCCESS; +} + +// Note: no more error processing, handled in function internal +int32_t schLaunchTask(SSchJob *pJob, SSchTask *pTask) { + bool enough = false; + int32_t code = 0; + + SCH_SET_TASK_HANDLE(pTask, NULL); + + if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { + SCH_ERR_JRET(schCheckIncTaskFlowQuota(pJob, pTask, &enough)); + + if (enough) { + SCH_ERR_JRET(schLaunchTaskImpl(pJob, pTask)); + } + } else { + SCH_ERR_JRET(schLaunchTaskImpl(pJob, pTask)); + } + + return TSDB_CODE_SUCCESS; + +_return: + + SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); +} + +int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level) { + SCH_ERR_RET(schChkJobNeedFlowCtrl(pJob, level)); + + for (int32_t i = 0; i < level->taskNum; ++i) { + SSchTask *pTask = taosArrayGet(level->subTasks, i); + + SCH_ERR_RET(schLaunchTask(pJob, pTask)); + } + + return TSDB_CODE_SUCCESS; +} + +void schDropTaskInHashList(SSchJob *pJob, SHashObj *list) { + if (!SCH_JOB_NEED_DROP(pJob)) { + return; + } + + void *pIter = taosHashIterate(list, NULL); + while (pIter) { + SSchTask *pTask = *(SSchTask **)pIter; + + schDropTaskOnExecNode(pJob, pTask); + + pIter = taosHashIterate(list, pIter); + } +} + + +// Note: no more error processing, handled in function internal +int32_t schLaunchFetchTask(SSchJob *pJob) { + int32_t code = 0; + + void *resData = atomic_load_ptr(&pJob->resData); + if (resData) { + SCH_JOB_DLOG("res already fetched, res:%p", resData); + return TSDB_CODE_SUCCESS; + } + + SCH_ERR_JRET(schBuildAndSendMsg(pJob, pJob->fetchTask, &pJob->resNode, TDMT_SCH_FETCH)); + + return TSDB_CODE_SUCCESS; + +_return: + + SCH_RET(schProcessOnTaskFailure(pJob, pJob->fetchTask, code)); +} + + diff --git a/source/libs/scheduler/src/schUtil.c b/source/libs/scheduler/src/schUtil.c index 73077cbf0f6632e0a7a7b9979e0b6d17baf90fd3..f848dfa2101f7f5ab23c860f8e34f788fe8054cb 100644 --- a/source/libs/scheduler/src/schUtil.c +++ b/source/libs/scheduler/src/schUtil.c @@ -16,11 +16,25 @@ #include "catalog.h" #include "command.h" #include "query.h" -#include "schedulerInt.h" +#include "schInt.h" #include "tmsg.h" #include "tref.h" #include "trpc.h" +FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) { + qDebug("sch acquire jobId:0x%"PRIx64, refId); + return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId); +} + +FORCE_INLINE int32_t schReleaseJob(int64_t refId) { + if (0 == refId) { + return TSDB_CODE_SUCCESS; + } + + qDebug("sch release jobId:0x%"PRIx64, refId); + return taosReleaseRef(schMgmt.jobRef, refId); +} + char* schGetOpStr(SCH_OP_TYPE type) { switch (type) { case SCH_OP_NULL: @@ -29,6 +43,8 @@ char* schGetOpStr(SCH_OP_TYPE type) { return "EXEC"; case SCH_OP_FETCH: return "FETCH"; + case SCH_OP_GET_STATUS: + return "GET STATUS"; default: return "UNKNOWN"; } @@ -283,3 +299,20 @@ void schFreeSMsgSendInfo(SMsgSendInfo *msgSendInfo) { taosMemoryFree(msgSendInfo); } +int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask) { + int32_t s = taosHashGetSize(pTaskList); + if (s <= 0) { + return TSDB_CODE_SUCCESS; + } + + SSchTask **task = taosHashGet(pTaskList, &taskId, sizeof(taskId)); + if (NULL == task || NULL == (*task)) { + return TSDB_CODE_SUCCESS; + } + + *pTask = *task; + + return TSDB_CODE_SUCCESS; +} + + diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index e2389c2a750086a4326c6731a9d176f6fe504c6e..39465f3064e9b117ca97c345223b17ce83e95a3d 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -13,13 +13,10 @@ * along with this program. If not, see . */ -#include "catalog.h" -#include "command.h" #include "query.h" -#include "schedulerInt.h" +#include "schInt.h" #include "tmsg.h" #include "tref.h" -#include "trpc.h" SSchedulerMgmt schMgmt = { .jobRef = -1, @@ -67,121 +64,45 @@ int32_t schedulerInit(SSchedulerCfg *cfg) { return TSDB_CODE_SUCCESS; } -int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJobId, SQueryResult *pRes) { - qDebug("scheduler sync exec job start"); +int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJobId) { + qDebug("scheduler %s exec job start", pReq->syncReq ? "SYNC" : "ASYNC"); int32_t code = 0; SSchJob *pJob = NULL; - SCH_ERR_JRET(schInitJob(pReq, &pJob)); - *pJobId = pJob->refId; - - SCH_ERR_JRET(schExecJobImpl(pReq, pJob, true)); - -_return: - - if (code && NULL == pJob) { - qDestroyQueryPlan(pReq->pDag); - } - - if (pJob) { - schSetJobQueryRes(pJob, pRes); - schReleaseJob(pJob->refId); - } + SCH_ERR_JRET(schInitJob(pJobId, pReq)); - return code; -} + SCH_ERR_JRET(schHandleOpBeginEvent(*pJobId, &pJob, SCH_OP_EXEC, pReq)); -int32_t schedulerAsyncExecJob(SSchedulerReq *pReq, int64_t *pJobId) { - qDebug("scheduler async exec job start"); + SCH_ERR_JRET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_INIT, pReq)); - int32_t code = 0; - SSchJob *pJob = NULL; - SCH_ERR_JRET(schInitJob(pReq, &pJob)); - - *pJobId = pJob->refId; - - SCH_ERR_JRET(schExecJobImpl(pReq, pJob, false)); + SCH_ERR_JRET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_EXEC, pReq)); _return: - - if (code && NULL == pJob) { - qDestroyQueryPlan(pReq->pDag); - } - if (pJob) { - schReleaseJob(pJob->refId); - } - - return code; + SCH_RET(schHandleOpEndEvent(pJob, SCH_OP_EXEC, pReq, code)); } -int32_t schedulerFetchRows(int64_t job, void **pData) { - qDebug("scheduler sync fetch rows start"); - - if (NULL == pData) { - SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); - } +int32_t schedulerFetchRows(int64_t jobId, SSchedulerReq *pReq) { + qDebug("scheduler %s fetch rows start", pReq->syncReq ? "SYNC" : "ASYNC"); int32_t code = 0; - SSchJob *pJob = schAcquireJob(job); - if (NULL == pJob) { - qError("acquire job from jobRef list failed, may be dropped, jobId:0x%" PRIx64, job); - SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); - } - - SCH_ERR_RET(schBeginOperation(pJob, SCH_OP_FETCH, true)); - - pJob->userRes.fetchRes = pData; - code = schFetchRows(pJob); - - schReleaseJob(job); - - SCH_RET(code); -} - -void schedulerAsyncFetchRows(int64_t job, schedulerFetchFp fp, void* param) { - qDebug("scheduler async fetch rows start"); - - int32_t code = 0; - if (NULL == fp || NULL == param) { - SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); - } + SSchJob *pJob = NULL; - SSchJob *pJob = schAcquireJob(job); - if (NULL == pJob) { - qError("acquire sch job from job list failed, may be dropped, jobId:0x%" PRIx64, job); - SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); - } + SCH_ERR_JRET(schHandleOpBeginEvent(jobId, &pJob, SCH_OP_FETCH, pReq)); - SCH_ERR_JRET(schBeginOperation(pJob, SCH_OP_FETCH, false)); - - pJob->userRes.fetchFp = fp; - pJob->userRes.userParam = param; - - SCH_ERR_JRET(schAsyncFetchRows(pJob)); + SCH_ERR_JRET(schJobFetchRows(pJob)); _return: - if (code) { - fp(NULL, param, code); - } - - schReleaseJob(job); + SCH_RET(schHandleOpEndEvent(pJob, SCH_OP_FETCH, pReq, code)); } -int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub) { +int32_t schedulerGetTasksStatus(int64_t jobId, SArray *pSub) { int32_t code = 0; - SSchJob *pJob = schAcquireJob(job); - if (NULL == pJob) { - qDebug("acquire job from jobRef list failed, may not started or dropped, refId:0x%" PRIx64, job); - SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); - } + SSchJob *pJob = NULL; - if (pJob->status < JOB_TASK_STATUS_NOT_START || pJob->levelNum <= 0 || NULL == pJob->levels) { - qDebug("job not initialized or not executable job, refId:0x%" PRIx64, job); - SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); - } + SCH_ERR_JRET(schHandleOpBeginEvent(jobId, &pJob, SCH_OP_GET_STATUS, NULL)); for (int32_t i = pJob->levelNum - 1; i >= 0; --i) { SSchLevel *pLevel = taosArrayGet(pJob->levels, i); @@ -198,23 +119,7 @@ int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub) { _return: - schReleaseJob(job); - - SCH_RET(code); -} - -int32_t scheduleCancelJob(int64_t job) { - SSchJob *pJob = schAcquireJob(job); - if (NULL == pJob) { - qError("acquire job from jobRef list failed, may be dropped, jobId:0x%" PRIx64, job); - SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); - } - - int32_t code = schCancelJob(pJob); - - schReleaseJob(job); - - SCH_RET(code); + SCH_RET(schHandleOpEndEvent(pJob, SCH_OP_GET_STATUS, NULL, code)); } void schedulerStopQueryHb(void *pTrans) { @@ -225,33 +130,21 @@ void schedulerStopQueryHb(void *pTrans) { schCleanClusterHb(pTrans); } -void schedulerFreeJob(int64_t* job, int32_t errCode) { - if (0 == *job) { - return; - } - - SSchJob *pJob = schAcquireJob(*job); - if (NULL == pJob) { - qError("acquire sch job failed, may be dropped, jobId:0x%" PRIx64, *job); - *job = 0; +void schedulerFreeJob(int64_t* jobId, int32_t errCode) { + if (0 == *jobId) { return; } - int32_t code = schProcessOnJobDropped(pJob, errCode); - if (TSDB_CODE_SCH_JOB_IS_DROPPING == code) { - SCH_JOB_DLOG("sch job is already dropping, refId:0x%" PRIx64, *job); - *job = 0; + SSchJob *pJob = schAcquireJob(*jobId); + if (NULL == pJob) { + qError("Acquire sch job failed, may be dropped, jobId:0x%" PRIx64, *jobId); return; } - SCH_JOB_DLOG("start to remove job from jobRef list, refId:0x%" PRIx64, *job); - - if (taosRemoveRef(schMgmt.jobRef, *job)) { - SCH_JOB_ELOG("remove job from job list failed, refId:0x%" PRIx64, *job); - } - - schReleaseJob(*job); - *job = 0; + schSwitchJobStatus(pJob, JOB_TASK_STATUS_DROP, (void*)&errCode); + + schReleaseJob(*jobId); + *jobId = 0; } void schedulerDestroy(void) { diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index 7fe6cc22bfb2f34ba2b14cf3dde900685a973fc6..d6b1baf978bdc823b3337e80830ec89f5de4e790 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -50,7 +50,7 @@ #pragma GCC diagnostic ignored "-Wreturn-type" #pragma GCC diagnostic ignored "-Wformat" -#include "schedulerInt.h" +#include "schInt.h" #include "stub.h" #include "tref.h" @@ -87,7 +87,7 @@ void schtInitLogFile() { } -void schtQueryCb(SQueryResult* pResult, void* param, int32_t code) { +void schtQueryCb(SExecResult* pResult, void* param, int32_t code) { assert(TSDB_CODE_SUCCESS == code); *(int32_t*)param = 1; } @@ -507,14 +507,15 @@ void* schtRunJobThread(void *aa) { SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; SSchedulerReq req = {0}; + req.syncReq = false; req.pConn = &conn; req.pNodeList = qnodeList; req.pDag = &dag; req.sql = "select * from tb"; req.execFp = schtQueryCb; - req.execParam = &queryDone; + req.cbParam = &queryDone; - code = schedulerAsyncExecJob(&req, &queryJobRefId); + code = schedulerExecJob(&req, &queryJobRefId); assert(code == 0); pJob = schAcquireJob(queryJobRefId); @@ -584,7 +585,10 @@ void* schtRunJobThread(void *aa) { atomic_store_32(&schtStartFetch, 1); void *data = NULL; - code = schedulerFetchRows(queryJobRefId, &data); + req.syncReq = true; + req.pFetchRes = &data; + + code = schedulerFetchRows(queryJobRefId, &req); assert(code == 0 || code); if (0 == code) { @@ -594,7 +598,7 @@ void* schtRunJobThread(void *aa) { } data = NULL; - code = schedulerFetchRows(queryJobRefId, &data); + code = schedulerFetchRows(queryJobRefId, &req); assert(code == 0 || code); schtFreeQueryJob(0); @@ -658,15 +662,15 @@ TEST(queryTest, normalCase) { SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; - SSchedulerReq req = {0}; + SSchedulerReq req = {0}; req.pConn = &conn; req.pNodeList = qnodeList; req.pDag = &dag; req.sql = "select * from tb"; req.execFp = schtQueryCb; - req.execParam = &queryDone; + req.cbParam = &queryDone; - code = schedulerAsyncExecJob(&req, &job); + code = schedulerExecJob(&req, &job); ASSERT_EQ(code, 0); @@ -709,7 +713,10 @@ TEST(queryTest, normalCase) { taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job); void *data = NULL; - code = schedulerFetchRows(job, &data); + req.syncReq = true; + req.pFetchRes = &data; + + code = schedulerFetchRows(job, &req); ASSERT_EQ(code, 0); SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data; @@ -718,7 +725,7 @@ TEST(queryTest, normalCase) { taosMemoryFreeClear(data); data = NULL; - code = schedulerFetchRows(job, &data); + code = schedulerFetchRows(job, &req); ASSERT_EQ(code, 0); ASSERT_TRUE(data == NULL); @@ -768,8 +775,8 @@ TEST(queryTest, readyFirstCase) { req.pDag = &dag; req.sql = "select * from tb"; req.execFp = schtQueryCb; - req.execParam = &queryDone; - code = schedulerAsyncExecJob(&req, &job); + req.cbParam = &queryDone; + code = schedulerExecJob(&req, &job); ASSERT_EQ(code, 0); @@ -813,7 +820,9 @@ TEST(queryTest, readyFirstCase) { taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job); void *data = NULL; - code = schedulerFetchRows(job, &data); + req.syncReq = true; + req.pFetchRes = &data; + code = schedulerFetchRows(job, &req); ASSERT_EQ(code, 0); SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data; @@ -822,7 +831,7 @@ TEST(queryTest, readyFirstCase) { taosMemoryFreeClear(data); data = NULL; - code = schedulerFetchRows(job, &data); + code = schedulerFetchRows(job, &req); ASSERT_EQ(code, 0); ASSERT_TRUE(data == NULL); @@ -875,9 +884,9 @@ TEST(queryTest, flowCtrlCase) { req.pDag = &dag; req.sql = "select * from tb"; req.execFp = schtQueryCb; - req.execParam = &queryDone; + req.cbParam = &queryDone; - code = schedulerAsyncExecJob(&req, &job); + code = schedulerExecJob(&req, &job); ASSERT_EQ(code, 0); @@ -925,7 +934,9 @@ TEST(queryTest, flowCtrlCase) { taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job); void *data = NULL; - code = schedulerFetchRows(job, &data); + req.syncReq = true; + req.pFetchRes = &data; + code = schedulerFetchRows(job, &req); ASSERT_EQ(code, 0); SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data; @@ -934,7 +945,7 @@ TEST(queryTest, flowCtrlCase) { taosMemoryFreeClear(data); data = NULL; - code = schedulerFetchRows(job, &data); + code = schedulerFetchRows(job, &req); ASSERT_EQ(code, 0); ASSERT_TRUE(data == NULL); @@ -978,7 +989,7 @@ TEST(insertTest, normalCase) { TdThread thread1; taosThreadCreate(&(thread1), &thattr, schtSendRsp, &insertJobRefId); - SQueryResult res = {0}; + SExecResult res = {0}; SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; @@ -988,9 +999,9 @@ TEST(insertTest, normalCase) { req.pDag = &dag; req.sql = "insert into tb values(now,1)"; req.execFp = schtQueryCb; - req.execParam = NULL; + req.cbParam = NULL; - code = schedulerExecJob(&req, &insertJobRefId, &res); + code = schedulerExecJob(&req, &insertJobRefId); ASSERT_EQ(code, 0); ASSERT_EQ(res.numOfRows, 20); diff --git a/source/libs/sync/inc/syncRaftCfg.h b/source/libs/sync/inc/syncRaftCfg.h index 521ca6068dbcdb0c7d911be0efb0038ffa591af3..fead7cdc762b46b4d3e26a2af0d5f370eb19c6cf 100644 --- a/source/libs/sync/inc/syncRaftCfg.h +++ b/source/libs/sync/inc/syncRaftCfg.h @@ -36,7 +36,8 @@ typedef struct SRaftCfg { TdFilePtr pFile; char path[TSDB_FILENAME_LEN * 2]; int8_t isStandBy; - int8_t snapshotEnable; + int32_t batchSize; + int8_t snapshotStrategy; SyncIndex lastConfigIndex; SyncIndex configIndexArr[MAX_CONFIG_INDEX_COUNT]; @@ -62,7 +63,8 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg); typedef struct SRaftCfgMeta { int8_t isStandBy; - int8_t snapshotEnable; + int32_t batchSize; + int8_t snapshotStrategy; SyncIndex lastConfigIndex; } SRaftCfgMeta; diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h index 3b1e4f456027fe4e0b6eab4c0267edf819e5e7f2..0dc67cf15077cee2558b582b33b358583b9e8aab 100644 --- a/source/libs/sync/inc/syncSnapshot.h +++ b/source/libs/sync/inc/syncSnapshot.h @@ -40,14 +40,14 @@ typedef struct SSyncSnapshotSender { bool start; int32_t seq; int32_t ack; - void *pReader; - void *pCurrentBlock; + void * pReader; + void * pCurrentBlock; int32_t blockLen; SSnapshotParam snapshotParam; SSnapshot snapshot; SSyncCfg lastConfig; int64_t sendingMS; - SSyncNode *pSyncNode; + SSyncNode * pSyncNode; int32_t replicaIndex; SyncTerm term; SyncTerm privateTerm; @@ -64,20 +64,20 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender); int32_t snapshotReSend(SSyncSnapshotSender *pSender); cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender); -char *snapshotSender2Str(SSyncSnapshotSender *pSender); -char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event); +char * snapshotSender2Str(SSyncSnapshotSender *pSender); +char * snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event); //--------------------------------------------------- typedef struct SSyncSnapshotReceiver { bool start; int32_t ack; - void *pWriter; + void * pWriter; SyncTerm term; SyncTerm privateTerm; SSnapshotParam snapshotParam; SSnapshot snapshot; SRaftId fromId; - SSyncNode *pSyncNode; + SSyncNode * pSyncNode; } SSyncSnapshotReceiver; @@ -88,8 +88,8 @@ int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver); bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver); cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver); -char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver); -char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event); +char * snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver); +char * snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event); //--------------------------------------------------- // on message diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index c923ee3d1d72f68ae270b4717299647477cd5b68..885ab1acae068d8d8f98fdde20be2eea2cc3d0c9 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -834,7 +834,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc // // operation: // if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry - // match my-commit-index or my-commit-index + 1 + // match my-commit-index or my-commit-index + batchSize do { bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && (pMsg->prevLogIndex <= ths->commitIndex); @@ -928,11 +928,13 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc bool condition = condition1 || condition2; if (condition) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch, not match, pre-index:%ld, pre-term:%lu, datalen:%d", pMsg->prevLogIndex, - pMsg->prevLogTerm, pMsg->dataLen); - syncNodeEventLog(ths, logBuf); + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-batch, not match, pre-index:%ld, pre-term:%lu, datalen:%d", + pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); + syncNodeEventLog(ths, logBuf); + } while (0); // prepare response msg SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index f3206e9ccc92d675756a52ebd1e77ec6fdb0a435..e4724fc999dcedb565e309f5591818d03f6775b9 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -109,19 +109,30 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p } // only start once -static void syncNodeStartSnapshot(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm, - SyncAppendEntriesReply* pMsg) { +static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm, + SyncAppendEntriesReply* pMsg) { // get sender SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId)); ASSERT(pSender != NULL); + if (snapshotSenderIsStart(pSender)) { + do { + char* eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender already start"); + syncNodeErrorLog(ths, eventLog); + taosMemoryFree(eventLog); + } while (0); + + return; + } + SSnapshot snapshot = { .data = NULL, .lastApplyIndex = endIndex, .lastApplyTerm = lastApplyTerm, .lastConfigIndex = SYNC_INDEX_INVALID}; - void* pReader = NULL; SSnapshotParam readerParam = {.start = beginIndex, .end = endIndex}; - ths->pFsm->FpSnapshotStartRead(ths->pFsm, &readerParam, &pReader); - if (!snapshotSenderIsStart(pSender) && pMsg->privateTerm < pSender->privateTerm) { + int32_t code = ths->pFsm->FpSnapshotStartRead(ths->pFsm, &readerParam, &pReader); + ASSERT(code == 0); + + if (pMsg->privateTerm < pSender->privateTerm) { ASSERT(pReader != NULL); snapshotSenderStart(pSender, readerParam, snapshot, pReader); @@ -178,7 +189,9 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie // start snapshot SSnapshot oldSnapshot; ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &oldSnapshot); - syncNodeStartSnapshot(ths, newMatchIndex + 1, oldSnapshot.lastApplyIndex, oldSnapshot.lastApplyTerm, pMsg); + ASSERT(oldSnapshot.lastApplyIndex >= newMatchIndex + 1); + syncNodeStartSnapshotOnce(ths, newMatchIndex + 1, oldSnapshot.lastApplyIndex, oldSnapshot.lastApplyTerm, + pMsg); // term maybe not ok? syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), oldSnapshot.lastApplyIndex + 1); syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), newMatchIndex); @@ -187,7 +200,6 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie } else { SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - // notice! int64, uint64 if (nextIndex > SYNC_INDEX_BEGIN) { --nextIndex; @@ -198,7 +210,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie SSyncRaftEntry* pEntry; int32_t code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, nextIndex, &pEntry); ASSERT(code == 0); - syncNodeStartSnapshot(ths, SYNC_INDEX_BEGIN, nextIndex, pEntry->term, pMsg); + syncNodeStartSnapshotOnce(ths, SYNC_INDEX_BEGIN, nextIndex, pEntry->term, pMsg); // get sender SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId)); diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index 816430b5b54bf0052014866d21aa5109eb2aa48c..2712b4edc6e930c04718acda0013e8b4da6723f9 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -96,12 +96,20 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { return ret; } - if (pSyncNode->pRaftCfg->snapshotEnable) { - ret = syncNodeRequestVotePeersSnapshot(pSyncNode); - } else { - ret = syncNodeRequestVotePeers(pSyncNode); + switch (pSyncNode->pRaftCfg->snapshotStrategy) { + case SYNC_STRATEGY_NO_SNAPSHOT: + ret = syncNodeRequestVotePeers(pSyncNode); + break; + + case SYNC_STRATEGY_STANDARD_SNAPSHOT: + case SYNC_STRATEGY_WAL_FIRST: + ret = syncNodeRequestVotePeersSnapshot(pSyncNode); + break; + + default: + ret = syncNodeRequestVotePeers(pSyncNode); + break; } - ASSERT(ret == 0); syncNodeResetElectTimer(pSyncNode); diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index cefd306f7d3010ccb67852e08d3c5d81b7ad207f..e207d89212186ff806dabef9c490e98efc826699 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -397,6 +397,38 @@ bool syncIsRestoreFinish(int64_t rid) { return b; } +int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot) { + if (index < SYNC_INDEX_BEGIN) { + return -1; + } + + SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + if (pSyncNode == NULL) { + return -1; + } + ASSERT(rid == pSyncNode->rid); + + SSyncRaftEntry* pEntry = NULL; + int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index, &pEntry); + if (code != 0) { + if (pEntry != NULL) { + syncEntryDestory(pEntry); + } + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return -1; + } + ASSERT(pEntry != NULL); + + pSnapshot->data = NULL; + pSnapshot->lastApplyIndex = index; + pSnapshot->lastApplyTerm = pEntry->term; + pSnapshot->lastConfigIndex = syncNodeGetSnapshotConfigIndex(pSyncNode, index); + + syncEntryDestory(pEntry); + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return 0; +} + int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { @@ -672,12 +704,12 @@ int32_t syncNodeProposeBatch(SSyncNode* pSyncNode, SRpcMsg* pMsgArr, bool* pIsWe } if (arrSize > SYNC_MAX_BATCH_SIZE) { - syncNodeErrorLog(pSyncNode, "sync propose match batch error"); + syncNodeErrorLog(pSyncNode, "sync propose batch error"); terrno = TSDB_CODE_SYN_BATCH_ERROR; return -1; } - if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { syncNodeErrorLog(pSyncNode, "sync propose not leader"); terrno = TSDB_CODE_SYN_NOT_LEADER; return -1; @@ -707,13 +739,36 @@ int32_t syncNodeProposeBatch(SSyncNode* pSyncNode, SRpcMsg* pMsgArr, bool* pIsWe syncClientRequestBatch2RpcMsg(pSyncMsg, &rpcMsg); taosMemoryFree(pSyncMsg); // only free msg body, do not free rpc msg content - if (pSyncNode->FpEqMsg != NULL && (*pSyncNode->FpEqMsg)(pSyncNode->msgcb, &rpcMsg) == 0) { - // enqueue msg ok + if (pSyncNode->replicaNum == 1 && pSyncNode->vgId != 1) { + int32_t code = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg); + if (code == 0) { + // update rpc msg applyIndex + SRpcMsg* msgArr = syncClientRequestBatchRpcMsgArr(pSyncMsg); + ASSERT(arrSize == pSyncMsg->dataCount); + for (int i = 0; i < arrSize; ++i) { + pMsgArr[i].info.conn.applyIndex = msgArr[i].info.conn.applyIndex; + syncRespMgrDel(pSyncNode->pSyncRespMgr, raftArr[i].seqNum); + } + + rpcFreeCont(rpcMsg.pCont); + terrno = 0; + return 1; + + } else { + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } } else { - sError("enqueue msg error, FpEqMsg is NULL"); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; + if (pSyncNode->FpEqMsg != NULL && (*pSyncNode->FpEqMsg)(pSyncNode->msgcb, &rpcMsg) == 0) { + // enqueue msg ok + return 0; + + } else { + sError("vgId:%d, enqueue msg error, FpEqMsg is NULL", pSyncNode->vgId); + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } } return 0; @@ -730,7 +785,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { if (pSyncNode->changing && pMsg->msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH) { ret = -1; terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; - sError("sync propose not ready, type:%s,%d", TMSG_INFO(pMsg->msgType), pMsg->msgType); + sError("vgId:%d, sync propose not ready, type:%s,%d", pSyncNode->vgId, TMSG_INFO(pMsg->msgType), pMsg->msgType); goto _END; } @@ -739,7 +794,8 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { if (!syncNodeCanChange(pSyncNode)) { ret = -1; terrno = TSDB_CODE_SYN_RECONFIG_NOT_READY; - sError("sync reconfig not ready, type:%s,%d", TMSG_INFO(pMsg->msgType), pMsg->msgType); + sError("vgId:%d, sync reconfig not ready, type:%s,%d", pSyncNode->vgId, TMSG_INFO(pMsg->msgType), + pMsg->msgType); goto _END; } @@ -762,6 +818,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { int32_t code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, &retIndex); if (code == 0) { pMsg->info.conn.applyIndex = retIndex; + pMsg->info.conn.applyTerm = pSyncNode->pRaftStore->currentTerm; rpcFreeCont(rpcMsg.pCont); syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); ret = 1; @@ -780,7 +837,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { } else { ret = -1; terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - sError("enqueue msg error, FpEqMsg is NULL"); + sError("vgId:%d, enqueue msg error, FpEqMsg is NULL", pSyncNode->vgId); } } @@ -790,7 +847,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { } else { ret = -1; terrno = TSDB_CODE_SYN_NOT_LEADER; - sError("sync propose not leader, %s", syncUtilState2String(pSyncNode->state)); + sError("vgId:%d, sync propose not leader, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state)); goto _END; } @@ -820,8 +877,9 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { // create a new raft config file SRaftCfgMeta meta; meta.isStandBy = pSyncInfo->isStandBy; - meta.snapshotEnable = pSyncInfo->snapshotStrategy; + meta.snapshotStrategy = pSyncInfo->snapshotStrategy; meta.lastConfigIndex = SYNC_INDEX_INVALID; + meta.batchSize = pSyncInfo->batchSize; ret = raftCfgCreateFile((SSyncCfg*)&(pSyncInfo->syncCfg), meta, pSyncNode->configPath); ASSERT(ret == 0); @@ -969,7 +1027,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { pSyncNode->FpOnSnapshotSend = syncNodeOnSnapshotSendCb; pSyncNode->FpOnSnapshotRsp = syncNodeOnSnapshotRspCb; - if (pSyncNode->pRaftCfg->snapshotEnable) { + if (pSyncNode->pRaftCfg->snapshotStrategy) { sInfo("sync node use snapshot"); pSyncNode->FpOnRequestVote = syncNodeOnRequestVoteSnapshotCb; pSyncNode->FpOnRequestVoteReply = syncNodeOnRequestVoteReplySnapshotCb; @@ -1107,7 +1165,7 @@ void syncNodeClose(SSyncNode* pSyncNode) { // option // bool syncNodeSnapshotEnable(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotEnable; } -ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotEnable; } +ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotStrategy; } // ping -------------- int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) { @@ -2489,6 +2547,9 @@ int32_t syncNodeOnClientRequestBatchCb(SSyncNode* ths, SyncClientRequestBatch* p ASSERT(0); return -1; } + + // update rpc msg conn apply.index + msgArr[i].info.conn.applyIndex = pEntry->index; } // fsync once @@ -2496,6 +2557,15 @@ int32_t syncNodeOnClientRequestBatchCb(SSyncNode* ths, SyncClientRequestBatch* p SWal* pWal = pData->pWal; walFsync(pWal, true); + if (ths->replicaNum > 1) { + // if multi replica, start replicate right now + syncNodeReplicate(ths); + + } else if (ths->replicaNum == 1) { + // one replica + syncMaybeAdvanceCommitIndex(ths); + } + return 0; } diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index ec3f18132d7e197bdb563a70bb06f0bda45f6521..ead1168632a154be285c07c4a7183a2a202451dd 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -182,7 +182,8 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { cJSON *pRoot = cJSON_CreateObject(); cJSON_AddItemToObject(pRoot, "SSyncCfg", syncCfg2Json(&(pRaftCfg->cfg))); cJSON_AddNumberToObject(pRoot, "isStandBy", pRaftCfg->isStandBy); - cJSON_AddNumberToObject(pRoot, "snapshotEnable", pRaftCfg->snapshotEnable); + cJSON_AddNumberToObject(pRoot, "snapshotStrategy", pRaftCfg->snapshotStrategy); + cJSON_AddNumberToObject(pRoot, "batchSize", pRaftCfg->batchSize); char buf64[128]; snprintf(buf64, sizeof(buf64), "%ld", pRaftCfg->lastConfigIndex); @@ -228,7 +229,8 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) { SRaftCfg raftCfg; raftCfg.cfg = *pCfg; raftCfg.isStandBy = meta.isStandBy; - raftCfg.snapshotEnable = meta.snapshotEnable; + raftCfg.batchSize = meta.batchSize; + raftCfg.snapshotStrategy = meta.snapshotStrategy; raftCfg.lastConfigIndex = meta.lastConfigIndex; raftCfg.configIndexCount = 1; memset(raftCfg.configIndexArr, 0, sizeof(raftCfg.configIndexArr)); @@ -257,8 +259,11 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) { cJSON *pJsonIsStandBy = cJSON_GetObjectItem(pJson, "isStandBy"); pRaftCfg->isStandBy = cJSON_GetNumberValue(pJsonIsStandBy); - cJSON *pJsonSnapshotEnable = cJSON_GetObjectItem(pJson, "snapshotEnable"); - pRaftCfg->snapshotEnable = cJSON_GetNumberValue(pJsonSnapshotEnable); + cJSON *pJsonBatchSize = cJSON_GetObjectItem(pJson, "batchSize"); + pRaftCfg->batchSize = cJSON_GetNumberValue(pJsonBatchSize); + + cJSON *pJsonSnapshotStrategy = cJSON_GetObjectItem(pJson, "snapshotStrategy"); + pRaftCfg->snapshotStrategy = cJSON_GetNumberValue(pJsonSnapshotStrategy); cJSON *pJsonLastConfigIndex = cJSON_GetObjectItem(pJson, "lastConfigIndex"); pRaftCfg->lastConfigIndex = atoll(cJSON_GetStringValue(pJsonLastConfigIndex)); diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index bcca44130a05d1e806d2ea56a4c29344676d0451..da31e9c4c46f3fac3625844b8af69e2a78e49cdd 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -132,10 +132,6 @@ int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) { SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex); SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex); if (preLogTerm == SYNC_TERM_INVALID) { - SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId); - ASSERT(pSender != NULL); - ASSERT(!snapshotSenderIsStart(pSender)); - SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); @@ -145,26 +141,32 @@ int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) { return -1; } + // entry pointer array SSyncRaftEntry* entryPArr[SYNC_MAX_BATCH_SIZE]; memset(entryPArr, 0, sizeof(entryPArr)); + // get entry batch int32_t getCount = 0; SyncIndex getEntryIndex = nextIndex; for (int32_t i = 0; i < pSyncNode->batchSize; ++i) { - SSyncRaftEntry* pEntry; + SSyncRaftEntry* pEntry = NULL; int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, getEntryIndex, &pEntry); if (code == 0) { ASSERT(pEntry != NULL); entryPArr[i] = pEntry; getCount++; + getEntryIndex++; + } else { break; } } + // build msg SyncAppendEntriesBatch* pMsg = syncAppendEntriesBatchBuild(entryPArr, getCount, pSyncNode->vgId); ASSERT(pMsg != NULL); + // free entries for (int32_t i = 0; i < pSyncNode->batchSize; ++i) { SSyncRaftEntry* pEntry = entryPArr[i]; if (pEntry != NULL) { @@ -197,12 +199,6 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) { syncIndexMgrLog2("begin append entries peers pNextIndex:", pSyncNode->pNextIndex); syncIndexMgrLog2("begin append entries peers pMatchIndex:", pSyncNode->pMatchIndex); logStoreSimpleLog2("begin append entries peers LogStore:", pSyncNode->pLogStore); - if (gRaftDetailLog) { - SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); - sTrace("begin append entries peers, snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu", - snapshot.lastApplyIndex, snapshot.lastApplyTerm); - } int32_t ret = 0; for (int i = 0; i < pSyncNode->peersNum; ++i) { @@ -224,9 +220,6 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) { return -1; } - // batch optimized - // SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex); - // prepare entry SyncAppendEntries* pMsg = NULL; @@ -283,11 +276,24 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) { // start replicate int32_t ret = 0; - if (pSyncNode->pRaftCfg->snapshotEnable) { - ret = syncNodeAppendEntriesPeersSnapshot(pSyncNode); - } else { - ret = syncNodeAppendEntriesPeers(pSyncNode); + switch (pSyncNode->pRaftCfg->snapshotStrategy) { + case SYNC_STRATEGY_NO_SNAPSHOT: + ret = syncNodeAppendEntriesPeers(pSyncNode); + break; + + case SYNC_STRATEGY_STANDARD_SNAPSHOT: + ret = syncNodeAppendEntriesPeersSnapshot(pSyncNode); + break; + + case SYNC_STRATEGY_WAL_FIRST: + ret = syncNodeAppendEntriesPeersSnapshot2(pSyncNode); + break; + + default: + ret = syncNodeAppendEntriesPeers(pSyncNode); + break; } + return ret; } diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 990a92aad7618b60aec2aa9161c346c53b173ee9..8dd1349edb190d284e8c34dc9b71b5e3890aff4e 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -127,7 +127,7 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl) { while (pStub) { size_t len; - void *key = taosHashGetKey(pStub, &len); + void * key = taosHashGetKey(pStub, &len); SyncIndex *pIndex = (SyncIndex *)key; int64_t nowMS = taosGetTimestampMs(); diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 5cdfec72c5f6740655111796e44e9320a9ea54f2..a33f66733b2b2054f3f19f6df785fd06f2d1cbd8 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -374,14 +374,14 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) { char *snapshotSender2Str(SSyncSnapshotSender *pSender) { cJSON *pJson = snapshotSender2Json(pSender); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) { int32_t len = 256; - char *s = taosMemoryMalloc(len); + char * s = taosMemoryMalloc(len); SRaftId destId = pSender->pSyncNode->replicasId[pSender->replicaIndex]; char host[64]; @@ -644,7 +644,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) { cJSON_AddStringToObject(pFromId, "addr", u64buf); { uint64_t u64 = pReceiver->fromId.addr; - cJSON *pTmp = pFromId; + cJSON * pTmp = pFromId; char host[128] = {0}; uint16_t port; syncUtilU642Addr(u64, host, sizeof(host), &port); @@ -677,14 +677,14 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) { char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver) { cJSON *pJson = snapshotReceiver2Json(pReceiver); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) { int32_t len = 256; - char *s = taosMemoryMalloc(len); + char * s = taosMemoryMalloc(len); SRaftId fromId = pReceiver->fromId; char host[128]; diff --git a/source/libs/sync/test/syncAppendEntriesBatchTest.cpp b/source/libs/sync/test/syncAppendEntriesBatchTest.cpp index 515d580b35857e1dddfc088f41d6a13783f3b618..f2544d8fec7afcf707207e792376488986834380 100644 --- a/source/libs/sync/test/syncAppendEntriesBatchTest.cpp +++ b/source/libs/sync/test/syncAppendEntriesBatchTest.cpp @@ -54,15 +54,15 @@ void test1() { SyncAppendEntriesBatch *pMsg = createMsg(); syncAppendEntriesBatchLog2((char *)"==test1==", pMsg); -/* - SOffsetAndContLen *metaArr = syncAppendEntriesBatchMetaTableArray(pMsg); - int32_t retArrSize = pMsg->dataCount; - for (int i = 0; i < retArrSize; ++i) { - SSyncRaftEntry *pEntry = (SSyncRaftEntry*)(pMsg->data + metaArr[i].offset); - ASSERT(pEntry->bytes == metaArr[i].contLen); - syncEntryPrint(pEntry); - } -*/ + /* + SOffsetAndContLen *metaArr = syncAppendEntriesBatchMetaTableArray(pMsg); + int32_t retArrSize = pMsg->dataCount; + for (int i = 0; i < retArrSize; ++i) { + SSyncRaftEntry *pEntry = (SSyncRaftEntry*)(pMsg->data + metaArr[i].offset); + ASSERT(pEntry->bytes == metaArr[i].contLen); + syncEntryPrint(pEntry); + } + */ syncAppendEntriesBatchDestroy(pMsg); } diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index 968baff9521356d2cdeec87a89bbb832af64cf75..7cd97695f98eb6dfe801d7382bfccd5fd6aef54d 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -114,7 +114,7 @@ int32_t SnapshotDoRead(struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32 return 0; } -int32_t SnapshotStartWrite(struct SSyncFSM* pFsm, void *pParam, void** ppWriter) { +int32_t SnapshotStartWrite(struct SSyncFSM* pFsm, void* pParam, void** ppWriter) { *ppWriter = (void*)0xCDEF; char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), "==callback== ==SnapshotStartWrite== pFsm:%p, *ppWriter:%p", pFsm, *ppWriter); diff --git a/source/libs/sync/test/syncIndexTest.cpp b/source/libs/sync/test/syncIndexTest.cpp index 8627a6c1748455247bd9752c5f2807f62124001a..07a05d437e172858ff2c6e37c3fbb906396a70e6 100644 --- a/source/libs/sync/test/syncIndexTest.cpp +++ b/source/libs/sync/test/syncIndexTest.cpp @@ -8,11 +8,10 @@ void print(SHashObj *pNextIndex) { printf("----------------\n"); uint64_t *p = (uint64_t *)taosHashIterate(pNextIndex, NULL); while (p) { - size_t len; - void* key = taosHashGetKey(p, &len); + void * key = taosHashGetKey(p, &len); - SRaftId *pRaftId = (SRaftId*)key; + SRaftId *pRaftId = (SRaftId *)key; printf("key:<%lu, %d>, value:%lu \n", pRaftId->addr, pRaftId->vgId, *p); p = (uint64_t *)taosHashIterate(pNextIndex, p); diff --git a/source/libs/sync/test/syncRaftCfgTest.cpp b/source/libs/sync/test/syncRaftCfgTest.cpp index 0f111ef22c2575a38e07658eef60fe3b0656d06d..2823a7826b8908e907261d2e830e3230a8373ed7 100644 --- a/source/libs/sync/test/syncRaftCfgTest.cpp +++ b/source/libs/sync/test/syncRaftCfgTest.cpp @@ -26,6 +26,7 @@ SRaftCfg* createRaftCfg() { snprintf(((pCfg->cfg.nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->cfg.nodeInfo)[i]).nodeFqdn), "100.200.300.%d", i); } pCfg->isStandBy = taosGetTimestampSec() % 100; + pCfg->batchSize = taosGetTimestampSec() % 100; pCfg->configIndexCount = 5; for (int i = 0; i < MAX_CONFIG_INDEX_COUNT; ++i) { @@ -83,7 +84,8 @@ void test3() { } else { SRaftCfgMeta meta; meta.isStandBy = 7; - meta.snapshotEnable = 9; + meta.snapshotStrategy = 9; + meta.batchSize = 10; meta.lastConfigIndex = 789; raftCfgCreateFile(pCfg, meta, s); printf("%s create json file: %s \n", (char*)__FUNCTION__, s); @@ -108,7 +110,8 @@ void test5() { pCfg->cfg.myIndex = taosGetTimestampSec(); pCfg->isStandBy += 2; - pCfg->snapshotEnable += 3; + pCfg->snapshotStrategy += 3; + pCfg->batchSize += 4; pCfg->lastConfigIndex += 1000; pCfg->configIndexCount = 5; diff --git a/source/libs/sync/test/syncRespMgrTest.cpp b/source/libs/sync/test/syncRespMgrTest.cpp index fd18109280bbd42c028a67d2898d658bf91bdeef..93a7ce430fd7db81956e6a2bd0d16a0f4f7a02e4 100644 --- a/source/libs/sync/test/syncRespMgrTest.cpp +++ b/source/libs/sync/test/syncRespMgrTest.cpp @@ -74,7 +74,7 @@ void syncRespMgrGetAndDelTest(uint64_t i) { } SSyncNode *createSyncNode() { - SSyncNode *pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(SSyncNode)); + SSyncNode *pSyncNode = (SSyncNode *)taosMemoryMalloc(sizeof(SSyncNode)); memset(pSyncNode, 0, sizeof(SSyncNode)); return pSyncNode; } diff --git a/source/libs/sync/test/syncSnapshotReceiverTest.cpp b/source/libs/sync/test/syncSnapshotReceiverTest.cpp index b4bf08dd409861e7002feba17e987f340162848f..e5d93ddff421941e71b53caac9319ec61cf23bbf 100644 --- a/source/libs/sync/test/syncSnapshotReceiverTest.cpp +++ b/source/libs/sync/test/syncSnapshotReceiverTest.cpp @@ -29,7 +29,7 @@ int32_t SnapshotStartRead(struct SSyncFSM* pFsm, void** ppReader) { return 0; } int32_t SnapshotStopRead(struct SSyncFSM* pFsm, void* pReader) { return 0; } int32_t SnapshotDoRead(struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32_t* len) { return 0; } -int32_t SnapshotStartWrite(struct SSyncFSM* pFsm, void *pParam, void** ppWriter) { return 0; } +int32_t SnapshotStartWrite(struct SSyncFSM* pFsm, void* pParam, void** ppWriter) { return 0; } int32_t SnapshotStopWrite(struct SSyncFSM* pFsm, void* pWriter, bool isApply) { return 0; } int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_t len) { return 0; } diff --git a/source/libs/sync/test/syncTestTool.cpp b/source/libs/sync/test/syncTestTool.cpp index c6d3a3e4afe4816160452f0d4e206646ea0fc3d4..2c08910aa8159d7032b513b24c0d757e33873c65 100644 --- a/source/libs/sync/test/syncTestTool.cpp +++ b/source/libs/sync/test/syncTestTool.cpp @@ -111,7 +111,7 @@ int32_t SnapshotDoRead(struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32 return 0; } -int32_t SnapshotStartWrite(struct SSyncFSM* pFsm, void *pParam, void** ppWriter) { +int32_t SnapshotStartWrite(struct SSyncFSM* pFsm, void* pParam, void** ppWriter) { *ppWriter = (void*)0xCDEF; char logBuf[256] = {0}; @@ -314,18 +314,18 @@ int main(int argc, char** argv) { exit(-1); } - int32_t replicaNum = atoi(argv[1]); - int32_t myIndex = atoi(argv[2]); - ESyncStrategy enableSnapshot = (ESyncStrategy)atoi(argv[3]); - int32_t lastApplyIndex = atoi(argv[4]); - int32_t lastApplyTerm = atoi(argv[5]); - int32_t writeRecordNum = atoi(argv[6]); - bool isStandBy = atoi(argv[7]); - int32_t isConfigChange = atoi(argv[8]); - int32_t iterTimes = atoi(argv[9]); - int32_t finishLastApplyIndex = atoi(argv[10]); - int32_t finishLastApplyTerm = atoi(argv[11]); - int32_t leaderTransfer = atoi(argv[12]); + int32_t replicaNum = atoi(argv[1]); + int32_t myIndex = atoi(argv[2]); + ESyncStrategy enableSnapshot = (ESyncStrategy)atoi(argv[3]); + int32_t lastApplyIndex = atoi(argv[4]); + int32_t lastApplyTerm = atoi(argv[5]); + int32_t writeRecordNum = atoi(argv[6]); + bool isStandBy = atoi(argv[7]); + int32_t isConfigChange = atoi(argv[8]); + int32_t iterTimes = atoi(argv[9]); + int32_t finishLastApplyIndex = atoi(argv[10]); + int32_t finishLastApplyTerm = atoi(argv[11]); + int32_t leaderTransfer = atoi(argv[12]); sInfo( "args: replicaNum:%d, myIndex:%d, enableSnapshot:%d, lastApplyIndex:%d, lastApplyTerm:%d, writeRecordNum:%d, " diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index cfb7b8a0e255cf32301984f9135f2d4711144d74..243a234abe5481ae16a015629a618cb00d646f7c 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -260,6 +260,14 @@ char *taosDirName(char *name) { name[0] = 0; } return name; +#elif defined(_TD_DARWIN_64) + char *end = strrchr(name, '/'); + if (end != NULL) { + *end = '\0'; + } else { + name[0] = 0; + } + return name; #else return dirname(name); #endif diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index cb943b9d28dbfe83d4a06198d5b284837b33a46a..556fd7836078ec69e002360a8ba70b2076114fc6 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -58,6 +58,15 @@ typedef struct TdFile { #define FILE_WITH_LOCK 1 +typedef struct AutoDelFile * AutoDelFilePtr; +typedef struct AutoDelFile { + char *name; + AutoDelFilePtr lastAutoDelFilePtr; +} AutoDelFile; +static TdThreadMutex autoDelFileLock; +static AutoDelFilePtr nowAutoDelFilePtr = NULL; +static TdThreadOnce autoDelFileInit = PTHREAD_ONCE_INIT; + void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) { #ifdef WINDOWS const char *tdengineTmpFileNamePrefix = "tdengine-"; @@ -238,7 +247,33 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) { return 0; } -void autoDelFileListAdd(const char *path) { return; } +void autoDelFileList() { + taosThreadMutexLock(&autoDelFileLock); + while (nowAutoDelFilePtr != NULL) { + taosRemoveFile(nowAutoDelFilePtr->name); + AutoDelFilePtr tmp = nowAutoDelFilePtr->lastAutoDelFilePtr; + taosMemoryFree(nowAutoDelFilePtr->name); + taosMemoryFree(nowAutoDelFilePtr); + nowAutoDelFilePtr = tmp; + } + taosThreadMutexUnlock(&autoDelFileLock); + taosThreadMutexDestroy(&autoDelFileLock); +} + +void autoDelFileListInit() { + taosThreadMutexInit(&autoDelFileLock, NULL); + atexit(autoDelFileList); +} + +void autoDelFileListAdd(const char *path) { + taosThreadOnce(&autoDelFileInit, autoDelFileListInit); + taosThreadMutexLock(&autoDelFileLock); + AutoDelFilePtr tmp = taosMemoryMalloc(sizeof(AutoDelFile)); + tmp->lastAutoDelFilePtr = nowAutoDelFilePtr; + tmp->name = taosMemoryStrDup(path); + nowAutoDelFilePtr = tmp; + taosThreadMutexUnlock(&autoDelFileLock); +} TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { int fd = -1; @@ -283,10 +318,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { } } - if (tdFileOptions & TD_FILE_AUTO_DEL) { - autoDelFileListAdd(path); - } - TdFilePtr pFile = (TdFilePtr)taosMemoryMalloc(sizeof(TdFile)); if (pFile == NULL) { if (fd >= 0) close(fd); @@ -299,6 +330,9 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { pFile->fd = fd; pFile->fp = fp; pFile->refId = 0; + if (tdFileOptions & TD_FILE_AUTO_DEL) { + autoDelFileListAdd(path); + } return pFile; } diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index aa25b853423a1151959b1ef74c00d5ff4fa47461..07575336a1ce521b47970896eefed8808dcb26b8 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -282,14 +282,14 @@ void *taosMemoryRealloc(void *ptr, int32_t size) { #endif } -void *taosMemoryStrDup(void *ptr) { +void *taosMemoryStrDup(const char *ptr) { #ifdef USE_TD_MEMORY if (ptr == NULL) return NULL; TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char *)ptr - sizeof(TdMemoryInfo)); assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); - void *tmp = tstrdup((const char *)pTdMemoryInfo); + void *tmp = tstrdup(pTdMemoryInfo); if (tmp == NULL) return NULL; memcpy(tmp, pTdMemoryInfo, sizeof(TdMemoryInfo)); @@ -297,7 +297,7 @@ void *taosMemoryStrDup(void *ptr) { return (char *)tmp + sizeof(TdMemoryInfo); #else - return tstrdup((const char *)ptr); + return tstrdup(ptr); #endif } diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 5c94d99da0458cf8ba4d1937651607f671d75ab2..98dfaa4972b001ed9a30369e7390222e637a60fc 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -947,9 +947,9 @@ int32_t taosGetFqdn(char *fqdn) { hostname[1023] = '\0'; if (gethostname(hostname, 1023) == -1) { #ifdef WINDOWS - printf("failed to get hostname, reason:%s", strerror(WSAGetLastError())); + printf("failed to get hostname, reason:%s\n", strerror(WSAGetLastError())); #else - printf("failed to get hostname, reason:%s", strerror(errno)); + printf("failed to get hostname, reason:%s\n", strerror(errno)); #endif assert(0); return -1; @@ -968,7 +968,7 @@ int32_t taosGetFqdn(char *fqdn) { #endif // __APPLE__ int32_t ret = getaddrinfo(hostname, NULL, &hints, &result); if (!result) { - fprintf(stderr, "failed to get fqdn, code:%d, reason:%s", ret, gai_strerror(ret)); + fprintf(stderr, "failed to get fqdn, code:%d, reason:%s\n", ret, gai_strerror(ret)); return -1; } diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 4981f7dc260b32ff092c348656e228a957dd663f..b6220b0ae8f68d89cba66a13682295e56539941c 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -759,9 +759,11 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { return 0; #elif defined(_TD_DARWIN_64) uuid_t uuid = {0}; + char buf[37] = {0}; uuid_generate(uuid); // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null - uuid_unparse_lower(uuid, uid); + uuid_unparse_lower(uuid, buf); + memcpy(uid, buf, uidlen); return 0; #else int len = 0; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 3ee2d83f6f77502211e239c25123fbfc58686a02..0301b842c431b73dfd06b3df3c6615bc57f6d843 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -77,6 +77,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE, "Out of memory in rpc TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIMESTAMP, "Invalid timestamp format") TAOS_DEFINE_ERROR(TSDB_CODE_MSG_DECODE_ERROR, "Msg decode error") TAOS_DEFINE_ERROR(TSDB_CODE_NO_AVAIL_DISK, "No available disk") +TAOS_DEFINE_ERROR(TSDB_CODE_NOT_FOUND, "Not found") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") @@ -394,6 +395,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_DROPPING, "Task dropping") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_DUPLICATTED_OPERATION, "Duplicatted operation") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_MSG_ERROR, "Task message error") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JOB_FREED, "Job already freed") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JOB_NOT_EXIST, "Job not exist") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_STATUS_ERROR, "Task status error") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_IN_ERROR, "Json not support in in/notin operator") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR, "Json not support in this place") diff --git a/source/util/src/tmallocator.c b/source/util/src/tmallocator.c deleted file mode 100644 index 0303af07e85306cac52a34746c2c80b9a16f649d..0000000000000000000000000000000000000000 --- a/source/util/src/tmallocator.c +++ /dev/null @@ -1,110 +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 . - */ - -#define _DEFAULT_SOURCE -#include "tmallocator.h" - -/* ------------------------ HEAP ALLOCATOR ------------------------ */ -#if 0 -typedef struct { - size_t tusage; -} SHeapAllocator; - -static void * haMalloc(SMemAllocator *pma, size_t size); -static void * haCalloc(SMemAllocator *pma, size_t nmemb, size_t size); -static void * haRealloc(SMemAllocator *pma, void *ptr, size_t size); -static void haFree(SMemAllocator *pma, void *ptr); -static size_t haUsage(SMemAllocator *pma); - -SMemAllocator *tdCreateHeapAllocator() { - SMemAllocator *pma = NULL; - - pma = taosMemoryCalloc(1, sizeof(SMemAllocator) + sizeof(SHeapAllocator)); - if (pma) { - pma->impl = POINTER_SHIFT(pma, sizeof(SMemAllocator)); - pma->malloc = haMalloc; - pma->calloc = haCalloc; - pma->realloc = haRealloc; - pma->free = haFree; - pma->usage = haUsage; - } - - return pma; -} - -void tdDestroyHeapAllocator(SMemAllocator *pMemAllocator) { - // TODO -} - -static void *haMalloc(SMemAllocator *pma, size_t size) { - void * ptr; - size_t tsize = size + sizeof(size_t); - SHeapAllocator *pha = (SHeapAllocator *)(pma->impl); - - ptr = taosMemoryMalloc(tsize); - if (ptr) { - *(size_t *)ptr = size; - ptr = POINTER_SHIFT(ptr, sizeof(size_t)); - atomic_fetch_add_64(&(pha->tusage), tsize); - } - - return ptr; -} - -static void *haCalloc(SMemAllocator *pma, size_t nmemb, size_t size) { - void * ptr; - size_t tsize = nmemb * size; - - ptr = haMalloc(pma, tsize); - if (ptr) { - memset(ptr, 0, tsize); - } - - return ptr; -} - -static void *haRealloc(SMemAllocator *pma, void *ptr, size_t size) { - size_t psize; - size_t tsize = size + sizeof(size_t); - - if (ptr == NULL) { - psize = 0; - } else { - psize = *(size_t *)POINTER_SHIFT(ptr, -sizeof(size_t)); - } - - if (psize < size) { - // TODO - } else { - return ptr; - } -} - -static void haFree(SMemAllocator *pma, void *ptr) { /* TODO */ - SHeapAllocator *pha = (SHeapAllocator *)(pma->impl); - if (ptr) { - size_t tsize = *(size_t *)POINTER_SHIFT(ptr, -sizeof(size_t)) + sizeof(size_t); - atomic_fetch_sub_64(&(pha->tusage), tsize); - taosMemoryFree(POINTER_SHIFT(ptr, -sizeof(size_t))); - } -} - -static size_t haUsage(SMemAllocator *pma) { return ((SHeapAllocator *)(pma->impl))->tusage; } - -/* ------------------------ ARENA ALLOCATOR ------------------------ */ -typedef struct { - size_t usage; -} SArenaAllocator; -#endif \ No newline at end of file diff --git a/tests/pytest/util/constant.py b/tests/pytest/util/constant.py index 83487da0236c0459221af441f01adffc6af66289..509d87e4894d67569cdd4fbdfee5044e5f6d0818 100644 --- a/tests/pytest/util/constant.py +++ b/tests/pytest/util/constant.py @@ -93,7 +93,7 @@ TS_FUNC = [ "CSUM", "DERIVATIVE", "DIFF", "IRATE", "MAVG", "SAMPLE", "STATECOUNT", "STATEDURATION", "TWA" ] -SYSINFO_FUCN = [ +SYSINFO_FUNC = [ "DATABASE", "CLIENT_VERSION", "SERVER_VERSION", "SERVER_STATUS", "CURRENT_USER", "USER" ] diff --git a/tests/pytest/util/gettime.py b/tests/pytest/util/gettime.py new file mode 100644 index 0000000000000000000000000000000000000000..94eed384789b85b746a523c3a0875bf1f5b711ea --- /dev/null +++ b/tests/pytest/util/gettime.py @@ -0,0 +1,62 @@ +################################################################### +# 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 time +from datetime import datetime + +class GetTime: + + def get_ms_timestamp(self,ts_str): + _ts_str = ts_str + if " " in ts_str: + p = ts_str.split(" ")[1] + if len(p) > 15 : + _ts_str = ts_str[:-3] + if ':' in _ts_str and '.' in _ts_str: + timestamp = datetime.strptime(_ts_str, "%Y-%m-%d %H:%M:%S.%f") + date_time = int(int(time.mktime(timestamp.timetuple()))*1000 + timestamp.microsecond/1000) + elif ':' in _ts_str and '.' not in _ts_str: + timestamp = datetime.strptime(_ts_str, "%Y-%m-%d %H:%M:%S") + date_time = int(int(time.mktime(timestamp.timetuple()))*1000 + timestamp.microsecond/1000) + else: + timestamp = datetime.strptime(_ts_str, "%Y-%m-%d") + date_time = int(int(time.mktime(timestamp.timetuple()))*1000 + timestamp.microsecond/1000) + return date_time + def get_us_timestamp(self,ts_str): + _ts = self.get_ms_timestamp(ts_str) * 1000 + if " " in ts_str: + p = ts_str.split(" ")[1] + if len(p) > 12: + us_ts = p[12:15] + _ts += int(us_ts) + return _ts + def get_ns_timestamp(self,ts_str): + _ts = self.get_us_timestamp(ts_str) *1000 + if " " in ts_str: + p = ts_str.split(" ")[1] + if len(p) > 15: + us_ts = p[15:] + _ts += int(us_ts) + return _ts + def time_transform(self,ts_str,precision): + date_time = [] + if precision == 'ms': + for i in ts_str: + date_time.append(self.get_ms_timestamp(i)) + elif precision == 'us': + for i in ts_str: + date_time.append(self.get_us_timestamp(i)) + elif precision == 'ns': + for i in ts_str: + date_time.append(self.get_ns_timestamp(i)) + return date_time \ No newline at end of file diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index cbcc2d86efa4706da16706c1d9eec490eb3d02f2..4e009e702d35038904ef3f39097eed5141a4e8a6 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -163,11 +163,12 @@ # --- sma ./test.sh -f tsim/sma/drop_sma.sim ./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim -./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim -./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim +#./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim +#./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim # --- valgrind -./test.sh -f tsim/valgrind/checkError.sim -v +./test.sh -f tsim/valgrind/checkError1.sim +./test.sh -f tsim/valgrind/checkError2.sim # --- vnode # ./test.sh -f tsim/vnode/replica3_basic.sim diff --git a/tests/script/sh/checkValgrind.sh b/tests/script/sh/checkValgrind.sh index e3afb10752bf1fb4c1e5db267b35cb1070630c62..fdbac45ea672ee7802dd4ceff9718fac512d2ca9 100755 --- a/tests/script/sh/checkValgrind.sh +++ b/tests/script/sh/checkValgrind.sh @@ -4,13 +4,17 @@ set +e #set -x NODE_NAME= +DETAIL=0 -while getopts "n:" arg +while getopts "n:d" arg do case $arg in n) NODE_NAME=$OPTARG ;; + d) + DETAIL=1 + ;; ?) echo "unkown argument" ;; @@ -30,10 +34,26 @@ fi TAOS_DIR=`pwd` LOG_DIR=$TAOS_DIR/sim/$NODE_NAME/log -#CFG_DIR=$TAOS_DIR/sim/$NODE_NAME/cfg -#echo ---- $LOG_DIR +error_summary=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "ERROR SUMMARY:" | awk '{print $4}' | awk '{sum+=$1}END{print sum}'` +still_reachable=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "still reachable in" | wc -l` +definitely_lost=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "definitely lost in" | wc -l` +indirectly_lost=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "indirectly lost in " | wc -l` +possibly_lost=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "possibly lost in " | wc -l` +invalid_read=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "Invalid read of " | wc -l` +invalid_write=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "Invalid write of " | wc -l` +invalid_free=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "Invalid free() " | wc -l` + +if [ $DETAIL -eq 1 ]; then + echo error_summary: $error_summary + echo still_reachable: $still_reachable + echo definitely_lost: $definitely_lost + echo indirectly_lost: $indirectly_lost + echo possibly_lost: $possibly_lost + echo invalid_read: $invalid_read + echo invalid_write: $invalid_write + echo invalid_free: $invalid_free +fi -#errors=`grep "ERROR SUMMARY:" ${LOG_DIR}/valgrind-taosd-*.log | cut -d ' ' -f 2,3,4,5 | tr -d "\n"` -errors=`cat ${LOG_DIR}/valgrind-taosd-*.log | grep "ERROR SUMMARY:" | awk '{print $4}' | awk '{sum+=$1}END{print sum}'` +let "errors=$error_summary+$still_reachable+$definitely_lost+$indirectly_lost+$possibly_lost+$invalid_read+$invalid_write+$invalid_free" echo $errors diff --git a/tests/script/tsim/query/read.sim b/tests/script/tsim/query/read.sim new file mode 100644 index 0000000000000000000000000000000000000000..c6bec2586d5be29cd0e77268957950444e716c6a --- /dev/null +++ b/tests/script/tsim/query/read.sim @@ -0,0 +1,335 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c wallevel -v 2 +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 + +print ========= start dnode1 as leader +system sh/exec.sh -n dnode1 -s start +sleep 2000 +sql connect + +sql create database abc1 vgroups 2; +sql use abc1; +sql create table st1 (ts timestamp, k int, x int, y int, z binary(12), u nchar(12)) tags(a int, b nchar(12), c varchar(24), d bool) sma(x); +sql create table tu using st1 tags(1, 'abc', 'binary1', true); +sql create table tu1 using st1 tags(2, '水木', 'binary2', false); +sql create table tu2 using st1 tags(3, '水木1', 'binary3', true); +sql create table tu3 using st1 tags(4, 'abc', '12', false); +sql insert into tu values('2022-01-01 1:1:1', 1, 10, 9, 'a', '水3木') ('2022-07-02 22:46:53.294', 2, 10, 8, 'a', '水1木') ('2022-07-02 22:47:53.294', 1, 10, 7, 'b', '水2木')('2022-07-02 22:48:53.294', 1, 10, null, 'd', '3')('2022-07-02 22:50:53.294', 1, 10, null, null, '322'); +sql insert into tu1 values('2022-01-01 1:1:1', 11, 101, 91, 'aa', '3水木'); +sql insert into tu2 values('2022-01-01 1:1:1', 111, 1010, 919, 'aaa', '3水木3'); + +sql select * from tu; +if $rows != 5 then + return -1 +endi + +sql select * from tu order by ts desc; +if $rows != 5 then + return -1 +endi + +sql create table st2 (ts timestamp, k int, x int, y int, z binary(12), u nchar(12)) tags(a int) sma(x); +sql create table tuu1 using st2 tags(2); +sql insert into tuu1 values('2022-01-01 1:1:1', 11, 101, 911, 'aa', '3水木33'); +sql insert into tuu1 values('2022-01-01 1:1:2', NULL, 101, 911, 'aa', '3水木33'); +sql insert into tu values('2022-01-01 1:1:1', NULL, NULL, NULL, NULL, '水3木'); +sql insert into tu values('2022-01-01 1:1:1', NULL, 911, NULL, NULL, ''); +sql flush database abc1; + +sql insert into tu values('2021-12-1 1:1:1', 1,1,1,'a', 12); +sql insert into tu values('2022-6-1 1:1:1', 1,1,1,'a', 12); +sql insert into tu values('2022-6-1 1:1:2', 1,1,1,'a', 12); +sql insert into tu values('2022-6-1 1:1:3', 1,1,1,'a', 12); + +sql select * from tu order by ts desc; +if $rows != 9 then + return -1 +endi + +sql select * from tu order by ts asc; +if $rows != 9 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-1 1:1:0' order by ts asc; +if $rows != 0 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-1 1:1:0' order by ts desc; +if $rows != 0 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-1 1:1:2' order by ts asc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-1 1:1:2' order by ts desc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-1 1:1:2' order by ts asc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-1 1:10:2' order by ts desc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-1 1:10:2' order by ts asc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-9 1:10:2' order by ts desc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<'2022-1-9 1:10:2' order by ts asc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-1-9 1:10:2' order by ts asc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-1-9 1:10:2' order by ts desc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-9 1:10:2' order by ts asc; +if $rows != 4 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-9 1:10:2' order by ts desc; +if $rows != 4 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:10:2' order by ts asc; +if $rows != 4 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:10:2' order by ts desc; +if $rows != 4 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:1' order by ts asc; +if $row != 2 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:1' order by ts desc; +if $row != 2 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' order by ts asc; +if $rows != 8 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' order by ts desc; +if $rows != 8 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' order by ts asc; +if $rows != 9 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' order by ts desc; +if $rows != 9 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:2' order by ts asc; +if $rows != 3 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:2' order by ts desc; +if $rows != 3 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:1' order by ts asc; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:1' order by ts desc; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:0' order by ts asc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-31 1:1:1' and ts<='2022-6-1 1:1:0' order by ts desc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-6-1 1:1:0' order by ts asc; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-6-1 1:1:0' order by ts desc; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-1 1:1:0' order by ts asc; +if $rows != 5 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-1 1:1:0' order by ts desc; +if $rows != 5 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-7 1:1:0' order by ts desc; +if $rows != 9 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-7 1:1:0' order by ts asc; +if $rows != 9 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-2 1:1:0' order by ts desc; +if $rows != 5 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-2 1:1:0' order by ts asc; +if $rows != 5 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-2 22:47:0' order by ts desc; +if $rows != 6 then + return -1 +endi + +sql select * from tu where ts>='2021-12-1 1:1:1' and ts<='2022-7-2 22:47:0' order by ts asc; +if $rows != 6 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:47:0' order by ts asc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:47:0' order by ts desc; +if $rows != 1 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-8-2 22:47:0' order by ts asc; +if $rows != 4 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-8-2 22:47:0' order by ts desc; +if $rows != 4 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:48:53.299' order by ts asc; +if $rows != 3 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:48:53.299' order by ts desc; +if $rows != 3 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:48:53.293'; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:48:53.293' order by ts desc; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:48:53.292' order by ts asc; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:48:53.292' order by ts desc; +if $rows != 2 then + return -1 +endi + +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<='2022-7-2 22:48:53.294'; +sql select * from tu where ts>='2022-7-1 1:1:1' and ts<'2022-7-2 22:48:53.294'; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:48:53.294'; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<='2022-7-2 22:47:53.294'; + +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<='2022-7-2 22:47:53.293' order by ts asc; + +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<='2022-7-2 22:47:53.293' order by ts desc; + +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<='2022-7-2 22:48:53.293' order by ts asc; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<='2022-7-2 22:48:53.293' order by ts desc; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<='2022-7-2 22:48:53.293' order by ts desc; +sql select * from tu where ts>='2022-7-1 22:46:55' and ts<='2022-7-2 22:48:53.293' order by ts desc; +sql select * from tu where ts>='2022-7-1 22:46:55' and ts<='2022-7-2 22:48:53.293' order by ts asc; +sql select * from tu where ts>='2022-7-1 22:46:55' and ts<='2022-7-2 22:48:53.293' order by ts desc; + +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:47:53.294'; + +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:48:53.294'; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:48:53.294' order by ts desc; + +sql select * from tu where ts>='2022-7-1 22:46:55' and ts<'2022-7-2 22:48:53.294' order by ts desc; +sql select * from tu where ts>='2021-12-2 22:46:55' and ts<'2022-7-2 22:48:53.294' order by ts desc; + +sql select * from tu where ts>='2021-12-2 22:46:55' and ts<'2022-7-2 22:48:53.294' order by ts asc; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:46:59.294' order by ts asc; + +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:46:59.294' order by ts asc; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:46:59.294' order by ts asc; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:46:59.294' order by ts desc; + +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:46:59.294' order by ts desc; + +sql select * from tu where ts>='2021-7-2 22:46:55' and ts<'2022-7-2 22:46:54.294' order by ts desc; + +sql select * from tu where ts>='2021-12-2 22:46:55' and ts<'2022-7-2 22:46:54.294' order by ts desc; +sql select * from tu where ts>='2022-7-2 22:46:55' and ts<'2022-7-2 22:46:54.294' order by ts desc; + +sql select * from tu where ts>='2022-7-2 22:46:51' and ts<'2022-7-2 22:48:54.294' order by ts desc; +sql select * from tu where ts>='2022-7-2 22:46:51' and ts<'2022-7-2 22:48:54.294' order by ts asc; +sql select * from tu where ts>='2022-7-2 22:46:51' and ts<'2022-7-2 22:58:54.294' order by ts asc; + +sql select * from tu where ts>='2022-7-2 22:46:51' and ts<'2022-7-2 22:58:54.294' order by ts asc; + +sql select * from tu where ts>='2022-7-2 22:46:51' and ts<'2022-7-2 22:58:54.294' order by ts desc; diff --git a/tests/script/tsim/stable/alter_count.sim b/tests/script/tsim/stable/alter_count.sim index eca8ca1559405f8e9266b987536c598d1fcc97cd..decad53f6454d8fa1dd8f8907d0ffd542049820f 100644 --- a/tests/script/tsim/stable/alter_count.sim +++ b/tests/script/tsim/stable/alter_count.sim @@ -150,6 +150,7 @@ endi sql select count(a), count(b), count(c), count(d), count(e), count(f), count(g), count(h) from tb if $data01 != 21 then + print expect 21, actual $data01 return -1 endi diff --git a/tests/script/tsim/stream/distributeInterval0.sim b/tests/script/tsim/stream/distributeInterval0.sim index 1c0d0a3bd7b32a3fed62a714c36cede0524c4d52..ab2ca92c86b0d543631be0463e59668ac6470a5a 100644 --- a/tests/script/tsim/stream/distributeInterval0.sim +++ b/tests/script/tsim/stream/distributeInterval0.sim @@ -97,23 +97,23 @@ if $data01 != 8 then goto loop1 endi -if $data02 != 4 then +if $data02 != 6 then print =====data02=$data02 goto loop1 endi -if $data03 != 4 then - print ======$data03 +if $data03 != 52 then + print ======data03=$data03 goto loop1 endi if $data04 != 52 then - print ======$data04 + print ======data04=$data04 goto loop1 endi if $data05 != 13 then - print ======$data05 + print ======data05=$data05 goto loop1 endi diff --git a/tests/script/tsim/testsuit.sim b/tests/script/tsim/testsuit.sim index 1636bb38c800350a2b39a26d5dcd9a25ab56dc23..e0c46ae5fe59f62cdf0c3a152a83fef7ceb76c02 100644 --- a/tests/script/tsim/testsuit.sim +++ b/tests/script/tsim/testsuit.sim @@ -1,9 +1,7 @@ -run tsim/user/pass_alter.sim -run tsim/user/basic1.sim -run tsim/user/privilege2.sim -run tsim/user/user_len.sim -run tsim/user/privilege1.sim -run tsim/user/pass_len.sim +run tsim/user/password.sim +run tsim/user/privilege_db.sim +run tsim/user/privilege_sysinfo.sim +run tsim/user/basic.sim run tsim/table/basic1.sim run tsim/trans/lossdata1.sim run tsim/trans/create_db.sim @@ -26,18 +24,23 @@ run tsim/stable/values.sim run tsim/stable/dnode3.sim run tsim/stable/alter_insert1.sim run tsim/stable/refcount.sim +run tsim/stable/tag_filter.sim run tsim/stable/disk.sim run tsim/db/basic1.sim run tsim/db/basic3.sim run tsim/db/basic7.sim run tsim/db/basic6.sim +run tsim/db/alter_replica_13.sim run tsim/db/create_all_options.sim run tsim/db/basic2.sim run tsim/db/error1.sim +run tsim/db/alter_replica_31.sim run tsim/db/taosdlog.sim run tsim/db/alter_option.sim run tsim/mnode/basic1.sim -#run tsim/mnode/basic3.sim +run tsim/mnode/basic4.sim +run tsim/mnode/basic3.sim +run tsim/mnode/basic5.sim run tsim/mnode/basic2.sim run tsim/parser/fourArithmetic-basic.sim run tsim/parser/groupby-basic.sim @@ -57,11 +60,12 @@ run tsim/query/complex_group.sim run tsim/query/interval.sim run tsim/query/session.sim run tsim/query/scalarFunction.sim -#run tsim/query/scalarNull.sim +run tsim/query/scalarNull.sim run tsim/query/complex_where.sim run tsim/tmq/basic1.sim run tsim/tmq/basic4.sim run tsim/tmq/basic1Of2Cons.sim +run tsim/tmq/snapshot.sim run tsim/tmq/prepareBasicEnv-1vgrp.sim run tsim/tmq/topic.sim run tsim/tmq/basic4Of2Cons.sim @@ -73,14 +77,36 @@ run tsim/tmq/basic3Of2Cons.sim run tsim/tmq/basic2Of2ConsOverlap.sim run tsim/tmq/clearConsume.sim run tsim/qnode/basic1.sim -run tsim/dnode/basic1.sim +run tsim/dnode/redistribute_vgroup_replica3_v3.sim +run tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim +run tsim/dnode/redistribute_vgroup_replica3_v2.sim +run tsim/dnode/drop_dnode_has_mnode.sim +run tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim +run tsim/dnode/drop_dnode_has_vnode_replica1.sim +run tsim/dnode/balance_replica3.sim +run tsim/dnode/redistribute_vgroup_replica1.sim +run tsim/dnode/drop_dnode_has_vnode_replica3.sim +run tsim/dnode/balance_replica1.sim +run tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim +run tsim/dnode/drop_dnode_has_qnode_snode.sim +run tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim +run tsim/dnode/create_dnode.sim +run tsim/testsuit.sim run tsim/show/basic.sim run tsim/stream/basic1.sim +run tsim/stream/windowClose.sim +run tsim/stream/partitionby1.sim run tsim/stream/triggerInterval0.sim run tsim/stream/triggerSession0.sim +run tsim/stream/distributeIntervalRetrive0.sim run tsim/stream/basic0.sim run tsim/stream/session0.sim +run tsim/stream/schedSnode.sim +run tsim/stream/partitionby.sim run tsim/stream/session1.sim +run tsim/stream/distributeInterval0.sim +run tsim/stream/distributeSession0.sim +run tsim/stream/state0.sim run tsim/stream/basic2.sim run tsim/insert/basic1.sim run tsim/insert/commit-merge0.sim @@ -88,15 +114,18 @@ run tsim/insert/basic0.sim run tsim/insert/update0.sim run tsim/insert/backquote.sim run tsim/insert/null.sim +run tsim/catalog/alterInCurrent.sim run tsim/sync/oneReplica1VgElectWithInsert.sim run tsim/sync/threeReplica1VgElect.sim run tsim/sync/oneReplica1VgElect.sim run tsim/sync/3Replica5VgElect.sim +run tsim/sync/3Replica5VgElect3mnodedrop.sim +run tsim/sync/3Replica5VgElect3mnode.sim run tsim/sync/insertDataByRunBack.sim run tsim/sync/oneReplica5VgElect.sim run tsim/sync/3Replica1VgElect.sim run tsim/sync/threeReplica1VgElectWihtInsert.sim -run tsim/sma/tsmaCreateInsertData.sim +run tsim/sma/tsmaCreateInsertQuery.sim run tsim/sma/rsmaCreateInsertQuery.sim run tsim/valgrind/basic.sim run tsim/valgrind/checkError.sim diff --git a/tests/script/tsim/tmq/basic1.sim b/tests/script/tsim/tmq/basic1.sim index ee9e87cf047ae35cf771d1c92dc89b737bb584de..6880f290f5fda796cbf5b90f98cf5d40c1976eff 100644 --- a/tests/script/tsim/tmq/basic1.sim +++ b/tests/script/tsim/tmq/basic1.sim @@ -131,6 +131,7 @@ if $data[0][1] != $consumerId then return -1 endi if $data[0][2] != $expectmsgcnt then + print expect $expectmsgcnt , actual $data02 return -1 endi if $data[0][3] != $expectmsgcnt then diff --git a/tests/script/tsim/valgrind/basic.sim b/tests/script/tsim/valgrind/basic1.sim similarity index 59% rename from tests/script/tsim/valgrind/basic.sim rename to tests/script/tsim/valgrind/basic1.sim index fe7b6973d4ea0e42f0bce6051075669df5711b8d..c599263b5a852bddfa0b36a8eb1a0daadcdfe2ec 100644 --- a/tests/script/tsim/valgrind/basic.sim +++ b/tests/script/tsim/valgrind/basic1.sim @@ -9,17 +9,15 @@ step1: $x = $x + 1 sleep 1000 if $x == 10 then - print ====> dnode not ready! + print ----> dnode not ready! return -1 endi sql show dnodes -print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ----> $data00 $data01 $data02 $data03 $data04 $data05 if $rows != 1 then return -1 endi -goto _OVER - print =============== step2: create alter drop show user sql create user u1 pass 'taosdata' sql show users @@ -29,5 +27,17 @@ sql alter user u1 pass 'taosdata' sql drop user u1 sql_error alter user u2 sysinfo 0 +print =============== step3: create drop dnode +sql create dnode $hostname port 7200 +sql drop dnode 2 +sql alter dnode 1 'debugflag 143' + +print =============== step4: create alter drop show database +sql create database db vgroups 1 +sql show databases +sql show db.vgroups +sql drop database db +sql show databases + _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/valgrind/basic2.sim b/tests/script/tsim/valgrind/basic2.sim index 440873b89b84fe11015a4c32f6d9356c4177c8e6..ab25b7e0b77dc82e85a491f4cc849d8e437cbe73 100644 --- a/tests/script/tsim/valgrind/basic2.sim +++ b/tests/script/tsim/valgrind/basic2.sim @@ -9,11 +9,11 @@ step1: $x = $x + 1 sleep 1000 if $x == 10 then - print ====> dnode not ready! + print ----> dnode not ready! return -1 endi sql show dnodes -print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ----> $data00 $data01 $data02 $data03 $data04 $data05 if $rows != 1 then return -1 endi diff --git a/tests/script/tsim/valgrind/checkError.sim b/tests/script/tsim/valgrind/checkError.sim deleted file mode 100644 index 8798f80cd0bae203b0c910709cbc682695c342fa..0000000000000000000000000000000000000000 --- a/tests/script/tsim/valgrind/checkError.sim +++ /dev/null @@ -1,91 +0,0 @@ -system sh/stop_dnodes.sh -system sh/deploy.sh -n dnode1 -i 1 -#system sh/deploy.sh -n dnode2 -i 2 -#system sh/deploy.sh -n dnode3 -i 3 -#system sh/deploy.sh -n dnode4 -i 4 -#system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 -system sh/exec.sh -n dnode1 -s start -#system sh/exec.sh -n dnode2 -s start -#system sh/exec.sh -n dnode3 -s start -#system sh/exec.sh -n dnode4 -s start - -sleep 2000 - -#$loop_cnt = 0 -#check_dnode_ready: -# $loop_cnt = $loop_cnt + 1 -# sleep 200 -# if $loop_cnt == 10 then -# print ====> dnode not ready! -# return -1 -# endi -#sql show dnodes -#print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] -#print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] -#print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] -#print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] -#if $data[0][0] != 1 then -# return -1 -#endi -#if $data[0][4] != ready then -# goto check_dnode_ready -#endi -# -##sql connect -#sql create dnode $hostname port 7200 -#sql create dnode $hostname port 7300 -#sql create dnode $hostname port 7400 -# -#$loop_cnt = 0 -#check_dnode_ready_1: -#$loop_cnt = $loop_cnt + 1 -#sleep 200 -#if $loop_cnt == 10 then -# print ====> dnodes not ready! -# return -1 -#endi -#sql show dnodes -#print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] -#print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] -#print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] -#print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] -#if $data[0][4] != ready then -# goto check_dnode_ready_1 -#endi -#if $data[1][4] != ready then -# goto check_dnode_ready_1 -#endi -#if $data[2][4] != ready then -# goto check_dnode_ready_1 -#endi -#if $data[3][4] != ready then -# goto check_dnode_ready_1 -#endi - -#=========== please add any actions above ================= - -print ====> stop all dondes to output valgrind log file -system sh/exec.sh -n dnode1 -s stop -x SIGINT - -print ====> start to check if there are ERRORS in vagrind log file for each dnode -# -n : dnode[x] be check -system_content sh/checkValgrind.sh -n dnode1 -print cmd return result----> [ $system_content ] -# temporarily expand the threshold, since no time to fix the memory leaks. -if $system_content <= 5 then - return 0 -endi - -# This error occurs frequently, allowing it -# ==435850== 46 bytes in 1 blocks are definitely lost in loss record 1 of 3 -# ==435850== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgp reload_memcheck-amd64-linux.so) -# ==435850== by 0x414AE0: taosMemoryCalloc (osMemory.c:212) -# ==435850== by 0x352730: transAllocBuffer (transComm.c:123) -# ==435850== by 0x34F42A: cliAllocRecvBufferCb (transCli.c:485) - -$null= -if $system_content == $null then - return 0 -endi - -return -1 diff --git a/tests/script/tsim/valgrind/checkError1.sim b/tests/script/tsim/valgrind/checkError1.sim new file mode 100644 index 0000000000000000000000000000000000000000..10c9cb5d6f74c906e7c45466ccffa9b6e0ca95c5 --- /dev/null +++ b/tests/script/tsim/valgrind/checkError1.sim @@ -0,0 +1,50 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start -v +sql connect + +print =============== step1: show dnodes + +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ----> dnode not ready! + return -1 + endi +sql show dnodes +print ----> $data00 $data01 $data02 $data03 $data04 $data05 +if $rows != 1 then + return -1 +endi + +print =============== step2: create alter drop show user +sql create user u1 pass 'taosdata' +sql show users +sql alter user u1 sysinfo 1 +sql alter user u1 enable 1 +sql alter user u1 pass 'taosdata' +sql drop user u1 +sql_error alter user u2 sysinfo 0 + +print =============== step3: + +print =============== stop +system sh/exec.sh -n dnode1 -s stop -x SIGINT + +print =============== check +print ----> start to check if there are ERRORS in vagrind log file for each dnode +system_content sh/checkValgrind.sh -n dnode1 + +print cmd return result ----> [ $system_content ] +if $system_content <= 40 then + return 0 +endi + +$null= +if $system_content == $null then + return 0 +endi + +return -1 diff --git a/tests/script/tsim/valgrind/checkError2.sim b/tests/script/tsim/valgrind/checkError2.sim new file mode 100644 index 0000000000000000000000000000000000000000..cfc502bf3edb93666d1f29a1704ef135d8dd9667 --- /dev/null +++ b/tests/script/tsim/valgrind/checkError2.sim @@ -0,0 +1,41 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start -v +sql connect + +print =============== step1: create drop show dnodes +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ----> dnode not ready! + return -1 + endi +sql show dnodes +print ----> $data00 $data01 $data02 $data03 $data04 $data05 +if $rows != 1 then + return -1 +endi + +print =============== step2: create db +sql create database db vgroups 1 + +_OVER: +system sh/exec.sh -n dnode1 -s stop -x SIGINT + +print =============== check +print ----> start to check if there are ERRORS in vagrind log file for each dnode +system_content sh/checkValgrind.sh -n dnode1 + +print cmd return result ----> [ $system_content ] +if $system_content <= 60 then + return 0 +endi + +$null= +if $system_content == $null then + return 0 +endi + +return -1 diff --git a/tests/system-test/0-others/udfTest.py b/tests/system-test/0-others/udfTest.py index 40f803432a134a77f06cc3ba38efaa9a5d7060a6..ddbbd9b2de88e401f64531b451ff0720b2107615 100644 --- a/tests/system-test/0-others/udfTest.py +++ b/tests/system-test/0-others/udfTest.py @@ -313,11 +313,11 @@ class TDTestCase: tdSql.checkRows(1) tdSql.query("select udf1(num1) , bottom(num1,1) from tb;") tdSql.checkRows(1) - tdSql.query("select udf1(num1) , last_row(num1) from tb;") - tdSql.checkRows(1) + # tdSql.query("select udf1(num1) , last_row(num1) from tb;") + # tdSql.checkRows(1) - tdSql.query("select round(num1) , last_row(num1) from tb;") - tdSql.checkRows(1) + # tdSql.query("select round(num1) , last_row(num1) from tb;") + # tdSql.checkRows(1) # stable @@ -342,10 +342,10 @@ class TDTestCase: tdSql.query("select ceil(c1) , bottom(c1,1) from stb1;") tdSql.checkRows(1) - tdSql.query("select udf1(c1) , last_row(c1) from stb1;") - tdSql.checkRows(1) - tdSql.query("select ceil(c1) , last_row(c1) from stb1;") - tdSql.checkRows(1) + # tdSql.query("select udf1(c1) , last_row(c1) from stb1;") + # tdSql.checkRows(1) + # tdSql.query("select ceil(c1) , last_row(c1) from stb1;") + # tdSql.checkRows(1) # regular table with compute functions diff --git a/tests/system-test/0-others/udf_create.py b/tests/system-test/0-others/udf_create.py index 63650d6edcce63c6111f078b35876b6a5c8dfeb6..e53ed651f09158c402d07435ab596357cbba49e3 100644 --- a/tests/system-test/0-others/udf_create.py +++ b/tests/system-test/0-others/udf_create.py @@ -315,11 +315,11 @@ class TDTestCase: tdSql.checkRows(1) tdSql.query("select udf1(num1) , bottom(num1,1) from tb;") tdSql.checkRows(1) - tdSql.query("select udf1(num1) , last_row(num1) from tb;") - tdSql.checkRows(1) + # tdSql.query("select udf1(num1) , last_row(num1) from tb;") + # tdSql.checkRows(1) - tdSql.query("select round(num1) , last_row(num1) from tb;") - tdSql.checkRows(1) + # tdSql.query("select round(num1) , last_row(num1) from tb;") + # tdSql.checkRows(1) # stable @@ -344,10 +344,10 @@ class TDTestCase: tdSql.query("select ceil(c1) , bottom(c1,1) from stb1;") tdSql.checkRows(1) - tdSql.query("select udf1(c1) , last_row(c1) from stb1;") - tdSql.checkRows(1) - tdSql.query("select ceil(c1) , last_row(c1) from stb1;") - tdSql.checkRows(1) + # tdSql.query("select udf1(c1) , last_row(c1) from stb1;") + # tdSql.checkRows(1) + # tdSql.query("select ceil(c1) , last_row(c1) from stb1;") + # tdSql.checkRows(1) # regular table with compute functions diff --git a/tests/system-test/0-others/udf_restart_taosd.py b/tests/system-test/0-others/udf_restart_taosd.py index c318980b6750ca36f3d3894a8673d9a5cb54bc4c..b860a0dfabeb562c1e2e83a02c613aaa1cb29f17 100644 --- a/tests/system-test/0-others/udf_restart_taosd.py +++ b/tests/system-test/0-others/udf_restart_taosd.py @@ -312,11 +312,11 @@ class TDTestCase: tdSql.checkRows(1) tdSql.query("select udf1(num1) , bottom(num1,1) from tb;") tdSql.checkRows(1) - tdSql.query("select udf1(num1) , last_row(num1) from tb;") - tdSql.checkRows(1) + # tdSql.query("select udf1(num1) , last_row(num1) from tb;") + # tdSql.checkRows(1) - tdSql.query("select round(num1) , last_row(num1) from tb;") - tdSql.checkRows(1) + # tdSql.query("select round(num1) , last_row(num1) from tb;") + # tdSql.checkRows(1) # stable @@ -341,10 +341,10 @@ class TDTestCase: tdSql.query("select ceil(c1) , bottom(c1,1) from stb1;") tdSql.checkRows(1) - tdSql.query("select udf1(c1) , last_row(c1) from stb1;") - tdSql.checkRows(1) - tdSql.query("select ceil(c1) , last_row(c1) from stb1;") - tdSql.checkRows(1) + # tdSql.query("select udf1(c1) , last_row(c1) from stb1;") + # tdSql.checkRows(1) + # tdSql.query("select ceil(c1) , last_row(c1) from stb1;") + # tdSql.checkRows(1) # regular table with compute functions diff --git a/tests/system-test/1-insert/alter_stable.py b/tests/system-test/1-insert/alter_stable.py index a4cec781384818b777abf1b90a31d6c88f51693a..b66cbb89c0796416d033294a1c9ae9d92afb1dc1 100644 --- a/tests/system-test/1-insert/alter_stable.py +++ b/tests/system-test/1-insert/alter_stable.py @@ -108,8 +108,8 @@ class TDTestCase: tdSql.error(f'alter stable {self.stbname}_{i} add column {key} {values}') tdSql.error(f'alter stable {self.stbname}_{i} drop column {key}') #! bug TD-16921 - #tdSql.error(f'alter stable {self.ntbname} add column {key} {values}') - #tdSql.error(f'alter stable {self.ntbname} drop column {key}') + tdSql.error(f'alter stable {self.ntbname} add column {key} {values}') + tdSql.error(f'alter stable {self.ntbname} drop column {key}') tdSql.execute(f'alter stable {self.stbname} drop column {key}') tdSql.query(f'describe {self.stbname}') tdSql.checkRows(len(self.column_dict)+len(self.tag_dict)) @@ -132,7 +132,7 @@ class TDTestCase: tdSql.checkEqual(result[0][2],self.binary_length+1) tdSql.error(f'alter stable {self.stbname}_{i} modify column {key} {v}') #! bug TD-16921 - # tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}') + tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}') elif 'nchar' in values.lower(): v = f'nchar({self.binary_length+1})' v_error = f'nchar({self.binary_length-1})' @@ -147,11 +147,11 @@ class TDTestCase: tdSql.checkEqual(result[0][2],self.binary_length+1) tdSql.error(f'alter stable {self.stbname}_{i} modify column {key} {v}') #! bug TD-16921 - #tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}') + tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}') else: for v in self.column_dict.values(): tdSql.error(f'alter stable {self.stbname} modify column {key} {v}') - # tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}') + tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}') for i in range(self.tbnum): tdSql.error(f'alter stable {self.stbname}_{i} modify column {key} {v}') def run(self): diff --git a/tests/system-test/1-insert/create_retentions.py b/tests/system-test/1-insert/create_retentions.py index db902d0031906b79febab9380a82b290c665bffe..e333dafa289fc44a2bcb200844f22ba079f1eba6 100644 --- a/tests/system-test/1-insert/create_retentions.py +++ b/tests/system-test/1-insert/create_retentions.py @@ -87,29 +87,29 @@ class TDTestCase: @property def create_stable_sql_err(self): return [ - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(ceil) watermark 1s max_delay 1m", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(count) watermark 1min", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay -1s", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark -1m", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) max_delay 1m ", - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} binary(16)) tags (tag1 int) rollup(avg) watermark 1s", - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) tags (tag1 int) rollup(avg) max_delay 1m", - # f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) rollup(avg) watermark 1s max_delay 1s", - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) tags (tag1 int) " , - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) " , - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) " , - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) " , + f"create stable stb11 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(ceil) watermark 1s max_delay 1m", + f"create stable stb12 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(count) watermark 1min", + f"create stable stb13 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay -1s", + f"create stable stb14 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark -1m", + f"create stable stb15 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ", + f"create stable stb16 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) max_delay 1m ", + f"create stable stb21 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} binary(16)) tags (tag1 int) rollup(avg) watermark 1s", + f"create stable stb22 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) tags (tag1 int) rollup(avg) max_delay 1m", + f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) rollup(avg) watermark 1s max_delay 1s", + f"create stable stb23 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) tags (tag1 int) " , + f"create stable stb24 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) " , + f"create stable stb25 ({PRIMARY_COL} timestamp, {INT_COL} int) " , + f"create stable stb26 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) " , # watermark, max_delay: [0, 900000], [ms, s, m, ?] - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1u", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 1b", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 900001ms", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 16m", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 901s", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1h", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 0.2h", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 0.002d", + f"create stable stb17 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1u", + f"create stable stb18 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 1b", + f"create stable stb19 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 900001ms", + f"create stable stb20 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 16m", + f"create stable stb27 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 901s", + f"create stable stb28 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1h", + f"create stable stb29 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 0.2h", + f"create stable stb30 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 0.002d", ] @@ -125,8 +125,8 @@ class TDTestCase: f"create stable stb7 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL})", ] - def test_create_stb(self): - tdSql.execute("use db2") + def test_create_stb(self, db="db2"): + tdSql.execute(f"use {db}") for err_sql in self.create_stable_sql_err: tdSql.error(err_sql) for cur_sql in self.create_stable_sql_current: @@ -136,7 +136,7 @@ class TDTestCase: tdSql.checkRows(len(self.create_stable_sql_current)) tdSql.execute("use db") # because db is a noraml database, not a rollup database, should not be able to create a rollup stable - # tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 5s max_delay 1m") + tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 5s max_delay 1m") def test_create_databases(self): @@ -255,6 +255,7 @@ class TDTestCase: tdSql.execute("drop database if exists db2 ") tdSql.execute("use db3") + self.test_create_stb(db="db3") # self.__create_tb() # self.__insert_data() self.all_test() diff --git a/tests/system-test/1-insert/test_stmt_muti_insert_query.py b/tests/system-test/1-insert/test_stmt_muti_insert_query.py index de10b2f6b9b848907799eb86fff9b26e1d2f192e..9fb802b96b43f30108119e9a2d4d4e70ed6e70f3 100644 --- a/tests/system-test/1-insert/test_stmt_muti_insert_query.py +++ b/tests/system-test/1-insert/test_stmt_muti_insert_query.py @@ -96,7 +96,7 @@ class TDTestCase: ff float, dd double, bb binary(100), nn nchar(100), tt timestamp)", ) # conn.load_table_info("log") - + tdLog.debug("statement start") start = datetime.now() stmt = conn.statement("insert into stb1 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") @@ -118,8 +118,11 @@ class TDTestCase: params[14].nchar(["涛思数据", None, "a long string with 中文字符"]) params[15].timestamp([None, None, 1626861392591]) # print(type(stmt)) + tdLog.debug("bind_param_batch start") stmt.bind_param_batch(params) + tdLog.debug("bind_param_batch end") stmt.execute() + tdLog.debug("execute end") end = datetime.now() print("elapsed time: ", end - start) assert stmt.affected_rows == 3 @@ -155,7 +158,7 @@ class TDTestCase: print(rows1) assert str(rows1[0][0]) == "2021-07-21 17:56:32.589000" assert rows1[0][10] == 3 - + tdLog.debug("close start") stmt.close() diff --git a/tests/system-test/1-insert/test_stmt_set_tbname_tag.py b/tests/system-test/1-insert/test_stmt_set_tbname_tag.py index 387492c4d6ac7b72e95db777d727b8f96ff2ce56..a329b475db6e23351bb177a1bc07cbf320686433 100644 --- a/tests/system-test/1-insert/test_stmt_set_tbname_tag.py +++ b/tests/system-test/1-insert/test_stmt_set_tbname_tag.py @@ -218,13 +218,13 @@ class TDTestCase: tdLog.debug("assert 8th case %s"%rows) assert rows[0][0] == 3, ' 8th case is failed' - # #query: selector Functions 9 - # queryparam=new_bind_params(1) - # queryparam[0].int(2) - # rows=self.stmtExe(conn,"select bottom(bu,?) from log group by bu ; ",queryparam) - # tdLog.debug("assert 9th case %s"%rows) - # assert rows[0][0] == 4, ' 9 case is failed' - # assert rows[1][0] == 3, ' 9 case is failed' + #query: selector Functions 9 + queryparam=new_bind_params(1) + queryparam[0].int(2) + rows=self.stmtExe(conn,"select bottom(bu,?) from log group by bu order by bu desc ; ",queryparam) + tdLog.debug("assert 9th case %s"%rows) + assert rows[1][0] == 4, ' 9 case is failed' + assert rows[2][0] == 3, ' 9 case is failed' # #query: time-series specific Functions 10 diff --git a/tests/system-test/2-query/Timediff.py b/tests/system-test/2-query/Timediff.py index b8f3649eff7edfdd20c0d1a06fa25657c83f74c0..9c595a8c8c20b6fc7821fbef2a95db66396c9e36 100644 --- a/tests/system-test/2-query/Timediff.py +++ b/tests/system-test/2-query/Timediff.py @@ -1,202 +1,171 @@ from util.log import * from util.sql import * from util.cases import * - +from util.gettime import * class TDTestCase: def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - + self.get_time = GetTime() + self.ts_str = [ + '2020-1-1', + '2020-2-1 00:00:01', + '2020-3-1 00:00:00.001', + '2020-4-1 00:00:00.001002', + '2020-5-1 00:00:00.001002001' + + ] + self.db_param_precision = ['ms','us','ns'] + self.time_unit = ['1w','1d','1h','1m','1s','1a','1u','1b'] + self.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1'] + self.ntbname = 'ntb' + self.stbname = 'stb' + self.ctbname = 'ctb' + self.subtractor = 1 # unit:s + def check_tbtype(self,tb_type): + if tb_type.lower() == 'ntb': + tdSql.query(f'select timediff(ts,{self.subtractor}) from {self.ntbname}') + elif tb_type.lower() == 'ctb': + tdSql.query(f'select timediff(ts,{self.subtractor}) from {self.ctbname}') + elif tb_type.lower() == 'stb': + tdSql.query(f'select timediff(ts,{self.subtractor}) from {self.stbname}') + def check_tb_type(self,unit,tb_type): + if tb_type.lower() == 'ntb': + tdSql.query(f'select timediff(ts,{self.subtractor},{unit}) from {self.ntbname}') + elif tb_type.lower() == 'ctb': + tdSql.query(f'select timediff(ts,{self.subtractor},{unit}) from {self.ctbname}') + elif tb_type.lower() == 'stb': + tdSql.query(f'select timediff(ts,{self.subtractor},{unit}) from {self.stbname}') + def data_check(self,date_time,precision,tb_type): + for unit in self.time_unit: + if (unit.lower() == '1u' and precision.lower() == 'ms') or (unit.lower() == '1b' and precision.lower() == 'us') or (unit.lower() == '1b' and precision.lower() == 'ms'): + if tb_type.lower() == 'ntb': + tdSql.error(f'select timediff(ts,{self.subtractor},{unit}) from {self.ntbname}') + elif tb_type.lower() == 'ctb': + tdSql.error(f'select timediff(ts,{self.subtractor},{unit}) from {self.ctbname}') + elif tb_type.lower() == 'stb': + tdSql.error(f'select timediff(ts,{self.subtractor},{unit}) from {self.stbname}') + elif precision.lower() == 'ms': + self.check_tb_type(unit,tb_type) + tdSql.checkRows(len(self.ts_str)) + if unit.lower() == '1a': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i])-self.subtractor*1000) + elif unit.lower() == '1s': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]/1000)-self.subtractor) + elif unit.lower() == '1m': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000)-self.subtractor)/60)) + elif unit.lower() == '1h': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000)-self.subtractor)/60/60)) + elif unit.lower() == '1d': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000)-self.subtractor)/60/60/24)) + elif unit.lower() == '1w': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000)-self.subtractor)/60/60/24/7)) + self.check_tbtype(tb_type) + tdSql.checkRows(len(self.ts_str)) + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i])-self.subtractor*1000) + elif precision.lower() == 'us': + self.check_tb_type(unit,tb_type) + tdSql.checkRows(len(self.ts_str)) + if unit.lower() == '1w': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000)-self.subtractor)/60/60/24/7)) + elif unit.lower() == '1d': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000)-self.subtractor)/60/60/24)) + elif unit.lower() == '1h': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000)-self.subtractor)/60/60)) + elif unit.lower() == '1m': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000)-self.subtractor)/60)) + elif unit.lower() == '1s': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000)-self.subtractor))) + elif unit.lower() == '1a': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000)-self.subtractor*1000))) + elif unit.lower() == '1u': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000))) + self.check_tbtype(tb_type) + tdSql.checkRows(len(self.ts_str)) + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000))) + elif precision.lower() == 'ns': + self.check_tb_type(unit,tb_type) + tdSql.checkRows(len(self.ts_str)) + if unit.lower() == '1w': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000000)-self.subtractor)/60/60/24/7)) + elif unit.lower() == '1d': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000000)-self.subtractor)/60/60/24)) + elif unit.lower() == '1h': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000000)-self.subtractor)/60/60)) + elif unit.lower() == '1m': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000000)-self.subtractor)/60)) + elif unit.lower() == '1s': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000000)-self.subtractor))) + elif unit.lower() == '1a': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000)-self.subtractor*1000))) + elif unit.lower() == '1u': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000)-self.subtractor*1000000))) + self.check_tbtype(tb_type) + tdSql.checkRows(len(self.ts_str)) + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000000))) + for unit in self.error_unit: + if tb_type.lower() == 'ntb': + tdSql.error(f'select timediff(ts,{self.subtractor},{unit}) from {self.ntbname}') + tdSql.error(f'select timediff(c0,{self.subtractor},{unit}) from {self.ntbname}') + elif tb_type.lower() == 'ctb': + tdSql.error(f'select timediff(ts,{self.subtractor},{unit}) from {self.ctbname}') + tdSql.error(f'select timediff(c0,{self.subtractor},{unit}) from {self.ntbname}') + elif tb_type.lower() == 'stb': + tdSql.error(f'select timediff(ts,{self.subtractor},{unit}) from {self.stbname}') + tdSql.error(f'select timediff(c0,{self.subtractor},{unit}) from {self.ntbname}') + def function_check_ntb(self): + for precision in self.db_param_precision: + tdSql.execute('drop database if exists db') + tdSql.execute(f'create database db precision "{precision}"') + tdSql.execute('use db') + tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)') + for ts in self.ts_str: + tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)') + for unit in self.error_unit: + tdSql.error(f'select timediff(ts,{self.subtractor},{unit}) from {self.ntbname}') + date_time = self.get_time.time_transform(self.ts_str,precision) + self.data_check(date_time,precision,'ntb') + def function_check_stb(self): + for precision in self.db_param_precision: + tdSql.execute('drop database if exists db') + tdSql.execute(f'create database db precision "{precision}"') + tdSql.execute('use db') + tdSql.execute(f'create table {self.stbname} (ts timestamp,c0 int) tags(t0 int)') + tdSql.execute(f'create table {self.ctbname} using {self.stbname} tags(1)') + for ts in self.ts_str: + tdSql.execute(f'insert into {self.ctbname} values("{ts}",1)') + date_time = self.get_time.time_transform(self.ts_str,precision) + self.data_check(date_time,precision,'ctb') + self.data_check(date_time,precision,'stb') def run(self): # sourcery skip: extract-duplicate-method - tdSql.prepare() - tdLog.printNoPrefix("==========step1:create tables==========") - tdSql.execute( - '''create table if not exists ntb - (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) - ''' - ) - tdSql.execute( - '''create table if not exists stb - (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int) - ''' - ) - tdSql.execute( - '''create table if not exists stb_1 using stb tags(100) - ''' - ) - tdLog.printNoPrefix("==========step2:insert data into ntb==========") - - # RFC3339:2020-01-01T00:00:00+8:00 - # ISO8601:2020-01-01T00:00:00.000+0800 - tdSql.execute( - 'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - tdSql.execute( - 'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00') from ntb") - tdSql.checkRows(3) - tdSql.query("select timediff(1,0,1d) from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1d) from db.ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1s) from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1) - tdSql.query("select timediff(1,0,1s) from db.ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1) - tdSql.query("select timediff(1,0,1w) from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1w) from db.ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1h) from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1h) from db.ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1m) from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1m) from db.ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff(1,0,1a) from ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1000) - tdSql.query("select timediff(1,0,1a) from db.ntb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1000) - tdSql.error("select timediff(1,0,1u) from ntb") - #tdSql.checkRows(3) - #tdSql.checkData(0,0,1000000) - tdSql.error("select timediff(1,0,1u) from db.ntb") - #tdSql.checkRows(3) - #tdSql.checkData(0,0,1000000) - - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00') from stb") - tdSql.checkRows(3) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00') from db.stb") - tdSql.checkRows(3) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1d) from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1d) from db.stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1h) from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,24) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1h) from db.stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,24) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1w) from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1m) from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1440) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1m) from db.stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,1440) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1s) from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,86400) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1s) from db.stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,86400) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1a) from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,86400000) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1a) from db.stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,86400000) - tdSql.error("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1u) from stb") - #tdSql.checkRows(3) - #tdSql.checkData(0,0,86400000000) - tdSql.error("select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1u) from db.stb") - #tdSql.checkRows(3) - #tdSql.checkData(0,0,86400000000) - - - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00') from stb_1") - tdSql.checkRows(3) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00') from db.stb_1") - tdSql.checkRows(3) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1w) from stb_1 ") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1w) from db.stb_1 ") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1d) from stb_1 ") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1d) from db.stb_1 ") - tdSql.checkRows(3) - tdSql.checkData(0,0,0) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1h) from stb_1 ") - tdSql.checkRows(3) - tdSql.checkData(0,0,12) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1h) from db.stb_1 ") - tdSql.checkRows(3) - tdSql.checkData(0,0,12) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1m) from stb_1" ) - tdSql.checkRows(3) - tdSql.checkData(0,0,720) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1m) from db.stb_1" ) - tdSql.checkRows(3) - tdSql.checkData(0,0,720) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1s) from stb_1") - tdSql.checkRows(3) - tdSql.checkData(0,0,43200) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1s) from db.stb_1") - tdSql.checkRows(3) - tdSql.checkData(0,0,43200) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1a) from stb_1") - tdSql.checkRows(3) - tdSql.checkData(0,0,43200000) - tdSql.query("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1a) from db.stb_1") - tdSql.checkRows(3) - tdSql.checkData(0,0,43200000) - tdSql.error("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1u) from stb_1") - #tdSql.checkRows(3) - #tdSql.checkData(0,0,43200000000) - tdSql.error("select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1u) from db.stb_1") - #tdSql.checkRows(3) - #tdSql.checkData(0,0,43200000000) - - tdSql.query("select timediff('a','b') from stb") - tdSql.checkRows(3) - tdSql.checkData(0,0,None) - tdSql.checkData(1,0,None) - tdSql.checkData(2,0,None) - tdSql.error("select timediff(1.5,1.5) from stb") - tdSql.error("select timediff(1) from stb") - tdSql.error("select timediff(10,1,1.5) from stb") - # tdSql.error("select timediff(10,1,2s) from stb") - # tdSql.error("select timedifff(10,1,c1) from stb") - tdSql.error("select timediff(1.5,1.5) from stb_1") - tdSql.error("select timediff(1) from stb_1") - tdSql.error("select timediff(10,1,1.5) from stb_1") - # tdSql.error("select timediff(10,1,2s) from stb_1") - # tdSql.error("select timedifff(10,1,c1) from stb_1") - tdSql.error("select timediff(1.5,1.5) from ntb") - tdSql.error("select timediff(1) from ntb") - tdSql.error("select timediff(10,1,1.5) from ntb") - # tdSql.error("select timediff(10,1,2s) from ntb") - # tdSql.error("select timedifff(10,1,c1) from ntb") - - - - - + self.function_check_ntb() + self.function_check_stb() + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/system-test/2-query/and_or_for_byte.py b/tests/system-test/2-query/and_or_for_byte.py new file mode 100644 index 0000000000000000000000000000000000000000..28d3e1cf438f22740bbf25097f801c644037fb7c --- /dev/null +++ b/tests/system-test/2-query/and_or_for_byte.py @@ -0,0 +1,545 @@ +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * +import random + + +class TDTestCase: + updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, + "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, + "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "fnDebugFlag": 143} + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), True) + self.tb_nums = 10 + self.row_nums = 20 + self.ts = 1434938400000 + self.time_step = 1000 + + def insert_datas_and_check_abs(self ,tbnums , rownums , time_step ): + tdLog.info(" prepare datas for auto check abs function ") + + tdSql.execute(" create database test ") + tdSql.execute(" use test ") + tdSql.execute(" create stable stb (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint,\ + c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int)") + for tbnum in range(tbnums): + tbname = "sub_tb_%d"%tbnum + tdSql.execute(" create table %s using stb tags(%d) "%(tbname , tbnum)) + + ts = self.ts + for row in range(rownums): + ts = self.ts + time_step*row + c1 = random.randint(0,10000) + c2 = random.randint(0,100000) + c3 = random.randint(0,125) + c4 = random.randint(0,125) + c5 = random.random()/1.0 + c6 = random.random()/1.0 + c7 = "'true'" + c8 = "'binary_val'" + c9 = "'nchar_val'" + c10 = ts + tdSql.execute(f" insert into {tbname} values ({ts},{c1},{c2},{c3},{c4},{c5},{c6},{c7},{c8},{c9},{c10})") + + tdSql.execute("use test") + tbnames = ["stb", "sub_tb_1"] + support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] + for tbname in tbnames: + tdSql.query("desc {}".format(tbname)) + coltypes = tdSql.queryResult + colnames = [] + for coltype in coltypes: + colname = coltype[0] + if coltype[1] in support_types: + colnames.append(colname) + cols = random.sample(colnames,3) + self.check_function("&",False,tbname,cols[0],cols[1],cols[2]) + self.check_function("|",False,tbname,cols[0],cols[1],cols[2]) + + + def prepare_datas(self): + tdSql.execute( + '''create table stb1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + for i in range(9): + tdSql.execute( + f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute( + "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute( + "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into t1 values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ''' + ) + + def prepare_tag_datas(self): + # prepare datas + tdSql.execute( + "create database if not exists testdb keep 3650 duration 1000") + tdSql.execute(" use testdb ") + tdSql.execute( + '''create table stb1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) + ''' + ) + + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute( + f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + + for i in range(9): + tdSql.execute( + f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute( + "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute( + "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into t1 values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ''' + ) + + def check_result_auto(self, origin_query, abs_query): + abs_result = tdSql.getResult(abs_query) + origin_result = tdSql.getResult(origin_query) + + auto_result = [] + + for row in origin_result: + row_check = [] + for elem in row: + if elem == None: + elem = None + elif elem >= 0: + elem = elem + else: + elem = -elem + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + for row_index, row in enumerate(abs_result): + for col_index, elem in enumerate(row): + if auto_result[row_index][col_index] != elem: + check_status = False + if not check_status: + tdLog.notice( + "abs function value has not as expected , sql is \"%s\" " % abs_query) + sys.exit(1) + else: + tdLog.info( + "abs value check pass , it work as expected ,sql is \"%s\" " % abs_query) + + def check_function(self, opera ,agg, tbname , *args): + + if opera =="&": + pass + elif opera =="|": + pass + else: + pass + work_sql = " select " + for ind , arg in enumerate(args): + if ind ==len(args)-1: + work_sql += f"cast({arg} as bigint) " + else: + work_sql += f"cast({arg} as bigint){opera}" + + if not agg: + work_sql+= f" from {tbname} order by ts" + else: + work_sql+= f" from {tbname} " + tdSql.query(work_sql) + work_result = tdSql.queryResult + + origin_sql = " select " + for ind , arg in enumerate(args): + if ind ==len(args)-1: + origin_sql += f"cast({arg} as bigint) " + else: + origin_sql += f"cast({arg} as bigint)," + if not agg: + origin_sql+= f" from {tbname} order by ts" + else: + origin_sql+= f" from {tbname} " + tdSql.query(origin_sql) + origin_result = tdSql.queryResult + + # compute and or with byte in binary data + compute_result = [] + + for row in origin_result: + if None in row: + compute_result.append(None) + else: + if opera == "&": + result = row[0] + for elem in row: + result = result&elem + elif opera == "|": + result = row[0] + for elem in row: + result = result|elem + compute_result.append(result) + + tdSql.query(work_sql) + for ind , result in enumerate(compute_result): + tdSql.checkData(ind,0,result) + + def test_errors(self): + tdSql.execute("use testdb") + error_sql_lists = [ + "select c1&&c2 from t1", + "select c1&|c2 from t1", + "select c1&(c1=c2) from t1", + "select c1&* from t1", + "select 123&, from t1", + "select 123&\" from t1", + "select c1&- from t1;", + "select c1&&= from t1)", + "select c1&! from t1", + "select c1&@ from stb1", + "select c1&# from stb1", + "select c1&$ from stb1", + "select c1&% from stb1", + "select c1&() from stb1", + ] + for error_sql in error_sql_lists: + tdSql.error(error_sql) + + def basic_query(self): + # basic query + tdSql.query("select c1&c2|c3 from ct1") + tdSql.checkRows(13) + tdSql.query("select c1 ,c2&c3, c1&c2&c3 from t1") + tdSql.checkRows(12) + tdSql.query("select c1 ,c1&c1&c1|c1 from stb1") + tdSql.checkRows(25) + + # used for empty table , ct3 is empty + tdSql.query("select abs(c1)&c2&c3 from ct3") + tdSql.checkRows(0) + tdSql.query("select abs(c2&c1&c3) from ct3") + tdSql.checkRows(0) + tdSql.query("select abs(c3)+c1&c3+c2 from ct3") + tdSql.checkRows(0) + + tdSql.query("select abs(c1)&c2&c3 from ct4") + tdSql.checkRows(12) + tdSql.checkData(0,0,None) + tdSql.checkData(1,0,8) + tdSql.checkData(10,0,0) + tdSql.query("select abs(c2&c1&c3) from ct4") + tdSql.checkRows(12) + tdSql.checkData(0,0,None) + tdSql.checkData(1,0,8) + tdSql.checkData(10,0,0) + tdSql.query("select (abs(c3)+c1)&(c3+c2) from ct4") + tdSql.checkRows(12) + tdSql.checkData(0,0,None) + tdSql.checkData(1,0,640) + tdSql.checkData(10,0,0) + + # used for regular table + tdSql.query("select abs(c1)&c3&c3 from t1") + tdSql.checkData(0, 0, None) + tdSql.checkData(1, 0, 1) + tdSql.checkData(3, 0, 1) + tdSql.checkData(5, 0, None) + + tdSql.query("select abs(c1)&c2|ceil(c3)&c4|floor(c5) from t1") + tdSql.checkData(1, 0, 11) + tdSql.checkData(3, 0, 3) + tdSql.checkData(5, 0, None) + tdSql.query("select ts,c1, c2, c3&c4|c5 from t1") + tdSql.checkData(1, 3, 11) + tdSql.checkData(3, 3, 3) + tdSql.checkData(5, 3, None) + + self.check_function("&",False,"stb1","c1","ceil(c2)","abs(c3)","c4+1") + self.check_function("|",False,"stb1","c1","ceil(c2)","abs(c3)","c4+1") + self.check_function("&",False,"stb1","c1+c2","ceil(c2)","abs(c3+c2)","c4+1") + self.check_function("&",False,"ct4","123","ceil(c2)","abs(c3+c2)","c4+1") + self.check_function("&",False,"ct4","123","ceil(t1)","abs(c3+c2)","c4+1") + self.check_function("&",False,"ct4","t1+c1","-ceil(t1)","abs(c3+c2)","c4+1") + self.check_function("&",False,"stb1","c1","floor(t1)","abs(c1+c2)","t1+1") + self.check_function("&",True,"stb1","max(c1)","min(floor(t1))","sum(abs(c1+c2))","last(t1)+1") + self.check_function("&",False,"stb1","abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))))","floor(t1)","abs(c1+c2)","t1+1") + + # mix with common col + tdSql.query("select c1&abs(c1)&c2&c3 ,c1,c2, t1 from ct1") + tdSql.checkData(0, 0, 8) + tdSql.checkData(1, 0, 1) + tdSql.checkData(4, 0, 0) + tdSql.checkData(4, 3, 0) + tdSql.checkData(3, 2, 55555) + + + # mix with common functions + tdSql.query(" select c1&abs(c1)&c2&c3, abs(c1), c5, floor(c5) from ct4 ") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(0, 3, None) + + tdSql.checkData(3, 0, 2) + tdSql.checkData(3, 1, 6) + tdSql.checkData(3, 2, 6.66000) + tdSql.checkData(3, 3, 6.00000) + + tdSql.query("select c1&abs(c1)&c2&c3, abs(c1),c5, floor(c5) from stb1 order by ts ") + tdSql.checkData(3, 0, 2) + tdSql.checkData(3, 1, 6) + tdSql.checkData(3, 2, 6.66000) + tdSql.checkData(3, 3, 6.00000) + + # mix with agg functions , not support + tdSql.error("select c1&abs(c1)&c2&c3, abs(c1),c5, count(c5) from stb1 ") + tdSql.error("select c1&abs(c1)&c2&c3, abs(c1),c5, count(c5) from ct1 ") + tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from stb1 ") + tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from ct1 ") + tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from ct1 ") + tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from stb1 ") + + # agg functions mix with agg functions + + tdSql.query("select sum(c1&abs(c1)&c2&c3) ,max(c5), count(c5) from stb1") + + tdSql.query("select max(c1)&max(c2)|first(ts), count(c5) from ct1") + + # bug fix for compute + tdSql.query("select c1&abs(c1)&c2&c3, abs(c1&abs(c1)&c2&c3) -0 ,ceil(c1&abs(c1)&c2&c3)-0 from ct4 ") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 8.000000000) + + tdSql.query(" select c1&c2|c3, abs(c1&c2|c3) -0 ,ceil(c1&c2|c3-0.1)-0.1 from ct4") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 888) + tdSql.checkData(1, 1, 888.000000000) + tdSql.checkData(1, 2, 894.900000000) + + + + + def check_boundary_values(self): + + tdSql.execute("drop database if exists bound_test") + tdSql.execute("create database if not exists bound_test") + time.sleep(3) + tdSql.execute("use bound_test") + tdSql.execute( + "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + ) + tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.error( + f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + self.check_function("&", False , "sub1_bound" ,"c1","c2","c3","c4","c5","c6" ) + self.check_function("&", False ,"sub1_bound","abs(c1)","abs(c2)","abs(c3)","abs(c4)","abs(c5)","abs(c6)" ) + self.check_function("&", False ,"stb_bound","123","abs(c2)","t1","abs(c4)","abs(c5)","abs(c6)" ) + + # check basic elem for table per row + tdSql.query( + "select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from sub1_bound ") + tdSql.checkData(0, 0, 2147483647) + tdSql.checkData(0, 1, 9223372036854775807) + tdSql.checkData(0, 2, 32767) + tdSql.checkData(0, 3, 127) + tdSql.checkData(0, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(0, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(1, 0, 2147483647) + tdSql.checkData(1, 1, 9223372036854775807) + tdSql.checkData(1, 2, 32767) + tdSql.checkData(1, 3, 127) + tdSql.checkData(1, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(1, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(3, 0, 2147483646) + tdSql.checkData(3, 1, 9223372036854775806) + tdSql.checkData(3, 2, 32766) + tdSql.checkData(3, 3, 126) + tdSql.checkData(3, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(3, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + + # check + - * / in functions + self.check_function("&", False ,"stb_bound","abs(c1+1)","abs(c2)","t1","abs(c3*1)","abs(c5)/2","abs(c6)" ) + + tdSql.query( + "select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") + tdSql.checkData(0, 0, 2147483648.000000000) + tdSql.checkData(0, 1, 9223372036854775807) + tdSql.checkData(0, 2, 32767.000000000) + tdSql.checkData(0, 3, 63.500000000) + tdSql.checkData( + 0, 4, 169999997607218212453866206899682148352.000000000) + tdSql.checkData(0, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + + tdSql.checkData(1, 0, 2147483646.000000000) + tdSql.checkData(1, 1, 9223372036854775808.000000000) + tdSql.checkData(1, 2, 32767.000000000) + tdSql.checkData(1, 3, 63.500000000) + tdSql.checkData( + 1, 4, 169999997607218212453866206899682148352.000000000) + + + def test_tag_compute_for_scalar_function(self): + + tdSql.execute("use testdb") + + self.check_function("&", False ,"ct4","123","abs(c1)","t1","abs(t2)","abs(t3)","abs(t4)","t5") + self.check_function("&", False ,"ct4","c1+2","abs(t2+2)","t3","abs(t4)","abs(t5)","abs(c1)","t5") + + tdSql.query(" select sum(c1) from stb1 where t1+10 >1; ") + tdSql.query("select c1 ,t1 from stb1 where t1 =0 ") + tdSql.checkRows(13) + self.check_function("&", False ,"t1","c1+2","abs(c2)") + tdSql.query("select t1 from stb1 where t1 >0 ") + tdSql.checkRows(3) + tdSql.query("select t1 from stb1 where t1 =3 ") + tdSql.checkRows(1) + # tdSql.query("select sum(t1) from (select c1 ,t1 from stb1)") + # tdSql.checkData(0,0,61) + # tdSql.query("select distinct(c1) ,t1 from stb1") + # tdSql.checkRows(20) + tdSql.query("select max(c1) , t1&c2&t2 from stb1;") + tdSql.checkData(0,1,0) + + # tag filter with abs function + tdSql.query("select t1 from stb1 where abs(t1)=1") + tdSql.checkRows(1) + tdSql.query("select t1 from stb1 where abs(c1+t1)=1") + tdSql.checkRows(1) + tdSql.checkData(0,0,0) + + tdSql.query( + "select abs(c1+t1)*t1 from stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") + + def support_super_table_test(self): + tdSql.execute(" use testdb ") + self.check_function("|", False , "stb1" , "c1","c2","c3","c4" ) + self.check_function("|", False , "stb1" , "c1","c2","abs(c3)","c4","ceil(t1)" ) + self.check_function("&", False , "stb1" , "c1","c2","abs(c3)","floor(c4)","ceil(t1)" ) + self.check_function("&", True , "stb1" , "max(c1)","max(c2)","sum(abs(c3))","max(floor(c4))","min(ceil(t1))" ) + + + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring + tdSql.prepare() + self.prepare_datas() + self.prepare_tag_datas() + self.test_errors() + self.basic_query() + self.check_boundary_values() + self.test_tag_compute_for_scalar_function() + self.support_super_table_test() + self.insert_datas_and_check_abs(self.tb_nums,self.row_nums,self.time_step) + + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/csum.py b/tests/system-test/2-query/csum.py index b7fa9a0cbb6d0ccf9ae27d897b526ec1071ef5ec..5bd1d4d45e6fea063d3463d793ca3219e57a7a96 100644 --- a/tests/system-test/2-query/csum.py +++ b/tests/system-test/2-query/csum.py @@ -419,12 +419,66 @@ class TDTestCase: tdSql.checkData(3,0,4) tdSql.query("select csum(abs(c1))+2 from t1 ") tdSql.checkRows(4) + + def csum_support_stable(self): + tdSql.query(" select csum(1) from stb1 ") + tdSql.checkRows(70) + tdSql.query("select csum(c1) from stb1 partition by tbname ") + tdSql.checkRows(40) + # tdSql.query("select csum(st1) from stb1 partition by tbname") + # tdSql.checkRows(70) + tdSql.query("select csum(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(40) + tdSql.query("select csum(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(40) + tdSql.query("select csum(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(40) + + # # bug need fix + # tdSql.query("select csum(st1+c1) from stb1 partition by tbname slimit 1 ") + # tdSql.checkRows(4) + # tdSql.error("select csum(st1+c1) from stb1 partition by tbname limit 1 ") + + + # bug need fix + tdSql.query("select csum(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(40) + + # bug need fix + # tdSql.query("select tbname , csum(c1) from stb1 partition by tbname") + # tdSql.checkRows(40) + # tdSql.query("select tbname , csum(st1) from stb1 partition by tbname") + # tdSql.checkRows(70) + # tdSql.query("select tbname , csum(st1) from stb1 partition by tbname slimit 1") + # tdSql.checkRows(7) + + # partition by tags + # tdSql.query("select st1 , csum(c1) from stb1 partition by st1") + # tdSql.checkRows(40) + # tdSql.query("select csum(c1) from stb1 partition by st1") + # tdSql.checkRows(40) + # tdSql.query("select st1 , csum(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(4) + # tdSql.query("select csum(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(4) + + # partition by col + # tdSql.query("select c1 , csum(c1) from stb1 partition by c1") + # tdSql.checkRows(41) + # tdSql.query("select csum(c1) from stb1 partition by c1") + # tdSql.checkRows(41) + # tdSql.query("select c1 , csum(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(4) + # tdSql.query("select csum(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(4) + def run(self): import traceback try: # run in develop branch self.csum_test_run() + self.csum_support_stable() pass except Exception as e: traceback.print_exc() diff --git a/tests/system-test/2-query/distribute_agg_stddev.py b/tests/system-test/2-query/distribute_agg_stddev.py index 59ede389839380edfe2eff0b064d67890cdde897..09a6b86d3429b2af4647d2948b4e6bd22b90d0ae 100644 --- a/tests/system-test/2-query/distribute_agg_stddev.py +++ b/tests/system-test/2-query/distribute_agg_stddev.py @@ -7,7 +7,7 @@ import platform import math class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143, "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } @@ -24,7 +24,7 @@ class TDTestCase: stddev_sql = f"select stddev({col_name}) from {tbname};" same_sql = f"select {col_name} from {tbname} where {col_name} is not null " - + tdSql.query(same_sql) pre_data = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None] if (platform.system().lower() == 'windows' and pre_data.dtype == 'int32'): @@ -32,21 +32,21 @@ class TDTestCase: pre_avg = np.sum(pre_data)/len(pre_data) # Calculate variance - stddev_result = 0 + stddev_result = 0 for num in tdSql.queryResult: stddev_result += (num-pre_avg)*(num-pre_avg)/len(tdSql.queryResult) stddev_result = math.sqrt(stddev_result) tdSql.query(stddev_sql) - + if -0.0001 < tdSql.queryResult[0][0]-stddev_result < 0.0001: tdLog.info(" sql:%s; row:0 col:0 data:%d , expect:%d"%(stddev_sql,tdSql.queryResult[0][0],stddev_result)) else: tdLog.exit(" sql:%s; row:0 col:0 data:%d , expect:%d"%(stddev_sql,tdSql.queryResult[0][0],stddev_result)) def prepare_datas_of_distribute(self): - + # prepate datas for 20 tables distributed at different vgroups tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") tdSql.execute(" use testdb ") @@ -117,17 +117,17 @@ class TDTestCase: vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] - + # check sub_table of per vnode ,make sure sub_table has been distributed tdSql.query("show tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) self.vnode_disbutes = vnode_tables count = 0 @@ -138,14 +138,14 @@ class TDTestCase: tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") def check_stddev_distribute_diff_vnode(self,col_name): - + vgroup_ids = [] for k ,v in self.vnode_disbutes.items(): if len(v)>=2: vgroup_ids.append(k) - + distribute_tbnames = [] - + for vgroup_id in vgroup_ids: vnode_tables = self.vnode_disbutes[vgroup_id] distribute_tbnames.append(random.sample(vnode_tables,1)[0]) @@ -154,7 +154,7 @@ class TDTestCase: tbname_ins += "'%s' ,"%tbname tbname_filters = tbname_ins[:-1] - + stddev_sql = f"select stddev({col_name}) from stb1 where tbname in ({tbname_filters});" same_sql = f"select {col_name} from stb1 where tbname in ({tbname_filters}) and {col_name} is not null " @@ -166,7 +166,7 @@ class TDTestCase: pre_avg = np.sum(pre_data)/len(pre_data) # Calculate variance - stddev_result = 0 + stddev_result = 0 for num in tdSql.queryResult: stddev_result += (num-pre_avg)*(num-pre_avg)/len(tdSql.queryResult) @@ -177,8 +177,8 @@ class TDTestCase: def check_stddev_status(self): - # check max function work status - + # check max function work status + tdSql.query("show tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] @@ -187,31 +187,31 @@ class TDTestCase: tdSql.query("desc stb1") col_names = tdSql.queryResult - + colnames = [] for col_name in col_names: if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: colnames.append(col_name[0]) - + for tablename in tablenames: for colname in colnames: if colname.startswith("c"): self.check_stddev_functions(tablename,colname) else: - # self.check_stddev_functions(tablename,colname) + # self.check_stddev_functions(tablename,colname) pass - # check max function for different vnode + # check max function for different vnode for colname in colnames: if colname.startswith("c"): self.check_stddev_distribute_diff_vnode(colname) else: - # self.check_stddev_distribute_diff_vnode(colname) # bug for tag + # self.check_stddev_distribute_diff_vnode(colname) # bug for tag pass - + def distribute_agg_query(self): # basic filter tdSql.query(" select stddev(c1) from stb1 ") @@ -235,7 +235,7 @@ class TDTestCase: tdSql.query("select stddev(c1) from stb1 where t1> 4 partition by tbname") tdSql.checkRows(15) - # union all + # union all tdSql.query("select stddev(c1) from stb1 union all select stddev(c1) from stb1 ") tdSql.checkRows(2) tdSql.checkData(0,0,6.694663959) @@ -244,7 +244,7 @@ class TDTestCase: tdSql.checkRows(1) tdSql.checkData(0,0,0.000000000) - # join + # join tdSql.execute(" create database if not exists db ") tdSql.execute(" use db ") @@ -252,7 +252,7 @@ class TDTestCase: tdSql.execute(" create table tb1 using st tags(1) ") tdSql.execute(" create table tb2 using st tags(2) ") - + for i in range(10): ts = i*10 + self.ts tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") @@ -263,7 +263,7 @@ class TDTestCase: tdSql.checkData(0,0,2.872281323) tdSql.checkData(0,1,2.872281323) - # group by + # group by tdSql.execute(" use testdb ") # partition by tbname or partition by tag @@ -295,7 +295,7 @@ class TDTestCase: self.check_stddev_status() self.distribute_agg_query() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/elapsed.py b/tests/system-test/2-query/elapsed.py index a62e946866eeb8b34cf9a5b995ce4035b5b6a280..dfebb61d62d6d656660bf26b3e610c413385b1a4 100644 --- a/tests/system-test/2-query/elapsed.py +++ b/tests/system-test/2-query/elapsed.py @@ -163,12 +163,12 @@ class TDTestCase: "select elapsed(ts) from regular_table_1 group by tbname,ind order by desc; ", "select elapsed(ts) from sub_table1_1 group by tbname,ind order by desc; ", "select elapsed(ts) from sub_table1_1 group by tbname,ind order by desc; ", - # "select elapsed(ts,10s) from stable_empty group by ts order by ts;", - "select elapsed(ts,10s) from stable_1 group by ind order by ts;", - "select elapsed(ts,10s) from stable_2 group by tstag order by ts;", - "select elapsed(ts,10s) from stable_1 group by tbname,tstag,tscol order by ts;", - "select elapsed(ts,10s),ts from stable_1 group by tbname ,ind order by ts;", - "select ts,elapsed(ts,10s),tscol*100 from stable_1 group by tbname ,ind order by ts;", + # "select elapsed(ts,1s) from stable_empty group by ts order by ts;", + "select elapsed(ts,1s) from stable_1 group by ind order by ts;", + "select elapsed(ts,1s) from stable_2 group by tstag order by ts;", + "select elapsed(ts,1s) from stable_1 group by tbname,tstag,tscol order by ts;", + "select elapsed(ts,1s),ts from stable_1 group by tbname ,ind order by ts;", + "select ts,elapsed(ts,1s),tscol*100 from stable_1 group by tbname ,ind order by ts;", "select elapsed(ts) from stable_1 group by tstag order by ts;", "select elapsed(ts) from sub_empty_1 group by tbname,ind ,tscol order by ts desc;", "select tbname, tscol,elapsed(ts) from sub_table1_1 group by tbname ,ind order by ts desc;", @@ -178,13 +178,13 @@ class TDTestCase: "select elapsed(tscol) from sub_empty_1 order by ts desc;", "select elapsed(tstag) from sub_empty_1 order by ts desc;", "select elapsed(ind) from sub_table1_1 order by ts desc;", - "select elapsed(ind,10s) from sub_table1_1 order by ts desc;", - "select elapsed(tscol,10s) from sub_table1_1 order by ts desc;", - "select elapsed(tstag,10s) from sub_table1_1 order by ts desc;", - "select elapsed(q_int,10s) from sub_table1_1 order by ts desc;", - "select elapsed(loc,10s) from sub_table1_1 order by ts desc;", - "select elapsed(q_bigint,10s) from sub_table1_1 order by ts desc;", - "select elapsed(bin_chars,10s) from sub_table1_1 order by ts desc;"] + "select elapsed(ind,1s) from sub_table1_1 order by ts desc;", + "select elapsed(tscol,1s) from sub_table1_1 order by ts desc;", + "select elapsed(tstag,1s) from sub_table1_1 order by ts desc;", + "select elapsed(q_int,1s) from sub_table1_1 order by ts desc;", + "select elapsed(loc,1s) from sub_table1_1 order by ts desc;", + "select elapsed(q_bigint,1s) from sub_table1_1 order by ts desc;", + "select elapsed(bin_chars,1s) from sub_table1_1 order by ts desc;"] for sql in sqls_list : tdSql.error(sql) @@ -199,269 +199,269 @@ class TDTestCase: ts_end_time = self.ts + (self.num-1-i)*10000 ts_col_end_time = self.ts + (self.num-1-i)*10 - filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d group by tbname " %(ts_start_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts >= %d group by tbname " %(ts_start_time) tdSql.query(filter_sql) tdSql.checkRows(3) - tdSql.checkData(0,0,float(self.num -i-1)) - tdSql.checkData(1,0,float(self.num -i-1)) - tdSql.checkData(2,0,float(self.num -i-1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) + tdSql.checkData(1,0,float((self.num -i-1)*10)) + tdSql.checkData(2,0,float((self.num -i-1)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts >= %d " %(ts_start_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts >= %d " %(ts_start_time) tdSql.query(filter_sql) tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d and tscol >= %d and tstag='2015-01-01 00:01:00'group by tbname " %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts >= %d and tscol >= %d and tstag='2015-01-01 00:01:00'group by tbname " %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts >= %d and tscol >= %d " %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts >= %d and tscol >= %d " %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d and tscol > %d and tstag='2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts >= %d and tscol > %d and tstag='2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts >= %d and tscol > %d " %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts >= %d and tscol > %d " %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where ts > %d and tscol > %d and tstag < '2015-01-01 00:01:00' group by tbname " %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts > %d and tscol > %d and tstag < '2015-01-01 00:01:00' group by tbname " %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts > %d and tscol > %d " %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts > %d and tscol > %d " %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where ts > %d and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts > %d and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) tdSql.checkRows(0) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts > %d and tscol <= %d " %(ts_start_time,ts_col_start_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts > %d and tscol <= %d " %(ts_start_time,ts_col_start_time) tdSql.query(filter_sql) tdSql.checkRows(0) - filter_sql = "select elapsed(ts,10s) from stable_1 where ts < %d and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_end_time,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts < %d and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_end_time,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts < %d and tscol <= %d " %(ts_end_time,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts < %d and tscol <= %d " %(ts_end_time,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where ts < %d and tscol <= %d group by tbname " %(ts_end_time,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts < %d and tscol <= %d group by tbname " %(ts_end_time,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(3) - tdSql.checkData(0,0,float(self.num - i - 2)) - tdSql.checkData(1,0,float(self.num - i - 2)) - tdSql.checkData(2,0,float(self.num - i - 2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) + tdSql.checkData(1,0,float((self.num -i-2)*10)) + tdSql.checkData(2,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts < %d and tscol <= %d " %(ts_end_time,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts < %d and tscol <= %d " %(ts_end_time,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num - i - 2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where ts = %d and tscol < %d group by tbname " %(ts_end_time,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where ts = %d and tscol < %d group by tbname " %(ts_end_time,ts_col_end_time) tdSql.query(filter_sql) tdSql.checkRows(0) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts = %d and tscol < %d " %(ts_end_time,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where ts = %d and tscol < %d " %(ts_end_time,ts_col_end_time) tdSql.query(filter_sql) tdSql.checkRows(0) - filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint != %d and tscol < %d group by tbname " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where q_tinyint != %d and tscol < %d group by tbname " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(3) - tdSql.checkData(0,0,float(self.num -i-2)) - tdSql.checkData(1,0,float(self.num -i-2)) - tdSql.checkData(2,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) + tdSql.checkData(1,0,float((self.num -i-2)*10)) + tdSql.checkData(2,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint != %d and tscol < %d " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where q_tinyint != %d and tscol < %d " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint != %d and tscol <= %d group by tbname " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where q_tinyint != %d and tscol <= %d group by tbname " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num: tdSql.checkRows(0) else: tdSql.checkRows(3) - tdSql.checkData(0,0,float(self.num - i - 1)) - tdSql.checkData(1,0,float(self.num - i - 1)) - tdSql.checkData(2,0,float(self.num - i - 1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) + tdSql.checkData(1,0,float((self.num -i-1)*10)) + tdSql.checkData(2,0,float((self.num -i-1)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint != %d and tscol <= %d " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where q_tinyint != %d and tscol <= %d " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num - i - 1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint <> %d and tscol < %d group by tbname " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where q_tinyint <> %d and tscol < %d group by tbname " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(3) - tdSql.checkData(0,0,float(self.num -i-2)) - tdSql.checkData(1,0,float(self.num -i-2)) - tdSql.checkData(2,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) + tdSql.checkData(1,0,float((self.num -i-2)*10)) + tdSql.checkData(2,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint <> %d and tscol < %d " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where q_tinyint <> %d and tscol < %d " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num-1: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(0,0,float((self.num -i-2)*10)) - filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint <> %d and tscol <= %d group by tbname " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from stable_1 where q_tinyint <> %d and tscol <= %d group by tbname " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num: tdSql.checkRows(0) else: tdSql.checkRows(3) - tdSql.checkData(0,0,float(self.num - i - 1)) - tdSql.checkData(1,0,float(self.num - i - 1)) - tdSql.checkData(2,0,float(self.num - i - 1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) + tdSql.checkData(1,0,float((self.num -i-1)*10)) + tdSql.checkData(2,0,float((self.num -i-1)*10)) - filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint <> %d and tscol <= %d " %(i,ts_col_end_time) + filter_sql = "select elapsed(ts,1s) from sub_table1_1 where q_tinyint <> %d and tscol <= %d " %(i,ts_col_end_time) tdSql.query(filter_sql) if i == self.num: tdSql.checkRows(0) else: tdSql.checkRows(1) - tdSql.checkData(0,0,float(self.num - i - 1)) + tdSql.checkData(0,0,float((self.num -i-1)*10)) # filter between and - tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ") - tdSql.checkData(0,0,2) - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and \ + tdSql.query("select elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ") + tdSql.checkData(0,0,20) + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and \ q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' group by tbname ") - tdSql.checkData(0,0,2) - tdSql.checkData(1,0,2) - tdSql.checkData(2,0,2) + tdSql.checkData(0,0,20) + tdSql.checkData(1,0,20) + tdSql.checkData(2,0,20) # filter in and or - tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ") - tdSql.checkData(0,0,2) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' group by tbname ") - tdSql.checkData(0,0,2) - tdSql.checkData(1,0,2) - tdSql.checkData(2,0,2) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint in (125,126,127) and tscol <= '2015-01-01 00:01:00.000' group by tbname ") - tdSql.checkData(0,0,2) - tdSql.checkData(1,0,2) - tdSql.checkData(2,0,2) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ") - tdSql.checkData(0,0,1) - tdSql.checkData(1,0,1) - tdSql.checkData(2,0,1) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ") - tdSql.checkData(0,0,1) - tdSql.checkData(1,0,1) - tdSql.checkData(2,0,1) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ") - tdSql.checkData(0,0,6) - tdSql.checkData(1,0,6) - tdSql.checkData(2,0,6) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ") - tdSql.checkData(0,0,6) - tdSql.checkData(1,0,6) - tdSql.checkData(2,0,6) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars is not null and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") - tdSql.checkData(0,0,6) - tdSql.checkData(1,0,6) - tdSql.checkData(2,0,6) - - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars is null and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.query("select elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ") + tdSql.checkData(0,0,20) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,20) + tdSql.checkData(1,0,20) + tdSql.checkData(2,0,20) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint in (125,126,127) and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,20) + tdSql.checkData(1,0,20) + tdSql.checkData(2,0,20) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,10) + tdSql.checkData(1,0,10) + tdSql.checkData(2,0,10) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,10) + tdSql.checkData(1,0,10) + tdSql.checkData(2,0,10) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,60) + tdSql.checkData(1,0,60) + tdSql.checkData(2,0,60) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,60) + tdSql.checkData(1,0,60) + tdSql.checkData(2,0,60) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars is not null and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.checkData(0,0,60) + tdSql.checkData(1,0,60) + tdSql.checkData(2,0,60) + + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars is null and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars match '^b' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars match '^b' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") tdSql.checkRows(3) - tdSql.checkData(0,0,6) - tdSql.checkData(1,0,6) - tdSql.checkData(2,0,6) + tdSql.checkData(0,0,60) + tdSql.checkData(1,0,60) + tdSql.checkData(2,0,60) - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars nmatch '^a' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars nmatch '^a' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") tdSql.checkRows(3) - tdSql.checkData(0,0,6) - tdSql.checkData(1,0,6) - tdSql.checkData(2,0,6) + tdSql.checkData(0,0,60) + tdSql.checkData(1,0,60) + tdSql.checkData(2,0,60) - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars ='bintest1' or bin_chars ='bintest2' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars ='bintest1' or bin_chars ='bintest2' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") tdSql.checkRows(3) - tdSql.query("select elapsed(ts,10s) from stable_1 where (ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000') or (ts between '2015-01-01 00:01:00.000' and '2015-01-01 00:02:00.000') group by tbname; ") + tdSql.query("select elapsed(ts,1s) from stable_1 where (ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000') or (ts between '2015-01-01 00:01:00.000' and '2015-01-01 00:02:00.000') group by tbname; ") tdSql.checkRows(3) - tdSql.checkData(0,0,9) - tdSql.checkData(1,0,9) - tdSql.checkData(2,0,9) + tdSql.checkData(0,0,90) + tdSql.checkData(1,0,90) + tdSql.checkData(2,0,90) def query_interval(self): @@ -473,9 +473,9 @@ class TDTestCase: tdSql.query("select max(q_int)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") + tdSql.query("select elapsed(ts,1s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") + tdSql.query("select elapsed(ts,1s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") tdSql.checkRows(0) for i in range(self.num): @@ -487,254 +487,254 @@ class TDTestCase: # only interval - interval_sql = "select elapsed(ts,10s) from stable_1 where ts <=%d interval(10s) group by tbname " %(ts_start_time) + interval_sql = "select elapsed(ts,1s) from stable_1 where ts <=%d interval(10s) group by tbname " %(ts_start_time) tdSql.query(interval_sql) tdSql.checkRows(3*(i+1)) - interval_sql = "select elapsed(ts,10s) from sub_table1_1 where ts <=%d interval(10s) " %(ts_start_time) + interval_sql = "select elapsed(ts,1s) from sub_table1_1 where ts <=%d interval(10s) " %(ts_start_time) tdSql.query(interval_sql) tdSql.checkRows(i+1) for x in range(i+1): if x == i: tdSql.checkData(x,1,0) else : - tdSql.checkData(x,1,1) + tdSql.checkData(x,1,10) # interval and fill , fill_type = ["NULL","value,100","prev","next","linear"] - # interval (10s) and time range is outer records + # interval (1s) and time range is outer records - tdSql.query("select elapsed(ts,10s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") + tdSql.query("select elapsed(ts,1s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") + tdSql.query("select elapsed(ts,1s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") tdSql.checkRows(180) - tdSql.checkData(0,1,10) + tdSql.checkData(0,1,100) tdSql.checkData(9,1,0) tdSql.checkData(59,1,0) - tdSql.checkData(60,1,10) + tdSql.checkData(60,1,100) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(next) group by tbname;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(next) group by tbname;") tdSql.checkRows(180) - tdSql.checkData(0,1,10) + tdSql.checkData(0,1,100) tdSql.checkData(9,1,0) tdSql.checkData(10,1,None) tdSql.checkData(59,1,None) - tdSql.checkData(60,1,10) - tdSql.checkData(61,1,10) + tdSql.checkData(60,1,100) + tdSql.checkData(61,1,100) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(linear) group by tbname;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(linear) group by tbname;") tdSql.checkRows(180) - tdSql.checkData(0,1,10) + tdSql.checkData(0,1,100) tdSql.checkData(9,1,0) tdSql.checkData(10,1,None) tdSql.checkData(59,1,None) - tdSql.checkData(60,1,10) - tdSql.checkData(61,1,10) + tdSql.checkData(60,1,100) + tdSql.checkData(61,1,100) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(NULL) group by tbname;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(NULL) group by tbname;") tdSql.checkRows(180) - tdSql.checkData(0,1,10) + tdSql.checkData(0,1,100) tdSql.checkData(9,1,0) tdSql.checkData(10,1,None) tdSql.checkData(59,1,None) - tdSql.checkData(60,1,10) - tdSql.checkData(61,1,10) + tdSql.checkData(60,1,100) + tdSql.checkData(61,1,100) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(value ,2) group by tbname;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(value ,2) group by tbname;") tdSql.checkRows(180) - tdSql.checkData(0,1,10) + tdSql.checkData(0,1,100) tdSql.checkData(9,1,0) - tdSql.checkData(10,1,2) - tdSql.checkData(59,1,2) + tdSql.checkData(10,1,20) + tdSql.checkData(59,1,20) tdSql.checkData(60,1,10) - tdSql.checkData(61,1,10) + tdSql.checkData(61,1,100) # interval (20s) and time range is outer records - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(prev) group by tbname,ind ;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(prev) group by tbname,ind ;") tdSql.checkRows(90) - tdSql.checkData(0,1,20) - tdSql.checkData(4,1,10) - tdSql.checkData(5,1,10) - tdSql.checkData(29,1,10) - tdSql.checkData(30,1,20) - tdSql.checkData(31,1,20) - - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(next) group by tbname,ind ;") + tdSql.checkData(0,1,200) + tdSql.checkData(4,1,100) + tdSql.checkData(5,1,100) + tdSql.checkData(29,1,100) + tdSql.checkData(30,1,200) + tdSql.checkData(31,1,200) + + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(next) group by tbname,ind ;") tdSql.checkRows(90) - tdSql.checkData(0,1,20) - tdSql.checkData(4,1,10) + tdSql.checkData(0,1,200) + tdSql.checkData(4,1,100) tdSql.checkData(5,1,None) tdSql.checkData(29,1,None) - tdSql.checkData(30,1,20) - tdSql.checkData(31,1,20) + tdSql.checkData(30,1,200) + tdSql.checkData(31,1,200) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(linear) group by tbname,ind ;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(linear) group by tbname,ind ;") tdSql.checkRows(90) - tdSql.checkData(0,1,20) - tdSql.checkData(4,1,10) + tdSql.checkData(0,1,200) + tdSql.checkData(4,1,100) tdSql.checkData(5,1,None) tdSql.checkData(29,1,None) - tdSql.checkData(30,1,20) - tdSql.checkData(31,1,20) + tdSql.checkData(30,1,200) + tdSql.checkData(31,1,200) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(NULL) group by tbname,ind ;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(NULL) group by tbname,ind ;") tdSql.checkRows(90) - tdSql.checkData(0,1,20) - tdSql.checkData(4,1,10) + tdSql.checkData(0,1,200) + tdSql.checkData(4,1,100) tdSql.checkData(5,1,None) tdSql.checkData(29,1,None) - tdSql.checkData(30,1,20) - tdSql.checkData(31,1,20) + tdSql.checkData(30,1,200) + tdSql.checkData(31,1,200) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(value ,2) group by tbname,ind ;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(value ,2) group by tbname,ind ;") tdSql.checkRows(90) - tdSql.checkData(0,1,20) - tdSql.checkData(4,1,10) - tdSql.checkData(5,1,2) - tdSql.checkData(29,1,2) - tdSql.checkData(30,1,20) - tdSql.checkData(31,1,20) + tdSql.checkData(0,1,200) + tdSql.checkData(4,1,100) + tdSql.checkData(5,1,20) + tdSql.checkData(29,1,20) + tdSql.checkData(30,1,200) + tdSql.checkData(31,1,200) # interval (20s) and time range is in records - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(prev) group by tbname,ind ;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(prev) group by tbname,ind ;") tdSql.checkRows(9) - tdSql.checkData(0,1,20) - tdSql.checkData(2,1,10) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) - tdSql.checkData(7,1,20) - tdSql.checkData(8,1,10) - - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(next) group by tbname,ind ;") + tdSql.checkData(0,1,200) + tdSql.checkData(2,1,100) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) + tdSql.checkData(7,1,200) + tdSql.checkData(8,1,100) + + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(next) group by tbname,ind ;") tdSql.checkRows(9) - tdSql.checkData(0,1,20) - tdSql.checkData(2,1,10) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) - tdSql.checkData(7,1,20) - tdSql.checkData(8,1,10) - - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(linear) group by tbname,ind ;") + tdSql.checkData(0,1,200) + tdSql.checkData(2,1,100) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) + tdSql.checkData(7,1,200) + tdSql.checkData(8,1,100) + + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(linear) group by tbname,ind ;") tdSql.checkRows(9) - tdSql.checkData(0,1,20) - tdSql.checkData(2,1,10) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) - tdSql.checkData(7,1,20) - tdSql.checkData(8,1,10) - - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;") + tdSql.checkData(0,1,200) + tdSql.checkData(2,1,100) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) + tdSql.checkData(7,1,200) + tdSql.checkData(8,1,100) + + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;") tdSql.checkRows(9) - tdSql.checkData(0,1,20) - tdSql.checkData(2,1,10) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) - tdSql.checkData(7,1,20) - tdSql.checkData(8,1,10) - - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(value ,2 ) group by tbname,ind ;") + tdSql.checkData(0,1,200) + tdSql.checkData(2,1,100) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) + tdSql.checkData(7,1,200) + tdSql.checkData(8,1,100) + + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(value ,2 ) group by tbname,ind ;") tdSql.checkRows(9) - tdSql.checkData(0,1,20) - tdSql.checkData(2,1,10) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) - tdSql.checkData(7,1,20) - tdSql.checkData(8,1,10) - - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) group by tbname,ind ;") + tdSql.checkData(0,1,200) + tdSql.checkData(2,1,100) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) + tdSql.checkData(7,1,200) + tdSql.checkData(8,1,100) + + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) group by tbname,ind ;") tdSql.checkRows(9) - tdSql.checkData(0,1,20) - tdSql.checkData(2,1,10) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) - tdSql.checkData(7,1,20) - tdSql.checkData(8,1,10) - - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;") + tdSql.checkData(0,1,200) + tdSql.checkData(2,1,100) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) + tdSql.checkData(7,1,200) + tdSql.checkData(8,1,100) + + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;") tdSql.checkRows(18) tdSql.checkData(0,1,None) tdSql.checkData(2,1,None) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) tdSql.checkData(7,1,None) tdSql.checkData(8,1,None) - tdSql.checkData(9,1,20) + tdSql.checkData(9,1,200) # interval sliding - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(20s) fill(NULL) group by tbname,ind ;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(20s) fill(NULL) group by tbname,ind ;") tdSql.checkRows(18) tdSql.checkData(0,1,None) tdSql.checkData(2,1,None) - tdSql.checkData(3,1,20) - tdSql.checkData(5,1,10) + tdSql.checkData(3,1,200) + tdSql.checkData(5,1,100) tdSql.checkData(7,1,None) tdSql.checkData(8,1,None) - tdSql.checkData(9,1,20) + tdSql.checkData(9,1,200) - tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(10s) fill(NULL) group by tbname,ind ;") + tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(10s) fill(NULL) group by tbname,ind ;") tdSql.checkRows(39) tdSql.checkData(0,1,None) tdSql.checkData(2,1,None) - tdSql.checkData(6,1,10) - tdSql.checkData(7,1,20) + tdSql.checkData(6,1,100) + tdSql.checkData(7,1,200) tdSql.checkData(12,1,0) tdSql.checkData(13,1,None) tdSql.checkData(15,1,None) - tdSql.checkData(19,1,10) - tdSql.checkData(20,1,20) + tdSql.checkData(19,1,100) + tdSql.checkData(20,1,200) tdSql.checkData(25,1,0) def query_mix_common(self): tdLog.info (" ======================================elapsed mixup with common col, it will not support =======================================") - tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and ind =1 group by tbname; ") + tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and ind =1 group by tbname; ") tdSql.checkRows(1) - tdSql.checkData(0,0,6) + tdSql.checkData(0,0,60) - tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.query("select elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") tdSql.checkRows(1) - tdSql.checkData(0,0,6) + tdSql.checkData(0,0,60) - tdSql.error("select ts,elapsed(ts,10s) from sub_empty_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") - tdSql.error("select ts,elapsed(ts,10s) from stable_empty where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.error("select ts,elapsed(ts,1s) from sub_empty_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select ts,elapsed(ts,1s) from stable_empty where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") - tdSql.error("select ts,elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") - tdSql.error("select ts,elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.error("select ts,elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select ts,elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") - tdSql.error("select q_int,elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") - tdSql.error("select q_int,elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.error("select q_int,elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select q_int,elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") - tdSql.error("select ts,q_int,elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") - tdSql.error("select ts,q_int,elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.error("select ts,q_int,elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select ts,q_int,elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") def query_mix_Aggregate(self): tdLog.info (" ====================================== elapsed mixup with aggregate ==================================================") - tdSql.query("select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) from sub_table1_1 ; ") + tdSql.query("select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) from sub_table1_1 ; ") - data = tdSql.getResult("select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) from sub_table1_1 ; ") + data = tdSql.getResult("select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) from sub_table1_1 ; ") - querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)", "elapsed(ts,10s)"] + querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)", "elapsed(ts,1s)"] for index , query in enumerate(querys): sql = "select %s from sub_table1_1 " %(query) tdSql.query(sql) tdSql.checkData(0,0,data[0][index]) - tdSql.query("select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) from stable_1 group by tbname; ") + tdSql.query("select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) from stable_1 group by tbname; ") # Arithmetic with elapsed for common table operators = ["+" ,"-" , "*" ,"/" ,"%"] - querys_oper = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)", "elapsed(ts,10s)"] + querys_oper = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)", "elapsed(ts,1s)"] for operator in operators: @@ -785,7 +785,7 @@ class TDTestCase: # Arithmetic with elapsed for super table operators = ["+" ,"-" , "*" ,"/" ,"%"] - querys_oper = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)", "elapsed(ts,10s)"] + querys_oper = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)", "elapsed(ts,1s)"] for operator in operators: @@ -847,25 +847,25 @@ class TDTestCase: tdLog.info (" ====================================== elapsed mixup with select function =================================================") - querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,10s)"] + querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,1s)"] - querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,10s)"] + querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,1s)"] - tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,10s) from sub_table1_1 ; ") + tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,1s) from sub_table1_1 ; ") - data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,10s) from sub_table1_1 ; ") + data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,1s) from sub_table1_1 ; ") for index , query in enumerate(querys_mix): sql = "select %s from sub_table1_1 " %(query) tdSql.query(sql) tdSql.checkData(0,0,data[0][index]) - tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,10s) from stable_1 group by tbname ; ") + tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,1s) from stable_1 group by tbname ; ") - data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,10s) from stable_1 group by tbname ; ") + data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,1s) from stable_1 group by tbname ; ") - querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","APERCENTILE(q_int,10)","elapsed(ts,10s)"] + querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","APERCENTILE(q_int,10)","elapsed(ts,1s)"] for index , query in enumerate(querys_mix): sql = "select %s from stable_1 group by tbname " %(query) @@ -992,8 +992,8 @@ class TDTestCase: for index , query in enumerate(querys): - sql1 = "select elapsed(ts,10s),%s from sub_table1_1 " %(query) - sql2 = "select elapsed(ts,10s),%s from stable_1 group by tbname" %(query) + sql1 = "select elapsed(ts,1s),%s from sub_table1_1 " %(query) + sql2 = "select elapsed(ts,1s),%s from stable_1 group by tbname" %(query) if query in ["diff(q_int)","DERIVATIVE(q_int,1s,1)","ceil(q_float)","floor(q_float)","round(q_float)"]: tdSql.error(sql1) tdSql.error(sql2) @@ -1003,15 +1003,15 @@ class TDTestCase: # only support mixup with spread - sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,10s) from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ;" + sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,1s) from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ;" tdSql.execute(sql) data = tdSql.getResult(sql) - sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,10s) from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ;" + sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,1s) from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ;" tdSql.execute(sql) - querys_mix = ["spread(ts)","spread(q_tinyint)-10","elapsed(ts,10s)"] + querys_mix = ["spread(ts)","spread(q_tinyint)-10","elapsed(ts,1s)"] for index , query in enumerate(querys_mix): sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; " %(query) @@ -1053,50 +1053,50 @@ class TDTestCase: tdLog.info (" ====================================== elapsed mixup with arithmetic =================================================") - tdSql.execute("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; ") - tdSql.execute("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; ") + tdSql.execute("select elapsed(ts,1s)+1 ,elapsed(ts,1s)-2,elapsed(ts,1s)*3,elapsed(ts,1s)/4,elapsed(ts,1s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; ") + tdSql.execute("select elapsed(ts,1s)+1 ,elapsed(ts,1s)-2,elapsed(ts,1s)*3,elapsed(ts,1s)/4,elapsed(ts,1s)%5 from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" ; ") - # queries = ["elapsed(ts,10s)+1" ,"elapsed(ts,10s)-2","elapsed(ts,10s)*3","elapsed(ts,10s)/4","elapsed(ts,10s)%5" ] + # queries = ["elapsed(ts,1s)+1" ,"elapsed(ts,1s)-2","elapsed(ts,1s)*3","elapsed(ts,1s)/4","elapsed(ts,1s)%5" ] # for index ,query in enumerate(queries): # sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ;" % (query) # data = tdSql.getResult(sql) - # tdSql.query("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ; ") + # tdSql.query("select elapsed(ts,1s)+1 ,elapsed(ts,1s)-2,elapsed(ts,1s)*3,elapsed(ts,1s)/4,elapsed(ts,1s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ; ") # tdSql.checkData(0,index+1,data[0][1]) def query_with_join(self): tdLog.info (" ====================================== elapsed mixup with join =================================================") - tdSql.error("select elapsed(ts,10s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts; ") - tdSql.error("select elapsed(ts,10s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts group by tbname; ") + tdSql.error("select elapsed(ts,1s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts; ") + tdSql.error("select elapsed(ts,1s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts group by tbname; ") - tdSql.execute("select elapsed(ts,10s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2 where TABLE1.ts =TABLE2.ts; ") - tdSql.error("select elapsed(ts,10s) from stable_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind; ") - tdSql.error("select elapsed(ts,10s) from stable_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind group by tbname,ind; ") # join not support group by + tdSql.execute("select elapsed(ts,1s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2 where TABLE1.ts =TABLE2.ts; ") + tdSql.error("select elapsed(ts,1s) from stable_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind; ") + tdSql.error("select elapsed(ts,1s) from stable_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind group by tbname,ind; ") # join not support group by - tdSql.error("select elapsed(ts,10s) from sub_empty_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind ; ") - tdSql.execute("select elapsed(ts,10s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.error("select elapsed(ts,1s) from sub_empty_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind ; ") + tdSql.execute("select elapsed(ts,1s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") - tdSql.query("select elapsed(ts,10s) from sub_table1_1 TABLE1 , sub_table1_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") - tdSql.checkData(0,0,9) + tdSql.query("select elapsed(ts,1s) from sub_table1_1 TABLE1 , sub_table1_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.checkData(0,0,90) - tdSql.query("select elapsed(ts,10s) from sub_empty_1 TABLE1 , sub_table1_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.query("select elapsed(ts,1s) from sub_empty_1 TABLE1 , sub_table1_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s) from sub_empty_1 TABLE1 , regular_empty TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.query("select elapsed(ts,1s) from sub_empty_1 TABLE1 , regular_empty TABLE2 where TABLE1.ts =TABLE2.ts ; ") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s) from sub_empty_1 TABLE1 , regular_table_1 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.query("select elapsed(ts,1s) from sub_empty_1 TABLE1 , regular_table_1 TABLE2 where TABLE1.ts =TABLE2.ts ; ") tdSql.checkRows(0) - tdSql.query("select elapsed(ts,10s) from sub_table1_3 TABLE1 , regular_table_1 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.query("select elapsed(ts,1s) from sub_table1_3 TABLE1 , regular_table_1 TABLE2 where TABLE1.ts =TABLE2.ts ; ") tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query("select elapsed(ts,10s) from regular_table_1 ; ") + tdSql.query("select elapsed(ts,1s) from regular_table_1 ; ") tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) def query_with_union(self): @@ -1104,196 +1104,196 @@ class TDTestCase: # union all with empty - tdSql.query("select elapsed(ts,10s) from regular_table_1 union all select elapsed(ts,10s) from regular_table_2;") + tdSql.query("select elapsed(ts,1s) from regular_table_1 union all select elapsed(ts,1s) from regular_table_2;") - tdSql.query("select elapsed(ts,10s) from regular_table_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) union all \ - select elapsed(ts,10s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + tdSql.query("select elapsed(ts,1s) from regular_table_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) union all \ + select elapsed(ts,1s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") tdSql.checkRows(1200) - tdSql.checkData(0,1,0.1) + tdSql.checkData(0,1,1) tdSql.checkData(500,1,0) - tdSql.query("select elapsed(ts,10s) from sub_empty_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) union all \ - select elapsed(ts,10s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + tdSql.query("select elapsed(ts,1s) from sub_empty_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) union all \ + select elapsed(ts,1s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") tdSql.checkRows(600) - tdSql.checkData(0,1,0.1) + tdSql.checkData(0,1,1) tdSql.checkData(500,0,0) - tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from sub_empty_2;') + tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from sub_empty_2;') tdSql.checkRows(0) - tdSql.query('select elapsed(ts,10s) from regular_table_1 union all select elapsed(ts,10s) from sub_empty_1;') + tdSql.query('select elapsed(ts,1s) from regular_table_1 union all select elapsed(ts,1s) from sub_empty_1;') tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from regular_table_1;') + tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from regular_table_1;') tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from sub_table1_1;') + tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from sub_table1_1;') tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query('select elapsed(ts,10s) from sub_table1_1 union all select elapsed(ts,10s) from sub_empty_1;') + tdSql.query('select elapsed(ts,1s) from sub_table1_1 union all select elapsed(ts,1s) from sub_empty_1;') tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from regular_table_1;') + tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from regular_table_1;') tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.error('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from stable_sub_empty group by tbname;') + tdSql.error('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from stable_sub_empty group by tbname;') - tdSql.error('select elapsed(ts,10s) from regular_table_1 union all select elapsed(ts,10s) from stable_sub_empty group by tbname;') + tdSql.error('select elapsed(ts,1s) from regular_table_1 union all select elapsed(ts,1s) from stable_sub_empty group by tbname;') - tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,10s) from sub_empty_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev);') + tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,1s) from sub_empty_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev);') tdSql.checkRows(0) - tdSql.error('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from stable_empty group by tbname;') + tdSql.error('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from stable_empty group by tbname;') - tdSql.error('select elapsed(ts,10s) from sub_empty_1 interval(1s) union all select elapsed(ts,10s) from stable_empty interval(1s) group by tbname;') + tdSql.error('select elapsed(ts,1s) from sub_empty_1 interval(1s) union all select elapsed(ts,1s) from stable_empty interval(1s) group by tbname;') - # tdSql.error('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,10s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) group by tbname;') + # tdSql.error('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,1s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) group by tbname;') - tdSql.query("select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_empty group by tbname ;") + tdSql.query("select elapsed(ts,1s) from stable_empty group by tbname union all select elapsed(ts,1s) from stable_empty group by tbname ;") tdSql.checkRows(0) # case : TD-12229 - tdSql.query("select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_1 group by tbname ;") + tdSql.query("select elapsed(ts,1s) from stable_empty group by tbname union all select elapsed(ts,1s) from stable_1 group by tbname ;") tdSql.checkRows(3) - tdSql.query("select elapsed(ts,10s) from stable_1 group by tbname union all select elapsed(ts,10s) from stable_1 group by tbname ;") + tdSql.query("select elapsed(ts,1s) from stable_1 group by tbname union all select elapsed(ts,1s) from stable_1 group by tbname ;") tdSql.checkRows(6) - tdSql.checkData(0,0,9) - tdSql.checkData(5,0,9) + tdSql.checkData(0,0,90) + tdSql.checkData(5,0,90) - tdSql.query("select elapsed(ts,10s) from stable_1 group by tbname union all select elapsed(ts,10s) from stable_2 group by tbname ;") + tdSql.query("select elapsed(ts,1s) from stable_1 group by tbname union all select elapsed(ts,1s) from stable_2 group by tbname ;") tdSql.checkRows(6) - tdSql.checkData(0,0,9) - tdSql.checkData(5,0,9) + tdSql.checkData(0,0,90) + tdSql.checkData(5,0,90) - tdSql.query('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ - select elapsed(ts,10s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') + tdSql.query('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,1s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') tdSql.checkRows(360) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(50,1,0) #case : TD-12229 - tdSql.query('select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_2 group by tbname ;') + tdSql.query('select elapsed(ts,1s) from stable_empty group by tbname union all select elapsed(ts,1s) from stable_2 group by tbname ;') tdSql.checkRows(3) - tdSql.query('select elapsed(ts,10s) from stable_1 group by tbname union all select elapsed(ts,10s) from stable_empty group by tbname ;') + tdSql.query('select elapsed(ts,1s) from stable_1 group by tbname union all select elapsed(ts,1s) from stable_empty group by tbname ;') tdSql.checkRows(3) - tdSql.query('select elapsed(ts,10s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ - select elapsed(ts,10s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') + tdSql.query('select elapsed(ts,1s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,1s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') tdSql.checkRows(180) - tdSql.query('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ - select elapsed(ts,10s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') + tdSql.query('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,1s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') tdSql.checkRows(180) # union all with sub table and regular table # sub_table with sub_table - tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from sub_table2_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from sub_table2_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(120) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(120) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(120) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(120) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(120) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(120) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(60) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ - select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(60) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) # stable with stable - tdSql.query('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ - select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname;') + tdSql.query('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname;') tdSql.checkRows(360) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(12,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_2 interval(10s) union all select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev);') + tdSql.query('select elapsed(ts,1s) from regular_table_2 interval(10s) union all select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev);') tdSql.checkRows(10) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(9,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_2 interval(10s) union all select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.query('select elapsed(ts,1s) from regular_table_2 interval(10s) union all select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') tdSql.checkRows(70) - tdSql.checkData(0,1,1) + tdSql.checkData(0,1,10) tdSql.checkData(9,1,0) - tdSql.query('select elapsed(ts,10s) from regular_table_2 interval(10s) order by ts desc union all select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) order by ts asc;') + tdSql.query('select elapsed(ts,1s) from regular_table_2 interval(10s) order by ts desc union all select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) order by ts asc;') tdSql.checkRows(70) tdSql.checkData(0,1,0) - tdSql.checkData(1,1,1) - tdSql.checkData(9,1,1) + tdSql.checkData(1,1,10) + tdSql.checkData(9,1,10) - tdSql.query('select elapsed(ts,10s) from stable_1 group by tbname, ind order by ts desc union all select elapsed(ts,10s) from stable_2 group by tbname, ind order by ts asc ;') + tdSql.query('select elapsed(ts,1s) from stable_1 group by tbname, ind order by ts desc union all select elapsed(ts,1s) from stable_2 group by tbname, ind order by ts asc ;') tdSql.checkRows(6) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query('select elapsed(ts,10s) from stable_1 group by tbname, ind order by ts desc union all select elapsed(ts,10s) from stable_1 group by tbname, ind order by ts asc ;') + tdSql.query('select elapsed(ts,1s) from stable_1 group by tbname, ind order by ts desc union all select elapsed(ts,1s) from stable_1 group by tbname, ind order by ts asc ;') tdSql.checkRows(6) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query('select elapsed(ts,10s) from stable_1 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,10s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') + tdSql.query('select elapsed(ts,1s) from stable_1 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,1s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') tdSql.checkRows(210) tdSql.checkData(0,1,0) - tdSql.checkData(1,1,1) + tdSql.checkData(1,1,10) tdSql.checkData(9,1,1) - tdSql.query('select elapsed(ts,10s) from stable_2 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') + tdSql.query('select elapsed(ts,1s) from stable_2 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') tdSql.checkRows(210) tdSql.checkData(0,1,0) - tdSql.checkData(1,1,1) - tdSql.checkData(9,1,1) + tdSql.checkData(1,1,10) + tdSql.checkData(9,1,10) - tdSql.query('select elapsed(ts,10s) from stable_1 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') + tdSql.query('select elapsed(ts,1s) from stable_1 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') tdSql.checkRows(210) tdSql.checkData(0,1,0) - tdSql.checkData(1,1,1) - tdSql.checkData(9,1,1) + tdSql.checkData(1,1,10) + tdSql.checkData(9,1,10) def query_nest(self): @@ -1305,12 +1305,12 @@ class TDTestCase: # ts can't be used at outer query - tdSql.query("select elapsed(ts,10s) from (select ts from regular_table_1 );") + tdSql.query("select elapsed(ts,1s) from (select ts from regular_table_1 );") # case : TD-12164 - tdSql.error("select elapsed(ts,10s) from (select qint ts from regular_table_1 );") - tdSql.error("select elapsed(tbname ,10s) from (select qint tbname from regular_table_1 );") + tdSql.error("select elapsed(ts,1s) from (select qint ts from regular_table_1 );") + tdSql.error("select elapsed(tbname ,1s) from (select qint tbname from regular_table_1 );") tdSql.error("select elapsed(tsc ,1s) from (select q_int tsc from regular_table_1) ;") tdSql.error("select elapsed(tsv ,1s) from (select elapsed(ts,1s) tsv from regular_table_1);") tdSql.error("select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1);") @@ -1318,40 +1318,40 @@ class TDTestCase: # tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from regular_table_1) ;") # case TD-12276 - # tdSql.error("select elapsed(ts,10s) from (select ts,tbname from regular_table_1 order by ts asc );") + # tdSql.error("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts asc );") - # tdSql.error("select elapsed(ts,10s) from (select ts,tbname from regular_table_1 order by ts desc );") + # tdSql.error("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts desc );") - # tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) interval(1s);") + # tdSql.error("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) interval(1s);") - # tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from regular_table_1 order by ts ) interval(1s);") + # tdSql.error("select elapsed(ts,1s) from (select ts ,q_int,tbname from regular_table_1 order by ts ) interval(1s);") # sub table - tdSql.query("select elapsed(ts,10s) from (select ts from sub_table1_1 );") + tdSql.query("select elapsed(ts,1s) from (select ts from sub_table1_1 );") - # tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from sub_table1_1 order by ts ) interval(1s);") + # tdSql.error("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from sub_table1_1 order by ts ) interval(1s);") - # tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from sub_table1_1 order by ts ) interval(1s);") + # tdSql.error("select elapsed(ts,1s) from (select ts ,q_int,tbname from sub_table1_1 order by ts ) interval(1s);") - tdSql.query("select elapsed(ts,10s) from (select ts ,tbname,top(q_int,3) from sub_table1_1 ) interval(10s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,tbname,top(q_int,3) from sub_table1_1 ) interval(10s);") - tdSql.query("select elapsed(ts,10s) from (select ts ,tbname,bottom(q_int,3) from sub_table1_1 ) interval(10s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,tbname,bottom(q_int,3) from sub_table1_1 ) interval(10s);") - tdSql.query("select elapsed(ts,10s) from (select ts ,tbname from sub_table1_1 ) interval(10s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,tbname from sub_table1_1 ) interval(10s);") - tdSql.query("select elapsed(ts,10s) from (select ts ,tbname from sub_table1_1 ) interval(10s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,tbname from sub_table1_1 ) interval(10s);") - # tdSql.error("select elapsed(ts,10s) from (select ts ,count(*),tbname from sub_table1_1 order by ts ) interval(1s);") + # tdSql.error("select elapsed(ts,1s) from (select ts ,count(*),tbname from sub_table1_1 order by ts ) interval(1s);") - querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)","elapsed(ts,10s)"] + querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)","elapsed(ts,1s)"] for query in querys: - sql1 = "select elapsed(ts,10s) from (select %s from regular_table_1 order by ts ) interval(1s); " % query - sql2 = "select elapsed(ts,10s) from (select ts , tbname ,%s from regular_table_1 order by ts ) interval(1s); " % query - sql3 = "select elapsed(ts,10s) from (select ts , tbname ,%s from stable_1 group by tbname, ind order by ts ) interval(1s); " % query - sql4 = "select elapsed(ts,10s) from (select %s from sub_table2_1 order by ts ) interval(1s); " % query - sql5 = "select elapsed(ts,10s) from (select ts , tbname ,%s from sub_table2_1 order by ts ) interval(1s); " % query + sql1 = "select elapsed(ts,1s) from (select %s from regular_table_1 order by ts ) interval(1s); " % query + sql2 = "select elapsed(ts,1s) from (select ts , tbname ,%s from regular_table_1 order by ts ) interval(1s); " % query + sql3 = "select elapsed(ts,1s) from (select ts , tbname ,%s from stable_1 group by tbname, ind order by ts ) interval(1s); " % query + sql4 = "select elapsed(ts,1s) from (select %s from sub_table2_1 order by ts ) interval(1s); " % query + sql5 = "select elapsed(ts,1s) from (select ts , tbname ,%s from sub_table2_1 order by ts ) interval(1s); " % query tdSql.error(sql1) tdSql.error(sql2) @@ -1370,22 +1370,22 @@ class TDTestCase: # stable - tdSql.error("select elapsed(ts,10s) from (select ts from stable_1 ) group by tbname ;") + tdSql.error("select elapsed(ts,1s) from (select ts from stable_1 ) group by tbname ;") - tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from stable_1 group by tbname order by ts ) interval(1s) group by tbname;") + tdSql.error("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from stable_1 group by tbname order by ts ) interval(1s) group by tbname;") - tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from stable_1 order by ts ) interval(1s) group by tbname;") + tdSql.error("select elapsed(ts,1s) from (select ts ,q_int,tbname from stable_1 order by ts ) interval(1s) group by tbname;") # mixup with aggregate querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","top(q_double,1)", - "bottom(q_float,1)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)" ,"elapsed(ts,10s)"] + "bottom(q_float,1)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)" ,"elapsed(ts,1s)"] for index , query in enumerate(querys): - sql1 = "select elapsed(ts,10s) from (select %s from sub_table1_1) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) ; " %(query) - sql2 = "select elapsed(ts,10s) from (select %s from stable_1 ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query) - sql3 = "select elapsed(ts,10s) from (select %s from stable_1 group by tbname) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query) + sql1 = "select elapsed(ts,1s) from (select %s from sub_table1_1) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) ; " %(query) + sql2 = "select elapsed(ts,1s) from (select %s from stable_1 ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query) + sql3 = "select elapsed(ts,1s) from (select %s from stable_1 group by tbname) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query) if query in ["interp(q_int)" ]: # print(sql1 ) @@ -1397,55 +1397,55 @@ class TDTestCase: tdSql.error(sql2) tdSql.error(sql3) - tdSql.query("select elapsed(ts,10s) from (select ts,tbname from regular_table_1 order by ts ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + tdSql.query("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") - tdSql.query("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + tdSql.query("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") # ===============================================inner nest============================================ # sub table - tdSql.query("select data from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from sub_table1_1 ); ") - tdSql.checkData(0,0,9) + tdSql.query("select data from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from sub_table1_1 ); ") + tdSql.checkData(0,0,90) - # tdSql.query("select data from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from sub_table1_1 \ + # tdSql.query("select data from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from sub_table1_1 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) - # tdSql.checkData(0,0,0.1) + # tdSql.checkData(0,0,1) - tdSql.query("select * from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 ); ") - tdSql.checkData(0,5,9) + tdSql.query("select * from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 ); ") + tdSql.checkData(0,5,90) - # tdSql.query("select * from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select * from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) - # tdSql.checkData(0,0,0.1) + # tdSql.checkData(0,0,1) - tdSql.query("select max(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 ); ") - tdSql.checkData(0,0,9) + tdSql.query("select max(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 ); ") + tdSql.checkData(0,0,90) - # tdSql.query("select max(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select max(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(1) - # tdSql.checkData(0,0,0.1) + # tdSql.checkData(0,0,1) - # tdSql.query("select max(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from sub_empty_2 \ + # tdSql.query("select max(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from sub_empty_2 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(0) - # tdSql.query("select max(data),min(data),avg(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select max(data),min(data),avg(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(1) - # tdSql.query("select ceil(data),floor(data),round(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select ceil(data),floor(data),round(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) - # tdSql.query("select spread(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select spread(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(1) - # tdSql.query("select diff(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select diff(data) from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(599) @@ -1453,23 +1453,23 @@ class TDTestCase: # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(598) - # tdSql.query("select ceil(data)from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select ceil(data)from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) - # tdSql.query("select floor(data)from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select floor(data)from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) - # tdSql.query("select round(data)from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select round(data)from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) - # tdSql.query("select data*10+2 from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select data*10+2 from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) - # tdSql.query("select data*10+2 from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + # tdSql.query("select data*10+2 from (select count(*),avg(q_int) , sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \ # where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") # tdSql.checkRows(600) @@ -1477,49 +1477,49 @@ class TDTestCase: # case TD-12344 # session not support stable - tdSql.error('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts ,10s) group by tbname,ind order by ts asc ') + tdSql.error('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts ,1s) group by tbname,ind order by ts asc ') - tdSql.query('select elapsed(ts,10s) from sub_table1_1 session(ts,1w) ; ') + tdSql.query('select elapsed(ts,1s) from sub_table1_1 session(ts,1w) ; ') tdSql.checkRows(1) - tdSql.checkData(0,0,9) - tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ') + tdSql.checkData(0,0,90) + tdSql.query('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ') tdSql.checkRows(1) - tdSql.checkData(0,0,9) + tdSql.checkData(0,0,90) - tdSql.query('select elapsed(ts,10s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') + tdSql.query('select elapsed(ts,1s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') - tdSql.error('select elapsed(ts,10s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') - tdSql.error('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) session(ts,1w) ; ') + # tdSql.error('select elapsed(ts,1s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') + # tdSql.error('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) session(ts,1w) ; ') - tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ') + tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ') tdSql.checkRows(0) # windows state # not support stable - tdSql.error('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int) group by tbname,ind order by ts asc ') + tdSql.error('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int) group by tbname,ind order by ts asc ') - tdSql.query('select elapsed(ts,10s) from sub_table1_1 state_window(q_int) ; ') + tdSql.query('select elapsed(ts,1s) from sub_table1_1 state_window(q_int) ; ') tdSql.checkRows(10) tdSql.checkData(0,0,0) - tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int) ; ') + tdSql.query('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int) ; ') tdSql.checkRows(10) tdSql.checkData(0,0,0) - # tdSql.error('select elapsed(ts,10s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') + # tdSql.error('select elapsed(ts,1s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') - # tdSql.error('select elapsed(ts,10s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') + # tdSql.error('select elapsed(ts,1s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') - # tdSql.error('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) state_window(q_int) ; ') + # tdSql.error('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) state_window(q_int) ; ') - # tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int); ') + # tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int); ') # tdSql.checkRows(0) def continuous_query(self): tdSql.error('create table elapsed_t as select elapsed(ts) from sub_table1_1 interval(1m) sliding(30s);') tdSql.error('create table elapsed_tb as select elapsed(ts) from stable_1 interval(1m) sliding(30s) group by tbname;') - tdSql.error('create table elapsed_tc as select elapsed(ts) from stable_1 interval(10s) sliding(5s) interval(1m) sliding(30s) group by tbname;') + tdSql.error('create table elapsed_tc as select elapsed(ts) from stable_1 interval(1s) sliding(5s) interval(1m) sliding(30s) group by tbname;') def query_precision(self): def generate_data(precision="ms"): @@ -1549,7 +1549,7 @@ class TDTestCase: tdSql.execute(sql1) tdSql.execute(sql2) - time_units = ["10s","10a","10u","10b"] + time_units = ["1s","1a","1u","1b"] precision_list = ["ms","us","ns"] for pres in precision_list: @@ -1558,13 +1558,13 @@ class TDTestCase: for index,unit in enumerate(time_units): if pres == "ms": - if unit in ["10u","10b"]: + if unit in ["1u","1b"]: tdSql.error("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) pass else: tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) - elif pres == "us" and unit in ["10b"]: - if unit in ["10b"]: + elif pres == "us" and unit in ["1b"]: + if unit in ["1b"]: tdSql.error("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) pass else: @@ -1572,7 +1572,7 @@ class TDTestCase: else: tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) - basic_result = 9 + basic_result = 90 tdSql.checkData(0,0,basic_result*pow(1000,index)) def run(self): @@ -1600,4 +1600,3 @@ class TDTestCase: tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase()) - diff --git a/tests/system-test/2-query/function_diff.py b/tests/system-test/2-query/function_diff.py index 8edc96ed814608635ae133fafa5d7ac04210592c..2bcacd5ae3e1a18e21664a26516c4f0d8ce5df8d 100644 --- a/tests/system-test/2-query/function_diff.py +++ b/tests/system-test/2-query/function_diff.py @@ -355,9 +355,63 @@ class TDTestCase: tdSql.execute(f"create table tt{i} using stb2 tags({i})") pass + def diff_support_stable(self): + tdSql.query(" select diff(1) from stb1 ") + tdSql.checkRows(229) + tdSql.checkData(0,0,0) + tdSql.query("select diff(c1) from stb1 partition by tbname ") + tdSql.checkRows(199) + # tdSql.query("select diff(st1) from stb1 partition by tbname") + # tdSql.checkRows(229) + tdSql.query("select diff(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(199) + tdSql.query("select diff(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(199) + tdSql.query("select diff(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(199) + + # # bug need fix + # tdSql.query("select diff(st1+c1) from stb1 partition by tbname slimit 1 ") + # tdSql.checkRows(19) + # tdSql.error("select diff(st1+c1) from stb1 partition by tbname limit 1 ") + + + # bug need fix + tdSql.query("select diff(st1+c1) from stb1 partition by tbname") + tdSql.checkRows(199) + + # bug need fix + # tdSql.query("select tbname , diff(c1) from stb1 partition by tbname") + # tdSql.checkRows(199) + # tdSql.query("select tbname , diff(st1) from stb1 partition by tbname") + # tdSql.checkRows(199) + # tdSql.query("select tbname , diff(st1) from stb1 partition by tbname slimit 1") + # tdSql.checkRows(19) + + # partition by tags + # tdSql.query("select st1 , diff(c1) from stb1 partition by st1") + # tdSql.checkRows(199) + # tdSql.query("select diff(c1) from stb1 partition by st1") + # tdSql.checkRows(199) + # tdSql.query("select st1 , diff(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(19) + # tdSql.query("select diff(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(19) + + # partition by col + # tdSql.query("select c1 , diff(c1) from stb1 partition by c1") + # tdSql.checkRows(199) + # tdSql.query("select diff(c1) from stb1 partition by c1") + # tdSql.checkRows(41) + # tdSql.query("select c1 , diff(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(19) + # tdSql.query("select diff(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(19) + + def diff_test_run(self) : - tdLog.printNoPrefix("==========TD-10594==========") + tdLog.printNoPrefix("==========run test case for diff function==========") tbnum = 10 nowtime = int(round(time.time() * 1000)) per_table_rows = 10 @@ -422,6 +476,7 @@ class TDTestCase: try: # run in develop branch self.diff_test_run() + self.diff_support_stable() pass except Exception as e: traceback.print_exc() diff --git a/tests/system-test/2-query/histogram.py b/tests/system-test/2-query/histogram.py index bc061f8fb793ff716e35fe22fc278b25bca9e257..4b322c61cf9b5cfdec091f8683c9e6d58ba16ed0 100644 --- a/tests/system-test/2-query/histogram.py +++ b/tests/system-test/2-query/histogram.py @@ -1,3257 +1,566 @@ +import datetime +import re +import json + +from dataclasses import dataclass, field +from typing import List, Any, Tuple + +from certifi import where +from util.log import tdLog +from util.sql import tdSql +from util.cases import tdCases +from util.dnodes import tdDnodes +from util.constant import * +from util.common import is_json + +PRIMARY_COL = "ts" + +INT_COL = "c_int" +BINT_COL = "c_bint" +SINT_COL = "c_sint" +TINT_COL = "c_tint" +FLOAT_COL = "c_float" +DOUBLE_COL = "c_double" +BOOL_COL = "c_bool" +TINT_UN_COL = "c_utint" +SINT_UN_COL = "c_usint" +BINT_UN_COL = "c_ubint" +INT_UN_COL = "c_uint" +BINARY_COL = "c_binary" +NCHAR_COL = "c_nchar" +TS_COL = "c_ts" + +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, TINT_UN_COL, SINT_UN_COL, BINT_UN_COL, INT_UN_COL] +CHAR_COL = [BINARY_COL, NCHAR_COL, ] +BOOLEAN_COL = [BOOL_COL, ] +TS_TYPE_COL = [TS_COL, ] + +INT_TAG = "t_int" + +ALL_COL = [PRIMARY_COL, INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BINARY_COL, NCHAR_COL, BOOL_COL, TS_COL] +TAG_COL = [INT_TAG] + +# insert data args: +TIME_STEP = 10000 +NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + +# init db/table +DBNAME = "db" +STBNAME = "stb1" +CTBNAME = "ct1" +NTBNAME = "nt1" + + +@dataclass +class DataSet: + ts_data : List[int] = field(default_factory=list) + int_data : List[int] = field(default_factory=list) + bint_data : List[int] = field(default_factory=list) + sint_data : List[int] = field(default_factory=list) + tint_data : List[int] = field(default_factory=list) + int_un_data : List[int] = field(default_factory=list) + bint_un_data: List[int] = field(default_factory=list) + sint_un_data: List[int] = field(default_factory=list) + tint_un_data: List[int] = field(default_factory=list) + float_data : List[float] = field(default_factory=list) + double_data : List[float] = field(default_factory=list) + bool_data : List[int] = field(default_factory=list) + binary_data : List[str] = field(default_factory=list) + nchar_data : List[str] = field(default_factory=list) + + +@dataclass +class Hsgschema: + func_type : str = "SELECT" + from_clause : str = STBNAME + where_clause : str = None + group_clause : str = None + having_clause : str = None + partition_clause : str = None + + histogram_flag : str = "HISTOGRAM" + col : str = None + real_col : Any = None + bin_type : str = None + bin_desc : Any = None + normalized : int = 0 + other : dict = None + + user_input : str = None + linear_bin : str = None + log_bin : str = None + + liner_width : float = None + + bin_start : float = None + bin_count : int = None + bin_infinity : bool = None + + def __post_init__(self): + if isinstance(self.other, dict): + for k,v in self.other.items(): + if k.lower().strip() == "func_type" and isinstance(v, str) and not self.func_type: + self.func_type = v + del self.other[k] + + if k.lower().strip() == "from_clause" and isinstance(v, str) and not self.from_clause: + self.from_clause = v + del self.other[k] + + if k.lower().strip() == "where_clause" and isinstance(v, str) and not self.where_clause: + self.where_clause = v + del self.other[k] + + if k.lower().strip() == "group_clause" and isinstance(v, str) and not self.group_clause: + self.group_clause = v + del self.other[k] + + if k.lower().strip() == "having_clause" and isinstance(v, str) and not self.having_clause: + self.having_clause = v + del self.other[k] + + if k.lower().strip() == "partition_clause" and isinstance(v, str) and not self.partition_clause: + self.partition_clause = v + del self.other[k] + + if k.lower().strip() == "histogram_flag" and isinstance(v, str) and not self.histogram_flag: + self.histogram_flag = v + del self.other[k] + + if k.lower().strip() == "col" and isinstance(v, str) and not self.col: + self.col = v + del self.other[k] + + if k.lower().strip() == "bin_type" and isinstance(v, str) and not self.bin_type: + self.bin_type = v + del self.other[k] + + if k.lower().strip() == "user_input" and isinstance(v, str) and not self.user_input and self.bin_type.lower().strip() == "user_input": + self.user_input = v + del self.other[k] + + if k.lower().strip() == "linear_bin" and isinstance(v, str) and not self.linear_bin and self.bin_type.lower().strip() == "linear_bin": + self.linear_bin = v + del self.other[k] + + if k.lower().strip() == "log_bin" and isinstance(v, str) and not self.log_bin and self.bin_type.lower().strip() == "log_bin": + self.log_bin = v + del self.other[k] + + if k.lower().strip() == "normalized" and isinstance(v, int) and not self.normalized: + self.normalized = v + del self.other[k] + + if isinstance(self.bin_type,str) and self.bin_type.upper().strip() == "USER_INPUT": + self.bin_desc = self.user_input + elif isinstance(self.bin_type,str) and self.bin_type.upper().strip() == "LINEAR_BIN": + self.bin_desc = self.linear_bin + elif isinstance(self.bin_type,str) and self.bin_type.upper().strip() == "LOG_BIN": + self.bin_desc = self.log_bin + +# from ...pytest.util.sql import * +# from ...pytest.util.constant import * -################################################################### -# Copyright (c) 2021 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 -# -################################################################### +class TDTestCase: -# -*- coding: utf-8 -*- + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + self.precision = "ms" + self.sma_count = 0 + self.sma_created_index = [] + + def __create_hsg(self, sma:Hsgschema): + return f"""{sma.histogram_flag}({sma.col}, '{sma.bin_type}', '{sma.bin_desc}', {sma.normalized})""" + + def __gen_sql(self, sma:Hsgschema): + sql = f"{sma.func_type} {self.__create_hsg(sma)} from {sma.from_clause} " + if sma.where_clause: + sql += f" where {sma.where_clause}" + if sma.partition_clause: + sql += f" partition by {sma.partition_clause}" + if sma.group_clause: + sql += f" group by {sma.group_clause}" + if sma.having_clause: + sql += f" having {sma.having_clause}" + return sql + + def __gen_no_hsg_sql(self, sma:Hsgschema): + return f"{sma.func_type} {sma.col} from {sma.from_clause}" + + def __hsg_check(self, sma:Hsgschema): + if not sma.histogram_flag: + return False + if not sma.col or (not isinstance(sma.col, str) and not isinstance(sma.col, int) and not isinstance(sma.col, float)): + return False + if tdSql.is_err_sql(self.__gen_no_hsg_sql(sma)): + return False + if any ([not sma.bin_type, not isinstance(sma.bin_type, str) ]): + return False + if all([sma.bin_type.upper().strip() != "USER_INPUT", sma.bin_type.upper().strip() != "LINEAR_BIN" , sma.bin_type.upper().strip() != "LOG_BIN"]): + return False + if not sma.bin_desc: + return False + if sma.normalized is None or not isinstance(sma.normalized, int) or (sma.normalized != 0 and sma.normalized != 1): + return False + if sma.bin_type.upper().strip() == "USER_INPUT": + # user_raw = eval(sma.bin_desc) if isinstance(sma.bin_desc, str) else sma.bin_desc + if not is_json(sma.bin_desc) and not isinstance(sma.bin_desc, list) and not isinstance(sma.bin_desc, set): + return False + user_raw = json.loads(sma.bin_desc) if is_json(sma.bin_desc) else sma.bin_desc + if not isinstance(user_raw, list): + return False + if len(user_raw) >= 2: + for i in range(len(user_raw)-1): + if user_raw[i] >= user_raw[ i+1 ]: + return False + if not isinstance(user_raw[i], int) and not isinstance(user_raw[i], float): + return False + if not isinstance(user_raw[-1], int) and not isinstance(user_raw[-1], float): + return False + else: + if not isinstance(user_raw[-1], int) and not isinstance(user_raw[-1], float): + return False + sma.bin_count = len(user_raw) - 1 + + if sma.bin_type.upper().strip() == "LINEAR_BIN": + if not is_json(sma.bin_desc): + return False + user_raw = json.loads(sma.bin_desc) + if not isinstance(user_raw, dict): + return False + if any([len(user_raw.keys()) != 4, "start" not in user_raw.keys(), "width" not in user_raw.keys(), "count" not in user_raw.keys(), "infinity" not in user_raw.keys()]): + return False + if not isinstance(user_raw["start"], int) and not isinstance(user_raw["start"], float): + return False + if not isinstance(user_raw["width"], int) and not isinstance(user_raw["width"], float) or user_raw["width"] == 0 : + return False + if not isinstance(user_raw["count"], int) and not isinstance(user_raw["count"], float) or user_raw["count"] <= 0: + return False + if not isinstance(user_raw["infinity"], bool) : + return False + sma.bin_infinity = user_raw["infinity"] + sma.bin_count = int(user_raw["count"]) + 2 if user_raw["infinity"] else int(user_raw["count"]) + + if sma.bin_type.upper().strip() == "LOG_BIN": + if not is_json(sma.bin_desc): + return False + user_raw = json.loads(sma.bin_desc) + if not isinstance(user_raw, dict): + return False + if any([ len(user_raw.keys()) != 4, "start" not in user_raw.keys(), "factor" not in user_raw.keys(), "count" not in user_raw.keys(), "infinity" not in user_raw.keys()]): + return False + if not isinstance(user_raw["start"], int) and not isinstance(user_raw["start"], float) or user_raw["start"] == 0: + return False + if not isinstance(user_raw["factor"], int) and not isinstance(user_raw["factor"], float) or user_raw["factor"] <= 0 : + return False + if not isinstance(user_raw["count"], int) and not isinstance(user_raw["count"], float) or user_raw["count"] <= 0: + return False + if not isinstance(user_raw["infinity"], bool) : + return False + sma.bin_infinity = user_raw["infinity"] + sma.bin_count = int(user_raw["count"]) + 2 if user_raw["infinity"] else int(user_raw["count"]) + + invalid_func = AGG_FUNC + invalid_func.extend(SELECT_FUNC) + invalid_func.extend(TS_FUNC) + for func in invalid_func: + if sma.where_clause and func in sma.where_clause.upper().strip(): + return False + if sma.group_clause and func in sma.group_clause.upper().strip(): + return False + if sma.partition_clause and func in sma.partition_clause.upper().strip(): + return False + if isinstance(sma.col, str) and func in sma.col.upper().strip(): + return False + + tdSql.execute(self.__gen_no_hsg_sql(sma)) + if tdSql.cursor.istype(0, "BINARY") or tdSql.cursor.istype(0, "NCHAR") or tdSql.cursor.istype(0, "BOOL") or tdSql.cursor.istype(0, "TIMESTAMP"): + return False + + return True + + def hsg_check(self, sma:Hsgschema): + if self.__hsg_check(sma): + tdSql.query(self.__gen_sql(sma)) + tdSql.checkRows(sma.bin_count) + sum_rate = 0 + if sma.normalized and (not sma.bin_infinity or sma.bin_type.upper().strip() == "USER_INPUT"): + for i in range(tdSql.queryRows): + row_data = json.loads(tdSql.queryResult[i][0]) + sum_rate += row_data["count"] + if sum_rate != 0 and (sum_rate-1) > 0.00001: + tdLog.exit(f"summary of result count should be 0 or 1, now summary is {sum_rate} !!!") + else: + tdLog.success(f"summary of result count is {sum_rate}!") -import sys -from util.log import * -from util.cases import * -from util.sql import * + else: + tdSql.error(self.__gen_sql(sma)) + + @property + def __hsg_querysql(self): + err_sqls = [] + cur_sqls = [] + # err_set + ### case 1.1: required fields check + err_sqls.append( Hsgschema( histogram_flag="", bin_type="USER_INPUT", user_input="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema( col="", bin_type="USER_INPUT", user_input="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="", bin_desc="[0,3,6,9]", normalized=0 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="", normalized=0 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9]", normalized="" ) ) + + ## case 1.2: format check + err_sqls.append( Hsgschema(col=(INT_COL, BINT_COL), bin_type="USER_INPUT", user_input="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema(col={"col": INT_COL}, bin_type="USER_INPUT", user_input="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema( col=(INT_UN_COL, INT_COL), bin_type="USER_INPUT", user_input="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema( col=f"sum({INT_UN_COL}, {INT_COL})", bin_type="USER_INPUT", user_input="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema(col=INT_COL, bin_type="USER_INPUT_1", user_input="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema(col=INT_COL, bin_type=("USER_INPUT",), bin_desc="[0,3,6,9]" ) ) + err_sqls.append( Hsgschema(col=INT_COL, bin_type="USER_INPUT", user_input="0,3,6,9" ) ) + err_sqls.append( Hsgschema(col=INT_COL, bin_type="USER_INPUT", user_input={0,3,6,9} ) ) + err_sqls.append( Hsgschema(col=INT_COL, bin_type="USER_INPUT", user_input=(0,3,6,9) ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9]", normalized=1.5 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9]", normalized="null" ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input='{"start": -200, "width": 100, "count": 20, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input={"start": -200, "width": 100, "count": 20, "infinity": True}, normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[3,0,10,6,9]", normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9,'a']", normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="['a']", normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin=['{"start": 1, "width": 3, "count": 10, "infinity": false}'], normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='[{"start": 1, "width": 3, "count": 10, "infinity": false}]', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"begin": 1, "width": 3, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "length": 3, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 3, "num": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 3, "count": 10, "withnull": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 3, "count": 10, "infinity": false, "other": 1}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": null, "width": 3, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": "a", "width": 3, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": "a", "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": null, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 0, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": 0, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": -10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": 10, "infinity": "false"}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": 10, "infinity": null}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin=['{"start": 1, "factor": 4, "count": 4, "infinity": true}'], normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='[{"start": 1, "factor": 4, "count": 4, "infinity": true}]', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"begin": 1, "factor": 4, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "step": 4, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "num": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 4, "witgnull": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 4, "infinity": true, "other": 2}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": null, "factor": 4, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": "a", "factor": 4, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 0, "factor": 4, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": "a", "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": null, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 0, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": -10, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 0, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": -10, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": "true"}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": null}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}', where_clause=f"count({INT_COL}) >= 0 ") ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}', group_clause=f"min({INT_COL}) ") ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}', partition_clause=f"CSUM({INT_COL}) ") ) + err_sqls.append( Hsgschema( col=f"TWA({INT_COL})", bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}') ) + err_sqls.append( Hsgschema( col=BINARY_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}') ) + err_sqls.append( Hsgschema( col=NCHAR_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}') ) + err_sqls.append( Hsgschema( col=TS_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}') ) + err_sqls.append( Hsgschema( col=BOOL_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}') ) + + + ### case 2: + + # current_set + for num_col in NUM_COL: + cur_sqls.append( Hsgschema( col=num_col, bin_type="USER_INPUT", user_input="[0,3,6,9,11]", normalized=0) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="USER_INPUT", user_input="[0,3,6,9,11]", normalized=1) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": false}', normalized=1) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": true}', normalized=1) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": false}', normalized=0) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": true}', normalized=0 ) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": false}', normalized=1 ) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": true}', normalized=1 ) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": false}', normalized=0 ) ) + cur_sqls.append( Hsgschema( col=num_col, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": true}', normalized=0 ) ) + + cur_sqls.append( Hsgschema( col=INT_UN_COL, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": false}', normalized=1) ) + cur_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9]", normalized=0 ) ) + cur_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input=[0,3,6,9] ) ) + cur_sqls.append( Hsgschema( col=1, bin_type="USER_INPUT", user_input="[0,3,6,9]" ) ) + cur_sqls.append( Hsgschema( col=BINT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 3, "count": 10, "infinity": false}', normalized=0 ) ) + cur_sqls.append( Hsgschema( col=FLOAT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 4, "infinity": true}', normalized=0 ) ) + cur_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": 1.5, "infinity": false}', normalized=1 ) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="USER_INPUT", user_input="[0,3,6,9,11]", normalized=0) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="USER_INPUT", user_input="[0,3,6,9,11]", normalized=1) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": false}', normalized=1) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": true}', normalized=1) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": false}', normalized=0) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="linear_bin", linear_bin='{"start": -200, "width": 100, "count": 20, "infinity": true}', normalized=0 ) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": false}', normalized=1 ) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": true}', normalized=1 ) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": false}', normalized=0 ) ) + cur_sqls.append( Hsgschema( col=INT_TAG, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 6, "infinity": true}', normalized=0 ) ) + + + return err_sqls, cur_sqls + + def test_histogram(self,ctb_num=20): + err_sqls , cur_sqls = self.__hsg_querysql + for err_sql in err_sqls: + self.hsg_check(err_sql) + for cur_sql in cur_sqls: + self.hsg_check(cur_sql) + + tdSql.query("SELECT HISTOGRAM(c_int, 'USER_INPUT', '[0,3,6,9]', 0) from stb1 where c_int < 10 ") + tdSql.checkData(0, 0, f'{{"lower_bin":0, "upper_bin":3, "count":{ ( ctb_num - 2 ) * 3 }}}') + tdSql.checkData(1, 0, f'{{"lower_bin":3, "upper_bin":6, "count":{ ( ctb_num - 2 ) * 3 }}}') + tdSql.checkData(2, 0, f'{{"lower_bin":6, "upper_bin":9, "count":{ ( ctb_num - 2 ) * 3 }}}') + + tdSql.query("SELECT HISTOGRAM(c_int, 'USER_INPUT', '[0,3,6,9]', 0) from ct1 where c_int < 10") + tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}') + tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":6, "count":3}') + tdSql.checkData(2, 0, '{"lower_bin":6, "upper_bin":9, "count":3}') + + tdSql.query("SELECT HISTOGRAM(c_int, 'USER_INPUT', '[0,3,6,9]', 0) from nt1 where c_int < 10") + tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}') + tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":6, "count":3}') + tdSql.checkData(2, 0, '{"lower_bin":6, "upper_bin":9, "count":3}') + + def all_test(self): + self.test_histogram() + + def __create_tb(self, stb=STBNAME, ctb_num=20, ntbnum=1): + tdLog.printNoPrefix("==========step: create table") + create_stb_sql = f'''create table {stb}( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) tags ({INT_TAG} int) + ''' + for i in range(ntbnum): + + create_ntb_sql = f'''create table nt{i+1}( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(ctb_num): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + def __data_set(self, rows): + data_set = DataSet() + + for i in range(rows): + data_set.ts_data.append(NOW + 1 * (rows - i)) + data_set.int_data.append(rows - i) + data_set.bint_data.append(11111 * (rows - i)) + data_set.sint_data.append(111 * (rows - i) % 32767) + data_set.tint_data.append(11 * (rows - i) % 127) + data_set.int_un_data.append(rows - i) + data_set.bint_un_data.append(11111 * (rows - i)) + data_set.sint_un_data.append(111 * (rows - i) % 32767) + data_set.tint_un_data.append(11 * (rows - i) % 127) + data_set.float_data.append(1.11 * (rows - i)) + data_set.double_data.append(1100.0011 * (rows - i)) + data_set.bool_data.append((rows - i) % 2) + data_set.binary_data.append(f'binary{(rows - i)}') + data_set.nchar_data.append(f'nchar_测试_{(rows - i)}') + + return data_set + + def __insert_data(self, ctbnum=20): + tdLog.printNoPrefix("==========step: start inser data into tables now.....") + data = self.__data_set(rows=self.rows) + + # now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + null_data = '''null, null, null, null, null, null, null, null, null, null, null, null, null, null''' + zero_data = "0, 0, 0, 0, 0, 0, 0, 'binary_0', 'nchar_0', 0, 0, 0, 0, 0" + + for i in range(self.rows): + row_data = f''' + {data.int_data[i]}, {data.bint_data[i]}, {data.sint_data[i]}, {data.tint_data[i]}, {data.float_data[i]}, {data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.tint_un_data[i]}, + {data.sint_un_data[i]}, {data.int_un_data[i]}, {data.bint_un_data[i]} + ''' + neg_row_data = f''' + {-1 * data.int_data[i]}, {-1 * data.bint_data[i]}, {-1 * data.sint_data[i]}, {-1 * data.tint_data[i]}, {-1 * data.float_data[i]}, {-1 * data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {1 * data.tint_un_data[i]}, + {1 * data.sint_un_data[i]}, {1 * data.int_un_data[i]}, {1 * data.bint_un_data[i]} + ''' + + tdSql.execute( + f"insert into ct1 values ( {NOW - i * TIME_STEP}, {row_data} )") + tdSql.execute( + f"insert into ct2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )") + tdSql.execute( + f"insert into nt1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )") + + for j in range(ctbnum-3): + tdSql.execute( + f"insert into ct{j+4} values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )") + + tdSql.execute( + f"insert into ct2 values ( {NOW + int(TIME_STEP * 0.6)}, {null_data} )") + tdSql.execute( + f"insert into ct2 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.6)}, {null_data} )") + tdSql.execute( + f"insert into ct2 values ( {NOW - self.rows * int(TIME_STEP * 0.29) }, {null_data} )") + + tdSql.execute( + f"insert into ct4 values ( {NOW + int(TIME_STEP * 0.8)}, {null_data} )") + tdSql.execute( + f"insert into ct4 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.8)}, {null_data} )") + tdSql.execute( + f"insert into ct4 values ( {NOW - self.rows * int(TIME_STEP * 0.39)}, {null_data} )") + + tdSql.execute( + f"insert into {NTBNAME} values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )") + tdSql.execute( + f"insert into {NTBNAME} values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )") + tdSql.execute( + f"insert into {NTBNAME} values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )") + def run(self): + self.rows = 10 -class TDTestCase: - def caseDescription(self): - ''' - case1: [TD-11222]: Histogram function - ''' - return + tdLog.printNoPrefix("==========step0:all check") - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) + tdLog.printNoPrefix("==========step1:create table in normal database") + tdSql.prepare() + self.__create_tb() + self.__insert_data() + self.all_test() - def getBuildPath(self): - selfPath = os.path.dirname(os.path.realpath(__file__)) + tdLog.printNoPrefix("==========step2:create table in normal database") + tdSql.execute("create database db1 vgroups 2") + tdSql.execute("use db1") + self.__create_tb() + self.__insert_data() + self.all_test() - 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 or "taosd.exe" 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 histogram_check_base(self): - print("running {}".format(__file__)) - tdSql.execute("drop database if exists db") - tdSql.execute("create database if not exists db") - tdSql.execute('use db') - - #Prepare data - tdSql.execute("create stable stb (col_timestamp timestamp, col_tinyint tinyint, col_smallint smallint, col_int int, col_bigint bigint, col_float float, col_double double, col_bool bool, col_binary binary(10), col_nchar nchar(10)) \ - tags(tag_timestamp timestamp, tag_tinyint tinyint, tag_smallint smallint, tag_int int, tag_bigint bigint, tag_float float, tag_double double, tag_bool bool, tag_binary binary(10), tag_nchar nchar(10));") - tdSql.execute("create table ctb using stb tags (now, 1, 1, 1, 1, 1.0, 1.0, true, 'abc', 'abc');") - tdSql.execute("create table tb (col_timestamp timestamp, col_tinyint tinyint, col_smallint smallint, col_int int, col_bigint bigint, col_float float, col_double double, col_bool bool, col_binary binary(10), col_nchar nchar(10));") - - tdSql.execute("insert into ctb values (now, -9, -9, -9, -9, -9.5, -9.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 1s, -1, -1, -1, -1, -1.5, -1.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 2s, 1, 1, 1, 1, 1.5, 1.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 3s, 2, 2, 2, 2, 2.5, 2.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 4s, 3, 3, 3, 3, 3.5, 3.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 5s, 4, 4, 4, 4, 4.5, 4.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 6s, 5, 5, 5, 5, 5.5, 5.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 7s, 6, 6, 6, 6, 6.5, 6.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 8s, 7, 7, 7, 7, 7.5, 7.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 9s, 8, 8, 8, 8, 8.5, 8.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 10s, 9, 9, 9, 9, 9.5, 9.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 11s, 10, 10, 10, 10, 10.5, 10.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 12s, 15, 15, 15, 15, 15.5, 15.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 13s, 20, 20, 20, 20, 20.5, 20.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 14s, 99, 99, 99, 99, 99.5, 99.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb values (now + 15s, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);") - - tdSql.execute("insert into tb values (now, -9, -9, -9, -9, -9.5, -9.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 1s, -1, -1, -1, -1, -1.5, -1.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 2s, 1, 1, 1, 1, 1.5, 1.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 3s, 2, 2, 2, 2, 2.5, 2.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 4s, 3, 3, 3, 3, 3.5, 3.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 5s, 4, 4, 4, 4, 4.5, 4.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 6s, 5, 5, 5, 5, 5.5, 5.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 7s, 6, 6, 6, 6, 6.5, 6.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 8s, 7, 7, 7, 7, 7.5, 7.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 9s, 8, 8, 8, 8, 8.5, 8.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 10s, 9, 9, 9, 9, 9.5, 9.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 11s, 10, 10, 10, 10, 10.5, 10.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 12s, 15, 15, 15, 15, 15.5, 15.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 13s, 20, 20, 20, 20, 20.5, 20.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 14s, 99, 99, 99, 99, 99.5, 99.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb values (now + 15s, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);") - - #execute query - print("============== STEP 1: column types ================== ") - #Supported column types - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - - tdSql.query('select histogram(col_float, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_float, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_float, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - - tdSql.query('select histogram(col_double, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_double, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.query('select histogram(col_double, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - - #Unsupported column types - tdSql.error('select histogram(col_timestamp, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_timestamp, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(col_timestamp, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(col_bool, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_bool, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(col_bool, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(col_binary, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_binary, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(col_binary, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(col_nchar, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_nchar, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(col_nchar, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(col, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(col, "user_input", "[1,3,5,7]", 0) from tb;') - - #Unsupported tags - tdSql.error('select histogram(tag_timestamp, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(tag_timestamp, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(tag_timestamp, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(tag_tinyint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(tag_tinyint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(tag_tinyint, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(tag_smallint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(tag_smallint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(tag_smallint, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.query('select histogram(tag_int, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.query('select histogram(tag_int, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.query('select histogram(tag_int, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.query('select histogram(tag_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.query('select histogram(tag_bigint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.query('select histogram(tag_bigint, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.query('select histogram(tag_float, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.query('select histogram(tag_float, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.query('select histogram(tag_float, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.query('select histogram(tag_double, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.query('select histogram(tag_double, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.query('select histogram(tag_double, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(tag_bool, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(tag_bool, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(tag_bool, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(tag_binary, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(tag_binary, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(tag_binary, "user_input", "[1,3,5,7]", 0) from tb;') - - tdSql.error('select histogram(tag_nchar, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(tag_nchar, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.error('select histogram(tag_nchar, "user_input", "[1,3,5,7]", 0) from tb;') - - - print("============== STEP 2: bin types ================== ") - ## user_input ## - #TINYINT - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5]", 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5]", 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5]", 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select histogram(col_tinyint, "user_input", "[0,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[0,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[0,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_tinyint, "user_input", "[-10,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[-10,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[-10,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_tinyint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - - tdSql.query('select histogram(col_tinyint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - - #SMALLINT - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5]", 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5]", 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5]", 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select histogram(col_smallint, "user_input", "[0,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_smallint, "user_input", "[0,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_smallint, "user_input", "[0,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_smallint, "user_input", "[-10,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_smallint, "user_input", "[-10,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_smallint, "user_input", "[-10,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_smallint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - - tdSql.query('select histogram(col_smallint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - - #INT - tdSql.query('select histogram(col_int, "user_input", "[1,3,5]", 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5]", 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5]", 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_int, "user_input", "[0,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_int, "user_input", "[0,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_int, "user_input", "[-10,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_int, "user_input", "[-10,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_int, "user_input", "[-10,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_int, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - - tdSql.query('select histogram(col_int, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - - #BIGINT - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5]", 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5]", 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5]", 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select histogram(col_bigint, "user_input", "[0,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_bigint, "user_input", "[0,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_bigint, "user_input", "[0,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_bigint, "user_input", "[-10,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_bigint, "user_input", "[-10,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - tdSql.query('select histogram(col_bigint, "user_input", "[-10,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":12}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":1}'); - - tdSql.query('select histogram(col_bigint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[-8.9,9.9,19.9,99.9]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-8.9, "upper_bin":9.9, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":99.9, "count":2}'); - - tdSql.query('select histogram(col_bigint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - - #FLOAT - tdSql.query('select histogram(col_float, "user_input", "[1,3,5]", 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[1,3,5]", 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[1,3,5]", 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - tdSql.query('select histogram(col_float, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select histogram(col_float, "user_input", "[0,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":9}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[0,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":9}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[0,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":9}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - - tdSql.query('select histogram(col_float, "user_input", "[-10,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[-10,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[-10,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - - tdSql.query('select histogram(col_float, "user_input", "[-9.4,9.6,20.4,99.9]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-9.4, "upper_bin":9.6, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.6, "upper_bin":20.4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20.4, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[-9.4,9.6,20.4,99.9]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-9.4, "upper_bin":9.6, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.6, "upper_bin":20.4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20.4, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[-9.4,9.6,20.4,99.9]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-9.4, "upper_bin":9.6, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.6, "upper_bin":20.4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20.4, "upper_bin":99.9, "count":2}'); - - tdSql.query('select histogram(col_float, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_float, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - - #DOUBLE - tdSql.query('select histogram(col_double, "user_input", "[1,3,5]", 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[1,3,5]", 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[1,3,5]", 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - tdSql.query('select histogram(col_double, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[1,3,5,7]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[1,3,5,7]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select histogram(col_double, "user_input", "[0,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":9}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[0,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":9}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[0,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":10, "count":9}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - - tdSql.query('select histogram(col_double, "user_input", "[-10,10,20,100]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[-10,10,20,100]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[-10,10,20,100]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":10, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":10, "upper_bin":20, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20, "upper_bin":100, "count":2}'); - - tdSql.query('select histogram(col_double, "user_input", "[-9.4,9.6,20.4,99.9]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-9.4, "upper_bin":9.6, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.6, "upper_bin":20.4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20.4, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[-9.4,9.6,20.4,99.9]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-9.4, "upper_bin":9.6, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.6, "upper_bin":20.4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20.4, "upper_bin":99.9, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[-9.4,9.6,20.4,99.9]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-9.4, "upper_bin":9.6, "count":10}'); - tdSql.checkData(1, 0, '{"lower_bin":9.6, "upper_bin":20.4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":20.4, "upper_bin":99.9, "count":2}'); - - tdSql.query('select histogram(col_double, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - tdSql.query('select histogram(col_double, "user_input", "[-99999999999999,9.9,19.9,99999999999999]", 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-1e+14, "upper_bin":9.9, "count":11}'); - tdSql.checkData(1, 0, '{"lower_bin":9.9, "upper_bin":19.9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":19.9, "upper_bin":1e+14, "count":2}'); - - #ERROR CASE - tdSql.error('select histogram(col_double, 1, "[1,5,3,7]", 0) from stb;') - tdSql.error('select histogram(col_double, 1, "[1,5,3,7]", 0) from ctb;') - tdSql.error('select histogram(col_double, 1, "[1,5,3,7]", 0) from tb;') - tdSql.error('select histogram(col_double, -1.0, "[1,5,3,7]", 0) from stb;') - tdSql.error('select histogram(col_double, -1.0, "[1,5,3,7]", 0) from ctb;') - tdSql.error('select histogram(col_double, -1.0, "[1,5,3,7]", 0) from tb;') - tdSql.error('select histogram(col_double, true, "[1,5,3,7]", 0) from stb;') - tdSql.error('select histogram(col_double, false, "[1,5,3,7]", 0) from ctb;') - tdSql.error('select histogram(col_double, true, "[1,5,3,7]", 0) from tb;') - tdSql.error('select histogram(col_double, "user", "[1,5,3,7]", 0) from stb;') - tdSql.error('select histogram(col_double, "user", "[1,5,3,7]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user", "[1,5,3,7]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[1,5,3,7]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[1,5,3,7]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[1,5,3,7]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[1,-1,3,-3]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[1,-1,3,-3]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[1,-1,3,-3]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0,5.5,3.3,7.7]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0,5.5,3.3,7.7]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0,5.5,3.3,7.7]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[1,1,1]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[1,1,1]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[1,1,1]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[-1,-1,1]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[-1,-1,1]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[-1,-1,1]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[false,3,5]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[false,3,5]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[false,3,5]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[1,true,5]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[1,true,5]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[1,true,5]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0,"abc",5]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0,"abc",5]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0,"abc",5]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0, 5, "中文"]", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0, 5, "中文"]", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "[1.0, 5, "中文"]", 0) from tb;') - tdSql.error('select histogram(col_double, "user_input", "{1.0, 3.0, 5.0}", 0) from stb;') - tdSql.error('select histogram(col_double, "user_input", "{1.0, 3.0, 5.0}", 0) from ctb;') - tdSql.error('select histogram(col_double, "user_input", "{1.0, 3.0, 5.0}", 0) from tb;') - tdSql.error('select histogram(col_double, \'user_input\', \'{"start": 1.0, "width": 3.0, "count": 5, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_double, \'user_input\', \'{"start": 1.0, "width": 3.0, "count": 5, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_double, \'user_input\', \'{"start": 1.0, "width": 3.0, "count": 5, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_double, \'user_input\', \'{"start": 1.0, "factor": 3.0, "count": 5, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_double, \'user_input\', \'{"start": 1.0, "factor": 3.0, "count": 5, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_double, \'user_input\', \'{"start": 1.0, "factor": 3.0, "count": 5, "infinity": true}\', 0) from tb;') - - - ## linear_bins ## - #INTEGER - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 3, "count": 8, "infinity": false}\', 0) from stb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":4, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":4, "upper_bin":7, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":7, "upper_bin":10, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":13, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":13, "upper_bin":16, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":16, "upper_bin":19, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":19, "upper_bin":22, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":22, "upper_bin":25, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 3, "count": 8, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":4, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":4, "upper_bin":7, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":7, "upper_bin":10, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":13, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":13, "upper_bin":16, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":16, "upper_bin":19, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":19, "upper_bin":22, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":22, "upper_bin":25, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 3, "count": 8, "infinity": false}\', 0) from tb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":4, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":4, "upper_bin":7, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":7, "upper_bin":10, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":13, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":13, "upper_bin":16, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":16, "upper_bin":19, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":19, "upper_bin":22, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":22, "upper_bin":25, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -10.0, "width": 3.0, "count": 8, "infinity": false}\', 0) from stb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-7, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-7, "upper_bin":-4, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-4, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":2, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":2, "upper_bin":5, "count":3}'); - tdSql.checkData(5, 0, '{"lower_bin":5, "upper_bin":8, "count":3}'); - tdSql.checkData(6, 0, '{"lower_bin":8, "upper_bin":11, "count":2}'); - tdSql.checkData(7, 0, '{"lower_bin":11, "upper_bin":14, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -10.0, "width": 3.0, "count": 8, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-7, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-7, "upper_bin":-4, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-4, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":2, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":2, "upper_bin":5, "count":3}'); - tdSql.checkData(5, 0, '{"lower_bin":5, "upper_bin":8, "count":3}'); - tdSql.checkData(6, 0, '{"lower_bin":8, "upper_bin":11, "count":2}'); - tdSql.checkData(7, 0, '{"lower_bin":11, "upper_bin":14, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -10.0, "width": 3.0, "count": 8, "infinity": false}\', 0) from tb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-7, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-7, "upper_bin":-4, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-4, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":2, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":2, "upper_bin":5, "count":3}'); - tdSql.checkData(5, 0, '{"lower_bin":5, "upper_bin":8, "count":3}'); - tdSql.checkData(6, 0, '{"lower_bin":8, "upper_bin":11, "count":2}'); - tdSql.checkData(7, 0, '{"lower_bin":11, "upper_bin":14, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -2.5, "width": 0.5, "count": 8, "infinity": false}\', 0) from stb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-2.5, "upper_bin":-2, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-2, "upper_bin":-1.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.5, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -2.5, "width": 0.5, "count": 8, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-2.5, "upper_bin":-2, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-2, "upper_bin":-1.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.5, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -2.5, "width": 0.5, "count": 8, "infinity": false}\', 0) from tb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-2.5, "upper_bin":-2, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-2, "upper_bin":-1.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.5, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 4, "width": -0.5, "count": 10, "infinity": false}\', 0) from stb;') - tdSql.checkRows(10); - tdSql.checkData(0, 0, '{"lower_bin":3.5, "upper_bin":4, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":3.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":3, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":2.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":1.5, "upper_bin":2, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(8, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(9, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 4, "width": -0.5, "count": 10, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(10); - tdSql.checkData(0, 0, '{"lower_bin":3.5, "upper_bin":4, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":3.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":3, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":2.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":1.5, "upper_bin":2, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(8, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(9, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 4, "width": -0.5, "count": 10, "infinity": false}\', 0) from tb;') - tdSql.checkRows(10); - tdSql.checkData(0, 0, '{"lower_bin":3.5, "upper_bin":4, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":3.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":3, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":2.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":1.5, "upper_bin":2, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(8, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(9, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.9999, "infinity": false}\', 0) from stb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.9999, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.9999, "infinity": false}\', 0) from tb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":1.5, "upper_bin":2, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":1.5, "upper_bin":2, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":1.5, "upper_bin":2, "count":1}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 5, "count": 5, "infinity": true}\', 0) from stb;') - tdSql.checkRows(7); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":5, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":15, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":15, "upper_bin":20, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":20, "upper_bin":25, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":25, "upper_bin":inf, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 5, "count": 5, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(7); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":5, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":15, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":15, "upper_bin":20, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":20, "upper_bin":25, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":25, "upper_bin":inf, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 5, "count": 5, "infinity": true}\', 0) from tb;') - tdSql.checkRows(7); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":5, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":15, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":15, "upper_bin":20, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":20, "upper_bin":25, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":25, "upper_bin":inf, "count":1}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.76e+308, "width": 5, "count": 1, "infinity": true}\', 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-1.76e+308, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.76e+308, "upper_bin":inf, "count":15}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.76e+308, "width": 5, "count": 1, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-1.76e+308, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.76e+308, "upper_bin":inf, "count":15}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.76e+308, "width": 5, "count": 1, "infinity": true}\', 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-1.76e+308, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.76e+308, "upper_bin":inf, "count":15}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 10, "width": -5, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":5, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":-5, "upper_bin":0, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-5, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 10, "width": -5, "count": 3, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":5, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":-5, "upper_bin":0, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-5, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": 10, "width": -5, "count": 3, "infinity": true}\', 0) from tb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":5, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":-5, "upper_bin":0, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-5, "count":1}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": false}\', 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": false}\', 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": true}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-7e+307, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.checkData(3, 0, '{"lower_bin":7e+307, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-7e+307, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.checkData(3, 0, '{"lower_bin":7e+307, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": true}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-7e+307, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.checkData(3, 0, '{"lower_bin":7e+307, "upper_bin":inf, "count":0}'); - - #FLOATING NUMBER - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 3, "count": 8, "infinity": false}\', 0) from stb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":4, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":4, "upper_bin":7, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":7, "upper_bin":10, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":13, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":13, "upper_bin":16, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":16, "upper_bin":19, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":19, "upper_bin":22, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":22, "upper_bin":25, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 3, "count": 8, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":4, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":4, "upper_bin":7, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":7, "upper_bin":10, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":13, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":13, "upper_bin":16, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":16, "upper_bin":19, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":19, "upper_bin":22, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":22, "upper_bin":25, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 3, "count": 8, "infinity": false}\', 0) from tb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":4, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":4, "upper_bin":7, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":7, "upper_bin":10, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":13, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":13, "upper_bin":16, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":16, "upper_bin":19, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":19, "upper_bin":22, "count":1}'); - tdSql.checkData(7, 0, '{"lower_bin":22, "upper_bin":25, "count":0}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -10.0, "width": 3.0, "count": 8, "infinity": false}\', 0) from stb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-7, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-7, "upper_bin":-4, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-4, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":2, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":2, "upper_bin":5, "count":3}'); - tdSql.checkData(5, 0, '{"lower_bin":5, "upper_bin":8, "count":3}'); - tdSql.checkData(6, 0, '{"lower_bin":8, "upper_bin":11, "count":3}'); - tdSql.checkData(7, 0, '{"lower_bin":11, "upper_bin":14, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -10.0, "width": 3.0, "count": 8, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-7, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-7, "upper_bin":-4, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-4, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":2, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":2, "upper_bin":5, "count":3}'); - tdSql.checkData(5, 0, '{"lower_bin":5, "upper_bin":8, "count":3}'); - tdSql.checkData(6, 0, '{"lower_bin":8, "upper_bin":11, "count":3}'); - tdSql.checkData(7, 0, '{"lower_bin":11, "upper_bin":14, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -10.0, "width": 3.0, "count": 8, "infinity": false}\', 0) from tb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-7, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-7, "upper_bin":-4, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-4, "upper_bin":-1, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":2, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":2, "upper_bin":5, "count":3}'); - tdSql.checkData(5, 0, '{"lower_bin":5, "upper_bin":8, "count":3}'); - tdSql.checkData(6, 0, '{"lower_bin":8, "upper_bin":11, "count":3}'); - tdSql.checkData(7, 0, '{"lower_bin":11, "upper_bin":14, "count":0}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -2.5, "width": 0.5, "count": 8, "infinity": false}\', 0) from stb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-2.5, "upper_bin":-2, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-2, "upper_bin":-1.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.5, "upper_bin":-1, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":0}'); - tdSql.checkData(7, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -2.5, "width": 0.5, "count": 8, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-2.5, "upper_bin":-2, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-2, "upper_bin":-1.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.5, "upper_bin":-1, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":0}'); - tdSql.checkData(7, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -2.5, "width": 0.5, "count": 8, "infinity": false}\', 0) from tb;') - tdSql.checkRows(8); - tdSql.checkData(0, 0, '{"lower_bin":-2.5, "upper_bin":-2, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-2, "upper_bin":-1.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.5, "upper_bin":-1, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":0}'); - tdSql.checkData(7, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 4, "width": -0.5, "count": 10, "infinity": false}\', 0) from stb;') - tdSql.checkRows(10); - tdSql.checkData(0, 0, '{"lower_bin":3.5, "upper_bin":4, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":3.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":3, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":2.5, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":1.5, "upper_bin":2, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":0}'); - tdSql.checkData(7, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(8, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(9, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 4, "width": -0.5, "count": 10, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(10); - tdSql.checkData(0, 0, '{"lower_bin":3.5, "upper_bin":4, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":3.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":3, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":2.5, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":1.5, "upper_bin":2, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":0}'); - tdSql.checkData(7, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(8, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(9, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 4, "width": -0.5, "count": 10, "infinity": false}\', 0) from tb;') - tdSql.checkRows(10); - tdSql.checkData(0, 0, '{"lower_bin":3.5, "upper_bin":4, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":3.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":3, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":2.5, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":1.5, "upper_bin":2, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.checkData(6, 0, '{"lower_bin":0.5, "upper_bin":1, "count":0}'); - tdSql.checkData(7, 0, '{"lower_bin":0, "upper_bin":0.5, "count":0}'); - tdSql.checkData(8, 0, '{"lower_bin":-0.5, "upper_bin":0, "count":0}'); - tdSql.checkData(9, 0, '{"lower_bin":-1, "upper_bin":-0.5, "count":0}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.9999, "infinity": false}\', 0) from stb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.9999, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.9999, "infinity": false}\', 0) from tb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":1.5, "upper_bin":2, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":1.5, "upper_bin":2, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 1, "width": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":1.5, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":1.5, "upper_bin":2, "count":0}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 0, "width": 5, "count": 5, "infinity": true}\', 0) from stb;') - tdSql.checkRows(7); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":5, "count":4}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":15, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":15, "upper_bin":20, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":20, "upper_bin":25, "count":1}'); - tdSql.checkData(6, 0, '{"lower_bin":25, "upper_bin":inf, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 0, "width": 5, "count": 5, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(7); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":5, "count":4}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":15, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":15, "upper_bin":20, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":20, "upper_bin":25, "count":1}'); - tdSql.checkData(6, 0, '{"lower_bin":25, "upper_bin":inf, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 0, "width": 5, "count": 5, "infinity": true}\', 0) from tb;') - tdSql.checkRows(7); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":5, "count":4}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(3, 0, '{"lower_bin":10, "upper_bin":15, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":15, "upper_bin":20, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":20, "upper_bin":25, "count":1}'); - tdSql.checkData(6, 0, '{"lower_bin":25, "upper_bin":inf, "count":1}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 10, "width": -5, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":4}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":5, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":-5, "upper_bin":0, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-5, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 10, "width": -5, "count": 3, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":4}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":5, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":-5, "upper_bin":0, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-5, "count":1}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": 10, "width": -5, "count": 3, "infinity": true}\', 0) from tb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":4}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":5, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":-5, "upper_bin":0, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-5, "count":1}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -1.76e+308, "width": 5, "count": 1, "infinity": true}\', 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-1.76e+308, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.76e+308, "upper_bin":inf, "count":15}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -1.76e+308, "width": 5, "count": 1, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-1.76e+308, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.76e+308, "upper_bin":inf, "count":15}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -1.76e+308, "width": 5, "count": 1, "infinity": true}\', 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-1.76e+308, "upper_bin":-1.76e+308, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-1.76e+308, "upper_bin":inf, "count":15}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": false}\', 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": false}\', 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": true}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-7e+307, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.checkData(3, 0, '{"lower_bin":7e+307, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-7e+307, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.checkData(3, 0, '{"lower_bin":7e+307, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"start": -0.7e+308, "width": 0.7e+308, "count": 2, "infinity": true}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-7e+307, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-7e+307, "upper_bin":0, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":0, "upper_bin":7e+307, "count":13}'); - tdSql.checkData(3, 0, '{"lower_bin":7e+307, "upper_bin":inf, "count":0}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"width":2, "start": 0, "count": 4, "infinity": false}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"width":2, "start": 0, "count": 4, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"width":2, "start": 0, "count": 4, "infinity": false}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"width":2, "start": 0, "count": 4, "infinity": false}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"width":2, "start": 0, "count": 4, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"width":2, "start": 0, "count": 4, "infinity": false}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"count": 4, "width":2, "start": 0, "infinity": false}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"count": 4, "width":2, "start": 0, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"count": 4, "width":2, "start": 0, "infinity": false}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"infinity": false, "width":2, "start": 0, "count": 4}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"infinity": false, "width":2, "start": 0, "count": 4}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - tdSql.query('select histogram(col_float, \'linear_bin\', \'{"infinity": false, "width":2, "start": 0, "count": 4}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":6, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6, "upper_bin":8, "count":2}'); - - #ERROR CASE - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": true, "width": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": true, "width": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": true, "width": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": false, "width": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": false, "width": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": false, "width": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": "abc", "width": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": "abc", "width": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": "abc", "width": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": "中文", "width": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": "中文", "width": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": "中文", "width": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": abc, "width": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": abc, "width": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": abc, "width": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.80e+308, "width": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.80e+308, "width": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.80e+308, "width": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1.80e+308, "width": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1.80e+308, "width": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 1.80e+308, "width": 5, "count": 5, "infinity": false}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": true, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": true, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": true, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": false, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": false, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": false, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": "abc", "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": "abc", "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": "abc", "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": "中文", "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": "中文", "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": "中文", "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": abc, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": abc, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": abc, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 0, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 0, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 0, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": -1.80e+308, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": -1.80e+308, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": -1.80e+308, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1.80e+308, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1.80e+308, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1.80e+308, "count": 5, "infinity": false}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.4e+308, "width": 1.4e+308, "count": 3, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.4e+308, "width": 1.4e+308, "count": 3, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.4e+308, "width": 1.4e+308, "count": 3, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.4e+308, "width": 1.4e+308, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.4e+308, "width": 1.4e+308, "count": 3, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": -1.4e+308, "width": 1.4e+308, "count": 3, "infinity": true}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": -1, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": -1, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": -1, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 0, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 0, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 0, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1001, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1001, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1001, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": true, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": true, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": true, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": false, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": false, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": false, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": "abc", "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": "abc", "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": "abc", "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": "中文", "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": "中文", "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": "中文", "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": abc, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": abc, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": abc, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1.8e+308, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1.8e+308, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1.8e+308, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": -1.8e+308, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": -1.8e+308, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": -1.8e+308, "infinity": true}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 1}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 1}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 1}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 0}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 0}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 0}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": -1.5}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": -1.5}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": -1.5}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 1.8e+308}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 1.8e+308}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": 1.8e+308}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": "abc"}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": "abc"}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": "abc"}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": "中文"}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": "中文"}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": "中文"}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": abc}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": abc}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": abc}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"begin": 0, "width": 1, "count": 1, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"begin": 0, "width": 1, "count": 1, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"begin": 0, "width": 1, "count": 1, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "factor": 1, "cnt": 1, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "factor": 1, "cnt": 1, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "factor": 1, "cnt": 1, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "inf": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "inf": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{"start": 0, "width": 1, "count": 1, "inf": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{start: 0, width: 1, count: 1, infinity: true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{start: 0, width: 1, count: 1, infinity: true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'{start: 0, width: 1, count: 1, infinity: true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'[ 0, 1, 1, true]\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'[ 0, 1, 1, true]\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'linear_bin\', \'[ 0, 1, 1, true]\', 0) from tb;') - - ## log_bin ## - #INTEGER - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 3, "count": 6, "infinity": false}\', 0) from stb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":9, "count":6}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":27, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":27, "upper_bin":81, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":81, "upper_bin":243, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":243, "upper_bin":729, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 3, "count": 6, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":9, "count":6}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":27, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":27, "upper_bin":81, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":81, "upper_bin":243, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":243, "upper_bin":729, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 3, "count": 6, "infinity": false}\', 0) from tb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":9, "count":6}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":27, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":27, "upper_bin":81, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":81, "upper_bin":243, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":243, "upper_bin":729, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.0, "factor": 3.0, "count": 6, "infinity": false}\', 0) from stb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":-3, "upper_bin":-1, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-9, "upper_bin":-3, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-27, "upper_bin":-9, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-81, "upper_bin":-27, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-243, "upper_bin":-81, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":-729, "upper_bin":-243, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.0, "factor": 3.0, "count": 6, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":-3, "upper_bin":-1, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-9, "upper_bin":-3, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-27, "upper_bin":-9, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-81, "upper_bin":-27, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-243, "upper_bin":-81, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":-729, "upper_bin":-243, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.0, "factor": 3.0, "count": 6, "infinity": false}\', 0) from tb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":-3, "upper_bin":-1, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-9, "upper_bin":-3, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-27, "upper_bin":-9, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-81, "upper_bin":-27, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-243, "upper_bin":-81, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":-729, "upper_bin":-243, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 10, "factor": 0.5, "count": 6, "infinity": false}\', 0) from stb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(1, 0, '{"lower_bin":2.5, "upper_bin":5, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":1.25, "upper_bin":2.5, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":0.625, "upper_bin":1.25, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":0.3125, "upper_bin":0.625, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0.15625, "upper_bin":0.3125, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 10, "factor": 0.5, "count": 6, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(1, 0, '{"lower_bin":2.5, "upper_bin":5, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":1.25, "upper_bin":2.5, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":0.625, "upper_bin":1.25, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":0.3125, "upper_bin":0.625, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0.15625, "upper_bin":0.3125, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 10, "factor": 0.5, "count": 6, "infinity": false}\', 0) from tb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(1, 0, '{"lower_bin":2.5, "upper_bin":5, "count":3}'); - tdSql.checkData(2, 0, '{"lower_bin":1.25, "upper_bin":2.5, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":0.625, "upper_bin":1.25, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":0.3125, "upper_bin":0.625, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":0.15625, "upper_bin":0.3125, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -10, "factor": 0.5, "count": 6, "infinity": false}\', 0) from stb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-5, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-5, "upper_bin":-2.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-2.5, "upper_bin":-1.25, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":-1.25, "upper_bin":-0.625, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.625, "upper_bin":-0.3125, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":-0.3125, "upper_bin":-0.15625, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -10, "factor": 0.5, "count": 6, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-5, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-5, "upper_bin":-2.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-2.5, "upper_bin":-1.25, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":-1.25, "upper_bin":-0.625, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.625, "upper_bin":-0.3125, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":-0.3125, "upper_bin":-0.15625, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -10, "factor": 0.5, "count": 6, "infinity": false}\', 0) from tb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":-10, "upper_bin":-5, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":-5, "upper_bin":-2.5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-2.5, "upper_bin":-1.25, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":-1.25, "upper_bin":-0.625, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-0.625, "upper_bin":-0.3125, "count":0}'); - tdSql.checkData(5, 0, '{"lower_bin":-0.3125, "upper_bin":-0.15625, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 2, "factor": 1.5, "count": 6, "infinity": false}\', 0) from stb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":2, "upper_bin":3, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":4.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":4.5, "upper_bin":6.75, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6.75, "upper_bin":10.125, "count":4}'); - tdSql.checkData(4, 0, '{"lower_bin":10.125, "upper_bin":15.1875, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":15.1875, "upper_bin":22.7812, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 2, "factor": 1.5, "count": 6, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":2, "upper_bin":3, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":4.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":4.5, "upper_bin":6.75, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6.75, "upper_bin":10.125, "count":4}'); - tdSql.checkData(4, 0, '{"lower_bin":10.125, "upper_bin":15.1875, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":15.1875, "upper_bin":22.7812, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 2, "factor": 1.5, "count": 6, "infinity": false}\', 0) from tb;') - tdSql.checkRows(6); - tdSql.checkData(0, 0, '{"lower_bin":2, "upper_bin":3, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":4.5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":4.5, "upper_bin":6.75, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":6.75, "upper_bin":10.125, "count":4}'); - tdSql.checkData(4, 0, '{"lower_bin":10.125, "upper_bin":15.1875, "count":1}'); - tdSql.checkData(5, 0, '{"lower_bin":15.1875, "upper_bin":22.7812, "count":1}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 3.2, "factor": 0.5, "count": 1.9999, "infinity": false}\', 0) from stb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1.6, "upper_bin":3.2, "count":2}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 3.2, "factor": 0.5, "count": 1.9999, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1.6, "upper_bin":3.2, "count":2}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 3.2, "factor": 0.5, "count": 1.9999, "infinity": false}\', 0) from tb;') - tdSql.checkRows(1); - tdSql.checkData(0, 0, '{"lower_bin":1.6, "upper_bin":3.2, "count":2}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 3.2, "factor": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from stb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1.6, "upper_bin":3.2, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0.8, "upper_bin":1.6, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 3.2, "factor": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1.6, "upper_bin":3.2, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0.8, "upper_bin":1.6, "count":1}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 3.2, "factor": 0.5, "count": 1.99999999999999999, "infinity": false}\', 0) from tb;') - tdSql.checkRows(2); - tdSql.checkData(0, 0, '{"lower_bin":1.6, "upper_bin":3.2, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":0.8, "upper_bin":1.6, "count":1}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 5, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":1, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":1, "upper_bin":5, "count":4}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":25, "count":7}'); - tdSql.checkData(3, 0, '{"lower_bin":25, "upper_bin":125, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":125, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 5, "count": 3, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":1, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":1, "upper_bin":5, "count":4}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":25, "count":7}'); - tdSql.checkData(3, 0, '{"lower_bin":25, "upper_bin":125, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":125, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 5, "count": 3, "infinity": true}\', 0) from tb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":1, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":1, "upper_bin":5, "count":4}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":25, "count":7}'); - tdSql.checkData(3, 0, '{"lower_bin":25, "upper_bin":125, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":125, "upper_bin":inf, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 0.2e+308, "factor": 3.14, "count": 1, "infinity": true}\', 0) from stb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":2e+307, "count":15}'); - tdSql.checkData(1, 0, '{"lower_bin":2e+307, "upper_bin":6.28e+307, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":6.28e+307, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 0.2e+308, "factor": 3.14, "count": 1, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":2e+307, "count":15}'); - tdSql.checkData(1, 0, '{"lower_bin":2e+307, "upper_bin":6.28e+307, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":6.28e+307, "upper_bin":inf, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 0.2e+308, "factor": 3.14, "count": 1, "infinity": true}\', 0) from tb;') - tdSql.checkRows(3); - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":2e+307, "count":15}'); - tdSql.checkData(1, 0, '{"lower_bin":2e+307, "upper_bin":6.28e+307, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":6.28e+307, "upper_bin":inf, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -2, "factor": 3, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":-2, "upper_bin":inf, "count":14}'); - tdSql.checkData(1, 0, '{"lower_bin":-6, "upper_bin":-2, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-18, "upper_bin":-6, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-54, "upper_bin":-18, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-54, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -2, "factor": 3, "count": 3, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":-2, "upper_bin":inf, "count":14}'); - tdSql.checkData(1, 0, '{"lower_bin":-6, "upper_bin":-2, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-18, "upper_bin":-6, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-54, "upper_bin":-18, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-54, "count":0}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": -2, "factor": 3, "count": 3, "infinity": true}\', 0) from tb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":-2, "upper_bin":inf, "count":14}'); - tdSql.checkData(1, 0, '{"lower_bin":-6, "upper_bin":-2, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-18, "upper_bin":-6, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":-54, "upper_bin":-18, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":-54, "count":0}'); - - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 10, "factor": 0.5, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":5, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":1.25, "upper_bin":2.5, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":1.25, "count":3}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 10, "factor": 0.5, "count": 3, "infinity": true}\', 0) from ctb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":5, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":1.25, "upper_bin":2.5, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":1.25, "count":3}'); - tdSql.query('select histogram(col_tinyint, \'log_bin\', \'{"start": 10, "factor": 0.5, "count": 3, "infinity": true}\', 0) from tb;') - tdSql.checkRows(5); - tdSql.checkData(0, 0, '{"lower_bin":10, "upper_bin":inf, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.checkData(2, 0, '{"lower_bin":2.5, "upper_bin":5, "count":3}'); - tdSql.checkData(3, 0, '{"lower_bin":1.25, "upper_bin":2.5, "count":1}'); - tdSql.checkData(4, 0, '{"lower_bin":-inf, "upper_bin":1.25, "count":3}'); - - #FLOAT - tdSql.query('select histogram(col_float, \'log_bin\', \'{"factor":2, "start": 1, "count": 4, "infinity": false}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"factor":2, "start": 1, "count": 4, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"factor":2, "start": 1, "count": 4, "infinity": false}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - - tdSql.query('select histogram(col_float, \'log_bin\', \'{"count": 4, "factor":2, "start": 1, "infinity": false}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"count": 4, "factor":2, "start": 1, "infinity": false}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"count": 4, "factor":2, "start": 1, "infinity": false}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - - tdSql.query('select histogram(col_float, \'log_bin\', \'{"infinity": false, "count": 4, "factor":2, "start": 1}\', 0) from stb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"infinity": false, "count": 4, "factor":2, "start": 1}\', 0) from ctb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"infinity": false, "count": 4, "factor":2, "start": 1}\', 0) from tb;') - tdSql.checkRows(4); - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":4, "upper_bin":8, "count":4}'); - tdSql.checkData(3, 0, '{"lower_bin":8, "upper_bin":16, "count":4}'); - - #ERROR CASE - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": true, "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": true, "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": true, "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": false, "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": false, "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": false, "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": "abc", "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": "abc", "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": "abc", "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": "中文", "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": "中文", "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": "中文", "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": abc, "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": abc, "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": abc, "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.80e+308, "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.80e+308, "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.80e+308, "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1.80e+308, "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1.80e+308, "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1.80e+308, "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 5, "count": 5, "infinity": false}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": true, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": true, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": true, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": false, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": false, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": false, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": "abc", "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": "abc", "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": "abc", "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": "中文", "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": "中文", "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": "中文", "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": abc, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": abc, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": abc, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 1.80e+308, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 1.80e+308, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 1.80e+308, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 0, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 0, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 0, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": -5, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": -5, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": -5, "count": 5, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 1, "count": 5, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 1, "count": 5, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 1, "factor": 1, "count": 5, "infinity": false}\', 0) from tb;') - - #out of range - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.4e+308, "factor": 1.5, "count": 3, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.4e+308, "factor": 1.5, "count": 3, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.4e+308, "factor": 1.5, "count": 3, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.4e+308, "factor": 1.5, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.4e+308, "factor": 1.5, "count": 3, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": -1.4e+308, "factor": 1.5, "count": 3, "infinity": true}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": -1, "infinity": false}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": -1, "infinity": false}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": -1, "infinity": false}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 0, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 0, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 0, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1001, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1001, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1001, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": true, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": true, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": true, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": false, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": false, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": false, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": "abc", "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": "abc", "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": "abc", "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": "中文", "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": "中文", "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": "中文", "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": abc, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": abc, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": abc, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1.8e+308, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1.8e+308, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1.8e+308, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": -1.8e+308, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": -1.8e+308, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": -1.8e+308, "infinity": true}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 1}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 1}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 1}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 0}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 0}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 0}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": -1.5}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": -1.5}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": -1.5}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 1.8e+308}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 1.8e+308}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": 1.8e+308}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": "abc"}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": "abc"}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": "abc"}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": "中文"}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": "中文"}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": "中文"}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": abc}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": abc}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "infinity": abc}\', 0) from tb;') - - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"begin": 0, "factor": 1, "count": 1, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"begin": 0, "factor": 1, "count": 1, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"begin": 0, "factor": 1, "count": 1, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "width": 1, "count": 1, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "cnt": 1, "infinity": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "cnt": 1, "infinity": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "cnt": 1, "infinity": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "inf": true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "inf": true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{"start": 0, "factor": 1, "count": 1, "inf": true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{start: 0, factor: 1, count: 1, infinity: true}\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{start: 0, factor: 1, count: 1, infinity: true}\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'{start: 0, factor: 1, count: 1, infinity: true}\', 0) from tb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'[ 0, 1, 1, true]\', 0) from stb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'[ 0, 1, 1, true]\', 0) from ctb;') - tdSql.error('select histogram(col_tinyint, \'log_bin\', \'[ 0, 1, 1, true]\', 0) from tb;') - - print("============== STEP 3: normalization ================== ") - ## Normalization ## - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 1) from ctb;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0.333333}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0.333333}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":0.333333}'); - tdSql.query('select histogram(col_smallint, "user_input", "[1,3,5,7]", 1) from tb;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0.333333}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0.333333}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":0.333333}'); - - tdSql.query('select histogram(col_int, "user_input", "[1,5,10]", 0) from stb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":5, "count":4}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":5}'); - tdSql.query('select histogram(col_int, "user_input", "[1,5,10]", 1) from ctb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":5, "count":0.444444}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":0.555556}'); - tdSql.query('select histogram(col_int, "user_input", "[1,5,10]", 1) from tb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":5, "count":0.444444}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":10, "count":0.555556}'); - - tdSql.query('select histogram(col_double, "user_input", "[0,5,11]", 0) from stb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":5, "count":4}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":11, "count":6}'); - tdSql.query('select histogram(col_double, "user_input", "[0,5,11]", 1) from ctb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":5, "count":0.400000}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":11, "count":0.600000}'); - tdSql.query('select histogram(col_double, "user_input", "[0,5,11]", 1) from tb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":5, "count":0.400000}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":11, "count":0.600000}'); - - tdSql.query('select histogram(col_bigint, \'linear_bin\', \'{"start": 1, "width": 5, "count": 2, "infinity": false}\', 0) from stb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":6, "count":5}'); - tdSql.checkData(1, 0, '{"lower_bin":6, "upper_bin":11, "count":4}'); - tdSql.query('select histogram(col_bigint, \'linear_bin\', \'{"start": 1, "width": 5, "count": 2, "infinity": false}\', 1) from ctb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":6, "count":0.555556}'); - tdSql.checkData(1, 0, '{"lower_bin":6, "upper_bin":11, "count":0.444444}'); - tdSql.query('select histogram(col_bigint, \'linear_bin\', \'{"start": 1, "width": 5, "count": 2, "infinity": false}\', 1) from tb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":6, "count":0.555556}'); - tdSql.checkData(1, 0, '{"lower_bin":6, "upper_bin":11, "count":0.444444}'); - - tdSql.query('select histogram(col_int, \'linear_bin\', \'{"start": -10, "width": 5, "count": 3, "infinity": true}\', 0) from stb;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-10, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-10, "upper_bin":-5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":-5, "upper_bin":0, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":0, "upper_bin":5, "count":5}'); - tdSql.checkData(4, 0, '{"lower_bin":5, "upper_bin":inf, "count":8}'); - tdSql.query('select histogram(col_int, \'linear_bin\', \'{"start": -10, "width": 5, "count": 3, "infinity": true}\', 1) from ctb;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-10, "count":0.000000}'); - tdSql.checkData(1, 0, '{"lower_bin":-10, "upper_bin":-5, "count":0.066667}'); - tdSql.checkData(2, 0, '{"lower_bin":-5, "upper_bin":0, "count":0.066667}'); - tdSql.checkData(3, 0, '{"lower_bin":0, "upper_bin":5, "count":0.333333}'); - tdSql.checkData(4, 0, '{"lower_bin":5, "upper_bin":inf, "count":0.533333}'); - tdSql.query('select histogram(col_int, \'linear_bin\', \'{"start": -10, "width": 5, "count": 3, "infinity": true}\', 1) from tb;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-10, "count":0.000000}'); - tdSql.checkData(1, 0, '{"lower_bin":-10, "upper_bin":-5, "count":0.066667}'); - tdSql.checkData(2, 0, '{"lower_bin":-5, "upper_bin":0, "count":0.066667}'); - tdSql.checkData(3, 0, '{"lower_bin":0, "upper_bin":5, "count":0.333333}'); - tdSql.checkData(4, 0, '{"lower_bin":5, "upper_bin":inf, "count":0.533333}'); - - tdSql.query('select histogram(col_float, \'log_bin\', \'{"start": 1, "factor": 5, "count": 3, "infinity": false}\', 0) from stb;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":5, "count":4}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":25, "count":8}'); - tdSql.checkData(2, 0, '{"lower_bin":25, "upper_bin":125, "count":1}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"start": 1, "factor": 5, "count": 3, "infinity": false}\', 1) from ctb;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":5, "count":0.307692}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":25, "count":0.615385}'); - tdSql.checkData(2, 0, '{"lower_bin":25, "upper_bin":125, "count":0.076923}'); - tdSql.query('select histogram(col_float, \'log_bin\', \'{"start": 1, "factor": 5, "count": 3, "infinity": false}\', 1) from tb;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":5, "count":0.307692}'); - tdSql.checkData(1, 0, '{"lower_bin":5, "upper_bin":25, "count":0.615385}'); - tdSql.checkData(2, 0, '{"lower_bin":25, "upper_bin":125, "count":0.076923}'); - - tdSql.query('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": false}\', 0) from stb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":-0.5, "upper_bin":-0.25, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":-0.25, "upper_bin":-0.125, "count":0}'); - tdSql.query('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": false}\', 1) from ctb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":-0.5, "upper_bin":-0.25, "count":0.000000}'); - tdSql.checkData(1, 0, '{"lower_bin":-0.25, "upper_bin":-0.125, "count":0.000000}'); - tdSql.query('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": false}\', 1) from tb;') - tdSql.checkRows(2) - tdSql.checkData(0, 0, '{"lower_bin":-0.5, "upper_bin":-0.25, "count":0.000000}'); - tdSql.checkData(1, 0, '{"lower_bin":-0.25, "upper_bin":-0.125, "count":0.000000}'); - - tdSql.query('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": true}\', 0) from stb;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-0.5, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":-0.5, "upper_bin":-0.25, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":-0.25, "upper_bin":-0.125, "count":0}'); - tdSql.checkData(3, 0, '{"lower_bin":-0.125, "upper_bin":inf, "count":13}'); - tdSql.query('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": true}\', 1) from ctb;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-0.5, "count":0.133333}'); - tdSql.checkData(1, 0, '{"lower_bin":-0.5, "upper_bin":-0.25, "count":0.000000}'); - tdSql.checkData(2, 0, '{"lower_bin":-0.25, "upper_bin":-0.125, "count":0.000000}'); - tdSql.checkData(3, 0, '{"lower_bin":-0.125, "upper_bin":inf, "count":0.866667}'); - tdSql.query('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": true}\', 1) from tb;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":-inf, "upper_bin":-0.5, "count":0.133333}'); - tdSql.checkData(1, 0, '{"lower_bin":-0.5, "upper_bin":-0.25, "count":0.000000}'); - tdSql.checkData(2, 0, '{"lower_bin":-0.25, "upper_bin":-0.125, "count":0.000000}'); - tdSql.checkData(3, 0, '{"lower_bin":-0.125, "upper_bin":inf, "count":0.866667}'); - - #ERROR CASE - tdSql.error('select histogram(col_smallint, "user_input", "[1,3,5,7]", -10) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 2) from ctb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 3.14) from tb;') - - tdSql.error('select histogram(col_bigint, \'linear_bin\', \'{"start": 1, "width": 5, "count": 2, "infinity": false}\', true) from stb;') - tdSql.error('select histogram(col_bigint, \'linear_bin\', \'{"start": 1, "width": 5, "count": 2, "infinity": false}\', false) from ctb;') - - tdSql.error('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": true}\', "abc") from tb;') - tdSql.error('select histogram(col_double, \'log_bin\', \'{"start": -0.5, "factor": 0.5, "count": 2, "infinity": true}\', abc) from tb;') - - print("============== STEP 4: combinations ================== ") - ## Combinations ## - #select distinct func(col_name) - tdSql.error('select distinct histogram(col_tinyint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_smallint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_int, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_float, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_double, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_bool, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_timestamp, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_nchar, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(col_binary, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_tinyint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_smallint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_int, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_float, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_double, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_bool, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_timestamp, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_nchar, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select distinct histogram(tag_binary, "user_input", "[1,3,5,7]", 0) from stb;') - - tdSql.error('select histogram(*, "user_input", "[1,3,5,7]", 0) from stb;') - - #select func(col_name arith_oper xxx) - tdSql.error('select histogram(col_int + 1, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int - 1, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int * 2.0, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int / 2.0, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int % 2.0, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_timestamp + now, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int + col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int - col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int * col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int / col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int % col_bigint, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int + pow(1,2), "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int - abs(-100), "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int * round(col_float), "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int / ceil(1.5), "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int % floor(col_double), "user_input", "[1,3,5,7]", 0) from stb;') - - #select func() arith_oper xxx - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) + 1 from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) - 1 from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) * 1 from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) / 1 from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) % 1 from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) + col_double from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) - col_double from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) * col_double from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) / col_double from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) % col_double from stb;') - - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) + abs(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) - ceil(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) * floor(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) / round(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) % acos(col_double) from stb;') - - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) + max(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) - min(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) * first(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) / last(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) % top(col_double, 1) from stb;') - - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) + sum(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) - avg(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) * count(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) / stddev(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0) % twa(col_double) from stb;') - - #select func(),xxx - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_tinyint from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_smallint from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_int from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_bigint from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_timstamp from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_bool from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_float from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_double from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_binary from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),col_nchar from stb;') - - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_tinyint from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_smallint from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_int from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_bigint from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_timstamp from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_bool from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_float from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_double from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_binary from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_nchar from stb;') - - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_tinyint from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_smallint from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_int from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_bigint from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_timstamp from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_bool from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_float from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_double from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_binary from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tag_nchar from stb;') - - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),ts from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),tbname from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),_c0 from stb;') - tdSql.error('select histogram(tag_int, "user_input", "[1,3,5,7]", 0),_C0 from stb;') - - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),abs(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),ceil(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),floor(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),round(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),acos(col_double) from stb;') - - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),max(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),min(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),first(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),last(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),top(col_double, 1) from stb;') - - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),sum(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),avg(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),count(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),stddev(col_double) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),twa(col_double) from stb;') - - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),histogram(col_int, "user_input", "[1,3,5,7]", 0) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),histogram(col_int, "linear_bin", \'{"start": -1, "width":5, "count":5, "infinity":false}\', 0) from stb;') - tdSql.error('select histogram(col_int, "user_input", "[1,3,5,7]", 0),histogram(col_int, "log_bin", \'{"start": 10, "factor":0.5, "count":5, "infinity":false}\', 0) from stb;') - - #select where condition - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int > 3;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int < 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int >= 3;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int <= 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int = 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int != 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int <> 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int > 5 and col_int <7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int >= 5 and col_int <=7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_int, "user_input", "[1,3,5,7,9,15]", 0) from tb where col_int between 5 and 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint > 3;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint < 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint >= 3;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint <= 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint = 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint != 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint <> 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint > 5 and col_tinyint <7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint >= 5 and col_tinyint <=7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_tinyint, "user_input", "[1,3,5,7,9,15]", 0) from ctb where col_tinyint between 5 and 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint > 3;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint < 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint >= 3;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint <= 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint = 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint != 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint <> 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint > 5 and col_bigint <7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":0}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint >= 5 and col_bigint <=7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where col_bigint between 5 and 7;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":0}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":1}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":0}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":0}'); - - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint > 0;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint < 2;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint >= 1;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint <= 1;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint = 1;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint != 2;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint <> 2;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint > 0 and tag_bigint < 2;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint >= 1 and tag_bigint <= 1;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_bigint, "user_input", "[1,3,5,7,9,15]", 0) from stb where tag_bigint between 0 and 2;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - #select session - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1w);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1d);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1h);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1m);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1s);') - #tdSql.checkRows(16) - #tdSql.checkData(0, 1, "(0:10]:0"); - #tdSql.checkData(1, 1, "(0:10]:0"); - #tdSql.checkData(2, 1, "(0:10]:1"); - #tdSql.checkData(3, 1, "(0:10]:1"); - #tdSql.checkData(4, 1, "(0:10]:1"); - #tdSql.checkData(5, 1, "(0:10]:1"); - #tdSql.checkData(6, 1, "(0:10]:1"); - #tdSql.checkData(7, 1, "(0:10]:1"); - #tdSql.checkData(8, 1, "(0:10]:1"); - #tdSql.checkData(9, 1, "(0:10]:1"); - #tdSql.checkData(10, 1, "(0:10]:1"); - #tdSql.checkData(11, 1, "(0:10]:1"); - #tdSql.checkData(12, 1, "(0:10]:0"); - #tdSql.checkData(13, 1, "(0:10]:0"); - #tdSql.checkData(14, 1, "(0:10]:0"); - #tdSql.checkData(15, 1, "(0:10]:0"); - - #tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb session (col_timestamp, 1a);') - #tdSql.checkRows(16) - #tdSql.checkData(0, 1, "(0:10]:0"); - #tdSql.checkData(1, 1, "(0:10]:0"); - #tdSql.checkData(2, 1, "(0:10]:1"); - #tdSql.checkData(3, 1, "(0:10]:1"); - #tdSql.checkData(4, 1, "(0:10]:1"); - #tdSql.checkData(5, 1, "(0:10]:1"); - #tdSql.checkData(6, 1, "(0:10]:1"); - #tdSql.checkData(7, 1, "(0:10]:1"); - #tdSql.checkData(8, 1, "(0:10]:1"); - #tdSql.checkData(9, 1, "(0:10]:1"); - #tdSql.checkData(10, 1, "(0:10]:1"); - #tdSql.checkData(11, 1, "(0:10]:1"); - #tdSql.checkData(12, 1, "(0:10]:0"); - #tdSql.checkData(13, 1, "(0:10]:0"); - #tdSql.checkData(14, 1, "(0:10]:0"); - #tdSql.checkData(15, 1, "(0:10]:0"); - - #select state_window - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_timestamp);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_tinyint);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_smallint);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_int);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_bigint);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_bool);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_float);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_double);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_binary);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb state_window(col_nchar);') - - #select interval/sliding/fill - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1y);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1n);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1w);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1d);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1h);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1s);') - tdSql.checkRows(16) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1a);') - tdSql.checkRows(16) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1w) sliding(1w);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1d) sliding(1d);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1h) sliding(1h);') - tdSql.checkRows(1) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":10}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,10]", 0) from tb interval(1s) sliding(1s);') - tdSql.checkRows(16) - tdSql.checkData(0, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(1, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(2, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(3, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(4, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(5, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(6, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(7, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(8, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(9, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(10, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(11, 1, '{"lower_bin":0, "upper_bin":10, "count":1}'); - tdSql.checkData(12, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(13, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(14, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - tdSql.checkData(15, 1, '{"lower_bin":0, "upper_bin":10, "count":0}'); - - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1w and col_timestamp < now + 1w interval(1w) fill(NULL);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1d and col_timestamp < now + 1d interval(1d) fill(None);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1h and col_timestamp < now + 1h interval(1h) fill(Prev);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1m and col_timestamp < now + 1m interval(1m) fill(Next);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1s and col_timestamp < now + 1s interval(1s) fill(Linear);') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from tb where col_timestamp > now - 1a and col_timestamp < now + 1a interval(1a) fill(Value, 1);') - - #select group by - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_tinyint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_smallint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_int;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_bigint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_bool;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_float;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_double;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_binary;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by col_nchar;') - - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_tinyint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_smallint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_int;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_bigint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_bool;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_float;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_double;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_binary;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_nchar;') - - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tbname;') - - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_tinyint,col_tinyint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_smallint,col_smallint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_int,col_int;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_bigint,col_bigint;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_bool,col_bool;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_float,col_float;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_double,col_double;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_binary,col_binary;') - tdSql.error('select histogram(col_int, "user_input", "[0,10]", 0) from stb group by tag_nchar,col_nchar;') - - #select order by - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_timestamp;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_timestamp desc;') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_tinyint;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_tinyint desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_smallint;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_smallint desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_int;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_int desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_bigint;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_bigint desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_bool;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_bool desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_float;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_float desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_double;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_double desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_double;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_double desc;') - - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_tinyint;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_tinyint desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_smallint;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_smallint desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_int;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_int desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bigint;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bigint desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bool;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bool desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_float;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_float desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double desc;') - - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tbname;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tbname desc;') - - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_timestamp,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_timestamp,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_tinyint,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_tinyint,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_smallint,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_smallint,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_int,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_int,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bigint,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bigint,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bool,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_bool,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_float,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_float,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double,col_timestamp desc;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double,col_timestamp;') - tdSql.error('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by tag_double,col_timestamp desc;') - - #select limit/offset - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb limit 3;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb limit 3;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb limit 3;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb limit 3 offset 2;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb limit 3 offset 2;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb limit 3 offset 2;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb limit 2,3;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb limit 2,3;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb limit 2,3;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - #nested query - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from (select * from stb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from (select * from ctb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from (select * from tb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.query('select histogram(val, "user_input", "[0,3,5,7,9,15]", 0) from (select col_int as val from stb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(val, "user_input", "[0,3,5,7,9,15]", 0) from (select col_int as val from ctb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select histogram(val, "user_input", "[0,3,5,7,9,15]", 0) from (select col_int as val from tb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.query('select * from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select * from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb)') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select * from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb)') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb)') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb)') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.query('select first(_c0) from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb);') - tdSql.checkRows(1) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.query('select first(_c0) from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb)') - tdSql.checkRows(1) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.query('select first(_c0) from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb)') - tdSql.checkRows(1) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - - tdSql.query('select last(_c0) from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb);') - tdSql.checkRows(1) - tdSql.checkData(0, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select last(_c0) from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb)') - tdSql.checkRows(1) - tdSql.checkData(0, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select last(_c0) from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb)') - tdSql.checkRows(1) - tdSql.checkData(0, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb limit 3);') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb limit 3)') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb limit 3)') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb) limit 3;') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb) limit 3') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb) limit 3') - tdSql.checkRows(3) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb order by col_timestamp);') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb order by col_timestamp)') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - tdSql.query('select _c0 from (select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb order by col_timestamp)') - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - #join - tdSql.execute("create stable stb1 (col_timestamp timestamp, col_tinyint tinyint, col_smallint smallint, col_int int, col_bigint bigint, col_float float, col_double double, col_bool bool, col_binary binary(10), col_nchar nchar(10)) \ - tags(tag_timestamp timestamp, tag_tinyint tinyint, tag_smallint smallint, tag_int int, tag_bigint bigint, tag_float float, tag_double double, tag_bool bool, tag_binary binary(10), tag_nchar nchar(10));") - tdSql.execute("create table ctb1 using stb1 tags (now, 1, 1, 1, 1, 1.0, 1.0, true, 'abc', 'abc');") - tdSql.execute("create table tb1 (col_timestamp timestamp, col_tinyint tinyint, col_smallint smallint, col_int int, col_bigint bigint, col_float float, col_double double, col_bool bool, col_binary binary(10), col_nchar nchar(10));") - - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:00', -9, -9, -9, -9, -9.5, -9.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:01', -1, -1, -1, -1, -1.5, -1.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:02', 1, 1, 1, 1, 1.5, 1.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:03', 2, 2, 2, 2, 2.5, 2.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:04', 3, 3, 3, 3, 3.5, 3.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:05', 4, 4, 4, 4, 4.5, 4.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:06', 5, 5, 5, 5, 5.5, 5.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:07', 6, 6, 6, 6, 6.5, 6.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:08', 7, 7, 7, 7, 7.5, 7.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:09', 8, 8, 8, 8, 8.5, 8.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:10', 9, 9, 9, 9, 9.5, 9.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:11', 10, 10, 10, 10, 10.5, 10.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:12', 15, 15, 15, 15, 15.5, 15.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:13', 20, 20, 20, 20, 20.5, 20.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:14', 99, 99, 99, 99, 99.5, 99.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb1 values ('2022-01-01 00:00:15', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);") - - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:00', -9, -9, -9, -9, -9.5, -9.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:01', -1, -1, -1, -1, -1.5, -1.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:02', 1, 1, 1, 1, 1.5, 1.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:03', 2, 2, 2, 2, 2.5, 2.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:04', 3, 3, 3, 3, 3.5, 3.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:05', 4, 4, 4, 4, 4.5, 4.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:06', 5, 5, 5, 5, 5.5, 5.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:07', 6, 6, 6, 6, 6.5, 6.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:08', 7, 7, 7, 7, 7.5, 7.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:09', 8, 8, 8, 8, 8.5, 8.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:10', 9, 9, 9, 9, 9.5, 9.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:11', 10, 10, 10, 10, 10.5, 10.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:12', 15, 15, 15, 15, 15.5, 15.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:13', 20, 20, 20, 20, 20.5, 20.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:14', 99, 99, 99, 99, 99.5, 99.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb1 values ('2022-01-01 00:00:15', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);") - - tdSql.execute("create stable stb2 (col_timestamp timestamp, col_tinyint tinyint, col_smallint smallint, col_int int, col_bigint bigint, col_float float, col_double double, col_bool bool, col_binary binary(10), col_nchar nchar(10)) \ - tags(tag_timestamp timestamp, tag_tinyint tinyint, tag_smallint smallint, tag_int int, tag_bigint bigint, tag_float float, tag_double double, tag_bool bool, tag_binary binary(10), tag_nchar nchar(10));") - tdSql.execute("create table ctb2 using stb2 tags (now, 1, 1, 1, 1, 1.0, 1.0, true, 'abc', 'abc');") - tdSql.execute("create table tb2 (col_timestamp timestamp, col_tinyint tinyint, col_smallint smallint, col_int int, col_bigint bigint, col_float float, col_double double, col_bool bool, col_binary binary(10), col_nchar nchar(10));") - - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:00', -9, -9, -9, -9, -9.5, -9.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:01', -1, -1, -1, -1, -1.5, -1.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:02', 1, 1, 1, 1, 1.5, 1.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:03', 2, 2, 2, 2, 2.5, 2.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:04', 3, 3, 3, 3, 3.5, 3.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:05', 4, 4, 4, 4, 4.5, 4.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:06', 5, 5, 5, 5, 5.5, 5.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:07', 6, 6, 6, 6, 6.5, 6.5, true, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:08', 7, 7, 7, 7, 7.5, 7.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:09', 8, 8, 8, 8, 8.5, 8.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:10', 9, 9, 9, 9, 9.5, 9.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:11', 10, 10, 10, 10, 10.5, 10.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:12', 15, 15, 15, 15, 15.5, 15.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:13', 20, 20, 20, 20, 20.5, 20.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:14', 99, 99, 99, 99, 99.5, 99.5, false, 'abc', 'abc');") - tdSql.execute("insert into ctb2 values ('2022-01-01 00:00:15', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);") - - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:00', -9, -9, -9, -9, -9.5, -9.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:01', -1, -1, -1, -1, -1.5, -1.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:02', 1, 1, 1, 1, 1.5, 1.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:03', 2, 2, 2, 2, 2.5, 2.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:04', 3, 3, 3, 3, 3.5, 3.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:05', 4, 4, 4, 4, 4.5, 4.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:06', 5, 5, 5, 5, 5.5, 5.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:07', 6, 6, 6, 6, 6.5, 6.5, true, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:08', 7, 7, 7, 7, 7.5, 7.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:09', 8, 8, 8, 8, 8.5, 8.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:10', 9, 9, 9, 9, 9.5, 9.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:11', 10, 10, 10, 10, 10.5, 10.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:12', 15, 15, 15, 15, 15.5, 15.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:13', 20, 20, 20, 20, 20.5, 20.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:14', 99, 99, 99, 99, 99.5, 99.5, false, 'abc', 'abc');") - tdSql.execute("insert into tb2 values ('2022-01-01 00:00:15', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);") - - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from tb1, tb2 where tb1.col_timestamp = tb2.col_timestamp;'); - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from ctb1, ctb2 where ctb1.col_timestamp = ctb2.col_timestamp;'); - tdSql.checkRows(5) - tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":5, "upper_bin":7, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":7, "upper_bin":9, "count":2}'); - tdSql.checkData(4, 0, '{"lower_bin":9, "upper_bin":15, "count":2}'); - - #stable join will cause crash - #tdSql.query('select histogram(col_int, "user_input", "[0,3,5,7,9,15]", 0) from stb1, stb2 where stb1.col_timestamp = stb2.col_timestamp and stb1.tag_int = stb2.tag_int;'); - #tdSql.checkRows(5) - #tdSql.checkData(0, 0, "(0:3]:3"); - #tdSql.checkData(1, 0, "(3:5]:2"); - #tdSql.checkData(2, 0, "(5:7]:2"); - #tdSql.checkData(3, 0, "(7:9]:2"); - #tdSql.checkData(4, 0, "(9:15]:2"); - - #union all - tdSql.query('select histogram(col_int, \'user_input\', \'[1,3,5]\', 0) from tb1 union all select histogram(col_int, \'user_input\', \'[1,3,5]\', 0) from tb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_int, \'user_input\', \'[1,3,5]\', 0) from ctb1 union all select histogram(col_int, \'user_input\', \'[1,3,5]\', 0) from ctb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_int, \'user_input\', \'[1,3,5]\', 0) from stb1 union all select histogram(col_int, \'user_input\', \'[1,3,5]\', 0) from stb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - tdSql.query('select histogram(col_int, \'linear_bin\', \'{"start":1, "width":2, "count":2, "infinity":false}\', 0) from tb1 union all select histogram(col_int, \'linear_bin\', \'{"start":1, "width":2, "count":2, "infinity":false}\', 0) from tb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_int, \'linear_bin\', \'{"start":1, "width":2, "count":2, "infinity":false}\', 0) from ctb1 union all select histogram(col_int, \'linear_bin\', \'{"start":1, "width":2, "count":2, "infinity":false}\', 0) from ctb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.query('select histogram(col_int, \'linear_bin\', \'{"start":1, "width":2, "count":2, "infinity":false}\', 0) from stb1 union all select histogram(col_int, \'linear_bin\', \'{"start":1, "width":2, "count":2, "infinity":false}\', 0) from stb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":3, "count":2}'); - tdSql.checkData(3, 0, '{"lower_bin":3, "upper_bin":5, "count":2}'); - - tdSql.query('select histogram(col_int, \'log_bin\', \'{"start":1, "factor":2, "count":2, "infinity":false}\', 0) from tb1 union all select histogram(col_int, \'log_bin\', \'{"start":1, "factor":2, "count":2, "infinity":false}\', 0) from tb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.query('select histogram(col_int, \'log_bin\', \'{"start":1, "factor":2, "count":2, "infinity":false}\', 0) from ctb1 union all select histogram(col_int, \'log_bin\', \'{"start":1, "factor":2, "count":2, "infinity":false}\', 0) from ctb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.query('select histogram(col_int, \'log_bin\', \'{"start":1, "factor":2, "count":2, "infinity":false}\', 0) from stb1 union all select histogram(col_int, \'log_bin\', \'{"start":1, "factor":2, "count":2, "infinity":false}\', 0) from stb2;') - tdSql.checkRows(4) - tdSql.checkData(0, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(1, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - tdSql.checkData(2, 0, '{"lower_bin":1, "upper_bin":2, "count":1}'); - tdSql.checkData(3, 0, '{"lower_bin":2, "upper_bin":4, "count":2}'); - - - tdSql.execute('drop database db') - - def histogram_check_distribute(self): - dbname = "db" - stbname = "stb" - row_num = 10 - child_table_num = 20 - vgroups = 2 - user_input_json = "[1,3,5,7]" - ts = 1537146000000 - binary_str = 'taosdata' - nchar_str = '涛思数据' - column_dict = { - 'ts' : 'timestamp', - 'col1' : 'tinyint', - 'col2' : 'smallint', - 'col3' : 'int', - 'col4' : 'bigint', - 'col5' : 'tinyint unsigned', - 'col6' : 'smallint unsigned', - 'col7' : 'int unsigned', - 'col8' : 'bigint unsigned', - 'col9' : 'float', - 'col10': 'double', - 'col11': 'bool', - 'col12': 'binary(20)', - 'col13': 'nchar(20)' - } - tdSql.execute(f"create database if not exists {dbname} vgroups {vgroups}") - tdSql.execute(f'use {dbname}') - # build 20 child tables,every table insert 10 rows - tdSql.execute(f'''create table {stbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, - col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''') - for i in range(child_table_num): - tdSql.execute(f"create table {stbname}_{i} using {stbname} tags('beijing')") - tdSql.query('show tables') - vgroup_list = [] - for i in range(len(tdSql.queryResult)): - vgroup_list.append(tdSql.queryResult[i][6]) - vgroup_list_set = set(vgroup_list) - for i in vgroup_list_set: - vgroups_num = vgroup_list.count(i) - if vgroups_num >=2: - tdLog.info(f'This scene with {vgroups_num} vgroups is ok!') - continue - else: - tdLog.exit(f'This scene does not meet the requirements with {vgroups_num} vgroup!\n') - for i in range(child_table_num): - for j in range(row_num): - tdSql.execute(f"insert into {stbname}_{i} values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{binary_str}%d', '{nchar_str}%d')" - % (ts + j + i, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 0.1, j + 0.1, j % 2, j + 1, j + 1)) - # user_input - for k,v in column_dict.items(): - if v.lower() == 'tinyint' or v.lower() == 'smallint' or v.lower() == 'int' or v.lower() == 'bigint' or v.lower() =='float' or v.lower() =='double'\ - or v.lower() =='tinyint unsigned' or v.lower() =='smallint unsigned' or v.lower() =='int unsigned' or v.lower() =='bigint unsigned': - tdSql.query(f'select histogram({k}, "user_input", "{user_input_json}", 0) from {stbname}') - tdSql.checkRows(len(user_input_json[1:-1].split(','))-1) - elif 'binary' in v.lower() or 'nchar' in v.lower() or 'bool' == v.lower(): - tdSql.error(f'select histogram({k}, "user_input", "{user_input_json}", 0) from {stbname}') - - tdSql.execute(f'drop database {dbname}') - - - def run(self): - self.histogram_check_base() - self.histogram_check_distribute() + tdDnodes.stop(1) + tdDnodes.start(1) + + tdLog.printNoPrefix("==========step3:after wal, all check again ") + tdSql.execute("use db") + self.all_test() + tdSql.execute("use db1") + self.all_test() def stop(self): tdSql.close() - tdLog.success("%s successfully executed" % __file__) + tdLog.success(f"{__file__} successfully executed") -tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/json_tag.py b/tests/system-test/2-query/json_tag.py index 9e48f7d45aaeb1ea62dae3c30c620fde03bbc838..81098159f2bc98bb12fc8784ffe452d4ea9cbfd3 100644 --- a/tests/system-test/2-query/json_tag.py +++ b/tests/system-test/2-query/json_tag.py @@ -543,9 +543,9 @@ class TDTestCase: tdSql.checkData(0, 0, 10) tdSql.query("select avg(dataint) from jsons1 where jtag is not null") tdSql.checkData(0, 0, 5.3) - tdSql.query("select twa(dataint) from jsons1 where jtag is not null") - tdSql.checkData(0, 0, 28.386363636363637) - tdSql.query("select irate(dataint) from jsons1 where jtag is not null") + # tdSql.query("select twa(dataint) from jsons1 where jtag is not null") + # tdSql.checkData(0, 0, 28.386363636363637) + # tdSql.query("select irate(dataint) from jsons1 where jtag is not null") tdSql.query("select sum(dataint) from jsons1 where jtag->'tag1' is not null") tdSql.checkData(0, 0, 45) @@ -575,10 +575,10 @@ class TDTestCase: #test calculation function:diff/derivative/spread/ceil/floor/round/ tdSql.query("select diff(dataint) from jsons1 where jtag->'tag1'>1") tdSql.checkRows(2) - tdSql.checkData(0, 0, -1) - tdSql.checkData(1, 0, 10) + # tdSql.checkData(0, 0, -1) + # tdSql.checkData(1, 0, 10) tdSql.query("select derivative(dataint, 10m, 0) from jsons1 where jtag->'tag1'>1") - tdSql.checkData(0, 0, -2) + # tdSql.checkData(0, 0, -2) tdSql.query("select spread(dataint) from jsons1 where jtag->'tag1'>1") tdSql.checkData(0, 0, 10) tdSql.query("select ceil(dataint) from jsons1 where jtag->'tag1'>1") diff --git a/tests/system-test/2-query/mavg.py b/tests/system-test/2-query/mavg.py index fa2d0f47a4580472a4c8403f4e9b6e7384c73a52..346d9e1df39b6abd46a8305b0f1a1714781b99f3 100644 --- a/tests/system-test/2-query/mavg.py +++ b/tests/system-test/2-query/mavg.py @@ -673,11 +673,65 @@ class TDTestCase: tdSql.query("select mavg(abs(c1),1) from t1") tdSql.checkRows(4) + def mavg_support_stable(self): + tdSql.query(" select mavg(1,3) from stb1 ") + tdSql.checkRows(68) + tdSql.checkData(0,0,1.000000000) + tdSql.query("select mavg(c1,3) from stb1 partition by tbname ") + tdSql.checkRows(38) + # tdSql.query("select mavg(st1,3) from stb1 partition by tbname") + # tdSql.checkRows(38) + tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") + tdSql.checkRows(38) + tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") + tdSql.checkRows(38) + tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") + tdSql.checkRows(38) + + # # bug need fix + # tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname slimit 1 ") + # tdSql.checkRows(2) + # tdSql.error("select mavg(st1+c1,3) from stb1 partition by tbname limit 1 ") + + + # bug need fix + tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") + tdSql.checkRows(38) + + # bug need fix + # tdSql.query("select tbname , mavg(c1,3) from stb1 partition by tbname") + # tdSql.checkRows(38) + # tdSql.query("select tbname , mavg(st1,3) from stb1 partition by tbname") + # tdSql.checkRows(38) + # tdSql.query("select tbname , mavg(st1,3) from stb1 partition by tbname slimit 1") + # tdSql.checkRows(2) + + # partition by tags + # tdSql.query("select st1 , mavg(c1,3) from stb1 partition by st1") + # tdSql.checkRows(38) + # tdSql.query("select mavg(c1,3) from stb1 partition by st1") + # tdSql.checkRows(38) + # tdSql.query("select st1 , mavg(c1,3) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(2) + # tdSql.query("select mavg(c1,3) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(2) + + # partition by col + # tdSql.query("select c1 , mavg(c1,3) from stb1 partition by c1") + # tdSql.checkRows(38) + # tdSql.query("select mavg(c1 ,3) from stb1 partition by c1") + # tdSql.checkRows(38) + # tdSql.query("select c1 , mavg(c1,3) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(2) + # tdSql.query("select diff(c1) from stb1 partition by st1 slimit 1") + # tdSql.checkRows(2) + def run(self): import traceback try: # run in develop branch self.mavg_test_run() + self.mavg_support_stable() pass except Exception as e: traceback.print_exc() diff --git a/tests/system-test/2-query/percentile.py b/tests/system-test/2-query/percentile.py index 8df9bcb9ce4df065a151d33116f1331298ee35fd..c2584fd3949ad1df852f292a553f152ed7b5098f 100644 --- a/tests/system-test/2-query/percentile.py +++ b/tests/system-test/2-query/percentile.py @@ -21,7 +21,7 @@ import numpy as np class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor(), True) self.rowNum = 10 self.ts = 1537146000000 diff --git a/tests/system-test/2-query/queryQnode.py b/tests/system-test/2-query/queryQnode.py index 0011fe248f2c951f4829cc02d9f718310e429789..d9976d8f3e2cb9c9dac494d3f5c0245d03e19944 100644 --- a/tests/system-test/2-query/queryQnode.py +++ b/tests/system-test/2-query/queryQnode.py @@ -478,6 +478,9 @@ class TDTestCase: self.test_case3() # tdLog.debug(" LIMIT test_case3 ............ [OK]") + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") return # diff --git a/tests/system-test/2-query/sample.py b/tests/system-test/2-query/sample.py index 33ef7e65db0fbb3d40730f9cc012fd5d0d7b9d15..f583b7dd783df58f9784e732a69ba7c40cf1c4b2 100644 --- a/tests/system-test/2-query/sample.py +++ b/tests/system-test/2-query/sample.py @@ -798,6 +798,36 @@ class TDTestCase: tdSql.query("select sample(c1,100)+2 from ct1") tdSql.query("select abs(sample(c1,100)) from ct1") + # support stable and tbname + tdSql.query("select tbname ,sample(c1,2) from stb1 partition by tbname order by tbname") + tdSql.checkRows(4) + tdSql.checkData(0,0,'ct1') + tdSql.checkData(3,0,'ct4') + + # # bug need fix + # tdSql.query(" select tbname ,c1 ,t1, sample(c1,2) from stb1 partition by tbname order by tbname ") + # tdSql.checkRows(4) + # tdSql.checkData(0,0,'ct1') + # tdSql.checkData(3,0,'ct4') + # tdSql.checkData(0,2,1) + # tdSql.checkData(3,2,4) + + tdSql.query(" select tbname ,c1 ,t1, sample(c1,2) from stb1 partition by t1 order by t1 ") + tdSql.checkRows(4) + tdSql.checkData(0,0,'ct1') + tdSql.checkData(3,0,'ct4') + tdSql.checkData(0,2,1) + tdSql.checkData(3,2,4) + + # bug need fix + # tdSql.query(" select tbname ,c1 ,t1, sample(c1,2) from stb1 partition by c1 order by c1 ") + # tdSql.checkRows(21) + + # bug need fix + # tdSql.query(" select sample(c1,2) from stb1 partition by c1 ") + # tdSql.checkRows(21) + + def sample_test_run(self) : tdLog.printNoPrefix("==========support sample function==========") tbnum = 10 diff --git a/tests/system-test/2-query/statecount.py b/tests/system-test/2-query/statecount.py index fbeb04bc2f54a8e749b893abecb6605eb512d505..ed97521c51153aa3ac9824f4435599d5c84375f1 100644 --- a/tests/system-test/2-query/statecount.py +++ b/tests/system-test/2-query/statecount.py @@ -18,6 +18,7 @@ class TDTestCase: def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) + self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record def prepare_datas(self): tdSql.execute( @@ -344,6 +345,8 @@ class TDTestCase: tdSql.error("select stateduration(c1,'GT',1,1b) from ct1") tdSql.error("select stateduration(c1,'GT',1,1u) from ct1") tdSql.error("select stateduration(c1,'GT',1,1000s) from t1") + tdSql.error("select stateduration(c1,'GT',1,10m) from t1") + tdSql.error("select stateduration(c1,'GT',1,10d) from t1") tdSql.query("select stateduration(c1,'GT',1,1s) from t1") tdSql.checkData(10,0,63072035) tdSql.query("select stateduration(c1,'GT',1,1m) from t1") @@ -355,6 +358,58 @@ class TDTestCase: tdSql.query("select stateduration(c1,'GT',1,1w) from t1") tdSql.checkData(10,0,int(63072035/60/7/24/60)) + def query_precision(self): + def generate_data(precision="ms"): + tdSql.execute("create database if not exists db_%s precision '%s';" %(precision, precision)) + tdSql.execute("use db_%s;" %precision) + tdSql.execute("create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision) + tdSql.execute("create table db_%s.tb1 using st tags(1);"%precision) + tdSql.execute("create table db_%s.tb2 using st tags(2);"%precision) + + if precision == "ms": + start_ts = self.ts + step = 10000 + elif precision == "us": + start_ts = self.ts*1000 + step = 10000000 + elif precision == "ns": + start_ts = self.ts*1000000 + step = 10000000000 + else: + pass + + for i in range(10): + + sql1 = "insert into db_%s.tb1 values (%d,%d)"%(precision ,start_ts+i*step,i) + sql2 = "insert into db_%s.tb1 values (%d,%d)"%(precision, start_ts+i*step,i) + tdSql.execute(sql1) + tdSql.execute(sql2) + + time_units = ["1s","1a","1u","1b"] + + precision_list = ["ms","us","ns"] + for pres in precision_list: + generate_data(pres) + + for index,unit in enumerate(time_units): + + if pres == "ms": + if unit in ["1u","1b"]: + tdSql.error("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + pass + else: + tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + elif pres == "us" and unit in ["1b"]: + if unit in ["1b"]: + tdSql.error("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + pass + else: + tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + else: + + tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + basic_result = 70 + tdSql.checkData(9,0,basic_result*pow(1000,index)) def check_boundary_values(self): @@ -420,6 +475,8 @@ class TDTestCase: tdLog.printNoPrefix("==========step6: statecount unit time test ============") self.check_unit_time() + self.query_precision() + def stop(self): diff --git a/tests/system-test/2-query/tail.py b/tests/system-test/2-query/tail.py index c03f4e03db538cfba937a156b54ada4320f6058a..1cf63e082e4894503033e760ca3f522c53f4b640 100644 --- a/tests/system-test/2-query/tail.py +++ b/tests/system-test/2-query/tail.py @@ -337,7 +337,7 @@ class TDTestCase: tdSql.checkData(2,0,5) # nest query - # tdSql.query("select tail(c1,2) from (select c1 from ct1)") + # tdSql.query("select tail(c1,2) from (select _rowts , c1 from ct1)") tdSql.query("select c1 from (select tail(c1,2) c1 from ct4) order by 1 nulls first") tdSql.checkRows(2) tdSql.checkData(0, 0, None) @@ -363,10 +363,59 @@ class TDTestCase: tdSql.error("select tail(c1,2) from ct1 group by tbname") # super table - + tdSql.error("select tbname , tail(c1,2) from stb1 group by tbname") + tdSql.query("select tail(c1,2) from stb1 partition by tbname") + tdSql.checkRows(4) + + + # bug need fix + # tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname") + # tdSql.checkRows(4) + + # tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname order by tbname") + # tdSql.checkRows(4) + + # tdSql.query(" select tbname , count(c1) from stb1 partition by tbname order by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname , max(c1) ,c1 from stb1 partition by tbname order by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname ,first(c1) from stb1 partition by tbname order by tbname ") + # tdSql.checkRows(2) + + tdSql.query("select tail(c1,2) from stb1 partition by tbname") + tdSql.checkRows(4) + + + # # bug need fix + # tdSql.query(" select tbname , tail(c1,2) from stb1 where t1 = 0 partition by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname , tail(c1,2) from stb1 where t1 = 0 partition by tbname order by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname , tail(c1,2) from stb1 where c1 = 0 partition by tbname order by tbname ") + # tdSql.checkRows(3) + # tdSql.query(" select tbname , tail(c1,2) from stb1 where c1 = 0 partition by tbname ") + # tdSql.checkRows(3) + # tdSql.query(" select tbname , tail(c1,2) from stb1 where c1 = 0 partition by tbname ") + # tdSql.checkRows(3) + tdSql.query(" select tail(t1,2) from stb1 ") + tdSql.checkRows(2) + tdSql.query(" select tail(t1+c1,2) from stb1 ") + tdSql.checkRows(2) + tdSql.query(" select tail(t1+c1,2) from stb1 partition by tbname ") + tdSql.checkRows(4) + tdSql.query(" select tail(t1,2) from stb1 partition by tbname ") + tdSql.checkRows(4) + # nest query + tdSql.query(" select tail(c1,2) from (select _rowts , t1 ,c1 , tbname from stb1 ) ") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.checkData(1,0,9) + tdSql.query("select tail(t1,2) from (select _rowts , t1 , tbname from stb1 )") + tdSql.checkRows(2) + tdSql.checkData(0,0,4) + tdSql.checkData(1,0,1) - def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") diff --git a/tests/system-test/2-query/timetruncate.py b/tests/system-test/2-query/timetruncate.py index ebc8e6b6f91acc6c5435ff6766c92dd968d55b07..ea4f963b716d45b2a2e77d8db52286442fb658a5 100644 --- a/tests/system-test/2-query/timetruncate.py +++ b/tests/system-test/2-query/timetruncate.py @@ -5,184 +5,130 @@ from util.sql import * import numpy as np import time from datetime import datetime - +from util.gettime import * class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) - - self.rowNum = 10 - self.ts = 1537146000000 # 2018-9-17 09:00:00.000 - + self.get_time = GetTime() self.ts_str = [ '2020-1-1', '2020-2-1 00:00:01', '2020-3-1 00:00:00.001', '2020-4-1 00:00:00.001002', '2020-5-1 00:00:00.001002001' - ] self.db_param_precision = ['ms','us','ns'] - self.time_unit = ['1w','1d','1h','1m','1s','1a','1u'] - #self.error_unit = ['1b','2w','2d','2h','2m','2s','2a','2u','1c','#1'] + self.time_unit = ['1w','1d','1h','1m','1s','1a','1u','1b'] self.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1'] self.ntbname = 'ntb' self.stbname = 'stb' self.ctbname = 'ctb' - def get_ms_timestamp(self,ts_str): - _ts_str = ts_str - if " " in ts_str: - p = ts_str.split(" ")[1] - if len(p) > 15 : - _ts_str = ts_str[:-3] - if ':' in _ts_str and '.' in _ts_str: - timestamp = datetime.strptime(_ts_str, "%Y-%m-%d %H:%M:%S.%f") - date_time = int(int(time.mktime(timestamp.timetuple()))*1000 + timestamp.microsecond/1000) - elif ':' in _ts_str and '.' not in _ts_str: - timestamp = datetime.strptime(_ts_str, "%Y-%m-%d %H:%M:%S") - date_time = int(int(time.mktime(timestamp.timetuple()))*1000 + timestamp.microsecond/1000) - else: - timestamp = datetime.strptime(_ts_str, "%Y-%m-%d") - date_time = int(int(time.mktime(timestamp.timetuple()))*1000 + timestamp.microsecond/1000) - return date_time - def get_us_timestamp(self,ts_str): - _ts = self.get_ms_timestamp(ts_str) * 1000 - if " " in ts_str: - p = ts_str.split(" ")[1] - if len(p) > 12: - us_ts = p[12:15] - _ts += int(us_ts) - return _ts - def get_ns_timestamp(self,ts_str): - _ts = self.get_us_timestamp(ts_str) *1000 - if " " in ts_str: - p = ts_str.split(" ")[1] - if len(p) > 15: - us_ts = p[15:] - _ts += int(us_ts) - return _ts - def time_transform(self,ts_str,precision): - date_time = [] - if precision == 'ms': - for i in ts_str: - date_time.append(self.get_ms_timestamp(i)) - elif precision == 'us': - for i in ts_str: - date_time.append(self.get_us_timestamp(i)) - elif precision == 'ns': - for i in ts_str: - date_time.append(self.get_us_timestamp(i)) - return date_time def check_ms_timestamp(self,unit,date_time): if unit.lower() == '1a': for i in range(len(self.ts_str)): - ts_result = self.get_ms_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i])) elif unit.lower() == '1s': for i in range(len(self.ts_str)): - ts_result = self.get_ms_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000)*1000) elif unit.lower() == '1m': for i in range(len(self.ts_str)): - ts_result = self.get_ms_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000/60)*60*1000) elif unit.lower() == '1h': for i in range(len(self.ts_str)): - ts_result = self.get_ms_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000/60/60)*60*60*1000 ) elif unit.lower() == '1d': for i in range(len(self.ts_str)): - ts_result = self.get_ms_timestamp(str(tdSql.queryResult[i][0])) - tdSql.checkEqual(ts_result,int(date_time[i]/1000/60/60/24)*24*60*60*1000) + ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0])) + tdSql.checkEqual(ts_result,int(date_time[i]/1000/60/60/24)*24*60*60*1000) elif unit.lower() == '1w': for i in range(len(self.ts_str)): - ts_result = self.get_ms_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_ms_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000/60/60/24/7)*7*24*60*60*1000) def check_us_timestamp(self,unit,date_time): if unit.lower() == '1u': for i in range(len(self.ts_str)): - ts_result = self.get_us_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i])) elif unit.lower() == '1a': for i in range(len(self.ts_str)): - ts_result = self.get_us_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000)*1000) elif unit.lower() == '1s': for i in range(len(self.ts_str)): - ts_result = self.get_us_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000)*1000*1000) elif unit.lower() == '1m': for i in range(len(self.ts_str)): - ts_result = self.get_us_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000/60)*60*1000*1000) elif unit.lower() == '1h': for i in range(len(self.ts_str)): - ts_result = self.get_us_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000/60/60)*60*60*1000*1000 ) elif unit.lower() == '1d': for i in range(len(self.ts_str)): - ts_result = self.get_us_timestamp(str(tdSql.queryResult[i][0])) - tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000/60/60/24)*24*60*60*1000*1000 ) + ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) + tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000/60/60/24)*24*60*60*1000*1000 ) elif unit.lower() == '1w': for i in range(len(self.ts_str)): - ts_result = self.get_us_timestamp(str(tdSql.queryResult[i][0])) + ts_result = self.get_time.get_us_timestamp(str(tdSql.queryResult[i][0])) tdSql.checkEqual(ts_result,int(date_time[i]/1000/1000/60/60/24/7)*7*24*60*60*1000*1000) def check_ns_timestamp(self,unit,date_time): - if unit.lower() == '1u': + if unit.lower() == '1b': + for i in range(len(self.ts_str)): + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i])) + elif unit.lower() == '1u': for i in range(len(self.ts_str)): - tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000)*1000) + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000)*1000) elif unit.lower() == '1a': for i in range(len(self.ts_str)): - tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000)*1000*1000) + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000)*1000*1000) elif unit.lower() == '1s': for i in range(len(self.ts_str)): - tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000)*1000*1000*1000) + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000)*1000*1000*1000) elif unit.lower() == '1m': for i in range(len(self.ts_str)): - tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/60)*60*1000*1000*1000) + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60)*60*1000*1000*1000) elif unit.lower() == '1h': for i in range(len(self.ts_str)): - tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/60/60)*60*60*1000*1000*1000 ) + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60/60)*60*60*1000*1000*1000 ) elif unit.lower() == '1d': for i in range(len(self.ts_str)): - tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/60/60/24)*24*60*60*1000*1000*1000 ) + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60/60/24)*24*60*60*1000*1000*1000 ) elif unit.lower() == '1w': for i in range(len(self.ts_str)): - tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/60/60/24/7)*7*24*60*60*1000*1000*1000) + tdSql.checkEqual(tdSql.queryResult[i][0],int(date_time[i]*1000/1000/1000/1000/1000/60/60/24/7)*7*24*60*60*1000*1000*1000) + def check_tb_type(self,unit,tb_type): + if tb_type.lower() == 'ntb': + tdSql.query(f'select timetruncate(ts,{unit}) from {self.ntbname}') + elif tb_type.lower() == 'ctb': + tdSql.query(f'select timetruncate(ts,{unit}) from {self.ctbname}') + elif tb_type.lower() == 'stb': + tdSql.query(f'select timetruncate(ts,{unit}) from {self.stbname}') def data_check(self,date_time,precision,tb_type): for unit in self.time_unit: - if (unit.lower() == '1u' and precision.lower() == 'ms') or () : - if tb_type.lower() == 'ntb': + if (unit.lower() == '1u' and precision.lower() == 'ms') or (unit.lower() == '1b' and precision.lower() == 'us') or (unit.lower() == '1b' and precision.lower() == 'ms'): + if tb_type.lower() == 'ntb': tdSql.error(f'select timetruncate(ts,{unit}) from {self.ntbname}') elif tb_type.lower() == 'ctb': tdSql.error(f'select timetruncate(ts,{unit}) from {self.ctbname}') elif tb_type.lower() == 'stb': tdSql.error(f'select timetruncate(ts,{unit}) from {self.stbname}') elif precision.lower() == 'ms': - if tb_type.lower() == 'ntb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.ntbname}') - elif tb_type.lower() == 'ctb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.ctbname}') - elif tb_type.lower() == 'stb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.stbname}') + self.check_tb_type(unit,tb_type) tdSql.checkRows(len(self.ts_str)) self.check_ms_timestamp(unit,date_time) elif precision.lower() == 'us': - if tb_type.lower() == 'ntb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.ntbname}') - elif tb_type.lower() == 'ctb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.ctbname}') - elif tb_type.lower() == 'stb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.stbname}') + self.check_tb_type(unit,tb_type) tdSql.checkRows(len(self.ts_str)) self.check_us_timestamp(unit,date_time) elif precision.lower() == 'ns': - if tb_type.lower() == 'ntb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.ntbname}') - elif tb_type.lower() == 'ctb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.ctbname}') - elif tb_type.lower() == 'stb': - tdSql.query(f'select timetruncate(ts,{unit}) from {self.stbname}') + self.check_tb_type(unit,tb_type) tdSql.checkRows(len(self.ts_str)) self.check_ns_timestamp(unit,date_time) for unit in self.error_unit: @@ -200,9 +146,8 @@ class TDTestCase: tdSql.execute(f'create table {self.ntbname} (ts timestamp,c0 int)') for ts in self.ts_str: tdSql.execute(f'insert into {self.ntbname} values("{ts}",1)') - date_time = self.time_transform(self.ts_str,precision) + date_time = self.get_time.time_transform(self.ts_str,precision) self.data_check(date_time,precision,'ntb') - def function_check_stb(self): for precision in self.db_param_precision: tdSql.execute('drop database if exists db') @@ -212,7 +157,7 @@ class TDTestCase: tdSql.execute(f'create table {self.ctbname} using {self.stbname} tags(1)') for ts in self.ts_str: tdSql.execute(f'insert into {self.ctbname} values("{ts}",1)') - date_time = self.time_transform(self.ts_str,precision) + date_time = self.get_time.time_transform(self.ts_str,precision) self.data_check(date_time,precision,'ctb') self.data_check(date_time,precision,'stb') def run(self): diff --git a/tests/system-test/2-query/unique.py b/tests/system-test/2-query/unique.py index aeebf2425aeb75cbe5cf3d05a46c71cbe530b6d8..456922ea2194f425c84ba485d471b7ba9588a902 100644 --- a/tests/system-test/2-query/unique.py +++ b/tests/system-test/2-query/unique.py @@ -386,10 +386,60 @@ class TDTestCase: tdSql.error("select unique(c1) from ct1 group by tbname") # super table - + + # super table + tdSql.error("select tbname , tail(c1,2) from stb1 group by tbname") + tdSql.query("select tail(c1,2) from stb1 partition by tbname") + tdSql.checkRows(4) - + # bug need fix + # tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname") + # tdSql.checkRows(4) + + # tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname order by tbname") + # tdSql.checkRows(4) + + # tdSql.query(" select tbname , count(c1) from stb1 partition by tbname order by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname , max(c1) ,c1 from stb1 partition by tbname order by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname ,first(c1) from stb1 partition by tbname order by tbname ") + # tdSql.checkRows(2) + + tdSql.query("select tail(c1,2) from stb1 partition by tbname") + tdSql.checkRows(4) + + + # # bug need fix + # tdSql.query(" select tbname , unique(c1) from stb1 where t1 = 0 partition by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname , unique(c1) from stb1 where t1 = 0 partition by tbname order by tbname ") + # tdSql.checkRows(2) + # tdSql.query(" select tbname , unique(c1) from stb1 where c1 = 0 partition by tbname order by tbname ") + # tdSql.checkRows(3) + # tdSql.query(" select tbname , unique(c1) from stb1 where c1 = 0 partition by tbname ") + # tdSql.checkRows(3) + + tdSql.query(" select unique(t1) from stb1 ") + tdSql.checkRows(2) + tdSql.query(" select unique(t1+c1) from stb1 ") + tdSql.checkRows(13) + tdSql.query(" select unique(t1+c1) from stb1 partition by tbname ") + tdSql.checkRows(13) + tdSql.query(" select unique(t1) from stb1 partition by tbname ") + tdSql.checkRows(2) + + # nest query + tdSql.query(" select unique(c1) from (select _rowts , t1 ,c1 , tbname from stb1 ) ") + tdSql.checkRows(11) + tdSql.checkData(0,0,6) + tdSql.checkData(10,0,3) + tdSql.query("select unique(t1) from (select _rowts , t1 , tbname from stb1 )") + tdSql.checkRows(2) + tdSql.checkData(0,0,4) + tdSql.checkData(1,0,1) + def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py index fc2552d6f27c5cc80884535e4c3baa8a4ddcfd98..eaef1348457223d0754e9148d4d7cf315f136886 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py @@ -172,7 +172,7 @@ class TDTestCase: tmqCom.initConsumerTable() tdLog.info("create topics from stb with filter") - queryString = "select ts, acos(c1), ceil(pow(c1,3)) from %s.%s where (sin(c2) >= 0) and (c1 %% 4 == 0) and (ts >= %d) and (t4 like 'shanghai')"%(paraDict['dbName'], paraDict['stbName'], paraDict["startTs"]+math.ceil(self.rowsPerTbl/5)) + queryString = "select ts, acos(c1), ceil(pow(c1,3)) from %s.%s where (sin(c2) >= 0) and (c1 %% 4 != 0) and (ts+1a >= %d) and (t4 like '%%shanghai')"%(paraDict['dbName'], paraDict['stbName'], paraDict["startTs"]+math.ceil(self.rowsPerTbl/10)) # queryString = "select * from %s.%s"%(paraDict['dbName'], paraDict['stbName']) # sqlString = "create topic %s as stable %s" %(topicNameList[0], paraDict['stbName']) sqlString = "create topic %s as %s" %(topicNameList[0], queryString) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 889b3165685259a83291e2796421a8315b42c8fe..2e0330a2df3820497714e80d0e853f31a7daa972 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -29,6 +29,7 @@ python3 ./test.py -f 1-insert/block_wise.py python3 ./test.py -f 1-insert/create_retentions.py #python3 ./test.py -f 1-insert/table_param_ttl.py + python3 ./test.py -f 2-query/between.py python3 ./test.py -f 2-query/distinct.py python3 ./test.py -f 2-query/varchar.py @@ -53,6 +54,7 @@ python3 ./test.py -f 2-query/spread.py python3 ./test.py -f 2-query/hyperloglog.py python3 ./test.py -f 2-query/explain.py python3 ./test.py -f 2-query/leastsquares.py +python3 ./test.py -f 2-query/histogram.py python3 ./test.py -f 2-query/timezone.py @@ -94,7 +96,7 @@ python3 ./test.py -f 2-query/query_cols_tags_and_or.py # python3 ./test.py -f 2-query/nestedQuery_str.py python3 ./test.py -f 2-query/avg.py -#python3 ./test.py -f 2-query/elapsed.py +python3 ./test.py -f 2-query/elapsed.py python3 ./test.py -f 2-query/csum.py python3 ./test.py -f 2-query/mavg.py python3 ./test.py -f 2-query/diff.py @@ -116,9 +118,10 @@ python3 ./test.py -f 2-query/distribute_agg_avg.py python3 ./test.py -f 2-query/distribute_agg_stddev.py python3 ./test.py -f 2-query/twa.py python3 ./test.py -f 2-query/irate.py +python3 ./test.py -f 2-query/and_or_for_byte.py python3 ./test.py -f 2-query/function_null.py -#python3 ./test.py -f 2-query/queryQnode.py +python3 ./test.py -f 2-query/queryQnode.py #python3 ./test.py -f 6-cluster/5dnode1mnode.py #python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3 @@ -172,3 +175,176 @@ python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-1ctb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb.py + + +#------------querPolicy 2----------- + +python3 ./test.py -f 2-query/between.py -Q 2 +python3 ./test.py -f 2-query/distinct.py -Q 2 +python3 ./test.py -f 2-query/varchar.py -Q 2 +python3 ./test.py -f 2-query/ltrim.py -Q 2 +python3 ./test.py -f 2-query/rtrim.py -Q 2 +python3 ./test.py -f 2-query/length.py -Q 2 +python3 ./test.py -f 2-query/char_length.py -Q 2 +python3 ./test.py -f 2-query/upper.py -Q 2 +python3 ./test.py -f 2-query/lower.py -Q 2 +python3 ./test.py -f 2-query/join.py -Q 2 +python3 ./test.py -f 2-query/join2.py -Q 2 +python3 ./test.py -f 2-query/cast.py -Q 2 +python3 ./test.py -f 2-query/substr.py -Q 2 +python3 ./test.py -f 2-query/union.py -Q 2 +python3 ./test.py -f 2-query/union1.py -Q 2 +python3 ./test.py -f 2-query/concat.py -Q 2 +python3 ./test.py -f 2-query/concat2.py -Q 2 +python3 ./test.py -f 2-query/concat_ws.py -Q 2 +python3 ./test.py -f 2-query/concat_ws2.py -Q 2 +python3 ./test.py -f 2-query/check_tsdb.py -Q 2 +python3 ./test.py -f 2-query/spread.py -Q 2 +python3 ./test.py -f 2-query/hyperloglog.py -Q 2 +python3 ./test.py -f 2-query/explain.py -Q 2 +python3 ./test.py -f 2-query/leastsquares.py -Q 2 +python3 ./test.py -f 2-query/timezone.py -Q 2 +python3 ./test.py -f 2-query/Now.py -Q 2 +python3 ./test.py -f 2-query/Today.py -Q 2 +python3 ./test.py -f 2-query/max.py -Q 2 +python3 ./test.py -f 2-query/min.py -Q 2 +python3 ./test.py -f 2-query/count.py -Q 2 +python3 ./test.py -f 2-query/last.py -Q 2 +python3 ./test.py -f 2-query/first.py -Q 2 +python3 ./test.py -f 2-query/To_iso8601.py -Q 2 +python3 ./test.py -f 2-query/To_unixtimestamp.py -Q 2 +python3 ./test.py -f 2-query/timetruncate.py -Q 2 +python3 ./test.py -f 2-query/diff.py -Q 2 +python3 ./test.py -f 2-query/Timediff.py -Q 2 +python3 ./test.py -f 2-query/json_tag.py -Q 2 +python3 ./test.py -f 2-query/top.py -Q 2 +python3 ./test.py -f 2-query/bottom.py -Q 2 +python3 ./test.py -f 2-query/percentile.py -Q 2 +python3 ./test.py -f 2-query/apercentile.py -Q 2 +python3 ./test.py -f 2-query/abs.py -Q 2 +python3 ./test.py -f 2-query/ceil.py -Q 2 +python3 ./test.py -f 2-query/floor.py -Q 2 +python3 ./test.py -f 2-query/round.py -Q 2 +python3 ./test.py -f 2-query/log.py -Q 2 +python3 ./test.py -f 2-query/pow.py -Q 2 +python3 ./test.py -f 2-query/sqrt.py -Q 2 +python3 ./test.py -f 2-query/sin.py -Q 2 +python3 ./test.py -f 2-query/cos.py -Q 2 +python3 ./test.py -f 2-query/tan.py -Q 2 +python3 ./test.py -f 2-query/arcsin.py -Q 2 +python3 ./test.py -f 2-query/arccos.py -Q 2 +python3 ./test.py -f 2-query/arctan.py -Q 2 +python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 2 + +# python3 ./test.py -f 2-query/nestedQuery.py -Q 2 +# python3 ./test.py -f 2-query/nestedQuery_str.py -Q 2 + +python3 ./test.py -f 2-query/avg.py -Q 2 +# python3 ./test.py -f 2-query/elapsed.py -Q 2 +python3 ./test.py -f 2-query/csum.py -Q 2 +python3 ./test.py -f 2-query/mavg.py -Q 2 +python3 ./test.py -f 2-query/diff.py -Q 2 +python3 ./test.py -f 2-query/sample.py -Q 2 +python3 ./test.py -f 2-query/function_diff.py -Q 2 +python3 ./test.py -f 2-query/unique.py -Q 2 +python3 ./test.py -f 2-query/stateduration.py -Q 2 +python3 ./test.py -f 2-query/function_stateduration.py -Q 2 +python3 ./test.py -f 2-query/statecount.py -Q 2 +python3 ./test.py -f 2-query/tail.py -Q 2 +python3 ./test.py -f 2-query/ttl_comment.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_count.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_max.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_min.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_sum.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_spread.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_apercentile.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_avg.py -Q 2 +python3 ./test.py -f 2-query/distribute_agg_stddev.py -Q 2 +python3 ./test.py -f 2-query/twa.py -Q 2 +python3 ./test.py -f 2-query/irate.py -Q 2 +python3 ./test.py -f 2-query/function_null.py -Q 2 + +#------------querPolicy 3----------- + +python3 ./test.py -f 2-query/between.py -Q 3 +python3 ./test.py -f 2-query/distinct.py -Q 3 +python3 ./test.py -f 2-query/varchar.py -Q 3 +python3 ./test.py -f 2-query/ltrim.py -Q 3 +python3 ./test.py -f 2-query/rtrim.py -Q 3 +python3 ./test.py -f 2-query/length.py -Q 3 +python3 ./test.py -f 2-query/char_length.py -Q 3 +python3 ./test.py -f 2-query/upper.py -Q 3 +python3 ./test.py -f 2-query/lower.py -Q 3 +python3 ./test.py -f 2-query/join.py -Q 3 +python3 ./test.py -f 2-query/join2.py -Q 3 +python3 ./test.py -f 2-query/cast.py -Q 3 +python3 ./test.py -f 2-query/substr.py -Q 3 +python3 ./test.py -f 2-query/union.py -Q 3 +python3 ./test.py -f 2-query/union1.py -Q 3 +python3 ./test.py -f 2-query/concat.py -Q 3 +python3 ./test.py -f 2-query/concat2.py -Q 3 +python3 ./test.py -f 2-query/concat_ws.py -Q 3 +python3 ./test.py -f 2-query/concat_ws2.py -Q 3 +python3 ./test.py -f 2-query/check_tsdb.py -Q 3 +python3 ./test.py -f 2-query/spread.py -Q 3 +python3 ./test.py -f 2-query/hyperloglog.py -Q 3 +python3 ./test.py -f 2-query/explain.py -Q 3 +python3 ./test.py -f 2-query/leastsquares.py -Q 3 +python3 ./test.py -f 2-query/timezone.py -Q 3 +python3 ./test.py -f 2-query/Now.py -Q 3 +python3 ./test.py -f 2-query/Today.py -Q 3 +python3 ./test.py -f 2-query/max.py -Q 3 +python3 ./test.py -f 2-query/min.py -Q 3 +python3 ./test.py -f 2-query/count.py -Q 3 +python3 ./test.py -f 2-query/last.py -Q 3 +python3 ./test.py -f 2-query/first.py -Q 3 +python3 ./test.py -f 2-query/To_iso8601.py -Q 3 +python3 ./test.py -f 2-query/To_unixtimestamp.py -Q 3 +python3 ./test.py -f 2-query/timetruncate.py -Q 3 +python3 ./test.py -f 2-query/diff.py -Q 3 +python3 ./test.py -f 2-query/Timediff.py -Q 3 +python3 ./test.py -f 2-query/json_tag.py -Q 3 +python3 ./test.py -f 2-query/top.py -Q 3 +python3 ./test.py -f 2-query/bottom.py -Q 3 +python3 ./test.py -f 2-query/percentile.py -Q 3 +python3 ./test.py -f 2-query/apercentile.py -Q 3 +python3 ./test.py -f 2-query/abs.py -Q 3 +python3 ./test.py -f 2-query/ceil.py -Q 3 +python3 ./test.py -f 2-query/floor.py -Q 3 +python3 ./test.py -f 2-query/round.py -Q 3 +python3 ./test.py -f 2-query/log.py -Q 3 +python3 ./test.py -f 2-query/pow.py -Q 3 +python3 ./test.py -f 2-query/sqrt.py -Q 3 +python3 ./test.py -f 2-query/sin.py -Q 3 +python3 ./test.py -f 2-query/cos.py -Q 3 +python3 ./test.py -f 2-query/tan.py -Q 3 +python3 ./test.py -f 2-query/arcsin.py -Q 3 +python3 ./test.py -f 2-query/arccos.py -Q 3 +python3 ./test.py -f 2-query/arctan.py -Q 3 +python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 3 +# python3 ./test.py -f 2-query/nestedQuery.py -Q 3 +# python3 ./test.py -f 2-query/nestedQuery_str.py -Q 3 +# python3 ./test.py -f 2-query/avg.py -Q 3 +# python3 ./test.py -f 2-query/elapsed.py -Q 3 +python3 ./test.py -f 2-query/csum.py -Q 3 +python3 ./test.py -f 2-query/mavg.py -Q 3 +python3 ./test.py -f 2-query/diff.py -Q 3 +python3 ./test.py -f 2-query/sample.py -Q 3 +python3 ./test.py -f 2-query/function_diff.py -Q 3 +python3 ./test.py -f 2-query/unique.py -Q 3 +python3 ./test.py -f 2-query/stateduration.py -Q 3 +python3 ./test.py -f 2-query/function_stateduration.py -Q 3 +python3 ./test.py -f 2-query/statecount.py -Q 3 +python3 ./test.py -f 2-query/tail.py -Q 3 +python3 ./test.py -f 2-query/ttl_comment.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_count.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_max.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_min.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_sum.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_spread.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_apercentile.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_avg.py -Q 3 +python3 ./test.py -f 2-query/distribute_agg_stddev.py -Q 3 +python3 ./test.py -f 2-query/twa.py -Q 3 +python3 ./test.py -f 2-query/irate.py -Q 3 +python3 ./test.py -f 2-query/function_null.py -Q 3 diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index 41ce1cc28071d2c86a3110a01df524653603dde1..cdbdc0de604d6359ce73d834ac84b7b7c5482395 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -44,27 +44,27 @@ static int32_t shellParseSingleOpt(int32_t key, char *arg); void shellPrintHelp() { char indent[] = " "; - printf("Usage: taos [OPTION...] \n\n"); - printf("%s%s%s%s\n", indent, "-a,", indent, SHELL_AUTH); - printf("%s%s%s%s\n", indent, "-A,", indent, SHELL_GEN_AUTH); - printf("%s%s%s%s\n", indent, "-c,", indent, SHELL_CFG_DIR); - printf("%s%s%s%s\n", indent, "-C,", indent, SHELL_DMP_CFG); - printf("%s%s%s%s\n", indent, "-d,", indent, SHELL_DB); - printf("%s%s%s%s\n", indent, "-f,", indent, SHELL_FILE); - printf("%s%s%s%s\n", indent, "-h,", indent, SHELL_HOST); - printf("%s%s%s%s\n", indent, "-k,", indent, SHELL_CHECK); - printf("%s%s%s%s\n", indent, "-l,", indent, SHELL_PKG_LEN); - printf("%s%s%s%s\n", indent, "-n,", indent, SHELL_NET_ROLE); - printf("%s%s%s%s\n", indent, "-N,", indent, SHELL_PKT_NUM); - printf("%s%s%s%s\n", indent, "-p,", indent, SHELL_PASSWORD); - printf("%s%s%s%s\n", indent, "-P,", indent, SHELL_PORT); - printf("%s%s%s%s\n", indent, "-r,", indent, SHELL_RAW_TIME); - printf("%s%s%s%s\n", indent, "-s,", indent, SHELL_CMD); - printf("%s%s%s%s\n", indent, "-t,", indent, SHELL_STARTUP); - printf("%s%s%s%s\n", indent, "-u,", indent, SHELL_USER); - printf("%s%s%s%s\n", indent, "-w,", indent, SHELL_WIDTH); - printf("%s%s%s%s\n", indent, "-V,", indent, SHELL_VERSION); - printf("\n\nReport bugs to %s.\n", SHELL_EMAIL); + printf("Usage: taos [OPTION...] \r\n\r\n"); + printf("%s%s%s%s\r\n", indent, "-a,", indent, SHELL_AUTH); + printf("%s%s%s%s\r\n", indent, "-A,", indent, SHELL_GEN_AUTH); + printf("%s%s%s%s\r\n", indent, "-c,", indent, SHELL_CFG_DIR); + printf("%s%s%s%s\r\n", indent, "-C,", indent, SHELL_DMP_CFG); + printf("%s%s%s%s\r\n", indent, "-d,", indent, SHELL_DB); + printf("%s%s%s%s\r\n", indent, "-f,", indent, SHELL_FILE); + printf("%s%s%s%s\r\n", indent, "-h,", indent, SHELL_HOST); + printf("%s%s%s%s\r\n", indent, "-k,", indent, SHELL_CHECK); + printf("%s%s%s%s\r\n", indent, "-l,", indent, SHELL_PKG_LEN); + printf("%s%s%s%s\r\n", indent, "-n,", indent, SHELL_NET_ROLE); + printf("%s%s%s%s\r\n", indent, "-N,", indent, SHELL_PKT_NUM); + printf("%s%s%s%s\r\n", indent, "-p,", indent, SHELL_PASSWORD); + printf("%s%s%s%s\r\n", indent, "-P,", indent, SHELL_PORT); + printf("%s%s%s%s\r\n", indent, "-r,", indent, SHELL_RAW_TIME); + printf("%s%s%s%s\r\n", indent, "-s,", indent, SHELL_CMD); + printf("%s%s%s%s\r\n", indent, "-t,", indent, SHELL_STARTUP); + printf("%s%s%s%s\r\n", indent, "-u,", indent, SHELL_USER); + printf("%s%s%s%s\r\n", indent, "-w,", indent, SHELL_WIDTH); + printf("%s%s%s%s\r\n", indent, "-V,", indent, SHELL_VERSION); + printf("\r\n\r\nReport bugs to %s.\r\n", SHELL_EMAIL); } #ifdef LINUX @@ -196,23 +196,23 @@ int32_t shellParseArgsWithoutArgp(int argc, char *argv[]) { char *key = argv[i]; int32_t keyLen = strlen(key); if (keyLen != 2) { - fprintf(stderr, "invalid option %s\n", key); + fprintf(stderr, "invalid option %s\r\n", key); return -1; } if (key[0] != '-') { - fprintf(stderr, "invalid option %s\n", key); + fprintf(stderr, "invalid option %s\r\n", key); return -1; } if (key[1] == 'h' || key[1] == 'P' || key[1] == 'u' || key[1] == 'a' || key[1] == 'c' || key[1] == 's' || key[1] == 'f' || key[1] == 'd' || key[1] == 'w' || key[1] == 'n' || key[1] == 'l' || key[1] == 'N') { if (i + 1 >= argc) { - fprintf(stderr, "option %s requires an argument\n", key); + fprintf(stderr, "option %s requires an argument\r\n", key); return -1; } char *val = argv[i + 1]; if (val[0] == '-') { - fprintf(stderr, "option %s requires an argument\n", key); + fprintf(stderr, "option %s requires an argument\r\n", key); return -1; } shellParseSingleOpt(key[1], val); @@ -221,7 +221,7 @@ int32_t shellParseArgsWithoutArgp(int argc, char *argv[]) { key[1] == 't' || key[1] == 'V' || key[1] == '?' || key[1] == 1) { shellParseSingleOpt(key[1], NULL); } else { - fprintf(stderr, "invalid option %s\n", key); + fprintf(stderr, "invalid option %s\r\n", key); return -1; } } @@ -241,7 +241,7 @@ static void shellInitArgs(int argc, char *argv[]) { } taosSetConsoleEcho(true); if (EOF == getchar()) { - fprintf(stderr, "getchar() return EOF\n"); + fprintf(stderr, "getchar() return EOF\r\n"); } } else { tstrncpy(shell.args.password, (char *)(argv[i] + 2), sizeof(shell.args.password)); @@ -263,22 +263,22 @@ static void shellInitArgs(int argc, char *argv[]) { static int32_t shellCheckArgs() { SShellArgs *pArgs = &shell.args; if (pArgs->host != NULL && (strlen(pArgs->host) <= 0 || strlen(pArgs->host) > TSDB_FQDN_LEN)) { - printf("Invalid host:%s\n", pArgs->host); + printf("Invalid host:%s\r\n", pArgs->host); return -1; } if (pArgs->user != NULL && (strlen(pArgs->user) <= 0 || strlen(pArgs->user) > TSDB_USER_LEN)) { - printf("Invalid user:%s\n", pArgs->user); + printf("Invalid user:%s\r\n", pArgs->user); return -1; } if (pArgs->auth != NULL && (strlen(pArgs->auth) <= 0 || strlen(pArgs->auth) > TSDB_PASSWORD_LEN)) { - printf("Invalid auth:%s\n", pArgs->auth); + printf("Invalid auth:%s\r\n", pArgs->auth); return -1; } if (pArgs->database != NULL && (strlen(pArgs->database) <= 0 || strlen(pArgs->database) > TSDB_DB_NAME_LEN)) { - printf("Invalid database:%s\n", pArgs->database); + printf("Invalid database:%s\r\n", pArgs->database); return -1; } @@ -291,7 +291,7 @@ static int32_t shellCheckArgs() { if (pArgs->cfgdir != NULL) { if (strlen(pArgs->cfgdir) <= 0 || strlen(pArgs->cfgdir) >= PATH_MAX) { - printf("Invalid cfgdir:%s\n", pArgs->cfgdir); + printf("Invalid cfgdir:%s\r\n", pArgs->cfgdir); return -1; } else { if (taosExpandDir(pArgs->cfgdir, configDir, PATH_MAX) != 0) { @@ -301,37 +301,37 @@ static int32_t shellCheckArgs() { } if (pArgs->commands != NULL && (strlen(pArgs->commands) <= 0)) { - printf("Invalid commands:%s\n", pArgs->commands); + printf("Invalid commands:%s\r\n", pArgs->commands); return -1; } if (pArgs->netrole != NULL && !(strcmp(pArgs->netrole, "client") == 0 || strcmp(pArgs->netrole, "server") == 0)) { - printf("Invalid netrole:%s\n", pArgs->netrole); + printf("Invalid netrole:%s\r\n", pArgs->netrole); return -1; } if (pArgs->password != NULL && (strlen(pArgs->password) <= 0)) { - printf("Invalid password\n"); + printf("Invalid password\r\n"); return -1; } if (pArgs->port < 0 || pArgs->port > 65535) { - printf("Invalid port\n"); + printf("Invalid port\r\n"); return -1; } if (pArgs->pktLen < SHELL_MIN_PKG_LEN || pArgs->pktLen > SHELL_MAX_PKG_LEN) { - printf("Invalid pktLen:%d, range:[%d, %d]\n", pArgs->pktLen, SHELL_MIN_PKG_LEN, SHELL_MAX_PKG_LEN); + printf("Invalid pktLen:%d, range:[%d, %d]\r\n", pArgs->pktLen, SHELL_MIN_PKG_LEN, SHELL_MAX_PKG_LEN); return -1; } if (pArgs->pktNum < SHELL_MIN_PKG_NUM || pArgs->pktNum > SHELL_MAX_PKG_NUM) { - printf("Invalid pktNum:%d, range:[%d, %d]\n", pArgs->pktNum, SHELL_MIN_PKG_NUM, SHELL_MAX_PKG_NUM); + printf("Invalid pktNum:%d, range:[%d, %d]\r\n", pArgs->pktNum, SHELL_MIN_PKG_NUM, SHELL_MAX_PKG_NUM); return -1; } if (pArgs->displayWidth <= 0 || pArgs->displayWidth > 10 * 1024) { - printf("Invalid displayWidth:%d, range:[1, 10 * 1024]\n", pArgs->displayWidth); + printf("Invalid displayWidth:%d, range:[1, 10 * 1024]\r\n", pArgs->displayWidth); return -1; } @@ -341,8 +341,8 @@ static int32_t shellCheckArgs() { int32_t shellParseArgs(int32_t argc, char *argv[]) { shellInitArgs(argc, argv); shell.info.clientVersion = - "Welcome to the TDengine shell from %s, Client Version:%s\n" - "Copyright (c) 2022 by TAOS Data, Inc. All rights reserved.\n\n"; + "Welcome to the TDengine shell from %s, Client Version:%s\r\n" + "Copyright (c) 2022 by TAOS Data, Inc. All rights reserved.\r\n\r\n"; shell.info.promptHeader = TAOS_CONSOLE_PROMPT_HEADER; shell.info.promptContinue = TAOS_CONSOLE_PROMPT_CONTINUE; shell.info.promptSize = 6; diff --git a/tools/shell/src/shellCommand.c b/tools/shell/src/shellCommand.c index cc1171b3dfe310847373597d2f5f626abd60c8f4..ce3718e00194e7c94d94faa3a9d9d5cc99505b11 100644 --- a/tools/shell/src/shellCommand.c +++ b/tools/shell/src/shellCommand.c @@ -314,7 +314,7 @@ void shellGetScreenSize(int32_t *ws_col, int32_t *ws_row) { #else struct winsize w; if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) { - // fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n"); + // fprintf(stderr, "No stream device, and use default value(col 120, row 30)\r\n"); if (ws_col != NULL) *ws_col = 120; if (ws_row != NULL) *ws_row = 30; } else { @@ -473,7 +473,7 @@ int32_t shellReadCommand(char *command) { shellPositionCursorHome(&cmd); break; case 3: - printf("\n"); + printf("\r\n"); shellResetCommand(&cmd, ""); #ifdef WINDOWS raise(SIGINT); @@ -483,7 +483,7 @@ int32_t shellReadCommand(char *command) { break; case 4: // EOF or Ctrl+D taosResetTerminalMode(); - printf("\n"); + printf("\r\n"); return -1; case 5: // ctrl E shellPositionCursorEnd(&cmd); @@ -495,7 +495,7 @@ int32_t shellReadCommand(char *command) { case '\r': #ifdef WINDOWS #else - printf("\n"); + printf("\r\n"); #endif if (shellIsReadyGo(&cmd)) { sprintf(command, "%s%s", cmd.buffer, cmd.command); diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 4500188b95ac9af234dd52c5a66fe3bb76a09f2c..d6b7f18fb9f6ea7fd8b79b7c2d011117118b7b90 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -180,7 +180,7 @@ void shellRunSingleCommandImp(char *command) { } if (shellRegexMatch(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) { - fprintf(stdout, "Database changed.\n\n"); + fprintf(stdout, "Database changed.\r\n\r\n"); fflush(stdout); taos_free_result(pSql); @@ -197,19 +197,19 @@ void shellRunSingleCommandImp(char *command) { et = taosGetTimestampUs(); if (error_no == 0) { - printf("Query OK, %d rows affected (%.6fs)\n", numOfRows, (et - st) / 1E6); + printf("Query OK, %d rows affected (%.6fs)\r\n", numOfRows, (et - st) / 1E6); } else { - printf("Query interrupted (%s), %d rows affected (%.6fs)\n", taos_errstr(pSql), numOfRows, (et - st) / 1E6); + printf("Query interrupted (%s), %d rows affected (%.6fs)\r\n", taos_errstr(pSql), numOfRows, (et - st) / 1E6); } taos_free_result(pSql); } else { int32_t num_rows_affacted = taos_affected_rows(pSql); taos_free_result(pSql); et = taosGetTimestampUs(); - printf("Query OK, %d of %d rows affected (%.6fs)\n", num_rows_affacted, num_rows_affacted, (et - st) / 1E6); + printf("Query OK, %d of %d rows affected (%.6fs)\r\n", num_rows_affacted, num_rows_affacted, (et - st) / 1E6); } - printf("\n"); + printf("\r\n"); } char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) { @@ -344,7 +344,7 @@ int32_t shellDumpResultToFile(const char *fname, TAOS_RES *tres) { TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { - fprintf(stderr, "failed to open file: %s\n", fullname); + fprintf(stderr, "failed to open file: %s\r\n", fullname); return -1; } @@ -358,7 +358,7 @@ int32_t shellDumpResultToFile(const char *fname, TAOS_RES *tres) { } taosFprintfFile(pFile, "%s", fields[col].name); } - taosFprintfFile(pFile, "\n"); + taosFprintfFile(pFile, "\r\n"); int32_t numOfRows = 0; do { @@ -369,7 +369,7 @@ int32_t shellDumpResultToFile(const char *fname, TAOS_RES *tres) { } shellDumpFieldToFile(pFile, (const char *)row[i], fields + i, length[i], precision); } - taosFprintfFile(pFile, "\n"); + taosFprintfFile(pFile, "\r\n"); numOfRows++; row = taos_fetch_row(tres); @@ -559,7 +559,7 @@ int32_t shellVerticalPrintResult(TAOS_RES *tres, const char *sql) { int32_t showMore = 1; do { if (numOfRows < resShowMaxNum) { - printf("*************************** %d.row ***************************\n", numOfRows + 1); + printf("*************************** %d.row ***************************\r\n", numOfRows + 1); int32_t *length = taos_fetch_lengths(tres); @@ -570,16 +570,17 @@ int32_t shellVerticalPrintResult(TAOS_RES *tres, const char *sql) { printf("%*.s%s: ", padding, " ", field->name); shellPrintField((const char *)row[i], field, 0, length[i], precision); + putchar('\r'); putchar('\n'); } } else if (showMore) { - printf("\n"); - printf(" Notice: The result shows only the first %d rows.\n", SHELL_DEFAULT_RES_SHOW_NUM); - printf(" You can use the `LIMIT` clause to get fewer result to show.\n"); - printf(" Or use '>>' to redirect the whole set of the result to a specified file.\n"); - printf("\n"); - printf(" You can use Ctrl+C to stop the underway fetching.\n"); - printf("\n"); + printf("\r\n"); + printf(" Notice: The result shows only the first %d rows.\r\n", SHELL_DEFAULT_RES_SHOW_NUM); + printf(" You can use the `LIMIT` clause to get fewer result to show.\r\n"); + printf(" Or use '>>' to redirect the whole set of the result to a specified file.\r\n"); + printf("\r\n"); + printf(" You can use Ctrl+C to stop the underway fetching.\r\n"); + printf("\r\n"); showMore = 0; } @@ -667,10 +668,12 @@ void shellPrintHeader(TAOS_FIELD *fields, int32_t *width, int32_t num_fields) { rowWidth += width[col] + 3; } + putchar('\r'); putchar('\n'); for (int32_t i = 0; i < rowWidth; i++) { putchar('='); } + putchar('\r'); putchar('\n'); } @@ -709,15 +712,16 @@ int32_t shellHorizontalPrintResult(TAOS_RES *tres, const char *sql) { putchar(' '); putchar('|'); } + putchar('\r'); putchar('\n'); } else if (showMore) { - printf("\n"); - printf(" Notice: The result shows only the first %d rows.\n", SHELL_DEFAULT_RES_SHOW_NUM); - printf(" You can use the `LIMIT` clause to get fewer result to show.\n"); - printf(" Or use '>>' to redirect the whole set of the result to a specified file.\n"); - printf("\n"); - printf(" You can use Ctrl+C to stop the underway fetching.\n"); - printf("\n"); + printf("\r\n"); + printf(" Notice: The result shows only the first %d rows.\r\n", SHELL_DEFAULT_RES_SHOW_NUM); + printf(" You can use the `LIMIT` clause to get fewer result to show.\r\n"); + printf(" Or use '>>' to redirect the whole set of the result to a specified file.\r\n"); + printf("\r\n"); + printf(" You can use Ctrl+C to stop the underway fetching.\r\n"); + printf("\r\n"); showMore = 0; } @@ -794,7 +798,7 @@ void shellCleanupHistory() { void shellPrintError(TAOS_RES *tres, int64_t st) { int64_t et = taosGetTimestampUs(); - fprintf(stderr, "\nDB error: %s (%.6fs)\n", taos_errstr(tres), (et - st) / 1E6); + fprintf(stderr, "\r\nDB error: %s (%.6fs)\r\n", taos_errstr(tres), (et - st) / 1E6); taos_free_result(tres); } @@ -816,7 +820,7 @@ void shellSourceFile(const char *file) { TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { - fprintf(stderr, "failed to open file %s\n", fullname); + fprintf(stderr, "failed to open file %s\r\n", fullname); taosMemoryFree(cmd); return; } @@ -837,7 +841,7 @@ void shellSourceFile(const char *file) { } memcpy(cmd + cmd_len, line, read_len); - printf("%s%s\n", shell.info.promptHeader, cmd); + printf("%s%s\r\n", shell.info.promptHeader, cmd); shellRunCommand(cmd); memset(cmd, 0, TSDB_MAX_ALLOWED_SQL_LEN); cmd_len = 0; @@ -851,7 +855,7 @@ void shellSourceFile(const char *file) { void shellGetGrantInfo() { char sinfo[1024] = {0}; tstrncpy(sinfo, taos_get_server_info(shell.conn), sizeof(sinfo)); - strtok(sinfo, "\n"); + strtok(sinfo, "\r\n"); char sql[] = "show grants"; @@ -860,25 +864,25 @@ void shellGetGrantInfo() { int32_t code = taos_errno(tres); if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_OPS_NOT_SUPPORT && code != TSDB_CODE_MND_NO_RIGHTS) { - fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\n\n", code, taos_errstr(tres)); + fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres)); } return; } int32_t num_fields = taos_field_count(tres); if (num_fields == 0) { - fprintf(stderr, "\nInvalid grant information.\n"); + fprintf(stderr, "\r\nInvalid grant information.\r\n"); exit(0); } else { if (tres == NULL) { - fprintf(stderr, "\nGrant information is null.\n"); + fprintf(stderr, "\r\nGrant information is null.\r\n"); exit(0); } TAOS_FIELD *fields = taos_fetch_fields(tres); TAOS_ROW row = taos_fetch_row(tres); if (row == NULL) { - fprintf(stderr, "\nFailed to get grant information from server. Abort.\n"); + fprintf(stderr, "\r\nFailed to get grant information from server. Abort.\r\n"); exit(0); } @@ -891,17 +895,17 @@ void shellGetGrantInfo() { memcpy(expired, row[2], fields[2].bytes); if (strcmp(serverVersion, "community") == 0) { - fprintf(stdout, "Server is Community Edition.\n"); + fprintf(stdout, "Server is Community Edition.\r\n"); } else if (strcmp(expiretime, "unlimited") == 0) { - fprintf(stdout, "Server is Enterprise %s Edition, %s and will never expire.\n", serverVersion, sinfo); + fprintf(stdout, "Server is Enterprise %s Edition, %s and will never expire.\r\n", serverVersion, sinfo); } else { - fprintf(stdout, "Server is Enterprise %s Edition, %s and will expire at %s.\n", serverVersion, sinfo, expiretime); + fprintf(stdout, "Server is Enterprise %s Edition, %s and will expire at %s.\r\n", serverVersion, sinfo, expiretime); } taos_free_result(tres); } - fprintf(stdout, "\n"); + fprintf(stdout, "\r\n"); } void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { tsem_post(&shell.cancelSem); } @@ -921,7 +925,7 @@ void *shellCancelHandler(void *arg) { } taosResetTerminalMode(); - printf("\nReceive SIGTERM or other signal, quit shell.\n"); + printf("\r\nReceive SIGTERM or other signal, quit shell.\r\n"); shellWriteHistory(); shellExit(); } @@ -936,7 +940,7 @@ void *shellThreadLoop(void *arg) { char *command = taosMemoryMalloc(SHELL_MAX_COMMAND_SIZE); if (command == NULL) { - printf("failed to malloc command\n"); + printf("failed to malloc command\r\n"); return NULL; } @@ -979,7 +983,7 @@ int32_t shellExecute() { if (pArgs->commands != NULL || pArgs->file[0] != 0) { if (pArgs->commands != NULL) { - printf("%s%s\n", shell.info.promptHeader, pArgs->commands); + printf("%s%s\r\n", shell.info.promptHeader, pArgs->commands); char *cmd = strdup(pArgs->commands); shellRunCommand(cmd); taosMemoryFree(cmd); @@ -996,7 +1000,7 @@ int32_t shellExecute() { } if (tsem_init(&shell.cancelSem, 0, 0) != 0) { - printf("failed to create cancel semphore\n"); + printf("failed to create cancel semphore\r\n"); return -1; } diff --git a/tools/shell/src/shellNettest.c b/tools/shell/src/shellNettest.c index d25d07d83139558b5d5426422884b8cbf3adb4cc..52ce37b22c7666e5c068937e5b073b6ffb0c530c 100644 --- a/tools/shell/src/shellNettest.c +++ b/tools/shell/src/shellNettest.c @@ -34,7 +34,7 @@ static void shellWorkAsClient() { clientRpc = rpcOpen(&rpcInit); if (clientRpc == NULL) { - printf("failed to init net test client since %s\n", terrstr()); + printf("failed to init net test client since %s\r\n", terrstr()); goto _OVER; } @@ -49,7 +49,7 @@ static void shellWorkAsClient() { pArgs->port = tsServerPort; } - printf("network test client is initialized, the server is %s:%u\n", fqdn, pArgs->port); + printf("network test client is initialized, the server is %s:%u\r\n", fqdn, pArgs->port); tstrncpy(epSet.eps[0].fqdn, fqdn, TSDB_FQDN_LEN); epSet.eps[0].port = (uint16_t)pArgs->port; @@ -62,13 +62,13 @@ static void shellWorkAsClient() { rpcMsg.pCont = rpcMallocCont(pArgs->pktLen); rpcMsg.contLen = pArgs->pktLen; - printf("request is sent, size:%d\n", rpcMsg.contLen); + printf("request is sent, size:%d\r\n", rpcMsg.contLen); rpcSendRecv(clientRpc, &epSet, &rpcMsg, &rpcRsp); if (rpcRsp.code == 0 && rpcRsp.contLen == rpcMsg.contLen) { - printf("response is received, size:%d\n", rpcMsg.contLen); + printf("response is received, size:%d\r\n", rpcMsg.contLen); if (rpcRsp.code == 0) totalSucc++; } else { - printf("response not received since %s\n", tstrerror(rpcRsp.code)); + printf("response not received since %s\r\n", tstrerror(rpcRsp.code)); } rpcFreeCont(rpcRsp.pCont); @@ -78,7 +78,7 @@ static void shellWorkAsClient() { uint64_t endTime = taosGetTimestampUs(); uint64_t elT = endTime - startTime; - printf("\ntotal succ:%5d/%d\tcost:%8.2lf ms\tspeed:%8.2lf MB/s\n", totalSucc, pArgs->pktNum, elT / 1000.0, + printf("\r\ntotal succ:%5d/%d\tcost:%8.2lf ms\tspeed:%8.2lf MB/s\r\n", totalSucc, pArgs->pktNum, elT / 1000.0, pArgs->pktLen / (elT / 1000000.0) / 1024.0 / 1024.0 * totalSucc); _OVER: @@ -91,7 +91,7 @@ _OVER: } static void shellProcessMsg(void *p, SRpcMsg *pRpc, SEpSet *pEpSet) { - printf("request is received, size:%d\n", pRpc->contLen); + printf("request is received, size:%d\r\n", pRpc->contLen); fflush(stdout); SRpcMsg rsp = {.info = pRpc->info, .code = 0}; rsp.pCont = rpcMallocCont(pRpc->contLen); @@ -124,9 +124,9 @@ static void shellWorkAsServer() { void *serverRpc = rpcOpen(&rpcInit); if (serverRpc == NULL) { - printf("failed to init net test server since %s\n", terrstr()); + printf("failed to init net test server since %s\r\n", terrstr()); } else { - printf("network test server is initialized, port:%u\n", pArgs->port); + printf("network test server is initialized, port:%u\r\n", pArgs->port); taosSetSignal(SIGTERM, shellNettestHandler); while (1) taosMsleep(10); } diff --git a/tools/shell/src/shellUtil.c b/tools/shell/src/shellUtil.c index 1529ac0e52b45d11c29691b491bb0284918c0575..e96e3d361940dc1f3f981a74d7122d364e72216c 100644 --- a/tools/shell/src/shellUtil.c +++ b/tools/shell/src/shellUtil.c @@ -40,7 +40,7 @@ bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) { return false; } else { regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); - fprintf(stderr, "Regex match failed: %s\n", msgbuf); + fprintf(stderr, "Regex match failed: %s\r\n", msgbuf); regfree(®ex); shellExit(); } @@ -68,19 +68,19 @@ int32_t shellCheckIntSize() { return 0; } -void shellPrintVersion() { printf("version: %s\n", version); } +void shellPrintVersion() { printf("version: %s\r\n", version); } void shellGenerateAuth() { char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0}; taosEncryptPass_c((uint8_t *)shell.args.password, strlen(shell.args.password), secretEncrypt); - printf("%s\n", secretEncrypt); + printf("%s\r\n", secretEncrypt); fflush(stdout); } void shellDumpConfig() { SConfig *pCfg = taosGetCfg(); if (pCfg == NULL) { - printf("TDengine read global config failed!\n"); + printf("TDengine read global config failed!\r\n"); } else { cfgDumpCfg(pCfg, 1, true); } @@ -95,23 +95,23 @@ void shellCheckServerStatus() { code = taos_check_server_status(shell.args.host, shell.args.port, details, 1024); switch (code) { case TSDB_SRV_STATUS_UNAVAILABLE: - printf("0: unavailable\n"); + printf("0: unavailable\r\n"); break; case TSDB_SRV_STATUS_NETWORK_OK: - printf("1: network ok\n"); + printf("1: network ok\r\n"); break; case TSDB_SRV_STATUS_SERVICE_OK: - printf("2: service ok\n"); + printf("2: service ok\r\n"); break; case TSDB_SRV_STATUS_SERVICE_DEGRADED: - printf("3: service degraded\n"); + printf("3: service degraded\r\n"); break; case TSDB_SRV_STATUS_EXTING: - printf("4: exiting\n"); + printf("4: exiting\r\n"); break; } if (strlen(details) != 0) { - printf("%s\n\n", details); + printf("%s\r\n\r\n", details); } fflush(stdout); if (code == TSDB_SRV_STATUS_NETWORK_OK && shell.args.is_startup) { diff --git a/tools/taos-tools b/tools/taos-tools index 1163c0f60aa65d6cc58283247c8bf8c56ba43b92..7105027650b51e701cfa1dac11b8fb42d447dd01 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit 1163c0f60aa65d6cc58283247c8bf8c56ba43b92 +Subproject commit 7105027650b51e701cfa1dac11b8fb42d447dd01 diff --git a/tools/taosadapter b/tools/taosadapter index c3815951fc80617ecd171f3743b8b4a4d0bc712e..c885e967e490105999b84d009a15168728dfafaf 160000 --- a/tools/taosadapter +++ b/tools/taosadapter @@ -1 +1 @@ -Subproject commit c3815951fc80617ecd171f3743b8b4a4d0bc712e +Subproject commit c885e967e490105999b84d009a15168728dfafaf